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