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 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.AnimatorSet; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 22 | import android.animation.ArgbEvaluator; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
| 24 | import android.animation.ValueAnimator; |
| 25 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
| 26 | import android.content.Context; |
| 27 | import android.graphics.Canvas; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 28 | import android.graphics.Matrix; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 29 | import android.graphics.Paint; |
| 30 | import android.graphics.Rect; |
| 31 | import android.os.Handler; |
| 32 | import android.os.RemoteException; |
| 33 | import android.util.Log; |
| 34 | import android.util.Slog; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 35 | import android.view.MotionEvent; |
| 36 | import android.view.View; |
| 37 | import android.view.ViewConfiguration; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 38 | import android.view.WindowManagerGlobal; |
| 39 | import android.view.animation.DecelerateInterpolator; |
| 40 | import android.view.animation.Interpolator; |
| 41 | import android.support.annotation.DimenRes; |
| 42 | import com.android.systemui.Dependency; |
| 43 | import com.android.systemui.OverviewProxyService; |
| 44 | import com.android.systemui.R; |
| 45 | import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper; |
| 46 | import com.android.systemui.shared.recents.IOverviewProxy; |
| 47 | import com.android.systemui.shared.recents.utilities.Utilities; |
| 48 | |
| 49 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT; |
| 50 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM; |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 51 | import static com.android.systemui.OverviewProxyService.DEBUG_OVERVIEW_PROXY; |
| 52 | import static com.android.systemui.OverviewProxyService.TAG_OPS; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 53 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 54 | |
| 55 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 56 | * Class to detect gestures on the navigation bar and implement quick scrub. |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 57 | */ |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 58 | public class QuickStepController implements GestureHelper { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 59 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 60 | private static final String TAG = "QuickStepController"; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 61 | private static final int ANIM_DURATION_MS = 200; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 62 | |
| 63 | private NavigationBarView mNavigationBarView; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 64 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 65 | private boolean mQuickScrubActive; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 66 | private boolean mAllowGestureDetection; |
| 67 | private boolean mQuickStepStarted; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 68 | private float mDownOffset; |
| 69 | private float mTranslation; |
| 70 | private int mTouchDownX; |
| 71 | private int mTouchDownY; |
| 72 | private boolean mDragPositive; |
| 73 | private boolean mIsVertical; |
| 74 | private boolean mIsRTL; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 75 | private float mTrackAlpha; |
| 76 | private int mLightTrackColor; |
| 77 | private int mDarkTrackColor; |
| 78 | private float mDarkIntensity; |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 79 | private View mHomeButtonView; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 80 | |
| 81 | private final Handler mHandler = new Handler(); |
| 82 | private final Interpolator mQuickScrubEndInterpolator = new DecelerateInterpolator(); |
| 83 | private final Rect mTrackRect = new Rect(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 84 | private final Paint mTrackPaint = new Paint(); |
| 85 | private final int mScrollTouchSlop; |
| 86 | private final OverviewProxyService mOverviewEventSender; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 87 | private final int mTrackThickness; |
| 88 | private final int mTrackPadding; |
| 89 | private final ValueAnimator mTrackAnimator; |
| 90 | private final ValueAnimator mButtonAnimator; |
| 91 | private final AnimatorSet mQuickScrubEndAnimator; |
| 92 | private final Context mContext; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 93 | private final Matrix mTransformGlobalMatrix = new Matrix(); |
| 94 | private final Matrix mTransformLocalMatrix = new Matrix(); |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 95 | private final ArgbEvaluator mTrackColorEvaluator = new ArgbEvaluator(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 96 | |
| 97 | private final AnimatorUpdateListener mTrackAnimatorListener = valueAnimator -> { |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 98 | mTrackAlpha = (float) valueAnimator.getAnimatedValue(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 99 | mNavigationBarView.invalidate(); |
| 100 | }; |
| 101 | |
| 102 | private final AnimatorUpdateListener mButtonTranslationListener = animator -> { |
| 103 | int pos = (int) animator.getAnimatedValue(); |
| 104 | if (!mQuickScrubActive) { |
| 105 | pos = mDragPositive ? Math.min((int) mTranslation, pos) : Math.max((int) mTranslation, pos); |
| 106 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 107 | if (mIsVertical) { |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 108 | mHomeButtonView.setTranslationY(pos); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 109 | } else { |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 110 | mHomeButtonView.setTranslationX(pos); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 111 | } |
| 112 | }; |
| 113 | |
| 114 | private AnimatorListenerAdapter mQuickScrubEndListener = new AnimatorListenerAdapter() { |
| 115 | @Override |
| 116 | public void onAnimationEnd(Animator animation) { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 117 | mQuickScrubActive = false; |
| 118 | mTranslation = 0; |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 119 | mQuickScrubEndAnimator.setCurrentPlayTime(mQuickScrubEndAnimator.getDuration()); |
| 120 | mHomeButtonView = null; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 121 | } |
| 122 | }; |
| 123 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 124 | public QuickStepController(Context context) { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 125 | mContext = context; |
| 126 | mScrollTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 127 | mOverviewEventSender = Dependency.get(OverviewProxyService.class); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 128 | mTrackThickness = getDimensionPixelSize(mContext, R.dimen.nav_quick_scrub_track_thickness); |
| 129 | mTrackPadding = getDimensionPixelSize(mContext, R.dimen.nav_quick_scrub_track_edge_padding); |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 130 | mTrackPaint.setAlpha(0); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 131 | |
| 132 | mTrackAnimator = ObjectAnimator.ofFloat(); |
| 133 | mTrackAnimator.addUpdateListener(mTrackAnimatorListener); |
Matthew Ng | 55437a9 | 2018-02-23 15:02:07 -0800 | [diff] [blame] | 134 | mTrackAnimator.setFloatValues(0); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 135 | mButtonAnimator = ObjectAnimator.ofInt(); |
| 136 | mButtonAnimator.addUpdateListener(mButtonTranslationListener); |
Matthew Ng | 55437a9 | 2018-02-23 15:02:07 -0800 | [diff] [blame] | 137 | mButtonAnimator.setIntValues(0); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 138 | mQuickScrubEndAnimator = new AnimatorSet(); |
| 139 | mQuickScrubEndAnimator.playTogether(mTrackAnimator, mButtonAnimator); |
| 140 | mQuickScrubEndAnimator.setDuration(ANIM_DURATION_MS); |
| 141 | mQuickScrubEndAnimator.addListener(mQuickScrubEndListener); |
| 142 | mQuickScrubEndAnimator.setInterpolator(mQuickScrubEndInterpolator); |
| 143 | } |
| 144 | |
| 145 | public void setComponents(NavigationBarView navigationBarView) { |
| 146 | mNavigationBarView = navigationBarView; |
| 147 | } |
| 148 | |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 149 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 150 | * @return true if we want to intercept touch events for quick scrub and prevent proxying the |
| 151 | * event to the overview service. |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 152 | */ |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 153 | @Override |
| 154 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 155 | return handleTouchEvent(event); |
| 156 | } |
| 157 | |
| 158 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 159 | * @return true if we want to handle touch events for quick scrub or if down event (that will |
| 160 | * 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] | 161 | */ |
| 162 | @Override |
| 163 | public boolean onTouchEvent(MotionEvent event) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 164 | // The same down event was just sent on intercept and therefore can be ignored here |
| 165 | final boolean ignoreProxyDownEvent = event.getAction() == MotionEvent.ACTION_DOWN |
| 166 | && mOverviewEventSender.getProxy() != null; |
| 167 | return ignoreProxyDownEvent || handleTouchEvent(event); |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | private boolean handleTouchEvent(MotionEvent event) { |
Matthew Ng | 22cf514 | 2018-03-14 12:26:14 -0700 | [diff] [blame] | 171 | if (!mNavigationBarView.isQuickScrubEnabled() |
| 172 | && !mNavigationBarView.isQuickStepSwipeUpEnabled()) { |
| 173 | mNavigationBarView.getHomeButton().setDelayTouchFeedback(false /* delay */); |
| 174 | return false; |
| 175 | } |
| 176 | mNavigationBarView.requestUnbufferedDispatch(event); |
| 177 | |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 178 | final ButtonDispatcher homeButton = mNavigationBarView.getHomeButton(); |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 179 | final boolean homePressed = mNavigationBarView.getDownHitTarget() == HIT_TARGET_HOME; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 180 | int action = event.getAction(); |
| 181 | switch (action & MotionEvent.ACTION_MASK) { |
| 182 | case MotionEvent.ACTION_DOWN: { |
| 183 | int x = (int) event.getX(); |
| 184 | int y = (int) event.getY(); |
Winson Chung | 0be8f08 | 2018-02-15 15:52:49 -0800 | [diff] [blame] | 185 | // End any existing quickscrub animations before starting the new transition |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 186 | if (mHomeButtonView != null) { |
Winson Chung | 0be8f08 | 2018-02-15 15:52:49 -0800 | [diff] [blame] | 187 | mQuickScrubEndAnimator.end(); |
| 188 | } |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 189 | mHomeButtonView = homeButton.getCurrentView(); |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 190 | homeButton.setDelayTouchFeedback(true /* delay */); |
| 191 | mTouchDownX = x; |
| 192 | mTouchDownY = y; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 193 | mTransformGlobalMatrix.set(Matrix.IDENTITY_MATRIX); |
| 194 | mTransformLocalMatrix.set(Matrix.IDENTITY_MATRIX); |
| 195 | mNavigationBarView.transformMatrixToGlobal(mTransformGlobalMatrix); |
| 196 | mNavigationBarView.transformMatrixToLocal(mTransformLocalMatrix); |
| 197 | mQuickStepStarted = false; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 198 | mAllowGestureDetection = true; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 199 | break; |
| 200 | } |
| 201 | case MotionEvent.ACTION_MOVE: { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 202 | if (mQuickStepStarted || !mAllowGestureDetection){ |
| 203 | break; |
| 204 | } |
| 205 | int x = (int) event.getX(); |
| 206 | int y = (int) event.getY(); |
| 207 | int xDiff = Math.abs(x - mTouchDownX); |
| 208 | int yDiff = Math.abs(y - mTouchDownY); |
| 209 | boolean exceededTouchSlopX = xDiff > mScrollTouchSlop && xDiff > yDiff; |
| 210 | boolean exceededTouchSlopY = yDiff > mScrollTouchSlop && yDiff > xDiff; |
| 211 | boolean exceededTouchSlop, exceededPerpendicularTouchSlop; |
| 212 | int pos, touchDown, offset, trackSize; |
Matthew Ng | e0903c9 | 2018-01-17 15:32:41 -0800 | [diff] [blame] | 213 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 214 | if (mIsVertical) { |
| 215 | exceededTouchSlop = exceededTouchSlopY; |
| 216 | exceededPerpendicularTouchSlop = exceededTouchSlopX; |
| 217 | pos = y; |
| 218 | touchDown = mTouchDownY; |
| 219 | offset = pos - mTrackRect.top; |
| 220 | trackSize = mTrackRect.height(); |
| 221 | } else { |
| 222 | exceededTouchSlop = exceededTouchSlopX; |
| 223 | exceededPerpendicularTouchSlop = exceededTouchSlopY; |
| 224 | pos = x; |
| 225 | touchDown = mTouchDownX; |
| 226 | offset = pos - mTrackRect.left; |
| 227 | trackSize = mTrackRect.width(); |
| 228 | } |
| 229 | // Decide to start quickstep if dragging away from the navigation bar, otherwise in |
| 230 | // the parallel direction, decide to start quickscrub. Only one may run. |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 231 | if (!mQuickScrubActive && exceededPerpendicularTouchSlop) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 232 | if (mNavigationBarView.isQuickStepSwipeUpEnabled()) { |
| 233 | startQuickStep(event); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 234 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 235 | break; |
| 236 | } |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 237 | |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 238 | // Do not handle quick scrub if disabled or hit target is not home button |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 239 | if (!homePressed || !mNavigationBarView.isQuickScrubEnabled()) { |
| 240 | break; |
| 241 | } |
| 242 | |
| 243 | if (!mDragPositive) { |
| 244 | offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width(); |
| 245 | } |
| 246 | |
| 247 | // Control the button movement |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 248 | if (!mQuickScrubActive && exceededTouchSlop) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 249 | boolean allowDrag = !mDragPositive |
| 250 | ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown; |
| 251 | if (allowDrag) { |
| 252 | mDownOffset = offset; |
| 253 | homeButton.abortCurrentGesture(); |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 254 | startQuickScrub(); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 255 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 256 | } |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 257 | if (mQuickScrubActive && (mDragPositive && offset >= 0 |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 258 | || !mDragPositive && offset <= 0)) { |
| 259 | float scrubFraction = Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1); |
| 260 | mTranslation = !mDragPositive |
| 261 | ? Utilities.clamp(offset - mDownOffset, -trackSize, 0) |
| 262 | : Utilities.clamp(offset - mDownOffset, 0, trackSize); |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 263 | try { |
| 264 | mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction); |
| 265 | if (DEBUG_OVERVIEW_PROXY) { |
| 266 | Log.d(TAG_OPS, "Quick Scrub Progress:" + scrubFraction); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 267 | } |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 268 | } catch (RemoteException e) { |
| 269 | Log.e(TAG, "Failed to send progress of quick scrub.", e); |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 270 | } |
| 271 | if (mIsVertical) { |
| 272 | mHomeButtonView.setTranslationY(mTranslation); |
| 273 | } else { |
| 274 | mHomeButtonView.setTranslationX(mTranslation); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | break; |
| 278 | } |
| 279 | case MotionEvent.ACTION_CANCEL: |
| 280 | case MotionEvent.ACTION_UP: |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 281 | endQuickScrub(true /* animate */); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 282 | break; |
| 283 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 284 | |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 285 | // Proxy motion events to launcher if not handled by quick scrub |
| 286 | if (!mQuickScrubActive && mAllowGestureDetection) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 287 | proxyMotionEvents(event); |
| 288 | } |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 289 | return mQuickScrubActive || mQuickStepStarted; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void onDraw(Canvas canvas) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 294 | if (mNavigationBarView.isQuickScrubEnabled()) { |
| 295 | return; |
| 296 | } |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 297 | int color = (int) mTrackColorEvaluator.evaluate(mDarkIntensity, mLightTrackColor, |
| 298 | mDarkTrackColor); |
| 299 | mTrackPaint.setColor(color); |
| 300 | mTrackPaint.setAlpha((int) (mTrackPaint.getAlpha() * mTrackAlpha)); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 301 | canvas.drawRect(mTrackRect, mTrackPaint); |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 306 | final int width = right - left; |
| 307 | final int height = bottom - top; |
| 308 | final int x1, x2, y1, y2; |
| 309 | if (mIsVertical) { |
| 310 | x1 = (width - mTrackThickness) / 2; |
| 311 | x2 = x1 + mTrackThickness; |
| 312 | y1 = mDragPositive ? height / 2 : mTrackPadding; |
| 313 | y2 = y1 + height / 2 - mTrackPadding; |
| 314 | } else { |
| 315 | y1 = (height - mTrackThickness) / 2; |
| 316 | y2 = y1 + mTrackThickness; |
| 317 | x1 = mDragPositive ? width / 2 : mTrackPadding; |
| 318 | x2 = x1 + width / 2 - mTrackPadding; |
| 319 | } |
| 320 | mTrackRect.set(x1, y1, x2, y2); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | @Override |
| 324 | public void onDarkIntensityChange(float intensity) { |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 325 | mDarkIntensity = intensity; |
| 326 | mNavigationBarView.invalidate(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | @Override |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 330 | public void setBarState(boolean isVertical, boolean isRTL) { |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 331 | final boolean changed = (mIsVertical != isVertical) || (mIsRTL != isRTL); |
| 332 | if (changed) { |
| 333 | // End quickscrub if the state changes mid-transition |
| 334 | endQuickScrub(false /* animate */); |
| 335 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 336 | mIsVertical = isVertical; |
| 337 | mIsRTL = isRTL; |
| 338 | try { |
| 339 | int navbarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition(); |
| 340 | mDragPositive = navbarPos == NAV_BAR_LEFT || navbarPos == NAV_BAR_BOTTOM; |
| 341 | if (isRTL) { |
| 342 | mDragPositive = !mDragPositive; |
| 343 | } |
| 344 | } catch (RemoteException e) { |
| 345 | Slog.e(TAG, "Failed to get nav bar position.", e); |
| 346 | } |
| 347 | } |
| 348 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 349 | @Override |
| 350 | public void onNavigationButtonLongPress(View v) { |
| 351 | mAllowGestureDetection = false; |
| 352 | mHandler.removeCallbacksAndMessages(null); |
| 353 | } |
| 354 | |
| 355 | private void startQuickStep(MotionEvent event) { |
| 356 | mQuickStepStarted = true; |
| 357 | event.transform(mTransformGlobalMatrix); |
| 358 | try { |
| 359 | mOverviewEventSender.getProxy().onQuickStep(event); |
| 360 | if (DEBUG_OVERVIEW_PROXY) { |
| 361 | Log.d(TAG_OPS, "Quick Step Start"); |
| 362 | } |
| 363 | } catch (RemoteException e) { |
| 364 | Log.e(TAG, "Failed to send quick step started.", e); |
| 365 | } finally { |
| 366 | event.transform(mTransformLocalMatrix); |
| 367 | } |
| 368 | mOverviewEventSender.notifyQuickStepStarted(); |
| 369 | mNavigationBarView.getHomeButton().abortCurrentGesture(); |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 370 | mHandler.removeCallbacksAndMessages(null); |
| 371 | } |
| 372 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 373 | private void startQuickScrub() { |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 374 | if (!mQuickScrubActive) { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 375 | mQuickScrubActive = true; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 376 | mLightTrackColor = mContext.getColor(R.color.quick_step_track_background_light); |
| 377 | mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark); |
| 378 | mTrackAnimator.setFloatValues(0, 1); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 379 | mTrackAnimator.start(); |
| 380 | try { |
| 381 | mOverviewEventSender.getProxy().onQuickScrubStart(); |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 382 | if (DEBUG_OVERVIEW_PROXY) { |
| 383 | Log.d(TAG_OPS, "Quick Scrub Start"); |
| 384 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 385 | } catch (RemoteException e) { |
| 386 | Log.e(TAG, "Failed to send start of quick scrub.", e); |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 391 | private void endQuickScrub(boolean animate) { |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame^] | 392 | if (mQuickScrubActive) { |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 393 | animateEnd(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 394 | try { |
| 395 | mOverviewEventSender.getProxy().onQuickScrubEnd(); |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 396 | if (DEBUG_OVERVIEW_PROXY) { |
| 397 | Log.d(TAG_OPS, "Quick Scrub End"); |
| 398 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 399 | } catch (RemoteException e) { |
| 400 | Log.e(TAG, "Failed to send end of quick scrub.", e); |
| 401 | } |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 402 | } |
| 403 | if (mHomeButtonView != null && !animate) { |
| 404 | mQuickScrubEndAnimator.end(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 405 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 408 | private boolean proxyMotionEvents(MotionEvent event) { |
| 409 | final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy(); |
| 410 | event.transform(mTransformGlobalMatrix); |
| 411 | try { |
| 412 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 413 | overviewProxy.onPreMotionEvent(mNavigationBarView.getDownHitTarget()); |
| 414 | } |
| 415 | overviewProxy.onMotionEvent(event); |
| 416 | if (DEBUG_OVERVIEW_PROXY) { |
| 417 | Log.d(TAG_OPS, "Send MotionEvent: " + event.toString()); |
| 418 | } |
| 419 | return true; |
| 420 | } catch (RemoteException e) { |
| 421 | Log.e(TAG, "Callback failed", e); |
| 422 | } finally { |
| 423 | event.transform(mTransformLocalMatrix); |
Matthew Ng | db2734c | 2018-02-16 16:02:20 -0800 | [diff] [blame] | 424 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 425 | return false; |
Matthew Ng | db2734c | 2018-02-16 16:02:20 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 428 | private void animateEnd() { |
| 429 | mButtonAnimator.setIntValues((int) mTranslation, 0); |
| 430 | mTrackAnimator.setFloatValues(mTrackAlpha, 0); |
Matthew Ng | 55437a9 | 2018-02-23 15:02:07 -0800 | [diff] [blame] | 431 | mQuickScrubEndAnimator.setCurrentPlayTime(0); |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 432 | mQuickScrubEndAnimator.start(); |
| 433 | } |
| 434 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 435 | private int getDimensionPixelSize(Context context, @DimenRes int resId) { |
| 436 | return context.getResources().getDimensionPixelSize(resId); |
| 437 | } |
| 438 | } |