TabletStatusBar.java revision 212f625b71fb1f137e23fd1b6a679dca3f1e9f3c
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.MATCH_PARENT, 301 ViewGroup.LayoutParams.MATCH_PARENT, 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 if (DEBUG_COMPAT_HELP 1081 || ! Prefs.read(mContext).getBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, false)) { 1082 showCompatibilityHelp(); 1083 } 1084 } else { 1085 hideCompatibilityHelp(); 1086 mCompatModePanel.closePanel(); 1087 } 1088 } 1089 1090 private void showCompatibilityHelp() { 1091 if (mCompatibilityHelpDialog != null) { 1092 return; 1093 } 1094 1095 mCompatibilityHelpDialog = View.inflate(mContext, R.layout.compat_mode_help, null); 1096 View button = mCompatibilityHelpDialog.findViewById(R.id.button); 1097 1098 button.setOnClickListener(new View.OnClickListener() { 1099 @Override 1100 public void onClick(View v) { 1101 hideCompatibilityHelp(); 1102 SharedPreferences.Editor editor = Prefs.edit(mContext); 1103 editor.putBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, true); 1104 editor.apply(); 1105 } 1106 }); 1107 1108 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 1109 ViewGroup.LayoutParams.MATCH_PARENT, 1110 ViewGroup.LayoutParams.MATCH_PARENT, 1111 WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG, 1112 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 1113 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 1114 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 1115 PixelFormat.TRANSLUCENT); 1116 lp.setTitle("CompatibilityModeDialog"); 1117 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 1118 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 1119 lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade 1120 1121 WindowManagerImpl.getDefault().addView(mCompatibilityHelpDialog, lp); 1122 } 1123 1124 private void hideCompatibilityHelp() { 1125 if (mCompatibilityHelpDialog != null) { 1126 WindowManagerImpl.getDefault().removeView(mCompatibilityHelpDialog); 1127 mCompatibilityHelpDialog = null; 1128 } 1129 } 1130 1131 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { 1132 mInputMethodSwitchButton.setImeWindowStatus(token, 1133 (vis & InputMethodService.IME_ACTIVE) != 0); 1134 updateNotificationIcons(); 1135 mInputMethodsPanel.setImeToken(token); 1136 int res; 1137 switch (backDisposition) { 1138 case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: 1139 res = R.drawable.ic_sysbar_back; 1140 break; 1141 case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: 1142 res = R.drawable.ic_sysbar_back_ime; 1143 break; 1144 case InputMethodService.BACK_DISPOSITION_DEFAULT: 1145 default: 1146 if ((vis & InputMethodService.IME_VISIBLE) != 0) { 1147 res = R.drawable.ic_sysbar_back_ime; 1148 } else { 1149 res = R.drawable.ic_sysbar_back; 1150 } 1151 break; 1152 } 1153 mBackButton.setImageResource(res); 1154 if (FAKE_SPACE_BAR) { 1155 mFakeSpaceBar.setVisibility(((vis & InputMethodService.IME_VISIBLE) != 0) 1156 ? View.VISIBLE : View.GONE); 1157 } 1158 } 1159 1160 @Override 1161 public void setHardKeyboardStatus(boolean available, boolean enabled) { 1162 if (DEBUG) { 1163 Slog.d(TAG, "Set hard keyboard status: available=" + available 1164 + ", enabled=" + enabled); 1165 } 1166 mInputMethodSwitchButton.setHardKeyboardStatus(available); 1167 updateNotificationIcons(); 1168 mInputMethodsPanel.setHardKeyboardStatus(available, enabled); 1169 } 1170 1171 @Override 1172 public void onHardKeyboardEnabledChange(boolean enabled) { 1173 try { 1174 mBarService.setHardKeyboardEnabled(enabled); 1175 } catch (RemoteException ex) { 1176 } 1177 } 1178 1179 private boolean isImmersive() { 1180 try { 1181 return ActivityManagerNative.getDefault().isTopActivityImmersive(); 1182 //Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); 1183 } catch (RemoteException ex) { 1184 // the end is nigh 1185 return false; 1186 } 1187 } 1188 1189 private void setAreThereNotifications() { 1190 if (mNotificationPanel != null) { 1191 mNotificationPanel.setClearable(mNotificationData.hasClearableItems()); 1192 } 1193 } 1194 1195 /** 1196 * Cancel this notification and tell the status bar service about the failure. Hold no locks. 1197 */ 1198 void handleNotificationError(IBinder key, StatusBarNotification n, String message) { 1199 removeNotification(key); 1200 try { 1201 mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message); 1202 } catch (RemoteException ex) { 1203 // The end is nigh. 1204 } 1205 } 1206 1207 private void sendKey(KeyEvent key) { 1208 try { 1209 if (DEBUG) Slog.d(TAG, "injecting key event: " + key); 1210 mWindowManager.injectInputEventNoWait(key); 1211 } catch (RemoteException ex) { 1212 } 1213 } 1214 1215 private View.OnClickListener mOnClickListener = new View.OnClickListener() { 1216 public void onClick(View v) { 1217 if (v == mNotificationTrigger) { 1218 onClickNotificationTrigger(); 1219 } else if (v == mRecentButton) { 1220 onClickRecentButton(); 1221 } else if (v == mInputMethodSwitchButton) { 1222 onClickInputMethodSwitchButton(); 1223 } else if (v == mCompatModeButton) { 1224 onClickCompatModeButton(); 1225 } 1226 } 1227 }; 1228 1229 public void onClickNotificationTrigger() { 1230 if (DEBUG) Slog.d(TAG, "clicked notification icons; disabled=" + mDisabled); 1231 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { 1232 int msg = !mNotificationPanel.isShowing() 1233 ? MSG_OPEN_NOTIFICATION_PANEL 1234 : MSG_CLOSE_NOTIFICATION_PANEL; 1235 mHandler.removeMessages(msg); 1236 mHandler.sendEmptyMessage(msg); 1237 } 1238 } 1239 1240 public void onClickRecentButton() { 1241 if (DEBUG) Slog.d(TAG, "clicked recent apps; disabled=" + mDisabled); 1242 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { 1243 int msg = (mRecentsPanel.getVisibility() == View.GONE) 1244 ? MSG_OPEN_RECENTS_PANEL 1245 : MSG_CLOSE_RECENTS_PANEL; 1246 mHandler.removeMessages(msg); 1247 mHandler.sendEmptyMessage(msg); 1248 } 1249 } 1250 1251 public void onClickInputMethodSwitchButton() { 1252 if (DEBUG) Slog.d(TAG, "clicked input methods panel; disabled=" + mDisabled); 1253 int msg = (mInputMethodsPanel.getVisibility() == View.GONE) ? 1254 MSG_OPEN_INPUT_METHODS_PANEL : MSG_CLOSE_INPUT_METHODS_PANEL; 1255 mHandler.removeMessages(msg); 1256 mHandler.sendEmptyMessage(msg); 1257 } 1258 1259 public void onClickCompatModeButton() { 1260 int msg = (mCompatModePanel.getVisibility() == View.GONE) ? 1261 MSG_OPEN_COMPAT_MODE_PANEL : MSG_CLOSE_COMPAT_MODE_PANEL; 1262 mHandler.removeMessages(msg); 1263 mHandler.sendEmptyMessage(msg); 1264 } 1265 1266 public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag, int id) { 1267 return new NotificationClicker(intent, pkg, tag, id); 1268 } 1269 1270 private class NotificationClicker implements View.OnClickListener { 1271 private PendingIntent mIntent; 1272 private String mPkg; 1273 private String mTag; 1274 private int mId; 1275 1276 NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { 1277 mIntent = intent; 1278 mPkg = pkg; 1279 mTag = tag; 1280 mId = id; 1281 } 1282 1283 public void onClick(View v) { 1284 try { 1285 // The intent we are sending is for the application, which 1286 // won't have permission to immediately start an activity after 1287 // the user switches to home. We know it is safe to do at this 1288 // point, so make sure new activity switches are now allowed. 1289 ActivityManagerNative.getDefault().resumeAppSwitches(); 1290 } catch (RemoteException e) { 1291 } 1292 1293 if (mIntent != null) { 1294 int[] pos = new int[2]; 1295 v.getLocationOnScreen(pos); 1296 Intent overlay = new Intent(); 1297 overlay.setSourceBounds( 1298 new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); 1299 try { 1300 mIntent.send(mContext, 0, overlay); 1301 } catch (PendingIntent.CanceledException e) { 1302 // the stack trace isn't very helpful here. Just log the exception message. 1303 Slog.w(TAG, "Sending contentIntent failed: " + e); 1304 } 1305 } 1306 1307 try { 1308 mBarService.onNotificationClick(mPkg, mTag, mId); 1309 } catch (RemoteException ex) { 1310 // system process is dead if we're here. 1311 } 1312 1313 // close the shade if it was open 1314 animateCollapse(); 1315 1316 // If this click was on the intruder alert, hide that instead 1317// mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); 1318 } 1319 } 1320 1321 StatusBarNotification removeNotificationViews(IBinder key) { 1322 NotificationData.Entry entry = mNotificationData.remove(key); 1323 if (entry == null) { 1324 Slog.w(TAG, "removeNotification for unknown key: " + key); 1325 return null; 1326 } 1327 // Remove the expanded view. 1328 ViewGroup rowParent = (ViewGroup)entry.row.getParent(); 1329 if (rowParent != null) rowParent.removeView(entry.row); 1330 1331 if (key == mNotificationPeekKey) { 1332 // must close the peek as well, since it's gone 1333 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 1334 } 1335 // Remove the icon. 1336// ViewGroup iconParent = (ViewGroup)entry.icon.getParent(); 1337// if (iconParent != null) iconParent.removeView(entry.icon); 1338 updateNotificationIcons(); 1339 1340 return entry.notification; 1341 } 1342 1343 private class NotificationTriggerTouchListener implements View.OnTouchListener { 1344 VelocityTracker mVT; 1345 float mInitialTouchX, mInitialTouchY; 1346 int mTouchSlop; 1347 1348 public NotificationTriggerTouchListener() { 1349 mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); 1350 } 1351 1352 public boolean onTouch(View v, MotionEvent event) { 1353// Slog.d(TAG, String.format("touch: (%.1f, %.1f) initial: (%.1f, %.1f)", 1354// event.getX(), 1355// event.getY(), 1356// mInitialTouchX, 1357// mInitialTouchY)); 1358 final int action = event.getAction(); 1359 switch (action) { 1360 case MotionEvent.ACTION_DOWN: 1361 mVT = VelocityTracker.obtain(); 1362 mInitialTouchX = event.getX(); 1363 mInitialTouchY = event.getY(); 1364 // fall through 1365 case MotionEvent.ACTION_OUTSIDE: 1366 case MotionEvent.ACTION_MOVE: 1367 // check for fling 1368 if (mVT != null) { 1369 mVT.addMovement(event); 1370 mVT.computeCurrentVelocity(1000); // pixels per second 1371 // require a little more oomph once we're already in peekaboo mode 1372 if (mVT.getYVelocity() < -mNotificationFlingVelocity) { 1373 animateExpand(); 1374 mVT.recycle(); 1375 mVT = null; 1376 } 1377 } 1378 return true; 1379 case MotionEvent.ACTION_UP: 1380 case MotionEvent.ACTION_CANCEL: 1381 if (mVT != null) { 1382 if (action == MotionEvent.ACTION_UP 1383 // was this a sloppy tap? 1384 && Math.abs(event.getX() - mInitialTouchX) < mTouchSlop 1385 && Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3) 1386 // dragging off the bottom doesn't count 1387 && (int)event.getY() < v.getBottom()) { 1388 animateExpand(); 1389 v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); 1390 v.playSoundEffect(SoundEffectConstants.CLICK); 1391 } 1392 1393 mVT.recycle(); 1394 mVT = null; 1395 return true; 1396 } 1397 } 1398 return false; 1399 } 1400 } 1401 1402 final static int NOTIFICATION_PEEK_HOLD_THRESH = 200; // ms 1403 final static int NOTIFICATION_PEEK_FADE_DELAY = 3000; // ms 1404 1405 public void resetNotificationPeekFadeTimer() { 1406 if (DEBUG) { 1407 Slog.d(TAG, "setting peek fade timer for " + NOTIFICATION_PEEK_FADE_DELAY 1408 + "ms from now"); 1409 } 1410 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK); 1411 mHandler.sendEmptyMessageDelayed(MSG_CLOSE_NOTIFICATION_PEEK, 1412 NOTIFICATION_PEEK_FADE_DELAY); 1413 } 1414 1415 private class NotificationIconTouchListener implements View.OnTouchListener { 1416 VelocityTracker mVT; 1417 int mPeekIndex; 1418 float mInitialTouchX, mInitialTouchY; 1419 int mTouchSlop; 1420 1421 public NotificationIconTouchListener() { 1422 mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); 1423 } 1424 1425 public boolean onTouch(View v, MotionEvent event) { 1426 boolean peeking = mNotificationPeekWindow.getVisibility() != View.GONE; 1427 boolean panelShowing = mNotificationPanel.isShowing(); 1428 if (panelShowing) return false; 1429 1430 int numIcons = mIconLayout.getChildCount(); 1431 int newPeekIndex = (int)(event.getX() * numIcons / mIconLayout.getWidth()); 1432 if (newPeekIndex > numIcons - 1) newPeekIndex = numIcons - 1; 1433 else if (newPeekIndex < 0) newPeekIndex = 0; 1434 1435 final int action = event.getAction(); 1436 switch (action) { 1437 case MotionEvent.ACTION_DOWN: 1438 mVT = VelocityTracker.obtain(); 1439 mInitialTouchX = event.getX(); 1440 mInitialTouchY = event.getY(); 1441 mPeekIndex = -1; 1442 1443 // fall through 1444 case MotionEvent.ACTION_OUTSIDE: 1445 case MotionEvent.ACTION_MOVE: 1446 // peek and switch icons if necessary 1447 1448 if (newPeekIndex != mPeekIndex) { 1449 mPeekIndex = newPeekIndex; 1450 1451 if (DEBUG) Slog.d(TAG, "will peek at notification #" + mPeekIndex); 1452 Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK); 1453 peekMsg.arg1 = mPeekIndex; 1454 1455 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1456 1457 if (peeking) { 1458 // no delay if we're scrubbing left-right 1459 mHandler.sendMessage(peekMsg); 1460 } else { 1461 // wait for fling 1462 mHandler.sendMessageDelayed(peekMsg, NOTIFICATION_PEEK_HOLD_THRESH); 1463 } 1464 } 1465 1466 // check for fling 1467 if (mVT != null) { 1468 mVT.addMovement(event); 1469 mVT.computeCurrentVelocity(1000); // pixels per second 1470 // require a little more oomph once we're already in peekaboo mode 1471 if (!panelShowing && ( 1472 (peeking && mVT.getYVelocity() < -mNotificationFlingVelocity*3) 1473 || (mVT.getYVelocity() < -mNotificationFlingVelocity))) { 1474 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1475 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL); 1476 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK); 1477 mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL); 1478 } 1479 } 1480 return true; 1481 case MotionEvent.ACTION_UP: 1482 case MotionEvent.ACTION_CANCEL: 1483 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1484 if (!peeking) { 1485 if (action == MotionEvent.ACTION_UP 1486 // was this a sloppy tap? 1487 && Math.abs(event.getX() - mInitialTouchX) < mTouchSlop 1488 && Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3) 1489 // dragging off the bottom doesn't count 1490 && (int)event.getY() < v.getBottom()) { 1491 Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK); 1492 peekMsg.arg1 = mPeekIndex; 1493 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK); 1494 mHandler.sendMessage(peekMsg); 1495 1496 v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); 1497 v.playSoundEffect(SoundEffectConstants.CLICK); 1498 1499 peeking = true; // not technically true yet, but the next line will run 1500 } 1501 } 1502 1503 if (peeking) { 1504 resetNotificationPeekFadeTimer(); 1505 } 1506 1507 mVT.recycle(); 1508 mVT = null; 1509 return true; 1510 } 1511 return false; 1512 } 1513 } 1514 1515 StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) { 1516 if (DEBUG) { 1517 Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification); 1518 } 1519 // Construct the icon. 1520 final StatusBarIconView iconView = new StatusBarIconView(mContext, 1521 notification.pkg + "/0x" + Integer.toHexString(notification.id), 1522 notification.notification); 1523 iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 1524 1525 final StatusBarIcon ic = new StatusBarIcon(notification.pkg, 1526 notification.notification.icon, 1527 notification.notification.iconLevel, 1528 notification.notification.number, 1529 notification.notification.tickerText); 1530 if (!iconView.set(ic)) { 1531 handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic); 1532 return null; 1533 } 1534 // Construct the expanded view. 1535 NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView); 1536 if (!inflateViews(entry, mPile)) { 1537 handleNotificationError(key, notification, "Couldn't expand RemoteViews for: " 1538 + notification); 1539 return null; 1540 } 1541 1542 // Add the icon. 1543 int pos = mNotificationData.add(entry); 1544 if (DEBUG) { 1545 Slog.d(TAG, "addNotificationViews: added at " + pos); 1546 } 1547 updateNotificationIcons(); 1548 1549 return iconView; 1550 } 1551 1552 private void reloadAllNotificationIcons() { 1553 if (mIconLayout == null) return; 1554 mIconLayout.removeAllViews(); 1555 updateNotificationIcons(); 1556 } 1557 1558 private void updateNotificationIcons() { 1559 // XXX: need to implement a new limited linear layout class 1560 // to avoid removing & readding everything 1561 1562 if (mIconLayout == null) return; 1563 1564 // first, populate the main notification panel 1565 loadNotificationPanel(); 1566 1567 final LinearLayout.LayoutParams params 1568 = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight); 1569 1570 // alternate behavior in DND mode 1571 if (mNotificationDNDMode) { 1572 if (mIconLayout.getChildCount() == 0) { 1573 final Notification dndNotification = new Notification.Builder(mContext) 1574 .setContentTitle(mContext.getText(R.string.notifications_off_title)) 1575 .setContentText(mContext.getText(R.string.notifications_off_text)) 1576 .setSmallIcon(R.drawable.ic_notification_dnd) 1577 .setOngoing(true) 1578 .getNotification(); 1579 1580 final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd", 1581 dndNotification); 1582 iconView.setImageResource(R.drawable.ic_notification_dnd); 1583 iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 1584 iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0); 1585 1586 mNotificationDNDDummyEntry = new NotificationData.Entry( 1587 null, 1588 new StatusBarNotification("", 0, "", 0, 0, dndNotification), 1589 iconView); 1590 1591 mIconLayout.addView(iconView, params); 1592 } 1593 1594 return; 1595 } else if (0 != (mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS)) { 1596 // if icons are disabled but we're not in DND mode, this is probably Setup and we should 1597 // just leave the area totally empty 1598 return; 1599 } 1600 1601 int N = mNotificationData.size(); 1602 1603 if (DEBUG) { 1604 Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout); 1605 } 1606 1607 ArrayList<View> toShow = new ArrayList<View>(); 1608 1609 // Extra Special Icons 1610 // The IME switcher and compatibility mode icons take the place of notifications. You didn't 1611 // need to see all those new emails, did you? 1612 int maxNotificationIconsCount = mMaxNotificationIcons; 1613 if (mInputMethodSwitchButton.getVisibility() != View.GONE) maxNotificationIconsCount --; 1614 if (mCompatModeButton.getVisibility() != View.GONE) maxNotificationIconsCount --; 1615 1616 for (int i=0; i< maxNotificationIconsCount; i++) { 1617 if (i>=N) break; 1618 toShow.add(mNotificationData.get(N-i-1).icon); 1619 } 1620 1621 ArrayList<View> toRemove = new ArrayList<View>(); 1622 for (int i=0; i<mIconLayout.getChildCount(); i++) { 1623 View child = mIconLayout.getChildAt(i); 1624 if (!toShow.contains(child)) { 1625 toRemove.add(child); 1626 } 1627 } 1628 1629 for (View remove : toRemove) { 1630 mIconLayout.removeView(remove); 1631 } 1632 1633 for (int i=0; i<toShow.size(); i++) { 1634 View v = toShow.get(i); 1635 v.setPadding(mIconHPadding, 0, mIconHPadding, 0); 1636 if (v.getParent() == null) { 1637 mIconLayout.addView(v, i, params); 1638 } 1639 } 1640 } 1641 1642 private void loadNotificationPanel() { 1643 int N = mNotificationData.size(); 1644 1645 ArrayList<View> toShow = new ArrayList<View>(); 1646 1647 for (int i=0; i<N; i++) { 1648 View row = mNotificationData.get(N-i-1).row; 1649 toShow.add(row); 1650 } 1651 1652 ArrayList<View> toRemove = new ArrayList<View>(); 1653 for (int i=0; i<mPile.getChildCount(); i++) { 1654 View child = mPile.getChildAt(i); 1655 if (!toShow.contains(child)) { 1656 toRemove.add(child); 1657 } 1658 } 1659 1660 for (View remove : toRemove) { 1661 mPile.removeView(remove); 1662 } 1663 1664 for (int i=0; i<toShow.size(); i++) { 1665 View v = toShow.get(i); 1666 if (v.getParent() == null) { 1667 mPile.addView(v, N-1-i); // the notification panel has newest at the bottom 1668 } 1669 } 1670 1671 mNotificationPanel.setNotificationCount(N); 1672 } 1673 1674 void workAroundBadLayerDrawableOpacity(View v) { 1675 LayerDrawable d = (LayerDrawable)v.getBackground(); 1676 if (d == null) return; 1677 v.setBackgroundDrawable(null); 1678 d.setOpacity(PixelFormat.TRANSLUCENT); 1679 v.setBackgroundDrawable(d); 1680 } 1681 1682 private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) { 1683 StatusBarNotification sbn = entry.notification; 1684 RemoteViews remoteViews = sbn.notification.contentView; 1685 if (remoteViews == null) { 1686 return false; 1687 } 1688 1689 // create the row view 1690 LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( 1691 Context.LAYOUT_INFLATER_SERVICE); 1692 View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false); 1693 workAroundBadLayerDrawableOpacity(row); 1694 View vetoButton = row.findViewById(R.id.veto); 1695 if (entry.notification.isClearable()) { 1696 final String _pkg = sbn.pkg; 1697 final String _tag = sbn.tag; 1698 final int _id = sbn.id; 1699 vetoButton.setOnClickListener(new View.OnClickListener() { 1700 public void onClick(View v) { 1701 try { 1702 mBarService.onNotificationClear(_pkg, _tag, _id); 1703 } catch (RemoteException ex) { 1704 // system process is dead if we're here. 1705 } 1706 } 1707 }); 1708 } else { 1709 if ((sbn.notification.flags & Notification.FLAG_ONGOING_EVENT) == 0) { 1710 vetoButton.setVisibility(View.INVISIBLE); 1711 vetoButton.setContentDescription("VETO"); 1712 } else { 1713 vetoButton.setVisibility(View.GONE); 1714 } 1715 } 1716 vetoButton.setContentDescription(mContext.getString( 1717 R.string.accessibility_remove_notification)); 1718 1719 // the large icon 1720 ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon); 1721 if (sbn.notification.largeIcon != null) { 1722 largeIcon.setImageBitmap(sbn.notification.largeIcon); 1723 largeIcon.setContentDescription(sbn.notification.tickerText); 1724 } else { 1725 largeIcon.getLayoutParams().width = 0; 1726 largeIcon.setVisibility(View.INVISIBLE); 1727 } 1728 largeIcon.setContentDescription(sbn.notification.tickerText); 1729 1730 // bind the click event to the content area 1731 ViewGroup content = (ViewGroup)row.findViewById(R.id.content); 1732 // XXX: update to allow controls within notification views 1733 content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 1734// content.setOnFocusChangeListener(mFocusChangeListener); 1735 PendingIntent contentIntent = sbn.notification.contentIntent; 1736 if (contentIntent != null) { 1737 content.setOnClickListener(new NotificationClicker(contentIntent, 1738 sbn.pkg, sbn.tag, sbn.id)); 1739 } else { 1740 content.setOnClickListener(null); 1741 } 1742 1743 View expanded = null; 1744 Exception exception = null; 1745 try { 1746 expanded = remoteViews.apply(mContext, content); 1747 } 1748 catch (RuntimeException e) { 1749 exception = e; 1750 } 1751 if (expanded == null) { 1752 final String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id); 1753 Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); 1754 return false; 1755 } else { 1756 content.addView(expanded); 1757 row.setDrawingCacheEnabled(true); 1758 } 1759 1760 entry.row = row; 1761 entry.content = content; 1762 entry.expanded = expanded; 1763 entry.largeIcon = largeIcon; 1764 1765 return true; 1766 } 1767 1768 public void clearAll() { 1769 try { 1770 mBarService.onClearAllNotifications(); 1771 } catch (RemoteException ex) { 1772 // system process is dead if we're here. 1773 } 1774 animateCollapse(); 1775 } 1776 1777 public void userActivity() { 1778 } 1779 1780 public void toggleRecentApps() { 1781 int msg = (mRecentsPanel.getVisibility() == View.GONE) 1782 ? MSG_OPEN_RECENTS_PANEL : MSG_CLOSE_RECENTS_PANEL; 1783 mHandler.removeMessages(msg); 1784 mHandler.sendEmptyMessage(msg); 1785 } 1786 1787 public class TouchOutsideListener implements View.OnTouchListener { 1788 private int mMsg; 1789 private StatusBarPanel mPanel; 1790 1791 public TouchOutsideListener(int msg, StatusBarPanel panel) { 1792 mMsg = msg; 1793 mPanel = panel; 1794 } 1795 1796 public boolean onTouch(View v, MotionEvent ev) { 1797 final int action = ev.getAction(); 1798 if (action == MotionEvent.ACTION_OUTSIDE 1799 || (action == MotionEvent.ACTION_DOWN 1800 && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) { 1801 mHandler.removeMessages(mMsg); 1802 mHandler.sendEmptyMessage(mMsg); 1803 return true; 1804 } 1805 return false; 1806 } 1807 } 1808 1809 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 1810 pw.print("mDisabled=0x"); 1811 pw.println(Integer.toHexString(mDisabled)); 1812 pw.println("mNetworkController:"); 1813 mNetworkController.dump(fd, pw, args); 1814 } 1815} 1816 1817 1818