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