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