blob: 6eadd2b741ea11ae79250db4ae433d8f91669feb [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
Joe Onoratofd52b182010-11-10 18:00:52 -080017package com.android.systemui.statusbar.phone;
Joe Onorato808182d2010-07-09 18:52:06 -040018
Daniel Sandlerd7e96862012-04-26 01:10:29 -040019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
21import android.animation.AnimatorSet;
Daniel Sandler0761e4c2011-08-11 00:19:49 -040022import android.animation.ObjectAnimator;
Daniel Sandler101784e2012-10-15 13:39:38 -040023import android.animation.TimeInterpolator;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070024import android.app.ActivityManager;
Joe Onorato808182d2010-07-09 18:52:06 -040025import android.app.ActivityManagerNative;
Joe Onorato808182d2010-07-09 18:52:06 -040026import android.app.Notification;
27import android.app.PendingIntent;
Joe Onorato808182d2010-07-09 18:52:06 -040028import android.app.StatusBarManager;
29import android.content.BroadcastReceiver;
30import android.content.Context;
31import android.content.Intent;
32import android.content.IntentFilter;
Daniel Sandlerb17a7262012-10-05 14:32:50 -040033import android.content.SharedPreferences;
Michael Jurka7f2668c2012-03-27 07:49:52 -070034import android.content.res.Resources;
John Spurlock919adac2012-10-02 16:41:12 -040035import android.database.ContentObserver;
Romain Guy648342f2012-05-25 10:44:45 -070036import android.graphics.Canvas;
37import android.graphics.ColorFilter;
Joe Onorato808182d2010-07-09 18:52:06 -040038import android.graphics.PixelFormat;
Daniel Sandlere680f542012-09-28 12:22:27 -040039import android.graphics.Point;
Romain Guy648342f2012-05-25 10:44:45 -070040import android.graphics.PorterDuff;
Joe Onorato808182d2010-07-09 18:52:06 -040041import android.graphics.Rect;
Romain Guy648342f2012-05-25 10:44:45 -070042import android.graphics.drawable.Drawable;
Michael Jurka7f2668c2012-03-27 07:49:52 -070043import android.inputmethodservice.InputMethodService;
John Spurlock919adac2012-10-02 16:41:12 -040044import android.os.Handler;
Joe Onorato808182d2010-07-09 18:52:06 -040045import android.os.IBinder;
Joe Onorato808182d2010-07-09 18:52:06 -040046import android.os.Message;
Michael Jurka7f2668c2012-03-27 07:49:52 -070047import android.os.RemoteException;
Joe Onorato808182d2010-07-09 18:52:06 -040048import android.os.SystemClock;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070049import android.os.UserHandle;
Daniel Sandlerd3090562011-08-09 00:28:44 -040050import android.provider.Settings;
John Spurlockde84f0e2013-06-12 12:41:00 -040051import android.service.notification.StatusBarNotification;
Daniel Sandler36412a72011-08-04 09:35:13 -040052import android.util.DisplayMetrics;
Chris Wren64161cc2012-12-17 16:49:30 -050053import android.util.EventLog;
Joe Onorato808182d2010-07-09 18:52:06 -040054import android.util.Log;
55import android.view.Display;
56import android.view.Gravity;
Joe Onorato808182d2010-07-09 18:52:06 -040057import android.view.MotionEvent;
58import android.view.VelocityTracker;
59import android.view.View;
John Spurlockdcf4f212013-05-21 17:19:53 -040060import android.view.View.MeasureSpec;
Joe Onorato808182d2010-07-09 18:52:06 -040061import android.view.ViewGroup;
Jim Millerf2a16b22011-07-06 17:32:48 -070062import android.view.ViewGroup.LayoutParams;
Daniel Sandler101784e2012-10-15 13:39:38 -040063import android.view.ViewPropertyAnimator;
Daniel Sandlerb17a7262012-10-05 14:32:50 -040064import android.view.ViewStub;
Joe Onorato808182d2010-07-09 18:52:06 -040065import android.view.WindowManager;
Daniel Sandlerd7e96862012-04-26 01:10:29 -040066import android.view.animation.AccelerateInterpolator;
Joe Onorato808182d2010-07-09 18:52:06 -040067import android.view.animation.Animation;
68import android.view.animation.AnimationUtils;
Daniel Sandler67e7d902012-06-06 16:32:21 -040069import android.view.animation.DecelerateInterpolator;
Daniel Sandler21b274e2012-05-02 15:07:51 -040070import android.widget.FrameLayout;
Joe Onorato808182d2010-07-09 18:52:06 -040071import android.widget.ImageView;
72import android.widget.LinearLayout;
Joe Onorato808182d2010-07-09 18:52:06 -040073import android.widget.ScrollView;
74import android.widget.TextView;
John Spurlockdcf4f212013-05-21 17:19:53 -040075import android.widget.Toast;
Joe Onorato808182d2010-07-09 18:52:06 -040076import com.android.internal.statusbar.StatusBarIcon;
Chris Wren64161cc2012-12-17 16:49:30 -050077import com.android.systemui.EventLogTags;
Joe Onorato808182d2010-07-09 18:52:06 -040078import com.android.systemui.R;
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -050079import com.android.systemui.statusbar.BaseStatusBar;
Michael Jurkaa600fd92012-06-25 15:57:05 -070080import com.android.systemui.statusbar.CommandQueue;
Daniel Sandler33805342012-07-23 15:45:12 -040081import com.android.systemui.statusbar.GestureRecorder;
Michael Jurka7f2668c2012-03-27 07:49:52 -070082import com.android.systemui.statusbar.NotificationData;
Daniel Sandler58b173b2012-05-03 11:25:29 -040083import com.android.systemui.statusbar.NotificationData.Entry;
Christian Robertson2e347422011-08-11 14:01:04 -070084import com.android.systemui.statusbar.SignalClusterView;
Michael Jurka7f2668c2012-03-27 07:49:52 -070085import com.android.systemui.statusbar.StatusBarIconView;
Daniel Sandler2b697352011-07-22 16:23:09 -040086import com.android.systemui.statusbar.policy.BatteryController;
Winson Chungd63c59782012-09-05 17:34:41 -070087import com.android.systemui.statusbar.policy.BluetoothController;
Michael Jurka7f2668c2012-03-27 07:49:52 -070088import com.android.systemui.statusbar.policy.DateView;
Chris Wren157026f2013-06-28 16:54:01 -040089import com.android.systemui.statusbar.policy.HeadsUpNotificationView;
Daniel Sandler2b697352011-07-22 16:23:09 -040090import com.android.systemui.statusbar.policy.LocationController;
91import com.android.systemui.statusbar.policy.NetworkController;
Daniel Sandler8ba33c92011-10-04 21:49:30 -040092import com.android.systemui.statusbar.policy.NotificationRowLayout;
Michael Jurkaa600fd92012-06-25 15:57:05 -070093import com.android.systemui.statusbar.policy.OnSizeChangedListener;
Daniel Sandlerb17a7262012-10-05 14:32:50 -040094import com.android.systemui.statusbar.policy.Prefs;
John Spurlockde84f0e2013-06-12 12:41:00 -040095import com.android.systemui.statusbar.policy.RotationLockController;
Joe Onorato808182d2010-07-09 18:52:06 -040096
Daniel Sandler6a858c32012-03-12 14:38:58 -040097import java.io.FileDescriptor;
98import java.io.PrintWriter;
99import java.util.ArrayList;
100
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500101public class PhoneStatusBar extends BaseStatusBar {
Joe Onoratofd52b182010-11-10 18:00:52 -0800102 static final String TAG = "PhoneStatusBar";
Daniel Sandler198a0302012-08-17 16:04:31 -0400103 public static final boolean DEBUG = BaseStatusBar.DEBUG;
Daniel Sandlerc1ebee42012-03-26 19:39:46 -0400104 public static final boolean SPEW = DEBUG;
Daniel Sandler7579bca2011-08-18 15:47:26 -0400105 public static final boolean DUMPTRUCK = true; // extra dumpsys info
Daniel Sandlerfa027f52013-04-11 22:01:47 -0400106 public static final boolean DEBUG_GESTURES = false;
Joe Onorato808182d2010-07-09 18:52:06 -0400107
Daniel Sandlerb17a7262012-10-05 14:32:50 -0400108 public static final boolean DEBUG_CLINGS = false;
109
Daniel Sandlerace0bd72012-10-11 09:56:45 -0700110 public static final boolean ENABLE_NOTIFICATION_PANEL_CLING = false;
111
Daniel Sandler040c2e42012-10-17 00:56:33 -0400112 public static final boolean SETTINGS_DRAG_SHORTCUT = true;
113
Daniel Sandler96e61c3c82011-08-04 22:49:06 -0400114 // additional instrumentation for testing purposes; intended to be left on during development
Daniel Sandler7c351742011-10-17 10:48:06 -0400115 public static final boolean CHATTY = DEBUG;
Daniel Sandler96e61c3c82011-08-04 22:49:06 -0400116
Joe Onorato808182d2010-07-09 18:52:06 -0400117 public static final String ACTION_STATUSBAR_START
118 = "com.android.internal.policy.statusbar.START";
119
Daniel Sandler8ba33c92011-10-04 21:49:30 -0400120 private static final int MSG_OPEN_NOTIFICATION_PANEL = 1000;
Daniel Sandler11cf1782012-09-27 14:03:08 -0400121 private static final int MSG_CLOSE_PANELS = 1001;
122 private static final int MSG_OPEN_SETTINGS_PANEL = 1002;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700123 // 1020-1030 reserved for BaseStatusBar
Joe Onorato808182d2010-07-09 18:52:06 -0400124
125 // will likely move to a resource or other tunable param at some point
Chris Wren157026f2013-06-28 16:54:01 -0400126 private static final int HEADS_UP_DECAY_MS = 0; // disabled, was 10000;
Joe Onorato808182d2010-07-09 18:52:06 -0400127
Daniel Sandler8cc36e52011-10-17 14:18:46 -0400128 private static final boolean CLOSE_PANEL_WHEN_EMPTIED = true;
129
Daniel Sandler58b173b2012-05-03 11:25:29 -0400130 private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10; // see NotificationManagerService
131 private static final int HIDE_ICONS_BELOW_SCORE = Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER;
132
John Spurlockad3e6cb2013-04-30 08:47:43 -0400133 private static final int STATUS_OR_NAV_OVERLAY =
134 View.STATUS_BAR_OVERLAY | View.NAVIGATION_BAR_OVERLAY;
John Spurlock32beb2c2013-03-11 10:16:47 -0400135 private static final long AUTOHIDE_TIMEOUT_MS = 3000;
136 private static final float TRANSPARENT_ALPHA = 0.7f;
137
Daniel Sandlerdc940ea2011-08-25 14:35:53 -0700138 // fling gesture tuning parameters, scaled to display density
139 private float mSelfExpandVelocityPx; // classic value: 2000px/s
140 private float mSelfCollapseVelocityPx; // classic value: 2000px/s (will be negated to collapse "up")
141 private float mFlingExpandMinVelocityPx; // classic value: 200px/s
142 private float mFlingCollapseMinVelocityPx; // classic value: 200px/s
143 private float mCollapseMinDisplayFraction; // classic value: 0.08 (25px/min(320px,480px) on G1)
144 private float mExpandMinDisplayFraction; // classic value: 0.5 (drag open halfway to expand)
145 private float mFlingGestureMaxXVelocityPx; // classic value: 150px/s
146
147 private float mExpandAccelPx; // classic value: 2000px/s/s
148 private float mCollapseAccelPx; // classic value: 2000px/s/s (will be negated to collapse "up")
149
John Spurlock209bede2013-07-17 12:23:27 -0400150 private float mFlingGestureMaxOutputVelocityPx; // how fast can it really go? (should be a little
Daniel Sandlere5011a32012-06-11 16:07:52 -0400151 // faster than mSelfCollapseVelocityPx)
152
Joe Onoratofd52b182010-11-10 18:00:52 -0800153 PhoneStatusBarPolicy mIconPolicy;
Joe Onorato808182d2010-07-09 18:52:06 -0400154
Daniel Sandler2b697352011-07-22 16:23:09 -0400155 // These are no longer handled by the policy, because we need custom strategies for them
Winson Chungd63c59782012-09-05 17:34:41 -0700156 BluetoothController mBluetoothController;
Daniel Sandler2b697352011-07-22 16:23:09 -0400157 BatteryController mBatteryController;
158 LocationController mLocationController;
159 NetworkController mNetworkController;
Svetoslav79578b22013-04-29 16:55:57 -0700160 RotationLockController mRotationLockController;
Jim Miller5e6af442011-12-02 18:24:26 -0800161
Daniel Sandler7c3e39d2011-07-29 16:30:49 -0400162 int mNaturalBarHeight = -1;
163 int mIconSize = -1;
164 int mIconHPadding = -1;
Joe Onorato808182d2010-07-09 18:52:06 -0400165 Display mDisplay;
Daniel Sandlere680f542012-09-28 12:22:27 -0400166 Point mCurrentDisplaySize = new Point();
Joe Onorato808182d2010-07-09 18:52:06 -0400167
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400168 StatusBarWindowView mStatusBarWindow;
Joe Onoratofd52b182010-11-10 18:00:52 -0800169 PhoneStatusBarView mStatusBarView;
Daniel Sandlera310af82012-04-24 01:20:13 -0400170
Joe Onorato808182d2010-07-09 18:52:06 -0400171 int mPixelFormat;
Joe Onorato808182d2010-07-09 18:52:06 -0400172 Object mQueueLock = new Object();
173
Daniel Sandler173bae22012-09-25 14:37:42 -0400174 // viewgroup containing the normal contents of the statusbar
175 LinearLayout mStatusBarContents;
John Spurlock209bede2013-07-17 12:23:27 -0400176
Daniel Sandler173bae22012-09-25 14:37:42 -0400177 // right-hand icons
178 LinearLayout mSystemIconArea;
John Spurlock209bede2013-07-17 12:23:27 -0400179
180 // left-hand icons
Joe Onorato808182d2010-07-09 18:52:06 -0400181 LinearLayout mStatusIcons;
Daniel Sandler173bae22012-09-25 14:37:42 -0400182 // the icons themselves
183 IconMerger mNotificationIcons;
184 // [+>
185 View mMoreIcon;
Joe Onorato808182d2010-07-09 18:52:06 -0400186
187 // expanded notifications
Daniel Sandler040c2e42012-10-17 00:56:33 -0400188 NotificationPanelView mNotificationPanel; // the sliding/resizing panel within the notification window
Joe Onorato808182d2010-07-09 18:52:06 -0400189 ScrollView mScrollView;
Joe Onorato808182d2010-07-09 18:52:06 -0400190 View mExpandedContents;
Daniel Sandler21b274e2012-05-02 15:07:51 -0400191 int mNotificationPanelGravity;
Daniel Sandler8e72c9e2012-08-15 00:09:26 -0400192 int mNotificationPanelMarginBottomPx, mNotificationPanelMarginPx;
Daniel Sandlere680f542012-09-28 12:22:27 -0400193 float mNotificationPanelMinHeightFrac;
Daniel Sandler66d92f82012-06-13 13:36:52 -0400194 boolean mNotificationPanelIsFullScreenWidth;
Daniel Sandlerb9301c32012-08-14 15:08:24 -0400195 TextView mNotificationPanelDebugText;
Daniel Sandler21b274e2012-05-02 15:07:51 -0400196
Daniel Sandler8e72c9e2012-08-15 00:09:26 -0400197 // settings
Daniel Sandler101784e2012-10-15 13:39:38 -0400198 QuickSettings mQS;
199 boolean mHasSettingsPanel, mHasFlipSettings;
Daniel Sandler3ffdcc72012-09-23 14:31:48 -0400200 SettingsPanelView mSettingsPanel;
Daniel Sandler101784e2012-10-15 13:39:38 -0400201 View mFlipSettingsView;
202 QuickSettingsContainerView mSettingsContainer;
Daniel Sandler8e72c9e2012-08-15 00:09:26 -0400203 int mSettingsPanelGravity;
204
Joe Onorato808182d2010-07-09 18:52:06 -0400205 // top bar
Daniel Sandler3679bf52012-10-16 21:30:28 -0400206 View mNotificationPanelHeader;
John Spurlock209bede2013-07-17 12:23:27 -0400207 View mDateTimeView;
Daniel Sandler1347c302011-08-01 16:47:53 -0400208 View mClearButton;
Daniel Sandler101784e2012-10-15 13:39:38 -0400209 ImageView mSettingsButton, mNotificationButton;
Daniel Sandlerd3090562011-08-09 00:28:44 -0400210
Daniel Sandler3d32a242012-06-05 13:44:14 -0400211 // carrier/wifi label
212 private TextView mCarrierLabel;
213 private boolean mCarrierLabelVisible = false;
214 private int mCarrierLabelHeight;
Daniel Sandlerdd4ef492012-07-27 11:19:52 -0400215 private TextView mEmergencyCallLabel;
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400216 private int mNotificationHeaderHeight;
217
218 private boolean mShowCarrierInPanel = false;
Daniel Sandler3d32a242012-06-05 13:44:14 -0400219
Joe Onorato808182d2010-07-09 18:52:06 -0400220 // position
221 int[] mPositionTmp = new int[2];
Joe Onorato808182d2010-07-09 18:52:06 -0400222 boolean mExpandedVisible;
223
224 // the date view
225 DateView mDateView;
226
Chris Wren157026f2013-06-28 16:54:01 -0400227 // for heads up notifications
228 private HeadsUpNotificationView mHeadsUpNotificationView;
Joe Onorato808182d2010-07-09 18:52:06 -0400229
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400230 // on-screen navigation buttons
Daniel Sandler0129b312011-05-11 11:54:11 -0400231 private NavigationBarView mNavigationBarView = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400232
Joe Onorato808182d2010-07-09 18:52:06 -0400233 // the tracker view
Joe Onorato808182d2010-07-09 18:52:06 -0400234 int mTrackingPosition; // the position of the top of the tracking view.
Joe Onorato808182d2010-07-09 18:52:06 -0400235
236 // ticker
237 private Ticker mTicker;
238 private View mTickerView;
239 private boolean mTicking;
240
241 // Tracking finger for opening/closing.
242 int mEdgeBorder; // corresponds to R.dimen.status_bar_edge_ignore
243 boolean mTracking;
244 VelocityTracker mVelocityTracker;
245
Daniel Sandlerb17a7262012-10-05 14:32:50 -0400246 // help screen
247 private boolean mClingShown;
248 private ViewGroup mCling;
249 private boolean mSuppressStatusBarDrags; // while a cling is up, briefly deaden the bar to give things time to settle
250
Joe Onorato808182d2010-07-09 18:52:06 -0400251 int[] mAbsPos = new int[2];
Chet Haase2f2022a2011-10-11 06:41:59 -0700252 Runnable mPostCollapseCleanup = null;
253
Daniel Sandler173bae22012-09-25 14:37:42 -0400254 private Animator mLightsOutAnimation;
255 private Animator mLightsOnAnimation;
Joe Onorato808182d2010-07-09 18:52:06 -0400256
257 // for disabling the status bar
258 int mDisabled = 0;
259
Daniel Sandler60ee2562011-07-22 12:34:33 -0400260 // tracking calls to View.setSystemUiVisibility()
261 int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
262
Daniel Sandler36412a72011-08-04 09:35:13 -0400263 DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Dianne Hackborn1dacf272011-08-02 15:01:22 -0700264
Daniel Sandler33805342012-07-23 15:45:12 -0400265 // XXX: gesture research
Daniel Sandler151f00d2012-10-02 22:33:08 -0400266 private final GestureRecorder mGestureRec = DEBUG_GESTURES
John Spurlock209bede2013-07-17 12:23:27 -0400267 ? new GestureRecorder("/sdcard/statusbar_gestures.dat")
Daniel Sandler151f00d2012-10-02 22:33:08 -0400268 : null;
Daniel Sandler33805342012-07-23 15:45:12 -0400269
Daniel Sandler328310c2011-09-23 15:56:52 -0400270 private int mNavigationIconHints = 0;
Romain Guyf7f16f72012-05-24 19:13:56 -0700271 private final Animator.AnimatorListener mMakeIconsInvisible = new AnimatorListenerAdapter() {
272 @Override
273 public void onAnimationEnd(Animator animation) {
Daniel Sandler67e7d902012-06-06 16:32:21 -0400274 // double-check to avoid races
Daniel Sandler173bae22012-09-25 14:37:42 -0400275 if (mStatusBarContents.getAlpha() == 0) {
John Spurlockcd686b52013-06-05 10:13:46 -0400276 if (DEBUG) Log.d(TAG, "makeIconsInvisible");
Daniel Sandler173bae22012-09-25 14:37:42 -0400277 mStatusBarContents.setVisibility(View.INVISIBLE);
Daniel Sandler67e7d902012-06-06 16:32:21 -0400278 }
Romain Guyf7f16f72012-05-24 19:13:56 -0700279 }
280 };
Daniel Sandler328310c2011-09-23 15:56:52 -0400281
John Spurlock919adac2012-10-02 16:41:12 -0400282 // ensure quick settings is disabled until the current user makes it through the setup wizard
283 private boolean mUserSetup = false;
284 private ContentObserver mUserSetupObserver = new ContentObserver(new Handler()) {
285 @Override
286 public void onChange(boolean selfChange) {
287 final boolean userSetup = 0 != Settings.Secure.getIntForUser(
288 mContext.getContentResolver(),
289 Settings.Secure.USER_SETUP_COMPLETE,
290 0 /*default */,
291 mCurrentUserId);
John Spurlockcd686b52013-06-05 10:13:46 -0400292 if (MULTIUSER_DEBUG) Log.d(TAG, String.format("User setup changed: " +
John Spurlocke4e8c562012-10-04 09:55:01 -0400293 "selfChange=%s userSetup=%s mUserSetup=%s",
294 selfChange, userSetup, mUserSetup));
Daniel Sandlera8ef3b02012-11-29 15:52:39 -0500295 if (mSettingsButton != null && mHasFlipSettings) {
Daniel Sandler101784e2012-10-15 13:39:38 -0400296 mSettingsButton.setVisibility(userSetup ? View.VISIBLE : View.INVISIBLE);
297 }
298 if (mSettingsPanel != null) {
John Spurlocke4e8c562012-10-04 09:55:01 -0400299 mSettingsPanel.setEnabled(userSetup);
Daniel Sandler101784e2012-10-15 13:39:38 -0400300 }
John Spurlock919adac2012-10-02 16:41:12 -0400301 if (userSetup != mUserSetup) {
302 mUserSetup = userSetup;
John Spurlock919adac2012-10-02 16:41:12 -0400303 if (!mUserSetup && mStatusBarView != null)
304 animateCollapseQuickSettings();
305 }
306 }
307 };
308
John Spurlockdcf4f212013-05-21 17:19:53 -0400309 private Toast mHideybarConfirmation;
310 private boolean mHideybarConfirmationDismissed;
311
312 private final View.OnTouchListener mDismissHideybarConfirmationOnTouchOutside =
313 new View.OnTouchListener() {
314 @Override
315 public boolean onTouch(View v, MotionEvent event) {
316 if (event.getActionMasked() == MotionEvent.ACTION_OUTSIDE) {
317 dismissHideybarConfirmation();
318 }
319 return false;
320 }
321 };
322
323 private final Runnable mHideybarConfirmationAction = new Runnable() {
324 @Override
325 public void run() {
326 if (mHideybarConfirmation != null) {
327 final boolean isGloballyConfirmed = Prefs.read(mContext)
328 .getBoolean(Prefs.HIDEYBAR_CONFIRMED, false);
329 if (!isGloballyConfirmed) {
330 // user pressed button, consider this a confirmation
331 Prefs.edit(mContext)
332 .putBoolean(Prefs.HIDEYBAR_CONFIRMED, true)
333 .apply();
334 }
335 dismissHideybarConfirmation();
336 }
337 }
338 };
339
John Spurlock32beb2c2013-03-11 10:16:47 -0400340 private boolean mAutohideSuspended;
341
342 private final Runnable mAutohide = new Runnable() {
343 @Override
344 public void run() {
John Spurlockad3e6cb2013-04-30 08:47:43 -0400345 int requested = mSystemUiVisibility & ~STATUS_OR_NAV_OVERLAY;
John Spurlock32beb2c2013-03-11 10:16:47 -0400346 notifyUiVisibilityChanged(requested);
347 }};
348
Joe Onorato808182d2010-07-09 18:52:06 -0400349 @Override
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400350 public void start() {
351 mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
352 .getDefaultDisplay();
John Spurlockdcf4f212013-05-21 17:19:53 -0400353 mDisplay.getSize(mCurrentDisplaySize);
Joe Onorato808182d2010-07-09 18:52:06 -0400354
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -0500355 super.start(); // calls createAndAddWindows()
Joe Onorato808182d2010-07-09 18:52:06 -0400356
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400357 addNavigationBar();
358
Chris Wren157026f2013-06-28 16:54:01 -0400359 if (ENABLE_HEADS_UP) addHeadsUpView();
Joe Onorato808182d2010-07-09 18:52:06 -0400360
361 // Lastly, call to the icon policy to install/update all the icons.
Joe Onoratofd52b182010-11-10 18:00:52 -0800362 mIconPolicy = new PhoneStatusBarPolicy(mContext);
Joe Onorato808182d2010-07-09 18:52:06 -0400363 }
364
365 // ================================================================================
366 // Constructing the view
367 // ================================================================================
Jim Millere898ac52012-04-06 17:10:57 -0700368 protected PhoneStatusBarView makeStatusBarView() {
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400369 final Context context = mContext;
Joe Onorato808182d2010-07-09 18:52:06 -0400370
371 Resources res = context.getResources();
372
Daniel Sandler6e8db882011-10-26 15:40:51 -0400373 updateDisplaySize(); // populates mDisplayMetrics
Daniel Sandler7c3e39d2011-07-29 16:30:49 -0400374 loadDimens();
Joe Onorato808182d2010-07-09 18:52:06 -0400375
Dianne Hackborn1dacf272011-08-02 15:01:22 -0700376 mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
377
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400378 mStatusBarWindow = (StatusBarWindowView) View.inflate(context,
Daniel Sandlera310af82012-04-24 01:20:13 -0400379 R.layout.super_status_bar, null);
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400380 mStatusBarWindow.mService = this;
Daniel Sandler21b274e2012-05-02 15:07:51 -0400381 mStatusBarWindow.setOnTouchListener(new View.OnTouchListener() {
382 @Override
383 public boolean onTouch(View v, MotionEvent event) {
384 if (event.getAction() == MotionEvent.ACTION_DOWN) {
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500385 if (mExpandedVisible) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400386 animateCollapsePanels();
Daniel Sandler21b274e2012-05-02 15:07:51 -0400387 }
388 }
Chris Wren5de6e942012-05-16 14:22:21 -0400389 return mStatusBarWindow.onTouchEvent(event);
Daniel Sandler21b274e2012-05-02 15:07:51 -0400390 }});
391
Daniel Sandlera310af82012-04-24 01:20:13 -0400392 mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400393 mStatusBarView.setBar(this);
John Spurlock209bede2013-07-17 12:23:27 -0400394
Daniel Sandler08d05e32012-08-08 16:39:54 -0400395
396 PanelHolder holder = (PanelHolder) mStatusBarWindow.findViewById(R.id.panel_holder);
397 mStatusBarView.setPanelHolder(holder);
398
Daniel Sandler040c2e42012-10-17 00:56:33 -0400399 mNotificationPanel = (NotificationPanelView) mStatusBarWindow.findViewById(R.id.notification_panel);
400 mNotificationPanel.setStatusBar(this);
Daniel Sandler66d92f82012-06-13 13:36:52 -0400401 mNotificationPanelIsFullScreenWidth =
402 (mNotificationPanel.getLayoutParams().width == ViewGroup.LayoutParams.MATCH_PARENT);
Joe Onorato808182d2010-07-09 18:52:06 -0400403
Daniel Sandlerefb0faf2012-10-10 14:15:34 -0700404 // make the header non-responsive to clicks
405 mNotificationPanel.findViewById(R.id.header).setOnTouchListener(
406 new View.OnTouchListener() {
407 @Override
408 public boolean onTouch(View v, MotionEvent event) {
409 return true; // e eats everything
410 }
411 });
412
Jeff Brown98365d72012-08-19 20:30:52 -0700413 if (!ActivityManager.isHighEndGfx()) {
Romain Guy328b3582012-05-08 15:30:57 -0700414 mStatusBarWindow.setBackground(null);
Romain Guy648342f2012-05-25 10:44:45 -0700415 mNotificationPanel.setBackground(new FastColorDrawable(context.getResources().getColor(
416 R.color.notification_panel_solid_background)));
Romain Guy328b3582012-05-08 15:30:57 -0700417 }
Chris Wren157026f2013-06-28 16:54:01 -0400418 if (ENABLE_HEADS_UP) {
419 mHeadsUpNotificationView =
420 (HeadsUpNotificationView) View.inflate(context, R.layout.heads_up, null);
421 mHeadsUpNotificationView.setVisibility(View.GONE);
422 mHeadsUpNotificationView.setBar(this);
Daniel Sandler6b318802012-04-13 14:05:19 -0400423 }
Daniel Sandlerb9301c32012-08-14 15:08:24 -0400424 if (MULTIUSER_DEBUG) {
425 mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(R.id.header_debug_info);
426 mNotificationPanelDebugText.setVisibility(View.VISIBLE);
427 }
Joe Onorato808182d2010-07-09 18:52:06 -0400428
John Spurlockd5ef5462012-06-13 11:19:51 -0400429 updateShowSearchHoldoff();
430
Daniel Sandler0129b312011-05-11 11:54:11 -0400431 try {
Jeff Brown98365d72012-08-19 20:30:52 -0700432 boolean showNav = mWindowManagerService.hasNavigationBar();
John Spurlockcd686b52013-06-05 10:13:46 -0400433 if (DEBUG) Log.v(TAG, "hasNavigationBar=" + showNav);
Daniel Sandler0129b312011-05-11 11:54:11 -0400434 if (showNav) {
Jim Miller5e6af442011-12-02 18:24:26 -0800435 mNavigationBarView =
Daniel Sandler0129b312011-05-11 11:54:11 -0400436 (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null);
Daniel Sandler60ee2562011-07-22 12:34:33 -0400437
Daniel Sandler6da2b762011-09-14 16:04:59 -0400438 mNavigationBarView.setDisabledFlags(mDisabled);
Jim Millere898ac52012-04-06 17:10:57 -0700439 mNavigationBarView.setBar(this);
Daniel Sandler0129b312011-05-11 11:54:11 -0400440 }
Daniel Sandler0c4ccff2011-10-19 16:39:14 -0400441 } catch (RemoteException ex) {
442 // no window manager? good luck with that
Daniel Sandler0129b312011-05-11 11:54:11 -0400443 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400444
Joe Onorato808182d2010-07-09 18:52:06 -0400445 // figure out which pixel-format to use for the status bar.
Daniel Sandlerf733c2a2011-09-25 15:03:40 -0400446 mPixelFormat = PixelFormat.OPAQUE;
Daniel Sandler173bae22012-09-25 14:37:42 -0400447
448 mSystemIconArea = (LinearLayout) mStatusBarView.findViewById(R.id.system_icon_area);
Daniel Sandlera310af82012-04-24 01:20:13 -0400449 mStatusIcons = (LinearLayout)mStatusBarView.findViewById(R.id.statusIcons);
450 mNotificationIcons = (IconMerger)mStatusBarView.findViewById(R.id.notificationIcons);
Mats H Carlssoncd231432012-10-10 13:37:38 +0200451 mMoreIcon = mStatusBarView.findViewById(R.id.moreIcon);
Daniel Sandler05e24142011-11-10 11:56:49 -0500452 mNotificationIcons.setOverflowIndicator(mMoreIcon);
Daniel Sandler173bae22012-09-25 14:37:42 -0400453 mStatusBarContents = (LinearLayout)mStatusBarView.findViewById(R.id.status_bar_contents);
Daniel Sandlera310af82012-04-24 01:20:13 -0400454 mTickerView = mStatusBarView.findViewById(R.id.ticker);
Joe Onorato808182d2010-07-09 18:52:06 -0400455
Daniel Sandlera310af82012-04-24 01:20:13 -0400456 mPile = (NotificationRowLayout)mStatusBarWindow.findViewById(R.id.latestItems);
Daniel Sandlere5011a32012-06-11 16:07:52 -0400457 mPile.setLayoutTransitionsEnabled(false);
Daniel Sandlerf7a19562012-04-04 14:04:21 -0400458 mPile.setLongPressListener(getNotificationLongClicker());
Daniel Sandler0761e4c2011-08-11 00:19:49 -0400459 mExpandedContents = mPile; // was: expanded.findViewById(R.id.notificationLinearLayout);
Daniel Sandlerd7141482011-08-18 15:14:52 -0400460
Daniel Sandler3679bf52012-10-16 21:30:28 -0400461 mNotificationPanelHeader = mStatusBarWindow.findViewById(R.id.header);
462
Daniel Sandlera310af82012-04-24 01:20:13 -0400463 mClearButton = mStatusBarWindow.findViewById(R.id.clear_all_button);
Joe Onorato808182d2010-07-09 18:52:06 -0400464 mClearButton.setOnClickListener(mClearButtonListener);
Daniel Sandler0761e4c2011-08-11 00:19:49 -0400465 mClearButton.setAlpha(0f);
Romain Guy8900e632012-05-25 12:08:39 -0700466 mClearButton.setVisibility(View.INVISIBLE);
Daniel Sandler8ba33c92011-10-04 21:49:30 -0400467 mClearButton.setEnabled(false);
Daniel Sandlera310af82012-04-24 01:20:13 -0400468 mDateView = (DateView)mStatusBarWindow.findViewById(R.id.date);
Daniel Sandlere111ad32012-10-13 15:17:45 -0400469
470 mHasSettingsPanel = res.getBoolean(R.bool.config_hasSettingsPanel);
Daniel Sandler101784e2012-10-15 13:39:38 -0400471 mHasFlipSettings = res.getBoolean(R.bool.config_hasFlipSettingsPanel);
Daniel Sandlere111ad32012-10-13 15:17:45 -0400472
Daniel Sandler3679bf52012-10-16 21:30:28 -0400473 mDateTimeView = mNotificationPanelHeader.findViewById(R.id.datetime);
Daniel Sandler458d5e12013-02-21 15:12:49 -0500474 if (mDateTimeView != null) {
Daniel Sandler3679bf52012-10-16 21:30:28 -0400475 mDateTimeView.setOnClickListener(mClockClickListener);
476 mDateTimeView.setEnabled(true);
477 }
478
Daniel Sandlere111ad32012-10-13 15:17:45 -0400479 mSettingsButton = (ImageView) mStatusBarWindow.findViewById(R.id.settings_button);
Daniel Sandler6e5fe432012-09-16 15:34:36 -0400480 if (mSettingsButton != null) {
Daniel Sandlere111ad32012-10-13 15:17:45 -0400481 mSettingsButton.setOnClickListener(mSettingsButtonListener);
482 if (mHasSettingsPanel) {
483 if (mStatusBarView.hasFullWidthNotifications()) {
484 // the settings panel is hiding behind this button
485 mSettingsButton.setImageResource(R.drawable.ic_notify_quicksettings);
486 mSettingsButton.setVisibility(View.VISIBLE);
487 } else {
488 // there is a settings panel, but it's on the other side of the (large) screen
Daniel Sandler7382a022012-10-22 14:36:50 -0400489 final View buttonHolder = mStatusBarWindow.findViewById(
490 R.id.settings_button_holder);
491 if (buttonHolder != null) {
492 buttonHolder.setVisibility(View.GONE);
493 }
Daniel Sandlere111ad32012-10-13 15:17:45 -0400494 }
Daniel Sandlerefb0faf2012-10-10 14:15:34 -0700495 } else {
Daniel Sandlere111ad32012-10-13 15:17:45 -0400496 // no settings panel, go straight to settings
497 mSettingsButton.setVisibility(View.VISIBLE);
498 mSettingsButton.setImageResource(R.drawable.ic_notify_settings);
Daniel Sandlerefb0faf2012-10-10 14:15:34 -0700499 }
Daniel Sandler6e5fe432012-09-16 15:34:36 -0400500 }
Daniel Sandler101784e2012-10-15 13:39:38 -0400501 if (mHasFlipSettings) {
502 mNotificationButton = (ImageView) mStatusBarWindow.findViewById(R.id.notification_button);
503 if (mNotificationButton != null) {
504 mNotificationButton.setOnClickListener(mNotificationButtonListener);
505 }
506 }
507
Daniel Sandlera310af82012-04-24 01:20:13 -0400508 mScrollView = (ScrollView)mStatusBarWindow.findViewById(R.id.scroll);
Daniel Sandler079b33d2012-03-02 16:29:41 -0500509 mScrollView.setVerticalScrollBarEnabled(false); // less drawing during pulldowns
Daniel Sandler3679bf52012-10-16 21:30:28 -0400510 if (!mNotificationPanelIsFullScreenWidth) {
511 mScrollView.setSystemUiVisibility(
512 View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER |
513 View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS |
514 View.STATUS_BAR_DISABLE_CLOCK);
515 }
Joe Onorato808182d2010-07-09 18:52:06 -0400516
Daniel Sandlera310af82012-04-24 01:20:13 -0400517 mTicker = new MyTicker(context, mStatusBarView);
Joe Onorato808182d2010-07-09 18:52:06 -0400518
Daniel Sandlera310af82012-04-24 01:20:13 -0400519 TickerView tickerView = (TickerView)mStatusBarView.findViewById(R.id.tickerText);
Joe Onorato808182d2010-07-09 18:52:06 -0400520 tickerView.mTicker = mTicker;
521
Joe Onorato808182d2010-07-09 18:52:06 -0400522 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore);
523
Joe Onorato808182d2010-07-09 18:52:06 -0400524 // set the inital view visibility
525 setAreThereNotifications();
Joe Onorato808182d2010-07-09 18:52:06 -0400526
Daniel Sandler2b697352011-07-22 16:23:09 -0400527 // Other icons
528 mLocationController = new LocationController(mContext); // will post a notification
529 mBatteryController = new BatteryController(mContext);
Daniel Sandlera310af82012-04-24 01:20:13 -0400530 mBatteryController.addIconView((ImageView)mStatusBarView.findViewById(R.id.battery));
Daniel Sandler2b697352011-07-22 16:23:09 -0400531 mNetworkController = new NetworkController(mContext);
Winson Chungd63c59782012-09-05 17:34:41 -0700532 mBluetoothController = new BluetoothController(mContext);
Svetoslav79578b22013-04-29 16:55:57 -0700533 mRotationLockController = new RotationLockController(mContext);
Jim Miller5e6af442011-12-02 18:24:26 -0800534 final SignalClusterView signalCluster =
Daniel Sandlera310af82012-04-24 01:20:13 -0400535 (SignalClusterView)mStatusBarView.findViewById(R.id.signal_cluster);
Daniel Sandler3d32a242012-06-05 13:44:14 -0400536
Winson Chungd63c59782012-09-05 17:34:41 -0700537
Christian Robertson2e347422011-08-11 14:01:04 -0700538 mNetworkController.addSignalCluster(signalCluster);
Daniel Sandler28f89d42011-08-15 14:04:15 -0400539 signalCluster.setNetworkController(mNetworkController);
Daniel Sandler18ac7822012-06-11 16:07:18 -0400540
Daniel Sandler8b268d42013-05-28 16:17:13 -0400541 final boolean isAPhone = mNetworkController.hasVoiceCallingFeature();
542 if (isAPhone) {
543 mEmergencyCallLabel =
544 (TextView) mStatusBarWindow.findViewById(R.id.emergency_calls_only);
545 if (mEmergencyCallLabel != null) {
546 mNetworkController.addEmergencyLabelView(mEmergencyCallLabel);
547 mEmergencyCallLabel.setOnClickListener(new View.OnClickListener() {
548 public void onClick(View v) { }});
549 mEmergencyCallLabel.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
550 @Override
551 public void onLayoutChange(View v, int left, int top, int right, int bottom,
552 int oldLeft, int oldTop, int oldRight, int oldBottom) {
553 updateCarrierLabelVisibility(false);
554 }});
555 }
Daniel Sandlerdd4ef492012-07-27 11:19:52 -0400556 }
557
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400558 mCarrierLabel = (TextView)mStatusBarWindow.findViewById(R.id.carrier_label);
559 mShowCarrierInPanel = (mCarrierLabel != null);
John Spurlockcd686b52013-06-05 10:13:46 -0400560 if (DEBUG) Log.v(TAG, "carrierlabel=" + mCarrierLabel + " show=" + mShowCarrierInPanel);
Daniel Sandlerbf526d12012-09-04 22:56:44 -0400561 if (mShowCarrierInPanel) {
Daniel Sandlerdd4ef492012-07-27 11:19:52 -0400562 mCarrierLabel.setVisibility(mCarrierLabelVisible ? View.VISIBLE : View.INVISIBLE);
563
Daniel Sandler67234c42012-06-15 13:17:39 -0400564 // for mobile devices, we always show mobile connection info here (SPN/PLMN)
565 // for other devices, we show whatever network is connected
Daniel Sandler18ac7822012-06-11 16:07:18 -0400566 if (mNetworkController.hasMobileDataFeature()) {
567 mNetworkController.addMobileLabelView(mCarrierLabel);
568 } else {
Daniel Sandler67234c42012-06-15 13:17:39 -0400569 mNetworkController.addCombinedLabelView(mCarrierLabel);
Daniel Sandler18ac7822012-06-11 16:07:18 -0400570 }
Daniel Sandlerdd4ef492012-07-27 11:19:52 -0400571
572 // set up the dynamic hide/show of the label
573 mPile.setOnSizeChangedListener(new OnSizeChangedListener() {
574 @Override
575 public void onSizeChanged(View view, int w, int h, int oldw, int oldh) {
576 updateCarrierLabelVisibility(false);
577 }
578 });
Daniel Sandler3d32a242012-06-05 13:44:14 -0400579 }
580
Daniel Sandlere111ad32012-10-13 15:17:45 -0400581 // Quick Settings (where available, some restrictions apply)
582 if (mHasSettingsPanel) {
Daniel Sandler101784e2012-10-15 13:39:38 -0400583 // first, figure out where quick settings should be inflated
584 final View settings_stub;
585 if (mHasFlipSettings) {
586 // a version of quick settings that flips around behind the notifications
587 settings_stub = mStatusBarWindow.findViewById(R.id.flip_settings_stub);
588 if (settings_stub != null) {
589 mFlipSettingsView = ((ViewStub)settings_stub).inflate();
590 mFlipSettingsView.setVisibility(View.GONE);
591 mFlipSettingsView.setVerticalScrollBarEnabled(false);
592 }
Daniel Sandlere111ad32012-10-13 15:17:45 -0400593 } else {
Daniel Sandler101784e2012-10-15 13:39:38 -0400594 // full quick settings panel
595 settings_stub = mStatusBarWindow.findViewById(R.id.quick_settings_stub);
596 if (settings_stub != null) {
597 mSettingsPanel = (SettingsPanelView) ((ViewStub)settings_stub).inflate();
598 } else {
599 mSettingsPanel = (SettingsPanelView) mStatusBarWindow.findViewById(R.id.settings_panel);
600 }
601
602 if (mSettingsPanel != null) {
Daniel Sandler101784e2012-10-15 13:39:38 -0400603 if (!ActivityManager.isHighEndGfx()) {
604 mSettingsPanel.setBackground(new FastColorDrawable(context.getResources().getColor(
605 R.color.notification_panel_solid_background)));
606 }
607 }
Daniel Sandlere111ad32012-10-13 15:17:45 -0400608 }
609
Daniel Sandler101784e2012-10-15 13:39:38 -0400610 // wherever you find it, Quick Settings needs a container to survive
611 mSettingsContainer = (QuickSettingsContainerView)
612 mStatusBarWindow.findViewById(R.id.quick_settings_container);
613 if (mSettingsContainer != null) {
614 mQS = new QuickSettings(mContext, mSettingsContainer);
Daniel Sandler3679bf52012-10-16 21:30:28 -0400615 if (!mNotificationPanelIsFullScreenWidth) {
616 mSettingsContainer.setSystemUiVisibility(
617 View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER
618 | View.STATUS_BAR_DISABLE_SYSTEM_INFO);
619 }
Daniel Sandler101784e2012-10-15 13:39:38 -0400620 if (mSettingsPanel != null) {
621 mSettingsPanel.setQuickSettings(mQS);
Daniel Sandlere111ad32012-10-13 15:17:45 -0400622 }
Daniel Sandler101784e2012-10-15 13:39:38 -0400623 mQS.setService(this);
Daniel Sandlerfe3376b2012-10-16 19:54:02 -0400624 mQS.setBar(mStatusBarView);
Daniel Sandler101784e2012-10-15 13:39:38 -0400625 mQS.setup(mNetworkController, mBluetoothController, mBatteryController,
Svetoslav79578b22013-04-29 16:55:57 -0700626 mLocationController, mRotationLockController);
Daniel Sandler101784e2012-10-15 13:39:38 -0400627 } else {
628 mQS = null; // fly away, be free
Daniel Sandlere111ad32012-10-13 15:17:45 -0400629 }
Siva Velusamy537421b2012-09-14 14:45:02 -0700630 }
631
John Spurlock209bede2013-07-17 12:23:27 -0400632 mClingShown = ! (DEBUG_CLINGS
Daniel Sandlerb17a7262012-10-05 14:32:50 -0400633 || !Prefs.read(mContext).getBoolean(Prefs.SHOWN_QUICK_SETTINGS_HELP, false));
634
Daniel Sandlerace0bd72012-10-11 09:56:45 -0700635 if (!ENABLE_NOTIFICATION_PANEL_CLING || ActivityManager.isRunningInTestHarness()) {
Daniel Sandlerb17a7262012-10-05 14:32:50 -0400636 mClingShown = true;
637 }
638
Jim Miller5e6af442011-12-02 18:24:26 -0800639// final ImageView wimaxRSSI =
Daniel Sandler633eabe2011-11-09 16:49:44 -0500640// (ImageView)sb.findViewById(R.id.wimax_signal);
641// if (wimaxRSSI != null) {
642// mNetworkController.addWimaxIconView(wimaxRSSI);
643// }
Michael Jurka3b1fc472011-06-13 10:54:40 -0700644
Joe Onorato808182d2010-07-09 18:52:06 -0400645 // receive broadcasts
646 IntentFilter filter = new IntentFilter();
647 filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
648 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
649 filter.addAction(Intent.ACTION_SCREEN_OFF);
Daniel Sandler7f3cf952012-08-31 14:57:09 -0400650 filter.addAction(Intent.ACTION_SCREEN_ON);
Joe Onorato808182d2010-07-09 18:52:06 -0400651 context.registerReceiver(mBroadcastReceiver, filter);
652
John Spurlock919adac2012-10-02 16:41:12 -0400653 // listen for USER_SETUP_COMPLETE setting (per-user)
654 resetUserSetupObserver();
655
Daniel Sandlera310af82012-04-24 01:20:13 -0400656 return mStatusBarView;
Joe Onorato808182d2010-07-09 18:52:06 -0400657 }
658
Michael Jurka7f2668c2012-03-27 07:49:52 -0700659 @Override
Michael Jurkacb2522c2012-04-13 09:32:47 -0700660 protected View getStatusBarView() {
661 return mStatusBarView;
662 }
663
664 @Override
Jim Millere898ac52012-04-06 17:10:57 -0700665 protected WindowManager.LayoutParams getSearchLayoutParams(LayoutParams layoutParams) {
666 boolean opaque = false;
667 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
668 LayoutParams.MATCH_PARENT,
669 LayoutParams.MATCH_PARENT,
670 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
671 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
672 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
673 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
674 (opaque ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT));
Jeff Brown98365d72012-08-19 20:30:52 -0700675 if (ActivityManager.isHighEndGfx()) {
Jim Millere898ac52012-04-06 17:10:57 -0700676 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
Jim Millere898ac52012-04-06 17:10:57 -0700677 }
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700678 lp.gravity = Gravity.BOTTOM | Gravity.START;
Jim Millere898ac52012-04-06 17:10:57 -0700679 lp.setTitle("SearchPanel");
680 // TODO: Define custom animation for Search panel
681 lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications;
682 lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
683 | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
684 return lp;
685 }
686
Jim Millere898ac52012-04-06 17:10:57 -0700687 @Override
688 protected void updateSearchPanel() {
689 super.updateSearchPanel();
Jim Millere898ac52012-04-06 17:10:57 -0700690 mNavigationBarView.setDelegateView(mSearchPanelView);
691 }
692
693 @Override
694 public void showSearchPanel() {
Jim Millerb490c3e2012-05-31 13:34:16 -0700695 super.showSearchPanel();
John Spurlock7a733442012-11-08 09:08:14 -0500696 mHandler.removeCallbacks(mShowSearchPanel);
Daniel Sandlerd5483c32012-10-19 16:44:15 -0400697
698 // we want to freeze the sysui state wherever it is
699 mSearchPanelView.setSystemUiVisibility(mSystemUiVisibility);
700
Jim Millere898ac52012-04-06 17:10:57 -0700701 WindowManager.LayoutParams lp =
702 (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams();
703 lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Jeff Brown98365d72012-08-19 20:30:52 -0700704 mWindowManager.updateViewLayout(mNavigationBarView, lp);
Jim Millere898ac52012-04-06 17:10:57 -0700705 }
706
707 @Override
708 public void hideSearchPanel() {
709 super.hideSearchPanel();
710 WindowManager.LayoutParams lp =
711 (android.view.WindowManager.LayoutParams) mNavigationBarView.getLayoutParams();
712 lp.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Jeff Brown98365d72012-08-19 20:30:52 -0700713 mWindowManager.updateViewLayout(mNavigationBarView, lp);
Jim Millere898ac52012-04-06 17:10:57 -0700714 }
715
Joe Onorato808182d2010-07-09 18:52:06 -0400716 protected int getStatusBarGravity() {
717 return Gravity.TOP | Gravity.FILL_HORIZONTAL;
718 }
719
Joe Onoratodc100302011-01-11 17:07:41 -0800720 public int getStatusBarHeight() {
Daniel Sandlera310af82012-04-24 01:20:13 -0400721 if (mNaturalBarHeight < 0) {
722 final Resources res = mContext.getResources();
Jim Millera073e572012-05-23 17:03:27 -0700723 mNaturalBarHeight =
Daniel Sandlera310af82012-04-24 01:20:13 -0400724 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
725 }
726 return mNaturalBarHeight;
Joe Onoratodc100302011-01-11 17:07:41 -0800727 }
728
Daniel Sandler5c8da942011-06-28 00:29:04 -0400729 private View.OnClickListener mRecentsClickListener = new View.OnClickListener() {
730 public void onClick(View v) {
John Spurlockc8b46ca2013-04-08 12:59:26 -0400731 awakenDreams();
Daniel Sandler5c8da942011-06-28 00:29:04 -0400732 toggleRecentApps();
733 }
734 };
Chris Wren0c8275b2012-05-08 13:36:48 -0400735
Jim Miller9a720f52012-05-30 03:19:43 -0700736 private int mShowSearchHoldoff = 0;
737 private Runnable mShowSearchPanel = new Runnable() {
738 public void run() {
739 showSearchPanel();
Daniel Sandlera2fbe532012-08-10 01:19:03 -0400740 awakenDreams();
Jim Miller9a720f52012-05-30 03:19:43 -0700741 }
742 };
743
Jim Millere898ac52012-04-06 17:10:57 -0700744 View.OnTouchListener mHomeSearchActionListener = new View.OnTouchListener() {
745 public boolean onTouch(View v, MotionEvent event) {
746 switch(event.getAction()) {
Jim Miller9a720f52012-05-30 03:19:43 -0700747 case MotionEvent.ACTION_DOWN:
Daniel Sandlerd5483c32012-10-19 16:44:15 -0400748 if (!shouldDisableNavbarGestures()) {
Jim Miller9a720f52012-05-30 03:19:43 -0700749 mHandler.removeCallbacks(mShowSearchPanel);
750 mHandler.postDelayed(mShowSearchPanel, mShowSearchHoldoff);
751 }
752 break;
753
754 case MotionEvent.ACTION_UP:
755 case MotionEvent.ACTION_CANCEL:
756 mHandler.removeCallbacks(mShowSearchPanel);
Daniel Sandlera2fbe532012-08-10 01:19:03 -0400757 awakenDreams();
Jim Miller9a720f52012-05-30 03:19:43 -0700758 break;
759 }
760 return false;
Jim Millere898ac52012-04-06 17:10:57 -0700761 }
762 };
Daniel Sandler5c8da942011-06-28 00:29:04 -0400763
Daniel Sandlera2fbe532012-08-10 01:19:03 -0400764 private void awakenDreams() {
765 if (mDreamManager != null) {
766 try {
767 mDreamManager.awaken();
768 } catch (RemoteException e) {
769 // fine, stay asleep then
770 }
771 }
772 }
773
Michael Jurka412cba82011-10-17 09:05:00 -0700774 private void prepareNavigationBarView() {
775 mNavigationBarView.reorient();
776
777 mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener);
Michael Jurka80343f62012-10-18 13:13:46 +0200778 mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPreloadOnTouchListener);
Jim Miller998bb762012-05-21 13:37:27 -0700779 mNavigationBarView.getHomeButton().setOnTouchListener(mHomeSearchActionListener);
Daniel Sandler207d5482012-11-06 16:23:43 -0500780 mNavigationBarView.getSearchLight().setOnTouchListener(mHomeSearchActionListener);
Jim Millere898ac52012-04-06 17:10:57 -0700781 updateSearchPanel();
Michael Jurka412cba82011-10-17 09:05:00 -0700782 }
783
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400784 // For small-screen devices (read: phones) that lack hardware navigation buttons
785 private void addNavigationBar() {
John Spurlockcd686b52013-06-05 10:13:46 -0400786 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + mNavigationBarView);
Daniel Sandler0129b312011-05-11 11:54:11 -0400787 if (mNavigationBarView == null) return;
Jim Miller17dfec72011-07-08 19:09:55 -0700788
Michael Jurka412cba82011-10-17 09:05:00 -0700789 prepareNavigationBarView();
Daniel Sandler5c8da942011-06-28 00:29:04 -0400790
Jeff Brown98365d72012-08-19 20:30:52 -0700791 mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams());
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400792 }
793
794 private void repositionNavigationBar() {
Daniel Sandler0129b312011-05-11 11:54:11 -0400795 if (mNavigationBarView == null) return;
Jim Miller17dfec72011-07-08 19:09:55 -0700796
Michael Jurka412cba82011-10-17 09:05:00 -0700797 prepareNavigationBarView();
Daniel Sandler5c8da942011-06-28 00:29:04 -0400798
Jeff Brown98365d72012-08-19 20:30:52 -0700799 mWindowManager.updateViewLayout(mNavigationBarView, getNavigationBarLayoutParams());
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400800 }
801
John Spurlock1bbd49d2012-10-19 11:09:32 -0400802 private void notifyNavigationBarScreenOn(boolean screenOn) {
803 if (mNavigationBarView == null) return;
804 mNavigationBarView.notifyScreenOn(screenOn);
805 }
806
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400807 private WindowManager.LayoutParams getNavigationBarLayoutParams() {
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400808 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700809 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400810 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
811 0
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400812 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
813 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
Dianne Hackborndf89e652011-10-06 22:35:11 -0700814 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Daniel Sandlerc26185b2012-08-29 15:49:53 -0400815 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
Jim Millerd99e7fd2012-05-08 16:30:42 -0700816 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
John Spurlockad3e6cb2013-04-30 08:47:43 -0400817 PixelFormat.TRANSLUCENT);
Daniel Sandlerc638c1e2011-08-24 16:19:23 -0700818 // this will allow the navbar to run in an overlay on devices that support this
Jeff Brown98365d72012-08-19 20:30:52 -0700819 if (ActivityManager.isHighEndGfx()) {
Daniel Sandlerc638c1e2011-08-24 16:19:23 -0700820 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
821 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400822
823 lp.setTitle("NavigationBar");
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400824 lp.windowAnimations = 0;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400825 return lp;
826 }
827
Chris Wren157026f2013-06-28 16:54:01 -0400828 private void addHeadsUpView() {
Joe Onorato808182d2010-07-09 18:52:06 -0400829 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
830 ViewGroup.LayoutParams.MATCH_PARENT,
831 ViewGroup.LayoutParams.WRAP_CONTENT,
Daniel Sandlerfa7887b2012-03-26 09:43:31 -0400832 WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, // above the status bar!
Joe Onorato808182d2010-07-09 18:52:06 -0400833 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
834 | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
835 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
836 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
Jeff Brown46e75292010-11-10 16:53:45 -0800837 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
838 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
Joe Onorato808182d2010-07-09 18:52:06 -0400839 PixelFormat.TRANSLUCENT);
840 lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL;
Daniel Sandlerfa7887b2012-03-26 09:43:31 -0400841 //lp.y += height * 1.5; // FIXME
Chris Wren157026f2013-06-28 16:54:01 -0400842 lp.setTitle("Heads Up");
Dianne Hackborn59aed382011-08-02 17:31:44 -0700843 lp.packageName = mContext.getPackageName();
Chris Wren157026f2013-06-28 16:54:01 -0400844 lp.windowAnimations = R.style.Animation_StatusBar_HeadsUp;
Joe Onorato808182d2010-07-09 18:52:06 -0400845
Chris Wren157026f2013-06-28 16:54:01 -0400846 mWindowManager.addView(mHeadsUpNotificationView, lp);
Joe Onorato808182d2010-07-09 18:52:06 -0400847 }
848
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800849 public void refreshAllStatusBarIcons() {
Fabrice Di Meglioc0cea0f2013-01-11 16:18:00 -0800850 refreshAllIconsForLayout(mStatusIcons);
851 refreshAllIconsForLayout(mNotificationIcons);
852 }
853
854 private void refreshAllIconsForLayout(LinearLayout ll) {
855 final int count = ll.getChildCount();
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800856 for (int n = 0; n < count; n++) {
Fabrice Di Meglioc0cea0f2013-01-11 16:18:00 -0800857 View child = ll.getChildAt(n);
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800858 if (child instanceof StatusBarIconView) {
859 ((StatusBarIconView) child).updateDrawable();
860 }
861 }
862 }
863
Joe Onorato808182d2010-07-09 18:52:06 -0400864 public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
John Spurlockcd686b52013-06-05 10:13:46 -0400865 if (SPEW) Log.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex
Joe Onorato808182d2010-07-09 18:52:06 -0400866 + " icon=" + icon);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700867 StatusBarIconView view = new StatusBarIconView(mContext, slot, null);
Joe Onorato808182d2010-07-09 18:52:06 -0400868 view.set(icon);
869 mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(mIconSize, mIconSize));
870 }
871
872 public void updateIcon(String slot, int index, int viewIndex,
873 StatusBarIcon old, StatusBarIcon icon) {
John Spurlockcd686b52013-06-05 10:13:46 -0400874 if (SPEW) Log.d(TAG, "updateIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex
Joe Onorato808182d2010-07-09 18:52:06 -0400875 + " old=" + old + " icon=" + icon);
876 StatusBarIconView view = (StatusBarIconView)mStatusIcons.getChildAt(viewIndex);
877 view.set(icon);
878 }
879
880 public void removeIcon(String slot, int index, int viewIndex) {
John Spurlockcd686b52013-06-05 10:13:46 -0400881 if (SPEW) Log.d(TAG, "removeIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex);
Joe Onorato808182d2010-07-09 18:52:06 -0400882 mStatusIcons.removeViewAt(viewIndex);
883 }
884
885 public void addNotification(IBinder key, StatusBarNotification notification) {
John Spurlockcd686b52013-06-05 10:13:46 -0400886 if (DEBUG) Log.d(TAG, "addNotification score=" + notification.getScore());
Joe Onorato808182d2010-07-09 18:52:06 -0400887 StatusBarIconView iconView = addNotificationViews(key, notification);
888 if (iconView == null) return;
889
Chris Wren157026f2013-06-28 16:54:01 -0400890 if (mUseHeadsUp && shouldInterrupt(notification)) {
891 if (DEBUG) Log.d(TAG, "launching notification in heads up mode");
892 // 1. Populate mHeadsUpNotificationView
Joe Onorato808182d2010-07-09 18:52:06 -0400893
Daniel Sandlerfa7887b2012-03-26 09:43:31 -0400894 // bind the click event to the content area
Chris Wren157026f2013-06-28 16:54:01 -0400895 PendingIntent contentIntent = notification.getNotification().contentIntent;
Daniel Sandlerfa7887b2012-03-26 09:43:31 -0400896 final View.OnClickListener listener = (contentIntent != null)
897 ? new NotificationClicker(contentIntent,
Chris Wren157026f2013-06-28 16:54:01 -0400898 notification.getPackageName(), notification.getTag(), notification.getId())
Daniel Sandlerfa7887b2012-03-26 09:43:31 -0400899 : null;
Joe Onorato808182d2010-07-09 18:52:06 -0400900
Chris Wren157026f2013-06-28 16:54:01 -0400901 if (mHeadsUpNotificationView.applyContent(notification.getNotification(), listener)) {
Joe Onorato808182d2010-07-09 18:52:06 -0400902
Chris Wren157026f2013-06-28 16:54:01 -0400903 mCurrentlyInterruptingNotification = notification;
Jim Millere898ac52012-04-06 17:10:57 -0700904
Chris Wren157026f2013-06-28 16:54:01 -0400905 // 2. Animate mHeadsUpNotificationView in
906 mHandler.sendEmptyMessage(MSG_SHOW_HEADS_UP);
Joe Onorato808182d2010-07-09 18:52:06 -0400907
Chris Wren157026f2013-06-28 16:54:01 -0400908 // 3. Set alarm to age the notification off (TODO)
909 mHandler.removeMessages(MSG_HIDE_HEADS_UP);
910 if (HEADS_UP_DECAY_MS > 0) {
911 mHandler.sendEmptyMessageDelayed(MSG_HIDE_HEADS_UP, HEADS_UP_DECAY_MS);
912 }
Daniel Sandlerfa7887b2012-03-26 09:43:31 -0400913 }
Chris Wren157026f2013-06-28 16:54:01 -0400914 } else if (notification.getNotification().fullScreenIntent != null) {
Daniel Sandlerc9ce0ab2012-09-04 13:27:09 -0400915 // Stop screensaver if the notification has a full-screen intent.
916 // (like an incoming phone call)
917 awakenDreams();
918
Joe Onorato808182d2010-07-09 18:52:06 -0400919 // not immersive & a full-screen alert should be shown
John Spurlockcd686b52013-06-05 10:13:46 -0400920 if (DEBUG) Log.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent");
Joe Onorato808182d2010-07-09 18:52:06 -0400921 try {
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -0400922 notification.getNotification().fullScreenIntent.send();
Joe Onorato808182d2010-07-09 18:52:06 -0400923 } catch (PendingIntent.CanceledException e) {
924 }
925 } else {
926 // usual case: status bar visible & not immersive
927
Chris Wren157026f2013-06-28 16:54:01 -0400928 // show the ticker if there isn't already a heads up
929 if (mCurrentlyInterruptingNotification == null) {
Chris Wren0c8275b2012-05-08 13:36:48 -0400930 tick(null, notification, true);
Daniel Sandlerfa7887b2012-03-26 09:43:31 -0400931 }
Joe Onorato808182d2010-07-09 18:52:06 -0400932 }
933
934 // Recalculate the position of the sliding windows and the titles.
935 setAreThereNotifications();
936 updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
937 }
938
Joe Onorato808182d2010-07-09 18:52:06 -0400939 public void removeNotification(IBinder key) {
Joe Onorato808182d2010-07-09 18:52:06 -0400940 StatusBarNotification old = removeNotificationViews(key);
John Spurlockcd686b52013-06-05 10:13:46 -0400941 if (SPEW) Log.d(TAG, "removeNotification key=" + key + " old=" + old);
Joe Onorato808182d2010-07-09 18:52:06 -0400942
943 if (old != null) {
944 // Cancel the ticker if it's still running
945 mTicker.removeEntry(old);
946
947 // Recalculate the position of the sliding windows and the titles.
Joe Onorato808182d2010-07-09 18:52:06 -0400948 updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
Jim Millere898ac52012-04-06 17:10:57 -0700949
Chris Wren157026f2013-06-28 16:54:01 -0400950 if (ENABLE_HEADS_UP && old == mCurrentlyInterruptingNotification) {
951 mHandler.sendEmptyMessage(MSG_HIDE_HEADS_UP);
Daniel Sandlerfa7887b2012-03-26 09:43:31 -0400952 }
Daniel Sandler8cc36e52011-10-17 14:18:46 -0400953
Daniel Sandler37a38aa2013-02-13 17:15:57 -0500954 if (CLOSE_PANEL_WHEN_EMPTIED && mNotificationData.size() == 0) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400955 animateCollapsePanels();
Daniel Sandler8cc36e52011-10-17 14:18:46 -0400956 }
Joe Onorato808182d2010-07-09 18:52:06 -0400957 }
Daniel Sandler0761e4c2011-08-11 00:19:49 -0400958
959 setAreThereNotifications();
Joe Onorato808182d2010-07-09 18:52:06 -0400960 }
961
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700962 @Override
963 protected void refreshLayout(int layoutDirection) {
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700964 if (mNavigationBarView != null) {
965 mNavigationBarView.setLayoutDirection(layoutDirection);
966 }
967
968 if (mClearButton != null && mClearButton instanceof ImageView) {
969 // Force asset reloading
970 ((ImageView)mClearButton).setImageDrawable(null);
971 ((ImageView)mClearButton).setImageResource(R.drawable.ic_notify_clear);
972 }
973
974 if (mSettingsButton != null) {
975 // Force asset reloading
976 mSettingsButton.setImageDrawable(null);
977 mSettingsButton.setImageResource(R.drawable.ic_notify_quicksettings);
978 }
979
980 if (mNotificationButton != null) {
981 // Force asset reloading
982 mNotificationButton.setImageDrawable(null);
983 mNotificationButton.setImageResource(R.drawable.ic_notifications);
984 }
Fabrice Di Meglio82fca5d2013-01-09 15:42:31 -0800985
986 refreshAllStatusBarIcons();
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700987 }
988
John Spurlockd5ef5462012-06-13 11:19:51 -0400989 private void updateShowSearchHoldoff() {
990 mShowSearchHoldoff = mContext.getResources().getInteger(
991 R.integer.config_show_search_delay);
Michael Jurka3b1fc472011-06-13 10:54:40 -0700992 }
993
Daniel Sandler7c3e39d2011-07-29 16:30:49 -0400994 private void loadNotificationShade() {
Daniel Sandler26cda272012-05-22 15:44:08 -0400995 if (mPile == null) return;
996
Daniel Sandler7c3e39d2011-07-29 16:30:49 -0400997 int N = mNotificationData.size();
998
999 ArrayList<View> toShow = new ArrayList<View>();
1000
Daniel Sandler26cda272012-05-22 15:44:08 -04001001 final boolean provisioned = isDeviceProvisioned();
1002 // If the device hasn't been through Setup, we only show system notifications
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04001003 for (int i=0; i<N; i++) {
Daniel Sandler26cda272012-05-22 15:44:08 -04001004 Entry ent = mNotificationData.get(N-i-1);
Daniel Sandlerb9301c32012-08-14 15:08:24 -04001005 if (!(provisioned || showNotificationEvenIfUnprovisioned(ent.notification))) continue;
1006 if (!notificationIsForCurrentUser(ent.notification)) continue;
1007 toShow.add(ent.row);
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04001008 }
1009
1010 ArrayList<View> toRemove = new ArrayList<View>();
1011 for (int i=0; i<mPile.getChildCount(); i++) {
1012 View child = mPile.getChildAt(i);
1013 if (!toShow.contains(child)) {
1014 toRemove.add(child);
Joe Onorato808182d2010-07-09 18:52:06 -04001015 }
1016 }
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04001017
1018 for (View remove : toRemove) {
1019 mPile.removeView(remove);
1020 }
1021
1022 for (int i=0; i<toShow.size(); i++) {
1023 View v = toShow.get(i);
1024 if (v.getParent() == null) {
Daniel Sandler2561b0b2012-02-13 21:04:12 -05001025 mPile.addView(v, i);
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04001026 }
1027 }
Daniel Sandler26cda272012-05-22 15:44:08 -04001028
Daniel Sandler6e5fe432012-09-16 15:34:36 -04001029 if (mSettingsButton != null) {
1030 mSettingsButton.setEnabled(isDeviceProvisioned());
1031 }
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04001032 }
1033
Chris Wren0c8275b2012-05-08 13:36:48 -04001034 @Override
1035 protected void updateNotificationIcons() {
Daniel Sandler26cda272012-05-22 15:44:08 -04001036 if (mNotificationIcons == null) return;
1037
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04001038 loadNotificationShade();
1039
1040 final LinearLayout.LayoutParams params
1041 = new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight);
1042
1043 int N = mNotificationData.size();
1044
1045 if (DEBUG) {
John Spurlockcd686b52013-06-05 10:13:46 -04001046 Log.d(TAG, "refreshing icons: " + N + " notifications, mNotificationIcons=" + mNotificationIcons);
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04001047 }
1048
1049 ArrayList<View> toShow = new ArrayList<View>();
1050
Daniel Sandler26cda272012-05-22 15:44:08 -04001051 final boolean provisioned = isDeviceProvisioned();
1052 // If the device hasn't been through Setup, we only show system notifications
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04001053 for (int i=0; i<N; i++) {
Daniel Sandler58b173b2012-05-03 11:25:29 -04001054 Entry ent = mNotificationData.get(N-i-1);
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -04001055 if (!((provisioned && ent.notification.getScore() >= HIDE_ICONS_BELOW_SCORE)
Daniel Sandlerb9301c32012-08-14 15:08:24 -04001056 || showNotificationEvenIfUnprovisioned(ent.notification))) continue;
1057 if (!notificationIsForCurrentUser(ent.notification)) continue;
1058 toShow.add(ent.icon);
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04001059 }
1060
1061 ArrayList<View> toRemove = new ArrayList<View>();
1062 for (int i=0; i<mNotificationIcons.getChildCount(); i++) {
1063 View child = mNotificationIcons.getChildAt(i);
1064 if (!toShow.contains(child)) {
1065 toRemove.add(child);
1066 }
1067 }
1068
1069 for (View remove : toRemove) {
1070 mNotificationIcons.removeView(remove);
1071 }
1072
1073 for (int i=0; i<toShow.size(); i++) {
1074 View v = toShow.get(i);
1075 if (v.getParent() == null) {
1076 mNotificationIcons.addView(v, i, params);
1077 }
1078 }
1079 }
1080
Daniel Sandlere5011a32012-06-11 16:07:52 -04001081 protected void updateCarrierLabelVisibility(boolean force) {
Daniel Sandlerbf526d12012-09-04 22:56:44 -04001082 if (!mShowCarrierInPanel) return;
John Spurlock209bede2013-07-17 12:23:27 -04001083 // The idea here is to only show the carrier label when there is enough room to see it,
Daniel Sandler3d32a242012-06-05 13:44:14 -04001084 // i.e. when there aren't enough notifications to fill the panel.
1085 if (DEBUG) {
John Spurlockcd686b52013-06-05 10:13:46 -04001086 Log.d(TAG, String.format("pileh=%d scrollh=%d carrierh=%d",
Daniel Sandler3d32a242012-06-05 13:44:14 -04001087 mPile.getHeight(), mScrollView.getHeight(), mCarrierLabelHeight));
1088 }
Daniel Sandlerdd4ef492012-07-27 11:19:52 -04001089
1090 final boolean emergencyCallsShownElsewhere = mEmergencyCallLabel != null;
1091 final boolean makeVisible =
1092 !(emergencyCallsShownElsewhere && mNetworkController.isEmergencyOnly())
Daniel Sandler101784e2012-10-15 13:39:38 -04001093 && mPile.getHeight() < (mNotificationPanel.getHeight() - mCarrierLabelHeight - mNotificationHeaderHeight)
1094 && mScrollView.getVisibility() == View.VISIBLE;
John Spurlock209bede2013-07-17 12:23:27 -04001095
Daniel Sandlere5011a32012-06-11 16:07:52 -04001096 if (force || mCarrierLabelVisible != makeVisible) {
Daniel Sandler3d32a242012-06-05 13:44:14 -04001097 mCarrierLabelVisible = makeVisible;
1098 if (DEBUG) {
John Spurlockcd686b52013-06-05 10:13:46 -04001099 Log.d(TAG, "making carrier label " + (makeVisible?"visible":"invisible"));
Daniel Sandler3d32a242012-06-05 13:44:14 -04001100 }
1101 mCarrierLabel.animate().cancel();
1102 if (makeVisible) {
1103 mCarrierLabel.setVisibility(View.VISIBLE);
1104 }
1105 mCarrierLabel.animate()
1106 .alpha(makeVisible ? 1f : 0f)
1107 //.setStartDelay(makeVisible ? 500 : 0)
1108 //.setDuration(makeVisible ? 750 : 100)
1109 .setDuration(150)
1110 .setListener(makeVisible ? null : new AnimatorListenerAdapter() {
1111 @Override
1112 public void onAnimationEnd(Animator animation) {
1113 if (!mCarrierLabelVisible) { // race
1114 mCarrierLabel.setVisibility(View.INVISIBLE);
1115 mCarrierLabel.setAlpha(0f);
1116 }
1117 }
1118 })
1119 .start();
1120 }
1121 }
1122
Chris Wren0c8275b2012-05-08 13:36:48 -04001123 @Override
1124 protected void setAreThereNotifications() {
Daniel Sandler0761e4c2011-08-11 00:19:49 -04001125 final boolean any = mNotificationData.size() > 0;
Joe Onorato808182d2010-07-09 18:52:06 -04001126
Daniel Sandler0761e4c2011-08-11 00:19:49 -04001127 final boolean clearable = any && mNotificationData.hasClearableItems();
1128
1129 if (DEBUG) {
John Spurlockcd686b52013-06-05 10:13:46 -04001130 Log.d(TAG, "setAreThereNotifications: N=" + mNotificationData.size()
Daniel Sandler0761e4c2011-08-11 00:19:49 -04001131 + " any=" + any + " clearable=" + clearable);
1132 }
1133
John Spurlock209bede2013-07-17 12:23:27 -04001134 if (mHasFlipSettings
1135 && mFlipSettingsView != null
Daniel Sandlerf249efc2012-10-17 16:42:36 -04001136 && mFlipSettingsView.getVisibility() == View.VISIBLE
1137 && mScrollView.getVisibility() != View.VISIBLE) {
1138 // the flip settings panel is unequivocally showing; we should not be shown
Daniel Sandler6e2810b2012-10-17 09:40:09 -04001139 mClearButton.setVisibility(View.INVISIBLE);
1140 } else if (mClearButton.isShown()) {
Daniel Sandler0761e4c2011-08-11 00:19:49 -04001141 if (clearable != (mClearButton.getAlpha() == 1.0f)) {
Romain Guy8900e632012-05-25 12:08:39 -07001142 ObjectAnimator clearAnimation = ObjectAnimator.ofFloat(
1143 mClearButton, "alpha", clearable ? 1.0f : 0.0f).setDuration(250);
1144 clearAnimation.addListener(new AnimatorListenerAdapter() {
1145 @Override
1146 public void onAnimationEnd(Animator animation) {
1147 if (mClearButton.getAlpha() <= 0.0f) {
1148 mClearButton.setVisibility(View.INVISIBLE);
1149 }
1150 }
1151
1152 @Override
1153 public void onAnimationStart(Animator animation) {
1154 if (mClearButton.getAlpha() <= 0.0f) {
1155 mClearButton.setVisibility(View.VISIBLE);
1156 }
1157 }
1158 });
1159 clearAnimation.start();
Daniel Sandler0761e4c2011-08-11 00:19:49 -04001160 }
1161 } else {
1162 mClearButton.setAlpha(clearable ? 1.0f : 0.0f);
Romain Guy8900e632012-05-25 12:08:39 -07001163 mClearButton.setVisibility(clearable ? View.VISIBLE : View.INVISIBLE);
Daniel Sandler0761e4c2011-08-11 00:19:49 -04001164 }
Daniel Sandler8ba33c92011-10-04 21:49:30 -04001165 mClearButton.setEnabled(clearable);
Romain Guy8900e632012-05-25 12:08:39 -07001166
Daniel Sandlerd7e96862012-04-26 01:10:29 -04001167 final View nlo = mStatusBarView.findViewById(R.id.notification_lights_out);
1168 final boolean showDot = (any&&!areLightsOn());
1169 if (showDot != (nlo.getAlpha() == 1.0f)) {
1170 if (showDot) {
1171 nlo.setAlpha(0f);
1172 nlo.setVisibility(View.VISIBLE);
1173 }
1174 nlo.animate()
1175 .alpha(showDot?1:0)
1176 .setDuration(showDot?750:250)
1177 .setInterpolator(new AccelerateInterpolator(2.0f))
1178 .setListener(showDot ? null : new AnimatorListenerAdapter() {
1179 @Override
1180 public void onAnimationEnd(Animator _a) {
1181 nlo.setVisibility(View.GONE);
1182 }
1183 })
1184 .start();
1185 }
Daniel Sandler3d32a242012-06-05 13:44:14 -04001186
Daniel Sandlere5011a32012-06-11 16:07:52 -04001187 updateCarrierLabelVisibility(false);
Joe Onorato808182d2010-07-09 18:52:06 -04001188 }
1189
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001190 public void showClock(boolean show) {
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -05001191 if (mStatusBarView == null) return;
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001192 View clock = mStatusBarView.findViewById(R.id.clock);
1193 if (clock != null) {
1194 clock.setVisibility(show ? View.VISIBLE : View.GONE);
1195 }
1196 }
Joe Onorato808182d2010-07-09 18:52:06 -04001197
1198 /**
1199 * State is one or more of the DISABLE constants from StatusBarManager.
1200 */
1201 public void disable(int state) {
1202 final int old = mDisabled;
1203 final int diff = state ^ old;
1204 mDisabled = state;
1205
Daniel Sandlere21f2882011-08-18 10:14:59 -04001206 if (DEBUG) {
John Spurlockcd686b52013-06-05 10:13:46 -04001207 Log.d(TAG, String.format("disable: 0x%08x -> 0x%08x (diff: 0x%08x)",
Daniel Sandlere21f2882011-08-18 10:14:59 -04001208 old, state, diff));
1209 }
1210
Daniel Sandler6da2b762011-09-14 16:04:59 -04001211 StringBuilder flagdbg = new StringBuilder();
1212 flagdbg.append("disable: < ");
1213 flagdbg.append(((state & StatusBarManager.DISABLE_EXPAND) != 0) ? "EXPAND" : "expand");
1214 flagdbg.append(((diff & StatusBarManager.DISABLE_EXPAND) != 0) ? "* " : " ");
1215 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "ICONS" : "icons");
1216 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "* " : " ");
1217 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "ALERTS" : "alerts");
1218 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "* " : " ");
1219 flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "TICKER" : "ticker");
1220 flagdbg.append(((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "* " : " ");
1221 flagdbg.append(((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "SYSTEM_INFO" : "system_info");
1222 flagdbg.append(((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "* " : " ");
Daniel Sandler6da2b762011-09-14 16:04:59 -04001223 flagdbg.append(((state & StatusBarManager.DISABLE_BACK) != 0) ? "BACK" : "back");
1224 flagdbg.append(((diff & StatusBarManager.DISABLE_BACK) != 0) ? "* " : " ");
Daniel Sandlerdba93562011-10-06 16:39:58 -04001225 flagdbg.append(((state & StatusBarManager.DISABLE_HOME) != 0) ? "HOME" : "home");
1226 flagdbg.append(((diff & StatusBarManager.DISABLE_HOME) != 0) ? "* " : " ");
1227 flagdbg.append(((state & StatusBarManager.DISABLE_RECENT) != 0) ? "RECENT" : "recent");
1228 flagdbg.append(((diff & StatusBarManager.DISABLE_RECENT) != 0) ? "* " : " ");
Daniel Sandler6da2b762011-09-14 16:04:59 -04001229 flagdbg.append(((state & StatusBarManager.DISABLE_CLOCK) != 0) ? "CLOCK" : "clock");
1230 flagdbg.append(((diff & StatusBarManager.DISABLE_CLOCK) != 0) ? "* " : " ");
Daniel Sandlerd5483c32012-10-19 16:44:15 -04001231 flagdbg.append(((state & StatusBarManager.DISABLE_SEARCH) != 0) ? "SEARCH" : "search");
1232 flagdbg.append(((diff & StatusBarManager.DISABLE_SEARCH) != 0) ? "* " : " ");
Daniel Sandler6da2b762011-09-14 16:04:59 -04001233 flagdbg.append(">");
John Spurlockcd686b52013-06-05 10:13:46 -04001234 Log.d(TAG, flagdbg.toString());
Jim Millera073e572012-05-23 17:03:27 -07001235
Daniel Sandler8e18dc72012-05-17 00:44:59 -04001236 if ((diff & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) {
Daniel Sandler173bae22012-09-25 14:37:42 -04001237 mSystemIconArea.animate().cancel();
Daniel Sandler8e18dc72012-05-17 00:44:59 -04001238 if ((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) {
Daniel Sandler173bae22012-09-25 14:37:42 -04001239 mSystemIconArea.animate()
Daniel Sandler67e7d902012-06-06 16:32:21 -04001240 .alpha(0f)
1241 .translationY(mNaturalBarHeight*0.5f)
Daniel Sandler67e7d902012-06-06 16:32:21 -04001242 .setDuration(175)
1243 .setInterpolator(new DecelerateInterpolator(1.5f))
1244 .setListener(mMakeIconsInvisible)
1245 .start();
Daniel Sandler8e18dc72012-05-17 00:44:59 -04001246 } else {
Daniel Sandler173bae22012-09-25 14:37:42 -04001247 mSystemIconArea.setVisibility(View.VISIBLE);
1248 mSystemIconArea.animate()
Daniel Sandler67e7d902012-06-06 16:32:21 -04001249 .alpha(1f)
1250 .translationY(0)
1251 .setStartDelay(0)
1252 .setInterpolator(new DecelerateInterpolator(1.5f))
1253 .setDuration(175)
1254 .start();
Daniel Sandler8e18dc72012-05-17 00:44:59 -04001255 }
1256 }
Daniel Sandler6da2b762011-09-14 16:04:59 -04001257
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001258 if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) {
1259 boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0;
1260 showClock(show);
1261 }
Joe Onorato808182d2010-07-09 18:52:06 -04001262 if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
1263 if ((state & StatusBarManager.DISABLE_EXPAND) != 0) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04001264 animateCollapsePanels();
Joe Onorato808182d2010-07-09 18:52:06 -04001265 }
1266 }
Daniel Sandlere21f2882011-08-18 10:14:59 -04001267
Jim Miller5e6af442011-12-02 18:24:26 -08001268 if ((diff & (StatusBarManager.DISABLE_HOME
1269 | StatusBarManager.DISABLE_RECENT
Daniel Sandlerd5483c32012-10-19 16:44:15 -04001270 | StatusBarManager.DISABLE_BACK
1271 | StatusBarManager.DISABLE_SEARCH)) != 0) {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001272 // the nav bar will take care of these
Daniel Sandlerd9283b902011-09-14 21:42:00 -04001273 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state);
Daniel Sandler6da2b762011-09-14 16:04:59 -04001274
Daniel Sandlerdba93562011-10-06 16:39:58 -04001275 if ((state & StatusBarManager.DISABLE_RECENT) != 0) {
Daniel Sandler6da2b762011-09-14 16:04:59 -04001276 // close recents if it's visible
1277 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
1278 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
1279 }
Daniel Sandlere21f2882011-08-18 10:14:59 -04001280 }
1281
Joe Onorato808182d2010-07-09 18:52:06 -04001282 if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
1283 if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
Joe Onorato808182d2010-07-09 18:52:06 -04001284 if (mTicking) {
Daniel Sandlerf59a90c2012-09-28 15:33:14 -04001285 haltTicker();
Joe Onorato808182d2010-07-09 18:52:06 -04001286 }
Daniel Sandler173bae22012-09-25 14:37:42 -04001287
1288 mNotificationIcons.animate()
1289 .alpha(0f)
1290 .translationY(mNaturalBarHeight*0.5f)
1291 .setDuration(175)
1292 .setInterpolator(new DecelerateInterpolator(1.5f))
1293 .setListener(mMakeIconsInvisible)
1294 .start();
Joe Onorato808182d2010-07-09 18:52:06 -04001295 } else {
Daniel Sandler173bae22012-09-25 14:37:42 -04001296 mNotificationIcons.setVisibility(View.VISIBLE);
1297 mNotificationIcons.animate()
1298 .alpha(1f)
1299 .translationY(0)
1300 .setStartDelay(0)
1301 .setInterpolator(new DecelerateInterpolator(1.5f))
1302 .setDuration(175)
1303 .start();
Joe Onorato808182d2010-07-09 18:52:06 -04001304 }
1305 } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
1306 if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
Daniel Sandlerf59a90c2012-09-28 15:33:14 -04001307 haltTicker();
Joe Onorato808182d2010-07-09 18:52:06 -04001308 }
1309 }
1310 }
1311
Michael Jurka7f2668c2012-03-27 07:49:52 -07001312 @Override
Michael Jurkaecc395a2012-03-30 05:31:46 -07001313 protected BaseStatusBar.H createHandler() {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001314 return new PhoneStatusBar.H();
1315 }
1316
Joe Onorato808182d2010-07-09 18:52:06 -04001317 /**
1318 * All changes to the status bar and notifications funnel through here and are batched.
1319 */
Michael Jurka7f2668c2012-03-27 07:49:52 -07001320 private class H extends BaseStatusBar.H {
Joe Onorato808182d2010-07-09 18:52:06 -04001321 public void handleMessage(Message m) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001322 super.handleMessage(m);
Joe Onorato808182d2010-07-09 18:52:06 -04001323 switch (m.what) {
Daniel Sandler8ba33c92011-10-04 21:49:30 -04001324 case MSG_OPEN_NOTIFICATION_PANEL:
Daniel Sandler11cf1782012-09-27 14:03:08 -04001325 animateExpandNotificationsPanel();
Daniel Sandler8ba33c92011-10-04 21:49:30 -04001326 break;
Daniel Sandler11cf1782012-09-27 14:03:08 -04001327 case MSG_OPEN_SETTINGS_PANEL:
1328 animateExpandSettingsPanel();
1329 break;
1330 case MSG_CLOSE_PANELS:
1331 animateCollapsePanels();
Daniel Sandler8ba33c92011-10-04 21:49:30 -04001332 break;
Chris Wren157026f2013-06-28 16:54:01 -04001333 case MSG_SHOW_HEADS_UP:
1334 setHeadsUpVisibility(true);
Joe Onorato808182d2010-07-09 18:52:06 -04001335 break;
Chris Wren157026f2013-06-28 16:54:01 -04001336 case MSG_HIDE_HEADS_UP:
1337 setHeadsUpVisibility(false);
1338 mCurrentlyInterruptingNotification = null;
Joe Onorato808182d2010-07-09 18:52:06 -04001339 break;
1340 }
1341 }
1342 }
1343
Daniel Sandler040c2e42012-10-17 00:56:33 -04001344 public Handler getHandler() {
1345 return mHandler;
1346 }
1347
Joe Onorato808182d2010-07-09 18:52:06 -04001348 View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() {
1349 public void onFocusChange(View v, boolean hasFocus) {
1350 // Because 'v' is a ViewGroup, all its children will be (un)selected
1351 // too, which allows marqueeing to work.
1352 v.setSelected(hasFocus);
1353 }
1354 };
1355
Daniel Sandler08d05e32012-08-08 16:39:54 -04001356 void makeExpandedVisible(boolean revealAfterDraw) {
John Spurlockcd686b52013-06-05 10:13:46 -04001357 if (SPEW) Log.d(TAG, "Make expanded visible: expanded visible=" + mExpandedVisible);
Joe Onorato808182d2010-07-09 18:52:06 -04001358 if (mExpandedVisible) {
1359 return;
1360 }
Jim Millera073e572012-05-23 17:03:27 -07001361
Joe Onorato808182d2010-07-09 18:52:06 -04001362 mExpandedVisible = true;
Daniel Sandlere5011a32012-06-11 16:07:52 -04001363 mPile.setLayoutTransitionsEnabled(true);
John Spurlockd5ef5462012-06-13 11:19:51 -04001364 if (mNavigationBarView != null)
1365 mNavigationBarView.setSlippery(true);
Joe Onorato808182d2010-07-09 18:52:06 -04001366
Daniel Sandlere5011a32012-06-11 16:07:52 -04001367 updateCarrierLabelVisibility(true);
Daniel Sandler3d32a242012-06-05 13:44:14 -04001368
Joe Onorato808182d2010-07-09 18:52:06 -04001369 updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
Daniel Sandlera310af82012-04-24 01:20:13 -04001370
1371 // Expand the window to encompass the full screen in anticipation of the drag.
1372 // This is only possible to do atomically because the status bar is at the top of the screen!
1373 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams();
Daniel Sandler4391b0b2012-05-10 13:15:26 -04001374 lp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
1375 lp.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Daniel Sandler21b274e2012-05-02 15:07:51 -04001376 lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
Jeff Brown98365d72012-08-19 20:30:52 -07001377 mWindowManager.updateViewLayout(mStatusBarWindow, lp);
Daniel Sandlera310af82012-04-24 01:20:13 -04001378
John Spurlock804df702012-06-01 15:34:27 -04001379 // Updating the window layout will force an expensive traversal/redraw.
1380 // Kick off the reveal animation after this is complete to avoid animation latency.
1381 if (revealAfterDraw) {
Daniel Sandler08d05e32012-08-08 16:39:54 -04001382// mHandler.post(mStartRevealAnimation);
John Spurlock804df702012-06-01 15:34:27 -04001383 }
1384
Daniel Sandlera310af82012-04-24 01:20:13 -04001385 visibilityChanged(true);
John Spurlock32beb2c2013-03-11 10:16:47 -04001386
1387 suspendAutohide();
Joe Onorato808182d2010-07-09 18:52:06 -04001388 }
1389
Daniel Sandler11cf1782012-09-27 14:03:08 -04001390 public void animateCollapsePanels() {
1391 animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
Michael Jurka3b1fc472011-06-13 10:54:40 -07001392 }
1393
Daniel Sandler11cf1782012-09-27 14:03:08 -04001394 public void animateCollapsePanels(int flags) {
Joe Onorato808182d2010-07-09 18:52:06 -04001395 if (SPEW) {
John Spurlockcd686b52013-06-05 10:13:46 -04001396 Log.d(TAG, "animateCollapse():"
Joe Onorato808182d2010-07-09 18:52:06 -04001397 + " mExpandedVisible=" + mExpandedVisible
Jim Miller9a720f52012-05-30 03:19:43 -07001398 + " flags=" + flags);
Joe Onorato808182d2010-07-09 18:52:06 -04001399 }
1400
Jim Miller9a720f52012-05-30 03:19:43 -07001401 if ((flags & CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL) == 0) {
Michael Jurka3b1fc472011-06-13 10:54:40 -07001402 mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
1403 mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
1404 }
Jim Miller9a720f52012-05-30 03:19:43 -07001405
1406 if ((flags & CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL) == 0) {
1407 mHandler.removeMessages(MSG_CLOSE_SEARCH_PANEL);
1408 mHandler.sendEmptyMessage(MSG_CLOSE_SEARCH_PANEL);
1409 }
Michael Jurka3b1fc472011-06-13 10:54:40 -07001410
Daniel Sandlerac47ff72012-10-23 10:41:44 -04001411 mStatusBarWindow.cancelExpandHelper();
Daniel Sandler08d05e32012-08-08 16:39:54 -04001412 mStatusBarView.collapseAllPanels(true);
Joe Onorato808182d2010-07-09 18:52:06 -04001413 }
1414
Daniel Sandler101784e2012-10-15 13:39:38 -04001415 public ViewPropertyAnimator setVisibilityWhenDone(
1416 final ViewPropertyAnimator a, final View v, final int vis) {
1417 a.setListener(new AnimatorListenerAdapter() {
1418 @Override
1419 public void onAnimationEnd(Animator animation) {
1420 v.setVisibility(vis);
1421 a.setListener(null); // oneshot
1422 }
1423 });
1424 return a;
1425 }
1426
1427 public Animator setVisibilityWhenDone(
1428 final Animator a, final View v, final int vis) {
1429 a.addListener(new AnimatorListenerAdapter() {
1430 @Override
1431 public void onAnimationEnd(Animator animation) {
1432 v.setVisibility(vis);
1433 }
1434 });
1435 return a;
1436 }
1437
1438 public Animator interpolator(TimeInterpolator ti, Animator a) {
1439 a.setInterpolator(ti);
1440 return a;
1441 }
1442
1443 public Animator startDelay(int d, Animator a) {
1444 a.setStartDelay(d);
1445 return a;
1446 }
John Spurlock209bede2013-07-17 12:23:27 -04001447
Daniel Sandler101784e2012-10-15 13:39:38 -04001448 public Animator start(Animator a) {
1449 a.start();
1450 return a;
1451 }
1452
1453 final TimeInterpolator mAccelerateInterpolator = new AccelerateInterpolator();
1454 final TimeInterpolator mDecelerateInterpolator = new DecelerateInterpolator();
1455 final int FLIP_DURATION_OUT = 125;
1456 final int FLIP_DURATION_IN = 225;
1457 final int FLIP_DURATION = (FLIP_DURATION_IN + FLIP_DURATION_OUT);
1458
1459 Animator mScrollViewAnim, mFlipSettingsViewAnim, mNotificationButtonAnim,
1460 mSettingsButtonAnim, mClearButtonAnim;
1461
Daniel Sandler08d05e32012-08-08 16:39:54 -04001462 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -04001463 public void animateExpandNotificationsPanel() {
John Spurlockcd686b52013-06-05 10:13:46 -04001464 if (SPEW) Log.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible);
Joe Onorato808182d2010-07-09 18:52:06 -04001465 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
1466 return ;
1467 }
Joe Onorato808182d2010-07-09 18:52:06 -04001468
Daniel Sandler08d05e32012-08-08 16:39:54 -04001469 mNotificationPanel.expand();
Daniel Sandler040c2e42012-10-17 00:56:33 -04001470 if (mHasFlipSettings && mScrollView.getVisibility() != View.VISIBLE) {
1471 flipToNotifications();
Daniel Sandler101784e2012-10-15 13:39:38 -04001472 }
Joe Onorato808182d2010-07-09 18:52:06 -04001473
1474 if (false) postStartTracing();
1475 }
1476
Daniel Sandler040c2e42012-10-17 00:56:33 -04001477 public void flipToNotifications() {
1478 if (mFlipSettingsViewAnim != null) mFlipSettingsViewAnim.cancel();
1479 if (mScrollViewAnim != null) mScrollViewAnim.cancel();
1480 if (mSettingsButtonAnim != null) mSettingsButtonAnim.cancel();
1481 if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel();
1482 if (mClearButtonAnim != null) mClearButtonAnim.cancel();
1483
1484 mScrollView.setVisibility(View.VISIBLE);
1485 mScrollViewAnim = start(
1486 startDelay(FLIP_DURATION_OUT,
1487 interpolator(mDecelerateInterpolator,
1488 ObjectAnimator.ofFloat(mScrollView, View.SCALE_X, 0f, 1f)
1489 .setDuration(FLIP_DURATION_IN)
1490 )));
1491 mFlipSettingsViewAnim = start(
1492 setVisibilityWhenDone(
1493 interpolator(mAccelerateInterpolator,
1494 ObjectAnimator.ofFloat(mFlipSettingsView, View.SCALE_X, 1f, 0f)
1495 )
1496 .setDuration(FLIP_DURATION_OUT),
1497 mFlipSettingsView, View.INVISIBLE));
1498 mNotificationButtonAnim = start(
1499 setVisibilityWhenDone(
1500 ObjectAnimator.ofFloat(mNotificationButton, View.ALPHA, 0f)
1501 .setDuration(FLIP_DURATION),
1502 mNotificationButton, View.INVISIBLE));
1503 mSettingsButton.setVisibility(View.VISIBLE);
1504 mSettingsButtonAnim = start(
1505 ObjectAnimator.ofFloat(mSettingsButton, View.ALPHA, 1f)
1506 .setDuration(FLIP_DURATION));
1507 mClearButton.setVisibility(View.VISIBLE);
1508 mClearButton.setAlpha(0f);
1509 setAreThereNotifications(); // this will show/hide the button as necessary
1510 mNotificationPanel.postDelayed(new Runnable() {
1511 public void run() {
1512 updateCarrierLabelVisibility(false);
1513 }
1514 }, FLIP_DURATION - 150);
1515 }
1516
Svetoslav Ganove20a1772012-09-25 16:07:46 -07001517 @Override
Daniel Sandler11cf1782012-09-27 14:03:08 -04001518 public void animateExpandSettingsPanel() {
John Spurlockcd686b52013-06-05 10:13:46 -04001519 if (SPEW) Log.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible);
Svetoslav Ganove20a1772012-09-25 16:07:46 -07001520 if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
1521 return;
1522 }
1523
Daniel Sandlera8ef3b02012-11-29 15:52:39 -05001524 // Settings are not available in setup
1525 if (!mUserSetup) return;
1526
Daniel Sandler101784e2012-10-15 13:39:38 -04001527 if (mHasFlipSettings) {
1528 mNotificationPanel.expand();
1529 if (mFlipSettingsView.getVisibility() != View.VISIBLE) {
Daniel Sandler040c2e42012-10-17 00:56:33 -04001530 flipToSettings();
Daniel Sandler101784e2012-10-15 13:39:38 -04001531 }
1532 } else if (mSettingsPanel != null) {
1533 mSettingsPanel.expand();
1534 }
Svetoslav Ganove20a1772012-09-25 16:07:46 -07001535
1536 if (false) postStartTracing();
1537 }
1538
Daniel Sandler040c2e42012-10-17 00:56:33 -04001539 public void switchToSettings() {
Daniel Sandlera8ef3b02012-11-29 15:52:39 -05001540 // Settings are not available in setup
1541 if (!mUserSetup) return;
1542
Daniel Sandler040c2e42012-10-17 00:56:33 -04001543 mFlipSettingsView.setScaleX(1f);
1544 mFlipSettingsView.setVisibility(View.VISIBLE);
1545 mSettingsButton.setVisibility(View.GONE);
1546 mScrollView.setVisibility(View.GONE);
Daniel Sandler720a34d2012-10-18 11:44:04 -04001547 mScrollView.setScaleX(0f);
Daniel Sandler040c2e42012-10-17 00:56:33 -04001548 mNotificationButton.setVisibility(View.VISIBLE);
1549 mNotificationButton.setAlpha(1f);
1550 mClearButton.setVisibility(View.GONE);
1551 }
1552
1553 public void flipToSettings() {
Daniel Sandlera8ef3b02012-11-29 15:52:39 -05001554 // Settings are not available in setup
1555 if (!mUserSetup) return;
1556
Daniel Sandler040c2e42012-10-17 00:56:33 -04001557 if (mFlipSettingsViewAnim != null) mFlipSettingsViewAnim.cancel();
1558 if (mScrollViewAnim != null) mScrollViewAnim.cancel();
1559 if (mSettingsButtonAnim != null) mSettingsButtonAnim.cancel();
1560 if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel();
1561 if (mClearButtonAnim != null) mClearButtonAnim.cancel();
1562
1563 mFlipSettingsView.setVisibility(View.VISIBLE);
1564 mFlipSettingsView.setScaleX(0f);
1565 mFlipSettingsViewAnim = start(
1566 startDelay(FLIP_DURATION_OUT,
1567 interpolator(mDecelerateInterpolator,
1568 ObjectAnimator.ofFloat(mFlipSettingsView, View.SCALE_X, 0f, 1f)
1569 .setDuration(FLIP_DURATION_IN)
1570 )));
1571 mScrollViewAnim = start(
1572 setVisibilityWhenDone(
1573 interpolator(mAccelerateInterpolator,
1574 ObjectAnimator.ofFloat(mScrollView, View.SCALE_X, 1f, 0f)
1575 )
John Spurlock209bede2013-07-17 12:23:27 -04001576 .setDuration(FLIP_DURATION_OUT),
Daniel Sandler040c2e42012-10-17 00:56:33 -04001577 mScrollView, View.INVISIBLE));
1578 mSettingsButtonAnim = start(
1579 setVisibilityWhenDone(
1580 ObjectAnimator.ofFloat(mSettingsButton, View.ALPHA, 0f)
1581 .setDuration(FLIP_DURATION),
1582 mScrollView, View.INVISIBLE));
1583 mNotificationButton.setVisibility(View.VISIBLE);
1584 mNotificationButtonAnim = start(
1585 ObjectAnimator.ofFloat(mNotificationButton, View.ALPHA, 1f)
1586 .setDuration(FLIP_DURATION));
1587 mClearButtonAnim = start(
1588 setVisibilityWhenDone(
1589 ObjectAnimator.ofFloat(mClearButton, View.ALPHA, 0f)
1590 .setDuration(FLIP_DURATION),
1591 mClearButton, View.INVISIBLE));
1592 mNotificationPanel.postDelayed(new Runnable() {
1593 public void run() {
1594 updateCarrierLabelVisibility(false);
1595 }
1596 }, FLIP_DURATION - 150);
1597 }
1598
1599 public void flipPanels() {
1600 if (mHasFlipSettings) {
1601 if (mFlipSettingsView.getVisibility() != View.VISIBLE) {
1602 flipToSettings();
1603 } else {
1604 flipToNotifications();
1605 }
1606 }
1607 }
1608
Svetoslav Ganove20a1772012-09-25 16:07:46 -07001609 public void animateCollapseQuickSettings() {
1610 mStatusBarView.collapseAllPanels(true);
1611 }
1612
Daniel Sandler6e2810b2012-10-17 09:40:09 -04001613 void makeExpandedInvisibleSoon() {
1614 mHandler.postDelayed(new Runnable() { public void run() { makeExpandedInvisible(); }}, 50);
1615 }
1616
Daniel Sandler08d05e32012-08-08 16:39:54 -04001617 void makeExpandedInvisible() {
John Spurlockcd686b52013-06-05 10:13:46 -04001618 if (SPEW) Log.d(TAG, "makeExpandedInvisible: mExpandedVisible=" + mExpandedVisible
Joe Onorato808182d2010-07-09 18:52:06 -04001619 + " mExpandedVisible=" + mExpandedVisible);
1620
1621 if (!mExpandedVisible) {
1622 return;
1623 }
Daniel Sandlered930e52012-07-03 14:31:22 -04001624
Daniel Sandlerc38bbc32012-10-05 12:21:38 -04001625 // Ensure the panel is fully collapsed (just in case; bug 6765842, 7260868)
1626 mStatusBarView.collapseAllPanels(/*animate=*/ false);
Daniel Sandlered930e52012-07-03 14:31:22 -04001627
Daniel Sandler040c2e42012-10-17 00:56:33 -04001628 if (mHasFlipSettings) {
1629 // reset things to their proper state
Daniel Sandler50bc4f52012-10-22 14:47:55 -04001630 if (mFlipSettingsViewAnim != null) mFlipSettingsViewAnim.cancel();
1631 if (mScrollViewAnim != null) mScrollViewAnim.cancel();
1632 if (mSettingsButtonAnim != null) mSettingsButtonAnim.cancel();
1633 if (mNotificationButtonAnim != null) mNotificationButtonAnim.cancel();
1634 if (mClearButtonAnim != null) mClearButtonAnim.cancel();
1635
Daniel Sandler040c2e42012-10-17 00:56:33 -04001636 mScrollView.setScaleX(1f);
1637 mScrollView.setVisibility(View.VISIBLE);
1638 mSettingsButton.setAlpha(1f);
1639 mSettingsButton.setVisibility(View.VISIBLE);
1640 mNotificationPanel.setVisibility(View.GONE);
1641 mFlipSettingsView.setVisibility(View.GONE);
1642 mNotificationButton.setVisibility(View.GONE);
1643 setAreThereNotifications(); // show the clear button
1644 }
1645
Joe Onorato808182d2010-07-09 18:52:06 -04001646 mExpandedVisible = false;
Daniel Sandlere5011a32012-06-11 16:07:52 -04001647 mPile.setLayoutTransitionsEnabled(false);
John Spurlockd5ef5462012-06-13 11:19:51 -04001648 if (mNavigationBarView != null)
1649 mNavigationBarView.setSlippery(false);
Joe Onorato808182d2010-07-09 18:52:06 -04001650 visibilityChanged(false);
Daniel Sandlera310af82012-04-24 01:20:13 -04001651
1652 // Shrink the window to the size of the status bar only
1653 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams();
1654 lp.height = getStatusBarHeight();
Daniel Sandler4391b0b2012-05-10 13:15:26 -04001655 lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
1656 lp.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
Jeff Brown98365d72012-08-19 20:30:52 -07001657 mWindowManager.updateViewLayout(mStatusBarWindow, lp);
Joe Onorato808182d2010-07-09 18:52:06 -04001658
1659 if ((mDisabled & StatusBarManager.DISABLE_NOTIFICATION_ICONS) == 0) {
1660 setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in);
1661 }
Joe Onorato808182d2010-07-09 18:52:06 -04001662
Daniel Sandler469e96e2012-05-04 15:56:19 -04001663 // Close any "App info" popups that might have snuck on-screen
1664 dismissPopups();
1665
Chet Haase2f2022a2011-10-11 06:41:59 -07001666 if (mPostCollapseCleanup != null) {
1667 mPostCollapseCleanup.run();
1668 mPostCollapseCleanup = null;
1669 }
John Spurlock32beb2c2013-03-11 10:16:47 -04001670
1671 // Reschedule suspended auto-hide if necessary
John Spurlockad3e6cb2013-04-30 08:47:43 -04001672 resumeAutohide();
Joe Onorato808182d2010-07-09 18:52:06 -04001673 }
1674
Romain Guy54ab3472012-06-14 12:52:53 -07001675 /**
1676 * Enables or disables layers on the children of the notifications pile.
John Spurlock209bede2013-07-17 12:23:27 -04001677 *
Romain Guy54ab3472012-06-14 12:52:53 -07001678 * When layers are enabled, this method attempts to enable layers for the minimal
1679 * number of children. Only children visible when the notification area is fully
1680 * expanded will receive a layer. The technique used in this method might cause
1681 * more children than necessary to get a layer (at most one extra child with the
1682 * current UI.)
John Spurlock209bede2013-07-17 12:23:27 -04001683 *
Romain Guy54ab3472012-06-14 12:52:53 -07001684 * @param layerType {@link View#LAYER_TYPE_NONE} or {@link View#LAYER_TYPE_HARDWARE}
1685 */
1686 private void setPileLayers(int layerType) {
1687 final int count = mPile.getChildCount();
1688
1689 switch (layerType) {
1690 case View.LAYER_TYPE_NONE:
1691 for (int i = 0; i < count; i++) {
1692 mPile.getChildAt(i).setLayerType(layerType, null);
1693 }
1694 break;
1695 case View.LAYER_TYPE_HARDWARE:
John Spurlock209bede2013-07-17 12:23:27 -04001696 final int[] location = new int[2];
Romain Guy54ab3472012-06-14 12:52:53 -07001697 mNotificationPanel.getLocationInWindow(location);
1698
1699 final int left = location[0];
1700 final int top = location[1];
1701 final int right = left + mNotificationPanel.getWidth();
1702 final int bottom = top + getExpandedViewMaxHeight();
1703
1704 final Rect childBounds = new Rect();
1705
1706 for (int i = 0; i < count; i++) {
1707 final View view = mPile.getChildAt(i);
1708 view.getLocationInWindow(location);
1709
1710 childBounds.set(location[0], location[1],
1711 location[0] + view.getWidth(), location[1] + view.getHeight());
1712
1713 if (childBounds.intersects(left, top, right, bottom)) {
1714 view.setLayerType(layerType, null);
1715 }
1716 }
1717
1718 break;
1719 }
1720 }
1721
Daniel Sandlerb17a7262012-10-05 14:32:50 -04001722 public boolean isClinging() {
1723 return mCling != null && mCling.getVisibility() == View.VISIBLE;
1724 }
1725
1726 public void hideCling() {
1727 if (isClinging()) {
1728 mCling.animate().alpha(0f).setDuration(250).start();
1729 mCling.setVisibility(View.GONE);
1730 mSuppressStatusBarDrags = false;
1731 }
1732 }
1733
1734 public void showCling() {
Daniel Sandler118f4842012-10-07 20:38:39 -04001735 // lazily inflate this to accommodate orientation change
1736 final ViewStub stub = (ViewStub) mStatusBarWindow.findViewById(R.id.status_bar_cling_stub);
1737 if (stub == null) {
1738 mClingShown = true;
1739 return; // no clings on this device
1740 }
1741
Daniel Sandlerb17a7262012-10-05 14:32:50 -04001742 mSuppressStatusBarDrags = true;
1743
1744 mHandler.postDelayed(new Runnable() {
1745 @Override
1746 public void run() {
Daniel Sandlerb17a7262012-10-05 14:32:50 -04001747 mCling = (ViewGroup) stub.inflate();
Daniel Sandler118f4842012-10-07 20:38:39 -04001748
Daniel Sandlerb17a7262012-10-05 14:32:50 -04001749 mCling.setOnTouchListener(new View.OnTouchListener() {
1750 @Override
1751 public boolean onTouch(View v, MotionEvent event) {
1752 return true; // e eats everything
1753 }});
1754 mCling.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
1755 @Override
1756 public void onClick(View v) {
1757 hideCling();
1758 }});
1759
1760 mCling.setAlpha(0f);
1761 mCling.setVisibility(View.VISIBLE);
1762 mCling.animate().alpha(1f);
1763
1764 mClingShown = true;
1765 SharedPreferences.Editor editor = Prefs.edit(mContext);
1766 editor.putBoolean(Prefs.SHOWN_QUICK_SETTINGS_HELP, true);
1767 editor.apply();
1768
1769 makeExpandedVisible(true); // enforce visibility in case the shade is still animating closed
1770 animateExpandNotificationsPanel();
1771
1772 mSuppressStatusBarDrags = false;
1773 }
1774 }, 500);
1775
1776 animateExpandNotificationsPanel();
1777 }
1778
1779 public boolean interceptTouchEvent(MotionEvent event) {
Chris Wren64161cc2012-12-17 16:49:30 -05001780 if (DEBUG_GESTURES) {
1781 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
1782 EventLog.writeEvent(EventLogTags.SYSUI_STATUSBAR_TOUCH,
1783 event.getActionMasked(), (int) event.getX(), (int) event.getY(), mDisabled);
1784 }
1785
1786 }
1787
Joe Onorato808182d2010-07-09 18:52:06 -04001788 if (SPEW) {
John Spurlockcd686b52013-06-05 10:13:46 -04001789 Log.d(TAG, "Touch: rawY=" + event.getRawY() + " event=" + event + " mDisabled="
John Spurlock804df702012-06-01 15:34:27 -04001790 + mDisabled + " mTracking=" + mTracking);
Daniel Sandler96e61c3c82011-08-04 22:49:06 -04001791 } else if (CHATTY) {
Daniel Sandlerfe172cc2011-09-12 13:47:25 -04001792 if (event.getAction() != MotionEvent.ACTION_MOVE) {
John Spurlockcd686b52013-06-05 10:13:46 -04001793 Log.d(TAG, String.format(
Daniel Sandlerfe172cc2011-09-12 13:47:25 -04001794 "panel: %s at (%f, %f) mDisabled=0x%08x",
1795 MotionEvent.actionToString(event.getAction()),
Daniel Sandler96e61c3c82011-08-04 22:49:06 -04001796 event.getRawX(), event.getRawY(), mDisabled));
1797 }
Joe Onorato808182d2010-07-09 18:52:06 -04001798 }
1799
Daniel Sandler151f00d2012-10-02 22:33:08 -04001800 if (DEBUG_GESTURES) {
1801 mGestureRec.add(event);
1802 }
Daniel Sandler33805342012-07-23 15:45:12 -04001803
Daniel Sandlerb17a7262012-10-05 14:32:50 -04001804 // Cling (first-run help) handling.
1805 // The cling is supposed to show the first time you drag, or even tap, the status bar.
John Spurlock209bede2013-07-17 12:23:27 -04001806 // It should show the notification panel, then fade in after half a second, giving you
Daniel Sandlerb17a7262012-10-05 14:32:50 -04001807 // an explanation of what just happened, as well as teach you how to access quick
John Spurlock209bede2013-07-17 12:23:27 -04001808 // settings (another drag). The user can dismiss the cling by clicking OK or by
Daniel Sandlerb17a7262012-10-05 14:32:50 -04001809 // dragging quick settings into view.
1810 final int act = event.getActionMasked();
1811 if (mSuppressStatusBarDrags) {
1812 return true;
1813 } else if (act == MotionEvent.ACTION_UP && !mClingShown) {
1814 showCling();
1815 } else {
1816 hideCling();
1817 }
1818
John Spurlock32beb2c2013-03-11 10:16:47 -04001819 suspendAutohide();
Joe Onorato808182d2010-07-09 18:52:06 -04001820 return false;
1821 }
1822
Daniel Sandler08d05e32012-08-08 16:39:54 -04001823 public GestureRecorder getGestureRecorder() {
1824 return mGestureRec;
Jeff Brown911fe302011-09-12 14:21:17 -07001825 }
1826
Daniel Sandler60ee2562011-07-22 12:34:33 -04001827 @Override // CommandQueue
Daniel Sandler328310c2011-09-23 15:56:52 -04001828 public void setNavigationIconHints(int hints) {
1829 if (hints == mNavigationIconHints) return;
1830
1831 mNavigationIconHints = hints;
1832
1833 if (mNavigationBarView != null) {
1834 mNavigationBarView.setNavigationIconHints(hints);
1835 }
1836 }
1837
1838 @Override // CommandQueue
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07001839 public void setSystemUiVisibility(int vis, int mask) {
1840 final int oldVal = mSystemUiVisibility;
1841 final int newVal = (oldVal&~mask) | (vis&mask);
1842 final int diff = newVal ^ oldVal;
John Spurlockcd686b52013-06-05 10:13:46 -04001843 if (DEBUG) Log.d(TAG, String.format(
John Spurlockdcf4f212013-05-21 17:19:53 -04001844 "setSystemUiVisibility vis=%s mask=%s oldVal=%s newVal=%s diff=%s",
1845 Integer.toHexString(vis), Integer.toHexString(mask),
1846 Integer.toHexString(oldVal), Integer.toHexString(newVal),
1847 Integer.toHexString(diff)));
Daniel Sandlere137a1e2011-08-17 16:47:19 -04001848 if (diff != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07001849 mSystemUiVisibility = newVal;
Daniel Sandler60ee2562011-07-22 12:34:33 -04001850
Daniel Sandlere137a1e2011-08-17 16:47:19 -04001851 if (0 != (diff & View.SYSTEM_UI_FLAG_LOW_PROFILE)) {
1852 final boolean lightsOut = (0 != (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE));
1853 if (lightsOut) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04001854 animateCollapsePanels();
Daniel Sandlerd7e96862012-04-26 01:10:29 -04001855 if (mTicking) {
Daniel Sandlerf59a90c2012-09-28 15:33:14 -04001856 haltTicker();
Daniel Sandlerd7e96862012-04-26 01:10:29 -04001857 }
Daniel Sandlere137a1e2011-08-17 16:47:19 -04001858 }
Jim Millera073e572012-05-23 17:03:27 -07001859
Daniel Sandler69314e72011-08-20 00:31:08 -04001860 if (mNavigationBarView != null) {
1861 mNavigationBarView.setLowProfile(lightsOut);
1862 }
Jim Millera073e572012-05-23 17:03:27 -07001863
Daniel Sandlerd7e96862012-04-26 01:10:29 -04001864 setStatusBarLowProfile(lightsOut);
Daniel Sandler60ee2562011-07-22 12:34:33 -04001865 }
1866
John Spurlockad3e6cb2013-04-30 08:47:43 -04001867 boolean sbOverlayChanged = 0 != (diff & View.STATUS_BAR_OVERLAY);
1868 boolean nbOverlayChanged = 0 != (diff & View.NAVIGATION_BAR_OVERLAY);
1869 if (sbOverlayChanged || nbOverlayChanged) {
1870 boolean sbOverlay = 0 != (vis & View.STATUS_BAR_OVERLAY);
1871 boolean nbOverlay = 0 != (vis & View.NAVIGATION_BAR_OVERLAY);
1872 if (sbOverlayChanged) {
1873 setTransparent(mStatusBarView, sbOverlay);
1874 }
1875 if (nbOverlayChanged) {
1876 setTransparent(mNavigationBarView, nbOverlay);
1877 }
1878 if (sbOverlayChanged && sbOverlay || nbOverlayChanged && nbOverlay) {
John Spurlock32beb2c2013-03-11 10:16:47 -04001879 scheduleAutohide();
1880 } else {
John Spurlock32beb2c2013-03-11 10:16:47 -04001881 cancelAutohide();
1882 }
1883 }
John Spurlockdcf4f212013-05-21 17:19:53 -04001884 if (mNavigationBarView != null) {
1885 int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_ALLOW_OVERLAY;
1886 boolean oldVisible = (oldVal & flags) == flags;
1887 boolean newVisible = (newVal & flags) == flags;
1888 if (!oldVisible && newVisible) {
1889 mHideybarConfirmationDismissed = false;
1890 }
1891 setHideybarConfirmationVisible(newVisible);
1892 }
John Spurlock32beb2c2013-03-11 10:16:47 -04001893 notifyUiVisibilityChanged(mSystemUiVisibility);
Joe Onorato93056472010-09-10 10:30:46 -04001894 }
Daniel Sandler1d4d30a2011-04-28 12:35:29 -04001895 }
1896
John Spurlockdcf4f212013-05-21 17:19:53 -04001897 private void dismissHideybarConfirmation() {
1898 if (mHideybarConfirmation != null) {
1899 mHideybarConfirmationDismissed = true;
1900 mHideybarConfirmation.cancel();
1901 mHideybarConfirmation = null;
1902 }
1903 }
1904
1905 private void setHideybarConfirmationVisible(boolean visible) {
John Spurlockcd686b52013-06-05 10:13:46 -04001906 if (DEBUG) Log.d(TAG, "setHideybarConfirmationVisible " + visible);
John Spurlockdcf4f212013-05-21 17:19:53 -04001907 if (visible && mHideybarConfirmation == null && !mHideybarConfirmationDismissed) {
John Spurlocke804cb52013-06-14 13:59:31 -04001908 // create the confirmation toast bar
1909 int msg = R.string.hideybar_confirmation_message;
John Spurlockdcf4f212013-05-21 17:19:53 -04001910 mHideybarConfirmation = Toast.makeBar(mContext, msg, Toast.LENGTH_INFINITE)
1911 .setAction(com.android.internal.R.string.ok, mHideybarConfirmationAction);
1912 View v = mHideybarConfirmation.getView();
John Spurlock743356a2013-06-15 11:58:08 -04001913 v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
John Spurlockdcf4f212013-05-21 17:19:53 -04001914 boolean isGloballyConfirmed = Prefs.read(mContext)
1915 .getBoolean(Prefs.HIDEYBAR_CONFIRMED, false);
1916 if (isGloballyConfirmed) {
1917 // dismiss on outside touch if globally confirmed
1918 v.setOnTouchListener(mDismissHideybarConfirmationOnTouchOutside);
1919 }
John Spurlock743356a2013-06-15 11:58:08 -04001920 // position at the bottom like normal toasts, but use top gravity
1921 // to avoid jumping around when showing/hiding the nav bar
1922 v.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
1923 int offsetY = mContext.getResources().getDimensionPixelSize(
1924 com.android.internal.R.dimen.toast_y_offset);
1925 mHideybarConfirmation.setGravity(Gravity.TOP,
1926 0, mCurrentDisplaySize.y - v.getMeasuredHeight() / 2 - offsetY);
John Spurlockdcf4f212013-05-21 17:19:53 -04001927 // show the confirmation
1928 mHideybarConfirmation.show();
1929 } else if (!visible) {
1930 dismissHideybarConfirmation();
1931 }
1932 }
1933
John Spurlockad3e6cb2013-04-30 08:47:43 -04001934 @Override
1935 public void resumeAutohide() {
1936 if (mAutohideSuspended) {
1937 scheduleAutohide();
1938 }
1939 }
1940
1941 @Override
1942 public void suspendAutohide() {
John Spurlock32beb2c2013-03-11 10:16:47 -04001943 mHandler.removeCallbacks(mAutohide);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001944 mAutohideSuspended = 0 != (mSystemUiVisibility & STATUS_OR_NAV_OVERLAY);
John Spurlock32beb2c2013-03-11 10:16:47 -04001945 }
1946
1947 private void cancelAutohide() {
1948 mAutohideSuspended = false;
1949 mHandler.removeCallbacks(mAutohide);
1950 }
1951
1952 private void scheduleAutohide() {
1953 cancelAutohide();
1954 mHandler.postDelayed(mAutohide, AUTOHIDE_TIMEOUT_MS);
1955 }
1956
John Spurlockad3e6cb2013-04-30 08:47:43 -04001957 private void setTransparent(View view, boolean transparent) {
John Spurlock32beb2c2013-03-11 10:16:47 -04001958 float alpha = transparent ? TRANSPARENT_ALPHA : 1;
John Spurlockcd686b52013-06-05 10:13:46 -04001959 if (DEBUG) Log.d(TAG, "Setting " + (view == mStatusBarView ? "status bar" :
John Spurlockad3e6cb2013-04-30 08:47:43 -04001960 view == mNavigationBarView ? "navigation bar" : "view") + " alpha to " + alpha);
1961 view.setAlpha(alpha);
John Spurlock32beb2c2013-03-11 10:16:47 -04001962 }
1963
Daniel Sandlerd7e96862012-04-26 01:10:29 -04001964 private void setStatusBarLowProfile(boolean lightsOut) {
1965 if (mLightsOutAnimation == null) {
Daniel Sandler825b3302012-10-01 15:22:36 -04001966 final View notifications = mStatusBarView.findViewById(R.id.notification_icon_area);
1967 final View systemIcons = mStatusBarView.findViewById(R.id.statusIcons);
1968 final View signal = mStatusBarView.findViewById(R.id.signal_cluster);
1969 final View battery = mStatusBarView.findViewById(R.id.battery);
1970 final View clock = mStatusBarView.findViewById(R.id.clock);
Jim Millera073e572012-05-23 17:03:27 -07001971
Daniel Sandler825b3302012-10-01 15:22:36 -04001972 final AnimatorSet lightsOutAnim = new AnimatorSet();
1973 lightsOutAnim.playTogether(
1974 ObjectAnimator.ofFloat(notifications, View.ALPHA, 0),
1975 ObjectAnimator.ofFloat(systemIcons, View.ALPHA, 0),
1976 ObjectAnimator.ofFloat(signal, View.ALPHA, 0),
1977 ObjectAnimator.ofFloat(battery, View.ALPHA, 0.5f),
1978 ObjectAnimator.ofFloat(clock, View.ALPHA, 0.5f)
1979 );
1980 lightsOutAnim.setDuration(750);
1981
1982 final AnimatorSet lightsOnAnim = new AnimatorSet();
1983 lightsOnAnim.playTogether(
1984 ObjectAnimator.ofFloat(notifications, View.ALPHA, 1),
1985 ObjectAnimator.ofFloat(systemIcons, View.ALPHA, 1),
1986 ObjectAnimator.ofFloat(signal, View.ALPHA, 1),
1987 ObjectAnimator.ofFloat(battery, View.ALPHA, 1),
1988 ObjectAnimator.ofFloat(clock, View.ALPHA, 1)
1989 );
1990 lightsOnAnim.setDuration(250);
1991
1992 mLightsOutAnimation = lightsOutAnim;
1993 mLightsOnAnimation = lightsOnAnim;
Daniel Sandlerd7e96862012-04-26 01:10:29 -04001994 }
Jim Millera073e572012-05-23 17:03:27 -07001995
Daniel Sandlerd7e96862012-04-26 01:10:29 -04001996 mLightsOutAnimation.cancel();
1997 mLightsOnAnimation.cancel();
1998
1999 final Animator a = lightsOut ? mLightsOutAnimation : mLightsOnAnimation;
2000 a.start();
2001
2002 setAreThereNotifications();
2003 }
2004
2005 private boolean areLightsOn() {
2006 return 0 == (mSystemUiVisibility & View.SYSTEM_UI_FLAG_LOW_PROFILE);
2007 }
Jim Millera073e572012-05-23 17:03:27 -07002008
Daniel Sandler60ee2562011-07-22 12:34:33 -04002009 public void setLightsOn(boolean on) {
2010 Log.v(TAG, "setLightsOn(" + on + ")");
2011 if (on) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002012 setSystemUiVisibility(0, View.SYSTEM_UI_FLAG_LOW_PROFILE);
Daniel Sandler60ee2562011-07-22 12:34:33 -04002013 } else {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002014 setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE, View.SYSTEM_UI_FLAG_LOW_PROFILE);
Daniel Sandler60ee2562011-07-22 12:34:33 -04002015 }
2016 }
2017
John Spurlock32beb2c2013-03-11 10:16:47 -04002018 private void notifyUiVisibilityChanged(int vis) {
Daniel Sandler1d4d30a2011-04-28 12:35:29 -04002019 try {
John Spurlock32beb2c2013-03-11 10:16:47 -04002020 mWindowManagerService.statusBarVisibilityChanged(vis);
Daniel Sandler1d4d30a2011-04-28 12:35:29 -04002021 } catch (RemoteException ex) {
2022 }
Joe Onorato93056472010-09-10 10:30:46 -04002023 }
2024
Daniel Sandler5c8da942011-06-28 00:29:04 -04002025 public void topAppWindowChanged(boolean showMenu) {
2026 if (DEBUG) {
John Spurlockcd686b52013-06-05 10:13:46 -04002027 Log.d(TAG, (showMenu?"showing":"hiding") + " the MENU button");
Daniel Sandler5c8da942011-06-28 00:29:04 -04002028 }
2029 if (mNavigationBarView != null) {
Daniel Sandlerf1ebcee2011-09-15 16:02:56 -04002030 mNavigationBarView.setMenuVisibility(showMenu);
Daniel Sandler5c8da942011-06-28 00:29:04 -04002031 }
2032
2033 // See above re: lights-out policy for legacy apps.
2034 if (showMenu) setLightsOn(true);
2035 }
2036
Daniel Sandler328310c2011-09-23 15:56:52 -04002037 @Override
2038 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
2039 boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS)
2040 || ((vis & InputMethodService.IME_VISIBLE) != 0);
2041
2042 mCommandQueue.setNavigationIconHints(
2043 altBack ? (mNavigationIconHints | StatusBarManager.NAVIGATION_HINT_BACK_ALT)
2044 : (mNavigationIconHints & ~StatusBarManager.NAVIGATION_HINT_BACK_ALT));
Daniel Sandler101784e2012-10-15 13:39:38 -04002045 if (mQS != null) mQS.setImeWindowStatus(vis > 0);
Daniel Sandler328310c2011-09-23 15:56:52 -04002046 }
2047
Jeff Brown2992ea72011-01-28 22:04:14 -08002048 @Override
Winson Chung43229d72012-09-12 18:04:18 -07002049 public void setHardKeyboardStatus(boolean available, boolean enabled) {}
Daniel Sandlere02d8082010-10-08 15:13:22 -04002050
Chris Wren0c8275b2012-05-08 13:36:48 -04002051 @Override
2052 protected void tick(IBinder key, StatusBarNotification n, boolean firstTime) {
Daniel Sandlerd7e96862012-04-26 01:10:29 -04002053 // no ticking in lights-out mode
2054 if (!areLightsOn()) return;
Jim Millera073e572012-05-23 17:03:27 -07002055
Daniel Sandler26cda272012-05-22 15:44:08 -04002056 // no ticking in Setup
2057 if (!isDeviceProvisioned()) return;
2058
John Spurlock61e36832012-09-10 09:43:27 -04002059 // not for you
2060 if (!notificationIsForCurrentUser(n)) return;
2061
Joe Onorato808182d2010-07-09 18:52:06 -04002062 // Show the ticker if one is requested. Also don't do this
2063 // until status bar window is attached to the window manager,
2064 // because... well, what's the point otherwise? And trying to
2065 // run a ticker without being attached will crash!
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -04002066 if (n.getNotification().tickerText != null && mStatusBarWindow.getWindowToken() != null) {
Joe Onorato808182d2010-07-09 18:52:06 -04002067 if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS
2068 | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) {
2069 mTicker.addEntry(n);
2070 }
2071 }
2072 }
2073
Joe Onorato808182d2010-07-09 18:52:06 -04002074 private class MyTicker extends Ticker {
Daniel Sandlerdfa08db2010-08-05 16:18:42 -04002075 MyTicker(Context context, View sb) {
Joe Onorato808182d2010-07-09 18:52:06 -04002076 super(context, sb);
2077 }
2078
2079 @Override
Daniel Sandlerdfa08db2010-08-05 16:18:42 -04002080 public void tickerStarting() {
Joe Onorato808182d2010-07-09 18:52:06 -04002081 mTicking = true;
Daniel Sandler173bae22012-09-25 14:37:42 -04002082 mStatusBarContents.setVisibility(View.GONE);
Joe Onorato808182d2010-07-09 18:52:06 -04002083 mTickerView.setVisibility(View.VISIBLE);
2084 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_up_in, null));
Daniel Sandler173bae22012-09-25 14:37:42 -04002085 mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.push_up_out, null));
Joe Onorato808182d2010-07-09 18:52:06 -04002086 }
2087
2088 @Override
Daniel Sandlerdfa08db2010-08-05 16:18:42 -04002089 public void tickerDone() {
Daniel Sandler173bae22012-09-25 14:37:42 -04002090 mStatusBarContents.setVisibility(View.VISIBLE);
Joe Onorato808182d2010-07-09 18:52:06 -04002091 mTickerView.setVisibility(View.GONE);
Daniel Sandler173bae22012-09-25 14:37:42 -04002092 mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.push_down_in, null));
Joe Onorato808182d2010-07-09 18:52:06 -04002093 mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_down_out,
2094 mTickingDoneListener));
Joe Onorato808182d2010-07-09 18:52:06 -04002095 }
2096
Daniel Sandlerdfa08db2010-08-05 16:18:42 -04002097 public void tickerHalting() {
Daniel Sandler173bae22012-09-25 14:37:42 -04002098 mStatusBarContents.setVisibility(View.VISIBLE);
Joe Onorato808182d2010-07-09 18:52:06 -04002099 mTickerView.setVisibility(View.GONE);
Daniel Sandler173bae22012-09-25 14:37:42 -04002100 mStatusBarContents.startAnimation(loadAnim(com.android.internal.R.anim.fade_in, null));
Daniel Sandlerf59a90c2012-09-28 15:33:14 -04002101 // we do not animate the ticker away at this point, just get rid of it (b/6992707)
Joe Onorato808182d2010-07-09 18:52:06 -04002102 }
2103 }
2104
2105 Animation.AnimationListener mTickingDoneListener = new Animation.AnimationListener() {;
2106 public void onAnimationEnd(Animation animation) {
2107 mTicking = false;
2108 }
2109 public void onAnimationRepeat(Animation animation) {
2110 }
2111 public void onAnimationStart(Animation animation) {
2112 }
2113 };
2114
2115 private Animation loadAnim(int id, Animation.AnimationListener listener) {
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04002116 Animation anim = AnimationUtils.loadAnimation(mContext, id);
Joe Onorato808182d2010-07-09 18:52:06 -04002117 if (listener != null) {
2118 anim.setAnimationListener(listener);
2119 }
2120 return anim;
2121 }
2122
Daniel Sandler48852952011-12-01 14:34:23 -05002123 public static String viewInfo(View v) {
2124 return "[(" + v.getLeft() + "," + v.getTop() + ")(" + v.getRight() + "," + v.getBottom()
2125 + ") " + v.getWidth() + "x" + v.getHeight() + "]";
Joe Onorato808182d2010-07-09 18:52:06 -04002126 }
2127
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04002128 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Joe Onorato808182d2010-07-09 18:52:06 -04002129 synchronized (mQueueLock) {
2130 pw.println("Current Status Bar state:");
Daniel Sandlere7237fc2012-08-14 16:08:27 -04002131 pw.println(" mExpandedVisible=" + mExpandedVisible
Daniel Sandlerfdbac772012-07-03 14:30:10 -04002132 + ", mTrackingPosition=" + mTrackingPosition);
Joe Onorato808182d2010-07-09 18:52:06 -04002133 pw.println(" mTicking=" + mTicking);
2134 pw.println(" mTracking=" + mTracking);
Daniel Sandler36412a72011-08-04 09:35:13 -04002135 pw.println(" mDisplayMetrics=" + mDisplayMetrics);
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04002136 pw.println(" mPile: " + viewInfo(mPile));
Joe Onorato808182d2010-07-09 18:52:06 -04002137 pw.println(" mTickerView: " + viewInfo(mTickerView));
2138 pw.println(" mScrollView: " + viewInfo(mScrollView)
2139 + " scroll " + mScrollView.getScrollX() + "," + mScrollView.getScrollY());
Joe Onorato808182d2010-07-09 18:52:06 -04002140 }
Joe Onorato808182d2010-07-09 18:52:06 -04002141
Daniel Sandler48852952011-12-01 14:34:23 -05002142 pw.print(" mNavigationBarView=");
2143 if (mNavigationBarView == null) {
2144 pw.println("null");
2145 } else {
2146 mNavigationBarView.dump(fd, pw, args);
2147 }
2148
Daniel Sandler37a38aa2013-02-13 17:15:57 -05002149 pw.println(" Panels: ");
2150 if (mNotificationPanel != null) {
2151 pw.println(" mNotificationPanel=" +
2152 mNotificationPanel + " params=" + mNotificationPanel.getLayoutParams().debug(""));
2153 pw.print (" ");
2154 mNotificationPanel.dump(fd, pw, args);
2155 }
2156 if (mSettingsPanel != null) {
2157 pw.println(" mSettingsPanel=" +
2158 mSettingsPanel + " params=" + mSettingsPanel.getLayoutParams().debug(""));
2159 pw.print (" ");
2160 mSettingsPanel.dump(fd, pw, args);
2161 }
2162
Daniel Sandler7579bca2011-08-18 15:47:26 -04002163 if (DUMPTRUCK) {
2164 synchronized (mNotificationData) {
2165 int N = mNotificationData.size();
2166 pw.println(" notification icons: " + N);
2167 for (int i=0; i<N; i++) {
2168 NotificationData.Entry e = mNotificationData.get(i);
2169 pw.println(" [" + i + "] key=" + e.key + " icon=" + e.icon);
2170 StatusBarNotification n = e.notification;
Daniel Sandler4f91efd2013-04-25 16:38:41 -04002171 pw.println(" pkg=" + n.getPackageName() + " id=" + n.getId() + " score=" + n.getScore());
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -04002172 pw.println(" notification=" + n.getNotification());
2173 pw.println(" tickerText=\"" + n.getNotification().tickerText + "\"");
Daniel Sandler7579bca2011-08-18 15:47:26 -04002174 }
2175 }
2176
2177 int N = mStatusIcons.getChildCount();
2178 pw.println(" system icons: " + N);
2179 for (int i=0; i<N; i++) {
2180 StatusBarIconView ic = (StatusBarIconView) mStatusIcons.getChildAt(i);
2181 pw.println(" [" + i + "] icon=" + ic);
2182 }
Jim Miller5e6af442011-12-02 18:24:26 -08002183
Daniel Sandler89d97132011-09-08 15:31:57 -04002184 if (false) {
2185 pw.println("see the logcat for a dump of the views we have created.");
2186 // must happen on ui thread
2187 mHandler.post(new Runnable() {
2188 public void run() {
2189 mStatusBarView.getLocationOnScreen(mAbsPos);
John Spurlockcd686b52013-06-05 10:13:46 -04002190 Log.d(TAG, "mStatusBarView: ----- (" + mAbsPos[0] + "," + mAbsPos[1]
Daniel Sandler89d97132011-09-08 15:31:57 -04002191 + ") " + mStatusBarView.getWidth() + "x"
Daniel Sandlera310af82012-04-24 01:20:13 -04002192 + getStatusBarHeight());
Daniel Sandler89d97132011-09-08 15:31:57 -04002193 mStatusBarView.debug();
Daniel Sandler89d97132011-09-08 15:31:57 -04002194 }
2195 });
2196 }
Joe Onorato808182d2010-07-09 18:52:06 -04002197 }
Daniel Sandler89d97132011-09-08 15:31:57 -04002198
Daniel Sandler151f00d2012-10-02 22:33:08 -04002199 if (DEBUG_GESTURES) {
2200 pw.print(" status bar gestures: ");
2201 mGestureRec.dump(fd, pw, args);
2202 }
Daniel Sandler33805342012-07-23 15:45:12 -04002203
Daniel Sandler89d97132011-09-08 15:31:57 -04002204 mNetworkController.dump(fd, pw, args);
Joe Onorato808182d2010-07-09 18:52:06 -04002205 }
2206
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -05002207 @Override
2208 public void createAndAddWindows() {
2209 addStatusBarWindow();
Joe Onorato808182d2010-07-09 18:52:06 -04002210 }
Jim Millere898ac52012-04-06 17:10:57 -07002211
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -05002212 private void addStatusBarWindow() {
2213 // Put up the view
2214 final int height = getStatusBarHeight();
Joe Onorato808182d2010-07-09 18:52:06 -04002215
Daniel Sandlera310af82012-04-24 01:20:13 -04002216 // Now that the status bar window encompasses the sliding panel and its
2217 // translucent backdrop, the entire thing is made TRANSLUCENT and is
2218 // hardware-accelerated.
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -05002219 final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
2220 ViewGroup.LayoutParams.MATCH_PARENT,
2221 height,
2222 WindowManager.LayoutParams.TYPE_STATUS_BAR,
2223 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2224 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
2225 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
Daniel Sandlera310af82012-04-24 01:20:13 -04002226 PixelFormat.TRANSLUCENT);
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -05002227
Romain Guy0901fda2012-05-22 21:10:57 -07002228 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -05002229
2230 lp.gravity = getStatusBarGravity();
2231 lp.setTitle("StatusBar");
2232 lp.packageName = mContext.getPackageName();
Jim Millere898ac52012-04-06 17:10:57 -07002233
Daniel Sandlera310af82012-04-24 01:20:13 -04002234 makeStatusBarView();
Jeff Brown98365d72012-08-19 20:30:52 -07002235 mWindowManager.addView(mStatusBarWindow, lp);
Joe Onorato808182d2010-07-09 18:52:06 -04002236 }
2237
Joe Onorato808182d2010-07-09 18:52:06 -04002238 void setNotificationIconVisibility(boolean visible, int anim) {
2239 int old = mNotificationIcons.getVisibility();
2240 int v = visible ? View.VISIBLE : View.INVISIBLE;
2241 if (old != v) {
2242 mNotificationIcons.setVisibility(v);
2243 mNotificationIcons.startAnimation(loadAnim(anim, null));
2244 }
2245 }
2246
Dianne Hackborn1dacf272011-08-02 15:01:22 -07002247 void updateExpandedInvisiblePosition() {
Daniel Sandlerc6d29fc2012-02-25 00:33:12 -05002248 mTrackingPosition = -mDisplayMetrics.heightPixels;
Dianne Hackborn1dacf272011-08-02 15:01:22 -07002249 }
2250
Daniel Sandler1fac1fd2012-04-30 12:07:30 -04002251 static final float saturate(float a) {
2252 return a < 0f ? 0f : (a > 1f ? 1f : a);
2253 }
2254
Chris Wren8fd12652012-05-09 21:25:57 -04002255 @Override
2256 protected int getExpandedViewMaxHeight() {
Daniel Sandler21b274e2012-05-02 15:07:51 -04002257 return mDisplayMetrics.heightPixels - mNotificationPanelMarginBottomPx;
2258 }
2259
Chris Wren0c8275b2012-05-08 13:36:48 -04002260 @Override
Daniel Sandler08d05e32012-08-08 16:39:54 -04002261 public void updateExpandedViewPos(int thingy) {
John Spurlockcd686b52013-06-05 10:13:46 -04002262 if (DEBUG) Log.v(TAG, "updateExpandedViewPos");
Daniel Sandlere680f542012-09-28 12:22:27 -04002263
2264 // on larger devices, the notification panel is propped open a bit
2265 mNotificationPanel.setMinimumHeight(
2266 (int)(mNotificationPanelMinHeightFrac * mCurrentDisplaySize.y));
2267
Daniel Sandler21b274e2012-05-02 15:07:51 -04002268 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mNotificationPanel.getLayoutParams();
Daniel Sandler21b274e2012-05-02 15:07:51 -04002269 lp.gravity = mNotificationPanelGravity;
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -07002270 lp.setMarginStart(mNotificationPanelMarginPx);
Daniel Sandler21b274e2012-05-02 15:07:51 -04002271 mNotificationPanel.setLayoutParams(lp);
Daniel Sandlere680f542012-09-28 12:22:27 -04002272
Daniel Sandlere111ad32012-10-13 15:17:45 -04002273 if (mSettingsPanel != null) {
2274 lp = (FrameLayout.LayoutParams) mSettingsPanel.getLayoutParams();
2275 lp.gravity = mSettingsPanelGravity;
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -07002276 lp.setMarginEnd(mNotificationPanelMarginPx);
Daniel Sandlere111ad32012-10-13 15:17:45 -04002277 mSettingsPanel.setLayoutParams(lp);
2278 }
Daniel Sandlerbf526d12012-09-04 22:56:44 -04002279
2280 updateCarrierLabelVisibility(false);
Joe Onorato808182d2010-07-09 18:52:06 -04002281 }
2282
Daniel Sandler747a9e92012-08-10 16:39:19 -04002283 // called by makeStatusbar and also by PhoneStatusBarView
Dianne Hackborn1dacf272011-08-02 15:01:22 -07002284 void updateDisplaySize() {
Daniel Sandler36412a72011-08-04 09:35:13 -04002285 mDisplay.getMetrics(mDisplayMetrics);
Daniel Sandler151f00d2012-10-02 22:33:08 -04002286 if (DEBUG_GESTURES) {
John Spurlock209bede2013-07-17 12:23:27 -04002287 mGestureRec.tag("display",
Daniel Sandler151f00d2012-10-02 22:33:08 -04002288 String.format("%dx%d", mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels));
2289 }
Dianne Hackborn1dacf272011-08-02 15:01:22 -07002290 }
2291
Joe Onorato808182d2010-07-09 18:52:06 -04002292 private View.OnClickListener mClearButtonListener = new View.OnClickListener() {
2293 public void onClick(View v) {
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002294 synchronized (mNotificationData) {
Chet Haase2f2022a2011-10-11 06:41:59 -07002295 // animate-swipe all dismissable notifications, then animate the shade closed
2296 int numChildren = mPile.getChildCount();
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002297
Chet Haase2f2022a2011-10-11 06:41:59 -07002298 int scrollTop = mScrollView.getScrollY();
2299 int scrollBottom = scrollTop + mScrollView.getHeight();
2300 final ArrayList<View> snapshot = new ArrayList<View>(numChildren);
2301 for (int i=0; i<numChildren; i++) {
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002302 final View child = mPile.getChildAt(i);
Chet Haase2f2022a2011-10-11 06:41:59 -07002303 if (mPile.canChildBeDismissed(child) && child.getBottom() > scrollTop &&
2304 child.getTop() < scrollBottom) {
2305 snapshot.add(child);
2306 }
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002307 }
Craig Mautner93a035c2012-04-09 15:23:59 -07002308 if (snapshot.isEmpty()) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04002309 animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
Craig Mautner93a035c2012-04-09 15:23:59 -07002310 return;
2311 }
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002312 new Thread(new Runnable() {
2313 @Override
2314 public void run() {
Chet Haase2f2022a2011-10-11 06:41:59 -07002315 // Decrease the delay for every row we animate to give the sense of
2316 // accelerating the swipes
2317 final int ROW_DELAY_DECREMENT = 10;
2318 int currentDelay = 140;
2319 int totalDelay = 0;
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002320
Chet Haase2f2022a2011-10-11 06:41:59 -07002321 // Set the shade-animating state to avoid doing other work during
2322 // all of these animations. In particular, avoid layout and
2323 // redrawing when collapsing the shade.
2324 mPile.setViewRemoval(false);
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002325
Chet Haase2f2022a2011-10-11 06:41:59 -07002326 mPostCollapseCleanup = new Runnable() {
Craig Mautner93a035c2012-04-09 15:23:59 -07002327 @Override
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002328 public void run() {
Daniel Sandlere7237fc2012-08-14 16:08:27 -04002329 if (DEBUG) {
John Spurlockcd686b52013-06-05 10:13:46 -04002330 Log.v(TAG, "running post-collapse cleanup");
Daniel Sandlere7237fc2012-08-14 16:08:27 -04002331 }
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002332 try {
Chet Haase2f2022a2011-10-11 06:41:59 -07002333 mPile.setViewRemoval(true);
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002334 mBarService.onClearAllNotifications();
Chet Haase2f2022a2011-10-11 06:41:59 -07002335 } catch (Exception ex) { }
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002336 }
Chet Haase2f2022a2011-10-11 06:41:59 -07002337 };
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002338
Chet Haase2f2022a2011-10-11 06:41:59 -07002339 View sampleView = snapshot.get(0);
2340 int width = sampleView.getWidth();
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -07002341 final int dir = sampleView.isLayoutRtl() ? -1 : +1;
2342 final int velocity = dir * width * 8; // 1000/8 = 125 ms duration
Craig Mautner93a035c2012-04-09 15:23:59 -07002343 for (final View _v : snapshot) {
Chet Haase2f2022a2011-10-11 06:41:59 -07002344 mHandler.postDelayed(new Runnable() {
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002345 @Override
2346 public void run() {
Chet Haase2f2022a2011-10-11 06:41:59 -07002347 mPile.dismissRowAnimated(_v, velocity);
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002348 }
Chet Haase2f2022a2011-10-11 06:41:59 -07002349 }, totalDelay);
2350 currentDelay = Math.max(50, currentDelay - ROW_DELAY_DECREMENT);
2351 totalDelay += currentDelay;
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002352 }
Chet Haase2f2022a2011-10-11 06:41:59 -07002353 // Delay the collapse animation until after all swipe animations have
2354 // finished. Provide some buffer because there may be some extra delay
2355 // before actually starting each swipe animation. Ideally, we'd
2356 // synchronize the end of those animations with the start of the collaps
2357 // exactly.
2358 mHandler.postDelayed(new Runnable() {
Craig Mautner93a035c2012-04-09 15:23:59 -07002359 @Override
Chet Haase2f2022a2011-10-11 06:41:59 -07002360 public void run() {
Daniel Sandler11cf1782012-09-27 14:03:08 -04002361 animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
Chet Haase2f2022a2011-10-11 06:41:59 -07002362 }
2363 }, totalDelay + 225);
Daniel Sandler8ba33c92011-10-04 21:49:30 -04002364 }
2365 }).start();
Joe Onorato808182d2010-07-09 18:52:06 -04002366 }
Joe Onorato808182d2010-07-09 18:52:06 -04002367 }
2368 };
2369
Daniel Sandler3679bf52012-10-16 21:30:28 -04002370 public void startActivityDismissingKeyguard(Intent intent, boolean onlyProvisioned) {
2371 if (onlyProvisioned && !isDeviceProvisioned()) return;
2372 try {
2373 // Dismiss the lock screen when Settings starts.
2374 ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
2375 } catch (RemoteException e) {
2376 }
2377 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2378 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
2379 animateCollapsePanels();
2380 }
2381
Daniel Sandlerd3090562011-08-09 00:28:44 -04002382 private View.OnClickListener mSettingsButtonListener = new View.OnClickListener() {
2383 public void onClick(View v) {
Daniel Sandlere111ad32012-10-13 15:17:45 -04002384 if (mHasSettingsPanel) {
2385 animateExpandSettingsPanel();
2386 } else {
Daniel Sandler3679bf52012-10-16 21:30:28 -04002387 startActivityDismissingKeyguard(
2388 new Intent(android.provider.Settings.ACTION_SETTINGS), true);
Daniel Sandlere111ad32012-10-13 15:17:45 -04002389 }
Daniel Sandlerd3090562011-08-09 00:28:44 -04002390 }
2391 };
2392
Daniel Sandler3679bf52012-10-16 21:30:28 -04002393 private View.OnClickListener mClockClickListener = new View.OnClickListener() {
2394 public void onClick(View v) {
2395 startActivityDismissingKeyguard(
2396 new Intent(Intent.ACTION_QUICK_CLOCK), true); // have fun, everyone
2397 }
2398 };
2399
Daniel Sandler101784e2012-10-15 13:39:38 -04002400 private View.OnClickListener mNotificationButtonListener = new View.OnClickListener() {
2401 public void onClick(View v) {
2402 animateExpandNotificationsPanel();
2403 }
2404 };
2405
Joe Onorato808182d2010-07-09 18:52:06 -04002406 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
2407 public void onReceive(Context context, Intent intent) {
John Spurlockcd686b52013-06-05 10:13:46 -04002408 if (DEBUG) Log.v(TAG, "onReceive: " + intent);
Joe Onorato808182d2010-07-09 18:52:06 -04002409 String action = intent.getAction();
Daniel Sandlered930e52012-07-03 14:31:22 -04002410 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
Jim Miller9a720f52012-05-30 03:19:43 -07002411 int flags = CommandQueue.FLAG_EXCLUDE_NONE;
Michael Jurka3b1fc472011-06-13 10:54:40 -07002412 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
Daniel Sandleredbdd3a2011-06-21 12:57:08 -04002413 String reason = intent.getStringExtra("reason");
Jim Miller9a720f52012-05-30 03:19:43 -07002414 if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
2415 flags |= CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL;
Michael Jurka3b1fc472011-06-13 10:54:40 -07002416 }
2417 }
Daniel Sandler11cf1782012-09-27 14:03:08 -04002418 animateCollapsePanels(flags);
Joe Onorato808182d2010-07-09 18:52:06 -04002419 }
Daniel Sandlered930e52012-07-03 14:31:22 -04002420 else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
2421 // no waiting!
Daniel Sandler08d05e32012-08-08 16:39:54 -04002422 makeExpandedInvisible();
John Spurlock1bbd49d2012-10-19 11:09:32 -04002423 notifyNavigationBarScreenOn(false);
Daniel Sandlered930e52012-07-03 14:31:22 -04002424 }
Joe Onorato808182d2010-07-09 18:52:06 -04002425 else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
Daniel Sandler7f3cf952012-08-31 14:57:09 -04002426 if (DEBUG) {
John Spurlockcd686b52013-06-05 10:13:46 -04002427 Log.v(TAG, "configuration changed: " + mContext.getResources().getConfiguration());
Daniel Sandler7f3cf952012-08-31 14:57:09 -04002428 }
Daniel Sandlere680f542012-09-28 12:22:27 -04002429 mDisplay.getSize(mCurrentDisplaySize);
2430
Joe Onorato808182d2010-07-09 18:52:06 -04002431 updateResources();
Daniel Sandler21b274e2012-05-02 15:07:51 -04002432 repositionNavigationBar();
2433 updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
Daniel Sandler7f3cf952012-08-31 14:57:09 -04002434 updateShowSearchHoldoff();
2435 }
2436 else if (Intent.ACTION_SCREEN_ON.equals(action)) {
2437 // work around problem where mDisplay.getRotation() is not stable while screen is off (bug 7086018)
2438 repositionNavigationBar();
John Spurlock1bbd49d2012-10-19 11:09:32 -04002439 notifyNavigationBarScreenOn(true);
Joe Onorato808182d2010-07-09 18:52:06 -04002440 }
2441 }
2442 };
2443
Daniel Sandlerb9301c32012-08-14 15:08:24 -04002444 @Override
2445 public void userSwitched(int newUserId) {
2446 if (MULTIUSER_DEBUG) mNotificationPanelDebugText.setText("USER " + newUserId);
Daniel Sandler11cf1782012-09-27 14:03:08 -04002447 animateCollapsePanels();
Daniel Sandlerb9301c32012-08-14 15:08:24 -04002448 updateNotificationIcons();
John Spurlock919adac2012-10-02 16:41:12 -04002449 resetUserSetupObserver();
Daniel Sandlerb9301c32012-08-14 15:08:24 -04002450 }
John Spurlock919adac2012-10-02 16:41:12 -04002451
2452 private void resetUserSetupObserver() {
2453 mContext.getContentResolver().unregisterContentObserver(mUserSetupObserver);
2454 mUserSetupObserver.onChange(false);
2455 mContext.getContentResolver().registerContentObserver(
2456 Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE), true,
2457 mUserSetupObserver,
2458 mCurrentUserId);
2459 }
2460
Chris Wren157026f2013-06-28 16:54:01 -04002461 private void setHeadsUpVisibility(boolean vis) {
2462 if (!ENABLE_HEADS_UP) return;
2463 if (DEBUG) Log.v(TAG, (vis ? "showing" : "hiding") + " heads up window");
2464 mHeadsUpNotificationView.setVisibility(vis ? View.VISIBLE : View.GONE);
Joe Onorato808182d2010-07-09 18:52:06 -04002465 }
2466
Chris Wren157026f2013-06-28 16:54:01 -04002467 public void dismissHeadsUp() {
2468 if (mCurrentlyInterruptingNotification == null) return;
Daniel Sandlerfa7887b2012-03-26 09:43:31 -04002469
2470 try {
2471 mBarService.onNotificationClear(
Chris Wren157026f2013-06-28 16:54:01 -04002472 mCurrentlyInterruptingNotification.getPackageName(),
2473 mCurrentlyInterruptingNotification.getTag(),
2474 mCurrentlyInterruptingNotification.getId());
Daniel Sandlerfa7887b2012-03-26 09:43:31 -04002475 } catch (android.os.RemoteException ex) {
2476 // oh well
2477 }
2478 }
Jim Millere898ac52012-04-06 17:10:57 -07002479
Joe Onorato808182d2010-07-09 18:52:06 -04002480 /**
2481 * Reload some of our resources when the configuration changes.
2482 *
2483 * We don't reload everything when the configuration changes -- we probably
2484 * should, but getting that smooth is tough. Someday we'll fix that. In the
2485 * meantime, just update the things that we know change.
2486 */
2487 void updateResources() {
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04002488 final Context context = mContext;
2489 final Resources res = context.getResources();
Joe Onorato808182d2010-07-09 18:52:06 -04002490
Daniel Sandler1347c302011-08-01 16:47:53 -04002491 if (mClearButton instanceof TextView) {
2492 ((TextView)mClearButton).setText(context.getText(R.string.status_bar_clear_all_button));
2493 }
Winson Chungd63c59782012-09-05 17:34:41 -07002494
2495 // Update the QuickSettings container
Daniel Sandler101784e2012-10-15 13:39:38 -04002496 if (mQS != null) mQS.updateResources();
Winson Chungd63c59782012-09-05 17:34:41 -07002497
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04002498 loadDimens();
2499 }
Jim Miller5e6af442011-12-02 18:24:26 -08002500
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04002501 protected void loadDimens() {
2502 final Resources res = mContext.getResources();
2503
2504 mNaturalBarHeight = res.getDimensionPixelSize(
2505 com.android.internal.R.dimen.status_bar_height);
2506
2507 int newIconSize = res.getDimensionPixelSize(
2508 com.android.internal.R.dimen.status_bar_icon_size);
2509 int newIconHPadding = res.getDimensionPixelSize(
2510 R.dimen.status_bar_icon_padding);
2511
2512 if (newIconHPadding != mIconHPadding || newIconSize != mIconSize) {
John Spurlockcd686b52013-06-05 10:13:46 -04002513// Log.d(TAG, "size=" + newIconSize + " padding=" + newIconHPadding);
Daniel Sandler7c3e39d2011-07-29 16:30:49 -04002514 mIconHPadding = newIconHPadding;
2515 mIconSize = newIconSize;
2516 //reloadAllNotificationIcons(); // reload the tray
2517 }
2518
Joe Onorato808182d2010-07-09 18:52:06 -04002519 mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore);
2520
Daniel Sandlerdc940ea2011-08-25 14:35:53 -07002521 mSelfExpandVelocityPx = res.getDimension(R.dimen.self_expand_velocity);
2522 mSelfCollapseVelocityPx = res.getDimension(R.dimen.self_collapse_velocity);
2523 mFlingExpandMinVelocityPx = res.getDimension(R.dimen.fling_expand_min_velocity);
2524 mFlingCollapseMinVelocityPx = res.getDimension(R.dimen.fling_collapse_min_velocity);
2525
2526 mCollapseMinDisplayFraction = res.getFraction(R.dimen.collapse_min_display_fraction, 1, 1);
2527 mExpandMinDisplayFraction = res.getFraction(R.dimen.expand_min_display_fraction, 1, 1);
2528
2529 mExpandAccelPx = res.getDimension(R.dimen.expand_accel);
2530 mCollapseAccelPx = res.getDimension(R.dimen.collapse_accel);
2531
2532 mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity);
Jim Millera073e572012-05-23 17:03:27 -07002533
Daniel Sandlere5011a32012-06-11 16:07:52 -04002534 mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity);
2535
Daniel Sandler21b274e2012-05-02 15:07:51 -04002536 mNotificationPanelMarginBottomPx
2537 = (int) res.getDimension(R.dimen.notification_panel_margin_bottom);
Daniel Sandler8e72c9e2012-08-15 00:09:26 -04002538 mNotificationPanelMarginPx
Daniel Sandler21b274e2012-05-02 15:07:51 -04002539 = (int) res.getDimension(R.dimen.notification_panel_margin_left);
2540 mNotificationPanelGravity = res.getInteger(R.integer.notification_panel_layout_gravity);
2541 if (mNotificationPanelGravity <= 0) {
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -07002542 mNotificationPanelGravity = Gravity.START | Gravity.TOP;
Daniel Sandler8e72c9e2012-08-15 00:09:26 -04002543 }
2544 mSettingsPanelGravity = res.getInteger(R.integer.settings_panel_layout_gravity);
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -07002545 Log.d(TAG, "mSettingsPanelGravity = " + mSettingsPanelGravity);
Daniel Sandler8e72c9e2012-08-15 00:09:26 -04002546 if (mSettingsPanelGravity <= 0) {
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -07002547 mSettingsPanelGravity = Gravity.END | Gravity.TOP;
Daniel Sandler21b274e2012-05-02 15:07:51 -04002548 }
Daniel Sandler3d32a242012-06-05 13:44:14 -04002549
2550 mCarrierLabelHeight = res.getDimensionPixelSize(R.dimen.carrier_label_height);
Daniel Sandlerbf526d12012-09-04 22:56:44 -04002551 mNotificationHeaderHeight = res.getDimensionPixelSize(R.dimen.notification_panel_header_height);
Daniel Sandlerdc940ea2011-08-25 14:35:53 -07002552
Daniel Sandlere680f542012-09-28 12:22:27 -04002553 mNotificationPanelMinHeightFrac = res.getFraction(R.dimen.notification_panel_min_height_frac, 1, 1);
2554 if (mNotificationPanelMinHeightFrac < 0f || mNotificationPanelMinHeightFrac > 1f) {
2555 mNotificationPanelMinHeightFrac = 0f;
John Spurlock804df702012-06-01 15:34:27 -04002556 }
Daniel Sandlere680f542012-09-28 12:22:27 -04002557
John Spurlockcd686b52013-06-05 10:13:46 -04002558 if (false) Log.v(TAG, "updateResources");
John Spurlock804df702012-06-01 15:34:27 -04002559 }
2560
Joe Onorato808182d2010-07-09 18:52:06 -04002561 //
2562 // tracing
2563 //
2564
2565 void postStartTracing() {
2566 mHandler.postDelayed(mStartTracing, 3000);
2567 }
2568
2569 void vibrate() {
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04002570 android.os.Vibrator vib = (android.os.Vibrator)mContext.getSystemService(
2571 Context.VIBRATOR_SERVICE);
Joe Onorato808182d2010-07-09 18:52:06 -04002572 vib.vibrate(250);
2573 }
2574
2575 Runnable mStartTracing = new Runnable() {
2576 public void run() {
2577 vibrate();
2578 SystemClock.sleep(250);
John Spurlockcd686b52013-06-05 10:13:46 -04002579 Log.d(TAG, "startTracing");
Joe Onorato808182d2010-07-09 18:52:06 -04002580 android.os.Debug.startMethodTracing("/data/statusbar-traces/trace");
2581 mHandler.postDelayed(mStopTracing, 10000);
2582 }
2583 };
2584
2585 Runnable mStopTracing = new Runnable() {
2586 public void run() {
2587 android.os.Debug.stopMethodTracing();
John Spurlockcd686b52013-06-05 10:13:46 -04002588 Log.d(TAG, "stopTracing");
Joe Onorato808182d2010-07-09 18:52:06 -04002589 vibrate();
2590 }
2591 };
Chris Wren0c8275b2012-05-08 13:36:48 -04002592
2593 @Override
2594 protected void haltTicker() {
2595 mTicker.halt();
2596 }
Jim Miller670d9dd2012-05-12 13:28:26 -07002597
2598 @Override
Jim Millerb4238e02012-05-14 15:26:20 -07002599 protected boolean shouldDisableNavbarGestures() {
Daniel Sandlerd5483c32012-10-19 16:44:15 -04002600 return !isDeviceProvisioned()
2601 || mExpandedVisible
2602 || (mDisabled & StatusBarManager.DISABLE_SEARCH) != 0;
Jim Miller670d9dd2012-05-12 13:28:26 -07002603 }
Joe Onorato808182d2010-07-09 18:52:06 -04002604
Romain Guy648342f2012-05-25 10:44:45 -07002605 private static class FastColorDrawable extends Drawable {
2606 private final int mColor;
2607
2608 public FastColorDrawable(int color) {
2609 mColor = 0xff000000 | color;
2610 }
2611
2612 @Override
2613 public void draw(Canvas canvas) {
2614 canvas.drawColor(mColor, PorterDuff.Mode.SRC);
2615 }
2616
2617 @Override
2618 public void setAlpha(int alpha) {
2619 }
2620
2621 @Override
2622 public void setColorFilter(ColorFilter cf) {
2623 }
2624
2625 @Override
2626 public int getOpacity() {
2627 return PixelFormat.OPAQUE;
2628 }
2629
2630 @Override
2631 public void setBounds(int left, int top, int right, int bottom) {
2632 }
2633
2634 @Override
2635 public void setBounds(Rect bounds) {
2636 }
2637 }
John Spurlock5c454122013-06-17 07:35:46 -04002638
2639 @Override
2640 public void destroy() {
2641 super.destroy();
2642 if (mStatusBarWindow != null) {
2643 mWindowManager.removeViewImmediate(mStatusBarWindow);
2644 }
2645 if (mNavigationBarView != null) {
2646 mWindowManager.removeViewImmediate(mNavigationBarView);
2647 }
2648 mContext.unregisterReceiver(mBroadcastReceiver);
2649 }
Romain Guy648342f2012-05-25 10:44:45 -07002650}