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