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