PhoneStatusBar.java revision 9deaa286d8db51cd53118b3c14a418c512cf55db
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.animation.TimeInterpolator; 24import android.app.ActivityManager; 25import android.app.ActivityManagerNative; 26import android.app.Notification; 27import android.app.PendingIntent; 28import android.app.StatusBarManager; 29import android.content.BroadcastReceiver; 30import android.content.Context; 31import android.content.Intent; 32import android.content.IntentFilter; 33import android.content.SharedPreferences; 34import android.content.res.Resources; 35import android.database.ContentObserver; 36import android.graphics.Canvas; 37import android.graphics.ColorFilter; 38import android.graphics.PixelFormat; 39import android.graphics.Point; 40import android.graphics.PorterDuff; 41import android.graphics.Rect; 42import android.graphics.drawable.Drawable; 43import android.inputmethodservice.InputMethodService; 44import android.os.Handler; 45import android.os.IBinder; 46import android.os.Message; 47import android.os.RemoteException; 48import android.os.SystemClock; 49import android.os.UserHandle; 50import android.provider.Settings; 51import android.service.notification.StatusBarNotification; 52import android.util.DisplayMetrics; 53import android.util.EventLog; 54import android.util.Log; 55import android.view.Display; 56import android.view.Gravity; 57import android.view.MotionEvent; 58import android.view.VelocityTracker; 59import android.view.View; 60import android.view.View.MeasureSpec; 61import android.view.ViewGroup; 62import android.view.ViewGroup.LayoutParams; 63import android.view.ViewPropertyAnimator; 64import android.view.ViewStub; 65import android.view.WindowManager; 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 android.widget.Toast; 76import com.android.internal.statusbar.StatusBarIcon; 77import com.android.systemui.EventLogTags; 78import com.android.systemui.R; 79import com.android.systemui.statusbar.BaseStatusBar; 80import com.android.systemui.statusbar.CommandQueue; 81import com.android.systemui.statusbar.GestureRecorder; 82import com.android.systemui.statusbar.NotificationData; 83import com.android.systemui.statusbar.NotificationData.Entry; 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.BluetoothController; 88import com.android.systemui.statusbar.policy.DateView; 89import com.android.systemui.statusbar.policy.HeadsUpNotificationView; 90import com.android.systemui.statusbar.policy.LocationController; 91import com.android.systemui.statusbar.policy.NetworkController; 92import com.android.systemui.statusbar.policy.NotificationRowLayout; 93import com.android.systemui.statusbar.policy.OnSizeChangedListener; 94import com.android.systemui.statusbar.policy.Prefs; 95import com.android.systemui.statusbar.policy.RotationLockController; 96 97import java.io.FileDescriptor; 98import java.io.PrintWriter; 99import java.util.ArrayList; 100 101public class PhoneStatusBar extends BaseStatusBar { 102 static final String TAG = "PhoneStatusBar"; 103 public static final boolean DEBUG = BaseStatusBar.DEBUG; 104 public static final boolean SPEW = DEBUG; 105 public static final boolean DUMPTRUCK = true; // extra dumpsys info 106 public static final boolean DEBUG_GESTURES = false; 107 108 public static final boolean DEBUG_CLINGS = false; 109 110 public static final boolean ENABLE_NOTIFICATION_PANEL_CLING = false; 111 112 public static final boolean SETTINGS_DRAG_SHORTCUT = true; 113 114 // additional instrumentation for testing purposes; intended to be left on during development 115 public static final boolean CHATTY = DEBUG; 116 117 public static final String ACTION_STATUSBAR_START 118 = "com.android.internal.policy.statusbar.START"; 119 120 private static final int MSG_OPEN_NOTIFICATION_PANEL = 1000; 121 private static final int MSG_CLOSE_PANELS = 1001; 122 private static final int MSG_OPEN_SETTINGS_PANEL = 1002; 123 // 1020-1030 reserved for BaseStatusBar 124 125 private static final boolean CLOSE_PANEL_WHEN_EMPTIED = true; 126 127 private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10; // see NotificationManagerService 128 private static final int HIDE_ICONS_BELOW_SCORE = Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER; 129 130 private static final int STATUS_OR_NAV_OVERLAY = 131 View.STATUS_BAR_OVERLAY | View.NAVIGATION_BAR_OVERLAY; 132 private static final long AUTOHIDE_TIMEOUT_MS = 3000; 133 private static final float TRANSPARENT_ALPHA = 0.7f; 134 135 // fling gesture tuning parameters, scaled to display density 136 private float mSelfExpandVelocityPx; // classic value: 2000px/s 137 private float mSelfCollapseVelocityPx; // classic value: 2000px/s (will be negated to collapse "up") 138 private float mFlingExpandMinVelocityPx; // classic value: 200px/s 139 private float mFlingCollapseMinVelocityPx; // classic value: 200px/s 140 private float mCollapseMinDisplayFraction; // classic value: 0.08 (25px/min(320px,480px) on G1) 141 private float mExpandMinDisplayFraction; // classic value: 0.5 (drag open halfway to expand) 142 private float mFlingGestureMaxXVelocityPx; // classic value: 150px/s 143 144 private float mExpandAccelPx; // classic value: 2000px/s/s 145 private float mCollapseAccelPx; // classic value: 2000px/s/s (will be negated to collapse "up") 146 147 private float mFlingGestureMaxOutputVelocityPx; // how fast can it really go? (should be a little 148 // faster than mSelfCollapseVelocityPx) 149 150 PhoneStatusBarPolicy mIconPolicy; 151 152 // These are no longer handled by the policy, because we need custom strategies for them 153 BluetoothController mBluetoothController; 154 BatteryController mBatteryController; 155 LocationController mLocationController; 156 NetworkController mNetworkController; 157 RotationLockController mRotationLockController; 158 159 int mNaturalBarHeight = -1; 160 int mIconSize = -1; 161 int mIconHPadding = -1; 162 Display mDisplay; 163 Point mCurrentDisplaySize = new Point(); 164 165 StatusBarWindowView mStatusBarWindow; 166 PhoneStatusBarView mStatusBarView; 167 168 int mPixelFormat; 169 Object mQueueLock = new Object(); 170 171 // viewgroup containing the normal contents of the statusbar 172 LinearLayout mStatusBarContents; 173 174 // right-hand icons 175 LinearLayout mSystemIconArea; 176 177 // left-hand icons 178 LinearLayout mStatusIcons; 179 // the icons themselves 180 IconMerger mNotificationIcons; 181 // [+> 182 View mMoreIcon; 183 184 // expanded notifications 185 NotificationPanelView mNotificationPanel; // the sliding/resizing panel within the notification window 186 ScrollView mScrollView; 187 View mExpandedContents; 188 int mNotificationPanelGravity; 189 int mNotificationPanelMarginBottomPx, mNotificationPanelMarginPx; 190 float mNotificationPanelMinHeightFrac; 191 boolean mNotificationPanelIsFullScreenWidth; 192 TextView mNotificationPanelDebugText; 193 194 // settings 195 QuickSettings mQS; 196 boolean mHasSettingsPanel, mHasFlipSettings; 197 SettingsPanelView mSettingsPanel; 198 View mFlipSettingsView; 199 QuickSettingsContainerView mSettingsContainer; 200 int mSettingsPanelGravity; 201 202 // top bar 203 View mNotificationPanelHeader; 204 View mDateTimeView; 205 View mClearButton; 206 ImageView mSettingsButton, mNotificationButton; 207 208 // carrier/wifi label 209 private TextView mCarrierLabel; 210 private boolean mCarrierLabelVisible = false; 211 private int mCarrierLabelHeight; 212 private TextView mEmergencyCallLabel; 213 private int mNotificationHeaderHeight; 214 215 private boolean mShowCarrierInPanel = false; 216 217 // position 218 int[] mPositionTmp = new int[2]; 219 boolean mExpandedVisible; 220 221 // the date view 222 DateView mDateView; 223 224 // for heads up notifications 225 private HeadsUpNotificationView mHeadsUpNotificationView; 226 private int mHeadsUpNotificationDecay; 227 228 // on-screen navigation buttons 229 private NavigationBarView mNavigationBarView = null; 230 231 // the tracker view 232 int mTrackingPosition; // the position of the top of the tracking view. 233 234 // ticker 235 private Ticker mTicker; 236 private View mTickerView; 237 private boolean mTicking; 238 239 // Tracking finger for opening/closing. 240 int mEdgeBorder; // corresponds to R.dimen.status_bar_edge_ignore 241 boolean mTracking; 242 VelocityTracker mVelocityTracker; 243 244 // help screen 245 private boolean mClingShown; 246 private ViewGroup mCling; 247 private boolean mSuppressStatusBarDrags; // while a cling is up, briefly deaden the bar to give things time to settle 248 249 int[] mAbsPos = new int[2]; 250 Runnable mPostCollapseCleanup = null; 251 252 private Animator mLightsOutAnimation; 253 private Animator mLightsOnAnimation; 254 255 // for disabling the status bar 256 int mDisabled = 0; 257 258 // tracking calls to View.setSystemUiVisibility() 259 int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE; 260 261 DisplayMetrics mDisplayMetrics = new DisplayMetrics(); 262 263 // XXX: gesture research 264 private final GestureRecorder mGestureRec = DEBUG_GESTURES 265 ? new GestureRecorder("/sdcard/statusbar_gestures.dat") 266 : null; 267 268 private int mNavigationIconHints = 0; 269 private final Animator.AnimatorListener mMakeIconsInvisible = new AnimatorListenerAdapter() { 270 @Override 271 public void onAnimationEnd(Animator animation) { 272 // double-check to avoid races 273 if (mStatusBarContents.getAlpha() == 0) { 274 if (DEBUG) Log.d(TAG, "makeIconsInvisible"); 275 mStatusBarContents.setVisibility(View.INVISIBLE); 276 } 277 } 278 }; 279 280 // ensure quick settings is disabled until the current user makes it through the setup wizard 281 private boolean mUserSetup = false; 282 private ContentObserver mUserSetupObserver = new ContentObserver(new Handler()) { 283 @Override 284 public void onChange(boolean selfChange) { 285 final boolean userSetup = 0 != Settings.Secure.getIntForUser( 286 mContext.getContentResolver(), 287 Settings.Secure.USER_SETUP_COMPLETE, 288 0 /*default */, 289 mCurrentUserId); 290 if (MULTIUSER_DEBUG) Log.d(TAG, String.format("User setup changed: " + 291 "selfChange=%s userSetup=%s mUserSetup=%s", 292 selfChange, userSetup, mUserSetup)); 293 if (mSettingsButton != null && mHasFlipSettings) { 294 mSettingsButton.setVisibility(userSetup ? View.VISIBLE : View.INVISIBLE); 295 } 296 if (mSettingsPanel != null) { 297 mSettingsPanel.setEnabled(userSetup); 298 } 299 if (userSetup != mUserSetup) { 300 mUserSetup = userSetup; 301 if (!mUserSetup && mStatusBarView != null) 302 animateCollapseQuickSettings(); 303 } 304 } 305 }; 306 307 private Toast mHideybarConfirmation; 308 private boolean mHideybarConfirmationDismissed; 309 310 private final View.OnTouchListener mDismissHideybarConfirmationOnTouchOutside = 311 new View.OnTouchListener() { 312 @Override 313 public boolean onTouch(View v, MotionEvent event) { 314 if (event.getActionMasked() == MotionEvent.ACTION_OUTSIDE) { 315 dismissHideybarConfirmation(); 316 } 317 return false; 318 } 319 }; 320 321 private final Runnable mHideybarConfirmationAction = new Runnable() { 322 @Override 323 public void run() { 324 if (mHideybarConfirmation != null) { 325 final boolean isGloballyConfirmed = Prefs.read(mContext) 326 .getBoolean(Prefs.HIDEYBAR_CONFIRMED, false); 327 if (!isGloballyConfirmed) { 328 // user pressed button, consider this a confirmation 329 Prefs.edit(mContext) 330 .putBoolean(Prefs.HIDEYBAR_CONFIRMED, true) 331 .apply(); 332 } 333 dismissHideybarConfirmation(); 334 } 335 } 336 }; 337 338 private boolean mAutohideSuspended; 339 340 private final Runnable mAutohide = new Runnable() { 341 @Override 342 public void run() { 343 int requested = mSystemUiVisibility & ~STATUS_OR_NAV_OVERLAY; 344 if (mSystemUiVisibility != requested) { 345 notifyUiVisibilityChanged(requested); 346 } 347 }}; 348 349 @Override 350 public void start() { 351 mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) 352 .getDefaultDisplay(); 353 mDisplay.getSize(mCurrentDisplaySize); 354 355 super.start(); // calls createAndAddWindows() 356 357 addNavigationBar(); 358 359 if (ENABLE_HEADS_UP) addHeadsUpView(); 360 361 // Lastly, call to the icon policy to install/update all the icons. 362 mIconPolicy = new PhoneStatusBarPolicy(mContext); 363 } 364 365 // ================================================================================ 366 // Constructing the view 367 // ================================================================================ 368 protected PhoneStatusBarView makeStatusBarView() { 369 final Context context = mContext; 370 371 Resources res = context.getResources(); 372 373 updateDisplaySize(); // populates mDisplayMetrics 374 loadDimens(); 375 376 mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); 377 378 mStatusBarWindow = (StatusBarWindowView) View.inflate(context, 379 R.layout.super_status_bar, null); 380 mStatusBarWindow.mService = this; 381 mStatusBarWindow.setOnTouchListener(new View.OnTouchListener() { 382 @Override 383 public boolean onTouch(View v, MotionEvent event) { 384 checkUserAutohide(v, event); 385 if (event.getAction() == MotionEvent.ACTION_DOWN) { 386 if (mExpandedVisible) { 387 animateCollapsePanels(); 388 } 389 } 390 return mStatusBarWindow.onTouchEvent(event); 391 }}); 392 393 mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar); 394 mStatusBarView.setBar(this); 395 396 397 PanelHolder holder = (PanelHolder) mStatusBarWindow.findViewById(R.id.panel_holder); 398 mStatusBarView.setPanelHolder(holder); 399 400 mNotificationPanel = (NotificationPanelView) mStatusBarWindow.findViewById(R.id.notification_panel); 401 mNotificationPanel.setStatusBar(this); 402 mNotificationPanelIsFullScreenWidth = 403 (mNotificationPanel.getLayoutParams().width == ViewGroup.LayoutParams.MATCH_PARENT); 404 405 // make the header non-responsive to clicks 406 mNotificationPanel.findViewById(R.id.header).setOnTouchListener( 407 new View.OnTouchListener() { 408 @Override 409 public boolean onTouch(View v, MotionEvent event) { 410 return true; // e eats everything 411 } 412 }); 413 414 if (!ActivityManager.isHighEndGfx()) { 415 mStatusBarWindow.setBackground(null); 416 mNotificationPanel.setBackground(new FastColorDrawable(context.getResources().getColor( 417 R.color.notification_panel_solid_background))); 418 } 419 if (ENABLE_HEADS_UP) { 420 mHeadsUpNotificationView = 421 (HeadsUpNotificationView) View.inflate(context, R.layout.heads_up, null); 422 mHeadsUpNotificationView.setVisibility(View.GONE); 423 mHeadsUpNotificationView.setBar(this); 424 } 425 if (MULTIUSER_DEBUG) { 426 mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(R.id.header_debug_info); 427 mNotificationPanelDebugText.setVisibility(View.VISIBLE); 428 } 429 430 updateShowSearchHoldoff(); 431 432 try { 433 boolean showNav = mWindowManagerService.hasNavigationBar(); 434 if (DEBUG) Log.v(TAG, "hasNavigationBar=" + showNav); 435 if (showNav) { 436 mNavigationBarView = 437 (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null); 438 439 mNavigationBarView.setDisabledFlags(mDisabled); 440 mNavigationBarView.setBar(this); 441 mNavigationBarView.setOnTouchListener(new View.OnTouchListener() { 442 @Override 443 public boolean onTouch(View v, MotionEvent event) { 444 checkUserAutohide(v, event); 445 return false; 446 }}); 447 } 448 } catch (RemoteException ex) { 449 // no window manager? good luck with that 450 } 451 452 // figure out which pixel-format to use for the status bar. 453 mPixelFormat = PixelFormat.OPAQUE; 454 455 mSystemIconArea = (LinearLayout) mStatusBarView.findViewById(R.id.system_icon_area); 456 mStatusIcons = (LinearLayout)mStatusBarView.findViewById(R.id.statusIcons); 457 mNotificationIcons = (IconMerger)mStatusBarView.findViewById(R.id.notificationIcons); 458 mMoreIcon = mStatusBarView.findViewById(R.id.moreIcon); 459 mNotificationIcons.setOverflowIndicator(mMoreIcon); 460 mStatusBarContents = (LinearLayout)mStatusBarView.findViewById(R.id.status_bar_contents); 461 mTickerView = mStatusBarView.findViewById(R.id.ticker); 462 463 mPile = (NotificationRowLayout)mStatusBarWindow.findViewById(R.id.latestItems); 464 mPile.setLayoutTransitionsEnabled(false); 465 mPile.setLongPressListener(getNotificationLongClicker()); 466 mExpandedContents = mPile; // was: expanded.findViewById(R.id.notificationLinearLayout); 467 468 mNotificationPanelHeader = mStatusBarWindow.findViewById(R.id.header); 469 470 mClearButton = mStatusBarWindow.findViewById(R.id.clear_all_button); 471 mClearButton.setOnClickListener(mClearButtonListener); 472 mClearButton.setAlpha(0f); 473 mClearButton.setVisibility(View.INVISIBLE); 474 mClearButton.setEnabled(false); 475 mDateView = (DateView)mStatusBarWindow.findViewById(R.id.date); 476 477 mHasSettingsPanel = res.getBoolean(R.bool.config_hasSettingsPanel); 478 mHasFlipSettings = res.getBoolean(R.bool.config_hasFlipSettingsPanel); 479 480 mDateTimeView = mNotificationPanelHeader.findViewById(R.id.datetime); 481 if (mDateTimeView != null) { 482 mDateTimeView.setOnClickListener(mClockClickListener); 483 mDateTimeView.setEnabled(true); 484 } 485 486 mSettingsButton = (ImageView) mStatusBarWindow.findViewById(R.id.settings_button); 487 if (mSettingsButton != null) { 488 mSettingsButton.setOnClickListener(mSettingsButtonListener); 489 if (mHasSettingsPanel) { 490 if (mStatusBarView.hasFullWidthNotifications()) { 491 // the settings panel is hiding behind this button 492 mSettingsButton.setImageResource(R.drawable.ic_notify_quicksettings); 493 mSettingsButton.setVisibility(View.VISIBLE); 494 } else { 495 // there is a settings panel, but it's on the other side of the (large) screen 496 final View buttonHolder = mStatusBarWindow.findViewById( 497 R.id.settings_button_holder); 498 if (buttonHolder != null) { 499 buttonHolder.setVisibility(View.GONE); 500 } 501 } 502 } else { 503 // no settings panel, go straight to settings 504 mSettingsButton.setVisibility(View.VISIBLE); 505 mSettingsButton.setImageResource(R.drawable.ic_notify_settings); 506 } 507 } 508 if (mHasFlipSettings) { 509 mNotificationButton = (ImageView) mStatusBarWindow.findViewById(R.id.notification_button); 510 if (mNotificationButton != null) { 511 mNotificationButton.setOnClickListener(mNotificationButtonListener); 512 } 513 } 514 515 mScrollView = (ScrollView)mStatusBarWindow.findViewById(R.id.scroll); 516 mScrollView.setVerticalScrollBarEnabled(false); // less drawing during pulldowns 517 if (!mNotificationPanelIsFullScreenWidth) { 518 mScrollView.setSystemUiVisibility( 519 View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER | 520 View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS | 521 View.STATUS_BAR_DISABLE_CLOCK); 522 } 523 524 mTicker = new MyTicker(context, mStatusBarView); 525 526 TickerView tickerView = (TickerView)mStatusBarView.findViewById(R.id.tickerText); 527 tickerView.mTicker = mTicker; 528 529 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore); 530 531 // set the inital view visibility 532 setAreThereNotifications(); 533 534 // Other icons 535 mLocationController = new LocationController(mContext); // will post a notification 536 mBatteryController = new BatteryController(mContext); 537 mBatteryController.addIconView((ImageView)mStatusBarView.findViewById(R.id.battery)); 538 mNetworkController = new NetworkController(mContext); 539 mBluetoothController = new BluetoothController(mContext); 540 mRotationLockController = new RotationLockController(mContext); 541 final SignalClusterView signalCluster = 542 (SignalClusterView)mStatusBarView.findViewById(R.id.signal_cluster); 543 544 545 mNetworkController.addSignalCluster(signalCluster); 546 signalCluster.setNetworkController(mNetworkController); 547 548 final boolean isAPhone = mNetworkController.hasVoiceCallingFeature(); 549 if (isAPhone) { 550 mEmergencyCallLabel = 551 (TextView) mStatusBarWindow.findViewById(R.id.emergency_calls_only); 552 if (mEmergencyCallLabel != null) { 553 mNetworkController.addEmergencyLabelView(mEmergencyCallLabel); 554 mEmergencyCallLabel.setOnClickListener(new View.OnClickListener() { 555 public void onClick(View v) { }}); 556 mEmergencyCallLabel.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { 557 @Override 558 public void onLayoutChange(View v, int left, int top, int right, int bottom, 559 int oldLeft, int oldTop, int oldRight, int oldBottom) { 560 updateCarrierLabelVisibility(false); 561 }}); 562 } 563 } 564 565 mCarrierLabel = (TextView)mStatusBarWindow.findViewById(R.id.carrier_label); 566 mShowCarrierInPanel = (mCarrierLabel != null); 567 if (DEBUG) Log.v(TAG, "carrierlabel=" + mCarrierLabel + " show=" + mShowCarrierInPanel); 568 if (mShowCarrierInPanel) { 569 mCarrierLabel.setVisibility(mCarrierLabelVisible ? View.VISIBLE : View.INVISIBLE); 570 571 // for mobile devices, we always show mobile connection info here (SPN/PLMN) 572 // for other devices, we show whatever network is connected 573 if (mNetworkController.hasMobileDataFeature()) { 574 mNetworkController.addMobileLabelView(mCarrierLabel); 575 } else { 576 mNetworkController.addCombinedLabelView(mCarrierLabel); 577 } 578 579 // set up the dynamic hide/show of the label 580 mPile.setOnSizeChangedListener(new OnSizeChangedListener() { 581 @Override 582 public void onSizeChanged(View view, int w, int h, int oldw, int oldh) { 583 updateCarrierLabelVisibility(false); 584 } 585 }); 586 } 587 588 // Quick Settings (where available, some restrictions apply) 589 if (mHasSettingsPanel) { 590 // first, figure out where quick settings should be inflated 591 final View settings_stub; 592 if (mHasFlipSettings) { 593 // a version of quick settings that flips around behind the notifications 594 settings_stub = mStatusBarWindow.findViewById(R.id.flip_settings_stub); 595 if (settings_stub != null) { 596 mFlipSettingsView = ((ViewStub)settings_stub).inflate(); 597 mFlipSettingsView.setVisibility(View.GONE); 598 mFlipSettingsView.setVerticalScrollBarEnabled(false); 599 } 600 } else { 601 // full quick settings panel 602 settings_stub = mStatusBarWindow.findViewById(R.id.quick_settings_stub); 603 if (settings_stub != null) { 604 mSettingsPanel = (SettingsPanelView) ((ViewStub)settings_stub).inflate(); 605 } else { 606 mSettingsPanel = (SettingsPanelView) mStatusBarWindow.findViewById(R.id.settings_panel); 607 } 608 609 if (mSettingsPanel != null) { 610 if (!ActivityManager.isHighEndGfx()) { 611 mSettingsPanel.setBackground(new FastColorDrawable(context.getResources().getColor( 612 R.color.notification_panel_solid_background))); 613 } 614 } 615 } 616 617 // wherever you find it, Quick Settings needs a container to survive 618 mSettingsContainer = (QuickSettingsContainerView) 619 mStatusBarWindow.findViewById(R.id.quick_settings_container); 620 if (mSettingsContainer != null) { 621 mQS = new QuickSettings(mContext, mSettingsContainer); 622 if (!mNotificationPanelIsFullScreenWidth) { 623 mSettingsContainer.setSystemUiVisibility( 624 View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER 625 | View.STATUS_BAR_DISABLE_SYSTEM_INFO); 626 } 627 if (mSettingsPanel != null) { 628 mSettingsPanel.setQuickSettings(mQS); 629 } 630 mQS.setService(this); 631 mQS.setBar(mStatusBarView); 632 mQS.setup(mNetworkController, mBluetoothController, mBatteryController, 633 mLocationController, mRotationLockController); 634 } else { 635 mQS = null; // fly away, be free 636 } 637 } 638 639 mClingShown = ! (DEBUG_CLINGS 640 || !Prefs.read(mContext).getBoolean(Prefs.SHOWN_QUICK_SETTINGS_HELP, false)); 641 642 if (!ENABLE_NOTIFICATION_PANEL_CLING || ActivityManager.isRunningInTestHarness()) { 643 mClingShown = true; 644 } 645 646// final ImageView wimaxRSSI = 647// (ImageView)sb.findViewById(R.id.wimax_signal); 648// if (wimaxRSSI != null) { 649// mNetworkController.addWimaxIconView(wimaxRSSI); 650// } 651 652 // receive broadcasts 653 IntentFilter filter = new IntentFilter(); 654 filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); 655 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 656 filter.addAction(Intent.ACTION_SCREEN_OFF); 657 filter.addAction(Intent.ACTION_SCREEN_ON); 658 context.registerReceiver(mBroadcastReceiver, filter); 659 660 // listen for USER_SETUP_COMPLETE setting (per-user) 661 resetUserSetupObserver(); 662 663 return mStatusBarView; 664 } 665 666 @Override 667 protected View getStatusBarView() { 668 return mStatusBarView; 669 } 670 671 @Override 672 protected WindowManager.LayoutParams getSearchLayoutParams(LayoutParams layoutParams) { 673 boolean opaque = false; 674 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 675 LayoutParams.MATCH_PARENT, 676 LayoutParams.MATCH_PARENT, 677 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, 678 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 679 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 680 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 681 (opaque ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT)); 682 if (ActivityManager.isHighEndGfx()) { 683 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 684 } 685 lp.gravity = Gravity.BOTTOM | Gravity.START; 686 lp.setTitle("SearchPanel"); 687 // TODO: Define custom animation for Search panel 688 lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications; 689 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 690 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 691 return lp; 692 } 693 694 @Override 695 protected void updateSearchPanel() { 696 super.updateSearchPanel(); 697 mNavigationBarView.setDelegateView(mSearchPanelView); 698 } 699 700 @Override 701 public void showSearchPanel() { 702 super.showSearchPanel(); 703 mHandler.removeCallbacks(mShowSearchPanel); 704 705 // we want to freeze the sysui state wherever it is 706 mSearchPanelView.setSystemUiVisibility(mSystemUiVisibility); 707 708 WindowManager.LayoutParams lp = 709 (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams(); 710 lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; 711 mWindowManager.updateViewLayout(mNavigationBarView, lp); 712 } 713 714 @Override 715 public void hideSearchPanel() { 716 super.hideSearchPanel(); 717 WindowManager.LayoutParams lp = 718 (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams(); 719 lp.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; 720 mWindowManager.updateViewLayout(mNavigationBarView, lp); 721 } 722 723 protected int getStatusBarGravity() { 724 return Gravity.TOP | Gravity.FILL_HORIZONTAL; 725 } 726 727 public int getStatusBarHeight() { 728 if (mNaturalBarHeight < 0) { 729 final Resources res = mContext.getResources(); 730 mNaturalBarHeight = 731 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); 732 } 733 return mNaturalBarHeight; 734 } 735 736 private View.OnClickListener mRecentsClickListener = new View.OnClickListener() { 737 public void onClick(View v) { 738 awakenDreams(); 739 toggleRecentApps(); 740 } 741 }; 742 743 private int mShowSearchHoldoff = 0; 744 private Runnable mShowSearchPanel = new Runnable() { 745 public void run() { 746 showSearchPanel(); 747 awakenDreams(); 748 } 749 }; 750 751 View.OnTouchListener mHomeSearchActionListener = new View.OnTouchListener() { 752 public boolean onTouch(View v, MotionEvent event) { 753 switch(event.getAction()) { 754 case MotionEvent.ACTION_DOWN: 755 if (!shouldDisableNavbarGestures()) { 756 mHandler.removeCallbacks(mShowSearchPanel); 757 mHandler.postDelayed(mShowSearchPanel, mShowSearchHoldoff); 758 } 759 break; 760 761 case MotionEvent.ACTION_UP: 762 case MotionEvent.ACTION_CANCEL: 763 mHandler.removeCallbacks(mShowSearchPanel); 764 awakenDreams(); 765 break; 766 } 767 return false; 768 } 769 }; 770 771 private void awakenDreams() { 772 if (mDreamManager != null) { 773 try { 774 mDreamManager.awaken(); 775 } catch (RemoteException e) { 776 // fine, stay asleep then 777 } 778 } 779 } 780 781 private void prepareNavigationBarView() { 782 mNavigationBarView.reorient(); 783 784 mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener); 785 mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPreloadOnTouchListener); 786 mNavigationBarView.getHomeButton().setOnTouchListener(mHomeSearchActionListener); 787 mNavigationBarView.getSearchLight().setOnTouchListener(mHomeSearchActionListener); 788 updateSearchPanel(); 789 } 790 791 // For small-screen devices (read: phones) that lack hardware navigation buttons 792 private void addNavigationBar() { 793 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + mNavigationBarView); 794 if (mNavigationBarView == null) return; 795 796 prepareNavigationBarView(); 797 798 mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams()); 799 } 800 801 private void repositionNavigationBar() { 802 if (mNavigationBarView == null) return; 803 804 prepareNavigationBarView(); 805 806 mWindowManager.updateViewLayout(mNavigationBarView, getNavigationBarLayoutParams()); 807 } 808 809 private void notifyNavigationBarScreenOn(boolean screenOn) { 810 if (mNavigationBarView == null) return; 811 mNavigationBarView.notifyScreenOn(screenOn); 812 } 813 814 private WindowManager.LayoutParams getNavigationBarLayoutParams() { 815 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 816 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 817 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, 818 0 819 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING 820 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 821 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 822 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH 823 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 824 PixelFormat.TRANSLUCENT); 825 // this will allow the navbar to run in an overlay on devices that support this 826 if (ActivityManager.isHighEndGfx()) { 827 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 828 } 829 830 lp.setTitle("NavigationBar"); 831 lp.windowAnimations = 0; 832 return lp; 833 } 834 835 private void addHeadsUpView() { 836 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 837 ViewGroup.LayoutParams.MATCH_PARENT, 838 ViewGroup.LayoutParams.WRAP_CONTENT, 839 WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL, // above the status bar! 840 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 841 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 842 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 843 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 844 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 845 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 846 PixelFormat.TRANSLUCENT); 847 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 848 lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL; 849 lp.setTitle("Heads Up"); 850 lp.packageName = mContext.getPackageName(); 851 lp.windowAnimations = R.style.Animation_StatusBar_HeadsUp; 852 853 mWindowManager.addView(mHeadsUpNotificationView, lp); 854 } 855 856 public void refreshAllStatusBarIcons() { 857 refreshAllIconsForLayout(mStatusIcons); 858 refreshAllIconsForLayout(mNotificationIcons); 859 } 860 861 private void refreshAllIconsForLayout(LinearLayout ll) { 862 final int count = ll.getChildCount(); 863 for (int n = 0; n < count; n++) { 864 View child = ll.getChildAt(n); 865 if (child instanceof StatusBarIconView) { 866 ((StatusBarIconView) child).updateDrawable(); 867 } 868 } 869 } 870 871 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) { 872 if (SPEW) Log.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex 873 + " icon=" + icon); 874 StatusBarIconView view = new StatusBarIconView(mContext, slot, null); 875 view.set(icon); 876 mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(mIconSize, mIconSize)); 877 } 878 879 public void updateIcon(String slot, int index, int viewIndex, 880 StatusBarIcon old, StatusBarIcon icon) { 881 if (SPEW) Log.d(TAG, "updateIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex 882 + " old=" + old + " icon=" + icon); 883 StatusBarIconView view = (StatusBarIconView)mStatusIcons.getChildAt(viewIndex); 884 view.set(icon); 885 } 886 887 public void removeIcon(String slot, int index, int viewIndex) { 888 if (SPEW) Log.d(TAG, "removeIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex); 889 mStatusIcons.removeViewAt(viewIndex); 890 } 891 892 public void addNotification(IBinder key, StatusBarNotification notification) { 893 if (DEBUG) Log.d(TAG, "addNotification score=" + notification.getScore()); 894 StatusBarIconView iconView = addNotificationViews(key, notification); 895 if (iconView == null) return; 896 897 if (mUseHeadsUp && shouldInterrupt(notification)) { 898 if (DEBUG) Log.d(TAG, "launching notification in heads up mode"); 899 // 1. Populate mHeadsUpNotificationView 900 mInterruptingNotificationTime = System.currentTimeMillis(); 901 mInterruptingNotificationEntry = new Entry(key, notification, null); 902 903 if (inflateViews(mInterruptingNotificationEntry, 904 mHeadsUpNotificationView.getHolder())) { 905 mHeadsUpNotificationView.setNotification(mInterruptingNotificationEntry); 906 // 2. Animate mHeadsUpNotificationView in 907 mHandler.sendEmptyMessage(MSG_SHOW_HEADS_UP); 908 909 // 3. Set alarm to age the notification off 910 resetHeadsUpDecayTimer(); 911 } else { 912 mInterruptingNotificationEntry = null; 913 } 914 } else if (notification.getNotification().fullScreenIntent != null) { 915 // Stop screensaver if the notification has a full-screen intent. 916 // (like an incoming phone call) 917 awakenDreams(); 918 919 // not immersive & a full-screen alert should be shown 920 if (DEBUG) Log.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent"); 921 try { 922 notification.getNotification().fullScreenIntent.send(); 923 } catch (PendingIntent.CanceledException e) { 924 } 925 } else { 926 // usual case: status bar visible & not immersive 927 928 // show the ticker if there isn't already a heads up 929 if (mInterruptingNotificationEntry == null) { 930 tick(null, notification, true); 931 } 932 } 933 934 // Recalculate the position of the sliding windows and the titles. 935 setAreThereNotifications(); 936 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 937 } 938 939 @Override 940 public void resetHeadsUpDecayTimer() { 941 mHandler.removeMessages(MSG_HIDE_HEADS_UP); 942 if (mHeadsUpNotificationDecay > 0) { 943 mHandler.sendEmptyMessageDelayed(MSG_HIDE_HEADS_UP, mHeadsUpNotificationDecay); 944 } 945 } 946 947 public void removeNotification(IBinder key) { 948 StatusBarNotification old = removeNotificationViews(key); 949 if (SPEW) Log.d(TAG, "removeNotification key=" + key + " old=" + old); 950 951 if (old != null) { 952 // Cancel the ticker if it's still running 953 mTicker.removeEntry(old); 954 955 // Recalculate the position of the sliding windows and the titles. 956 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 957 958 if (ENABLE_HEADS_UP && mInterruptingNotificationEntry != null 959 && old == mInterruptingNotificationEntry.notification) { 960 mHandler.sendEmptyMessage(MSG_HIDE_HEADS_UP); 961 } 962 963 if (CLOSE_PANEL_WHEN_EMPTIED && mNotificationData.size() == 0) { 964 animateCollapsePanels(); 965 } 966 } 967 968 setAreThereNotifications(); 969 } 970 971 @Override 972 protected void refreshLayout(int layoutDirection) { 973 if (mNavigationBarView != null) { 974 mNavigationBarView.setLayoutDirection(layoutDirection); 975 } 976 977 if (mClearButton != null && mClearButton instanceof ImageView) { 978 // Force asset reloading 979 ((ImageView)mClearButton).setImageDrawable(null); 980 ((ImageView)mClearButton).setImageResource(R.drawable.ic_notify_clear); 981 } 982 983 if (mSettingsButton != null) { 984 // Force asset reloading 985 mSettingsButton.setImageDrawable(null); 986 mSettingsButton.setImageResource(R.drawable.ic_notify_quicksettings); 987 } 988 989 if (mNotificationButton != null) { 990 // Force asset reloading 991 mNotificationButton.setImageDrawable(null); 992 mNotificationButton.setImageResource(R.drawable.ic_notifications); 993 } 994 995 refreshAllStatusBarIcons(); 996 } 997 998 private void updateShowSearchHoldoff() { 999 mShowSearchHoldoff = mContext.getResources().getInteger( 1000 R.integer.config_show_search_delay); 1001 } 1002 1003 private void loadNotificationShade() { 1004 if (mPile == null) return; 1005 1006 int N = mNotificationData.size(); 1007 1008 ArrayList<View> toShow = new ArrayList<View>(); 1009 1010 final boolean provisioned = isDeviceProvisioned(); 1011 // If the device hasn't been through Setup, we only show system notifications 1012 for (int i=0; i<N; i++) { 1013 Entry ent = mNotificationData.get(N-i-1); 1014 if (!(provisioned || showNotificationEvenIfUnprovisioned(ent.notification))) continue; 1015 if (!notificationIsForCurrentUser(ent.notification)) continue; 1016 toShow.add(ent.row); 1017 } 1018 1019 ArrayList<View> toRemove = new ArrayList<View>(); 1020 for (int i=0; i<mPile.getChildCount(); i++) { 1021 View child = mPile.getChildAt(i); 1022 if (!toShow.contains(child)) { 1023 toRemove.add(child); 1024 } 1025 } 1026 1027 for (View remove : toRemove) { 1028 mPile.removeView(remove); 1029 } 1030 1031 for (int i=0; i<toShow.size(); i++) { 1032 View v = toShow.get(i); 1033 if (v.getParent() == null) { 1034 mPile.addView(v, i); 1035 } 1036 } 1037 1038 if (mSettingsButton != null) { 1039 mSettingsButton.setEnabled(isDeviceProvisioned()); 1040 } 1041 } 1042 1043 @Override 1044 protected void updateNotificationIcons() { 1045 if (mNotificationIcons == null) return; 1046 1047 loadNotificationShade(); 1048 1049 final LinearLayout.LayoutParams params 1050 = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight); 1051 1052 int N = mNotificationData.size(); 1053 1054 if (DEBUG) { 1055 Log.d(TAG, "refreshing icons: " + N + " notifications, mNotificationIcons=" + mNotificationIcons); 1056 } 1057 1058 ArrayList<View> toShow = new ArrayList<View>(); 1059 1060 final boolean provisioned = isDeviceProvisioned(); 1061 // If the device hasn't been through Setup, we only show system notifications 1062 for (int i=0; i<N; i++) { 1063 Entry ent = mNotificationData.get(N-i-1); 1064 if (!((provisioned && ent.notification.getScore() >= HIDE_ICONS_BELOW_SCORE) 1065 || showNotificationEvenIfUnprovisioned(ent.notification))) continue; 1066 if (!notificationIsForCurrentUser(ent.notification)) continue; 1067 toShow.add(ent.icon); 1068 } 1069 1070 ArrayList<View> toRemove = new ArrayList<View>(); 1071 for (int i=0; i<mNotificationIcons.getChildCount(); i++) { 1072 View child = mNotificationIcons.getChildAt(i); 1073 if (!toShow.contains(child)) { 1074 toRemove.add(child); 1075 } 1076 } 1077 1078 for (View remove : toRemove) { 1079 mNotificationIcons.removeView(remove); 1080 } 1081 1082 for (int i=0; i<toShow.size(); i++) { 1083 View v = toShow.get(i); 1084 if (v.getParent() == null) { 1085 mNotificationIcons.addView(v, i, params); 1086 } 1087 } 1088 } 1089 1090 protected void updateCarrierLabelVisibility(boolean force) { 1091 if (!mShowCarrierInPanel) return; 1092 // The idea here is to only show the carrier label when there is enough room to see it, 1093 // i.e. when there aren't enough notifications to fill the panel. 1094 if (DEBUG) { 1095 Log.d(TAG, String.format("pileh=%d scrollh=%d carrierh=%d", 1096 mPile.getHeight(), mScrollView.getHeight(), mCarrierLabelHeight)); 1097 } 1098 1099 final boolean emergencyCallsShownElsewhere = mEmergencyCallLabel != null; 1100 final boolean makeVisible = 1101 !(emergencyCallsShownElsewhere && mNetworkController.isEmergencyOnly()) 1102 && mPile.getHeight() < (mNotificationPanel.getHeight() - mCarrierLabelHeight - mNotificationHeaderHeight) 1103 && mScrollView.getVisibility() == View.VISIBLE; 1104 1105 if (force || mCarrierLabelVisible != makeVisible) { 1106 mCarrierLabelVisible = makeVisible; 1107 if (DEBUG) { 1108 Log.d(TAG, "making carrier label " + (makeVisible?"visible":"invisible")); 1109 } 1110 mCarrierLabel.animate().cancel(); 1111 if (makeVisible) { 1112 mCarrierLabel.setVisibility(View.VISIBLE); 1113 } 1114 mCarrierLabel.animate() 1115 .alpha(makeVisible ? 1f : 0f) 1116 //.setStartDelay(makeVisible ? 500 : 0) 1117 //.setDuration(makeVisible ? 750 : 100) 1118 .setDuration(150) 1119 .setListener(makeVisible ? null : new AnimatorListenerAdapter() { 1120 @Override 1121 public void onAnimationEnd(Animator animation) { 1122 if (!mCarrierLabelVisible) { // race 1123 mCarrierLabel.setVisibility(View.INVISIBLE); 1124 mCarrierLabel.setAlpha(0f); 1125 } 1126 } 1127 }) 1128 .start(); 1129 } 1130 } 1131 1132 @Override 1133 protected void setAreThereNotifications() { 1134 final boolean any = mNotificationData.size() > 0; 1135 1136 final boolean clearable = any && mNotificationData.hasClearableItems(); 1137 1138 if (DEBUG) { 1139 Log.d(TAG, "setAreThereNotifications: N=" + mNotificationData.size() 1140 + " any=" + any + " clearable=" + clearable); 1141 } 1142 1143 if (mHasFlipSettings 1144 && mFlipSettingsView != null 1145 && mFlipSettingsView.getVisibility() == View.VISIBLE 1146 && mScrollView.getVisibility() != View.VISIBLE) { 1147 // the flip settings panel is unequivocally showing; we should not be shown 1148 mClearButton.setVisibility(View.INVISIBLE); 1149 } else if (mClearButton.isShown()) { 1150 if (clearable != (mClearButton.getAlpha() == 1.0f)) { 1151 ObjectAnimator clearAnimation = ObjectAnimator.ofFloat( 1152 mClearButton, "alpha", clearable ? 1.0f : 0.0f).setDuration(250); 1153 clearAnimation.addListener(new AnimatorListenerAdapter() { 1154 @Override 1155 public void onAnimationEnd(Animator animation) { 1156 if (mClearButton.getAlpha() <= 0.0f) { 1157 mClearButton.setVisibility(View.INVISIBLE); 1158 } 1159 } 1160 1161 @Override 1162 public void onAnimationStart(Animator animation) { 1163 if (mClearButton.getAlpha() <= 0.0f) { 1164 mClearButton.setVisibility(View.VISIBLE); 1165 } 1166 } 1167 }); 1168 clearAnimation.start(); 1169 } 1170 } else { 1171 mClearButton.setAlpha(clearable ? 1.0f : 0.0f); 1172 mClearButton.setVisibility(clearable ? View.VISIBLE : View.INVISIBLE); 1173 } 1174 mClearButton.setEnabled(clearable); 1175 1176 final View nlo = mStatusBarView.findViewById(R.id.notification_lights_out); 1177 final boolean showDot = (any&&!areLightsOn()); 1178 if (showDot != (nlo.getAlpha() == 1.0f)) { 1179 if (showDot) { 1180 nlo.setAlpha(0f); 1181 nlo.setVisibility(View.VISIBLE); 1182 } 1183 nlo.animate() 1184 .alpha(showDot?1:0) 1185 .setDuration(showDot?750:250) 1186 .setInterpolator(new AccelerateInterpolator(2.0f)) 1187 .setListener(showDot ? null : new AnimatorListenerAdapter() { 1188 @Override 1189 public void onAnimationEnd(Animator _a) { 1190 nlo.setVisibility(View.GONE); 1191 } 1192 }) 1193 .start(); 1194 } 1195 1196 updateCarrierLabelVisibility(false); 1197 } 1198 1199 public void showClock(boolean show) { 1200 if (mStatusBarView == null) return; 1201 View clock = mStatusBarView.findViewById(R.id.clock); 1202 if (clock != null) { 1203 clock.setVisibility(show ? View.VISIBLE : View.GONE); 1204 } 1205 } 1206 1207 /** 1208 * State is one or more of the DISABLE constants from StatusBarManager. 1209 */ 1210 public void disable(int state) { 1211 final int old = mDisabled; 1212 final int diff = state ^ old; 1213 mDisabled = state; 1214 1215 if (DEBUG) { 1216 Log.d(TAG, String.format("disable: 0x%08x -> 0x%08x (diff: 0x%08x)", 1217 old, state, diff)); 1218 } 1219 1220 StringBuilder flagdbg = new StringBuilder(); 1221 flagdbg.append("disable: < "); 1222 flagdbg.append(((state & StatusBarManager.DISABLE_EXPAND) != 0) ? "EXPAND" : "expand"); 1223 flagdbg.append(((diff & StatusBarManager.DISABLE_EXPAND) != 0) ? "* " : " "); 1224 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "ICONS" : "icons"); 1225 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "* " : " "); 1226 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "ALERTS" : "alerts"); 1227 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "* " : " "); 1228 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "TICKER" : "ticker"); 1229 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "* " : " "); 1230 flagdbg.append(((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "SYSTEM_INFO" : "system_info"); 1231 flagdbg.append(((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "* " : " "); 1232 flagdbg.append(((state & StatusBarManager.DISABLE_BACK) != 0) ? "BACK" : "back"); 1233 flagdbg.append(((diff & StatusBarManager.DISABLE_BACK) != 0) ? "* " : " "); 1234 flagdbg.append(((state & StatusBarManager.DISABLE_HOME) != 0) ? "HOME" : "home"); 1235 flagdbg.append(((diff & StatusBarManager.DISABLE_HOME) != 0) ? "* " : " "); 1236 flagdbg.append(((state & StatusBarManager.DISABLE_RECENT) != 0) ? "RECENT" : "recent"); 1237 flagdbg.append(((diff & StatusBarManager.DISABLE_RECENT) != 0) ? "* " : " "); 1238 flagdbg.append(((state & StatusBarManager.DISABLE_CLOCK) != 0) ? "CLOCK" : "clock"); 1239 flagdbg.append(((diff & StatusBarManager.DISABLE_CLOCK) != 0) ? "* " : " "); 1240 flagdbg.append(((state & StatusBarManager.DISABLE_SEARCH) != 0) ? "SEARCH" : "search"); 1241 flagdbg.append(((diff & StatusBarManager.DISABLE_SEARCH) != 0) ? "* " : " "); 1242 flagdbg.append(">"); 1243 Log.d(TAG, flagdbg.toString()); 1244 1245 if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { 1246 mSystemIconArea.animate().cancel(); 1247 if ((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) { 1248 mSystemIconArea.animate() 1249 .alpha(0f) 1250 .translationY(mNaturalBarHeight*0.5f) 1251 .setDuration(175) 1252 .setInterpolator(new DecelerateInterpolator(1.5f)) 1253 .setListener(mMakeIconsInvisible) 1254 .start(); 1255 } else { 1256 mSystemIconArea.setVisibility(View.VISIBLE); 1257 mSystemIconArea.animate() 1258 .alpha(1f) 1259 .translationY(0) 1260 .setStartDelay(0) 1261 .setInterpolator(new DecelerateInterpolator(1.5f)) 1262 .setDuration(175) 1263 .start(); 1264 } 1265 } 1266 1267 if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) { 1268 boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0; 1269 showClock(show); 1270 } 1271 if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { 1272 if ((state & StatusBarManager.DISABLE_EXPAND) != 0) { 1273 animateCollapsePanels(); 1274 } 1275 } 1276 1277 if ((diff & (StatusBarManager.DISABLE_HOME 1278 | StatusBarManager.DISABLE_RECENT 1279 | StatusBarManager.DISABLE_BACK 1280 | StatusBarManager.DISABLE_SEARCH)) != 0) { 1281 // the nav bar will take care of these 1282 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state); 1283 1284 if ((state & StatusBarManager.DISABLE_RECENT) != 0) { 1285 // close recents if it's visible 1286 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); 1287 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); 1288 } 1289 } 1290 1291 if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1292 if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1293 if (mTicking) { 1294 haltTicker(); 1295 } 1296 1297 mNotificationIcons.animate() 1298 .alpha(0f) 1299 .translationY(mNaturalBarHeight*0.5f) 1300 .setDuration(175) 1301 .setInterpolator(new DecelerateInterpolator(1.5f)) 1302 .setListener(mMakeIconsInvisible) 1303 .start(); 1304 } else { 1305 mNotificationIcons.setVisibility(View.VISIBLE); 1306 mNotificationIcons.animate() 1307 .alpha(1f) 1308 .translationY(0) 1309 .setStartDelay(0) 1310 .setInterpolator(new DecelerateInterpolator(1.5f)) 1311 .setDuration(175) 1312 .start(); 1313 } 1314 } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1315 if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1316 haltTicker(); 1317 } 1318 } 1319 } 1320 1321 @Override 1322 protected BaseStatusBar.H createHandler() { 1323 return new PhoneStatusBar.H(); 1324 } 1325 1326 /** 1327 * All changes to the status bar and notifications funnel through here and are batched. 1328 */ 1329 private class H extends BaseStatusBar.H { 1330 public void handleMessage(Message m) { 1331 super.handleMessage(m); 1332 switch (m.what) { 1333 case MSG_OPEN_NOTIFICATION_PANEL: 1334 animateExpandNotificationsPanel(); 1335 break; 1336 case MSG_OPEN_SETTINGS_PANEL: 1337 animateExpandSettingsPanel(); 1338 break; 1339 case MSG_CLOSE_PANELS: 1340 animateCollapsePanels(); 1341 break; 1342 case MSG_SHOW_HEADS_UP: 1343 setHeadsUpVisibility(true); 1344 break; 1345 case MSG_HIDE_HEADS_UP: 1346 setHeadsUpVisibility(false); 1347 mInterruptingNotificationEntry = null; 1348 break; 1349 } 1350 } 1351 } 1352 1353 public Handler getHandler() { 1354 return mHandler; 1355 } 1356 1357 View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() { 1358 public void onFocusChange(View v, boolean hasFocus) { 1359 // Because 'v' is a ViewGroup, all its children will be (un)selected 1360 // too, which allows marqueeing to work. 1361 v.setSelected(hasFocus); 1362 } 1363 }; 1364 1365 void makeExpandedVisible() { 1366 if (SPEW) Log.d(TAG, "Make expanded visible: expanded visible=" + mExpandedVisible); 1367 if (mExpandedVisible) { 1368 return; 1369 } 1370 1371 mExpandedVisible = true; 1372 mPile.setLayoutTransitionsEnabled(true); 1373 if (mNavigationBarView != null) 1374 mNavigationBarView.setSlippery(true); 1375 1376 updateCarrierLabelVisibility(true); 1377 1378 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 1379 1380 // Expand the window to encompass the full screen in anticipation of the drag. 1381 // This is only possible to do atomically because the status bar is at the top of the screen! 1382 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); 1383 lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 1384 lp.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; 1385 lp.height = ViewGroup.LayoutParams.MATCH_PARENT; 1386 mWindowManager.updateViewLayout(mStatusBarWindow, lp); 1387 1388 visibilityChanged(true); 1389 1390 suspendAutohide(); 1391 } 1392 1393 public void animateCollapsePanels() { 1394 animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); 1395 } 1396 1397 public void animateCollapsePanels(int flags) { 1398 if (SPEW) { 1399 Log.d(TAG, "animateCollapse():" 1400 + " mExpandedVisible=" + mExpandedVisible 1401 + " flags=" + flags); 1402 } 1403 1404 if ((flags & CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL) == 0) { 1405 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); 1406 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); 1407 } 1408 1409 if ((flags & CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL) == 0) { 1410 mHandler.removeMessages(MSG_CLOSE_SEARCH_PANEL); 1411 mHandler.sendEmptyMessage(MSG_CLOSE_SEARCH_PANEL); 1412 } 1413 1414 mStatusBarWindow.cancelExpandHelper(); 1415 mStatusBarView.collapseAllPanels(true); 1416 } 1417 1418 public ViewPropertyAnimator setVisibilityWhenDone( 1419 final ViewPropertyAnimator a, final View v, final int vis) { 1420 a.setListener(new AnimatorListenerAdapter() { 1421 @Override 1422 public void onAnimationEnd(Animator animation) { 1423 v.setVisibility(vis); 1424 a.setListener(null); // oneshot 1425 } 1426 }); 1427 return a; 1428 } 1429 1430 public Animator setVisibilityWhenDone( 1431 final Animator a, final View v, final int vis) { 1432 a.addListener(new AnimatorListenerAdapter() { 1433 @Override 1434 public void onAnimationEnd(Animator animation) { 1435 v.setVisibility(vis); 1436 } 1437 }); 1438 return a; 1439 } 1440 1441 public Animator interpolator(TimeInterpolator ti, Animator a) { 1442 a.setInterpolator(ti); 1443 return a; 1444 } 1445 1446 public Animator startDelay(int d, Animator a) { 1447 a.setStartDelay(d); 1448 return a; 1449 } 1450 1451 public Animator start(Animator a) { 1452 a.start(); 1453 return a; 1454 } 1455 1456 final TimeInterpolator mAccelerateInterpolator = new AccelerateInterpolator(); 1457 final TimeInterpolator mDecelerateInterpolator = new DecelerateInterpolator(); 1458 final int FLIP_DURATION_OUT = 125; 1459 final int FLIP_DURATION_IN = 225; 1460 final int FLIP_DURATION = (FLIP_DURATION_IN + FLIP_DURATION_OUT); 1461 1462 Animator mScrollViewAnim, mFlipSettingsViewAnim, mNotificationButtonAnim, 1463 mSettingsButtonAnim, mClearButtonAnim; 1464 1465 @Override 1466 public void animateExpandNotificationsPanel() { 1467 if (SPEW) Log.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible); 1468 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1469 return ; 1470 } 1471 1472 mNotificationPanel.expand(); 1473 if (mHasFlipSettings && mScrollView.getVisibility() != View.VISIBLE) { 1474 flipToNotifications(); 1475 } 1476 1477 if (false) postStartTracing(); 1478 } 1479 1480 public void flipToNotifications() { 1481 if (mFlipSettingsViewAnim != null) mFlipSettingsViewAnim.cancel(); 1482 if (mScrollViewAnim != null) mScrollViewAnim.cancel(); 1483 if (mSettingsButtonAnim != null) mSettingsButtonAnim.cancel(); 1484 if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel(); 1485 if (mClearButtonAnim != null) mClearButtonAnim.cancel(); 1486 1487 mScrollView.setVisibility(View.VISIBLE); 1488 mScrollViewAnim = start( 1489 startDelay(FLIP_DURATION_OUT, 1490 interpolator(mDecelerateInterpolator, 1491 ObjectAnimator.ofFloat(mScrollView, View.SCALE_X, 0f, 1f) 1492 .setDuration(FLIP_DURATION_IN) 1493 ))); 1494 mFlipSettingsViewAnim = start( 1495 setVisibilityWhenDone( 1496 interpolator(mAccelerateInterpolator, 1497 ObjectAnimator.ofFloat(mFlipSettingsView, View.SCALE_X, 1f, 0f) 1498 ) 1499 .setDuration(FLIP_DURATION_OUT), 1500 mFlipSettingsView, View.INVISIBLE)); 1501 mNotificationButtonAnim = start( 1502 setVisibilityWhenDone( 1503 ObjectAnimator.ofFloat(mNotificationButton, View.ALPHA, 0f) 1504 .setDuration(FLIP_DURATION), 1505 mNotificationButton, View.INVISIBLE)); 1506 mSettingsButton.setVisibility(View.VISIBLE); 1507 mSettingsButtonAnim = start( 1508 ObjectAnimator.ofFloat(mSettingsButton, View.ALPHA, 1f) 1509 .setDuration(FLIP_DURATION)); 1510 mClearButton.setVisibility(View.VISIBLE); 1511 mClearButton.setAlpha(0f); 1512 setAreThereNotifications(); // this will show/hide the button as necessary 1513 mNotificationPanel.postDelayed(new Runnable() { 1514 public void run() { 1515 updateCarrierLabelVisibility(false); 1516 } 1517 }, FLIP_DURATION - 150); 1518 } 1519 1520 @Override 1521 public void animateExpandSettingsPanel() { 1522 if (SPEW) Log.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible); 1523 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1524 return; 1525 } 1526 1527 // Settings are not available in setup 1528 if (!mUserSetup) return; 1529 1530 if (mHasFlipSettings) { 1531 mNotificationPanel.expand(); 1532 if (mFlipSettingsView.getVisibility() != View.VISIBLE) { 1533 flipToSettings(); 1534 } 1535 } else if (mSettingsPanel != null) { 1536 mSettingsPanel.expand(); 1537 } 1538 1539 if (false) postStartTracing(); 1540 } 1541 1542 public void switchToSettings() { 1543 // Settings are not available in setup 1544 if (!mUserSetup) return; 1545 1546 mFlipSettingsView.setScaleX(1f); 1547 mFlipSettingsView.setVisibility(View.VISIBLE); 1548 mSettingsButton.setVisibility(View.GONE); 1549 mScrollView.setVisibility(View.GONE); 1550 mScrollView.setScaleX(0f); 1551 mNotificationButton.setVisibility(View.VISIBLE); 1552 mNotificationButton.setAlpha(1f); 1553 mClearButton.setVisibility(View.GONE); 1554 } 1555 1556 public void flipToSettings() { 1557 // Settings are not available in setup 1558 if (!mUserSetup) return; 1559 1560 if (mFlipSettingsViewAnim != null) mFlipSettingsViewAnim.cancel(); 1561 if (mScrollViewAnim != null) mScrollViewAnim.cancel(); 1562 if (mSettingsButtonAnim != null) mSettingsButtonAnim.cancel(); 1563 if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel(); 1564 if (mClearButtonAnim != null) mClearButtonAnim.cancel(); 1565 1566 mFlipSettingsView.setVisibility(View.VISIBLE); 1567 mFlipSettingsView.setScaleX(0f); 1568 mFlipSettingsViewAnim = start( 1569 startDelay(FLIP_DURATION_OUT, 1570 interpolator(mDecelerateInterpolator, 1571 ObjectAnimator.ofFloat(mFlipSettingsView, View.SCALE_X, 0f, 1f) 1572 .setDuration(FLIP_DURATION_IN) 1573 ))); 1574 mScrollViewAnim = start( 1575 setVisibilityWhenDone( 1576 interpolator(mAccelerateInterpolator, 1577 ObjectAnimator.ofFloat(mScrollView, View.SCALE_X, 1f, 0f) 1578 ) 1579 .setDuration(FLIP_DURATION_OUT), 1580 mScrollView, View.INVISIBLE)); 1581 mSettingsButtonAnim = start( 1582 setVisibilityWhenDone( 1583 ObjectAnimator.ofFloat(mSettingsButton, View.ALPHA, 0f) 1584 .setDuration(FLIP_DURATION), 1585 mScrollView, View.INVISIBLE)); 1586 mNotificationButton.setVisibility(View.VISIBLE); 1587 mNotificationButtonAnim = start( 1588 ObjectAnimator.ofFloat(mNotificationButton, View.ALPHA, 1f) 1589 .setDuration(FLIP_DURATION)); 1590 mClearButtonAnim = start( 1591 setVisibilityWhenDone( 1592 ObjectAnimator.ofFloat(mClearButton, View.ALPHA, 0f) 1593 .setDuration(FLIP_DURATION), 1594 mClearButton, View.INVISIBLE)); 1595 mNotificationPanel.postDelayed(new Runnable() { 1596 public void run() { 1597 updateCarrierLabelVisibility(false); 1598 } 1599 }, FLIP_DURATION - 150); 1600 } 1601 1602 public void flipPanels() { 1603 if (mHasFlipSettings) { 1604 if (mFlipSettingsView.getVisibility() != View.VISIBLE) { 1605 flipToSettings(); 1606 } else { 1607 flipToNotifications(); 1608 } 1609 } 1610 } 1611 1612 public void animateCollapseQuickSettings() { 1613 mStatusBarView.collapseAllPanels(true); 1614 } 1615 1616 void makeExpandedInvisibleSoon() { 1617 mHandler.postDelayed(new Runnable() { public void run() { makeExpandedInvisible(); }}, 50); 1618 } 1619 1620 void makeExpandedInvisible() { 1621 if (SPEW) Log.d(TAG, "makeExpandedInvisible: mExpandedVisible=" + mExpandedVisible 1622 + " mExpandedVisible=" + mExpandedVisible); 1623 1624 if (!mExpandedVisible) { 1625 return; 1626 } 1627 1628 // Ensure the panel is fully collapsed (just in case; bug 6765842, 7260868) 1629 mStatusBarView.collapseAllPanels(/*animate=*/ false); 1630 1631 if (mHasFlipSettings) { 1632 // reset things to their proper state 1633 if (mFlipSettingsViewAnim != null) mFlipSettingsViewAnim.cancel(); 1634 if (mScrollViewAnim != null) mScrollViewAnim.cancel(); 1635 if (mSettingsButtonAnim != null) mSettingsButtonAnim.cancel(); 1636 if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel(); 1637 if (mClearButtonAnim != null) mClearButtonAnim.cancel(); 1638 1639 mScrollView.setScaleX(1f); 1640 mScrollView.setVisibility(View.VISIBLE); 1641 mSettingsButton.setAlpha(1f); 1642 mSettingsButton.setVisibility(View.VISIBLE); 1643 mNotificationPanel.setVisibility(View.GONE); 1644 mFlipSettingsView.setVisibility(View.GONE); 1645 mNotificationButton.setVisibility(View.GONE); 1646 setAreThereNotifications(); // show the clear button 1647 } 1648 1649 mExpandedVisible = false; 1650 mPile.setLayoutTransitionsEnabled(false); 1651 if (mNavigationBarView != null) 1652 mNavigationBarView.setSlippery(false); 1653 visibilityChanged(false); 1654 1655 // Shrink the window to the size of the status bar only 1656 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams(); 1657 lp.height = getStatusBarHeight(); 1658 lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 1659 lp.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; 1660 mWindowManager.updateViewLayout(mStatusBarWindow, lp); 1661 1662 if ((mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS) == 0) { 1663 setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in); 1664 } 1665 1666 // Close any "App info" popups that might have snuck on-screen 1667 dismissPopups(); 1668 1669 if (mPostCollapseCleanup != null) { 1670 mPostCollapseCleanup.run(); 1671 mPostCollapseCleanup = null; 1672 } 1673 1674 // Reschedule suspended auto-hide if necessary 1675 resumeAutohide(); 1676 } 1677 1678 /** 1679 * Enables or disables layers on the children of the notifications pile. 1680 * 1681 * When layers are enabled, this method attempts to enable layers for the minimal 1682 * number of children. Only children visible when the notification area is fully 1683 * expanded will receive a layer. The technique used in this method might cause 1684 * more children than necessary to get a layer (at most one extra child with the 1685 * current UI.) 1686 * 1687 * @param layerType {@link View#LAYER_TYPE_NONE} or {@link View#LAYER_TYPE_HARDWARE} 1688 */ 1689 private void setPileLayers(int layerType) { 1690 final int count = mPile.getChildCount(); 1691 1692 switch (layerType) { 1693 case View.LAYER_TYPE_NONE: 1694 for (int i = 0; i < count; i++) { 1695 mPile.getChildAt(i).setLayerType(layerType, null); 1696 } 1697 break; 1698 case View.LAYER_TYPE_HARDWARE: 1699 final int[] location = new int[2]; 1700 mNotificationPanel.getLocationInWindow(location); 1701 1702 final int left = location[0]; 1703 final int top = location[1]; 1704 final int right = left + mNotificationPanel.getWidth(); 1705 final int bottom = top + getExpandedViewMaxHeight(); 1706 1707 final Rect childBounds = new Rect(); 1708 1709 for (int i = 0; i < count; i++) { 1710 final View view = mPile.getChildAt(i); 1711 view.getLocationInWindow(location); 1712 1713 childBounds.set(location[0], location[1], 1714 location[0] + view.getWidth(), location[1] + view.getHeight()); 1715 1716 if (childBounds.intersects(left, top, right, bottom)) { 1717 view.setLayerType(layerType, null); 1718 } 1719 } 1720 1721 break; 1722 } 1723 } 1724 1725 public boolean isClinging() { 1726 return mCling != null && mCling.getVisibility() == View.VISIBLE; 1727 } 1728 1729 public void hideCling() { 1730 if (isClinging()) { 1731 mCling.animate().alpha(0f).setDuration(250).start(); 1732 mCling.setVisibility(View.GONE); 1733 mSuppressStatusBarDrags = false; 1734 } 1735 } 1736 1737 public void showCling() { 1738 // lazily inflate this to accommodate orientation change 1739 final ViewStub stub = (ViewStub) mStatusBarWindow.findViewById(R.id.status_bar_cling_stub); 1740 if (stub == null) { 1741 mClingShown = true; 1742 return; // no clings on this device 1743 } 1744 1745 mSuppressStatusBarDrags = true; 1746 1747 mHandler.postDelayed(new Runnable() { 1748 @Override 1749 public void run() { 1750 mCling = (ViewGroup) stub.inflate(); 1751 1752 mCling.setOnTouchListener(new View.OnTouchListener() { 1753 @Override 1754 public boolean onTouch(View v, MotionEvent event) { 1755 return true; // e eats everything 1756 }}); 1757 mCling.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() { 1758 @Override 1759 public void onClick(View v) { 1760 hideCling(); 1761 }}); 1762 1763 mCling.setAlpha(0f); 1764 mCling.setVisibility(View.VISIBLE); 1765 mCling.animate().alpha(1f); 1766 1767 mClingShown = true; 1768 SharedPreferences.Editor editor = Prefs.edit(mContext); 1769 editor.putBoolean(Prefs.SHOWN_QUICK_SETTINGS_HELP, true); 1770 editor.apply(); 1771 1772 makeExpandedVisible(); // enforce visibility in case the shade is still animating closed 1773 animateExpandNotificationsPanel(); 1774 1775 mSuppressStatusBarDrags = false; 1776 } 1777 }, 500); 1778 1779 animateExpandNotificationsPanel(); 1780 } 1781 1782 public boolean interceptTouchEvent(MotionEvent event) { 1783 if (DEBUG_GESTURES) { 1784 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) { 1785 EventLog.writeEvent(EventLogTags.SYSUI_STATUSBAR_TOUCH, 1786 event.getActionMasked(), (int) event.getX(), (int) event.getY(), mDisabled); 1787 } 1788 1789 } 1790 1791 if (SPEW) { 1792 Log.d(TAG, "Touch: rawY=" + event.getRawY() + " event=" + event + " mDisabled=" 1793 + mDisabled + " mTracking=" + mTracking); 1794 } else if (CHATTY) { 1795 if (event.getAction() != MotionEvent.ACTION_MOVE) { 1796 Log.d(TAG, String.format( 1797 "panel: %s at (%f, %f) mDisabled=0x%08x", 1798 MotionEvent.actionToString(event.getAction()), 1799 event.getRawX(), event.getRawY(), mDisabled)); 1800 } 1801 } 1802 1803 if (DEBUG_GESTURES) { 1804 mGestureRec.add(event); 1805 } 1806 1807 // Cling (first-run help) handling. 1808 // The cling is supposed to show the first time you drag, or even tap, the status bar. 1809 // It should show the notification panel, then fade in after half a second, giving you 1810 // an explanation of what just happened, as well as teach you how to access quick 1811 // settings (another drag). The user can dismiss the cling by clicking OK or by 1812 // dragging quick settings into view. 1813 final int act = event.getActionMasked(); 1814 if (mSuppressStatusBarDrags) { 1815 return true; 1816 } else if (act == MotionEvent.ACTION_UP && !mClingShown) { 1817 showCling(); 1818 } else { 1819 hideCling(); 1820 } 1821 1822 suspendAutohide(); 1823 return false; 1824 } 1825 1826 public GestureRecorder getGestureRecorder() { 1827 return mGestureRec; 1828 } 1829 1830 @Override // CommandQueue 1831 public void setNavigationIconHints(int hints) { 1832 if (hints == mNavigationIconHints) return; 1833 1834 mNavigationIconHints = hints; 1835 1836 if (mNavigationBarView != null) { 1837 mNavigationBarView.setNavigationIconHints(hints); 1838 } 1839 } 1840 1841 @Override // CommandQueue 1842 public void setSystemUiVisibility(int vis, int mask) { 1843 final int oldVal = mSystemUiVisibility; 1844 final int newVal = (oldVal&~mask) | (vis&mask); 1845 final int diff = newVal ^ oldVal; 1846 if (DEBUG) Log.d(TAG, String.format( 1847 "setSystemUiVisibility vis=%s mask=%s oldVal=%s newVal=%s diff=%s", 1848 Integer.toHexString(vis), Integer.toHexString(mask), 1849 Integer.toHexString(oldVal), Integer.toHexString(newVal), 1850 Integer.toHexString(diff))); 1851 if (diff != 0) { 1852 mSystemUiVisibility = newVal; 1853 1854 if (0 != (diff & View.SYSTEM_UI_FLAG_LOW_PROFILE)) { 1855 final boolean lightsOut = (0 != (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE)); 1856 if (lightsOut) { 1857 animateCollapsePanels(); 1858 if (mTicking) { 1859 haltTicker(); 1860 } 1861 } 1862 1863 if (mNavigationBarView != null) { 1864 mNavigationBarView.setLowProfile(lightsOut); 1865 } 1866 1867 setStatusBarLowProfile(lightsOut); 1868 } 1869 1870 boolean sbOverlayChanged = 0 != (diff & View.STATUS_BAR_OVERLAY); 1871 boolean nbOverlayChanged = 0 != (diff & View.NAVIGATION_BAR_OVERLAY); 1872 if (sbOverlayChanged || nbOverlayChanged) { 1873 boolean sbOverlay = 0 != (vis & View.STATUS_BAR_OVERLAY); 1874 boolean nbOverlay = 0 != (vis & View.NAVIGATION_BAR_OVERLAY); 1875 if (sbOverlayChanged) { 1876 setTransparent(mStatusBarView, sbOverlay); 1877 } 1878 if (nbOverlayChanged) { 1879 setTransparent(mNavigationBarView, nbOverlay); 1880 } 1881 if (sbOverlayChanged && sbOverlay || nbOverlayChanged && nbOverlay) { 1882 scheduleAutohide(); 1883 } else { 1884 cancelAutohide(); 1885 } 1886 } 1887 if (mNavigationBarView != null) { 1888 int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_ALLOW_OVERLAY; 1889 boolean oldVisible = (oldVal & flags) == flags; 1890 boolean newVisible = (newVal & flags) == flags; 1891 if (!oldVisible && newVisible) { 1892 mHideybarConfirmationDismissed = false; 1893 } 1894 setHideybarConfirmationVisible(newVisible); 1895 } 1896 notifyUiVisibilityChanged(mSystemUiVisibility); 1897 } 1898 } 1899 1900 private void dismissHideybarConfirmation() { 1901 if (mHideybarConfirmation != null) { 1902 mHideybarConfirmationDismissed = true; 1903 mHideybarConfirmation.cancel(); 1904 mHideybarConfirmation = null; 1905 } 1906 } 1907 1908 private void setHideybarConfirmationVisible(boolean visible) { 1909 if (DEBUG) Log.d(TAG, "setHideybarConfirmationVisible " + visible); 1910 if (visible && mHideybarConfirmation == null && !mHideybarConfirmationDismissed) { 1911 // create the confirmation toast bar 1912 int msg = R.string.hideybar_confirmation_message; 1913 mHideybarConfirmation = Toast.makeBar(mContext, msg, Toast.LENGTH_INFINITE) 1914 .setAction(com.android.internal.R.string.ok, mHideybarConfirmationAction); 1915 View v = mHideybarConfirmation.getView(); 1916 v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); 1917 boolean isGloballyConfirmed = Prefs.read(mContext) 1918 .getBoolean(Prefs.HIDEYBAR_CONFIRMED, false); 1919 if (isGloballyConfirmed) { 1920 // dismiss on outside touch if globally confirmed 1921 v.setOnTouchListener(mDismissHideybarConfirmationOnTouchOutside); 1922 } 1923 // position at the bottom like normal toasts, but use top gravity 1924 // to avoid jumping around when showing/hiding the nav bar 1925 v.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); 1926 int offsetY = mContext.getResources().getDimensionPixelSize( 1927 com.android.internal.R.dimen.toast_y_offset); 1928 mHideybarConfirmation.setGravity(Gravity.TOP, 1929 0, mCurrentDisplaySize.y - v.getMeasuredHeight() / 2 - offsetY); 1930 // show the confirmation 1931 mHideybarConfirmation.show(); 1932 } else if (!visible) { 1933 dismissHideybarConfirmation(); 1934 } 1935 } 1936 1937 @Override 1938 public void resumeAutohide() { 1939 if (mAutohideSuspended) { 1940 scheduleAutohide(); 1941 } 1942 } 1943 1944 @Override 1945 public void suspendAutohide() { 1946 mHandler.removeCallbacks(mAutohide); 1947 mAutohideSuspended = 0 != (mSystemUiVisibility & STATUS_OR_NAV_OVERLAY); 1948 } 1949 1950 private void cancelAutohide() { 1951 mAutohideSuspended = false; 1952 mHandler.removeCallbacks(mAutohide); 1953 } 1954 1955 private void scheduleAutohide() { 1956 cancelAutohide(); 1957 mHandler.postDelayed(mAutohide, AUTOHIDE_TIMEOUT_MS); 1958 } 1959 1960 private void checkUserAutohide(View v, MotionEvent event) { 1961 if ((mSystemUiVisibility & STATUS_OR_NAV_OVERLAY) != 0 // an overlay bar is revealed 1962 && event.getAction() == MotionEvent.ACTION_OUTSIDE // touch outside the source bar 1963 && event.getX() == 0 && event.getY() == 0 // a touch outside both bars 1964 ) { 1965 userAutohide(); 1966 } 1967 } 1968 1969 private void userAutohide() { 1970 cancelAutohide(); 1971 mHandler.postDelayed(mAutohide, 25); 1972 } 1973 1974 private void setTransparent(View view, boolean transparent) { 1975 float alpha = transparent ? TRANSPARENT_ALPHA : 1; 1976 if (DEBUG) Log.d(TAG, "Setting " + (view == mStatusBarView ? "status bar" : 1977 view == mNavigationBarView ? "navigation bar" : "view") + " alpha to " + alpha); 1978 view.setAlpha(alpha); 1979 } 1980 1981 private void setStatusBarLowProfile(boolean lightsOut) { 1982 if (mLightsOutAnimation == null) { 1983 final View notifications = mStatusBarView.findViewById(R.id.notification_icon_area); 1984 final View systemIcons = mStatusBarView.findViewById(R.id.statusIcons); 1985 final View signal = mStatusBarView.findViewById(R.id.signal_cluster); 1986 final View battery = mStatusBarView.findViewById(R.id.battery); 1987 final View clock = mStatusBarView.findViewById(R.id.clock); 1988 1989 final AnimatorSet lightsOutAnim = new AnimatorSet(); 1990 lightsOutAnim.playTogether( 1991 ObjectAnimator.ofFloat(notifications, View.ALPHA, 0), 1992 ObjectAnimator.ofFloat(systemIcons, View.ALPHA, 0), 1993 ObjectAnimator.ofFloat(signal, View.ALPHA, 0), 1994 ObjectAnimator.ofFloat(battery, View.ALPHA, 0.5f), 1995 ObjectAnimator.ofFloat(clock, View.ALPHA, 0.5f) 1996 ); 1997 lightsOutAnim.setDuration(750); 1998 1999 final AnimatorSet lightsOnAnim = new AnimatorSet(); 2000 lightsOnAnim.playTogether( 2001 ObjectAnimator.ofFloat(notifications, View.ALPHA, 1), 2002 ObjectAnimator.ofFloat(systemIcons, View.ALPHA, 1), 2003 ObjectAnimator.ofFloat(signal, View.ALPHA, 1), 2004 ObjectAnimator.ofFloat(battery, View.ALPHA, 1), 2005 ObjectAnimator.ofFloat(clock, View.ALPHA, 1) 2006 ); 2007 lightsOnAnim.setDuration(250); 2008 2009 mLightsOutAnimation = lightsOutAnim; 2010 mLightsOnAnimation = lightsOnAnim; 2011 } 2012 2013 mLightsOutAnimation.cancel(); 2014 mLightsOnAnimation.cancel(); 2015 2016 final Animator a = lightsOut ? mLightsOutAnimation : mLightsOnAnimation; 2017 a.start(); 2018 2019 setAreThereNotifications(); 2020 } 2021 2022 private boolean areLightsOn() { 2023 return 0 == (mSystemUiVisibility & View.SYSTEM_UI_FLAG_LOW_PROFILE); 2024 } 2025 2026 public void setLightsOn(boolean on) { 2027 Log.v(TAG, "setLightsOn(" + on + ")"); 2028 if (on) { 2029 setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE); 2030 } else { 2031 setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE, View.SYSTEM_UI_FLAG_LOW_PROFILE); 2032 } 2033 } 2034 2035 private void notifyUiVisibilityChanged(int vis) { 2036 try { 2037 mWindowManagerService.statusBarVisibilityChanged(vis); 2038 } catch (RemoteException ex) { 2039 } 2040 } 2041 2042 public void topAppWindowChanged(boolean showMenu) { 2043 if (DEBUG) { 2044 Log.d(TAG, (showMenu?"showing":"hiding") + " the MENU button"); 2045 } 2046 if (mNavigationBarView != null) { 2047 mNavigationBarView.setMenuVisibility(showMenu); 2048 } 2049 2050 // See above re: lights-out policy for legacy apps. 2051 if (showMenu) setLightsOn(true); 2052 } 2053 2054 @Override 2055 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { 2056 boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS) 2057 || ((vis & InputMethodService.IME_VISIBLE) != 0); 2058 2059 mCommandQueue.setNavigationIconHints( 2060 altBack ? (mNavigationIconHints | StatusBarManager.NAVIGATION_HINT_BACK_ALT) 2061 : (mNavigationIconHints & ~StatusBarManager.NAVIGATION_HINT_BACK_ALT)); 2062 if (mQS != null) mQS.setImeWindowStatus(vis > 0); 2063 } 2064 2065 @Override 2066 public void setHardKeyboardStatus(boolean available, boolean enabled) {} 2067 2068 @Override 2069 protected void tick(IBinder key, StatusBarNotification n, boolean firstTime) { 2070 // no ticking in lights-out mode 2071 if (!areLightsOn()) return; 2072 2073 // no ticking in Setup 2074 if (!isDeviceProvisioned()) return; 2075 2076 // not for you 2077 if (!notificationIsForCurrentUser(n)) return; 2078 2079 // Show the ticker if one is requested. Also don't do this 2080 // until status bar window is attached to the window manager, 2081 // because... well, what's the point otherwise? And trying to 2082 // run a ticker without being attached will crash! 2083 if (n.getNotification().tickerText != null && mStatusBarWindow.getWindowToken() != null) { 2084 if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS 2085 | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { 2086 mTicker.addEntry(n); 2087 } 2088 } 2089 } 2090 2091 private class MyTicker extends Ticker { 2092 MyTicker(Context context, View sb) { 2093 super(context, sb); 2094 } 2095 2096 @Override 2097 public void tickerStarting() { 2098 mTicking = true; 2099 mStatusBarContents.setVisibility(View.GONE); 2100 mTickerView.setVisibility(View.VISIBLE); 2101 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_up_in, null)); 2102 mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.push_up_out, null)); 2103 } 2104 2105 @Override 2106 public void tickerDone() { 2107 mStatusBarContents.setVisibility(View.VISIBLE); 2108 mTickerView.setVisibility(View.GONE); 2109 mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.push_down_in, null)); 2110 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_down_out, 2111 mTickingDoneListener)); 2112 } 2113 2114 public void tickerHalting() { 2115 mStatusBarContents.setVisibility(View.VISIBLE); 2116 mTickerView.setVisibility(View.GONE); 2117 mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.fade_in, null)); 2118 // we do not animate the ticker away at this point, just get rid of it (b/6992707) 2119 } 2120 } 2121 2122 Animation.AnimationListener mTickingDoneListener = new Animation.AnimationListener() {; 2123 public void onAnimationEnd(Animation animation) { 2124 mTicking = false; 2125 } 2126 public void onAnimationRepeat(Animation animation) { 2127 } 2128 public void onAnimationStart(Animation animation) { 2129 } 2130 }; 2131 2132 private Animation loadAnim(int id, Animation.AnimationListener listener) { 2133 Animation anim = AnimationUtils.loadAnimation(mContext, id); 2134 if (listener != null) { 2135 anim.setAnimationListener(listener); 2136 } 2137 return anim; 2138 } 2139 2140 public static String viewInfo(View v) { 2141 return "[(" + v.getLeft() + "," + v.getTop() + ")(" + v.getRight() + "," + v.getBottom() 2142 + ") " + v.getWidth() + "x" + v.getHeight() + "]"; 2143 } 2144 2145 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 2146 synchronized (mQueueLock) { 2147 pw.println("Current Status Bar state:"); 2148 pw.println(" mExpandedVisible=" + mExpandedVisible 2149 + ", mTrackingPosition=" + mTrackingPosition); 2150 pw.println(" mTicking=" + mTicking); 2151 pw.println(" mTracking=" + mTracking); 2152 pw.println(" mDisplayMetrics=" + mDisplayMetrics); 2153 pw.println(" mPile: " + viewInfo(mPile)); 2154 pw.println(" mTickerView: " + viewInfo(mTickerView)); 2155 pw.println(" mScrollView: " + viewInfo(mScrollView) 2156 + " scroll " + mScrollView.getScrollX() + "," + mScrollView.getScrollY()); 2157 } 2158 2159 pw.print(" mNavigationBarView="); 2160 if (mNavigationBarView == null) { 2161 pw.println("null"); 2162 } else { 2163 mNavigationBarView.dump(fd, pw, args); 2164 } 2165 2166 pw.println(" Panels: "); 2167 if (mNotificationPanel != null) { 2168 pw.println(" mNotificationPanel=" + 2169 mNotificationPanel + " params=" + mNotificationPanel.getLayoutParams().debug("")); 2170 pw.print (" "); 2171 mNotificationPanel.dump(fd, pw, args); 2172 } 2173 if (mSettingsPanel != null) { 2174 pw.println(" mSettingsPanel=" + 2175 mSettingsPanel + " params=" + mSettingsPanel.getLayoutParams().debug("")); 2176 pw.print (" "); 2177 mSettingsPanel.dump(fd, pw, args); 2178 } 2179 2180 if (DUMPTRUCK) { 2181 synchronized (mNotificationData) { 2182 int N = mNotificationData.size(); 2183 pw.println(" notification icons: " + N); 2184 for (int i=0; i<N; i++) { 2185 NotificationData.Entry e = mNotificationData.get(i); 2186 pw.println(" [" + i + "] key=" + e.key + " icon=" + e.icon); 2187 StatusBarNotification n = e.notification; 2188 pw.println(" pkg=" + n.getPackageName() + " id=" + n.getId() + " score=" + n.getScore()); 2189 pw.println(" notification=" + n.getNotification()); 2190 pw.println(" tickerText=\"" + n.getNotification().tickerText + "\""); 2191 } 2192 } 2193 2194 int N = mStatusIcons.getChildCount(); 2195 pw.println(" system icons: " + N); 2196 for (int i=0; i<N; i++) { 2197 StatusBarIconView ic = (StatusBarIconView) mStatusIcons.getChildAt(i); 2198 pw.println(" [" + i + "] icon=" + ic); 2199 } 2200 2201 if (false) { 2202 pw.println("see the logcat for a dump of the views we have created."); 2203 // must happen on ui thread 2204 mHandler.post(new Runnable() { 2205 public void run() { 2206 mStatusBarView.getLocationOnScreen(mAbsPos); 2207 Log.d(TAG, "mStatusBarView: ----- (" + mAbsPos[0] + "," + mAbsPos[1] 2208 + ") " + mStatusBarView.getWidth() + "x" 2209 + getStatusBarHeight()); 2210 mStatusBarView.debug(); 2211 } 2212 }); 2213 } 2214 } 2215 2216 if (DEBUG_GESTURES) { 2217 pw.print(" status bar gestures: "); 2218 mGestureRec.dump(fd, pw, args); 2219 } 2220 2221 mNetworkController.dump(fd, pw, args); 2222 } 2223 2224 @Override 2225 public void createAndAddWindows() { 2226 addStatusBarWindow(); 2227 } 2228 2229 private void addStatusBarWindow() { 2230 // Put up the view 2231 final int height = getStatusBarHeight(); 2232 2233 // Now that the status bar window encompasses the sliding panel and its 2234 // translucent backdrop, the entire thing is made TRANSLUCENT and is 2235 // hardware-accelerated. 2236 final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 2237 ViewGroup.LayoutParams.MATCH_PARENT, 2238 height, 2239 WindowManager.LayoutParams.TYPE_STATUS_BAR, 2240 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 2241 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING 2242 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 2243 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, 2244 PixelFormat.TRANSLUCENT); 2245 2246 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 2247 2248 lp.gravity = getStatusBarGravity(); 2249 lp.setTitle("StatusBar"); 2250 lp.packageName = mContext.getPackageName(); 2251 2252 makeStatusBarView(); 2253 mWindowManager.addView(mStatusBarWindow, lp); 2254 } 2255 2256 void setNotificationIconVisibility(boolean visible, int anim) { 2257 int old = mNotificationIcons.getVisibility(); 2258 int v = visible ? View.VISIBLE : View.INVISIBLE; 2259 if (old != v) { 2260 mNotificationIcons.setVisibility(v); 2261 mNotificationIcons.startAnimation(loadAnim(anim, null)); 2262 } 2263 } 2264 2265 void updateExpandedInvisiblePosition() { 2266 mTrackingPosition = -mDisplayMetrics.heightPixels; 2267 } 2268 2269 static final float saturate(float a) { 2270 return a < 0f ? 0f : (a > 1f ? 1f : a); 2271 } 2272 2273 @Override 2274 protected int getExpandedViewMaxHeight() { 2275 return mDisplayMetrics.heightPixels - mNotificationPanelMarginBottomPx; 2276 } 2277 2278 @Override 2279 public void updateExpandedViewPos(int thingy) { 2280 if (DEBUG) Log.v(TAG, "updateExpandedViewPos"); 2281 2282 // on larger devices, the notification panel is propped open a bit 2283 mNotificationPanel.setMinimumHeight( 2284 (int)(mNotificationPanelMinHeightFrac * mCurrentDisplaySize.y)); 2285 2286 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mNotificationPanel.getLayoutParams(); 2287 lp.gravity = mNotificationPanelGravity; 2288 lp.setMarginStart(mNotificationPanelMarginPx); 2289 mNotificationPanel.setLayoutParams(lp); 2290 2291 if (mSettingsPanel != null) { 2292 lp = (FrameLayout.LayoutParams) mSettingsPanel.getLayoutParams(); 2293 lp.gravity = mSettingsPanelGravity; 2294 lp.setMarginEnd(mNotificationPanelMarginPx); 2295 mSettingsPanel.setLayoutParams(lp); 2296 } 2297 2298 updateCarrierLabelVisibility(false); 2299 } 2300 2301 // called by makeStatusbar and also by PhoneStatusBarView 2302 void updateDisplaySize() { 2303 mDisplay.getMetrics(mDisplayMetrics); 2304 if (DEBUG_GESTURES) { 2305 mGestureRec.tag("display", 2306 String.format("%dx%d", mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels)); 2307 } 2308 } 2309 2310 private View.OnClickListener mClearButtonListener = new View.OnClickListener() { 2311 public void onClick(View v) { 2312 synchronized (mNotificationData) { 2313 // animate-swipe all dismissable notifications, then animate the shade closed 2314 int numChildren = mPile.getChildCount(); 2315 2316 int scrollTop = mScrollView.getScrollY(); 2317 int scrollBottom = scrollTop + mScrollView.getHeight(); 2318 final ArrayList<View> snapshot = new ArrayList<View>(numChildren); 2319 for (int i=0; i<numChildren; i++) { 2320 final View child = mPile.getChildAt(i); 2321 if (mPile.canChildBeDismissed(child) && child.getBottom() > scrollTop && 2322 child.getTop() < scrollBottom) { 2323 snapshot.add(child); 2324 } 2325 } 2326 if (snapshot.isEmpty()) { 2327 animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); 2328 return; 2329 } 2330 new Thread(new Runnable() { 2331 @Override 2332 public void run() { 2333 // Decrease the delay for every row we animate to give the sense of 2334 // accelerating the swipes 2335 final int ROW_DELAY_DECREMENT = 10; 2336 int currentDelay = 140; 2337 int totalDelay = 0; 2338 2339 // Set the shade-animating state to avoid doing other work during 2340 // all of these animations. In particular, avoid layout and 2341 // redrawing when collapsing the shade. 2342 mPile.setViewRemoval(false); 2343 2344 mPostCollapseCleanup = new Runnable() { 2345 @Override 2346 public void run() { 2347 if (DEBUG) { 2348 Log.v(TAG, "running post-collapse cleanup"); 2349 } 2350 try { 2351 mPile.setViewRemoval(true); 2352 mBarService.onClearAllNotifications(); 2353 } catch (Exception ex) { } 2354 } 2355 }; 2356 2357 View sampleView = snapshot.get(0); 2358 int width = sampleView.getWidth(); 2359 final int dir = sampleView.isLayoutRtl() ? -1 : +1; 2360 final int velocity = dir * width * 8; // 1000/8 = 125 ms duration 2361 for (final View _v : snapshot) { 2362 mHandler.postDelayed(new Runnable() { 2363 @Override 2364 public void run() { 2365 mPile.dismissRowAnimated(_v, velocity); 2366 } 2367 }, totalDelay); 2368 currentDelay = Math.max(50, currentDelay - ROW_DELAY_DECREMENT); 2369 totalDelay += currentDelay; 2370 } 2371 // Delay the collapse animation until after all swipe animations have 2372 // finished. Provide some buffer because there may be some extra delay 2373 // before actually starting each swipe animation. Ideally, we'd 2374 // synchronize the end of those animations with the start of the collaps 2375 // exactly. 2376 mHandler.postDelayed(new Runnable() { 2377 @Override 2378 public void run() { 2379 animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); 2380 } 2381 }, totalDelay + 225); 2382 } 2383 }).start(); 2384 } 2385 } 2386 }; 2387 2388 public void startActivityDismissingKeyguard(Intent intent, boolean onlyProvisioned) { 2389 if (onlyProvisioned && !isDeviceProvisioned()) return; 2390 try { 2391 // Dismiss the lock screen when Settings starts. 2392 ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity(); 2393 } catch (RemoteException e) { 2394 } 2395 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 2396 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT)); 2397 animateCollapsePanels(); 2398 } 2399 2400 private View.OnClickListener mSettingsButtonListener = new View.OnClickListener() { 2401 public void onClick(View v) { 2402 if (mHasSettingsPanel) { 2403 animateExpandSettingsPanel(); 2404 } else { 2405 startActivityDismissingKeyguard( 2406 new Intent(android.provider.Settings.ACTION_SETTINGS), true); 2407 } 2408 } 2409 }; 2410 2411 private View.OnClickListener mClockClickListener = new View.OnClickListener() { 2412 public void onClick(View v) { 2413 startActivityDismissingKeyguard( 2414 new Intent(Intent.ACTION_QUICK_CLOCK), true); // have fun, everyone 2415 } 2416 }; 2417 2418 private View.OnClickListener mNotificationButtonListener = new View.OnClickListener() { 2419 public void onClick(View v) { 2420 animateExpandNotificationsPanel(); 2421 } 2422 }; 2423 2424 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 2425 public void onReceive(Context context, Intent intent) { 2426 if (DEBUG) Log.v(TAG, "onReceive: " + intent); 2427 String action = intent.getAction(); 2428 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { 2429 int flags = CommandQueue.FLAG_EXCLUDE_NONE; 2430 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { 2431 String reason = intent.getStringExtra("reason"); 2432 if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) { 2433 flags |= CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL; 2434 } 2435 } 2436 animateCollapsePanels(flags); 2437 } 2438 else if (Intent.ACTION_SCREEN_OFF.equals(action)) { 2439 // no waiting! 2440 makeExpandedInvisible(); 2441 notifyNavigationBarScreenOn(false); 2442 } 2443 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { 2444 if (DEBUG) { 2445 Log.v(TAG, "configuration changed: " + mContext.getResources().getConfiguration()); 2446 } 2447 mDisplay.getSize(mCurrentDisplaySize); 2448 2449 updateResources(); 2450 repositionNavigationBar(); 2451 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 2452 updateShowSearchHoldoff(); 2453 } 2454 else if (Intent.ACTION_SCREEN_ON.equals(action)) { 2455 // work around problem where mDisplay.getRotation() is not stable while screen is off (bug 7086018) 2456 repositionNavigationBar(); 2457 notifyNavigationBarScreenOn(true); 2458 } 2459 } 2460 }; 2461 2462 @Override 2463 public void userSwitched(int newUserId) { 2464 if (MULTIUSER_DEBUG) mNotificationPanelDebugText.setText("USER " + newUserId); 2465 animateCollapsePanels(); 2466 updateNotificationIcons(); 2467 resetUserSetupObserver(); 2468 } 2469 2470 private void resetUserSetupObserver() { 2471 mContext.getContentResolver().unregisterContentObserver(mUserSetupObserver); 2472 mUserSetupObserver.onChange(false); 2473 mContext.getContentResolver().registerContentObserver( 2474 Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE), true, 2475 mUserSetupObserver, 2476 mCurrentUserId); 2477 } 2478 2479 private void setHeadsUpVisibility(boolean vis) { 2480 if (!ENABLE_HEADS_UP) return; 2481 if (DEBUG) Log.v(TAG, (vis ? "showing" : "hiding") + " heads up window"); 2482 mHeadsUpNotificationView.setVisibility(vis ? View.VISIBLE : View.GONE); 2483 } 2484 2485 public void onHeadsUpDismissed() { 2486 if (mInterruptingNotificationEntry == null) return; 2487 2488 try { 2489 mBarService.onNotificationClear( 2490 mInterruptingNotificationEntry.notification.getPackageName(), 2491 mInterruptingNotificationEntry.notification.getTag(), 2492 mInterruptingNotificationEntry.notification.getId()); 2493 } catch (android.os.RemoteException ex) { 2494 // oh well 2495 } 2496 } 2497 2498 /** 2499 * Reload some of our resources when the configuration changes. 2500 * 2501 * We don't reload everything when the configuration changes -- we probably 2502 * should, but getting that smooth is tough. Someday we'll fix that. In the 2503 * meantime, just update the things that we know change. 2504 */ 2505 void updateResources() { 2506 final Context context = mContext; 2507 final Resources res = context.getResources(); 2508 2509 if (mClearButton instanceof TextView) { 2510 ((TextView)mClearButton).setText(context.getText(R.string.status_bar_clear_all_button)); 2511 } 2512 2513 // Update the QuickSettings container 2514 if (mQS != null) mQS.updateResources(); 2515 2516 loadDimens(); 2517 } 2518 2519 protected void loadDimens() { 2520 final Resources res = mContext.getResources(); 2521 2522 mNaturalBarHeight = res.getDimensionPixelSize( 2523 com.android.internal.R.dimen.status_bar_height); 2524 2525 int newIconSize = res.getDimensionPixelSize( 2526 com.android.internal.R.dimen.status_bar_icon_size); 2527 int newIconHPadding = res.getDimensionPixelSize( 2528 R.dimen.status_bar_icon_padding); 2529 2530 if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) { 2531// Log.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding); 2532 mIconHPadding = newIconHPadding; 2533 mIconSize = newIconSize; 2534 //reloadAllNotificationIcons(); // reload the tray 2535 } 2536 2537 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore); 2538 2539 mSelfExpandVelocityPx = res.getDimension(R.dimen.self_expand_velocity); 2540 mSelfCollapseVelocityPx = res.getDimension(R.dimen.self_collapse_velocity); 2541 mFlingExpandMinVelocityPx = res.getDimension(R.dimen.fling_expand_min_velocity); 2542 mFlingCollapseMinVelocityPx = res.getDimension(R.dimen.fling_collapse_min_velocity); 2543 2544 mCollapseMinDisplayFraction = res.getFraction(R.dimen.collapse_min_display_fraction, 1, 1); 2545 mExpandMinDisplayFraction = res.getFraction(R.dimen.expand_min_display_fraction, 1, 1); 2546 2547 mExpandAccelPx = res.getDimension(R.dimen.expand_accel); 2548 mCollapseAccelPx = res.getDimension(R.dimen.collapse_accel); 2549 2550 mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity); 2551 2552 mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity); 2553 2554 mNotificationPanelMarginBottomPx 2555 = (int) res.getDimension(R.dimen.notification_panel_margin_bottom); 2556 mNotificationPanelMarginPx 2557 = (int) res.getDimension(R.dimen.notification_panel_margin_left); 2558 mNotificationPanelGravity = res.getInteger(R.integer.notification_panel_layout_gravity); 2559 if (mNotificationPanelGravity <= 0) { 2560 mNotificationPanelGravity = Gravity.START | Gravity.TOP; 2561 } 2562 mSettingsPanelGravity = res.getInteger(R.integer.settings_panel_layout_gravity); 2563 Log.d(TAG, "mSettingsPanelGravity = " + mSettingsPanelGravity); 2564 if (mSettingsPanelGravity <= 0) { 2565 mSettingsPanelGravity = Gravity.END | Gravity.TOP; 2566 } 2567 2568 mCarrierLabelHeight = res.getDimensionPixelSize(R.dimen.carrier_label_height); 2569 mNotificationHeaderHeight = res.getDimensionPixelSize(R.dimen.notification_panel_header_height); 2570 2571 mNotificationPanelMinHeightFrac = res.getFraction(R.dimen.notification_panel_min_height_frac, 1, 1); 2572 if (mNotificationPanelMinHeightFrac < 0f || mNotificationPanelMinHeightFrac > 1f) { 2573 mNotificationPanelMinHeightFrac = 0f; 2574 } 2575 2576 mHeadsUpNotificationDecay = res.getInteger(R.integer.heads_up_notification_decay); 2577 mRowHeight = res.getDimensionPixelSize(R.dimen.notification_row_min_height); 2578 2579 if (false) Log.v(TAG, "updateResources"); 2580 } 2581 2582 // 2583 // tracing 2584 // 2585 2586 void postStartTracing() { 2587 mHandler.postDelayed(mStartTracing, 3000); 2588 } 2589 2590 void vibrate() { 2591 android.os.Vibrator vib = (android.os.Vibrator)mContext.getSystemService( 2592 Context.VIBRATOR_SERVICE); 2593 vib.vibrate(250); 2594 } 2595 2596 Runnable mStartTracing = new Runnable() { 2597 public void run() { 2598 vibrate(); 2599 SystemClock.sleep(250); 2600 Log.d(TAG, "startTracing"); 2601 android.os.Debug.startMethodTracing("/data/statusbar-traces/trace"); 2602 mHandler.postDelayed(mStopTracing, 10000); 2603 } 2604 }; 2605 2606 Runnable mStopTracing = new Runnable() { 2607 public void run() { 2608 android.os.Debug.stopMethodTracing(); 2609 Log.d(TAG, "stopTracing"); 2610 vibrate(); 2611 } 2612 }; 2613 2614 @Override 2615 protected void haltTicker() { 2616 mTicker.halt(); 2617 } 2618 2619 @Override 2620 protected boolean shouldDisableNavbarGestures() { 2621 return !isDeviceProvisioned() 2622 || mExpandedVisible 2623 || (mDisabled & StatusBarManager.DISABLE_SEARCH) != 0; 2624 } 2625 2626 private static class FastColorDrawable extends Drawable { 2627 private final int mColor; 2628 2629 public FastColorDrawable(int color) { 2630 mColor = 0xff000000 | color; 2631 } 2632 2633 @Override 2634 public void draw(Canvas canvas) { 2635 canvas.drawColor(mColor, PorterDuff.Mode.SRC); 2636 } 2637 2638 @Override 2639 public void setAlpha(int alpha) { 2640 } 2641 2642 @Override 2643 public void setColorFilter(ColorFilter cf) { 2644 } 2645 2646 @Override 2647 public int getOpacity() { 2648 return PixelFormat.OPAQUE; 2649 } 2650 2651 @Override 2652 public void setBounds(int left, int top, int right, int bottom) { 2653 } 2654 2655 @Override 2656 public void setBounds(Rect bounds) { 2657 } 2658 } 2659 2660 @Override 2661 public void destroy() { 2662 super.destroy(); 2663 if (mStatusBarWindow != null) { 2664 mWindowManager.removeViewImmediate(mStatusBarWindow); 2665 } 2666 if (mNavigationBarView != null) { 2667 mWindowManager.removeViewImmediate(mNavigationBarView); 2668 } 2669 mContext.unregisterReceiver(mBroadcastReceiver); 2670 } 2671} 2672