TabletStatusBar.java revision c803422bed63f24e987294dae974d81342fb5189
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 // The height of the bar, as definied by the build. It may be taller if we're plugged 107 // into hdmi. 108 int mNaturalBarHeight = -1; 109 int mIconSize = -1; 110 int mIconHPadding = -1; 111 private int mMaxNotificationIcons = 5; 112 113 H mHandler = new H(); 114 115 IWindowManager mWindowManager; 116 117 // tracking all current notifications 118 private NotificationData mNotificationData = new NotificationData(); 119 120 TabletStatusBarView mStatusBarView; 121 View mNotificationArea; 122 View mNotificationTrigger; 123 NotificationIconArea mNotificationIconArea; 124 ViewGroup mNavigationArea; 125 126 boolean mNotificationDNDMode; 127 NotificationData.Entry mNotificationDNDDummyEntry; 128 129 ImageView mBackButton; 130 View mHomeButton; 131 View mMenuButton; 132 View mRecentButton; 133 134 ViewGroup mFeedbackIconArea; // notification icons, IME icon, compat icon 135 InputMethodButton mInputMethodSwitchButton; 136 CompatModeButton mCompatModeButton; 137 138 NotificationPanel mNotificationPanel; 139 WindowManager.LayoutParams mNotificationPanelParams; 140 NotificationPeekPanel mNotificationPeekWindow; 141 ViewGroup mNotificationPeekRow; 142 int mNotificationPeekIndex; 143 IBinder mNotificationPeekKey; 144 LayoutTransition mNotificationPeekScrubLeft, mNotificationPeekScrubRight; 145 146 int mNotificationPeekTapDuration; 147 int mNotificationFlingVelocity; 148 149 ViewGroup mPile; 150 151 HeightReceiver mHeightReceiver; 152 BatteryController mBatteryController; 153 BluetoothController mBluetoothController; 154 LocationController mLocationController; 155 NetworkController mNetworkController; 156 157 ViewGroup mBarContents; 158 LayoutTransition mBarContentsLayoutTransition; 159 160 // hide system chrome ("lights out") support 161 View mShadow; 162 163 NotificationIconArea.IconLayout mIconLayout; 164 165 TabletTicker mTicker; 166 167 View mFakeSpaceBar; 168 KeyEvent mSpaceBarKeyEvent = null; 169 170 View mCompatibilityHelpDialog = null; 171 172 // for disabling the status bar 173 int mDisabled = 0; 174 175 private RecentsPanelView mRecentsPanel; 176 private InputMethodsPanel mInputMethodsPanel; 177 private CompatModePanel mCompatModePanel; 178 179 int mSystemUiVisibility = 0; 180 181 public Context getContext() { return mContext; } 182 183 protected void addPanelWindows() { 184 final Context context = mContext; 185 final Resources res = mContext.getResources(); 186 187 // Notification Panel 188 mNotificationPanel = (NotificationPanel)View.inflate(context, 189 R.layout.status_bar_notification_panel, null); 190 mNotificationPanel.setBar(this); 191 mNotificationPanel.show(false, false); 192 mNotificationPanel.setOnTouchListener( 193 new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPanel)); 194 195 // the battery icon 196 mBatteryController.addIconView((ImageView)mNotificationPanel.findViewById(R.id.battery)); 197 mBatteryController.addLabelView( 198 (TextView)mNotificationPanel.findViewById(R.id.battery_text)); 199 200 // Bt 201 mBluetoothController.addIconView( 202 (ImageView)mNotificationPanel.findViewById(R.id.bluetooth)); 203 204 // network icons: either a combo icon that switches between mobile and data, or distinct 205 // mobile and data icons 206 final ImageView comboRSSI = 207 (ImageView)mNotificationPanel.findViewById(R.id.network_signal); 208 if (comboRSSI != null) { 209 mNetworkController.addCombinedSignalIconView(comboRSSI); 210 } 211 final ImageView mobileRSSI = 212 (ImageView)mNotificationPanel.findViewById(R.id.mobile_signal); 213 if (mobileRSSI != null) { 214 mNetworkController.addPhoneSignalIconView(mobileRSSI); 215 } 216 final ImageView wifiRSSI = 217 (ImageView)mNotificationPanel.findViewById(R.id.wifi_signal); 218 if (wifiRSSI != null) { 219 mNetworkController.addWifiIconView(wifiRSSI); 220 } 221 222 mNetworkController.addDataTypeIconView( 223 (ImageView)mNotificationPanel.findViewById(R.id.network_type)); 224 mNetworkController.addDataDirectionOverlayIconView( 225 (ImageView)mNotificationPanel.findViewById(R.id.network_direction)); 226 mNetworkController.addLabelView( 227 (TextView)mNotificationPanel.findViewById(R.id.network_text)); 228 mNetworkController.addLabelView( 229 (TextView)mBarContents.findViewById(R.id.network_text)); 230 231 mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel); 232 233 WindowManager.LayoutParams lp = mNotificationPanelParams = new WindowManager.LayoutParams( 234 res.getDimensionPixelSize(R.dimen.notification_panel_width), 235 getNotificationPanelHeight(), 236 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 237 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 238 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 239 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 240 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 241 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 242 PixelFormat.TRANSLUCENT); 243 lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; 244 lp.setTitle("NotificationPanel"); 245 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 246 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 247 lp.windowAnimations = com.android.internal.R.style.Animation; // == no animation 248// lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade 249 250 WindowManagerImpl.getDefault().addView(mNotificationPanel, lp); 251 252 // Notification preview window 253 mNotificationPeekWindow = (NotificationPeekPanel) View.inflate(context, 254 R.layout.status_bar_notification_peek, null); 255 mNotificationPeekWindow.setBar(this); 256 257 mNotificationPeekRow = (ViewGroup) mNotificationPeekWindow.findViewById(R.id.content); 258 mNotificationPeekWindow.setVisibility(View.GONE); 259 mNotificationPeekWindow.setOnTouchListener( 260 new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PEEK, mNotificationPeekWindow)); 261 mNotificationPeekScrubRight = new LayoutTransition(); 262 mNotificationPeekScrubRight.setAnimator(LayoutTransition.APPEARING, 263 ObjectAnimator.ofInt(null, "left", -512, 0)); 264 mNotificationPeekScrubRight.setAnimator(LayoutTransition.DISAPPEARING, 265 ObjectAnimator.ofInt(null, "left", -512, 0)); 266 mNotificationPeekScrubRight.setDuration(500); 267 268 mNotificationPeekScrubLeft = new LayoutTransition(); 269 mNotificationPeekScrubLeft.setAnimator(LayoutTransition.APPEARING, 270 ObjectAnimator.ofInt(null, "left", 512, 0)); 271 mNotificationPeekScrubLeft.setAnimator(LayoutTransition.DISAPPEARING, 272 ObjectAnimator.ofInt(null, "left", 512, 0)); 273 mNotificationPeekScrubLeft.setDuration(500); 274 275 // XXX: setIgnoreChildren? 276 lp = new WindowManager.LayoutParams( 277 512, // ViewGroup.LayoutParams.WRAP_CONTENT, 278 ViewGroup.LayoutParams.WRAP_CONTENT, 279 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 280 WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 281 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 282 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 283 PixelFormat.TRANSLUCENT); 284 lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; 285 lp.y = res.getDimensionPixelOffset(R.dimen.peek_window_y_offset); 286 lp.setTitle("NotificationPeekWindow"); 287 lp.windowAnimations = com.android.internal.R.style.Animation_Toast; 288 289 WindowManagerImpl.getDefault().addView(mNotificationPeekWindow, lp); 290 291 // Recents Panel 292 mRecentsPanel = (RecentsPanelView) View.inflate(context, 293 R.layout.status_bar_recent_panel, null); 294 mRecentsPanel.setVisibility(View.GONE); 295 mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL, 296 mRecentsPanel)); 297 mStatusBarView.setIgnoreChildren(2, mRecentButton, mRecentsPanel); 298 299 lp = new WindowManager.LayoutParams( 300 ViewGroup.LayoutParams.WRAP_CONTENT, 301 ViewGroup.LayoutParams.WRAP_CONTENT, 302 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 303 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 304 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 305 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 306 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 307 PixelFormat.TRANSLUCENT); 308 lp.gravity = Gravity.BOTTOM | Gravity.LEFT; 309 lp.setTitle("RecentsPanel"); 310 lp.windowAnimations = R.style.Animation_RecentPanel; 311 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 312 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 313 314 WindowManagerImpl.getDefault().addView(mRecentsPanel, lp); 315 mRecentsPanel.setBar(this); 316 317 // Input methods Panel 318 mInputMethodsPanel = (InputMethodsPanel) View.inflate(context, 319 R.layout.status_bar_input_methods_panel, null); 320 mInputMethodsPanel.setHardKeyboardEnabledChangeListener(this); 321 mInputMethodsPanel.setOnTouchListener(new TouchOutsideListener( 322 MSG_CLOSE_INPUT_METHODS_PANEL, mInputMethodsPanel)); 323 mInputMethodsPanel.setImeSwitchButton(mInputMethodSwitchButton); 324 mStatusBarView.setIgnoreChildren(3, mInputMethodSwitchButton, mInputMethodsPanel); 325 lp = new WindowManager.LayoutParams( 326 ViewGroup.LayoutParams.WRAP_CONTENT, 327 ViewGroup.LayoutParams.WRAP_CONTENT, 328 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 329 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 330 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 331 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 332 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 333 PixelFormat.TRANSLUCENT); 334 lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; 335 lp.setTitle("InputMethodsPanel"); 336 lp.windowAnimations = R.style.Animation_RecentPanel; 337 338 WindowManagerImpl.getDefault().addView(mInputMethodsPanel, lp); 339 340 // Compatibility mode selector panel 341 mCompatModePanel = (CompatModePanel) View.inflate(context, 342 R.layout.status_bar_compat_mode_panel, null); 343 mCompatModePanel.setOnTouchListener(new TouchOutsideListener( 344 MSG_CLOSE_COMPAT_MODE_PANEL, mCompatModePanel)); 345 mCompatModePanel.setTrigger(mCompatModeButton); 346 mCompatModePanel.setVisibility(View.GONE); 347 mStatusBarView.setIgnoreChildren(4, mCompatModeButton, mCompatModePanel); 348 lp = new WindowManager.LayoutParams( 349 250, 350 ViewGroup.LayoutParams.WRAP_CONTENT, 351 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 352 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 353 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 354 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 355 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 356 PixelFormat.TRANSLUCENT); 357 lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; 358 lp.setTitle("CompatModePanel"); 359 lp.windowAnimations = android.R.style.Animation_Dialog; 360 361 WindowManagerImpl.getDefault().addView(mCompatModePanel, lp); 362 } 363 364 private int getNotificationPanelHeight() { 365 final Resources res = mContext.getResources(); 366 final Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); 367 final Point size = new Point(); 368 d.getRealSize(size); 369 return Math.max(res.getDimensionPixelSize(R.dimen.notification_panel_min_height), size.y); 370 } 371 372 @Override 373 public void start() { 374 super.start(); // will add the main bar view 375 } 376 377 @Override 378 protected void onConfigurationChanged(Configuration newConfig) { 379 mHeightReceiver.updateHeight(); // display size may have changed 380 loadDimens(); 381 mNotificationPanelParams.height = getNotificationPanelHeight(); 382 WindowManagerImpl.getDefault().updateViewLayout(mNotificationPanel, 383 mNotificationPanelParams); 384 } 385 386 protected void loadDimens() { 387 final Resources res = mContext.getResources(); 388 389 mNaturalBarHeight = res.getDimensionPixelSize( 390 com.android.internal.R.dimen.system_bar_height); 391 392 int newIconSize = res.getDimensionPixelSize( 393 com.android.internal.R.dimen.system_bar_icon_size); 394 int newIconHPadding = res.getDimensionPixelSize( 395 R.dimen.status_bar_icon_padding); 396 397 if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) { 398// Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding); 399 mIconHPadding = newIconHPadding; 400 mIconSize = newIconSize; 401 reloadAllNotificationIcons(); // reload the tray 402 } 403 404 final int numIcons = res.getInteger(R.integer.config_maxNotificationIcons); 405 if (numIcons != mMaxNotificationIcons) { 406 mMaxNotificationIcons = numIcons; 407 if (DEBUG) Slog.d(TAG, "max notification icons: " + mMaxNotificationIcons); 408 reloadAllNotificationIcons(); 409 } 410 } 411 412 protected View makeStatusBarView() { 413 final Context context = mContext; 414 415 mWindowManager = IWindowManager.Stub.asInterface( 416 ServiceManager.getService(Context.WINDOW_SERVICE)); 417 418 // This guy will listen for HDMI plugged broadcasts so we can resize the 419 // status bar as appropriate. 420 mHeightReceiver = new HeightReceiver(mContext); 421 mHeightReceiver.registerReceiver(); 422 loadDimens(); 423 424 final TabletStatusBarView sb = (TabletStatusBarView)View.inflate( 425 context, R.layout.status_bar, null); 426 mStatusBarView = sb; 427 428 sb.setHandler(mHandler); 429 430 mBarContents = (ViewGroup) sb.findViewById(R.id.bar_contents); 431 // layout transitions for the status bar's contents 432 mBarContentsLayoutTransition = new LayoutTransition(); 433 // add/removal will fade as normal 434 mBarContentsLayoutTransition.setAnimator(LayoutTransition.APPEARING, 435 ObjectAnimator.ofFloat(null, "alpha", 0f, 1f)); 436 mBarContentsLayoutTransition.setAnimator(LayoutTransition.DISAPPEARING, 437 ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)); 438 // no animations for siblings on change: just jump into place please 439 mBarContentsLayoutTransition.setAnimator(LayoutTransition.CHANGE_APPEARING, null); 440 mBarContentsLayoutTransition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, null); 441 // quick like bunny 442 mBarContentsLayoutTransition.setDuration(250 * (DEBUG?10:1)); 443 mBarContents.setLayoutTransition(mBarContentsLayoutTransition); 444 445 // the whole right-hand side of the bar 446 mNotificationArea = sb.findViewById(R.id.notificationArea); 447 448 // the button to open the notification area 449 mNotificationTrigger = sb.findViewById(R.id.notificationTrigger); 450 mNotificationTrigger.setOnTouchListener(new NotificationTriggerTouchListener()); 451 452 // the more notifications icon 453 mNotificationIconArea = (NotificationIconArea)sb.findViewById(R.id.notificationIcons); 454 455 // where the icons go 456 mIconLayout = (NotificationIconArea.IconLayout) sb.findViewById(R.id.icons); 457 mIconLayout.setOnTouchListener(new NotificationIconTouchListener()); 458 459 ViewConfiguration vc = ViewConfiguration.get(context); 460 mNotificationPeekTapDuration = vc.getTapTimeout(); 461 mNotificationFlingVelocity = 300; // px/s 462 463 mTicker = new TabletTicker(this); 464 465 // The icons 466 mLocationController = new LocationController(mContext); // will post a notification 467 468 mBatteryController = new BatteryController(mContext); 469 mBatteryController.addIconView((ImageView)sb.findViewById(R.id.battery)); 470 mBluetoothController = new BluetoothController(mContext); 471 mBluetoothController.addIconView((ImageView)sb.findViewById(R.id.bluetooth)); 472 473 mNetworkController = new NetworkController(mContext); 474 final ImageView comboRSSI = 475 (ImageView)sb.findViewById(R.id.network_signal); 476 if (comboRSSI != null) { 477 mNetworkController.addCombinedSignalIconView(comboRSSI); 478 } 479 final ImageView mobileRSSI = 480 (ImageView)sb.findViewById(R.id.mobile_signal); 481 if (mobileRSSI != null) { 482 mNetworkController.addPhoneSignalIconView(mobileRSSI); 483 } 484 final ImageView wifiRSSI = 485 (ImageView)sb.findViewById(R.id.wifi_signal); 486 if (wifiRSSI != null) { 487 mNetworkController.addWifiIconView(wifiRSSI); 488 } 489 mNetworkController.addDataTypeIconView( 490 (ImageView)sb.findViewById(R.id.network_type)); 491 mNetworkController.addDataDirectionOverlayIconView( 492 (ImageView)sb.findViewById(R.id.network_direction)); 493 494 // The navigation buttons 495 mBackButton = (ImageView)sb.findViewById(R.id.back); 496 mNavigationArea = (ViewGroup) sb.findViewById(R.id.navigationArea); 497 mHomeButton = mNavigationArea.findViewById(R.id.home); 498 mMenuButton = mNavigationArea.findViewById(R.id.menu); 499 mRecentButton = mNavigationArea.findViewById(R.id.recent_apps); 500 mRecentButton.setOnClickListener(mOnClickListener); 501 mNavigationArea.setLayoutTransition(mBarContentsLayoutTransition); 502 503 // The bar contents buttons 504 mFeedbackIconArea = (ViewGroup)sb.findViewById(R.id.feedbackIconArea); 505 mInputMethodSwitchButton = (InputMethodButton) sb.findViewById(R.id.imeSwitchButton); 506 // Overwrite the lister 507 mInputMethodSwitchButton.setOnClickListener(mOnClickListener); 508 509 mCompatModeButton = (CompatModeButton) sb.findViewById(R.id.compatModeButton); 510 mCompatModeButton.setOnClickListener(mOnClickListener); 511 512 // for redirecting errant bar taps to the IME 513 mFakeSpaceBar = sb.findViewById(R.id.fake_space_bar); 514 515 // "shadows" of the status bar features, for lights-out mode 516 mShadow = sb.findViewById(R.id.bar_shadow); 517 mShadow.setOnTouchListener( 518 new View.OnTouchListener() { 519 public boolean onTouch(View v, MotionEvent ev) { 520 if (ev.getAction() == MotionEvent.ACTION_DOWN) { 521 // even though setting the systemUI visibility below will turn these views 522 // on, we need them to come up faster so that they can catch this motion 523 // event 524 mShadow.setVisibility(View.GONE); 525 mBarContents.setVisibility(View.VISIBLE); 526 527 try { 528 mBarService.setSystemUiVisibility(View.STATUS_BAR_VISIBLE); 529 } catch (RemoteException ex) { 530 // system process dead 531 } 532 } 533 return false; 534 } 535 }); 536 537 // tuning parameters 538 final int LIGHTS_GOING_OUT_SYSBAR_DURATION = 600; 539 final int LIGHTS_GOING_OUT_SHADOW_DURATION = 1000; 540 final int LIGHTS_GOING_OUT_SHADOW_DELAY = 500; 541 542 final int LIGHTS_COMING_UP_SYSBAR_DURATION = 200; 543// final int LIGHTS_COMING_UP_SYSBAR_DELAY = 50; 544 final int LIGHTS_COMING_UP_SHADOW_DURATION = 0; 545 546 LayoutTransition xition = new LayoutTransition(); 547 xition.setAnimator(LayoutTransition.APPEARING, 548 ObjectAnimator.ofFloat(null, "alpha", 0.5f, 1f)); 549 xition.setDuration(LayoutTransition.APPEARING, LIGHTS_COMING_UP_SYSBAR_DURATION); 550 xition.setStartDelay(LayoutTransition.APPEARING, 0); 551 xition.setAnimator(LayoutTransition.DISAPPEARING, 552 ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)); 553 xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_GOING_OUT_SYSBAR_DURATION); 554 xition.setStartDelay(LayoutTransition.DISAPPEARING, 0); 555 ((ViewGroup)sb.findViewById(R.id.bar_contents_holder)).setLayoutTransition(xition); 556 557 xition = new LayoutTransition(); 558 xition.setAnimator(LayoutTransition.APPEARING, 559 ObjectAnimator.ofFloat(null, "alpha", 0f, 1f)); 560 xition.setDuration(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DURATION); 561 xition.setStartDelay(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DELAY); 562 xition.setAnimator(LayoutTransition.DISAPPEARING, 563 ObjectAnimator.ofFloat(null, "alpha", 1f, 0f)); 564 xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_COMING_UP_SHADOW_DURATION); 565 xition.setStartDelay(LayoutTransition.DISAPPEARING, 0); 566 ((ViewGroup)sb.findViewById(R.id.bar_shadow_holder)).setLayoutTransition(xition); 567 568 // set the initial view visibility 569 setAreThereNotifications(); 570 571 // Add the windows 572 addPanelWindows(); 573 574 mPile = (ViewGroup)mNotificationPanel.findViewById(R.id.content); 575 mPile.removeAllViews(); 576 577 ScrollView scroller = (ScrollView)mPile.getParent(); 578 scroller.setFillViewport(true); 579 580 mHeightReceiver.addOnBarHeightChangedListener(this); 581 582 return sb; 583 } 584 585 public int getStatusBarHeight() { 586 return mHeightReceiver.getHeight(); 587 } 588 589 protected int getStatusBarGravity() { 590 return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL; 591 } 592 593 public void onBarHeightChanged(int height) { 594 final WindowManager.LayoutParams lp 595 = (WindowManager.LayoutParams)mStatusBarView.getLayoutParams(); 596 if (lp == null) { 597 // haven't been added yet 598 return; 599 } 600 if (lp.height != height) { 601 lp.height = height; 602 final WindowManager wm = WindowManagerImpl.getDefault(); 603 wm.updateViewLayout(mStatusBarView, lp); 604 } 605 } 606 607 private class H extends Handler { 608 public void handleMessage(Message m) { 609 switch (m.what) { 610 case MSG_OPEN_NOTIFICATION_PEEK: 611 if (DEBUG) Slog.d(TAG, "opening notification peek window; arg=" + m.arg1); 612 613 if (m.arg1 >= 0) { 614 final int N = mNotificationData.size(); 615 616 if (!mNotificationDNDMode) { 617 if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) { 618 NotificationData.Entry entry = mNotificationData.get(N-1-mNotificationPeekIndex); 619 entry.icon.setBackgroundColor(0); 620 mNotificationPeekIndex = -1; 621 mNotificationPeekKey = null; 622 } 623 } 624 625 final int peekIndex = m.arg1; 626 if (peekIndex < N) { 627 //Slog.d(TAG, "loading peek: " + peekIndex); 628 NotificationData.Entry entry = 629 mNotificationDNDMode 630 ? mNotificationDNDDummyEntry 631 : mNotificationData.get(N-1-peekIndex); 632 NotificationData.Entry copy = new NotificationData.Entry( 633 entry.key, 634 entry.notification, 635 entry.icon); 636 inflateViews(copy, mNotificationPeekRow); 637 638 if (mNotificationDNDMode) { 639 copy.content.setOnClickListener(new View.OnClickListener() { 640 public void onClick(View v) { 641 SharedPreferences.Editor editor = Prefs.edit(mContext); 642 editor.putBoolean(Prefs.DO_NOT_DISTURB_PREF, false); 643 editor.apply(); 644 animateCollapse(); 645 } 646 }); 647 } 648 649 entry.icon.setBackgroundColor(0x20FFFFFF); 650 651// mNotificationPeekRow.setLayoutTransition( 652// peekIndex < mNotificationPeekIndex 653// ? mNotificationPeekScrubLeft 654// : mNotificationPeekScrubRight); 655 656 mNotificationPeekRow.removeAllViews(); 657 mNotificationPeekRow.addView(copy.row); 658 659 mNotificationPeekWindow.setVisibility(View.VISIBLE); 660 mNotificationPanel.show(false, true); 661 662 mNotificationPeekIndex = peekIndex; 663 mNotificationPeekKey = entry.key; 664 } 665 } 666 break; 667 case MSG_CLOSE_NOTIFICATION_PEEK: 668 if (DEBUG) Slog.d(TAG, "closing notification peek window"); 669 mNotificationPeekWindow.setVisibility(View.GONE); 670 mNotificationPeekRow.removeAllViews(); 671 672 final int N = mNotificationData.size(); 673 if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) { 674 NotificationData.Entry entry = 675 mNotificationDNDMode 676 ? mNotificationDNDDummyEntry 677 : mNotificationData.get(N-1-mNotificationPeekIndex); 678 entry.icon.setBackgroundColor(0); 679 } 680 681 mNotificationPeekIndex = -1; 682 mNotificationPeekKey = null; 683 break; 684 case MSG_OPEN_NOTIFICATION_PANEL: 685 if (DEBUG) Slog.d(TAG, "opening notifications panel"); 686 if (!mNotificationPanel.isShowing()) { 687 mNotificationPeekWindow.setVisibility(View.GONE); 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 (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 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK); 1014 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1015 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 1016 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); 1017 mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); 1018 } 1019 1020 public void animateCollapse() { 1021 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PANEL); 1022 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL); 1023 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); 1024 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); 1025 mHandler.removeMessages(MSG_CLOSE_INPUT_METHODS_PANEL); 1026 mHandler.sendEmptyMessage(MSG_CLOSE_INPUT_METHODS_PANEL); 1027 mHandler.removeMessages(MSG_CLOSE_COMPAT_MODE_PANEL); 1028 mHandler.sendEmptyMessage(MSG_CLOSE_COMPAT_MODE_PANEL); 1029 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK); 1030 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 1031 } 1032 1033 private void notifyUiVisibilityChanged() { 1034 try { 1035 mWindowManager.statusBarVisibilityChanged(mSystemUiVisibility); 1036 } catch (RemoteException ex) { 1037 } 1038 } 1039 1040 @Override // CommandQueue 1041 public void setSystemUiVisibility(int vis) { 1042 if (vis != mSystemUiVisibility) { 1043 mSystemUiVisibility = vis; 1044 1045 mHandler.removeMessages(MSG_HIDE_CHROME); 1046 mHandler.removeMessages(MSG_SHOW_CHROME); 1047 mHandler.sendEmptyMessage(0 == (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) 1048 ? MSG_SHOW_CHROME : MSG_HIDE_CHROME); 1049 1050 notifyUiVisibilityChanged(); 1051 } 1052 } 1053 1054 public void setLightsOn(boolean on) { 1055 // Policy note: if the frontmost activity needs the menu key, we assume it is a legacy app 1056 // that can't handle lights-out mode. 1057 if (mMenuButton.getVisibility() == View.VISIBLE) { 1058 on = true; 1059 } 1060 1061 Slog.v(TAG, "setLightsOn(" + on + ")"); 1062 if (on) { 1063 setSystemUiVisibility(mSystemUiVisibility & ~View.SYSTEM_UI_FLAG_LOW_PROFILE); 1064 } else { 1065 setSystemUiVisibility(mSystemUiVisibility | View.SYSTEM_UI_FLAG_LOW_PROFILE); 1066 } 1067 } 1068 1069 public void topAppWindowChanged(boolean showMenu) { 1070 if (DEBUG) { 1071 Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button"); 1072 } 1073 mMenuButton.setVisibility(showMenu ? View.VISIBLE : View.GONE); 1074 1075 // See above re: lights-out policy for legacy apps. 1076 if (showMenu) setLightsOn(true); 1077 1078 mCompatModeButton.refresh(); 1079 if (mCompatModeButton.getVisibility() == View.VISIBLE) { 1080 showCompatibilityHelp(); 1081 } else { 1082 hideCompatibilityHelp(); 1083 mCompatModePanel.closePanel(); 1084 } 1085 } 1086 1087 private void showCompatibilityHelp() { 1088 if (mCompatibilityHelpDialog != null) { 1089 return; 1090 } 1091 1092 mCompatibilityHelpDialog = View.inflate(mContext, R.layout.compat_mode_help, null); 1093 View button = mCompatibilityHelpDialog.findViewById(R.id.button); 1094 1095 button.setOnClickListener(new View.OnClickListener() { 1096 @Override 1097 public void onClick(View v) { 1098 hideCompatibilityHelp(); 1099 SharedPreferences.Editor editor = Prefs.edit(mContext); 1100 editor.putBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, true); 1101 editor.apply(); 1102 } 1103 }); 1104 1105 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 1106 ViewGroup.LayoutParams.MATCH_PARENT, 1107 ViewGroup.LayoutParams.MATCH_PARENT, 1108 WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG, 1109 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 1110 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 1111 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 1112 PixelFormat.TRANSLUCENT); 1113 lp.setTitle("CompatibilityModeDialog"); 1114 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 1115 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 1116 lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade 1117 1118 WindowManagerImpl.getDefault().addView(mCompatibilityHelpDialog, lp); 1119 } 1120 1121 private void hideCompatibilityHelp() { 1122 if (mCompatibilityHelpDialog != null) { 1123 WindowManagerImpl.getDefault().removeView(mCompatibilityHelpDialog); 1124 mCompatibilityHelpDialog = null; 1125 } 1126 } 1127 1128 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { 1129 mInputMethodSwitchButton.setImeWindowStatus(token, 1130 (vis & InputMethodService.IME_ACTIVE) != 0); 1131 updateNotificationIcons(); 1132 mInputMethodsPanel.setImeToken(token); 1133 int res; 1134 switch (backDisposition) { 1135 case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: 1136 res = R.drawable.ic_sysbar_back; 1137 break; 1138 case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: 1139 res = R.drawable.ic_sysbar_back_ime; 1140 break; 1141 case InputMethodService.BACK_DISPOSITION_DEFAULT: 1142 default: 1143 if ((vis & InputMethodService.IME_VISIBLE) != 0) { 1144 res = R.drawable.ic_sysbar_back_ime; 1145 } else { 1146 res = R.drawable.ic_sysbar_back; 1147 } 1148 break; 1149 } 1150 mBackButton.setImageResource(res); 1151 if (FAKE_SPACE_BAR) { 1152 mFakeSpaceBar.setVisibility(((vis & InputMethodService.IME_VISIBLE) != 0) 1153 ? View.VISIBLE : View.GONE); 1154 } 1155 } 1156 1157 @Override 1158 public void setHardKeyboardStatus(boolean available, boolean enabled) { 1159 if (DEBUG) { 1160 Slog.d(TAG, "Set hard keyboard status: available=" + available 1161 + ", enabled=" + enabled); 1162 } 1163 mInputMethodSwitchButton.setHardKeyboardStatus(available); 1164 updateNotificationIcons(); 1165 mInputMethodsPanel.setHardKeyboardStatus(available, enabled); 1166 } 1167 1168 @Override 1169 public void onHardKeyboardEnabledChange(boolean enabled) { 1170 try { 1171 mBarService.setHardKeyboardEnabled(enabled); 1172 } catch (RemoteException ex) { 1173 } 1174 } 1175 1176 private boolean isImmersive() { 1177 try { 1178 return ActivityManagerNative.getDefault().isTopActivityImmersive(); 1179 //Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); 1180 } catch (RemoteException ex) { 1181 // the end is nigh 1182 return false; 1183 } 1184 } 1185 1186 private void setAreThereNotifications() { 1187 if (mNotificationPanel != null) { 1188 mNotificationPanel.setClearable(mNotificationData.hasClearableItems()); 1189 } 1190 } 1191 1192 /** 1193 * Cancel this notification and tell the status bar service about the failure. Hold no locks. 1194 */ 1195 void handleNotificationError(IBinder key, StatusBarNotification n, String message) { 1196 removeNotification(key); 1197 try { 1198 mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message); 1199 } catch (RemoteException ex) { 1200 // The end is nigh. 1201 } 1202 } 1203 1204 private void sendKey(KeyEvent key) { 1205 try { 1206 if (DEBUG) Slog.d(TAG, "injecting key event: " + key); 1207 mWindowManager.injectInputEventNoWait(key); 1208 } catch (RemoteException ex) { 1209 } 1210 } 1211 1212 private View.OnClickListener mOnClickListener = new View.OnClickListener() { 1213 public void onClick(View v) { 1214 if (v == mNotificationTrigger) { 1215 onClickNotificationTrigger(); 1216 } else if (v == mRecentButton) { 1217 onClickRecentButton(); 1218 } else if (v == mInputMethodSwitchButton) { 1219 onClickInputMethodSwitchButton(); 1220 } else if (v == mCompatModeButton) { 1221 onClickCompatModeButton(); 1222 } 1223 } 1224 }; 1225 1226 public void onClickNotificationTrigger() { 1227 if (DEBUG) Slog.d(TAG, "clicked notification icons; disabled=" + mDisabled); 1228 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { 1229 int msg = !mNotificationPanel.isShowing() 1230 ? MSG_OPEN_NOTIFICATION_PANEL 1231 : MSG_CLOSE_NOTIFICATION_PANEL; 1232 mHandler.removeMessages(msg); 1233 mHandler.sendEmptyMessage(msg); 1234 } 1235 } 1236 1237 public void onClickRecentButton() { 1238 if (DEBUG) Slog.d(TAG, "clicked recent apps; disabled=" + mDisabled); 1239 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { 1240 int msg = (mRecentsPanel.getVisibility() == View.GONE) 1241 ? MSG_OPEN_RECENTS_PANEL 1242 : MSG_CLOSE_RECENTS_PANEL; 1243 mHandler.removeMessages(msg); 1244 mHandler.sendEmptyMessage(msg); 1245 } 1246 } 1247 1248 public void onClickInputMethodSwitchButton() { 1249 if (DEBUG) Slog.d(TAG, "clicked input methods panel; disabled=" + mDisabled); 1250 int msg = (mInputMethodsPanel.getVisibility() == View.GONE) ? 1251 MSG_OPEN_INPUT_METHODS_PANEL : MSG_CLOSE_INPUT_METHODS_PANEL; 1252 mHandler.removeMessages(msg); 1253 mHandler.sendEmptyMessage(msg); 1254 } 1255 1256 public void onClickCompatModeButton() { 1257 int msg = (mCompatModePanel.getVisibility() == View.GONE) ? 1258 MSG_OPEN_COMPAT_MODE_PANEL : MSG_CLOSE_COMPAT_MODE_PANEL; 1259 mHandler.removeMessages(msg); 1260 mHandler.sendEmptyMessage(msg); 1261 } 1262 1263 public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag, int id) { 1264 return new NotificationClicker(intent, pkg, tag, id); 1265 } 1266 1267 private class NotificationClicker implements View.OnClickListener { 1268 private PendingIntent mIntent; 1269 private String mPkg; 1270 private String mTag; 1271 private int mId; 1272 1273 NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { 1274 mIntent = intent; 1275 mPkg = pkg; 1276 mTag = tag; 1277 mId = id; 1278 } 1279 1280 public void onClick(View v) { 1281 try { 1282 // The intent we are sending is for the application, which 1283 // won't have permission to immediately start an activity after 1284 // the user switches to home. We know it is safe to do at this 1285 // point, so make sure new activity switches are now allowed. 1286 ActivityManagerNative.getDefault().resumeAppSwitches(); 1287 } catch (RemoteException e) { 1288 } 1289 1290 if (mIntent != null) { 1291 int[] pos = new int[2]; 1292 v.getLocationOnScreen(pos); 1293 Intent overlay = new Intent(); 1294 overlay.setSourceBounds( 1295 new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); 1296 try { 1297 mIntent.send(mContext, 0, overlay); 1298 } catch (PendingIntent.CanceledException e) { 1299 // the stack trace isn't very helpful here. Just log the exception message. 1300 Slog.w(TAG, "Sending contentIntent failed: " + e); 1301 } 1302 } 1303 1304 try { 1305 mBarService.onNotificationClick(mPkg, mTag, mId); 1306 } catch (RemoteException ex) { 1307 // system process is dead if we're here. 1308 } 1309 1310 // close the shade if it was open 1311 animateCollapse(); 1312 1313 // If this click was on the intruder alert, hide that instead 1314// mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); 1315 } 1316 } 1317 1318 StatusBarNotification removeNotificationViews(IBinder key) { 1319 NotificationData.Entry entry = mNotificationData.remove(key); 1320 if (entry == null) { 1321 Slog.w(TAG, "removeNotification for unknown key: " + key); 1322 return null; 1323 } 1324 // Remove the expanded view. 1325 ViewGroup rowParent = (ViewGroup)entry.row.getParent(); 1326 if (rowParent != null) rowParent.removeView(entry.row); 1327 1328 if (key == mNotificationPeekKey) { 1329 // must close the peek as well, since it's gone 1330 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 1331 } 1332 // Remove the icon. 1333// ViewGroup iconParent = (ViewGroup)entry.icon.getParent(); 1334// if (iconParent != null) iconParent.removeView(entry.icon); 1335 updateNotificationIcons(); 1336 1337 return entry.notification; 1338 } 1339 1340 private class NotificationTriggerTouchListener implements View.OnTouchListener { 1341 VelocityTracker mVT; 1342 float mInitialTouchX, mInitialTouchY; 1343 int mTouchSlop; 1344 1345 public NotificationTriggerTouchListener() { 1346 mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); 1347 } 1348 1349 public boolean onTouch(View v, MotionEvent event) { 1350// Slog.d(TAG, String.format("touch: (%.1f, %.1f) initial: (%.1f, %.1f)", 1351// event.getX(), 1352// event.getY(), 1353// mInitialTouchX, 1354// mInitialTouchY)); 1355 final int action = event.getAction(); 1356 switch (action) { 1357 case MotionEvent.ACTION_DOWN: 1358 mVT = VelocityTracker.obtain(); 1359 mInitialTouchX = event.getX(); 1360 mInitialTouchY = event.getY(); 1361 // fall through 1362 case MotionEvent.ACTION_OUTSIDE: 1363 case MotionEvent.ACTION_MOVE: 1364 // check for fling 1365 if (mVT != null) { 1366 mVT.addMovement(event); 1367 mVT.computeCurrentVelocity(1000); // pixels per second 1368 // require a little more oomph once we're already in peekaboo mode 1369 if (mVT.getYVelocity() < -mNotificationFlingVelocity) { 1370 animateExpand(); 1371 mVT.recycle(); 1372 mVT = null; 1373 } 1374 } 1375 return true; 1376 case MotionEvent.ACTION_UP: 1377 case MotionEvent.ACTION_CANCEL: 1378 if (mVT != null) { 1379 if (action == MotionEvent.ACTION_UP 1380 // was this a sloppy tap? 1381 && Math.abs(event.getX() - mInitialTouchX) < mTouchSlop 1382 && Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3) 1383 // dragging off the bottom doesn't count 1384 && (int)event.getY() < v.getBottom()) { 1385 animateExpand(); 1386 v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); 1387 v.playSoundEffect(SoundEffectConstants.CLICK); 1388 } 1389 1390 mVT.recycle(); 1391 mVT = null; 1392 return true; 1393 } 1394 } 1395 return false; 1396 } 1397 } 1398 1399 final static int NOTIFICATION_PEEK_HOLD_THRESH = 200; // ms 1400 final static int NOTIFICATION_PEEK_FADE_DELAY = 3000; // ms 1401 1402 public void resetNotificationPeekFadeTimer() { 1403 if (DEBUG) { 1404 Slog.d(TAG, "setting peek fade timer for " + NOTIFICATION_PEEK_FADE_DELAY 1405 + "ms from now"); 1406 } 1407 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK); 1408 mHandler.sendEmptyMessageDelayed(MSG_CLOSE_NOTIFICATION_PEEK, 1409 NOTIFICATION_PEEK_FADE_DELAY); 1410 } 1411 1412 private class NotificationIconTouchListener implements View.OnTouchListener { 1413 VelocityTracker mVT; 1414 int mPeekIndex; 1415 float mInitialTouchX, mInitialTouchY; 1416 int mTouchSlop; 1417 1418 public NotificationIconTouchListener() { 1419 mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); 1420 } 1421 1422 public boolean onTouch(View v, MotionEvent event) { 1423 boolean peeking = mNotificationPeekWindow.getVisibility() != View.GONE; 1424 boolean panelShowing = mNotificationPanel.isShowing(); 1425 if (panelShowing) return false; 1426 1427 int numIcons = mIconLayout.getChildCount(); 1428 int newPeekIndex = (int)(event.getX() * numIcons / mIconLayout.getWidth()); 1429 if (newPeekIndex > numIcons - 1) newPeekIndex = numIcons - 1; 1430 else if (newPeekIndex < 0) newPeekIndex = 0; 1431 1432 final int action = event.getAction(); 1433 switch (action) { 1434 case MotionEvent.ACTION_DOWN: 1435 mVT = VelocityTracker.obtain(); 1436 mInitialTouchX = event.getX(); 1437 mInitialTouchY = event.getY(); 1438 mPeekIndex = -1; 1439 1440 // fall through 1441 case MotionEvent.ACTION_OUTSIDE: 1442 case MotionEvent.ACTION_MOVE: 1443 // peek and switch icons if necessary 1444 1445 if (newPeekIndex != mPeekIndex) { 1446 mPeekIndex = newPeekIndex; 1447 1448 if (DEBUG) Slog.d(TAG, "will peek at notification #" + mPeekIndex); 1449 Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK); 1450 peekMsg.arg1 = mPeekIndex; 1451 1452 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1453 1454 if (peeking) { 1455 // no delay if we're scrubbing left-right 1456 mHandler.sendMessage(peekMsg); 1457 } else { 1458 // wait for fling 1459 mHandler.sendMessageDelayed(peekMsg, NOTIFICATION_PEEK_HOLD_THRESH); 1460 } 1461 } 1462 1463 // check for fling 1464 if (mVT != null) { 1465 mVT.addMovement(event); 1466 mVT.computeCurrentVelocity(1000); // pixels per second 1467 // require a little more oomph once we're already in peekaboo mode 1468 if (!panelShowing && ( 1469 (peeking && mVT.getYVelocity() < -mNotificationFlingVelocity*3) 1470 || (mVT.getYVelocity() < -mNotificationFlingVelocity))) { 1471 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1472 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); 1473 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 1474 mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); 1475 } 1476 } 1477 return true; 1478 case MotionEvent.ACTION_UP: 1479 case MotionEvent.ACTION_CANCEL: 1480 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1481 if (!peeking) { 1482 if (action == MotionEvent.ACTION_UP 1483 // was this a sloppy tap? 1484 && Math.abs(event.getX() - mInitialTouchX) < mTouchSlop 1485 && Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3) 1486 // dragging off the bottom doesn't count 1487 && (int)event.getY() < v.getBottom()) { 1488 Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK); 1489 peekMsg.arg1 = mPeekIndex; 1490 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1491 mHandler.sendMessage(peekMsg); 1492 1493 v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); 1494 v.playSoundEffect(SoundEffectConstants.CLICK); 1495 1496 peeking = true; // not technically true yet, but the next line will run 1497 } 1498 } 1499 1500 if (peeking) { 1501 resetNotificationPeekFadeTimer(); 1502 } 1503 1504 mVT.recycle(); 1505 mVT = null; 1506 return true; 1507 } 1508 return false; 1509 } 1510 } 1511 1512 StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) { 1513 if (DEBUG) { 1514 Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification); 1515 } 1516 // Construct the icon. 1517 final StatusBarIconView iconView = new StatusBarIconView(mContext, 1518 notification.pkg + "/0x" + Integer.toHexString(notification.id), 1519 notification.notification); 1520 iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 1521 1522 final StatusBarIcon ic = new StatusBarIcon(notification.pkg, 1523 notification.notification.icon, 1524 notification.notification.iconLevel, 1525 notification.notification.number, 1526 notification.notification.tickerText); 1527 if (!iconView.set(ic)) { 1528 handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic); 1529 return null; 1530 } 1531 // Construct the expanded view. 1532 NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView); 1533 if (!inflateViews(entry, mPile)) { 1534 handleNotificationError(key, notification, "Couldn't expand RemoteViews for: " 1535 + notification); 1536 return null; 1537 } 1538 1539 // Add the icon. 1540 int pos = mNotificationData.add(entry); 1541 if (DEBUG) { 1542 Slog.d(TAG, "addNotificationViews: added at " + pos); 1543 } 1544 updateNotificationIcons(); 1545 1546 return iconView; 1547 } 1548 1549 private void reloadAllNotificationIcons() { 1550 if (mIconLayout == null) return; 1551 mIconLayout.removeAllViews(); 1552 updateNotificationIcons(); 1553 } 1554 1555 private void updateNotificationIcons() { 1556 // XXX: need to implement a new limited linear layout class 1557 // to avoid removing & readding everything 1558 1559 if (mIconLayout == null) return; 1560 1561 // first, populate the main notification panel 1562 loadNotificationPanel(); 1563 1564 final LinearLayout.LayoutParams params 1565 = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight); 1566 1567 // alternate behavior in DND mode 1568 if (mNotificationDNDMode) { 1569 if (mIconLayout.getChildCount() == 0) { 1570 final Notification dndNotification = new Notification.Builder(mContext) 1571 .setContentTitle(mContext.getText(R.string.notifications_off_title)) 1572 .setContentText(mContext.getText(R.string.notifications_off_text)) 1573 .setSmallIcon(R.drawable.ic_notification_dnd) 1574 .setOngoing(true) 1575 .getNotification(); 1576 1577 final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd", 1578 dndNotification); 1579 iconView.setImageResource(R.drawable.ic_notification_dnd); 1580 iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 1581 iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0); 1582 1583 mNotificationDNDDummyEntry = new NotificationData.Entry( 1584 null, 1585 new StatusBarNotification("", 0, "", 0, 0, dndNotification), 1586 iconView); 1587 1588 mIconLayout.addView(iconView, params); 1589 } 1590 1591 return; 1592 } else if (0 != (mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS)) { 1593 // if icons are disabled but we're not in DND mode, this is probably Setup and we should 1594 // just leave the area totally empty 1595 return; 1596 } 1597 1598 int N = mNotificationData.size(); 1599 1600 if (DEBUG) { 1601 Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout); 1602 } 1603 1604 ArrayList<View> toShow = new ArrayList<View>(); 1605 1606 // Extra Special Icons 1607 // The IME switcher and compatibility mode icons take the place of notifications. You didn't 1608 // need to see all those new emails, did you? 1609 int maxNotificationIconsCount = mMaxNotificationIcons; 1610 if (mInputMethodSwitchButton.getVisibility() != View.GONE) maxNotificationIconsCount --; 1611 if (mCompatModeButton.getVisibility() != View.GONE) maxNotificationIconsCount --; 1612 1613 for (int i=0; i< maxNotificationIconsCount; i++) { 1614 if (i>=N) break; 1615 toShow.add(mNotificationData.get(N-i-1).icon); 1616 } 1617 1618 ArrayList<View> toRemove = new ArrayList<View>(); 1619 for (int i=0; i<mIconLayout.getChildCount(); i++) { 1620 View child = mIconLayout.getChildAt(i); 1621 if (!toShow.contains(child)) { 1622 toRemove.add(child); 1623 } 1624 } 1625 1626 for (View remove : toRemove) { 1627 mIconLayout.removeView(remove); 1628 } 1629 1630 for (int i=0; i<toShow.size(); i++) { 1631 View v = toShow.get(i); 1632 v.setPadding(mIconHPadding, 0, mIconHPadding, 0); 1633 if (v.getParent() == null) { 1634 mIconLayout.addView(v, i, params); 1635 } 1636 } 1637 } 1638 1639 private void loadNotificationPanel() { 1640 int N = mNotificationData.size(); 1641 1642 ArrayList<View> toShow = new ArrayList<View>(); 1643 1644 for (int i=0; i<N; i++) { 1645 View row = mNotificationData.get(N-i-1).row; 1646 toShow.add(row); 1647 } 1648 1649 ArrayList<View> toRemove = new ArrayList<View>(); 1650 for (int i=0; i<mPile.getChildCount(); i++) { 1651 View child = mPile.getChildAt(i); 1652 if (!toShow.contains(child)) { 1653 toRemove.add(child); 1654 } 1655 } 1656 1657 for (View remove : toRemove) { 1658 mPile.removeView(remove); 1659 } 1660 1661 for (int i=0; i<toShow.size(); i++) { 1662 View v = toShow.get(i); 1663 if (v.getParent() == null) { 1664 mPile.addView(v, N-1-i); // the notification panel has newest at the bottom 1665 } 1666 } 1667 1668 mNotificationPanel.setNotificationCount(N); 1669 } 1670 1671 void workAroundBadLayerDrawableOpacity(View v) { 1672 LayerDrawable d = (LayerDrawable)v.getBackground(); 1673 if (d == null) return; 1674 v.setBackgroundDrawable(null); 1675 d.setOpacity(PixelFormat.TRANSLUCENT); 1676 v.setBackgroundDrawable(d); 1677 } 1678 1679 private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) { 1680 StatusBarNotification sbn = entry.notification; 1681 RemoteViews remoteViews = sbn.notification.contentView; 1682 if (remoteViews == null) { 1683 return false; 1684 } 1685 1686 // create the row view 1687 LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( 1688 Context.LAYOUT_INFLATER_SERVICE); 1689 View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false); 1690 workAroundBadLayerDrawableOpacity(row); 1691 View vetoButton = row.findViewById(R.id.veto); 1692 if (entry.notification.isClearable()) { 1693 final String _pkg = sbn.pkg; 1694 final String _tag = sbn.tag; 1695 final int _id = sbn.id; 1696 vetoButton.setOnClickListener(new View.OnClickListener() { 1697 public void onClick(View v) { 1698 try { 1699 mBarService.onNotificationClear(_pkg, _tag, _id); 1700 } catch (RemoteException ex) { 1701 // system process is dead if we're here. 1702 } 1703 } 1704 }); 1705 } else { 1706 if ((sbn.notification.flags & Notification.FLAG_ONGOING_EVENT) == 0) { 1707 vetoButton.setVisibility(View.INVISIBLE); 1708 vetoButton.setContentDescription("VETO"); 1709 } else { 1710 vetoButton.setVisibility(View.GONE); 1711 } 1712 } 1713 vetoButton.setContentDescription(mContext.getString( 1714 R.string.accessibility_remove_notification)); 1715 1716 // the large icon 1717 ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon); 1718 if (sbn.notification.largeIcon != null) { 1719 largeIcon.setImageBitmap(sbn.notification.largeIcon); 1720 largeIcon.setContentDescription(sbn.notification.tickerText); 1721 } else { 1722 largeIcon.getLayoutParams().width = 0; 1723 largeIcon.setVisibility(View.INVISIBLE); 1724 } 1725 largeIcon.setContentDescription(sbn.notification.tickerText); 1726 1727 // bind the click event to the content area 1728 ViewGroup content = (ViewGroup)row.findViewById(R.id.content); 1729 // XXX: update to allow controls within notification views 1730 content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 1731// content.setOnFocusChangeListener(mFocusChangeListener); 1732 PendingIntent contentIntent = sbn.notification.contentIntent; 1733 if (contentIntent != null) { 1734 content.setOnClickListener(new NotificationClicker(contentIntent, 1735 sbn.pkg, sbn.tag, sbn.id)); 1736 } else { 1737 content.setOnClickListener(null); 1738 } 1739 1740 View expanded = null; 1741 Exception exception = null; 1742 try { 1743 expanded = remoteViews.apply(mContext, content); 1744 } 1745 catch (RuntimeException e) { 1746 exception = e; 1747 } 1748 if (expanded == null) { 1749 final String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id); 1750 Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); 1751 return false; 1752 } else { 1753 content.addView(expanded); 1754 row.setDrawingCacheEnabled(true); 1755 } 1756 1757 entry.row = row; 1758 entry.content = content; 1759 entry.expanded = expanded; 1760 entry.largeIcon = largeIcon; 1761 1762 return true; 1763 } 1764 1765 public void clearAll() { 1766 try { 1767 mBarService.onClearAllNotifications(); 1768 } catch (RemoteException ex) { 1769 // system process is dead if we're here. 1770 } 1771 animateCollapse(); 1772 } 1773 1774 public void userActivity() { 1775 } 1776 1777 public void toggleRecentApps() { 1778 int msg = (mRecentsPanel.getVisibility() == View.GONE) 1779 ? MSG_OPEN_RECENTS_PANEL : MSG_CLOSE_RECENTS_PANEL; 1780 mHandler.removeMessages(msg); 1781 mHandler.sendEmptyMessage(msg); 1782 } 1783 1784 public class TouchOutsideListener implements View.OnTouchListener { 1785 private int mMsg; 1786 private StatusBarPanel mPanel; 1787 1788 public TouchOutsideListener(int msg, StatusBarPanel panel) { 1789 mMsg = msg; 1790 mPanel = panel; 1791 } 1792 1793 public boolean onTouch(View v, MotionEvent ev) { 1794 final int action = ev.getAction(); 1795 if (action == MotionEvent.ACTION_OUTSIDE 1796 || (action == MotionEvent.ACTION_DOWN 1797 && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) { 1798 mHandler.removeMessages(mMsg); 1799 mHandler.sendEmptyMessage(mMsg); 1800 return true; 1801 } 1802 return false; 1803 } 1804 } 1805 1806 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 1807 pw.print("mDisabled=0x"); 1808 pw.println(Integer.toHexString(mDisabled)); 1809 pw.println("mNetworkController:"); 1810 mNetworkController.dump(fd, pw, args); 1811 } 1812} 1813 1814 1815