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