PhoneStatusBar.java revision e680f5483f845e2c9f75b80358599b5d654a9f8b
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.AnimatorListenerAdapter; 21import android.animation.AnimatorSet; 22import android.animation.ObjectAnimator; 23import android.app.ActivityManager; 24import android.app.ActivityManagerNative; 25import android.app.Notification; 26import android.app.PendingIntent; 27import android.app.StatusBarManager; 28import android.content.BroadcastReceiver; 29import android.content.Context; 30import android.content.Intent; 31import android.content.IntentFilter; 32import android.content.res.Resources; 33import android.graphics.Canvas; 34import android.graphics.ColorFilter; 35import android.graphics.PixelFormat; 36import android.graphics.Point; 37import android.graphics.PorterDuff; 38import android.graphics.Rect; 39import android.graphics.drawable.Drawable; 40import android.graphics.drawable.NinePatchDrawable; 41import android.inputmethodservice.InputMethodService; 42import android.os.IBinder; 43import android.os.Message; 44import android.os.RemoteException; 45import android.os.ServiceManager; 46import android.os.SystemClock; 47import android.os.UserHandle; 48import android.provider.Settings; 49import android.service.dreams.Dream; 50import android.service.dreams.IDreamManager; 51import android.util.DisplayMetrics; 52import android.util.Log; 53import android.util.Slog; 54import android.view.Display; 55import android.view.Gravity; 56import android.view.MotionEvent; 57import android.view.VelocityTracker; 58import android.view.View; 59import android.view.ViewGroup; 60import android.view.ViewGroup.LayoutParams; 61import android.view.WindowManager; 62import android.view.animation.AccelerateInterpolator; 63import android.view.animation.Animation; 64import android.view.animation.AnimationUtils; 65import android.view.animation.DecelerateInterpolator; 66import android.widget.FrameLayout; 67import android.widget.ImageView; 68import android.widget.LinearLayout; 69import android.widget.ScrollView; 70import android.widget.TextView; 71 72import com.android.internal.statusbar.StatusBarIcon; 73import com.android.internal.statusbar.StatusBarNotification; 74import com.android.systemui.R; 75import com.android.systemui.statusbar.BaseStatusBar; 76import com.android.systemui.statusbar.CommandQueue; 77import com.android.systemui.statusbar.GestureRecorder; 78import com.android.systemui.statusbar.NotificationData; 79import com.android.systemui.statusbar.NotificationData.Entry; 80import com.android.systemui.statusbar.SignalClusterView; 81import com.android.systemui.statusbar.StatusBarIconView; 82import com.android.systemui.statusbar.policy.BatteryController; 83import com.android.systemui.statusbar.policy.BluetoothController; 84import com.android.systemui.statusbar.policy.DateView; 85import com.android.systemui.statusbar.policy.IntruderAlertView; 86import com.android.systemui.statusbar.policy.LocationController; 87import com.android.systemui.statusbar.policy.NetworkController; 88import com.android.systemui.statusbar.policy.NotificationRowLayout; 89import com.android.systemui.statusbar.policy.OnSizeChangedListener; 90 91import java.io.FileDescriptor; 92import java.io.PrintWriter; 93import java.util.ArrayList; 94 95public class PhoneStatusBar extends BaseStatusBar { 96 static final String TAG = "PhoneStatusBar"; 97 public static final boolean DEBUG = BaseStatusBar.DEBUG; 98 public static final boolean SPEW = DEBUG; 99 public static final boolean DUMPTRUCK = true; // extra dumpsys info 100 101 // additional instrumentation for testing purposes; intended to be left on during development 102 public static final boolean CHATTY = DEBUG; 103 104 public static final String ACTION_STATUSBAR_START 105 = "com.android.internal.policy.statusbar.START"; 106 107 private static final int MSG_OPEN_NOTIFICATION_PANEL = 1000; 108 private static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001; 109 // 1020-1030 reserved for BaseStatusBar 110 111 // will likely move to a resource or other tunable param at some point 112 private static final int INTRUDER_ALERT_DECAY_MS = 0; // disabled, was 10000; 113 114 private static final boolean CLOSE_PANEL_WHEN_EMPTIED = true; 115 116 private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10; // see NotificationManagerService 117 private static final int HIDE_ICONS_BELOW_SCORE = Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER; 118 119 // fling gesture tuning parameters, scaled to display density 120 private float mSelfExpandVelocityPx; // classic value: 2000px/s 121 private float mSelfCollapseVelocityPx; // classic value: 2000px/s (will be negated to collapse "up") 122 private float mFlingExpandMinVelocityPx; // classic value: 200px/s 123 private float mFlingCollapseMinVelocityPx; // classic value: 200px/s 124 private float mCollapseMinDisplayFraction; // classic value: 0.08 (25px/min(320px,480px) on G1) 125 private float mExpandMinDisplayFraction; // classic value: 0.5 (drag open halfway to expand) 126 private float mFlingGestureMaxXVelocityPx; // classic value: 150px/s 127 128 private float mExpandAccelPx; // classic value: 2000px/s/s 129 private float mCollapseAccelPx; // classic value: 2000px/s/s (will be negated to collapse "up") 130 131 private float mFlingGestureMaxOutputVelocityPx; // how fast can it really go? (should be a little 132 // faster than mSelfCollapseVelocityPx) 133 134 PhoneStatusBarPolicy mIconPolicy; 135 136 // These are no longer handled by the policy, because we need custom strategies for them 137 BluetoothController mBluetoothController; 138 BatteryController mBatteryController; 139 LocationController mLocationController; 140 NetworkController mNetworkController; 141 142 int mNaturalBarHeight = -1; 143 int mIconSize = -1; 144 int mIconHPadding = -1; 145 Display mDisplay; 146 Point mCurrentDisplaySize = new Point(); 147 148 IDreamManager mDreamManager; 149 150 StatusBarWindowView mStatusBarWindow; 151 PhoneStatusBarView mStatusBarView; 152 153 int mPixelFormat; 154 Object mQueueLock = new Object(); 155 156 // viewgroup containing the normal contents of the statusbar 157 LinearLayout mStatusBarContents; 158 159 // right-hand icons 160 LinearLayout mSystemIconArea; 161 162 // left-hand icons 163 LinearLayout mStatusIcons; 164 // the icons themselves 165 IconMerger mNotificationIcons; 166 // [+> 167 View mMoreIcon; 168 169 // expanded notifications 170 PanelView mNotificationPanel; // the sliding/resizing panel within the notification window 171 ScrollView mScrollView; 172 View mExpandedContents; 173 int mNotificationPanelGravity; 174 int mNotificationPanelMarginBottomPx, mNotificationPanelMarginPx; 175 float mNotificationPanelMinHeightFrac; 176 boolean mNotificationPanelIsFullScreenWidth; 177 TextView mNotificationPanelDebugText; 178 179 // settings 180 SettingsPanelView mSettingsPanel; 181 int mSettingsPanelGravity; 182 183 // top bar 184 View mClearButton; 185 View mSettingsButton; 186 187 // carrier/wifi label 188 private TextView mCarrierLabel; 189 private boolean mCarrierLabelVisible = false; 190 private int mCarrierLabelHeight; 191 private TextView mEmergencyCallLabel; 192 private int mNotificationHeaderHeight; 193 194 private boolean mShowCarrierInPanel = false; 195 196 // position 197 int[] mPositionTmp = new int[2]; 198 boolean mExpandedVisible; 199 200 // the date view 201 DateView mDateView; 202 203 // for immersive activities 204 private IntruderAlertView mIntruderAlertView; 205 206 // on-screen navigation buttons 207 private NavigationBarView mNavigationBarView = null; 208 209 // the tracker view 210 int mTrackingPosition; // the position of the top of the tracking view. 211 212 // ticker 213 private Ticker mTicker; 214 private View mTickerView; 215 private boolean mTicking; 216 217 // Tracking finger for opening/closing. 218 int mEdgeBorder; // corresponds to R.dimen.status_bar_edge_ignore 219 boolean mTracking; 220 VelocityTracker mVelocityTracker; 221 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 Animator mLightsOutAnimation; 236 private Animator 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 // XXX: gesture research 247 private GestureRecorder mGestureRec = new GestureRecorder("/sdcard/statusbar_gestures.dat"); 248 249 private int mNavigationIconHints = 0; 250 private final Animator.AnimatorListener mMakeIconsInvisible = new AnimatorListenerAdapter() { 251 @Override 252 public void onAnimationEnd(Animator animation) { 253 // double-check to avoid races 254 if (mStatusBarContents.getAlpha() == 0) { 255 Slog.d(TAG, "makeIconsInvisible"); 256 mStatusBarContents.setVisibility(View.INVISIBLE); 257 } 258 } 259 }; 260 261 @Override 262 public void start() { 263 mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) 264 .getDefaultDisplay(); 265 266 mDreamManager = IDreamManager.Stub.asInterface( 267 ServiceManager.checkService(Dream.DREAM_SERVICE)); 268 269 super.start(); // calls createAndAddWindows() 270 271 addNavigationBar(); 272 273 if (ENABLE_INTRUDERS) addIntruderView(); 274 275 // Lastly, call to the icon policy to install/update all the icons. 276 mIconPolicy = new PhoneStatusBarPolicy(mContext); 277 } 278 279 // ================================================================================ 280 // Constructing the view 281 // ================================================================================ 282 protected PhoneStatusBarView makeStatusBarView() { 283 final Context context = mContext; 284 285 Resources res = context.getResources(); 286 287 updateDisplaySize(); // populates mDisplayMetrics 288 loadDimens(); 289 290 mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); 291 292 mStatusBarWindow = (StatusBarWindowView) View.inflate(context, 293 R.layout.super_status_bar, null); 294 mStatusBarWindow.mService = this; 295 mStatusBarWindow.setOnTouchListener(new View.OnTouchListener() { 296 @Override 297 public boolean onTouch(View v, MotionEvent event) { 298 if (event.getAction() == MotionEvent.ACTION_DOWN) { 299 if (mExpandedVisible && !mAnimating) { 300 animateCollapseNotifications(); 301 } 302 } 303 return mStatusBarWindow.onTouchEvent(event); 304 }}); 305 306 mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar); 307 mStatusBarView.setBar(this); 308 309 PanelHolder holder = (PanelHolder) mStatusBarWindow.findViewById(R.id.panel_holder); 310 mStatusBarView.setPanelHolder(holder); 311 312 mNotificationPanel = (PanelView) mStatusBarWindow.findViewById(R.id.notification_panel); 313 mNotificationPanelIsFullScreenWidth = 314 (mNotificationPanel.getLayoutParams().width == ViewGroup.LayoutParams.MATCH_PARENT); 315 mNotificationPanel.setSystemUiVisibility( 316 View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER | View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS); 317 318 if (!ActivityManager.isHighEndGfx()) { 319 mStatusBarWindow.setBackground(null); 320 mNotificationPanel.setBackground(new FastColorDrawable(context.getResources().getColor( 321 R.color.notification_panel_solid_background))); 322 } 323 if (ENABLE_INTRUDERS) { 324 mIntruderAlertView = (IntruderAlertView) View.inflate(context, R.layout.intruder_alert, null); 325 mIntruderAlertView.setVisibility(View.GONE); 326 mIntruderAlertView.setBar(this); 327 } 328 if (MULTIUSER_DEBUG) { 329 mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(R.id.header_debug_info); 330 mNotificationPanelDebugText.setVisibility(View.VISIBLE); 331 } 332 333 updateShowSearchHoldoff(); 334 335 try { 336 boolean showNav = mWindowManagerService.hasNavigationBar(); 337 if (DEBUG) Slog.v(TAG, "hasNavigationBar=" + showNav); 338 if (showNav) { 339 mNavigationBarView = 340 (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null); 341 342 mNavigationBarView.setDisabledFlags(mDisabled); 343 mNavigationBarView.setBar(this); 344 } 345 } catch (RemoteException ex) { 346 // no window manager? good luck with that 347 } 348 349 // figure out which pixel-format to use for the status bar. 350 mPixelFormat = PixelFormat.OPAQUE; 351 352 mSystemIconArea = (LinearLayout) mStatusBarView.findViewById(R.id.system_icon_area); 353 mStatusIcons = (LinearLayout)mStatusBarView.findViewById(R.id.statusIcons); 354 mNotificationIcons = (IconMerger)mStatusBarView.findViewById(R.id.notificationIcons); 355 mNotificationIcons.setOverflowIndicator(mMoreIcon); 356 mStatusBarContents = (LinearLayout)mStatusBarView.findViewById(R.id.status_bar_contents); 357 mTickerView = mStatusBarView.findViewById(R.id.ticker); 358 359 mPile = (NotificationRowLayout)mStatusBarWindow.findViewById(R.id.latestItems); 360 mPile.setLayoutTransitionsEnabled(false); 361 mPile.setLongPressListener(getNotificationLongClicker()); 362 mExpandedContents = mPile; // was: expanded.findViewById(R.id.notificationLinearLayout); 363 364 mClearButton = mStatusBarWindow.findViewById(R.id.clear_all_button); 365 mClearButton.setOnClickListener(mClearButtonListener); 366 mClearButton.setAlpha(0f); 367 mClearButton.setVisibility(View.INVISIBLE); 368 mClearButton.setEnabled(false); 369 mDateView = (DateView)mStatusBarWindow.findViewById(R.id.date); 370 mSettingsButton = mStatusBarWindow.findViewById(R.id.settings_button); 371 if (mSettingsButton != null) { 372 mSettingsButton.setOnClickListener(mSettingsButtonListener); 373 } 374 375 mScrollView = (ScrollView)mStatusBarWindow.findViewById(R.id.scroll); 376 mScrollView.setVerticalScrollBarEnabled(false); // less drawing during pulldowns 377 378 mTicker = new MyTicker(context, mStatusBarView); 379 380 TickerView tickerView = (TickerView)mStatusBarView.findViewById(R.id.tickerText); 381 tickerView.mTicker = mTicker; 382 383 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore); 384 385 // set the inital view visibility 386 setAreThereNotifications(); 387 388 // Other icons 389 mLocationController = new LocationController(mContext); // will post a notification 390 mBatteryController = new BatteryController(mContext); 391 mBatteryController.addIconView((ImageView)mStatusBarView.findViewById(R.id.battery)); 392 mNetworkController = new NetworkController(mContext); 393 mBluetoothController = new BluetoothController(mContext); 394 final SignalClusterView signalCluster = 395 (SignalClusterView)mStatusBarView.findViewById(R.id.signal_cluster); 396 397 398 mNetworkController.addSignalCluster(signalCluster); 399 signalCluster.setNetworkController(mNetworkController); 400 401 mEmergencyCallLabel = (TextView)mStatusBarWindow.findViewById(R.id.emergency_calls_only); 402 if (mEmergencyCallLabel != null) { 403 mNetworkController.addEmergencyLabelView(mEmergencyCallLabel); 404 mEmergencyCallLabel.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { 405 @Override 406 public void onLayoutChange(View v, int left, int top, int right, int bottom, 407 int oldLeft, int oldTop, int oldRight, int oldBottom) { 408 updateCarrierLabelVisibility(false); 409 }}); 410 } 411 412 mCarrierLabel = (TextView)mStatusBarWindow.findViewById(R.id.carrier_label); 413 mShowCarrierInPanel = (mCarrierLabel != null); 414 Slog.v(TAG, "carrierlabel=" + mCarrierLabel + " show=" + mShowCarrierInPanel); 415 if (mShowCarrierInPanel) { 416 mCarrierLabel.setVisibility(mCarrierLabelVisible ? View.VISIBLE : View.INVISIBLE); 417 418 // for mobile devices, we always show mobile connection info here (SPN/PLMN) 419 // for other devices, we show whatever network is connected 420 if (mNetworkController.hasMobileDataFeature()) { 421 mNetworkController.addMobileLabelView(mCarrierLabel); 422 } else { 423 mNetworkController.addCombinedLabelView(mCarrierLabel); 424 } 425 426 // set up the dynamic hide/show of the label 427 mPile.setOnSizeChangedListener(new OnSizeChangedListener() { 428 @Override 429 public void onSizeChanged(View view, int w, int h, int oldw, int oldh) { 430 updateCarrierLabelVisibility(false); 431 } 432 }); 433 } 434 435 // Quick Settings (WIP) 436 mSettingsPanel = (SettingsPanelView) mStatusBarWindow.findViewById(R.id.settings_panel); 437 mSettingsPanel.setBar(mStatusBarView); 438 mSettingsPanel.setService(this); 439 mSettingsPanel.setup(mNetworkController, mBluetoothController, mBatteryController, 440 mLocationController); 441 mSettingsPanel.setSystemUiVisibility( 442 View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER | View.STATUS_BAR_DISABLE_SYSTEM_INFO); 443 444 if (!ActivityManager.isHighEndGfx()) { 445 mSettingsPanel.setBackground(new FastColorDrawable(context.getResources().getColor( 446 R.color.notification_panel_solid_background))); 447 } 448 449// final ImageView wimaxRSSI = 450// (ImageView)sb.findViewById(R.id.wimax_signal); 451// if (wimaxRSSI != null) { 452// mNetworkController.addWimaxIconView(wimaxRSSI); 453// } 454 455 // receive broadcasts 456 IntentFilter filter = new IntentFilter(); 457 filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); 458 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 459 filter.addAction(Intent.ACTION_SCREEN_OFF); 460 filter.addAction(Intent.ACTION_SCREEN_ON); 461 context.registerReceiver(mBroadcastReceiver, filter); 462 463 return mStatusBarView; 464 } 465 466 @Override 467 protected View getStatusBarView() { 468 return mStatusBarView; 469 } 470 471 @Override 472 protected WindowManager.LayoutParams getRecentsLayoutParams(LayoutParams layoutParams) { 473 boolean opaque = false; 474 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 475 layoutParams.width, 476 layoutParams.height, 477 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 478 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 479 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 480 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 481 (opaque ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT)); 482 if (ActivityManager.isHighEndGfx()) { 483 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 484 } else { 485 lp.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND; 486 lp.dimAmount = 0.75f; 487 } 488 lp.gravity = Gravity.BOTTOM | Gravity.LEFT; 489 lp.setTitle("RecentsPanel"); 490 lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications; 491 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 492 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 493 return lp; 494 } 495 496 @Override 497 protected WindowManager.LayoutParams getSearchLayoutParams(LayoutParams layoutParams) { 498 boolean opaque = false; 499 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 500 LayoutParams.MATCH_PARENT, 501 LayoutParams.MATCH_PARENT, 502 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, 503 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 504 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 505 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 506 (opaque ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT)); 507 if (ActivityManager.isHighEndGfx()) { 508 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 509 } 510 lp.gravity = Gravity.BOTTOM | Gravity.LEFT; 511 lp.setTitle("SearchPanel"); 512 // TODO: Define custom animation for Search panel 513 lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications; 514 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 515 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 516 return lp; 517 } 518 519 @Override 520 protected void updateSearchPanel() { 521 super.updateSearchPanel(); 522 mSearchPanelView.setStatusBarView(mNavigationBarView); 523 mNavigationBarView.setDelegateView(mSearchPanelView); 524 } 525 526 @Override 527 public void showSearchPanel() { 528 super.showSearchPanel(); 529 WindowManager.LayoutParams lp = 530 (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams(); 531 lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; 532 mWindowManager.updateViewLayout(mNavigationBarView, lp); 533 } 534 535 @Override 536 public void hideSearchPanel() { 537 super.hideSearchPanel(); 538 WindowManager.LayoutParams lp = 539 (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams(); 540 lp.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; 541 mWindowManager.updateViewLayout(mNavigationBarView, lp); 542 } 543 544 protected int getStatusBarGravity() { 545 return Gravity.TOP | Gravity.FILL_HORIZONTAL; 546 } 547 548 public int getStatusBarHeight() { 549 if (mNaturalBarHeight < 0) { 550 final Resources res = mContext.getResources(); 551 mNaturalBarHeight = 552 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); 553 } 554 return mNaturalBarHeight; 555 } 556 557 private View.OnClickListener mRecentsClickListener = new View.OnClickListener() { 558 public void onClick(View v) { 559 toggleRecentApps(); 560 } 561 }; 562 563 private int mShowSearchHoldoff = 0; 564 private Runnable mShowSearchPanel = new Runnable() { 565 public void run() { 566 showSearchPanel(); 567 awakenDreams(); 568 } 569 }; 570 571 View.OnTouchListener mHomeSearchActionListener = new View.OnTouchListener() { 572 public boolean onTouch(View v, MotionEvent event) { 573 switch(event.getAction()) { 574 case MotionEvent.ACTION_DOWN: 575 if (!shouldDisableNavbarGestures() && !inKeyguardRestrictedInputMode()) { 576 mHandler.removeCallbacks(mShowSearchPanel); 577 mHandler.postDelayed(mShowSearchPanel, mShowSearchHoldoff); 578 } 579 break; 580 581 case MotionEvent.ACTION_UP: 582 case MotionEvent.ACTION_CANCEL: 583 mHandler.removeCallbacks(mShowSearchPanel); 584 awakenDreams(); 585 break; 586 } 587 return false; 588 } 589 }; 590 591 private void awakenDreams() { 592 if (mDreamManager != null) { 593 try { 594 mDreamManager.awaken(); 595 } catch (RemoteException e) { 596 // fine, stay asleep then 597 } 598 } 599 } 600 601 private void prepareNavigationBarView() { 602 mNavigationBarView.reorient(); 603 604 mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener); 605 mNavigationBarView.getRecentsButton().setOnTouchListener(getRecentTasksLoader()); 606 mNavigationBarView.getHomeButton().setOnTouchListener(mHomeSearchActionListener); 607 updateSearchPanel(); 608 } 609 610 // For small-screen devices (read: phones) that lack hardware navigation buttons 611 private void addNavigationBar() { 612 if (DEBUG) Slog.v(TAG, "addNavigationBar: about to add " + mNavigationBarView); 613 if (mNavigationBarView == null) return; 614 615 prepareNavigationBarView(); 616 617 mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams()); 618 } 619 620 private void repositionNavigationBar() { 621 if (mNavigationBarView == null) return; 622 623 prepareNavigationBarView(); 624 625 mWindowManager.updateViewLayout(mNavigationBarView, getNavigationBarLayoutParams()); 626 } 627 628 private WindowManager.LayoutParams getNavigationBarLayoutParams() { 629 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 630 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 631 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, 632 0 633 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING 634 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 635 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 636 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH 637 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 638 PixelFormat.OPAQUE); 639 // this will allow the navbar to run in an overlay on devices that support this 640 if (ActivityManager.isHighEndGfx()) { 641 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 642 } 643 644 lp.setTitle("NavigationBar"); 645 lp.windowAnimations = 0; 646 return lp; 647 } 648 649 private void addIntruderView() { 650 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 651 ViewGroup.LayoutParams.MATCH_PARENT, 652 ViewGroup.LayoutParams.WRAP_CONTENT, 653 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, // above the status bar! 654 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 655 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 656 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 657 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 658 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 659 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 660 PixelFormat.TRANSLUCENT); 661 lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL; 662 //lp.y += height * 1.5; // FIXME 663 lp.setTitle("IntruderAlert"); 664 lp.packageName = mContext.getPackageName(); 665 lp.windowAnimations = R.style.Animation_StatusBar_IntruderAlert; 666 667 mWindowManager.addView(mIntruderAlertView, lp); 668 } 669 670 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) { 671 if (SPEW) Slog.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex 672 + " icon=" + icon); 673 StatusBarIconView view = new StatusBarIconView(mContext, slot, null); 674 view.set(icon); 675 mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(mIconSize, mIconSize)); 676 } 677 678 public void updateIcon(String slot, int index, int viewIndex, 679 StatusBarIcon old, StatusBarIcon icon) { 680 if (SPEW) Slog.d(TAG, "updateIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex 681 + " old=" + old + " icon=" + icon); 682 StatusBarIconView view = (StatusBarIconView)mStatusIcons.getChildAt(viewIndex); 683 view.set(icon); 684 } 685 686 public void removeIcon(String slot, int index, int viewIndex) { 687 if (SPEW) Slog.d(TAG, "removeIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex); 688 mStatusIcons.removeViewAt(viewIndex); 689 } 690 691 public void addNotification(IBinder key, StatusBarNotification notification) { 692 /* if (DEBUG) */ Slog.d(TAG, "addNotification score=" + notification.score); 693 StatusBarIconView iconView = addNotificationViews(key, notification); 694 if (iconView == null) return; 695 696 boolean immersive = false; 697 try { 698 immersive = ActivityManagerNative.getDefault().isTopActivityImmersive(); 699 if (DEBUG) { 700 Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); 701 } 702 } catch (RemoteException ex) { 703 } 704 705 /* 706 * DISABLED due to missing API 707 if (ENABLE_INTRUDERS && ( 708 // TODO(dsandler): Only if the screen is on 709 notification.notification.intruderView != null)) { 710 Slog.d(TAG, "Presenting high-priority notification"); 711 // special new transient ticker mode 712 // 1. Populate mIntruderAlertView 713 714 if (notification.notification.intruderView == null) { 715 Slog.e(TAG, notification.notification.toString() + " wanted to intrude but intruderView was null"); 716 return; 717 } 718 719 // bind the click event to the content area 720 PendingIntent contentIntent = notification.notification.contentIntent; 721 final View.OnClickListener listener = (contentIntent != null) 722 ? new NotificationClicker(contentIntent, 723 notification.pkg, notification.tag, notification.id) 724 : null; 725 726 mIntruderAlertView.applyIntruderContent(notification.notification.intruderView, listener); 727 728 mCurrentlyIntrudingNotification = notification; 729 730 // 2. Animate mIntruderAlertView in 731 mHandler.sendEmptyMessage(MSG_SHOW_INTRUDER); 732 733 // 3. Set alarm to age the notification off (TODO) 734 mHandler.removeMessages(MSG_HIDE_INTRUDER); 735 if (INTRUDER_ALERT_DECAY_MS > 0) { 736 mHandler.sendEmptyMessageDelayed(MSG_HIDE_INTRUDER, INTRUDER_ALERT_DECAY_MS); 737 } 738 } else 739 */ 740 741 if (notification.notification.fullScreenIntent != null) { 742 // Stop screensaver if the notification has a full-screen intent. 743 // (like an incoming phone call) 744 awakenDreams(); 745 746 // not immersive & a full-screen alert should be shown 747 Slog.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent"); 748 try { 749 notification.notification.fullScreenIntent.send(); 750 } catch (PendingIntent.CanceledException e) { 751 } 752 } else { 753 // usual case: status bar visible & not immersive 754 755 // show the ticker if there isn't an intruder too 756 if (mCurrentlyIntrudingNotification == null) { 757 tick(null, notification, true); 758 } 759 } 760 761 // Recalculate the position of the sliding windows and the titles. 762 setAreThereNotifications(); 763 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 764 } 765 766 public void removeNotification(IBinder key) { 767 StatusBarNotification old = removeNotificationViews(key); 768 if (SPEW) Slog.d(TAG, "removeNotification key=" + key + " old=" + old); 769 770 if (old != null) { 771 // Cancel the ticker if it's still running 772 mTicker.removeEntry(old); 773 774 // Recalculate the position of the sliding windows and the titles. 775 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 776 777 if (ENABLE_INTRUDERS && old == mCurrentlyIntrudingNotification) { 778 mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); 779 } 780 781 if (CLOSE_PANEL_WHEN_EMPTIED && mNotificationData.size() == 0 && !mAnimating) { 782 animateCollapseNotifications(); 783 } 784 } 785 786 setAreThereNotifications(); 787 } 788 789 private void updateShowSearchHoldoff() { 790 mShowSearchHoldoff = mContext.getResources().getInteger( 791 R.integer.config_show_search_delay); 792 } 793 794 private void loadNotificationShade() { 795 if (mPile == null) return; 796 797 int N = mNotificationData.size(); 798 799 ArrayList<View> toShow = new ArrayList<View>(); 800 801 final boolean provisioned = isDeviceProvisioned(); 802 // If the device hasn't been through Setup, we only show system notifications 803 for (int i=0; i<N; i++) { 804 Entry ent = mNotificationData.get(N-i-1); 805 if (!(provisioned || showNotificationEvenIfUnprovisioned(ent.notification))) continue; 806 if (!notificationIsForCurrentUser(ent.notification)) continue; 807 toShow.add(ent.row); 808 } 809 810 ArrayList<View> toRemove = new ArrayList<View>(); 811 for (int i=0; i<mPile.getChildCount(); i++) { 812 View child = mPile.getChildAt(i); 813 if (!toShow.contains(child)) { 814 toRemove.add(child); 815 } 816 } 817 818 for (View remove : toRemove) { 819 mPile.removeView(remove); 820 } 821 822 for (int i=0; i<toShow.size(); i++) { 823 View v = toShow.get(i); 824 if (v.getParent() == null) { 825 mPile.addView(v, i); 826 } 827 } 828 829 if (mSettingsButton != null) { 830 mSettingsButton.setEnabled(isDeviceProvisioned()); 831 } 832 } 833 834 @Override 835 protected void updateNotificationIcons() { 836 if (mNotificationIcons == null) return; 837 838 loadNotificationShade(); 839 840 final LinearLayout.LayoutParams params 841 = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight); 842 843 int N = mNotificationData.size(); 844 845 if (DEBUG) { 846 Slog.d(TAG, "refreshing icons: " + N + " notifications, mNotificationIcons=" + mNotificationIcons); 847 } 848 849 ArrayList<View> toShow = new ArrayList<View>(); 850 851 final boolean provisioned = isDeviceProvisioned(); 852 // If the device hasn't been through Setup, we only show system notifications 853 for (int i=0; i<N; i++) { 854 Entry ent = mNotificationData.get(N-i-1); 855 if (!((provisioned && ent.notification.score >= HIDE_ICONS_BELOW_SCORE) 856 || showNotificationEvenIfUnprovisioned(ent.notification))) continue; 857 if (!notificationIsForCurrentUser(ent.notification)) continue; 858 toShow.add(ent.icon); 859 } 860 861 ArrayList<View> toRemove = new ArrayList<View>(); 862 for (int i=0; i<mNotificationIcons.getChildCount(); i++) { 863 View child = mNotificationIcons.getChildAt(i); 864 if (!toShow.contains(child)) { 865 toRemove.add(child); 866 } 867 } 868 869 for (View remove : toRemove) { 870 mNotificationIcons.removeView(remove); 871 } 872 873 for (int i=0; i<toShow.size(); i++) { 874 View v = toShow.get(i); 875 if (v.getParent() == null) { 876 mNotificationIcons.addView(v, i, params); 877 } 878 } 879 } 880 881 protected void updateCarrierLabelVisibility(boolean force) { 882 if (!mShowCarrierInPanel) return; 883 // The idea here is to only show the carrier label when there is enough room to see it, 884 // i.e. when there aren't enough notifications to fill the panel. 885 if (DEBUG) { 886 Slog.d(TAG, String.format("pileh=%d scrollh=%d carrierh=%d", 887 mPile.getHeight(), mScrollView.getHeight(), mCarrierLabelHeight)); 888 } 889 890 final boolean emergencyCallsShownElsewhere = mEmergencyCallLabel != null; 891 final boolean makeVisible = 892 !(emergencyCallsShownElsewhere && mNetworkController.isEmergencyOnly()) 893 && mPile.getHeight() < (mNotificationPanel.getHeight() - mCarrierLabelHeight - mNotificationHeaderHeight); 894 895 if (force || mCarrierLabelVisible != makeVisible) { 896 mCarrierLabelVisible = makeVisible; 897 if (DEBUG) { 898 Slog.d(TAG, "making carrier label " + (makeVisible?"visible":"invisible")); 899 } 900 mCarrierLabel.animate().cancel(); 901 if (makeVisible) { 902 mCarrierLabel.setVisibility(View.VISIBLE); 903 } 904 mCarrierLabel.animate() 905 .alpha(makeVisible ? 1f : 0f) 906 //.setStartDelay(makeVisible ? 500 : 0) 907 //.setDuration(makeVisible ? 750 : 100) 908 .setDuration(150) 909 .setListener(makeVisible ? null : new AnimatorListenerAdapter() { 910 @Override 911 public void onAnimationEnd(Animator animation) { 912 if (!mCarrierLabelVisible) { // race 913 mCarrierLabel.setVisibility(View.INVISIBLE); 914 mCarrierLabel.setAlpha(0f); 915 } 916 } 917 }) 918 .start(); 919 } 920 } 921 922 @Override 923 protected void setAreThereNotifications() { 924 final boolean any = mNotificationData.size() > 0; 925 926 final boolean clearable = any && mNotificationData.hasClearableItems(); 927 928 if (DEBUG) { 929 Slog.d(TAG, "setAreThereNotifications: N=" + mNotificationData.size() 930 + " any=" + any + " clearable=" + clearable); 931 } 932 933 if (mClearButton.isShown()) { 934 if (clearable != (mClearButton.getAlpha() == 1.0f)) { 935 ObjectAnimator clearAnimation = ObjectAnimator.ofFloat( 936 mClearButton, "alpha", clearable ? 1.0f : 0.0f).setDuration(250); 937 clearAnimation.addListener(new AnimatorListenerAdapter() { 938 @Override 939 public void onAnimationEnd(Animator animation) { 940 if (mClearButton.getAlpha() <= 0.0f) { 941 mClearButton.setVisibility(View.INVISIBLE); 942 } 943 } 944 945 @Override 946 public void onAnimationStart(Animator animation) { 947 if (mClearButton.getAlpha() <= 0.0f) { 948 mClearButton.setVisibility(View.VISIBLE); 949 } 950 } 951 }); 952 clearAnimation.start(); 953 } 954 } else { 955 mClearButton.setAlpha(clearable ? 1.0f : 0.0f); 956 mClearButton.setVisibility(clearable ? View.VISIBLE : View.INVISIBLE); 957 } 958 mClearButton.setEnabled(clearable); 959 960 final View nlo = mStatusBarView.findViewById(R.id.notification_lights_out); 961 final boolean showDot = (any&&!areLightsOn()); 962 if (showDot != (nlo.getAlpha() == 1.0f)) { 963 if (showDot) { 964 nlo.setAlpha(0f); 965 nlo.setVisibility(View.VISIBLE); 966 } 967 nlo.animate() 968 .alpha(showDot?1:0) 969 .setDuration(showDot?750:250) 970 .setInterpolator(new AccelerateInterpolator(2.0f)) 971 .setListener(showDot ? null : new AnimatorListenerAdapter() { 972 @Override 973 public void onAnimationEnd(Animator _a) { 974 nlo.setVisibility(View.GONE); 975 } 976 }) 977 .start(); 978 } 979 980 updateCarrierLabelVisibility(false); 981 } 982 983 public void showClock(boolean show) { 984 if (mStatusBarView == null) return; 985 View clock = mStatusBarView.findViewById(R.id.clock); 986 if (clock != null) { 987 clock.setVisibility(show ? View.VISIBLE : View.GONE); 988 } 989 } 990 991 /** 992 * State is one or more of the DISABLE constants from StatusBarManager. 993 */ 994 public void disable(int state) { 995 final int old = mDisabled; 996 final int diff = state ^ old; 997 mDisabled = state; 998 999 if (DEBUG) { 1000 Slog.d(TAG, String.format("disable: 0x%08x -> 0x%08x (diff: 0x%08x)", 1001 old, state, diff)); 1002 } 1003 1004 StringBuilder flagdbg = new StringBuilder(); 1005 flagdbg.append("disable: < "); 1006 flagdbg.append(((state & StatusBarManager.DISABLE_EXPAND) != 0) ? "EXPAND" : "expand"); 1007 flagdbg.append(((diff & StatusBarManager.DISABLE_EXPAND) != 0) ? "* " : " "); 1008 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "ICONS" : "icons"); 1009 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "* " : " "); 1010 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "ALERTS" : "alerts"); 1011 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "* " : " "); 1012 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "TICKER" : "ticker"); 1013 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "* " : " "); 1014 flagdbg.append(((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "SYSTEM_INFO" : "system_info"); 1015 flagdbg.append(((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "* " : " "); 1016 flagdbg.append(((state & StatusBarManager.DISABLE_BACK) != 0) ? "BACK" : "back"); 1017 flagdbg.append(((diff & StatusBarManager.DISABLE_BACK) != 0) ? "* " : " "); 1018 flagdbg.append(((state & StatusBarManager.DISABLE_HOME) != 0) ? "HOME" : "home"); 1019 flagdbg.append(((diff & StatusBarManager.DISABLE_HOME) != 0) ? "* " : " "); 1020 flagdbg.append(((state & StatusBarManager.DISABLE_RECENT) != 0) ? "RECENT" : "recent"); 1021 flagdbg.append(((diff & StatusBarManager.DISABLE_RECENT) != 0) ? "* " : " "); 1022 flagdbg.append(((state & StatusBarManager.DISABLE_CLOCK) != 0) ? "CLOCK" : "clock"); 1023 flagdbg.append(((diff & StatusBarManager.DISABLE_CLOCK) != 0) ? "* " : " "); 1024 flagdbg.append(">"); 1025 Slog.d(TAG, flagdbg.toString()); 1026 1027 if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { 1028 mSystemIconArea.animate().cancel(); 1029 if ((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { 1030 mSystemIconArea.animate() 1031 .alpha(0f) 1032 .translationY(mNaturalBarHeight*0.5f) 1033 .setDuration(175) 1034 .setInterpolator(new DecelerateInterpolator(1.5f)) 1035 .setListener(mMakeIconsInvisible) 1036 .start(); 1037 } else { 1038 mSystemIconArea.setVisibility(View.VISIBLE); 1039 mSystemIconArea.animate() 1040 .alpha(1f) 1041 .translationY(0) 1042 .setStartDelay(0) 1043 .setInterpolator(new DecelerateInterpolator(1.5f)) 1044 .setDuration(175) 1045 .start(); 1046 } 1047 } 1048 1049 if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) { 1050 boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0; 1051 showClock(show); 1052 } 1053 if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { 1054 if ((state & StatusBarManager.DISABLE_EXPAND) != 0) { 1055 animateCollapseNotifications(); 1056 } 1057 } 1058 1059 if ((diff & (StatusBarManager.DISABLE_HOME 1060 | StatusBarManager.DISABLE_RECENT 1061 | StatusBarManager.DISABLE_BACK)) != 0) { 1062 // the nav bar will take care of these 1063 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state); 1064 1065 if ((state & StatusBarManager.DISABLE_RECENT) != 0) { 1066 // close recents if it's visible 1067 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); 1068 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); 1069 } 1070 } 1071 1072 if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1073 if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1074 if (mTicking) { 1075 mTicker.halt(); 1076 } 1077 1078 mNotificationIcons.animate() 1079 .alpha(0f) 1080 .translationY(mNaturalBarHeight*0.5f) 1081 .setDuration(175) 1082 .setInterpolator(new DecelerateInterpolator(1.5f)) 1083 .setListener(mMakeIconsInvisible) 1084 .start(); 1085 } else { 1086 mNotificationIcons.setVisibility(View.VISIBLE); 1087 mNotificationIcons.animate() 1088 .alpha(1f) 1089 .translationY(0) 1090 .setStartDelay(0) 1091 .setInterpolator(new DecelerateInterpolator(1.5f)) 1092 .setDuration(175) 1093 .start(); 1094 } 1095 } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1096 if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1097 mTicker.halt(); 1098 } 1099 } 1100 } 1101 1102 @Override 1103 protected BaseStatusBar.H createHandler() { 1104 return new PhoneStatusBar.H(); 1105 } 1106 1107 /** 1108 * All changes to the status bar and notifications funnel through here and are batched. 1109 */ 1110 private class H extends BaseStatusBar.H { 1111 public void handleMessage(Message m) { 1112 super.handleMessage(m); 1113 switch (m.what) { 1114 case MSG_OPEN_NOTIFICATION_PANEL: 1115 animateExpandNotifications(); 1116 break; 1117 case MSG_CLOSE_NOTIFICATION_PANEL: 1118 animateCollapseNotifications(); 1119 break; 1120 case MSG_SHOW_INTRUDER: 1121 setIntruderAlertVisibility(true); 1122 break; 1123 case MSG_HIDE_INTRUDER: 1124 setIntruderAlertVisibility(false); 1125 mCurrentlyIntrudingNotification = null; 1126 break; 1127 } 1128 } 1129 } 1130 1131 View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() { 1132 public void onFocusChange(View v, boolean hasFocus) { 1133 // Because 'v' is a ViewGroup, all its children will be (un)selected 1134 // too, which allows marqueeing to work. 1135 v.setSelected(hasFocus); 1136 } 1137 }; 1138 1139 void makeExpandedVisible(boolean revealAfterDraw) { 1140 if (SPEW) Slog.d(TAG, "Make expanded visible: expanded visible=" + mExpandedVisible); 1141 if (mExpandedVisible) { 1142 return; 1143 } 1144 1145 mExpandedVisible = true; 1146 mPile.setLayoutTransitionsEnabled(true); 1147 if (mNavigationBarView != null) 1148 mNavigationBarView.setSlippery(true); 1149 1150 updateCarrierLabelVisibility(true); 1151 1152 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 1153 1154 // Expand the window to encompass the full screen in anticipation of the drag. 1155 // This is only possible to do atomically because the status bar is at the top of the screen! 1156 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); 1157 lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 1158 lp.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; 1159 lp.height = ViewGroup.LayoutParams.MATCH_PARENT; 1160 mWindowManager.updateViewLayout(mStatusBarWindow, lp); 1161 1162 // Updating the window layout will force an expensive traversal/redraw. 1163 // Kick off the reveal animation after this is complete to avoid animation latency. 1164 if (revealAfterDraw) { 1165// mHandler.post(mStartRevealAnimation); 1166 } 1167 1168 visibilityChanged(true); 1169 } 1170 1171 public void animateCollapseNotifications() { 1172 animateCollapseNotifications(CommandQueue.FLAG_EXCLUDE_NONE); 1173 } 1174 1175 public void animateCollapseNotifications(int flags) { 1176 if (SPEW) { 1177 Slog.d(TAG, "animateCollapse():" 1178 + " mExpandedVisible=" + mExpandedVisible 1179 + " mAnimating=" + mAnimating 1180 + " mAnimatingReveal=" + mAnimatingReveal 1181 + " mAnimY=" + mAnimY 1182 + " mAnimVel=" + mAnimVel 1183 + " flags=" + flags); 1184 } 1185 1186 if ((flags & CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL) == 0) { 1187 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); 1188 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); 1189 } 1190 1191 if ((flags & CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL) == 0) { 1192 mHandler.removeMessages(MSG_CLOSE_SEARCH_PANEL); 1193 mHandler.sendEmptyMessage(MSG_CLOSE_SEARCH_PANEL); 1194 } 1195 1196 mStatusBarView.collapseAllPanels(true); 1197 } 1198 1199 @Override 1200 public void animateExpandNotifications() { 1201 if (SPEW) Slog.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible); 1202 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1203 return ; 1204 } 1205 1206 mNotificationPanel.expand(); 1207 1208 if (false) postStartTracing(); 1209 } 1210 1211 @Override 1212 public void animateExpandQuickSettings() { 1213 if (SPEW) Slog.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible); 1214 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1215 return; 1216 } 1217 1218 mSettingsPanel.expand(); 1219 1220 if (false) postStartTracing(); 1221 } 1222 1223 public void animateCollapseQuickSettings() { 1224 mStatusBarView.collapseAllPanels(true); 1225 } 1226 1227 void makeExpandedInvisible() { 1228 if (SPEW) Slog.d(TAG, "makeExpandedInvisible: mExpandedVisible=" + mExpandedVisible 1229 + " mExpandedVisible=" + mExpandedVisible); 1230 1231 if (!mExpandedVisible) { 1232 return; 1233 } 1234 1235 // Ensure the panel is fully collapsed (just in case; bug 6765842) 1236 // @@@ mStatusBarView.collapseAllPanels(/*animate=*/ false); 1237 1238 mExpandedVisible = false; 1239 mPile.setLayoutTransitionsEnabled(false); 1240 if (mNavigationBarView != null) 1241 mNavigationBarView.setSlippery(false); 1242 visibilityChanged(false); 1243 1244 // Shrink the window to the size of the status bar only 1245 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); 1246 lp.height = getStatusBarHeight(); 1247 lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 1248 lp.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; 1249 mWindowManager.updateViewLayout(mStatusBarWindow, lp); 1250 1251 if ((mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS) == 0) { 1252 setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in); 1253 } 1254 1255 // Close any "App info" popups that might have snuck on-screen 1256 dismissPopups(); 1257 1258 if (mPostCollapseCleanup != null) { 1259 mPostCollapseCleanup.run(); 1260 mPostCollapseCleanup = null; 1261 } 1262 } 1263 1264 /** 1265 * Enables or disables layers on the children of the notifications pile. 1266 * 1267 * When layers are enabled, this method attempts to enable layers for the minimal 1268 * number of children. Only children visible when the notification area is fully 1269 * expanded will receive a layer. The technique used in this method might cause 1270 * more children than necessary to get a layer (at most one extra child with the 1271 * current UI.) 1272 * 1273 * @param layerType {@link View#LAYER_TYPE_NONE} or {@link View#LAYER_TYPE_HARDWARE} 1274 */ 1275 private void setPileLayers(int layerType) { 1276 final int count = mPile.getChildCount(); 1277 1278 switch (layerType) { 1279 case View.LAYER_TYPE_NONE: 1280 for (int i = 0; i < count; i++) { 1281 mPile.getChildAt(i).setLayerType(layerType, null); 1282 } 1283 break; 1284 case View.LAYER_TYPE_HARDWARE: 1285 final int[] location = new int[2]; 1286 mNotificationPanel.getLocationInWindow(location); 1287 1288 final int left = location[0]; 1289 final int top = location[1]; 1290 final int right = left + mNotificationPanel.getWidth(); 1291 final int bottom = top + getExpandedViewMaxHeight(); 1292 1293 final Rect childBounds = new Rect(); 1294 1295 for (int i = 0; i < count; i++) { 1296 final View view = mPile.getChildAt(i); 1297 view.getLocationInWindow(location); 1298 1299 childBounds.set(location[0], location[1], 1300 location[0] + view.getWidth(), location[1] + view.getHeight()); 1301 1302 if (childBounds.intersects(left, top, right, bottom)) { 1303 view.setLayerType(layerType, null); 1304 } 1305 } 1306 1307 break; 1308 } 1309 } 1310 1311 boolean interceptTouchEvent(MotionEvent event) { 1312 if (SPEW) { 1313 Slog.d(TAG, "Touch: rawY=" + event.getRawY() + " event=" + event + " mDisabled=" 1314 + mDisabled + " mTracking=" + mTracking); 1315 } else if (CHATTY) { 1316 if (event.getAction() != MotionEvent.ACTION_MOVE) { 1317 Slog.d(TAG, String.format( 1318 "panel: %s at (%f, %f) mDisabled=0x%08x", 1319 MotionEvent.actionToString(event.getAction()), 1320 event.getRawX(), event.getRawY(), mDisabled)); 1321 } 1322 } 1323 1324 mGestureRec.add(event); 1325 1326 return false; 1327 } 1328 1329 public GestureRecorder getGestureRecorder() { 1330 return mGestureRec; 1331 } 1332 1333 @Override // CommandQueue 1334 public void setNavigationIconHints(int hints) { 1335 if (hints == mNavigationIconHints) return; 1336 1337 mNavigationIconHints = hints; 1338 1339 if (mNavigationBarView != null) { 1340 mNavigationBarView.setNavigationIconHints(hints); 1341 } 1342 } 1343 1344 @Override // CommandQueue 1345 public void setSystemUiVisibility(int vis, int mask) { 1346 final int oldVal = mSystemUiVisibility; 1347 final int newVal = (oldVal&~mask) | (vis&mask); 1348 final int diff = newVal ^ oldVal; 1349 1350 if (diff != 0) { 1351 mSystemUiVisibility = newVal; 1352 1353 if (0 != (diff & View.SYSTEM_UI_FLAG_LOW_PROFILE)) { 1354 final boolean lightsOut = (0 != (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE)); 1355 if (lightsOut) { 1356 animateCollapseNotifications(); 1357 if (mTicking) { 1358 mTicker.halt(); 1359 } 1360 } 1361 1362 if (mNavigationBarView != null) { 1363 mNavigationBarView.setLowProfile(lightsOut); 1364 } 1365 1366 setStatusBarLowProfile(lightsOut); 1367 } 1368 1369 notifyUiVisibilityChanged(); 1370 } 1371 } 1372 1373 private void setStatusBarLowProfile(boolean lightsOut) { 1374 if (mLightsOutAnimation == null) { 1375 mLightsOutAnimation = ObjectAnimator.ofFloat(mStatusBarContents, View.ALPHA, 0); 1376 mLightsOutAnimation.setDuration(750); 1377 1378 mLightsOnAnimation = new AnimatorSet(); 1379 mLightsOnAnimation = ObjectAnimator.ofFloat(mStatusBarContents, View.ALPHA, 1); 1380 mLightsOnAnimation.setDuration(250); 1381 } 1382 1383 mLightsOutAnimation.cancel(); 1384 mLightsOnAnimation.cancel(); 1385 1386 final Animator a = lightsOut ? mLightsOutAnimation : mLightsOnAnimation; 1387 a.start(); 1388 1389 setAreThereNotifications(); 1390 } 1391 1392 private boolean areLightsOn() { 1393 return 0 == (mSystemUiVisibility & View.SYSTEM_UI_FLAG_LOW_PROFILE); 1394 } 1395 1396 public void setLightsOn(boolean on) { 1397 Log.v(TAG, "setLightsOn(" + on + ")"); 1398 if (on) { 1399 setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE); 1400 } else { 1401 setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE, View.SYSTEM_UI_FLAG_LOW_PROFILE); 1402 } 1403 } 1404 1405 private void notifyUiVisibilityChanged() { 1406 try { 1407 mWindowManagerService.statusBarVisibilityChanged(mSystemUiVisibility); 1408 } catch (RemoteException ex) { 1409 } 1410 } 1411 1412 public void topAppWindowChanged(boolean showMenu) { 1413 if (DEBUG) { 1414 Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button"); 1415 } 1416 if (mNavigationBarView != null) { 1417 mNavigationBarView.setMenuVisibility(showMenu); 1418 } 1419 1420 // See above re: lights-out policy for legacy apps. 1421 if (showMenu) setLightsOn(true); 1422 } 1423 1424 @Override 1425 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { 1426 boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS) 1427 || ((vis & InputMethodService.IME_VISIBLE) != 0); 1428 1429 mCommandQueue.setNavigationIconHints( 1430 altBack ? (mNavigationIconHints | StatusBarManager.NAVIGATION_HINT_BACK_ALT) 1431 : (mNavigationIconHints & ~StatusBarManager.NAVIGATION_HINT_BACK_ALT)); 1432 mSettingsPanel.setImeWindowStatus(vis > 0); 1433 } 1434 1435 @Override 1436 public void setHardKeyboardStatus(boolean available, boolean enabled) {} 1437 1438 @Override 1439 protected void tick(IBinder key, StatusBarNotification n, boolean firstTime) { 1440 // no ticking in lights-out mode 1441 if (!areLightsOn()) return; 1442 1443 // no ticking in Setup 1444 if (!isDeviceProvisioned()) return; 1445 1446 // not for you 1447 if (!notificationIsForCurrentUser(n)) return; 1448 1449 // Show the ticker if one is requested. Also don't do this 1450 // until status bar window is attached to the window manager, 1451 // because... well, what's the point otherwise? And trying to 1452 // run a ticker without being attached will crash! 1453 if (n.notification.tickerText != null && mStatusBarWindow.getWindowToken() != null) { 1454 if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS 1455 | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { 1456 mTicker.addEntry(n); 1457 } 1458 } 1459 } 1460 1461 private class MyTicker extends Ticker { 1462 MyTicker(Context context, View sb) { 1463 super(context, sb); 1464 } 1465 1466 @Override 1467 public void tickerStarting() { 1468 mTicking = true; 1469 mStatusBarContents.setVisibility(View.GONE); 1470 mTickerView.setVisibility(View.VISIBLE); 1471 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_up_in, null)); 1472 mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.push_up_out, null)); 1473 } 1474 1475 @Override 1476 public void tickerDone() { 1477 mStatusBarContents.setVisibility(View.VISIBLE); 1478 mTickerView.setVisibility(View.GONE); 1479 mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.push_down_in, null)); 1480 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_down_out, 1481 mTickingDoneListener)); 1482 } 1483 1484 public void tickerHalting() { 1485 mStatusBarContents.setVisibility(View.VISIBLE); 1486 mTickerView.setVisibility(View.GONE); 1487 mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.fade_in, null)); 1488 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.fade_out, 1489 mTickingDoneListener)); 1490 } 1491 } 1492 1493 Animation.AnimationListener mTickingDoneListener = new Animation.AnimationListener() {; 1494 public void onAnimationEnd(Animation animation) { 1495 mTicking = false; 1496 } 1497 public void onAnimationRepeat(Animation animation) { 1498 } 1499 public void onAnimationStart(Animation animation) { 1500 } 1501 }; 1502 1503 private Animation loadAnim(int id, Animation.AnimationListener listener) { 1504 Animation anim = AnimationUtils.loadAnimation(mContext, id); 1505 if (listener != null) { 1506 anim.setAnimationListener(listener); 1507 } 1508 return anim; 1509 } 1510 1511 public static String viewInfo(View v) { 1512 return "[(" + v.getLeft() + "," + v.getTop() + ")(" + v.getRight() + "," + v.getBottom() 1513 + ") " + v.getWidth() + "x" + v.getHeight() + "]"; 1514 } 1515 1516 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 1517 synchronized (mQueueLock) { 1518 pw.println("Current Status Bar state:"); 1519 pw.println(" mExpandedVisible=" + mExpandedVisible 1520 + ", mTrackingPosition=" + mTrackingPosition); 1521 pw.println(" mTicking=" + mTicking); 1522 pw.println(" mTracking=" + mTracking); 1523 pw.println(" mNotificationPanel=" + 1524 ((mNotificationPanel == null) 1525 ? "null" 1526 : (mNotificationPanel + " params=" + mNotificationPanel.getLayoutParams().debug("")))); 1527 pw.println(" mAnimating=" + mAnimating 1528 + ", mAnimY=" + mAnimY + ", mAnimVel=" + mAnimVel 1529 + ", mAnimAccel=" + mAnimAccel); 1530 pw.println(" mAnimLastTimeNanos=" + mAnimLastTimeNanos); 1531 pw.println(" mAnimatingReveal=" + mAnimatingReveal 1532 + " mViewDelta=" + mViewDelta); 1533 pw.println(" mDisplayMetrics=" + mDisplayMetrics); 1534 pw.println(" mPile: " + viewInfo(mPile)); 1535 pw.println(" mTickerView: " + viewInfo(mTickerView)); 1536 pw.println(" mScrollView: " + viewInfo(mScrollView) 1537 + " scroll " + mScrollView.getScrollX() + "," + mScrollView.getScrollY()); 1538 } 1539 1540 pw.print(" mNavigationBarView="); 1541 if (mNavigationBarView == null) { 1542 pw.println("null"); 1543 } else { 1544 mNavigationBarView.dump(fd, pw, args); 1545 } 1546 1547 if (DUMPTRUCK) { 1548 synchronized (mNotificationData) { 1549 int N = mNotificationData.size(); 1550 pw.println(" notification icons: " + N); 1551 for (int i=0; i<N; i++) { 1552 NotificationData.Entry e = mNotificationData.get(i); 1553 pw.println(" [" + i + "] key=" + e.key + " icon=" + e.icon); 1554 StatusBarNotification n = e.notification; 1555 pw.println(" pkg=" + n.pkg + " id=" + n.id + " score=" + n.score); 1556 pw.println(" notification=" + n.notification); 1557 pw.println(" tickerText=\"" + n.notification.tickerText + "\""); 1558 } 1559 } 1560 1561 int N = mStatusIcons.getChildCount(); 1562 pw.println(" system icons: " + N); 1563 for (int i=0; i<N; i++) { 1564 StatusBarIconView ic = (StatusBarIconView) mStatusIcons.getChildAt(i); 1565 pw.println(" [" + i + "] icon=" + ic); 1566 } 1567 1568 if (false) { 1569 pw.println("see the logcat for a dump of the views we have created."); 1570 // must happen on ui thread 1571 mHandler.post(new Runnable() { 1572 public void run() { 1573 mStatusBarView.getLocationOnScreen(mAbsPos); 1574 Slog.d(TAG, "mStatusBarView: ----- (" + mAbsPos[0] + "," + mAbsPos[1] 1575 + ") " + mStatusBarView.getWidth() + "x" 1576 + getStatusBarHeight()); 1577 mStatusBarView.debug(); 1578 } 1579 }); 1580 } 1581 } 1582 1583 pw.print(" status bar gestures: "); 1584 mGestureRec.dump(fd, pw, args); 1585 1586 mNetworkController.dump(fd, pw, args); 1587 } 1588 1589 @Override 1590 public void createAndAddWindows() { 1591 addStatusBarWindow(); 1592 } 1593 1594 private void addStatusBarWindow() { 1595 // Put up the view 1596 final int height = getStatusBarHeight(); 1597 1598 // Now that the status bar window encompasses the sliding panel and its 1599 // translucent backdrop, the entire thing is made TRANSLUCENT and is 1600 // hardware-accelerated. 1601 final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 1602 ViewGroup.LayoutParams.MATCH_PARENT, 1603 height, 1604 WindowManager.LayoutParams.TYPE_STATUS_BAR, 1605 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 1606 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING 1607 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 1608 PixelFormat.TRANSLUCENT); 1609 1610 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 1611 1612 lp.gravity = getStatusBarGravity(); 1613 lp.setTitle("StatusBar"); 1614 lp.packageName = mContext.getPackageName(); 1615 1616 makeStatusBarView(); 1617 mWindowManager.addView(mStatusBarWindow, lp); 1618 } 1619 1620 void setNotificationIconVisibility(boolean visible, int anim) { 1621 int old = mNotificationIcons.getVisibility(); 1622 int v = visible ? View.VISIBLE : View.INVISIBLE; 1623 if (old != v) { 1624 mNotificationIcons.setVisibility(v); 1625 mNotificationIcons.startAnimation(loadAnim(anim, null)); 1626 } 1627 } 1628 1629 void updateExpandedInvisiblePosition() { 1630 mTrackingPosition = -mDisplayMetrics.heightPixels; 1631 } 1632 1633 static final float saturate(float a) { 1634 return a < 0f ? 0f : (a > 1f ? 1f : a); 1635 } 1636 1637 @Override 1638 protected int getExpandedViewMaxHeight() { 1639 return mDisplayMetrics.heightPixels - mNotificationPanelMarginBottomPx; 1640 } 1641 1642 @Override 1643 public void updateExpandedViewPos(int thingy) { 1644 if (DEBUG) Slog.v(TAG, "updateExpandedViewPos"); 1645 1646 // on larger devices, the notification panel is propped open a bit 1647 mNotificationPanel.setMinimumHeight( 1648 (int)(mNotificationPanelMinHeightFrac * mCurrentDisplaySize.y)); 1649 1650 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mNotificationPanel.getLayoutParams(); 1651 lp.gravity = mNotificationPanelGravity; 1652 lp.leftMargin = mNotificationPanelMarginPx; 1653 mNotificationPanel.setLayoutParams(lp); 1654 1655 lp = (FrameLayout.LayoutParams) mSettingsPanel.getLayoutParams(); 1656 lp.gravity = mSettingsPanelGravity; 1657 lp.rightMargin = mNotificationPanelMarginPx; 1658 mSettingsPanel.setLayoutParams(lp); 1659 1660 updateCarrierLabelVisibility(false); 1661 } 1662 1663 // called by makeStatusbar and also by PhoneStatusBarView 1664 void updateDisplaySize() { 1665 mDisplay.getMetrics(mDisplayMetrics); 1666 mGestureRec.tag("display", 1667 String.format("%dx%d", mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels)); 1668 } 1669 1670 private View.OnClickListener mClearButtonListener = new View.OnClickListener() { 1671 public void onClick(View v) { 1672 synchronized (mNotificationData) { 1673 // animate-swipe all dismissable notifications, then animate the shade closed 1674 int numChildren = mPile.getChildCount(); 1675 1676 int scrollTop = mScrollView.getScrollY(); 1677 int scrollBottom = scrollTop + mScrollView.getHeight(); 1678 final ArrayList<View> snapshot = new ArrayList<View>(numChildren); 1679 for (int i=0; i<numChildren; i++) { 1680 final View child = mPile.getChildAt(i); 1681 if (mPile.canChildBeDismissed(child) && child.getBottom() > scrollTop && 1682 child.getTop() < scrollBottom) { 1683 snapshot.add(child); 1684 } 1685 } 1686 if (snapshot.isEmpty()) { 1687 animateCollapseNotifications(CommandQueue.FLAG_EXCLUDE_NONE); 1688 return; 1689 } 1690 new Thread(new Runnable() { 1691 @Override 1692 public void run() { 1693 // Decrease the delay for every row we animate to give the sense of 1694 // accelerating the swipes 1695 final int ROW_DELAY_DECREMENT = 10; 1696 int currentDelay = 140; 1697 int totalDelay = 0; 1698 1699 // Set the shade-animating state to avoid doing other work during 1700 // all of these animations. In particular, avoid layout and 1701 // redrawing when collapsing the shade. 1702 mPile.setViewRemoval(false); 1703 1704 mPostCollapseCleanup = new Runnable() { 1705 @Override 1706 public void run() { 1707 if (DEBUG) { 1708 Slog.v(TAG, "running post-collapse cleanup"); 1709 } 1710 try { 1711 mPile.setViewRemoval(true); 1712 mBarService.onClearAllNotifications(); 1713 } catch (Exception ex) { } 1714 } 1715 }; 1716 1717 View sampleView = snapshot.get(0); 1718 int width = sampleView.getWidth(); 1719 final int velocity = width * 8; // 1000/8 = 125 ms duration 1720 for (final View _v : snapshot) { 1721 mHandler.postDelayed(new Runnable() { 1722 @Override 1723 public void run() { 1724 mPile.dismissRowAnimated(_v, velocity); 1725 } 1726 }, totalDelay); 1727 currentDelay = Math.max(50, currentDelay - ROW_DELAY_DECREMENT); 1728 totalDelay += currentDelay; 1729 } 1730 // Delay the collapse animation until after all swipe animations have 1731 // finished. Provide some buffer because there may be some extra delay 1732 // before actually starting each swipe animation. Ideally, we'd 1733 // synchronize the end of those animations with the start of the collaps 1734 // exactly. 1735 mHandler.postDelayed(new Runnable() { 1736 @Override 1737 public void run() { 1738 animateCollapseNotifications(CommandQueue.FLAG_EXCLUDE_NONE); 1739 } 1740 }, totalDelay + 225); 1741 } 1742 }).start(); 1743 } 1744 } 1745 }; 1746 1747 private View.OnClickListener mSettingsButtonListener = new View.OnClickListener() { 1748 public void onClick(View v) { 1749 // We take this as a good indicator that Setup is running and we shouldn't 1750 // allow you to go somewhere else 1751 if (!isDeviceProvisioned()) return; 1752 try { 1753 // Dismiss the lock screen when Settings starts. 1754 ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity(); 1755 } catch (RemoteException e) { 1756 } 1757 v.getContext().startActivityAsUser(new Intent(Settings.ACTION_SETTINGS) 1758 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 1759 new UserHandle(UserHandle.USER_CURRENT)); 1760 animateCollapseNotifications(); 1761 } 1762 }; 1763 1764 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 1765 public void onReceive(Context context, Intent intent) { 1766 Slog.v(TAG, "onReceive: " + intent); 1767 String action = intent.getAction(); 1768 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { 1769 int flags = CommandQueue.FLAG_EXCLUDE_NONE; 1770 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { 1771 String reason = intent.getStringExtra("reason"); 1772 if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) { 1773 flags |= CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL; 1774 } 1775 } 1776 animateCollapseNotifications(flags); 1777 } 1778 else if (Intent.ACTION_SCREEN_OFF.equals(action)) { 1779 // no waiting! 1780 makeExpandedInvisible(); 1781 } 1782 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { 1783 if (DEBUG) { 1784 Slog.v(TAG, "configuration changed: " + mContext.getResources().getConfiguration()); 1785 } 1786 mDisplay.getSize(mCurrentDisplaySize); 1787 1788 updateResources(); 1789 repositionNavigationBar(); 1790 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 1791 updateShowSearchHoldoff(); 1792 } 1793 else if (Intent.ACTION_SCREEN_ON.equals(action)) { 1794 // work around problem where mDisplay.getRotation() is not stable while screen is off (bug 7086018) 1795 repositionNavigationBar(); 1796 } 1797 } 1798 }; 1799 1800 @Override 1801 public void userSwitched(int newUserId) { 1802 if (MULTIUSER_DEBUG) mNotificationPanelDebugText.setText("USER " + newUserId); 1803 animateCollapseNotifications(); 1804 updateNotificationIcons(); 1805 } 1806 1807 private void setIntruderAlertVisibility(boolean vis) { 1808 if (!ENABLE_INTRUDERS) return; 1809 if (DEBUG) { 1810 Slog.v(TAG, (vis ? "showing" : "hiding") + " intruder alert window"); 1811 } 1812 mIntruderAlertView.setVisibility(vis ? View.VISIBLE : View.GONE); 1813 } 1814 1815 public void dismissIntruder() { 1816 if (mCurrentlyIntrudingNotification == null) return; 1817 1818 try { 1819 mBarService.onNotificationClear( 1820 mCurrentlyIntrudingNotification.pkg, 1821 mCurrentlyIntrudingNotification.tag, 1822 mCurrentlyIntrudingNotification.id); 1823 } catch (android.os.RemoteException ex) { 1824 // oh well 1825 } 1826 } 1827 1828 /** 1829 * Reload some of our resources when the configuration changes. 1830 * 1831 * We don't reload everything when the configuration changes -- we probably 1832 * should, but getting that smooth is tough. Someday we'll fix that. In the 1833 * meantime, just update the things that we know change. 1834 */ 1835 void updateResources() { 1836 final Context context = mContext; 1837 final Resources res = context.getResources(); 1838 1839 if (mClearButton instanceof TextView) { 1840 ((TextView)mClearButton).setText(context.getText(R.string.status_bar_clear_all_button)); 1841 } 1842 1843 // Update the QuickSettings container 1844 mSettingsPanel.updateResources(); 1845 1846 loadDimens(); 1847 } 1848 1849 protected void loadDimens() { 1850 final Resources res = mContext.getResources(); 1851 1852 mNaturalBarHeight = res.getDimensionPixelSize( 1853 com.android.internal.R.dimen.status_bar_height); 1854 1855 int newIconSize = res.getDimensionPixelSize( 1856 com.android.internal.R.dimen.status_bar_icon_size); 1857 int newIconHPadding = res.getDimensionPixelSize( 1858 R.dimen.status_bar_icon_padding); 1859 1860 if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) { 1861// Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding); 1862 mIconHPadding = newIconHPadding; 1863 mIconSize = newIconSize; 1864 //reloadAllNotificationIcons(); // reload the tray 1865 } 1866 1867 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore); 1868 1869 mSelfExpandVelocityPx = res.getDimension(R.dimen.self_expand_velocity); 1870 mSelfCollapseVelocityPx = res.getDimension(R.dimen.self_collapse_velocity); 1871 mFlingExpandMinVelocityPx = res.getDimension(R.dimen.fling_expand_min_velocity); 1872 mFlingCollapseMinVelocityPx = res.getDimension(R.dimen.fling_collapse_min_velocity); 1873 1874 mCollapseMinDisplayFraction = res.getFraction(R.dimen.collapse_min_display_fraction, 1, 1); 1875 mExpandMinDisplayFraction = res.getFraction(R.dimen.expand_min_display_fraction, 1, 1); 1876 1877 mExpandAccelPx = res.getDimension(R.dimen.expand_accel); 1878 mCollapseAccelPx = res.getDimension(R.dimen.collapse_accel); 1879 1880 mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity); 1881 1882 mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity); 1883 1884 mNotificationPanelMarginBottomPx 1885 = (int) res.getDimension(R.dimen.notification_panel_margin_bottom); 1886 mNotificationPanelMarginPx 1887 = (int) res.getDimension(R.dimen.notification_panel_margin_left); 1888 mNotificationPanelGravity = res.getInteger(R.integer.notification_panel_layout_gravity); 1889 if (mNotificationPanelGravity <= 0) { 1890 mNotificationPanelGravity = Gravity.LEFT | Gravity.TOP; 1891 } 1892 mSettingsPanelGravity = res.getInteger(R.integer.settings_panel_layout_gravity); 1893 if (mSettingsPanelGravity <= 0) { 1894 mSettingsPanelGravity = Gravity.RIGHT | Gravity.TOP; 1895 } 1896 1897 mCarrierLabelHeight = res.getDimensionPixelSize(R.dimen.carrier_label_height); 1898 mNotificationHeaderHeight = res.getDimensionPixelSize(R.dimen.notification_panel_header_height); 1899 1900 mNotificationPanelMinHeightFrac = res.getFraction(R.dimen.notification_panel_min_height_frac, 1, 1); 1901 if (mNotificationPanelMinHeightFrac < 0f || mNotificationPanelMinHeightFrac > 1f) { 1902 mNotificationPanelMinHeightFrac = 0f; 1903 } 1904 1905 if (false) Slog.v(TAG, "updateResources"); 1906 } 1907 1908 // 1909 // tracing 1910 // 1911 1912 void postStartTracing() { 1913 mHandler.postDelayed(mStartTracing, 3000); 1914 } 1915 1916 void vibrate() { 1917 android.os.Vibrator vib = (android.os.Vibrator)mContext.getSystemService( 1918 Context.VIBRATOR_SERVICE); 1919 vib.vibrate(250); 1920 } 1921 1922 Runnable mStartTracing = new Runnable() { 1923 public void run() { 1924 vibrate(); 1925 SystemClock.sleep(250); 1926 Slog.d(TAG, "startTracing"); 1927 android.os.Debug.startMethodTracing("/data/statusbar-traces/trace"); 1928 mHandler.postDelayed(mStopTracing, 10000); 1929 } 1930 }; 1931 1932 Runnable mStopTracing = new Runnable() { 1933 public void run() { 1934 android.os.Debug.stopMethodTracing(); 1935 Slog.d(TAG, "stopTracing"); 1936 vibrate(); 1937 } 1938 }; 1939 1940 @Override 1941 protected void haltTicker() { 1942 mTicker.halt(); 1943 } 1944 1945 @Override 1946 protected boolean shouldDisableNavbarGestures() { 1947 return mExpandedVisible || (mDisabled & StatusBarManager.DISABLE_HOME) != 0; 1948 } 1949 1950 private static class FastColorDrawable extends Drawable { 1951 private final int mColor; 1952 1953 public FastColorDrawable(int color) { 1954 mColor = 0xff000000 | color; 1955 } 1956 1957 @Override 1958 public void draw(Canvas canvas) { 1959 canvas.drawColor(mColor, PorterDuff.Mode.SRC); 1960 } 1961 1962 @Override 1963 public void setAlpha(int alpha) { 1964 } 1965 1966 @Override 1967 public void setColorFilter(ColorFilter cf) { 1968 } 1969 1970 @Override 1971 public int getOpacity() { 1972 return PixelFormat.OPAQUE; 1973 } 1974 1975 @Override 1976 public void setBounds(int left, int top, int right, int bottom) { 1977 } 1978 1979 @Override 1980 public void setBounds(Rect bounds) { 1981 } 1982 } 1983} 1984