blob: 50c4fac31bbfc609f554c83cd07d69e2978e6a3d [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
Lucas Dupin1c327432019-01-03 13:37:53 -0800391 && !mService.isBouncerShowing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200392 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700393 }
394 if (!intercept) {
395 super.onInterceptTouchEvent(ev);
396 }
Chris Wren5de6e942012-05-16 14:22:21 -0400397 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700398 MotionEvent cancellation = MotionEvent.obtain(ev);
399 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400400 stackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200401 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700402 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400403 }
404 return intercept;
405 }
406
407 @Override
408 public boolean onTouchEvent(MotionEvent ev) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100409 boolean handled = false;
410 if (mService.isDozing()) {
Lucas Dupin1c327432019-01-03 13:37:53 -0800411 handled = !mService.isPulsing();
Adrian Roos8008bd12017-02-22 15:02:09 +0100412 }
Jason Monk1fd3fc32018-08-14 17:20:09 -0400413 if ((mStatusBarStateController.getState() == StatusBarState.KEYGUARD && !handled)
Selim Cinekf8c4add2017-06-08 09:54:58 -0700414 || mDragDownHelper.isDraggingDown()) {
Selim Cinek740c1112016-12-22 16:39:54 +0100415 // we still want to finish our drag down gesture when locking the screen
Jorim Jaggiecbab362014-04-23 16:13:15 +0200416 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700417 }
418 if (!handled) {
419 handled = super.onTouchEvent(ev);
420 }
John Spurlock257f2832013-09-21 18:41:53 -0400421 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500422 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400423 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
424 }
Chris Wren5de6e942012-05-16 14:22:21 -0400425 return handled;
426 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400427
428 @Override
429 public void onDraw(Canvas canvas) {
430 super.onDraw(canvas);
431 if (DEBUG) {
432 Paint pt = new Paint();
433 pt.setColor(0x80FFFF00);
434 pt.setStrokeWidth(12.0f);
435 pt.setStyle(Paint.Style.STROKE);
436 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
437 }
438 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400439
440 public void cancelExpandHelper() {
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400441 NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
442 if (stackScrollLayout != null) {
443 stackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400444 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400445 }
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700446
Selim Cinek48a92a52017-05-02 20:02:30 -0700447 public void cancelCurrentTouch() {
448 if (mTouchActive) {
449 final long now = SystemClock.uptimeMillis();
450 MotionEvent event = MotionEvent.obtain(now, now,
451 MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
452 event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
453 dispatchTouchEvent(event);
454 event.recycle();
455 mTouchCancelled = true;
456 }
457 }
458
Selim Cinek2627d722018-01-19 12:16:49 -0800459 public void setExpandAnimationRunning(boolean expandAnimationRunning) {
460 mExpandAnimationRunning = expandAnimationRunning;
461 }
462
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800463 public void setExpandAnimationPending(boolean pending) {
464 mExpandAnimationPending = pending;
465 }
466
Selim Cinekfc5c1992018-01-29 12:40:32 -0800467 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
468 pw.print(" mExpandAnimationPending="); pw.println(mExpandAnimationPending);
469 pw.print(" mExpandAnimationRunning="); pw.println(mExpandAnimationRunning);
470 pw.print(" mTouchCancelled="); pw.println(mTouchCancelled);
471 pw.print(" mTouchActive="); pw.println(mTouchActive);
472 }
473
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700474 public class LayoutParams extends FrameLayout.LayoutParams {
475
476 public boolean ignoreRightInset;
477
478 public LayoutParams(int width, int height) {
479 super(width, height);
480 }
481
482 public LayoutParams(Context c, AttributeSet attrs) {
483 super(c, attrs);
484
485 TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout);
486 ignoreRightInset = a.getBoolean(
487 R.styleable.StatusBarWindowView_Layout_ignoreRightInset, false);
488 a.recycle();
489 }
490 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700491
492 @Override
493 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback,
494 int type) {
495 if (type == ActionMode.TYPE_FLOATING) {
496 return startActionMode(originalView, callback, type);
497 }
498 return super.startActionModeForChild(originalView, callback, type);
499 }
500
501 private ActionMode createFloatingActionMode(
502 View originatingView, ActionMode.Callback2 callback) {
503 if (mFloatingActionMode != null) {
504 mFloatingActionMode.finish();
505 }
506 cleanupFloatingActionModeViews();
Tarandeep Singhc9c83a92017-08-29 14:39:22 -0700507 mFloatingToolbar = new FloatingToolbar(mFakeWindow);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700508 final FloatingActionMode mode =
Abodunrinwa Toki17293cc2017-05-22 14:16:04 +0100509 new FloatingActionMode(mContext, callback, originatingView, mFloatingToolbar);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700510 mFloatingActionModeOriginatingView = originatingView;
511 mFloatingToolbarPreDrawListener =
512 new ViewTreeObserver.OnPreDrawListener() {
513 @Override
514 public boolean onPreDraw() {
515 mode.updateViewLocationInWindow();
516 return true;
517 }
518 };
519 return mode;
520 }
521
522 private void setHandledFloatingActionMode(ActionMode mode) {
523 mFloatingActionMode = mode;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700524 mFloatingActionMode.invalidate(); // Will show the floating toolbar if necessary.
525 mFloatingActionModeOriginatingView.getViewTreeObserver()
526 .addOnPreDrawListener(mFloatingToolbarPreDrawListener);
527 }
528
529 private void cleanupFloatingActionModeViews() {
530 if (mFloatingToolbar != null) {
531 mFloatingToolbar.dismiss();
532 mFloatingToolbar = null;
533 }
534 if (mFloatingActionModeOriginatingView != null) {
535 if (mFloatingToolbarPreDrawListener != null) {
536 mFloatingActionModeOriginatingView.getViewTreeObserver()
537 .removeOnPreDrawListener(mFloatingToolbarPreDrawListener);
538 mFloatingToolbarPreDrawListener = null;
539 }
540 mFloatingActionModeOriginatingView = null;
541 }
542 }
543
544 private ActionMode startActionMode(
545 View originatingView, ActionMode.Callback callback, int type) {
546 ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback);
547 ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback);
548 if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) {
549 setHandledFloatingActionMode(mode);
550 } else {
551 mode = null;
552 }
553 return mode;
554 }
555
556 private class ActionModeCallback2Wrapper extends ActionMode.Callback2 {
557 private final ActionMode.Callback mWrapped;
558
559 public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) {
560 mWrapped = wrapped;
561 }
562
563 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
564 return mWrapped.onCreateActionMode(mode, menu);
565 }
566
567 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
568 requestFitSystemWindows();
569 return mWrapped.onPrepareActionMode(mode, menu);
570 }
571
572 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
573 return mWrapped.onActionItemClicked(mode, item);
574 }
575
576 public void onDestroyActionMode(ActionMode mode) {
577 mWrapped.onDestroyActionMode(mode);
578 if (mode == mFloatingActionMode) {
579 cleanupFloatingActionModeViews();
580 mFloatingActionMode = null;
581 }
582 requestFitSystemWindows();
583 }
584
585 @Override
586 public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
587 if (mWrapped instanceof ActionMode.Callback2) {
588 ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect);
589 } else {
590 super.onGetContentRect(mode, view, outRect);
591 }
592 }
593 }
594
595 /**
596 * Minimal window to satisfy FloatingToolbar.
597 */
598 private Window mFakeWindow = new Window(mContext) {
599 @Override
600 public void takeSurface(SurfaceHolder.Callback2 callback) {
601 }
602
603 @Override
604 public void takeInputQueue(InputQueue.Callback callback) {
605 }
606
607 @Override
608 public boolean isFloating() {
609 return false;
610 }
611
612 @Override
613 public void alwaysReadCloseOnTouchAttr() {
614 }
615
616 @Override
617 public void setContentView(@LayoutRes int layoutResID) {
618 }
619
620 @Override
621 public void setContentView(View view) {
622 }
623
624 @Override
625 public void setContentView(View view, ViewGroup.LayoutParams params) {
626 }
627
628 @Override
629 public void addContentView(View view, ViewGroup.LayoutParams params) {
630 }
631
632 @Override
633 public void clearContentView() {
634 }
635
636 @Override
637 public View getCurrentFocus() {
638 return null;
639 }
640
641 @Override
642 public LayoutInflater getLayoutInflater() {
643 return null;
644 }
645
646 @Override
647 public void setTitle(CharSequence title) {
648 }
649
650 @Override
651 public void setTitleColor(@ColorInt int textColor) {
652 }
653
654 @Override
655 public void openPanel(int featureId, KeyEvent event) {
656 }
657
658 @Override
659 public void closePanel(int featureId) {
660 }
661
662 @Override
663 public void togglePanel(int featureId, KeyEvent event) {
664 }
665
666 @Override
667 public void invalidatePanelMenu(int featureId) {
668 }
669
670 @Override
671 public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) {
672 return false;
673 }
674
675 @Override
676 public boolean performPanelIdentifierAction(int featureId, int id, int flags) {
677 return false;
678 }
679
680 @Override
681 public void closeAllPanels() {
682 }
683
684 @Override
685 public boolean performContextMenuIdentifierAction(int id, int flags) {
686 return false;
687 }
688
689 @Override
690 public void onConfigurationChanged(Configuration newConfig) {
691 }
692
693 @Override
694 public void setBackgroundDrawable(Drawable drawable) {
695 }
696
697 @Override
698 public void setFeatureDrawableResource(int featureId, @DrawableRes int resId) {
699 }
700
701 @Override
702 public void setFeatureDrawableUri(int featureId, Uri uri) {
703 }
704
705 @Override
706 public void setFeatureDrawable(int featureId, Drawable drawable) {
707 }
708
709 @Override
710 public void setFeatureDrawableAlpha(int featureId, int alpha) {
711 }
712
713 @Override
714 public void setFeatureInt(int featureId, int value) {
715 }
716
717 @Override
718 public void takeKeyEvents(boolean get) {
719 }
720
721 @Override
722 public boolean superDispatchKeyEvent(KeyEvent event) {
723 return false;
724 }
725
726 @Override
727 public boolean superDispatchKeyShortcutEvent(KeyEvent event) {
728 return false;
729 }
730
731 @Override
732 public boolean superDispatchTouchEvent(MotionEvent event) {
733 return false;
734 }
735
736 @Override
737 public boolean superDispatchTrackballEvent(MotionEvent event) {
738 return false;
739 }
740
741 @Override
742 public boolean superDispatchGenericMotionEvent(MotionEvent event) {
743 return false;
744 }
745
746 @Override
747 public View getDecorView() {
748 return StatusBarWindowView.this;
749 }
750
751 @Override
752 public View peekDecorView() {
753 return null;
754 }
755
756 @Override
757 public Bundle saveHierarchyState() {
758 return null;
759 }
760
761 @Override
762 public void restoreHierarchyState(Bundle savedInstanceState) {
763 }
764
765 @Override
766 protected void onActive() {
767 }
768
769 @Override
770 public void setChildDrawable(int featureId, Drawable drawable) {
771 }
772
773 @Override
774 public void setChildInt(int featureId, int value) {
775 }
776
777 @Override
778 public boolean isShortcutKey(int keyCode, KeyEvent event) {
779 return false;
780 }
781
782 @Override
783 public void setVolumeControlStream(int streamType) {
784 }
785
786 @Override
787 public int getVolumeControlStream() {
788 return 0;
789 }
790
791 @Override
792 public int getStatusBarColor() {
793 return 0;
794 }
795
796 @Override
797 public void setStatusBarColor(@ColorInt int color) {
798 }
799
800 @Override
801 public int getNavigationBarColor() {
802 return 0;
803 }
804
805 @Override
806 public void setNavigationBarColor(@ColorInt int color) {
807 }
808
809 @Override
810 public void setDecorCaptionShade(int decorCaptionShade) {
811 }
812
813 @Override
814 public void setResizingCaptionDrawable(Drawable drawable) {
815 }
816
817 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -0700818 public void onMultiWindowModeChanged() {
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700819 }
820
821 @Override
Winson Chung4d8681f2017-05-23 16:22:08 -0700822 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
823 }
824
825 @Override
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700826 public void reportActivityRelaunched() {
827 }
Jorim Jaggib6030952018-10-23 18:31:52 +0200828
829 @Override
830 public WindowInsetsController getInsetsController() {
831 return null;
832 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700833 };
834
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400835}
836