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