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; |
| 25 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 26 | import android.animation.Animator; |
| 27 | import android.animation.AnimatorListenerAdapter; |
| 28 | import android.animation.AnimatorSet; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 29 | import android.animation.ArgbEvaluator; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 30 | import android.animation.ObjectAnimator; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 31 | import android.animation.PropertyValuesHolder; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 32 | import android.content.Context; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 34 | import android.graphics.Canvas; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 35 | import android.graphics.Color; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 36 | import android.graphics.Matrix; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 37 | import android.graphics.Rect; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 38 | import android.graphics.drawable.Drawable; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 39 | import android.os.Handler; |
| 40 | import android.os.RemoteException; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 41 | import android.util.FloatProperty; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 42 | import android.util.Log; |
| 43 | import android.util.Slog; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 44 | import android.view.MotionEvent; |
| 45 | import android.view.View; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 46 | import android.view.WindowManagerGlobal; |
| 47 | import android.view.animation.DecelerateInterpolator; |
| 48 | import android.view.animation.Interpolator; |
| 49 | import android.support.annotation.DimenRes; |
| 50 | import com.android.systemui.Dependency; |
| 51 | import com.android.systemui.OverviewProxyService; |
| 52 | import com.android.systemui.R; |
| 53 | import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper; |
| 54 | import com.android.systemui.shared.recents.IOverviewProxy; |
| 55 | import com.android.systemui.shared.recents.utilities.Utilities; |
Matthew Ng | f29ad75 | 2018-04-26 11:24:05 -0700 | [diff] [blame] | 56 | import com.android.systemui.shared.system.NavigationBarCompat; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 57 | import com.android.internal.graphics.ColorUtils; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 58 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 59 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 60 | * Class to detect gestures on the navigation bar and implement quick scrub. |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 61 | */ |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 62 | public class QuickStepController implements GestureHelper { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 63 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 64 | private static final String TAG = "QuickStepController"; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 65 | private static final int ANIM_IN_DURATION_MS = 150; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 66 | private static final int ANIM_OUT_DURATION_MS = 134; |
| 67 | private static final float TRACK_SCALE = 0.95f; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 68 | |
| 69 | private NavigationBarView mNavigationBarView; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 70 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 71 | private boolean mQuickScrubActive; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 72 | private boolean mAllowGestureDetection; |
| 73 | private boolean mQuickStepStarted; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 74 | private int mTouchDownX; |
| 75 | private int mTouchDownY; |
| 76 | private boolean mDragPositive; |
| 77 | private boolean mIsVertical; |
| 78 | private boolean mIsRTL; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 79 | private float mTrackAlpha; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 80 | private float mTrackScale = TRACK_SCALE; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 81 | private int mLightTrackColor; |
| 82 | private int mDarkTrackColor; |
| 83 | private float mDarkIntensity; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 84 | private AnimatorSet mTrackAnimator; |
| 85 | private ButtonDispatcher mHitTarget; |
| 86 | private View mCurrentNavigationBarView; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 87 | |
| 88 | private final Handler mHandler = new Handler(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 89 | private final Rect mTrackRect = new Rect(); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 90 | private final Drawable mTrackDrawable; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 91 | private final OverviewProxyService mOverviewEventSender; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 92 | private final int mTrackThickness; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 93 | private final int mTrackEndPadding; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 94 | private final Context mContext; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 95 | private final Matrix mTransformGlobalMatrix = new Matrix(); |
| 96 | private final Matrix mTransformLocalMatrix = new Matrix(); |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 97 | private final ArgbEvaluator mTrackColorEvaluator = new ArgbEvaluator(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 98 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 99 | private final FloatProperty<QuickStepController> mTrackAlphaProperty = |
| 100 | new FloatProperty<QuickStepController>("TrackAlpha") { |
| 101 | @Override |
| 102 | public void setValue(QuickStepController controller, float alpha) { |
| 103 | mTrackAlpha = alpha; |
| 104 | mNavigationBarView.invalidate(); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public Float get(QuickStepController controller) { |
| 109 | return mTrackAlpha; |
| 110 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 113 | private final FloatProperty<QuickStepController> mTrackScaleProperty = |
| 114 | new FloatProperty<QuickStepController>("TrackScale") { |
| 115 | @Override |
| 116 | public void setValue(QuickStepController controller, float scale) { |
| 117 | mTrackScale = scale; |
| 118 | mNavigationBarView.invalidate(); |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public Float get(QuickStepController controller) { |
| 123 | return mTrackScale; |
| 124 | } |
| 125 | }; |
| 126 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 127 | private final FloatProperty<QuickStepController> mNavBarAlphaProperty = |
| 128 | new FloatProperty<QuickStepController>("NavBarAlpha") { |
| 129 | @Override |
| 130 | public void setValue(QuickStepController controller, float alpha) { |
| 131 | if (mCurrentNavigationBarView != null) { |
| 132 | mCurrentNavigationBarView.setAlpha(alpha); |
| 133 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 134 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 135 | |
| 136 | @Override |
| 137 | public Float get(QuickStepController controller) { |
| 138 | if (mCurrentNavigationBarView != null) { |
| 139 | return mCurrentNavigationBarView.getAlpha(); |
| 140 | } |
| 141 | return 1f; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 142 | } |
| 143 | }; |
| 144 | |
| 145 | private AnimatorListenerAdapter mQuickScrubEndListener = new AnimatorListenerAdapter() { |
| 146 | @Override |
| 147 | public void onAnimationEnd(Animator animation) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 148 | resetQuickScrub(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 149 | } |
| 150 | }; |
| 151 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 152 | public QuickStepController(Context context) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 153 | final Resources res = context.getResources(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 154 | mContext = context; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 155 | mOverviewEventSender = Dependency.get(OverviewProxyService.class); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 156 | mTrackThickness = res.getDimensionPixelSize(R.dimen.nav_quick_scrub_track_thickness); |
| 157 | mTrackEndPadding = res.getDimensionPixelSize(R.dimen.nav_quick_scrub_track_edge_padding); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 158 | mTrackDrawable = context.getDrawable(R.drawable.qs_scrubber_track).mutate(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | public void setComponents(NavigationBarView navigationBarView) { |
| 162 | mNavigationBarView = navigationBarView; |
| 163 | } |
| 164 | |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 165 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 166 | * @return true if we want to intercept touch events for quick scrub and prevent proxying the |
| 167 | * event to the overview service. |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 168 | */ |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 169 | @Override |
| 170 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 171 | return handleTouchEvent(event); |
| 172 | } |
| 173 | |
| 174 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 175 | * @return true if we want to handle touch events for quick scrub or if down event (that will |
| 176 | * 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] | 177 | */ |
| 178 | @Override |
| 179 | public boolean onTouchEvent(MotionEvent event) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 180 | // The same down event was just sent on intercept and therefore can be ignored here |
| 181 | final boolean ignoreProxyDownEvent = event.getAction() == MotionEvent.ACTION_DOWN |
| 182 | && mOverviewEventSender.getProxy() != null; |
| 183 | return ignoreProxyDownEvent || handleTouchEvent(event); |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | private boolean handleTouchEvent(MotionEvent event) { |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 187 | if (mOverviewEventSender.getProxy() == null || (!mNavigationBarView.isQuickScrubEnabled() |
| 188 | && !mNavigationBarView.isQuickStepSwipeUpEnabled())) { |
Matthew Ng | 22cf514 | 2018-03-14 12:26:14 -0700 | [diff] [blame] | 189 | return false; |
| 190 | } |
| 191 | mNavigationBarView.requestUnbufferedDispatch(event); |
| 192 | |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 193 | int action = event.getActionMasked(); |
| 194 | switch (action) { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 195 | case MotionEvent.ACTION_DOWN: { |
| 196 | int x = (int) event.getX(); |
| 197 | int y = (int) event.getY(); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 198 | |
Winson Chung | 0be8f08 | 2018-02-15 15:52:49 -0800 | [diff] [blame] | 199 | // End any existing quickscrub animations before starting the new transition |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 200 | if (mTrackAnimator != null) { |
| 201 | mTrackAnimator.end(); |
| 202 | mTrackAnimator = null; |
Winson Chung | 0be8f08 | 2018-02-15 15:52:49 -0800 | [diff] [blame] | 203 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 204 | |
| 205 | mCurrentNavigationBarView = mNavigationBarView.getCurrentView(); |
| 206 | mHitTarget = mNavigationBarView.getButtonAtPosition(x, y); |
| 207 | if (mHitTarget != null) { |
| 208 | // Pre-emptively delay the touch feedback for the button that we just touched |
| 209 | mHitTarget.setDelayTouchFeedback(true); |
| 210 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 211 | mTouchDownX = x; |
| 212 | mTouchDownY = y; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 213 | mTransformGlobalMatrix.set(Matrix.IDENTITY_MATRIX); |
| 214 | mTransformLocalMatrix.set(Matrix.IDENTITY_MATRIX); |
| 215 | mNavigationBarView.transformMatrixToGlobal(mTransformGlobalMatrix); |
| 216 | mNavigationBarView.transformMatrixToLocal(mTransformLocalMatrix); |
| 217 | mQuickStepStarted = false; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 218 | mAllowGestureDetection = true; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 219 | break; |
| 220 | } |
| 221 | case MotionEvent.ACTION_MOVE: { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 222 | if (mQuickStepStarted || !mAllowGestureDetection){ |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 223 | break; |
| 224 | } |
| 225 | int x = (int) event.getX(); |
| 226 | int y = (int) event.getY(); |
| 227 | int xDiff = Math.abs(x - mTouchDownX); |
| 228 | int yDiff = Math.abs(y - mTouchDownY); |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 229 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 230 | boolean exceededScrubTouchSlop, exceededSwipeUpTouchSlop; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 231 | int pos, touchDown, offset, trackSize; |
Matthew Ng | e0903c9 | 2018-01-17 15:32:41 -0800 | [diff] [blame] | 232 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 233 | if (mIsVertical) { |
Matthew Ng | f29ad75 | 2018-04-26 11:24:05 -0700 | [diff] [blame] | 234 | exceededScrubTouchSlop = |
| 235 | yDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && yDiff > xDiff; |
| 236 | exceededSwipeUpTouchSlop = |
| 237 | xDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && xDiff > yDiff; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 238 | pos = y; |
| 239 | touchDown = mTouchDownY; |
| 240 | offset = pos - mTrackRect.top; |
| 241 | trackSize = mTrackRect.height(); |
| 242 | } else { |
Matthew Ng | f29ad75 | 2018-04-26 11:24:05 -0700 | [diff] [blame] | 243 | exceededScrubTouchSlop = |
| 244 | xDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && xDiff > yDiff; |
| 245 | exceededSwipeUpTouchSlop = |
| 246 | yDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && yDiff > xDiff; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 247 | pos = x; |
| 248 | touchDown = mTouchDownX; |
| 249 | offset = pos - mTrackRect.left; |
| 250 | trackSize = mTrackRect.width(); |
| 251 | } |
| 252 | // Decide to start quickstep if dragging away from the navigation bar, otherwise in |
| 253 | // the parallel direction, decide to start quickscrub. Only one may run. |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 254 | if (!mQuickScrubActive && exceededSwipeUpTouchSlop) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 255 | if (mNavigationBarView.isQuickStepSwipeUpEnabled()) { |
| 256 | startQuickStep(event); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 257 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 258 | break; |
| 259 | } |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 260 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 261 | // Do not handle quick scrub if disabled |
| 262 | if (!mNavigationBarView.isQuickScrubEnabled()) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 263 | break; |
| 264 | } |
| 265 | |
| 266 | if (!mDragPositive) { |
| 267 | offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width(); |
| 268 | } |
| 269 | |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 270 | final boolean allowDrag = !mDragPositive |
| 271 | ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 272 | float scrubFraction = Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1); |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 273 | if (allowDrag) { |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 274 | // Passing the drag slop then touch slop will start quick step |
| 275 | if (!mQuickScrubActive && exceededScrubTouchSlop) { |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 276 | startQuickScrub(); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 277 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 278 | } |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 279 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 280 | if (mQuickScrubActive && (mDragPositive && offset >= 0 |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 281 | || !mDragPositive && offset <= 0)) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 282 | try { |
| 283 | mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction); |
| 284 | if (DEBUG_OVERVIEW_PROXY) { |
| 285 | Log.d(TAG_OPS, "Quick Scrub Progress:" + scrubFraction); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 286 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 287 | } catch (RemoteException e) { |
| 288 | Log.e(TAG, "Failed to send progress of quick scrub.", e); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | break; |
| 292 | } |
| 293 | case MotionEvent.ACTION_CANCEL: |
| 294 | case MotionEvent.ACTION_UP: |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 295 | endQuickScrub(true /* animate */); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 296 | break; |
| 297 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 298 | |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 299 | // Proxy motion events to launcher if not handled by quick scrub |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 300 | // Proxy motion events up/cancel that would be sent after long press on any nav button |
| 301 | if (!mQuickScrubActive && (mAllowGestureDetection || action == MotionEvent.ACTION_CANCEL |
| 302 | || action == MotionEvent.ACTION_UP)) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 303 | proxyMotionEvents(event); |
| 304 | } |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 305 | return mQuickScrubActive || mQuickStepStarted; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | @Override |
| 309 | public void onDraw(Canvas canvas) { |
Matthew Ng | f781bbd | 2018-03-21 14:58:55 -0700 | [diff] [blame] | 310 | if (!mNavigationBarView.isQuickScrubEnabled()) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 311 | return; |
| 312 | } |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 313 | int color = (int) mTrackColorEvaluator.evaluate(mDarkIntensity, mLightTrackColor, |
| 314 | mDarkTrackColor); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 315 | int colorAlpha = ColorUtils.setAlphaComponent(color, |
| 316 | (int) (Color.alpha(color) * mTrackAlpha)); |
| 317 | mTrackDrawable.setTint(colorAlpha); |
| 318 | |
| 319 | // Scale the track, but apply the inverse scale from the nav bar |
| 320 | canvas.save(); |
| 321 | canvas.scale(mTrackScale / mNavigationBarView.getScaleX(), |
| 322 | 1f / mNavigationBarView.getScaleY(), |
| 323 | mTrackRect.centerX(), mTrackRect.centerY()); |
| 324 | mTrackDrawable.draw(canvas); |
| 325 | canvas.restore(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | @Override |
| 329 | 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] | 330 | final int paddingLeft = mNavigationBarView.getPaddingLeft(); |
| 331 | final int paddingTop = mNavigationBarView.getPaddingTop(); |
| 332 | final int paddingRight = mNavigationBarView.getPaddingRight(); |
| 333 | final int paddingBottom = mNavigationBarView.getPaddingBottom(); |
| 334 | final int width = (right - left) - paddingRight - paddingLeft; |
| 335 | final int height = (bottom - top) - paddingBottom - paddingTop; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 336 | final int x1, x2, y1, y2; |
| 337 | if (mIsVertical) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 338 | x1 = (width - mTrackThickness) / 2 + paddingLeft; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 339 | x2 = x1 + mTrackThickness; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 340 | y1 = paddingTop + mTrackEndPadding; |
| 341 | y2 = y1 + height - 2 * mTrackEndPadding; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 342 | } else { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 343 | y1 = (height - mTrackThickness) / 2 + paddingTop; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 344 | y2 = y1 + mTrackThickness; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 345 | x1 = mNavigationBarView.getPaddingStart() + mTrackEndPadding; |
| 346 | x2 = x1 + width - 2 * mTrackEndPadding; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 347 | } |
| 348 | mTrackRect.set(x1, y1, x2, y2); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 349 | mTrackDrawable.setBounds(mTrackRect); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Override |
| 353 | public void onDarkIntensityChange(float intensity) { |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 354 | mDarkIntensity = intensity; |
| 355 | mNavigationBarView.invalidate(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | @Override |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 359 | public void setBarState(boolean isVertical, boolean isRTL) { |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 360 | final boolean changed = (mIsVertical != isVertical) || (mIsRTL != isRTL); |
| 361 | if (changed) { |
| 362 | // End quickscrub if the state changes mid-transition |
| 363 | endQuickScrub(false /* animate */); |
| 364 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 365 | mIsVertical = isVertical; |
| 366 | mIsRTL = isRTL; |
| 367 | try { |
| 368 | int navbarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition(); |
| 369 | mDragPositive = navbarPos == NAV_BAR_LEFT || navbarPos == NAV_BAR_BOTTOM; |
| 370 | if (isRTL) { |
| 371 | mDragPositive = !mDragPositive; |
| 372 | } |
| 373 | } catch (RemoteException e) { |
| 374 | Slog.e(TAG, "Failed to get nav bar position.", e); |
| 375 | } |
| 376 | } |
| 377 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 378 | @Override |
| 379 | public void onNavigationButtonLongPress(View v) { |
| 380 | mAllowGestureDetection = false; |
| 381 | mHandler.removeCallbacksAndMessages(null); |
| 382 | } |
| 383 | |
| 384 | private void startQuickStep(MotionEvent event) { |
| 385 | mQuickStepStarted = true; |
| 386 | event.transform(mTransformGlobalMatrix); |
| 387 | try { |
| 388 | mOverviewEventSender.getProxy().onQuickStep(event); |
| 389 | if (DEBUG_OVERVIEW_PROXY) { |
| 390 | Log.d(TAG_OPS, "Quick Step Start"); |
| 391 | } |
| 392 | } catch (RemoteException e) { |
| 393 | Log.e(TAG, "Failed to send quick step started.", e); |
| 394 | } finally { |
| 395 | event.transform(mTransformLocalMatrix); |
| 396 | } |
| 397 | mOverviewEventSender.notifyQuickStepStarted(); |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 398 | mHandler.removeCallbacksAndMessages(null); |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 399 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 400 | if (mHitTarget != null) { |
| 401 | mHitTarget.abortCurrentGesture(); |
| 402 | } |
| 403 | |
| 404 | if (mQuickScrubActive) { |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 405 | animateEnd(); |
| 406 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 409 | private void startQuickScrub() { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 410 | if (!mQuickScrubActive) { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 411 | mQuickScrubActive = true; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 412 | mLightTrackColor = mContext.getColor(R.color.quick_step_track_background_light); |
| 413 | mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark); |
Matthew Ng | 6607c3d | 2018-04-26 15:23:27 -0700 | [diff] [blame] | 414 | |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 415 | ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this, |
| 416 | PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 1f), |
| 417 | PropertyValuesHolder.ofFloat(mTrackScaleProperty, 1f)); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 418 | trackAnimator.setInterpolator(ALPHA_IN); |
| 419 | trackAnimator.setDuration(ANIM_IN_DURATION_MS); |
| 420 | ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 0f); |
| 421 | navBarAnimator.setInterpolator(ALPHA_OUT); |
| 422 | navBarAnimator.setDuration(ANIM_OUT_DURATION_MS); |
| 423 | mTrackAnimator = new AnimatorSet(); |
| 424 | mTrackAnimator.playTogether(trackAnimator, navBarAnimator); |
| 425 | mTrackAnimator.start(); |
Matthew Ng | 6607c3d | 2018-04-26 15:23:27 -0700 | [diff] [blame] | 426 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 427 | try { |
| 428 | mOverviewEventSender.getProxy().onQuickScrubStart(); |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 429 | if (DEBUG_OVERVIEW_PROXY) { |
| 430 | Log.d(TAG_OPS, "Quick Scrub Start"); |
| 431 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 432 | } catch (RemoteException e) { |
| 433 | Log.e(TAG, "Failed to send start of quick scrub.", e); |
| 434 | } |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 435 | mOverviewEventSender.notifyQuickScrubStarted(); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 436 | |
| 437 | if (mHitTarget != null) { |
| 438 | mHitTarget.abortCurrentGesture(); |
| 439 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 443 | private void endQuickScrub(boolean animate) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 444 | if (mQuickScrubActive) { |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 445 | animateEnd(); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 446 | try { |
| 447 | mOverviewEventSender.getProxy().onQuickScrubEnd(); |
| 448 | if (DEBUG_OVERVIEW_PROXY) { |
| 449 | Log.d(TAG_OPS, "Quick Scrub End"); |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 450 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 451 | } catch (RemoteException e) { |
| 452 | Log.e(TAG, "Failed to send end of quick scrub.", e); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 453 | } |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 454 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 455 | if (!animate) { |
| 456 | if (mTrackAnimator != null) { |
| 457 | mTrackAnimator.end(); |
| 458 | mTrackAnimator = null; |
| 459 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 460 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 463 | private void animateEnd() { |
| 464 | if (mTrackAnimator != null) { |
| 465 | mTrackAnimator.cancel(); |
| 466 | } |
| 467 | |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 468 | ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this, |
| 469 | PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 0f), |
| 470 | PropertyValuesHolder.ofFloat(mTrackScaleProperty, TRACK_SCALE)); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 471 | trackAnimator.setInterpolator(ALPHA_OUT); |
| 472 | trackAnimator.setDuration(ANIM_OUT_DURATION_MS); |
| 473 | ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 1f); |
| 474 | navBarAnimator.setInterpolator(ALPHA_IN); |
| 475 | navBarAnimator.setDuration(ANIM_IN_DURATION_MS); |
| 476 | mTrackAnimator = new AnimatorSet(); |
| 477 | mTrackAnimator.playTogether(trackAnimator, navBarAnimator); |
| 478 | mTrackAnimator.addListener(mQuickScrubEndListener); |
| 479 | mTrackAnimator.start(); |
| 480 | } |
| 481 | |
| 482 | private void resetQuickScrub() { |
| 483 | mQuickScrubActive = false; |
| 484 | mAllowGestureDetection = false; |
| 485 | mCurrentNavigationBarView = null; |
| 486 | } |
| 487 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 488 | private boolean proxyMotionEvents(MotionEvent event) { |
| 489 | final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy(); |
| 490 | event.transform(mTransformGlobalMatrix); |
| 491 | try { |
| 492 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 493 | overviewProxy.onPreMotionEvent(mNavigationBarView.getDownHitTarget()); |
| 494 | } |
| 495 | overviewProxy.onMotionEvent(event); |
| 496 | if (DEBUG_OVERVIEW_PROXY) { |
| 497 | Log.d(TAG_OPS, "Send MotionEvent: " + event.toString()); |
| 498 | } |
| 499 | return true; |
| 500 | } catch (RemoteException e) { |
| 501 | Log.e(TAG, "Callback failed", e); |
| 502 | } finally { |
| 503 | event.transform(mTransformLocalMatrix); |
Matthew Ng | db2734c | 2018-02-16 16:02:20 -0800 | [diff] [blame] | 504 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 505 | return false; |
Matthew Ng | db2734c | 2018-02-16 16:02:20 -0800 | [diff] [blame] | 506 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 507 | } |