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