blob: a8ae5f65a2a023a2d31c694c2f6544105a431c1b [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;
Issei Suzukica19e6e2019-02-26 12:39:11 +010032import android.hardware.display.AmbientDisplayConfiguration;
Jaewan Kim50269362016-12-23 11:22:02 +090033import android.media.AudioManager;
John Spurlock0b99ea92014-10-01 15:32:22 -040034import android.media.session.MediaSessionLegacyHelper;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070035import android.net.Uri;
36import android.os.Bundle;
Adrian Roos8008bd12017-02-22 15:02:09 +010037import android.os.SystemClock;
Lucas Dupin34f6d962019-02-22 14:47:50 -080038import android.os.UserHandle;
39import android.provider.Settings;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040040import android.util.AttributeSet;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070041import android.view.ActionMode;
felkachang7749c9a2018-06-11 15:56:15 +080042import android.view.DisplayCutout;
Lucas Dupin34f6d962019-02-22 14:47:50 -080043import android.view.GestureDetector;
Selim Cinek48a92a52017-05-02 20:02:30 -070044import android.view.InputDevice;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070045import android.view.InputQueue;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040046import android.view.KeyEvent;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070047import android.view.LayoutInflater;
48import android.view.Menu;
49import android.view.MenuItem;
Chris Wren5de6e942012-05-16 14:22:21 -040050import android.view.MotionEvent;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070051import android.view.SurfaceHolder;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070052import android.view.View;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070053import android.view.ViewGroup;
54import android.view.ViewTreeObserver;
55import android.view.Window;
Jorim Jaggib6030952018-10-23 18:31:52 +020056import android.view.WindowInsetsController;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040057import android.widget.FrameLayout;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040058
Selim Cinekf8c4add2017-06-08 09:54:58 -070059import com.android.internal.annotations.VisibleForTesting;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070060import com.android.internal.view.FloatingActionMode;
61import com.android.internal.widget.FloatingToolbar;
Jason Monk1fd3fc32018-08-14 17:20:09 -040062import com.android.systemui.Dependency;
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -040063import com.android.systemui.ExpandHelper;
Chris Wren5de6e942012-05-16 14:22:21 -040064import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070065import com.android.systemui.classifier.FalsingManager;
Beverly8fdb5332019-02-04 14:29:49 -050066import com.android.systemui.plugins.statusbar.StatusBarStateController;
Jorim Jaggiecbab362014-04-23 16:13:15 +020067import com.android.systemui.statusbar.DragDownHelper;
68import com.android.systemui.statusbar.StatusBarState;
Rohan Shah20790b82018-07-02 17:21:04 -070069import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Lucas Dupin34f6d962019-02-22 14:47:50 -080070import com.android.systemui.tuner.TunerService;
Chris Wren5de6e942012-05-16 14:22:21 -040071
Selim Cinekfc5c1992018-01-29 12:40:32 -080072import java.io.FileDescriptor;
73import java.io.PrintWriter;
74
Lucas Dupin34f6d962019-02-22 14:47:50 -080075/**
76 * Combined status bar and notification panel view. Also holding backdrop and scrims.
77 */
Jorim Jaggiecbab362014-04-23 16:13:15 +020078public class StatusBarWindowView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040079 public static final String TAG = "StatusBarWindowView";
Jason Monk2a6ea9c2017-01-26 11:14:51 -050080 public static final boolean DEBUG = StatusBar.DEBUG;
Chris Wren5de6e942012-05-16 14:22:21 -040081
Lucas Dupin34f6d962019-02-22 14:47:50 -080082 private final GestureDetector mGestureDetector;
83 private final StatusBarStateController mStatusBarStateController;
84 private boolean mDoubleTapEnabled;
85 private boolean mSingleTapEnabled;
Jorim Jaggiecbab362014-04-23 16:13:15 +020086 private DragDownHelper mDragDownHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010087 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070088 private NotificationPanelView mNotificationPanel;
Adrian Roos9dc32092014-09-02 23:34:10 +020089 private View mBrightnessMirror;
Jorim Jaggif0c38072018-06-19 17:27:08 +020090 private PhoneStatusBarView mStatusBarView;
Chris Wren5de6e942012-05-16 14:22:21 -040091
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070092 private int mRightInset = 0;
Adrian Roos85d202b2016-06-02 16:27:47 -070093 private int mLeftInset = 0;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070094
Jason Monk2a6ea9c2017-01-26 11:14:51 -050095 private StatusBar mService;
Selim Cineka0fad3b2014-09-19 17:20:05 +020096 private final Paint mTransparentSrcPaint = new Paint();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070097 private FalsingManager mFalsingManager;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040098
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070099 // Implements the floating action mode for TextView's Cut/Copy/Past menu. Normally provided by
100 // DecorView, but since this is a special window we have to roll our own.
101 private View mFloatingActionModeOriginatingView;
102 private ActionMode mFloatingActionMode;
103 private FloatingToolbar mFloatingToolbar;
104 private ViewTreeObserver.OnPreDrawListener mFloatingToolbarPreDrawListener;
Selim Cinek48a92a52017-05-02 20:02:30 -0700105 private boolean mTouchCancelled;
106 private boolean mTouchActive;
Selim Cinek2627d722018-01-19 12:16:49 -0800107 private boolean mExpandAnimationRunning;
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800108 private boolean mExpandAnimationPending;
Lucas Dupin34f6d962019-02-22 14:47:50 -0800109
110 private final GestureDetector.SimpleOnGestureListener mGestureListener =
111 new GestureDetector.SimpleOnGestureListener() {
112 @Override
113 public boolean onSingleTapConfirmed(MotionEvent e) {
114 if (mSingleTapEnabled) {
115 mService.wakeUpIfDozing(SystemClock.uptimeMillis(), StatusBarWindowView.this,
116 "SINGLE_TAP");
117 }
118 return mSingleTapEnabled;
119 }
120
121 @Override
122 public boolean onDoubleTap(MotionEvent e) {
123 if (mDoubleTapEnabled) {
124 mService.wakeUpIfDozing(SystemClock.uptimeMillis(), StatusBarWindowView.this,
125 "DOUBLE_TAP");
126 }
127 return mDoubleTapEnabled;
128 }
129 };
130 private final TunerService.Tunable mTunable = (key, newValue) -> {
131 AmbientDisplayConfiguration configuration = new AmbientDisplayConfiguration(mContext);
132 switch (key) {
133 case Settings.Secure.DOZE_DOUBLE_TAP_GESTURE:
134 mDoubleTapEnabled = configuration.doubleTapGestureEnabled(UserHandle.USER_CURRENT);
135 break;
136 case Settings.Secure.DOZE_TAP_SCREEN_GESTURE:
137 mSingleTapEnabled = configuration.tapGestureEnabled(UserHandle.USER_CURRENT);
138 }
139 };
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700140
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200141 /**
142 * If set to true, the current gesture started below the notch and we need to dispatch touch
143 * events manually as it's outside of the regular view bounds.
144 */
145 private boolean mExpandingBelowNotch;
146
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400147 public StatusBarWindowView(Context context, AttributeSet attrs) {
148 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -0400149 setMotionEventSplittingEnabled(false);
Selim Cineka0fad3b2014-09-19 17:20:05 +0200150 mTransparentSrcPaint.setColor(0);
151 mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700152 mFalsingManager = FalsingManager.getInstance(context);
Lucas Dupin34f6d962019-02-22 14:47:50 -0800153 mGestureDetector = new GestureDetector(context, mGestureListener);
154 mStatusBarStateController = Dependency.get(StatusBarStateController.class);
155 Dependency.get(TunerService.class).addTunable(mTunable,
156 Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
157 Settings.Secure.DOZE_TAP_SCREEN_GESTURE);
Chris Wren5de6e942012-05-16 14:22:21 -0400158 }
159
160 @Override
John Spurlockfba91202014-04-22 12:58:26 -0400161 protected boolean fitSystemWindows(Rect insets) {
162 if (getFitsSystemWindows()) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700163 boolean paddingChanged = insets.top != getPaddingTop()
Jorim Jaggi416493b2014-09-13 03:57:32 +0200164 || insets.bottom != getPaddingBottom();
Jorim Jaggiaa806142015-05-20 18:04:16 -0700165
felkachang7749c9a2018-06-11 15:56:15 +0800166 int rightCutout = 0;
167 int leftCutout = 0;
168 DisplayCutout displayCutout = getRootWindowInsets().getDisplayCutout();
169 if (displayCutout != null) {
170 leftCutout = displayCutout.getSafeInsetLeft();
171 rightCutout = displayCutout.getSafeInsetRight();
172 }
173
174 int targetLeft = Math.max(insets.left, leftCutout);
175 int targetRight = Math.max(insets.right, rightCutout);
176
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700177 // Super-special right inset handling, because scrims and backdrop need to ignore it.
felkachang7749c9a2018-06-11 15:56:15 +0800178 if (targetRight != mRightInset || targetLeft != mLeftInset) {
179 mRightInset = targetRight;
180 mLeftInset = targetLeft;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700181 applyMargins();
182 }
Adrian Roos85d202b2016-06-02 16:27:47 -0700183 // Drop top inset, and pass through bottom inset.
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700184 if (paddingChanged) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700185 setPadding(0, 0, 0, 0);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200186 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200187 insets.left = 0;
188 insets.top = 0;
189 insets.right = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400190 } else {
Adrian Roos85d202b2016-06-02 16:27:47 -0700191 if (mRightInset != 0 || mLeftInset != 0) {
Adrian Roose49e4092015-06-10 18:50:18 -0700192 mRightInset = 0;
Adrian Roos85d202b2016-06-02 16:27:47 -0700193 mLeftInset = 0;
Adrian Roose49e4092015-06-10 18:50:18 -0700194 applyMargins();
195 }
Jorim Jaggi416493b2014-09-13 03:57:32 +0200196 boolean changed = getPaddingLeft() != 0
197 || getPaddingRight() != 0
198 || getPaddingTop() != 0
199 || getPaddingBottom() != 0;
200 if (changed) {
201 setPadding(0, 0, 0, 0);
202 }
Jorim Jaggiaa806142015-05-20 18:04:16 -0700203 insets.top = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400204 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200205 return false;
John Spurlockfba91202014-04-22 12:58:26 -0400206 }
207
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700208 private void applyMargins() {
209 final int N = getChildCount();
210 for (int i = 0; i < N; i++) {
211 View child = getChildAt(i);
212 if (child.getLayoutParams() instanceof LayoutParams) {
213 LayoutParams lp = (LayoutParams) child.getLayoutParams();
Adrian Roos85d202b2016-06-02 16:27:47 -0700214 if (!lp.ignoreRightInset
215 && (lp.rightMargin != mRightInset || lp.leftMargin != mLeftInset)) {
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700216 lp.rightMargin = mRightInset;
Adrian Roos85d202b2016-06-02 16:27:47 -0700217 lp.leftMargin = mLeftInset;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700218 child.requestLayout();
219 }
220 }
221 }
222 }
223
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400224 @VisibleForTesting
225 protected NotificationStackScrollLayout getStackScrollLayout() {
226 return mStackScrollLayout;
227 }
228
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700229 @Override
230 public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) {
231 return new LayoutParams(getContext(), attrs);
232 }
233
234 @Override
235 protected FrameLayout.LayoutParams generateDefaultLayoutParams() {
236 return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
237 }
238
John Spurlockfba91202014-04-22 12:58:26 -0400239 @Override
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400240 protected void onFinishInflate() {
241 super.onFinishInflate();
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100242 mStackScrollLayout = (NotificationStackScrollLayout) findViewById(
243 R.id.notification_stack_scroller);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700244 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
Adrian Roos9dc32092014-09-02 23:34:10 +0200245 mBrightnessMirror = findViewById(R.id.brightness_mirror);
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400246 }
247
dooyoung.hwange4b841e2016-11-16 08:59:23 +0900248 @Override
249 public void onViewAdded(View child) {
250 super.onViewAdded(child);
251 if (child.getId() == R.id.brightness_mirror) {
252 mBrightnessMirror = child;
253 }
254 }
255
Jorim Jaggif0c38072018-06-19 17:27:08 +0200256 public void setStatusBarView(PhoneStatusBarView statusBarView) {
257 mStatusBarView = statusBarView;
258 }
259
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500260 public void setService(StatusBar service) {
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400261 mService = service;
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400262 NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
263 ExpandHelper.Callback expandHelperCallback = stackScrollLayout.getExpandHelperCallback();
264 DragDownHelper.DragDownCallback dragDownCallback = stackScrollLayout.getDragDownCallback();
265 setDragDownHelper(new DragDownHelper(getContext(), this, expandHelperCallback,
266 dragDownCallback));
Selim Cinekf8c4add2017-06-08 09:54:58 -0700267 }
268
269 @VisibleForTesting
270 void setDragDownHelper(DragDownHelper dragDownHelper) {
271 mDragDownHelper = dragDownHelper;
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400272 }
273
274 @Override
275 protected void onAttachedToWindow () {
276 super.onAttachedToWindow();
Lucas Dupin90a38dd2018-09-05 09:37:37 -0700277 setWillNotDraw(!DEBUG);
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400278 }
279
280 @Override
281 public boolean dispatchKeyEvent(KeyEvent event) {
Adrian Roos56cf73a2016-07-18 14:23:32 -0700282 if (mService.interceptMediaKey(event)) {
283 return true;
284 }
285 if (super.dispatchKeyEvent(event)) {
286 return true;
287 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400288 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
289 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200290 case KeyEvent.KEYCODE_BACK:
291 if (!down) {
292 mService.onBackPressed();
293 }
294 return true;
295 case KeyEvent.KEYCODE_MENU:
296 if (!down) {
297 return mService.onMenuPressed();
298 }
Jorim Jaggi34250762014-07-03 23:51:19 +0200299 case KeyEvent.KEYCODE_SPACE:
300 if (!down) {
301 return mService.onSpacePressed();
302 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400303 break;
John Spurlockd06aa572014-09-10 10:40:49 -0400304 case KeyEvent.KEYCODE_VOLUME_DOWN:
305 case KeyEvent.KEYCODE_VOLUME_UP:
John Spurlock0b99ea92014-10-01 15:32:22 -0400306 if (mService.isDozing()) {
Jaewan Kim50269362016-12-23 11:22:02 +0900307 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
308 event, AudioManager.USE_DEFAULT_STREAM_TYPE, true);
John Spurlock0b99ea92014-10-01 15:32:22 -0400309 return true;
John Spurlockd06aa572014-09-10 10:40:49 -0400310 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400311 break;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400312 }
Adrian Roos56cf73a2016-07-18 14:23:32 -0700313 return false;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400314 }
Chris Wren5de6e942012-05-16 14:22:21 -0400315
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700316 public void setTouchActive(boolean touchActive) {
317 mTouchActive = touchActive;
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700318 }
319
Chris Wren5de6e942012-05-16 14:22:21 -0400320 @Override
Adrian Roos9dc32092014-09-02 23:34:10 +0200321 public boolean dispatchTouchEvent(MotionEvent ev) {
Selim Cinek48a92a52017-05-02 20:02:30 -0700322 boolean isDown = ev.getActionMasked() == MotionEvent.ACTION_DOWN;
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200323 boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP;
Adrian Roosa6c03f82017-07-26 16:20:30 +0200324 boolean isCancel = ev.getActionMasked() == MotionEvent.ACTION_CANCEL;
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200325
326 // Reset manual touch dispatch state here but make sure the UP/CANCEL event still gets
327 // delivered.
328 boolean expandingBelowNotch = mExpandingBelowNotch;
329 if (isUp || isCancel) {
330 mExpandingBelowNotch = false;
331 }
332
Adrian Roosa6c03f82017-07-26 16:20:30 +0200333 if (!isCancel && mService.shouldIgnoreTouch()) {
334 return false;
335 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700336 if (isDown && mNotificationPanel.isFullyCollapsed()) {
Jorim Jaggie05256e2016-09-08 14:58:20 -0700337 mNotificationPanel.startExpandLatencyTracking();
338 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700339 if (isDown) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700340 setTouchActive(true);
Selim Cinek48a92a52017-05-02 20:02:30 -0700341 mTouchCancelled = false;
342 } else if (ev.getActionMasked() == MotionEvent.ACTION_UP
343 || ev.getActionMasked() == MotionEvent.ACTION_CANCEL) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700344 setTouchActive(false);
Selim Cinek48a92a52017-05-02 20:02:30 -0700345 }
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800346 if (mTouchCancelled || mExpandAnimationRunning || mExpandAnimationPending) {
Selim Cinek48a92a52017-05-02 20:02:30 -0700347 return false;
348 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700349 mFalsingManager.onTouchEvent(ev, getWidth(), getHeight());
Lucas Dupin34f6d962019-02-22 14:47:50 -0800350 mGestureDetector.onTouchEvent(ev);
Adrian Roos9dc32092014-09-02 23:34:10 +0200351 if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) {
352 // Disallow new pointers while the brightness mirror is visible. This is so that you
353 // can't touch anything other than the brightness slider while the mirror is showing
354 // and the rest of the panel is transparent.
355 if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
356 return false;
357 }
358 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700359 if (isDown) {
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400360 getStackScrollLayout().closeControlsIfOutsideTouch(ev);
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700361 }
Adrian Roos67cca742017-04-13 16:52:51 -0700362 if (mService.isDozing()) {
363 mService.mDozeScrimController.extendPulse();
364 }
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700365
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200366 // In case we start outside of the view bounds (below the status bar), we need to dispatch
367 // the touch manually as the view system can't accomodate for touches outside of the
368 // regular view bounds.
369 if (isDown && ev.getY() >= mBottom) {
370 mExpandingBelowNotch = true;
371 expandingBelowNotch = true;
372 }
373 if (expandingBelowNotch) {
Jorim Jaggif0c38072018-06-19 17:27:08 +0200374 return mStatusBarView.dispatchTouchEvent(ev);
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200375 }
376
Adrian Roos9dc32092014-09-02 23:34:10 +0200377 return super.dispatchTouchEvent(ev);
378 }
379
380 @Override
Chris Wren5de6e942012-05-16 14:22:21 -0400381 public boolean onInterceptTouchEvent(MotionEvent ev) {
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400382 NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
Lucas Dupin1c327432019-01-03 13:37:53 -0800383 if (mService.isDozing() && !mService.isPulsing()) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100384 // Capture all touch events in always-on.
Adrian Roosebea7a72016-10-26 12:51:26 -0700385 return true;
386 }
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700387 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100388 if (mNotificationPanel.isFullyExpanded()
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400389 && stackScrollLayout.getVisibility() == View.VISIBLE
Jason Monk1fd3fc32018-08-14 17:20:09 -0400390 && mStatusBarStateController.getState() == StatusBarState.KEYGUARD
Selim Cinek3d6ae232019-01-04 14:14:33 -0800391 && !mService.isBouncerShowing()
392 && !mService.isDozing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200393 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700394 }
395 if (!intercept) {
396 super.onInterceptTouchEvent(ev);
397 }
Chris Wren5de6e942012-05-16 14:22:21 -0400398 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700399 MotionEvent cancellation = MotionEvent.obtain(ev);
400 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400401 stackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200402 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700403 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400404 }
405 return intercept;
406 }
407
408 @Override
409 public boolean onTouchEvent(MotionEvent ev) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100410 boolean handled = false;
411 if (mService.isDozing()) {
Lucas Dupin1c327432019-01-03 13:37:53 -0800412 handled = !mService.isPulsing();
Adrian Roos8008bd12017-02-22 15:02:09 +0100413 }
Jason Monk1fd3fc32018-08-14 17:20:09 -0400414 if ((mStatusBarStateController.getState() == StatusBarState.KEYGUARD && !handled)
Selim Cinekf8c4add2017-06-08 09:54:58 -0700415 || mDragDownHelper.isDraggingDown()) {
Selim Cinek740c1112016-12-22 16:39:54 +0100416 // we still want to finish our drag down gesture when locking the screen
Jorim Jaggiecbab362014-04-23 16:13:15 +0200417 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700418 }
419 if (!handled) {
420 handled = super.onTouchEvent(ev);
421 }
John Spurlock257f2832013-09-21 18:41:53 -0400422 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500423 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400424 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
425 }
Chris Wren5de6e942012-05-16 14:22:21 -0400426 return handled;
427 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400428
429 @Override
430 public void onDraw(Canvas canvas) {
431 super.onDraw(canvas);
432 if (DEBUG) {
433 Paint pt = new Paint();
434 pt.setColor(0x80FFFF00);
435 pt.setStrokeWidth(12.0f);
436 pt.setStyle(Paint.Style.STROKE);
437 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
438 }
439 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400440
441 public void cancelExpandHelper() {
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400442 NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
443 if (stackScrollLayout != null) {
444 stackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400445 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400446 }
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700447
Selim Cinek48a92a52017-05-02 20:02:30 -0700448 public void cancelCurrentTouch() {
449 if (mTouchActive) {
450 final long now = SystemClock.uptimeMillis();
451 MotionEvent event = MotionEvent.obtain(now, now,
452 MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
453 event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
454 dispatchTouchEvent(event);
455 event.recycle();
456 mTouchCancelled = true;
457 }
458 }
459
Selim Cinek2627d722018-01-19 12:16:49 -0800460 public void setExpandAnimationRunning(boolean expandAnimationRunning) {
461 mExpandAnimationRunning = expandAnimationRunning;
462 }
463
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800464 public void setExpandAnimationPending(boolean pending) {
465 mExpandAnimationPending = pending;
466 }
467
Selim Cinekfc5c1992018-01-29 12:40:32 -0800468 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
469 pw.print(" mExpandAnimationPending="); pw.println(mExpandAnimationPending);
470 pw.print(" mExpandAnimationRunning="); pw.println(mExpandAnimationRunning);
471 pw.print(" mTouchCancelled="); pw.println(mTouchCancelled);
472 pw.print(" mTouchActive="); pw.println(mTouchActive);
473 }
474
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700475 public class LayoutParams extends FrameLayout.LayoutParams {
476
477 public boolean ignoreRightInset;
478
479 public LayoutParams(int width, int height) {
480 super(width, height);
481 }
482
483 public LayoutParams(Context c, AttributeSet attrs) {
484 super(c, attrs);
485
486 TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout);
487 ignoreRightInset = a.getBoolean(
488 R.styleable.StatusBarWindowView_Layout_ignoreRightInset, false);
489 a.recycle();
490 }
491 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700492
493 @Override
494 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback,
495 int type) {
496 if (type == ActionMode.TYPE_FLOATING) {
497 return startActionMode(originalView, callback, type);
498 }
499 return super.startActionModeForChild(originalView, callback, type);
500 }
501
502 private ActionMode createFloatingActionMode(
503 View originatingView, ActionMode.Callback2 callback) {
504 if (mFloatingActionMode != null) {
505 mFloatingActionMode.finish();
506 }
507 cleanupFloatingActionModeViews();
Tarandeep Singhc9c83a92017-08-29 14:39:22 -0700508 mFloatingToolbar = new FloatingToolbar(mFakeWindow);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700509 final FloatingActionMode mode =
Abodunrinwa Toki17293cc2017-05-22 14:16:04 +0100510 new FloatingActionMode(mContext, callback, originatingView, mFloatingToolbar);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700511 mFloatingActionModeOriginatingView = originatingView;
512 mFloatingToolbarPreDrawListener =
513 new ViewTreeObserver.OnPreDrawListener() {
514 @Override
515 public boolean onPreDraw() {
516 mode.updateViewLocationInWindow();
517 return true;
518 }
519 };
520 return mode;
521 }
522
523 private void setHandledFloatingActionMode(ActionMode mode) {
524 mFloatingActionMode = mode;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700525 mFloatingActionMode.invalidate(); // Will show the floating toolbar if necessary.
526 mFloatingActionModeOriginatingView.getViewTreeObserver()
527 .addOnPreDrawListener(mFloatingToolbarPreDrawListener);
528 }
529
530 private void cleanupFloatingActionModeViews() {
531 if (mFloatingToolbar != null) {
532 mFloatingToolbar.dismiss();
533 mFloatingToolbar = null;
534 }
535 if (mFloatingActionModeOriginatingView != null) {
536 if (mFloatingToolbarPreDrawListener != null) {
537 mFloatingActionModeOriginatingView.getViewTreeObserver()
538 .removeOnPreDrawListener(mFloatingToolbarPreDrawListener);
539 mFloatingToolbarPreDrawListener = null;
540 }
541 mFloatingActionModeOriginatingView = null;
542 }
543 }
544
545 private ActionMode startActionMode(
546 View originatingView, ActionMode.Callback callback, int type) {
547 ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback);
548 ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback);
549 if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) {
550 setHandledFloatingActionMode(mode);
551 } else {
552 mode = null;
553 }
554 return mode;
555 }
556
557 private class ActionModeCallback2Wrapper extends ActionMode.Callback2 {
558 private final ActionMode.Callback mWrapped;
559
560 public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) {
561 mWrapped = wrapped;
562 }
563
564 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
565 return mWrapped.onCreateActionMode(mode, menu);
566 }
567
568 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
569 requestFitSystemWindows();
570 return mWrapped.onPrepareActionMode(mode, menu);
571 }
572
573 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
574 return mWrapped.onActionItemClicked(mode, item);
575 }
576
577 public void onDestroyActionMode(ActionMode mode) {
578 mWrapped.onDestroyActionMode(mode);
579 if (mode == mFloatingActionMode) {
580 cleanupFloatingActionModeViews();
581 mFloatingActionMode = null;
582 }
583 requestFitSystemWindows();
584 }
585
586 @Override
587 public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
588 if (mWrapped instanceof ActionMode.Callback2) {
589 ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect);
590 } else {
591 super.onGetContentRect(mode, view, outRect);
592 }
593 }
594 }
595
596 /**
597 * Minimal window to satisfy FloatingToolbar.
598 */
599 private Window mFakeWindow = new Window(mContext) {
600 @Override
601 public void takeSurface(SurfaceHolder.Callback2 callback) {
602 }
603
604 @Override
605 public void takeInputQueue(InputQueue.Callback callback) {
606 }
607
608 @Override
609 public boolean isFloating() {
610 return false;
611 }
612
613 @Override
614 public void alwaysReadCloseOnTouchAttr() {
615 }
616
617 @Override
618 public void setContentView(@LayoutRes int layoutResID) {
619 }
620
621 @Override
622 public void setContentView(View view) {
623 }
624
625 @Override
626 public void setContentView(View view, ViewGroup.LayoutParams params) {
627 }
628
629 @Override
630 public void addContentView(View view, ViewGroup.LayoutParams params) {
631 }
632
633 @Override
634 public void clearContentView() {
635 }
636
637 @Override
638 public View getCurrentFocus() {
639 return null;
640 }
641
642 @Override
643 public LayoutInflater getLayoutInflater() {
644 return null;
645 }
646
647 @Override
648 public void setTitle(CharSequence title) {
649 }
650
651 @Override
652 public void setTitleColor(@ColorInt int textColor) {
653 }
654
655 @Override
656 public void openPanel(int featureId, KeyEvent event) {
657 }
658
659 @Override
660 public void closePanel(int featureId) {
661 }
662
663 @Override
664 public void togglePanel(int featureId, KeyEvent event) {
665 }
666
667 @Override
668 public void invalidatePanelMenu(int featureId) {
669 }
670
671 @Override
672 public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) {
673 return false;
674 }
675
676 @Override
677 public boolean performPanelIdentifierAction(int featureId, int id, int flags) {
678 return false;
679 }
680
681 @Override
682 public void closeAllPanels() {
683 }
684
685 @Override
686 public boolean performContextMenuIdentifierAction(int id, int flags) {
687 return false;
688 }
689
690 @Override
691 public void onConfigurationChanged(Configuration newConfig) {
692 }
693
694 @Override
695 public void setBackgroundDrawable(Drawable drawable) {
696 }
697
698 @Override
699 public void setFeatureDrawableResource(int featureId, @DrawableRes int resId) {
700 }
701
702 @Override
703 public void setFeatureDrawableUri(int featureId, Uri uri) {
704 }
705
706 @Override
707 public void setFeatureDrawable(int featureId, Drawable drawable) {
708 }
709
710 @Override
711 public void setFeatureDrawableAlpha(int featureId, int alpha) {
712 }
713
714 @Override
715 public void setFeatureInt(int featureId, int value) {
716 }
717
718 @Override
719 public void takeKeyEvents(boolean get) {
720 }
721
722 @Override
723 public boolean superDispatchKeyEvent(KeyEvent event) {
724 return false;
725 }
726
727 @Override
728 public boolean superDispatchKeyShortcutEvent(KeyEvent event) {
729 return false;
730 }
731
732 @Override
733 public boolean superDispatchTouchEvent(MotionEvent event) {
734 return false;
735 }
736
737 @Override
738 public boolean superDispatchTrackballEvent(MotionEvent event) {
739 return false;
740 }
741
742 @Override
743 public boolean superDispatchGenericMotionEvent(MotionEvent event) {
744 return false;
745 }
746
747 @Override
748 public View getDecorView() {
749 return StatusBarWindowView.this;
750 }
751
752 @Override
753 public View peekDecorView() {
754 return null;
755 }
756
757 @Override
758 public Bundle saveHierarchyState() {
759 return null;
760 }
761
762 @Override
763 public void restoreHierarchyState(Bundle savedInstanceState) {
764 }
765
766 @Override
767 protected void onActive() {
768 }
769
770 @Override
771 public void setChildDrawable(int featureId, Drawable drawable) {
772 }
773
774 @Override
775 public void setChildInt(int featureId, int value) {
776 }
777
778 @Override
779 public boolean isShortcutKey(int keyCode, KeyEvent event) {
780 return false;
781 }
782
783 @Override
784 public void setVolumeControlStream(int streamType) {
785 }
786
787 @Override
788 public int getVolumeControlStream() {
789 return 0;
790 }
791
792 @Override
793 public int getStatusBarColor() {
794 return 0;
795 }
796
797 @Override
798 public void setStatusBarColor(@ColorInt int color) {
799 }
800
801 @Override
802 public int getNavigationBarColor() {
803 return 0;
804 }
805
806 @Override
807 public void setNavigationBarColor(@ColorInt int color) {
808 }
809
810 @Override
811 public void setDecorCaptionShade(int decorCaptionShade) {
812 }
813
814 @Override
815 public void setResizingCaptionDrawable(Drawable drawable) {
816 }
817
818 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -0700819 public void onMultiWindowModeChanged() {
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700820 }
821
822 @Override
Winson Chung4d8681f2017-05-23 16:22:08 -0700823 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
824 }
825
826 @Override
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700827 public void reportActivityRelaunched() {
828 }
Jorim Jaggib6030952018-10-23 18:31:52 +0200829
830 @Override
831 public WindowInsetsController getInsetsController() {
832 return null;
833 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700834 };
835
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400836}
837