Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 19 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM; |
| 20 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT; |
| 21 | import static com.android.systemui.Interpolators.ALPHA_IN; |
| 22 | import static com.android.systemui.Interpolators.ALPHA_OUT; |
| 23 | import static com.android.systemui.OverviewProxyService.DEBUG_OVERVIEW_PROXY; |
| 24 | import static com.android.systemui.OverviewProxyService.TAG_OPS; |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 25 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_DEAD_ZONE; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 26 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 27 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 28 | import android.animation.Animator; |
| 29 | import android.animation.AnimatorListenerAdapter; |
| 30 | import android.animation.AnimatorSet; |
| 31 | import android.animation.ObjectAnimator; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 32 | import android.animation.PropertyValuesHolder; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 33 | import android.content.Context; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 34 | import android.content.res.Resources; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 35 | import android.graphics.Canvas; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 36 | import android.graphics.Matrix; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 37 | import android.graphics.Paint; |
| 38 | import android.graphics.RadialGradient; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 39 | import android.graphics.Rect; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 40 | import android.graphics.Shader; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 41 | import android.hardware.input.InputManager; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 42 | import android.os.Handler; |
| 43 | import android.os.RemoteException; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 44 | import android.os.SystemClock; |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 45 | import android.provider.Settings; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 46 | import android.util.FloatProperty; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 47 | import android.util.Log; |
| 48 | import android.util.Slog; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 49 | import android.view.HapticFeedbackConstants; |
| 50 | import android.view.InputDevice; |
| 51 | import android.view.KeyCharacterMap; |
| 52 | import android.view.KeyEvent; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 53 | import android.view.MotionEvent; |
| 54 | import android.view.View; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 55 | import android.view.ViewPropertyAnimator; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 56 | import android.view.WindowManagerGlobal; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 57 | import com.android.systemui.Dependency; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 58 | import com.android.systemui.Interpolators; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 59 | import com.android.systemui.OverviewProxyService; |
| 60 | import com.android.systemui.R; |
Winson Chung | 0d3815d | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 61 | import com.android.systemui.SysUiServiceProvider; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 62 | import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper; |
| 63 | import com.android.systemui.shared.recents.IOverviewProxy; |
| 64 | import com.android.systemui.shared.recents.utilities.Utilities; |
Matthew Ng | f29ad75 | 2018-04-26 11:24:05 -0700 | [diff] [blame] | 65 | import com.android.systemui.shared.system.NavigationBarCompat; |
Winson Chung | 0d3815d | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 66 | import java.io.PrintWriter; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 67 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 68 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 69 | * Class to detect gestures on the navigation bar and implement quick scrub. |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 70 | */ |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 71 | public class QuickStepController implements GestureHelper { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 72 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 73 | private static final String TAG = "QuickStepController"; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 74 | private static final int ANIM_IN_DURATION_MS = 150; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 75 | private static final int ANIM_OUT_DURATION_MS = 134; |
| 76 | private static final float TRACK_SCALE = 0.95f; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 77 | private static final float GRADIENT_WIDTH = .75f; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 78 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 79 | /** Experiment to swipe home button left to execute a back key press */ |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 80 | private static final String PULL_HOME_GO_BACK_PROP = "quickstepcontroller_homegoesback"; |
| 81 | private static final String HIDE_BACK_BUTTON_PROP = "quickstepcontroller_hideback"; |
Matthew Ng | c414e28 | 2018-09-05 15:50:10 -0700 | [diff] [blame] | 82 | private static final String BACK_AFTER_END_PROP |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 83 | = "quickstepcontroller_homegoesbackwhenend"; |
| 84 | private static final String NAVBAR_EXPERIMENTS_DISABLED = "navbarexperiments_disabled"; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 85 | private static final long BACK_BUTTON_FADE_OUT_ALPHA = 60; |
| 86 | private static final long BACK_BUTTON_FADE_IN_ALPHA = 150; |
| 87 | private static final long BACK_GESTURE_POLL_TIMEOUT = 1000; |
| 88 | |
| 89 | /** When the home-swipe-back gesture is disallowed, make it harder to pull */ |
| 90 | private static final float DISALLOW_GESTURE_DAMPING_FACTOR = 0.16f; |
| 91 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 92 | private NavigationBarView mNavigationBarView; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 93 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 94 | private boolean mQuickScrubActive; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 95 | private boolean mAllowGestureDetection; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 96 | private boolean mBackGestureActive; |
| 97 | private boolean mCanPerformBack; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 98 | private boolean mQuickStepStarted; |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 99 | private boolean mNotificationsVisibleOnDown; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 100 | private int mTouchDownX; |
| 101 | private int mTouchDownY; |
| 102 | private boolean mDragPositive; |
| 103 | private boolean mIsVertical; |
| 104 | private boolean mIsRTL; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 105 | private float mTrackAlpha; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 106 | private float mTrackScale = TRACK_SCALE; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 107 | private float mDarkIntensity; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 108 | private RadialGradient mHighlight; |
| 109 | private float mHighlightCenter; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 110 | private AnimatorSet mTrackAnimator; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 111 | private ViewPropertyAnimator mHomeAnimator; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 112 | private ButtonDispatcher mHitTarget; |
| 113 | private View mCurrentNavigationBarView; |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 114 | private boolean mIsInScreenPinning; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 115 | |
| 116 | private final Handler mHandler = new Handler(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 117 | private final Rect mTrackRect = new Rect(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 118 | private final OverviewProxyService mOverviewEventSender; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 119 | private final int mTrackThickness; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 120 | private final int mTrackEndPadding; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 121 | private final int mHomeBackGestureDragLimit; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 122 | private final Context mContext; |
Winson Chung | 0d3815d | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 123 | private final StatusBar mStatusBar; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 124 | private final Matrix mTransformGlobalMatrix = new Matrix(); |
| 125 | private final Matrix mTransformLocalMatrix = new Matrix(); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 126 | private final Paint mTrackPaint = new Paint(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 127 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 128 | private final FloatProperty<QuickStepController> mTrackAlphaProperty = |
| 129 | new FloatProperty<QuickStepController>("TrackAlpha") { |
| 130 | @Override |
| 131 | public void setValue(QuickStepController controller, float alpha) { |
| 132 | mTrackAlpha = alpha; |
| 133 | mNavigationBarView.invalidate(); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public Float get(QuickStepController controller) { |
| 138 | return mTrackAlpha; |
| 139 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 140 | }; |
| 141 | |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 142 | private final FloatProperty<QuickStepController> mTrackScaleProperty = |
| 143 | new FloatProperty<QuickStepController>("TrackScale") { |
| 144 | @Override |
| 145 | public void setValue(QuickStepController controller, float scale) { |
| 146 | mTrackScale = scale; |
| 147 | mNavigationBarView.invalidate(); |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public Float get(QuickStepController controller) { |
| 152 | return mTrackScale; |
| 153 | } |
| 154 | }; |
| 155 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 156 | private final FloatProperty<QuickStepController> mNavBarAlphaProperty = |
| 157 | new FloatProperty<QuickStepController>("NavBarAlpha") { |
| 158 | @Override |
| 159 | public void setValue(QuickStepController controller, float alpha) { |
| 160 | if (mCurrentNavigationBarView != null) { |
| 161 | mCurrentNavigationBarView.setAlpha(alpha); |
| 162 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 163 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 164 | |
| 165 | @Override |
| 166 | public Float get(QuickStepController controller) { |
| 167 | if (mCurrentNavigationBarView != null) { |
| 168 | return mCurrentNavigationBarView.getAlpha(); |
| 169 | } |
| 170 | return 1f; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 171 | } |
| 172 | }; |
| 173 | |
| 174 | private AnimatorListenerAdapter mQuickScrubEndListener = new AnimatorListenerAdapter() { |
| 175 | @Override |
| 176 | public void onAnimationEnd(Animator animation) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 177 | resetQuickScrub(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 178 | } |
| 179 | }; |
| 180 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 181 | private final Runnable mExecuteBackRunnable = new Runnable() { |
| 182 | @Override |
| 183 | public void run() { |
| 184 | if (canPerformHomeBackGesture()) { |
| 185 | performBack(); |
| 186 | mHandler.postDelayed(this, BACK_GESTURE_POLL_TIMEOUT); |
| 187 | } |
| 188 | } |
| 189 | }; |
| 190 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 191 | public QuickStepController(Context context) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 192 | final Resources res = context.getResources(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 193 | mContext = context; |
Winson Chung | 0d3815d | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 194 | mStatusBar = SysUiServiceProvider.getComponent(context, StatusBar.class); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 195 | mOverviewEventSender = Dependency.get(OverviewProxyService.class); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 196 | mTrackThickness = res.getDimensionPixelSize(R.dimen.nav_quick_scrub_track_thickness); |
| 197 | mTrackEndPadding = res.getDimensionPixelSize(R.dimen.nav_quick_scrub_track_edge_padding); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 198 | mHomeBackGestureDragLimit = |
| 199 | res.getDimensionPixelSize(R.dimen.nav_home_back_gesture_drag_limit); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 200 | mTrackPaint.setAntiAlias(true); |
| 201 | mTrackPaint.setDither(true); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | public void setComponents(NavigationBarView navigationBarView) { |
| 205 | mNavigationBarView = navigationBarView; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 206 | |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 207 | mNavigationBarView.getBackButton().setVisibility(shouldhideBackButton(mContext) |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 208 | ? View.GONE |
| 209 | : View.VISIBLE); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 212 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 213 | * @return true if we want to intercept touch events for quick scrub and prevent proxying the |
| 214 | * event to the overview service. |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 215 | */ |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 216 | @Override |
| 217 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Winson Chung | 0d3815d | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 218 | if (mStatusBar.isKeyguardShowing()) { |
| 219 | // Disallow any handling when the keyguard is showing |
| 220 | return false; |
| 221 | } |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 222 | return handleTouchEvent(event); |
| 223 | } |
| 224 | |
| 225 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 226 | * @return true if we want to handle touch events for quick scrub or if down event (that will |
| 227 | * get consumed and ignored). No events will be proxied to the overview service. |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 228 | */ |
| 229 | @Override |
| 230 | public boolean onTouchEvent(MotionEvent event) { |
Winson Chung | 0d3815d | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 231 | if (mStatusBar.isKeyguardShowing()) { |
| 232 | // Disallow any handling when the keyguard is showing |
| 233 | return false; |
| 234 | } |
| 235 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 236 | // The same down event was just sent on intercept and therefore can be ignored here |
| 237 | final boolean ignoreProxyDownEvent = event.getAction() == MotionEvent.ACTION_DOWN |
| 238 | && mOverviewEventSender.getProxy() != null; |
| 239 | return ignoreProxyDownEvent || handleTouchEvent(event); |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | private boolean handleTouchEvent(MotionEvent event) { |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 243 | final boolean deadZoneConsumed = |
| 244 | mNavigationBarView.getDownHitTarget() == HIT_TARGET_DEAD_ZONE; |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 245 | if (mOverviewEventSender.getProxy() == null || (!mNavigationBarView.isQuickScrubEnabled() |
| 246 | && !mNavigationBarView.isQuickStepSwipeUpEnabled())) { |
Matthew Ng | 2cbe8cd | 2018-08-20 11:27:40 -0700 | [diff] [blame] | 247 | return deadZoneConsumed; |
Matthew Ng | 22cf514 | 2018-03-14 12:26:14 -0700 | [diff] [blame] | 248 | } |
| 249 | mNavigationBarView.requestUnbufferedDispatch(event); |
| 250 | |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 251 | int action = event.getActionMasked(); |
| 252 | switch (action) { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 253 | case MotionEvent.ACTION_DOWN: { |
| 254 | int x = (int) event.getX(); |
| 255 | int y = (int) event.getY(); |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 256 | mIsInScreenPinning = mNavigationBarView.inScreenPinning(); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 257 | |
Winson Chung | 0be8f08 | 2018-02-15 15:52:49 -0800 | [diff] [blame] | 258 | // End any existing quickscrub animations before starting the new transition |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 259 | if (mTrackAnimator != null) { |
| 260 | mTrackAnimator.end(); |
| 261 | mTrackAnimator = null; |
Winson Chung | 0be8f08 | 2018-02-15 15:52:49 -0800 | [diff] [blame] | 262 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 263 | |
| 264 | mCurrentNavigationBarView = mNavigationBarView.getCurrentView(); |
| 265 | mHitTarget = mNavigationBarView.getButtonAtPosition(x, y); |
| 266 | if (mHitTarget != null) { |
| 267 | // Pre-emptively delay the touch feedback for the button that we just touched |
| 268 | mHitTarget.setDelayTouchFeedback(true); |
| 269 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 270 | mTouchDownX = x; |
| 271 | mTouchDownY = y; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 272 | mTransformGlobalMatrix.set(Matrix.IDENTITY_MATRIX); |
| 273 | mTransformLocalMatrix.set(Matrix.IDENTITY_MATRIX); |
| 274 | mNavigationBarView.transformMatrixToGlobal(mTransformGlobalMatrix); |
| 275 | mNavigationBarView.transformMatrixToLocal(mTransformLocalMatrix); |
| 276 | mQuickStepStarted = false; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 277 | mBackGestureActive = false; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 278 | mAllowGestureDetection = true; |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 279 | mNotificationsVisibleOnDown = !mNavigationBarView.isNotificationsFullyCollapsed(); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 280 | mCanPerformBack = canPerformHomeBackGesture(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 281 | break; |
| 282 | } |
| 283 | case MotionEvent.ACTION_MOVE: { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 284 | if (mQuickStepStarted || !mAllowGestureDetection){ |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 285 | break; |
| 286 | } |
| 287 | int x = (int) event.getX(); |
| 288 | int y = (int) event.getY(); |
| 289 | int xDiff = Math.abs(x - mTouchDownX); |
| 290 | int yDiff = Math.abs(y - mTouchDownY); |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 291 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 292 | boolean exceededScrubTouchSlop, exceededSwipeUpTouchSlop; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 293 | int pos, touchDown, offset, trackSize; |
Matthew Ng | e0903c9 | 2018-01-17 15:32:41 -0800 | [diff] [blame] | 294 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 295 | if (mIsVertical) { |
Matthew Ng | f29ad75 | 2018-04-26 11:24:05 -0700 | [diff] [blame] | 296 | exceededScrubTouchSlop = |
| 297 | yDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && yDiff > xDiff; |
| 298 | exceededSwipeUpTouchSlop = |
| 299 | xDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && xDiff > yDiff; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 300 | pos = y; |
| 301 | touchDown = mTouchDownY; |
| 302 | offset = pos - mTrackRect.top; |
| 303 | trackSize = mTrackRect.height(); |
| 304 | } else { |
Matthew Ng | f29ad75 | 2018-04-26 11:24:05 -0700 | [diff] [blame] | 305 | exceededScrubTouchSlop = |
| 306 | xDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && xDiff > yDiff; |
| 307 | exceededSwipeUpTouchSlop = |
| 308 | yDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && yDiff > xDiff; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 309 | pos = x; |
| 310 | touchDown = mTouchDownX; |
| 311 | offset = pos - mTrackRect.left; |
| 312 | trackSize = mTrackRect.width(); |
| 313 | } |
| 314 | // Decide to start quickstep if dragging away from the navigation bar, otherwise in |
| 315 | // the parallel direction, decide to start quickscrub. Only one may run. |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 316 | if (!mBackGestureActive && !mQuickScrubActive && exceededSwipeUpTouchSlop) { |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 317 | if (mNavigationBarView.isQuickStepSwipeUpEnabled() |
| 318 | && !mNotificationsVisibleOnDown) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 319 | startQuickStep(event); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 320 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 321 | break; |
| 322 | } |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 323 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 324 | // Do not handle quick scrub if disabled |
| 325 | if (!mNavigationBarView.isQuickScrubEnabled()) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 326 | break; |
| 327 | } |
| 328 | |
| 329 | if (!mDragPositive) { |
| 330 | offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width(); |
| 331 | } |
| 332 | |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 333 | final boolean allowDrag = !mDragPositive |
| 334 | ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 335 | float scrubFraction = Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 336 | if (!mQuickScrubActive && !mBackGestureActive && exceededScrubTouchSlop) { |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 337 | // Passing the drag slop then touch slop will start quick step |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 338 | if (allowDrag) { |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 339 | startQuickScrub(); |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 340 | } else if (swipeHomeGoBackGestureEnabled(mContext) |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 341 | && mNavigationBarView.getDownHitTarget() == HIT_TARGET_HOME |
| 342 | && mDragPositive ? pos < touchDown : pos > touchDown) { |
| 343 | startBackGesture(); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 344 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 345 | } |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 346 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 347 | if (mQuickScrubActive && (mDragPositive && offset >= 0 |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 348 | || !mDragPositive && offset <= 0)) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 349 | try { |
| 350 | mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction); |
| 351 | if (DEBUG_OVERVIEW_PROXY) { |
| 352 | Log.d(TAG_OPS, "Quick Scrub Progress:" + scrubFraction); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 353 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 354 | } catch (RemoteException e) { |
| 355 | Log.e(TAG, "Failed to send progress of quick scrub.", e); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 356 | } |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 357 | mHighlightCenter = x; |
| 358 | mNavigationBarView.invalidate(); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 359 | } else if (mBackGestureActive) { |
| 360 | int diff = pos - touchDown; |
| 361 | // If dragging the incorrect direction after starting back gesture or unable |
| 362 | // to execute back functionality, then move home but dampen its distance |
| 363 | if (!mCanPerformBack || (mDragPositive ? diff > 0 : diff < 0)) { |
| 364 | diff *= DISALLOW_GESTURE_DAMPING_FACTOR; |
| 365 | } if (Math.abs(diff) > mHomeBackGestureDragLimit) { |
| 366 | // Once the user drags the home button past a certain limit, the distance |
| 367 | // will lessen as the home button dampens showing that it was pulled too far |
| 368 | float distanceAfterDragLimit = (Math.abs(diff) - mHomeBackGestureDragLimit) |
Matthew Ng | c414e28 | 2018-09-05 15:50:10 -0700 | [diff] [blame] | 369 | * DISALLOW_GESTURE_DAMPING_FACTOR; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 370 | diff = (int)(distanceAfterDragLimit + mHomeBackGestureDragLimit); |
| 371 | if (mDragPositive) { |
| 372 | diff *= -1; |
| 373 | } |
| 374 | } |
| 375 | moveHomeButton(diff); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 376 | } |
| 377 | break; |
| 378 | } |
| 379 | case MotionEvent.ACTION_CANCEL: |
| 380 | case MotionEvent.ACTION_UP: |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 381 | endQuickScrub(true /* animate */); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 382 | endBackGesture(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 383 | break; |
| 384 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 385 | |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 386 | if (shouldProxyEvents(action)) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 387 | proxyMotionEvents(event); |
| 388 | } |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 389 | return mBackGestureActive || mQuickScrubActive || mQuickStepStarted || deadZoneConsumed; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 392 | private boolean shouldProxyEvents(int action) { |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 393 | if (!mBackGestureActive && !mQuickScrubActive && !mIsInScreenPinning) { |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 394 | // Allow down, cancel and up events, move and other events are passed if notifications |
| 395 | // are not showing and disabled gestures (such as long press) are not executed |
| 396 | switch (action) { |
| 397 | case MotionEvent.ACTION_DOWN: |
| 398 | case MotionEvent.ACTION_CANCEL: |
| 399 | case MotionEvent.ACTION_UP: |
| 400 | return true; |
| 401 | default: |
| 402 | return !mNotificationsVisibleOnDown && mAllowGestureDetection; |
| 403 | } |
| 404 | } |
| 405 | return false; |
| 406 | } |
| 407 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 408 | @Override |
| 409 | public void onDraw(Canvas canvas) { |
Matthew Ng | f781bbd | 2018-03-21 14:58:55 -0700 | [diff] [blame] | 410 | if (!mNavigationBarView.isQuickScrubEnabled()) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 411 | return; |
| 412 | } |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 413 | mTrackPaint.setAlpha(Math.round(255f * mTrackAlpha)); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 414 | |
| 415 | // Scale the track, but apply the inverse scale from the nav bar |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 416 | final float radius = mTrackRect.height() / 2; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 417 | canvas.save(); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 418 | float translate = Utilities.clamp(mHighlightCenter, mTrackRect.left, mTrackRect.right); |
| 419 | canvas.translate(translate, 0); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 420 | canvas.scale(mTrackScale / mNavigationBarView.getScaleX(), |
| 421 | 1f / mNavigationBarView.getScaleY(), |
| 422 | mTrackRect.centerX(), mTrackRect.centerY()); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 423 | canvas.drawRoundRect(mTrackRect.left - translate, mTrackRect.top, |
| 424 | mTrackRect.right - translate, mTrackRect.bottom, radius, radius, mTrackPaint); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 425 | canvas.restore(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 430 | final int paddingLeft = mNavigationBarView.getPaddingLeft(); |
| 431 | final int paddingTop = mNavigationBarView.getPaddingTop(); |
| 432 | final int paddingRight = mNavigationBarView.getPaddingRight(); |
| 433 | final int paddingBottom = mNavigationBarView.getPaddingBottom(); |
| 434 | final int width = (right - left) - paddingRight - paddingLeft; |
| 435 | final int height = (bottom - top) - paddingBottom - paddingTop; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 436 | final int x1, x2, y1, y2; |
| 437 | if (mIsVertical) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 438 | x1 = (width - mTrackThickness) / 2 + paddingLeft; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 439 | x2 = x1 + mTrackThickness; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 440 | y1 = paddingTop + mTrackEndPadding; |
| 441 | y2 = y1 + height - 2 * mTrackEndPadding; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 442 | } else { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 443 | y1 = (height - mTrackThickness) / 2 + paddingTop; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 444 | y2 = y1 + mTrackThickness; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 445 | x1 = mNavigationBarView.getPaddingStart() + mTrackEndPadding; |
| 446 | x2 = x1 + width - 2 * mTrackEndPadding; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 447 | } |
| 448 | mTrackRect.set(x1, y1, x2, y2); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 449 | updateHighlight(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | @Override |
| 453 | public void onDarkIntensityChange(float intensity) { |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 454 | final float oldIntensity = mDarkIntensity; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 455 | mDarkIntensity = intensity; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 456 | |
| 457 | // When in quick scrub, invalidate gradient if changing intensity from black to white and |
| 458 | // vice-versa |
| 459 | if (mNavigationBarView.isQuickScrubEnabled() |
| 460 | && Math.round(intensity) != Math.round(oldIntensity)) { |
| 461 | updateHighlight(); |
| 462 | } |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 463 | mNavigationBarView.invalidate(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | @Override |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 467 | public void setBarState(boolean isVertical, boolean isRTL) { |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 468 | final boolean changed = (mIsVertical != isVertical) || (mIsRTL != isRTL); |
| 469 | if (changed) { |
| 470 | // End quickscrub if the state changes mid-transition |
| 471 | endQuickScrub(false /* animate */); |
| 472 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 473 | mIsVertical = isVertical; |
| 474 | mIsRTL = isRTL; |
| 475 | try { |
| 476 | int navbarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition(); |
| 477 | mDragPositive = navbarPos == NAV_BAR_LEFT || navbarPos == NAV_BAR_BOTTOM; |
| 478 | if (isRTL) { |
| 479 | mDragPositive = !mDragPositive; |
| 480 | } |
| 481 | } catch (RemoteException e) { |
| 482 | Slog.e(TAG, "Failed to get nav bar position.", e); |
| 483 | } |
| 484 | } |
| 485 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 486 | @Override |
| 487 | public void onNavigationButtonLongPress(View v) { |
| 488 | mAllowGestureDetection = false; |
| 489 | mHandler.removeCallbacksAndMessages(null); |
| 490 | } |
| 491 | |
Winson Chung | 0d3815d | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 492 | @Override |
| 493 | public void dump(PrintWriter pw) { |
| 494 | pw.println("QuickStepController {"); |
| 495 | pw.print(" "); pw.println("mQuickScrubActive=" + mQuickScrubActive); |
| 496 | pw.print(" "); pw.println("mQuickStepStarted=" + mQuickStepStarted); |
| 497 | pw.print(" "); pw.println("mAllowGestureDetection=" + mAllowGestureDetection); |
| 498 | pw.print(" "); pw.println("mBackGestureActive=" + mBackGestureActive); |
| 499 | pw.print(" "); pw.println("mCanPerformBack=" + mCanPerformBack); |
| 500 | pw.print(" "); pw.println("mNotificationsVisibleOnDown=" + mNotificationsVisibleOnDown); |
| 501 | pw.print(" "); pw.println("mIsVertical=" + mIsVertical); |
| 502 | pw.print(" "); pw.println("mIsRTL=" + mIsRTL); |
| 503 | pw.print(" "); pw.println("mIsInScreenPinning=" + mIsInScreenPinning); |
| 504 | pw.println("}"); |
| 505 | } |
| 506 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 507 | private void startQuickStep(MotionEvent event) { |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 508 | if (mIsInScreenPinning) { |
| 509 | mNavigationBarView.showPinningEscapeToast(); |
| 510 | mAllowGestureDetection = false; |
| 511 | return; |
| 512 | } |
| 513 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 514 | mQuickStepStarted = true; |
| 515 | event.transform(mTransformGlobalMatrix); |
| 516 | try { |
| 517 | mOverviewEventSender.getProxy().onQuickStep(event); |
| 518 | if (DEBUG_OVERVIEW_PROXY) { |
| 519 | Log.d(TAG_OPS, "Quick Step Start"); |
| 520 | } |
| 521 | } catch (RemoteException e) { |
| 522 | Log.e(TAG, "Failed to send quick step started.", e); |
| 523 | } finally { |
| 524 | event.transform(mTransformLocalMatrix); |
| 525 | } |
| 526 | mOverviewEventSender.notifyQuickStepStarted(); |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 527 | mHandler.removeCallbacksAndMessages(null); |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 528 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 529 | if (mHitTarget != null) { |
| 530 | mHitTarget.abortCurrentGesture(); |
| 531 | } |
| 532 | |
| 533 | if (mQuickScrubActive) { |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 534 | animateEnd(); |
| 535 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 538 | private void startQuickScrub() { |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 539 | if (mIsInScreenPinning) { |
| 540 | mNavigationBarView.showPinningEscapeToast(); |
| 541 | mAllowGestureDetection = false; |
| 542 | return; |
| 543 | } |
| 544 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 545 | if (!mQuickScrubActive) { |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 546 | updateHighlight(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 547 | mQuickScrubActive = true; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 548 | ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this, |
| 549 | PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 1f), |
| 550 | PropertyValuesHolder.ofFloat(mTrackScaleProperty, 1f)); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 551 | trackAnimator.setInterpolator(ALPHA_IN); |
| 552 | trackAnimator.setDuration(ANIM_IN_DURATION_MS); |
| 553 | ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 0f); |
| 554 | navBarAnimator.setInterpolator(ALPHA_OUT); |
| 555 | navBarAnimator.setDuration(ANIM_OUT_DURATION_MS); |
| 556 | mTrackAnimator = new AnimatorSet(); |
| 557 | mTrackAnimator.playTogether(trackAnimator, navBarAnimator); |
| 558 | mTrackAnimator.start(); |
Matthew Ng | 6607c3d | 2018-04-26 15:23:27 -0700 | [diff] [blame] | 559 | |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 560 | // Disable slippery for quick scrub to not cancel outside the nav bar |
| 561 | mNavigationBarView.updateSlippery(); |
| 562 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 563 | try { |
| 564 | mOverviewEventSender.getProxy().onQuickScrubStart(); |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 565 | if (DEBUG_OVERVIEW_PROXY) { |
| 566 | Log.d(TAG_OPS, "Quick Scrub Start"); |
| 567 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 568 | } catch (RemoteException e) { |
| 569 | Log.e(TAG, "Failed to send start of quick scrub.", e); |
| 570 | } |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 571 | mOverviewEventSender.notifyQuickScrubStarted(); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 572 | |
| 573 | if (mHitTarget != null) { |
| 574 | mHitTarget.abortCurrentGesture(); |
| 575 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 579 | private void endQuickScrub(boolean animate) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 580 | if (mQuickScrubActive) { |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 581 | animateEnd(); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 582 | try { |
| 583 | mOverviewEventSender.getProxy().onQuickScrubEnd(); |
| 584 | if (DEBUG_OVERVIEW_PROXY) { |
| 585 | Log.d(TAG_OPS, "Quick Scrub End"); |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 586 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 587 | } catch (RemoteException e) { |
| 588 | Log.e(TAG, "Failed to send end of quick scrub.", e); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 589 | } |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 590 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 591 | if (!animate) { |
| 592 | if (mTrackAnimator != null) { |
| 593 | mTrackAnimator.end(); |
| 594 | mTrackAnimator = null; |
| 595 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 596 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 599 | private void startBackGesture() { |
| 600 | if (!mBackGestureActive) { |
| 601 | mBackGestureActive = true; |
| 602 | mNavigationBarView.getHomeButton().abortCurrentGesture(); |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 603 | final boolean runBackMidGesture = !shouldExecuteBackOnUp(mContext); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 604 | if (mCanPerformBack) { |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 605 | if (!shouldhideBackButton(mContext)) { |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 606 | mNavigationBarView.getBackButton().setAlpha(0 /* alpha */, true /* animate */, |
| 607 | BACK_BUTTON_FADE_OUT_ALPHA); |
| 608 | } |
Matthew Ng | c414e28 | 2018-09-05 15:50:10 -0700 | [diff] [blame] | 609 | if (runBackMidGesture) { |
| 610 | performBack(); |
| 611 | } |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 612 | } |
| 613 | mHandler.removeCallbacks(mExecuteBackRunnable); |
Matthew Ng | c414e28 | 2018-09-05 15:50:10 -0700 | [diff] [blame] | 614 | if (runBackMidGesture) { |
| 615 | mHandler.postDelayed(mExecuteBackRunnable, BACK_GESTURE_POLL_TIMEOUT); |
| 616 | } |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
| 620 | private void endBackGesture() { |
| 621 | if (mBackGestureActive) { |
| 622 | mHandler.removeCallbacks(mExecuteBackRunnable); |
| 623 | mHomeAnimator = mNavigationBarView.getHomeButton().getCurrentView() |
| 624 | .animate() |
| 625 | .setDuration(BACK_BUTTON_FADE_IN_ALPHA) |
| 626 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 627 | if (mIsVertical) { |
| 628 | mHomeAnimator.translationY(0); |
| 629 | } else { |
| 630 | mHomeAnimator.translationX(0); |
| 631 | } |
| 632 | mHomeAnimator.start(); |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 633 | if (!shouldhideBackButton(mContext)) { |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 634 | mNavigationBarView.getBackButton().setAlpha( |
| 635 | mOverviewEventSender.getBackButtonAlpha(), true /* animate */); |
| 636 | } |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 637 | if (shouldExecuteBackOnUp(mContext)) { |
Matthew Ng | c414e28 | 2018-09-05 15:50:10 -0700 | [diff] [blame] | 638 | performBack(); |
| 639 | } |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 643 | private void animateEnd() { |
| 644 | if (mTrackAnimator != null) { |
| 645 | mTrackAnimator.cancel(); |
| 646 | } |
| 647 | |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 648 | ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this, |
| 649 | PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 0f), |
| 650 | PropertyValuesHolder.ofFloat(mTrackScaleProperty, TRACK_SCALE)); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 651 | trackAnimator.setInterpolator(ALPHA_OUT); |
| 652 | trackAnimator.setDuration(ANIM_OUT_DURATION_MS); |
| 653 | ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 1f); |
| 654 | navBarAnimator.setInterpolator(ALPHA_IN); |
| 655 | navBarAnimator.setDuration(ANIM_IN_DURATION_MS); |
| 656 | mTrackAnimator = new AnimatorSet(); |
| 657 | mTrackAnimator.playTogether(trackAnimator, navBarAnimator); |
| 658 | mTrackAnimator.addListener(mQuickScrubEndListener); |
| 659 | mTrackAnimator.start(); |
| 660 | } |
| 661 | |
| 662 | private void resetQuickScrub() { |
| 663 | mQuickScrubActive = false; |
| 664 | mAllowGestureDetection = false; |
Matthew Ng | 819daaa | 2018-07-23 15:12:57 -0700 | [diff] [blame] | 665 | if (mCurrentNavigationBarView != null) { |
| 666 | mCurrentNavigationBarView.setAlpha(1f); |
| 667 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 668 | mCurrentNavigationBarView = null; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 669 | updateHighlight(); |
| 670 | } |
| 671 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 672 | private void moveHomeButton(float pos) { |
| 673 | if (mHomeAnimator != null) { |
| 674 | mHomeAnimator.cancel(); |
| 675 | mHomeAnimator = null; |
| 676 | } |
| 677 | final View homeButton = mNavigationBarView.getHomeButton().getCurrentView(); |
| 678 | if (mIsVertical) { |
| 679 | homeButton.setTranslationY(pos); |
| 680 | } else { |
| 681 | homeButton.setTranslationX(pos); |
| 682 | } |
| 683 | } |
| 684 | |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 685 | private void updateHighlight() { |
Matthew Ng | 908111d | 2018-06-26 15:22:56 -0700 | [diff] [blame] | 686 | if (mTrackRect.isEmpty()) { |
| 687 | return; |
| 688 | } |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 689 | int colorBase, colorGrad; |
| 690 | if (mDarkIntensity > 0.5f) { |
| 691 | colorBase = mContext.getColor(R.color.quick_step_track_background_background_dark); |
| 692 | colorGrad = mContext.getColor(R.color.quick_step_track_background_foreground_dark); |
| 693 | } else { |
| 694 | colorBase = mContext.getColor(R.color.quick_step_track_background_background_light); |
| 695 | colorGrad = mContext.getColor(R.color.quick_step_track_background_foreground_light); |
| 696 | } |
| 697 | mHighlight = new RadialGradient(0, mTrackRect.height() / 2, |
| 698 | mTrackRect.width() * GRADIENT_WIDTH, colorGrad, colorBase, |
| 699 | Shader.TileMode.CLAMP); |
| 700 | mTrackPaint.setShader(mHighlight); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 703 | private boolean canPerformHomeBackGesture() { |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 704 | return swipeHomeGoBackGestureEnabled(mContext) |
| 705 | && mOverviewEventSender.getBackButtonAlpha() > 0; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | private void performBack() { |
| 709 | sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); |
| 710 | sendEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK); |
| 711 | mNavigationBarView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 712 | } |
| 713 | |
| 714 | private void sendEvent(int action, int code) { |
| 715 | long when = SystemClock.uptimeMillis(); |
| 716 | final KeyEvent ev = new KeyEvent(when, when, action, code, 0 /* repeat */, |
| 717 | 0 /* metaState */, KeyCharacterMap.VIRTUAL_KEYBOARD, 0 /* scancode */, |
| 718 | KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, |
| 719 | InputDevice.SOURCE_KEYBOARD); |
| 720 | InputManager.getInstance().injectInputEvent(ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); |
| 721 | } |
| 722 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 723 | private boolean proxyMotionEvents(MotionEvent event) { |
| 724 | final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy(); |
| 725 | event.transform(mTransformGlobalMatrix); |
| 726 | try { |
| 727 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 728 | overviewProxy.onPreMotionEvent(mNavigationBarView.getDownHitTarget()); |
| 729 | } |
| 730 | overviewProxy.onMotionEvent(event); |
| 731 | if (DEBUG_OVERVIEW_PROXY) { |
| 732 | Log.d(TAG_OPS, "Send MotionEvent: " + event.toString()); |
| 733 | } |
| 734 | return true; |
| 735 | } catch (RemoteException e) { |
| 736 | Log.e(TAG, "Callback failed", e); |
| 737 | } finally { |
| 738 | event.transform(mTransformLocalMatrix); |
Matthew Ng | db2734c | 2018-02-16 16:02:20 -0800 | [diff] [blame] | 739 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 740 | return false; |
Matthew Ng | db2734c | 2018-02-16 16:02:20 -0800 | [diff] [blame] | 741 | } |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame^] | 742 | |
| 743 | private static boolean getBoolGlobalSetting(Context context, String key) { |
| 744 | return Settings.Global.getInt(context.getContentResolver(), key, 0) != 0; |
| 745 | } |
| 746 | |
| 747 | public static boolean swipeHomeGoBackGestureEnabled(Context context) { |
| 748 | return !getBoolGlobalSetting(context, NAVBAR_EXPERIMENTS_DISABLED) |
| 749 | && getBoolGlobalSetting(context, PULL_HOME_GO_BACK_PROP); |
| 750 | } |
| 751 | |
| 752 | public static boolean shouldhideBackButton(Context context) { |
| 753 | return swipeHomeGoBackGestureEnabled(context) |
| 754 | && getBoolGlobalSetting(context, HIDE_BACK_BUTTON_PROP); |
| 755 | } |
| 756 | |
| 757 | public static boolean shouldExecuteBackOnUp(Context context) { |
| 758 | return !getBoolGlobalSetting(context, NAVBAR_EXPERIMENTS_DISABLED) |
| 759 | && getBoolGlobalSetting(context, BACK_AFTER_END_PROP); |
| 760 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 761 | } |