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