PhoneStatusBar.java revision 4eaa983f253d0215d4de777edd8616318610ea22
1808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato/*
2808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato * Copyright (C) 2010 The Android Open Source Project
3808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato *
4808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato * Licensed under the Apache License, Version 2.0 (the "License");
5808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato * you may not use this file except in compliance with the License.
6808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato * You may obtain a copy of the License at
7808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato *
8808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato *      http://www.apache.org/licenses/LICENSE-2.0
9808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato *
10808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato * Unless required by applicable law or agreed to in writing, software
11808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato * distributed under the License is distributed on an "AS IS" BASIS,
12808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato * See the License for the specific language governing permissions and
14808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato * limitations under the License.
15808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato */
16808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
17fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onoratopackage com.android.systemui.statusbar.phone;
18808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
190761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandlerimport android.animation.ObjectAnimator;
20fc8fa638617efb5695a1f89ea75375faebbe2a40Dianne Hackbornimport android.app.ActivityManager;
21808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.app.ActivityManagerNative;
22808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.app.Dialog;
2392d331883ada42e49001853e266cda2d9c8631b8Daniel Sandlerimport android.app.KeyguardManager;
24808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.app.Notification;
25808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.app.PendingIntent;
26808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.app.StatusBarManager;
27808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.content.BroadcastReceiver;
28808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.content.Context;
29808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.content.Intent;
30808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.content.IntentFilter;
3129ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powellimport android.content.pm.ApplicationInfo;
3229ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powellimport android.content.pm.PackageManager.NameNotFoundException;
33808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.content.res.Resources;
343b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurkaimport android.content.res.Configuration;
35328310c6fac6066d338926bb43d359862cae36d2Daniel Sandlerimport android.inputmethodservice.InputMethodService;
36808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.graphics.PixelFormat;
37808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.graphics.Rect;
38808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.graphics.drawable.Drawable;
3929ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powellimport android.os.Build;
40808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.os.IBinder;
41808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.os.RemoteException;
42808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.os.Handler;
43808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.os.Message;
441d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandlerimport android.os.ServiceManager;
45808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.os.SystemClock;
46d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandlerimport android.provider.Settings;
47935865923fdad9f47061ff0aedfe92d0b912d5d6Joe Onoratoimport android.text.TextUtils;
4836412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandlerimport android.util.DisplayMetrics;
49808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.util.Slog;
50808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.util.Log;
51808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.Display;
52808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.Gravity;
531d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandlerimport android.view.IWindowManager;
54808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.KeyEvent;
55808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.LayoutInflater;
56808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.MotionEvent;
57808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.VelocityTracker;
58808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.View;
59808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.ViewGroup;
60f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Millerimport android.view.ViewGroup.LayoutParams;
61808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.Window;
62808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.WindowManager;
63808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.WindowManagerImpl;
64808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.animation.Animation;
65808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.view.animation.AnimationUtils;
66808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.widget.ImageView;
67808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.widget.LinearLayout;
68808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.widget.RemoteViews;
69808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.widget.ScrollView;
70808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport android.widget.TextView;
71808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
72808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport java.io.FileDescriptor;
73808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport java.io.PrintWriter;
74808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport java.util.ArrayList;
75808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
76808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport com.android.internal.statusbar.StatusBarIcon;
77808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport com.android.internal.statusbar.StatusBarNotification;
78808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
79808182dc874e93582da38d013a4a790d6bc08fc9Joe Onoratoimport com.android.systemui.R;
80ab48b681401628a191a4a90d4906fa88edde95baMichael Jurkaimport com.android.systemui.recent.RecentTasksLoader;
813b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurkaimport com.android.systemui.recent.RecentsPanelView;
82ab48b681401628a191a4a90d4906fa88edde95baMichael Jurkaimport com.android.systemui.recent.TaskDescription;
83fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onoratoimport com.android.systemui.statusbar.NotificationData;
84fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onoratoimport com.android.systemui.statusbar.StatusBar;
85fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onoratoimport com.android.systemui.statusbar.StatusBarIconView;
862e347429dfcd03b0827c7506ba6305ab0d1f4951Christian Robertsonimport com.android.systemui.statusbar.SignalClusterView;
87fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onoratoimport com.android.systemui.statusbar.policy.DateView;
882b69735e014872ca2183b4a39a8381daa337e146Daniel Sandlerimport com.android.systemui.statusbar.policy.BatteryController;
892b69735e014872ca2183b4a39a8381daa337e146Daniel Sandlerimport com.android.systemui.statusbar.policy.LocationController;
902b69735e014872ca2183b4a39a8381daa337e146Daniel Sandlerimport com.android.systemui.statusbar.policy.NetworkController;
918ba33c965f940070060585e45e1c833519bb45c9Daniel Sandlerimport com.android.systemui.statusbar.policy.NotificationRowLayout;
92808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
93fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onoratopublic class PhoneStatusBar extends StatusBar {
94fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onorato    static final String TAG = "PhoneStatusBar";
953b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    public static final boolean DEBUG = false;
9636412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler    public static final boolean SPEW = false;
977579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler    public static final boolean DUMPTRUCK = true; // extra dumpsys info
98808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
9996e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler    // additional instrumentation for testing purposes; intended to be left on during development
1007c35174a6f0fd6a01b6d63418bf4355f16b8ae64Daniel Sandler    public static final boolean CHATTY = DEBUG;
10196e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler
102808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public static final String ACTION_STATUSBAR_START
103808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            = "com.android.internal.policy.statusbar.START";
104808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
105fc6fda3950338ce737f096548a079342317cfd7fDaniel Sandler    private static final boolean ENABLE_INTRUDERS = false;
106fc6fda3950338ce737f096548a079342317cfd7fDaniel Sandler
107808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    static final int EXPANDED_LEAVE_ALONE = -10000;
108808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    static final int EXPANDED_FULL_OPEN = -10001;
109808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1108ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler    private static final int MSG_ANIMATE = 100;
1118ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler    private static final int MSG_ANIMATE_REVEAL = 101;
1128ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler    private static final int MSG_OPEN_NOTIFICATION_PANEL = 1000;
1138ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler    private static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001;
114808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private static final int MSG_SHOW_INTRUDER = 1002;
115808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private static final int MSG_HIDE_INTRUDER = 1003;
1163b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    private static final int MSG_OPEN_RECENTS_PANEL = 1020;
1173b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    private static final int MSG_CLOSE_RECENTS_PANEL = 1021;
118808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
119808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // will likely move to a resource or other tunable param at some point
120808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private static final int INTRUDER_ALERT_DECAY_MS = 10000;
121808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1228cc36e572876f3bb9197f0109db3042466e5f917Daniel Sandler    private static final boolean CLOSE_PANEL_WHEN_EMPTIED = true;
1238cc36e572876f3bb9197f0109db3042466e5f917Daniel Sandler
124dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    // fling gesture tuning parameters, scaled to display density
125dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    private float mSelfExpandVelocityPx; // classic value: 2000px/s
126dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    private float mSelfCollapseVelocityPx; // classic value: 2000px/s (will be negated to collapse "up")
127dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    private float mFlingExpandMinVelocityPx; // classic value: 200px/s
128dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    private float mFlingCollapseMinVelocityPx; // classic value: 200px/s
129dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    private float mCollapseMinDisplayFraction; // classic value: 0.08 (25px/min(320px,480px) on G1)
130dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    private float mExpandMinDisplayFraction; // classic value: 0.5 (drag open halfway to expand)
131dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    private float mFlingGestureMaxXVelocityPx; // classic value: 150px/s
132dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler
133dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    private float mExpandAccelPx; // classic value: 2000px/s/s
134dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler    private float mCollapseAccelPx; // classic value: 2000px/s/s (will be negated to collapse "up")
135dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler
136fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onorato    PhoneStatusBarPolicy mIconPolicy;
137808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1382b69735e014872ca2183b4a39a8381daa337e146Daniel Sandler    // These are no longer handled by the policy, because we need custom strategies for them
1392b69735e014872ca2183b4a39a8381daa337e146Daniel Sandler    BatteryController mBatteryController;
1402b69735e014872ca2183b4a39a8381daa337e146Daniel Sandler    LocationController mLocationController;
1412b69735e014872ca2183b4a39a8381daa337e146Daniel Sandler    NetworkController mNetworkController;
1425e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller
1437c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    int mNaturalBarHeight = -1;
1447c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    int mIconSize = -1;
1457c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    int mIconHPadding = -1;
146808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    Display mDisplay;
147808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1481d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler    IWindowManager mWindowManager;
1491d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler
150fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onorato    PhoneStatusBarView mStatusBarView;
151808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    int mPixelFormat;
152808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    H mHandler = new H();
153808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    Object mQueueLock = new Object();
154808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
155808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // icons
156808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    LinearLayout mIcons;
157808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    IconMerger mNotificationIcons;
15805e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler    View mMoreIcon;
159808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    LinearLayout mStatusIcons;
160808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
161808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // expanded notifications
162808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    Dialog mExpandedDialog;
163808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    ExpandedView mExpandedView;
164808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    WindowManager.LayoutParams mExpandedParams;
165808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    ScrollView mScrollView;
166808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    View mExpandedContents;
167808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // top bar
168808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    TextView mNoNotificationsTitle;
1691347c30824ce3544dff03c93ffad9af7f0327e41Daniel Sandler    View mClearButton;
170d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler    View mSettingsButton;
171d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler
172808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // drag bar
173808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    CloseDragHandle mCloseView;
1745e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller
1757c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    // all notifications
1767c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    NotificationData mNotificationData = new NotificationData();
1778ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler    NotificationRowLayout mPile;
1787c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
179808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // position
180808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    int[] mPositionTmp = new int[2];
181808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    boolean mExpanded;
182808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    boolean mExpandedVisible;
183808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
184808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // the date view
185808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    DateView mDateView;
186808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
187808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // for immersive activities
188808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private View mIntruderAlertView;
189808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1908956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler    // on-screen navigation buttons
1910129b31ff493bb0aa10b778cbeacbec5964644f8Daniel Sandler    private NavigationBarView mNavigationBarView = null;
1928956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler
193808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // the tracker view
194808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    TrackingView mTrackingView;
195808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    WindowManager.LayoutParams mTrackingParams;
196808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    int mTrackingPosition; // the position of the top of the tracking view.
197808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private boolean mPanelSlightlyVisible;
198808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
199808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // ticker
200808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private Ticker mTicker;
201808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private View mTickerView;
202808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private boolean mTicking;
203808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2047daf95d5526e3b60f5db29cbacd9a4852d99a6f4Michael Jurka    // Recent apps
2053b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    private RecentsPanelView mRecentsPanel;
206ab48b681401628a191a4a90d4906fa88edde95baMichael Jurka    private RecentTasksLoader mRecentTasksLoader;
2073b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
208808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // Tracking finger for opening/closing.
209808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    int mEdgeBorder; // corresponds to R.dimen.status_bar_edge_ignore
210808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    boolean mTracking;
211808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    VelocityTracker mVelocityTracker;
212808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
213808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    static final int ANIM_FRAME_DURATION = (1000/60);
214808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
215808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    boolean mAnimating;
216808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    long mCurAnimationTime;
217808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    float mAnimY;
218808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    float mAnimVel;
219808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    float mAnimAccel;
220808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    long mAnimLastTime;
221808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    boolean mAnimatingReveal = false;
222808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    int mViewDelta;
223808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    int[] mAbsPos = new int[2];
2242f2022afa1eb85018368398bd150e9575fc099c9Chet Haase    Runnable mPostCollapseCleanup = null;
2252f2022afa1eb85018368398bd150e9575fc099c9Chet Haase
226808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
227808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // for disabling the status bar
228808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    int mDisabled = 0;
229808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
23060ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler    // tracking calls to View.setSystemUiVisibility()
23160ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler    int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
23260ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler
23336412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler    DisplayMetrics mDisplayMetrics = new DisplayMetrics();
2341dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn
235328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler    private int mNavigationIconHints = 0;
236328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler
2372561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    // TODO(dsandler): codify this stuff in NotificationManager's header somewhere
2382561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    private int mDisplayMinScore             = Notification.PRIORITY_LOW * 10;
2392561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    private int mIntruderMinScore            = Notification.PRIORITY_HIGH * 10;
2402561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    private int mIntruderInImmersiveMinScore = Notification.PRIORITY_HIGH * 10 + 5;
2412561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler
242808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private class ExpandedDialog extends Dialog {
243808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        ExpandedDialog(Context context) {
24436412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            super(context, com.android.internal.R.style.Theme_Translucent_NoTitleBar);
245808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
246808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
247808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        @Override
248808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public boolean dispatchKeyEvent(KeyEvent event) {
249808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
250808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            switch (event.getKeyCode()) {
251808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            case KeyEvent.KEYCODE_BACK:
252808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (!down) {
253808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    animateCollapse();
254808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
255808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                return true;
256808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
257808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return super.dispatchKeyEvent(event);
258808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
259808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
260808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
261808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    @Override
262f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato    public void start() {
263f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato        mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
264f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato                .getDefaultDisplay();
265808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2661d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler        mWindowManager = IWindowManager.Stub.asInterface(
2671d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler                ServiceManager.getService(Context.WINDOW_SERVICE));
2681d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler
2696e8db88b4b31a6e0211561f25ee1a422e4797ba1Daniel Sandler        super.start(); // calls makeStatusBarView()
270808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2718956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler        addNavigationBar();
2728956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler
273fc6fda3950338ce737f096548a079342317cfd7fDaniel Sandler        if (ENABLE_INTRUDERS) addIntruderView();
274808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
275808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // Lastly, call to the icon policy to install/update all the icons.
276fd52b18d9bf3cd62c7a07058536e9f97db65beeaJoe Onorato        mIconPolicy = new PhoneStatusBarPolicy(mContext);
277808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
278808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
279808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // ================================================================================
280808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // Constructing the view
281808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // ================================================================================
282808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    protected View makeStatusBarView() {
283f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato        final Context context = mContext;
284808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
285808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        Resources res = context.getResources();
286808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2876e8db88b4b31a6e0211561f25ee1a422e4797ba1Daniel Sandler        updateDisplaySize(); // populates mDisplayMetrics
2887c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        loadDimens();
289808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2901dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn        mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
2911dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn
292808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        ExpandedView expanded = (ExpandedView)View.inflate(context,
293808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                R.layout.status_bar_expanded, null);
294cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler        if (DEBUG) {
295cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler            expanded.setBackgroundColor(0x6000FF80);
296cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler        }
297808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        expanded.mService = this;
298808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
299808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mIntruderAlertView = View.inflate(context, R.layout.intruder_alert, null);
300808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mIntruderAlertView.setVisibility(View.GONE);
301808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mIntruderAlertView.setClickable(true);
302808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
30360ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler        PhoneStatusBarView sb = (PhoneStatusBarView)View.inflate(context,
30460ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler                R.layout.status_bar, null);
30560ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler        sb.mService = this;
30660ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler        mStatusBarView = sb;
30760ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler
3080129b31ff493bb0aa10b778cbeacbec5964644f8Daniel Sandler        try {
3090c4ccff36930ff4f0292b94ad51e164c9fa060a3Daniel Sandler            boolean showNav = mWindowManager.hasNavigationBar();
3100129b31ff493bb0aa10b778cbeacbec5964644f8Daniel Sandler            if (showNav) {
3115e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller                mNavigationBarView =
3120129b31ff493bb0aa10b778cbeacbec5964644f8Daniel Sandler                    (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null);
31360ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler
3146da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler                mNavigationBarView.setDisabledFlags(mDisabled);
3150129b31ff493bb0aa10b778cbeacbec5964644f8Daniel Sandler            }
3160c4ccff36930ff4f0292b94ad51e164c9fa060a3Daniel Sandler        } catch (RemoteException ex) {
3170c4ccff36930ff4f0292b94ad51e164c9fa060a3Daniel Sandler            // no window manager? good luck with that
3180129b31ff493bb0aa10b778cbeacbec5964644f8Daniel Sandler        }
3198956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler
320808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // figure out which pixel-format to use for the status bar.
321f733c2aaa652f3ead60c8b2bc982dc9bdbc7df8eDaniel Sandler        mPixelFormat = PixelFormat.OPAQUE;
322808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mStatusIcons = (LinearLayout)sb.findViewById(R.id.statusIcons);
323808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mNotificationIcons = (IconMerger)sb.findViewById(R.id.notificationIcons);
32405e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler        mMoreIcon = sb.findViewById(R.id.moreIcon);
32505e2414ef5a3a8fecbabc1f220c9925539d51f7aDaniel Sandler        mNotificationIcons.setOverflowIndicator(mMoreIcon);
326808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mIcons = (LinearLayout)sb.findViewById(R.id.icons);
327808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTickerView = sb.findViewById(R.id.ticker);
328808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
329808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedDialog = new ExpandedDialog(context);
330808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedView = expanded;
3318ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler        mPile = (NotificationRowLayout)expanded.findViewById(R.id.latestItems);
3320761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        mExpandedContents = mPile; // was: expanded.findViewById(R.id.notificationLinearLayout);
333808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mNoNotificationsTitle = (TextView)expanded.findViewById(R.id.noNotificationsTitle);
334d714148bd2752c63a46f51b12cea288fb1f10528Daniel Sandler        mNoNotificationsTitle.setVisibility(View.GONE); // disabling for now
335d714148bd2752c63a46f51b12cea288fb1f10528Daniel Sandler
3361347c30824ce3544dff03c93ffad9af7f0327e41Daniel Sandler        mClearButton = expanded.findViewById(R.id.clear_all_button);
337808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mClearButton.setOnClickListener(mClearButtonListener);
3380761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        mClearButton.setAlpha(0f);
3398ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler        mClearButton.setEnabled(false);
340d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler        mDateView = (DateView)expanded.findViewById(R.id.date);
341d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler        mSettingsButton = expanded.findViewById(R.id.settings_button);
342d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler        mSettingsButton.setOnClickListener(mSettingsButtonListener);
343808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mScrollView = (ScrollView)expanded.findViewById(R.id.scroll);
344808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
345808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTicker = new MyTicker(context, sb);
346808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
347808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        TickerView tickerView = (TickerView)sb.findViewById(R.id.tickerText);
348808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        tickerView.mTicker = mTicker;
349808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
350808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTrackingView = (TrackingView)View.inflate(context, R.layout.status_bar_tracking, null);
351808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTrackingView.mService = this;
352808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mCloseView = (CloseDragHandle)mTrackingView.findViewById(R.id.close);
353808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mCloseView.mService = this;
354808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
355808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore);
356808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
357808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // set the inital view visibility
358808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        setAreThereNotifications();
359808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
3602b69735e014872ca2183b4a39a8381daa337e146Daniel Sandler        // Other icons
3612b69735e014872ca2183b4a39a8381daa337e146Daniel Sandler        mLocationController = new LocationController(mContext); // will post a notification
3622b69735e014872ca2183b4a39a8381daa337e146Daniel Sandler        mBatteryController = new BatteryController(mContext);
3632b69735e014872ca2183b4a39a8381daa337e146Daniel Sandler        mBatteryController.addIconView((ImageView)sb.findViewById(R.id.battery));
3642b69735e014872ca2183b4a39a8381daa337e146Daniel Sandler        mNetworkController = new NetworkController(mContext);
3655e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller        final SignalClusterView signalCluster =
3662e347429dfcd03b0827c7506ba6305ab0d1f4951Christian Robertson                (SignalClusterView)sb.findViewById(R.id.signal_cluster);
3672e347429dfcd03b0827c7506ba6305ab0d1f4951Christian Robertson        mNetworkController.addSignalCluster(signalCluster);
36828f89d40ee7bab93cf7b783f92dbb18bdc43e473Daniel Sandler        signalCluster.setNetworkController(mNetworkController);
3695e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller//        final ImageView wimaxRSSI =
370633eabe56d3126fa92eb56636019e5792e20a5daDaniel Sandler//                (ImageView)sb.findViewById(R.id.wimax_signal);
371633eabe56d3126fa92eb56636019e5792e20a5daDaniel Sandler//        if (wimaxRSSI != null) {
372633eabe56d3126fa92eb56636019e5792e20a5daDaniel Sandler//            mNetworkController.addWimaxIconView(wimaxRSSI);
373633eabe56d3126fa92eb56636019e5792e20a5daDaniel Sandler//        }
3743b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        // Recents Panel
375ab48b681401628a191a4a90d4906fa88edde95baMichael Jurka        mRecentTasksLoader = new RecentTasksLoader(context);
37617dfec7111fcc53a4f6ae6e92b4a7f85a278fe71Jim Miller        updateRecentsPanel();
3773b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
378808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // receive broadcasts
379808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        IntentFilter filter = new IntentFilter();
380808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
381808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
382808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        filter.addAction(Intent.ACTION_SCREEN_OFF);
383808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        context.registerReceiver(mBroadcastReceiver, filter);
384808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
385808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        return sb;
386808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
387808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
388f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Miller    protected WindowManager.LayoutParams getRecentsLayoutParams(LayoutParams layoutParams) {
3893cd0a593937c0724d77db1e2e3995255cfae61acMichael Jurka        boolean opaque = false;
3903b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
391f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Miller                layoutParams.width,
392f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Miller                layoutParams.height,
3933b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
3943b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
3953b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
396fc8fa638617efb5695a1f89ea75375faebbe2a40Dianne Hackborn                | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
3973cd0a593937c0724d77db1e2e3995255cfae61acMichael Jurka                (opaque ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT));
398fc8fa638617efb5695a1f89ea75375faebbe2a40Dianne Hackborn        if (ActivityManager.isHighEndGfx(mDisplay)) {
399fc8fa638617efb5695a1f89ea75375faebbe2a40Dianne Hackborn            lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
400f16fc51d96be53a844877674b98cb70e60b45278Michael Jurka        } else {
401f16fc51d96be53a844877674b98cb70e60b45278Michael Jurka            lp.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
402f16fc51d96be53a844877674b98cb70e60b45278Michael Jurka            lp.dimAmount = 0.7f;
403fc8fa638617efb5695a1f89ea75375faebbe2a40Dianne Hackborn        }
4043b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        lp.gravity = Gravity.BOTTOM | Gravity.LEFT;
4053b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        lp.setTitle("RecentsPanel");
40699a9655b9333c3bff6e462b12baa56a5fcd4cb20Michael Jurka        lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications;
4073b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
4083b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
4093b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        return lp;
4103b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    }
4113b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
41217dfec7111fcc53a4f6ae6e92b4a7f85a278fe71Jim Miller    protected void updateRecentsPanel() {
4133b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        // Recents Panel
4143b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        boolean visible = false;
415ab48b681401628a191a4a90d4906fa88edde95baMichael Jurka        ArrayList<TaskDescription> recentTasksList = null;
41699a9655b9333c3bff6e462b12baa56a5fcd4cb20Michael Jurka        boolean firstScreenful = false;
4173b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        if (mRecentsPanel != null) {
4188b09866a25ade5cd3630996adff8c976268ec637Michael Jurka            visible = mRecentsPanel.isShowing();
4193b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            WindowManagerImpl.getDefault().removeView(mRecentsPanel);
420ab48b681401628a191a4a90d4906fa88edde95baMichael Jurka            if (visible) {
421ab48b681401628a191a4a90d4906fa88edde95baMichael Jurka                recentTasksList = mRecentsPanel.getRecentTasksList();
42299a9655b9333c3bff6e462b12baa56a5fcd4cb20Michael Jurka                firstScreenful = mRecentsPanel.getFirstScreenful();
423ab48b681401628a191a4a90d4906fa88edde95baMichael Jurka            }
4243b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        }
425f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Miller
426f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Miller        // Provide RecentsPanelView with a temporary parent to allow layout params to work.
427f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Miller        LinearLayout tmpRoot = new LinearLayout(mContext);
428f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Miller        mRecentsPanel = (RecentsPanelView) LayoutInflater.from(mContext).inflate(
429f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Miller                R.layout.status_bar_recent_panel, tmpRoot, false);
430ab48b681401628a191a4a90d4906fa88edde95baMichael Jurka        mRecentsPanel.setRecentTasksLoader(mRecentTasksLoader);
431ab48b681401628a191a4a90d4906fa88edde95baMichael Jurka        mRecentTasksLoader.setRecentsPanel(mRecentsPanel);
4323b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL,
4333b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                mRecentsPanel));
4343b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        mRecentsPanel.setVisibility(View.GONE);
4354eaa983f253d0215d4de777edd8616318610ea22Michael Jurka
4364eaa983f253d0215d4de777edd8616318610ea22Michael Jurka        // Make .03 alpha the minimum so you always see the item a bit-- slightly below
4374eaa983f253d0215d4de777edd8616318610ea22Michael Jurka        // .03, the item disappears entirely (as if alpha = 0) and that discontinuity looks
4384eaa983f253d0215d4de777edd8616318610ea22Michael Jurka        // a bit jarring
4394eaa983f253d0215d4de777edd8616318610ea22Michael Jurka        mRecentsPanel.setMinSwipeAlpha(0.03f);
440f2a16b27afd1ede5880d05eb9e19090c7e3e820eJim Miller        WindowManager.LayoutParams lp = getRecentsLayoutParams(mRecentsPanel.getLayoutParams());
4413b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
4423b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        WindowManagerImpl.getDefault().addView(mRecentsPanel, lp);
4433b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        mRecentsPanel.setBar(this);
4443b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        if (visible) {
44599a9655b9333c3bff6e462b12baa56a5fcd4cb20Michael Jurka            mRecentsPanel.show(true, false, recentTasksList, firstScreenful);
4463b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        }
4473b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
4483b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    }
4493b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
450808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    protected int getStatusBarGravity() {
451808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        return Gravity.TOP | Gravity.FILL_HORIZONTAL;
452808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
453808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
454dc10030581d6eec1c96acd62ed511f91d25d73a1Joe Onorato    public int getStatusBarHeight() {
455f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato        final Resources res = mContext.getResources();
456dc10030581d6eec1c96acd62ed511f91d25d73a1Joe Onorato        return res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
457dc10030581d6eec1c96acd62ed511f91d25d73a1Joe Onorato    }
458dc10030581d6eec1c96acd62ed511f91d25d73a1Joe Onorato
4595c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler    private View.OnClickListener mRecentsClickListener = new View.OnClickListener() {
4605c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler        public void onClick(View v) {
4615c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler            toggleRecentApps();
4625c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler        }
4635c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler    };
4645c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler
465412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka    private void prepareNavigationBarView() {
466412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka        mNavigationBarView.reorient();
467412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka
468412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka        mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener);
469412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka        mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPanel);
470412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka    }
471412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka
4728956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler    // For small-screen devices (read: phones) that lack hardware navigation buttons
4738956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler    private void addNavigationBar() {
4740129b31ff493bb0aa10b778cbeacbec5964644f8Daniel Sandler        if (mNavigationBarView == null) return;
47517dfec7111fcc53a4f6ae6e92b4a7f85a278fe71Jim Miller
476412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka        prepareNavigationBarView();
4775c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler
4788956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler        WindowManagerImpl.getDefault().addView(
4798956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler                mNavigationBarView, getNavigationBarLayoutParams());
4808956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler    }
4818956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler
4828956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler    private void repositionNavigationBar() {
4830129b31ff493bb0aa10b778cbeacbec5964644f8Daniel Sandler        if (mNavigationBarView == null) return;
48417dfec7111fcc53a4f6ae6e92b4a7f85a278fe71Jim Miller
485412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka        prepareNavigationBarView();
4865c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler
4878956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler        WindowManagerImpl.getDefault().updateViewLayout(
4888956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler                mNavigationBarView, getNavigationBarLayoutParams());
4898956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler    }
4908956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler
4918956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler    private WindowManager.LayoutParams getNavigationBarLayoutParams() {
4928956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
4931f903c3b577d20f7db7e3d5875cafe577d0d845fDianne Hackborn                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
4948956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler                WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
4958956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler                    0
4968956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler                    | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
4978956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
498df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn                    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
49998db5fabdad86dca379740d8050697950b9f026cJeff Brown                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
50098db5fabdad86dca379740d8050697950b9f026cJeff Brown                    | WindowManager.LayoutParams.FLAG_SLIPPERY,
501a388449e632fadb75a0eae67f77ff618b3a39a01Daniel Sandler                PixelFormat.OPAQUE);
502c638c1eb1bbed67d7d8f0d43f39137d766366f54Daniel Sandler        // this will allow the navbar to run in an overlay on devices that support this
503c638c1eb1bbed67d7d8f0d43f39137d766366f54Daniel Sandler        if (ActivityManager.isHighEndGfx(mDisplay)) {
504c638c1eb1bbed67d7d8f0d43f39137d766366f54Daniel Sandler            lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
505c638c1eb1bbed67d7d8f0d43f39137d766366f54Daniel Sandler        }
5068956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler
5078956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler        lp.setTitle("NavigationBar");
5088956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler        lp.windowAnimations = 0;
5098956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler
5108956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler        return lp;
5118956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler    }
5128956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler
513dc10030581d6eec1c96acd62ed511f91d25d73a1Joe Onorato    private void addIntruderView() {
514dc10030581d6eec1c96acd62ed511f91d25d73a1Joe Onorato        final int height = getStatusBarHeight();
515808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
516808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
517808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                ViewGroup.LayoutParams.MATCH_PARENT,
518808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                ViewGroup.LayoutParams.WRAP_CONTENT,
51929fc2c9705e1bb8ae098fca016032d2325031587Joe Onorato                WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL,
520808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
521808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
522808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
523808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
52446e75294d540fe807d78aec2582ae02cc38c7d42Jeff Brown                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
52546e75294d540fe807d78aec2582ae02cc38c7d42Jeff Brown                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
526808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                PixelFormat.TRANSLUCENT);
527808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL;
528808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.y += height * 1.5; // FIXME
529808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.setTitle("IntruderAlert");
53059aed3885e7bf34b4d7c021db4243484fa267526Dianne Hackborn        lp.packageName = mContext.getPackageName();
53159aed3885e7bf34b4d7c021db4243484fa267526Dianne Hackborn        lp.windowAnimations = R.style.Animation_StatusBar_IntruderAlert;
532808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
533808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        WindowManagerImpl.getDefault().addView(mIntruderAlertView, lp);
534808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
535808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
536808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
537808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) Slog.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex
538808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                + " icon=" + icon);
5396179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov        StatusBarIconView view = new StatusBarIconView(mContext, slot, null);
540808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        view.set(icon);
541808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(mIconSize, mIconSize));
542808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
543808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
544808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public void updateIcon(String slot, int index, int viewIndex,
545808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            StatusBarIcon old, StatusBarIcon icon) {
546808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) Slog.d(TAG, "updateIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex
547808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                + " old=" + old + " icon=" + icon);
548808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        StatusBarIconView view = (StatusBarIconView)mStatusIcons.getChildAt(viewIndex);
549808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        view.set(icon);
550808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
551808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
552808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public void removeIcon(String slot, int index, int viewIndex) {
553808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) Slog.d(TAG, "removeIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex);
554808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mStatusIcons.removeViewAt(viewIndex);
555808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
556808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
557808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public void addNotification(IBinder key, StatusBarNotification notification) {
5582561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler        /* if (DEBUG) */ Slog.d(TAG, "addNotification score=" + notification.score);
559808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        StatusBarIconView iconView = addNotificationViews(key, notification);
560808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (iconView == null) return;
561808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
562808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        boolean immersive = false;
563808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        try {
564808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            immersive = ActivityManagerNative.getDefault().isTopActivityImmersive();
5658355e932a033398625eef676ac93aec0cb084efeDaniel Sandler            if (DEBUG) {
5668355e932a033398625eef676ac93aec0cb084efeDaniel Sandler                Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive"));
5678355e932a033398625eef676ac93aec0cb084efeDaniel Sandler            }
568808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } catch (RemoteException ex) {
569808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
570fc6fda3950338ce737f096548a079342317cfd7fDaniel Sandler        if (ENABLE_INTRUDERS && (
571fc6fda3950338ce737f096548a079342317cfd7fDaniel Sandler                   (notification.score >= mIntruderInImmersiveMinScore)
572fc6fda3950338ce737f096548a079342317cfd7fDaniel Sandler                || (!immersive && (notification.score > mIntruderMinScore)))) {
5732561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            Slog.d(TAG, "Presenting high-priority notification");
5742561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            // special new transient ticker mode
5752561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            // 1. Populate mIntruderAlertView
5762561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler
5772561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            ImageView alertIcon = (ImageView) mIntruderAlertView.findViewById(R.id.alertIcon);
5782561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            TextView alertText = (TextView) mIntruderAlertView.findViewById(R.id.alertText);
5792561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            alertIcon.setImageDrawable(StatusBarIconView.getIcon(
5802561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                alertIcon.getContext(),
5812561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                iconView.getStatusBarIcon()));
5822561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            alertText.setText(notification.notification.tickerText);
5832561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler
5842561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            View button = mIntruderAlertView.findViewById(R.id.intruder_alert_content);
5852561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            button.setOnClickListener(
5862561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                new NotificationClicker(notification.notification.contentIntent,
5872561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                    notification.pkg, notification.tag, notification.id));
5882561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler
5892561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            // 2. Animate mIntruderAlertView in
5902561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            mHandler.sendEmptyMessage(MSG_SHOW_INTRUDER);
5912561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler
5922561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            // 3. Set alarm to age the notification off (TODO)
5932561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            mHandler.removeMessages(MSG_HIDE_INTRUDER);
5942561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            mHandler.sendEmptyMessageDelayed(MSG_HIDE_INTRUDER, INTRUDER_ALERT_DECAY_MS);
595808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else if (notification.notification.fullScreenIntent != null) {
596808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // not immersive & a full-screen alert should be shown
5978355e932a033398625eef676ac93aec0cb084efeDaniel Sandler            Slog.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent");
598808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            try {
599808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                notification.notification.fullScreenIntent.send();
600808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            } catch (PendingIntent.CanceledException e) {
601808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
602808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else {
603808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // usual case: status bar visible & not immersive
604808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
605808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // show the ticker
606808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            tick(notification);
607808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
608808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
609808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // Recalculate the position of the sliding windows and the titles.
610808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        setAreThereNotifications();
611808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
612808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
613808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
614808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public void updateNotification(IBinder key, StatusBarNotification notification) {
6157c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ")");
616808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
6177c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        final NotificationData.Entry oldEntry = mNotificationData.findByKey(key);
6187c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (oldEntry == null) {
6197c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            Slog.w(TAG, "updateNotification for unknown key: " + key);
6207c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            return;
621808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
6227c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
623808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final StatusBarNotification oldNotification = oldEntry.notification;
624808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final RemoteViews oldContentView = oldNotification.notification.contentView;
625808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
626808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final RemoteViews contentView = notification.notification.contentView;
627808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
6287c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
62920cdb151c9f1a956eee9eebe77459e14029ad131Daniel Sandler        if (DEBUG) {
630808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            Slog.d(TAG, "old notification: when=" + oldNotification.notification.when
631808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " ongoing=" + oldNotification.isOngoing()
632808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " expanded=" + oldEntry.expanded
63320cdb151c9f1a956eee9eebe77459e14029ad131Daniel Sandler                    + " contentView=" + oldContentView
63420cdb151c9f1a956eee9eebe77459e14029ad131Daniel Sandler                    + " rowParent=" + oldEntry.row.getParent());
635808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            Slog.d(TAG, "new notification: when=" + notification.notification.when
636808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " ongoing=" + oldNotification.isOngoing()
637808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " contentView=" + contentView);
638808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
639808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
64020cdb151c9f1a956eee9eebe77459e14029ad131Daniel Sandler
641808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // Can we just reapply the RemoteViews in place?  If when didn't change, the order
642808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // didn't change.
64320cdb151c9f1a956eee9eebe77459e14029ad131Daniel Sandler        boolean contentsUnchanged = oldEntry.expanded != null
644808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                && contentView != null && oldContentView != null
645808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                && contentView.getPackage() != null
646808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                && oldContentView.getPackage() != null
647808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                && oldContentView.getPackage().equals(contentView.getPackage())
64820cdb151c9f1a956eee9eebe77459e14029ad131Daniel Sandler                && oldContentView.getLayoutId() == contentView.getLayoutId();
64920cdb151c9f1a956eee9eebe77459e14029ad131Daniel Sandler        ViewGroup rowParent = (ViewGroup) oldEntry.row.getParent();
65020cdb151c9f1a956eee9eebe77459e14029ad131Daniel Sandler        boolean orderUnchanged = notification.notification.when==oldNotification.notification.when
6512561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                && notification.score == oldNotification.score;
6522561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                // score now encompasses/supersedes isOngoing()
653c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung
654c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung        boolean updateTicker = notification.notification.tickerText != null
655c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung                && !TextUtils.equals(notification.notification.tickerText,
656c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung                        oldEntry.notification.notification.tickerText);
6577c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        boolean isFirstAnyway = rowParent.indexOfChild(oldEntry.row) == 0;
6587c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (contentsUnchanged && (orderUnchanged || isFirstAnyway)) {
65920cdb151c9f1a956eee9eebe77459e14029ad131Daniel Sandler            if (DEBUG) Slog.d(TAG, "reusing notification for key: " + key);
660808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            oldEntry.notification = notification;
661808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            try {
662808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // Reapply the RemoteViews
663f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato                contentView.reapply(mContext, oldEntry.content);
664808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // update the contentIntent
665808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                final PendingIntent contentIntent = notification.notification.contentIntent;
666808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (contentIntent != null) {
667847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey                    final View.OnClickListener listener = new NotificationClicker(contentIntent,
668847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey                            notification.pkg, notification.tag, notification.id);
669847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey                    oldEntry.largeIcon.setOnClickListener(listener);
670847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey                    oldEntry.content.setOnClickListener(listener);
671184498ce5a8d77e1d9c45693363829daaeef9611Joe Onorato                } else {
672847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey                    oldEntry.largeIcon.setOnClickListener(null);
673184498ce5a8d77e1d9c45693363829daaeef9611Joe Onorato                    oldEntry.content.setOnClickListener(null);
674808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
675808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // Update the icon.
676808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
677808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                        notification.notification.icon, notification.notification.iconLevel,
6787c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                        notification.notification.number,
6797c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                        notification.notification.tickerText);
680808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (!oldEntry.icon.set(ic)) {
681808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    handleNotificationError(key, notification, "Couldn't update icon: " + ic);
682808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    return;
683808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
684d5b858639cc32d27c003d7165969ec47288b3bfaDaniel Sandler                // Update the large icon
685d5b858639cc32d27c003d7165969ec47288b3bfaDaniel Sandler                if (notification.notification.largeIcon != null) {
686d5b858639cc32d27c003d7165969ec47288b3bfaDaniel Sandler                    oldEntry.largeIcon.setImageBitmap(notification.notification.largeIcon);
687d5b858639cc32d27c003d7165969ec47288b3bfaDaniel Sandler                } else {
6887c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                    oldEntry.largeIcon.getLayoutParams().width = 0;
6897c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                    oldEntry.largeIcon.setVisibility(View.INVISIBLE);
690d5b858639cc32d27c003d7165969ec47288b3bfaDaniel Sandler                }
691808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
692808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            catch (RuntimeException e) {
693808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // It failed to add cleanly.  Log, and remove the view from the panel.
694808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                Slog.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e);
695808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                removeNotificationViews(key);
696808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                addNotificationViews(key, notification);
697808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
698808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else {
699808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (SPEW) Slog.d(TAG, "not reusing notification");
700808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            removeNotificationViews(key);
701808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            addNotificationViews(key, notification);
702808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
703808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
704c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung        // Update the veto button accordingly (and as a result, whether this row is
705c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung        // swipe-dismissable)
706c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung        updateNotificationVetoButton(oldEntry.row, notification);
707c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung
708808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // Restart the ticker if it's still running
709c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung        if (updateTicker) {
710c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung            mTicker.halt();
711935865923fdad9f47061ff0aedfe92d0b912d5d6Joe Onorato            tick(notification);
712935865923fdad9f47061ff0aedfe92d0b912d5d6Joe Onorato        }
713808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
714808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // Recalculate the position of the sliding windows and the titles.
715808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        setAreThereNotifications();
716808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
717808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
718808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
719808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public void removeNotification(IBinder key) {
720808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) Slog.d(TAG, "removeNotification key=" + key);
721808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        StatusBarNotification old = removeNotificationViews(key);
722808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
723808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (old != null) {
724808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // Cancel the ticker if it's still running
725808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTicker.removeEntry(old);
726808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
727808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // Recalculate the position of the sliding windows and the titles.
728808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
7298cc36e572876f3bb9197f0109db3042466e5f917Daniel Sandler
7308cc36e572876f3bb9197f0109db3042466e5f917Daniel Sandler            if (CLOSE_PANEL_WHEN_EMPTIED && mNotificationData.size() == 0 && !mAnimating) {
7318cc36e572876f3bb9197f0109db3042466e5f917Daniel Sandler                animateCollapse();
7328cc36e572876f3bb9197f0109db3042466e5f917Daniel Sandler            }
733808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
7340761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler
7350761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        setAreThereNotifications();
736808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
737808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
7383b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    @Override
7393b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    protected void onConfigurationChanged(Configuration newConfig) {
74017dfec7111fcc53a4f6ae6e92b4a7f85a278fe71Jim Miller        updateRecentsPanel();
7413b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    }
7423b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
7433b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
744808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notification) {
7457c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (DEBUG) {
7467c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            Slog.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification);
747808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
748808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // Construct the icon.
749f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato        final StatusBarIconView iconView = new StatusBarIconView(mContext,
7506179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov                notification.pkg + "/0x" + Integer.toHexString(notification.id),
7516179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov                notification.notification);
7527c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
7537c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
7547c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
7557c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                    notification.notification.icon,
7567c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                    notification.notification.iconLevel,
7577c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                    notification.notification.number,
7586179ea3196e9306d3f14361fe9ef14191b1edba6Svetoslav Ganov                    notification.notification.tickerText);
759808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (!iconView.set(ic)) {
7607c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            handleNotificationError(key, notification, "Couldn't create icon: " + ic);
7617c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            return null;
7627c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
7637c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        // Construct the expanded view.
7647c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView);
7657c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (!inflateViews(entry, mPile)) {
7667c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            handleNotificationError(key, notification, "Couldn't expand RemoteViews for: "
7677c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                    + notification);
768808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return null;
769808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
7707c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
7717c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        // Add the expanded view and icon.
7727c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        int pos = mNotificationData.add(entry);
7737c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (DEBUG) {
7747c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            Slog.d(TAG, "addNotificationViews: added at " + pos);
7757c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
7767c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        updateNotificationIcons();
7777c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
778808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        return iconView;
779808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
780808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
7817c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    private void loadNotificationShade() {
7827c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        int N = mNotificationData.size();
7837c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
7847c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        ArrayList<View> toShow = new ArrayList<View>();
7857c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
7867c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        for (int i=0; i<N; i++) {
7877c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            View row = mNotificationData.get(N-i-1).row;
7887c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            toShow.add(row);
7897c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
7907c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
7917c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        ArrayList<View> toRemove = new ArrayList<View>();
7927c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        for (int i=0; i<mPile.getChildCount(); i++) {
7937c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            View child = mPile.getChildAt(i);
7947c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            if (!toShow.contains(child)) {
7957c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                toRemove.add(child);
796808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
797808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
798808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
7997c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        for (View remove : toRemove) {
8007c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            mPile.removeView(remove);
8017c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
8027c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8037c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        for (int i=0; i<toShow.size(); i++) {
8047c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            View v = toShow.get(i);
8057c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            if (v.getParent() == null) {
8062561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                mPile.addView(v, i);
8077c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            }
8087c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
809808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
810808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
8117c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    private void reloadAllNotificationIcons() {
8127c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (mNotificationIcons == null) return;
8137c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        mNotificationIcons.removeAllViews();
8147c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        updateNotificationIcons();
8157c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    }
8167c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8177c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    private void updateNotificationIcons() {
8187c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        loadNotificationShade();
8197c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8207c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        final LinearLayout.LayoutParams params
8217c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight);
822808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
8237c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        int N = mNotificationData.size();
8247c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8257c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (DEBUG) {
8267c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            Slog.d(TAG, "refreshing icons: " + N + " notifications, mNotificationIcons=" + mNotificationIcons);
8277c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
8287c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8297c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        ArrayList<View> toShow = new ArrayList<View>();
8307c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8317c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        for (int i=0; i<N; i++) {
8327c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            toShow.add(mNotificationData.get(N-i-1).icon);
8337c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
8347c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8357c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        ArrayList<View> toRemove = new ArrayList<View>();
8367c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        for (int i=0; i<mNotificationIcons.getChildCount(); i++) {
8377c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            View child = mNotificationIcons.getChildAt(i);
8387c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            if (!toShow.contains(child)) {
8397c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                toRemove.add(child);
8407c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            }
8417c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
8427c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8437c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        for (View remove : toRemove) {
8447c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            mNotificationIcons.removeView(remove);
8457c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
8467c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8477c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        for (int i=0; i<toShow.size(); i++) {
8487c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            View v = toShow.get(i);
8497c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            if (v.getParent() == null) {
8507c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                mNotificationIcons.addView(v, i, params);
8517c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            }
8527c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
8537c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    }
8547c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8557c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) {
8567c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        StatusBarNotification sbn = entry.notification;
8577c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        RemoteViews remoteViews = sbn.notification.contentView;
8587c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (remoteViews == null) {
8597c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            return false;
8607c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
8617c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8627c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        // create the row view
8637c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(
8647c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                Context.LAYOUT_INFLATER_SERVICE);
8657c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false);
866c57ccf01fe24ce508404c99b449e9097e6d8b270Winson Chung        View vetoButton = updateNotificationVetoButton(row, sbn);
8677c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        vetoButton.setContentDescription(mContext.getString(
8687c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                R.string.accessibility_remove_notification));
869808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
8707c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        // the large icon
8717c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon);
8727c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (sbn.notification.largeIcon != null) {
8737c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            largeIcon.setImageBitmap(sbn.notification.largeIcon);
8747c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            largeIcon.setContentDescription(sbn.notification.tickerText);
8757c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        } else {
8767c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            largeIcon.getLayoutParams().width = 0;
8777c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            largeIcon.setVisibility(View.INVISIBLE);
8787c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
8797c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        largeIcon.setContentDescription(sbn.notification.tickerText);
880808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
8817c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        // bind the click event to the content area
8827c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        ViewGroup content = (ViewGroup)row.findViewById(R.id.content);
8837c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        // XXX: update to allow controls within notification views
8847c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
8857c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler//        content.setOnFocusChangeListener(mFocusChangeListener);
8867c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        PendingIntent contentIntent = sbn.notification.contentIntent;
8877c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (contentIntent != null) {
888847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey            final View.OnClickListener listener = new NotificationClicker(contentIntent,
889847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey                    sbn.pkg, sbn.tag, sbn.id);
890847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey            largeIcon.setOnClickListener(listener);
891847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey            content.setOnClickListener(listener);
892808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else {
893847fd751a9c9eb3cb02da1dca95d3d4b215c0b76Jeff Sharkey            largeIcon.setOnClickListener(null);
8947c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            content.setOnClickListener(null);
8957c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
8967c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
8977c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        View expanded = null;
8987c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        Exception exception = null;
8997c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        try {
9007c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            expanded = remoteViews.apply(mContext, content);
901808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
9027c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        catch (RuntimeException e) {
9037c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            exception = e;
9047c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
9057c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (expanded == null) {
9067c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            final String ident = sbn.pkg + "/0x" + Integer.toHexString(sbn.id);
9077c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            Slog.e(TAG, "couldn't inflate view for notification " + ident, exception);
9087c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            return false;
9097c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        } else {
9107c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            content.addView(expanded);
9117c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            row.setDrawingCacheEnabled(true);
9127c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
9137c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
91429ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell        applyLegacyRowBackground(sbn, content);
91529ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell
9167c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        entry.row = row;
9177c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        entry.content = content;
9187c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        entry.expanded = expanded;
9197c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        entry.largeIcon = largeIcon;
9207c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
9217c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        return true;
9227c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    }
9237c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
92429ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell    void applyLegacyRowBackground(StatusBarNotification sbn, View content) {
92529ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell        if (sbn.notification.contentView.getLayoutId() !=
92629ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell                com.android.internal.R.layout.status_bar_latest_event_content) {
92729ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell            int version = 0;
92829ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell            try {
92929ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell                ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(sbn.pkg, 0);
93029ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell                version = info.targetSdkVersion;
93129ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell            } catch (NameNotFoundException ex) {
93229ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell                Slog.e(TAG, "Failed looking up ApplicationInfo for " + sbn.pkg, ex);
93329ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell            }
934ad9deec87cae30f73e56f0f778fc3fb52035b325Adam Powell            if (version > 0 && version < Build.VERSION_CODES.GINGERBREAD) {
93529ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell                content.setBackgroundResource(R.drawable.notification_row_legacy_bg);
93629ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell            } else {
93729ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell                content.setBackgroundResource(R.drawable.notification_row_bg);
93829ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell            }
93929ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell        }
94029ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell    }
94129ea525d18b3c36c56e0c5391bb849a9baf27668Adam Powell
9427c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    StatusBarNotification removeNotificationViews(IBinder key) {
9437c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        NotificationData.Entry entry = mNotificationData.remove(key);
9447c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (entry == null) {
9457c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            Slog.w(TAG, "removeNotification for unknown key: " + key);
9467c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            return null;
9477c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
9487c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        // Remove the expanded view.
9497c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        ViewGroup rowParent = (ViewGroup)entry.row.getParent();
9507c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (rowParent != null) rowParent.removeView(entry.row);
9517c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        updateNotificationIcons();
9527c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
9537c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        return entry.notification;
9547c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    }
9557c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
9567c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    private void setAreThereNotifications() {
9570761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        final boolean any = mNotificationData.size() > 0;
9587c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
9590761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        final boolean clearable = any && mNotificationData.hasClearableItems();
9600761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler
9610761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        if (DEBUG) {
9620761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler            Slog.d(TAG, "setAreThereNotifications: N=" + mNotificationData.size()
9630761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                    + " any=" + any + " clearable=" + clearable);
9640761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        }
9650761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler
9660761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        if (mClearButton.isShown()) {
9670761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler            if (clearable != (mClearButton.getAlpha() == 1.0f)) {
9680761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                ObjectAnimator.ofFloat(mClearButton, "alpha",
9690761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                        clearable ? 1.0f : 0.0f)
9700761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                    .setDuration(250)
9710761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                    .start();
9720761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler            }
9730761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        } else {
9740761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler            mClearButton.setAlpha(clearable ? 1.0f : 0.0f);
9750761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        }
9768ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler        mClearButton.setEnabled(clearable);
9770761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler
978d714148bd2752c63a46f51b12cea288fb1f10528Daniel Sandler        /*
9790761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        if (mNoNotificationsTitle.isShown()) {
9800761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler            if (any != (mNoNotificationsTitle.getAlpha() == 0.0f)) {
9810761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                ObjectAnimator a = ObjectAnimator.ofFloat(mNoNotificationsTitle, "alpha",
9820761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                            (any ? 0.0f : 0.75f));
9830761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                a.setDuration(any ? 0 : 500);
9840761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                a.setStartDelay(any ? 250 : 1000);
9850761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler                a.start();
9860761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler            }
9870761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        } else {
9880761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler            mNoNotificationsTitle.setAlpha(any ? 0.0f : 0.75f);
9890761e4cd95b6968dd4b1659a766ef504d13f6d50Daniel Sandler        }
990d714148bd2752c63a46f51b12cea288fb1f10528Daniel Sandler        */
991808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
992808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
993f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey    public void showClock(boolean show) {
994f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey        View clock = mStatusBarView.findViewById(R.id.clock);
995f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey        if (clock != null) {
996f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey            clock.setVisibility(show ? View.VISIBLE : View.GONE);
997f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey        }
998f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey    }
999808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1000808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    /**
1001808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * State is one or more of the DISABLE constants from StatusBarManager.
1002808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     */
1003808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public void disable(int state) {
1004808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final int old = mDisabled;
1005808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final int diff = state ^ old;
1006808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mDisabled = state;
1007808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1008e21f288358df2c1cea57c0a359dcf647baeb970dDaniel Sandler        if (DEBUG) {
1009e21f288358df2c1cea57c0a359dcf647baeb970dDaniel Sandler            Slog.d(TAG, String.format("disable: 0x%08x -> 0x%08x (diff: 0x%08x)",
1010e21f288358df2c1cea57c0a359dcf647baeb970dDaniel Sandler                old, state, diff));
1011e21f288358df2c1cea57c0a359dcf647baeb970dDaniel Sandler        }
1012e21f288358df2c1cea57c0a359dcf647baeb970dDaniel Sandler
10136da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        StringBuilder flagdbg = new StringBuilder();
10146da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append("disable: < ");
10156da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((state & StatusBarManager.DISABLE_EXPAND) != 0) ? "EXPAND" : "expand");
10166da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((diff  & StatusBarManager.DISABLE_EXPAND) != 0) ? "* " : " ");
10176da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "ICONS" : "icons");
10186da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((diff  & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "* " : " ");
10196da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "ALERTS" : "alerts");
10206da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((diff  & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "* " : " ");
10216da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "TICKER" : "ticker");
10226da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((diff  & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "* " : " ");
10236da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "SYSTEM_INFO" : "system_info");
10246da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((diff  & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "* " : " ");
10256da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((state & StatusBarManager.DISABLE_BACK) != 0) ? "BACK" : "back");
10266da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((diff  & StatusBarManager.DISABLE_BACK) != 0) ? "* " : " ");
1027dba935659024a9ca83cb6bd3f1a9970e277f7658Daniel Sandler        flagdbg.append(((state & StatusBarManager.DISABLE_HOME) != 0) ? "HOME" : "home");
1028dba935659024a9ca83cb6bd3f1a9970e277f7658Daniel Sandler        flagdbg.append(((diff  & StatusBarManager.DISABLE_HOME) != 0) ? "* " : " ");
1029dba935659024a9ca83cb6bd3f1a9970e277f7658Daniel Sandler        flagdbg.append(((state & StatusBarManager.DISABLE_RECENT) != 0) ? "RECENT" : "recent");
1030dba935659024a9ca83cb6bd3f1a9970e277f7658Daniel Sandler        flagdbg.append(((diff  & StatusBarManager.DISABLE_RECENT) != 0) ? "* " : " ");
10316da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((state & StatusBarManager.DISABLE_CLOCK) != 0) ? "CLOCK" : "clock");
10326da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(((diff  & StatusBarManager.DISABLE_CLOCK) != 0) ? "* " : " ");
10336da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        flagdbg.append(">");
10346da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler        Slog.d(TAG, flagdbg.toString());
10356da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler
1036f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey        if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) {
1037f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey            boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0;
1038f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey            showClock(show);
1039f52c70b2ccf711f507723bc74a68ca8c3a12c57aJeff Sharkey        }
1040808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
1041808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if ((state & StatusBarManager.DISABLE_EXPAND) != 0) {
1042808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                animateCollapse();
1043808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1044808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1045e21f288358df2c1cea57c0a359dcf647baeb970dDaniel Sandler
10465e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller        if ((diff & (StatusBarManager.DISABLE_HOME
10475e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller                        | StatusBarManager.DISABLE_RECENT
1048dba935659024a9ca83cb6bd3f1a9970e277f7658Daniel Sandler                        | StatusBarManager.DISABLE_BACK)) != 0) {
1049dba935659024a9ca83cb6bd3f1a9970e277f7658Daniel Sandler            // the nav bar will take care of these
1050d9283b903125c875f973bf6f724f23e595bce756Daniel Sandler            if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state);
10516da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler
1052dba935659024a9ca83cb6bd3f1a9970e277f7658Daniel Sandler            if ((state & StatusBarManager.DISABLE_RECENT) != 0) {
10536da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler                // close recents if it's visible
10546da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler                mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
10556da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler                mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
10566da2b76ea496129da5370bfafd667ee94907a356Daniel Sandler            }
1057e21f288358df2c1cea57c0a359dcf647baeb970dDaniel Sandler        }
1058e21f288358df2c1cea57c0a359dcf647baeb970dDaniel Sandler
1059808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
1060808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
1061808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (mTicking) {
1062808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    mTicker.halt();
1063808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                } else {
1064808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    setNotificationIconVisibility(false, com.android.internal.R.anim.fade_out);
1065808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1066808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            } else {
1067808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (!mExpandedVisible) {
1068808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in);
1069808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1070808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1071808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
1072808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
1073808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mTicker.halt();
1074808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1075808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1076808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1077808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1078808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    /**
1079808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * All changes to the status bar and notifications funnel through here and are batched.
1080808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     */
1081808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private class H extends Handler {
1082808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void handleMessage(Message m) {
1083808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            switch (m.what) {
1084808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                case MSG_ANIMATE:
1085808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    doAnimation();
1086808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    break;
1087808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                case MSG_ANIMATE_REVEAL:
1088808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    doRevealAnimation();
1089808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    break;
10908ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                case MSG_OPEN_NOTIFICATION_PANEL:
10918ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                    animateExpand();
10928ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                    break;
10938ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                case MSG_CLOSE_NOTIFICATION_PANEL:
10948ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                    animateCollapse();
10958ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                    break;
1096808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                case MSG_SHOW_INTRUDER:
1097808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    setIntruderAlertVisibility(true);
1098808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    break;
1099808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                case MSG_HIDE_INTRUDER:
1100808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    setIntruderAlertVisibility(false);
1101808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    break;
11023b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                case MSG_OPEN_RECENTS_PANEL:
11033b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    if (DEBUG) Slog.d(TAG, "opening recents panel");
11043b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    if (mRecentsPanel != null) {
11053b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                        mRecentsPanel.show(true, true);
11063b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    }
11073b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    break;
11083b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                case MSG_CLOSE_RECENTS_PANEL:
11093b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    if (DEBUG) Slog.d(TAG, "closing recents panel");
11103b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
11113b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                        mRecentsPanel.show(false, true);
11123b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    }
11133b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    break;
1114808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1115808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1116808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1117808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1118808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() {
1119808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void onFocusChange(View v, boolean hasFocus) {
1120808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // Because 'v' is a ViewGroup, all its children will be (un)selected
1121808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // too, which allows marqueeing to work.
1122808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            v.setSelected(hasFocus);
1123808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1124808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    };
1125808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1126808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private void makeExpandedVisible() {
1127808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) Slog.d(TAG, "Make expanded visible: expanded visible=" + mExpandedVisible);
1128808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (mExpandedVisible) {
1129808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return;
1130808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1131808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedVisible = true;
1132808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        visibilityChanged(true);
1133808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1134808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
1135808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
1136808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedParams.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
113736412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler        if (DEBUG) {
113836412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            Slog.d(TAG, "makeExpandedVisible: expanded params = " + mExpandedParams);
113936412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler        }
1140808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedDialog.getWindow().setAttributes(mExpandedParams);
1141808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedView.requestFocus(View.FOCUS_FORWARD);
1142808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTrackingView.setVisibility(View.VISIBLE);
1143808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1144808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1145808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public void animateExpand() {
1146808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) Slog.d(TAG, "Animate expand: expanded=" + mExpanded);
1147808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
1148808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return ;
1149808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1150808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (mExpanded) {
1151808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return;
1152808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1153808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1154808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        prepareTracking(0, true);
1155dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        performFling(0, mSelfExpandVelocityPx, true);
1156808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1157808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1158808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    public void animateCollapse() {
11593b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        animateCollapse(false);
11603b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    }
11613b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
11623b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    public void animateCollapse(boolean excludeRecents) {
11638ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler        animateCollapse(excludeRecents, 1.0f);
11648ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler    }
11655e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller
11668ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler    public void animateCollapse(boolean excludeRecents, float velocityMultiplier) {
1167808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) {
1168808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            Slog.d(TAG, "animateCollapse(): mExpanded=" + mExpanded
1169808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mExpandedVisible=" + mExpandedVisible
1170808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mExpanded=" + mExpanded
1171808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mAnimating=" + mAnimating
1172808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mAnimY=" + mAnimY
1173808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mAnimVel=" + mAnimVel);
1174808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1175808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
11763b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        if (!excludeRecents) {
11773b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
11783b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
11793b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        }
11803b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
1181808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (!mExpandedVisible) {
1182808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return;
1183808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1184808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1185808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        int y;
1186808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (mAnimating) {
1187808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            y = (int)mAnimY;
1188808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else {
118936412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            y = mDisplayMetrics.heightPixels-1;
1190808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1191808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // Let the fling think that we're open so it goes in the right direction
1192808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // and doesn't try to re-open the windowshade.
1193808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpanded = true;
1194808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        prepareTracking(y, false);
11958ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler        performFling(y, -mSelfCollapseVelocityPx*velocityMultiplier, true);
1196808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1197808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1198808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void performExpand() {
1199808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) Slog.d(TAG, "performExpand: mExpanded=" + mExpanded);
1200808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
1201808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return ;
1202808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1203808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (mExpanded) {
1204808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return;
1205808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1206808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1207808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpanded = true;
1208808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        makeExpandedVisible();
1209808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        updateExpandedViewPos(EXPANDED_FULL_OPEN);
1210808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1211808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (false) postStartTracing();
1212808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1213808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1214808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void performCollapse() {
1215808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) Slog.d(TAG, "performCollapse: mExpanded=" + mExpanded
1216808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                + " mExpandedVisible=" + mExpandedVisible);
1217808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1218808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (!mExpandedVisible) {
1219808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return;
1220808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1221808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedVisible = false;
1222808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        visibilityChanged(false);
1223808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
1224808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedParams.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
1225808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedDialog.getWindow().setAttributes(mExpandedParams);
1226808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTrackingView.setVisibility(View.GONE);
1227808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1228808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if ((mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS) == 0) {
1229808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in);
1230808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1231808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1232808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (!mExpanded) {
1233808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return;
1234808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1235808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpanded = false;
12362f2022afa1eb85018368398bd150e9575fc099c9Chet Haase        if (mPostCollapseCleanup != null) {
12372f2022afa1eb85018368398bd150e9575fc099c9Chet Haase            mPostCollapseCleanup.run();
12382f2022afa1eb85018368398bd150e9575fc099c9Chet Haase            mPostCollapseCleanup = null;
12392f2022afa1eb85018368398bd150e9575fc099c9Chet Haase        }
1240808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1241808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1242808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void doAnimation() {
1243808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (mAnimating) {
1244808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (SPEW) Slog.d(TAG, "doAnimation");
1245808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (SPEW) Slog.d(TAG, "doAnimation before mAnimY=" + mAnimY);
1246808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            incrementAnim();
1247808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (SPEW) Slog.d(TAG, "doAnimation after  mAnimY=" + mAnimY);
124836412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            if (mAnimY >= mDisplayMetrics.heightPixels-1) {
1249808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (SPEW) Slog.d(TAG, "Animation completed to expanded state.");
1250808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mAnimating = false;
1251808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                updateExpandedViewPos(EXPANDED_FULL_OPEN);
1252808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                performExpand();
1253808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1254808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            else if (mAnimY < mStatusBarView.getHeight()) {
1255808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (SPEW) Slog.d(TAG, "Animation completed to collapsed state.");
1256808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mAnimating = false;
1257808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                updateExpandedViewPos(0);
1258808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                performCollapse();
1259808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1260808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            else {
1261808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                updateExpandedViewPos((int)mAnimY);
1262808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mCurAnimationTime += ANIM_FRAME_DURATION;
1263808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE), mCurAnimationTime);
1264808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1265808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1266808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1267808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1268808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void stopTracking() {
1269808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTracking = false;
1270808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mVelocityTracker.recycle();
1271808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mVelocityTracker = null;
1272808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1273808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1274808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void incrementAnim() {
1275808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        long now = SystemClock.uptimeMillis();
1276808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        float t = ((float)(now - mAnimLastTime)) / 1000;            // ms -> s
1277808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final float y = mAnimY;
1278808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final float v = mAnimVel;                                   // px/s
1279808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final float a = mAnimAccel;                                 // px/s/s
1280808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mAnimY = y + (v*t) + (0.5f*a*t*t);                          // px
1281808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mAnimVel = v + (a*t);                                       // px/s
1282808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mAnimLastTime = now;                                        // ms
1283808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        //Slog.d(TAG, "y=" + y + " v=" + v + " a=" + a + " t=" + t + " mAnimY=" + mAnimY
1284808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        //        + " mAnimAccel=" + mAnimAccel);
1285808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1286808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1287808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void doRevealAnimation() {
1288808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final int h = mCloseView.getHeight() + mStatusBarView.getHeight();
1289808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (mAnimatingReveal && mAnimating && mAnimY < h) {
1290808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            incrementAnim();
1291808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (mAnimY >= h) {
1292808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mAnimY = h;
1293808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                updateExpandedViewPos((int)mAnimY);
1294808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            } else {
1295808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                updateExpandedViewPos((int)mAnimY);
1296808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mCurAnimationTime += ANIM_FRAME_DURATION;
1297808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE_REVEAL),
1298808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                        mCurAnimationTime);
1299808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1300808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1301808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1302808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1303808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void prepareTracking(int y, boolean opening) {
130496e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler        if (CHATTY) {
130596e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler            Slog.d(TAG, "panel: beginning to track the user's touch, y=" + y + " opening=" + opening);
130696e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler        }
130796e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler
1308cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler        // there are some race conditions that cause this to be inaccurate; let's recalculate it any
1309cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler        // time we're about to drag the panel
1310cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler        updateExpandedSize();
1311cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler
1312808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTracking = true;
1313808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mVelocityTracker = VelocityTracker.obtain();
1314808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (opening) {
1315dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler            mAnimAccel = mExpandAccelPx;
1316dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler            mAnimVel = mFlingExpandMinVelocityPx;
1317808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mAnimY = mStatusBarView.getHeight();
1318808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            updateExpandedViewPos((int)mAnimY);
1319808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mAnimating = true;
1320808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mAnimatingReveal = true;
1321808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mHandler.removeMessages(MSG_ANIMATE);
1322808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mHandler.removeMessages(MSG_ANIMATE_REVEAL);
1323808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            long now = SystemClock.uptimeMillis();
1324808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mAnimLastTime = now;
1325808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mCurAnimationTime = now + ANIM_FRAME_DURATION;
1326808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mAnimating = true;
1327808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE_REVEAL),
1328808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    mCurAnimationTime);
1329808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            makeExpandedVisible();
1330808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else {
1331808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // it's open, close it?
1332808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (mAnimating) {
1333808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mAnimating = false;
1334808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mHandler.removeMessages(MSG_ANIMATE);
1335808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1336808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            updateExpandedViewPos(y + mViewDelta);
1337808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1338808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1339808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1340808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void performFling(int y, float vel, boolean always) {
134196e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler        if (CHATTY) {
134296e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler            Slog.d(TAG, "panel: will fling, y=" + y + " vel=" + vel);
134396e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler        }
134496e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler
1345808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mAnimatingReveal = false;
1346808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1347808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mAnimY = y;
1348808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mAnimVel = vel;
1349808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1350808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        //Slog.d(TAG, "starting with mAnimY=" + mAnimY + " mAnimVel=" + mAnimVel);
1351808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1352808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (mExpanded) {
1353808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (!always && (
1354dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                    vel > mFlingCollapseMinVelocityPx
1355dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                    || (y > (mDisplayMetrics.heightPixels*(1f-mCollapseMinDisplayFraction)) &&
1356dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                        vel > -mFlingExpandMinVelocityPx))) {
1357808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // We are expanded, but they didn't move sufficiently to cause
1358808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // us to retract.  Animate back to the expanded position.
1359dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                mAnimAccel = mExpandAccelPx;
1360808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (vel < 0) {
1361808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    mAnimVel = 0;
1362808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1363808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1364808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            else {
1365808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // We are expanded and are now going to animate away.
1366dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                mAnimAccel = -mCollapseAccelPx;
1367808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (vel > 0) {
1368808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    mAnimVel = 0;
1369808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1370808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1371808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else {
1372808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (always || (
1373dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                    vel > mFlingExpandMinVelocityPx
1374dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                    || (y > (mDisplayMetrics.heightPixels*(1f-mExpandMinDisplayFraction)) &&
1375dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                        vel > -mFlingCollapseMinVelocityPx))) {
1376808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // We are collapsed, and they moved enough to allow us to
1377808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // expand.  Animate in the notifications.
1378dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                mAnimAccel = mExpandAccelPx;
1379808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (vel < 0) {
1380808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    mAnimVel = 0;
1381808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1382808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1383808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            else {
1384808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // We are collapsed, but they didn't move sufficiently to cause
1385808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // us to retract.  Animate back to the collapsed position.
1386dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                mAnimAccel = -mCollapseAccelPx;
1387808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (vel > 0) {
1388808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    mAnimVel = 0;
1389808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1390808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1391808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1392808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        //Slog.d(TAG, "mAnimY=" + mAnimY + " mAnimVel=" + mAnimVel
1393808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        //        + " mAnimAccel=" + mAnimAccel);
1394808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1395808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        long now = SystemClock.uptimeMillis();
1396808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mAnimLastTime = now;
1397808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mCurAnimationTime = now + ANIM_FRAME_DURATION;
1398808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mAnimating = true;
1399808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mHandler.removeMessages(MSG_ANIMATE);
1400808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mHandler.removeMessages(MSG_ANIMATE_REVEAL);
1401808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE), mCurAnimationTime);
1402808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        stopTracking();
1403808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1404808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1405808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    boolean interceptTouchEvent(MotionEvent event) {
1406808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) {
1407808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            Slog.d(TAG, "Touch: rawY=" + event.getRawY() + " event=" + event + " mDisabled="
1408808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                + mDisabled);
140996e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler        } else if (CHATTY) {
1410fe172cc861448cf1115195cbad5b3300357c02f0Daniel Sandler            if (event.getAction() != MotionEvent.ACTION_MOVE) {
141196e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler                Slog.d(TAG, String.format(
1412fe172cc861448cf1115195cbad5b3300357c02f0Daniel Sandler                            "panel: %s at (%f, %f) mDisabled=0x%08x",
1413fe172cc861448cf1115195cbad5b3300357c02f0Daniel Sandler                            MotionEvent.actionToString(event.getAction()),
141496e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler                            event.getRawX(), event.getRawY(), mDisabled));
141596e61c3c86b2aff3d298d8757ba51eb568c30543Daniel Sandler            }
1416808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1417808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1418808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
1419808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return false;
1420808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1421808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
142268ebcdf3fd8b98fe35ec3e0b2e91fd254fcd807fJeff Brown        final int action = event.getAction();
1423808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final int statusBarSize = mStatusBarView.getHeight();
1424808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        final int hitSize = statusBarSize*2;
1425fe172cc861448cf1115195cbad5b3300357c02f0Daniel Sandler        final int y = (int)event.getRawY();
142668ebcdf3fd8b98fe35ec3e0b2e91fd254fcd807fJeff Brown        if (action == MotionEvent.ACTION_DOWN) {
1427808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (!mExpanded) {
1428808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mViewDelta = statusBarSize - y;
1429808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            } else {
1430808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mTrackingView.getLocationOnScreen(mAbsPos);
1431808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mViewDelta = mAbsPos[1] + mTrackingView.getHeight() - y;
1432808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1433808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if ((!mExpanded && y < hitSize) ||
143436412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler                    (mExpanded && y > (mDisplayMetrics.heightPixels-hitSize))) {
1435808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1436808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // We drop events at the edge of the screen to make the windowshade come
1437808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // down by accident less, especially when pushing open a device with a keyboard
1438808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // that rotates (like g1 and droid)
1439808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                int x = (int)event.getRawX();
1440808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                final int edgeBorder = mEdgeBorder;
144136412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler                if (x >= edgeBorder && x < mDisplayMetrics.widthPixels - edgeBorder) {
1442808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    prepareTracking(y, !mExpanded);// opening if we're not already fully visible
1443911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown                    trackMovement(event);
1444808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1445808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1446808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else if (mTracking) {
1447911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown            trackMovement(event);
1448808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            final int minY = statusBarSize + mCloseView.getHeight();
144968ebcdf3fd8b98fe35ec3e0b2e91fd254fcd807fJeff Brown            if (action == MotionEvent.ACTION_MOVE) {
1450808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (mAnimatingReveal && y < minY) {
1451808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    // nothing
1452808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                } else  {
1453808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    mAnimatingReveal = false;
1454808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    updateExpandedViewPos(y + mViewDelta);
1455808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
145668ebcdf3fd8b98fe35ec3e0b2e91fd254fcd807fJeff Brown            } else if (action == MotionEvent.ACTION_UP
145768ebcdf3fd8b98fe35ec3e0b2e91fd254fcd807fJeff Brown                    || action == MotionEvent.ACTION_CANCEL) {
1458808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mVelocityTracker.computeCurrentVelocity(1000);
1459808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1460808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                float yVel = mVelocityTracker.getYVelocity();
1461808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                boolean negative = yVel < 0;
1462808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1463808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                float xVel = mVelocityTracker.getXVelocity();
1464808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (xVel < 0) {
1465808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    xVel = -xVel;
1466808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1467dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                if (xVel > mFlingGestureMaxXVelocityPx) {
1468dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                    xVel = mFlingGestureMaxXVelocityPx; // limit how much we care about the x axis
1469808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1470808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1471808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                float vel = (float)Math.hypot(yVel, xVel);
1472808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (negative) {
1473808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    vel = -vel;
1474808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
1475808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1476dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                if (CHATTY) {
14775e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller                    Slog.d(TAG, String.format("gesture: vraw=(%f,%f) vnorm=(%f,%f) vlinear=%f",
14785e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller                        mVelocityTracker.getXVelocity(),
1479dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                        mVelocityTracker.getYVelocity(),
1480dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                        xVel, yVel,
1481dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                        vel));
1482dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler                }
1483dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler
1484fe172cc861448cf1115195cbad5b3300357c02f0Daniel Sandler                performFling(y + mViewDelta, vel, false);
1485808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1486808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1487808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1488808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        return false;
1489808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1490808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1491911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown    private void trackMovement(MotionEvent event) {
1492911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown        // Add movement to velocity tracker using raw screen X and Y coordinates instead
1493911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown        // of window coordinates because the window frame may be moving at the same time.
1494911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown        float deltaX = event.getRawX() - event.getX();
1495911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown        float deltaY = event.getRawY() - event.getY();
1496911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown        event.offsetLocation(deltaX, deltaY);
1497911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown        mVelocityTracker.addMovement(event);
1498911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown        event.offsetLocation(-deltaX, -deltaY);
1499911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown    }
1500911fe30d5841d0622f3925a9fbc66d499965b111Jeff Brown
150160ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler    @Override // CommandQueue
1502328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler    public void setNavigationIconHints(int hints) {
1503328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler        if (hints == mNavigationIconHints) return;
1504328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler
1505328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler        mNavigationIconHints = hints;
1506328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler
1507328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler        if (mNavigationBarView != null) {
1508328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler            mNavigationBarView.setNavigationIconHints(hints);
1509328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler        }
1510328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler    }
1511328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler
1512328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler    @Override // CommandQueue
151360ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler    public void setSystemUiVisibility(int vis) {
1514e137a1ea997036248c86e8fc0a94711020721f19Daniel Sandler        final int old = mSystemUiVisibility;
1515e137a1ea997036248c86e8fc0a94711020721f19Daniel Sandler        final int diff = vis ^ old;
1516e137a1ea997036248c86e8fc0a94711020721f19Daniel Sandler
1517e137a1ea997036248c86e8fc0a94711020721f19Daniel Sandler        if (diff != 0) {
151860ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler            mSystemUiVisibility = vis;
151960ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler
1520e137a1ea997036248c86e8fc0a94711020721f19Daniel Sandler            if (0 != (diff & View.SYSTEM_UI_FLAG_LOW_PROFILE)) {
1521e137a1ea997036248c86e8fc0a94711020721f19Daniel Sandler                final boolean lightsOut = (0 != (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE));
1522e137a1ea997036248c86e8fc0a94711020721f19Daniel Sandler                if (lightsOut) {
1523e137a1ea997036248c86e8fc0a94711020721f19Daniel Sandler                    animateCollapse();
1524e137a1ea997036248c86e8fc0a94711020721f19Daniel Sandler                }
152569314e72941c86734c12476d1e61459811159b74Daniel Sandler                if (mNavigationBarView != null) {
152669314e72941c86734c12476d1e61459811159b74Daniel Sandler                    mNavigationBarView.setLowProfile(lightsOut);
152769314e72941c86734c12476d1e61459811159b74Daniel Sandler                }
152860ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler            }
152960ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler
153060ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler            notifyUiVisibilityChanged();
153160ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler        }
153260ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler    }
153360ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler
15349305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato    public void setLightsOn(boolean on) {
153560ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler        Log.v(TAG, "setLightsOn(" + on + ")");
153660ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler        if (on) {
153760ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler            setSystemUiVisibility(mSystemUiVisibility & ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
153860ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler        } else {
153960ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler            setSystemUiVisibility(mSystemUiVisibility | View.SYSTEM_UI_FLAG_LOW_PROFILE);
15409305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato        }
15411d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler    }
15421d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler
154360ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler    private void notifyUiVisibilityChanged() {
15441d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler        try {
154560ee25643e0a7b8841063a4e97b0f18c51807e91Daniel Sandler            mWindowManager.statusBarVisibilityChanged(mSystemUiVisibility);
15461d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler        } catch (RemoteException ex) {
15471d4d30aebd2c22627131819cabfe95f97def2c83Daniel Sandler        }
15489305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato    }
15499305647eb61bb60a1f42481a0c0d208dc9bbe965Joe Onorato
15505c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler    public void topAppWindowChanged(boolean showMenu) {
15515c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler        if (DEBUG) {
15525c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler            Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button");
15535c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler        }
15545c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler        if (mNavigationBarView != null) {
1555f1ebcee22442e0bc2aa86582d352b5ee78257db3Daniel Sandler            mNavigationBarView.setMenuVisibility(showMenu);
15565c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler        }
15575c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler
15585c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler        // See above re: lights-out policy for legacy apps.
15595c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler        if (showMenu) setLightsOn(true);
15605c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler    }
15615c8da949804ed4b55dcebae63796714e0028b488Daniel Sandler
1562328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler    @Override
1563328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler    public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
1564328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler        boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS)
1565328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler            || ((vis & InputMethodService.IME_VISIBLE) != 0);
1566328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler
1567328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler        mCommandQueue.setNavigationIconHints(
1568328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler                altBack ? (mNavigationIconHints | StatusBarManager.NAVIGATION_HINT_BACK_ALT)
1569328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler                        : (mNavigationIconHints & ~StatusBarManager.NAVIGATION_HINT_BACK_ALT));
1570328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler    }
1571328310c6fac6066d338926bb43d359862cae36d2Daniel Sandler
15722992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    @Override
15732992ea782fa61780d8e0de7a36a2a84622f8694bJeff Brown    public void setHardKeyboardStatus(boolean available, boolean enabled) { }
1574e02d808abf370965c3c4e4d38af11bc69110fde2Daniel Sandler
15757c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag, int id) {
15767c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        return new NotificationClicker(intent, pkg, tag, id);
15777c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    }
15787c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
15797c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    private class NotificationClicker implements View.OnClickListener {
1580808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        private PendingIntent mIntent;
1581808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        private String mPkg;
1582808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        private String mTag;
1583808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        private int mId;
1584808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
15857c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        NotificationClicker(PendingIntent intent, String pkg, String tag, int id) {
1586808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mIntent = intent;
1587808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mPkg = pkg;
1588808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTag = tag;
1589808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mId = id;
1590808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1591808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1592808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void onClick(View v) {
1593808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            try {
1594808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // The intent we are sending is for the application, which
1595808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // won't have permission to immediately start an activity after
1596808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // the user switches to home.  We know it is safe to do at this
1597808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // point, so make sure new activity switches are now allowed.
1598808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                ActivityManagerNative.getDefault().resumeAppSwitches();
159990c52de28691ca0bbbf7c039ef20f85ce46882ccDianne Hackborn                // Also, notifications can be launched from the lock screen,
160090c52de28691ca0bbbf7c039ef20f85ce46882ccDianne Hackborn                // so dismiss the lock screen when the activity starts.
160190c52de28691ca0bbbf7c039ef20f85ce46882ccDianne Hackborn                ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
1602808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            } catch (RemoteException e) {
1603808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1604808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1605808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (mIntent != null) {
1606808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                int[] pos = new int[2];
1607808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                v.getLocationOnScreen(pos);
1608808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                Intent overlay = new Intent();
1609808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                overlay.setSourceBounds(
1610808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                        new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight()));
1611808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                try {
1612f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato                    mIntent.send(mContext, 0, overlay);
1613808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                } catch (PendingIntent.CanceledException e) {
1614808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    // the stack trace isn't very helpful here.  Just log the exception message.
1615808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    Slog.w(TAG, "Sending contentIntent failed: " + e);
1616808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
161792d331883ada42e49001853e266cda2d9c8631b8Daniel Sandler
161892d331883ada42e49001853e266cda2d9c8631b8Daniel Sandler                KeyguardManager kgm =
161992d331883ada42e49001853e266cda2d9c8631b8Daniel Sandler                    (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
162092d331883ada42e49001853e266cda2d9c8631b8Daniel Sandler                if (kgm != null) kgm.exitKeyguardSecurely(null);
1621808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1622808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1623808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            try {
1624808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mBarService.onNotificationClick(mPkg, mTag, mId);
1625808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            } catch (RemoteException ex) {
1626808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // system process is dead if we're here.
1627808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1628808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1629808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // close the shade if it was open
1630808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            animateCollapse();
1631808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1632808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // If this click was on the intruder alert, hide that instead
1633808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mHandler.sendEmptyMessage(MSG_HIDE_INTRUDER);
1634808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1635808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1636808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1637808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private void tick(StatusBarNotification n) {
1638808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // Show the ticker if one is requested. Also don't do this
1639808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // until status bar window is attached to the window manager,
1640808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // because...  well, what's the point otherwise?  And trying to
1641808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // run a ticker without being attached will crash!
1642808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (n.notification.tickerText != null && mStatusBarView.getWindowToken() != null) {
1643808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS
1644808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                            | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) {
1645808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mTicker.addEntry(n);
1646808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1647808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1648808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1649808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1650808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    /**
1651808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * Cancel this notification and tell the StatusBarManagerService / NotificationManagerService
1652808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * about the failure.
1653808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     *
1654808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * WARNING: this will call back into us.  Don't hold any locks.
1655808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     */
1656808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void handleNotificationError(IBinder key, StatusBarNotification n, String message) {
1657808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        removeNotification(key);
1658808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        try {
1659808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mBarService.onNotificationError(n.pkg, n.tag, n.id, n.uid, n.initialPid, message);
1660808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } catch (RemoteException ex) {
1661808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // The end is nigh.
1662808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1663808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1664808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1665808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private class MyTicker extends Ticker {
1666dfa08db1652585a8cf27f929371c7ca6bf18ca60Daniel Sandler        MyTicker(Context context, View sb) {
1667808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            super(context, sb);
1668808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1669808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1670808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        @Override
1671dfa08db1652585a8cf27f929371c7ca6bf18ca60Daniel Sandler        public void tickerStarting() {
1672808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTicking = true;
1673808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mIcons.setVisibility(View.GONE);
1674808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTickerView.setVisibility(View.VISIBLE);
1675808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_up_in, null));
1676808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mIcons.startAnimation(loadAnim(com.android.internal.R.anim.push_up_out, null));
1677808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1678808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1679808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        @Override
1680dfa08db1652585a8cf27f929371c7ca6bf18ca60Daniel Sandler        public void tickerDone() {
1681808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mIcons.setVisibility(View.VISIBLE);
1682808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTickerView.setVisibility(View.GONE);
1683808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mIcons.startAnimation(loadAnim(com.android.internal.R.anim.push_down_in, null));
1684808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_down_out,
1685808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                        mTickingDoneListener));
1686808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1687808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1688dfa08db1652585a8cf27f929371c7ca6bf18ca60Daniel Sandler        public void tickerHalting() {
1689808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mIcons.setVisibility(View.VISIBLE);
1690808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTickerView.setVisibility(View.GONE);
1691808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mIcons.startAnimation(loadAnim(com.android.internal.R.anim.fade_in, null));
1692808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.fade_out,
1693808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                        mTickingDoneListener));
1694808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1695808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1696808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1697808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    Animation.AnimationListener mTickingDoneListener = new Animation.AnimationListener() {;
1698808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void onAnimationEnd(Animation animation) {
1699808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mTicking = false;
1700808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1701808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void onAnimationRepeat(Animation animation) {
1702808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1703808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void onAnimationStart(Animation animation) {
1704808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1705808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    };
1706808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1707808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private Animation loadAnim(int id, Animation.AnimationListener listener) {
1708f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato        Animation anim = AnimationUtils.loadAnimation(mContext, id);
1709808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (listener != null) {
1710808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            anim.setAnimationListener(listener);
1711808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1712808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        return anim;
1713808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1714808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1715488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler    public static String viewInfo(View v) {
1716488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler        return "[(" + v.getLeft() + "," + v.getTop() + ")(" + v.getRight() + "," + v.getBottom()
1717488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler                + ") " + v.getWidth() + "x" + v.getHeight() + "]";
1718808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1719808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1720f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1721808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        synchronized (mQueueLock) {
1722808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("Current Status Bar state:");
1723808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mExpanded=" + mExpanded
1724808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + ", mExpandedVisible=" + mExpandedVisible);
1725808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mTicking=" + mTicking);
1726808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mTracking=" + mTracking);
1727808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mAnimating=" + mAnimating
1728808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + ", mAnimY=" + mAnimY + ", mAnimVel=" + mAnimVel
1729808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + ", mAnimAccel=" + mAnimAccel);
1730808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mCurAnimationTime=" + mCurAnimationTime
1731808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mAnimLastTime=" + mAnimLastTime);
17321dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            pw.println("  mAnimatingReveal=" + mAnimatingReveal
1733808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mViewDelta=" + mViewDelta);
173436412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            pw.println("  mDisplayMetrics=" + mDisplayMetrics);
1735808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mExpandedParams: " + mExpandedParams);
1736808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mExpandedView: " + viewInfo(mExpandedView));
1737808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mExpandedDialog: " + mExpandedDialog);
1738808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mTrackingParams: " + mTrackingParams);
1739808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mTrackingView: " + viewInfo(mTrackingView));
17407c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            pw.println("  mPile: " + viewInfo(mPile));
1741808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mNoNotificationsTitle: " + viewInfo(mNoNotificationsTitle));
1742808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mCloseView: " + viewInfo(mCloseView));
1743808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mTickerView: " + viewInfo(mTickerView));
1744808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pw.println("  mScrollView: " + viewInfo(mScrollView)
1745808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " scroll " + mScrollView.getScrollX() + "," + mScrollView.getScrollY());
1746808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
17477579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler
1748488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler        pw.print("  mNavigationBarView=");
1749488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler        if (mNavigationBarView == null) {
1750488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler            pw.println("null");
1751488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler        } else {
1752488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler            mNavigationBarView.dump(fd, pw, args);
1753488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler        }
1754488529506f2b767aec0c6e122e7227a9ebe067a2Daniel Sandler
17557579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler        if (DUMPTRUCK) {
17567579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler            synchronized (mNotificationData) {
17577579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                int N = mNotificationData.size();
17587579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                pw.println("  notification icons: " + N);
17597579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                for (int i=0; i<N; i++) {
17607579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                    NotificationData.Entry e = mNotificationData.get(i);
17617579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                    pw.println("    [" + i + "] key=" + e.key + " icon=" + e.icon);
17627579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                    StatusBarNotification n = e.notification;
17632561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                    pw.println("         pkg=" + n.pkg + " id=" + n.id + " score=" + n.score);
17647579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                    pw.println("         notification=" + n.notification);
17657579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                    pw.println("         tickerText=\"" + n.notification.tickerText + "\"");
17667579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                }
1767808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
17687579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler
17697579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler            int N = mStatusIcons.getChildCount();
17707579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler            pw.println("  system icons: " + N);
1771808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            for (int i=0; i<N; i++) {
17727579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                StatusBarIconView ic = (StatusBarIconView) mStatusIcons.getChildAt(i);
17737579bca7a02477353700d3b716f172b4fab267c0Daniel Sandler                pw.println("    [" + i + "] icon=" + ic);
1774808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
17755e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller
177689d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler            if (false) {
177789d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                pw.println("see the logcat for a dump of the views we have created.");
177889d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                // must happen on ui thread
177989d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                mHandler.post(new Runnable() {
178089d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                        public void run() {
178189d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                            mStatusBarView.getLocationOnScreen(mAbsPos);
178289d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                            Slog.d(TAG, "mStatusBarView: ----- (" + mAbsPos[0] + "," + mAbsPos[1]
178389d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                                    + ") " + mStatusBarView.getWidth() + "x"
178489d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                                    + mStatusBarView.getHeight());
178589d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                            mStatusBarView.debug();
178689d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler
178789d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                            mExpandedView.getLocationOnScreen(mAbsPos);
178889d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                            Slog.d(TAG, "mExpandedView: ----- (" + mAbsPos[0] + "," + mAbsPos[1]
178989d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                                    + ") " + mExpandedView.getWidth() + "x"
179089d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                                    + mExpandedView.getHeight());
179189d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                            mExpandedView.debug();
179289d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler
179389d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                            mTrackingView.getLocationOnScreen(mAbsPos);
179489d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                            Slog.d(TAG, "mTrackingView: ----- (" + mAbsPos[0] + "," + mAbsPos[1]
179589d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                                    + ") " + mTrackingView.getWidth() + "x"
179689d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                                    + mTrackingView.getHeight());
179789d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                            mTrackingView.debug();
179889d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                        }
179989d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler                    });
180089d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler            }
1801808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
180289d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler
180389d97131bd7fd7494c3469dfdf6351a84bae62bfDaniel Sandler        mNetworkController.dump(fd, pw, args);
1804808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1805808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1806808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void onBarViewAttached() {
18076e8db88b4b31a6e0211561f25ee1a422e4797ba1Daniel Sandler        // The status bar has just been attached to the view hierarchy; it's possible that the
18086e8db88b4b31a6e0211561f25ee1a422e4797ba1Daniel Sandler        // screen has rotated in-between when we set up the window and now, so let's double-check
18096e8db88b4b31a6e0211561f25ee1a422e4797ba1Daniel Sandler        // the display metrics just in case.
18106e8db88b4b31a6e0211561f25ee1a422e4797ba1Daniel Sandler        updateDisplaySize();
18116e8db88b4b31a6e0211561f25ee1a422e4797ba1Daniel Sandler
1812808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        WindowManager.LayoutParams lp;
1813808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        int pixelFormat;
1814808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        Drawable bg;
1815808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1816808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        /// ---------- Tracking View --------------
1817808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        bg = mTrackingView.getBackground();
1818808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (bg != null) {
1819808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pixelFormat = bg.getOpacity();
1820808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1821808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1822808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp = new WindowManager.LayoutParams(
1823808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                ViewGroup.LayoutParams.MATCH_PARENT,
1824808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                ViewGroup.LayoutParams.MATCH_PARENT,
182529fc2c9705e1bb8ae098fca016032d2325031587Joe Onorato                WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL,
182636412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler                0
182736412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
1828808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
1829808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
183049f58407340a2282e0c0ff31043bee8937bd6bffDaniel Sandler                PixelFormat.TRANSLUCENT);
1831b69f7015e7233d1c22d474f7f6850d4d93b2b790Daniel Sandler        if (ActivityManager.isHighEndGfx(mDisplay)) {
1832b69f7015e7233d1c22d474f7f6850d4d93b2b790Daniel Sandler            lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1833b69f7015e7233d1c22d474f7f6850d4d93b2b790Daniel Sandler        }
1834808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato//        lp.token = mStatusBarView.getWindowToken();
1835808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL;
1836808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.setTitle("TrackingView");
1837808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.y = mTrackingPosition;
1838808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTrackingParams = lp;
1839808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1840808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        WindowManagerImpl.getDefault().addView(mTrackingView, lp);
1841808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1842808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1843808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void onTrackingViewAttached() {
1844808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        WindowManager.LayoutParams lp;
1845808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        int pixelFormat;
1846808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1847808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        /// ---------- Expanded View --------------
1848808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        pixelFormat = PixelFormat.TRANSLUCENT;
1849808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1850808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp = mExpandedDialog.getWindow().getAttributes();
1851808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.x = 0;
185236412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler        mTrackingPosition = lp.y = mDisplayMetrics.heightPixels; // sufficiently large negative
185329fc2c9705e1bb8ae098fca016032d2325031587Joe Onorato        lp.type = WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
185436412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler        lp.flags = 0
185536412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
1856808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
1857808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1858808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                | WindowManager.LayoutParams.FLAG_DITHER
1859808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
1860b69f7015e7233d1c22d474f7f6850d4d93b2b790Daniel Sandler        if (ActivityManager.isHighEndGfx(mDisplay)) {
1861b69f7015e7233d1c22d474f7f6850d4d93b2b790Daniel Sandler            lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1862b69f7015e7233d1c22d474f7f6850d4d93b2b790Daniel Sandler        }
1863808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.format = pixelFormat;
1864808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL;
1865808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        lp.setTitle("StatusBarExpanded");
1866808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedParams = lp;
18671dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn        updateExpandedSize();
18681dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn        mExpandedDialog.getWindow().setFormat(pixelFormat);
1869808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1870808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
1871808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedDialog.setContentView(mExpandedView,
1872808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
1873808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                                           ViewGroup.LayoutParams.MATCH_PARENT));
1874808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedDialog.getWindow().setBackgroundDrawable(null);
1875808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mExpandedDialog.show();
1876808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1877808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1878808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void setNotificationIconVisibility(boolean visible, int anim) {
1879808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        int old = mNotificationIcons.getVisibility();
1880808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        int v = visible ? View.VISIBLE : View.INVISIBLE;
1881808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (old != v) {
1882808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mNotificationIcons.setVisibility(v);
1883808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mNotificationIcons.startAnimation(loadAnim(anim, null));
1884808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1885808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1886808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
18871dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn    void updateExpandedInvisiblePosition() {
18881dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn        if (mTrackingView != null) {
188936412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            mTrackingPosition = -mDisplayMetrics.heightPixels;
18901dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            if (mTrackingParams != null) {
18911dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                mTrackingParams.y = mTrackingPosition;
18921dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                WindowManagerImpl.getDefault().updateViewLayout(mTrackingView, mTrackingParams);
18931dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            }
18941dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn        }
18951dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn        if (mExpandedParams != null) {
189636412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            mExpandedParams.y = -mDisplayMetrics.heightPixels;
18971dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            mExpandedDialog.getWindow().setAttributes(mExpandedParams);
18981dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn        }
18991dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn    }
19001dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn
1901808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void updateExpandedViewPos(int expandedPosition) {
1902808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) {
1903808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            Slog.d(TAG, "updateExpandedViewPos before expandedPosition=" + expandedPosition
1904cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler                    + " mTrackingParams.y=" + ((mTrackingParams == null) ? "?" : mTrackingParams.y)
1905808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mTrackingPosition=" + mTrackingPosition);
1906808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1907808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1908808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        int h = mStatusBarView.getHeight();
190936412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler        int disph = mDisplayMetrics.heightPixels;
1910808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1911808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // If the expanded view is not visible, make sure they're still off screen.
1912808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // Maybe the view was resized.
1913808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (!mExpandedVisible) {
19141dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            updateExpandedInvisiblePosition();
1915808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            return;
1916808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1917808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1918808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // tracking view...
1919808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        int pos;
1920808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (expandedPosition == EXPANDED_FULL_OPEN) {
1921808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pos = h;
1922808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1923808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        else if (expandedPosition == EXPANDED_LEAVE_ALONE) {
1924808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pos = mTrackingPosition;
1925808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1926808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        else {
1927808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (expandedPosition <= disph) {
1928808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                pos = expandedPosition;
1929808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            } else {
1930808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                pos = disph;
1931808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1932808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            pos -= disph-h;
1933808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1934808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTrackingPosition = mTrackingParams.y = pos;
1935808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mTrackingParams.height = disph-h;
1936808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        WindowManagerImpl.getDefault().updateViewLayout(mTrackingView, mTrackingParams);
1937808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1938808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (mExpandedParams != null) {
19391dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            if (mCloseView.getWindowVisibility() == View.VISIBLE) {
19401dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                mCloseView.getLocationInWindow(mPositionTmp);
19411dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                final int closePos = mPositionTmp[1];
1942808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
19431dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                mExpandedContents.getLocationInWindow(mPositionTmp);
19441dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                final int contentsBottom = mPositionTmp[1] + mExpandedContents.getHeight();
1945808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
19461dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                mExpandedParams.y = pos + mTrackingView.getHeight()
19471dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                        - (mTrackingParams.height-closePos) - contentsBottom;
1948cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler
1949cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler                if (SPEW) {
19505e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller                    Slog.d(PhoneStatusBar.TAG,
1951cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler                            "pos=" + pos +
1952cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler                            " trackingHeight=" + mTrackingView.getHeight() +
19535e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller                            " (trackingParams.height - closePos)=" +
1954cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler                                (mTrackingParams.height - closePos) +
1955cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler                            " contentsBottom=" + contentsBottom);
1956cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler                }
1957cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler
19581dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            } else {
19591dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                // If the tracking view is not yet visible, then we can't have
19601dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                // a good value of the close view location.  We need to wait for
19611dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                // it to be visible to do a layout.
196236412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler                mExpandedParams.y = -mDisplayMetrics.heightPixels;
19631dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            }
1964808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            int max = h;
1965808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (mExpandedParams.y > max) {
1966808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mExpandedParams.y = max;
1967808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1968808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            int min = mTrackingPosition;
1969808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (mExpandedParams.y < min) {
1970808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mExpandedParams.y = min;
1971808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1972808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1973808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            boolean visible = (mTrackingPosition + mTrackingView.getHeight()) > h;
1974808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (!visible) {
1975808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // if the contents aren't visible, move the expanded view way off screen
1976808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // because the window itself extends below the content view.
1977808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mExpandedParams.y = -disph;
1978808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1979808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mExpandedDialog.getWindow().setAttributes(mExpandedParams);
1980808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1981808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // As long as this isn't just a repositioning that's not supposed to affect
1982808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // the user's perception of what's showing, call to say that the visibility
1983808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            // has changed. (Otherwise, someone else will call to do that).
1984808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (expandedPosition != EXPANDED_LEAVE_ALONE) {
1985808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (SPEW) Slog.d(TAG, "updateExpandedViewPos visibilityChanged(" + visible + ")");
1986808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                visibilityChanged(visible);
1987808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
1988808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1989808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
1990808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (SPEW) {
1991808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            Slog.d(TAG, "updateExpandedViewPos after  expandedPosition=" + expandedPosition
1992808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mTrackingParams.y=" + mTrackingParams.y
1993808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mTrackingPosition=" + mTrackingPosition
1994808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mExpandedParams.y=" + mExpandedParams.y
1995808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    + " mExpandedParams.height=" + mExpandedParams.height);
1996808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
1997808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
1998808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
19991dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn    int getExpandedHeight(int disph) {
2000cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler        if (DEBUG) {
2001cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler            Slog.d(TAG, "getExpandedHeight(" + disph + "): sbView="
2002cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler                    + mStatusBarView.getHeight() + " closeView=" + mCloseView.getHeight());
2003cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler        }
20041dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn        return disph - mStatusBarView.getHeight() - mCloseView.getHeight();
2005808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
2006808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
20071dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn    void updateDisplaySize() {
200836412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler        mDisplay.getMetrics(mDisplayMetrics);
200936412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler        if (DEBUG) {
201036412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            Slog.d(TAG, "updateDisplaySize: " + mDisplayMetrics);
201136412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler        }
20121dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn        updateExpandedSize();
20131dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn    }
20141dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn
20151dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn    void updateExpandedSize() {
2016cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler        if (DEBUG) {
2017cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler            Slog.d(TAG, "updateExpandedSize()");
2018cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler        }
201936412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler        if (mExpandedDialog != null && mExpandedParams != null && mDisplayMetrics != null) {
202036412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            mExpandedParams.width = mDisplayMetrics.widthPixels;
202136412a7e7c4929bdac1221b7ced9e73d0d204691Daniel Sandler            mExpandedParams.height = getExpandedHeight(mDisplayMetrics.heightPixels);
20221dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            if (!mExpandedVisible) {
20231dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                updateExpandedInvisiblePosition();
20241dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            } else {
20251dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn                mExpandedDialog.getWindow().setAttributes(mExpandedParams);
20261dacf2772d0099ae74f42f81d162a3d0e180ffb7Dianne Hackborn            }
2027cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler            if (DEBUG) {
20285e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller                Slog.d(TAG, "updateExpandedSize: height=" + mExpandedParams.height + " " +
2029cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler                    (mExpandedVisible ? "VISIBLE":"INVISIBLE"));
2030cf336e10c03a802bd96df164c49b069cb7ad6819Daniel Sandler            }
2031808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
2032808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
2033808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
20343b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    public void toggleRecentApps() {
2035412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka        int msg = (mRecentsPanel.getVisibility() == View.VISIBLE)
2036412cba8aa10231cdf515d9400a754e8a16a8eb3dMichael Jurka                ? MSG_CLOSE_RECENTS_PANEL : MSG_OPEN_RECENTS_PANEL;
20373b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        mHandler.removeMessages(msg);
20383b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        mHandler.sendEmptyMessage(msg);
20393b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    }
20403b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
2041808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    /**
2042808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * The LEDs are turned o)ff when the notification panel is shown, even just a little bit.
2043808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * This was added last-minute and is inconsistent with the way the rest of the notifications
2044808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * are handled, because the notification isn't really cancelled.  The lights are just
2045808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * turned off.  If any other notifications happen, the lights will turn back on.  Steve says
2046808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * this is what he wants. (see bug 1131461)
2047808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     */
2048808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void visibilityChanged(boolean visible) {
2049808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (mPanelSlightlyVisible != visible) {
2050808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mPanelSlightlyVisible = visible;
2051808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            try {
2052808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mBarService.onPanelRevealed();
2053808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            } catch (RemoteException ex) {
2054808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                // Won't fail unless the world has ended.
2055808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
2056808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
2057808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
2058808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2059808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void performDisableActions(int net) {
2060808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        int old = mDisabled;
2061808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        int diff = net ^ old;
2062808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mDisabled = net;
2063808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2064808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        // act accordingly
2065808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
2066808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if ((net & StatusBarManager.DISABLE_EXPAND) != 0) {
2067808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                Slog.d(TAG, "DISABLE_EXPAND: yes");
2068808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                animateCollapse();
2069808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
2070808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
2071808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
2072808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if ((net & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
2073808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes");
2074808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (mTicking) {
2075808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    mNotificationIcons.setVisibility(View.INVISIBLE);
2076808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    mTicker.halt();
2077808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                } else {
2078808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    setNotificationIconVisibility(false, com.android.internal.R.anim.fade_out);
2079808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
2080808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            } else {
2081808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no");
2082808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                if (!mExpandedVisible) {
2083808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in);
2084808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                }
2085808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
2086808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
2087808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (mTicking && (net & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
2088808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                mTicker.halt();
2089808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
2090808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
2091808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
2092808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2093808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private View.OnClickListener mClearButtonListener = new View.OnClickListener() {
20948ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler        final int mini(int a, int b) {
20958ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler            return (b>a?a:b);
20968ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler        }
2097808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void onClick(View v) {
20988ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler            synchronized (mNotificationData) {
20992f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                // animate-swipe all dismissable notifications, then animate the shade closed
21002f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                int numChildren = mPile.getChildCount();
21018ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler
21022f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                int scrollTop = mScrollView.getScrollY();
21032f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                int scrollBottom = scrollTop + mScrollView.getHeight();
21042f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                final ArrayList<View> snapshot = new ArrayList<View>(numChildren);
21052f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                for (int i=0; i<numChildren; i++) {
21068ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                    final View child = mPile.getChildAt(i);
21072f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                    if (mPile.canChildBeDismissed(child) && child.getBottom() > scrollTop &&
21082f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                            child.getTop() < scrollBottom) {
21092f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        snapshot.add(child);
21102f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                    }
21118ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                }
21122f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                final int N = snapshot.size();
21138ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                new Thread(new Runnable() {
21148ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                    @Override
21158ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                    public void run() {
21162f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // Decrease the delay for every row we animate to give the sense of
21172f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // accelerating the swipes
21182f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        final int ROW_DELAY_DECREMENT = 10;
21192f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        int currentDelay = 140;
21202f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        int totalDelay = 0;
21212f2022afa1eb85018368398bd150e9575fc099c9Chet Haase
21222f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // Set the shade-animating state to avoid doing other work during
21232f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // all of these animations. In particular, avoid layout and
21242f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // redrawing when collapsing the shade.
21252f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        mPile.setViewRemoval(false);
21262f2022afa1eb85018368398bd150e9575fc099c9Chet Haase
21272f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        mPostCollapseCleanup = new Runnable() {
21288ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                            public void run() {
21298ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                                try {
21302f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                                    mPile.setViewRemoval(true);
21318ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                                    mBarService.onClearAllNotifications();
21322f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                                } catch (Exception ex) { }
21338ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                            }
21342f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        };
21358ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler
21362f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        View sampleView = snapshot.get(0);
21372f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        int width = sampleView.getWidth();
21382f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        final int velocity = (int)(width * 8); // 1000/8 = 125 ms duration
21398ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                        for (View v : snapshot) {
21408ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                            final View _v = v;
21412f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                            mHandler.postDelayed(new Runnable() {
21428ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                                @Override
21438ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                                public void run() {
21442f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                                    mPile.dismissRowAnimated(_v, velocity);
21458ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                                }
21462f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                            }, totalDelay);
21472f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                            currentDelay = Math.max(50, currentDelay - ROW_DELAY_DECREMENT);
21482f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                            totalDelay += currentDelay;
21498ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                        }
21502f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // Delay the collapse animation until after all swipe animations have
21512f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // finished. Provide some buffer because there may be some extra delay
21522f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // before actually starting each swipe animation. Ideally, we'd
21532f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // synchronize the end of those animations with the start of the collaps
21542f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        // exactly.
21552f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        mHandler.postDelayed(new Runnable() {
21562f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                            public void run() {
21572f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                                animateCollapse(false);
21582f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                            }
21592f2022afa1eb85018368398bd150e9575fc099c9Chet Haase                        }, totalDelay + 225);
21608ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                    }
21618ba33c965f940070060585e45e1c833519bb45c9Daniel Sandler                }).start();
2162808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
2163808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
2164808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    };
2165808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2166d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler    private View.OnClickListener mSettingsButtonListener = new View.OnClickListener() {
2167d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler        public void onClick(View v) {
21685e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller            try {
21695e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller                // Dismiss the lock screen when Settings starts.
21705e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller                ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
21715e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller            } catch (RemoteException e) {
21725e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller            }
2173d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler            v.getContext().startActivity(new Intent(Settings.ACTION_SETTINGS)
2174d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
2175d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler            animateCollapse();
2176d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler        }
2177d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler    };
2178d309056d36759446c91ff5c1e17a217bfa4fdcfbDaniel Sandler
2179808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
2180808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void onReceive(Context context, Intent intent) {
2181808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            String action = intent.getAction();
2182808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
2183808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                    || Intent.ACTION_SCREEN_OFF.equals(action)) {
21843b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                boolean excludeRecents = false;
21853b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
2186edbdd3a024ca35c331036823dde1f484d3333b31Daniel Sandler                    String reason = intent.getStringExtra("reason");
21873b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    if (reason != null) {
21883b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                        excludeRecents = reason.equals("recentapps");
21893b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    }
21903b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                }
21913b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                animateCollapse(excludeRecents);
2192808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
2193808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
21948956dbbc5f292d8b79072ae73b25f2114c8c7479Daniel Sandler                repositionNavigationBar();
2195808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato                updateResources();
2196808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            }
2197808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
2198808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    };
2199808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2200808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    private void setIntruderAlertVisibility(boolean vis) {
2201808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mIntruderAlertView.setVisibility(vis ? View.VISIBLE : View.GONE);
2202808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
2203808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2204808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    /**
2205808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * Reload some of our resources when the configuration changes.
2206808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     *
2207808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * We don't reload everything when the configuration changes -- we probably
2208808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * should, but getting that smooth is tough.  Someday we'll fix that.  In the
2209808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     * meantime, just update the things that we know change.
2210808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato     */
2211808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void updateResources() {
2212f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato        final Context context = mContext;
2213f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato        final Resources res = context.getResources();
2214808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
22151347c30824ce3544dff03c93ffad9af7f0327e41Daniel Sandler        if (mClearButton instanceof TextView) {
22161347c30824ce3544dff03c93ffad9af7f0327e41Daniel Sandler            ((TextView)mClearButton).setText(context.getText(R.string.status_bar_clear_all_button));
22171347c30824ce3544dff03c93ffad9af7f0327e41Daniel Sandler        }
2218f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato        mNoNotificationsTitle.setText(context.getText(R.string.status_bar_no_notifications_title));
2219808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
22207c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        loadDimens();
22217c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    }
22225e6af448045f20f7a1b393960d200c25e9d976e8Jim Miller
22237c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler    protected void loadDimens() {
22247c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        final Resources res = mContext.getResources();
22257c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
22267c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        mNaturalBarHeight = res.getDimensionPixelSize(
22277c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler                com.android.internal.R.dimen.status_bar_height);
22287c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
22297c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        int newIconSize = res.getDimensionPixelSize(
22307c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            com.android.internal.R.dimen.status_bar_icon_size);
22317c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        int newIconHPadding = res.getDimensionPixelSize(
22327c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            R.dimen.status_bar_icon_padding);
22337c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
22347c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) {
22357c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler//            Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding);
22367c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            mIconHPadding = newIconHPadding;
22377c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            mIconSize = newIconSize;
22387c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler            //reloadAllNotificationIcons(); // reload the tray
22397c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler        }
22407c3e39de22c68e69c4924b339132f8e3bf3f96afDaniel Sandler
2241808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore);
2242808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2243dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        mSelfExpandVelocityPx = res.getDimension(R.dimen.self_expand_velocity);
2244dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        mSelfCollapseVelocityPx = res.getDimension(R.dimen.self_collapse_velocity);
2245dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        mFlingExpandMinVelocityPx = res.getDimension(R.dimen.fling_expand_min_velocity);
2246dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        mFlingCollapseMinVelocityPx = res.getDimension(R.dimen.fling_collapse_min_velocity);
2247dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler
2248dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        mCollapseMinDisplayFraction = res.getFraction(R.dimen.collapse_min_display_fraction, 1, 1);
2249dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        mExpandMinDisplayFraction = res.getFraction(R.dimen.expand_min_display_fraction, 1, 1);
2250dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler
2251dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        mExpandAccelPx = res.getDimension(R.dimen.expand_accel);
2252dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        mCollapseAccelPx = res.getDimension(R.dimen.collapse_accel);
2253dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler
2254dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler        mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity);
2255dc940eaa67db0108f8a8629826dbb3c5c7d779e9Daniel Sandler
2256808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        if (false) Slog.v(TAG, "updateResources");
2257808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
2258808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2259808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    //
2260808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    // tracing
2261808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    //
2262808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2263808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void postStartTracing() {
2264808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        mHandler.postDelayed(mStartTracing, 3000);
2265808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
2266808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2267808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    void vibrate() {
2268f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato        android.os.Vibrator vib = (android.os.Vibrator)mContext.getSystemService(
2269f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dcJoe Onorato                Context.VIBRATOR_SERVICE);
2270808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        vib.vibrate(250);
2271808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    }
2272808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
22732561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    public int getScoreThreshold() {
22742561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler        return mDisplayMinScore;
22752561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    }
22762561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler
22772561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    public void setScoreThreshold(int score) {
22782561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler        // XXX HAX
22792561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler        if (mDisplayMinScore != score) {
22802561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            this.mDisplayMinScore = score;
22812561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            applyScoreThreshold();
22822561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler        }
22832561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    }
22842561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler
22852561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    private void applyScoreThreshold() {
22862561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler        int N = mNotificationData.size();
22872561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler        for (int i=0; i<N; i++) {
22882561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            NotificationData.Entry entry = mNotificationData.get(i);
22892561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            int vis = (entry.notification.score < mDisplayMinScore)
22902561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                ? View.GONE
22912561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler                : View.VISIBLE;
22922561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            entry.row.setVisibility(vis);
22932561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler            entry.icon.setVisibility(vis);
22942561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler        }
22952561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler    }
22962561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler
2297808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    Runnable mStartTracing = new Runnable() {
2298808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void run() {
2299808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            vibrate();
2300808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            SystemClock.sleep(250);
2301808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            Slog.d(TAG, "startTracing");
2302808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            android.os.Debug.startMethodTracing("/data/statusbar-traces/trace");
2303808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            mHandler.postDelayed(mStopTracing, 10000);
2304808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
2305808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    };
2306808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2307808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    Runnable mStopTracing = new Runnable() {
2308808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        public void run() {
2309808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            android.os.Debug.stopMethodTracing();
2310808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            Slog.d(TAG, "stopTracing");
2311808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato            vibrate();
2312808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato        }
2313808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato    };
23143b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
23153b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    public class TouchOutsideListener implements View.OnTouchListener {
23163b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        private int mMsg;
23173b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        private RecentsPanelView mPanel;
23183b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
23193b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        public TouchOutsideListener(int msg, RecentsPanelView panel) {
23203b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            mMsg = msg;
23213b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            mPanel = panel;
23223b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        }
23233b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka
23243b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        public boolean onTouch(View v, MotionEvent ev) {
23253b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            final int action = ev.getAction();
23263b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            if (action == MotionEvent.ACTION_OUTSIDE
23273b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                || (action == MotionEvent.ACTION_DOWN
23283b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                    && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) {
23293b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                mHandler.removeMessages(mMsg);
23303b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                mHandler.sendEmptyMessage(mMsg);
23313b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka                return true;
23323b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            }
23333b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka            return false;
23343b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka        }
23353b1fc47d004f6b29af8f40d181baa3460b1e3b15Michael Jurka    }
2336808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato}
2337808182dc874e93582da38d013a4a790d6bc08fc9Joe Onorato
2338