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