blob: 19544b170d1ff1c5362cdc024d8a72119b0c40d2 [file] [log] [blame]
Matthew Nga8f24262017-12-19 11:54:24 -08001/*
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
17package com.android.systemui.statusbar.phone;
18
19import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
21import android.animation.AnimatorSet;
Matthew Ng7090a802018-01-19 13:36:22 -080022import android.animation.ArgbEvaluator;
Matthew Nga8f24262017-12-19 11:54:24 -080023import android.animation.ObjectAnimator;
24import android.animation.ValueAnimator;
25import android.animation.ValueAnimator.AnimatorUpdateListener;
26import android.content.Context;
27import android.graphics.Canvas;
Matthew Ng2ea93b72018-03-14 19:43:18 +000028import android.graphics.Matrix;
Matthew Nga8f24262017-12-19 11:54:24 -080029import android.graphics.Paint;
30import android.graphics.Rect;
31import android.os.Handler;
32import android.os.RemoteException;
33import android.util.Log;
34import android.util.Slog;
Matthew Nga8f24262017-12-19 11:54:24 -080035import android.view.GestureDetector;
36import android.view.MotionEvent;
37import android.view.View;
38import android.view.ViewConfiguration;
Matthew Nga8f24262017-12-19 11:54:24 -080039import android.view.WindowManagerGlobal;
40import android.view.animation.DecelerateInterpolator;
41import android.view.animation.Interpolator;
42import android.support.annotation.DimenRes;
43import com.android.systemui.Dependency;
44import com.android.systemui.OverviewProxyService;
45import com.android.systemui.R;
46import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper;
47import com.android.systemui.shared.recents.IOverviewProxy;
48import com.android.systemui.shared.recents.utilities.Utilities;
49
50import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT;
51import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM;
Matthew Ngbd824572018-01-17 16:25:56 -080052import static com.android.systemui.OverviewProxyService.DEBUG_OVERVIEW_PROXY;
53import static com.android.systemui.OverviewProxyService.TAG_OPS;
Winson Chungc4e06202018-02-13 10:37:35 -080054import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME;
Matthew Nga8f24262017-12-19 11:54:24 -080055
56/**
57 * Class to detect gestures on the navigation bar and implement quick scrub and switch.
58 */
Matthew Ng2ea93b72018-03-14 19:43:18 +000059public class QuickStepController extends GestureDetector.SimpleOnGestureListener implements
Matthew Nga8f24262017-12-19 11:54:24 -080060 GestureHelper {
61
Matthew Ng2ea93b72018-03-14 19:43:18 +000062 private static final String TAG = "QuickStepController";
Matthew Nga8f24262017-12-19 11:54:24 -080063 private static final int QUICK_SWITCH_FLING_VELOCITY = 0;
64 private static final int ANIM_DURATION_MS = 200;
Winson Chungde2a1242018-02-07 15:59:43 -080065 private static final long LONG_PRESS_DELAY_MS = 225;
Matthew Nga8f24262017-12-19 11:54:24 -080066
67 /**
68 * For quick step, set a damping value to allow the button to stick closer its origin position
69 * when dragging before quick scrub is active.
70 */
71 private static final int SWITCH_STICKINESS = 4;
72
73 private NavigationBarView mNavigationBarView;
74 private GestureDetector mGestureDetector;
75
76 private boolean mDraggingActive;
77 private boolean mQuickScrubActive;
Winson Chung49658842018-02-08 12:52:21 -080078 private boolean mAllowQuickSwitch;
Matthew Ng2ea93b72018-03-14 19:43:18 +000079 private boolean mAllowGestureDetection;
80 private boolean mQuickStepStarted;
Matthew Nga8f24262017-12-19 11:54:24 -080081 private float mDownOffset;
82 private float mTranslation;
83 private int mTouchDownX;
84 private int mTouchDownY;
85 private boolean mDragPositive;
86 private boolean mIsVertical;
87 private boolean mIsRTL;
Matthew Ng7090a802018-01-19 13:36:22 -080088 private float mTrackAlpha;
89 private int mLightTrackColor;
90 private int mDarkTrackColor;
91 private float mDarkIntensity;
Winson Chungd10ca302018-02-14 10:13:41 -080092 private View mHomeButtonView;
Matthew Nga8f24262017-12-19 11:54:24 -080093
94 private final Handler mHandler = new Handler();
95 private final Interpolator mQuickScrubEndInterpolator = new DecelerateInterpolator();
96 private final Rect mTrackRect = new Rect();
Matthew Nga8f24262017-12-19 11:54:24 -080097 private final Paint mTrackPaint = new Paint();
98 private final int mScrollTouchSlop;
99 private final OverviewProxyService mOverviewEventSender;
Matthew Nga8f24262017-12-19 11:54:24 -0800100 private final int mTrackThickness;
101 private final int mTrackPadding;
102 private final ValueAnimator mTrackAnimator;
103 private final ValueAnimator mButtonAnimator;
104 private final AnimatorSet mQuickScrubEndAnimator;
105 private final Context mContext;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000106 private final Matrix mTransformGlobalMatrix = new Matrix();
107 private final Matrix mTransformLocalMatrix = new Matrix();
Matthew Ng7090a802018-01-19 13:36:22 -0800108 private final ArgbEvaluator mTrackColorEvaluator = new ArgbEvaluator();
Matthew Nga8f24262017-12-19 11:54:24 -0800109
110 private final AnimatorUpdateListener mTrackAnimatorListener = valueAnimator -> {
Matthew Ng7090a802018-01-19 13:36:22 -0800111 mTrackAlpha = (float) valueAnimator.getAnimatedValue();
Matthew Nga8f24262017-12-19 11:54:24 -0800112 mNavigationBarView.invalidate();
113 };
114
115 private final AnimatorUpdateListener mButtonTranslationListener = animator -> {
116 int pos = (int) animator.getAnimatedValue();
117 if (!mQuickScrubActive) {
118 pos = mDragPositive ? Math.min((int) mTranslation, pos) : Math.max((int) mTranslation, pos);
119 }
Matthew Nga8f24262017-12-19 11:54:24 -0800120 if (mIsVertical) {
Winson Chungd10ca302018-02-14 10:13:41 -0800121 mHomeButtonView.setTranslationY(pos);
Matthew Nga8f24262017-12-19 11:54:24 -0800122 } else {
Winson Chungd10ca302018-02-14 10:13:41 -0800123 mHomeButtonView.setTranslationX(pos);
Matthew Nga8f24262017-12-19 11:54:24 -0800124 }
125 };
126
127 private AnimatorListenerAdapter mQuickScrubEndListener = new AnimatorListenerAdapter() {
128 @Override
129 public void onAnimationEnd(Animator animation) {
Matthew Nga8f24262017-12-19 11:54:24 -0800130 mQuickScrubActive = false;
131 mTranslation = 0;
Matthew Nged166f92018-02-20 16:22:09 -0800132 mQuickScrubEndAnimator.setCurrentPlayTime(mQuickScrubEndAnimator.getDuration());
133 mHomeButtonView = null;
Matthew Nga8f24262017-12-19 11:54:24 -0800134 }
135 };
136
137 private Runnable mLongPressRunnable = this::startQuickScrub;
138
139 private final GestureDetector.SimpleOnGestureListener mGestureListener =
140 new GestureDetector.SimpleOnGestureListener() {
141 @Override
142 public boolean onFling(MotionEvent e1, MotionEvent e2, float velX, float velY) {
Matthew Ng8f25fb962018-01-16 17:17:24 -0800143 if (!mNavigationBarView.isQuickScrubEnabled() || mQuickScrubActive
144 || !mAllowQuickSwitch
145 || mNavigationBarView.getDownHitTarget() != HIT_TARGET_HOME) {
Matthew Nga8f24262017-12-19 11:54:24 -0800146 return false;
147 }
148 float velocityX = mIsRTL ? -velX : velX;
149 float absVelY = Math.abs(velY);
150 final boolean isValidFling = velocityX > QUICK_SWITCH_FLING_VELOCITY &&
151 mIsVertical ? (absVelY > velocityX) : (velocityX > absVelY);
152 if (isValidFling) {
153 mDraggingActive = false;
Matthew Nged166f92018-02-20 16:22:09 -0800154 animateEnd();
Matthew Nga8f24262017-12-19 11:54:24 -0800155 mHandler.removeCallbacks(mLongPressRunnable);
156 try {
157 final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy();
158 overviewProxy.onQuickSwitch();
Matthew Ngbd824572018-01-17 16:25:56 -0800159 if (DEBUG_OVERVIEW_PROXY) {
160 Log.d(TAG_OPS, "Quick Switch");
161 }
Matthew Nga8f24262017-12-19 11:54:24 -0800162 } catch (RemoteException e) {
163 Log.e(TAG, "Failed to send start of quick switch.", e);
164 }
Winson Chung4faf38a2018-02-06 08:53:37 -0800165 return true;
Matthew Nga8f24262017-12-19 11:54:24 -0800166 }
Winson Chung4faf38a2018-02-06 08:53:37 -0800167 return false;
Matthew Nga8f24262017-12-19 11:54:24 -0800168 }
169 };
170
Matthew Ng2ea93b72018-03-14 19:43:18 +0000171 public QuickStepController(Context context) {
Matthew Nga8f24262017-12-19 11:54:24 -0800172 mContext = context;
173 mScrollTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
Matthew Nga8f24262017-12-19 11:54:24 -0800174 mOverviewEventSender = Dependency.get(OverviewProxyService.class);
175 mGestureDetector = new GestureDetector(mContext, mGestureListener);
176 mTrackThickness = getDimensionPixelSize(mContext, R.dimen.nav_quick_scrub_track_thickness);
177 mTrackPadding = getDimensionPixelSize(mContext, R.dimen.nav_quick_scrub_track_edge_padding);
Matthew Ng7090a802018-01-19 13:36:22 -0800178 mTrackPaint.setAlpha(0);
Matthew Nga8f24262017-12-19 11:54:24 -0800179
180 mTrackAnimator = ObjectAnimator.ofFloat();
181 mTrackAnimator.addUpdateListener(mTrackAnimatorListener);
Matthew Ng55437a92018-02-23 15:02:07 -0800182 mTrackAnimator.setFloatValues(0);
Matthew Nga8f24262017-12-19 11:54:24 -0800183 mButtonAnimator = ObjectAnimator.ofInt();
184 mButtonAnimator.addUpdateListener(mButtonTranslationListener);
Matthew Ng55437a92018-02-23 15:02:07 -0800185 mButtonAnimator.setIntValues(0);
Matthew Nga8f24262017-12-19 11:54:24 -0800186 mQuickScrubEndAnimator = new AnimatorSet();
187 mQuickScrubEndAnimator.playTogether(mTrackAnimator, mButtonAnimator);
188 mQuickScrubEndAnimator.setDuration(ANIM_DURATION_MS);
189 mQuickScrubEndAnimator.addListener(mQuickScrubEndListener);
190 mQuickScrubEndAnimator.setInterpolator(mQuickScrubEndInterpolator);
191 }
192
193 public void setComponents(NavigationBarView navigationBarView) {
194 mNavigationBarView = navigationBarView;
195 }
196
Winson Chung4faf38a2018-02-06 08:53:37 -0800197 /**
198 * @return true if we want to intercept touch events for quick scrub/switch and prevent proxying
199 * the event to the overview service.
200 */
Matthew Nga8f24262017-12-19 11:54:24 -0800201 @Override
202 public boolean onInterceptTouchEvent(MotionEvent event) {
Winson Chungde2a1242018-02-07 15:59:43 -0800203 return handleTouchEvent(event);
204 }
205
206 /**
Matthew Ng2ea93b72018-03-14 19:43:18 +0000207 * @return true if we want to handle touch events for quick scrub/switch or if down event (that
208 * will get consumed and ignored). No events will be proxied to the overview service.
Winson Chungde2a1242018-02-07 15:59:43 -0800209 */
210 @Override
211 public boolean onTouchEvent(MotionEvent event) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000212 // The same down event was just sent on intercept and therefore can be ignored here
213 final boolean ignoreProxyDownEvent = event.getAction() == MotionEvent.ACTION_DOWN
214 && mOverviewEventSender.getProxy() != null;
215 return ignoreProxyDownEvent || handleTouchEvent(event);
Winson Chungde2a1242018-02-07 15:59:43 -0800216 }
217
218 private boolean handleTouchEvent(MotionEvent event) {
Matthew Ng22cf5142018-03-14 12:26:14 -0700219 if (!mNavigationBarView.isQuickScrubEnabled()
220 && !mNavigationBarView.isQuickStepSwipeUpEnabled()) {
221 mNavigationBarView.getHomeButton().setDelayTouchFeedback(false /* delay */);
222 return false;
223 }
224 mNavigationBarView.requestUnbufferedDispatch(event);
225
Winson Chungde2a1242018-02-07 15:59:43 -0800226 final ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
Winson Chung4faf38a2018-02-06 08:53:37 -0800227 if (mGestureDetector.onTouchEvent(event)) {
Winson Chungde2a1242018-02-07 15:59:43 -0800228 // If the fling has been handled on UP, then skip proxying the UP
Winson Chung4faf38a2018-02-06 08:53:37 -0800229 return true;
230 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000231 final boolean homePressed = mNavigationBarView.getDownHitTarget() == HIT_TARGET_HOME;
Matthew Nga8f24262017-12-19 11:54:24 -0800232 int action = event.getAction();
233 switch (action & MotionEvent.ACTION_MASK) {
234 case MotionEvent.ACTION_DOWN: {
235 int x = (int) event.getX();
236 int y = (int) event.getY();
Winson Chung0be8f082018-02-15 15:52:49 -0800237 // End any existing quickscrub animations before starting the new transition
Matthew Nged166f92018-02-20 16:22:09 -0800238 if (mHomeButtonView != null) {
Winson Chung0be8f082018-02-15 15:52:49 -0800239 mQuickScrubEndAnimator.end();
240 }
Winson Chungd10ca302018-02-14 10:13:41 -0800241 mHomeButtonView = homeButton.getCurrentView();
Matthew Ng2ea93b72018-03-14 19:43:18 +0000242 homeButton.setDelayTouchFeedback(true /* delay */);
243 mTouchDownX = x;
244 mTouchDownY = y;
245 if (homePressed) {
Matthew Nga8f24262017-12-19 11:54:24 -0800246 mHandler.postDelayed(mLongPressRunnable, LONG_PRESS_DELAY_MS);
Matthew Nga8f24262017-12-19 11:54:24 -0800247 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000248 mTransformGlobalMatrix.set(Matrix.IDENTITY_MATRIX);
249 mTransformLocalMatrix.set(Matrix.IDENTITY_MATRIX);
250 mNavigationBarView.transformMatrixToGlobal(mTransformGlobalMatrix);
251 mNavigationBarView.transformMatrixToLocal(mTransformLocalMatrix);
252 mQuickStepStarted = false;
Winson Chung49658842018-02-08 12:52:21 -0800253 mAllowQuickSwitch = true;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000254 mAllowGestureDetection = true;
Matthew Nga8f24262017-12-19 11:54:24 -0800255 break;
256 }
257 case MotionEvent.ACTION_MOVE: {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000258 if (mQuickStepStarted || !mAllowGestureDetection){
259 break;
260 }
261 int x = (int) event.getX();
262 int y = (int) event.getY();
263 int xDiff = Math.abs(x - mTouchDownX);
264 int yDiff = Math.abs(y - mTouchDownY);
265 boolean exceededTouchSlopX = xDiff > mScrollTouchSlop && xDiff > yDiff;
266 boolean exceededTouchSlopY = yDiff > mScrollTouchSlop && yDiff > xDiff;
267 boolean exceededTouchSlop, exceededPerpendicularTouchSlop;
268 int pos, touchDown, offset, trackSize;
Matthew Nge0903c92018-01-17 15:32:41 -0800269
Matthew Ng2ea93b72018-03-14 19:43:18 +0000270 if (mIsVertical) {
271 exceededTouchSlop = exceededTouchSlopY;
272 exceededPerpendicularTouchSlop = exceededTouchSlopX;
273 pos = y;
274 touchDown = mTouchDownY;
275 offset = pos - mTrackRect.top;
276 trackSize = mTrackRect.height();
277 } else {
278 exceededTouchSlop = exceededTouchSlopX;
279 exceededPerpendicularTouchSlop = exceededTouchSlopY;
280 pos = x;
281 touchDown = mTouchDownX;
282 offset = pos - mTrackRect.left;
283 trackSize = mTrackRect.width();
284 }
285 // Decide to start quickstep if dragging away from the navigation bar, otherwise in
286 // the parallel direction, decide to start quickscrub. Only one may run.
287 if (!mDraggingActive && !mQuickScrubActive && exceededPerpendicularTouchSlop) {
288 if (mNavigationBarView.isQuickStepSwipeUpEnabled()) {
289 startQuickStep(event);
Winson Chung0e490d922018-03-14 16:08:43 +0000290 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000291 break;
292 }
Winson Chung0e490d922018-03-14 16:08:43 +0000293
Matthew Ng2ea93b72018-03-14 19:43:18 +0000294 // Do not handle quick scrub/switch if disabled or hit target is not home button
295 if (!homePressed || !mNavigationBarView.isQuickScrubEnabled()) {
296 break;
297 }
298
299 if (!mDragPositive) {
300 offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width();
301 }
302
303 // Control the button movement
304 if (!mDraggingActive && exceededTouchSlop) {
305 boolean allowDrag = !mDragPositive
306 ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown;
307 if (allowDrag) {
308 mDownOffset = offset;
309 homeButton.abortCurrentGesture();
310 mDraggingActive = true;
Winson Chung0e490d922018-03-14 16:08:43 +0000311 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000312 }
313 if (mDraggingActive && (mDragPositive && offset >= 0
314 || !mDragPositive && offset <= 0)) {
315 float scrubFraction = Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1);
316 mTranslation = !mDragPositive
317 ? Utilities.clamp(offset - mDownOffset, -trackSize, 0)
318 : Utilities.clamp(offset - mDownOffset, 0, trackSize);
319 if (mQuickScrubActive) {
320 try {
321 mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction);
322 if (DEBUG_OVERVIEW_PROXY) {
323 Log.d(TAG_OPS, "Quick Scrub Progress:" + scrubFraction);
Winson Chung0e490d922018-03-14 16:08:43 +0000324 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000325 } catch (RemoteException e) {
326 Log.e(TAG, "Failed to send progress of quick scrub.", e);
Winson Chung0e490d922018-03-14 16:08:43 +0000327 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000328 } else {
329 mTranslation /= SWITCH_STICKINESS;
330 }
331 if (mIsVertical) {
332 mHomeButtonView.setTranslationY(mTranslation);
333 } else {
334 mHomeButtonView.setTranslationX(mTranslation);
Matthew Nga8f24262017-12-19 11:54:24 -0800335 }
336 }
337 break;
338 }
339 case MotionEvent.ACTION_CANCEL:
340 case MotionEvent.ACTION_UP:
Winson Chungd10ca302018-02-14 10:13:41 -0800341 endQuickScrub(true /* animate */);
Matthew Nga8f24262017-12-19 11:54:24 -0800342 break;
343 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000344
345 // Proxy motion events to launcher if not handled by quick scrub/switch
346 boolean handled = mDraggingActive || mQuickScrubActive;
347 if (!handled && mAllowGestureDetection) {
348 proxyMotionEvents(event);
349 }
350 return handled || mQuickStepStarted;
Matthew Nga8f24262017-12-19 11:54:24 -0800351 }
352
353 @Override
354 public void onDraw(Canvas canvas) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000355 if (mNavigationBarView.isQuickScrubEnabled()) {
356 return;
357 }
Matthew Ng7090a802018-01-19 13:36:22 -0800358 int color = (int) mTrackColorEvaluator.evaluate(mDarkIntensity, mLightTrackColor,
359 mDarkTrackColor);
360 mTrackPaint.setColor(color);
361 mTrackPaint.setAlpha((int) (mTrackPaint.getAlpha() * mTrackAlpha));
Matthew Nga8f24262017-12-19 11:54:24 -0800362 canvas.drawRect(mTrackRect, mTrackPaint);
363 }
364
365 @Override
366 public void onLayout(boolean changed, int left, int top, int right, int bottom) {
367 final int width = right - left;
368 final int height = bottom - top;
369 final int x1, x2, y1, y2;
370 if (mIsVertical) {
371 x1 = (width - mTrackThickness) / 2;
372 x2 = x1 + mTrackThickness;
373 y1 = mDragPositive ? height / 2 : mTrackPadding;
374 y2 = y1 + height / 2 - mTrackPadding;
375 } else {
376 y1 = (height - mTrackThickness) / 2;
377 y2 = y1 + mTrackThickness;
378 x1 = mDragPositive ? width / 2 : mTrackPadding;
379 x2 = x1 + width / 2 - mTrackPadding;
380 }
381 mTrackRect.set(x1, y1, x2, y2);
Matthew Nga8f24262017-12-19 11:54:24 -0800382 }
383
384 @Override
385 public void onDarkIntensityChange(float intensity) {
Matthew Ng7090a802018-01-19 13:36:22 -0800386 mDarkIntensity = intensity;
387 mNavigationBarView.invalidate();
Matthew Nga8f24262017-12-19 11:54:24 -0800388 }
389
390 @Override
Matthew Nga8f24262017-12-19 11:54:24 -0800391 public void setBarState(boolean isVertical, boolean isRTL) {
Winson Chungd10ca302018-02-14 10:13:41 -0800392 final boolean changed = (mIsVertical != isVertical) || (mIsRTL != isRTL);
393 if (changed) {
394 // End quickscrub if the state changes mid-transition
395 endQuickScrub(false /* animate */);
396 }
Matthew Nga8f24262017-12-19 11:54:24 -0800397 mIsVertical = isVertical;
398 mIsRTL = isRTL;
399 try {
400 int navbarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition();
401 mDragPositive = navbarPos == NAV_BAR_LEFT || navbarPos == NAV_BAR_BOTTOM;
402 if (isRTL) {
403 mDragPositive = !mDragPositive;
404 }
405 } catch (RemoteException e) {
406 Slog.e(TAG, "Failed to get nav bar position.", e);
407 }
408 }
409
Matthew Ng2ea93b72018-03-14 19:43:18 +0000410 @Override
411 public void onNavigationButtonLongPress(View v) {
412 mAllowGestureDetection = false;
413 mHandler.removeCallbacksAndMessages(null);
414 }
415
416 private void startQuickStep(MotionEvent event) {
417 mQuickStepStarted = true;
418 event.transform(mTransformGlobalMatrix);
419 try {
420 mOverviewEventSender.getProxy().onQuickStep(event);
421 if (DEBUG_OVERVIEW_PROXY) {
422 Log.d(TAG_OPS, "Quick Step Start");
423 }
424 } catch (RemoteException e) {
425 Log.e(TAG, "Failed to send quick step started.", e);
426 } finally {
427 event.transform(mTransformLocalMatrix);
428 }
429 mOverviewEventSender.notifyQuickStepStarted();
430 mNavigationBarView.getHomeButton().abortCurrentGesture();
431 cancelQuickSwitch();
432 mHandler.removeCallbacksAndMessages(null);
433 }
434
Matthew Nga8f24262017-12-19 11:54:24 -0800435 private void startQuickScrub() {
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800436 if (!mQuickScrubActive && mDraggingActive) {
Matthew Nga8f24262017-12-19 11:54:24 -0800437 mQuickScrubActive = true;
Matthew Ng7090a802018-01-19 13:36:22 -0800438 mLightTrackColor = mContext.getColor(R.color.quick_step_track_background_light);
439 mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark);
440 mTrackAnimator.setFloatValues(0, 1);
Matthew Nga8f24262017-12-19 11:54:24 -0800441 mTrackAnimator.start();
442 try {
443 mOverviewEventSender.getProxy().onQuickScrubStart();
Matthew Ngbd824572018-01-17 16:25:56 -0800444 if (DEBUG_OVERVIEW_PROXY) {
445 Log.d(TAG_OPS, "Quick Scrub Start");
446 }
Matthew Nga8f24262017-12-19 11:54:24 -0800447 } catch (RemoteException e) {
448 Log.e(TAG, "Failed to send start of quick scrub.", e);
449 }
450 }
451 }
452
Winson Chungd10ca302018-02-14 10:13:41 -0800453 private void endQuickScrub(boolean animate) {
Matthew Nga8f24262017-12-19 11:54:24 -0800454 mHandler.removeCallbacks(mLongPressRunnable);
455 if (mDraggingActive || mQuickScrubActive) {
Matthew Nged166f92018-02-20 16:22:09 -0800456 animateEnd();
Matthew Nga8f24262017-12-19 11:54:24 -0800457 try {
458 mOverviewEventSender.getProxy().onQuickScrubEnd();
Matthew Ngbd824572018-01-17 16:25:56 -0800459 if (DEBUG_OVERVIEW_PROXY) {
460 Log.d(TAG_OPS, "Quick Scrub End");
461 }
Matthew Nga8f24262017-12-19 11:54:24 -0800462 } catch (RemoteException e) {
463 Log.e(TAG, "Failed to send end of quick scrub.", e);
464 }
Matthew Nged166f92018-02-20 16:22:09 -0800465 }
466 if (mHomeButtonView != null && !animate) {
467 mQuickScrubEndAnimator.end();
Matthew Nga8f24262017-12-19 11:54:24 -0800468 }
469 mDraggingActive = false;
470 }
471
Matthew Ng2ea93b72018-03-14 19:43:18 +0000472 private boolean proxyMotionEvents(MotionEvent event) {
473 final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy();
474 event.transform(mTransformGlobalMatrix);
475 try {
476 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
477 overviewProxy.onPreMotionEvent(mNavigationBarView.getDownHitTarget());
478 }
479 overviewProxy.onMotionEvent(event);
480 if (DEBUG_OVERVIEW_PROXY) {
481 Log.d(TAG_OPS, "Send MotionEvent: " + event.toString());
482 }
483 return true;
484 } catch (RemoteException e) {
485 Log.e(TAG, "Callback failed", e);
486 } finally {
487 event.transform(mTransformLocalMatrix);
Matthew Ngdb2734c2018-02-16 16:02:20 -0800488 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000489 return false;
Matthew Ngdb2734c2018-02-16 16:02:20 -0800490 }
491
Winson Chung49658842018-02-08 12:52:21 -0800492 public void cancelQuickSwitch() {
493 mAllowQuickSwitch = false;
494 mHandler.removeCallbacks(mLongPressRunnable);
495 }
496
Matthew Nged166f92018-02-20 16:22:09 -0800497 private void animateEnd() {
498 mButtonAnimator.setIntValues((int) mTranslation, 0);
499 mTrackAnimator.setFloatValues(mTrackAlpha, 0);
Matthew Ng55437a92018-02-23 15:02:07 -0800500 mQuickScrubEndAnimator.setCurrentPlayTime(0);
Matthew Nged166f92018-02-20 16:22:09 -0800501 mQuickScrubEndAnimator.start();
502 }
503
Matthew Nga8f24262017-12-19 11:54:24 -0800504 private int getDimensionPixelSize(Context context, @DimenRes int resId) {
505 return context.getResources().getDimensionPixelSize(resId);
506 }
507}