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