PhoneStatusBar.java revision 1bbd49d72eee001137b6d6e6ab3f353fe2c0433c
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
684        // we want to freeze the sysui state wherever it is
685        mSearchPanelView.setSystemUiVisibility(mSystemUiVisibility);
686
687        WindowManager.LayoutParams lp =
688            (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams();
689        lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
690        mWindowManager.updateViewLayout(mNavigationBarView, lp);
691    }
692
693    @Override
694    public void hideSearchPanel() {
695        super.hideSearchPanel();
696        WindowManager.LayoutParams lp =
697            (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams();
698        lp.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
699        mWindowManager.updateViewLayout(mNavigationBarView, lp);
700    }
701
702    protected int getStatusBarGravity() {
703        return Gravity.TOP | Gravity.FILL_HORIZONTAL;
704    }
705
706    public int getStatusBarHeight() {
707        if (mNaturalBarHeight < 0) {
708            final Resources res = mContext.getResources();
709            mNaturalBarHeight =
710                    res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
711        }
712        return mNaturalBarHeight;
713    }
714
715    private View.OnClickListener mRecentsClickListener = new View.OnClickListener() {
716        public void onClick(View v) {
717            toggleRecentApps();
718        }
719    };
720
721    private int mShowSearchHoldoff = 0;
722    private Runnable mShowSearchPanel = new Runnable() {
723        public void run() {
724            showSearchPanel();
725            awakenDreams();
726        }
727    };
728
729    View.OnTouchListener mHomeSearchActionListener = new View.OnTouchListener() {
730        public boolean onTouch(View v, MotionEvent event) {
731            switch(event.getAction()) {
732            case MotionEvent.ACTION_DOWN:
733                if (!shouldDisableNavbarGestures()) {
734                    mHandler.removeCallbacks(mShowSearchPanel);
735                    mHandler.postDelayed(mShowSearchPanel, mShowSearchHoldoff);
736                }
737            break;
738
739            case MotionEvent.ACTION_UP:
740            case MotionEvent.ACTION_CANCEL:
741                mHandler.removeCallbacks(mShowSearchPanel);
742                awakenDreams();
743            break;
744        }
745        return false;
746        }
747    };
748
749    private void awakenDreams() {
750        if (mDreamManager != null) {
751            try {
752                mDreamManager.awaken();
753            } catch (RemoteException e) {
754                // fine, stay asleep then
755            }
756        }
757    }
758
759    private void prepareNavigationBarView() {
760        mNavigationBarView.reorient();
761
762        mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener);
763        mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPreloadOnTouchListener);
764        mNavigationBarView.getHomeButton().setOnTouchListener(mHomeSearchActionListener);
765        updateSearchPanel();
766    }
767
768    // For small-screen devices (read: phones) that lack hardware navigation buttons
769    private void addNavigationBar() {
770        if (DEBUG) Slog.v(TAG, "addNavigationBar: about to add " + mNavigationBarView);
771        if (mNavigationBarView == null) return;
772
773        prepareNavigationBarView();
774
775        mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams());
776    }
777
778    private void repositionNavigationBar() {
779        if (mNavigationBarView == null) return;
780
781        prepareNavigationBarView();
782
783        mWindowManager.updateViewLayout(mNavigationBarView, getNavigationBarLayoutParams());
784    }
785
786    private void notifyNavigationBarScreenOn(boolean screenOn) {
787        if (mNavigationBarView == null) return;
788        mNavigationBarView.notifyScreenOn(screenOn);
789    }
790
791    private WindowManager.LayoutParams getNavigationBarLayoutParams() {
792        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
793                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
794                WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
795                    0
796                    | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
797                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
798                    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
799                    | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
800                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
801                PixelFormat.OPAQUE);
802        // this will allow the navbar to run in an overlay on devices that support this
803        if (ActivityManager.isHighEndGfx()) {
804            lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
805        }
806
807        lp.setTitle("NavigationBar");
808        lp.windowAnimations = 0;
809        return lp;
810    }
811
812    private void addIntruderView() {
813        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
814                ViewGroup.LayoutParams.MATCH_PARENT,
815                ViewGroup.LayoutParams.WRAP_CONTENT,
816                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, // above the status bar!
817                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
818                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
819                    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
820                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
821                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
822                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
823                PixelFormat.TRANSLUCENT);
824        lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL;
825        //lp.y += height * 1.5; // FIXME
826        lp.setTitle("IntruderAlert");
827        lp.packageName = mContext.getPackageName();
828        lp.windowAnimations = R.style.Animation_StatusBar_IntruderAlert;
829
830        mWindowManager.addView(mIntruderAlertView, lp);
831    }
832
833    public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
834        if (SPEW) Slog.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex
835                + " icon=" + icon);
836        StatusBarIconView view = new StatusBarIconView(mContext, slot, null);
837        view.set(icon);
838        mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(mIconSize, mIconSize));
839    }
840
841    public void updateIcon(String slot, int index, int viewIndex,
842            StatusBarIcon old, StatusBarIcon icon) {
843        if (SPEW) Slog.d(TAG, "updateIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex
844                + " old=" + old + " icon=" + icon);
845        StatusBarIconView view = (StatusBarIconView)mStatusIcons.getChildAt(viewIndex);
846        view.set(icon);
847    }
848
849    public void removeIcon(String slot, int index, int viewIndex) {
850        if (SPEW) Slog.d(TAG, "removeIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex);
851        mStatusIcons.removeViewAt(viewIndex);
852    }
853
854    public void addNotification(IBinder key, StatusBarNotification notification) {
855        /* if (DEBUG) */ Slog.d(TAG, "addNotification score=" + notification.score);
856        StatusBarIconView iconView = addNotificationViews(key, notification);
857        if (iconView == null) return;
858
859        boolean immersive = false;
860        try {
861            immersive = ActivityManagerNative.getDefault().isTopActivityImmersive();
862            if (DEBUG) {
863                Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive"));
864            }
865        } catch (RemoteException ex) {
866        }
867
868        /*
869         * DISABLED due to missing API
870        if (ENABLE_INTRUDERS && (
871                   // TODO(dsandler): Only if the screen is on
872                notification.notification.intruderView != null)) {
873            Slog.d(TAG, "Presenting high-priority notification");
874            // special new transient ticker mode
875            // 1. Populate mIntruderAlertView
876
877            if (notification.notification.intruderView == null) {
878                Slog.e(TAG, notification.notification.toString() + " wanted to intrude but intruderView was null");
879                return;
880            }
881
882            // bind the click event to the content area
883            PendingIntent contentIntent = notification.notification.contentIntent;
884            final View.OnClickListener listener = (contentIntent != null)
885                    ? new NotificationClicker(contentIntent,
886                            notification.pkg, notification.tag, notification.id)
887                    : null;
888
889            mIntruderAlertView.applyIntruderContent(notification.notification.intruderView, listener);
890
891            mCurrentlyIntrudingNotification = notification;
892
893            // 2. Animate mIntruderAlertView in
894            mHandler.sendEmptyMessage(MSG_SHOW_INTRUDER);
895
896            // 3. Set alarm to age the notification off (TODO)
897            mHandler.removeMessages(MSG_HIDE_INTRUDER);
898            if (INTRUDER_ALERT_DECAY_MS > 0) {
899                mHandler.sendEmptyMessageDelayed(MSG_HIDE_INTRUDER, INTRUDER_ALERT_DECAY_MS);
900            }
901        } else
902         */
903
904        if (notification.notification.fullScreenIntent != null) {
905            // Stop screensaver if the notification has a full-screen intent.
906            // (like an incoming phone call)
907            awakenDreams();
908
909            // not immersive & a full-screen alert should be shown
910            Slog.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent");
911            try {
912                notification.notification.fullScreenIntent.send();
913            } catch (PendingIntent.CanceledException e) {
914            }
915        } else {
916            // usual case: status bar visible & not immersive
917
918            // show the ticker if there isn't an intruder too
919            if (mCurrentlyIntrudingNotification == null) {
920                tick(null, notification, true);
921            }
922        }
923
924        // Recalculate the position of the sliding windows and the titles.
925        setAreThereNotifications();
926        updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
927    }
928
929    public void removeNotification(IBinder key) {
930        StatusBarNotification old = removeNotificationViews(key);
931        if (SPEW) Slog.d(TAG, "removeNotification key=" + key + " old=" + old);
932
933        if (old != null) {
934            // Cancel the ticker if it's still running
935            mTicker.removeEntry(old);
936
937            // Recalculate the position of the sliding windows and the titles.
938            updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
939
940            if (ENABLE_INTRUDERS && old == mCurrentlyIntrudingNotification) {
941                mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER);
942            }
943
944            if (CLOSE_PANEL_WHEN_EMPTIED && mNotificationData.size() == 0 && !mAnimating) {
945                animateCollapsePanels();
946            }
947        }
948
949        setAreThereNotifications();
950    }
951
952    private void updateShowSearchHoldoff() {
953        mShowSearchHoldoff = mContext.getResources().getInteger(
954            R.integer.config_show_search_delay);
955    }
956
957    private void loadNotificationShade() {
958        if (mPile == null) return;
959
960        int N = mNotificationData.size();
961
962        ArrayList<View> toShow = new ArrayList<View>();
963
964        final boolean provisioned = isDeviceProvisioned();
965        // If the device hasn't been through Setup, we only show system notifications
966        for (int i=0; i<N; i++) {
967            Entry ent = mNotificationData.get(N-i-1);
968            if (!(provisioned || showNotificationEvenIfUnprovisioned(ent.notification))) continue;
969            if (!notificationIsForCurrentUser(ent.notification)) continue;
970            toShow.add(ent.row);
971        }
972
973        ArrayList<View> toRemove = new ArrayList<View>();
974        for (int i=0; i<mPile.getChildCount(); i++) {
975            View child = mPile.getChildAt(i);
976            if (!toShow.contains(child)) {
977                toRemove.add(child);
978            }
979        }
980
981        for (View remove : toRemove) {
982            mPile.removeView(remove);
983        }
984
985        for (int i=0; i<toShow.size(); i++) {
986            View v = toShow.get(i);
987            if (v.getParent() == null) {
988                mPile.addView(v, i);
989            }
990        }
991
992        if (mSettingsButton != null) {
993            mSettingsButton.setEnabled(isDeviceProvisioned());
994        }
995    }
996
997    @Override
998    protected void updateNotificationIcons() {
999        if (mNotificationIcons == null) return;
1000
1001        loadNotificationShade();
1002
1003        final LinearLayout.LayoutParams params
1004            = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight);
1005
1006        int N = mNotificationData.size();
1007
1008        if (DEBUG) {
1009            Slog.d(TAG, "refreshing icons: " + N + " notifications, mNotificationIcons=" + mNotificationIcons);
1010        }
1011
1012        ArrayList<View> toShow = new ArrayList<View>();
1013
1014        final boolean provisioned = isDeviceProvisioned();
1015        // If the device hasn't been through Setup, we only show system notifications
1016        for (int i=0; i<N; i++) {
1017            Entry ent = mNotificationData.get(N-i-1);
1018            if (!((provisioned && ent.notification.score >= HIDE_ICONS_BELOW_SCORE)
1019                    || showNotificationEvenIfUnprovisioned(ent.notification))) continue;
1020            if (!notificationIsForCurrentUser(ent.notification)) continue;
1021            toShow.add(ent.icon);
1022        }
1023
1024        ArrayList<View> toRemove = new ArrayList<View>();
1025        for (int i=0; i<mNotificationIcons.getChildCount(); i++) {
1026            View child = mNotificationIcons.getChildAt(i);
1027            if (!toShow.contains(child)) {
1028                toRemove.add(child);
1029            }
1030        }
1031
1032        for (View remove : toRemove) {
1033            mNotificationIcons.removeView(remove);
1034        }
1035
1036        for (int i=0; i<toShow.size(); i++) {
1037            View v = toShow.get(i);
1038            if (v.getParent() == null) {
1039                mNotificationIcons.addView(v, i, params);
1040            }
1041        }
1042    }
1043
1044    protected void updateCarrierLabelVisibility(boolean force) {
1045        if (!mShowCarrierInPanel) return;
1046        // The idea here is to only show the carrier label when there is enough room to see it,
1047        // i.e. when there aren't enough notifications to fill the panel.
1048        if (DEBUG) {
1049            Slog.d(TAG, String.format("pileh=%d scrollh=%d carrierh=%d",
1050                    mPile.getHeight(), mScrollView.getHeight(), mCarrierLabelHeight));
1051        }
1052
1053        final boolean emergencyCallsShownElsewhere = mEmergencyCallLabel != null;
1054        final boolean makeVisible =
1055            !(emergencyCallsShownElsewhere && mNetworkController.isEmergencyOnly())
1056            && mPile.getHeight() < (mNotificationPanel.getHeight() - mCarrierLabelHeight - mNotificationHeaderHeight)
1057            && mScrollView.getVisibility() == View.VISIBLE;
1058
1059        if (force || mCarrierLabelVisible != makeVisible) {
1060            mCarrierLabelVisible = makeVisible;
1061            if (DEBUG) {
1062                Slog.d(TAG, "making carrier label " + (makeVisible?"visible":"invisible"));
1063            }
1064            mCarrierLabel.animate().cancel();
1065            if (makeVisible) {
1066                mCarrierLabel.setVisibility(View.VISIBLE);
1067            }
1068            mCarrierLabel.animate()
1069                .alpha(makeVisible ? 1f : 0f)
1070                //.setStartDelay(makeVisible ? 500 : 0)
1071                //.setDuration(makeVisible ? 750 : 100)
1072                .setDuration(150)
1073                .setListener(makeVisible ? null : new AnimatorListenerAdapter() {
1074                    @Override
1075                    public void onAnimationEnd(Animator animation) {
1076                        if (!mCarrierLabelVisible) { // race
1077                            mCarrierLabel.setVisibility(View.INVISIBLE);
1078                            mCarrierLabel.setAlpha(0f);
1079                        }
1080                    }
1081                })
1082                .start();
1083        }
1084    }
1085
1086    @Override
1087    protected void setAreThereNotifications() {
1088        final boolean any = mNotificationData.size() > 0;
1089
1090        final boolean clearable = any && mNotificationData.hasClearableItems();
1091
1092        if (DEBUG) {
1093            Slog.d(TAG, "setAreThereNotifications: N=" + mNotificationData.size()
1094                    + " any=" + any + " clearable=" + clearable);
1095        }
1096
1097        if (mHasFlipSettings
1098                && mFlipSettingsView != null
1099                && mFlipSettingsView.getVisibility() == View.VISIBLE
1100                && mScrollView.getVisibility() != View.VISIBLE) {
1101            // the flip settings panel is unequivocally showing; we should not be shown
1102            mClearButton.setVisibility(View.INVISIBLE);
1103        } else if (mClearButton.isShown()) {
1104            if (clearable != (mClearButton.getAlpha() == 1.0f)) {
1105                ObjectAnimator clearAnimation = ObjectAnimator.ofFloat(
1106                        mClearButton, "alpha", clearable ? 1.0f : 0.0f).setDuration(250);
1107                clearAnimation.addListener(new AnimatorListenerAdapter() {
1108                    @Override
1109                    public void onAnimationEnd(Animator animation) {
1110                        if (mClearButton.getAlpha() <= 0.0f) {
1111                            mClearButton.setVisibility(View.INVISIBLE);
1112                        }
1113                    }
1114
1115                    @Override
1116                    public void onAnimationStart(Animator animation) {
1117                        if (mClearButton.getAlpha() <= 0.0f) {
1118                            mClearButton.setVisibility(View.VISIBLE);
1119                        }
1120                    }
1121                });
1122                clearAnimation.start();
1123            }
1124        } else {
1125            mClearButton.setAlpha(clearable ? 1.0f : 0.0f);
1126            mClearButton.setVisibility(clearable ? View.VISIBLE : View.INVISIBLE);
1127        }
1128        mClearButton.setEnabled(clearable);
1129
1130        final View nlo = mStatusBarView.findViewById(R.id.notification_lights_out);
1131        final boolean showDot = (any&&!areLightsOn());
1132        if (showDot != (nlo.getAlpha() == 1.0f)) {
1133            if (showDot) {
1134                nlo.setAlpha(0f);
1135                nlo.setVisibility(View.VISIBLE);
1136            }
1137            nlo.animate()
1138                .alpha(showDot?1:0)
1139                .setDuration(showDot?750:250)
1140                .setInterpolator(new AccelerateInterpolator(2.0f))
1141                .setListener(showDot ? null : new AnimatorListenerAdapter() {
1142                    @Override
1143                    public void onAnimationEnd(Animator _a) {
1144                        nlo.setVisibility(View.GONE);
1145                    }
1146                })
1147                .start();
1148        }
1149
1150        updateCarrierLabelVisibility(false);
1151    }
1152
1153    public void showClock(boolean show) {
1154        if (mStatusBarView == null) return;
1155        View clock = mStatusBarView.findViewById(R.id.clock);
1156        if (clock != null) {
1157            clock.setVisibility(show ? View.VISIBLE : View.GONE);
1158        }
1159    }
1160
1161    /**
1162     * State is one or more of the DISABLE constants from StatusBarManager.
1163     */
1164    public void disable(int state) {
1165        final int old = mDisabled;
1166        final int diff = state ^ old;
1167        mDisabled = state;
1168
1169        if (DEBUG) {
1170            Slog.d(TAG, String.format("disable: 0x%08x -> 0x%08x (diff: 0x%08x)",
1171                old, state, diff));
1172        }
1173
1174        StringBuilder flagdbg = new StringBuilder();
1175        flagdbg.append("disable: < ");
1176        flagdbg.append(((state & StatusBarManager.DISABLE_EXPAND) != 0) ? "EXPAND" : "expand");
1177        flagdbg.append(((diff  & StatusBarManager.DISABLE_EXPAND) != 0) ? "* " : " ");
1178        flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "ICONS" : "icons");
1179        flagdbg.append(((diff  & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "* " : " ");
1180        flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "ALERTS" : "alerts");
1181        flagdbg.append(((diff  & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "* " : " ");
1182        flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "TICKER" : "ticker");
1183        flagdbg.append(((diff  & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "* " : " ");
1184        flagdbg.append(((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "SYSTEM_INFO" : "system_info");
1185        flagdbg.append(((diff  & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "* " : " ");
1186        flagdbg.append(((state & StatusBarManager.DISABLE_BACK) != 0) ? "BACK" : "back");
1187        flagdbg.append(((diff  & StatusBarManager.DISABLE_BACK) != 0) ? "* " : " ");
1188        flagdbg.append(((state & StatusBarManager.DISABLE_HOME) != 0) ? "HOME" : "home");
1189        flagdbg.append(((diff  & StatusBarManager.DISABLE_HOME) != 0) ? "* " : " ");
1190        flagdbg.append(((state & StatusBarManager.DISABLE_RECENT) != 0) ? "RECENT" : "recent");
1191        flagdbg.append(((diff  & StatusBarManager.DISABLE_RECENT) != 0) ? "* " : " ");
1192        flagdbg.append(((state & StatusBarManager.DISABLE_CLOCK) != 0) ? "CLOCK" : "clock");
1193        flagdbg.append(((diff  & StatusBarManager.DISABLE_CLOCK) != 0) ? "* " : " ");
1194        flagdbg.append(((state & StatusBarManager.DISABLE_SEARCH) != 0) ? "SEARCH" : "search");
1195        flagdbg.append(((diff  & StatusBarManager.DISABLE_SEARCH) != 0) ? "* " : " ");
1196        flagdbg.append(">");
1197        Slog.d(TAG, flagdbg.toString());
1198
1199        if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) {
1200            mSystemIconArea.animate().cancel();
1201            if ((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) {
1202                mSystemIconArea.animate()
1203                    .alpha(0f)
1204                    .translationY(mNaturalBarHeight*0.5f)
1205                    .setDuration(175)
1206                    .setInterpolator(new DecelerateInterpolator(1.5f))
1207                    .setListener(mMakeIconsInvisible)
1208                    .start();
1209            } else {
1210                mSystemIconArea.setVisibility(View.VISIBLE);
1211                mSystemIconArea.animate()
1212                    .alpha(1f)
1213                    .translationY(0)
1214                    .setStartDelay(0)
1215                    .setInterpolator(new DecelerateInterpolator(1.5f))
1216                    .setDuration(175)
1217                    .start();
1218            }
1219        }
1220
1221        if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) {
1222            boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0;
1223            showClock(show);
1224        }
1225        if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
1226            if ((state & StatusBarManager.DISABLE_EXPAND) != 0) {
1227                animateCollapsePanels();
1228            }
1229        }
1230
1231        if ((diff & (StatusBarManager.DISABLE_HOME
1232                        | StatusBarManager.DISABLE_RECENT
1233                        | StatusBarManager.DISABLE_BACK
1234                        | StatusBarManager.DISABLE_SEARCH)) != 0) {
1235            // the nav bar will take care of these
1236            if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state);
1237
1238            if ((state & StatusBarManager.DISABLE_RECENT) != 0) {
1239                // close recents if it's visible
1240                mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
1241                mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
1242            }
1243        }
1244
1245        if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
1246            if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
1247                if (mTicking) {
1248                    haltTicker();
1249                }
1250
1251                mNotificationIcons.animate()
1252                    .alpha(0f)
1253                    .translationY(mNaturalBarHeight*0.5f)
1254                    .setDuration(175)
1255                    .setInterpolator(new DecelerateInterpolator(1.5f))
1256                    .setListener(mMakeIconsInvisible)
1257                    .start();
1258            } else {
1259                mNotificationIcons.setVisibility(View.VISIBLE);
1260                mNotificationIcons.animate()
1261                    .alpha(1f)
1262                    .translationY(0)
1263                    .setStartDelay(0)
1264                    .setInterpolator(new DecelerateInterpolator(1.5f))
1265                    .setDuration(175)
1266                    .start();
1267            }
1268        } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
1269            if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
1270                haltTicker();
1271            }
1272        }
1273    }
1274
1275    @Override
1276    protected BaseStatusBar.H createHandler() {
1277        return new PhoneStatusBar.H();
1278    }
1279
1280    /**
1281     * All changes to the status bar and notifications funnel through here and are batched.
1282     */
1283    private class H extends BaseStatusBar.H {
1284        public void handleMessage(Message m) {
1285            super.handleMessage(m);
1286            switch (m.what) {
1287                case MSG_OPEN_NOTIFICATION_PANEL:
1288                    animateExpandNotificationsPanel();
1289                    break;
1290                case MSG_OPEN_SETTINGS_PANEL:
1291                    animateExpandSettingsPanel();
1292                    break;
1293                case MSG_CLOSE_PANELS:
1294                    animateCollapsePanels();
1295                    break;
1296                case MSG_SHOW_INTRUDER:
1297                    setIntruderAlertVisibility(true);
1298                    break;
1299                case MSG_HIDE_INTRUDER:
1300                    setIntruderAlertVisibility(false);
1301                    mCurrentlyIntrudingNotification = null;
1302                    break;
1303            }
1304        }
1305    }
1306
1307    public Handler getHandler() {
1308        return mHandler;
1309    }
1310
1311    View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() {
1312        public void onFocusChange(View v, boolean hasFocus) {
1313            // Because 'v' is a ViewGroup, all its children will be (un)selected
1314            // too, which allows marqueeing to work.
1315            v.setSelected(hasFocus);
1316        }
1317    };
1318
1319    void makeExpandedVisible(boolean revealAfterDraw) {
1320        if (SPEW) Slog.d(TAG, "Make expanded visible: expanded visible=" + mExpandedVisible);
1321        if (mExpandedVisible) {
1322            return;
1323        }
1324
1325        mExpandedVisible = true;
1326        mPile.setLayoutTransitionsEnabled(true);
1327        if (mNavigationBarView != null)
1328            mNavigationBarView.setSlippery(true);
1329
1330        updateCarrierLabelVisibility(true);
1331
1332        updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
1333
1334        // Expand the window to encompass the full screen in anticipation of the drag.
1335        // This is only possible to do atomically because the status bar is at the top of the screen!
1336        WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams();
1337        lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
1338        lp.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
1339        lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
1340        mWindowManager.updateViewLayout(mStatusBarWindow, lp);
1341
1342        // Updating the window layout will force an expensive traversal/redraw.
1343        // Kick off the reveal animation after this is complete to avoid animation latency.
1344        if (revealAfterDraw) {
1345//            mHandler.post(mStartRevealAnimation);
1346        }
1347
1348        visibilityChanged(true);
1349    }
1350
1351    public void animateCollapsePanels() {
1352        animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
1353    }
1354
1355    public void animateCollapsePanels(int flags) {
1356        if (SPEW) {
1357            Slog.d(TAG, "animateCollapse():"
1358                    + " mExpandedVisible=" + mExpandedVisible
1359                    + " mAnimating=" + mAnimating
1360                    + " mAnimatingReveal=" + mAnimatingReveal
1361                    + " mAnimY=" + mAnimY
1362                    + " mAnimVel=" + mAnimVel
1363                    + " flags=" + flags);
1364        }
1365
1366        if ((flags & CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL) == 0) {
1367            mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
1368            mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
1369        }
1370
1371        if ((flags & CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL) == 0) {
1372            mHandler.removeMessages(MSG_CLOSE_SEARCH_PANEL);
1373            mHandler.sendEmptyMessage(MSG_CLOSE_SEARCH_PANEL);
1374        }
1375
1376        mStatusBarView.collapseAllPanels(true);
1377    }
1378
1379    public ViewPropertyAnimator setVisibilityWhenDone(
1380            final ViewPropertyAnimator a, final View v, final int vis) {
1381        a.setListener(new AnimatorListenerAdapter() {
1382            @Override
1383            public void onAnimationEnd(Animator animation) {
1384                v.setVisibility(vis);
1385                a.setListener(null); // oneshot
1386            }
1387        });
1388        return a;
1389    }
1390
1391    public Animator setVisibilityWhenDone(
1392            final Animator a, final View v, final int vis) {
1393        a.addListener(new AnimatorListenerAdapter() {
1394            @Override
1395            public void onAnimationEnd(Animator animation) {
1396                v.setVisibility(vis);
1397            }
1398        });
1399        return a;
1400    }
1401
1402    public Animator interpolator(TimeInterpolator ti, Animator a) {
1403        a.setInterpolator(ti);
1404        return a;
1405    }
1406
1407    public Animator startDelay(int d, Animator a) {
1408        a.setStartDelay(d);
1409        return a;
1410    }
1411
1412    public Animator start(Animator a) {
1413        a.start();
1414        return a;
1415    }
1416
1417    final TimeInterpolator mAccelerateInterpolator = new AccelerateInterpolator();
1418    final TimeInterpolator mDecelerateInterpolator = new DecelerateInterpolator();
1419    final int FLIP_DURATION_OUT = 125;
1420    final int FLIP_DURATION_IN = 225;
1421    final int FLIP_DURATION = (FLIP_DURATION_IN + FLIP_DURATION_OUT);
1422
1423    Animator mScrollViewAnim, mFlipSettingsViewAnim, mNotificationButtonAnim,
1424        mSettingsButtonAnim, mClearButtonAnim;
1425
1426    @Override
1427    public void animateExpandNotificationsPanel() {
1428        if (SPEW) Slog.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible);
1429        if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
1430            return ;
1431        }
1432
1433        mNotificationPanel.expand();
1434        if (mHasFlipSettings && mScrollView.getVisibility() != View.VISIBLE) {
1435            flipToNotifications();
1436        }
1437
1438        if (false) postStartTracing();
1439    }
1440
1441    public void flipToNotifications() {
1442        if (mFlipSettingsViewAnim != null) mFlipSettingsViewAnim.cancel();
1443        if (mScrollViewAnim != null) mScrollViewAnim.cancel();
1444        if (mSettingsButtonAnim != null) mSettingsButtonAnim.cancel();
1445        if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel();
1446        if (mClearButtonAnim != null) mClearButtonAnim.cancel();
1447
1448        mScrollView.setVisibility(View.VISIBLE);
1449        mScrollViewAnim = start(
1450            startDelay(FLIP_DURATION_OUT,
1451                interpolator(mDecelerateInterpolator,
1452                    ObjectAnimator.ofFloat(mScrollView, View.SCALE_X, 0f, 1f)
1453                        .setDuration(FLIP_DURATION_IN)
1454                    )));
1455        mFlipSettingsViewAnim = start(
1456            setVisibilityWhenDone(
1457                interpolator(mAccelerateInterpolator,
1458                        ObjectAnimator.ofFloat(mFlipSettingsView, View.SCALE_X, 1f, 0f)
1459                        )
1460                    .setDuration(FLIP_DURATION_OUT),
1461                mFlipSettingsView, View.INVISIBLE));
1462        mNotificationButtonAnim = start(
1463            setVisibilityWhenDone(
1464                ObjectAnimator.ofFloat(mNotificationButton, View.ALPHA, 0f)
1465                    .setDuration(FLIP_DURATION),
1466                mNotificationButton, View.INVISIBLE));
1467        mSettingsButton.setVisibility(View.VISIBLE);
1468        mSettingsButtonAnim = start(
1469            ObjectAnimator.ofFloat(mSettingsButton, View.ALPHA, 1f)
1470                .setDuration(FLIP_DURATION));
1471        mClearButton.setVisibility(View.VISIBLE);
1472        mClearButton.setAlpha(0f);
1473        setAreThereNotifications(); // this will show/hide the button as necessary
1474        mNotificationPanel.postDelayed(new Runnable() {
1475            public void run() {
1476                updateCarrierLabelVisibility(false);
1477            }
1478        }, FLIP_DURATION - 150);
1479    }
1480
1481    @Override
1482    public void animateExpandSettingsPanel() {
1483        if (SPEW) Slog.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible);
1484        if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
1485            return;
1486        }
1487
1488        if (mHasFlipSettings) {
1489            mNotificationPanel.expand();
1490            if (mFlipSettingsView.getVisibility() != View.VISIBLE) {
1491                flipToSettings();
1492            }
1493        } else if (mSettingsPanel != null) {
1494            mSettingsPanel.expand();
1495        }
1496
1497        if (false) postStartTracing();
1498    }
1499
1500    public void switchToSettings() {
1501        mFlipSettingsView.setScaleX(1f);
1502        mFlipSettingsView.setVisibility(View.VISIBLE);
1503        mSettingsButton.setVisibility(View.GONE);
1504        mScrollView.setVisibility(View.GONE);
1505        mScrollView.setScaleX(0f);
1506        mNotificationButton.setVisibility(View.VISIBLE);
1507        mNotificationButton.setAlpha(1f);
1508        mClearButton.setVisibility(View.GONE);
1509    }
1510
1511    public void flipToSettings() {
1512        if (mFlipSettingsViewAnim != null) mFlipSettingsViewAnim.cancel();
1513        if (mScrollViewAnim != null) mScrollViewAnim.cancel();
1514        if (mSettingsButtonAnim != null) mSettingsButtonAnim.cancel();
1515        if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel();
1516        if (mClearButtonAnim != null) mClearButtonAnim.cancel();
1517
1518        mFlipSettingsView.setVisibility(View.VISIBLE);
1519        mFlipSettingsView.setScaleX(0f);
1520        mFlipSettingsViewAnim = start(
1521            startDelay(FLIP_DURATION_OUT,
1522                interpolator(mDecelerateInterpolator,
1523                    ObjectAnimator.ofFloat(mFlipSettingsView, View.SCALE_X, 0f, 1f)
1524                        .setDuration(FLIP_DURATION_IN)
1525                    )));
1526        mScrollViewAnim = start(
1527            setVisibilityWhenDone(
1528                interpolator(mAccelerateInterpolator,
1529                        ObjectAnimator.ofFloat(mScrollView, View.SCALE_X, 1f, 0f)
1530                        )
1531                    .setDuration(FLIP_DURATION_OUT),
1532                mScrollView, View.INVISIBLE));
1533        mSettingsButtonAnim = start(
1534            setVisibilityWhenDone(
1535                ObjectAnimator.ofFloat(mSettingsButton, View.ALPHA, 0f)
1536                    .setDuration(FLIP_DURATION),
1537                    mScrollView, View.INVISIBLE));
1538        mNotificationButton.setVisibility(View.VISIBLE);
1539        mNotificationButtonAnim = start(
1540            ObjectAnimator.ofFloat(mNotificationButton, View.ALPHA, 1f)
1541                .setDuration(FLIP_DURATION));
1542        mClearButtonAnim = start(
1543            setVisibilityWhenDone(
1544                ObjectAnimator.ofFloat(mClearButton, View.ALPHA, 0f)
1545                .setDuration(FLIP_DURATION),
1546                mClearButton, View.INVISIBLE));
1547        mNotificationPanel.postDelayed(new Runnable() {
1548            public void run() {
1549                updateCarrierLabelVisibility(false);
1550            }
1551        }, FLIP_DURATION - 150);
1552    }
1553
1554    public void flipPanels() {
1555        if (mHasFlipSettings) {
1556            if (mFlipSettingsView.getVisibility() != View.VISIBLE) {
1557                flipToSettings();
1558            } else {
1559                flipToNotifications();
1560            }
1561        }
1562    }
1563
1564    public void animateCollapseQuickSettings() {
1565        mStatusBarView.collapseAllPanels(true);
1566    }
1567
1568    void makeExpandedInvisibleSoon() {
1569        mHandler.postDelayed(new Runnable() { public void run() { makeExpandedInvisible(); }}, 50);
1570    }
1571
1572    void makeExpandedInvisible() {
1573        if (SPEW) Slog.d(TAG, "makeExpandedInvisible: mExpandedVisible=" + mExpandedVisible
1574                + " mExpandedVisible=" + mExpandedVisible);
1575
1576        if (!mExpandedVisible) {
1577            return;
1578        }
1579
1580        // Ensure the panel is fully collapsed (just in case; bug 6765842, 7260868)
1581        mStatusBarView.collapseAllPanels(/*animate=*/ false);
1582
1583        if (mHasFlipSettings) {
1584            // reset things to their proper state
1585            if (mFlipSettingsViewAnim != null) mFlipSettingsViewAnim.cancel();
1586            if (mScrollViewAnim != null) mScrollViewAnim.cancel();
1587            if (mSettingsButtonAnim != null) mSettingsButtonAnim.cancel();
1588            if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel();
1589            if (mClearButtonAnim != null) mClearButtonAnim.cancel();
1590
1591            mScrollView.setScaleX(1f);
1592            mScrollView.setVisibility(View.VISIBLE);
1593            mSettingsButton.setAlpha(1f);
1594            mSettingsButton.setVisibility(View.VISIBLE);
1595            mNotificationPanel.setVisibility(View.GONE);
1596            mFlipSettingsView.setVisibility(View.GONE);
1597            mNotificationButton.setVisibility(View.GONE);
1598            setAreThereNotifications(); // show the clear button
1599        }
1600
1601        mExpandedVisible = false;
1602        mPile.setLayoutTransitionsEnabled(false);
1603        if (mNavigationBarView != null)
1604            mNavigationBarView.setSlippery(false);
1605        visibilityChanged(false);
1606
1607        // Shrink the window to the size of the status bar only
1608        WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams();
1609        lp.height = getStatusBarHeight();
1610        lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
1611        lp.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
1612        mWindowManager.updateViewLayout(mStatusBarWindow, lp);
1613
1614        if ((mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS) == 0) {
1615            setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in);
1616        }
1617
1618        // Close any "App info" popups that might have snuck on-screen
1619        dismissPopups();
1620
1621        if (mPostCollapseCleanup != null) {
1622            mPostCollapseCleanup.run();
1623            mPostCollapseCleanup = null;
1624        }
1625    }
1626
1627    /**
1628     * Enables or disables layers on the children of the notifications pile.
1629     *
1630     * When layers are enabled, this method attempts to enable layers for the minimal
1631     * number of children. Only children visible when the notification area is fully
1632     * expanded will receive a layer. The technique used in this method might cause
1633     * more children than necessary to get a layer (at most one extra child with the
1634     * current UI.)
1635     *
1636     * @param layerType {@link View#LAYER_TYPE_NONE} or {@link View#LAYER_TYPE_HARDWARE}
1637     */
1638    private void setPileLayers(int layerType) {
1639        final int count = mPile.getChildCount();
1640
1641        switch (layerType) {
1642            case View.LAYER_TYPE_NONE:
1643                for (int i = 0; i < count; i++) {
1644                    mPile.getChildAt(i).setLayerType(layerType, null);
1645                }
1646                break;
1647            case View.LAYER_TYPE_HARDWARE:
1648                final int[] location = new int[2];
1649                mNotificationPanel.getLocationInWindow(location);
1650
1651                final int left = location[0];
1652                final int top = location[1];
1653                final int right = left + mNotificationPanel.getWidth();
1654                final int bottom = top + getExpandedViewMaxHeight();
1655
1656                final Rect childBounds = new Rect();
1657
1658                for (int i = 0; i < count; i++) {
1659                    final View view = mPile.getChildAt(i);
1660                    view.getLocationInWindow(location);
1661
1662                    childBounds.set(location[0], location[1],
1663                            location[0] + view.getWidth(), location[1] + view.getHeight());
1664
1665                    if (childBounds.intersects(left, top, right, bottom)) {
1666                        view.setLayerType(layerType, null);
1667                    }
1668                }
1669
1670                break;
1671        }
1672    }
1673
1674    public boolean isClinging() {
1675        return mCling != null && mCling.getVisibility() == View.VISIBLE;
1676    }
1677
1678    public void hideCling() {
1679        if (isClinging()) {
1680            mCling.animate().alpha(0f).setDuration(250).start();
1681            mCling.setVisibility(View.GONE);
1682            mSuppressStatusBarDrags = false;
1683        }
1684    }
1685
1686    public void showCling() {
1687        // lazily inflate this to accommodate orientation change
1688        final ViewStub stub = (ViewStub) mStatusBarWindow.findViewById(R.id.status_bar_cling_stub);
1689        if (stub == null) {
1690            mClingShown = true;
1691            return; // no clings on this device
1692        }
1693
1694        mSuppressStatusBarDrags = true;
1695
1696        mHandler.postDelayed(new Runnable() {
1697            @Override
1698            public void run() {
1699                mCling = (ViewGroup) stub.inflate();
1700
1701                mCling.setOnTouchListener(new View.OnTouchListener() {
1702                    @Override
1703                    public boolean onTouch(View v, MotionEvent event) {
1704                        return true; // e eats everything
1705                    }});
1706                mCling.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
1707                    @Override
1708                    public void onClick(View v) {
1709                        hideCling();
1710                    }});
1711
1712                mCling.setAlpha(0f);
1713                mCling.setVisibility(View.VISIBLE);
1714                mCling.animate().alpha(1f);
1715
1716                mClingShown = true;
1717                SharedPreferences.Editor editor = Prefs.edit(mContext);
1718                editor.putBoolean(Prefs.SHOWN_QUICK_SETTINGS_HELP, true);
1719                editor.apply();
1720
1721                makeExpandedVisible(true); // enforce visibility in case the shade is still animating closed
1722                animateExpandNotificationsPanel();
1723
1724                mSuppressStatusBarDrags = false;
1725            }
1726        }, 500);
1727
1728        animateExpandNotificationsPanel();
1729    }
1730
1731    public boolean interceptTouchEvent(MotionEvent event) {
1732        if (SPEW) {
1733            Slog.d(TAG, "Touch: rawY=" + event.getRawY() + " event=" + event + " mDisabled="
1734                + mDisabled + " mTracking=" + mTracking);
1735        } else if (CHATTY) {
1736            if (event.getAction() != MotionEvent.ACTION_MOVE) {
1737                Slog.d(TAG, String.format(
1738                            "panel: %s at (%f, %f) mDisabled=0x%08x",
1739                            MotionEvent.actionToString(event.getAction()),
1740                            event.getRawX(), event.getRawY(), mDisabled));
1741            }
1742        }
1743
1744        if (DEBUG_GESTURES) {
1745            mGestureRec.add(event);
1746        }
1747
1748        // Cling (first-run help) handling.
1749        // The cling is supposed to show the first time you drag, or even tap, the status bar.
1750        // It should show the notification panel, then fade in after half a second, giving you
1751        // an explanation of what just happened, as well as teach you how to access quick
1752        // settings (another drag). The user can dismiss the cling by clicking OK or by
1753        // dragging quick settings into view.
1754        final int act = event.getActionMasked();
1755        if (mSuppressStatusBarDrags) {
1756            return true;
1757        } else if (act == MotionEvent.ACTION_UP && !mClingShown) {
1758            showCling();
1759        } else {
1760            hideCling();
1761        }
1762
1763        return false;
1764    }
1765
1766    public GestureRecorder getGestureRecorder() {
1767        return mGestureRec;
1768    }
1769
1770    @Override // CommandQueue
1771    public void setNavigationIconHints(int hints) {
1772        if (hints == mNavigationIconHints) return;
1773
1774        mNavigationIconHints = hints;
1775
1776        if (mNavigationBarView != null) {
1777            mNavigationBarView.setNavigationIconHints(hints);
1778        }
1779    }
1780
1781    @Override // CommandQueue
1782    public void setSystemUiVisibility(int vis, int mask) {
1783        final int oldVal = mSystemUiVisibility;
1784        final int newVal = (oldVal&~mask) | (vis&mask);
1785        final int diff = newVal ^ oldVal;
1786
1787        if (diff != 0) {
1788            mSystemUiVisibility = newVal;
1789
1790            if (0 != (diff & View.SYSTEM_UI_FLAG_LOW_PROFILE)) {
1791                final boolean lightsOut = (0 != (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE));
1792                if (lightsOut) {
1793                    animateCollapsePanels();
1794                    if (mTicking) {
1795                        haltTicker();
1796                    }
1797                }
1798
1799                if (mNavigationBarView != null) {
1800                    mNavigationBarView.setLowProfile(lightsOut);
1801                }
1802
1803                setStatusBarLowProfile(lightsOut);
1804            }
1805
1806            notifyUiVisibilityChanged();
1807        }
1808    }
1809
1810    private void setStatusBarLowProfile(boolean lightsOut) {
1811        if (mLightsOutAnimation == null) {
1812            final View notifications = mStatusBarView.findViewById(R.id.notification_icon_area);
1813            final View systemIcons = mStatusBarView.findViewById(R.id.statusIcons);
1814            final View signal = mStatusBarView.findViewById(R.id.signal_cluster);
1815            final View battery = mStatusBarView.findViewById(R.id.battery);
1816            final View clock = mStatusBarView.findViewById(R.id.clock);
1817
1818            final AnimatorSet lightsOutAnim = new AnimatorSet();
1819            lightsOutAnim.playTogether(
1820                    ObjectAnimator.ofFloat(notifications, View.ALPHA, 0),
1821                    ObjectAnimator.ofFloat(systemIcons, View.ALPHA, 0),
1822                    ObjectAnimator.ofFloat(signal, View.ALPHA, 0),
1823                    ObjectAnimator.ofFloat(battery, View.ALPHA, 0.5f),
1824                    ObjectAnimator.ofFloat(clock, View.ALPHA, 0.5f)
1825                );
1826            lightsOutAnim.setDuration(750);
1827
1828            final AnimatorSet lightsOnAnim = new AnimatorSet();
1829            lightsOnAnim.playTogether(
1830                    ObjectAnimator.ofFloat(notifications, View.ALPHA, 1),
1831                    ObjectAnimator.ofFloat(systemIcons, View.ALPHA, 1),
1832                    ObjectAnimator.ofFloat(signal, View.ALPHA, 1),
1833                    ObjectAnimator.ofFloat(battery, View.ALPHA, 1),
1834                    ObjectAnimator.ofFloat(clock, View.ALPHA, 1)
1835                );
1836            lightsOnAnim.setDuration(250);
1837
1838            mLightsOutAnimation = lightsOutAnim;
1839            mLightsOnAnimation = lightsOnAnim;
1840        }
1841
1842        mLightsOutAnimation.cancel();
1843        mLightsOnAnimation.cancel();
1844
1845        final Animator a = lightsOut ? mLightsOutAnimation : mLightsOnAnimation;
1846        a.start();
1847
1848        setAreThereNotifications();
1849    }
1850
1851    private boolean areLightsOn() {
1852        return 0 == (mSystemUiVisibility & View.SYSTEM_UI_FLAG_LOW_PROFILE);
1853    }
1854
1855    public void setLightsOn(boolean on) {
1856        Log.v(TAG, "setLightsOn(" + on + ")");
1857        if (on) {
1858            setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE);
1859        } else {
1860            setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE, View.SYSTEM_UI_FLAG_LOW_PROFILE);
1861        }
1862    }
1863
1864    private void notifyUiVisibilityChanged() {
1865        try {
1866            mWindowManagerService.statusBarVisibilityChanged(mSystemUiVisibility);
1867        } catch (RemoteException ex) {
1868        }
1869    }
1870
1871    public void topAppWindowChanged(boolean showMenu) {
1872        if (DEBUG) {
1873            Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button");
1874        }
1875        if (mNavigationBarView != null) {
1876            mNavigationBarView.setMenuVisibility(showMenu);
1877        }
1878
1879        // See above re: lights-out policy for legacy apps.
1880        if (showMenu) setLightsOn(true);
1881    }
1882
1883    @Override
1884    public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
1885        boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS)
1886            || ((vis & InputMethodService.IME_VISIBLE) != 0);
1887
1888        mCommandQueue.setNavigationIconHints(
1889                altBack ? (mNavigationIconHints | StatusBarManager.NAVIGATION_HINT_BACK_ALT)
1890                        : (mNavigationIconHints & ~StatusBarManager.NAVIGATION_HINT_BACK_ALT));
1891        if (mQS != null) mQS.setImeWindowStatus(vis > 0);
1892    }
1893
1894    @Override
1895    public void setHardKeyboardStatus(boolean available, boolean enabled) {}
1896
1897    @Override
1898    protected void tick(IBinder key, StatusBarNotification n, boolean firstTime) {
1899        // no ticking in lights-out mode
1900        if (!areLightsOn()) return;
1901
1902        // no ticking in Setup
1903        if (!isDeviceProvisioned()) return;
1904
1905        // not for you
1906        if (!notificationIsForCurrentUser(n)) return;
1907
1908        // Show the ticker if one is requested. Also don't do this
1909        // until status bar window is attached to the window manager,
1910        // because...  well, what's the point otherwise?  And trying to
1911        // run a ticker without being attached will crash!
1912        if (n.notification.tickerText != null && mStatusBarWindow.getWindowToken() != null) {
1913            if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS
1914                            | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) {
1915                mTicker.addEntry(n);
1916            }
1917        }
1918    }
1919
1920    private class MyTicker extends Ticker {
1921        MyTicker(Context context, View sb) {
1922            super(context, sb);
1923        }
1924
1925        @Override
1926        public void tickerStarting() {
1927            mTicking = true;
1928            mStatusBarContents.setVisibility(View.GONE);
1929            mTickerView.setVisibility(View.VISIBLE);
1930            mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_up_in, null));
1931            mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.push_up_out, null));
1932        }
1933
1934        @Override
1935        public void tickerDone() {
1936            mStatusBarContents.setVisibility(View.VISIBLE);
1937            mTickerView.setVisibility(View.GONE);
1938            mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.push_down_in, null));
1939            mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_down_out,
1940                        mTickingDoneListener));
1941        }
1942
1943        public void tickerHalting() {
1944            mStatusBarContents.setVisibility(View.VISIBLE);
1945            mTickerView.setVisibility(View.GONE);
1946            mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.fade_in, null));
1947            // we do not animate the ticker away at this point, just get rid of it (b/6992707)
1948        }
1949    }
1950
1951    Animation.AnimationListener mTickingDoneListener = new Animation.AnimationListener() {;
1952        public void onAnimationEnd(Animation animation) {
1953            mTicking = false;
1954        }
1955        public void onAnimationRepeat(Animation animation) {
1956        }
1957        public void onAnimationStart(Animation animation) {
1958        }
1959    };
1960
1961    private Animation loadAnim(int id, Animation.AnimationListener listener) {
1962        Animation anim = AnimationUtils.loadAnimation(mContext, id);
1963        if (listener != null) {
1964            anim.setAnimationListener(listener);
1965        }
1966        return anim;
1967    }
1968
1969    public static String viewInfo(View v) {
1970        return "[(" + v.getLeft() + "," + v.getTop() + ")(" + v.getRight() + "," + v.getBottom()
1971                + ") " + v.getWidth() + "x" + v.getHeight() + "]";
1972    }
1973
1974    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1975        synchronized (mQueueLock) {
1976            pw.println("Current Status Bar state:");
1977            pw.println("  mExpandedVisible=" + mExpandedVisible
1978                    + ", mTrackingPosition=" + mTrackingPosition);
1979            pw.println("  mTicking=" + mTicking);
1980            pw.println("  mTracking=" + mTracking);
1981            pw.println("  mNotificationPanel=" +
1982                    ((mNotificationPanel == null)
1983                            ? "null"
1984                            : (mNotificationPanel + " params=" + mNotificationPanel.getLayoutParams().debug(""))));
1985            pw.println("  mAnimating=" + mAnimating
1986                    + ", mAnimY=" + mAnimY + ", mAnimVel=" + mAnimVel
1987                    + ", mAnimAccel=" + mAnimAccel);
1988            pw.println("  mAnimLastTimeNanos=" + mAnimLastTimeNanos);
1989            pw.println("  mAnimatingReveal=" + mAnimatingReveal
1990                    + " mViewDelta=" + mViewDelta);
1991            pw.println("  mDisplayMetrics=" + mDisplayMetrics);
1992            pw.println("  mPile: " + viewInfo(mPile));
1993            pw.println("  mTickerView: " + viewInfo(mTickerView));
1994            pw.println("  mScrollView: " + viewInfo(mScrollView)
1995                    + " scroll " + mScrollView.getScrollX() + "," + mScrollView.getScrollY());
1996        }
1997
1998        pw.print("  mNavigationBarView=");
1999        if (mNavigationBarView == null) {
2000            pw.println("null");
2001        } else {
2002            mNavigationBarView.dump(fd, pw, args);
2003        }
2004
2005        if (DUMPTRUCK) {
2006            synchronized (mNotificationData) {
2007                int N = mNotificationData.size();
2008                pw.println("  notification icons: " + N);
2009                for (int i=0; i<N; i++) {
2010                    NotificationData.Entry e = mNotificationData.get(i);
2011                    pw.println("    [" + i + "] key=" + e.key + " icon=" + e.icon);
2012                    StatusBarNotification n = e.notification;
2013                    pw.println("         pkg=" + n.pkg + " id=" + n.id + " score=" + n.score);
2014                    pw.println("         notification=" + n.notification);
2015                    pw.println("         tickerText=\"" + n.notification.tickerText + "\"");
2016                }
2017            }
2018
2019            int N = mStatusIcons.getChildCount();
2020            pw.println("  system icons: " + N);
2021            for (int i=0; i<N; i++) {
2022                StatusBarIconView ic = (StatusBarIconView) mStatusIcons.getChildAt(i);
2023                pw.println("    [" + i + "] icon=" + ic);
2024            }
2025
2026            if (false) {
2027                pw.println("see the logcat for a dump of the views we have created.");
2028                // must happen on ui thread
2029                mHandler.post(new Runnable() {
2030                        public void run() {
2031                            mStatusBarView.getLocationOnScreen(mAbsPos);
2032                            Slog.d(TAG, "mStatusBarView: ----- (" + mAbsPos[0] + "," + mAbsPos[1]
2033                                    + ") " + mStatusBarView.getWidth() + "x"
2034                                    + getStatusBarHeight());
2035                            mStatusBarView.debug();
2036                        }
2037                    });
2038            }
2039        }
2040
2041        if (DEBUG_GESTURES) {
2042            pw.print("  status bar gestures: ");
2043            mGestureRec.dump(fd, pw, args);
2044        }
2045
2046        mNetworkController.dump(fd, pw, args);
2047    }
2048
2049    @Override
2050    public void createAndAddWindows() {
2051        addStatusBarWindow();
2052    }
2053
2054    private void addStatusBarWindow() {
2055        // Put up the view
2056        final int height = getStatusBarHeight();
2057
2058        // Now that the status bar window encompasses the sliding panel and its
2059        // translucent backdrop, the entire thing is made TRANSLUCENT and is
2060        // hardware-accelerated.
2061        final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
2062                ViewGroup.LayoutParams.MATCH_PARENT,
2063                height,
2064                WindowManager.LayoutParams.TYPE_STATUS_BAR,
2065                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2066                    | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
2067                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
2068                PixelFormat.TRANSLUCENT);
2069
2070        lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
2071
2072        lp.gravity = getStatusBarGravity();
2073        lp.setTitle("StatusBar");
2074        lp.packageName = mContext.getPackageName();
2075
2076        makeStatusBarView();
2077        mWindowManager.addView(mStatusBarWindow, lp);
2078    }
2079
2080    void setNotificationIconVisibility(boolean visible, int anim) {
2081        int old = mNotificationIcons.getVisibility();
2082        int v = visible ? View.VISIBLE : View.INVISIBLE;
2083        if (old != v) {
2084            mNotificationIcons.setVisibility(v);
2085            mNotificationIcons.startAnimation(loadAnim(anim, null));
2086        }
2087    }
2088
2089    void updateExpandedInvisiblePosition() {
2090        mTrackingPosition = -mDisplayMetrics.heightPixels;
2091    }
2092
2093    static final float saturate(float a) {
2094        return a < 0f ? 0f : (a > 1f ? 1f : a);
2095    }
2096
2097    @Override
2098    protected int getExpandedViewMaxHeight() {
2099        return mDisplayMetrics.heightPixels - mNotificationPanelMarginBottomPx;
2100    }
2101
2102    @Override
2103    public void updateExpandedViewPos(int thingy) {
2104        if (DEBUG) Slog.v(TAG, "updateExpandedViewPos");
2105
2106        // on larger devices, the notification panel is propped open a bit
2107        mNotificationPanel.setMinimumHeight(
2108                (int)(mNotificationPanelMinHeightFrac * mCurrentDisplaySize.y));
2109
2110        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mNotificationPanel.getLayoutParams();
2111        lp.gravity = mNotificationPanelGravity;
2112        lp.leftMargin = mNotificationPanelMarginPx;
2113        mNotificationPanel.setLayoutParams(lp);
2114
2115        if (mSettingsPanel != null) {
2116            lp = (FrameLayout.LayoutParams) mSettingsPanel.getLayoutParams();
2117            lp.gravity = mSettingsPanelGravity;
2118            lp.rightMargin = mNotificationPanelMarginPx;
2119            mSettingsPanel.setLayoutParams(lp);
2120        }
2121
2122        updateCarrierLabelVisibility(false);
2123    }
2124
2125    // called by makeStatusbar and also by PhoneStatusBarView
2126    void updateDisplaySize() {
2127        mDisplay.getMetrics(mDisplayMetrics);
2128        if (DEBUG_GESTURES) {
2129            mGestureRec.tag("display",
2130                    String.format("%dx%d", mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels));
2131        }
2132    }
2133
2134    private View.OnClickListener mClearButtonListener = new View.OnClickListener() {
2135        public void onClick(View v) {
2136            synchronized (mNotificationData) {
2137                // animate-swipe all dismissable notifications, then animate the shade closed
2138                int numChildren = mPile.getChildCount();
2139
2140                int scrollTop = mScrollView.getScrollY();
2141                int scrollBottom = scrollTop + mScrollView.getHeight();
2142                final ArrayList<View> snapshot = new ArrayList<View>(numChildren);
2143                for (int i=0; i<numChildren; i++) {
2144                    final View child = mPile.getChildAt(i);
2145                    if (mPile.canChildBeDismissed(child) && child.getBottom() > scrollTop &&
2146                            child.getTop() < scrollBottom) {
2147                        snapshot.add(child);
2148                    }
2149                }
2150                if (snapshot.isEmpty()) {
2151                    animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
2152                    return;
2153                }
2154                new Thread(new Runnable() {
2155                    @Override
2156                    public void run() {
2157                        // Decrease the delay for every row we animate to give the sense of
2158                        // accelerating the swipes
2159                        final int ROW_DELAY_DECREMENT = 10;
2160                        int currentDelay = 140;
2161                        int totalDelay = 0;
2162
2163                        // Set the shade-animating state to avoid doing other work during
2164                        // all of these animations. In particular, avoid layout and
2165                        // redrawing when collapsing the shade.
2166                        mPile.setViewRemoval(false);
2167
2168                        mPostCollapseCleanup = new Runnable() {
2169                            @Override
2170                            public void run() {
2171                                if (DEBUG) {
2172                                    Slog.v(TAG, "running post-collapse cleanup");
2173                                }
2174                                try {
2175                                    mPile.setViewRemoval(true);
2176                                    mBarService.onClearAllNotifications();
2177                                } catch (Exception ex) { }
2178                            }
2179                        };
2180
2181                        View sampleView = snapshot.get(0);
2182                        int width = sampleView.getWidth();
2183                        final int velocity = width * 8; // 1000/8 = 125 ms duration
2184                        for (final View _v : snapshot) {
2185                            mHandler.postDelayed(new Runnable() {
2186                                @Override
2187                                public void run() {
2188                                    mPile.dismissRowAnimated(_v, velocity);
2189                                }
2190                            }, totalDelay);
2191                            currentDelay = Math.max(50, currentDelay - ROW_DELAY_DECREMENT);
2192                            totalDelay += currentDelay;
2193                        }
2194                        // Delay the collapse animation until after all swipe animations have
2195                        // finished. Provide some buffer because there may be some extra delay
2196                        // before actually starting each swipe animation. Ideally, we'd
2197                        // synchronize the end of those animations with the start of the collaps
2198                        // exactly.
2199                        mHandler.postDelayed(new Runnable() {
2200                            @Override
2201                            public void run() {
2202                                animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
2203                            }
2204                        }, totalDelay + 225);
2205                    }
2206                }).start();
2207            }
2208        }
2209    };
2210
2211    public void startActivityDismissingKeyguard(Intent intent, boolean onlyProvisioned) {
2212        if (onlyProvisioned && !isDeviceProvisioned()) return;
2213        try {
2214            // Dismiss the lock screen when Settings starts.
2215            ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
2216        } catch (RemoteException e) {
2217        }
2218        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2219        mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
2220        animateCollapsePanels();
2221    }
2222
2223    private View.OnClickListener mSettingsButtonListener = new View.OnClickListener() {
2224        public void onClick(View v) {
2225            if (mHasSettingsPanel) {
2226                animateExpandSettingsPanel();
2227            } else {
2228                startActivityDismissingKeyguard(
2229                        new Intent(android.provider.Settings.ACTION_SETTINGS), true);
2230            }
2231        }
2232    };
2233
2234    private View.OnClickListener mClockClickListener = new View.OnClickListener() {
2235        public void onClick(View v) {
2236            startActivityDismissingKeyguard(
2237                    new Intent(Intent.ACTION_QUICK_CLOCK), true); // have fun, everyone
2238        }
2239    };
2240
2241    private View.OnClickListener mNotificationButtonListener = new View.OnClickListener() {
2242        public void onClick(View v) {
2243            animateExpandNotificationsPanel();
2244        }
2245    };
2246
2247    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
2248        public void onReceive(Context context, Intent intent) {
2249            Slog.v(TAG, "onReceive: " + intent);
2250            String action = intent.getAction();
2251            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
2252                int flags = CommandQueue.FLAG_EXCLUDE_NONE;
2253                if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
2254                    String reason = intent.getStringExtra("reason");
2255                    if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
2256                        flags |= CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL;
2257                    }
2258                }
2259                animateCollapsePanels(flags);
2260            }
2261            else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
2262                // no waiting!
2263                makeExpandedInvisible();
2264                notifyNavigationBarScreenOn(false);
2265            }
2266            else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
2267                if (DEBUG) {
2268                    Slog.v(TAG, "configuration changed: " + mContext.getResources().getConfiguration());
2269                }
2270                mDisplay.getSize(mCurrentDisplaySize);
2271
2272                updateResources();
2273                repositionNavigationBar();
2274                updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
2275                updateShowSearchHoldoff();
2276            }
2277            else if (Intent.ACTION_SCREEN_ON.equals(action)) {
2278                // work around problem where mDisplay.getRotation() is not stable while screen is off (bug 7086018)
2279                repositionNavigationBar();
2280                notifyNavigationBarScreenOn(true);
2281            }
2282        }
2283    };
2284
2285    @Override
2286    public void userSwitched(int newUserId) {
2287        if (MULTIUSER_DEBUG) mNotificationPanelDebugText.setText("USER " + newUserId);
2288        animateCollapsePanels();
2289        updateNotificationIcons();
2290        resetUserSetupObserver();
2291    }
2292
2293    private void resetUserSetupObserver() {
2294        mContext.getContentResolver().unregisterContentObserver(mUserSetupObserver);
2295        mUserSetupObserver.onChange(false);
2296        mContext.getContentResolver().registerContentObserver(
2297                Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE), true,
2298                mUserSetupObserver,
2299                mCurrentUserId);
2300    }
2301
2302    private void setIntruderAlertVisibility(boolean vis) {
2303        if (!ENABLE_INTRUDERS) return;
2304        if (DEBUG) {
2305            Slog.v(TAG, (vis ? "showing" : "hiding") + " intruder alert window");
2306        }
2307        mIntruderAlertView.setVisibility(vis ? View.VISIBLE : View.GONE);
2308    }
2309
2310    public void dismissIntruder() {
2311        if (mCurrentlyIntrudingNotification == null) return;
2312
2313        try {
2314            mBarService.onNotificationClear(
2315                    mCurrentlyIntrudingNotification.pkg,
2316                    mCurrentlyIntrudingNotification.tag,
2317                    mCurrentlyIntrudingNotification.id);
2318        } catch (android.os.RemoteException ex) {
2319            // oh well
2320        }
2321    }
2322
2323    /**
2324     * Reload some of our resources when the configuration changes.
2325     *
2326     * We don't reload everything when the configuration changes -- we probably
2327     * should, but getting that smooth is tough.  Someday we'll fix that.  In the
2328     * meantime, just update the things that we know change.
2329     */
2330    void updateResources() {
2331        final Context context = mContext;
2332        final Resources res = context.getResources();
2333
2334        if (mClearButton instanceof TextView) {
2335            ((TextView)mClearButton).setText(context.getText(R.string.status_bar_clear_all_button));
2336        }
2337
2338        // Update the QuickSettings container
2339        if (mQS != null) mQS.updateResources();
2340
2341        loadDimens();
2342    }
2343
2344    protected void loadDimens() {
2345        final Resources res = mContext.getResources();
2346
2347        mNaturalBarHeight = res.getDimensionPixelSize(
2348                com.android.internal.R.dimen.status_bar_height);
2349
2350        int newIconSize = res.getDimensionPixelSize(
2351            com.android.internal.R.dimen.status_bar_icon_size);
2352        int newIconHPadding = res.getDimensionPixelSize(
2353            R.dimen.status_bar_icon_padding);
2354
2355        if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) {
2356//            Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding);
2357            mIconHPadding = newIconHPadding;
2358            mIconSize = newIconSize;
2359            //reloadAllNotificationIcons(); // reload the tray
2360        }
2361
2362        mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore);
2363
2364        mSelfExpandVelocityPx = res.getDimension(R.dimen.self_expand_velocity);
2365        mSelfCollapseVelocityPx = res.getDimension(R.dimen.self_collapse_velocity);
2366        mFlingExpandMinVelocityPx = res.getDimension(R.dimen.fling_expand_min_velocity);
2367        mFlingCollapseMinVelocityPx = res.getDimension(R.dimen.fling_collapse_min_velocity);
2368
2369        mCollapseMinDisplayFraction = res.getFraction(R.dimen.collapse_min_display_fraction, 1, 1);
2370        mExpandMinDisplayFraction = res.getFraction(R.dimen.expand_min_display_fraction, 1, 1);
2371
2372        mExpandAccelPx = res.getDimension(R.dimen.expand_accel);
2373        mCollapseAccelPx = res.getDimension(R.dimen.collapse_accel);
2374
2375        mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity);
2376
2377        mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity);
2378
2379        mNotificationPanelMarginBottomPx
2380            = (int) res.getDimension(R.dimen.notification_panel_margin_bottom);
2381        mNotificationPanelMarginPx
2382            = (int) res.getDimension(R.dimen.notification_panel_margin_left);
2383        mNotificationPanelGravity = res.getInteger(R.integer.notification_panel_layout_gravity);
2384        if (mNotificationPanelGravity <= 0) {
2385            mNotificationPanelGravity = Gravity.LEFT | Gravity.TOP;
2386        }
2387        mSettingsPanelGravity = res.getInteger(R.integer.settings_panel_layout_gravity);
2388        if (mSettingsPanelGravity <= 0) {
2389            mSettingsPanelGravity = Gravity.RIGHT | Gravity.TOP;
2390        }
2391
2392        mCarrierLabelHeight = res.getDimensionPixelSize(R.dimen.carrier_label_height);
2393        mNotificationHeaderHeight = res.getDimensionPixelSize(R.dimen.notification_panel_header_height);
2394
2395        mNotificationPanelMinHeightFrac = res.getFraction(R.dimen.notification_panel_min_height_frac, 1, 1);
2396        if (mNotificationPanelMinHeightFrac < 0f || mNotificationPanelMinHeightFrac > 1f) {
2397            mNotificationPanelMinHeightFrac = 0f;
2398        }
2399
2400        if (false) Slog.v(TAG, "updateResources");
2401    }
2402
2403    //
2404    // tracing
2405    //
2406
2407    void postStartTracing() {
2408        mHandler.postDelayed(mStartTracing, 3000);
2409    }
2410
2411    void vibrate() {
2412        android.os.Vibrator vib = (android.os.Vibrator)mContext.getSystemService(
2413                Context.VIBRATOR_SERVICE);
2414        vib.vibrate(250);
2415    }
2416
2417    Runnable mStartTracing = new Runnable() {
2418        public void run() {
2419            vibrate();
2420            SystemClock.sleep(250);
2421            Slog.d(TAG, "startTracing");
2422            android.os.Debug.startMethodTracing("/data/statusbar-traces/trace");
2423            mHandler.postDelayed(mStopTracing, 10000);
2424        }
2425    };
2426
2427    Runnable mStopTracing = new Runnable() {
2428        public void run() {
2429            android.os.Debug.stopMethodTracing();
2430            Slog.d(TAG, "stopTracing");
2431            vibrate();
2432        }
2433    };
2434
2435    @Override
2436    protected void haltTicker() {
2437        mTicker.halt();
2438    }
2439
2440    @Override
2441    protected boolean shouldDisableNavbarGestures() {
2442        return !isDeviceProvisioned()
2443                || mExpandedVisible
2444                || (mDisabled & StatusBarManager.DISABLE_SEARCH) != 0;
2445    }
2446
2447    private static class FastColorDrawable extends Drawable {
2448        private final int mColor;
2449
2450        public FastColorDrawable(int color) {
2451            mColor = 0xff000000 | color;
2452        }
2453
2454        @Override
2455        public void draw(Canvas canvas) {
2456            canvas.drawColor(mColor, PorterDuff.Mode.SRC);
2457        }
2458
2459        @Override
2460        public void setAlpha(int alpha) {
2461        }
2462
2463        @Override
2464        public void setColorFilter(ColorFilter cf) {
2465        }
2466
2467        @Override
2468        public int getOpacity() {
2469            return PixelFormat.OPAQUE;
2470        }
2471
2472        @Override
2473        public void setBounds(int left, int top, int right, int bottom) {
2474        }
2475
2476        @Override
2477        public void setBounds(Rect bounds) {
2478        }
2479    }
2480}
2481