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