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