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