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