TabletStatusBar.java revision d7c8b6d2a4d2ec16f4f61c66f400d8b20726964c
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.systemui.statusbar.tablet; 18 19import java.io.FileDescriptor; 20import java.io.PrintWriter; 21import java.util.ArrayList; 22 23import android.animation.LayoutTransition; 24import android.animation.ObjectAnimator; 25import android.app.ActivityManagerNative; 26import android.app.Dialog; 27import android.app.PendingIntent; 28import android.app.Notification; 29import android.app.StatusBarManager; 30import android.content.Context; 31import android.content.Intent; 32import android.content.SharedPreferences; 33import android.content.res.Configuration; 34import android.content.res.Resources; 35import android.inputmethodservice.InputMethodService; 36import android.graphics.PixelFormat; 37import android.graphics.Rect; 38import android.graphics.drawable.LayerDrawable; 39import android.provider.Settings; 40import android.os.Handler; 41import android.os.IBinder; 42import android.os.Message; 43import android.os.RemoteException; 44import android.os.ServiceManager; 45import android.text.TextUtils; 46import android.util.Slog; 47import android.view.accessibility.AccessibilityEvent; 48import android.view.Display; 49import android.view.Gravity; 50import android.view.IWindowManager; 51import android.view.KeyEvent; 52import android.view.LayoutInflater; 53import android.view.MotionEvent; 54import android.view.SoundEffectConstants; 55import android.view.VelocityTracker; 56import android.view.View; 57import android.view.ViewConfiguration; 58import android.view.ViewGroup; 59import android.view.WindowManager; 60import android.view.WindowManagerImpl; 61import android.widget.ImageView; 62import android.widget.LinearLayout; 63import android.widget.RemoteViews; 64import android.widget.ScrollView; 65import android.widget.TextView; 66 67import com.android.internal.statusbar.StatusBarIcon; 68import com.android.internal.statusbar.StatusBarNotification; 69 70import com.android.systemui.R; 71import com.android.systemui.statusbar.*; 72import com.android.systemui.statusbar.policy.BatteryController; 73import com.android.systemui.statusbar.policy.BluetoothController; 74import com.android.systemui.statusbar.policy.CompatModeButton; 75import com.android.systemui.statusbar.policy.LocationController; 76import com.android.systemui.statusbar.policy.NetworkController; 77import com.android.systemui.statusbar.policy.Prefs; 78import com.android.systemui.recent.RecentsPanelView; 79import com.android.systemui.recent.carousel.RecentApplicationsActivity; 80 81public class TabletStatusBar extends StatusBar implements 82 HeightReceiver.OnBarHeightChangedListener, 83 InputMethodsPanel.OnHardKeyboardEnabledChangeListener { 84 public static final boolean DEBUG = false; 85 public static final String TAG = "TabletStatusBar"; 86 87 88 public static final int MSG_OPEN_NOTIFICATION_PANEL = 1000; 89 public static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001; 90 public static final int MSG_OPEN_NOTIFICATION_PEEK = 1002; 91 public static final int MSG_CLOSE_NOTIFICATION_PEEK = 1003; 92 public static final int MSG_OPEN_RECENTS_PANEL = 1020; 93 public static final int MSG_CLOSE_RECENTS_PANEL = 1021; 94 public static final int MSG_SHOW_CHROME = 1030; 95 public static final int MSG_HIDE_CHROME = 1031; 96 public static final int MSG_OPEN_INPUT_METHODS_PANEL = 1040; 97 public static final int MSG_CLOSE_INPUT_METHODS_PANEL = 1041; 98 public static final int MSG_OPEN_COMPAT_MODE_PANEL = 1050; 99 public static final int MSG_CLOSE_COMPAT_MODE_PANEL = 1051; 100 public static final int MSG_STOP_TICKER = 2000; 101 102 // Fitts' Law assistance for LatinIME; see policy.EventHole 103 private static final boolean FAKE_SPACE_BAR = true; 104 105 // The height of the bar, as definied by the build. It may be taller if we're plugged 106 // into hdmi. 107 int mNaturalBarHeight = -1; 108 int mIconSize = -1; 109 int mIconHPadding = -1; 110 private int mMaxNotificationIcons = 5; 111 112 H mHandler = new H(); 113 114 IWindowManager mWindowManager; 115 116 // tracking all current notifications 117 private NotificationData mNotificationData = new NotificationData(); 118 119 TabletStatusBarView mStatusBarView; 120 View mNotificationArea; 121 View mNotificationTrigger; 122 NotificationIconArea mNotificationIconArea; 123 ViewGroup mNavigationArea; 124 125 boolean mNotificationDNDMode; 126 NotificationData.Entry mNotificationDNDDummyEntry; 127 128 ImageView mBackButton; 129 View mHomeButton; 130 View mMenuButton; 131 View mRecentButton; 132 133 ViewGroup mFeedbackIconArea; // notification icons, IME icon, compat icon 134 InputMethodButton mInputMethodSwitchButton; 135 CompatModeButton mCompatModeButton; 136 137 NotificationPanel mNotificationPanel; 138 WindowManager.LayoutParams mNotificationPanelParams; 139 NotificationPeekPanel mNotificationPeekWindow; 140 ViewGroup mNotificationPeekRow; 141 int mNotificationPeekIndex; 142 IBinder mNotificationPeekKey; 143 LayoutTransition mNotificationPeekScrubLeft, mNotificationPeekScrubRight; 144 145 int mNotificationPeekTapDuration; 146 int mNotificationFlingVelocity; 147 148 ViewGroup mPile; 149 150 HeightReceiver mHeightReceiver; 151 BatteryController mBatteryController; 152 BluetoothController mBluetoothController; 153 LocationController mLocationController; 154 NetworkController mNetworkController; 155 156 ViewGroup mBarContents; 157 LayoutTransition mBarContentsLayoutTransition; 158 159 // hide system chrome ("lights out") support 160 View mShadow; 161 162 NotificationIconArea.IconLayout mIconLayout; 163 164 TabletTicker mTicker; 165 166 View mFakeSpaceBar; 167 KeyEvent mSpaceBarKeyEvent = null; 168 169 // for disabling the status bar 170 int mDisabled = 0; 171 172 private RecentsPanelView mRecentsPanel; 173 private InputMethodsPanel mInputMethodsPanel; 174 private CompatModePanel mCompatModePanel; 175 176 public Context getContext() { return mContext; } 177 178 protected void addPanelWindows() { 179 final Context context = mContext; 180 final Resources res = mContext.getResources(); 181 182 // Notification Panel 183 mNotificationPanel = (NotificationPanel)View.inflate(context, 184 R.layout.status_bar_notification_panel, null); 185 mNotificationPanel.show(false, false); 186 mNotificationPanel.setOnTouchListener( 187 new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPanel)); 188 189 // the battery and network icons 190 mBatteryController.addIconView((ImageView)mNotificationPanel.findViewById(R.id.battery)); 191 mBatteryController.addLabelView( 192 (TextView)mNotificationPanel.findViewById(R.id.battery_text)); 193 mBluetoothController.addIconView( 194 (ImageView)mNotificationPanel.findViewById(R.id.bluetooth)); 195 mNetworkController.addCombinedSignalIconView( 196 (ImageView)mNotificationPanel.findViewById(R.id.network_signal)); 197 mNetworkController.addDataTypeIconView( 198 (ImageView)mNotificationPanel.findViewById(R.id.network_type)); 199 mNetworkController.addDataDirectionOverlayIconView( 200 (ImageView)mNotificationPanel.findViewById(R.id.network_direction)); 201 mNetworkController.addLabelView( 202 (TextView)mNotificationPanel.findViewById(R.id.network_text)); 203 mNetworkController.addLabelView( 204 (TextView)mBarContents.findViewById(R.id.network_text)); 205 206 mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel); 207 208 WindowManager.LayoutParams lp = mNotificationPanelParams = new WindowManager.LayoutParams( 209 res.getDimensionPixelSize(R.dimen.notification_panel_width), 210 getNotificationPanelHeight(), 211 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 212 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 213 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 214 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 215 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 216 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 217 PixelFormat.TRANSLUCENT); 218 lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; 219 lp.setTitle("NotificationPanel"); 220 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 221 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 222 lp.windowAnimations = com.android.internal.R.style.Animation; // == no animation 223// lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade 224 225 WindowManagerImpl.getDefault().addView(mNotificationPanel, lp); 226 227 // Notification preview window 228 mNotificationPeekWindow = (NotificationPeekPanel) View.inflate(context, 229 R.layout.status_bar_notification_peek, null); 230 mNotificationPeekWindow.setBar(this); 231 232 mNotificationPeekRow = (ViewGroup) mNotificationPeekWindow.findViewById(R.id.content); 233 mNotificationPeekWindow.setVisibility(View.GONE); 234 mNotificationPeekWindow.setOnTouchListener( 235 new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PEEK, mNotificationPeekWindow)); 236 mNotificationPeekScrubRight = new LayoutTransition(); 237 mNotificationPeekScrubRight.setAnimator(LayoutTransition.APPEARING, 238 ObjectAnimator.ofInt(null, "left", -512, 0)); 239 mNotificationPeekScrubRight.setAnimator(LayoutTransition.DISAPPEARING, 240 ObjectAnimator.ofInt(null, "left", -512, 0)); 241 mNotificationPeekScrubRight.setDuration(500); 242 243 mNotificationPeekScrubLeft = new LayoutTransition(); 244 mNotificationPeekScrubLeft.setAnimator(LayoutTransition.APPEARING, 245 ObjectAnimator.ofInt(null, "left", 512, 0)); 246 mNotificationPeekScrubLeft.setAnimator(LayoutTransition.DISAPPEARING, 247 ObjectAnimator.ofInt(null, "left", 512, 0)); 248 mNotificationPeekScrubLeft.setDuration(500); 249 250 // XXX: setIgnoreChildren? 251 lp = new WindowManager.LayoutParams( 252 512, // ViewGroup.LayoutParams.WRAP_CONTENT, 253 ViewGroup.LayoutParams.WRAP_CONTENT, 254 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 255 WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 256 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 257 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 258 PixelFormat.TRANSLUCENT); 259 lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; 260 lp.y = res.getDimensionPixelOffset(R.dimen.peek_window_y_offset); 261 lp.setTitle("NotificationPeekWindow"); 262 lp.windowAnimations = com.android.internal.R.style.Animation_Toast; 263 264 WindowManagerImpl.getDefault().addView(mNotificationPeekWindow, lp); 265 266 // Recents Panel 267 mRecentsPanel = (RecentsPanelView) View.inflate(context, 268 R.layout.status_bar_recent_panel, null); 269 mRecentsPanel.setVisibility(View.GONE); 270 mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL, 271 mRecentsPanel)); 272 mStatusBarView.setIgnoreChildren(2, mRecentButton, mRecentsPanel); 273 274 lp = new WindowManager.LayoutParams( 275 ViewGroup.LayoutParams.WRAP_CONTENT, 276 ViewGroup.LayoutParams.WRAP_CONTENT, 277 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 278 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 279 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 280 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 281 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 282 PixelFormat.TRANSLUCENT); 283 lp.gravity = Gravity.BOTTOM | Gravity.LEFT; 284 lp.setTitle("RecentsPanel"); 285 lp.windowAnimations = R.style.Animation_RecentPanel; 286 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 287 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 288 289 WindowManagerImpl.getDefault().addView(mRecentsPanel, lp); 290 mRecentsPanel.setBar(this); 291 292 // Input methods Panel 293 mInputMethodsPanel = (InputMethodsPanel) View.inflate(context, 294 R.layout.status_bar_input_methods_panel, null); 295 mInputMethodsPanel.setHardKeyboardEnabledChangeListener(this); 296 mInputMethodsPanel.setOnTouchListener(new TouchOutsideListener( 297 MSG_CLOSE_INPUT_METHODS_PANEL, mInputMethodsPanel)); 298 mInputMethodsPanel.setImeSwitchButton(mInputMethodSwitchButton); 299 mStatusBarView.setIgnoreChildren(3, mInputMethodSwitchButton, mInputMethodsPanel); 300 lp = new WindowManager.LayoutParams( 301 ViewGroup.LayoutParams.WRAP_CONTENT, 302 ViewGroup.LayoutParams.WRAP_CONTENT, 303 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 304 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 305 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 306 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 307 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 308 PixelFormat.TRANSLUCENT); 309 lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; 310 lp.setTitle("InputMethodsPanel"); 311 lp.windowAnimations = R.style.Animation_RecentPanel; 312 313 WindowManagerImpl.getDefault().addView(mInputMethodsPanel, lp); 314 315 // Compatibility mode selector panel 316 mCompatModePanel = (CompatModePanel) View.inflate(context, 317 R.layout.status_bar_compat_mode_panel, null); 318 mCompatModePanel.setOnTouchListener(new TouchOutsideListener( 319 MSG_CLOSE_COMPAT_MODE_PANEL, mCompatModePanel)); 320 mCompatModePanel.setTrigger(mCompatModeButton); 321 mCompatModePanel.setVisibility(View.GONE); 322 mStatusBarView.setIgnoreChildren(4, mCompatModeButton, mCompatModePanel); 323 lp = new WindowManager.LayoutParams( 324 250, 325 ViewGroup.LayoutParams.WRAP_CONTENT, 326 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 327 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 328 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 329 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 330 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 331 PixelFormat.TRANSLUCENT); 332 lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; 333 lp.setTitle("CompatModePanel"); 334 lp.windowAnimations = android.R.style.Animation_Dialog; 335 336 WindowManagerImpl.getDefault().addView(mCompatModePanel, lp); 337 } 338 339 private int getNotificationPanelHeight() { 340 final Resources res = mContext.getResources(); 341 final Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); 342 return Math.max(res.getDimensionPixelSize(R.dimen.notification_panel_min_height), 343 d.getRealHeight()); 344 } 345 346 @Override 347 public void start() { 348 super.start(); // will add the main bar view 349 } 350 351 @Override 352 protected void onConfigurationChanged(Configuration newConfig) { 353 loadDimens(); 354 mNotificationPanelParams.height = getNotificationPanelHeight(); 355 WindowManagerImpl.getDefault().updateViewLayout(mNotificationPanel, 356 mNotificationPanelParams); 357 } 358 359 protected void loadDimens() { 360 final Resources res = mContext.getResources(); 361 362 mNaturalBarHeight = res.getDimensionPixelSize( 363 com.android.internal.R.dimen.system_bar_height); 364 365 int newIconSize = res.getDimensionPixelSize( 366 com.android.internal.R.dimen.system_bar_icon_size); 367 int newIconHPadding = res.getDimensionPixelSize( 368 R.dimen.status_bar_icon_padding); 369 370 if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) { 371// Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding); 372 mIconHPadding = newIconHPadding; 373 mIconSize = newIconSize; 374 reloadAllNotificationIcons(); // reload the tray 375 } 376 377 final int numIcons = res.getInteger(R.integer.config_maxNotificationIcons); 378 if (numIcons != mMaxNotificationIcons) { 379 mMaxNotificationIcons = numIcons; 380 if (DEBUG) Slog.d(TAG, "max notification icons: " + mMaxNotificationIcons); 381 reloadAllNotificationIcons(); 382 } 383 } 384 385 protected View makeStatusBarView() { 386 final Context context = mContext; 387 388 mWindowManager = IWindowManager.Stub.asInterface( 389 ServiceManager.getService(Context.WINDOW_SERVICE)); 390 391 // This guy will listen for HDMI plugged broadcasts so we can resize the 392 // status bar as appropriate. 393 mHeightReceiver = new HeightReceiver(mContext); 394 mHeightReceiver.registerReceiver(); 395 loadDimens(); 396 397 final TabletStatusBarView sb = (TabletStatusBarView)View.inflate( 398 context, R.layout.status_bar, null); 399 mStatusBarView = sb; 400 401 sb.setHandler(mHandler); 402 403 mBarContents = (ViewGroup) sb.findViewById(R.id.bar_contents); 404 // layout transitions for the status bar's contents 405 mBarContentsLayoutTransition = new LayoutTransition(); 406 // add/removal will fade as normal 407 mBarContentsLayoutTransition.setAnimator(LayoutTransition.APPEARING, 408 ObjectAnimator.ofFloat(null, "alpha", 0f, 1f)); 409 mBarContentsLayoutTransition.setAnimator(LayoutTransition.DISAPPEARING, 410 ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)); 411 // no animations for siblings on change: just jump into place please 412 mBarContentsLayoutTransition.setAnimator(LayoutTransition.CHANGE_APPEARING, null); 413 mBarContentsLayoutTransition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, null); 414 // quick like bunny 415 mBarContentsLayoutTransition.setDuration(250 * (DEBUG?10:1)); 416 mBarContents.setLayoutTransition(mBarContentsLayoutTransition); 417 418 // the whole right-hand side of the bar 419 mNotificationArea = sb.findViewById(R.id.notificationArea); 420 421 // the button to open the notification area 422 mNotificationTrigger = sb.findViewById(R.id.notificationTrigger); 423 mNotificationTrigger.setOnTouchListener(new NotificationTriggerTouchListener()); 424 425 // the more notifications icon 426 mNotificationIconArea = (NotificationIconArea)sb.findViewById(R.id.notificationIcons); 427 428 // where the icons go 429 mIconLayout = (NotificationIconArea.IconLayout) sb.findViewById(R.id.icons); 430 mIconLayout.setOnTouchListener(new NotificationIconTouchListener()); 431 432 ViewConfiguration vc = ViewConfiguration.get(context); 433 mNotificationPeekTapDuration = vc.getTapTimeout(); 434 mNotificationFlingVelocity = 300; // px/s 435 436 mTicker = new TabletTicker(this); 437 438 // The icons 439 mLocationController = new LocationController(mContext); // will post a notification 440 441 mBatteryController = new BatteryController(mContext); 442 mBatteryController.addIconView((ImageView)sb.findViewById(R.id.battery)); 443 mBluetoothController = new BluetoothController(mContext); 444 mBluetoothController.addIconView((ImageView)sb.findViewById(R.id.bluetooth)); 445 mNetworkController = new NetworkController(mContext); 446 mNetworkController.addCombinedSignalIconView( 447 (ImageView)sb.findViewById(R.id.network_signal)); 448 mNetworkController.addDataTypeIconView( 449 (ImageView)sb.findViewById(R.id.network_type)); 450 mNetworkController.addDataDirectionOverlayIconView( 451 (ImageView)sb.findViewById(R.id.network_direction)); 452 453 // The navigation buttons 454 mBackButton = (ImageView)sb.findViewById(R.id.back); 455 mNavigationArea = (ViewGroup) sb.findViewById(R.id.navigationArea); 456 mHomeButton = mNavigationArea.findViewById(R.id.home); 457 mMenuButton = mNavigationArea.findViewById(R.id.menu); 458 mRecentButton = mNavigationArea.findViewById(R.id.recent_apps); 459 mRecentButton.setOnClickListener(mOnClickListener); 460 mNavigationArea.setLayoutTransition(mBarContentsLayoutTransition); 461 462 // The bar contents buttons 463 mFeedbackIconArea = (ViewGroup)sb.findViewById(R.id.feedbackIconArea); 464 mInputMethodSwitchButton = (InputMethodButton) sb.findViewById(R.id.imeSwitchButton); 465 // Overwrite the lister 466 mInputMethodSwitchButton.setOnClickListener(mOnClickListener); 467 468 mCompatModeButton = (CompatModeButton) sb.findViewById(R.id.compatModeButton); 469 mCompatModeButton.setOnClickListener(mOnClickListener); 470 471 // for redirecting errant bar taps to the IME 472 mFakeSpaceBar = sb.findViewById(R.id.fake_space_bar); 473 474 // "shadows" of the status bar features, for lights-out mode 475 mShadow = sb.findViewById(R.id.bar_shadow); 476 mShadow.setOnTouchListener( 477 new View.OnTouchListener() { 478 public boolean onTouch(View v, MotionEvent ev) { 479 if (ev.getAction() == MotionEvent.ACTION_DOWN) { 480 // even though setting the systemUI visibility below will turn these views 481 // on, we need them to come up faster so that they can catch this motion 482 // event 483 mShadow.setVisibility(View.GONE); 484 mBarContents.setVisibility(View.VISIBLE); 485 486 try { 487 mBarService.setSystemUiVisibility(View.STATUS_BAR_VISIBLE); 488 } catch (RemoteException ex) { 489 // system process dead 490 } 491 } 492 return false; 493 } 494 }); 495 496 // tuning parameters 497 final int LIGHTS_GOING_OUT_SYSBAR_DURATION = 600; 498 final int LIGHTS_GOING_OUT_SHADOW_DURATION = 1000; 499 final int LIGHTS_GOING_OUT_SHADOW_DELAY = 500; 500 501 final int LIGHTS_COMING_UP_SYSBAR_DURATION = 200; 502// final int LIGHTS_COMING_UP_SYSBAR_DELAY = 50; 503 final int LIGHTS_COMING_UP_SHADOW_DURATION = 0; 504 505 LayoutTransition xition = new LayoutTransition(); 506 xition.setAnimator(LayoutTransition.APPEARING, 507 ObjectAnimator.ofFloat(null, "alpha", 0.5f, 1f)); 508 xition.setDuration(LayoutTransition.APPEARING, LIGHTS_COMING_UP_SYSBAR_DURATION); 509 xition.setStartDelay(LayoutTransition.APPEARING, 0); 510 xition.setAnimator(LayoutTransition.DISAPPEARING, 511 ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)); 512 xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_GOING_OUT_SYSBAR_DURATION); 513 xition.setStartDelay(LayoutTransition.DISAPPEARING, 0); 514 ((ViewGroup)sb.findViewById(R.id.bar_contents_holder)).setLayoutTransition(xition); 515 516 xition = new LayoutTransition(); 517 xition.setAnimator(LayoutTransition.APPEARING, 518 ObjectAnimator.ofFloat(null, "alpha", 0f, 1f)); 519 xition.setDuration(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DURATION); 520 xition.setStartDelay(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DELAY); 521 xition.setAnimator(LayoutTransition.DISAPPEARING, 522 ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)); 523 xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_COMING_UP_SHADOW_DURATION); 524 xition.setStartDelay(LayoutTransition.DISAPPEARING, 0); 525 ((ViewGroup)sb.findViewById(R.id.bar_shadow_holder)).setLayoutTransition(xition); 526 527 // set the initial view visibility 528 setAreThereNotifications(); 529 530 // Add the windows 531 addPanelWindows(); 532 533 mPile = (ViewGroup)mNotificationPanel.findViewById(R.id.content); 534 mPile.removeAllViews(); 535 536 ScrollView scroller = (ScrollView)mPile.getParent(); 537 scroller.setFillViewport(true); 538 539 mHeightReceiver.addOnBarHeightChangedListener(this); 540 541 return sb; 542 } 543 544 public int getStatusBarHeight() { 545 return mHeightReceiver.getHeight(); 546 } 547 548 protected int getStatusBarGravity() { 549 return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL; 550 } 551 552 public void onBarHeightChanged(int height) { 553 final WindowManager.LayoutParams lp 554 = (WindowManager.LayoutParams)mStatusBarView.getLayoutParams(); 555 if (lp == null) { 556 // haven't been added yet 557 return; 558 } 559 if (lp.height != height) { 560 lp.height = height; 561 final WindowManager wm = WindowManagerImpl.getDefault(); 562 wm.updateViewLayout(mStatusBarView, lp); 563 } 564 } 565 566 private class H extends Handler { 567 public void handleMessage(Message m) { 568 switch (m.what) { 569 case MSG_OPEN_NOTIFICATION_PEEK: 570 if (DEBUG) Slog.d(TAG, "opening notification peek window; arg=" + m.arg1); 571 572 if (m.arg1 >= 0) { 573 final int N = mNotificationData.size(); 574 575 if (!mNotificationDNDMode) { 576 if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) { 577 NotificationData.Entry entry = mNotificationData.get(N-1-mNotificationPeekIndex); 578 entry.icon.setBackgroundColor(0); 579 mNotificationPeekIndex = -1; 580 mNotificationPeekKey = null; 581 } 582 } 583 584 final int peekIndex = m.arg1; 585 if (peekIndex < N) { 586 //Slog.d(TAG, "loading peek: " + peekIndex); 587 NotificationData.Entry entry = 588 mNotificationDNDMode 589 ? mNotificationDNDDummyEntry 590 : mNotificationData.get(N-1-peekIndex); 591 NotificationData.Entry copy = new NotificationData.Entry( 592 entry.key, 593 entry.notification, 594 entry.icon); 595 inflateViews(copy, mNotificationPeekRow); 596 597 if (mNotificationDNDMode) { 598 copy.content.setOnClickListener(new View.OnClickListener() { 599 public void onClick(View v) { 600 SharedPreferences.Editor editor = Prefs.edit(mContext); 601 editor.putBoolean(Prefs.DO_NOT_DISTURB_PREF, false); 602 editor.apply(); 603 animateCollapse(); 604 } 605 }); 606 } 607 608 entry.icon.setBackgroundColor(0x20FFFFFF); 609 610// mNotificationPeekRow.setLayoutTransition( 611// peekIndex < mNotificationPeekIndex 612// ? mNotificationPeekScrubLeft 613// : mNotificationPeekScrubRight); 614 615 mNotificationPeekRow.removeAllViews(); 616 mNotificationPeekRow.addView(copy.row); 617 618 mNotificationPeekWindow.setVisibility(View.VISIBLE); 619 mNotificationPanel.show(false, true); 620 621 mNotificationPeekIndex = peekIndex; 622 mNotificationPeekKey = entry.key; 623 } 624 } 625 break; 626 case MSG_CLOSE_NOTIFICATION_PEEK: 627 if (DEBUG) Slog.d(TAG, "closing notification peek window"); 628 mNotificationPeekWindow.setVisibility(View.GONE); 629 mNotificationPeekRow.removeAllViews(); 630 631 final int N = mNotificationData.size(); 632 if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) { 633 NotificationData.Entry entry = 634 mNotificationDNDMode 635 ? mNotificationDNDDummyEntry 636 : mNotificationData.get(N-1-mNotificationPeekIndex); 637 entry.icon.setBackgroundColor(0); 638 } 639 640 mNotificationPeekIndex = -1; 641 mNotificationPeekKey = null; 642 break; 643 case MSG_OPEN_NOTIFICATION_PANEL: 644 if (DEBUG) Slog.d(TAG, "opening notifications panel"); 645 if (!mNotificationPanel.isShowing()) { 646 mNotificationPeekWindow.setVisibility(View.GONE); 647 mNotificationPanel.show(true, true); 648 mNotificationArea.setVisibility(View.INVISIBLE); 649 mTicker.halt(); 650 } 651 break; 652 case MSG_CLOSE_NOTIFICATION_PANEL: 653 if (DEBUG) Slog.d(TAG, "closing notifications panel"); 654 if (mNotificationPanel.isShowing()) { 655 mNotificationPanel.show(false, true); 656 mNotificationArea.setVisibility(View.VISIBLE); 657 } 658 break; 659 case MSG_OPEN_RECENTS_PANEL: 660 if (DEBUG) Slog.d(TAG, "opening recents panel"); 661 if (mRecentsPanel != null) { 662 disable(StatusBarManager.DISABLE_BACK); 663 mRecentsPanel.setVisibility(View.VISIBLE); 664 mRecentsPanel.show(true, true); 665 } 666 break; 667 case MSG_CLOSE_RECENTS_PANEL: 668 if (DEBUG) Slog.d(TAG, "closing recents panel"); 669 if (mRecentsPanel != null && mRecentsPanel.isShowing()) { 670 disable(StatusBarManager.DISABLE_NONE); 671 mRecentsPanel.show(false, true); 672 } 673 break; 674 case MSG_OPEN_INPUT_METHODS_PANEL: 675 if (DEBUG) Slog.d(TAG, "opening input methods panel"); 676 if (mInputMethodsPanel != null) mInputMethodsPanel.openPanel(); 677 break; 678 case MSG_CLOSE_INPUT_METHODS_PANEL: 679 if (DEBUG) Slog.d(TAG, "closing input methods panel"); 680 if (mInputMethodsPanel != null) mInputMethodsPanel.closePanel(false); 681 break; 682 case MSG_OPEN_COMPAT_MODE_PANEL: 683 if (DEBUG) Slog.d(TAG, "opening compat panel"); 684 if (mCompatModePanel != null) mCompatModePanel.openPanel(); 685 break; 686 case MSG_CLOSE_COMPAT_MODE_PANEL: 687 if (DEBUG) Slog.d(TAG, "closing compat panel"); 688 if (mCompatModePanel != null) mCompatModePanel.closePanel(); 689 break; 690 case MSG_SHOW_CHROME: 691 if (DEBUG) Slog.d(TAG, "hiding shadows (lights on)"); 692 mBarContents.setVisibility(View.VISIBLE); 693 mShadow.setVisibility(View.GONE); 694 notifyLightsChanged(true); 695 break; 696 case MSG_HIDE_CHROME: 697 if (DEBUG) Slog.d(TAG, "showing shadows (lights out)"); 698 animateCollapse(); 699 mBarContents.setVisibility(View.GONE); 700 mShadow.setVisibility(View.VISIBLE); 701 notifyLightsChanged(false); 702 break; 703 case MSG_STOP_TICKER: 704 mTicker.halt(); 705 break; 706 } 707 } 708 } 709 710 private void notifyLightsChanged(boolean shown) { 711 try { 712 Slog.d(TAG, "lights " + (shown?"on":"out")); 713 mWindowManager.statusBarVisibilityChanged( 714 shown ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN); 715 } catch (RemoteException ex) { 716 } 717 } 718 719 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) { 720 if (DEBUG) Slog.d(TAG, "addIcon(" + slot + ") -> " + icon); 721 } 722 723 public void updateIcon(String slot, int index, int viewIndex, 724 StatusBarIcon old, StatusBarIcon icon) { 725 if (DEBUG) Slog.d(TAG, "updateIcon(" + slot + ") -> " + icon); 726 } 727 728 public void removeIcon(String slot, int index, int viewIndex) { 729 if (DEBUG) Slog.d(TAG, "removeIcon(" + slot + ")"); 730 } 731 732 public void addNotification(IBinder key, StatusBarNotification notification) { 733 if (DEBUG) Slog.d(TAG, "addNotification(" + key + " -> " + notification + ")"); 734 addNotificationViews(key, notification); 735 736 final boolean immersive = isImmersive(); 737 if (false && immersive) { 738 // TODO: immersive mode popups for tablet 739 } else if (notification.notification.fullScreenIntent != null) { 740 // not immersive & a full-screen alert should be shown 741 Slog.w(TAG, "Notification has fullScreenIntent and activity is not immersive;" 742 + " sending fullScreenIntent"); 743 try { 744 notification.notification.fullScreenIntent.send(); 745 } catch (PendingIntent.CanceledException e) { 746 } 747 } else { 748 tick(key, notification, true); 749 } 750 751 setAreThereNotifications(); 752 } 753 754 public void updateNotification(IBinder key, StatusBarNotification notification) { 755 if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ")"); 756 757 final NotificationData.Entry oldEntry = mNotificationData.findByKey(key); 758 if (oldEntry == null) { 759 Slog.w(TAG, "updateNotification for unknown key: " + key); 760 return; 761 } 762 763 final StatusBarNotification oldNotification = oldEntry.notification; 764 final RemoteViews oldContentView = oldNotification.notification.contentView; 765 766 final RemoteViews contentView = notification.notification.contentView; 767 768 if (DEBUG) { 769 Slog.d(TAG, "old notification: when=" + oldNotification.notification.when 770 + " ongoing=" + oldNotification.isOngoing() 771 + " expanded=" + oldEntry.expanded 772 + " contentView=" + oldContentView 773 + " rowParent=" + oldEntry.row.getParent()); 774 Slog.d(TAG, "new notification: when=" + notification.notification.when 775 + " ongoing=" + oldNotification.isOngoing() 776 + " contentView=" + contentView); 777 } 778 779 // Can we just reapply the RemoteViews in place? If when didn't change, the order 780 // didn't change. 781 boolean contentsUnchanged = oldEntry.expanded != null 782 && contentView != null && oldContentView != null 783 && contentView.getPackage() != null 784 && oldContentView.getPackage() != null 785 && oldContentView.getPackage().equals(contentView.getPackage()) 786 && oldContentView.getLayoutId() == contentView.getLayoutId(); 787 ViewGroup rowParent = (ViewGroup) oldEntry.row.getParent(); 788 boolean orderUnchanged = notification.notification.when==oldNotification.notification.when 789 && notification.priority == oldNotification.priority; 790 // priority now encompasses isOngoing() 791 boolean isLastAnyway = rowParent.indexOfChild(oldEntry.row) == rowParent.getChildCount()-1; 792 if (contentsUnchanged && (orderUnchanged || isLastAnyway)) { 793 if (DEBUG) Slog.d(TAG, "reusing notification for key: " + key); 794 oldEntry.notification = notification; 795 try { 796 // Reapply the RemoteViews 797 contentView.reapply(mContext, oldEntry.content); 798 // update the contentIntent 799 final PendingIntent contentIntent = notification.notification.contentIntent; 800 if (contentIntent != null) { 801 oldEntry.content.setOnClickListener(new NotificationClicker(contentIntent, 802 notification.pkg, notification.tag, notification.id)); 803 } else { 804 oldEntry.content.setOnClickListener(null); 805 } 806 // Update the icon. 807 final StatusBarIcon ic = new StatusBarIcon(notification.pkg, 808 notification.notification.icon, notification.notification.iconLevel, 809 notification.notification.number); 810 if (!oldEntry.icon.set(ic)) { 811 handleNotificationError(key, notification, "Couldn't update icon: " + ic); 812 return; 813 } 814 // Update the large icon 815 if (notification.notification.largeIcon != null) { 816 oldEntry.largeIcon.setImageBitmap(notification.notification.largeIcon); 817 } else { 818 oldEntry.largeIcon.getLayoutParams().width = 0; 819 oldEntry.largeIcon.setVisibility(View.INVISIBLE); 820 } 821 822 if (key == mNotificationPeekKey) { 823 // must update the peek window 824 Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK); 825 peekMsg.arg1 = mNotificationPeekIndex; 826 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 827 mHandler.sendMessage(peekMsg); 828 } 829 } 830 catch (RuntimeException e) { 831 // It failed to add cleanly. Log, and remove the view from the panel. 832 Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e); 833 removeNotificationViews(key); 834 addNotificationViews(key, notification); 835 } 836 } else { 837 if (DEBUG) Slog.d(TAG, "not reusing notification for key: " + key); 838 removeNotificationViews(key); 839 addNotificationViews(key, notification); 840 } 841 // fullScreenIntent doesn't happen on updates. You need to clear & repost a new 842 // notification. 843 final boolean immersive = isImmersive(); 844 if (false && immersive) { 845 // TODO: immersive mode 846 } else { 847 tick(key, notification, false); 848 } 849 850 setAreThereNotifications(); 851 } 852 853 public void removeNotification(IBinder key) { 854 if (DEBUG) Slog.d(TAG, "removeNotification(" + key + ")"); 855 removeNotificationViews(key); 856 mTicker.remove(key); 857 setAreThereNotifications(); 858 } 859 860 public void showClock(boolean show) { 861 View clock = mBarContents.findViewById(R.id.clock); 862 View network_text = mBarContents.findViewById(R.id.network_text); 863 if (clock != null) { 864 clock.setVisibility(show ? View.VISIBLE : View.GONE); 865 } 866 if (network_text != null) { 867 network_text.setVisibility((!show) ? View.VISIBLE : View.GONE); 868 } 869 } 870 871 public void disable(int state) { 872 int old = mDisabled; 873 int diff = state ^ old; 874 mDisabled = state; 875 876 // act accordingly 877 if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) { 878 boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0; 879 Slog.i(TAG, "DISABLE_CLOCK: " + (show ? "no" : "yes")); 880 showClock(show); 881 } 882 if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { 883 boolean show = (state & StatusBarManager.DISABLE_SYSTEM_INFO) == 0; 884 Slog.i(TAG, "DISABLE_SYSTEM_INFO: " + (show ? "no" : "yes")); 885 mNotificationTrigger.setVisibility(show ? View.VISIBLE : View.GONE); 886 } 887 if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { 888 if ((state & StatusBarManager.DISABLE_EXPAND) != 0) { 889 Slog.i(TAG, "DISABLE_EXPAND: yes"); 890 animateCollapse(); 891 } 892 } 893 if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 894 mNotificationDNDMode = Prefs.read(mContext) 895 .getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT); 896 897 if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 898 Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: yes" + (mNotificationDNDMode?" (DND)":"")); 899 mTicker.halt(); 900 } else { 901 Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: no" + (mNotificationDNDMode?" (DND)":"")); 902 } 903 904 // refresh icons to show either notifications or the DND message 905 reloadAllNotificationIcons(); 906 } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 907 if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 908 mTicker.halt(); 909 } 910 } 911 if ((diff & StatusBarManager.DISABLE_NAVIGATION) != 0) { 912 if ((state & StatusBarManager.DISABLE_NAVIGATION) != 0) { 913 Slog.i(TAG, "DISABLE_NAVIGATION: yes"); 914 mNavigationArea.setVisibility(View.INVISIBLE); 915 mInputMethodSwitchButton.setScreenLocked(true); 916 } else { 917 Slog.i(TAG, "DISABLE_NAVIGATION: no"); 918 mNavigationArea.setVisibility(View.VISIBLE); 919 mInputMethodSwitchButton.setScreenLocked(false); 920 } 921 } 922 if ((diff & StatusBarManager.DISABLE_BACK) != 0) { 923 if ((state & StatusBarManager.DISABLE_BACK) != 0) { 924 Slog.i(TAG, "DISABLE_BACK: yes"); 925 mBackButton.setVisibility(View.INVISIBLE); 926 mInputMethodSwitchButton.setScreenLocked(true); 927 } else { 928 Slog.i(TAG, "DISABLE_BACK: no"); 929 mBackButton.setVisibility(View.VISIBLE); 930 mInputMethodSwitchButton.setScreenLocked(false); 931 } 932 } 933 934 } 935 936 private boolean hasTicker(Notification n) { 937 return n.tickerView != null || !TextUtils.isEmpty(n.tickerText); 938 } 939 940 private void tick(IBinder key, StatusBarNotification n, boolean firstTime) { 941 // Don't show the ticker when the windowshade is open. 942 if (mNotificationPanel.isShowing()) { 943 return; 944 } 945 // If they asked for FLAG_ONLY_ALERT_ONCE, then only show this notification 946 // if it's a new notification. 947 if (!firstTime && (n.notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0) { 948 return; 949 } 950 // Show the ticker if one is requested. Also don't do this 951 // until status bar window is attached to the window manager, 952 // because... well, what's the point otherwise? And trying to 953 // run a ticker without being attached will crash! 954 if (hasTicker(n.notification) && mStatusBarView.getWindowToken() != null) { 955 if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS 956 | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { 957 mTicker.add(key, n); 958 mFeedbackIconArea.setVisibility(View.GONE); 959 } 960 } 961 } 962 963 // called by TabletTicker when it's done with all queued ticks 964 public void doneTicking() { 965 mFeedbackIconArea.setVisibility(View.VISIBLE); 966 } 967 968 public void animateExpand() { 969 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK); 970 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 971 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 972 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); 973 mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); 974 } 975 976 public void animateCollapse() { 977 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PANEL); 978 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL); 979 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); 980 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); 981 mHandler.removeMessages(MSG_CLOSE_INPUT_METHODS_PANEL); 982 mHandler.sendEmptyMessage(MSG_CLOSE_INPUT_METHODS_PANEL); 983 mHandler.removeMessages(MSG_CLOSE_COMPAT_MODE_PANEL); 984 mHandler.sendEmptyMessage(MSG_CLOSE_COMPAT_MODE_PANEL); 985 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK); 986 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 987 } 988 989 // called by StatusBar 990 @Override 991 public void setLightsOn(boolean on) { 992 // Policy note: if the frontmost activity needs the menu key, we assume it is a legacy app 993 // that can't handle lights-out mode. 994 if (mMenuButton.getVisibility() == View.VISIBLE) { 995 on = true; 996 } 997 mHandler.removeMessages(MSG_HIDE_CHROME); 998 mHandler.removeMessages(MSG_SHOW_CHROME); 999 mHandler.sendEmptyMessage(on ? MSG_SHOW_CHROME : MSG_HIDE_CHROME); 1000 } 1001 1002 public void topAppWindowChanged(boolean windowVisible) { 1003 if (DEBUG) { 1004 Slog.d(TAG, (windowVisible?"showing":"hiding") + " the MENU button"); 1005 } 1006 mMenuButton.setVisibility(windowVisible ? View.VISIBLE : View.GONE); 1007 1008 // See above re: lights-out policy for legacy apps. 1009 if (windowVisible) setLightsOn(true); 1010 1011 mCompatModeButton.refresh(); 1012 if (mCompatModeButton.getVisibility() == View.VISIBLE) { 1013 if (! Prefs.read(mContext).getBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, false)) { 1014 showCompatibilityHelp(); 1015 } 1016 } 1017 } 1018 1019 private void showCompatibilityHelp() { 1020 final View dlg = View.inflate(mContext, R.layout.compat_mode_help, null); 1021 View button = dlg.findViewById(R.id.button); 1022 1023 button.setOnClickListener(new View.OnClickListener() { 1024 @Override 1025 public void onClick(View v) { 1026 WindowManagerImpl.getDefault().removeView(dlg); 1027 } 1028 }); 1029 1030 WindowManager.LayoutParams lp = mNotificationPanelParams = new WindowManager.LayoutParams( 1031 ViewGroup.LayoutParams.MATCH_PARENT, 1032 ViewGroup.LayoutParams.MATCH_PARENT, 1033 WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG, 1034 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 1035 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 1036 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 1037 PixelFormat.TRANSLUCENT); 1038 lp.setTitle("CompatibilityModeDialog"); 1039 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 1040 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 1041 lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade 1042 1043 WindowManagerImpl.getDefault().addView(dlg, lp); 1044 1045 SharedPreferences.Editor editor = Prefs.edit(mContext); 1046 editor.putBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, true); 1047 editor.apply(); 1048 } 1049 1050 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { 1051 mInputMethodSwitchButton.setImeWindowStatus(token, 1052 (vis & InputMethodService.IME_ACTIVE) != 0); 1053 updateNotificationIcons(); 1054 mInputMethodsPanel.setImeToken(token); 1055 int res; 1056 switch (backDisposition) { 1057 case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: 1058 res = R.drawable.ic_sysbar_back; 1059 break; 1060 case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: 1061 res = R.drawable.ic_sysbar_back_ime; 1062 break; 1063 case InputMethodService.BACK_DISPOSITION_DEFAULT: 1064 default: 1065 if ((vis & InputMethodService.IME_VISIBLE) != 0) { 1066 res = R.drawable.ic_sysbar_back_ime; 1067 } else { 1068 res = R.drawable.ic_sysbar_back; 1069 } 1070 break; 1071 } 1072 mBackButton.setImageResource(res); 1073 if (FAKE_SPACE_BAR) { 1074 mFakeSpaceBar.setVisibility(((vis & InputMethodService.IME_VISIBLE) != 0) 1075 ? View.VISIBLE : View.GONE); 1076 } 1077 } 1078 1079 @Override 1080 public void setHardKeyboardStatus(boolean available, boolean enabled) { 1081 if (DEBUG) { 1082 Slog.d(TAG, "Set hard keyboard status: available=" + available 1083 + ", enabled=" + enabled); 1084 } 1085 mInputMethodSwitchButton.setHardKeyboardStatus(available); 1086 updateNotificationIcons(); 1087 mInputMethodsPanel.setHardKeyboardStatus(available, enabled); 1088 } 1089 1090 @Override 1091 public void onHardKeyboardEnabledChange(boolean enabled) { 1092 try { 1093 mBarService.setHardKeyboardEnabled(enabled); 1094 } catch (RemoteException ex) { 1095 } 1096 } 1097 1098 private boolean isImmersive() { 1099 try { 1100 return ActivityManagerNative.getDefault().isTopActivityImmersive(); 1101 //Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); 1102 } catch (RemoteException ex) { 1103 // the end is nigh 1104 return false; 1105 } 1106 } 1107 1108 private void setAreThereNotifications() { 1109 final boolean hasClearable = mNotificationData.hasClearableItems(); 1110 } 1111 1112 /** 1113 * Cancel this notification and tell the status bar service about the failure. Hold no locks. 1114 */ 1115 void handleNotificationError(IBinder key, StatusBarNotification n, String message) { 1116 removeNotification(key); 1117 try { 1118 mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message); 1119 } catch (RemoteException ex) { 1120 // The end is nigh. 1121 } 1122 } 1123 1124 private void sendKey(KeyEvent key) { 1125 try { 1126 if (DEBUG) Slog.d(TAG, "injecting key event: " + key); 1127 mWindowManager.injectInputEventNoWait(key); 1128 } catch (RemoteException ex) { 1129 } 1130 } 1131 1132 private View.OnClickListener mOnClickListener = new View.OnClickListener() { 1133 public void onClick(View v) { 1134 if (v == mNotificationTrigger) { 1135 onClickNotificationTrigger(); 1136 } else if (v == mRecentButton) { 1137 onClickRecentButton(); 1138 } else if (v == mInputMethodSwitchButton) { 1139 onClickInputMethodSwitchButton(); 1140 } else if (v == mCompatModeButton) { 1141 onClickCompatModeButton(); 1142 } 1143 } 1144 }; 1145 1146 public void onClickNotificationTrigger() { 1147 if (DEBUG) Slog.d(TAG, "clicked notification icons; disabled=" + mDisabled); 1148 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { 1149 int msg = !mNotificationPanel.isShowing() 1150 ? MSG_OPEN_NOTIFICATION_PANEL 1151 : MSG_CLOSE_NOTIFICATION_PANEL; 1152 mHandler.removeMessages(msg); 1153 mHandler.sendEmptyMessage(msg); 1154 } 1155 } 1156 1157 public void onClickRecentButton() { 1158 if (DEBUG) Slog.d(TAG, "clicked recent apps; disabled=" + mDisabled); 1159 if (mRecentsPanel == null) { 1160 Intent intent = new Intent(); 1161 intent.setClass(mContext, RecentApplicationsActivity.class); 1162 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 1163 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 1164 mContext.startActivity(intent); 1165 } else { 1166 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { 1167 int msg = (mRecentsPanel.getVisibility() == View.GONE) 1168 ? MSG_OPEN_RECENTS_PANEL 1169 : MSG_CLOSE_RECENTS_PANEL; 1170 mHandler.removeMessages(msg); 1171 mHandler.sendEmptyMessage(msg); 1172 } 1173 } 1174 } 1175 1176 public void onClickInputMethodSwitchButton() { 1177 if (DEBUG) Slog.d(TAG, "clicked input methods panel; disabled=" + mDisabled); 1178 int msg = (mInputMethodsPanel.getVisibility() == View.GONE) ? 1179 MSG_OPEN_INPUT_METHODS_PANEL : MSG_CLOSE_INPUT_METHODS_PANEL; 1180 mHandler.removeMessages(msg); 1181 mHandler.sendEmptyMessage(msg); 1182 } 1183 1184 public void onClickCompatModeButton() { 1185 int msg = (mCompatModePanel.getVisibility() == View.GONE) ? 1186 MSG_OPEN_COMPAT_MODE_PANEL : MSG_CLOSE_COMPAT_MODE_PANEL; 1187 mHandler.removeMessages(msg); 1188 mHandler.sendEmptyMessage(msg); 1189 } 1190 1191 public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag, int id) { 1192 return new NotificationClicker(intent, pkg, tag, id); 1193 } 1194 1195 private class NotificationClicker implements View.OnClickListener { 1196 private PendingIntent mIntent; 1197 private String mPkg; 1198 private String mTag; 1199 private int mId; 1200 1201 NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { 1202 mIntent = intent; 1203 mPkg = pkg; 1204 mTag = tag; 1205 mId = id; 1206 } 1207 1208 public void onClick(View v) { 1209 try { 1210 // The intent we are sending is for the application, which 1211 // won't have permission to immediately start an activity after 1212 // the user switches to home. We know it is safe to do at this 1213 // point, so make sure new activity switches are now allowed. 1214 ActivityManagerNative.getDefault().resumeAppSwitches(); 1215 } catch (RemoteException e) { 1216 } 1217 1218 if (mIntent != null) { 1219 int[] pos = new int[2]; 1220 v.getLocationOnScreen(pos); 1221 Intent overlay = new Intent(); 1222 overlay.setSourceBounds( 1223 new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); 1224 try { 1225 mIntent.send(mContext, 0, overlay); 1226 } catch (PendingIntent.CanceledException e) { 1227 // the stack trace isn't very helpful here. Just log the exception message. 1228 Slog.w(TAG, "Sending contentIntent failed: " + e); 1229 } 1230 } 1231 1232 try { 1233 mBarService.onNotificationClick(mPkg, mTag, mId); 1234 } catch (RemoteException ex) { 1235 // system process is dead if we're here. 1236 } 1237 1238 // close the shade if it was open 1239 animateCollapse(); 1240 1241 // If this click was on the intruder alert, hide that instead 1242// mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); 1243 } 1244 } 1245 1246 StatusBarNotification removeNotificationViews(IBinder key) { 1247 NotificationData.Entry entry = mNotificationData.remove(key); 1248 if (entry == null) { 1249 Slog.w(TAG, "removeNotification for unknown key: " + key); 1250 return null; 1251 } 1252 // Remove the expanded view. 1253 ViewGroup rowParent = (ViewGroup)entry.row.getParent(); 1254 if (rowParent != null) rowParent.removeView(entry.row); 1255 1256 if (key == mNotificationPeekKey) { 1257 // must close the peek as well, since it's gone 1258 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 1259 } 1260 // Remove the icon. 1261// ViewGroup iconParent = (ViewGroup)entry.icon.getParent(); 1262// if (iconParent != null) iconParent.removeView(entry.icon); 1263 updateNotificationIcons(); 1264 1265 return entry.notification; 1266 } 1267 1268 private class NotificationTriggerTouchListener implements View.OnTouchListener { 1269 VelocityTracker mVT; 1270 float mInitialTouchX, mInitialTouchY; 1271 int mTouchSlop; 1272 1273 public NotificationTriggerTouchListener() { 1274 mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); 1275 } 1276 1277 public boolean onTouch(View v, MotionEvent event) { 1278// Slog.d(TAG, String.format("touch: (%.1f, %.1f) initial: (%.1f, %.1f)", 1279// event.getX(), 1280// event.getY(), 1281// mInitialTouchX, 1282// mInitialTouchY)); 1283 final int action = event.getAction(); 1284 switch (action) { 1285 case MotionEvent.ACTION_DOWN: 1286 mVT = VelocityTracker.obtain(); 1287 mInitialTouchX = event.getX(); 1288 mInitialTouchY = event.getY(); 1289 // fall through 1290 case MotionEvent.ACTION_OUTSIDE: 1291 case MotionEvent.ACTION_MOVE: 1292 // check for fling 1293 if (mVT != null) { 1294 mVT.addMovement(event); 1295 mVT.computeCurrentVelocity(1000); // pixels per second 1296 // require a little more oomph once we're already in peekaboo mode 1297 if (mVT.getYVelocity() < -mNotificationFlingVelocity) { 1298 animateExpand(); 1299 mVT.recycle(); 1300 mVT = null; 1301 } 1302 } 1303 return true; 1304 case MotionEvent.ACTION_UP: 1305 case MotionEvent.ACTION_CANCEL: 1306 if (mVT != null) { 1307 if (action == MotionEvent.ACTION_UP 1308 // was this a sloppy tap? 1309 && Math.abs(event.getX() - mInitialTouchX) < mTouchSlop 1310 && Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3) 1311 // dragging off the bottom doesn't count 1312 && (int)event.getY() < v.getBottom()) { 1313 animateExpand(); 1314 v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); 1315 v.playSoundEffect(SoundEffectConstants.CLICK); 1316 } 1317 1318 mVT.recycle(); 1319 mVT = null; 1320 return true; 1321 } 1322 } 1323 return false; 1324 } 1325 } 1326 1327 final static int NOTIFICATION_PEEK_HOLD_THRESH = 200; // ms 1328 final static int NOTIFICATION_PEEK_FADE_DELAY = 3000; // ms 1329 1330 public void resetNotificationPeekFadeTimer() { 1331 if (DEBUG) { 1332 Slog.d(TAG, "setting peek fade timer for " + NOTIFICATION_PEEK_FADE_DELAY 1333 + "ms from now"); 1334 } 1335 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK); 1336 mHandler.sendEmptyMessageDelayed(MSG_CLOSE_NOTIFICATION_PEEK, 1337 NOTIFICATION_PEEK_FADE_DELAY); 1338 } 1339 1340 private class NotificationIconTouchListener implements View.OnTouchListener { 1341 VelocityTracker mVT; 1342 int mPeekIndex; 1343 float mInitialTouchX, mInitialTouchY; 1344 int mTouchSlop; 1345 1346 public NotificationIconTouchListener() { 1347 mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); 1348 } 1349 1350 public boolean onTouch(View v, MotionEvent event) { 1351 boolean peeking = mNotificationPeekWindow.getVisibility() != View.GONE; 1352 boolean panelShowing = mNotificationPanel.isShowing(); 1353 if (panelShowing) return false; 1354 1355 int numIcons = mIconLayout.getChildCount(); 1356 int newPeekIndex = (int)(event.getX() * numIcons / mIconLayout.getWidth()); 1357 if (newPeekIndex > numIcons - 1) newPeekIndex = numIcons - 1; 1358 else if (newPeekIndex < 0) newPeekIndex = 0; 1359 1360 final int action = event.getAction(); 1361 switch (action) { 1362 case MotionEvent.ACTION_DOWN: 1363 mVT = VelocityTracker.obtain(); 1364 mInitialTouchX = event.getX(); 1365 mInitialTouchY = event.getY(); 1366 mPeekIndex = -1; 1367 1368 // fall through 1369 case MotionEvent.ACTION_OUTSIDE: 1370 case MotionEvent.ACTION_MOVE: 1371 // peek and switch icons if necessary 1372 1373 if (newPeekIndex != mPeekIndex) { 1374 mPeekIndex = newPeekIndex; 1375 1376 if (DEBUG) Slog.d(TAG, "will peek at notification #" + mPeekIndex); 1377 Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK); 1378 peekMsg.arg1 = mPeekIndex; 1379 1380 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1381 1382 if (peeking) { 1383 // no delay if we're scrubbing left-right 1384 mHandler.sendMessage(peekMsg); 1385 } else { 1386 // wait for fling 1387 mHandler.sendMessageDelayed(peekMsg, NOTIFICATION_PEEK_HOLD_THRESH); 1388 } 1389 } 1390 1391 // check for fling 1392 if (mVT != null) { 1393 mVT.addMovement(event); 1394 mVT.computeCurrentVelocity(1000); // pixels per second 1395 // require a little more oomph once we're already in peekaboo mode 1396 if (!panelShowing && ( 1397 (peeking && mVT.getYVelocity() < -mNotificationFlingVelocity*3) 1398 || (mVT.getYVelocity() < -mNotificationFlingVelocity))) { 1399 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1400 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); 1401 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 1402 mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); 1403 } 1404 } 1405 return true; 1406 case MotionEvent.ACTION_UP: 1407 case MotionEvent.ACTION_CANCEL: 1408 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1409 if (!peeking) { 1410 if (action == MotionEvent.ACTION_UP 1411 // was this a sloppy tap? 1412 && Math.abs(event.getX() - mInitialTouchX) < mTouchSlop 1413 && Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3) 1414 // dragging off the bottom doesn't count 1415 && (int)event.getY() < v.getBottom()) { 1416 Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK); 1417 peekMsg.arg1 = mPeekIndex; 1418 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1419 mHandler.sendMessage(peekMsg); 1420 1421 v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); 1422 v.playSoundEffect(SoundEffectConstants.CLICK); 1423 1424 peeking = true; // not technically true yet, but the next line will run 1425 } 1426 } 1427 1428 if (peeking) { 1429 resetNotificationPeekFadeTimer(); 1430 } 1431 1432 mVT.recycle(); 1433 mVT = null; 1434 return true; 1435 } 1436 return false; 1437 } 1438 } 1439 1440 StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) { 1441 if (DEBUG) { 1442 Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification); 1443 } 1444 // Construct the icon. 1445 final StatusBarIconView iconView = new StatusBarIconView(mContext, 1446 notification.pkg + "/0x" + Integer.toHexString(notification.id)); 1447 iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 1448 1449 final StatusBarIcon ic = new StatusBarIcon(notification.pkg, 1450 notification.notification.icon, 1451 notification.notification.iconLevel, 1452 notification.notification.number); 1453 if (!iconView.set(ic)) { 1454 handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic); 1455 return null; 1456 } 1457 // Construct the expanded view. 1458 NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView); 1459 if (!inflateViews(entry, mPile)) { 1460 handleNotificationError(key, notification, "Couldn't expand RemoteViews for: " 1461 + notification); 1462 return null; 1463 } 1464 1465 // Add the icon. 1466 int pos = mNotificationData.add(entry); 1467 if (DEBUG) { 1468 Slog.d(TAG, "addNotificationViews: added at " + pos); 1469 } 1470 updateNotificationIcons(); 1471 1472 return iconView; 1473 } 1474 1475 private void reloadAllNotificationIcons() { 1476 if (mIconLayout == null) return; 1477 mIconLayout.removeAllViews(); 1478 updateNotificationIcons(); 1479 } 1480 1481 private void updateNotificationIcons() { 1482 // XXX: need to implement a new limited linear layout class 1483 // to avoid removing & readding everything 1484 1485 if (mIconLayout == null) return; 1486 1487 // first, populate the main notification panel 1488 loadNotificationPanel(); 1489 1490 final LinearLayout.LayoutParams params 1491 = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight); 1492 1493 // alternate behavior in DND mode 1494 if (mNotificationDNDMode) { 1495 if (mIconLayout.getChildCount() == 0) { 1496 final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd"); 1497 iconView.setImageResource(R.drawable.ic_notification_dnd); 1498 iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 1499 iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0); 1500 1501 final Notification dndNotification = new Notification.Builder(mContext) 1502 .setContentTitle(mContext.getText(R.string.notifications_off_title)) 1503 .setContentText(mContext.getText(R.string.notifications_off_text)) 1504 .setSmallIcon(R.drawable.ic_notification_dnd) 1505 .setOngoing(true) 1506 .getNotification(); 1507 1508 mNotificationDNDDummyEntry = new NotificationData.Entry( 1509 null, 1510 new StatusBarNotification("", 0, "", 0, 0, dndNotification), 1511 iconView); 1512 1513 mIconLayout.addView(iconView, params); 1514 } 1515 1516 return; 1517 } 1518 1519 int N = mNotificationData.size(); 1520 1521 if (DEBUG) { 1522 Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout); 1523 } 1524 1525 ArrayList<View> toShow = new ArrayList<View>(); 1526 1527 // Extra Special Icons 1528 // The IME switcher and compatibility mode icons take the place of notifications. You didn't 1529 // need to see all those new emails, did you? 1530 int maxNotificationIconsCount = mMaxNotificationIcons; 1531 if (mInputMethodSwitchButton.getVisibility() != View.GONE) maxNotificationIconsCount --; 1532 if (mCompatModeButton.getVisibility() != View.GONE) maxNotificationIconsCount --; 1533 1534 for (int i=0; i< maxNotificationIconsCount; i++) { 1535 if (i>=N) break; 1536 toShow.add(mNotificationData.get(N-i-1).icon); 1537 } 1538 1539 ArrayList<View> toRemove = new ArrayList<View>(); 1540 for (int i=0; i<mIconLayout.getChildCount(); i++) { 1541 View child = mIconLayout.getChildAt(i); 1542 if (!toShow.contains(child)) { 1543 toRemove.add(child); 1544 } 1545 } 1546 1547 for (View remove : toRemove) { 1548 mIconLayout.removeView(remove); 1549 } 1550 1551 for (int i=0; i<toShow.size(); i++) { 1552 View v = toShow.get(i); 1553 v.setPadding(mIconHPadding, 0, mIconHPadding, 0); 1554 if (v.getParent() == null) { 1555 mIconLayout.addView(v, i, params); 1556 } 1557 } 1558 } 1559 1560 private void loadNotificationPanel() { 1561 int N = mNotificationData.size(); 1562 1563 ArrayList<View> toShow = new ArrayList<View>(); 1564 1565 for (int i=0; i<N; i++) { 1566 View row = mNotificationData.get(N-i-1).row; 1567 toShow.add(row); 1568 } 1569 1570 ArrayList<View> toRemove = new ArrayList<View>(); 1571 for (int i=0; i<mPile.getChildCount(); i++) { 1572 View child = mPile.getChildAt(i); 1573 if (!toShow.contains(child)) { 1574 toRemove.add(child); 1575 } 1576 } 1577 1578 for (View remove : toRemove) { 1579 mPile.removeView(remove); 1580 } 1581 1582 for (int i=0; i<toShow.size(); i++) { 1583 View v = toShow.get(i); 1584 if (v.getParent() == null) { 1585 mPile.addView(v, N-1-i); // the notification panel has newest at the bottom 1586 } 1587 } 1588 1589 mNotificationPanel.setNotificationCount(N); 1590 } 1591 1592 void workAroundBadLayerDrawableOpacity(View v) { 1593 LayerDrawable d = (LayerDrawable)v.getBackground(); 1594 if (d == null) return; 1595 v.setBackgroundDrawable(null); 1596 d.setOpacity(PixelFormat.TRANSLUCENT); 1597 v.setBackgroundDrawable(d); 1598 } 1599 1600 private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) { 1601 StatusBarNotification sbn = entry.notification; 1602 RemoteViews remoteViews = sbn.notification.contentView; 1603 if (remoteViews == null) { 1604 return false; 1605 } 1606 1607 // create the row view 1608 LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( 1609 Context.LAYOUT_INFLATER_SERVICE); 1610 View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false); 1611 workAroundBadLayerDrawableOpacity(row); 1612 View vetoButton = row.findViewById(R.id.veto); 1613 if (entry.notification.isClearable()) { 1614 final String _pkg = sbn.pkg; 1615 final String _tag = sbn.tag; 1616 final int _id = sbn.id; 1617 vetoButton.setOnClickListener(new View.OnClickListener() { 1618 public void onClick(View v) { 1619 try { 1620 mBarService.onNotificationClear(_pkg, _tag, _id); 1621 } catch (RemoteException ex) { 1622 // system process is dead if we're here. 1623 } 1624 } 1625 }); 1626 } else { 1627 if ((sbn.notification.flags & Notification.FLAG_ONGOING_EVENT) == 0) { 1628 vetoButton.setVisibility(View.INVISIBLE); 1629 } else { 1630 vetoButton.setVisibility(View.GONE); 1631 } 1632 } 1633 1634 // the large icon 1635 ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon); 1636 if (sbn.notification.largeIcon != null) { 1637 largeIcon.setImageBitmap(sbn.notification.largeIcon); 1638 } else { 1639 largeIcon.getLayoutParams().width = 0; 1640 largeIcon.setVisibility(View.INVISIBLE); 1641 } 1642 1643 // bind the click event to the content area 1644 ViewGroup content = (ViewGroup)row.findViewById(R.id.content); 1645 // XXX: update to allow controls within notification views 1646 content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 1647// content.setOnFocusChangeListener(mFocusChangeListener); 1648 PendingIntent contentIntent = sbn.notification.contentIntent; 1649 if (contentIntent != null) { 1650 content.setOnClickListener(new NotificationClicker(contentIntent, 1651 sbn.pkg, sbn.tag, sbn.id)); 1652 } else { 1653 content.setOnClickListener(null); 1654 } 1655 1656 View expanded = null; 1657 Exception exception = null; 1658 try { 1659 expanded = remoteViews.apply(mContext, content); 1660 } 1661 catch (RuntimeException e) { 1662 exception = e; 1663 } 1664 if (expanded == null) { 1665 final String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id); 1666 Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); 1667 return false; 1668 } else { 1669 content.addView(expanded); 1670 row.setDrawingCacheEnabled(true); 1671 } 1672 1673 entry.row = row; 1674 entry.content = content; 1675 entry.expanded = expanded; 1676 entry.largeIcon = largeIcon; 1677 1678 return true; 1679 } 1680 1681 public void userActivity() { 1682 } 1683 1684 public class TouchOutsideListener implements View.OnTouchListener { 1685 private int mMsg; 1686 private StatusBarPanel mPanel; 1687 1688 public TouchOutsideListener(int msg, StatusBarPanel panel) { 1689 mMsg = msg; 1690 mPanel = panel; 1691 } 1692 1693 public boolean onTouch(View v, MotionEvent ev) { 1694 final int action = ev.getAction(); 1695 if (action == MotionEvent.ACTION_OUTSIDE 1696 || (action == MotionEvent.ACTION_DOWN 1697 && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) { 1698 mHandler.removeMessages(mMsg); 1699 mHandler.sendEmptyMessage(mMsg); 1700 return true; 1701 } 1702 return false; 1703 } 1704 } 1705 1706 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 1707 pw.print("mDisabled=0x"); 1708 pw.println(Integer.toHexString(mDisabled)); 1709 pw.println("mNetworkController:"); 1710 mNetworkController.dump(fd, pw, args); 1711 } 1712} 1713 1714 1715