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