blob: bfa1b635f06b42a88a029d97491cca7f5add6b05 [file] [log] [blame]
Joe Onorato808182d2010-07-09 18:52:06 -04001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.statusbar.tablet;
18
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -040019import android.animation.LayoutTransition;
20import android.animation.ObjectAnimator;
Jim Millere898ac52012-04-06 17:10:57 -070021import android.app.ActivityManager;
Daniel Sandlerdfa08db2010-08-05 16:18:42 -040022import android.app.ActivityManagerNative;
Joe Onoratoef1e7762010-09-17 18:38:38 -040023import android.app.Notification;
Michael Jurkab7f43272011-10-27 15:06:38 -070024import android.app.PendingIntent;
Daniel Sandlerdfa08db2010-08-05 16:18:42 -040025import android.app.StatusBarManager;
Daniel Sandler5feceeb2013-03-22 18:29:23 -070026import android.service.notification.StatusBarNotification;
Michael Jurkab7f43272011-10-27 15:06:38 -070027import android.content.BroadcastReceiver;
Joe Onorato808182d2010-07-09 18:52:06 -040028import android.content.Context;
29import android.content.Intent;
Michael Jurkab7f43272011-10-27 15:06:38 -070030import android.content.IntentFilter;
Daniel Sandlerce6ff642011-02-18 12:51:08 -050031import android.content.SharedPreferences;
Daniel Sandler0ad460b2010-12-14 12:14:53 -050032import android.content.res.Configuration;
Joe Onorato808182d2010-07-09 18:52:06 -040033import android.content.res.Resources;
Daniel Sandler9120d552010-07-23 09:11:14 -040034import android.graphics.PixelFormat;
Jeff Brownbc68a592011-07-25 12:58:12 -070035import android.graphics.Point;
Adam Powell29ea5252011-11-15 18:59:36 -080036import android.graphics.drawable.Drawable;
Joe Onorato4daaeaf2010-11-17 20:43:12 -080037import android.graphics.drawable.LayerDrawable;
Michael Jurka7f2668c2012-03-27 07:49:52 -070038import android.inputmethodservice.InputMethodService;
Joe Onorato808182d2010-07-09 18:52:06 -040039import android.os.IBinder;
Daniel Sandler3eebd1f2010-07-27 08:39:33 -040040import android.os.Message;
Daniel Sandlerdfa08db2010-08-05 16:18:42 -040041import android.os.RemoteException;
Joe Onoratoef1e7762010-09-17 18:38:38 -040042import android.text.TextUtils;
Daniel Sandler3eebd1f2010-07-27 08:39:33 -040043import android.util.Slog;
Joe Onorato07949e92011-05-25 17:35:35 -070044import android.view.Display;
Joe Onorato808182d2010-07-09 18:52:06 -040045import android.view.Gravity;
Daniel Sandler10163c62010-12-08 11:51:05 -050046import android.view.KeyEvent;
Joe Onoratob62ac122010-09-20 16:16:32 -040047import android.view.MotionEvent;
Daniel Sandleraa051d62011-03-01 16:23:57 -050048import android.view.SoundEffectConstants;
Daniel Sandler8304da42010-10-25 15:53:25 -040049import android.view.VelocityTracker;
Joe Onorato808182d2010-07-09 18:52:06 -040050import android.view.View;
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -040051import android.view.ViewConfiguration;
Daniel Sandler9120d552010-07-23 09:11:14 -040052import android.view.ViewGroup;
Michael Jurka7f2668c2012-03-27 07:49:52 -070053import android.view.ViewGroup.LayoutParams;
Daniel Sandler9120d552010-07-23 09:11:14 -040054import android.view.WindowManager;
Michael Jurka7f2668c2012-03-27 07:49:52 -070055import android.view.accessibility.AccessibilityEvent;
Daniel Sandler3eebd1f2010-07-27 08:39:33 -040056import android.widget.ImageView;
Joe Onorato808182d2010-07-09 18:52:06 -040057import android.widget.LinearLayout;
Daniel Sandlerdfa08db2010-08-05 16:18:42 -040058import android.widget.ScrollView;
Daniel Sandler9120d552010-07-23 09:11:14 -040059import android.widget.TextView;
Joe Onorato808182d2010-07-09 18:52:06 -040060
61import com.android.internal.statusbar.StatusBarIcon;
Joe Onorato808182d2010-07-09 18:52:06 -040062import com.android.systemui.R;
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -050063import com.android.systemui.statusbar.BaseStatusBar;
Jim Miller9a720f52012-05-30 03:19:43 -070064import com.android.systemui.statusbar.CommandQueue;
Daniel Sandlerd2217f02012-05-04 16:40:13 -040065import com.android.systemui.statusbar.DoNotDisturb;
Michael Jurkab7f43272011-10-27 15:06:38 -070066import com.android.systemui.statusbar.NotificationData;
Michael Jurkaa600fd92012-06-25 15:57:05 -070067import com.android.systemui.statusbar.NotificationData.Entry;
Michael Jurkab7f43272011-10-27 15:06:38 -070068import com.android.systemui.statusbar.SignalClusterView;
Michael Jurkab7f43272011-10-27 15:06:38 -070069import com.android.systemui.statusbar.StatusBarIconView;
Joe Onoratofd52b182010-11-10 18:00:52 -080070import com.android.systemui.statusbar.policy.BatteryController;
Joe Onoratofce2bf32011-02-01 17:00:29 -080071import com.android.systemui.statusbar.policy.BluetoothController;
Daniel Sandler45c04012011-06-07 15:29:07 -040072import com.android.systemui.statusbar.policy.CompatModeButton;
Daniel Sandlere40451a2011-02-03 14:51:35 -050073import com.android.systemui.statusbar.policy.LocationController;
Joe Onoratofd52b182010-11-10 18:00:52 -080074import com.android.systemui.statusbar.policy.NetworkController;
Daniel Sandlerf7a19562012-04-04 14:04:21 -040075import com.android.systemui.statusbar.policy.NotificationRowLayout;
Daniel Sandlerce6ff642011-02-18 12:51:08 -050076import com.android.systemui.statusbar.policy.Prefs;
Joe Onorato808182d2010-07-09 18:52:06 -040077
Daniel Sandler6a858c32012-03-12 14:38:58 -040078import java.io.FileDescriptor;
79import java.io.PrintWriter;
80import java.util.ArrayList;
81
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -050082public class TabletStatusBar extends BaseStatusBar implements
Michael Jurkacb2522c2012-04-13 09:32:47 -070083 InputMethodsPanel.OnHardKeyboardEnabledChangeListener {
Daniel Sandlerfb970e92010-08-20 10:57:17 -040084 public static final boolean DEBUG = false;
Daniel Sandlere25f8332011-06-15 15:00:10 -040085 public static final boolean DEBUG_COMPAT_HELP = false;
Joe Onoratofd52b182010-11-10 18:00:52 -080086 public static final String TAG = "TabletStatusBar";
Joe Onorato808182d2010-07-09 18:52:06 -040087
Daniel Sandler0ad460b2010-12-14 12:14:53 -050088
Joe Onoratob62ac122010-09-20 16:16:32 -040089 public static final int MSG_OPEN_NOTIFICATION_PANEL = 1000;
90 public static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001;
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -040091 public static final int MSG_OPEN_NOTIFICATION_PEEK = 1002;
92 public static final int MSG_CLOSE_NOTIFICATION_PEEK = 1003;
Michael Jurka7f2668c2012-03-27 07:49:52 -070093 // 1020-1029 reserved for BaseStatusBar
Daniel Sandler0ad460b2010-12-14 12:14:53 -050094 public static final int MSG_SHOW_CHROME = 1030;
95 public static final int MSG_HIDE_CHROME = 1031;
satok82beadf2010-12-27 19:03:06 +090096 public static final int MSG_OPEN_INPUT_METHODS_PANEL = 1040;
97 public static final int MSG_CLOSE_INPUT_METHODS_PANEL = 1041;
Daniel Sandler3b0543a2011-06-14 11:30:28 -040098 public static final int MSG_OPEN_COMPAT_MODE_PANEL = 1050;
99 public static final int MSG_CLOSE_COMPAT_MODE_PANEL = 1051;
Daniel Sandler2ed08d22011-01-30 16:07:28 -0500100 public static final int MSG_STOP_TICKER = 2000;
Jim Miller44c66fe2010-10-20 18:32:52 -0700101
Daniel Sandler3a2fded2011-02-23 11:19:59 -0500102 // Fitts' Law assistance for LatinIME; see policy.EventHole
Daniel Sandler10163c62010-12-08 11:51:05 -0500103 private static final boolean FAKE_SPACE_BAR = true;
104
Daniel Sandler298a2a82011-08-11 16:13:22 -0400105 // Notification "peeking" (flyover preview of individual notifications)
Daniel Sandler298a2a82011-08-11 16:13:22 -0400106 final static int NOTIFICATION_PEEK_HOLD_THRESH = 200; // ms
107 final static int NOTIFICATION_PEEK_FADE_DELAY = 3000; // ms
108
Daniel Sandler58b173b2012-05-03 11:25:29 -0400109 private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10; // see NotificationManagerService
110 private static final int HIDE_ICONS_BELOW_SCORE = Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER;
111
Joe Onoratodc100302011-01-11 17:07:41 -0800112 // The height of the bar, as definied by the build. It may be taller if we're plugged
113 // into hdmi.
114 int mNaturalBarHeight = -1;
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500115 int mIconSize = -1;
116 int mIconHPadding = -1;
Andrew Flynn1d9af302012-03-07 15:48:51 -0800117 int mNavIconWidth = -1;
118 int mMenuNavIconWidth = -1;
satok5485ff62011-05-27 19:15:01 +0900119 private int mMaxNotificationIcons = 5;
Daniel Sandler9120d552010-07-23 09:11:14 -0400120
Joe Onoratob62ac122010-09-20 16:16:32 -0400121 TabletStatusBarView mStatusBarView;
Joe Onoratofd52b182010-11-10 18:00:52 -0800122 View mNotificationArea;
123 View mNotificationTrigger;
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400124 NotificationIconArea mNotificationIconArea;
Daniel Sandler21eb86a2011-03-02 11:52:58 -0500125 ViewGroup mNavigationArea;
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -0500126
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500127 boolean mNotificationDNDMode;
128 NotificationData.Entry mNotificationDNDDummyEntry;
129
Joe Onorato536c58f2010-11-28 17:52:28 -0800130 ImageView mBackButton;
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -0500131 View mHomeButton;
Daniel Sandlere02d8082010-10-08 15:13:22 -0400132 View mMenuButton;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400133 View mRecentButton;
Daniel Sandler328310c2011-09-23 15:56:52 -0400134 private boolean mAltBackButtonEnabledForIme;
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400135
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400136 ViewGroup mFeedbackIconArea; // notification icons, IME icon, compat icon
satokcd7cd292010-11-20 15:46:23 +0900137 InputMethodButton mInputMethodSwitchButton;
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400138 CompatModeButton mCompatModeButton;
satok06487a52010-10-29 11:37:18 +0900139
Joe Onoratoddf680b2010-09-26 13:59:40 -0700140 NotificationPanel mNotificationPanel;
Joe Onorato07949e92011-05-25 17:35:35 -0700141 WindowManager.LayoutParams mNotificationPanelParams;
Joe Onorato8a576712010-11-15 16:50:34 -0800142 NotificationPeekPanel mNotificationPeekWindow;
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400143 ViewGroup mNotificationPeekRow;
144 int mNotificationPeekIndex;
Daniel Sandlera8e5b062010-12-01 13:53:08 -0500145 IBinder mNotificationPeekKey;
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400146 LayoutTransition mNotificationPeekScrubLeft, mNotificationPeekScrubRight;
147
148 int mNotificationPeekTapDuration;
149 int mNotificationFlingVelocity;
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400150
Joe Onoratofd52b182010-11-10 18:00:52 -0800151 BatteryController mBatteryController;
Joe Onoratofce2bf32011-02-01 17:00:29 -0800152 BluetoothController mBluetoothController;
Daniel Sandlere40451a2011-02-03 14:51:35 -0500153 LocationController mLocationController;
Joe Onoratofd52b182010-11-10 18:00:52 -0800154 NetworkController mNetworkController;
Daniel Sandlerd2217f02012-05-04 16:40:13 -0400155 DoNotDisturb mDoNotDisturb;
Daniel Sandler1e3ed8f2010-08-13 10:12:48 -0400156
Daniel Sandler21eb86a2011-03-02 11:52:58 -0500157 ViewGroup mBarContents;
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -0500158
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500159 // hide system chrome ("lights out") support
160 View mShadow;
Daniel Sandlerce70d912010-09-02 11:59:41 -0400161
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400162 NotificationIconArea.IconLayout mIconLayout;
163
Joe Onoratoef1e7762010-09-17 18:38:38 -0400164 TabletTicker mTicker;
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400165
Daniel Sandler10163c62010-12-08 11:51:05 -0500166 View mFakeSpaceBar;
167 KeyEvent mSpaceBarKeyEvent = null;
168
Dianne Hackborned31bbf2011-06-15 11:16:06 -0700169 View mCompatibilityHelpDialog = null;
Jim Millere898ac52012-04-06 17:10:57 -0700170
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400171 // for disabling the status bar
172 int mDisabled = 0;
173
satok82beadf2010-12-27 19:03:06 +0900174 private InputMethodsPanel mInputMethodsPanel;
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400175 private CompatModePanel mCompatModePanel;
Joe Onorato55d2d762010-09-26 13:02:01 -0700176
Mike Lockwood066c8912011-08-24 10:17:18 -0400177 private int mSystemUiVisibility = 0;
Daniel Sandler60ee2562011-07-22 12:34:33 -0400178
Daniel Sandler328310c2011-09-23 15:56:52 -0400179 private int mNavigationIconHints = 0;
180
Jim Miller9a720f52012-05-30 03:19:43 -0700181 private int mShowSearchHoldoff = 0;
182
Daniel Sandlerc51451a2010-12-16 19:06:46 -0500183 public Context getContext() { return mContext; }
184
Jim Miller9a720f52012-05-30 03:19:43 -0700185 private Runnable mShowSearchPanel = new Runnable() {
186 public void run() {
187 showSearchPanel();
188 }
189 };
190
Jim Miller998bb762012-05-21 13:37:27 -0700191 private View.OnTouchListener mHomeSearchActionListener = new View.OnTouchListener() {
192 public boolean onTouch(View v, MotionEvent event) {
193 switch(event.getAction()) {
194 case MotionEvent.ACTION_DOWN:
John Spurlock67ad3682012-06-26 17:42:00 -0400195 if (!shouldDisableNavbarGestures() && !inKeyguardRestrictedInputMode()) {
Jim Miller9a720f52012-05-30 03:19:43 -0700196 mHandler.removeCallbacks(mShowSearchPanel);
197 mHandler.postDelayed(mShowSearchPanel, mShowSearchHoldoff);
Jim Millera073e572012-05-23 17:03:27 -0700198 }
Jim Miller998bb762012-05-21 13:37:27 -0700199 break;
Jim Miller9a720f52012-05-30 03:19:43 -0700200
201 case MotionEvent.ACTION_UP:
202 case MotionEvent.ACTION_CANCEL:
203 mHandler.removeCallbacks(mShowSearchPanel);
204 break;
Jim Miller998bb762012-05-21 13:37:27 -0700205 }
206 return false;
207 }
208 };
209
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500210 @Override
211 protected void createAndAddWindows() {
212 addStatusBarWindow();
213 addPanelWindows();
214 }
Jim Millere898ac52012-04-06 17:10:57 -0700215
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500216 private void addStatusBarWindow() {
Daniel Sandler079b33d2012-03-02 16:29:41 -0500217 final View sb = makeStatusBarView();
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500218
219 final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
220 ViewGroup.LayoutParams.MATCH_PARENT,
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700221 ViewGroup.LayoutParams.MATCH_PARENT,
222 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500223 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
224 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
225 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
Greg Hackmannbb033ea2012-07-10 14:39:29 -0700226 PixelFormat.OPAQUE);
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500227
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500228 // We explicitly leave FLAG_HARDWARE_ACCELERATED out of the flags. The status bar occupies
229 // very little screen real-estate and is updated fairly frequently. By using CPU rendering
230 // for the status bar, we prevent the GPU from having to wake up just to do these small
231 // updates, which should help keep power consumption down.
232
233 lp.gravity = getStatusBarGravity();
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700234 lp.setTitle("SystemBar");
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500235 lp.packageName = mContext.getPackageName();
Jeff Brown98365d72012-08-19 20:30:52 -0700236 mWindowManager.addView(sb, lp);
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500237 }
238
Daniel Sandler9120d552010-07-23 09:11:14 -0400239 protected void addPanelWindows() {
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400240 final Context context = mContext;
Joe Onorato07949e92011-05-25 17:35:35 -0700241 final Resources res = mContext.getResources();
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400242
Jim Miller44c66fe2010-10-20 18:32:52 -0700243 // Notification Panel
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400244 mNotificationPanel = (NotificationPanel)View.inflate(context,
Daniel Sandler4a066c52012-04-20 14:49:13 -0400245 R.layout.system_bar_notification_panel, null);
Daniel Sandler1347c302011-08-01 16:47:53 -0400246 mNotificationPanel.setBar(this);
Joe Onorato7c270fa2010-12-08 17:31:42 -0800247 mNotificationPanel.show(false, false);
Joe Onoratob62ac122010-09-20 16:16:32 -0400248 mNotificationPanel.setOnTouchListener(
Joe Onoratoddf680b2010-09-26 13:59:40 -0700249 new TouchOutsideListener(MSG_CLOSE_NOTIFICATION_PANEL, mNotificationPanel));
Joe Onoratob62ac122010-09-20 16:16:32 -0400250
Daniel Sandler2b697352011-07-22 16:23:09 -0400251 // the battery icon
Joe Onoratofd52b182010-11-10 18:00:52 -0800252 mBatteryController.addIconView((ImageView)mNotificationPanel.findViewById(R.id.battery));
253 mBatteryController.addLabelView(
254 (TextView)mNotificationPanel.findViewById(R.id.battery_text));
Daniel Sandler2b697352011-07-22 16:23:09 -0400255
256 // Bt
Joe Onoratofce2bf32011-02-01 17:00:29 -0800257 mBluetoothController.addIconView(
258 (ImageView)mNotificationPanel.findViewById(R.id.bluetooth));
Daniel Sandler2b697352011-07-22 16:23:09 -0400259
260 // network icons: either a combo icon that switches between mobile and data, or distinct
261 // mobile and data icons
Jim Millera073e572012-05-23 17:03:27 -0700262 final ImageView mobileRSSI =
Daniel Sandler2b697352011-07-22 16:23:09 -0400263 (ImageView)mNotificationPanel.findViewById(R.id.mobile_signal);
264 if (mobileRSSI != null) {
265 mNetworkController.addPhoneSignalIconView(mobileRSSI);
266 }
Jim Millera073e572012-05-23 17:03:27 -0700267 final ImageView wifiRSSI =
Daniel Sandler2b697352011-07-22 16:23:09 -0400268 (ImageView)mNotificationPanel.findViewById(R.id.wifi_signal);
269 if (wifiRSSI != null) {
270 mNetworkController.addWifiIconView(wifiRSSI);
271 }
Daniel Sandler5962fd52012-01-11 14:57:04 -0500272 mNetworkController.addWifiLabelView(
273 (TextView)mNotificationPanel.findViewById(R.id.wifi_text));
Daniel Sandler2b697352011-07-22 16:23:09 -0400274
Joe Onorato42f8e132010-11-29 15:52:43 -0800275 mNetworkController.addDataTypeIconView(
Daniel Sandler5962fd52012-01-11 14:57:04 -0500276 (ImageView)mNotificationPanel.findViewById(R.id.mobile_type));
277 mNetworkController.addMobileLabelView(
278 (TextView)mNotificationPanel.findViewById(R.id.mobile_text));
279 mNetworkController.addCombinedLabelView(
Daniel Sandler3e8f5a22010-12-03 14:52:10 -0500280 (TextView)mBarContents.findViewById(R.id.network_text));
Joe Onoratofd52b182010-11-10 18:00:52 -0800281
Joe Onorato55d2d762010-09-26 13:02:01 -0700282 mStatusBarView.setIgnoreChildren(0, mNotificationTrigger, mNotificationPanel);
Daniel Sandlerd39e3882010-08-31 14:16:13 -0400283
Joe Onorato07949e92011-05-25 17:35:35 -0700284 WindowManager.LayoutParams lp = mNotificationPanelParams = new WindowManager.LayoutParams(
285 res.getDimensionPixelSize(R.dimen.notification_panel_width),
286 getNotificationPanelHeight(),
Daniel Sandler4ce64fb2012-05-03 10:53:10 -0400287 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
Daniel Sandler9120d552010-07-23 09:11:14 -0400288 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Joe Onorato07949e92011-05-25 17:35:35 -0700289 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
Jeff Brown46e75292010-11-10 16:53:45 -0800290 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
Joe Onorato7c270fa2010-12-08 17:31:42 -0800291 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
292 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
Daniel Sandler9120d552010-07-23 09:11:14 -0400293 PixelFormat.TRANSLUCENT);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700294 lp.gravity = Gravity.BOTTOM | Gravity.END;
Daniel Sandler9120d552010-07-23 09:11:14 -0400295 lp.setTitle("NotificationPanel");
Joe Onorato7c270fa2010-12-08 17:31:42 -0800296 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
297 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
298 lp.windowAnimations = com.android.internal.R.style.Animation; // == no animation
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500299// lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade
Daniel Sandler9120d552010-07-23 09:11:14 -0400300
Jeff Brown98365d72012-08-19 20:30:52 -0700301 mWindowManager.addView(mNotificationPanel, lp);
Daniel Sandler9120d552010-07-23 09:11:14 -0400302
Jim Millere898ac52012-04-06 17:10:57 -0700303 // Search Panel
304 mStatusBarView.setBar(this);
Jim Miller998bb762012-05-21 13:37:27 -0700305 mHomeButton.setOnTouchListener(mHomeSearchActionListener);
Jim Millere898ac52012-04-06 17:10:57 -0700306 updateSearchPanel();
307
satok82beadf2010-12-27 19:03:06 +0900308 // Input methods Panel
309 mInputMethodsPanel = (InputMethodsPanel) View.inflate(context,
Daniel Sandler4a066c52012-04-20 14:49:13 -0400310 R.layout.system_bar_input_methods_panel, null);
Jeff Brown2992ea72011-01-28 22:04:14 -0800311 mInputMethodsPanel.setHardKeyboardEnabledChangeListener(this);
satok82beadf2010-12-27 19:03:06 +0900312 mInputMethodsPanel.setOnTouchListener(new TouchOutsideListener(
313 MSG_CLOSE_INPUT_METHODS_PANEL, mInputMethodsPanel));
satok913f42d2011-01-17 16:58:10 +0900314 mInputMethodsPanel.setImeSwitchButton(mInputMethodSwitchButton);
Daniel Sandler328310c2011-09-23 15:56:52 -0400315 mStatusBarView.setIgnoreChildren(2, mInputMethodSwitchButton, mInputMethodsPanel);
satok82beadf2010-12-27 19:03:06 +0900316 lp = new WindowManager.LayoutParams(
317 ViewGroup.LayoutParams.WRAP_CONTENT,
318 ViewGroup.LayoutParams.WRAP_CONTENT,
319 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
320 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
321 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
322 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
323 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
324 PixelFormat.TRANSLUCENT);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700325 lp.gravity = Gravity.BOTTOM | Gravity.END;
satok82beadf2010-12-27 19:03:06 +0900326 lp.setTitle("InputMethodsPanel");
327 lp.windowAnimations = R.style.Animation_RecentPanel;
328
Jeff Brown98365d72012-08-19 20:30:52 -0700329 mWindowManager.addView(mInputMethodsPanel, lp);
Jim Millere898ac52012-04-06 17:10:57 -0700330
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400331 // Compatibility mode selector panel
332 mCompatModePanel = (CompatModePanel) View.inflate(context,
Daniel Sandler4a066c52012-04-20 14:49:13 -0400333 R.layout.system_bar_compat_mode_panel, null);
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400334 mCompatModePanel.setOnTouchListener(new TouchOutsideListener(
335 MSG_CLOSE_COMPAT_MODE_PANEL, mCompatModePanel));
336 mCompatModePanel.setTrigger(mCompatModeButton);
337 mCompatModePanel.setVisibility(View.GONE);
Daniel Sandler328310c2011-09-23 15:56:52 -0400338 mStatusBarView.setIgnoreChildren(3, mCompatModeButton, mCompatModePanel);
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400339 lp = new WindowManager.LayoutParams(
340 250,
341 ViewGroup.LayoutParams.WRAP_CONTENT,
342 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
343 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
344 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
345 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
346 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
347 PixelFormat.TRANSLUCENT);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700348 lp.gravity = Gravity.BOTTOM | Gravity.END;
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400349 lp.setTitle("CompatModePanel");
350 lp.windowAnimations = android.R.style.Animation_Dialog;
351
Jeff Brown98365d72012-08-19 20:30:52 -0700352 mWindowManager.addView(mCompatModePanel, lp);
Jim Millere898ac52012-04-06 17:10:57 -0700353
Michael Jurka80343f62012-10-18 13:13:46 +0200354 mRecentButton.setOnTouchListener(mRecentsPreloadOnTouchListener);
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500355
Daniel Sandlerf7a19562012-04-04 14:04:21 -0400356 mPile = (NotificationRowLayout)mNotificationPanel.findViewById(R.id.content);
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500357 mPile.removeAllViews();
Daniel Sandlerf7a19562012-04-04 14:04:21 -0400358 mPile.setLongPressListener(getNotificationLongClicker());
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500359
360 ScrollView scroller = (ScrollView)mPile.getParent();
361 scroller.setFillViewport(true);
Daniel Sandler9120d552010-07-23 09:11:14 -0400362 }
Joe Onorato808182d2010-07-09 18:52:06 -0400363
Chris Wren8fd12652012-05-09 21:25:57 -0400364 @Override
365 protected int getExpandedViewMaxHeight() {
366 return getNotificationPanelHeight();
367 }
368
Joe Onorato07949e92011-05-25 17:35:35 -0700369 private int getNotificationPanelHeight() {
370 final Resources res = mContext.getResources();
Jeff Brown98365d72012-08-19 20:30:52 -0700371 final Display d = mWindowManager.getDefaultDisplay();
Jeff Brownbc68a592011-07-25 12:58:12 -0700372 final Point size = new Point();
373 d.getRealSize(size);
374 return Math.max(res.getDimensionPixelSize(R.dimen.notification_panel_min_height), size.y);
Joe Onorato07949e92011-05-25 17:35:35 -0700375 }
376
Joe Onorato808182d2010-07-09 18:52:06 -0400377 @Override
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400378 public void start() {
379 super.start(); // will add the main bar view
Joe Onorato808182d2010-07-09 18:52:06 -0400380 }
381
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500382 @Override
Joe Onoratodc100302011-01-11 17:07:41 -0800383 protected void onConfigurationChanged(Configuration newConfig) {
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700384 super.onConfigurationChanged(newConfig);
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500385 loadDimens();
Joe Onorato07949e92011-05-25 17:35:35 -0700386 mNotificationPanelParams.height = getNotificationPanelHeight();
Jeff Brown98365d72012-08-19 20:30:52 -0700387 mWindowManager.updateViewLayout(mNotificationPanel, mNotificationPanelParams);
Jim Miller9a720f52012-05-30 03:19:43 -0700388 mShowSearchHoldoff = mContext.getResources().getInteger(
389 R.integer.config_show_search_delay);
Jim Miller955a0162012-06-11 21:06:13 -0700390 updateSearchPanel();
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500391 }
392
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700393 @Override
394 protected void refreshLayout(int layoutDirection) {
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700395 mNotificationPanel.refreshLayout(layoutDirection);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700396 }
397
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500398 protected void loadDimens() {
399 final Resources res = mContext.getResources();
400
Joe Onoratodc100302011-01-11 17:07:41 -0800401 mNaturalBarHeight = res.getDimensionPixelSize(
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700402 com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500403
404 int newIconSize = res.getDimensionPixelSize(
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700405 com.android.internal.R.dimen.system_bar_icon_size);
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500406 int newIconHPadding = res.getDimensionPixelSize(
407 R.dimen.status_bar_icon_padding);
Andrew Flynn1d9af302012-03-07 15:48:51 -0800408 int newNavIconWidth = res.getDimensionPixelSize(R.dimen.navigation_key_width);
409 int newMenuNavIconWidth = res.getDimensionPixelSize(R.dimen.navigation_menu_key_width);
410
411 if (mNavigationArea != null && newNavIconWidth != mNavIconWidth) {
412 mNavIconWidth = newNavIconWidth;
413
414 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
415 mNavIconWidth, ViewGroup.LayoutParams.MATCH_PARENT);
416 mBackButton.setLayoutParams(lp);
417 mHomeButton.setLayoutParams(lp);
418 mRecentButton.setLayoutParams(lp);
419 }
420
421 if (mNavigationArea != null && newMenuNavIconWidth != mMenuNavIconWidth) {
422 mMenuNavIconWidth = newMenuNavIconWidth;
423
424 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
425 mMenuNavIconWidth, ViewGroup.LayoutParams.MATCH_PARENT);
426 mMenuButton.setLayoutParams(lp);
427 }
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500428
429 if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) {
430// Slog.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding);
431 mIconHPadding = newIconHPadding;
432 mIconSize = newIconSize;
433 reloadAllNotificationIcons(); // reload the tray
434 }
satok5485ff62011-05-27 19:15:01 +0900435
436 final int numIcons = res.getInteger(R.integer.config_maxNotificationIcons);
437 if (numIcons != mMaxNotificationIcons) {
438 mMaxNotificationIcons = numIcons;
439 if (DEBUG) Slog.d(TAG, "max notification icons: " + mMaxNotificationIcons);
440 reloadAllNotificationIcons();
441 }
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500442 }
443
Michael Jurkacb2522c2012-04-13 09:32:47 -0700444 @Override
Daniel Sandler328310c2011-09-23 15:56:52 -0400445 public View getStatusBarView() {
446 return mStatusBarView;
447 }
448
Joe Onorato808182d2010-07-09 18:52:06 -0400449 protected View makeStatusBarView() {
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400450 final Context context = mContext;
Jim Miller85babff2011-01-11 14:26:03 -0800451
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500452 loadDimens();
Joe Onorato808182d2010-07-09 18:52:06 -0400453
Joe Onoratob62ac122010-09-20 16:16:32 -0400454 final TabletStatusBarView sb = (TabletStatusBarView)View.inflate(
Daniel Sandler4a066c52012-04-20 14:49:13 -0400455 context, R.layout.system_bar, null);
Joe Onorato808182d2010-07-09 18:52:06 -0400456 mStatusBarView = sb;
457
Joe Onoratob62ac122010-09-20 16:16:32 -0400458 sb.setHandler(mHandler);
459
Daniel Sandler0c4ccff2011-10-19 16:39:14 -0400460 try {
461 // Sanity-check that someone hasn't set up the config wrong and asked for a navigation
462 // bar on a tablet that has only the system bar
Jeff Brown98365d72012-08-19 20:30:52 -0700463 if (mWindowManagerService.hasNavigationBar()) {
Mike Lockwoodc33d5762011-10-21 13:28:22 -0400464 Slog.e(TAG, "Tablet device cannot show navigation bar and system bar");
Daniel Sandler0c4ccff2011-10-19 16:39:14 -0400465 }
466 } catch (RemoteException ex) {
Chet Haasebc0009d2011-09-08 16:19:50 -0700467 }
468
Daniel Sandler21eb86a2011-03-02 11:52:58 -0500469 mBarContents = (ViewGroup) sb.findViewById(R.id.bar_contents);
Joe Onoratof63b0f42010-09-12 17:03:19 -0400470
Joe Onoratofd52b182010-11-10 18:00:52 -0800471 // the whole right-hand side of the bar
472 mNotificationArea = sb.findViewById(R.id.notificationArea);
Chris Wren0c8275b2012-05-08 13:36:48 -0400473 mNotificationArea.setOnTouchListener(new NotificationTriggerTouchListener());
Joe Onoratofd52b182010-11-10 18:00:52 -0800474
Joe Onorato55d2d762010-09-26 13:02:01 -0700475 // the button to open the notification area
Joe Onoratofd52b182010-11-10 18:00:52 -0800476 mNotificationTrigger = sb.findViewById(R.id.notificationTrigger);
Joe Onorato55d2d762010-09-26 13:02:01 -0700477
Joe Onorato808182d2010-07-09 18:52:06 -0400478 // the more notifications icon
479 mNotificationIconArea = (NotificationIconArea)sb.findViewById(R.id.notificationIcons);
480
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400481 // where the icons go
482 mIconLayout = (NotificationIconArea.IconLayout) sb.findViewById(R.id.icons);
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400483
Michael Jurkaa600fd92012-06-25 15:57:05 -0700484 mNotificationPeekTapDuration = ViewConfiguration.getTapTimeout();
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400485 mNotificationFlingVelocity = 300; // px/s
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400486
Daniel Sandlerc51451a2010-12-16 19:06:46 -0500487 mTicker = new TabletTicker(this);
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400488
Joe Onoratofd52b182010-11-10 18:00:52 -0800489 // The icons
Daniel Sandlere40451a2011-02-03 14:51:35 -0500490 mLocationController = new LocationController(mContext); // will post a notification
491
Daniel Sandlerd2217f02012-05-04 16:40:13 -0400492 // watch the PREF_DO_NOT_DISTURB and convert to appropriate disable() calls
493 mDoNotDisturb = new DoNotDisturb(mContext);
494
Joe Onoratofd52b182010-11-10 18:00:52 -0800495 mBatteryController = new BatteryController(mContext);
496 mBatteryController.addIconView((ImageView)sb.findViewById(R.id.battery));
Joe Onoratofce2bf32011-02-01 17:00:29 -0800497 mBluetoothController = new BluetoothController(mContext);
498 mBluetoothController.addIconView((ImageView)sb.findViewById(R.id.bluetooth));
Daniel Sandler2b697352011-07-22 16:23:09 -0400499
Joe Onoratofd52b182010-11-10 18:00:52 -0800500 mNetworkController = new NetworkController(mContext);
Jim Millera073e572012-05-23 17:03:27 -0700501 final SignalClusterView signalCluster =
Christian Robertson2e347422011-08-11 14:01:04 -0700502 (SignalClusterView)sb.findViewById(R.id.signal_cluster);
503 mNetworkController.addSignalCluster(signalCluster);
Daniel Sandler1e3ed8f2010-08-13 10:12:48 -0400504
Joe Onorato091e1b82010-09-26 18:04:44 -0700505 // The navigation buttons
Joe Onorato6478adc2011-01-27 21:15:01 -0800506 mBackButton = (ImageView)sb.findViewById(R.id.back);
Daniel Sandler21eb86a2011-03-02 11:52:58 -0500507 mNavigationArea = (ViewGroup) sb.findViewById(R.id.navigationArea);
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -0500508 mHomeButton = mNavigationArea.findViewById(R.id.home);
Daniel Sandlere02d8082010-10-08 15:13:22 -0400509 mMenuButton = mNavigationArea.findViewById(R.id.menu);
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -0500510 mRecentButton = mNavigationArea.findViewById(R.id.recent_apps);
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -0500511 mRecentButton.setOnClickListener(mOnClickListener);
Daniel Sandler4f9986e2011-12-02 16:10:37 -0500512
513 LayoutTransition lt = new LayoutTransition();
514 lt.setDuration(250);
515 // don't wait for these transitions; we just want icons to fade in/out, not move around
516 lt.setDuration(LayoutTransition.CHANGE_APPEARING, 0);
517 lt.setDuration(LayoutTransition.CHANGE_DISAPPEARING, 0);
Daniel Sandler5a826602011-12-07 15:16:18 -0500518 lt.addTransitionListener(new LayoutTransition.TransitionListener() {
519 public void endTransition(LayoutTransition transition, ViewGroup container,
520 View view, int transitionType) {
521 // ensure the menu button doesn't stick around on the status bar after it's been
522 // removed
523 mBarContents.invalidate();
524 }
525 public void startTransition(LayoutTransition transition, ViewGroup container,
526 View view, int transitionType) {}
527 });
Daniel Sandler4f9986e2011-12-02 16:10:37 -0500528 mNavigationArea.setLayoutTransition(lt);
Daniel Sandler96f48182011-08-17 09:50:35 -0400529 // no multi-touch on the nav buttons
530 mNavigationArea.setMotionEventSplittingEnabled(false);
Joe Onorato091e1b82010-09-26 18:04:44 -0700531
satok06487a52010-10-29 11:37:18 +0900532 // The bar contents buttons
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400533 mFeedbackIconArea = (ViewGroup)sb.findViewById(R.id.feedbackIconArea);
satokcd7cd292010-11-20 15:46:23 +0900534 mInputMethodSwitchButton = (InputMethodButton) sb.findViewById(R.id.imeSwitchButton);
satok82beadf2010-12-27 19:03:06 +0900535 // Overwrite the lister
536 mInputMethodSwitchButton.setOnClickListener(mOnClickListener);
satok06487a52010-10-29 11:37:18 +0900537
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400538 mCompatModeButton = (CompatModeButton) sb.findViewById(R.id.compatModeButton);
539 mCompatModeButton.setOnClickListener(mOnClickListener);
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800540 mCompatModeButton.setVisibility(View.GONE);
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400541
Daniel Sandler10163c62010-12-08 11:51:05 -0500542 // for redirecting errant bar taps to the IME
543 mFakeSpaceBar = sb.findViewById(R.id.fake_space_bar);
544
Daniel Sandlerb9606992010-11-19 14:47:59 -0500545 // "shadows" of the status bar features, for lights-out mode
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500546 mShadow = sb.findViewById(R.id.bar_shadow);
547 mShadow.setOnTouchListener(
548 new View.OnTouchListener() {
549 public boolean onTouch(View v, MotionEvent ev) {
550 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
Daniel Sandlerd7201552011-01-28 09:58:02 -0500551 // even though setting the systemUI visibility below will turn these views
552 // on, we need them to come up faster so that they can catch this motion
553 // event
554 mShadow.setVisibility(View.GONE);
555 mBarContents.setVisibility(View.VISIBLE);
556
Joe Onorato55bf3802011-01-25 13:42:10 -0800557 try {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700558 mBarService.setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE);
Joe Onorato55bf3802011-01-25 13:42:10 -0800559 } catch (RemoteException ex) {
560 // system process dead
561 }
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500562 }
563 return false;
564 }
565 });
Daniel Sandlerb9606992010-11-19 14:47:59 -0500566
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500567 // tuning parameters
Daniel Sandler635fb492012-04-27 10:45:37 -0400568 final int LIGHTS_GOING_OUT_SYSBAR_DURATION = 750;
569 final int LIGHTS_GOING_OUT_SHADOW_DURATION = 750;
570 final int LIGHTS_GOING_OUT_SHADOW_DELAY = 0;
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500571
572 final int LIGHTS_COMING_UP_SYSBAR_DURATION = 200;
573// final int LIGHTS_COMING_UP_SYSBAR_DELAY = 50;
574 final int LIGHTS_COMING_UP_SHADOW_DURATION = 0;
575
576 LayoutTransition xition = new LayoutTransition();
577 xition.setAnimator(LayoutTransition.APPEARING,
578 ObjectAnimator.ofFloat(null, "alpha", 0.5f, 1f));
579 xition.setDuration(LayoutTransition.APPEARING, LIGHTS_COMING_UP_SYSBAR_DURATION);
580 xition.setStartDelay(LayoutTransition.APPEARING, 0);
581 xition.setAnimator(LayoutTransition.DISAPPEARING,
582 ObjectAnimator.ofFloat(null, "alpha", 1f, 0f));
583 xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_GOING_OUT_SYSBAR_DURATION);
584 xition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
585 ((ViewGroup)sb.findViewById(R.id.bar_contents_holder)).setLayoutTransition(xition);
586
587 xition = new LayoutTransition();
588 xition.setAnimator(LayoutTransition.APPEARING,
589 ObjectAnimator.ofFloat(null, "alpha", 0f, 1f));
590 xition.setDuration(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DURATION);
591 xition.setStartDelay(LayoutTransition.APPEARING, LIGHTS_GOING_OUT_SHADOW_DELAY);
592 xition.setAnimator(LayoutTransition.DISAPPEARING,
593 ObjectAnimator.ofFloat(null, "alpha", 1f, 0f));
594 xition.setDuration(LayoutTransition.DISAPPEARING, LIGHTS_COMING_UP_SHADOW_DURATION);
595 xition.setStartDelay(LayoutTransition.DISAPPEARING, 0);
596 ((ViewGroup)sb.findViewById(R.id.bar_shadow_holder)).setLayoutTransition(xition);
Daniel Sandlerb9606992010-11-19 14:47:59 -0500597
Joe Onorato5dd11692010-09-27 15:34:04 -0700598 // set the initial view visibility
599 setAreThereNotifications();
600
Michael Jurkab7f43272011-10-27 15:06:38 -0700601 // receive broadcasts
602 IntentFilter filter = new IntentFilter();
603 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
604 filter.addAction(Intent.ACTION_SCREEN_OFF);
605 context.registerReceiver(mBroadcastReceiver, filter);
606
Joe Onorato808182d2010-07-09 18:52:06 -0400607 return sb;
608 }
609
Michael Jurka7f2668c2012-03-27 07:49:52 -0700610 @Override
611 protected WindowManager.LayoutParams getRecentsLayoutParams(LayoutParams layoutParams) {
612 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
613 (int) mContext.getResources().getDimension(R.dimen.status_bar_recents_width),
614 ViewGroup.LayoutParams.MATCH_PARENT,
Daniel Sandler4ce64fb2012-05-03 10:53:10 -0400615 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
Michael Jurka7f2668c2012-03-27 07:49:52 -0700616 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
617 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
618 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
619 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
620 PixelFormat.TRANSLUCENT);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700621 lp.gravity = Gravity.BOTTOM | Gravity.START;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700622 lp.setTitle("RecentsPanel");
623 lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications;
624 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
625 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
626
627 return lp;
628 }
629
Jim Millere898ac52012-04-06 17:10:57 -0700630 @Override
631 protected WindowManager.LayoutParams getSearchLayoutParams(LayoutParams layoutParams) {
632 boolean opaque = false;
633 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
634 LayoutParams.MATCH_PARENT,
635 LayoutParams.MATCH_PARENT,
636 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
637 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
638 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
639 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
640 (opaque ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT));
Jeff Brown98365d72012-08-19 20:30:52 -0700641 if (ActivityManager.isHighEndGfx()) {
Jim Millere898ac52012-04-06 17:10:57 -0700642 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
643 } else {
644 lp.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
645 lp.dimAmount = 0.7f;
646 }
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700647 lp.gravity = Gravity.BOTTOM | Gravity.START;
Jim Millere898ac52012-04-06 17:10:57 -0700648 lp.setTitle("SearchPanel");
649 // TODO: Define custom animation for Search panel
650 lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications;
651 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
652 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
653 return lp;
654 }
655
Jim Millere898ac52012-04-06 17:10:57 -0700656 @Override
657 protected void updateSearchPanel() {
658 super.updateSearchPanel();
659 mSearchPanelView.setStatusBarView(mStatusBarView);
660 mStatusBarView.setDelegateView(mSearchPanelView);
661 }
662
663 @Override
664 public void showSearchPanel() {
665 super.showSearchPanel();
666 WindowManager.LayoutParams lp =
667 (android.view.WindowManager.LayoutParams) mStatusBarView.getLayoutParams();
668 lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Jeff Brown98365d72012-08-19 20:30:52 -0700669 mWindowManager.updateViewLayout(mStatusBarView, lp);
Jim Millere898ac52012-04-06 17:10:57 -0700670 }
671
672 @Override
673 public void hideSearchPanel() {
674 super.hideSearchPanel();
675 WindowManager.LayoutParams lp =
676 (android.view.WindowManager.LayoutParams) mStatusBarView.getLayoutParams();
677 lp.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Jeff Brown98365d72012-08-19 20:30:52 -0700678 mWindowManager.updateViewLayout(mStatusBarView, lp);
Jim Millere898ac52012-04-06 17:10:57 -0700679 }
680
Joe Onoratodc100302011-01-11 17:07:41 -0800681 public int getStatusBarHeight() {
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700682 return mStatusBarView != null ? mStatusBarView.getHeight()
683 : mContext.getResources().getDimensionPixelSize(
684 com.android.internal.R.dimen.navigation_bar_height);
Joe Onoratodc100302011-01-11 17:07:41 -0800685 }
686
Joe Onorato808182d2010-07-09 18:52:06 -0400687 protected int getStatusBarGravity() {
688 return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL;
689 }
690
Joe Onoratodc100302011-01-11 17:07:41 -0800691 public void onBarHeightChanged(int height) {
692 final WindowManager.LayoutParams lp
693 = (WindowManager.LayoutParams)mStatusBarView.getLayoutParams();
694 if (lp == null) {
695 // haven't been added yet
696 return;
697 }
698 if (lp.height != height) {
699 lp.height = height;
Jeff Brown98365d72012-08-19 20:30:52 -0700700 mWindowManager.updateViewLayout(mStatusBarView, lp);
Joe Onoratodc100302011-01-11 17:07:41 -0800701 }
702 }
703
Michael Jurka7f2668c2012-03-27 07:49:52 -0700704 @Override
Michael Jurkaecc395a2012-03-30 05:31:46 -0700705 protected BaseStatusBar.H createHandler() {
Michael Jurka7f2668c2012-03-27 07:49:52 -0700706 return new TabletStatusBar.H();
707 }
708
709 private class H extends BaseStatusBar.H {
Daniel Sandler9120d552010-07-23 09:11:14 -0400710 public void handleMessage(Message m) {
Michael Jurka7f2668c2012-03-27 07:49:52 -0700711 super.handleMessage(m);
Daniel Sandler9120d552010-07-23 09:11:14 -0400712 switch (m.what) {
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400713 case MSG_OPEN_NOTIFICATION_PEEK:
714 if (DEBUG) Slog.d(TAG, "opening notification peek window; arg=" + m.arg1);
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500715
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400716 if (m.arg1 >= 0) {
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500717 final int N = mNotificationData.size();
718
719 if (!mNotificationDNDMode) {
720 if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) {
721 NotificationData.Entry entry = mNotificationData.get(N-1-mNotificationPeekIndex);
722 entry.icon.setBackgroundColor(0);
723 mNotificationPeekIndex = -1;
724 mNotificationPeekKey = null;
725 }
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400726 }
727
728 final int peekIndex = m.arg1;
729 if (peekIndex < N) {
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500730 //Slog.d(TAG, "loading peek: " + peekIndex);
Jim Miller5fda69c2011-02-16 15:17:11 -0800731 NotificationData.Entry entry =
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500732 mNotificationDNDMode
733 ? mNotificationDNDDummyEntry
734 : mNotificationData.get(N-1-peekIndex);
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400735 NotificationData.Entry copy = new NotificationData.Entry(
Jim Miller85babff2011-01-11 14:26:03 -0800736 entry.key,
737 entry.notification,
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400738 entry.icon);
739 inflateViews(copy, mNotificationPeekRow);
740
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500741 if (mNotificationDNDMode) {
742 copy.content.setOnClickListener(new View.OnClickListener() {
743 public void onClick(View v) {
744 SharedPreferences.Editor editor = Prefs.edit(mContext);
745 editor.putBoolean(Prefs.DO_NOT_DISTURB_PREF, false);
746 editor.apply();
Daniel Sandler11cf1782012-09-27 14:03:08 -0400747 animateCollapsePanels();
Mike Lockwood066c8912011-08-24 10:17:18 -0400748 visibilityChanged(false);
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500749 }
750 });
751 }
752
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400753 entry.icon.setBackgroundColor(0x20FFFFFF);
754
755// mNotificationPeekRow.setLayoutTransition(
Jim Miller85babff2011-01-11 14:26:03 -0800756// peekIndex < mNotificationPeekIndex
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400757// ? mNotificationPeekScrubLeft
758// : mNotificationPeekScrubRight);
759
760 mNotificationPeekRow.removeAllViews();
761 mNotificationPeekRow.addView(copy.row);
762
763 mNotificationPeekWindow.setVisibility(View.VISIBLE);
Joe Onorato7c270fa2010-12-08 17:31:42 -0800764 mNotificationPanel.show(false, true);
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400765
766 mNotificationPeekIndex = peekIndex;
Daniel Sandlera8e5b062010-12-01 13:53:08 -0500767 mNotificationPeekKey = entry.key;
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400768 }
769 }
770 break;
771 case MSG_CLOSE_NOTIFICATION_PEEK:
772 if (DEBUG) Slog.d(TAG, "closing notification peek window");
773 mNotificationPeekWindow.setVisibility(View.GONE);
774 mNotificationPeekRow.removeAllViews();
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500775
776 final int N = mNotificationData.size();
Daniel Sandlera8e5b062010-12-01 13:53:08 -0500777 if (mNotificationPeekIndex >= 0 && mNotificationPeekIndex < N) {
Jim Miller5fda69c2011-02-16 15:17:11 -0800778 NotificationData.Entry entry =
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500779 mNotificationDNDMode
780 ? mNotificationDNDDummyEntry
781 : mNotificationData.get(N-1-mNotificationPeekIndex);
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400782 entry.icon.setBackgroundColor(0);
783 }
Daniel Sandlera8e5b062010-12-01 13:53:08 -0500784
785 mNotificationPeekIndex = -1;
786 mNotificationPeekKey = null;
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -0400787 break;
Daniel Sandler9120d552010-07-23 09:11:14 -0400788 case MSG_OPEN_NOTIFICATION_PANEL:
789 if (DEBUG) Slog.d(TAG, "opening notifications panel");
Joe Onorato7c270fa2010-12-08 17:31:42 -0800790 if (!mNotificationPanel.isShowing()) {
Joe Onorato7c270fa2010-12-08 17:31:42 -0800791 mNotificationPanel.show(true, true);
Daniel Sandler21eb86a2011-03-02 11:52:58 -0500792 mNotificationArea.setVisibility(View.INVISIBLE);
Joe Onorato50ec5ec2010-11-28 17:15:26 -0800793 mTicker.halt();
Joe Onorato091e1b82010-09-26 18:04:44 -0700794 }
Daniel Sandler9120d552010-07-23 09:11:14 -0400795 break;
796 case MSG_CLOSE_NOTIFICATION_PANEL:
797 if (DEBUG) Slog.d(TAG, "closing notifications panel");
Joe Onorato7c270fa2010-12-08 17:31:42 -0800798 if (mNotificationPanel.isShowing()) {
799 mNotificationPanel.show(false, true);
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500800 mNotificationArea.setVisibility(View.VISIBLE);
Joe Onorato091e1b82010-09-26 18:04:44 -0700801 }
Daniel Sandler9120d552010-07-23 09:11:14 -0400802 break;
satok82beadf2010-12-27 19:03:06 +0900803 case MSG_OPEN_INPUT_METHODS_PANEL:
804 if (DEBUG) Slog.d(TAG, "opening input methods panel");
Tadashi G. Takaokae385f0c2011-02-01 02:57:44 +0900805 if (mInputMethodsPanel != null) mInputMethodsPanel.openPanel();
satok82beadf2010-12-27 19:03:06 +0900806 break;
807 case MSG_CLOSE_INPUT_METHODS_PANEL:
808 if (DEBUG) Slog.d(TAG, "closing input methods panel");
Tadashi G. Takaokae385f0c2011-02-01 02:57:44 +0900809 if (mInputMethodsPanel != null) mInputMethodsPanel.closePanel(false);
satok82beadf2010-12-27 19:03:06 +0900810 break;
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400811 case MSG_OPEN_COMPAT_MODE_PANEL:
812 if (DEBUG) Slog.d(TAG, "opening compat panel");
813 if (mCompatModePanel != null) mCompatModePanel.openPanel();
814 break;
815 case MSG_CLOSE_COMPAT_MODE_PANEL:
816 if (DEBUG) Slog.d(TAG, "closing compat panel");
817 if (mCompatModePanel != null) mCompatModePanel.closePanel();
818 break;
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500819 case MSG_SHOW_CHROME:
Daniel Sandlere03d1bc2010-11-17 21:36:40 -0500820 if (DEBUG) Slog.d(TAG, "hiding shadows (lights on)");
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500821 mBarContents.setVisibility(View.VISIBLE);
822 mShadow.setVisibility(View.GONE);
Daniel Sandler60ee2562011-07-22 12:34:33 -0400823 mSystemUiVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
824 notifyUiVisibilityChanged();
Daniel Sandler06e66302010-11-05 15:00:06 -0400825 break;
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500826 case MSG_HIDE_CHROME:
Daniel Sandlere03d1bc2010-11-17 21:36:40 -0500827 if (DEBUG) Slog.d(TAG, "showing shadows (lights out)");
Daniel Sandler11cf1782012-09-27 14:03:08 -0400828 animateCollapsePanels();
Mike Lockwood066c8912011-08-24 10:17:18 -0400829 visibilityChanged(false);
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500830 mBarContents.setVisibility(View.GONE);
831 mShadow.setVisibility(View.VISIBLE);
Daniel Sandler60ee2562011-07-22 12:34:33 -0400832 mSystemUiVisibility |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
833 notifyUiVisibilityChanged();
Daniel Sandlere03d1bc2010-11-17 21:36:40 -0500834 break;
Daniel Sandler2ed08d22011-01-30 16:07:28 -0500835 case MSG_STOP_TICKER:
836 mTicker.halt();
837 break;
Daniel Sandler9120d552010-07-23 09:11:14 -0400838 }
839 }
840 }
Daniel Sandler271ea122010-10-22 14:06:10 -0400841
Joe Onorato808182d2010-07-09 18:52:06 -0400842 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
Daniel Sandler1e3ed8f2010-08-13 10:12:48 -0400843 if (DEBUG) Slog.d(TAG, "addIcon(" + slot + ") -> " + icon);
Joe Onorato808182d2010-07-09 18:52:06 -0400844 }
845
846 public void updateIcon(String slot, int index, int viewIndex,
847 StatusBarIcon old, StatusBarIcon icon) {
Daniel Sandler1e3ed8f2010-08-13 10:12:48 -0400848 if (DEBUG) Slog.d(TAG, "updateIcon(" + slot + ") -> " + icon);
Joe Onorato808182d2010-07-09 18:52:06 -0400849 }
850
851 public void removeIcon(String slot, int index, int viewIndex) {
Daniel Sandler1e3ed8f2010-08-13 10:12:48 -0400852 if (DEBUG) Slog.d(TAG, "removeIcon(" + slot + ")");
Joe Onorato808182d2010-07-09 18:52:06 -0400853 }
854
855 public void addNotification(IBinder key, StatusBarNotification notification) {
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400856 if (DEBUG) Slog.d(TAG, "addNotification(" + key + " -> " + notification + ")");
857 addNotificationViews(key, notification);
Daniel Sandlerfb970e92010-08-20 10:57:17 -0400858
Joe Onorato50ec5ec2010-11-28 17:15:26 -0800859 final boolean immersive = isImmersive();
Joe Onoratocf2b1992010-11-16 21:36:42 -0800860 if (false && immersive) {
Daniel Sandlerfb970e92010-08-20 10:57:17 -0400861 // TODO: immersive mode popups for tablet
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -0400862 } else if (notification.getNotification().fullScreenIntent != null) {
Daniel Sandlerfb970e92010-08-20 10:57:17 -0400863 // not immersive & a full-screen alert should be shown
Joe Onoratof68b5002011-01-16 17:00:34 -0800864 Slog.w(TAG, "Notification has fullScreenIntent and activity is not immersive;"
Daniel Sandlerfb970e92010-08-20 10:57:17 -0400865 + " sending fullScreenIntent");
866 try {
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -0400867 notification.getNotification().fullScreenIntent.send();
Daniel Sandlerfb970e92010-08-20 10:57:17 -0400868 } catch (PendingIntent.CanceledException e) {
869 }
870 } else {
Joe Onoratoeeed9942011-01-04 17:13:53 -0800871 tick(key, notification, true);
Daniel Sandlerfb970e92010-08-20 10:57:17 -0400872 }
Joe Onorato5dd11692010-09-27 15:34:04 -0700873
874 setAreThereNotifications();
Joe Onorato808182d2010-07-09 18:52:06 -0400875 }
876
Joe Onorato808182d2010-07-09 18:52:06 -0400877 public void removeNotification(IBinder key) {
Daniel Sandler3a2fded2011-02-23 11:19:59 -0500878 if (DEBUG) Slog.d(TAG, "removeNotification(" + key + ")");
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400879 removeNotificationViews(key);
Joe Onorato50ec5ec2010-11-28 17:15:26 -0800880 mTicker.remove(key);
Joe Onorato5dd11692010-09-27 15:34:04 -0700881 setAreThereNotifications();
Joe Onorato808182d2010-07-09 18:52:06 -0400882 }
883
Daniel Sandler3e8f5a22010-12-03 14:52:10 -0500884 public void showClock(boolean show) {
885 View clock = mBarContents.findViewById(R.id.clock);
886 View network_text = mBarContents.findViewById(R.id.network_text);
887 if (clock != null) {
888 clock.setVisibility(show ? View.VISIBLE : View.GONE);
889 }
890 if (network_text != null) {
891 network_text.setVisibility((!show) ? View.VISIBLE : View.GONE);
892 }
893 }
894
Joe Onorato808182d2010-07-09 18:52:06 -0400895 public void disable(int state) {
Joe Onorato091e1b82010-09-26 18:04:44 -0700896 int old = mDisabled;
897 int diff = state ^ old;
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400898 mDisabled = state;
899
Joe Onorato091e1b82010-09-26 18:04:44 -0700900 // act accordingly
Daniel Sandler3e8f5a22010-12-03 14:52:10 -0500901 if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) {
902 boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0;
Joe Onoratof68b5002011-01-16 17:00:34 -0800903 Slog.i(TAG, "DISABLE_CLOCK: " + (show ? "no" : "yes"));
Daniel Sandler3e8f5a22010-12-03 14:52:10 -0500904 showClock(show);
905 }
Daniel Sandler6f6cf3c2010-12-16 12:54:03 -0500906 if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) {
907 boolean show = (state & StatusBarManager.DISABLE_SYSTEM_INFO) == 0;
Joe Onoratof68b5002011-01-16 17:00:34 -0800908 Slog.i(TAG, "DISABLE_SYSTEM_INFO: " + (show ? "no" : "yes"));
Daniel Sandler6f6cf3c2010-12-16 12:54:03 -0500909 mNotificationTrigger.setVisibility(show ? View.VISIBLE : View.GONE);
910 }
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400911 if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
912 if ((state & StatusBarManager.DISABLE_EXPAND) != 0) {
Joe Onoratof68b5002011-01-16 17:00:34 -0800913 Slog.i(TAG, "DISABLE_EXPAND: yes");
Daniel Sandler11cf1782012-09-27 14:03:08 -0400914 animateCollapsePanels();
Mike Lockwood066c8912011-08-24 10:17:18 -0400915 visibilityChanged(false);
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400916 }
917 }
918 if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500919 mNotificationDNDMode = Prefs.read(mContext)
920 .getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT);
Daniel Sandler282ff9a2011-02-23 10:36:49 -0500921
922 if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
923 Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: yes" + (mNotificationDNDMode?" (DND)":""));
924 mTicker.halt();
925 } else {
926 Slog.i(TAG, "DISABLE_NOTIFICATION_ICONS: no" + (mNotificationDNDMode?" (DND)":""));
927 }
928
929 // refresh icons to show either notifications or the DND message
Daniel Sandlerce6ff642011-02-18 12:51:08 -0500930 reloadAllNotificationIcons();
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400931 } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
Joe Onorato091e1b82010-09-26 18:04:44 -0700932 if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
Joe Onoratoef1e7762010-09-17 18:38:38 -0400933 mTicker.halt();
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400934 }
935 }
Jim Miller354619c2012-04-27 17:33:44 -0700936 if ((diff & (StatusBarManager.DISABLE_RECENT
937 | StatusBarManager.DISABLE_BACK
Daniel Sandlerdba93562011-10-06 16:39:58 -0400938 | StatusBarManager.DISABLE_HOME)) != 0) {
939 setNavigationVisibility(state);
Michael Jurkab7f43272011-10-27 15:06:38 -0700940
941 if ((state & StatusBarManager.DISABLE_RECENT) != 0) {
942 // close recents if it's visible
943 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
944 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
945 }
Joe Onorato091e1b82010-09-26 18:04:44 -0700946 }
Mike Lockwoode3646dd2011-09-01 12:46:28 -0400947 }
948
949 private void setNavigationVisibility(int visibility) {
Daniel Sandlerdba93562011-10-06 16:39:58 -0400950 boolean disableHome = ((visibility & StatusBarManager.DISABLE_HOME) != 0);
951 boolean disableRecent = ((visibility & StatusBarManager.DISABLE_RECENT) != 0);
Mike Lockwoode3646dd2011-09-01 12:46:28 -0400952 boolean disableBack = ((visibility & StatusBarManager.DISABLE_BACK) != 0);
953
Daniel Sandlerdba93562011-10-06 16:39:58 -0400954 mBackButton.setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE);
955 mHomeButton.setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE);
956 mRecentButton.setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE);
Mike Lockwoode3646dd2011-09-01 12:46:28 -0400957
Daniel Sandlerdba93562011-10-06 16:39:58 -0400958 mInputMethodSwitchButton.setScreenLocked(
959 (visibility & StatusBarManager.DISABLE_SYSTEM_INFO) != 0);
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400960 }
961
Joe Onoratoef1e7762010-09-17 18:38:38 -0400962 private boolean hasTicker(Notification n) {
Joe Onorato46439ce2010-11-19 13:56:21 -0800963 return n.tickerView != null || !TextUtils.isEmpty(n.tickerText);
Joe Onoratoef1e7762010-09-17 18:38:38 -0400964 }
965
Chris Wren0c8275b2012-05-08 13:36:48 -0400966 @Override
967 protected void tick(IBinder key, StatusBarNotification n, boolean firstTime) {
Joe Onorato55d2d762010-09-26 13:02:01 -0700968 // Don't show the ticker when the windowshade is open.
Joe Onorato7c270fa2010-12-08 17:31:42 -0800969 if (mNotificationPanel.isShowing()) {
Joe Onorato55d2d762010-09-26 13:02:01 -0700970 return;
971 }
Joe Onoratoeeed9942011-01-04 17:13:53 -0800972 // If they asked for FLAG_ONLY_ALERT_ONCE, then only show this notification
973 // if it's a new notification.
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -0400974 if (!firstTime && (n.getNotification().flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0) {
Joe Onoratoeeed9942011-01-04 17:13:53 -0800975 return;
976 }
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400977 // Show the ticker if one is requested. Also don't do this
978 // until status bar window is attached to the window manager,
979 // because... well, what's the point otherwise? And trying to
980 // run a ticker without being attached will crash!
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -0400981 if (hasTicker(n.getNotification()) && mStatusBarView.getWindowToken() != null) {
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400982 if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS
983 | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) {
Joe Onorato50ec5ec2010-11-28 17:15:26 -0800984 mTicker.add(key, n);
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400985 mFeedbackIconArea.setVisibility(View.GONE);
Daniel Sandlerdfa08db2010-08-05 16:18:42 -0400986 }
987 }
988 }
989
Daniel Sandlerb8027d82010-12-16 19:35:54 -0500990 // called by TabletTicker when it's done with all queued ticks
991 public void doneTicking() {
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400992 mFeedbackIconArea.setVisibility(View.VISIBLE);
Daniel Sandlerb8027d82010-12-16 19:35:54 -0500993 }
994
Daniel Sandler11cf1782012-09-27 14:03:08 -0400995 public void animateExpandNotificationsPanel() {
Joe Onoratob62ac122010-09-20 16:16:32 -0400996 mHandler.removeMessages(MSG_OPEN_NOTIFICATION_PANEL);
997 mHandler.sendEmptyMessage(MSG_OPEN_NOTIFICATION_PANEL);
Joe Onorato808182d2010-07-09 18:52:06 -0400998 }
999
Daniel Sandler11cf1782012-09-27 14:03:08 -04001000 public void animateCollapsePanels() {
1001 animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
Michael Jurkab7f43272011-10-27 15:06:38 -07001002 }
1003
Daniel Sandler11cf1782012-09-27 14:03:08 -04001004 public void animateCollapsePanels(int flags) {
Jim Miller9a720f52012-05-30 03:19:43 -07001005 if ((flags & CommandQueue.FLAG_EXCLUDE_NOTIFICATION_PANEL) == 0) {
1006 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PANEL);
1007 mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL);
1008 }
1009 if ((flags & CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL) == 0) {
Michael Jurkab7f43272011-10-27 15:06:38 -07001010 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
1011 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
1012 }
Jim Miller9a720f52012-05-30 03:19:43 -07001013 if ((flags & CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL) == 0) {
1014 mHandler.removeMessages(MSG_CLOSE_SEARCH_PANEL);
1015 mHandler.sendEmptyMessage(MSG_CLOSE_SEARCH_PANEL);
1016 }
1017 if ((flags & CommandQueue.FLAG_EXCLUDE_INPUT_METHODS_PANEL) == 0) {
1018 mHandler.removeMessages(MSG_CLOSE_INPUT_METHODS_PANEL);
1019 mHandler.sendEmptyMessage(MSG_CLOSE_INPUT_METHODS_PANEL);
1020 }
1021 if ((flags & CommandQueue.FLAG_EXCLUDE_COMPAT_MODE_PANEL) == 0) {
1022 mHandler.removeMessages(MSG_CLOSE_COMPAT_MODE_PANEL);
1023 mHandler.sendEmptyMessage(MSG_CLOSE_COMPAT_MODE_PANEL);
1024 }
1025
Daniel Sandler9120d552010-07-23 09:11:14 -04001026 }
1027
Svetoslav Ganove20a1772012-09-25 16:07:46 -07001028 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -04001029 public void animateExpandSettingsPanel() {
Svetoslav Ganove20a1772012-09-25 16:07:46 -07001030 // TODO: Implement when TabletStatusBar begins to be used.
1031 }
1032
Daniel Sandler328310c2011-09-23 15:56:52 -04001033 @Override // CommandQueue
1034 public void setNavigationIconHints(int hints) {
1035 if (hints == mNavigationIconHints) return;
1036
1037 if (DEBUG) {
1038 android.widget.Toast.makeText(mContext,
1039 "Navigation icon hints = " + hints,
1040 500).show();
1041 }
1042
1043 mNavigationIconHints = hints;
1044
1045 mBackButton.setAlpha(
1046 (0 != (hints & StatusBarManager.NAVIGATION_HINT_BACK_NOP)) ? 0.5f : 1.0f);
1047 mHomeButton.setAlpha(
1048 (0 != (hints & StatusBarManager.NAVIGATION_HINT_HOME_NOP)) ? 0.5f : 1.0f);
1049 mRecentButton.setAlpha(
1050 (0 != (hints & StatusBarManager.NAVIGATION_HINT_RECENT_NOP)) ? 0.5f : 1.0f);
1051
1052 mBackButton.setImageResource(
1053 (0 != (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT))
1054 ? R.drawable.ic_sysbar_back_ime
1055 : R.drawable.ic_sysbar_back);
1056 }
1057
Daniel Sandler60ee2562011-07-22 12:34:33 -04001058 private void notifyUiVisibilityChanged() {
1059 try {
Jeff Brown98365d72012-08-19 20:30:52 -07001060 mWindowManagerService.statusBarVisibilityChanged(mSystemUiVisibility);
Daniel Sandler60ee2562011-07-22 12:34:33 -04001061 } catch (RemoteException ex) {
1062 }
1063 }
1064
1065 @Override // CommandQueue
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07001066 public void setSystemUiVisibility(int vis, int mask) {
1067 final int oldVal = mSystemUiVisibility;
1068 final int newVal = (oldVal&~mask) | (vis&mask);
1069 final int diff = newVal ^ oldVal;
Daniel Sandler60ee2562011-07-22 12:34:33 -04001070
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07001071 if (diff != 0) {
1072 mSystemUiVisibility = newVal;
1073
1074 if (0 != (diff & View.SYSTEM_UI_FLAG_LOW_PROFILE)) {
1075 mHandler.removeMessages(MSG_HIDE_CHROME);
1076 mHandler.removeMessages(MSG_SHOW_CHROME);
Jim Millera073e572012-05-23 17:03:27 -07001077 mHandler.sendEmptyMessage(0 == (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE)
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07001078 ? MSG_SHOW_CHROME : MSG_HIDE_CHROME);
1079 }
Daniel Sandler60ee2562011-07-22 12:34:33 -04001080
1081 notifyUiVisibilityChanged();
1082 }
1083 }
1084
Joe Onorato93056472010-09-10 10:30:46 -04001085 public void setLightsOn(boolean on) {
Daniel Sandler59485d742010-12-02 00:11:33 -05001086 // Policy note: if the frontmost activity needs the menu key, we assume it is a legacy app
1087 // that can't handle lights-out mode.
Daniel Sandler0ad460b2010-12-14 12:14:53 -05001088 if (mMenuButton.getVisibility() == View.VISIBLE) {
Daniel Sandler59485d742010-12-02 00:11:33 -05001089 on = true;
1090 }
Daniel Sandler60ee2562011-07-22 12:34:33 -04001091
1092 Slog.v(TAG, "setLightsOn(" + on + ")");
1093 if (on) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07001094 setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE);
Daniel Sandler60ee2562011-07-22 12:34:33 -04001095 } else {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07001096 setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE, View.SYSTEM_UI_FLAG_LOW_PROFILE);
Daniel Sandler60ee2562011-07-22 12:34:33 -04001097 }
Joe Onorato93056472010-09-10 10:30:46 -04001098 }
1099
Daniel Sandler5c8da942011-06-28 00:29:04 -04001100 public void topAppWindowChanged(boolean showMenu) {
Daniel Sandlere02d8082010-10-08 15:13:22 -04001101 if (DEBUG) {
Daniel Sandler5c8da942011-06-28 00:29:04 -04001102 Slog.d(TAG, (showMenu?"showing":"hiding") + " the MENU button");
Daniel Sandlere02d8082010-10-08 15:13:22 -04001103 }
Daniel Sandler5c8da942011-06-28 00:29:04 -04001104 mMenuButton.setVisibility(showMenu ? View.VISIBLE : View.GONE);
Daniel Sandler59485d742010-12-02 00:11:33 -05001105
1106 // See above re: lights-out policy for legacy apps.
Daniel Sandler5c8da942011-06-28 00:29:04 -04001107 if (showMenu) setLightsOn(true);
Daniel Sandler45c04012011-06-07 15:29:07 -04001108
Daniel Sandler3b0543a2011-06-14 11:30:28 -04001109 mCompatModeButton.refresh();
Daniel Sandler552b1f02011-06-15 01:03:02 -04001110 if (mCompatModeButton.getVisibility() == View.VISIBLE) {
Daniel Sandler319d1e32011-08-05 11:34:06 -04001111 if (DEBUG_COMPAT_HELP
1112 || ! Prefs.read(mContext).getBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, false)) {
Daniel Sandler552b1f02011-06-15 01:03:02 -04001113 showCompatibilityHelp();
Daniel Sandler319d1e32011-08-05 11:34:06 -04001114 }
Dianne Hackborned31bbf2011-06-15 11:16:06 -07001115 } else {
1116 hideCompatibilityHelp();
1117 mCompatModePanel.closePanel();
Daniel Sandler552b1f02011-06-15 01:03:02 -04001118 }
1119 }
1120
1121 private void showCompatibilityHelp() {
Dianne Hackborned31bbf2011-06-15 11:16:06 -07001122 if (mCompatibilityHelpDialog != null) {
1123 return;
1124 }
Jim Millere898ac52012-04-06 17:10:57 -07001125
Dianne Hackborned31bbf2011-06-15 11:16:06 -07001126 mCompatibilityHelpDialog = View.inflate(mContext, R.layout.compat_mode_help, null);
1127 View button = mCompatibilityHelpDialog.findViewById(R.id.button);
Daniel Sandler552b1f02011-06-15 01:03:02 -04001128
1129 button.setOnClickListener(new View.OnClickListener() {
1130 @Override
1131 public void onClick(View v) {
Dianne Hackborned31bbf2011-06-15 11:16:06 -07001132 hideCompatibilityHelp();
1133 SharedPreferences.Editor editor = Prefs.edit(mContext);
1134 editor.putBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, true);
1135 editor.apply();
Daniel Sandler552b1f02011-06-15 01:03:02 -04001136 }
1137 });
1138
Daniel Sandlerf1dd26b2011-06-20 14:44:35 -04001139 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
Daniel Sandler552b1f02011-06-15 01:03:02 -04001140 ViewGroup.LayoutParams.MATCH_PARENT,
1141 ViewGroup.LayoutParams.MATCH_PARENT,
1142 WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG,
1143 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
1144 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
1145 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
1146 PixelFormat.TRANSLUCENT);
1147 lp.setTitle("CompatibilityModeDialog");
1148 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
1149 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
1150 lp.windowAnimations = com.android.internal.R.style.Animation_ZoomButtons; // simple fade
1151
Jeff Brown98365d72012-08-19 20:30:52 -07001152 mWindowManager.addView(mCompatibilityHelpDialog, lp);
Daniel Sandlere02d8082010-10-08 15:13:22 -04001153 }
1154
Dianne Hackborned31bbf2011-06-15 11:16:06 -07001155 private void hideCompatibilityHelp() {
1156 if (mCompatibilityHelpDialog != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001157 mWindowManager.removeView(mCompatibilityHelpDialog);
Dianne Hackborned31bbf2011-06-15 11:16:06 -07001158 mCompatibilityHelpDialog = null;
1159 }
1160 }
Jim Millere898ac52012-04-06 17:10:57 -07001161
Joe Onorato857fd9b2011-01-27 15:08:35 -08001162 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
1163 mInputMethodSwitchButton.setImeWindowStatus(token,
1164 (vis & InputMethodService.IME_ACTIVE) != 0);
satok51133822011-01-25 15:01:48 +09001165 updateNotificationIcons();
satok913f42d2011-01-17 16:58:10 +09001166 mInputMethodsPanel.setImeToken(token);
Daniel Sandler328310c2011-09-23 15:56:52 -04001167
1168 boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS)
1169 || ((vis & InputMethodService.IME_VISIBLE) != 0);
1170 mAltBackButtonEnabledForIme = altBack;
1171
1172 mCommandQueue.setNavigationIconHints(
1173 altBack ? (mNavigationIconHints | StatusBarManager.NAVIGATION_HINT_BACK_ALT)
1174 : (mNavigationIconHints & ~StatusBarManager.NAVIGATION_HINT_BACK_ALT));
1175
Daniel Sandler10163c62010-12-08 11:51:05 -05001176 if (FAKE_SPACE_BAR) {
Joe Onorato857fd9b2011-01-27 15:08:35 -08001177 mFakeSpaceBar.setVisibility(((vis & InputMethodService.IME_VISIBLE) != 0)
1178 ? View.VISIBLE : View.GONE);
Daniel Sandler10163c62010-12-08 11:51:05 -05001179 }
satok06487a52010-10-29 11:37:18 +09001180 }
1181
Jeff Brown2992ea72011-01-28 22:04:14 -08001182 @Override
1183 public void setHardKeyboardStatus(boolean available, boolean enabled) {
1184 if (DEBUG) {
1185 Slog.d(TAG, "Set hard keyboard status: available=" + available
1186 + ", enabled=" + enabled);
1187 }
1188 mInputMethodSwitchButton.setHardKeyboardStatus(available);
1189 updateNotificationIcons();
1190 mInputMethodsPanel.setHardKeyboardStatus(available, enabled);
1191 }
1192
1193 @Override
1194 public void onHardKeyboardEnabledChange(boolean enabled) {
1195 try {
1196 mBarService.setHardKeyboardEnabled(enabled);
1197 } catch (RemoteException ex) {
1198 }
1199 }
1200
Joe Onorato50ec5ec2010-11-28 17:15:26 -08001201 private boolean isImmersive() {
1202 try {
1203 return ActivityManagerNative.getDefault().isTopActivityImmersive();
1204 //Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive"));
1205 } catch (RemoteException ex) {
1206 // the end is nigh
1207 return false;
1208 }
1209 }
Jim Miller85babff2011-01-11 14:26:03 -08001210
Chris Wren0c8275b2012-05-08 13:36:48 -04001211 @Override
1212 protected void setAreThereNotifications() {
Daniel Sandler06a0d4b2011-08-05 00:19:21 -04001213 if (mNotificationPanel != null) {
John Spurlock36231282012-06-23 17:11:27 -04001214 mNotificationPanel.setClearable(isDeviceProvisioned() && mNotificationData.hasClearableItems());
Daniel Sandler06a0d4b2011-08-05 00:19:21 -04001215 }
Joe Onorato5dd11692010-09-27 15:34:04 -07001216 }
1217
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001218 private View.OnClickListener mOnClickListener = new View.OnClickListener() {
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001219 public void onClick(View v) {
Daniel Sandler130453c2011-08-18 09:41:01 -04001220 if (v == mRecentButton) {
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001221 onClickRecentButton();
satok82beadf2010-12-27 19:03:06 +09001222 } else if (v == mInputMethodSwitchButton) {
1223 onClickInputMethodSwitchButton();
Daniel Sandler3b0543a2011-06-14 11:30:28 -04001224 } else if (v == mCompatModeButton) {
1225 onClickCompatModeButton();
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001226 }
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001227 }
1228 };
1229
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001230 public void onClickRecentButton() {
Daniel Sandlerb6d3dc62010-11-17 16:51:26 -05001231 if (DEBUG) Slog.d(TAG, "clicked recent apps; disabled=" + mDisabled);
Michael Jurka3b1fc472011-06-13 10:54:40 -07001232 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) {
Michael Jurkacb2522c2012-04-13 09:32:47 -07001233 toggleRecentApps();
Jim Miller44c66fe2010-10-20 18:32:52 -07001234 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001235 }
Joe Onorato55d2d762010-09-26 13:02:01 -07001236
satok82beadf2010-12-27 19:03:06 +09001237 public void onClickInputMethodSwitchButton() {
1238 if (DEBUG) Slog.d(TAG, "clicked input methods panel; disabled=" + mDisabled);
1239 int msg = (mInputMethodsPanel.getVisibility() == View.GONE) ?
1240 MSG_OPEN_INPUT_METHODS_PANEL : MSG_CLOSE_INPUT_METHODS_PANEL;
1241 mHandler.removeMessages(msg);
1242 mHandler.sendEmptyMessage(msg);
1243 }
1244
Daniel Sandler3b0543a2011-06-14 11:30:28 -04001245 public void onClickCompatModeButton() {
1246 int msg = (mCompatModePanel.getVisibility() == View.GONE) ?
1247 MSG_OPEN_COMPAT_MODE_PANEL : MSG_CLOSE_COMPAT_MODE_PANEL;
1248 mHandler.removeMessages(msg);
1249 mHandler.sendEmptyMessage(msg);
1250 }
1251
Daniel Sandler56a6d882011-02-23 16:40:33 -05001252 private class NotificationTriggerTouchListener implements View.OnTouchListener {
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001253 VelocityTracker mVT;
Daniel Sandler56a6d882011-02-23 16:40:33 -05001254 float mInitialTouchX, mInitialTouchY;
1255 int mTouchSlop;
1256
1257 public NotificationTriggerTouchListener() {
1258 mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
1259 }
1260
Daniel Sandler298a2a82011-08-11 16:13:22 -04001261 private Runnable mHiliteOnR = new Runnable() { public void run() {
1262 mNotificationArea.setBackgroundResource(
1263 com.android.internal.R.drawable.list_selector_pressed_holo_dark);
1264 }};
1265 public void hilite(final boolean on) {
1266 if (on) {
1267 mNotificationArea.postDelayed(mHiliteOnR, 100);
1268 } else {
1269 mNotificationArea.removeCallbacks(mHiliteOnR);
Michael Jurkaa600fd92012-06-25 15:57:05 -07001270 mNotificationArea.setBackground(null);
Daniel Sandler298a2a82011-08-11 16:13:22 -04001271 }
1272 }
1273
Daniel Sandler56a6d882011-02-23 16:40:33 -05001274 public boolean onTouch(View v, MotionEvent event) {
1275// Slog.d(TAG, String.format("touch: (%.1f, %.1f) initial: (%.1f, %.1f)",
1276// event.getX(),
1277// event.getY(),
1278// mInitialTouchX,
1279// mInitialTouchY));
Daniel Sandler130453c2011-08-18 09:41:01 -04001280
1281 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
1282 return true;
1283 }
1284
Daniel Sandler56a6d882011-02-23 16:40:33 -05001285 final int action = event.getAction();
1286 switch (action) {
1287 case MotionEvent.ACTION_DOWN:
1288 mVT = VelocityTracker.obtain();
1289 mInitialTouchX = event.getX();
1290 mInitialTouchY = event.getY();
Daniel Sandler298a2a82011-08-11 16:13:22 -04001291 hilite(true);
Daniel Sandler56a6d882011-02-23 16:40:33 -05001292 // fall through
1293 case MotionEvent.ACTION_OUTSIDE:
1294 case MotionEvent.ACTION_MOVE:
1295 // check for fling
1296 if (mVT != null) {
1297 mVT.addMovement(event);
1298 mVT.computeCurrentVelocity(1000); // pixels per second
1299 // require a little more oomph once we're already in peekaboo mode
1300 if (mVT.getYVelocity() < -mNotificationFlingVelocity) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04001301 animateExpandNotificationsPanel();
Mike Lockwood066c8912011-08-24 10:17:18 -04001302 visibilityChanged(true);
Daniel Sandler298a2a82011-08-11 16:13:22 -04001303 hilite(false);
Daniel Sandler56a6d882011-02-23 16:40:33 -05001304 mVT.recycle();
1305 mVT = null;
1306 }
1307 }
1308 return true;
1309 case MotionEvent.ACTION_UP:
1310 case MotionEvent.ACTION_CANCEL:
Daniel Sandler298a2a82011-08-11 16:13:22 -04001311 hilite(false);
Daniel Sandler56a6d882011-02-23 16:40:33 -05001312 if (mVT != null) {
1313 if (action == MotionEvent.ACTION_UP
1314 // was this a sloppy tap?
Jim Miller9f0f0e02011-05-17 20:06:29 -07001315 && Math.abs(event.getX() - mInitialTouchX) < mTouchSlop
Daniel Sandler56a6d882011-02-23 16:40:33 -05001316 && Math.abs(event.getY() - mInitialTouchY) < (mTouchSlop / 3)
1317 // dragging off the bottom doesn't count
1318 && (int)event.getY() < v.getBottom()) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04001319 animateExpandNotificationsPanel();
Mike Lockwood066c8912011-08-24 10:17:18 -04001320 visibilityChanged(true);
Daniel Sandleraa051d62011-03-01 16:23:57 -05001321 v.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
1322 v.playSoundEffect(SoundEffectConstants.CLICK);
Daniel Sandler56a6d882011-02-23 16:40:33 -05001323 }
1324
1325 mVT.recycle();
1326 mVT = null;
1327 return true;
1328 }
1329 }
1330 return false;
1331 }
1332 }
1333
Daniel Sandler663f0f22011-03-04 16:45:02 -05001334 public void resetNotificationPeekFadeTimer() {
1335 if (DEBUG) {
1336 Slog.d(TAG, "setting peek fade timer for " + NOTIFICATION_PEEK_FADE_DELAY
1337 + "ms from now");
1338 }
1339 mHandler.removeMessages(MSG_CLOSE_NOTIFICATION_PEEK);
1340 mHandler.sendEmptyMessageDelayed(MSG_CLOSE_NOTIFICATION_PEEK,
1341 NOTIFICATION_PEEK_FADE_DELAY);
1342 }
1343
Daniel Sandler0ad460b2010-12-14 12:14:53 -05001344 private void reloadAllNotificationIcons() {
1345 if (mIconLayout == null) return;
1346 mIconLayout.removeAllViews();
1347 updateNotificationIcons();
1348 }
1349
Chris Wren0c8275b2012-05-08 13:36:48 -04001350 @Override
1351 protected void updateNotificationIcons() {
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001352 // XXX: need to implement a new limited linear layout class
1353 // to avoid removing & readding everything
Daniel Sandlerdfa08db2010-08-05 16:18:42 -04001354
Daniel Sandler0ad460b2010-12-14 12:14:53 -05001355 if (mIconLayout == null) return;
1356
Daniel Sandler282ff9a2011-02-23 10:36:49 -05001357 // first, populate the main notification panel
1358 loadNotificationPanel();
1359
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001360 final LinearLayout.LayoutParams params
Joe Onoratodc100302011-01-11 17:07:41 -08001361 = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight);
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001362
Daniel Sandlerce6ff642011-02-18 12:51:08 -05001363 // alternate behavior in DND mode
Daniel Sandler282ff9a2011-02-23 10:36:49 -05001364 if (mNotificationDNDMode) {
1365 if (mIconLayout.getChildCount() == 0) {
Daniel Sandler282ff9a2011-02-23 10:36:49 -05001366 final Notification dndNotification = new Notification.Builder(mContext)
1367 .setContentTitle(mContext.getText(R.string.notifications_off_title))
1368 .setContentText(mContext.getText(R.string.notifications_off_text))
1369 .setSmallIcon(R.drawable.ic_notification_dnd)
1370 .setOngoing(true)
1371 .getNotification();
Daniel Sandlerce6ff642011-02-18 12:51:08 -05001372
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001373 final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd",
1374 dndNotification);
1375 iconView.setImageResource(R.drawable.ic_notification_dnd);
1376 iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
1377 iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0);
1378
Daniel Sandler282ff9a2011-02-23 10:36:49 -05001379 mNotificationDNDDummyEntry = new NotificationData.Entry(
Jeff Sharkey6d515712012-09-20 16:06:08 -07001380 null, new StatusBarNotification("", 0, "", 0, 0, Notification.PRIORITY_MAX,
1381 dndNotification, android.os.Process.myUserHandle()), iconView);
Daniel Sandlerce6ff642011-02-18 12:51:08 -05001382
Daniel Sandler282ff9a2011-02-23 10:36:49 -05001383 mIconLayout.addView(iconView, params);
1384 }
Daniel Sandlerce6ff642011-02-18 12:51:08 -05001385
1386 return;
Daniel Sandler8e41f312011-08-03 14:05:07 -04001387 } else if (0 != (mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS)) {
1388 // if icons are disabled but we're not in DND mode, this is probably Setup and we should
1389 // just leave the area totally empty
1390 return;
Daniel Sandlerce6ff642011-02-18 12:51:08 -05001391 }
1392
1393 int N = mNotificationData.size();
Daniel Sandlerdfa08db2010-08-05 16:18:42 -04001394
1395 if (DEBUG) {
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001396 Slog.d(TAG, "refreshing icons: " + N + " notifications, mIconLayout=" + mIconLayout);
Daniel Sandlerdfa08db2010-08-05 16:18:42 -04001397 }
1398
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001399 ArrayList<View> toShow = new ArrayList<View>();
1400
Daniel Sandler3b0543a2011-06-14 11:30:28 -04001401 // Extra Special Icons
1402 // The IME switcher and compatibility mode icons take the place of notifications. You didn't
1403 // need to see all those new emails, did you?
1404 int maxNotificationIconsCount = mMaxNotificationIcons;
1405 if (mInputMethodSwitchButton.getVisibility() != View.GONE) maxNotificationIconsCount --;
1406 if (mCompatModeButton.getVisibility() != View.GONE) maxNotificationIconsCount --;
1407
John Spurlock36231282012-06-23 17:11:27 -04001408 final boolean provisioned = isDeviceProvisioned();
1409 // If the device hasn't been through Setup, we only show system notifications
Daniel Sandler58b173b2012-05-03 11:25:29 -04001410 for (int i=0; toShow.size()< maxNotificationIconsCount; i++) {
1411 if (i >= N) break;
1412 Entry ent = mNotificationData.get(N-i-1);
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -04001413 if ((provisioned && ent.notification.getScore() >= HIDE_ICONS_BELOW_SCORE)
John Spurlock36231282012-06-23 17:11:27 -04001414 || showNotificationEvenIfUnprovisioned(ent.notification)) {
Daniel Sandler58b173b2012-05-03 11:25:29 -04001415 toShow.add(ent.icon);
1416 }
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001417 }
Daniel Sandlerdfa08db2010-08-05 16:18:42 -04001418
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001419 ArrayList<View> toRemove = new ArrayList<View>();
1420 for (int i=0; i<mIconLayout.getChildCount(); i++) {
1421 View child = mIconLayout.getChildAt(i);
1422 if (!toShow.contains(child)) {
1423 toRemove.add(child);
1424 }
Daniel Sandlerdfa08db2010-08-05 16:18:42 -04001425 }
Daniel Sandler271ea122010-10-22 14:06:10 -04001426
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001427 for (View remove : toRemove) {
1428 mIconLayout.removeView(remove);
1429 }
1430
1431 for (int i=0; i<toShow.size(); i++) {
1432 View v = toShow.get(i);
Daniel Sandler0ad460b2010-12-14 12:14:53 -05001433 v.setPadding(mIconHPadding, 0, mIconHPadding, 0);
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001434 if (v.getParent() == null) {
Daniel Sandler0ad460b2010-12-14 12:14:53 -05001435 mIconLayout.addView(v, i, params);
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001436 }
1437 }
Daniel Sandler0f0b11c2010-08-04 15:54:58 -04001438 }
1439
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001440 private void loadNotificationPanel() {
Daniel Sandlerce6ff642011-02-18 12:51:08 -05001441 int N = mNotificationData.size();
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001442
1443 ArrayList<View> toShow = new ArrayList<View>();
1444
John Spurlock36231282012-06-23 17:11:27 -04001445 final boolean provisioned = isDeviceProvisioned();
1446 // If the device hasn't been through Setup, we only show system notifications
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001447 for (int i=0; i<N; i++) {
John Spurlock36231282012-06-23 17:11:27 -04001448 Entry ent = mNotificationData.get(N-i-1);
1449 if (provisioned || showNotificationEvenIfUnprovisioned(ent.notification)) {
1450 toShow.add(ent.row);
1451 }
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001452 }
1453
1454 ArrayList<View> toRemove = new ArrayList<View>();
1455 for (int i=0; i<mPile.getChildCount(); i++) {
1456 View child = mPile.getChildAt(i);
1457 if (!toShow.contains(child)) {
1458 toRemove.add(child);
1459 }
1460 }
1461
1462 for (View remove : toRemove) {
1463 mPile.removeView(remove);
1464 }
1465
1466 for (int i=0; i<toShow.size(); i++) {
1467 View v = toShow.get(i);
1468 if (v.getParent() == null) {
Daniel Sandler58b173b2012-05-03 11:25:29 -04001469 // the notification panel has the most important things at the bottom
John Spurlock36231282012-06-23 17:11:27 -04001470 mPile.addView(v, Math.min(toShow.size()-1-i, mPile.getChildCount()));
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001471 }
1472 }
Daniel Sandler40c15452011-01-22 01:26:22 -05001473
John Spurlock36231282012-06-23 17:11:27 -04001474 mNotificationPanel.setNotificationCount(toShow.size());
1475 mNotificationPanel.setSettingsEnabled(isDeviceProvisioned());
Daniel Sandlerb0cc50d2010-10-26 16:55:56 -04001476 }
1477
Daniel Sandler6a858c32012-03-12 14:38:58 -04001478 @Override
1479 protected void workAroundBadLayerDrawableOpacity(View v) {
Adam Powell29ea5252011-11-15 18:59:36 -08001480 Drawable bgd = v.getBackground();
1481 if (!(bgd instanceof LayerDrawable)) return;
1482
1483 LayerDrawable d = (LayerDrawable) bgd;
Michael Jurkaa600fd92012-06-25 15:57:05 -07001484 v.setBackground(null);
Joe Onorato4daaeaf2010-11-17 20:43:12 -08001485 d.setOpacity(PixelFormat.TRANSLUCENT);
Michael Jurkaa600fd92012-06-25 15:57:05 -07001486 v.setBackground(d);
Joe Onorato4daaeaf2010-11-17 20:43:12 -08001487 }
1488
Daniel Sandler06a0d4b2011-08-05 00:19:21 -04001489 public void clearAll() {
1490 try {
1491 mBarService.onClearAllNotifications();
1492 } catch (RemoteException ex) {
1493 // system process is dead if we're here.
1494 }
Daniel Sandler11cf1782012-09-27 14:03:08 -04001495 animateCollapsePanels();
Mike Lockwood066c8912011-08-24 10:17:18 -04001496 visibilityChanged(false);
Daniel Sandler06a0d4b2011-08-05 00:19:21 -04001497 }
1498
Michael Jurkab7f43272011-10-27 15:06:38 -07001499 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1500 public void onReceive(Context context, Intent intent) {
1501 String action = intent.getAction();
1502 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1503 || Intent.ACTION_SCREEN_OFF.equals(action)) {
Jim Miller9a720f52012-05-30 03:19:43 -07001504 int flags = CommandQueue.FLAG_EXCLUDE_NONE;
Michael Jurkab7f43272011-10-27 15:06:38 -07001505 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
1506 String reason = intent.getStringExtra("reason");
Jim Miller9a720f52012-05-30 03:19:43 -07001507 if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
1508 flags |= CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL;
Michael Jurkab7f43272011-10-27 15:06:38 -07001509 }
1510 }
Daniel Sandler11cf1782012-09-27 14:03:08 -04001511 animateCollapsePanels(flags);
Michael Jurkab7f43272011-10-27 15:06:38 -07001512 }
1513 }
1514 };
1515
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001516 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1517 pw.print("mDisabled=0x");
1518 pw.println(Integer.toHexString(mDisabled));
Joe Onorato933464d2011-01-05 15:53:36 -08001519 pw.println("mNetworkController:");
1520 mNetworkController.dump(fd, pw, args);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001521 }
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -05001522
Chris Wren0c8275b2012-05-08 13:36:48 -04001523 @Override
1524 protected boolean isTopNotification(ViewGroup parent, NotificationData.Entry entry) {
Daniel Sandler15986c62012-06-28 13:38:28 -04001525 if (parent == null || entry == null) return false;
Chris Wren0c8275b2012-05-08 13:36:48 -04001526 return parent.indexOfChild(entry.row) == parent.getChildCount()-1;
1527 }
1528
1529 @Override
1530 protected void haltTicker() {
1531 mTicker.halt();
1532 }
1533
1534 @Override
1535 protected void updateExpandedViewPos(int expandedPosition) {
1536 }
Jim Miller670d9dd2012-05-12 13:28:26 -07001537
1538 @Override
Jim Millerb4238e02012-05-14 15:26:20 -07001539 protected boolean shouldDisableNavbarGestures() {
1540 return mNotificationPanel.getVisibility() == View.VISIBLE
1541 || (mDisabled & StatusBarManager.DISABLE_HOME) != 0;
Jim Miller670d9dd2012-05-12 13:28:26 -07001542 }
Joe Onorato808182d2010-07-09 18:52:06 -04001543}
Daniel Sandlerd39e3882010-08-31 14:16:13 -04001544
1545