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