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