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