blob: fa763c852cdf9e54db43d15795806e70c6f95a23 [file] [log] [blame]
Daniel Sandlerc4f2a562012-05-04 11:55:46 -04001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.statusbar.phone;
18
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070019import android.annotation.ColorInt;
20import android.annotation.DrawableRes;
21import android.annotation.LayoutRes;
John Spurlock257f2832013-09-21 18:41:53 -040022import android.app.StatusBarManager;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040023import android.content.Context;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070024import android.content.res.Configuration;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070025import android.content.res.TypedArray;
Daniel Sandler198a0302012-08-17 16:04:31 -040026import android.graphics.Canvas;
27import android.graphics.Paint;
Selim Cineka0fad3b2014-09-19 17:20:05 +020028import android.graphics.PorterDuff;
29import android.graphics.PorterDuffXfermode;
John Spurlockfba91202014-04-22 12:58:26 -040030import android.graphics.Rect;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070031import android.graphics.drawable.Drawable;
Jaewan Kim50269362016-12-23 11:22:02 +090032import android.media.AudioManager;
John Spurlock0b99ea92014-10-01 15:32:22 -040033import android.media.session.MediaSessionLegacyHelper;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070034import android.net.Uri;
35import android.os.Bundle;
Selim Cineka0fad3b2014-09-19 17:20:05 +020036import android.os.IBinder;
Adrian Roos8008bd12017-02-22 15:02:09 +010037import android.os.SystemClock;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040038import android.util.AttributeSet;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070039import android.view.ActionMode;
felkachang7749c9a2018-06-11 15:56:15 +080040import android.view.DisplayCutout;
Selim Cinek48a92a52017-05-02 20:02:30 -070041import android.view.InputDevice;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070042import android.view.InputQueue;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040043import android.view.KeyEvent;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070044import android.view.LayoutInflater;
45import android.view.Menu;
46import android.view.MenuItem;
Chris Wren5de6e942012-05-16 14:22:21 -040047import android.view.MotionEvent;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070048import android.view.SurfaceHolder;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070049import android.view.View;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070050import android.view.ViewGroup;
51import android.view.ViewTreeObserver;
52import android.view.Window;
Selim Cineka0fad3b2014-09-19 17:20:05 +020053import android.view.WindowManager;
54import android.view.WindowManagerGlobal;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040055import android.widget.FrameLayout;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040056
Selim Cinekf8c4add2017-06-08 09:54:58 -070057import com.android.internal.annotations.VisibleForTesting;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070058import com.android.internal.view.FloatingActionMode;
59import com.android.internal.widget.FloatingToolbar;
Chris Wren5de6e942012-05-16 14:22:21 -040060import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070061import com.android.systemui.classifier.FalsingManager;
Jorim Jaggiecbab362014-04-23 16:13:15 +020062import com.android.systemui.statusbar.DragDownHelper;
63import com.android.systemui.statusbar.StatusBarState;
Selim Cinekfab078b2014-03-27 22:45:58 +010064import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Chris Wren5de6e942012-05-16 14:22:21 -040065
Selim Cinekfc5c1992018-01-29 12:40:32 -080066import java.io.FileDescriptor;
67import java.io.PrintWriter;
68
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040069
Jorim Jaggiecbab362014-04-23 16:13:15 +020070public class StatusBarWindowView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040071 public static final String TAG = "StatusBarWindowView";
Jason Monk2a6ea9c2017-01-26 11:14:51 -050072 public static final boolean DEBUG = StatusBar.DEBUG;
Chris Wren5de6e942012-05-16 14:22:21 -040073
Jorim Jaggiecbab362014-04-23 16:13:15 +020074 private DragDownHelper mDragDownHelper;
Adrian Roos8008bd12017-02-22 15:02:09 +010075 private DoubleTapHelper mDoubleTapHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010076 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070077 private NotificationPanelView mNotificationPanel;
Adrian Roos9dc32092014-09-02 23:34:10 +020078 private View mBrightnessMirror;
Jorim Jaggi45611dd2018-06-19 17:27:08 +020079 private PhoneStatusBarView mStatusBarView;
Chris Wren5de6e942012-05-16 14:22:21 -040080
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070081 private int mRightInset = 0;
Adrian Roos85d202b2016-06-02 16:27:47 -070082 private int mLeftInset = 0;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070083
Jason Monk2a6ea9c2017-01-26 11:14:51 -050084 private StatusBar mService;
Selim Cineka0fad3b2014-09-19 17:20:05 +020085 private final Paint mTransparentSrcPaint = new Paint();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070086 private FalsingManager mFalsingManager;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040087
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070088 // Implements the floating action mode for TextView's Cut/Copy/Past menu. Normally provided by
89 // DecorView, but since this is a special window we have to roll our own.
90 private View mFloatingActionModeOriginatingView;
91 private ActionMode mFloatingActionMode;
92 private FloatingToolbar mFloatingToolbar;
93 private ViewTreeObserver.OnPreDrawListener mFloatingToolbarPreDrawListener;
Selim Cinek48a92a52017-05-02 20:02:30 -070094 private boolean mTouchCancelled;
95 private boolean mTouchActive;
Selim Cinek2627d722018-01-19 12:16:49 -080096 private boolean mExpandAnimationRunning;
Selim Cinek7e222c3c2018-01-25 12:22:41 -080097 private boolean mExpandAnimationPending;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070098
Jorim Jaggi0d4a9952018-06-06 17:22:56 +020099 /**
100 * If set to true, the current gesture started below the notch and we need to dispatch touch
101 * events manually as it's outside of the regular view bounds.
102 */
103 private boolean mExpandingBelowNotch;
104
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400105 public StatusBarWindowView(Context context, AttributeSet attrs) {
106 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -0400107 setMotionEventSplittingEnabled(false);
Selim Cineka0fad3b2014-09-19 17:20:05 +0200108 mTransparentSrcPaint.setColor(0);
109 mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700110 mFalsingManager = FalsingManager.getInstance(context);
Adrian Roos8008bd12017-02-22 15:02:09 +0100111 mDoubleTapHelper = new DoubleTapHelper(this, active -> {}, () -> {
112 mService.wakeUpIfDozing(SystemClock.uptimeMillis(), this);
113 return true;
114 }, null, null);
Chris Wren5de6e942012-05-16 14:22:21 -0400115 }
116
117 @Override
John Spurlockfba91202014-04-22 12:58:26 -0400118 protected boolean fitSystemWindows(Rect insets) {
119 if (getFitsSystemWindows()) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700120 boolean paddingChanged = insets.top != getPaddingTop()
Jorim Jaggi416493b2014-09-13 03:57:32 +0200121 || insets.bottom != getPaddingBottom();
Jorim Jaggiaa806142015-05-20 18:04:16 -0700122
felkachang7749c9a2018-06-11 15:56:15 +0800123 int rightCutout = 0;
124 int leftCutout = 0;
125 DisplayCutout displayCutout = getRootWindowInsets().getDisplayCutout();
126 if (displayCutout != null) {
127 leftCutout = displayCutout.getSafeInsetLeft();
128 rightCutout = displayCutout.getSafeInsetRight();
129 }
130
131 int targetLeft = Math.max(insets.left, leftCutout);
132 int targetRight = Math.max(insets.right, rightCutout);
133
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700134 // Super-special right inset handling, because scrims and backdrop need to ignore it.
felkachang7749c9a2018-06-11 15:56:15 +0800135 if (targetRight != mRightInset || targetLeft != mLeftInset) {
136 mRightInset = targetRight;
137 mLeftInset = targetLeft;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700138 applyMargins();
139 }
Adrian Roos85d202b2016-06-02 16:27:47 -0700140 // Drop top inset, and pass through bottom inset.
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700141 if (paddingChanged) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700142 setPadding(0, 0, 0, 0);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200143 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200144 insets.left = 0;
145 insets.top = 0;
146 insets.right = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400147 } else {
Adrian Roos85d202b2016-06-02 16:27:47 -0700148 if (mRightInset != 0 || mLeftInset != 0) {
Adrian Roose49e4092015-06-10 18:50:18 -0700149 mRightInset = 0;
Adrian Roos85d202b2016-06-02 16:27:47 -0700150 mLeftInset = 0;
Adrian Roose49e4092015-06-10 18:50:18 -0700151 applyMargins();
152 }
Jorim Jaggi416493b2014-09-13 03:57:32 +0200153 boolean changed = getPaddingLeft() != 0
154 || getPaddingRight() != 0
155 || getPaddingTop() != 0
156 || getPaddingBottom() != 0;
157 if (changed) {
158 setPadding(0, 0, 0, 0);
159 }
Jorim Jaggiaa806142015-05-20 18:04:16 -0700160 insets.top = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400161 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200162 return false;
John Spurlockfba91202014-04-22 12:58:26 -0400163 }
164
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700165 private void applyMargins() {
166 final int N = getChildCount();
167 for (int i = 0; i < N; i++) {
168 View child = getChildAt(i);
169 if (child.getLayoutParams() instanceof LayoutParams) {
170 LayoutParams lp = (LayoutParams) child.getLayoutParams();
Adrian Roos85d202b2016-06-02 16:27:47 -0700171 if (!lp.ignoreRightInset
172 && (lp.rightMargin != mRightInset || lp.leftMargin != mLeftInset)) {
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700173 lp.rightMargin = mRightInset;
Adrian Roos85d202b2016-06-02 16:27:47 -0700174 lp.leftMargin = mLeftInset;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700175 child.requestLayout();
176 }
177 }
178 }
179 }
180
181 @Override
182 public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) {
183 return new LayoutParams(getContext(), attrs);
184 }
185
186 @Override
187 protected FrameLayout.LayoutParams generateDefaultLayoutParams() {
188 return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
189 }
190
John Spurlockfba91202014-04-22 12:58:26 -0400191 @Override
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400192 protected void onFinishInflate() {
193 super.onFinishInflate();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100194 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
195 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700196 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Adrian Roos9dc32092014-09-02 23:34:10 +0200197 mBrightnessMirror = findViewById(R.id.brightness_mirror);
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400198 }
199
dooyoung.hwange4b841e2016-11-16 08:59:23 +0900200 @Override
201 public void onViewAdded(View child) {
202 super.onViewAdded(child);
203 if (child.getId() == R.id.brightness_mirror) {
204 mBrightnessMirror = child;
205 }
206 }
207
Jorim Jaggi45611dd2018-06-19 17:27:08 +0200208 public void setStatusBarView(PhoneStatusBarView statusBarView) {
209 mStatusBarView = statusBarView;
210 }
211
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500212 public void setService(StatusBar service) {
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400213 mService = service;
Selim Cinekf8c4add2017-06-08 09:54:58 -0700214 setDragDownHelper(new DragDownHelper(getContext(), this, mStackScrollLayout, mService));
215 }
216
217 @VisibleForTesting
218 void setDragDownHelper(DragDownHelper dragDownHelper) {
219 mDragDownHelper = dragDownHelper;
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400220 }
221
222 @Override
223 protected void onAttachedToWindow () {
224 super.onAttachedToWindow();
Daniel Sandlerb10d8852013-05-08 15:57:06 -0400225
Selim Cineka0fad3b2014-09-19 17:20:05 +0200226 // We need to ensure that our window doesn't suffer from overdraw which would normally
227 // occur if our window is translucent. Since we are drawing the whole window anyway with
228 // the scrim, we don't need the window to be cleared in the beginning.
Jorim Jaggi0e664392014-09-27 01:30:22 +0200229 if (mService.isScrimSrcModeEnabled()) {
230 IBinder windowToken = getWindowToken();
231 WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
232 lp.token = windowToken;
233 setLayoutParams(lp);
234 WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true);
235 setWillNotDraw(false);
236 } else {
237 setWillNotDraw(!DEBUG);
238 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400239 }
240
241 @Override
242 public boolean dispatchKeyEvent(KeyEvent event) {
Adrian Roos56cf73a2016-07-18 14:23:32 -0700243 if (mService.interceptMediaKey(event)) {
244 return true;
245 }
246 if (super.dispatchKeyEvent(event)) {
247 return true;
248 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400249 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
250 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200251 case KeyEvent.KEYCODE_BACK:
252 if (!down) {
253 mService.onBackPressed();
254 }
255 return true;
256 case KeyEvent.KEYCODE_MENU:
257 if (!down) {
258 return mService.onMenuPressed();
259 }
Jorim Jaggi34250762014-07-03 23:51:19 +0200260 case KeyEvent.KEYCODE_SPACE:
261 if (!down) {
262 return mService.onSpacePressed();
263 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400264 break;
John Spurlockd06aa572014-09-10 10:40:49 -0400265 case KeyEvent.KEYCODE_VOLUME_DOWN:
266 case KeyEvent.KEYCODE_VOLUME_UP:
John Spurlock0b99ea92014-10-01 15:32:22 -0400267 if (mService.isDozing()) {
Jaewan Kim50269362016-12-23 11:22:02 +0900268 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
269 event, AudioManager.USE_DEFAULT_STREAM_TYPE, true);
John Spurlock0b99ea92014-10-01 15:32:22 -0400270 return true;
John Spurlockd06aa572014-09-10 10:40:49 -0400271 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400272 break;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400273 }
Adrian Roos56cf73a2016-07-18 14:23:32 -0700274 return false;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400275 }
Chris Wren5de6e942012-05-16 14:22:21 -0400276
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700277 public void setTouchActive(boolean touchActive) {
278 mTouchActive = touchActive;
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700279 }
280
Chris Wren5de6e942012-05-16 14:22:21 -0400281 @Override
Adrian Roos9dc32092014-09-02 23:34:10 +0200282 public boolean dispatchTouchEvent(MotionEvent ev) {
Selim Cinek48a92a52017-05-02 20:02:30 -0700283 boolean isDown = ev.getActionMasked() == MotionEvent.ACTION_DOWN;
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200284 boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP;
Adrian Roosa6c03f82017-07-26 16:20:30 +0200285 boolean isCancel = ev.getActionMasked() == MotionEvent.ACTION_CANCEL;
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200286
287 // Reset manual touch dispatch state here but make sure the UP/CANCEL event still gets
288 // delivered.
289 boolean expandingBelowNotch = mExpandingBelowNotch;
290 if (isUp || isCancel) {
291 mExpandingBelowNotch = false;
292 }
293
Adrian Roosa6c03f82017-07-26 16:20:30 +0200294 if (!isCancel && mService.shouldIgnoreTouch()) {
295 return false;
296 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700297 if (isDown && mNotificationPanel.isFullyCollapsed()) {
Jorim Jaggie05256e2016-09-08 14:58:20 -0700298 mNotificationPanel.startExpandLatencyTracking();
299 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700300 if (isDown) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700301 setTouchActive(true);
Selim Cinek48a92a52017-05-02 20:02:30 -0700302 mTouchCancelled = false;
303 } else if (ev.getActionMasked() == MotionEvent.ACTION_UP
304 || ev.getActionMasked() == MotionEvent.ACTION_CANCEL) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700305 setTouchActive(false);
Selim Cinek48a92a52017-05-02 20:02:30 -0700306 }
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800307 if (mTouchCancelled || mExpandAnimationRunning || mExpandAnimationPending) {
Selim Cinek48a92a52017-05-02 20:02:30 -0700308 return false;
309 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700310 mFalsingManager.onTouchEvent(ev, getWidth(), getHeight());
Adrian Roos9dc32092014-09-02 23:34:10 +0200311 if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) {
312 // Disallow new pointers while the brightness mirror is visible. This is so that you
313 // can't touch anything other than the brightness slider while the mirror is showing
314 // and the rest of the panel is transparent.
315 if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
316 return false;
317 }
318 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700319 if (isDown) {
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700320 mStackScrollLayout.closeControlsIfOutsideTouch(ev);
321 }
Adrian Roos67cca742017-04-13 16:52:51 -0700322 if (mService.isDozing()) {
323 mService.mDozeScrimController.extendPulse();
324 }
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700325
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200326 // In case we start outside of the view bounds (below the status bar), we need to dispatch
327 // the touch manually as the view system can't accomodate for touches outside of the
328 // regular view bounds.
329 if (isDown && ev.getY() >= mBottom) {
330 mExpandingBelowNotch = true;
331 expandingBelowNotch = true;
332 }
333 if (expandingBelowNotch) {
Jorim Jaggi45611dd2018-06-19 17:27:08 +0200334 return mStatusBarView.dispatchTouchEvent(ev);
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200335 }
336
Adrian Roos9dc32092014-09-02 23:34:10 +0200337 return super.dispatchTouchEvent(ev);
338 }
339
340 @Override
Chris Wren5de6e942012-05-16 14:22:21 -0400341 public boolean onInterceptTouchEvent(MotionEvent ev) {
Selim Cinekbe2c4432017-05-30 12:11:09 -0700342 if (mService.isDozing() && !mStackScrollLayout.hasPulsingNotifications()) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100343 // Capture all touch events in always-on.
Adrian Roosebea7a72016-10-26 12:51:26 -0700344 return true;
345 }
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700346 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100347 if (mNotificationPanel.isFullyExpanded()
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200348 && mStackScrollLayout.getVisibility() == View.VISIBLE
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200349 && mService.getBarState() == StatusBarState.KEYGUARD
Adrian Roos500263a2017-01-23 14:49:54 -0800350 && !mService.isBouncerShowing()
351 && !mService.isDozing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200352 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700353 }
354 if (!intercept) {
355 super.onInterceptTouchEvent(ev);
356 }
Chris Wren5de6e942012-05-16 14:22:21 -0400357 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700358 MotionEvent cancellation = MotionEvent.obtain(ev);
359 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100360 mStackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200361 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700362 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400363 }
364 return intercept;
365 }
366
367 @Override
368 public boolean onTouchEvent(MotionEvent ev) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100369 boolean handled = false;
370 if (mService.isDozing()) {
371 mDoubleTapHelper.onTouchEvent(ev);
372 handled = true;
373 }
Selim Cinekf8c4add2017-06-08 09:54:58 -0700374 if ((mService.getBarState() == StatusBarState.KEYGUARD && !handled)
375 || mDragDownHelper.isDraggingDown()) {
Selim Cinek740c1112016-12-22 16:39:54 +0100376 // we still want to finish our drag down gesture when locking the screen
Jorim Jaggiecbab362014-04-23 16:13:15 +0200377 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700378 }
379 if (!handled) {
380 handled = super.onTouchEvent(ev);
381 }
John Spurlock257f2832013-09-21 18:41:53 -0400382 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500383 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400384 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
385 }
Chris Wren5de6e942012-05-16 14:22:21 -0400386 return handled;
387 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400388
389 @Override
390 public void onDraw(Canvas canvas) {
391 super.onDraw(canvas);
Jorim Jaggi0e664392014-09-27 01:30:22 +0200392 if (mService.isScrimSrcModeEnabled()) {
393 // We need to ensure that our window is always drawn fully even when we have paddings,
394 // since we simulate it to be opaque.
395 int paddedBottom = getHeight() - getPaddingBottom();
396 int paddedRight = getWidth() - getPaddingRight();
397 if (getPaddingTop() != 0) {
398 canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint);
399 }
400 if (getPaddingBottom() != 0) {
401 canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint);
402 }
403 if (getPaddingLeft() != 0) {
404 canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom,
405 mTransparentSrcPaint);
406 }
407 if (getPaddingRight() != 0) {
408 canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom,
409 mTransparentSrcPaint);
410 }
Selim Cineka0fad3b2014-09-19 17:20:05 +0200411 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400412 if (DEBUG) {
413 Paint pt = new Paint();
414 pt.setColor(0x80FFFF00);
415 pt.setStrokeWidth(12.0f);
416 pt.setStyle(Paint.Style.STROKE);
417 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
418 }
419 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400420
421 public void cancelExpandHelper() {
Selim Cinek1408eb52014-06-02 14:45:38 +0200422 if (mStackScrollLayout != null) {
423 mStackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400424 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400425 }
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700426
Selim Cinek48a92a52017-05-02 20:02:30 -0700427 public void cancelCurrentTouch() {
428 if (mTouchActive) {
429 final long now = SystemClock.uptimeMillis();
430 MotionEvent event = MotionEvent.obtain(now, now,
431 MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
432 event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
433 dispatchTouchEvent(event);
434 event.recycle();
435 mTouchCancelled = true;
436 }
437 }
438
Selim Cinek2627d722018-01-19 12:16:49 -0800439 public void setExpandAnimationRunning(boolean expandAnimationRunning) {
440 mExpandAnimationRunning = expandAnimationRunning;
441 }
442
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800443 public void setExpandAnimationPending(boolean pending) {
444 mExpandAnimationPending = pending;
445 }
446
Selim Cinekfc5c1992018-01-29 12:40:32 -0800447 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
448 pw.print(" mExpandAnimationPending="); pw.println(mExpandAnimationPending);
449 pw.print(" mExpandAnimationRunning="); pw.println(mExpandAnimationRunning);
450 pw.print(" mTouchCancelled="); pw.println(mTouchCancelled);
451 pw.print(" mTouchActive="); pw.println(mTouchActive);
452 }
453
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700454 public class LayoutParams extends FrameLayout.LayoutParams {
455
456 public boolean ignoreRightInset;
457
458 public LayoutParams(int width, int height) {
459 super(width, height);
460 }
461
462 public LayoutParams(Context c, AttributeSet attrs) {
463 super(c, attrs);
464
465 TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout);
466 ignoreRightInset = a.getBoolean(
467 R.styleable.StatusBarWindowView_Layout_ignoreRightInset, false);
468 a.recycle();
469 }
470 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700471
472 @Override
473 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback,
474 int type) {
475 if (type == ActionMode.TYPE_FLOATING) {
476 return startActionMode(originalView, callback, type);
477 }
478 return super.startActionModeForChild(originalView, callback, type);
479 }
480
481 private ActionMode createFloatingActionMode(
482 View originatingView, ActionMode.Callback2 callback) {
483 if (mFloatingActionMode != null) {
484 mFloatingActionMode.finish();
485 }
486 cleanupFloatingActionModeViews();
Tarandeep Singhc9c83a92017-08-29 14:39:22 -0700487 mFloatingToolbar = new FloatingToolbar(mFakeWindow);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700488 final FloatingActionMode mode =
Abodunrinwa Toki17293cc2017-05-22 14:16:04 +0100489 new FloatingActionMode(mContext, callback, originatingView, mFloatingToolbar);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700490 mFloatingActionModeOriginatingView = originatingView;
491 mFloatingToolbarPreDrawListener =
492 new ViewTreeObserver.OnPreDrawListener() {
493 @Override
494 public boolean onPreDraw() {
495 mode.updateViewLocationInWindow();
496 return true;
497 }
498 };
499 return mode;
500 }
501
502 private void setHandledFloatingActionMode(ActionMode mode) {
503 mFloatingActionMode = mode;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700504 mFloatingActionMode.invalidate(); // Will show the floating toolbar if necessary.
505 mFloatingActionModeOriginatingView.getViewTreeObserver()
506 .addOnPreDrawListener(mFloatingToolbarPreDrawListener);
507 }
508
509 private void cleanupFloatingActionModeViews() {
510 if (mFloatingToolbar != null) {
511 mFloatingToolbar.dismiss();
512 mFloatingToolbar = null;
513 }
514 if (mFloatingActionModeOriginatingView != null) {
515 if (mFloatingToolbarPreDrawListener != null) {
516 mFloatingActionModeOriginatingView.getViewTreeObserver()
517 .removeOnPreDrawListener(mFloatingToolbarPreDrawListener);
518 mFloatingToolbarPreDrawListener = null;
519 }
520 mFloatingActionModeOriginatingView = null;
521 }
522 }
523
524 private ActionMode startActionMode(
525 View originatingView, ActionMode.Callback callback, int type) {
526 ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback);
527 ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback);
528 if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) {
529 setHandledFloatingActionMode(mode);
530 } else {
531 mode = null;
532 }
533 return mode;
534 }
535
536 private class ActionModeCallback2Wrapper extends ActionMode.Callback2 {
537 private final ActionMode.Callback mWrapped;
538
539 public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) {
540 mWrapped = wrapped;
541 }
542
543 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
544 return mWrapped.onCreateActionMode(mode, menu);
545 }
546
547 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
548 requestFitSystemWindows();
549 return mWrapped.onPrepareActionMode(mode, menu);
550 }
551
552 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
553 return mWrapped.onActionItemClicked(mode, item);
554 }
555
556 public void onDestroyActionMode(ActionMode mode) {
557 mWrapped.onDestroyActionMode(mode);
558 if (mode == mFloatingActionMode) {
559 cleanupFloatingActionModeViews();
560 mFloatingActionMode = null;
561 }
562 requestFitSystemWindows();
563 }
564
565 @Override
566 public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
567 if (mWrapped instanceof ActionMode.Callback2) {
568 ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect);
569 } else {
570 super.onGetContentRect(mode, view, outRect);
571 }
572 }
573 }
574
575 /**
576 * Minimal window to satisfy FloatingToolbar.
577 */
578 private Window mFakeWindow = new Window(mContext) {
579 @Override
580 public void takeSurface(SurfaceHolder.Callback2 callback) {
581 }
582
583 @Override
584 public void takeInputQueue(InputQueue.Callback callback) {
585 }
586
587 @Override
588 public boolean isFloating() {
589 return false;
590 }
591
592 @Override
593 public void alwaysReadCloseOnTouchAttr() {
594 }
595
596 @Override
597 public void setContentView(@LayoutRes int layoutResID) {
598 }
599
600 @Override
601 public void setContentView(View view) {
602 }
603
604 @Override
605 public void setContentView(View view, ViewGroup.LayoutParams params) {
606 }
607
608 @Override
609 public void addContentView(View view, ViewGroup.LayoutParams params) {
610 }
611
612 @Override
613 public void clearContentView() {
614 }
615
616 @Override
617 public View getCurrentFocus() {
618 return null;
619 }
620
621 @Override
622 public LayoutInflater getLayoutInflater() {
623 return null;
624 }
625
626 @Override
627 public void setTitle(CharSequence title) {
628 }
629
630 @Override
631 public void setTitleColor(@ColorInt int textColor) {
632 }
633
634 @Override
635 public void openPanel(int featureId, KeyEvent event) {
636 }
637
638 @Override
639 public void closePanel(int featureId) {
640 }
641
642 @Override
643 public void togglePanel(int featureId, KeyEvent event) {
644 }
645
646 @Override
647 public void invalidatePanelMenu(int featureId) {
648 }
649
650 @Override
651 public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) {
652 return false;
653 }
654
655 @Override
656 public boolean performPanelIdentifierAction(int featureId, int id, int flags) {
657 return false;
658 }
659
660 @Override
661 public void closeAllPanels() {
662 }
663
664 @Override
665 public boolean performContextMenuIdentifierAction(int id, int flags) {
666 return false;
667 }
668
669 @Override
670 public void onConfigurationChanged(Configuration newConfig) {
671 }
672
673 @Override
674 public void setBackgroundDrawable(Drawable drawable) {
675 }
676
677 @Override
678 public void setFeatureDrawableResource(int featureId, @DrawableRes int resId) {
679 }
680
681 @Override
682 public void setFeatureDrawableUri(int featureId, Uri uri) {
683 }
684
685 @Override
686 public void setFeatureDrawable(int featureId, Drawable drawable) {
687 }
688
689 @Override
690 public void setFeatureDrawableAlpha(int featureId, int alpha) {
691 }
692
693 @Override
694 public void setFeatureInt(int featureId, int value) {
695 }
696
697 @Override
698 public void takeKeyEvents(boolean get) {
699 }
700
701 @Override
702 public boolean superDispatchKeyEvent(KeyEvent event) {
703 return false;
704 }
705
706 @Override
707 public boolean superDispatchKeyShortcutEvent(KeyEvent event) {
708 return false;
709 }
710
711 @Override
712 public boolean superDispatchTouchEvent(MotionEvent event) {
713 return false;
714 }
715
716 @Override
717 public boolean superDispatchTrackballEvent(MotionEvent event) {
718 return false;
719 }
720
721 @Override
722 public boolean superDispatchGenericMotionEvent(MotionEvent event) {
723 return false;
724 }
725
726 @Override
727 public View getDecorView() {
728 return StatusBarWindowView.this;
729 }
730
731 @Override
732 public View peekDecorView() {
733 return null;
734 }
735
736 @Override
737 public Bundle saveHierarchyState() {
738 return null;
739 }
740
741 @Override
742 public void restoreHierarchyState(Bundle savedInstanceState) {
743 }
744
745 @Override
746 protected void onActive() {
747 }
748
749 @Override
750 public void setChildDrawable(int featureId, Drawable drawable) {
751 }
752
753 @Override
754 public void setChildInt(int featureId, int value) {
755 }
756
757 @Override
758 public boolean isShortcutKey(int keyCode, KeyEvent event) {
759 return false;
760 }
761
762 @Override
763 public void setVolumeControlStream(int streamType) {
764 }
765
766 @Override
767 public int getVolumeControlStream() {
768 return 0;
769 }
770
771 @Override
772 public int getStatusBarColor() {
773 return 0;
774 }
775
776 @Override
777 public void setStatusBarColor(@ColorInt int color) {
778 }
779
780 @Override
781 public int getNavigationBarColor() {
782 return 0;
783 }
784
785 @Override
786 public void setNavigationBarColor(@ColorInt int color) {
787 }
788
789 @Override
790 public void setDecorCaptionShade(int decorCaptionShade) {
791 }
792
793 @Override
794 public void setResizingCaptionDrawable(Drawable drawable) {
795 }
796
797 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -0700798 public void onMultiWindowModeChanged() {
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700799 }
800
801 @Override
Winson Chung4d8681f2017-05-23 16:22:08 -0700802 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
803 }
804
805 @Override
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700806 public void reportActivityRelaunched() {
807 }
808 };
809
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400810}
811