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