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