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