Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 19 | import android.annotation.ColorInt; |
| 20 | import android.annotation.DrawableRes; |
| 21 | import android.annotation.LayoutRes; |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 22 | import android.app.StatusBarManager; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 23 | import android.content.Context; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 24 | import android.content.res.Configuration; |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 25 | import android.content.res.TypedArray; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 26 | import android.graphics.Canvas; |
| 27 | import android.graphics.Paint; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 28 | import android.graphics.PorterDuff; |
| 29 | import android.graphics.PorterDuffXfermode; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 30 | import android.graphics.Rect; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 32 | import android.hardware.display.AmbientDisplayConfiguration; |
Jaewan Kim | 5026936 | 2016-12-23 11:22:02 +0900 | [diff] [blame] | 33 | import android.media.AudioManager; |
John Spurlock | 0b99ea9 | 2014-10-01 15:32:22 -0400 | [diff] [blame] | 34 | import android.media.session.MediaSessionLegacyHelper; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 35 | import android.net.Uri; |
| 36 | import android.os.Bundle; |
Adrian Roos | 8008bd1 | 2017-02-22 15:02:09 +0100 | [diff] [blame] | 37 | import android.os.SystemClock; |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 38 | import android.os.UserHandle; |
| 39 | import android.provider.Settings; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 40 | import android.util.AttributeSet; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 41 | import android.view.ActionMode; |
felkachang | 7749c9a | 2018-06-11 15:56:15 +0800 | [diff] [blame] | 42 | import android.view.DisplayCutout; |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 43 | import android.view.GestureDetector; |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 44 | import android.view.InputDevice; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 45 | import android.view.InputQueue; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 46 | import android.view.KeyEvent; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 47 | import android.view.LayoutInflater; |
| 48 | import android.view.Menu; |
| 49 | import android.view.MenuItem; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 50 | import android.view.MotionEvent; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 51 | import android.view.SurfaceHolder; |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 52 | import android.view.View; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 53 | import android.view.ViewGroup; |
| 54 | import android.view.ViewTreeObserver; |
| 55 | import android.view.Window; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 56 | import android.view.WindowInsetsController; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 57 | import android.widget.FrameLayout; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 58 | |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 59 | import com.android.internal.annotations.VisibleForTesting; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 60 | import com.android.internal.view.FloatingActionMode; |
| 61 | import com.android.internal.widget.FloatingToolbar; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 62 | import com.android.systemui.Dependency; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 63 | import com.android.systemui.ExpandHelper; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 64 | import com.android.systemui.R; |
Dave Mankoff | 468d4f6 | 2019-05-08 14:56:29 -0400 | [diff] [blame] | 65 | import com.android.systemui.plugins.FalsingManager; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 66 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 67 | import com.android.systemui.statusbar.DragDownHelper; |
| 68 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 70 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 71 | import com.android.systemui.statusbar.phone.ScrimController.ScrimVisibility; |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 72 | import com.android.systemui.tuner.TunerService; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 73 | |
Selim Cinek | fc5c199 | 2018-01-29 12:40:32 -0800 | [diff] [blame] | 74 | import java.io.FileDescriptor; |
| 75 | import java.io.PrintWriter; |
| 76 | |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 77 | /** |
| 78 | * Combined status bar and notification panel view. Also holding backdrop and scrims. |
| 79 | */ |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 80 | public class StatusBarWindowView extends FrameLayout { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 81 | public static final String TAG = "StatusBarWindowView"; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 82 | public static final boolean DEBUG = StatusBar.DEBUG; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 83 | |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 84 | private final GestureDetector mGestureDetector; |
| 85 | private final StatusBarStateController mStatusBarStateController; |
| 86 | private boolean mDoubleTapEnabled; |
| 87 | private boolean mSingleTapEnabled; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 88 | private DragDownHelper mDragDownHelper; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 89 | private NotificationStackScrollLayout mStackScrollLayout; |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 90 | private NotificationPanelView mNotificationPanel; |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 91 | private View mBrightnessMirror; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 92 | private LockIcon mLockIcon; |
Jorim Jaggi | f0c3807 | 2018-06-19 17:27:08 +0200 | [diff] [blame] | 93 | private PhoneStatusBarView mStatusBarView; |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 94 | |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 95 | private int mRightInset = 0; |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 96 | private int mLeftInset = 0; |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 97 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 98 | private StatusBar mService; |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 99 | private final Paint mTransparentSrcPaint = new Paint(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 100 | private FalsingManager mFalsingManager; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 101 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 102 | // Implements the floating action mode for TextView's Cut/Copy/Past menu. Normally provided by |
| 103 | // DecorView, but since this is a special window we have to roll our own. |
| 104 | private View mFloatingActionModeOriginatingView; |
| 105 | private ActionMode mFloatingActionMode; |
| 106 | private FloatingToolbar mFloatingToolbar; |
| 107 | private ViewTreeObserver.OnPreDrawListener mFloatingToolbarPreDrawListener; |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 108 | private boolean mTouchCancelled; |
| 109 | private boolean mTouchActive; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 110 | private boolean mExpandAnimationRunning; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 111 | private boolean mExpandAnimationPending; |
Jerry Chang | f89d857 | 2019-04-18 11:09:13 +0800 | [diff] [blame] | 112 | private boolean mSuppressingWakeUpGesture; |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 113 | |
| 114 | private final GestureDetector.SimpleOnGestureListener mGestureListener = |
| 115 | new GestureDetector.SimpleOnGestureListener() { |
| 116 | @Override |
| 117 | public boolean onSingleTapConfirmed(MotionEvent e) { |
Jerry Chang | f89d857 | 2019-04-18 11:09:13 +0800 | [diff] [blame] | 118 | if (mSingleTapEnabled && !mSuppressingWakeUpGesture) { |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 119 | mService.wakeUpIfDozing(SystemClock.uptimeMillis(), StatusBarWindowView.this, |
| 120 | "SINGLE_TAP"); |
Lucas Dupin | 3bab3d8 | 2019-03-22 14:38:28 -0700 | [diff] [blame] | 121 | return true; |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 122 | } |
Lucas Dupin | 3bab3d8 | 2019-03-22 14:38:28 -0700 | [diff] [blame] | 123 | return false; |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public boolean onDoubleTap(MotionEvent e) { |
Lucas Dupin | 3bab3d8 | 2019-03-22 14:38:28 -0700 | [diff] [blame] | 128 | if (mDoubleTapEnabled || mSingleTapEnabled) { |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 129 | mService.wakeUpIfDozing(SystemClock.uptimeMillis(), StatusBarWindowView.this, |
| 130 | "DOUBLE_TAP"); |
Lucas Dupin | 3bab3d8 | 2019-03-22 14:38:28 -0700 | [diff] [blame] | 131 | return true; |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 132 | } |
Lucas Dupin | 3bab3d8 | 2019-03-22 14:38:28 -0700 | [diff] [blame] | 133 | return false; |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 134 | } |
| 135 | }; |
| 136 | private final TunerService.Tunable mTunable = (key, newValue) -> { |
| 137 | AmbientDisplayConfiguration configuration = new AmbientDisplayConfiguration(mContext); |
| 138 | switch (key) { |
| 139 | case Settings.Secure.DOZE_DOUBLE_TAP_GESTURE: |
| 140 | mDoubleTapEnabled = configuration.doubleTapGestureEnabled(UserHandle.USER_CURRENT); |
| 141 | break; |
| 142 | case Settings.Secure.DOZE_TAP_SCREEN_GESTURE: |
| 143 | mSingleTapEnabled = configuration.tapGestureEnabled(UserHandle.USER_CURRENT); |
| 144 | } |
| 145 | }; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 146 | |
Jorim Jaggi | 0d4a995 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 147 | /** |
| 148 | * If set to true, the current gesture started below the notch and we need to dispatch touch |
| 149 | * events manually as it's outside of the regular view bounds. |
| 150 | */ |
| 151 | private boolean mExpandingBelowNotch; |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 152 | private KeyguardBypassController mBypassController; |
Jorim Jaggi | 0d4a995 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 153 | |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 154 | public StatusBarWindowView(Context context, AttributeSet attrs) { |
| 155 | super(context, attrs); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 156 | setMotionEventSplittingEnabled(false); |
Selim Cinek | a0fad3b | 2014-09-19 17:20:05 +0200 | [diff] [blame] | 157 | mTransparentSrcPaint.setColor(0); |
| 158 | mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); |
Dave Mankoff | 781ef7e | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 159 | mFalsingManager = Dependency.get(FalsingManager.class); // TODO: inject into a controller. |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 160 | mGestureDetector = new GestureDetector(context, mGestureListener); |
| 161 | mStatusBarStateController = Dependency.get(StatusBarStateController.class); |
| 162 | Dependency.get(TunerService.class).addTunable(mTunable, |
| 163 | Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, |
| 164 | Settings.Secure.DOZE_TAP_SCREEN_GESTURE); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | @Override |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 168 | protected boolean fitSystemWindows(Rect insets) { |
| 169 | if (getFitsSystemWindows()) { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 170 | boolean paddingChanged = insets.top != getPaddingTop() |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 171 | || insets.bottom != getPaddingBottom(); |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 172 | |
felkachang | 7749c9a | 2018-06-11 15:56:15 +0800 | [diff] [blame] | 173 | int rightCutout = 0; |
| 174 | int leftCutout = 0; |
| 175 | DisplayCutout displayCutout = getRootWindowInsets().getDisplayCutout(); |
| 176 | if (displayCutout != null) { |
| 177 | leftCutout = displayCutout.getSafeInsetLeft(); |
| 178 | rightCutout = displayCutout.getSafeInsetRight(); |
| 179 | } |
| 180 | |
| 181 | int targetLeft = Math.max(insets.left, leftCutout); |
| 182 | int targetRight = Math.max(insets.right, rightCutout); |
| 183 | |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 184 | // Super-special right inset handling, because scrims and backdrop need to ignore it. |
felkachang | 7749c9a | 2018-06-11 15:56:15 +0800 | [diff] [blame] | 185 | if (targetRight != mRightInset || targetLeft != mLeftInset) { |
| 186 | mRightInset = targetRight; |
| 187 | mLeftInset = targetLeft; |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 188 | applyMargins(); |
| 189 | } |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 190 | // Drop top inset, and pass through bottom inset. |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 191 | if (paddingChanged) { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 192 | setPadding(0, 0, 0, 0); |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 193 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 194 | insets.left = 0; |
| 195 | insets.top = 0; |
| 196 | insets.right = 0; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 197 | } else { |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 198 | if (mRightInset != 0 || mLeftInset != 0) { |
Adrian Roos | e49e409 | 2015-06-10 18:50:18 -0700 | [diff] [blame] | 199 | mRightInset = 0; |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 200 | mLeftInset = 0; |
Adrian Roos | e49e409 | 2015-06-10 18:50:18 -0700 | [diff] [blame] | 201 | applyMargins(); |
| 202 | } |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 203 | boolean changed = getPaddingLeft() != 0 |
| 204 | || getPaddingRight() != 0 |
| 205 | || getPaddingTop() != 0 |
| 206 | || getPaddingBottom() != 0; |
| 207 | if (changed) { |
| 208 | setPadding(0, 0, 0, 0); |
| 209 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 210 | insets.top = 0; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 211 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 212 | return false; |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 213 | } |
| 214 | |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 215 | private void applyMargins() { |
| 216 | final int N = getChildCount(); |
| 217 | for (int i = 0; i < N; i++) { |
| 218 | View child = getChildAt(i); |
| 219 | if (child.getLayoutParams() instanceof LayoutParams) { |
| 220 | LayoutParams lp = (LayoutParams) child.getLayoutParams(); |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 221 | if (!lp.ignoreRightInset |
| 222 | && (lp.rightMargin != mRightInset || lp.leftMargin != mLeftInset)) { |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 223 | lp.rightMargin = mRightInset; |
Adrian Roos | 85d202b | 2016-06-02 16:27:47 -0700 | [diff] [blame] | 224 | lp.leftMargin = mLeftInset; |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 225 | child.requestLayout(); |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 231 | @VisibleForTesting |
| 232 | protected NotificationStackScrollLayout getStackScrollLayout() { |
| 233 | return mStackScrollLayout; |
| 234 | } |
| 235 | |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 236 | @Override |
| 237 | public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) { |
| 238 | return new LayoutParams(getContext(), attrs); |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | protected FrameLayout.LayoutParams generateDefaultLayoutParams() { |
| 243 | return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); |
| 244 | } |
| 245 | |
John Spurlock | fba9120 | 2014-04-22 12:58:26 -0400 | [diff] [blame] | 246 | @Override |
Selim Cinek | 4e6b2d3 | 2015-06-25 20:15:33 -0400 | [diff] [blame] | 247 | protected void onFinishInflate() { |
| 248 | super.onFinishInflate(); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 249 | mStackScrollLayout = findViewById(R.id.notification_stack_scroller); |
| 250 | mNotificationPanel = findViewById(R.id.notification_panel); |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 251 | mBrightnessMirror = findViewById(R.id.brightness_mirror); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 252 | mLockIcon = findViewById(R.id.lock_icon); |
Selim Cinek | 4e6b2d3 | 2015-06-25 20:15:33 -0400 | [diff] [blame] | 253 | } |
| 254 | |
dooyoung.hwang | e4b841e | 2016-11-16 08:59:23 +0900 | [diff] [blame] | 255 | @Override |
| 256 | public void onViewAdded(View child) { |
| 257 | super.onViewAdded(child); |
| 258 | if (child.getId() == R.id.brightness_mirror) { |
| 259 | mBrightnessMirror = child; |
| 260 | } |
| 261 | } |
| 262 | |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 263 | /** |
| 264 | * Propagate {@link StatusBar} pulsing state. |
| 265 | */ |
| 266 | public void setPulsing(boolean pulsing) { |
Lucas Dupin | 2d33663 | 2019-05-14 12:13:26 -0700 | [diff] [blame] | 267 | if (mLockIcon != null) { |
| 268 | mLockIcon.setPulsing(pulsing); |
| 269 | } |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Lucas Dupin | 71f3804 | 2019-05-10 16:23:04 -0700 | [diff] [blame] | 272 | /** |
| 273 | * Called when the biometric authentication mode changes. |
| 274 | * @param wakeAndUnlock If the type is {@link BiometricUnlockController#isWakeAndUnlock()} |
Selim Cinek | 390f1b9 | 2019-06-28 18:07:28 -0700 | [diff] [blame] | 275 | * @param isUnlock If the type is {@link BiometricUnlockController#isBiometricUnlock()} () |
Lucas Dupin | 71f3804 | 2019-05-10 16:23:04 -0700 | [diff] [blame] | 276 | */ |
Selim Cinek | 390f1b9 | 2019-06-28 18:07:28 -0700 | [diff] [blame] | 277 | public void onBiometricAuthModeChanged(boolean wakeAndUnlock, boolean isUnlock) { |
Lucas Dupin | 2d33663 | 2019-05-14 12:13:26 -0700 | [diff] [blame] | 278 | if (mLockIcon != null) { |
Selim Cinek | 390f1b9 | 2019-06-28 18:07:28 -0700 | [diff] [blame] | 279 | mLockIcon.onBiometricAuthModeChanged(wakeAndUnlock, isUnlock); |
Lucas Dupin | 2d33663 | 2019-05-14 12:13:26 -0700 | [diff] [blame] | 280 | } |
Lucas Dupin | 71f3804 | 2019-05-10 16:23:04 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Jorim Jaggi | f0c3807 | 2018-06-19 17:27:08 +0200 | [diff] [blame] | 283 | public void setStatusBarView(PhoneStatusBarView statusBarView) { |
| 284 | mStatusBarView = statusBarView; |
| 285 | } |
| 286 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 287 | public void setService(StatusBar service) { |
Selim Cinek | 4e6b2d3 | 2015-06-25 20:15:33 -0400 | [diff] [blame] | 288 | mService = service; |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 289 | NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout(); |
| 290 | ExpandHelper.Callback expandHelperCallback = stackScrollLayout.getExpandHelperCallback(); |
| 291 | DragDownHelper.DragDownCallback dragDownCallback = stackScrollLayout.getDragDownCallback(); |
| 292 | setDragDownHelper(new DragDownHelper(getContext(), this, expandHelperCallback, |
Dave Mankoff | 781ef7e | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 293 | dragDownCallback, mFalsingManager)); |
Selim Cinek | f8c4add | 2017-06-08 09:54:58 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | @VisibleForTesting |
| 297 | void setDragDownHelper(DragDownHelper dragDownHelper) { |
| 298 | mDragDownHelper = dragDownHelper; |
Selim Cinek | 4e6b2d3 | 2015-06-25 20:15:33 -0400 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | @Override |
| 302 | protected void onAttachedToWindow () { |
| 303 | super.onAttachedToWindow(); |
Lucas Dupin | 90a38dd | 2018-09-05 09:37:37 -0700 | [diff] [blame] | 304 | setWillNotDraw(!DEBUG); |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public boolean dispatchKeyEvent(KeyEvent event) { |
Adrian Roos | 56cf73a | 2016-07-18 14:23:32 -0700 | [diff] [blame] | 309 | if (mService.interceptMediaKey(event)) { |
| 310 | return true; |
| 311 | } |
| 312 | if (super.dispatchKeyEvent(event)) { |
| 313 | return true; |
| 314 | } |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 315 | boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 316 | switch (event.getKeyCode()) { |
Jorim Jaggi | 8c8bcc1 | 2014-04-16 21:36:51 +0200 | [diff] [blame] | 317 | case KeyEvent.KEYCODE_BACK: |
| 318 | if (!down) { |
| 319 | mService.onBackPressed(); |
| 320 | } |
| 321 | return true; |
| 322 | case KeyEvent.KEYCODE_MENU: |
| 323 | if (!down) { |
| 324 | return mService.onMenuPressed(); |
| 325 | } |
Jorim Jaggi | 3425076 | 2014-07-03 23:51:19 +0200 | [diff] [blame] | 326 | case KeyEvent.KEYCODE_SPACE: |
| 327 | if (!down) { |
| 328 | return mService.onSpacePressed(); |
| 329 | } |
John Spurlock | 0b99ea9 | 2014-10-01 15:32:22 -0400 | [diff] [blame] | 330 | break; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 331 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 332 | case KeyEvent.KEYCODE_VOLUME_UP: |
John Spurlock | 0b99ea9 | 2014-10-01 15:32:22 -0400 | [diff] [blame] | 333 | if (mService.isDozing()) { |
Jaewan Kim | 5026936 | 2016-12-23 11:22:02 +0900 | [diff] [blame] | 334 | MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent( |
| 335 | event, AudioManager.USE_DEFAULT_STREAM_TYPE, true); |
John Spurlock | 0b99ea9 | 2014-10-01 15:32:22 -0400 | [diff] [blame] | 336 | return true; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 337 | } |
John Spurlock | 0b99ea9 | 2014-10-01 15:32:22 -0400 | [diff] [blame] | 338 | break; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 339 | } |
Adrian Roos | 56cf73a | 2016-07-18 14:23:32 -0700 | [diff] [blame] | 340 | return false; |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 341 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 342 | |
Selim Cinek | d95ca7c | 2017-07-26 12:20:38 -0700 | [diff] [blame] | 343 | public void setTouchActive(boolean touchActive) { |
| 344 | mTouchActive = touchActive; |
Selim Cinek | d95ca7c | 2017-07-26 12:20:38 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Jerry Chang | f89d857 | 2019-04-18 11:09:13 +0800 | [diff] [blame] | 347 | void suppressWakeUpGesture(boolean suppress) { |
| 348 | mSuppressingWakeUpGesture = suppress; |
| 349 | } |
| 350 | |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 351 | @Override |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 352 | public boolean dispatchTouchEvent(MotionEvent ev) { |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 353 | boolean isDown = ev.getActionMasked() == MotionEvent.ACTION_DOWN; |
Jorim Jaggi | 0d4a995 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 354 | boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP; |
Adrian Roos | a6c03f8 | 2017-07-26 16:20:30 +0200 | [diff] [blame] | 355 | boolean isCancel = ev.getActionMasked() == MotionEvent.ACTION_CANCEL; |
Jorim Jaggi | 0d4a995 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 356 | |
| 357 | // Reset manual touch dispatch state here but make sure the UP/CANCEL event still gets |
| 358 | // delivered. |
| 359 | boolean expandingBelowNotch = mExpandingBelowNotch; |
| 360 | if (isUp || isCancel) { |
| 361 | mExpandingBelowNotch = false; |
| 362 | } |
| 363 | |
Adrian Roos | a6c03f8 | 2017-07-26 16:20:30 +0200 | [diff] [blame] | 364 | if (!isCancel && mService.shouldIgnoreTouch()) { |
| 365 | return false; |
| 366 | } |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 367 | if (isDown && mNotificationPanel.isFullyCollapsed()) { |
Jorim Jaggi | e05256e | 2016-09-08 14:58:20 -0700 | [diff] [blame] | 368 | mNotificationPanel.startExpandLatencyTracking(); |
| 369 | } |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 370 | if (isDown) { |
Selim Cinek | d95ca7c | 2017-07-26 12:20:38 -0700 | [diff] [blame] | 371 | setTouchActive(true); |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 372 | mTouchCancelled = false; |
| 373 | } else if (ev.getActionMasked() == MotionEvent.ACTION_UP |
| 374 | || ev.getActionMasked() == MotionEvent.ACTION_CANCEL) { |
Selim Cinek | d95ca7c | 2017-07-26 12:20:38 -0700 | [diff] [blame] | 375 | setTouchActive(false); |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 376 | } |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 377 | if (mTouchCancelled || mExpandAnimationRunning || mExpandAnimationPending) { |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 378 | return false; |
| 379 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 380 | mFalsingManager.onTouchEvent(ev, getWidth(), getHeight()); |
Lucas Dupin | 34f6d96 | 2019-02-22 14:47:50 -0800 | [diff] [blame] | 381 | mGestureDetector.onTouchEvent(ev); |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 382 | if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) { |
| 383 | // Disallow new pointers while the brightness mirror is visible. This is so that you |
| 384 | // can't touch anything other than the brightness slider while the mirror is showing |
| 385 | // and the rest of the panel is transparent. |
| 386 | if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) { |
| 387 | return false; |
| 388 | } |
| 389 | } |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 390 | if (isDown) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 391 | getStackScrollLayout().closeControlsIfOutsideTouch(ev); |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 392 | } |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 393 | if (mService.isDozing()) { |
| 394 | mService.mDozeScrimController.extendPulse(); |
| 395 | } |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 396 | |
Jorim Jaggi | 0d4a995 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 397 | // In case we start outside of the view bounds (below the status bar), we need to dispatch |
| 398 | // the touch manually as the view system can't accomodate for touches outside of the |
| 399 | // regular view bounds. |
| 400 | if (isDown && ev.getY() >= mBottom) { |
| 401 | mExpandingBelowNotch = true; |
| 402 | expandingBelowNotch = true; |
| 403 | } |
| 404 | if (expandingBelowNotch) { |
Jorim Jaggi | f0c3807 | 2018-06-19 17:27:08 +0200 | [diff] [blame] | 405 | return mStatusBarView.dispatchTouchEvent(ev); |
Jorim Jaggi | 0d4a995 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Adrian Roos | 9dc3209 | 2014-09-02 23:34:10 +0200 | [diff] [blame] | 408 | return super.dispatchTouchEvent(ev); |
| 409 | } |
| 410 | |
| 411 | @Override |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 412 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 413 | NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout(); |
Lucas Dupin | 1c32743 | 2019-01-03 13:37:53 -0800 | [diff] [blame] | 414 | if (mService.isDozing() && !mService.isPulsing()) { |
Adrian Roos | 8008bd1 | 2017-02-22 15:02:09 +0100 | [diff] [blame] | 415 | // Capture all touch events in always-on. |
Adrian Roos | ebea7a7 | 2016-10-26 12:51:26 -0700 | [diff] [blame] | 416 | return true; |
| 417 | } |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 418 | boolean intercept = false; |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 419 | if (mNotificationPanel.isFullyExpanded() |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 420 | && mDragDownHelper.isDragDownEnabled() |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 421 | && !mService.isBouncerShowing() |
| 422 | && !mService.isDozing()) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 423 | intercept = mDragDownHelper.onInterceptTouchEvent(ev); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 424 | } |
| 425 | if (!intercept) { |
| 426 | super.onInterceptTouchEvent(ev); |
| 427 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 428 | if (intercept) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 429 | MotionEvent cancellation = MotionEvent.obtain(ev); |
| 430 | cancellation.setAction(MotionEvent.ACTION_CANCEL); |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 431 | stackScrollLayout.onInterceptTouchEvent(cancellation); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 432 | mNotificationPanel.onInterceptTouchEvent(cancellation); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 433 | cancellation.recycle(); |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 434 | } |
| 435 | return intercept; |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public boolean onTouchEvent(MotionEvent ev) { |
Adrian Roos | 8008bd1 | 2017-02-22 15:02:09 +0100 | [diff] [blame] | 440 | boolean handled = false; |
| 441 | if (mService.isDozing()) { |
Lucas Dupin | 1c32743 | 2019-01-03 13:37:53 -0800 | [diff] [blame] | 442 | handled = !mService.isPulsing(); |
Adrian Roos | 8008bd1 | 2017-02-22 15:02:09 +0100 | [diff] [blame] | 443 | } |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 444 | if ((mDragDownHelper.isDragDownEnabled() && !handled) || mDragDownHelper.isDraggingDown()) { |
Selim Cinek | 740c111 | 2016-12-22 16:39:54 +0100 | [diff] [blame] | 445 | // we still want to finish our drag down gesture when locking the screen |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 446 | handled = mDragDownHelper.onTouchEvent(ev); |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 447 | } |
| 448 | if (!handled) { |
| 449 | handled = super.onTouchEvent(ev); |
| 450 | } |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 451 | final int action = ev.getAction(); |
John Spurlock | d157ca0 | 2013-11-04 10:28:05 -0500 | [diff] [blame] | 452 | if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) { |
John Spurlock | 257f283 | 2013-09-21 18:41:53 -0400 | [diff] [blame] | 453 | mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false); |
| 454 | } |
Chris Wren | 5de6e94 | 2012-05-16 14:22:21 -0400 | [diff] [blame] | 455 | return handled; |
| 456 | } |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 457 | |
| 458 | @Override |
| 459 | public void onDraw(Canvas canvas) { |
| 460 | super.onDraw(canvas); |
| 461 | if (DEBUG) { |
| 462 | Paint pt = new Paint(); |
| 463 | pt.setColor(0x80FFFF00); |
| 464 | pt.setStrokeWidth(12.0f); |
| 465 | pt.setStyle(Paint.Style.STROKE); |
| 466 | canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); |
| 467 | } |
| 468 | } |
Daniel Sandler | ac47ff7 | 2012-10-23 10:41:44 -0400 | [diff] [blame] | 469 | |
| 470 | public void cancelExpandHelper() { |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 471 | NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout(); |
| 472 | if (stackScrollLayout != null) { |
| 473 | stackScrollLayout.cancelExpandHelper(); |
Daniel Sandler | 1a3bdd5 | 2012-10-23 19:21:20 -0400 | [diff] [blame] | 474 | } |
Daniel Sandler | ac47ff7 | 2012-10-23 10:41:44 -0400 | [diff] [blame] | 475 | } |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 476 | |
Selim Cinek | 48a92a5 | 2017-05-02 20:02:30 -0700 | [diff] [blame] | 477 | public void cancelCurrentTouch() { |
| 478 | if (mTouchActive) { |
| 479 | final long now = SystemClock.uptimeMillis(); |
| 480 | MotionEvent event = MotionEvent.obtain(now, now, |
| 481 | MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); |
| 482 | event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 483 | dispatchTouchEvent(event); |
| 484 | event.recycle(); |
| 485 | mTouchCancelled = true; |
| 486 | } |
| 487 | } |
| 488 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 489 | public void setExpandAnimationRunning(boolean expandAnimationRunning) { |
| 490 | mExpandAnimationRunning = expandAnimationRunning; |
| 491 | } |
| 492 | |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 493 | public void setExpandAnimationPending(boolean pending) { |
| 494 | mExpandAnimationPending = pending; |
| 495 | } |
| 496 | |
Selim Cinek | fc5c199 | 2018-01-29 12:40:32 -0800 | [diff] [blame] | 497 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 498 | pw.print(" mExpandAnimationPending="); pw.println(mExpandAnimationPending); |
| 499 | pw.print(" mExpandAnimationRunning="); pw.println(mExpandAnimationRunning); |
| 500 | pw.print(" mTouchCancelled="); pw.println(mTouchCancelled); |
| 501 | pw.print(" mTouchActive="); pw.println(mTouchActive); |
| 502 | } |
| 503 | |
Lucas Dupin | cdbb1cb | 2019-05-16 19:48:30 -0700 | [diff] [blame] | 504 | /** |
| 505 | * Called whenever the scrims become opaque, transparent or semi-transparent. |
| 506 | */ |
| 507 | public void onScrimVisibilityChanged(@ScrimVisibility int scrimsVisible) { |
| 508 | if (mLockIcon != null) { |
| 509 | mLockIcon.onScrimVisibilityChanged(scrimsVisible); |
| 510 | } |
| 511 | } |
| 512 | |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 513 | /** |
| 514 | * When we're launching an affordance, like double pressing power to open camera. |
| 515 | */ |
| 516 | public void onShowingLaunchAffordanceChanged(boolean showing) { |
| 517 | if (mLockIcon != null) { |
| 518 | mLockIcon.onShowingLaunchAffordanceChanged(showing); |
| 519 | } |
| 520 | } |
| 521 | |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 522 | public void setBypassController(KeyguardBypassController bypassController) { |
| 523 | mBypassController = bypassController; |
| 524 | } |
| 525 | |
Selim Cinek | 60ee7fd | 2019-06-26 13:06:00 -0700 | [diff] [blame] | 526 | public void setBouncerShowingScrimmed(boolean bouncerShowing) { |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 527 | if (mLockIcon != null) { |
Selim Cinek | 60ee7fd | 2019-06-26 13:06:00 -0700 | [diff] [blame] | 528 | mLockIcon.setBouncerShowingScrimmed(bouncerShowing); |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Adrian Roos | 2f2bd9a | 2015-06-04 18:11:14 -0700 | [diff] [blame] | 532 | public class LayoutParams extends FrameLayout.LayoutParams { |
| 533 | |
| 534 | public boolean ignoreRightInset; |
| 535 | |
| 536 | public LayoutParams(int width, int height) { |
| 537 | super(width, height); |
| 538 | } |
| 539 | |
| 540 | public LayoutParams(Context c, AttributeSet attrs) { |
| 541 | super(c, attrs); |
| 542 | |
| 543 | TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout); |
| 544 | ignoreRightInset = a.getBoolean( |
| 545 | R.styleable.StatusBarWindowView_Layout_ignoreRightInset, false); |
| 546 | a.recycle(); |
| 547 | } |
| 548 | } |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 549 | |
| 550 | @Override |
| 551 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback, |
| 552 | int type) { |
| 553 | if (type == ActionMode.TYPE_FLOATING) { |
| 554 | return startActionMode(originalView, callback, type); |
| 555 | } |
| 556 | return super.startActionModeForChild(originalView, callback, type); |
| 557 | } |
| 558 | |
| 559 | private ActionMode createFloatingActionMode( |
| 560 | View originatingView, ActionMode.Callback2 callback) { |
| 561 | if (mFloatingActionMode != null) { |
| 562 | mFloatingActionMode.finish(); |
| 563 | } |
| 564 | cleanupFloatingActionModeViews(); |
Tarandeep Singh | c9c83a9 | 2017-08-29 14:39:22 -0700 | [diff] [blame] | 565 | mFloatingToolbar = new FloatingToolbar(mFakeWindow); |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 566 | final FloatingActionMode mode = |
Abodunrinwa Toki | 17293cc | 2017-05-22 14:16:04 +0100 | [diff] [blame] | 567 | new FloatingActionMode(mContext, callback, originatingView, mFloatingToolbar); |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 568 | mFloatingActionModeOriginatingView = originatingView; |
| 569 | mFloatingToolbarPreDrawListener = |
| 570 | new ViewTreeObserver.OnPreDrawListener() { |
| 571 | @Override |
| 572 | public boolean onPreDraw() { |
| 573 | mode.updateViewLocationInWindow(); |
| 574 | return true; |
| 575 | } |
| 576 | }; |
| 577 | return mode; |
| 578 | } |
| 579 | |
| 580 | private void setHandledFloatingActionMode(ActionMode mode) { |
| 581 | mFloatingActionMode = mode; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 582 | mFloatingActionMode.invalidate(); // Will show the floating toolbar if necessary. |
| 583 | mFloatingActionModeOriginatingView.getViewTreeObserver() |
| 584 | .addOnPreDrawListener(mFloatingToolbarPreDrawListener); |
| 585 | } |
| 586 | |
| 587 | private void cleanupFloatingActionModeViews() { |
| 588 | if (mFloatingToolbar != null) { |
| 589 | mFloatingToolbar.dismiss(); |
| 590 | mFloatingToolbar = null; |
| 591 | } |
| 592 | if (mFloatingActionModeOriginatingView != null) { |
| 593 | if (mFloatingToolbarPreDrawListener != null) { |
| 594 | mFloatingActionModeOriginatingView.getViewTreeObserver() |
| 595 | .removeOnPreDrawListener(mFloatingToolbarPreDrawListener); |
| 596 | mFloatingToolbarPreDrawListener = null; |
| 597 | } |
| 598 | mFloatingActionModeOriginatingView = null; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | private ActionMode startActionMode( |
| 603 | View originatingView, ActionMode.Callback callback, int type) { |
| 604 | ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback); |
| 605 | ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback); |
| 606 | if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) { |
| 607 | setHandledFloatingActionMode(mode); |
| 608 | } else { |
| 609 | mode = null; |
| 610 | } |
| 611 | return mode; |
| 612 | } |
| 613 | |
| 614 | private class ActionModeCallback2Wrapper extends ActionMode.Callback2 { |
| 615 | private final ActionMode.Callback mWrapped; |
| 616 | |
| 617 | public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) { |
| 618 | mWrapped = wrapped; |
| 619 | } |
| 620 | |
| 621 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 622 | return mWrapped.onCreateActionMode(mode, menu); |
| 623 | } |
| 624 | |
| 625 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 626 | requestFitSystemWindows(); |
| 627 | return mWrapped.onPrepareActionMode(mode, menu); |
| 628 | } |
| 629 | |
| 630 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 631 | return mWrapped.onActionItemClicked(mode, item); |
| 632 | } |
| 633 | |
| 634 | public void onDestroyActionMode(ActionMode mode) { |
| 635 | mWrapped.onDestroyActionMode(mode); |
| 636 | if (mode == mFloatingActionMode) { |
| 637 | cleanupFloatingActionModeViews(); |
| 638 | mFloatingActionMode = null; |
| 639 | } |
| 640 | requestFitSystemWindows(); |
| 641 | } |
| 642 | |
| 643 | @Override |
| 644 | public void onGetContentRect(ActionMode mode, View view, Rect outRect) { |
| 645 | if (mWrapped instanceof ActionMode.Callback2) { |
| 646 | ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect); |
| 647 | } else { |
| 648 | super.onGetContentRect(mode, view, outRect); |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Minimal window to satisfy FloatingToolbar. |
| 655 | */ |
| 656 | private Window mFakeWindow = new Window(mContext) { |
| 657 | @Override |
| 658 | public void takeSurface(SurfaceHolder.Callback2 callback) { |
| 659 | } |
| 660 | |
| 661 | @Override |
| 662 | public void takeInputQueue(InputQueue.Callback callback) { |
| 663 | } |
| 664 | |
| 665 | @Override |
| 666 | public boolean isFloating() { |
| 667 | return false; |
| 668 | } |
| 669 | |
| 670 | @Override |
| 671 | public void alwaysReadCloseOnTouchAttr() { |
| 672 | } |
| 673 | |
| 674 | @Override |
| 675 | public void setContentView(@LayoutRes int layoutResID) { |
| 676 | } |
| 677 | |
| 678 | @Override |
| 679 | public void setContentView(View view) { |
| 680 | } |
| 681 | |
| 682 | @Override |
| 683 | public void setContentView(View view, ViewGroup.LayoutParams params) { |
| 684 | } |
| 685 | |
| 686 | @Override |
| 687 | public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 688 | } |
| 689 | |
| 690 | @Override |
| 691 | public void clearContentView() { |
| 692 | } |
| 693 | |
| 694 | @Override |
| 695 | public View getCurrentFocus() { |
| 696 | return null; |
| 697 | } |
| 698 | |
| 699 | @Override |
| 700 | public LayoutInflater getLayoutInflater() { |
| 701 | return null; |
| 702 | } |
| 703 | |
| 704 | @Override |
| 705 | public void setTitle(CharSequence title) { |
| 706 | } |
| 707 | |
| 708 | @Override |
| 709 | public void setTitleColor(@ColorInt int textColor) { |
| 710 | } |
| 711 | |
| 712 | @Override |
| 713 | public void openPanel(int featureId, KeyEvent event) { |
| 714 | } |
| 715 | |
| 716 | @Override |
| 717 | public void closePanel(int featureId) { |
| 718 | } |
| 719 | |
| 720 | @Override |
| 721 | public void togglePanel(int featureId, KeyEvent event) { |
| 722 | } |
| 723 | |
| 724 | @Override |
| 725 | public void invalidatePanelMenu(int featureId) { |
| 726 | } |
| 727 | |
| 728 | @Override |
| 729 | public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) { |
| 730 | return false; |
| 731 | } |
| 732 | |
| 733 | @Override |
| 734 | public boolean performPanelIdentifierAction(int featureId, int id, int flags) { |
| 735 | return false; |
| 736 | } |
| 737 | |
| 738 | @Override |
| 739 | public void closeAllPanels() { |
| 740 | } |
| 741 | |
| 742 | @Override |
| 743 | public boolean performContextMenuIdentifierAction(int id, int flags) { |
| 744 | return false; |
| 745 | } |
| 746 | |
| 747 | @Override |
| 748 | public void onConfigurationChanged(Configuration newConfig) { |
| 749 | } |
| 750 | |
| 751 | @Override |
| 752 | public void setBackgroundDrawable(Drawable drawable) { |
| 753 | } |
| 754 | |
| 755 | @Override |
| 756 | public void setFeatureDrawableResource(int featureId, @DrawableRes int resId) { |
| 757 | } |
| 758 | |
| 759 | @Override |
| 760 | public void setFeatureDrawableUri(int featureId, Uri uri) { |
| 761 | } |
| 762 | |
| 763 | @Override |
| 764 | public void setFeatureDrawable(int featureId, Drawable drawable) { |
| 765 | } |
| 766 | |
| 767 | @Override |
| 768 | public void setFeatureDrawableAlpha(int featureId, int alpha) { |
| 769 | } |
| 770 | |
| 771 | @Override |
| 772 | public void setFeatureInt(int featureId, int value) { |
| 773 | } |
| 774 | |
| 775 | @Override |
| 776 | public void takeKeyEvents(boolean get) { |
| 777 | } |
| 778 | |
| 779 | @Override |
| 780 | public boolean superDispatchKeyEvent(KeyEvent event) { |
| 781 | return false; |
| 782 | } |
| 783 | |
| 784 | @Override |
| 785 | public boolean superDispatchKeyShortcutEvent(KeyEvent event) { |
| 786 | return false; |
| 787 | } |
| 788 | |
| 789 | @Override |
| 790 | public boolean superDispatchTouchEvent(MotionEvent event) { |
| 791 | return false; |
| 792 | } |
| 793 | |
| 794 | @Override |
| 795 | public boolean superDispatchTrackballEvent(MotionEvent event) { |
| 796 | return false; |
| 797 | } |
| 798 | |
| 799 | @Override |
| 800 | public boolean superDispatchGenericMotionEvent(MotionEvent event) { |
| 801 | return false; |
| 802 | } |
| 803 | |
| 804 | @Override |
| 805 | public View getDecorView() { |
| 806 | return StatusBarWindowView.this; |
| 807 | } |
| 808 | |
| 809 | @Override |
| 810 | public View peekDecorView() { |
| 811 | return null; |
| 812 | } |
| 813 | |
| 814 | @Override |
| 815 | public Bundle saveHierarchyState() { |
| 816 | return null; |
| 817 | } |
| 818 | |
| 819 | @Override |
| 820 | public void restoreHierarchyState(Bundle savedInstanceState) { |
| 821 | } |
| 822 | |
| 823 | @Override |
| 824 | protected void onActive() { |
| 825 | } |
| 826 | |
| 827 | @Override |
| 828 | public void setChildDrawable(int featureId, Drawable drawable) { |
| 829 | } |
| 830 | |
| 831 | @Override |
| 832 | public void setChildInt(int featureId, int value) { |
| 833 | } |
| 834 | |
| 835 | @Override |
| 836 | public boolean isShortcutKey(int keyCode, KeyEvent event) { |
| 837 | return false; |
| 838 | } |
| 839 | |
| 840 | @Override |
| 841 | public void setVolumeControlStream(int streamType) { |
| 842 | } |
| 843 | |
| 844 | @Override |
| 845 | public int getVolumeControlStream() { |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | @Override |
| 850 | public int getStatusBarColor() { |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | @Override |
| 855 | public void setStatusBarColor(@ColorInt int color) { |
| 856 | } |
| 857 | |
| 858 | @Override |
| 859 | public int getNavigationBarColor() { |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | @Override |
| 864 | public void setNavigationBarColor(@ColorInt int color) { |
| 865 | } |
| 866 | |
| 867 | @Override |
| 868 | public void setDecorCaptionShade(int decorCaptionShade) { |
| 869 | } |
| 870 | |
| 871 | @Override |
| 872 | public void setResizingCaptionDrawable(Drawable drawable) { |
| 873 | } |
| 874 | |
| 875 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 876 | public void onMultiWindowModeChanged() { |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | @Override |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 880 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { |
| 881 | } |
| 882 | |
| 883 | @Override |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 884 | public void reportActivityRelaunched() { |
| 885 | } |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 886 | |
| 887 | @Override |
| 888 | public WindowInsetsController getInsetsController() { |
| 889 | return null; |
| 890 | } |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 891 | }; |
| 892 | |
Daniel Sandler | c4f2a56 | 2012-05-04 11:55:46 -0400 | [diff] [blame] | 893 | } |
| 894 | |