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