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