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