PhoneStatusBar.java revision 7c3e39de22c68e69c4924b339132f8e3bf3f96af
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.app.Service; 20import android.app.ActivityManagerNative; 21import android.app.Dialog; 22import android.app.Notification; 23import android.app.PendingIntent; 24import android.app.Service; 25import android.app.StatusBarManager; 26import android.content.BroadcastReceiver; 27import android.content.Context; 28import android.content.Intent; 29import android.content.IntentFilter; 30import android.content.res.Resources; 31import android.content.res.Configuration; 32import android.graphics.PixelFormat; 33import android.graphics.Rect; 34import android.graphics.drawable.Drawable; 35import android.graphics.drawable.LayerDrawable; 36import android.net.Uri; 37import android.os.Bundle; 38import android.os.IBinder; 39import android.os.RemoteException; 40import android.os.Handler; 41import android.os.Message; 42import android.os.ServiceManager; 43import android.os.SystemClock; 44import android.text.TextUtils; 45import android.util.Slog; 46import android.util.Log; 47import android.view.Display; 48import android.view.Gravity; 49import android.view.IWindowManager; 50import android.view.KeyEvent; 51import android.view.LayoutInflater; 52import android.view.MotionEvent; 53import android.view.Surface; 54import android.view.VelocityTracker; 55import android.view.View; 56import android.view.ViewGroup; 57import android.view.ViewGroup.LayoutParams; 58import android.view.Window; 59import android.view.WindowManager; 60import android.view.WindowManagerImpl; 61import android.view.animation.Animation; 62import android.view.animation.AnimationUtils; 63import android.widget.ImageView; 64import android.widget.LinearLayout; 65import android.widget.RemoteViews; 66import android.widget.ScrollView; 67import android.widget.TextView; 68import android.widget.FrameLayout; 69 70import java.io.FileDescriptor; 71import java.io.PrintWriter; 72import java.util.ArrayList; 73import java.util.HashMap; 74import java.util.Set; 75 76import com.android.internal.statusbar.StatusBarIcon; 77import com.android.internal.statusbar.StatusBarIconList; 78import com.android.internal.statusbar.StatusBarNotification; 79 80import com.android.systemui.R; 81import com.android.systemui.recent.RecentsPanelView; 82import com.android.systemui.statusbar.NotificationData; 83import com.android.systemui.statusbar.StatusBar; 84import com.android.systemui.statusbar.StatusBarIconView; 85import com.android.systemui.statusbar.policy.DateView; 86import com.android.systemui.statusbar.policy.BatteryController; 87import com.android.systemui.statusbar.policy.LocationController; 88import com.android.systemui.statusbar.policy.NetworkController; 89 90public class PhoneStatusBar extends StatusBar { 91 static final String TAG = "PhoneStatusBar"; 92 static final boolean SPEW = false; 93 public static final boolean DEBUG = false; 94 95 public static final String ACTION_STATUSBAR_START 96 = "com.android.internal.policy.statusbar.START"; 97 98 static final int EXPANDED_LEAVE_ALONE = -10000; 99 static final int EXPANDED_FULL_OPEN = -10001; 100 101 private static final int MSG_ANIMATE = 1000; 102 private static final int MSG_ANIMATE_REVEAL = 1001; 103 private static final int MSG_SHOW_INTRUDER = 1002; 104 private static final int MSG_HIDE_INTRUDER = 1003; 105 private static final int MSG_OPEN_RECENTS_PANEL = 1020; 106 private static final int MSG_CLOSE_RECENTS_PANEL = 1021; 107 108 // will likely move to a resource or other tunable param at some point 109 private static final int INTRUDER_ALERT_DECAY_MS = 10000; 110 111 PhoneStatusBarPolicy mIconPolicy; 112 113 // These are no longer handled by the policy, because we need custom strategies for them 114 BatteryController mBatteryController; 115 LocationController mLocationController; 116 NetworkController mNetworkController; 117 118 int mNaturalBarHeight = -1; 119 int mIconSize = -1; 120 int mIconHPadding = -1; 121 Display mDisplay; 122 123 IWindowManager mWindowManager; 124 125 PhoneStatusBarView mStatusBarView; 126 int mPixelFormat; 127 H mHandler = new H(); 128 Object mQueueLock = new Object(); 129 130 // icons 131 LinearLayout mIcons; 132 IconMerger mNotificationIcons; 133 LinearLayout mStatusIcons; 134 135 // expanded notifications 136 Dialog mExpandedDialog; 137 ExpandedView mExpandedView; 138 WindowManager.LayoutParams mExpandedParams; 139 ScrollView mScrollView; 140 View mNotificationLinearLayout; 141 View mExpandedContents; 142 // top bar 143 TextView mNoNotificationsTitle; 144 TextView mClearButton; 145 // drag bar 146 CloseDragHandle mCloseView; 147 148 // all notifications 149 NotificationData mNotificationData = new NotificationData(); 150 ViewGroup mPile; 151 152 // position 153 int[] mPositionTmp = new int[2]; 154 boolean mExpanded; 155 boolean mExpandedVisible; 156 157 // the date view 158 DateView mDateView; 159 160 // for immersive activities 161 private View mIntruderAlertView; 162 163 // on-screen navigation buttons 164 private NavigationBarView mNavigationBarView = null; 165 166 // the tracker view 167 TrackingView mTrackingView; 168 WindowManager.LayoutParams mTrackingParams; 169 int mTrackingPosition; // the position of the top of the tracking view. 170 private boolean mPanelSlightlyVisible; 171 172 // ticker 173 private Ticker mTicker; 174 private View mTickerView; 175 private boolean mTicking; 176 177 // Recent applications 178 private RecentsPanelView mRecentsPanel; 179 180 // Tracking finger for opening/closing. 181 int mEdgeBorder; // corresponds to R.dimen.status_bar_edge_ignore 182 boolean mTracking; 183 VelocityTracker mVelocityTracker; 184 185 static final int ANIM_FRAME_DURATION = (1000/60); 186 187 boolean mAnimating; 188 long mCurAnimationTime; 189 float mDisplayHeight; 190 float mAnimY; 191 float mAnimVel; 192 float mAnimAccel; 193 long mAnimLastTime; 194 boolean mAnimatingReveal = false; 195 int mViewDelta; 196 int[] mAbsPos = new int[2]; 197 198 // for disabling the status bar 199 int mDisabled = 0; 200 201 // tracking calls to View.setSystemUiVisibility() 202 int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE; 203 204 private class ExpandedDialog extends Dialog { 205 ExpandedDialog(Context context) { 206 super(context, com.android.internal.R.style.Theme_Light_NoTitleBar); 207 } 208 209 @Override 210 public boolean dispatchKeyEvent(KeyEvent event) { 211 boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 212 switch (event.getKeyCode()) { 213 case KeyEvent.KEYCODE_BACK: 214 if (!down) { 215 animateCollapse(); 216 } 217 return true; 218 } 219 return super.dispatchKeyEvent(event); 220 } 221 } 222 223 @Override 224 public void start() { 225 mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) 226 .getDefaultDisplay(); 227 228 mWindowManager = IWindowManager.Stub.asInterface( 229 ServiceManager.getService(Context.WINDOW_SERVICE)); 230 231 super.start(); 232 233 addNavigationBar(); 234 235 //addIntruderView(); 236 237 // Lastly, call to the icon policy to install/update all the icons. 238 mIconPolicy = new PhoneStatusBarPolicy(mContext); 239 } 240 241 // ================================================================================ 242 // Constructing the view 243 // ================================================================================ 244 protected View makeStatusBarView() { 245 final Context context = mContext; 246 247 Resources res = context.getResources(); 248 249 loadDimens(); 250 251 ExpandedView expanded = (ExpandedView)View.inflate(context, 252 R.layout.status_bar_expanded, null); 253 expanded.mService = this; 254 255 mIntruderAlertView = View.inflate(context, R.layout.intruder_alert, null); 256 mIntruderAlertView.setVisibility(View.GONE); 257 mIntruderAlertView.setClickable(true); 258 259 PhoneStatusBarView sb = (PhoneStatusBarView)View.inflate(context, 260 R.layout.status_bar, null); 261 sb.mService = this; 262 mStatusBarView = sb; 263 264 try { 265 boolean showNav = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); 266 if (showNav) { 267 mNavigationBarView = 268 (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null); 269 270 sb.setOnSystemUiVisibilityChangeListener( 271 new View.OnSystemUiVisibilityChangeListener() { 272 @Override 273 public void onSystemUiVisibilityChange(int visibility) { 274 if (DEBUG) { 275 Slog.d(TAG, "systemUi: " + visibility); 276 } 277 boolean hide = (0 != (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)); 278 mNavigationBarView.setHidden(hide); 279 } 280 }); 281 } 282 } catch (Resources.NotFoundException ex) { 283 // no nav bar for you 284 } 285 286 // figure out which pixel-format to use for the status bar. 287 mPixelFormat = PixelFormat.TRANSLUCENT; 288 Drawable bg = sb.getBackground(); 289 if (bg != null) { 290 mPixelFormat = bg.getOpacity(); 291 } 292 293 mStatusIcons = (LinearLayout)sb.findViewById(R.id.statusIcons); 294 mNotificationIcons = (IconMerger)sb.findViewById(R.id.notificationIcons); 295 mIcons = (LinearLayout)sb.findViewById(R.id.icons); 296 mTickerView = sb.findViewById(R.id.ticker); 297 mDateView = (DateView)sb.findViewById(R.id.date); 298 299 mExpandedDialog = new ExpandedDialog(context); 300 mExpandedView = expanded; 301 mExpandedContents = expanded.findViewById(R.id.notificationLinearLayout); 302 mPile = (ViewGroup)expanded.findViewById(R.id.latestItems); 303 mNoNotificationsTitle = (TextView)expanded.findViewById(R.id.noNotificationsTitle); 304 mClearButton = (TextView)expanded.findViewById(R.id.clear_all_button); 305 mClearButton.setOnClickListener(mClearButtonListener); 306 mScrollView = (ScrollView)expanded.findViewById(R.id.scroll); 307 mNotificationLinearLayout = expanded.findViewById(R.id.notificationLinearLayout); 308 309 mTicker = new MyTicker(context, sb); 310 311 TickerView tickerView = (TickerView)sb.findViewById(R.id.tickerText); 312 tickerView.mTicker = mTicker; 313 314 mTrackingView = (TrackingView)View.inflate(context, R.layout.status_bar_tracking, null); 315 mTrackingView.mService = this; 316 mCloseView = (CloseDragHandle)mTrackingView.findViewById(R.id.close); 317 mCloseView.mService = this; 318 319 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore); 320 321 // set the inital view visibility 322 setAreThereNotifications(); 323 mDateView.setVisibility(View.INVISIBLE); 324 325 // Other icons 326 mLocationController = new LocationController(mContext); // will post a notification 327 mBatteryController = new BatteryController(mContext); 328 mBatteryController.addIconView((ImageView)sb.findViewById(R.id.battery)); 329 mNetworkController = new NetworkController(mContext); 330 final ImageView comboRSSI = 331 (ImageView)sb.findViewById(R.id.network_signal); 332 if (comboRSSI != null) { 333 mNetworkController.addCombinedSignalIconView(comboRSSI); 334 } 335 final ImageView mobileRSSI = 336 (ImageView)sb.findViewById(R.id.mobile_signal); 337 if (mobileRSSI != null) { 338 mNetworkController.addPhoneSignalIconView(mobileRSSI); 339 } 340 final ImageView wifiRSSI = 341 (ImageView)sb.findViewById(R.id.wifi_signal); 342 if (wifiRSSI != null) { 343 mNetworkController.addWifiIconView(wifiRSSI); 344 } 345 mNetworkController.addDataTypeIconView( 346 (ImageView)sb.findViewById(R.id.network_type)); 347 mNetworkController.addDataDirectionOverlayIconView( 348 (ImageView)sb.findViewById(R.id.network_direction)); 349 mNetworkController.setStackedMode(true); 350 351 // Recents Panel 352 updateRecentsPanel(); 353 354 // receive broadcasts 355 IntentFilter filter = new IntentFilter(); 356 filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); 357 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 358 filter.addAction(Intent.ACTION_SCREEN_OFF); 359 context.registerReceiver(mBroadcastReceiver, filter); 360 361 return sb; 362 } 363 364 protected WindowManager.LayoutParams getRecentsLayoutParams(LayoutParams layoutParams) { 365 boolean translucent = false; 366 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 367 layoutParams.width, 368 layoutParams.height, 369 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, 370 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 371 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 372 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 373 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 374 (translucent ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT)); 375 lp.gravity = Gravity.BOTTOM | Gravity.LEFT; 376 lp.setTitle("RecentsPanel"); 377 lp.windowAnimations = R.style.Animation_RecentPanel; 378 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 379 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; 380 return lp; 381 } 382 383 protected void updateRecentsPanel() { 384 // Recents Panel 385 boolean visible = false; 386 if (mRecentsPanel != null) { 387 visible = mRecentsPanel.getVisibility() == View.VISIBLE; 388 WindowManagerImpl.getDefault().removeView(mRecentsPanel); 389 } 390 391 // Provide RecentsPanelView with a temporary parent to allow layout params to work. 392 LinearLayout tmpRoot = new LinearLayout(mContext); 393 mRecentsPanel = (RecentsPanelView) LayoutInflater.from(mContext).inflate( 394 R.layout.status_bar_recent_panel, tmpRoot, false); 395 396 mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL, 397 mRecentsPanel)); 398 mRecentsPanel.setVisibility(View.GONE); 399 WindowManager.LayoutParams lp = getRecentsLayoutParams(mRecentsPanel.getLayoutParams()); 400 401 WindowManagerImpl.getDefault().addView(mRecentsPanel, lp); 402 mRecentsPanel.setBar(this); 403 if (visible) { 404 // need to set visibility to View.GONE earlier since that 405 // triggers refreshing application list 406 mRecentsPanel.setVisibility(View.VISIBLE); 407 mRecentsPanel.show(true, false); 408 } 409 410 } 411 412 protected int getStatusBarGravity() { 413 return Gravity.TOP | Gravity.FILL_HORIZONTAL; 414 } 415 416 public int getStatusBarHeight() { 417 final Resources res = mContext.getResources(); 418 return res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); 419 } 420 421 private View.OnClickListener mRecentsClickListener = new View.OnClickListener() { 422 public void onClick(View v) { 423 toggleRecentApps(); 424 } 425 }; 426 427 // For small-screen devices (read: phones) that lack hardware navigation buttons 428 private void addNavigationBar() { 429 if (mNavigationBarView == null) return; 430 431 mNavigationBarView.reorient(); 432 433 mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener); 434 435 WindowManagerImpl.getDefault().addView( 436 mNavigationBarView, getNavigationBarLayoutParams()); 437 } 438 439 private void repositionNavigationBar() { 440 if (mNavigationBarView == null) return; 441 442 mNavigationBarView.reorient(); 443 444 mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener); 445 446 WindowManagerImpl.getDefault().updateViewLayout( 447 mNavigationBarView, getNavigationBarLayoutParams()); 448 } 449 450 private WindowManager.LayoutParams getNavigationBarLayoutParams() { 451 final int rotation = mDisplay.getRotation(); 452 final boolean sideways = 453 (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270); 454 455 final Resources res = mContext.getResources(); 456 final int size = res.getDimensionPixelSize(R.dimen.navigation_bar_size); 457 458 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 459 sideways ? size : ViewGroup.LayoutParams.MATCH_PARENT, 460 sideways ? ViewGroup.LayoutParams.MATCH_PARENT : size, 461 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, 462 0 463 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 464 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 465 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING 466 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 467 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH 468 | WindowManager.LayoutParams.FLAG_SLIPPERY, 469 PixelFormat.TRANSLUCENT); 470 471 lp.setTitle("NavigationBar"); 472 switch (rotation) { 473 case Surface.ROTATION_90: 474 // device has been turned 90deg counter-clockwise 475 lp.gravity = Gravity.RIGHT | Gravity.FILL_VERTICAL; 476 break; 477 case Surface.ROTATION_270: 478 // device has been turned 90deg clockwise 479 lp.gravity = (NavigationBarView.NAVBAR_ALWAYS_AT_RIGHT ? Gravity.RIGHT 480 : Gravity.LEFT) 481 | Gravity.FILL_VERTICAL; 482 break; 483 default: 484 lp.gravity = Gravity.BOTTOM | Gravity.FILL_HORIZONTAL; 485 break; 486 } 487 lp.windowAnimations = 0; 488 489 return lp; 490 } 491 492 private void addIntruderView() { 493 final int height = getStatusBarHeight(); 494 495 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 496 ViewGroup.LayoutParams.MATCH_PARENT, 497 ViewGroup.LayoutParams.WRAP_CONTENT, 498 WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL, 499 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 500 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 501 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 502 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 503 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 504 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, 505 PixelFormat.TRANSLUCENT); 506 lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL; 507 lp.y += height * 1.5; // FIXME 508 lp.setTitle("IntruderAlert"); 509 lp.windowAnimations = com.android.internal.R.style.Animation_StatusBar_IntruderAlert; 510 511 WindowManagerImpl.getDefault().addView(mIntruderAlertView, lp); 512 } 513 514 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) { 515 if (SPEW) Slog.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex 516 + " icon=" + icon); 517 StatusBarIconView view = new StatusBarIconView(mContext, slot, null); 518 view.set(icon); 519 mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(mIconSize, mIconSize)); 520 } 521 522 public void updateIcon(String slot, int index, int viewIndex, 523 StatusBarIcon old, StatusBarIcon icon) { 524 if (SPEW) Slog.d(TAG, "updateIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex 525 + " old=" + old + " icon=" + icon); 526 StatusBarIconView view = (StatusBarIconView)mStatusIcons.getChildAt(viewIndex); 527 view.set(icon); 528 } 529 530 public void removeIcon(String slot, int index, int viewIndex) { 531 if (SPEW) Slog.d(TAG, "removeIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex); 532 mStatusIcons.removeViewAt(viewIndex); 533 } 534 535 public void addNotification(IBinder key, StatusBarNotification notification) { 536 StatusBarIconView iconView = addNotificationViews(key, notification); 537 if (iconView == null) return; 538 539 boolean immersive = false; 540 try { 541 immersive = ActivityManagerNative.getDefault().isTopActivityImmersive(); 542 Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); 543 } catch (RemoteException ex) { 544 } 545 if (immersive) { 546 if ((notification.notification.flags & Notification.FLAG_HIGH_PRIORITY) != 0) { 547 Slog.d(TAG, "Presenting high-priority notification in immersive activity"); 548 // special new transient ticker mode 549 // 1. Populate mIntruderAlertView 550 551 ImageView alertIcon = (ImageView) mIntruderAlertView.findViewById(R.id.alertIcon); 552 TextView alertText = (TextView) mIntruderAlertView.findViewById(R.id.alertText); 553 alertIcon.setImageDrawable(StatusBarIconView.getIcon( 554 alertIcon.getContext(), 555 iconView.getStatusBarIcon())); 556 alertText.setText(notification.notification.tickerText); 557 558 View button = mIntruderAlertView.findViewById(R.id.intruder_alert_content); 559 button.setOnClickListener( 560 new NotificationClicker(notification.notification.contentIntent, 561 notification.pkg, notification.tag, notification.id)); 562 563 // 2. Animate mIntruderAlertView in 564 mHandler.sendEmptyMessage(MSG_SHOW_INTRUDER); 565 566 // 3. Set alarm to age the notification off (TODO) 567 mHandler.removeMessages(MSG_HIDE_INTRUDER); 568 mHandler.sendEmptyMessageDelayed(MSG_HIDE_INTRUDER, INTRUDER_ALERT_DECAY_MS); 569 } 570 } else if (notification.notification.fullScreenIntent != null) { 571 // not immersive & a full-screen alert should be shown 572 Slog.d(TAG, "Notification has fullScreenIntent and activity is not immersive;" 573 + " sending fullScreenIntent"); 574 try { 575 notification.notification.fullScreenIntent.send(); 576 } catch (PendingIntent.CanceledException e) { 577 } 578 } else { 579 // usual case: status bar visible & not immersive 580 581 // show the ticker 582 tick(notification); 583 } 584 585 // Recalculate the position of the sliding windows and the titles. 586 setAreThereNotifications(); 587 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 588 } 589 590 public void updateNotification(IBinder key, StatusBarNotification notification) { 591 if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ")"); 592 593 final NotificationData.Entry oldEntry = mNotificationData.findByKey(key); 594 if (oldEntry == null) { 595 Slog.w(TAG, "updateNotification for unknown key: " + key); 596 return; 597 } 598 599 final StatusBarNotification oldNotification = oldEntry.notification; 600 final RemoteViews oldContentView = oldNotification.notification.contentView; 601 602 final RemoteViews contentView = notification.notification.contentView; 603 604 605 if (DEBUG) { 606 Slog.d(TAG, "old notification: when=" + oldNotification.notification.when 607 + " ongoing=" + oldNotification.isOngoing() 608 + " expanded=" + oldEntry.expanded 609 + " contentView=" + oldContentView 610 + " rowParent=" + oldEntry.row.getParent()); 611 Slog.d(TAG, "new notification: when=" + notification.notification.when 612 + " ongoing=" + oldNotification.isOngoing() 613 + " contentView=" + contentView); 614 } 615 616 617 // Can we just reapply the RemoteViews in place? If when didn't change, the order 618 // didn't change. 619 boolean contentsUnchanged = oldEntry.expanded != null 620 && contentView != null && oldContentView != null 621 && contentView.getPackage() != null 622 && oldContentView.getPackage() != null 623 && oldContentView.getPackage().equals(contentView.getPackage()) 624 && oldContentView.getLayoutId() == contentView.getLayoutId(); 625 ViewGroup rowParent = (ViewGroup) oldEntry.row.getParent(); 626 boolean orderUnchanged = notification.notification.when==oldNotification.notification.when 627 && notification.priority == oldNotification.priority; 628 // priority now encompasses isOngoing() 629 boolean isFirstAnyway = rowParent.indexOfChild(oldEntry.row) == 0; 630 if (contentsUnchanged && (orderUnchanged || isFirstAnyway)) { 631 if (DEBUG) Slog.d(TAG, "reusing notification for key: " + key); 632 oldEntry.notification = notification; 633 try { 634 // Reapply the RemoteViews 635 contentView.reapply(mContext, oldEntry.content); 636 // update the contentIntent 637 final PendingIntent contentIntent = notification.notification.contentIntent; 638 if (contentIntent != null) { 639 oldEntry.content.setOnClickListener(new NotificationClicker(contentIntent, 640 notification.pkg, notification.tag, notification.id)); 641 } else { 642 oldEntry.content.setOnClickListener(null); 643 } 644 // Update the icon. 645 final StatusBarIcon ic = new StatusBarIcon(notification.pkg, 646 notification.notification.icon, notification.notification.iconLevel, 647 notification.notification.number, 648 notification.notification.tickerText); 649 if (!oldEntry.icon.set(ic)) { 650 handleNotificationError(key, notification, "Couldn't update icon: " + ic); 651 return; 652 } 653 // Update the large icon 654 if (notification.notification.largeIcon != null) { 655 oldEntry.largeIcon.setImageBitmap(notification.notification.largeIcon); 656 } else { 657 oldEntry.largeIcon.getLayoutParams().width = 0; 658 oldEntry.largeIcon.setVisibility(View.INVISIBLE); 659 } 660 } 661 catch (RuntimeException e) { 662 // It failed to add cleanly. Log, and remove the view from the panel. 663 Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e); 664 removeNotificationViews(key); 665 addNotificationViews(key, notification); 666 } 667 } else { 668 if (SPEW) Slog.d(TAG, "not reusing notification"); 669 removeNotificationViews(key); 670 addNotificationViews(key, notification); 671 } 672 673 // Restart the ticker if it's still running 674 if (notification.notification.tickerText != null 675 && !TextUtils.equals(notification.notification.tickerText, 676 oldEntry.notification.notification.tickerText)) { 677 tick(notification); 678 } 679 680 // Recalculate the position of the sliding windows and the titles. 681 setAreThereNotifications(); 682 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 683 } 684 685 public void removeNotification(IBinder key) { 686 if (SPEW) Slog.d(TAG, "removeNotification key=" + key); 687 StatusBarNotification old = removeNotificationViews(key); 688 689 if (old != null) { 690 // Cancel the ticker if it's still running 691 mTicker.removeEntry(old); 692 693 // Recalculate the position of the sliding windows and the titles. 694 setAreThereNotifications(); 695 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 696 } 697 } 698 699 @Override 700 protected void onConfigurationChanged(Configuration newConfig) { 701 updateRecentsPanel(); 702 } 703 704 705 View[] makeNotificationView(StatusBarNotification notification, ViewGroup parent) { 706 Notification n = notification.notification; 707 RemoteViews remoteViews = n.contentView; 708 if (remoteViews == null) { 709 return null; 710 } 711 712 // create the row view 713 LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( 714 Context.LAYOUT_INFLATER_SERVICE); 715 View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false); 716 717 // wire up the veto button 718 View vetoButton = row.findViewById(R.id.veto); 719 if (notification.isClearable()) { 720 final String _pkg = notification.pkg; 721 final String _tag = notification.tag; 722 final int _id = notification.id; 723 vetoButton.setOnClickListener(new View.OnClickListener() { 724 public void onClick(View v) { 725 try { 726 mBarService.onNotificationClear(_pkg, _tag, _id); 727 } catch (RemoteException ex) { 728 // system process is dead if we're here. 729 } 730 } 731 }); 732 } else { 733 if ((notification.notification.flags & Notification.FLAG_ONGOING_EVENT) == 0) { 734 vetoButton.setVisibility(View.INVISIBLE); 735 } else { 736 vetoButton.setVisibility(View.GONE); 737 } 738 } 739 740 // the large icon 741 ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon); 742 if (notification.notification.largeIcon != null) { 743 largeIcon.setImageBitmap(notification.notification.largeIcon); 744 } else { 745 largeIcon.getLayoutParams().width = 0; 746 largeIcon.setVisibility(View.INVISIBLE); 747 } 748 749 // bind the click event to the content area 750 ViewGroup content = (ViewGroup)row.findViewById(R.id.content); 751 content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 752 content.setOnFocusChangeListener(mFocusChangeListener); 753 PendingIntent contentIntent = n.contentIntent; 754 if (contentIntent != null) { 755 content.setOnClickListener(new NotificationClicker(contentIntent, notification.pkg, 756 notification.tag, notification.id)); 757 } else { 758 content.setOnClickListener(null); 759 } 760 761 View expanded = null; 762 Exception exception = null; 763 try { 764 expanded = remoteViews.apply(mContext, content); 765 } 766 catch (RuntimeException e) { 767 exception = e; 768 } 769 if (expanded == null) { 770 String ident = notification.pkg + "/0x" + Integer.toHexString(notification.id); 771 Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); 772 return null; 773 } else { 774 content.addView(expanded); 775 row.setDrawingCacheEnabled(true); 776 } 777 778 return new View[] { row, content, expanded }; 779 } 780 781 StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) { 782 if (DEBUG) { 783 Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification); 784 } 785 // Construct the icon. 786 final StatusBarIconView iconView = new StatusBarIconView(mContext, 787 notification.pkg + "/0x" + Integer.toHexString(notification.id), 788 notification.notification); 789 iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 790 791 final StatusBarIcon ic = new StatusBarIcon(notification.pkg, 792 notification.notification.icon, 793 notification.notification.iconLevel, 794 notification.notification.number, 795 notification.notification.tickerText); 796 if (!iconView.set(ic)) { 797 handleNotificationError(key, notification, "Couldn't create icon: " + ic); 798 return null; 799 } 800 // Construct the expanded view. 801 NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView); 802 if (!inflateViews(entry, mPile)) { 803 handleNotificationError(key, notification, "Couldn't expand RemoteViews for: " 804 + notification); 805 return null; 806 } 807 808 // Add the expanded view and icon. 809 int pos = mNotificationData.add(entry); 810 if (DEBUG) { 811 Slog.d(TAG, "addNotificationViews: added at " + pos); 812 } 813 updateNotificationIcons(); 814 815 return iconView; 816 } 817 818 private void loadNotificationShade() { 819 int N = mNotificationData.size(); 820 821 ArrayList<View> toShow = new ArrayList<View>(); 822 823 for (int i=0; i<N; i++) { 824 View row = mNotificationData.get(N-i-1).row; 825 toShow.add(row); 826 } 827 828 ArrayList<View> toRemove = new ArrayList<View>(); 829 for (int i=0; i<mPile.getChildCount(); i++) { 830 View child = mPile.getChildAt(i); 831 if (!toShow.contains(child)) { 832 toRemove.add(child); 833 } 834 } 835 836 for (View remove : toRemove) { 837 mPile.removeView(remove); 838 } 839 840 for (int i=0; i<toShow.size(); i++) { 841 View v = toShow.get(i); 842 if (v.getParent() == null) { 843 mPile.addView(v, 0); // the notification shade has newest at the top 844 } 845 } 846 } 847 848 private void reloadAllNotificationIcons() { 849 if (mNotificationIcons == null) return; 850 mNotificationIcons.removeAllViews(); 851 updateNotificationIcons(); 852 } 853 854 private void updateNotificationIcons() { 855 loadNotificationShade(); 856 857 final LinearLayout.LayoutParams params 858 = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight); 859 860 int N = mNotificationData.size(); 861 862 if (DEBUG) { 863 Slog.d(TAG, "refreshing icons: " + N + " notifications, mNotificationIcons=" + mNotificationIcons); 864 } 865 866 ArrayList<View> toShow = new ArrayList<View>(); 867 868 for (int i=0; i<N; i++) { 869 toShow.add(mNotificationData.get(N-i-1).icon); 870 } 871 872 ArrayList<View> toRemove = new ArrayList<View>(); 873 for (int i=0; i<mNotificationIcons.getChildCount(); i++) { 874 View child = mNotificationIcons.getChildAt(i); 875 if (!toShow.contains(child)) { 876 toRemove.add(child); 877 } 878 } 879 880 for (View remove : toRemove) { 881 mNotificationIcons.removeView(remove); 882 } 883 884 for (int i=0; i<toShow.size(); i++) { 885 View v = toShow.get(i); 886 if (v.getParent() == null) { 887 mNotificationIcons.addView(v, i, params); 888 } 889 } 890 } 891 892 void workAroundBadLayerDrawableOpacity(View v) { 893 LayerDrawable d = (LayerDrawable)v.getBackground(); 894 if (d == null) return; 895 v.setBackgroundDrawable(null); 896 d.setOpacity(PixelFormat.TRANSLUCENT); 897 v.setBackgroundDrawable(d); 898 } 899 900 private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) { 901 StatusBarNotification sbn = entry.notification; 902 RemoteViews remoteViews = sbn.notification.contentView; 903 if (remoteViews == null) { 904 return false; 905 } 906 907 // create the row view 908 LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( 909 Context.LAYOUT_INFLATER_SERVICE); 910 View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false); 911 workAroundBadLayerDrawableOpacity(row); 912 View vetoButton = row.findViewById(R.id.veto); 913 if (entry.notification.isClearable()) { 914 final String _pkg = sbn.pkg; 915 final String _tag = sbn.tag; 916 final int _id = sbn.id; 917 vetoButton.setOnClickListener(new View.OnClickListener() { 918 public void onClick(View v) { 919 try { 920 mBarService.onNotificationClear(_pkg, _tag, _id); 921 } catch (RemoteException ex) { 922 // system process is dead if we're here. 923 } 924 } 925 }); 926 } else { 927 if ((sbn.notification.flags & Notification.FLAG_ONGOING_EVENT) == 0) { 928 vetoButton.setVisibility(View.INVISIBLE); 929 vetoButton.setContentDescription("VETO"); 930 } else { 931 vetoButton.setVisibility(View.GONE); 932 } 933 } 934 vetoButton.setContentDescription(mContext.getString( 935 R.string.accessibility_remove_notification)); 936 937 // the large icon 938 ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon); 939 if (sbn.notification.largeIcon != null) { 940 largeIcon.setImageBitmap(sbn.notification.largeIcon); 941 largeIcon.setContentDescription(sbn.notification.tickerText); 942 } else { 943 largeIcon.getLayoutParams().width = 0; 944 largeIcon.setVisibility(View.INVISIBLE); 945 } 946 largeIcon.setContentDescription(sbn.notification.tickerText); 947 948 // bind the click event to the content area 949 ViewGroup content = (ViewGroup)row.findViewById(R.id.content); 950 // XXX: update to allow controls within notification views 951 content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 952// content.setOnFocusChangeListener(mFocusChangeListener); 953 PendingIntent contentIntent = sbn.notification.contentIntent; 954 if (contentIntent != null) { 955 content.setOnClickListener(new NotificationClicker(contentIntent, 956 sbn.pkg, sbn.tag, sbn.id)); 957 } else { 958 content.setOnClickListener(null); 959 } 960 961 View expanded = null; 962 Exception exception = null; 963 try { 964 expanded = remoteViews.apply(mContext, content); 965 } 966 catch (RuntimeException e) { 967 exception = e; 968 } 969 if (expanded == null) { 970 final String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id); 971 Slog.e(TAG, "couldn't inflate view for notification " + ident, exception); 972 return false; 973 } else { 974 content.addView(expanded); 975 row.setDrawingCacheEnabled(true); 976 } 977 978 entry.row = row; 979 entry.content = content; 980 entry.expanded = expanded; 981 entry.largeIcon = largeIcon; 982 983 return true; 984 } 985 986 StatusBarNotification removeNotificationViews(IBinder key) { 987 NotificationData.Entry entry = mNotificationData.remove(key); 988 if (entry == null) { 989 Slog.w(TAG, "removeNotification for unknown key: " + key); 990 return null; 991 } 992 // Remove the expanded view. 993 ViewGroup rowParent = (ViewGroup)entry.row.getParent(); 994 if (rowParent != null) rowParent.removeView(entry.row); 995 updateNotificationIcons(); 996 997 return entry.notification; 998 } 999 1000 private void setAreThereNotifications() { 1001 mClearButton.setVisibility(mNotificationData.hasClearableItems() 1002 ? View.VISIBLE 1003 : View.INVISIBLE); 1004 1005 mNoNotificationsTitle.setVisibility(mNotificationData.size() > 0 1006 ? View.GONE 1007 : View.VISIBLE); 1008 } 1009 1010 1011 /** 1012 * State is one or more of the DISABLE constants from StatusBarManager. 1013 */ 1014 public void disable(int state) { 1015 final int old = mDisabled; 1016 final int diff = state ^ old; 1017 mDisabled = state; 1018 1019 if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { 1020 if ((state & StatusBarManager.DISABLE_EXPAND) != 0) { 1021 Slog.d(TAG, "DISABLE_EXPAND: yes"); 1022 animateCollapse(); 1023 } 1024 } 1025 if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1026 if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1027 Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes"); 1028 if (mTicking) { 1029 mTicker.halt(); 1030 } else { 1031 setNotificationIconVisibility(false, com.android.internal.R.anim.fade_out); 1032 } 1033 } else { 1034 Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no"); 1035 if (!mExpandedVisible) { 1036 setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in); 1037 } 1038 } 1039 } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1040 if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1041 Slog.d(TAG, "DISABLE_NOTIFICATION_TICKER: yes"); 1042 mTicker.halt(); 1043 } 1044 } 1045 } 1046 1047 /** 1048 * All changes to the status bar and notifications funnel through here and are batched. 1049 */ 1050 private class H extends Handler { 1051 public void handleMessage(Message m) { 1052 switch (m.what) { 1053 case MSG_ANIMATE: 1054 doAnimation(); 1055 break; 1056 case MSG_ANIMATE_REVEAL: 1057 doRevealAnimation(); 1058 break; 1059 case MSG_SHOW_INTRUDER: 1060 setIntruderAlertVisibility(true); 1061 break; 1062 case MSG_HIDE_INTRUDER: 1063 setIntruderAlertVisibility(false); 1064 break; 1065 case MSG_OPEN_RECENTS_PANEL: 1066 if (DEBUG) Slog.d(TAG, "opening recents panel"); 1067 if (mRecentsPanel != null) { 1068 disable(StatusBarManager.DISABLE_BACK); 1069 mRecentsPanel.setVisibility(View.VISIBLE); 1070 mRecentsPanel.show(true, true); 1071 } 1072 break; 1073 case MSG_CLOSE_RECENTS_PANEL: 1074 if (DEBUG) Slog.d(TAG, "closing recents panel"); 1075 if (mRecentsPanel != null && mRecentsPanel.isShowing()) { 1076 disable(StatusBarManager.DISABLE_NONE); 1077 mRecentsPanel.show(false, true); 1078 } 1079 break; 1080 } 1081 } 1082 } 1083 1084 View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() { 1085 public void onFocusChange(View v, boolean hasFocus) { 1086 // Because 'v' is a ViewGroup, all its children will be (un)selected 1087 // too, which allows marqueeing to work. 1088 v.setSelected(hasFocus); 1089 } 1090 }; 1091 1092 private void makeExpandedVisible() { 1093 if (SPEW) Slog.d(TAG, "Make expanded visible: expanded visible=" + mExpandedVisible); 1094 if (mExpandedVisible) { 1095 return; 1096 } 1097 mExpandedVisible = true; 1098 visibilityChanged(true); 1099 1100 updateExpandedViewPos(EXPANDED_LEAVE_ALONE); 1101 mExpandedParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 1102 mExpandedParams.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; 1103 mExpandedDialog.getWindow().setAttributes(mExpandedParams); 1104 mExpandedView.requestFocus(View.FOCUS_FORWARD); 1105 mTrackingView.setVisibility(View.VISIBLE); 1106 1107 if (!mTicking) { 1108 setDateViewVisibility(true, com.android.internal.R.anim.fade_in); 1109 } 1110 } 1111 1112 public void animateExpand() { 1113 if (SPEW) Slog.d(TAG, "Animate expand: expanded=" + mExpanded); 1114 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1115 return ; 1116 } 1117 if (mExpanded) { 1118 return; 1119 } 1120 1121 prepareTracking(0, true); 1122 performFling(0, 2000.0f, true); 1123 } 1124 1125 public void animateCollapse() { 1126 animateCollapse(false); 1127 } 1128 1129 public void animateCollapse(boolean excludeRecents) { 1130 if (SPEW) { 1131 Slog.d(TAG, "animateCollapse(): mExpanded=" + mExpanded 1132 + " mExpandedVisible=" + mExpandedVisible 1133 + " mExpanded=" + mExpanded 1134 + " mAnimating=" + mAnimating 1135 + " mAnimY=" + mAnimY 1136 + " mAnimVel=" + mAnimVel); 1137 } 1138 1139 if (!excludeRecents) { 1140 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); 1141 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); 1142 } 1143 1144 if (!mExpandedVisible) { 1145 return; 1146 } 1147 1148 int y; 1149 if (mAnimating) { 1150 y = (int)mAnimY; 1151 } else { 1152 y = mDisplay.getHeight()-1; 1153 } 1154 // Let the fling think that we're open so it goes in the right direction 1155 // and doesn't try to re-open the windowshade. 1156 mExpanded = true; 1157 prepareTracking(y, false); 1158 performFling(y, -2000.0f, true); 1159 } 1160 1161 void performExpand() { 1162 if (SPEW) Slog.d(TAG, "performExpand: mExpanded=" + mExpanded); 1163 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1164 return ; 1165 } 1166 if (mExpanded) { 1167 return; 1168 } 1169 1170 mExpanded = true; 1171 makeExpandedVisible(); 1172 updateExpandedViewPos(EXPANDED_FULL_OPEN); 1173 1174 if (false) postStartTracing(); 1175 } 1176 1177 void performCollapse() { 1178 if (SPEW) Slog.d(TAG, "performCollapse: mExpanded=" + mExpanded 1179 + " mExpandedVisible=" + mExpandedVisible); 1180 1181 if (!mExpandedVisible) { 1182 return; 1183 } 1184 mExpandedVisible = false; 1185 visibilityChanged(false); 1186 mExpandedParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 1187 mExpandedParams.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; 1188 mExpandedDialog.getWindow().setAttributes(mExpandedParams); 1189 mTrackingView.setVisibility(View.GONE); 1190 1191 if ((mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS) == 0) { 1192 setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in); 1193 } 1194 setDateViewVisibility(false, com.android.internal.R.anim.fade_out); 1195 1196 if (!mExpanded) { 1197 return; 1198 } 1199 mExpanded = false; 1200 } 1201 1202 void doAnimation() { 1203 if (mAnimating) { 1204 if (SPEW) Slog.d(TAG, "doAnimation"); 1205 if (SPEW) Slog.d(TAG, "doAnimation before mAnimY=" + mAnimY); 1206 incrementAnim(); 1207 if (SPEW) Slog.d(TAG, "doAnimation after mAnimY=" + mAnimY); 1208 if (mAnimY >= mDisplay.getHeight()-1) { 1209 if (SPEW) Slog.d(TAG, "Animation completed to expanded state."); 1210 mAnimating = false; 1211 updateExpandedViewPos(EXPANDED_FULL_OPEN); 1212 performExpand(); 1213 } 1214 else if (mAnimY < mStatusBarView.getHeight()) { 1215 if (SPEW) Slog.d(TAG, "Animation completed to collapsed state."); 1216 mAnimating = false; 1217 updateExpandedViewPos(0); 1218 performCollapse(); 1219 } 1220 else { 1221 updateExpandedViewPos((int)mAnimY); 1222 mCurAnimationTime += ANIM_FRAME_DURATION; 1223 mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE), mCurAnimationTime); 1224 } 1225 } 1226 } 1227 1228 void stopTracking() { 1229 mTracking = false; 1230 mVelocityTracker.recycle(); 1231 mVelocityTracker = null; 1232 } 1233 1234 void incrementAnim() { 1235 long now = SystemClock.uptimeMillis(); 1236 float t = ((float)(now - mAnimLastTime)) / 1000; // ms -> s 1237 final float y = mAnimY; 1238 final float v = mAnimVel; // px/s 1239 final float a = mAnimAccel; // px/s/s 1240 mAnimY = y + (v*t) + (0.5f*a*t*t); // px 1241 mAnimVel = v + (a*t); // px/s 1242 mAnimLastTime = now; // ms 1243 //Slog.d(TAG, "y=" + y + " v=" + v + " a=" + a + " t=" + t + " mAnimY=" + mAnimY 1244 // + " mAnimAccel=" + mAnimAccel); 1245 } 1246 1247 void doRevealAnimation() { 1248 final int h = mCloseView.getHeight() + mStatusBarView.getHeight(); 1249 if (mAnimatingReveal && mAnimating && mAnimY < h) { 1250 incrementAnim(); 1251 if (mAnimY >= h) { 1252 mAnimY = h; 1253 updateExpandedViewPos((int)mAnimY); 1254 } else { 1255 updateExpandedViewPos((int)mAnimY); 1256 mCurAnimationTime += ANIM_FRAME_DURATION; 1257 mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE_REVEAL), 1258 mCurAnimationTime); 1259 } 1260 } 1261 } 1262 1263 void prepareTracking(int y, boolean opening) { 1264 mTracking = true; 1265 mVelocityTracker = VelocityTracker.obtain(); 1266 if (opening) { 1267 mAnimAccel = 2000.0f; 1268 mAnimVel = 200; 1269 mAnimY = mStatusBarView.getHeight(); 1270 updateExpandedViewPos((int)mAnimY); 1271 mAnimating = true; 1272 mAnimatingReveal = true; 1273 mHandler.removeMessages(MSG_ANIMATE); 1274 mHandler.removeMessages(MSG_ANIMATE_REVEAL); 1275 long now = SystemClock.uptimeMillis(); 1276 mAnimLastTime = now; 1277 mCurAnimationTime = now + ANIM_FRAME_DURATION; 1278 mAnimating = true; 1279 mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE_REVEAL), 1280 mCurAnimationTime); 1281 makeExpandedVisible(); 1282 } else { 1283 // it's open, close it? 1284 if (mAnimating) { 1285 mAnimating = false; 1286 mHandler.removeMessages(MSG_ANIMATE); 1287 } 1288 updateExpandedViewPos(y + mViewDelta); 1289 } 1290 } 1291 1292 void performFling(int y, float vel, boolean always) { 1293 mAnimatingReveal = false; 1294 mDisplayHeight = mDisplay.getHeight(); 1295 1296 mAnimY = y; 1297 mAnimVel = vel; 1298 1299 //Slog.d(TAG, "starting with mAnimY=" + mAnimY + " mAnimVel=" + mAnimVel); 1300 1301 if (mExpanded) { 1302 if (!always && ( 1303 vel > 200.0f 1304 || (y > (mDisplayHeight-25) && vel > -200.0f))) { 1305 // We are expanded, but they didn't move sufficiently to cause 1306 // us to retract. Animate back to the expanded position. 1307 mAnimAccel = 2000.0f; 1308 if (vel < 0) { 1309 mAnimVel = 0; 1310 } 1311 } 1312 else { 1313 // We are expanded and are now going to animate away. 1314 mAnimAccel = -2000.0f; 1315 if (vel > 0) { 1316 mAnimVel = 0; 1317 } 1318 } 1319 } else { 1320 if (always || ( 1321 vel > 200.0f 1322 || (y > (mDisplayHeight/2) && vel > -200.0f))) { 1323 // We are collapsed, and they moved enough to allow us to 1324 // expand. Animate in the notifications. 1325 mAnimAccel = 2000.0f; 1326 if (vel < 0) { 1327 mAnimVel = 0; 1328 } 1329 } 1330 else { 1331 // We are collapsed, but they didn't move sufficiently to cause 1332 // us to retract. Animate back to the collapsed position. 1333 mAnimAccel = -2000.0f; 1334 if (vel > 0) { 1335 mAnimVel = 0; 1336 } 1337 } 1338 } 1339 //Slog.d(TAG, "mAnimY=" + mAnimY + " mAnimVel=" + mAnimVel 1340 // + " mAnimAccel=" + mAnimAccel); 1341 1342 long now = SystemClock.uptimeMillis(); 1343 mAnimLastTime = now; 1344 mCurAnimationTime = now + ANIM_FRAME_DURATION; 1345 mAnimating = true; 1346 mHandler.removeMessages(MSG_ANIMATE); 1347 mHandler.removeMessages(MSG_ANIMATE_REVEAL); 1348 mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE), mCurAnimationTime); 1349 stopTracking(); 1350 } 1351 1352 boolean interceptTouchEvent(MotionEvent event) { 1353 if (SPEW) { 1354 Slog.d(TAG, "Touch: rawY=" + event.getRawY() + " event=" + event + " mDisabled=" 1355 + mDisabled); 1356 } 1357 1358 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) { 1359 return false; 1360 } 1361 1362 final int statusBarSize = mStatusBarView.getHeight(); 1363 final int hitSize = statusBarSize*2; 1364 if (event.getAction() == MotionEvent.ACTION_DOWN) { 1365 final int y = (int)event.getRawY(); 1366 1367 if (!mExpanded) { 1368 mViewDelta = statusBarSize - y; 1369 } else { 1370 mTrackingView.getLocationOnScreen(mAbsPos); 1371 mViewDelta = mAbsPos[1] + mTrackingView.getHeight() - y; 1372 } 1373 if ((!mExpanded && y < hitSize) || 1374 (mExpanded && y > (mDisplay.getHeight()-hitSize))) { 1375 1376 // We drop events at the edge of the screen to make the windowshade come 1377 // down by accident less, especially when pushing open a device with a keyboard 1378 // that rotates (like g1 and droid) 1379 int x = (int)event.getRawX(); 1380 final int edgeBorder = mEdgeBorder; 1381 if (x >= edgeBorder && x < mDisplay.getWidth() - edgeBorder) { 1382 prepareTracking(y, !mExpanded);// opening if we're not already fully visible 1383 mVelocityTracker.addMovement(event); 1384 } 1385 } 1386 } else if (mTracking) { 1387 mVelocityTracker.addMovement(event); 1388 final int minY = statusBarSize + mCloseView.getHeight(); 1389 if (event.getAction() == MotionEvent.ACTION_MOVE) { 1390 int y = (int)event.getRawY(); 1391 if (mAnimatingReveal && y < minY) { 1392 // nothing 1393 } else { 1394 mAnimatingReveal = false; 1395 updateExpandedViewPos(y + mViewDelta); 1396 } 1397 } else if (event.getAction() == MotionEvent.ACTION_UP) { 1398 mVelocityTracker.computeCurrentVelocity(1000); 1399 1400 float yVel = mVelocityTracker.getYVelocity(); 1401 boolean negative = yVel < 0; 1402 1403 float xVel = mVelocityTracker.getXVelocity(); 1404 if (xVel < 0) { 1405 xVel = -xVel; 1406 } 1407 if (xVel > 150.0f) { 1408 xVel = 150.0f; // limit how much we care about the x axis 1409 } 1410 1411 float vel = (float)Math.hypot(yVel, xVel); 1412 if (negative) { 1413 vel = -vel; 1414 } 1415 1416 performFling((int)event.getRawY(), vel, false); 1417 } 1418 1419 } 1420 return false; 1421 } 1422 1423 @Override // CommandQueue 1424 public void setSystemUiVisibility(int vis) { 1425 if (vis != mSystemUiVisibility) { 1426 mSystemUiVisibility = vis; 1427 1428 if (0 != (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE)) { 1429 animateCollapse(); 1430 } 1431 1432 notifyUiVisibilityChanged(); 1433 } 1434 } 1435 1436 public void setLightsOn(boolean on) { 1437 Log.v(TAG, "setLightsOn(" + on + ")"); 1438 if (on) { 1439 setSystemUiVisibility(mSystemUiVisibility & ~View.SYSTEM_UI_FLAG_LOW_PROFILE); 1440 } else { 1441 setSystemUiVisibility(mSystemUiVisibility | View.SYSTEM_UI_FLAG_LOW_PROFILE); 1442 } 1443 } 1444 1445 private void notifyUiVisibilityChanged() { 1446 try { 1447 mWindowManager.statusBarVisibilityChanged(mSystemUiVisibility); 1448 } catch (RemoteException ex) { 1449 } 1450 } 1451 1452 public void topAppWindowChanged(boolean showMenu) { 1453 if (DEBUG) { 1454 Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button"); 1455 } 1456 if (mNavigationBarView != null) { 1457 mNavigationBarView.getMenuButton().setVisibility(showMenu 1458 ? View.VISIBLE : View.INVISIBLE); 1459 } 1460 1461 // See above re: lights-out policy for legacy apps. 1462 if (showMenu) setLightsOn(true); 1463 } 1464 1465 // Not supported 1466 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { } 1467 @Override 1468 public void setHardKeyboardStatus(boolean available, boolean enabled) { } 1469 1470 public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag, int id) { 1471 return new NotificationClicker(intent, pkg, tag, id); 1472 } 1473 1474 private class NotificationClicker implements View.OnClickListener { 1475 private PendingIntent mIntent; 1476 private String mPkg; 1477 private String mTag; 1478 private int mId; 1479 1480 NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { 1481 mIntent = intent; 1482 mPkg = pkg; 1483 mTag = tag; 1484 mId = id; 1485 } 1486 1487 public void onClick(View v) { 1488 try { 1489 // The intent we are sending is for the application, which 1490 // won't have permission to immediately start an activity after 1491 // the user switches to home. We know it is safe to do at this 1492 // point, so make sure new activity switches are now allowed. 1493 ActivityManagerNative.getDefault().resumeAppSwitches(); 1494 } catch (RemoteException e) { 1495 } 1496 1497 if (mIntent != null) { 1498 int[] pos = new int[2]; 1499 v.getLocationOnScreen(pos); 1500 Intent overlay = new Intent(); 1501 overlay.setSourceBounds( 1502 new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); 1503 try { 1504 mIntent.send(mContext, 0, overlay); 1505 } catch (PendingIntent.CanceledException e) { 1506 // the stack trace isn't very helpful here. Just log the exception message. 1507 Slog.w(TAG, "Sending contentIntent failed: " + e); 1508 } 1509 } 1510 1511 try { 1512 mBarService.onNotificationClick(mPkg, mTag, mId); 1513 } catch (RemoteException ex) { 1514 // system process is dead if we're here. 1515 } 1516 1517 // close the shade if it was open 1518 animateCollapse(); 1519 1520 // If this click was on the intruder alert, hide that instead 1521 mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER); 1522 } 1523 } 1524 1525 private void tick(StatusBarNotification n) { 1526 // Show the ticker if one is requested. Also don't do this 1527 // until status bar window is attached to the window manager, 1528 // because... well, what's the point otherwise? And trying to 1529 // run a ticker without being attached will crash! 1530 if (n.notification.tickerText != null && mStatusBarView.getWindowToken() != null) { 1531 if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS 1532 | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { 1533 mTicker.addEntry(n); 1534 } 1535 } 1536 } 1537 1538 /** 1539 * Cancel this notification and tell the StatusBarManagerService / NotificationManagerService 1540 * about the failure. 1541 * 1542 * WARNING: this will call back into us. Don't hold any locks. 1543 */ 1544 void handleNotificationError(IBinder key, StatusBarNotification n, String message) { 1545 removeNotification(key); 1546 try { 1547 mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message); 1548 } catch (RemoteException ex) { 1549 // The end is nigh. 1550 } 1551 } 1552 1553 private class MyTicker extends Ticker { 1554 MyTicker(Context context, View sb) { 1555 super(context, sb); 1556 } 1557 1558 @Override 1559 public void tickerStarting() { 1560 mTicking = true; 1561 mIcons.setVisibility(View.GONE); 1562 mTickerView.setVisibility(View.VISIBLE); 1563 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_up_in, null)); 1564 mIcons.startAnimation(loadAnim(com.android.internal.R.anim.push_up_out, null)); 1565 if (mExpandedVisible) { 1566 setDateViewVisibility(false, com.android.internal.R.anim.push_up_out); 1567 } 1568 } 1569 1570 @Override 1571 public void tickerDone() { 1572 mIcons.setVisibility(View.VISIBLE); 1573 mTickerView.setVisibility(View.GONE); 1574 mIcons.startAnimation(loadAnim(com.android.internal.R.anim.push_down_in, null)); 1575 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_down_out, 1576 mTickingDoneListener)); 1577 if (mExpandedVisible) { 1578 setDateViewVisibility(true, com.android.internal.R.anim.push_down_in); 1579 } 1580 } 1581 1582 public void tickerHalting() { 1583 mIcons.setVisibility(View.VISIBLE); 1584 mTickerView.setVisibility(View.GONE); 1585 mIcons.startAnimation(loadAnim(com.android.internal.R.anim.fade_in, null)); 1586 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.fade_out, 1587 mTickingDoneListener)); 1588 if (mExpandedVisible) { 1589 setDateViewVisibility(true, com.android.internal.R.anim.fade_in); 1590 } 1591 } 1592 } 1593 1594 Animation.AnimationListener mTickingDoneListener = new Animation.AnimationListener() {; 1595 public void onAnimationEnd(Animation animation) { 1596 mTicking = false; 1597 } 1598 public void onAnimationRepeat(Animation animation) { 1599 } 1600 public void onAnimationStart(Animation animation) { 1601 } 1602 }; 1603 1604 private Animation loadAnim(int id, Animation.AnimationListener listener) { 1605 Animation anim = AnimationUtils.loadAnimation(mContext, id); 1606 if (listener != null) { 1607 anim.setAnimationListener(listener); 1608 } 1609 return anim; 1610 } 1611 1612 public String viewInfo(View v) { 1613 return "(" + v.getLeft() + "," + v.getTop() + ")(" + v.getRight() + "," + v.getBottom() 1614 + " " + v.getWidth() + "x" + v.getHeight() + ")"; 1615 } 1616 1617 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 1618 synchronized (mQueueLock) { 1619 pw.println("Current Status Bar state:"); 1620 pw.println(" mExpanded=" + mExpanded 1621 + ", mExpandedVisible=" + mExpandedVisible); 1622 pw.println(" mTicking=" + mTicking); 1623 pw.println(" mTracking=" + mTracking); 1624 pw.println(" mAnimating=" + mAnimating 1625 + ", mAnimY=" + mAnimY + ", mAnimVel=" + mAnimVel 1626 + ", mAnimAccel=" + mAnimAccel); 1627 pw.println(" mCurAnimationTime=" + mCurAnimationTime 1628 + " mAnimLastTime=" + mAnimLastTime); 1629 pw.println(" mDisplayHeight=" + mDisplayHeight 1630 + " mAnimatingReveal=" + mAnimatingReveal 1631 + " mViewDelta=" + mViewDelta); 1632 pw.println(" mDisplayHeight=" + mDisplayHeight); 1633 pw.println(" mExpandedParams: " + mExpandedParams); 1634 pw.println(" mExpandedView: " + viewInfo(mExpandedView)); 1635 pw.println(" mExpandedDialog: " + mExpandedDialog); 1636 pw.println(" mTrackingParams: " + mTrackingParams); 1637 pw.println(" mTrackingView: " + viewInfo(mTrackingView)); 1638 pw.println(" mPile: " + viewInfo(mPile)); 1639 pw.println(" mNoNotificationsTitle: " + viewInfo(mNoNotificationsTitle)); 1640 pw.println(" mCloseView: " + viewInfo(mCloseView)); 1641 pw.println(" mTickerView: " + viewInfo(mTickerView)); 1642 pw.println(" mScrollView: " + viewInfo(mScrollView) 1643 + " scroll " + mScrollView.getScrollX() + "," + mScrollView.getScrollY()); 1644 pw.println("mNotificationLinearLayout: " + viewInfo(mNotificationLinearLayout)); 1645 } 1646 /* 1647 synchronized (mNotificationData) { 1648 int N = mNotificationData.ongoingCount(); 1649 pw.println(" ongoingCount.size=" + N); 1650 for (int i=0; i<N; i++) { 1651 StatusBarNotification n = mNotificationData.getOngoing(i); 1652 pw.println(" [" + i + "] key=" + n.key + " view=" + n.view); 1653 pw.println(" data=" + n.data); 1654 } 1655 N = mNotificationData.latestCount(); 1656 pw.println(" ongoingCount.size=" + N); 1657 for (int i=0; i<N; i++) { 1658 StatusBarNotification n = mNotificationData.getLatest(i); 1659 pw.println(" [" + i + "] key=" + n.key + " view=" + n.view); 1660 pw.println(" data=" + n.data); 1661 } 1662 } 1663 */ 1664 1665 if (false) { 1666 pw.println("see the logcat for a dump of the views we have created."); 1667 // must happen on ui thread 1668 mHandler.post(new Runnable() { 1669 public void run() { 1670 mStatusBarView.getLocationOnScreen(mAbsPos); 1671 Slog.d(TAG, "mStatusBarView: ----- (" + mAbsPos[0] + "," + mAbsPos[1] 1672 + ") " + mStatusBarView.getWidth() + "x" 1673 + mStatusBarView.getHeight()); 1674 mStatusBarView.debug(); 1675 1676 mExpandedView.getLocationOnScreen(mAbsPos); 1677 Slog.d(TAG, "mExpandedView: ----- (" + mAbsPos[0] + "," + mAbsPos[1] 1678 + ") " + mExpandedView.getWidth() + "x" 1679 + mExpandedView.getHeight()); 1680 mExpandedView.debug(); 1681 1682 mTrackingView.getLocationOnScreen(mAbsPos); 1683 Slog.d(TAG, "mTrackingView: ----- (" + mAbsPos[0] + "," + mAbsPos[1] 1684 + ") " + mTrackingView.getWidth() + "x" 1685 + mTrackingView.getHeight()); 1686 mTrackingView.debug(); 1687 } 1688 }); 1689 } 1690 } 1691 1692 void onBarViewAttached() { 1693 WindowManager.LayoutParams lp; 1694 int pixelFormat; 1695 Drawable bg; 1696 1697 /// ---------- Tracking View -------------- 1698 pixelFormat = PixelFormat.RGBX_8888; 1699 bg = mTrackingView.getBackground(); 1700 if (bg != null) { 1701 pixelFormat = bg.getOpacity(); 1702 } 1703 1704 lp = new WindowManager.LayoutParams( 1705 ViewGroup.LayoutParams.MATCH_PARENT, 1706 ViewGroup.LayoutParams.MATCH_PARENT, 1707 WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL, 1708 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 1709 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 1710 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, 1711 pixelFormat); 1712// lp.token = mStatusBarView.getWindowToken(); 1713 lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL; 1714 lp.setTitle("TrackingView"); 1715 lp.y = mTrackingPosition; 1716 mTrackingParams = lp; 1717 1718 WindowManagerImpl.getDefault().addView(mTrackingView, lp); 1719 } 1720 1721 void onTrackingViewAttached() { 1722 WindowManager.LayoutParams lp; 1723 int pixelFormat; 1724 Drawable bg; 1725 1726 /// ---------- Expanded View -------------- 1727 pixelFormat = PixelFormat.TRANSLUCENT; 1728 1729 final int disph = mDisplay.getHeight(); 1730 lp = mExpandedDialog.getWindow().getAttributes(); 1731 lp.width = ViewGroup.LayoutParams.MATCH_PARENT; 1732 lp.height = getExpandedHeight(); 1733 lp.x = 0; 1734 mTrackingPosition = lp.y = -disph; // sufficiently large negative 1735 lp.type = WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; 1736 lp.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 1737 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 1738 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 1739 | WindowManager.LayoutParams.FLAG_DITHER 1740 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 1741 lp.format = pixelFormat; 1742 lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL; 1743 lp.setTitle("StatusBarExpanded"); 1744 mExpandedDialog.getWindow().setAttributes(lp); 1745 mExpandedDialog.getWindow().setFormat(pixelFormat); 1746 mExpandedParams = lp; 1747 1748 mExpandedDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 1749 mExpandedDialog.setContentView(mExpandedView, 1750 new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1751 ViewGroup.LayoutParams.MATCH_PARENT)); 1752 mExpandedDialog.getWindow().setBackgroundDrawable(null); 1753 mExpandedDialog.show(); 1754 FrameLayout hack = (FrameLayout)mExpandedView.getParent(); 1755 } 1756 1757 void setDateViewVisibility(boolean visible, int anim) { 1758 mDateView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); 1759 mDateView.startAnimation(loadAnim(anim, null)); 1760 } 1761 1762 void setNotificationIconVisibility(boolean visible, int anim) { 1763 int old = mNotificationIcons.getVisibility(); 1764 int v = visible ? View.VISIBLE : View.INVISIBLE; 1765 if (old != v) { 1766 mNotificationIcons.setVisibility(v); 1767 mNotificationIcons.startAnimation(loadAnim(anim, null)); 1768 } 1769 } 1770 1771 void updateExpandedViewPos(int expandedPosition) { 1772 if (SPEW) { 1773 Slog.d(TAG, "updateExpandedViewPos before expandedPosition=" + expandedPosition 1774 + " mTrackingParams.y=" + mTrackingParams.y 1775 + " mTrackingPosition=" + mTrackingPosition); 1776 } 1777 1778 int h = mStatusBarView.getHeight(); 1779 int disph = mDisplay.getHeight(); 1780 1781 // If the expanded view is not visible, make sure they're still off screen. 1782 // Maybe the view was resized. 1783 if (!mExpandedVisible) { 1784 if (mTrackingView != null) { 1785 mTrackingPosition = -disph; 1786 if (mTrackingParams != null) { 1787 mTrackingParams.y = mTrackingPosition; 1788 WindowManagerImpl.getDefault().updateViewLayout(mTrackingView, mTrackingParams); 1789 } 1790 } 1791 if (mExpandedParams != null) { 1792 mExpandedParams.y = -disph; 1793 mExpandedDialog.getWindow().setAttributes(mExpandedParams); 1794 } 1795 return; 1796 } 1797 1798 // tracking view... 1799 int pos; 1800 if (expandedPosition == EXPANDED_FULL_OPEN) { 1801 pos = h; 1802 } 1803 else if (expandedPosition == EXPANDED_LEAVE_ALONE) { 1804 pos = mTrackingPosition; 1805 } 1806 else { 1807 if (expandedPosition <= disph) { 1808 pos = expandedPosition; 1809 } else { 1810 pos = disph; 1811 } 1812 pos -= disph-h; 1813 } 1814 mTrackingPosition = mTrackingParams.y = pos; 1815 mTrackingParams.height = disph-h; 1816 WindowManagerImpl.getDefault().updateViewLayout(mTrackingView, mTrackingParams); 1817 1818 if (mExpandedParams != null) { 1819 mCloseView.getLocationInWindow(mPositionTmp); 1820 final int closePos = mPositionTmp[1]; 1821 1822 mExpandedContents.getLocationInWindow(mPositionTmp); 1823 final int contentsBottom = mPositionTmp[1] + mExpandedContents.getHeight(); 1824 1825 mExpandedParams.y = pos + mTrackingView.getHeight() 1826 - (mTrackingParams.height-closePos) - contentsBottom; 1827 int max = h; 1828 if (mExpandedParams.y > max) { 1829 mExpandedParams.y = max; 1830 } 1831 int min = mTrackingPosition; 1832 if (mExpandedParams.y < min) { 1833 mExpandedParams.y = min; 1834 } 1835 1836 boolean visible = (mTrackingPosition + mTrackingView.getHeight()) > h; 1837 if (!visible) { 1838 // if the contents aren't visible, move the expanded view way off screen 1839 // because the window itself extends below the content view. 1840 mExpandedParams.y = -disph; 1841 } 1842 mExpandedDialog.getWindow().setAttributes(mExpandedParams); 1843 1844 // As long as this isn't just a repositioning that's not supposed to affect 1845 // the user's perception of what's showing, call to say that the visibility 1846 // has changed. (Otherwise, someone else will call to do that). 1847 if (expandedPosition != EXPANDED_LEAVE_ALONE) { 1848 if (SPEW) Slog.d(TAG, "updateExpandedViewPos visibilityChanged(" + visible + ")"); 1849 visibilityChanged(visible); 1850 } 1851 } 1852 1853 if (SPEW) { 1854 Slog.d(TAG, "updateExpandedViewPos after expandedPosition=" + expandedPosition 1855 + " mTrackingParams.y=" + mTrackingParams.y 1856 + " mTrackingPosition=" + mTrackingPosition 1857 + " mExpandedParams.y=" + mExpandedParams.y 1858 + " mExpandedParams.height=" + mExpandedParams.height); 1859 } 1860 } 1861 1862 int getExpandedHeight() { 1863 return mDisplay.getHeight() - mStatusBarView.getHeight() - mCloseView.getHeight(); 1864 } 1865 1866 void updateExpandedHeight() { 1867 if (mExpandedView != null) { 1868 mExpandedParams.height = getExpandedHeight(); 1869 mExpandedDialog.getWindow().setAttributes(mExpandedParams); 1870 } 1871 } 1872 1873 // The user is not allowed to get stuck without navigation UI. Upon the slightest user 1874 // interaction we bring the navigation back. 1875 public void userActivity() { 1876 if (mNavigationBarView != null) { 1877 mNavigationBarView.setHidden(false); 1878 } 1879 } 1880 1881 public void toggleRecentApps() { 1882 int msg = (mRecentsPanel.getVisibility() == View.GONE) 1883 ? MSG_OPEN_RECENTS_PANEL : MSG_CLOSE_RECENTS_PANEL; 1884 mHandler.removeMessages(msg); 1885 mHandler.sendEmptyMessage(msg); 1886 } 1887 1888 /** 1889 * The LEDs are turned o)ff when the notification panel is shown, even just a little bit. 1890 * This was added last-minute and is inconsistent with the way the rest of the notifications 1891 * are handled, because the notification isn't really cancelled. The lights are just 1892 * turned off. If any other notifications happen, the lights will turn back on. Steve says 1893 * this is what he wants. (see bug 1131461) 1894 */ 1895 void visibilityChanged(boolean visible) { 1896 if (mPanelSlightlyVisible != visible) { 1897 mPanelSlightlyVisible = visible; 1898 try { 1899 mBarService.onPanelRevealed(); 1900 } catch (RemoteException ex) { 1901 // Won't fail unless the world has ended. 1902 } 1903 } 1904 } 1905 1906 void performDisableActions(int net) { 1907 int old = mDisabled; 1908 int diff = net ^ old; 1909 mDisabled = net; 1910 1911 // act accordingly 1912 if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) { 1913 if ((net & StatusBarManager.DISABLE_EXPAND) != 0) { 1914 Slog.d(TAG, "DISABLE_EXPAND: yes"); 1915 animateCollapse(); 1916 } 1917 } 1918 if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1919 if ((net & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { 1920 Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes"); 1921 if (mTicking) { 1922 mNotificationIcons.setVisibility(View.INVISIBLE); 1923 mTicker.halt(); 1924 } else { 1925 setNotificationIconVisibility(false, com.android.internal.R.anim.fade_out); 1926 } 1927 } else { 1928 Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no"); 1929 if (!mExpandedVisible) { 1930 setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in); 1931 } 1932 } 1933 } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1934 if (mTicking && (net & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { 1935 mTicker.halt(); 1936 } 1937 } 1938 } 1939 1940 private View.OnClickListener mClearButtonListener = new View.OnClickListener() { 1941 public void onClick(View v) { 1942 try { 1943 mBarService.onClearAllNotifications(); 1944 } catch (RemoteException ex) { 1945 // system process is dead if we're here. 1946 } 1947 animateCollapse(); 1948 } 1949 }; 1950 1951 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 1952 public void onReceive(Context context, Intent intent) { 1953 String action = intent.getAction(); 1954 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action) 1955 || Intent.ACTION_SCREEN_OFF.equals(action)) { 1956 boolean excludeRecents = false; 1957 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { 1958 String reason = intent.getStringExtra("reason"); 1959 if (reason != null) { 1960 excludeRecents = reason.equals("recentapps"); 1961 } 1962 } 1963 animateCollapse(excludeRecents); 1964 } 1965 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { 1966 repositionNavigationBar(); 1967 updateResources(); 1968 } 1969 } 1970 }; 1971 1972 private void setIntruderAlertVisibility(boolean vis) { 1973 mIntruderAlertView.setVisibility(vis ? View.VISIBLE : View.GONE); 1974 } 1975 1976 /** 1977 * Reload some of our resources when the configuration changes. 1978 * 1979 * We don't reload everything when the configuration changes -- we probably 1980 * should, but getting that smooth is tough. Someday we'll fix that. In the 1981 * meantime, just update the things that we know change. 1982 */ 1983 void updateResources() { 1984 final Context context = mContext; 1985 final Resources res = context.getResources(); 1986 1987 mClearButton.setText(context.getText(R.string.status_bar_clear_all_button)); 1988 mNoNotificationsTitle.setText(context.getText(R.string.status_bar_no_notifications_title)); 1989 1990 loadDimens(); 1991 } 1992 1993 protected void loadDimens() { 1994 final Resources res = mContext.getResources(); 1995 1996 mNaturalBarHeight = res.getDimensionPixelSize( 1997 com.android.internal.R.dimen.status_bar_height); 1998 1999 int newIconSize = res.getDimensionPixelSize( 2000 com.android.internal.R.dimen.status_bar_icon_size); 2001 int newIconHPadding = res.getDimensionPixelSize( 2002 R.dimen.status_bar_icon_padding); 2003 2004 if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) { 2005// Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding); 2006 mIconHPadding = newIconHPadding; 2007 mIconSize = newIconSize; 2008 //reloadAllNotificationIcons(); // reload the tray 2009 } 2010 2011 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore); 2012 2013 if (false) Slog.v(TAG, "updateResources"); 2014 } 2015 2016 // 2017 // tracing 2018 // 2019 2020 void postStartTracing() { 2021 mHandler.postDelayed(mStartTracing, 3000); 2022 } 2023 2024 void vibrate() { 2025 android.os.Vibrator vib = (android.os.Vibrator)mContext.getSystemService( 2026 Context.VIBRATOR_SERVICE); 2027 vib.vibrate(250); 2028 } 2029 2030 Runnable mStartTracing = new Runnable() { 2031 public void run() { 2032 vibrate(); 2033 SystemClock.sleep(250); 2034 Slog.d(TAG, "startTracing"); 2035 android.os.Debug.startMethodTracing("/data/statusbar-traces/trace"); 2036 mHandler.postDelayed(mStopTracing, 10000); 2037 } 2038 }; 2039 2040 Runnable mStopTracing = new Runnable() { 2041 public void run() { 2042 android.os.Debug.stopMethodTracing(); 2043 Slog.d(TAG, "stopTracing"); 2044 vibrate(); 2045 } 2046 }; 2047 2048 public class TouchOutsideListener implements View.OnTouchListener { 2049 private int mMsg; 2050 private RecentsPanelView mPanel; 2051 2052 public TouchOutsideListener(int msg, RecentsPanelView panel) { 2053 mMsg = msg; 2054 mPanel = panel; 2055 } 2056 2057 public boolean onTouch(View v, MotionEvent ev) { 2058 final int action = ev.getAction(); 2059 if (action == MotionEvent.ACTION_OUTSIDE 2060 || (action == MotionEvent.ACTION_DOWN 2061 && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) { 2062 mHandler.removeMessages(mMsg); 2063 mHandler.sendEmptyMessage(mMsg); 2064 return true; 2065 } 2066 return false; 2067 } 2068 } 2069} 2070 2071