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