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