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