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