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