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