PhoneStatusBar.java revision d5ef54658ba7f869b1558df656772eebc3fb7328
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.phone; 18 19import android.animation.Animator; 20import android.animation.Animator.AnimatorListener; 21import android.animation.AnimatorListenerAdapter; 22import android.animation.AnimatorSet; 23import android.animation.ObjectAnimator; 24import android.app.ActivityManager; 25import android.app.ActivityManagerNative; 26import android.app.Dialog; 27import android.app.KeyguardManager; 28import android.app.Notification; 29import android.app.PendingIntent; 30import android.app.StatusBarManager; 31import android.content.BroadcastReceiver; 32import android.content.Context; 33import android.content.Intent; 34import android.content.IntentFilter; 35import android.content.res.Configuration; 36import android.content.res.Resources; 37import android.graphics.Canvas; 38import android.graphics.ColorFilter; 39import android.graphics.PixelFormat; 40import android.graphics.PorterDuff; 41import android.graphics.Rect; 42import android.graphics.drawable.Drawable; 43import android.graphics.drawable.NinePatchDrawable; 44import android.inputmethodservice.InputMethodService; 45import android.os.IBinder; 46import android.os.Message; 47import android.os.RemoteException; 48import android.os.ServiceManager; 49import android.os.SystemClock; 50import android.provider.Settings; 51import android.util.DisplayMetrics; 52import android.util.Log; 53import android.util.Slog; 54import android.view.Choreographer; 55import android.view.Display; 56import android.view.Gravity; 57import android.view.IWindowManager; 58import android.view.KeyEvent; 59import android.view.MotionEvent; 60import android.view.VelocityTracker; 61import android.view.View; 62import android.view.ViewGroup; 63import android.view.ViewGroup.LayoutParams; 64import android.view.WindowManager; 65import android.view.WindowManagerImpl; 66import android.view.animation.AccelerateInterpolator; 67import android.view.animation.Animation; 68import android.view.animation.AnimationUtils; 69import android.view.animation.DecelerateInterpolator; 70import android.widget.FrameLayout; 71import android.widget.ImageView; 72import android.widget.LinearLayout; 73import android.widget.ScrollView; 74import android.widget.TextView; 75import com.android.internal.statusbar.StatusBarIcon; 76import com.android.internal.statusbar.StatusBarNotification; 77import com.android.systemui.R; 78import com.android.systemui.recent.RecentTasksLoader; 79import com.android.systemui.statusbar.BaseStatusBar; 80import com.android.systemui.statusbar.NotificationData; 81import com.android.systemui.statusbar.NotificationData.Entry; 82import com.android.systemui.statusbar.CommandQueue; 83import com.android.systemui.statusbar.RotationToggle; 84import com.android.systemui.statusbar.SignalClusterView; 85import com.android.systemui.statusbar.StatusBarIconView; 86import com.android.systemui.statusbar.policy.BatteryController; 87import com.android.systemui.statusbar.policy.DateView; 88import com.android.systemui.statusbar.policy.IntruderAlertView; 89import com.android.systemui.statusbar.policy.LocationController; 90import com.android.systemui.statusbar.policy.OnSizeChangedListener; 91import com.android.systemui.statusbar.policy.NetworkController; 92import com.android.systemui.statusbar.policy.NotificationRowLayout; 93 94import java.io.FileDescriptor; 95import java.io.PrintWriter; 96import java.util.ArrayList; 97 98public class PhoneStatusBar extends BaseStatusBar { 99 static final String TAG = "PhoneStatusBar"; 100 public static final boolean DEBUG = false; 101 public static final boolean SPEW = DEBUG; 102 public static final boolean DUMPTRUCK = true; // extra dumpsys info 103 104 // additional instrumentation for testing purposes; intended to be left on during development 105 public static final boolean CHATTY = DEBUG; 106 107 public static final String ACTION_STATUSBAR_START 108 = "com.android.internal.policy.statusbar.START"; 109 110 private static final boolean DIM_BEHIND_EXPANDED_PANEL = true; 111 private static final boolean SHOW_CARRIER_LABEL = true; 112 113 private static final int MSG_OPEN_NOTIFICATION_PANEL = 1000; 114 private static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001; 115 // 1020-1030 reserved for BaseStatusBar 116 117 // will likely move to a resource or other tunable param at some point 118 private static final int INTRUDER_ALERT_DECAY_MS = 0; // disabled, was 10000; 119 120 private static final boolean CLOSE_PANEL_WHEN_EMPTIED = true; 121 122 private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10; // see NotificationManagerService 123 private static final int HIDE_ICONS_BELOW_SCORE = Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER; 124 125 // fling gesture tuning parameters, scaled to display density 126 private float mSelfExpandVelocityPx; // classic value: 2000px/s 127 private float mSelfCollapseVelocityPx; // classic value: 2000px/s (will be negated to collapse "up") 128 private float mFlingExpandMinVelocityPx; // classic value: 200px/s 129 private float mFlingCollapseMinVelocityPx; // classic value: 200px/s 130 private float mCollapseMinDisplayFraction; // classic value: 0.08 (25px/min(320px,480px) on G1) 131 private float mExpandMinDisplayFraction; // classic value: 0.5 (drag open halfway to expand) 132 private float mFlingGestureMaxXVelocityPx; // classic value: 150px/s 133 134 private float mExpandAccelPx; // classic value: 2000px/s/s 135 private float mCollapseAccelPx; // classic value: 2000px/s/s (will be negated to collapse "up") 136 137 private float mFlingGestureMaxOutputVelocityPx; // how fast can it really go? (should be a little 138 // faster than mSelfCollapseVelocityPx) 139 140 PhoneStatusBarPolicy mIconPolicy; 141 142 // These are no longer handled by the policy, because we need custom strategies for them 143 BatteryController mBatteryController; 144 LocationController mLocationController; 145 NetworkController mNetworkController; 146 147 int mNaturalBarHeight = -1; 148 int mIconSize = -1; 149 int mIconHPadding = -1; 150 Display mDisplay; 151 152 IWindowManager mWindowManager; 153 154 StatusBarWindowView mStatusBarWindow; 155 PhoneStatusBarView mStatusBarView; 156 157 int mPixelFormat; 158 Object mQueueLock = new Object(); 159 160 // icons 161 LinearLayout mIcons; 162 IconMerger mNotificationIcons; 163 View mMoreIcon; 164 LinearLayout mStatusIcons; 165 166 // expanded notifications 167 View mNotificationPanel; // the sliding/resizing panel within the notification window 168 ScrollView mScrollView; 169 View mExpandedContents; 170 int mNotificationPanelMarginBottomPx, mNotificationPanelMarginLeftPx; 171 final Rect mNotificationPanelBackgroundPadding = new Rect(); 172 int mNotificationPanelGravity; 173 int mNotificationPanelMinHeight; 174 175 // top bar 176 View mClearButton; 177 View mSettingsButton; 178 RotationToggle mRotationButton; 179 180 // carrier/wifi label 181 private TextView mCarrierLabel; 182 private boolean mCarrierLabelVisible = false; 183 private int mCarrierLabelHeight; 184 185 // drag bar 186 CloseDragHandle mCloseView; 187 private int mCloseViewHeight; 188 189 // position 190 int[] mPositionTmp = new int[2]; 191 boolean mExpanded; 192 boolean mExpandedVisible; 193 194 // the date view 195 DateView mDateView; 196 197 // for immersive activities 198 private IntruderAlertView mIntruderAlertView; 199 200 // on-screen navigation buttons 201 private NavigationBarView mNavigationBarView = null; 202 203 // the tracker view 204 int mTrackingPosition; // the position of the top of the tracking view. 205 private boolean mPanelSlightlyVisible; 206 207 // ticker 208 private Ticker mTicker; 209 private View mTickerView; 210 private boolean mTicking; 211 212 // Tracking finger for opening/closing. 213 int mEdgeBorder; // corresponds to R.dimen.status_bar_edge_ignore 214 boolean mTracking; 215 VelocityTracker mVelocityTracker; 216 217 Choreographer mChoreographer; 218 boolean mAnimating; 219 boolean mClosing; // only valid when mAnimating; indicates the initial acceleration 220 float mAnimY; 221 float mAnimVel; 222 float mAnimAccel; 223 long mAnimLastTimeNanos; 224 boolean mAnimatingReveal = false; 225 int mViewDelta; 226 float mFlingVelocity; 227 int mFlingY; 228 int[] mAbsPos = new int[2]; 229 Runnable mPostCollapseCleanup = null; 230 231 private AnimatorSet mLightsOutAnimation; 232 private AnimatorSet mLightsOnAnimation; 233 234 // for disabling the status bar 235 int mDisabled = 0; 236 237 // tracking calls to View.setSystemUiVisibility() 238 int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE; 239 240 DisplayMetrics mDisplayMetrics = new DisplayMetrics(); 241 242 private int mNavigationIconHints = 0; 243 private final Animator.AnimatorListener mMakeIconsInvisible = new AnimatorListenerAdapter() { 244 @Override 245 public void onAnimationEnd(Animator animation) { 246 // double-check to avoid races 247 if (mIcons.getAlpha() == 0) { 248 Slog.d(TAG, "makeIconsInvisible"); 249 mIcons.setVisibility(View.INVISIBLE); 250 } 251 } 252 }; 253 254 private final Runnable mStartRevealAnimation = new Runnable() { 255 @Override 256 public void run() { 257 mAnimAccel = mExpandAccelPx; 258 mAnimVel = mFlingExpandMinVelocityPx; 259 mAnimY = getStatusBarHeight(); 260 updateExpandedViewPos((int)mAnimY); 261 262 mAnimating = true; 263 mAnimatingReveal = true; 264 resetLastAnimTime(); 265 mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, 266 mAnimationCallback, null); 267 mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, 268 mRevealAnimationCallback, null); 269 mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, 270 mRevealAnimationCallback, null); 271 } 272 }; 273 274 private final Runnable mPerformSelfExpandFling = new Runnable() { 275 @Override 276 public void run() { 277 performFling(0, mSelfExpandVelocityPx, true); 278 } 279 }; 280 281 private final Runnable mPerformFling = new Runnable() { 282 @Override 283 public void run() { 284 performFling(mFlingY + mViewDelta, mFlingVelocity, false); 285 } 286 }; 287 288 private class ExpandedDialog extends Dialog { 289 ExpandedDialog(Context context) { 290 super(context, com.android.internal.R.style.Theme_Translucent_NoTitleBar); 291 } 292 293 @Override 294 public boolean dispatchKeyEvent(KeyEvent event) { 295 boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 296 switch (event.getKeyCode()) { 297 case KeyEvent.KEYCODE_BACK: 298 if (!down) { 299 animateCollapse(); 300 } 301 return true; 302 } 303 return super.dispatchKeyEvent(event); 304 } 305 } 306 307 @Override 308 public void start() { 309 mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) 310 .getDefaultDisplay(); 311 312 mWindowManager = IWindowManager.Stub.asInterface( 313 ServiceManager.getService(Context.WINDOW_SERVICE)); 314 315 super.start(); // calls createAndAddWindows() 316 317 addNavigationBar(); 318 319 if (ENABLE_INTRUDERS) addIntruderView(); 320 321 // Lastly, call to the icon policy to install/update all the icons. 322 mIconPolicy = new PhoneStatusBarPolicy(mContext); 323 } 324 325 // ================================================================================ 326 // Constructing the view 327 // ================================================================================ 328 protected PhoneStatusBarView makeStatusBarView() { 329 final Context context = mContext; 330 331 Resources res = context.getResources(); 332 333 updateDisplaySize(); // populates mDisplayMetrics 334 loadDimens(); 335 336 mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); 337 338 mStatusBarWindow = (StatusBarWindowView) View.inflate(context, 339 R.layout.super_status_bar, null); 340 if (DEBUG) { 341 mStatusBarWindow.setBackgroundColor(0x6000FF80); 342 } 343 mStatusBarWindow.mService = this; 344 mStatusBarWindow.setOnTouchListener(new View.OnTouchListener() { 345 @Override 346 public boolean onTouch(View v, MotionEvent event) { 347 if (event.getAction() == MotionEvent.ACTION_DOWN) { 348 if (mExpanded && !mAnimating) { 349 animateCollapse(); 350 } 351 } 352 return mStatusBarWindow.onTouchEvent(event); 353 }}); 354 355 mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar); 356 mNotificationPanel = mStatusBarWindow.findViewById(R.id.notification_panel); 357 // don't allow clicks on the panel to pass through to the background where they will cause the panel to close 358 mNotificationPanel.setOnTouchListener(new View.OnTouchListener() { 359 @Override 360 public boolean onTouch(View v, MotionEvent event) { 361 return true; 362 } 363 }); 364 mNotificationPanel.setSystemUiVisibility( 365 View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER 366 | View.STATUS_BAR_DISABLE_SYSTEM_INFO); 367 368 if (!ActivityManager.isHighEndGfx(mDisplay)) { 369 mStatusBarWindow.setBackground(null); 370 mNotificationPanel.setBackground(new FastColorDrawable(context.getResources().getColor( 371 R.color.notification_panel_solid_background))); 372 } 373 if (ENABLE_INTRUDERS) { 374 mIntruderAlertView = (IntruderAlertView) View.inflate(context, R.layout.intruder_alert, null); 375 mIntruderAlertView.setVisibility(View.GONE); 376 mIntruderAlertView.setBar(this); 377 } 378 379 updateShowSearchHoldoff(); 380 381 mStatusBarView.mService = this; 382 383 mChoreographer = Choreographer.getInstance(); 384 385 try { 386 boolean showNav = mWindowManager.hasNavigationBar(); 387 if (DEBUG) Slog.v(TAG, "hasNavigationBar=" + showNav); 388 if (showNav) { 389 mNavigationBarView = 390 (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null); 391 392 mNavigationBarView.setDisabledFlags(mDisabled); 393 mNavigationBarView.setBar(this); 394 } 395 } catch (RemoteException ex) { 396 // no window manager? good luck with that 397 } 398 399 // figure out which pixel-format to use for the status bar. 400 mPixelFormat = PixelFormat.OPAQUE; 401 mStatusIcons = (LinearLayout)mStatusBarView.findViewById(R.id.statusIcons); 402 mNotificationIcons = (IconMerger)mStatusBarView.findViewById(R.id.notificationIcons); 403 mNotificationIcons.setOverflowIndicator(mMoreIcon); 404 mIcons = (LinearLayout)mStatusBarView.findViewById(R.id.icons); 405 mTickerView = mStatusBarView.findViewById(R.id.ticker); 406 407 mPile = (NotificationRowLayout)mStatusBarWindow.findViewById(R.id.latestItems); 408 mPile.setLayoutTransitionsEnabled(false); 409 mPile.setLongPressListener(getNotificationLongClicker()); 410 if (SHOW_CARRIER_LABEL) { 411 mPile.setOnSizeChangedListener(new OnSizeChangedListener() { 412 @Override 413 public void onSizeChanged(View view, int w, int h, int oldw, int oldh) { 414 updateCarrierLabelVisibility(false); 415 } 416 }); 417 } 418 mExpandedContents = mPile; // was: expanded.findViewById(R.id.notificationLinearLayout); 419 420 mClearButton = mStatusBarWindow.findViewById(R.id.clear_all_button); 421 mClearButton.setOnClickListener(mClearButtonListener); 422 mClearButton.setAlpha(0f); 423 mClearButton.setVisibility(View.INVISIBLE); 424 mClearButton.setEnabled(false); 425 mDateView = (DateView)mStatusBarWindow.findViewById(R.id.date); 426 mSettingsButton = mStatusBarWindow.findViewById(R.id.settings_button); 427 mSettingsButton.setOnClickListener(mSettingsButtonListener); 428 mRotationButton = (RotationToggle) mStatusBarWindow.findViewById(R.id.rotation_lock_button); 429 430 mCarrierLabel = (TextView)mStatusBarWindow.findViewById(R.id.carrier_label); 431 mCarrierLabel.setVisibility(mCarrierLabelVisible ? View.VISIBLE : View.INVISIBLE); 432 433 mScrollView = (ScrollView)mStatusBarWindow.findViewById(R.id.scroll); 434 mScrollView.setVerticalScrollBarEnabled(false); // less drawing during pulldowns 435 436 mTicker = new MyTicker(context, mStatusBarView); 437 438 TickerView tickerView = (TickerView)mStatusBarView.findViewById(R.id.tickerText); 439 tickerView.mTicker = mTicker; 440 441 mCloseView = (CloseDragHandle)mStatusBarWindow.findViewById(R.id.close); 442 mCloseView.mService = this; 443 mCloseViewHeight = res.getDimensionPixelSize(R.dimen.close_handle_height); 444 445 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore); 446 447 // set the inital view visibility 448 setAreThereNotifications(); 449 450 // Other icons 451 mLocationController = new LocationController(mContext); // will post a notification 452 mBatteryController = new BatteryController(mContext); 453 mBatteryController.addIconView((ImageView)mStatusBarView.findViewById(R.id.battery)); 454 mNetworkController = new NetworkController(mContext); 455 final SignalClusterView signalCluster = 456 (SignalClusterView)mStatusBarView.findViewById(R.id.signal_cluster); 457 458 mNetworkController.addSignalCluster(signalCluster); 459 signalCluster.setNetworkController(mNetworkController); 460 461 if (SHOW_CARRIER_LABEL) { 462 // for wifi-only devices, we show SSID; otherwise, we show PLMN 463 if (mNetworkController.hasMobileDataFeature()) { 464 mNetworkController.addMobileLabelView(mCarrierLabel); 465 } else { 466 mNetworkController.addWifiLabelView(mCarrierLabel); 467 } 468 } 469 470// final ImageView wimaxRSSI = 471// (ImageView)sb.findViewById(R.id.wimax_signal); 472// if (wimaxRSSI != null) { 473// mNetworkController.addWimaxIconView(wimaxRSSI); 474// } 475 // Recents Panel 476 mRecentTasksLoader = new RecentTasksLoader(context); 477 updateRecentsPanel(); 478 479 // receive broadcasts 480 IntentFilter filter = new IntentFilter(); 481 filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); 482 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 483 filter.addAction(Intent.ACTION_SCREEN_OFF); 484 context.registerReceiver(mBroadcastReceiver, filter); 485 486 return mStatusBarView; 487 } 488 489 @Override 490 protected WindowManager.LayoutParams getRecentsLayoutParams(LayoutParams layoutParams) { 491 boolean opaque = false; 492 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 493 layoutParams.width, 494 layoutParams.height, 495 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 496 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 497 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 498 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 499 (opaque ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT)); 500 if (ActivityManager.isHighEndGfx(mDisplay)) { 501 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 502 } else { 503 lp.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND; 504 lp.dimAmount = 0.75f; 505 } 506 lp.gravity = Gravity.BOTTOM | Gravity.LEFT; 507 lp.setTitle("RecentsPanel"); 508 lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications; 509 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 510 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 511 return lp; 512 } 513 514 @Override 515 protected WindowManager.LayoutParams getSearchLayoutParams(LayoutParams layoutParams) { 516 boolean opaque = false; 517 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 518 LayoutParams.MATCH_PARENT, 519 LayoutParams.MATCH_PARENT, 520 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, 521 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 522 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 523 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 524 (opaque ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT)); 525 if (ActivityManager.isHighEndGfx(mDisplay)) { 526 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 527 } 528 lp.gravity = Gravity.BOTTOM | Gravity.LEFT; 529 lp.setTitle("SearchPanel"); 530 // TODO: Define custom animation for Search panel 531 lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications; 532 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 533 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 534 return lp; 535 } 536 537 protected void updateRecentsPanel() { 538 super.updateRecentsPanel(R.layout.status_bar_recent_panel); 539 // Make .03 alpha the minimum so you always see the item a bit-- slightly below 540 // .03, the item disappears entirely (as if alpha = 0) and that discontinuity looks 541 // a bit jarring 542 mRecentsPanel.setMinSwipeAlpha(0.03f); 543 if (mNavigationBarView != null) { 544 mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPanel); 545 } 546 } 547 548 @Override 549 protected void updateSearchPanel() { 550 super.updateSearchPanel(); 551 mSearchPanelView.setStatusBarView(mNavigationBarView); 552 mNavigationBarView.setDelegateView(mSearchPanelView); 553 } 554 555 @Override 556 public void showSearchPanel() { 557 super.showSearchPanel(); 558 WindowManager.LayoutParams lp = 559 (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams(); 560 lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; 561 WindowManagerImpl.getDefault().updateViewLayout(mNavigationBarView, lp); 562 } 563 564 @Override 565 public void hideSearchPanel() { 566 super.hideSearchPanel(); 567 WindowManager.LayoutParams lp = 568 (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams(); 569 lp.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; 570 WindowManagerImpl.getDefault().updateViewLayout(mNavigationBarView, lp); 571 } 572 573 protected int getStatusBarGravity() { 574 return Gravity.TOP | Gravity.FILL_HORIZONTAL; 575 } 576 577 public int getStatusBarHeight() { 578 if (mNaturalBarHeight < 0) { 579 final Resources res = mContext.getResources(); 580 mNaturalBarHeight = 581 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); 582 } 583 return mNaturalBarHeight; 584 } 585 586 private int getCloseViewHeight() { 587 return mCloseViewHeight; 588 } 589 590 private View.OnClickListener mRecentsClickListener = new View.OnClickListener() { 591 public void onClick(View v) { 592 toggleRecentApps(); 593 } 594 }; 595 596 private int mShowSearchHoldoff = 0; 597 private Runnable mShowSearchPanel = new Runnable() { 598 public void run() { 599 showSearchPanel(); 600 } 601 }; 602 603 View.OnTouchListener mHomeSearchActionListener = new View.OnTouchListener() { 604 public boolean onTouch(View v, MotionEvent event) { 605 switch(event.getAction()) { 606 case MotionEvent.ACTION_DOWN: 607 if (!shouldDisableNavbarGestures()) { 608 mHandler.removeCallbacks(mShowSearchPanel); 609 mHandler.postDelayed(mShowSearchPanel, mShowSearchHoldoff); 610 } 611 break; 612 613 case MotionEvent.ACTION_UP: 614 case MotionEvent.ACTION_CANCEL: 615 mHandler.removeCallbacks(mShowSearchPanel); 616 break; 617 } 618 return false; 619 } 620 }; 621 622 private void prepareNavigationBarView() { 623 mNavigationBarView.reorient(); 624 625 mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener); 626 mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPanel); 627 mNavigationBarView.getHomeButton().setOnTouchListener(mHomeSearchActionListener); 628 updateSearchPanel(); 629 } 630 631 // For small-screen devices (read: phones) that lack hardware navigation buttons 632 private void addNavigationBar() { 633 if (DEBUG) Slog.v(TAG, "addNavigationBar: about to add " + mNavigationBarView); 634 if (mNavigationBarView == null) return; 635 636 prepareNavigationBarView(); 637 638 WindowManagerImpl.getDefault().addView( 639 mNavigationBarView, getNavigationBarLayoutParams()); 640 } 641 642 private void repositionNavigationBar() { 643 if (mNavigationBarView == null) return; 644 645 prepareNavigationBarView(); 646 647 WindowManagerImpl.getDefault().updateViewLayout( 648 mNavigationBarView, getNavigationBarLayoutParams()); 649 } 650 651 private WindowManager.LayoutParams getNavigationBarLayoutParams() { 652 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 653 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 654 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, 655 0 656 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING 657 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 658 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 659 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 660 PixelFormat.OPAQUE); 661 // this will allow the navbar to run in an overlay on devices that support this 662 if (ActivityManager.isHighEndGfx(mDisplay)) { 663 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 664 } 665 666 lp.setTitle("NavigationBar"); 667 lp.windowAnimations = 0; 668 return lp; 669 } 670 671 private void addIntruderView() { 672 final int height = getStatusBarHeight(); 673 674 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 675 ViewGroup.LayoutParams.MATCH_PARENT, 676 ViewGroup.LayoutParams.WRAP_CONTENT, 677 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, // above the status bar! 678 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 679 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 680 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 681 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 682 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 683 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 684 PixelFormat.TRANSLUCENT); 685 lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL; 686 //lp.y += height * 1.5; // FIXME 687 lp.setTitle("IntruderAlert"); 688 lp.packageName = mContext.getPackageName(); 689 lp.windowAnimations = R.style.Animation_StatusBar_IntruderAlert; 690 691 WindowManagerImpl.getDefault().addView(mIntruderAlertView, lp); 692 } 693 694 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) { 695 if (SPEW) Slog.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex 696 + " icon=" + icon); 697 StatusBarIconView view = new StatusBarIconView(mContext, slot, null); 698 view.set(icon); 699 mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(mIconSize, mIconSize)); 700 } 701 702 public void updateIcon(String slot, int index, int viewIndex, 703 StatusBarIcon old, StatusBarIcon icon) { 704 if (SPEW) Slog.d(TAG, "updateIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex 705 + " old=" + old + " icon=" + icon); 706 StatusBarIconView view = (StatusBarIconView)mStatusIcons.getChildAt(viewIndex); 707 view.set(icon); 708 } 709 710 public void removeIcon(String slot, int index, int viewIndex) { 711 if (SPEW) Slog.d(TAG, "removeIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex); 712 mStatusIcons.removeViewAt(viewIndex); 713 } 714 715 public void addNotification(IBinder key, StatusBarNotification notification) { 716 /* if (DEBUG) */ Slog.d(TAG, "addNotification score=" + notification.score); 717 StatusBarIconView iconView = addNotificationViews(key, notification); 718 if (iconView == null) return; 719 720 boolean immersive = false; 721 try { 722 immersive = ActivityManagerNative.getDefault().isTopActivityImmersive(); 723 if (DEBUG) { 724 Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); 725 } 726 } catch (RemoteException ex) { 727 } 728 729 /* 730 * DISABLED due to missing API 731 if (ENABLE_INTRUDERS && ( 732 // TODO(dsandler): Only if the screen is on 733 notification.notification.intruderView != null)) { 734 Slog.d(TAG, "Presenting high-priority notification"); 735 // special new transient ticker mode 736 // 1. Populate mIntruderAlertView 737 738 if (notification.notification.intruderView == null) { 739 Slog.e(TAG, notification.notification.toString() + " wanted to intrude but intruderView was null"); 740 return; 741 } 742 743 // bind the click event to the content area 744 PendingIntent contentIntent = notification.notification.contentIntent; 745 final View.OnClickListener listener = (contentIntent != null) 746 ? new NotificationClicker(contentIntent, 747 notification.pkg, notification.tag, notification.id) 748 : null; 749 750 mIntruderAlertView.applyIntruderContent(notification.notification.intruderView, listener); 751 752 mCurrentlyIntrudingNotification = notification; 753 754 // 2. Animate mIntruderAlertView in 755 mHandler.sendEmptyMessage(MSG_SHOW_INTRUDER); 756 757 // 3. Set alarm to age the notification off (TODO) 758 mHandler.removeMessages(MSG_HIDE_INTRUDER); 759 if (INTRUDER_ALERT_DECAY_MS > 0) { 760 mHandler.sendEmptyMessageDelayed(MSG_HIDE_INTRUDER, INTRUDER_ALERT_DECAY_MS); 761 } 762 } else 763 */ 764 765 if (notification.notification.fullScreenIntent != null) { 766 // not immersive & a full-screen alert should be shown 767 Slog.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent"); 768 try { 769 notification.notification.fullScreenIntent.send(); 770 } catch (PendingIntent.CanceledException e) { 771 } 772 } else { 773 // usual case: status bar visible & not immersive 774 775 // show the ticker if there isn't an intruder too 776 if (mCurrentlyIntrudingNotification == null) { 777 tick(null, notification, true); 778 } 779 } 780 781 // Recalculate the position of the sliding windows and the titles. 782 setAreThereNotifications(); 783 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 784 } 785 786 public void removeNotification(IBinder key) { 787 StatusBarNotification old = removeNotificationViews(key); 788 if (SPEW) Slog.d(TAG, "removeNotification key=" + key + " old=" + old); 789 790 if (old != null) { 791 // Cancel the ticker if it's still running 792 mTicker.removeEntry(old); 793 794 // Recalculate the position of the sliding windows and the titles. 795 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 796 797 if (ENABLE_INTRUDERS && old == mCurrentlyIntrudingNotification) { 798 mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); 799 } 800 801 if (CLOSE_PANEL_WHEN_EMPTIED && mNotificationData.size() == 0 && !mAnimating) { 802 animateCollapse(); 803 } 804 } 805 806 setAreThereNotifications(); 807 } 808 809 @Override 810 protected void onConfigurationChanged(Configuration newConfig) { 811 updateRecentsPanel(); 812 updateShowSearchHoldoff(); 813 } 814 815 private void updateShowSearchHoldoff() { 816 mShowSearchHoldoff = mContext.getResources().getInteger( 817 R.integer.config_show_search_delay); 818 } 819 820 private void loadNotificationShade() { 821 if (mPile == null) return; 822 823 int N = mNotificationData.size(); 824 825 ArrayList<View> toShow = new ArrayList<View>(); 826 827 final boolean provisioned = isDeviceProvisioned(); 828 // If the device hasn't been through Setup, we only show system notifications 829 for (int i=0; i<N; i++) { 830 Entry ent = mNotificationData.get(N-i-1); 831 if (provisioned || "android".equals(ent.notification.pkg)) { 832 toShow.add(ent.row); 833 } 834 } 835 836 ArrayList<View> toRemove = new ArrayList<View>(); 837 for (int i=0; i<mPile.getChildCount(); i++) { 838 View child = mPile.getChildAt(i); 839 if (!toShow.contains(child)) { 840 toRemove.add(child); 841 } 842 } 843 844 for (View remove : toRemove) { 845 mPile.removeView(remove); 846 } 847 848 for (int i=0; i<toShow.size(); i++) { 849 View v = toShow.get(i); 850 if (v.getParent() == null) { 851 mPile.addView(v, i); 852 } 853 } 854 855 mSettingsButton.setEnabled(isDeviceProvisioned()); 856 } 857 858 private void reloadAllNotificationIcons() { 859 if (mNotificationIcons == null) return; 860 mNotificationIcons.removeAllViews(); 861 updateNotificationIcons(); 862 } 863 864 @Override 865 protected void updateNotificationIcons() { 866 if (mNotificationIcons == null) return; 867 868 loadNotificationShade(); 869 870 final LinearLayout.LayoutParams params 871 = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight); 872 873 int N = mNotificationData.size(); 874 875 if (DEBUG) { 876 Slog.d(TAG, "refreshing icons: " + N + " notifications, mNotificationIcons=" + mNotificationIcons); 877 } 878 879 ArrayList<View> toShow = new ArrayList<View>(); 880 881 final boolean provisioned = isDeviceProvisioned(); 882 // If the device hasn't been through Setup, we only show system notifications 883 for (int i=0; i<N; i++) { 884 Entry ent = mNotificationData.get(N-i-1); 885 if ((provisioned && ent.notification.score >= HIDE_ICONS_BELOW_SCORE) 886 || "android".equals(ent.notification.pkg)) { 887 toShow.add(ent.icon); 888 } 889 } 890 891 ArrayList<View> toRemove = new ArrayList<View>(); 892 for (int i=0; i<mNotificationIcons.getChildCount(); i++) { 893 View child = mNotificationIcons.getChildAt(i); 894 if (!toShow.contains(child)) { 895 toRemove.add(child); 896 } 897 } 898 899 for (View remove : toRemove) { 900 mNotificationIcons.removeView(remove); 901 } 902 903 for (int i=0; i<toShow.size(); i++) { 904 View v = toShow.get(i); 905 if (v.getParent() == null) { 906 mNotificationIcons.addView(v, i, params); 907 } 908 } 909 } 910 911 protected void updateCarrierLabelVisibility(boolean force) { 912 if (!SHOW_CARRIER_LABEL) return; 913 // The idea here is to only show the carrier label when there is enough room to see it, 914 // i.e. when there aren't enough notifications to fill the panel. 915 if (DEBUG) { 916 Slog.d(TAG, String.format("pileh=%d scrollh=%d carrierh=%d", 917 mPile.getHeight(), mScrollView.getHeight(), mCarrierLabelHeight)); 918 } 919 920 final boolean makeVisible = 921 mPile.getHeight() < (mScrollView.getHeight() - mCarrierLabelHeight); 922 923 if (force || mCarrierLabelVisible != makeVisible) { 924 mCarrierLabelVisible = makeVisible; 925 if (DEBUG) { 926 Slog.d(TAG, "making carrier label " + (makeVisible?"visible":"invisible")); 927 } 928 mCarrierLabel.animate().cancel(); 929 if (makeVisible) { 930 mCarrierLabel.setVisibility(View.VISIBLE); 931 } 932 mCarrierLabel.animate() 933 .alpha(makeVisible ? 1f : 0f) 934 //.setStartDelay(makeVisible ? 500 : 0) 935 //.setDuration(makeVisible ? 750 : 100) 936 .setDuration(150) 937 .setListener(makeVisible ? null : new AnimatorListenerAdapter() { 938 @Override 939 public void onAnimationEnd(Animator animation) { 940 if (!mCarrierLabelVisible) { // race 941 mCarrierLabel.setVisibility(View.INVISIBLE); 942 mCarrierLabel.setAlpha(0f); 943 } 944 } 945 }) 946 .start(); 947 } 948 } 949 950 @Override 951 protected void setAreThereNotifications() { 952 final boolean any = mNotificationData.size() > 0; 953 954 final boolean clearable = any && mNotificationData.hasClearableItems(); 955 956 if (DEBUG) { 957 Slog.d(TAG, "setAreThereNotifications: N=" + mNotificationData.size() 958 + " any=" + any + " clearable=" + clearable); 959 } 960 961 if (mClearButton.isShown()) { 962 if (clearable != (mClearButton.getAlpha() == 1.0f)) { 963 ObjectAnimator clearAnimation = ObjectAnimator.ofFloat( 964 mClearButton, "alpha", clearable ? 1.0f : 0.0f).setDuration(250); 965 clearAnimation.addListener(new AnimatorListenerAdapter() { 966 @Override 967 public void onAnimationEnd(Animator animation) { 968 if (mClearButton.getAlpha() <= 0.0f) { 969 mClearButton.setVisibility(View.INVISIBLE); 970 } 971 } 972 973 @Override 974 public void onAnimationStart(Animator animation) { 975 if (mClearButton.getAlpha() <= 0.0f) { 976 mClearButton.setVisibility(View.VISIBLE); 977 } 978 } 979 }); 980 clearAnimation.start(); 981 } 982 } else { 983 mClearButton.setAlpha(clearable ? 1.0f : 0.0f); 984 mClearButton.setVisibility(clearable ? View.VISIBLE : View.INVISIBLE); 985 } 986 mClearButton.setEnabled(clearable); 987 988 final View nlo = mStatusBarView.findViewById(R.id.notification_lights_out); 989 final boolean showDot = (any&&!areLightsOn()); 990 if (showDot != (nlo.getAlpha() == 1.0f)) { 991 if (showDot) { 992 nlo.setAlpha(0f); 993 nlo.setVisibility(View.VISIBLE); 994 } 995 nlo.animate() 996 .alpha(showDot?1:0) 997 .setDuration(showDot?750:250) 998 .setInterpolator(new AccelerateInterpolator(2.0f)) 999 .setListener(showDot ? null : new AnimatorListenerAdapter() { 1000 @Override 1001 public void onAnimationEnd(Animator _a) { 1002 nlo.setVisibility(View.GONE); 1003 } 1004 }) 1005 .start(); 1006 } 1007 1008 updateCarrierLabelVisibility(false); 1009 } 1010 1011 public void showClock(boolean show) { 1012 if (mStatusBarView == null) return; 1013 View clock = mStatusBarView.findViewById(R.id.clock); 1014 if (clock != null) { 1015 clock.setVisibility(show ? View.VISIBLE : View.GONE); 1016 } 1017 } 1018 1019 /** 1020 * State is one or more of the DISABLE constants from StatusBarManager. 1021 */ 1022 public void disable(int state) { 1023 final int old = mDisabled; 1024 final int diff = state ^ old; 1025 mDisabled = state; 1026 1027 if (DEBUG) { 1028 Slog.d(TAG, String.format("disable: 0x%08x -> 0x%08x (diff: 0x%08x)", 1029 old, state, diff)); 1030 } 1031 1032 StringBuilder flagdbg = new StringBuilder(); 1033 flagdbg.append("disable: < "); 1034 flagdbg.append(((state & StatusBarManager.DISABLE_EXPAND) != 0) ? "EXPAND" : "expand"); 1035 flagdbg.append(((diff & StatusBarManager.DISABLE_EXPAND) != 0) ? "* " : " "); 1036 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "ICONS" : "icons"); 1037 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "* " : " "); 1038 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "ALERTS" : "alerts"); 1039 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "* " : " "); 1040 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "TICKER" : "ticker"); 1041 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "* " : " "); 1042 flagdbg.append(((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "SYSTEM_INFO" : "system_info"); 1043 flagdbg.append(((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "* " : " "); 1044 flagdbg.append(((state & StatusBarManager.DISABLE_BACK) != 0) ? "BACK" : "back"); 1045 flagdbg.append(((diff & StatusBarManager.DISABLE_BACK) != 0) ? "* " : " "); 1046 flagdbg.append(((state & StatusBarManager.DISABLE_HOME) != 0) ? "HOME" : "home"); 1047 flagdbg.append(((diff & StatusBarManager.DISABLE_HOME) != 0) ? "* " : " "); 1048 flagdbg.append(((state & StatusBarManager.DISABLE_RECENT) != 0) ? "RECENT" : "recent"); 1049 flagdbg.append(((diff & StatusBarManager.DISABLE_RECENT) != 0) ? "* " : " "); 1050 flagdbg.append(((state & StatusBarManager.DISABLE_CLOCK) != 0) ? "CLOCK" : "clock"); 1051 flagdbg.append(((diff & StatusBarManager.DISABLE_CLOCK) != 0) ? "* " : " "); 1052 flagdbg.append(">"); 1053 Slog.d(TAG, flagdbg.toString()); 1054 1055 if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { 1056 mIcons.animate().cancel(); 1057 if ((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { 1058 if (mTicking) { 1059 mTicker.halt(); 1060 } 1061 mIcons.animate() 1062 .alpha(0f) 1063 .translationY(mNaturalBarHeight*0.5f) 1064 //.setStartDelay(100) 1065 .setDuration(175) 1066 .setInterpolator(new DecelerateInterpolator(1.5f)) 1067 .setListener(mMakeIconsInvisible) 1068 .start(); 1069 } else { 1070 mIcons.setVisibility(View.VISIBLE); 1071 mIcons.animate() 1072 .alpha(1f) 1073 .translationY(0) 1074 .setStartDelay(0) 1075 .setInterpolator(new DecelerateInterpolator(1.5f)) 1076 .setDuration(175) 1077 .start(); 1078 } 1079 } 1080 1081 if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) { 1082 boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0; 1083 showClock(show); 1084 } 1085 if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { 1086 if ((state & StatusBarManager.DISABLE_EXPAND) != 0) { 1087 animateCollapse(); 1088 } 1089 } 1090 1091 if ((diff & (StatusBarManager.DISABLE_HOME 1092 | StatusBarManager.DISABLE_RECENT 1093 | StatusBarManager.DISABLE_BACK)) != 0) { 1094 // the nav bar will take care of these 1095 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state); 1096 1097 if ((state & StatusBarManager.DISABLE_RECENT) != 0) { 1098 // close recents if it's visible 1099 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); 1100 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); 1101 } 1102 } 1103 1104 if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1105 if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1106 if (mTicking) { 1107 mTicker.halt(); 1108 } else { 1109 setNotificationIconVisibility(false, com.android.internal.R.anim.fade_out); 1110 } 1111 } else { 1112 if (!mExpandedVisible) { 1113 setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in); 1114 } 1115 } 1116 } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1117 if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1118 mTicker.halt(); 1119 } 1120 } 1121 } 1122 1123 @Override 1124 protected BaseStatusBar.H createHandler() { 1125 return new PhoneStatusBar.H(); 1126 } 1127 1128 /** 1129 * All changes to the status bar and notifications funnel through here and are batched. 1130 */ 1131 private class H extends BaseStatusBar.H { 1132 public void handleMessage(Message m) { 1133 super.handleMessage(m); 1134 switch (m.what) { 1135 case MSG_OPEN_NOTIFICATION_PANEL: 1136 animateExpand(); 1137 break; 1138 case MSG_CLOSE_NOTIFICATION_PANEL: 1139 animateCollapse(); 1140 break; 1141 case MSG_SHOW_INTRUDER: 1142 setIntruderAlertVisibility(true); 1143 break; 1144 case MSG_HIDE_INTRUDER: 1145 setIntruderAlertVisibility(false); 1146 mCurrentlyIntrudingNotification = null; 1147 break; 1148 } 1149 } 1150 } 1151 1152 final Runnable mAnimationCallback = new Runnable() { 1153 @Override 1154 public void run() { 1155 doAnimation(mChoreographer.getFrameTimeNanos()); 1156 } 1157 }; 1158 1159 final Runnable mRevealAnimationCallback = new Runnable() { 1160 @Override 1161 public void run() { 1162 doRevealAnimation(mChoreographer.getFrameTimeNanos()); 1163 } 1164 }; 1165 1166 View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() { 1167 public void onFocusChange(View v, boolean hasFocus) { 1168 // Because 'v' is a ViewGroup, all its children will be (un)selected 1169 // too, which allows marqueeing to work. 1170 v.setSelected(hasFocus); 1171 } 1172 }; 1173 1174 private void makeExpandedVisible(boolean revealAfterDraw) { 1175 if (SPEW) Slog.d(TAG, "Make expanded visible: expanded visible=" + mExpandedVisible); 1176 if (mExpandedVisible) { 1177 return; 1178 } 1179 1180 mExpandedVisible = true; 1181 mPile.setLayoutTransitionsEnabled(true); 1182 if (mNavigationBarView != null) 1183 mNavigationBarView.setSlippery(true); 1184 1185 updateCarrierLabelVisibility(true); 1186 1187 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 1188 1189 // Expand the window to encompass the full screen in anticipation of the drag. 1190 // This is only possible to do atomically because the status bar is at the top of the screen! 1191 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); 1192 lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 1193 lp.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; 1194 lp.height = ViewGroup.LayoutParams.MATCH_PARENT; 1195 final WindowManager wm = WindowManagerImpl.getDefault(); 1196 wm.updateViewLayout(mStatusBarWindow, lp); 1197 1198 // Updating the window layout will force an expensive traversal/redraw. 1199 // Kick off the reveal animation after this is complete to avoid animation latency. 1200 if (revealAfterDraw) { 1201 mHandler.post(mStartRevealAnimation); 1202 } 1203 1204 visibilityChanged(true); 1205 } 1206 1207 public void animateExpand() { 1208 if (SPEW) Slog.d(TAG, "Animate expand: expanded=" + mExpanded); 1209 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1210 return ; 1211 } 1212 if (mExpanded) { 1213 return; 1214 } 1215 1216 prepareTracking(0, true); 1217 mHandler.post(mPerformSelfExpandFling); 1218 } 1219 1220 public void animateCollapse() { 1221 animateCollapse(CommandQueue.FLAG_EXCLUDE_NONE); 1222 } 1223 1224 public void animateCollapse(int flags) { 1225 animateCollapse(flags, 1.0f); 1226 } 1227 1228 public void animateCollapse(int flags, float velocityMultiplier) { 1229 if (SPEW) { 1230 Slog.d(TAG, "animateCollapse(): mExpanded=" + mExpanded 1231 + " mExpandedVisible=" + mExpandedVisible 1232 + " mExpanded=" + mExpanded 1233 + " mAnimating=" + mAnimating 1234 + " mAnimY=" + mAnimY 1235 + " mAnimVel=" + mAnimVel 1236 + " flags=" + flags); 1237 } 1238 1239 if ((flags & CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL) == 0) { 1240 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); 1241 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); 1242 } 1243 1244 if ((flags & CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL) == 0) { 1245 mHandler.removeMessages(MSG_CLOSE_SEARCH_PANEL); 1246 mHandler.sendEmptyMessage(MSG_CLOSE_SEARCH_PANEL); 1247 } 1248 1249 if (!mExpandedVisible) { 1250 return; 1251 } 1252 1253 int y; 1254 if (mAnimating) { 1255 y = (int)mAnimY; 1256 } else { 1257 y = getExpandedViewMaxHeight()-1; 1258 } 1259 // Let the fling think that we're open so it goes in the right direction 1260 // and doesn't try to re-open the windowshade. 1261 mExpanded = true; 1262 prepareTracking(y, false); 1263 performFling(y, -mSelfCollapseVelocityPx*velocityMultiplier, true); 1264 } 1265 1266 void performExpand() { 1267 if (SPEW) Slog.d(TAG, "performExpand: mExpanded=" + mExpanded); 1268 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1269 return ; 1270 } 1271 if (mExpanded) { 1272 return; 1273 } 1274 1275 mExpanded = true; 1276 makeExpandedVisible(false); 1277 updateExpandedViewPos(EXPANDED_FULL_OPEN); 1278 1279 if (false) postStartTracing(); 1280 } 1281 1282 void performCollapse() { 1283 if (SPEW) Slog.d(TAG, "performCollapse: mExpanded=" + mExpanded 1284 + " mExpandedVisible=" + mExpandedVisible); 1285 1286 if (!mExpandedVisible) { 1287 return; 1288 } 1289 mExpandedVisible = false; 1290 mPile.setLayoutTransitionsEnabled(false); 1291 if (mNavigationBarView != null) 1292 mNavigationBarView.setSlippery(false); 1293 visibilityChanged(false); 1294 1295 // Shrink the window to the size of the status bar only 1296 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); 1297 lp.height = getStatusBarHeight(); 1298 lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 1299 lp.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; 1300 final WindowManager wm = WindowManagerImpl.getDefault(); 1301 wm.updateViewLayout(mStatusBarWindow, lp); 1302 1303 if ((mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS) == 0) { 1304 setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in); 1305 } 1306 1307 if (!mExpanded) { 1308 return; 1309 } 1310 mExpanded = false; 1311 1312 // Close any "App info" popups that might have snuck on-screen 1313 dismissPopups(); 1314 1315 if (mPostCollapseCleanup != null) { 1316 mPostCollapseCleanup.run(); 1317 mPostCollapseCleanup = null; 1318 } 1319 } 1320 1321 void resetLastAnimTime() { 1322 mAnimLastTimeNanos = System.nanoTime(); 1323 if (SPEW) { 1324 Throwable t = new Throwable(); 1325 t.fillInStackTrace(); 1326 Slog.d(TAG, "resetting last anim time=" + mAnimLastTimeNanos, t); 1327 } 1328 } 1329 1330 void doAnimation(long frameTimeNanos) { 1331 if (mAnimating) { 1332 if (SPEW) Slog.d(TAG, "doAnimation dt=" + (frameTimeNanos - mAnimLastTimeNanos)); 1333 if (SPEW) Slog.d(TAG, "doAnimation before mAnimY=" + mAnimY); 1334 incrementAnim(frameTimeNanos); 1335 if (SPEW) { 1336 Slog.d(TAG, "doAnimation after mAnimY=" + mAnimY); 1337 Slog.d(TAG, "doAnimation expandedViewMax=" + getExpandedViewMaxHeight()); 1338 } 1339 1340 if (mAnimY >= getExpandedViewMaxHeight()-1 && !mClosing) { 1341 if (SPEW) Slog.d(TAG, "Animation completed to expanded state."); 1342 mAnimating = false; 1343 updateExpandedViewPos(EXPANDED_FULL_OPEN); 1344 performExpand(); 1345 return; 1346 } 1347 1348 if (mAnimY == 0 && mAnimAccel == 0 && mClosing) { 1349 if (SPEW) Slog.d(TAG, "Animation completed to collapsed state."); 1350 mAnimating = false; 1351 performCollapse(); 1352 return; 1353 } 1354 1355 if (mAnimY < getStatusBarHeight() && mClosing) { 1356 // Draw one more frame with the bar positioned at the top of the screen 1357 // before ending the animation so that the user sees the bar in 1358 // its final position. The call to performCollapse() causes a window 1359 // relayout which takes time and might cause the animation to skip 1360 // on the very last frame before the bar disappears if we did it now. 1361 mAnimY = 0; 1362 mAnimAccel = 0; 1363 mAnimVel = 0; 1364 } 1365 1366 updateExpandedViewPos((int)mAnimY); 1367 mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, 1368 mAnimationCallback, null); 1369 } 1370 } 1371 1372 void stopTracking() { 1373 if (!mTracking) 1374 return; 1375 mTracking = false; 1376 mPile.setLayerType(View.LAYER_TYPE_NONE, null); 1377 mVelocityTracker.recycle(); 1378 mVelocityTracker = null; 1379 mCloseView.setPressed(false); 1380 } 1381 1382 void incrementAnim(long frameTimeNanos) { 1383 final long deltaNanos = Math.max(frameTimeNanos - mAnimLastTimeNanos, 0); 1384 final float t = deltaNanos * 0.000000001f; // ns -> s 1385 final float y = mAnimY; 1386 final float v = mAnimVel; // px/s 1387 final float a = mAnimAccel; // px/s/s 1388 mAnimY = y + (v*t) + (0.5f*a*t*t); // px 1389 mAnimVel = v + (a*t); // px/s 1390 mAnimLastTimeNanos = frameTimeNanos; // ns 1391 //Slog.d(TAG, "y=" + y + " v=" + v + " a=" + a + " t=" + t + " mAnimY=" + mAnimY 1392 // + " mAnimAccel=" + mAnimAccel); 1393 } 1394 1395 void doRevealAnimation(long frameTimeNanos) { 1396 if (SPEW) { 1397 Slog.d(TAG, "doRevealAnimation: dt=" + (frameTimeNanos - mAnimLastTimeNanos)); 1398 } 1399 final int h = mNotificationPanelMinHeight; 1400 if (mAnimatingReveal && mAnimating && mAnimY < h) { 1401 incrementAnim(frameTimeNanos); 1402 if (mAnimY >= h) { 1403 mAnimY = h; 1404 updateExpandedViewPos((int)mAnimY); 1405 } else { 1406 updateExpandedViewPos((int)mAnimY); 1407 mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, 1408 mRevealAnimationCallback, null); 1409 } 1410 } 1411 } 1412 1413 void prepareTracking(int y, boolean opening) { 1414 if (CHATTY) { 1415 Slog.d(TAG, "panel: beginning to track the user's touch, y=" + y + " opening=" + opening); 1416 } 1417 1418 mCloseView.setPressed(true); 1419 1420 mTracking = true; 1421 mPile.setLayerType(View.LAYER_TYPE_HARDWARE, null); 1422 mVelocityTracker = VelocityTracker.obtain(); 1423 if (opening) { 1424 makeExpandedVisible(true); 1425 } else { 1426 // it's open, close it? 1427 if (mAnimating) { 1428 mAnimating = false; 1429 mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, 1430 mAnimationCallback, null); 1431 } 1432 updateExpandedViewPos(y + mViewDelta); 1433 } 1434 } 1435 1436 void performFling(int y, float vel, boolean always) { 1437 if (CHATTY) { 1438 Slog.d(TAG, "panel: will fling, y=" + y + " vel=" + vel + " mExpanded=" + mExpanded); 1439 } 1440 1441 mAnimatingReveal = false; 1442 1443 mAnimY = y; 1444 mAnimVel = vel; 1445 1446 //Slog.d(TAG, "starting with mAnimY=" + mAnimY + " mAnimVel=" + mAnimVel); 1447 1448 if (mExpanded) { 1449 if (!always && ( 1450 vel > mFlingCollapseMinVelocityPx 1451 || (y > (getExpandedViewMaxHeight()*(1f-mCollapseMinDisplayFraction)) && 1452 vel > -mFlingExpandMinVelocityPx))) { 1453 // We are expanded, but they didn't move sufficiently to cause 1454 // us to retract. Animate back to the expanded position. 1455 mAnimAccel = mExpandAccelPx; 1456 if (vel < 0) { 1457 mAnimVel = 0; 1458 } 1459 } 1460 else { 1461 // We are expanded and are now going to animate away. 1462 mAnimAccel = -mCollapseAccelPx; 1463 if (vel > 0) { 1464 mAnimVel = 0; 1465 } 1466 } 1467 } else { 1468 if (always || ( 1469 vel > mFlingExpandMinVelocityPx 1470 || (y > (getExpandedViewMaxHeight()*(1f-mExpandMinDisplayFraction)) && 1471 vel > -mFlingCollapseMinVelocityPx))) { 1472 // We are collapsed, and they moved enough to allow us to 1473 // expand. Animate in the notifications. 1474 mAnimAccel = mExpandAccelPx; 1475 if (vel < 0) { 1476 mAnimVel = 0; 1477 } 1478 } 1479 else { 1480 // We are collapsed, but they didn't move sufficiently to cause 1481 // us to retract. Animate back to the collapsed position. 1482 mAnimAccel = -mCollapseAccelPx; 1483 if (vel > 0) { 1484 mAnimVel = 0; 1485 } 1486 } 1487 } 1488 //Slog.d(TAG, "mAnimY=" + mAnimY + " mAnimVel=" + mAnimVel 1489 // + " mAnimAccel=" + mAnimAccel); 1490 1491 resetLastAnimTime(); 1492 mAnimating = true; 1493 mClosing = mAnimAccel < 0; 1494 1495 mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, 1496 mAnimationCallback, null); 1497 mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, 1498 mRevealAnimationCallback, null); 1499 mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, 1500 mAnimationCallback, null); 1501 stopTracking(); 1502 } 1503 1504 boolean interceptTouchEvent(MotionEvent event) { 1505 if (SPEW) { 1506 Slog.d(TAG, "Touch: rawY=" + event.getRawY() + " event=" + event + " mDisabled=" 1507 + mDisabled + " mTracking=" + mTracking); 1508 } else if (CHATTY) { 1509 if (event.getAction() != MotionEvent.ACTION_MOVE) { 1510 Slog.d(TAG, String.format( 1511 "panel: %s at (%f, %f) mDisabled=0x%08x", 1512 MotionEvent.actionToString(event.getAction()), 1513 event.getRawX(), event.getRawY(), mDisabled)); 1514 } 1515 } 1516 1517 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1518 return false; 1519 } 1520 1521 final int action = event.getAction(); 1522 final int statusBarSize = getStatusBarHeight(); 1523 final int hitSize = statusBarSize*2; 1524 final int y = (int)event.getRawY(); 1525 if (action == MotionEvent.ACTION_DOWN) { 1526 if (!areLightsOn()) { 1527 setLightsOn(true); 1528 } 1529 1530 if (!mExpanded) { 1531 mViewDelta = statusBarSize - y; 1532 } else { 1533 mCloseView.getLocationOnScreen(mAbsPos); 1534 mViewDelta = mAbsPos[1] 1535 + getCloseViewHeight() // XXX: not closeViewHeight, but paddingBottom from the 9patch 1536 + mNotificationPanelBackgroundPadding.top 1537 + mNotificationPanelBackgroundPadding.bottom 1538 - y; 1539 } 1540 if ((!mExpanded && y < hitSize) || 1541 // @@ add taps outside the panel if it's not full-screen 1542 (mExpanded && y > (getExpandedViewMaxHeight()-hitSize))) { 1543 // We drop events at the edge of the screen to make the windowshade come 1544 // down by accident less, especially when pushing open a device with a keyboard 1545 // that rotates (like g1 and droid) 1546 int x = (int)event.getRawX(); 1547 final int edgeBorder = mEdgeBorder; 1548 if (x >= edgeBorder && x < mDisplayMetrics.widthPixels - edgeBorder) { 1549 prepareTracking(y, !mExpanded);// opening if we're not already fully visible 1550 trackMovement(event); 1551 } 1552 } 1553 } else if (mTracking) { 1554 trackMovement(event); 1555 if (action == MotionEvent.ACTION_MOVE) { 1556 if (mAnimatingReveal && (y + mViewDelta) < mNotificationPanelMinHeight) { 1557 // nothing 1558 } else { 1559 mAnimatingReveal = false; 1560 updateExpandedViewPos(y + mViewDelta); 1561 } 1562 } else if (action == MotionEvent.ACTION_UP 1563 || action == MotionEvent.ACTION_CANCEL) { 1564 mVelocityTracker.computeCurrentVelocity(1000); 1565 1566 float yVel = mVelocityTracker.getYVelocity(); 1567 boolean negative = yVel < 0; 1568 1569 float xVel = mVelocityTracker.getXVelocity(); 1570 if (xVel < 0) { 1571 xVel = -xVel; 1572 } 1573 if (xVel > mFlingGestureMaxXVelocityPx) { 1574 xVel = mFlingGestureMaxXVelocityPx; // limit how much we care about the x axis 1575 } 1576 1577 float vel = (float)Math.hypot(yVel, xVel); 1578 if (vel > mFlingGestureMaxOutputVelocityPx) { 1579 vel = mFlingGestureMaxOutputVelocityPx; 1580 } 1581 if (negative) { 1582 vel = -vel; 1583 } 1584 1585 if (CHATTY) { 1586 Slog.d(TAG, String.format("gesture: vraw=(%f,%f) vnorm=(%f,%f) vlinear=%f", 1587 mVelocityTracker.getXVelocity(), 1588 mVelocityTracker.getYVelocity(), 1589 xVel, yVel, 1590 vel)); 1591 } 1592 1593 if (mTrackingPosition == mNotificationPanelMinHeight) { 1594 // start the fling from the tracking position, ignore y and view delta 1595 mFlingY = mTrackingPosition; 1596 mViewDelta = 0; 1597 } else { 1598 mFlingY = y; 1599 } 1600 mFlingVelocity = vel; 1601 mHandler.post(mPerformFling); 1602 } 1603 1604 } 1605 return false; 1606 } 1607 1608 private void trackMovement(MotionEvent event) { 1609 // Add movement to velocity tracker using raw screen X and Y coordinates instead 1610 // of window coordinates because the window frame may be moving at the same time. 1611 float deltaX = event.getRawX() - event.getX(); 1612 float deltaY = event.getRawY() - event.getY(); 1613 event.offsetLocation(deltaX, deltaY); 1614 mVelocityTracker.addMovement(event); 1615 event.offsetLocation(-deltaX, -deltaY); 1616 } 1617 1618 @Override // CommandQueue 1619 public void setNavigationIconHints(int hints) { 1620 if (hints == mNavigationIconHints) return; 1621 1622 mNavigationIconHints = hints; 1623 1624 if (mNavigationBarView != null) { 1625 mNavigationBarView.setNavigationIconHints(hints); 1626 } 1627 } 1628 1629 @Override // CommandQueue 1630 public void setSystemUiVisibility(int vis, int mask) { 1631 final int oldVal = mSystemUiVisibility; 1632 final int newVal = (oldVal&~mask) | (vis&mask); 1633 final int diff = newVal ^ oldVal; 1634 1635 if (diff != 0) { 1636 mSystemUiVisibility = newVal; 1637 1638 if (0 != (diff & View.SYSTEM_UI_FLAG_LOW_PROFILE)) { 1639 final boolean lightsOut = (0 != (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE)); 1640 if (lightsOut) { 1641 animateCollapse(); 1642 if (mTicking) { 1643 mTicker.halt(); 1644 } 1645 } 1646 1647 if (mNavigationBarView != null) { 1648 mNavigationBarView.setLowProfile(lightsOut); 1649 } 1650 1651 setStatusBarLowProfile(lightsOut); 1652 } 1653 1654 notifyUiVisibilityChanged(); 1655 } 1656 } 1657 1658 private void setStatusBarLowProfile(boolean lightsOut) { 1659 if (mLightsOutAnimation == null) { 1660 final View notifications = mStatusBarView.findViewById(R.id.notification_icon_area); 1661 final View systemIcons = mStatusBarView.findViewById(R.id.statusIcons); 1662 final View signal = mStatusBarView.findViewById(R.id.signal_cluster); 1663 final View battery = mStatusBarView.findViewById(R.id.battery); 1664 final View clock = mStatusBarView.findViewById(R.id.clock); 1665 1666 mLightsOutAnimation = new AnimatorSet(); 1667 mLightsOutAnimation.playTogether( 1668 ObjectAnimator.ofFloat(notifications, View.ALPHA, 0), 1669 ObjectAnimator.ofFloat(systemIcons, View.ALPHA, 0), 1670 ObjectAnimator.ofFloat(signal, View.ALPHA, 0), 1671 ObjectAnimator.ofFloat(battery, View.ALPHA, 0.5f), 1672 ObjectAnimator.ofFloat(clock, View.ALPHA, 0.5f) 1673 ); 1674 mLightsOutAnimation.setDuration(750); 1675 1676 mLightsOnAnimation = new AnimatorSet(); 1677 mLightsOnAnimation.playTogether( 1678 ObjectAnimator.ofFloat(notifications, View.ALPHA, 1), 1679 ObjectAnimator.ofFloat(systemIcons, View.ALPHA, 1), 1680 ObjectAnimator.ofFloat(signal, View.ALPHA, 1), 1681 ObjectAnimator.ofFloat(battery, View.ALPHA, 1), 1682 ObjectAnimator.ofFloat(clock, View.ALPHA, 1) 1683 ); 1684 mLightsOnAnimation.setDuration(250); 1685 } 1686 1687 mLightsOutAnimation.cancel(); 1688 mLightsOnAnimation.cancel(); 1689 1690 final Animator a = lightsOut ? mLightsOutAnimation : mLightsOnAnimation; 1691 a.start(); 1692 1693 setAreThereNotifications(); 1694 } 1695 1696 private boolean areLightsOn() { 1697 return 0 == (mSystemUiVisibility & View.SYSTEM_UI_FLAG_LOW_PROFILE); 1698 } 1699 1700 public void setLightsOn(boolean on) { 1701 Log.v(TAG, "setLightsOn(" + on + ")"); 1702 if (on) { 1703 setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE); 1704 } else { 1705 setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE, View.SYSTEM_UI_FLAG_LOW_PROFILE); 1706 } 1707 } 1708 1709 private void notifyUiVisibilityChanged() { 1710 try { 1711 mWindowManager.statusBarVisibilityChanged(mSystemUiVisibility); 1712 } catch (RemoteException ex) { 1713 } 1714 } 1715 1716 public void topAppWindowChanged(boolean showMenu) { 1717 if (DEBUG) { 1718 Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button"); 1719 } 1720 if (mNavigationBarView != null) { 1721 mNavigationBarView.setMenuVisibility(showMenu); 1722 } 1723 1724 // See above re: lights-out policy for legacy apps. 1725 if (showMenu) setLightsOn(true); 1726 } 1727 1728 @Override 1729 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { 1730 boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS) 1731 || ((vis & InputMethodService.IME_VISIBLE) != 0); 1732 1733 mCommandQueue.setNavigationIconHints( 1734 altBack ? (mNavigationIconHints | StatusBarManager.NAVIGATION_HINT_BACK_ALT) 1735 : (mNavigationIconHints & ~StatusBarManager.NAVIGATION_HINT_BACK_ALT)); 1736 } 1737 1738 @Override 1739 public void setHardKeyboardStatus(boolean available, boolean enabled) { } 1740 1741 private class NotificationClicker implements View.OnClickListener { 1742 private PendingIntent mIntent; 1743 private String mPkg; 1744 private String mTag; 1745 private int mId; 1746 1747 NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { 1748 mIntent = intent; 1749 mPkg = pkg; 1750 mTag = tag; 1751 mId = id; 1752 } 1753 1754 public void onClick(View v) { 1755 try { 1756 // The intent we are sending is for the application, which 1757 // won't have permission to immediately start an activity after 1758 // the user switches to home. We know it is safe to do at this 1759 // point, so make sure new activity switches are now allowed. 1760 ActivityManagerNative.getDefault().resumeAppSwitches(); 1761 // Also, notifications can be launched from the lock screen, 1762 // so dismiss the lock screen when the activity starts. 1763 ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity(); 1764 } catch (RemoteException e) { 1765 } 1766 1767 if (mIntent != null) { 1768 int[] pos = new int[2]; 1769 v.getLocationOnScreen(pos); 1770 Intent overlay = new Intent(); 1771 overlay.setSourceBounds( 1772 new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); 1773 try { 1774 mIntent.send(mContext, 0, overlay); 1775 } catch (PendingIntent.CanceledException e) { 1776 // the stack trace isn't very helpful here. Just log the exception message. 1777 Slog.w(TAG, "Sending contentIntent failed: " + e); 1778 } 1779 1780 KeyguardManager kgm = 1781 (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); 1782 if (kgm != null) kgm.exitKeyguardSecurely(null); 1783 } 1784 1785 try { 1786 mBarService.onNotificationClick(mPkg, mTag, mId); 1787 } catch (RemoteException ex) { 1788 // system process is dead if we're here. 1789 } 1790 1791 // close the shade if it was open 1792 animateCollapse(); 1793 1794 // If this click was on the intruder alert, hide that instead 1795 mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); 1796 } 1797 } 1798 1799 @Override 1800 protected void tick(IBinder key, StatusBarNotification n, boolean firstTime) { 1801 // no ticking in lights-out mode 1802 if (!areLightsOn()) return; 1803 1804 // no ticking in Setup 1805 if (!isDeviceProvisioned()) return; 1806 1807 // Show the ticker if one is requested. Also don't do this 1808 // until status bar window is attached to the window manager, 1809 // because... well, what's the point otherwise? And trying to 1810 // run a ticker without being attached will crash! 1811 if (n.notification.tickerText != null && mStatusBarWindow.getWindowToken() != null) { 1812 if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS 1813 | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { 1814 mTicker.addEntry(n); 1815 } 1816 } 1817 } 1818 1819 private class MyTicker extends Ticker { 1820 MyTicker(Context context, View sb) { 1821 super(context, sb); 1822 } 1823 1824 @Override 1825 public void tickerStarting() { 1826 mTicking = true; 1827 mIcons.setVisibility(View.GONE); 1828 mTickerView.setVisibility(View.VISIBLE); 1829 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_up_in, null)); 1830 mIcons.startAnimation(loadAnim(com.android.internal.R.anim.push_up_out, null)); 1831 } 1832 1833 @Override 1834 public void tickerDone() { 1835 mIcons.setVisibility(View.VISIBLE); 1836 mTickerView.setVisibility(View.GONE); 1837 mIcons.startAnimation(loadAnim(com.android.internal.R.anim.push_down_in, null)); 1838 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_down_out, 1839 mTickingDoneListener)); 1840 } 1841 1842 public void tickerHalting() { 1843 mIcons.setVisibility(View.VISIBLE); 1844 mTickerView.setVisibility(View.GONE); 1845 mIcons.startAnimation(loadAnim(com.android.internal.R.anim.fade_in, null)); 1846 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.fade_out, 1847 mTickingDoneListener)); 1848 } 1849 } 1850 1851 Animation.AnimationListener mTickingDoneListener = new Animation.AnimationListener() {; 1852 public void onAnimationEnd(Animation animation) { 1853 mTicking = false; 1854 } 1855 public void onAnimationRepeat(Animation animation) { 1856 } 1857 public void onAnimationStart(Animation animation) { 1858 } 1859 }; 1860 1861 private Animation loadAnim(int id, Animation.AnimationListener listener) { 1862 Animation anim = AnimationUtils.loadAnimation(mContext, id); 1863 if (listener != null) { 1864 anim.setAnimationListener(listener); 1865 } 1866 return anim; 1867 } 1868 1869 public static String viewInfo(View v) { 1870 return "[(" + v.getLeft() + "," + v.getTop() + ")(" + v.getRight() + "," + v.getBottom() 1871 + ") " + v.getWidth() + "x" + v.getHeight() + "]"; 1872 } 1873 1874 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 1875 synchronized (mQueueLock) { 1876 pw.println("Current Status Bar state:"); 1877 pw.println(" mExpanded=" + mExpanded 1878 + ", mExpandedVisible=" + mExpandedVisible); 1879 pw.println(" mTicking=" + mTicking); 1880 pw.println(" mTracking=" + mTracking); 1881 pw.println(" mAnimating=" + mAnimating 1882 + ", mAnimY=" + mAnimY + ", mAnimVel=" + mAnimVel 1883 + ", mAnimAccel=" + mAnimAccel); 1884 pw.println(" mAnimLastTimeNanos=" + mAnimLastTimeNanos); 1885 pw.println(" mAnimatingReveal=" + mAnimatingReveal 1886 + " mViewDelta=" + mViewDelta); 1887 pw.println(" mDisplayMetrics=" + mDisplayMetrics); 1888 pw.println(" mPile: " + viewInfo(mPile)); 1889 pw.println(" mCloseView: " + viewInfo(mCloseView)); 1890 pw.println(" mTickerView: " + viewInfo(mTickerView)); 1891 pw.println(" mScrollView: " + viewInfo(mScrollView) 1892 + " scroll " + mScrollView.getScrollX() + "," + mScrollView.getScrollY()); 1893 } 1894 1895 pw.print(" mNavigationBarView="); 1896 if (mNavigationBarView == null) { 1897 pw.println("null"); 1898 } else { 1899 mNavigationBarView.dump(fd, pw, args); 1900 } 1901 1902 if (DUMPTRUCK) { 1903 synchronized (mNotificationData) { 1904 int N = mNotificationData.size(); 1905 pw.println(" notification icons: " + N); 1906 for (int i=0; i<N; i++) { 1907 NotificationData.Entry e = mNotificationData.get(i); 1908 pw.println(" [" + i + "] key=" + e.key + " icon=" + e.icon); 1909 StatusBarNotification n = e.notification; 1910 pw.println(" pkg=" + n.pkg + " id=" + n.id + " score=" + n.score); 1911 pw.println(" notification=" + n.notification); 1912 pw.println(" tickerText=\"" + n.notification.tickerText + "\""); 1913 } 1914 } 1915 1916 int N = mStatusIcons.getChildCount(); 1917 pw.println(" system icons: " + N); 1918 for (int i=0; i<N; i++) { 1919 StatusBarIconView ic = (StatusBarIconView) mStatusIcons.getChildAt(i); 1920 pw.println(" [" + i + "] icon=" + ic); 1921 } 1922 1923 if (false) { 1924 pw.println("see the logcat for a dump of the views we have created."); 1925 // must happen on ui thread 1926 mHandler.post(new Runnable() { 1927 public void run() { 1928 mStatusBarView.getLocationOnScreen(mAbsPos); 1929 Slog.d(TAG, "mStatusBarView: ----- (" + mAbsPos[0] + "," + mAbsPos[1] 1930 + ") " + mStatusBarView.getWidth() + "x" 1931 + getStatusBarHeight()); 1932 mStatusBarView.debug(); 1933 } 1934 }); 1935 } 1936 } 1937 1938 mNetworkController.dump(fd, pw, args); 1939 } 1940 1941 @Override 1942 public void createAndAddWindows() { 1943 addStatusBarWindow(); 1944 } 1945 1946 private void addStatusBarWindow() { 1947 // Put up the view 1948 final int height = getStatusBarHeight(); 1949 1950 // Now that the status bar window encompasses the sliding panel and its 1951 // translucent backdrop, the entire thing is made TRANSLUCENT and is 1952 // hardware-accelerated. 1953 final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 1954 ViewGroup.LayoutParams.MATCH_PARENT, 1955 height, 1956 WindowManager.LayoutParams.TYPE_STATUS_BAR, 1957 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 1958 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING 1959 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 1960 PixelFormat.TRANSLUCENT); 1961 1962 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 1963 1964 lp.gravity = getStatusBarGravity(); 1965 lp.setTitle("StatusBar"); 1966 lp.packageName = mContext.getPackageName(); 1967 1968 makeStatusBarView(); 1969 WindowManagerImpl.getDefault().addView(mStatusBarWindow, lp); 1970 } 1971 1972 void setNotificationIconVisibility(boolean visible, int anim) { 1973 int old = mNotificationIcons.getVisibility(); 1974 int v = visible ? View.VISIBLE : View.INVISIBLE; 1975 if (old != v) { 1976 mNotificationIcons.setVisibility(v); 1977 mNotificationIcons.startAnimation(loadAnim(anim, null)); 1978 } 1979 } 1980 1981 void updateExpandedInvisiblePosition() { 1982 mTrackingPosition = -mDisplayMetrics.heightPixels; 1983 } 1984 1985 static final float saturate(float a) { 1986 return a < 0f ? 0f : (a > 1f ? 1f : a); 1987 } 1988 1989 @Override 1990 protected int getExpandedViewMaxHeight() { 1991 return mDisplayMetrics.heightPixels - mNotificationPanelMarginBottomPx; 1992 } 1993 1994 @Override 1995 protected void updateExpandedViewPos(int expandedPosition) { 1996 if (SPEW) { 1997 Slog.d(TAG, "updateExpandedViewPos before expandedPosition=" + expandedPosition 1998 //+ " mTrackingParams.y=" + ((mTrackingParams == null) ? "?" : mTrackingParams.y) 1999 + " mTrackingPosition=" + mTrackingPosition 2000 + " gravity=" + mNotificationPanelGravity); 2001 } 2002 int panelh = 0; 2003 final int disph = getExpandedViewMaxHeight(); 2004 2005 // If the expanded view is not visible, make sure they're still off screen. 2006 // Maybe the view was resized. 2007 if (!mExpandedVisible) { 2008 updateExpandedInvisiblePosition(); 2009 return; 2010 } 2011 2012 // tracking view... 2013 int pos; 2014 if (expandedPosition == EXPANDED_FULL_OPEN) { 2015 panelh = disph; 2016 } 2017 else if (expandedPosition == EXPANDED_LEAVE_ALONE) { 2018 panelh = mTrackingPosition; 2019 } 2020 else { 2021 if (expandedPosition <= disph) { 2022 panelh = expandedPosition; 2023 } else { 2024 panelh = disph; 2025 } 2026 } 2027 2028 // catch orientation changes and other peculiar cases 2029 if (panelh > disph || (panelh < disph && !mTracking && !mAnimating)) { 2030 panelh = disph; 2031 } else if (panelh < 0) { 2032 panelh = 0; 2033 } 2034 2035 if (panelh == mTrackingPosition) return; 2036 2037 mTrackingPosition = panelh; 2038 2039 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mNotificationPanel.getLayoutParams(); 2040 lp.height = panelh; 2041 lp.gravity = mNotificationPanelGravity; 2042 lp.leftMargin = mNotificationPanelMarginLeftPx; 2043 if (SPEW) { 2044 Slog.v(TAG, "updated cropView height=" + panelh + " grav=" + lp.gravity); 2045 } 2046 mNotificationPanel.setLayoutParams(lp); 2047 2048 final int barh = getCloseViewHeight() + getStatusBarHeight(); 2049 final float frac = saturate((float)(panelh - barh) / (disph - barh)); 2050 2051 if (DIM_BEHIND_EXPANDED_PANEL && ActivityManager.isHighEndGfx(mDisplay)) { 2052 // woo, special effects 2053 final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2.2f)))); 2054 final int color = ((int)(0xB0 * k)) << 24; 2055 mStatusBarWindow.setBackgroundColor(color); 2056 } 2057 2058 updateCarrierLabelVisibility(false); 2059 } 2060 2061 void updateDisplaySize() { 2062 mDisplay.getMetrics(mDisplayMetrics); 2063 } 2064 2065 void performDisableActions(int net) { 2066 int old = mDisabled; 2067 int diff = net ^ old; 2068 mDisabled = net; 2069 2070 // act accordingly 2071 if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { 2072 if ((net & StatusBarManager.DISABLE_EXPAND) != 0) { 2073 Slog.d(TAG, "DISABLE_EXPAND: yes"); 2074 animateCollapse(); 2075 } 2076 } 2077 if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 2078 if ((net & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 2079 Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes"); 2080 if (mTicking) { 2081 mNotificationIcons.setVisibility(View.INVISIBLE); 2082 mTicker.halt(); 2083 } else { 2084 setNotificationIconVisibility(false, com.android.internal.R.anim.fade_out); 2085 } 2086 } else { 2087 Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no"); 2088 if (!mExpandedVisible) { 2089 setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in); 2090 } 2091 } 2092 } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 2093 if (mTicking && (net & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 2094 mTicker.halt(); 2095 } 2096 } 2097 } 2098 2099 private View.OnClickListener mClearButtonListener = new View.OnClickListener() { 2100 final int mini(int a, int b) { 2101 return (b>a?a:b); 2102 } 2103 public void onClick(View v) { 2104 synchronized (mNotificationData) { 2105 // animate-swipe all dismissable notifications, then animate the shade closed 2106 int numChildren = mPile.getChildCount(); 2107 2108 int scrollTop = mScrollView.getScrollY(); 2109 int scrollBottom = scrollTop + mScrollView.getHeight(); 2110 final ArrayList<View> snapshot = new ArrayList<View>(numChildren); 2111 for (int i=0; i<numChildren; i++) { 2112 final View child = mPile.getChildAt(i); 2113 if (mPile.canChildBeDismissed(child) && child.getBottom() > scrollTop && 2114 child.getTop() < scrollBottom) { 2115 snapshot.add(child); 2116 } 2117 } 2118 if (snapshot.isEmpty()) { 2119 animateCollapse(CommandQueue.FLAG_EXCLUDE_NONE); 2120 return; 2121 } 2122 new Thread(new Runnable() { 2123 @Override 2124 public void run() { 2125 // Decrease the delay for every row we animate to give the sense of 2126 // accelerating the swipes 2127 final int ROW_DELAY_DECREMENT = 10; 2128 int currentDelay = 140; 2129 int totalDelay = 0; 2130 2131 // Set the shade-animating state to avoid doing other work during 2132 // all of these animations. In particular, avoid layout and 2133 // redrawing when collapsing the shade. 2134 mPile.setViewRemoval(false); 2135 2136 mPostCollapseCleanup = new Runnable() { 2137 @Override 2138 public void run() { 2139 try { 2140 mPile.setViewRemoval(true); 2141 mBarService.onClearAllNotifications(); 2142 } catch (Exception ex) { } 2143 } 2144 }; 2145 2146 View sampleView = snapshot.get(0); 2147 int width = sampleView.getWidth(); 2148 final int velocity = width * 8; // 1000/8 = 125 ms duration 2149 for (final View _v : snapshot) { 2150 mHandler.postDelayed(new Runnable() { 2151 @Override 2152 public void run() { 2153 mPile.dismissRowAnimated(_v, velocity); 2154 } 2155 }, totalDelay); 2156 currentDelay = Math.max(50, currentDelay - ROW_DELAY_DECREMENT); 2157 totalDelay += currentDelay; 2158 } 2159 // Delay the collapse animation until after all swipe animations have 2160 // finished. Provide some buffer because there may be some extra delay 2161 // before actually starting each swipe animation. Ideally, we'd 2162 // synchronize the end of those animations with the start of the collaps 2163 // exactly. 2164 mHandler.postDelayed(new Runnable() { 2165 @Override 2166 public void run() { 2167 animateCollapse(CommandQueue.FLAG_EXCLUDE_NONE); 2168 } 2169 }, totalDelay + 225); 2170 } 2171 }).start(); 2172 } 2173 } 2174 }; 2175 2176 private View.OnClickListener mSettingsButtonListener = new View.OnClickListener() { 2177 public void onClick(View v) { 2178 // We take this as a good indicator that Setup is running and we shouldn't 2179 // allow you to go somewhere else 2180 if (!isDeviceProvisioned()) return; 2181 try { 2182 // Dismiss the lock screen when Settings starts. 2183 ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity(); 2184 } catch (RemoteException e) { 2185 } 2186 v.getContext().startActivity(new Intent(Settings.ACTION_SETTINGS) 2187 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 2188 animateCollapse(); 2189 } 2190 }; 2191 2192 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 2193 public void onReceive(Context context, Intent intent) { 2194 String action = intent.getAction(); 2195 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action) 2196 || Intent.ACTION_SCREEN_OFF.equals(action)) { 2197 int flags = CommandQueue.FLAG_EXCLUDE_NONE; 2198 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { 2199 String reason = intent.getStringExtra("reason"); 2200 if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) { 2201 flags |= CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL; 2202 } 2203 } 2204 animateCollapse(flags); 2205 } 2206 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { 2207 updateResources(); 2208 repositionNavigationBar(); 2209 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 2210 } 2211 } 2212 }; 2213 2214 private void setIntruderAlertVisibility(boolean vis) { 2215 if (!ENABLE_INTRUDERS) return; 2216 if (DEBUG) { 2217 Slog.v(TAG, (vis ? "showing" : "hiding") + " intruder alert window"); 2218 } 2219 mIntruderAlertView.setVisibility(vis ? View.VISIBLE : View.GONE); 2220 } 2221 2222 public void dismissIntruder() { 2223 if (mCurrentlyIntrudingNotification == null) return; 2224 2225 try { 2226 mBarService.onNotificationClear( 2227 mCurrentlyIntrudingNotification.pkg, 2228 mCurrentlyIntrudingNotification.tag, 2229 mCurrentlyIntrudingNotification.id); 2230 } catch (android.os.RemoteException ex) { 2231 // oh well 2232 } 2233 } 2234 2235 /** 2236 * Reload some of our resources when the configuration changes. 2237 * 2238 * We don't reload everything when the configuration changes -- we probably 2239 * should, but getting that smooth is tough. Someday we'll fix that. In the 2240 * meantime, just update the things that we know change. 2241 */ 2242 void updateResources() { 2243 final Context context = mContext; 2244 final Resources res = context.getResources(); 2245 2246 if (mClearButton instanceof TextView) { 2247 ((TextView)mClearButton).setText(context.getText(R.string.status_bar_clear_all_button)); 2248 } 2249 loadDimens(); 2250 } 2251 2252 protected void loadDimens() { 2253 final Resources res = mContext.getResources(); 2254 2255 mNaturalBarHeight = res.getDimensionPixelSize( 2256 com.android.internal.R.dimen.status_bar_height); 2257 2258 int newIconSize = res.getDimensionPixelSize( 2259 com.android.internal.R.dimen.status_bar_icon_size); 2260 int newIconHPadding = res.getDimensionPixelSize( 2261 R.dimen.status_bar_icon_padding); 2262 2263 if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) { 2264// Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding); 2265 mIconHPadding = newIconHPadding; 2266 mIconSize = newIconSize; 2267 //reloadAllNotificationIcons(); // reload the tray 2268 } 2269 2270 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore); 2271 2272 mSelfExpandVelocityPx = res.getDimension(R.dimen.self_expand_velocity); 2273 mSelfCollapseVelocityPx = res.getDimension(R.dimen.self_collapse_velocity); 2274 mFlingExpandMinVelocityPx = res.getDimension(R.dimen.fling_expand_min_velocity); 2275 mFlingCollapseMinVelocityPx = res.getDimension(R.dimen.fling_collapse_min_velocity); 2276 2277 mCollapseMinDisplayFraction = res.getFraction(R.dimen.collapse_min_display_fraction, 1, 1); 2278 mExpandMinDisplayFraction = res.getFraction(R.dimen.expand_min_display_fraction, 1, 1); 2279 2280 mExpandAccelPx = res.getDimension(R.dimen.expand_accel); 2281 mCollapseAccelPx = res.getDimension(R.dimen.collapse_accel); 2282 2283 mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity); 2284 2285 mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity); 2286 2287 mNotificationPanelMarginBottomPx 2288 = (int) res.getDimension(R.dimen.notification_panel_margin_bottom); 2289 mNotificationPanelMarginLeftPx 2290 = (int) res.getDimension(R.dimen.notification_panel_margin_left); 2291 mNotificationPanelGravity = res.getInteger(R.integer.notification_panel_layout_gravity); 2292 if (mNotificationPanelGravity <= 0) { 2293 mNotificationPanelGravity = Gravity.CENTER_VERTICAL | Gravity.TOP; 2294 } 2295 getNinePatchPadding(res.getDrawable(R.drawable.notification_panel_bg), mNotificationPanelBackgroundPadding); 2296 final int notificationPanelDecorationHeight = 2297 res.getDimensionPixelSize(R.dimen.notification_panel_padding_top) 2298 + res.getDimensionPixelSize(R.dimen.notification_panel_header_height) 2299 + mNotificationPanelBackgroundPadding.top 2300 + mNotificationPanelBackgroundPadding.bottom; 2301 mNotificationPanelMinHeight = 2302 notificationPanelDecorationHeight 2303 + res.getDimensionPixelSize(R.dimen.close_handle_underlap); 2304 2305 mCarrierLabelHeight = res.getDimensionPixelSize(R.dimen.carrier_label_height); 2306 2307 if (false) Slog.v(TAG, "updateResources"); 2308 } 2309 2310 private static void getNinePatchPadding(Drawable d, Rect outPadding) { 2311 if (d instanceof NinePatchDrawable) { 2312 NinePatchDrawable ninePatch = (NinePatchDrawable) d; 2313 ninePatch.getPadding(outPadding); 2314 } 2315 } 2316 2317 // 2318 // tracing 2319 // 2320 2321 void postStartTracing() { 2322 mHandler.postDelayed(mStartTracing, 3000); 2323 } 2324 2325 void vibrate() { 2326 android.os.Vibrator vib = (android.os.Vibrator)mContext.getSystemService( 2327 Context.VIBRATOR_SERVICE); 2328 vib.vibrate(250); 2329 } 2330 2331 Runnable mStartTracing = new Runnable() { 2332 public void run() { 2333 vibrate(); 2334 SystemClock.sleep(250); 2335 Slog.d(TAG, "startTracing"); 2336 android.os.Debug.startMethodTracing("/data/statusbar-traces/trace"); 2337 mHandler.postDelayed(mStopTracing, 10000); 2338 } 2339 }; 2340 2341 Runnable mStopTracing = new Runnable() { 2342 public void run() { 2343 android.os.Debug.stopMethodTracing(); 2344 Slog.d(TAG, "stopTracing"); 2345 vibrate(); 2346 } 2347 }; 2348 2349 @Override 2350 protected void haltTicker() { 2351 mTicker.halt(); 2352 } 2353 2354 @Override 2355 protected boolean shouldDisableNavbarGestures() { 2356 return mExpanded || (mDisabled & StatusBarManager.DISABLE_HOME) != 0; 2357 } 2358 2359 private static class FastColorDrawable extends Drawable { 2360 private final int mColor; 2361 2362 public FastColorDrawable(int color) { 2363 mColor = 0xff000000 | color; 2364 } 2365 2366 @Override 2367 public void draw(Canvas canvas) { 2368 canvas.drawColor(mColor, PorterDuff.Mode.SRC); 2369 } 2370 2371 @Override 2372 public void setAlpha(int alpha) { 2373 } 2374 2375 @Override 2376 public void setColorFilter(ColorFilter cf) { 2377 } 2378 2379 @Override 2380 public int getOpacity() { 2381 return PixelFormat.OPAQUE; 2382 } 2383 2384 @Override 2385 public void setBounds(int left, int top, int right, int bottom) { 2386 } 2387 2388 @Override 2389 public void setBounds(Rect bounds) { 2390 } 2391 } 2392} 2393