TabletStatusBar.java revision 6179ea3196e9306d3f14361fe9ef14191b1edba6
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.tablet;
18
19import java.io.FileDescriptor;
20import java.io.PrintWriter;
21import java.util.ArrayList;
22
23import android.animation.LayoutTransition;
24import android.animation.ObjectAnimator;
25import android.app.ActivityManagerNative;
26import android.app.Dialog;
27import android.app.PendingIntent;
28import android.app.Notification;
29import android.app.StatusBarManager;
30import android.content.Context;
31import android.content.Intent;
32import android.content.SharedPreferences;
33import android.content.res.Configuration;
34import android.content.res.Resources;
35import android.inputmethodservice.InputMethodService;
36import android.graphics.PixelFormat;
37import android.graphics.Rect;
38import android.graphics.drawable.LayerDrawable;
39import android.provider.Settings;
40import android.os.Handler;
41import android.os.IBinder;
42import android.os.Message;
43import android.os.RemoteException;
44import android.os.ServiceManager;
45import android.text.TextUtils;
46import android.util.Slog;
47import android.view.accessibility.AccessibilityEvent;
48import android.view.Display;
49import android.view.Gravity;
50import android.view.IWindowManager;
51import android.view.KeyEvent;
52import android.view.LayoutInflater;
53import android.view.MotionEvent;
54import android.view.SoundEffectConstants;
55import android.view.VelocityTracker;
56import android.view.View;
57import android.view.ViewConfiguration;
58import android.view.ViewGroup;
59import android.view.WindowManager;
60import android.view.WindowManagerImpl;
61import android.widget.ImageView;
62import android.widget.LinearLayout;
63import android.widget.RemoteViews;
64import android.widget.ScrollView;
65import android.widget.TextView;
66
67import com.android.internal.statusbar.StatusBarIcon;
68import com.android.internal.statusbar.StatusBarNotification;
69
70import com.android.systemui.R;
71import com.android.systemui.statusbar.*;
72import com.android.systemui.statusbar.policy.BatteryController;
73import com.android.systemui.statusbar.policy.BluetoothController;
74import com.android.systemui.statusbar.policy.CompatModeButton;
75import com.android.systemui.statusbar.policy.LocationController;
76import com.android.systemui.statusbar.policy.NetworkController;
77import com.android.systemui.statusbar.policy.Prefs;
78import com.android.systemui.recent.RecentsPanelView;
79
80public class TabletStatusBar extends StatusBar implements
81        HeightReceiver.OnBarHeightChangedListener,
82        InputMethodsPanel.OnHardKeyboardEnabledChangeListener {
83    public static final boolean DEBUG = false;
84    public static final boolean DEBUG_COMPAT_HELP = false;
85    public static final String TAG = "TabletStatusBar";
86
87
88    public static final int MSG_OPEN_NOTIFICATION_PANEL = 1000;
89    public static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001;
90    public static final int MSG_OPEN_NOTIFICATION_PEEK = 1002;
91    public static final int MSG_CLOSE_NOTIFICATION_PEEK = 1003;
92    public static final int MSG_OPEN_RECENTS_PANEL = 1020;
93    public static final int MSG_CLOSE_RECENTS_PANEL = 1021;
94    public static final int MSG_SHOW_CHROME = 1030;
95    public static final int MSG_HIDE_CHROME = 1031;
96    public static final int MSG_OPEN_INPUT_METHODS_PANEL = 1040;
97    public static final int MSG_CLOSE_INPUT_METHODS_PANEL = 1041;
98    public static final int MSG_OPEN_COMPAT_MODE_PANEL = 1050;
99    public static final int MSG_CLOSE_COMPAT_MODE_PANEL = 1051;
100    public static final int MSG_STOP_TICKER = 2000;
101
102    // Fitts' Law assistance for LatinIME; see policy.EventHole
103    private static final boolean FAKE_SPACE_BAR = true;
104
105    // The height of the bar, as definied by the build.  It may be taller if we're plugged
106    // into hdmi.
107    int mNaturalBarHeight = -1;
108    int mIconSize = -1;
109    int mIconHPadding = -1;
110    private int mMaxNotificationIcons = 5;
111
112    H mHandler = new H();
113
114    IWindowManager mWindowManager;
115
116    // tracking all current notifications
117    private NotificationData mNotificationData = new NotificationData();
118
119    TabletStatusBarView mStatusBarView;
120    View mNotificationArea;
121    View mNotificationTrigger;
122    NotificationIconArea mNotificationIconArea;
123    ViewGroup mNavigationArea;
124
125    boolean mNotificationDNDMode;
126    NotificationData.Entry mNotificationDNDDummyEntry;
127
128    ImageView mBackButton;
129    View mHomeButton;
130    View mMenuButton;
131    View mRecentButton;
132
133    ViewGroup mFeedbackIconArea; // notification icons, IME icon, compat icon
134    InputMethodButton mInputMethodSwitchButton;
135    CompatModeButton mCompatModeButton;
136
137    NotificationPanel mNotificationPanel;
138    WindowManager.LayoutParams mNotificationPanelParams;
139    NotificationPeekPanel mNotificationPeekWindow;
140    ViewGroup mNotificationPeekRow;
141    int mNotificationPeekIndex;
142    IBinder mNotificationPeekKey;
143    LayoutTransition mNotificationPeekScrubLeft, mNotificationPeekScrubRight;
144
145    int mNotificationPeekTapDuration;
146    int mNotificationFlingVelocity;
147
148    ViewGroup mPile;
149
150    HeightReceiver mHeightReceiver;
151    BatteryController mBatteryController;
152    BluetoothController mBluetoothController;
153    LocationController mLocationController;
154    NetworkController mNetworkController;
155
156    ViewGroup mBarContents;
157    LayoutTransition mBarContentsLayoutTransition;
158
159    // hide system chrome ("lights out") support
160    View mShadow;
161
162    NotificationIconArea.IconLayout mIconLayout;
163
164    TabletTicker mTicker;
165
166    View mFakeSpaceBar;
167    KeyEvent mSpaceBarKeyEvent = null;
168
169    View mCompatibilityHelpDialog = null;
170
171    // for disabling the status bar
172    int mDisabled = 0;
173
174    private RecentsPanelView mRecentsPanel;
175    private InputMethodsPanel mInputMethodsPanel;
176    private CompatModePanel mCompatModePanel;
177
178    public Context getContext() { return mContext; }
179
180    protected void addPanelWindows() {
181        final Context context = mContext;
182        final Resources res = mContext.getResources();
183
184        // Notification Panel
185        mNotificationPanel = (NotificationPanel)View.inflate(context,
186                R.layout.status_bar_notification_panel, null);
187        mNotificationPanel.show(false, false);
188        mNotificationPanel.setOnTouchListener(
189                new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPanel));
190
191        // the battery and network icons
192        mBatteryController.addIconView((ImageView)mNotificationPanel.findViewById(R.id.battery));
193        mBatteryController.addLabelView(
194                (TextView)mNotificationPanel.findViewById(R.id.battery_text));
195        mBluetoothController.addIconView(
196                (ImageView)mNotificationPanel.findViewById(R.id.bluetooth));
197        mNetworkController.addCombinedSignalIconView(
198                (ImageView)mNotificationPanel.findViewById(R.id.network_signal));
199        mNetworkController.addDataTypeIconView(
200                (ImageView)mNotificationPanel.findViewById(R.id.network_type));
201        mNetworkController.addDataDirectionOverlayIconView(
202                (ImageView)mNotificationPanel.findViewById(R.id.network_direction));
203        mNetworkController.addLabelView(
204                (TextView)mNotificationPanel.findViewById(R.id.network_text));
205        mNetworkController.addLabelView(
206                (TextView)mBarContents.findViewById(R.id.network_text));
207
208        mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel);
209
210        WindowManager.LayoutParams lp = mNotificationPanelParams = new WindowManager.LayoutParams(
211                res.getDimensionPixelSize(R.dimen.notification_panel_width),
212                getNotificationPanelHeight(),
213                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
214                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
215                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
216                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
217                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
218                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
219                PixelFormat.TRANSLUCENT);
220        lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
221        lp.setTitle("NotificationPanel");
222        lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
223                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
224        lp.windowAnimations = com.android.internal.R.style.Animation; // == no animation
225//        lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade
226
227        WindowManagerImpl.getDefault().addView(mNotificationPanel, lp);
228
229        // Notification preview window
230        mNotificationPeekWindow = (NotificationPeekPanel) View.inflate(context,
231                R.layout.status_bar_notification_peek, null);
232        mNotificationPeekWindow.setBar(this);
233
234        mNotificationPeekRow = (ViewGroup) mNotificationPeekWindow.findViewById(R.id.content);
235        mNotificationPeekWindow.setVisibility(View.GONE);
236        mNotificationPeekWindow.setOnTouchListener(
237                new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PEEK, mNotificationPeekWindow));
238        mNotificationPeekScrubRight = new LayoutTransition();
239        mNotificationPeekScrubRight.setAnimator(LayoutTransition.APPEARING,
240                ObjectAnimator.ofInt(null, "left", -512, 0));
241        mNotificationPeekScrubRight.setAnimator(LayoutTransition.DISAPPEARING,
242                ObjectAnimator.ofInt(null, "left", -512, 0));
243        mNotificationPeekScrubRight.setDuration(500);
244
245        mNotificationPeekScrubLeft = new LayoutTransition();
246        mNotificationPeekScrubLeft.setAnimator(LayoutTransition.APPEARING,
247                ObjectAnimator.ofInt(null, "left", 512, 0));
248        mNotificationPeekScrubLeft.setAnimator(LayoutTransition.DISAPPEARING,
249                ObjectAnimator.ofInt(null, "left", 512, 0));
250        mNotificationPeekScrubLeft.setDuration(500);
251
252        // XXX: setIgnoreChildren?
253        lp = new WindowManager.LayoutParams(
254                512, // ViewGroup.LayoutParams.WRAP_CONTENT,
255                ViewGroup.LayoutParams.WRAP_CONTENT,
256                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
257                WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
258                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
259                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
260                PixelFormat.TRANSLUCENT);
261        lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
262        lp.y = res.getDimensionPixelOffset(R.dimen.peek_window_y_offset);
263        lp.setTitle("NotificationPeekWindow");
264        lp.windowAnimations = com.android.internal.R.style.Animation_Toast;
265
266        WindowManagerImpl.getDefault().addView(mNotificationPeekWindow, lp);
267
268        // Recents Panel
269        mRecentsPanel = (RecentsPanelView) View.inflate(context,
270                R.layout.status_bar_recent_panel, null);
271        mRecentsPanel.setVisibility(View.GONE);
272        mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL,
273                mRecentsPanel));
274        mStatusBarView.setIgnoreChildren(2, mRecentButton, mRecentsPanel);
275
276        lp = new WindowManager.LayoutParams(
277                ViewGroup.LayoutParams.WRAP_CONTENT,
278                ViewGroup.LayoutParams.WRAP_CONTENT,
279                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
280                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
281                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
282                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
283                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
284                PixelFormat.TRANSLUCENT);
285        lp.gravity = Gravity.BOTTOM | Gravity.LEFT;
286        lp.setTitle("RecentsPanel");
287        lp.windowAnimations = R.style.Animation_RecentPanel;
288        lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
289                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
290
291        WindowManagerImpl.getDefault().addView(mRecentsPanel, lp);
292        mRecentsPanel.setBar(this);
293
294        // Input methods Panel
295        mInputMethodsPanel = (InputMethodsPanel) View.inflate(context,
296                R.layout.status_bar_input_methods_panel, null);
297        mInputMethodsPanel.setHardKeyboardEnabledChangeListener(this);
298        mInputMethodsPanel.setOnTouchListener(new TouchOutsideListener(
299                MSG_CLOSE_INPUT_METHODS_PANEL, mInputMethodsPanel));
300        mInputMethodsPanel.setImeSwitchButton(mInputMethodSwitchButton);
301        mStatusBarView.setIgnoreChildren(3, mInputMethodSwitchButton, mInputMethodsPanel);
302        lp = new WindowManager.LayoutParams(
303                ViewGroup.LayoutParams.WRAP_CONTENT,
304                ViewGroup.LayoutParams.WRAP_CONTENT,
305                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
306                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
307                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
308                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
309                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
310                PixelFormat.TRANSLUCENT);
311        lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
312        lp.setTitle("InputMethodsPanel");
313        lp.windowAnimations = R.style.Animation_RecentPanel;
314
315        WindowManagerImpl.getDefault().addView(mInputMethodsPanel, lp);
316
317        // Compatibility mode selector panel
318        mCompatModePanel = (CompatModePanel) View.inflate(context,
319                R.layout.status_bar_compat_mode_panel, null);
320        mCompatModePanel.setOnTouchListener(new TouchOutsideListener(
321                MSG_CLOSE_COMPAT_MODE_PANEL, mCompatModePanel));
322        mCompatModePanel.setTrigger(mCompatModeButton);
323        mCompatModePanel.setVisibility(View.GONE);
324        mStatusBarView.setIgnoreChildren(4, mCompatModeButton, mCompatModePanel);
325        lp = new WindowManager.LayoutParams(
326                250,
327                ViewGroup.LayoutParams.WRAP_CONTENT,
328                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
329                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
330                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
331                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
332                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
333                PixelFormat.TRANSLUCENT);
334        lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
335        lp.setTitle("CompatModePanel");
336        lp.windowAnimations = android.R.style.Animation_Dialog;
337
338        WindowManagerImpl.getDefault().addView(mCompatModePanel, lp);
339    }
340
341    private int getNotificationPanelHeight() {
342        final Resources res = mContext.getResources();
343        final Display d = WindowManagerImpl.getDefault().getDefaultDisplay();
344        return Math.max(res.getDimensionPixelSize(R.dimen.notification_panel_min_height),
345                d.getRealHeight());
346    }
347
348    @Override
349    public void start() {
350        super.start(); // will add the main bar view
351    }
352
353    @Override
354    protected void onConfigurationChanged(Configuration newConfig) {
355        loadDimens();
356        mNotificationPanelParams.height = getNotificationPanelHeight();
357        WindowManagerImpl.getDefault().updateViewLayout(mNotificationPanel,
358                mNotificationPanelParams);
359    }
360
361    protected void loadDimens() {
362        final Resources res = mContext.getResources();
363
364        mNaturalBarHeight = res.getDimensionPixelSize(
365                com.android.internal.R.dimen.system_bar_height);
366
367        int newIconSize = res.getDimensionPixelSize(
368            com.android.internal.R.dimen.system_bar_icon_size);
369        int newIconHPadding = res.getDimensionPixelSize(
370            R.dimen.status_bar_icon_padding);
371
372        if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) {
373//            Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding);
374            mIconHPadding = newIconHPadding;
375            mIconSize = newIconSize;
376            reloadAllNotificationIcons(); // reload the tray
377        }
378
379        final int numIcons = res.getInteger(R.integer.config_maxNotificationIcons);
380        if (numIcons != mMaxNotificationIcons) {
381            mMaxNotificationIcons = numIcons;
382            if (DEBUG) Slog.d(TAG, "max notification icons: " + mMaxNotificationIcons);
383            reloadAllNotificationIcons();
384        }
385    }
386
387    protected View makeStatusBarView() {
388        final Context context = mContext;
389
390        mWindowManager = IWindowManager.Stub.asInterface(
391                ServiceManager.getService(Context.WINDOW_SERVICE));
392
393        // This guy will listen for HDMI plugged broadcasts so we can resize the
394        // status bar as appropriate.
395        mHeightReceiver = new HeightReceiver(mContext);
396        mHeightReceiver.registerReceiver();
397        loadDimens();
398
399        final TabletStatusBarView sb = (TabletStatusBarView)View.inflate(
400                context, R.layout.status_bar, null);
401        mStatusBarView = sb;
402
403        sb.setHandler(mHandler);
404
405        mBarContents = (ViewGroup) sb.findViewById(R.id.bar_contents);
406        // layout transitions for the status bar's contents
407        mBarContentsLayoutTransition = new LayoutTransition();
408        // add/removal will fade as normal
409        mBarContentsLayoutTransition.setAnimator(LayoutTransition.APPEARING,
410                ObjectAnimator.ofFloat(null, "alpha", 0f, 1f));
411        mBarContentsLayoutTransition.setAnimator(LayoutTransition.DISAPPEARING,
412                ObjectAnimator.ofFloat(null, "alpha", 1f, 0f));
413        // no animations for siblings on change: just jump into place please
414        mBarContentsLayoutTransition.setAnimator(LayoutTransition.CHANGE_APPEARING, null);
415        mBarContentsLayoutTransition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, null);
416        // quick like bunny
417        mBarContentsLayoutTransition.setDuration(250 * (DEBUG?10:1));
418        mBarContents.setLayoutTransition(mBarContentsLayoutTransition);
419
420        // the whole right-hand side of the bar
421        mNotificationArea = sb.findViewById(R.id.notificationArea);
422
423        // the button to open the notification area
424        mNotificationTrigger = sb.findViewById(R.id.notificationTrigger);
425        mNotificationTrigger.setOnTouchListener(new NotificationTriggerTouchListener());
426
427        // the more notifications icon
428        mNotificationIconArea = (NotificationIconArea)sb.findViewById(R.id.notificationIcons);
429
430        // where the icons go
431        mIconLayout = (NotificationIconArea.IconLayout) sb.findViewById(R.id.icons);
432        mIconLayout.setOnTouchListener(new NotificationIconTouchListener());
433
434        ViewConfiguration vc = ViewConfiguration.get(context);
435        mNotificationPeekTapDuration = vc.getTapTimeout();
436        mNotificationFlingVelocity = 300; // px/s
437
438        mTicker = new TabletTicker(this);
439
440        // The icons
441        mLocationController = new LocationController(mContext); // will post a notification
442
443        mBatteryController = new BatteryController(mContext);
444        mBatteryController.addIconView((ImageView)sb.findViewById(R.id.battery));
445        mBluetoothController = new BluetoothController(mContext);
446        mBluetoothController.addIconView((ImageView)sb.findViewById(R.id.bluetooth));
447        mNetworkController = new NetworkController(mContext);
448        mNetworkController.addCombinedSignalIconView(
449                (ImageView)sb.findViewById(R.id.network_signal));
450        mNetworkController.addDataTypeIconView(
451                (ImageView)sb.findViewById(R.id.network_type));
452        mNetworkController.addDataDirectionOverlayIconView(
453                (ImageView)sb.findViewById(R.id.network_direction));
454
455        // The navigation buttons
456        mBackButton = (ImageView)sb.findViewById(R.id.back);
457        mNavigationArea = (ViewGroup) sb.findViewById(R.id.navigationArea);
458        mHomeButton = mNavigationArea.findViewById(R.id.home);
459        mMenuButton = mNavigationArea.findViewById(R.id.menu);
460        mRecentButton = mNavigationArea.findViewById(R.id.recent_apps);
461        mRecentButton.setOnClickListener(mOnClickListener);
462        mNavigationArea.setLayoutTransition(mBarContentsLayoutTransition);
463
464        // The bar contents buttons
465        mFeedbackIconArea = (ViewGroup)sb.findViewById(R.id.feedbackIconArea);
466        mInputMethodSwitchButton = (InputMethodButton) sb.findViewById(R.id.imeSwitchButton);
467        // Overwrite the lister
468        mInputMethodSwitchButton.setOnClickListener(mOnClickListener);
469
470        mCompatModeButton = (CompatModeButton) sb.findViewById(R.id.compatModeButton);
471        mCompatModeButton.setOnClickListener(mOnClickListener);
472
473        // for redirecting errant bar taps to the IME
474        mFakeSpaceBar = sb.findViewById(R.id.fake_space_bar);
475
476        // "shadows" of the status bar features, for lights-out mode
477        mShadow = sb.findViewById(R.id.bar_shadow);
478        mShadow.setOnTouchListener(
479            new View.OnTouchListener() {
480                public boolean onTouch(View v, MotionEvent ev) {
481                    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
482                        // even though setting the systemUI visibility below will turn these views
483                        // on, we need them to come up faster so that they can catch this motion
484                        // event
485                        mShadow.setVisibility(View.GONE);
486                        mBarContents.setVisibility(View.VISIBLE);
487
488                        try {
489                            mBarService.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
490                        } catch (RemoteException ex) {
491                            // system process dead
492                        }
493                    }
494                    return false;
495                }
496            });
497
498        // tuning parameters
499        final int LIGHTS_GOING_OUT_SYSBAR_DURATION = 600;
500        final int LIGHTS_GOING_OUT_SHADOW_DURATION = 1000;
501        final int LIGHTS_GOING_OUT_SHADOW_DELAY    = 500;
502
503        final int LIGHTS_COMING_UP_SYSBAR_DURATION = 200;
504//        final int LIGHTS_COMING_UP_SYSBAR_DELAY    = 50;
505        final int LIGHTS_COMING_UP_SHADOW_DURATION = 0;
506
507        LayoutTransition xition = new LayoutTransition();
508        xition.setAnimator(LayoutTransition.APPEARING,
509               ObjectAnimator.ofFloat(null, "alpha", 0.5f, 1f));
510        xition.setDuration(LayoutTransition.APPEARING, LIGHTS_COMING_UP_SYSBAR_DURATION);
511        xition.setStartDelay(LayoutTransition.APPEARING, 0);
512        xition.setAnimator(LayoutTransition.DISAPPEARING,
513               ObjectAnimator.ofFloat(null, "alpha", 1f, 0f));
514        xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_GOING_OUT_SYSBAR_DURATION);
515        xition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
516        ((ViewGroup)sb.findViewById(R.id.bar_contents_holder)).setLayoutTransition(xition);
517
518        xition = new LayoutTransition();
519        xition.setAnimator(LayoutTransition.APPEARING,
520               ObjectAnimator.ofFloat(null, "alpha", 0f, 1f));
521        xition.setDuration(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DURATION);
522        xition.setStartDelay(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DELAY);
523        xition.setAnimator(LayoutTransition.DISAPPEARING,
524               ObjectAnimator.ofFloat(null, "alpha", 1f, 0f));
525        xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_COMING_UP_SHADOW_DURATION);
526        xition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
527        ((ViewGroup)sb.findViewById(R.id.bar_shadow_holder)).setLayoutTransition(xition);
528
529        // set the initial view visibility
530        setAreThereNotifications();
531
532        // Add the windows
533        addPanelWindows();
534
535        mPile = (ViewGroup)mNotificationPanel.findViewById(R.id.content);
536        mPile.removeAllViews();
537
538        ScrollView scroller = (ScrollView)mPile.getParent();
539        scroller.setFillViewport(true);
540
541        mHeightReceiver.addOnBarHeightChangedListener(this);
542
543        return sb;
544    }
545
546    public int getStatusBarHeight() {
547        return mHeightReceiver.getHeight();
548    }
549
550    protected int getStatusBarGravity() {
551        return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL;
552    }
553
554    public void onBarHeightChanged(int height) {
555        final WindowManager.LayoutParams lp
556                = (WindowManager.LayoutParams)mStatusBarView.getLayoutParams();
557        if (lp == null) {
558            // haven't been added yet
559            return;
560        }
561        if (lp.height != height) {
562            lp.height = height;
563            final WindowManager wm = WindowManagerImpl.getDefault();
564            wm.updateViewLayout(mStatusBarView, lp);
565        }
566    }
567
568    private class H extends Handler {
569        public void handleMessage(Message m) {
570            switch (m.what) {
571                case MSG_OPEN_NOTIFICATION_PEEK:
572                    if (DEBUG) Slog.d(TAG, "opening notification peek window; arg=" + m.arg1);
573
574                    if (m.arg1 >= 0) {
575                        final int N = mNotificationData.size();
576
577                        if (!mNotificationDNDMode) {
578                            if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) {
579                                NotificationData.Entry entry = mNotificationData.get(N-1-mNotificationPeekIndex);
580                                entry.icon.setBackgroundColor(0);
581                                mNotificationPeekIndex = -1;
582                                mNotificationPeekKey = null;
583                            }
584                        }
585
586                        final int peekIndex = m.arg1;
587                        if (peekIndex < N) {
588                            //Slog.d(TAG, "loading peek: " + peekIndex);
589                            NotificationData.Entry entry =
590                                mNotificationDNDMode
591                                    ? mNotificationDNDDummyEntry
592                                    : mNotificationData.get(N-1-peekIndex);
593                            NotificationData.Entry copy = new NotificationData.Entry(
594                                    entry.key,
595                                    entry.notification,
596                                    entry.icon);
597                            inflateViews(copy, mNotificationPeekRow);
598
599                            if (mNotificationDNDMode) {
600                                copy.content.setOnClickListener(new View.OnClickListener() {
601                                    public void onClick(View v) {
602                                        SharedPreferences.Editor editor = Prefs.edit(mContext);
603                                        editor.putBoolean(Prefs.DO_NOT_DISTURB_PREF, false);
604                                        editor.apply();
605                                        animateCollapse();
606                                    }
607                                });
608                            }
609
610                            entry.icon.setBackgroundColor(0x20FFFFFF);
611
612//                          mNotificationPeekRow.setLayoutTransition(
613//                              peekIndex < mNotificationPeekIndex
614//                                  ? mNotificationPeekScrubLeft
615//                                  : mNotificationPeekScrubRight);
616
617                            mNotificationPeekRow.removeAllViews();
618                            mNotificationPeekRow.addView(copy.row);
619
620                            mNotificationPeekWindow.setVisibility(View.VISIBLE);
621                            mNotificationPanel.show(false, true);
622
623                            mNotificationPeekIndex = peekIndex;
624                            mNotificationPeekKey = entry.key;
625                        }
626                    }
627                    break;
628                case MSG_CLOSE_NOTIFICATION_PEEK:
629                    if (DEBUG) Slog.d(TAG, "closing notification peek window");
630                    mNotificationPeekWindow.setVisibility(View.GONE);
631                    mNotificationPeekRow.removeAllViews();
632
633                    final int N = mNotificationData.size();
634                    if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) {
635                        NotificationData.Entry entry =
636                            mNotificationDNDMode
637                                ? mNotificationDNDDummyEntry
638                                : mNotificationData.get(N-1-mNotificationPeekIndex);
639                        entry.icon.setBackgroundColor(0);
640                    }
641
642                    mNotificationPeekIndex = -1;
643                    mNotificationPeekKey = null;
644                    break;
645                case MSG_OPEN_NOTIFICATION_PANEL:
646                    if (DEBUG) Slog.d(TAG, "opening notifications panel");
647                    if (!mNotificationPanel.isShowing()) {
648                        mNotificationPeekWindow.setVisibility(View.GONE);
649                        mNotificationPanel.show(true, true);
650                        mNotificationArea.setVisibility(View.INVISIBLE);
651                        mTicker.halt();
652                    }
653                    break;
654                case MSG_CLOSE_NOTIFICATION_PANEL:
655                    if (DEBUG) Slog.d(TAG, "closing notifications panel");
656                    if (mNotificationPanel.isShowing()) {
657                        mNotificationPanel.show(false, true);
658                        mNotificationArea.setVisibility(View.VISIBLE);
659                    }
660                    break;
661                case MSG_OPEN_RECENTS_PANEL:
662                    if (DEBUG) Slog.d(TAG, "opening recents panel");
663                    if (mRecentsPanel != null) {
664                        disable(StatusBarManager.DISABLE_BACK);
665                        mRecentsPanel.setVisibility(View.VISIBLE);
666                        mRecentsPanel.show(true, true);
667                    }
668                    break;
669                case MSG_CLOSE_RECENTS_PANEL:
670                    if (DEBUG) Slog.d(TAG, "closing recents panel");
671                    if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
672                        disable(StatusBarManager.DISABLE_NONE);
673                        mRecentsPanel.show(false, true);
674                    }
675                    break;
676                case MSG_OPEN_INPUT_METHODS_PANEL:
677                    if (DEBUG) Slog.d(TAG, "opening input methods panel");
678                    if (mInputMethodsPanel != null) mInputMethodsPanel.openPanel();
679                    break;
680                case MSG_CLOSE_INPUT_METHODS_PANEL:
681                    if (DEBUG) Slog.d(TAG, "closing input methods panel");
682                    if (mInputMethodsPanel != null) mInputMethodsPanel.closePanel(false);
683                    break;
684                case MSG_OPEN_COMPAT_MODE_PANEL:
685                    if (DEBUG) Slog.d(TAG, "opening compat panel");
686                    if (mCompatModePanel != null) mCompatModePanel.openPanel();
687                    break;
688                case MSG_CLOSE_COMPAT_MODE_PANEL:
689                    if (DEBUG) Slog.d(TAG, "closing compat panel");
690                    if (mCompatModePanel != null) mCompatModePanel.closePanel();
691                    break;
692                case MSG_SHOW_CHROME:
693                    if (DEBUG) Slog.d(TAG, "hiding shadows (lights on)");
694                    mBarContents.setVisibility(View.VISIBLE);
695                    mShadow.setVisibility(View.GONE);
696                    notifyLightsChanged(true);
697                    break;
698                case MSG_HIDE_CHROME:
699                    if (DEBUG) Slog.d(TAG, "showing shadows (lights out)");
700                    animateCollapse();
701                    mBarContents.setVisibility(View.GONE);
702                    mShadow.setVisibility(View.VISIBLE);
703                    notifyLightsChanged(false);
704                    break;
705                case MSG_STOP_TICKER:
706                    mTicker.halt();
707                    break;
708            }
709        }
710    }
711
712    private void notifyLightsChanged(boolean shown) {
713        try {
714            Slog.d(TAG, "lights " + (shown?"on":"out"));
715            mWindowManager.statusBarVisibilityChanged(
716                    shown ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN);
717        } catch (RemoteException ex) {
718        }
719    }
720
721    public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
722        if (DEBUG) Slog.d(TAG, "addIcon(" + slot + ") -> " + icon);
723    }
724
725    public void updateIcon(String slot, int index, int viewIndex,
726            StatusBarIcon old, StatusBarIcon icon) {
727        if (DEBUG) Slog.d(TAG, "updateIcon(" + slot + ") -> " + icon);
728    }
729
730    public void removeIcon(String slot, int index, int viewIndex) {
731        if (DEBUG) Slog.d(TAG, "removeIcon(" + slot + ")");
732    }
733
734    public void addNotification(IBinder key, StatusBarNotification notification) {
735        if (DEBUG) Slog.d(TAG, "addNotification(" + key + " -> " + notification + ")");
736        addNotificationViews(key, notification);
737
738        final boolean immersive = isImmersive();
739        if (false && immersive) {
740            // TODO: immersive mode popups for tablet
741        } else if (notification.notification.fullScreenIntent != null) {
742            // not immersive & a full-screen alert should be shown
743            Slog.w(TAG, "Notification has fullScreenIntent and activity is not immersive;"
744                    + " sending fullScreenIntent");
745            try {
746                notification.notification.fullScreenIntent.send();
747            } catch (PendingIntent.CanceledException e) {
748            }
749        } else {
750            tick(key, notification, true);
751        }
752
753        setAreThereNotifications();
754    }
755
756    public void updateNotification(IBinder key, StatusBarNotification notification) {
757        if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ")");
758
759        final NotificationData.Entry oldEntry = mNotificationData.findByKey(key);
760        if (oldEntry == null) {
761            Slog.w(TAG, "updateNotification for unknown key: " + key);
762            return;
763        }
764
765        final StatusBarNotification oldNotification = oldEntry.notification;
766        final RemoteViews oldContentView = oldNotification.notification.contentView;
767
768        final RemoteViews contentView = notification.notification.contentView;
769
770        if (DEBUG) {
771            Slog.d(TAG, "old notification: when=" + oldNotification.notification.when
772                    + " ongoing=" + oldNotification.isOngoing()
773                    + " expanded=" + oldEntry.expanded
774                    + " contentView=" + oldContentView
775                    + " rowParent=" + oldEntry.row.getParent());
776            Slog.d(TAG, "new notification: when=" + notification.notification.when
777                    + " ongoing=" + oldNotification.isOngoing()
778                    + " contentView=" + contentView);
779        }
780
781        // Can we just reapply the RemoteViews in place?  If when didn't change, the order
782        // didn't change.
783        boolean contentsUnchanged = oldEntry.expanded != null
784                && contentView != null && oldContentView != null
785                && contentView.getPackage() != null
786                && oldContentView.getPackage() != null
787                && oldContentView.getPackage().equals(contentView.getPackage())
788                && oldContentView.getLayoutId() == contentView.getLayoutId();
789        ViewGroup rowParent = (ViewGroup) oldEntry.row.getParent();
790        boolean orderUnchanged = notification.notification.when==oldNotification.notification.when
791                && notification.priority == oldNotification.priority;
792                // priority now encompasses isOngoing()
793        boolean isLastAnyway = rowParent.indexOfChild(oldEntry.row) == rowParent.getChildCount()-1;
794        if (contentsUnchanged && (orderUnchanged || isLastAnyway)) {
795            if (DEBUG) Slog.d(TAG, "reusing notification for key: " + key);
796            oldEntry.notification = notification;
797            try {
798                // Reapply the RemoteViews
799                contentView.reapply(mContext, oldEntry.content);
800                // update the contentIntent
801                final PendingIntent contentIntent = notification.notification.contentIntent;
802                if (contentIntent != null) {
803                    oldEntry.content.setOnClickListener(new NotificationClicker(contentIntent,
804                                notification.pkg, notification.tag, notification.id));
805                } else {
806                    oldEntry.content.setOnClickListener(null);
807                }
808                // Update the icon.
809                final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
810                        notification.notification.icon, notification.notification.iconLevel,
811                        notification.notification.number,
812                        notification.notification.tickerText);
813                if (!oldEntry.icon.set(ic)) {
814                    handleNotificationError(key, notification, "Couldn't update icon: " + ic);
815                    return;
816                }
817                // Update the large icon
818                if (notification.notification.largeIcon != null) {
819                    oldEntry.largeIcon.setImageBitmap(notification.notification.largeIcon);
820                } else {
821                    oldEntry.largeIcon.getLayoutParams().width = 0;
822                    oldEntry.largeIcon.setVisibility(View.INVISIBLE);
823                }
824
825                if (key == mNotificationPeekKey) {
826                    // must update the peek window
827                    Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK);
828                    peekMsg.arg1 = mNotificationPeekIndex;
829                    mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
830                    mHandler.sendMessage(peekMsg);
831                }
832            }
833            catch (RuntimeException e) {
834                // It failed to add cleanly.  Log, and remove the view from the panel.
835                Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e);
836                removeNotificationViews(key);
837                addNotificationViews(key, notification);
838            }
839        } else {
840            if (DEBUG) Slog.d(TAG, "not reusing notification for key: " + key);
841            removeNotificationViews(key);
842            addNotificationViews(key, notification);
843        }
844        // fullScreenIntent doesn't happen on updates.  You need to clear & repost a new
845        // notification.
846        final boolean immersive = isImmersive();
847        if (false && immersive) {
848            // TODO: immersive mode
849        } else {
850            tick(key, notification, false);
851        }
852
853        setAreThereNotifications();
854    }
855
856    public void removeNotification(IBinder key) {
857        if (DEBUG) Slog.d(TAG, "removeNotification(" + key + ")");
858        removeNotificationViews(key);
859        mTicker.remove(key);
860        setAreThereNotifications();
861    }
862
863    public void showClock(boolean show) {
864        View clock = mBarContents.findViewById(R.id.clock);
865        View network_text = mBarContents.findViewById(R.id.network_text);
866        if (clock != null) {
867            clock.setVisibility(show ? View.VISIBLE : View.GONE);
868        }
869        if (network_text != null) {
870            network_text.setVisibility((!show) ? View.VISIBLE : View.GONE);
871        }
872    }
873
874    public void disable(int state) {
875        int old = mDisabled;
876        int diff = state ^ old;
877        mDisabled = state;
878
879        // act accordingly
880        if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) {
881            boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0;
882            Slog.i(TAG, "DISABLE_CLOCK: " + (show ? "no" : "yes"));
883            showClock(show);
884        }
885        if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) {
886            boolean show = (state & StatusBarManager.DISABLE_SYSTEM_INFO) == 0;
887            Slog.i(TAG, "DISABLE_SYSTEM_INFO: " + (show ? "no" : "yes"));
888            mNotificationTrigger.setVisibility(show ? View.VISIBLE : View.GONE);
889        }
890        if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
891            if ((state & StatusBarManager.DISABLE_EXPAND) != 0) {
892                Slog.i(TAG, "DISABLE_EXPAND: yes");
893                animateCollapse();
894            }
895        }
896        if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
897            mNotificationDNDMode = Prefs.read(mContext)
898                        .getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT);
899
900            if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
901                Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: yes" + (mNotificationDNDMode?" (DND)":""));
902                mTicker.halt();
903            } else {
904                Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: no" + (mNotificationDNDMode?" (DND)":""));
905            }
906
907            // refresh icons to show either notifications or the DND message
908            reloadAllNotificationIcons();
909        } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
910            if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
911                mTicker.halt();
912            }
913        }
914        if ((diff & StatusBarManager.DISABLE_NAVIGATION) != 0) {
915            if ((state & StatusBarManager.DISABLE_NAVIGATION) != 0) {
916                Slog.i(TAG, "DISABLE_NAVIGATION: yes");
917                mNavigationArea.setVisibility(View.INVISIBLE);
918                mInputMethodSwitchButton.setScreenLocked(true);
919            } else {
920                Slog.i(TAG, "DISABLE_NAVIGATION: no");
921                mNavigationArea.setVisibility(View.VISIBLE);
922                mInputMethodSwitchButton.setScreenLocked(false);
923            }
924        }
925        if ((diff & StatusBarManager.DISABLE_BACK) != 0) {
926            if ((state & StatusBarManager.DISABLE_BACK) != 0) {
927                Slog.i(TAG, "DISABLE_BACK: yes");
928                mBackButton.setVisibility(View.INVISIBLE);
929                mInputMethodSwitchButton.setScreenLocked(true);
930            } else {
931                Slog.i(TAG, "DISABLE_BACK: no");
932                mBackButton.setVisibility(View.VISIBLE);
933                mInputMethodSwitchButton.setScreenLocked(false);
934            }
935        }
936
937    }
938
939    private boolean hasTicker(Notification n) {
940        return n.tickerView != null || !TextUtils.isEmpty(n.tickerText);
941    }
942
943    private void tick(IBinder key, StatusBarNotification n, boolean firstTime) {
944        // Don't show the ticker when the windowshade is open.
945        if (mNotificationPanel.isShowing()) {
946            return;
947        }
948        // If they asked for FLAG_ONLY_ALERT_ONCE, then only show this notification
949        // if it's a new notification.
950        if (!firstTime && (n.notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0) {
951            return;
952        }
953        // Show the ticker if one is requested. Also don't do this
954        // until status bar window is attached to the window manager,
955        // because...  well, what's the point otherwise?  And trying to
956        // run a ticker without being attached will crash!
957        if (hasTicker(n.notification) && mStatusBarView.getWindowToken() != null) {
958            if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS
959                            | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) {
960                mTicker.add(key, n);
961                mFeedbackIconArea.setVisibility(View.GONE);
962            }
963        }
964    }
965
966    // called by TabletTicker when it's done with all queued ticks
967    public void doneTicking() {
968        mFeedbackIconArea.setVisibility(View.VISIBLE);
969    }
970
971    public void animateExpand() {
972        mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK);
973        mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
974        mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK);
975        mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL);
976        mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL);
977    }
978
979    public void animateCollapse() {
980        mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PANEL);
981        mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL);
982        mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
983        mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
984        mHandler.removeMessages(MSG_CLOSE_INPUT_METHODS_PANEL);
985        mHandler.sendEmptyMessage(MSG_CLOSE_INPUT_METHODS_PANEL);
986        mHandler.removeMessages(MSG_CLOSE_COMPAT_MODE_PANEL);
987        mHandler.sendEmptyMessage(MSG_CLOSE_COMPAT_MODE_PANEL);
988        mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK);
989        mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK);
990    }
991
992    // called by StatusBar
993    @Override
994    public void setLightsOn(boolean on) {
995        // Policy note: if the frontmost activity needs the menu key, we assume it is a legacy app
996        // that can't handle lights-out mode.
997        if (mMenuButton.getVisibility() == View.VISIBLE) {
998            on = true;
999        }
1000        mHandler.removeMessages(MSG_HIDE_CHROME);
1001        mHandler.removeMessages(MSG_SHOW_CHROME);
1002        mHandler.sendEmptyMessage(on ? MSG_SHOW_CHROME : MSG_HIDE_CHROME);
1003    }
1004
1005    public void topAppWindowChanged(boolean showMenu) {
1006        if (DEBUG) {
1007            Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button");
1008        }
1009        mMenuButton.setVisibility(showMenu ? View.VISIBLE : View.GONE);
1010
1011        // See above re: lights-out policy for legacy apps.
1012        if (showMenu) setLightsOn(true);
1013
1014        mCompatModeButton.refresh();
1015        if (mCompatModeButton.getVisibility() == View.VISIBLE) {
1016                showCompatibilityHelp();
1017        } else {
1018            hideCompatibilityHelp();
1019            mCompatModePanel.closePanel();
1020        }
1021    }
1022
1023    private void showCompatibilityHelp() {
1024        if (mCompatibilityHelpDialog != null) {
1025            return;
1026        }
1027
1028        mCompatibilityHelpDialog = View.inflate(mContext, R.layout.compat_mode_help, null);
1029        View button = mCompatibilityHelpDialog.findViewById(R.id.button);
1030
1031        button.setOnClickListener(new View.OnClickListener() {
1032            @Override
1033            public void onClick(View v) {
1034                hideCompatibilityHelp();
1035                SharedPreferences.Editor editor = Prefs.edit(mContext);
1036                editor.putBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, true);
1037                editor.apply();
1038            }
1039        });
1040
1041        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1042                ViewGroup.LayoutParams.MATCH_PARENT,
1043                ViewGroup.LayoutParams.MATCH_PARENT,
1044                WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG,
1045                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
1046                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
1047                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
1048                PixelFormat.TRANSLUCENT);
1049        lp.setTitle("CompatibilityModeDialog");
1050        lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
1051                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
1052        lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade
1053
1054        WindowManagerImpl.getDefault().addView(mCompatibilityHelpDialog, lp);
1055    }
1056
1057    private void hideCompatibilityHelp() {
1058        if (mCompatibilityHelpDialog != null) {
1059            WindowManagerImpl.getDefault().removeView(mCompatibilityHelpDialog);
1060            mCompatibilityHelpDialog = null;
1061        }
1062    }
1063
1064    public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
1065        mInputMethodSwitchButton.setImeWindowStatus(token,
1066                (vis & InputMethodService.IME_ACTIVE) != 0);
1067        updateNotificationIcons();
1068        mInputMethodsPanel.setImeToken(token);
1069        int res;
1070        switch (backDisposition) {
1071            case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS:
1072                res = R.drawable.ic_sysbar_back;
1073                break;
1074            case InputMethodService.BACK_DISPOSITION_WILL_DISMISS:
1075                res = R.drawable.ic_sysbar_back_ime;
1076                break;
1077            case InputMethodService.BACK_DISPOSITION_DEFAULT:
1078            default:
1079                if ((vis & InputMethodService.IME_VISIBLE) != 0) {
1080                    res = R.drawable.ic_sysbar_back_ime;
1081                } else {
1082                    res = R.drawable.ic_sysbar_back;
1083                }
1084                break;
1085        }
1086        mBackButton.setImageResource(res);
1087        if (FAKE_SPACE_BAR) {
1088            mFakeSpaceBar.setVisibility(((vis & InputMethodService.IME_VISIBLE) != 0)
1089                    ? View.VISIBLE : View.GONE);
1090        }
1091    }
1092
1093    @Override
1094    public void setHardKeyboardStatus(boolean available, boolean enabled) {
1095        if (DEBUG) {
1096            Slog.d(TAG, "Set hard keyboard status: available=" + available
1097                    + ", enabled=" + enabled);
1098        }
1099        mInputMethodSwitchButton.setHardKeyboardStatus(available);
1100        updateNotificationIcons();
1101        mInputMethodsPanel.setHardKeyboardStatus(available, enabled);
1102    }
1103
1104    @Override
1105    public void onHardKeyboardEnabledChange(boolean enabled) {
1106        try {
1107            mBarService.setHardKeyboardEnabled(enabled);
1108        } catch (RemoteException ex) {
1109        }
1110    }
1111
1112    private boolean isImmersive() {
1113        try {
1114            return ActivityManagerNative.getDefault().isTopActivityImmersive();
1115            //Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive"));
1116        } catch (RemoteException ex) {
1117            // the end is nigh
1118            return false;
1119        }
1120    }
1121
1122    private void setAreThereNotifications() {
1123        final boolean hasClearable = mNotificationData.hasClearableItems();
1124    }
1125
1126    /**
1127     * Cancel this notification and tell the status bar service about the failure. Hold no locks.
1128     */
1129    void handleNotificationError(IBinder key, StatusBarNotification n, String message) {
1130        removeNotification(key);
1131        try {
1132            mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message);
1133        } catch (RemoteException ex) {
1134            // The end is nigh.
1135        }
1136    }
1137
1138    private void sendKey(KeyEvent key) {
1139        try {
1140            if (DEBUG) Slog.d(TAG, "injecting key event: " + key);
1141            mWindowManager.injectInputEventNoWait(key);
1142        } catch (RemoteException ex) {
1143        }
1144    }
1145
1146    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
1147        public void onClick(View v) {
1148            if (v == mNotificationTrigger) {
1149                onClickNotificationTrigger();
1150            } else if (v == mRecentButton) {
1151                onClickRecentButton();
1152            } else if (v == mInputMethodSwitchButton) {
1153                onClickInputMethodSwitchButton();
1154            } else if (v == mCompatModeButton) {
1155                onClickCompatModeButton();
1156            }
1157        }
1158    };
1159
1160    public void onClickNotificationTrigger() {
1161        if (DEBUG) Slog.d(TAG, "clicked notification icons; disabled=" + mDisabled);
1162        if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) {
1163            int msg = !mNotificationPanel.isShowing()
1164                ? MSG_OPEN_NOTIFICATION_PANEL
1165                : MSG_CLOSE_NOTIFICATION_PANEL;
1166            mHandler.removeMessages(msg);
1167            mHandler.sendEmptyMessage(msg);
1168        }
1169    }
1170
1171    public void onClickRecentButton() {
1172        if (DEBUG) Slog.d(TAG, "clicked recent apps; disabled=" + mDisabled);
1173        if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) {
1174            int msg = (mRecentsPanel.getVisibility() == View.GONE)
1175                ? MSG_OPEN_RECENTS_PANEL
1176                : MSG_CLOSE_RECENTS_PANEL;
1177            mHandler.removeMessages(msg);
1178            mHandler.sendEmptyMessage(msg);
1179        }
1180    }
1181
1182    public void onClickInputMethodSwitchButton() {
1183        if (DEBUG) Slog.d(TAG, "clicked input methods panel; disabled=" + mDisabled);
1184        int msg = (mInputMethodsPanel.getVisibility() == View.GONE) ?
1185                MSG_OPEN_INPUT_METHODS_PANEL : MSG_CLOSE_INPUT_METHODS_PANEL;
1186        mHandler.removeMessages(msg);
1187        mHandler.sendEmptyMessage(msg);
1188    }
1189
1190    public void onClickCompatModeButton() {
1191        int msg = (mCompatModePanel.getVisibility() == View.GONE) ?
1192                MSG_OPEN_COMPAT_MODE_PANEL : MSG_CLOSE_COMPAT_MODE_PANEL;
1193        mHandler.removeMessages(msg);
1194        mHandler.sendEmptyMessage(msg);
1195    }
1196
1197    public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag, int id) {
1198        return new NotificationClicker(intent, pkg, tag, id);
1199    }
1200
1201    private class NotificationClicker implements View.OnClickListener {
1202        private PendingIntent mIntent;
1203        private String mPkg;
1204        private String mTag;
1205        private int mId;
1206
1207        NotificationClicker(PendingIntent intent, String pkg, String tag, int id) {
1208            mIntent = intent;
1209            mPkg = pkg;
1210            mTag = tag;
1211            mId = id;
1212        }
1213
1214        public void onClick(View v) {
1215            try {
1216                // The intent we are sending is for the application, which
1217                // won't have permission to immediately start an activity after
1218                // the user switches to home.  We know it is safe to do at this
1219                // point, so make sure new activity switches are now allowed.
1220                ActivityManagerNative.getDefault().resumeAppSwitches();
1221            } catch (RemoteException e) {
1222            }
1223
1224            if (mIntent != null) {
1225                int[] pos = new int[2];
1226                v.getLocationOnScreen(pos);
1227                Intent overlay = new Intent();
1228                overlay.setSourceBounds(
1229                        new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight()));
1230                try {
1231                    mIntent.send(mContext, 0, overlay);
1232                } catch (PendingIntent.CanceledException e) {
1233                    // the stack trace isn't very helpful here.  Just log the exception message.
1234                    Slog.w(TAG, "Sending contentIntent failed: " + e);
1235                }
1236            }
1237
1238            try {
1239                mBarService.onNotificationClick(mPkg, mTag, mId);
1240            } catch (RemoteException ex) {
1241                // system process is dead if we're here.
1242            }
1243
1244            // close the shade if it was open
1245            animateCollapse();
1246
1247            // If this click was on the intruder alert, hide that instead
1248//            mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER);
1249        }
1250    }
1251
1252    StatusBarNotification removeNotificationViews(IBinder key) {
1253        NotificationData.Entry entry = mNotificationData.remove(key);
1254        if (entry == null) {
1255            Slog.w(TAG, "removeNotification for unknown key: " + key);
1256            return null;
1257        }
1258        // Remove the expanded view.
1259        ViewGroup rowParent = (ViewGroup)entry.row.getParent();
1260        if (rowParent != null) rowParent.removeView(entry.row);
1261
1262        if (key == mNotificationPeekKey) {
1263            // must close the peek as well, since it's gone
1264            mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK);
1265        }
1266        // Remove the icon.
1267//        ViewGroup iconParent = (ViewGroup)entry.icon.getParent();
1268//        if (iconParent != null) iconParent.removeView(entry.icon);
1269        updateNotificationIcons();
1270
1271        return entry.notification;
1272    }
1273
1274    private class NotificationTriggerTouchListener implements View.OnTouchListener {
1275        VelocityTracker mVT;
1276        float mInitialTouchX, mInitialTouchY;
1277        int mTouchSlop;
1278
1279        public NotificationTriggerTouchListener() {
1280            mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
1281        }
1282
1283        public boolean onTouch(View v, MotionEvent event) {
1284//            Slog.d(TAG, String.format("touch: (%.1f, %.1f) initial: (%.1f, %.1f)",
1285//                        event.getX(),
1286//                        event.getY(),
1287//                        mInitialTouchX,
1288//                        mInitialTouchY));
1289            final int action = event.getAction();
1290            switch (action) {
1291                case MotionEvent.ACTION_DOWN:
1292                    mVT = VelocityTracker.obtain();
1293                    mInitialTouchX = event.getX();
1294                    mInitialTouchY = event.getY();
1295                    // fall through
1296                case MotionEvent.ACTION_OUTSIDE:
1297                case MotionEvent.ACTION_MOVE:
1298                    // check for fling
1299                    if (mVT != null) {
1300                        mVT.addMovement(event);
1301                        mVT.computeCurrentVelocity(1000); // pixels per second
1302                        // require a little more oomph once we're already in peekaboo mode
1303                        if (mVT.getYVelocity() < -mNotificationFlingVelocity) {
1304                            animateExpand();
1305                            mVT.recycle();
1306                            mVT = null;
1307                        }
1308                    }
1309                    return true;
1310                case MotionEvent.ACTION_UP:
1311                case MotionEvent.ACTION_CANCEL:
1312                    if (mVT != null) {
1313                        if (action == MotionEvent.ACTION_UP
1314                         // was this a sloppy tap?
1315                         && Math.abs(event.getX() - mInitialTouchX) < mTouchSlop
1316                         && Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3)
1317                         // dragging off the bottom doesn't count
1318                         && (int)event.getY() < v.getBottom()) {
1319                            animateExpand();
1320                            v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
1321                            v.playSoundEffect(SoundEffectConstants.CLICK);
1322                        }
1323
1324                        mVT.recycle();
1325                        mVT = null;
1326                        return true;
1327                    }
1328            }
1329            return false;
1330        }
1331    }
1332
1333    final static int NOTIFICATION_PEEK_HOLD_THRESH = 200; // ms
1334    final static int NOTIFICATION_PEEK_FADE_DELAY = 3000; // ms
1335
1336    public void resetNotificationPeekFadeTimer() {
1337        if (DEBUG) {
1338            Slog.d(TAG, "setting peek fade timer for " + NOTIFICATION_PEEK_FADE_DELAY
1339                + "ms from now");
1340        }
1341        mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK);
1342        mHandler.sendEmptyMessageDelayed(MSG_CLOSE_NOTIFICATION_PEEK,
1343                NOTIFICATION_PEEK_FADE_DELAY);
1344    }
1345
1346    private class NotificationIconTouchListener implements View.OnTouchListener {
1347        VelocityTracker mVT;
1348        int mPeekIndex;
1349        float mInitialTouchX, mInitialTouchY;
1350        int mTouchSlop;
1351
1352        public NotificationIconTouchListener() {
1353            mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
1354        }
1355
1356        public boolean onTouch(View v, MotionEvent event) {
1357            boolean peeking = mNotificationPeekWindow.getVisibility() != View.GONE;
1358            boolean panelShowing = mNotificationPanel.isShowing();
1359            if (panelShowing) return false;
1360
1361            int numIcons = mIconLayout.getChildCount();
1362            int newPeekIndex = (int)(event.getX() * numIcons / mIconLayout.getWidth());
1363            if (newPeekIndex > numIcons - 1) newPeekIndex = numIcons - 1;
1364            else if (newPeekIndex < 0) newPeekIndex = 0;
1365
1366            final int action = event.getAction();
1367            switch (action) {
1368                case MotionEvent.ACTION_DOWN:
1369                    mVT = VelocityTracker.obtain();
1370                    mInitialTouchX = event.getX();
1371                    mInitialTouchY = event.getY();
1372                    mPeekIndex = -1;
1373
1374                    // fall through
1375                case MotionEvent.ACTION_OUTSIDE:
1376                case MotionEvent.ACTION_MOVE:
1377                    // peek and switch icons if necessary
1378
1379                    if (newPeekIndex != mPeekIndex) {
1380                        mPeekIndex = newPeekIndex;
1381
1382                        if (DEBUG) Slog.d(TAG, "will peek at notification #" + mPeekIndex);
1383                        Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK);
1384                        peekMsg.arg1 = mPeekIndex;
1385
1386                        mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
1387
1388                        if (peeking) {
1389                            // no delay if we're scrubbing left-right
1390                            mHandler.sendMessage(peekMsg);
1391                        } else {
1392                            // wait for fling
1393                            mHandler.sendMessageDelayed(peekMsg, NOTIFICATION_PEEK_HOLD_THRESH);
1394                        }
1395                    }
1396
1397                    // check for fling
1398                    if (mVT != null) {
1399                        mVT.addMovement(event);
1400                        mVT.computeCurrentVelocity(1000); // pixels per second
1401                        // require a little more oomph once we're already in peekaboo mode
1402                        if (!panelShowing && (
1403                               (peeking && mVT.getYVelocity() < -mNotificationFlingVelocity*3)
1404                            || (mVT.getYVelocity() < -mNotificationFlingVelocity))) {
1405                            mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
1406                            mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL);
1407                            mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PEEK);
1408                            mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL);
1409                        }
1410                    }
1411                    return true;
1412                case MotionEvent.ACTION_UP:
1413                case MotionEvent.ACTION_CANCEL:
1414                    mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
1415                    if (!peeking) {
1416                        if (action == MotionEvent.ACTION_UP
1417                                // was this a sloppy tap?
1418                                && Math.abs(event.getX() - mInitialTouchX) < mTouchSlop
1419                                && Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3)
1420                                // dragging off the bottom doesn't count
1421                                && (int)event.getY() < v.getBottom()) {
1422                            Message peekMsg = mHandler.obtainMessage(MSG_OPEN_NOTIFICATION_PEEK);
1423                            peekMsg.arg1 = mPeekIndex;
1424                            mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PEEK);
1425                            mHandler.sendMessage(peekMsg);
1426
1427                            v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
1428                            v.playSoundEffect(SoundEffectConstants.CLICK);
1429
1430                            peeking = true; // not technically true yet, but the next line will run
1431                        }
1432                    }
1433
1434                    if (peeking) {
1435                        resetNotificationPeekFadeTimer();
1436                    }
1437
1438                    mVT.recycle();
1439                    mVT = null;
1440                    return true;
1441            }
1442            return false;
1443        }
1444    }
1445
1446    StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) {
1447        if (DEBUG) {
1448            Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification);
1449        }
1450        // Construct the icon.
1451        final StatusBarIconView iconView = new StatusBarIconView(mContext,
1452                notification.pkg + "/0x" + Integer.toHexString(notification.id),
1453                notification.notification);
1454        iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
1455
1456        final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
1457                    notification.notification.icon,
1458                    notification.notification.iconLevel,
1459                    notification.notification.number,
1460                    notification.notification.tickerText);
1461        if (!iconView.set(ic)) {
1462            handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic);
1463            return null;
1464        }
1465        // Construct the expanded view.
1466        NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView);
1467        if (!inflateViews(entry, mPile)) {
1468            handleNotificationError(key, notification, "Couldn't expand RemoteViews for: "
1469                    + notification);
1470            return null;
1471        }
1472
1473        // Add the icon.
1474        int pos = mNotificationData.add(entry);
1475        if (DEBUG) {
1476            Slog.d(TAG, "addNotificationViews: added at " + pos);
1477        }
1478        updateNotificationIcons();
1479
1480        return iconView;
1481    }
1482
1483    private void reloadAllNotificationIcons() {
1484        if (mIconLayout == null) return;
1485        mIconLayout.removeAllViews();
1486        updateNotificationIcons();
1487    }
1488
1489    private void updateNotificationIcons() {
1490        // XXX: need to implement a new limited linear layout class
1491        // to avoid removing & readding everything
1492
1493        if (mIconLayout == null) return;
1494
1495        // first, populate the main notification panel
1496        loadNotificationPanel();
1497
1498        final LinearLayout.LayoutParams params
1499            = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight);
1500
1501        // alternate behavior in DND mode
1502        if (mNotificationDNDMode) {
1503            if (mIconLayout.getChildCount() == 0) {
1504                final Notification dndNotification = new Notification.Builder(mContext)
1505                    .setContentTitle(mContext.getText(R.string.notifications_off_title))
1506                    .setContentText(mContext.getText(R.string.notifications_off_text))
1507                    .setSmallIcon(R.drawable.ic_notification_dnd)
1508                    .setOngoing(true)
1509                    .getNotification();
1510
1511                final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd",
1512                        dndNotification);
1513                iconView.setImageResource(R.drawable.ic_notification_dnd);
1514                iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
1515                iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0);
1516
1517                mNotificationDNDDummyEntry = new NotificationData.Entry(
1518                        null,
1519                        new StatusBarNotification("", 0, "", 0, 0, dndNotification),
1520                        iconView);
1521
1522                mIconLayout.addView(iconView, params);
1523            }
1524
1525            return;
1526        }
1527
1528        int N = mNotificationData.size();
1529
1530        if (DEBUG) {
1531            Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout);
1532        }
1533
1534        ArrayList<View> toShow = new ArrayList<View>();
1535
1536        // Extra Special Icons
1537        // The IME switcher and compatibility mode icons take the place of notifications. You didn't
1538        // need to see all those new emails, did you?
1539        int maxNotificationIconsCount = mMaxNotificationIcons;
1540        if (mInputMethodSwitchButton.getVisibility() != View.GONE) maxNotificationIconsCount --;
1541        if (mCompatModeButton.getVisibility()        != View.GONE) maxNotificationIconsCount --;
1542
1543        for (int i=0; i< maxNotificationIconsCount; i++) {
1544            if (i>=N) break;
1545            toShow.add(mNotificationData.get(N-i-1).icon);
1546        }
1547
1548        ArrayList<View> toRemove = new ArrayList<View>();
1549        for (int i=0; i<mIconLayout.getChildCount(); i++) {
1550            View child = mIconLayout.getChildAt(i);
1551            if (!toShow.contains(child)) {
1552                toRemove.add(child);
1553            }
1554        }
1555
1556        for (View remove : toRemove) {
1557            mIconLayout.removeView(remove);
1558        }
1559
1560        for (int i=0; i<toShow.size(); i++) {
1561            View v = toShow.get(i);
1562            v.setPadding(mIconHPadding, 0, mIconHPadding, 0);
1563            if (v.getParent() == null) {
1564                mIconLayout.addView(v, i, params);
1565            }
1566        }
1567    }
1568
1569    private void loadNotificationPanel() {
1570        int N = mNotificationData.size();
1571
1572        ArrayList<View> toShow = new ArrayList<View>();
1573
1574        for (int i=0; i<N; i++) {
1575            View row = mNotificationData.get(N-i-1).row;
1576            toShow.add(row);
1577        }
1578
1579        ArrayList<View> toRemove = new ArrayList<View>();
1580        for (int i=0; i<mPile.getChildCount(); i++) {
1581            View child = mPile.getChildAt(i);
1582            if (!toShow.contains(child)) {
1583                toRemove.add(child);
1584            }
1585        }
1586
1587        for (View remove : toRemove) {
1588            mPile.removeView(remove);
1589        }
1590
1591        for (int i=0; i<toShow.size(); i++) {
1592            View v = toShow.get(i);
1593            if (v.getParent() == null) {
1594                mPile.addView(v, N-1-i); // the notification panel has newest at the bottom
1595            }
1596        }
1597
1598        mNotificationPanel.setNotificationCount(N);
1599    }
1600
1601    void workAroundBadLayerDrawableOpacity(View v) {
1602        LayerDrawable d = (LayerDrawable)v.getBackground();
1603        if (d == null) return;
1604        v.setBackgroundDrawable(null);
1605        d.setOpacity(PixelFormat.TRANSLUCENT);
1606        v.setBackgroundDrawable(d);
1607    }
1608
1609    private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) {
1610        StatusBarNotification sbn = entry.notification;
1611        RemoteViews remoteViews = sbn.notification.contentView;
1612        if (remoteViews == null) {
1613            return false;
1614        }
1615
1616        // create the row view
1617        LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(
1618                Context.LAYOUT_INFLATER_SERVICE);
1619        View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false);
1620        workAroundBadLayerDrawableOpacity(row);
1621        View vetoButton = row.findViewById(R.id.veto);
1622        if (entry.notification.isClearable()) {
1623            final String _pkg = sbn.pkg;
1624            final String _tag = sbn.tag;
1625            final int _id = sbn.id;
1626            vetoButton.setOnClickListener(new View.OnClickListener() {
1627                    public void onClick(View v) {
1628                        try {
1629                            mBarService.onNotificationClear(_pkg, _tag, _id);
1630                        } catch (RemoteException ex) {
1631                            // system process is dead if we're here.
1632                        }
1633                    }
1634                });
1635        } else {
1636            if ((sbn.notification.flags & Notification.FLAG_ONGOING_EVENT) == 0) {
1637                vetoButton.setVisibility(View.INVISIBLE);
1638                vetoButton.setContentDescription("VETO");
1639            } else {
1640                vetoButton.setVisibility(View.GONE);
1641            }
1642        }
1643        vetoButton.setContentDescription(mContext.getString(
1644                R.string.accessibility_remove_notification));
1645
1646        // the large icon
1647        ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon);
1648        if (sbn.notification.largeIcon != null) {
1649            largeIcon.setImageBitmap(sbn.notification.largeIcon);
1650            largeIcon.setContentDescription(sbn.notification.tickerText);
1651        } else {
1652            largeIcon.getLayoutParams().width = 0;
1653            largeIcon.setVisibility(View.INVISIBLE);
1654        }
1655        largeIcon.setContentDescription(sbn.notification.tickerText);
1656
1657        // bind the click event to the content area
1658        ViewGroup content = (ViewGroup)row.findViewById(R.id.content);
1659        // XXX: update to allow controls within notification views
1660        content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
1661//        content.setOnFocusChangeListener(mFocusChangeListener);
1662        PendingIntent contentIntent = sbn.notification.contentIntent;
1663        if (contentIntent != null) {
1664            content.setOnClickListener(new NotificationClicker(contentIntent,
1665                        sbn.pkg, sbn.tag, sbn.id));
1666        } else {
1667            content.setOnClickListener(null);
1668        }
1669
1670        View expanded = null;
1671        Exception exception = null;
1672        try {
1673            expanded = remoteViews.apply(mContext, content);
1674        }
1675        catch (RuntimeException e) {
1676            exception = e;
1677        }
1678        if (expanded == null) {
1679            final String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id);
1680            Slog.e(TAG, "couldn't inflate view for notification " + ident, exception);
1681            return false;
1682        } else {
1683            content.addView(expanded);
1684            row.setDrawingCacheEnabled(true);
1685        }
1686
1687        entry.row = row;
1688        entry.content = content;
1689        entry.expanded = expanded;
1690        entry.largeIcon = largeIcon;
1691
1692        return true;
1693    }
1694
1695    public void userActivity() {
1696    }
1697
1698    public void toggleRecentApps() {
1699        int msg = (mRecentsPanel.getVisibility() == View.GONE)
1700                ? MSG_OPEN_RECENTS_PANEL : MSG_CLOSE_RECENTS_PANEL;
1701        mHandler.removeMessages(msg);
1702        mHandler.sendEmptyMessage(msg);
1703    }
1704
1705    public class TouchOutsideListener implements View.OnTouchListener {
1706        private int mMsg;
1707        private StatusBarPanel mPanel;
1708
1709        public TouchOutsideListener(int msg, StatusBarPanel panel) {
1710            mMsg = msg;
1711            mPanel = panel;
1712        }
1713
1714        public boolean onTouch(View v, MotionEvent ev) {
1715            final int action = ev.getAction();
1716            if (action == MotionEvent.ACTION_OUTSIDE
1717                    || (action == MotionEvent.ACTION_DOWN
1718                        && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) {
1719                mHandler.removeMessages(mMsg);
1720                mHandler.sendEmptyMessage(mMsg);
1721                return true;
1722            }
1723            return false;
1724        }
1725    }
1726
1727    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1728        pw.print("mDisabled=0x");
1729        pw.println(Integer.toHexString(mDisabled));
1730        pw.println("mNetworkController:");
1731        mNetworkController.dump(fd, pw, args);
1732    }
1733}
1734
1735
1736