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