blob: 5194bea2fd870c441711e79851f5a3612ac37adb [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
Winson Chung661d5f92018-05-21 18:41:39 -070019import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM;
20import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT;
21import static com.android.systemui.Interpolators.ALPHA_IN;
22import static com.android.systemui.Interpolators.ALPHA_OUT;
23import static com.android.systemui.OverviewProxyService.DEBUG_OVERVIEW_PROXY;
24import static com.android.systemui.OverviewProxyService.TAG_OPS;
Matthew Ng472d3e42018-06-14 15:16:55 -070025import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_DEAD_ZONE;
Winson Chung661d5f92018-05-21 18:41:39 -070026
Matthew Nga8f24262017-12-19 11:54:24 -080027import android.animation.Animator;
28import android.animation.AnimatorListenerAdapter;
29import android.animation.AnimatorSet;
Matthew Ng7090a802018-01-19 13:36:22 -080030import android.animation.ArgbEvaluator;
Matthew Nga8f24262017-12-19 11:54:24 -080031import android.animation.ObjectAnimator;
Winson Chung661d5f92018-05-21 18:41:39 -070032import android.animation.PropertyValuesHolder;
Matthew Nga8f24262017-12-19 11:54:24 -080033import android.content.Context;
Winson Chung661d5f92018-05-21 18:41:39 -070034import android.content.res.Resources;
Matthew Nga8f24262017-12-19 11:54:24 -080035import android.graphics.Canvas;
Winson Chung4baf1242018-05-24 14:21:57 -070036import android.graphics.Color;
Matthew Ng2ea93b72018-03-14 19:43:18 +000037import android.graphics.Matrix;
Matthew Nga8f24262017-12-19 11:54:24 -080038import android.graphics.Rect;
Winson Chung4baf1242018-05-24 14:21:57 -070039import android.graphics.drawable.Drawable;
Matthew Nga8f24262017-12-19 11:54:24 -080040import android.os.Handler;
41import android.os.RemoteException;
Winson Chung661d5f92018-05-21 18:41:39 -070042import android.util.FloatProperty;
Matthew Nga8f24262017-12-19 11:54:24 -080043import android.util.Log;
44import android.util.Slog;
Matthew Nga8f24262017-12-19 11:54:24 -080045import android.view.MotionEvent;
46import android.view.View;
Matthew Nga8f24262017-12-19 11:54:24 -080047import android.view.WindowManagerGlobal;
48import android.view.animation.DecelerateInterpolator;
49import android.view.animation.Interpolator;
50import android.support.annotation.DimenRes;
51import com.android.systemui.Dependency;
52import com.android.systemui.OverviewProxyService;
53import com.android.systemui.R;
54import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper;
55import com.android.systemui.shared.recents.IOverviewProxy;
56import com.android.systemui.shared.recents.utilities.Utilities;
Matthew Ngf29ad752018-04-26 11:24:05 -070057import com.android.systemui.shared.system.NavigationBarCompat;
Winson Chung4baf1242018-05-24 14:21:57 -070058import com.android.internal.graphics.ColorUtils;
Matthew Nga8f24262017-12-19 11:54:24 -080059
Matthew Nga8f24262017-12-19 11:54:24 -080060/**
Matthew Ngfba39692018-03-13 18:08:34 -070061 * Class to detect gestures on the navigation bar and implement quick scrub.
Matthew Nga8f24262017-12-19 11:54:24 -080062 */
Matthew Ngfba39692018-03-13 18:08:34 -070063public class QuickStepController implements GestureHelper {
Matthew Nga8f24262017-12-19 11:54:24 -080064
Matthew Ng2ea93b72018-03-14 19:43:18 +000065 private static final String TAG = "QuickStepController";
Winson Chung661d5f92018-05-21 18:41:39 -070066 private static final int ANIM_IN_DURATION_MS = 150;
Winson Chung4baf1242018-05-24 14:21:57 -070067 private static final int ANIM_OUT_DURATION_MS = 134;
68 private static final float TRACK_SCALE = 0.95f;
Matthew Nga8f24262017-12-19 11:54:24 -080069
70 private NavigationBarView mNavigationBarView;
Matthew Nga8f24262017-12-19 11:54:24 -080071
Matthew Nga8f24262017-12-19 11:54:24 -080072 private boolean mQuickScrubActive;
Matthew Ng2ea93b72018-03-14 19:43:18 +000073 private boolean mAllowGestureDetection;
74 private boolean mQuickStepStarted;
Matthew Nga8f24262017-12-19 11:54:24 -080075 private int mTouchDownX;
76 private int mTouchDownY;
77 private boolean mDragPositive;
78 private boolean mIsVertical;
79 private boolean mIsRTL;
Matthew Ng7090a802018-01-19 13:36:22 -080080 private float mTrackAlpha;
Winson Chung4baf1242018-05-24 14:21:57 -070081 private float mTrackScale = TRACK_SCALE;
Matthew Ng7090a802018-01-19 13:36:22 -080082 private int mLightTrackColor;
83 private int mDarkTrackColor;
84 private float mDarkIntensity;
Winson Chung661d5f92018-05-21 18:41:39 -070085 private AnimatorSet mTrackAnimator;
86 private ButtonDispatcher mHitTarget;
87 private View mCurrentNavigationBarView;
Matthew Nga8f24262017-12-19 11:54:24 -080088
89 private final Handler mHandler = new Handler();
Matthew Nga8f24262017-12-19 11:54:24 -080090 private final Rect mTrackRect = new Rect();
Winson Chung4baf1242018-05-24 14:21:57 -070091 private final Drawable mTrackDrawable;
Matthew Nga8f24262017-12-19 11:54:24 -080092 private final OverviewProxyService mOverviewEventSender;
Matthew Nga8f24262017-12-19 11:54:24 -080093 private final int mTrackThickness;
Winson Chung661d5f92018-05-21 18:41:39 -070094 private final int mTrackEndPadding;
Matthew Nga8f24262017-12-19 11:54:24 -080095 private final Context mContext;
Matthew Ng2ea93b72018-03-14 19:43:18 +000096 private final Matrix mTransformGlobalMatrix = new Matrix();
97 private final Matrix mTransformLocalMatrix = new Matrix();
Matthew Ng7090a802018-01-19 13:36:22 -080098 private final ArgbEvaluator mTrackColorEvaluator = new ArgbEvaluator();
Matthew Nga8f24262017-12-19 11:54:24 -080099
Winson Chung661d5f92018-05-21 18:41:39 -0700100 private final FloatProperty<QuickStepController> mTrackAlphaProperty =
101 new FloatProperty<QuickStepController>("TrackAlpha") {
102 @Override
103 public void setValue(QuickStepController controller, float alpha) {
104 mTrackAlpha = alpha;
105 mNavigationBarView.invalidate();
106 }
107
108 @Override
109 public Float get(QuickStepController controller) {
110 return mTrackAlpha;
111 }
Matthew Nga8f24262017-12-19 11:54:24 -0800112 };
113
Winson Chung4baf1242018-05-24 14:21:57 -0700114 private final FloatProperty<QuickStepController> mTrackScaleProperty =
115 new FloatProperty<QuickStepController>("TrackScale") {
116 @Override
117 public void setValue(QuickStepController controller, float scale) {
118 mTrackScale = scale;
119 mNavigationBarView.invalidate();
120 }
121
122 @Override
123 public Float get(QuickStepController controller) {
124 return mTrackScale;
125 }
126 };
127
Winson Chung661d5f92018-05-21 18:41:39 -0700128 private final FloatProperty<QuickStepController> mNavBarAlphaProperty =
129 new FloatProperty<QuickStepController>("NavBarAlpha") {
130 @Override
131 public void setValue(QuickStepController controller, float alpha) {
132 if (mCurrentNavigationBarView != null) {
133 mCurrentNavigationBarView.setAlpha(alpha);
134 }
Matthew Nga8f24262017-12-19 11:54:24 -0800135 }
Winson Chung661d5f92018-05-21 18:41:39 -0700136
137 @Override
138 public Float get(QuickStepController controller) {
139 if (mCurrentNavigationBarView != null) {
140 return mCurrentNavigationBarView.getAlpha();
141 }
142 return 1f;
Matthew Nga8f24262017-12-19 11:54:24 -0800143 }
144 };
145
146 private AnimatorListenerAdapter mQuickScrubEndListener = new AnimatorListenerAdapter() {
147 @Override
148 public void onAnimationEnd(Animator animation) {
Winson Chung661d5f92018-05-21 18:41:39 -0700149 resetQuickScrub();
Matthew Nga8f24262017-12-19 11:54:24 -0800150 }
151 };
152
Matthew Ng2ea93b72018-03-14 19:43:18 +0000153 public QuickStepController(Context context) {
Winson Chung661d5f92018-05-21 18:41:39 -0700154 final Resources res = context.getResources();
Matthew Nga8f24262017-12-19 11:54:24 -0800155 mContext = context;
Matthew Nga8f24262017-12-19 11:54:24 -0800156 mOverviewEventSender = Dependency.get(OverviewProxyService.class);
Winson Chung661d5f92018-05-21 18:41:39 -0700157 mTrackThickness = res.getDimensionPixelSize(R.dimen.nav_quick_scrub_track_thickness);
158 mTrackEndPadding = res.getDimensionPixelSize(R.dimen.nav_quick_scrub_track_edge_padding);
Winson Chung4baf1242018-05-24 14:21:57 -0700159 mTrackDrawable = context.getDrawable(R.drawable.qs_scrubber_track).mutate();
Matthew Nga8f24262017-12-19 11:54:24 -0800160 }
161
162 public void setComponents(NavigationBarView navigationBarView) {
163 mNavigationBarView = navigationBarView;
164 }
165
Winson Chung4faf38a2018-02-06 08:53:37 -0800166 /**
Matthew Ngfba39692018-03-13 18:08:34 -0700167 * @return true if we want to intercept touch events for quick scrub and prevent proxying the
168 * event to the overview service.
Winson Chung4faf38a2018-02-06 08:53:37 -0800169 */
Matthew Nga8f24262017-12-19 11:54:24 -0800170 @Override
171 public boolean onInterceptTouchEvent(MotionEvent event) {
Winson Chungde2a1242018-02-07 15:59:43 -0800172 return handleTouchEvent(event);
173 }
174
175 /**
Matthew Ngfba39692018-03-13 18:08:34 -0700176 * @return true if we want to handle touch events for quick scrub or if down event (that will
177 * get consumed and ignored). No events will be proxied to the overview service.
Winson Chungde2a1242018-02-07 15:59:43 -0800178 */
179 @Override
180 public boolean onTouchEvent(MotionEvent event) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000181 // The same down event was just sent on intercept and therefore can be ignored here
182 final boolean ignoreProxyDownEvent = event.getAction() == MotionEvent.ACTION_DOWN
183 && mOverviewEventSender.getProxy() != null;
184 return ignoreProxyDownEvent || handleTouchEvent(event);
Winson Chungde2a1242018-02-07 15:59:43 -0800185 }
186
187 private boolean handleTouchEvent(MotionEvent event) {
Matthew Ng472d3e42018-06-14 15:16:55 -0700188 final boolean deadZoneConsumed =
189 mNavigationBarView.getDownHitTarget() == HIT_TARGET_DEAD_ZONE;
Winson Chungd95a2252018-04-04 17:02:29 +0000190 if (mOverviewEventSender.getProxy() == null || (!mNavigationBarView.isQuickScrubEnabled()
191 && !mNavigationBarView.isQuickStepSwipeUpEnabled())) {
Matthew Ng22cf5142018-03-14 12:26:14 -0700192 return false;
193 }
194 mNavigationBarView.requestUnbufferedDispatch(event);
195
Matthew Ng9a223632018-03-30 16:47:22 -0700196 int action = event.getActionMasked();
197 switch (action) {
Matthew Nga8f24262017-12-19 11:54:24 -0800198 case MotionEvent.ACTION_DOWN: {
199 int x = (int) event.getX();
200 int y = (int) event.getY();
Winson Chung661d5f92018-05-21 18:41:39 -0700201
Winson Chung0be8f082018-02-15 15:52:49 -0800202 // End any existing quickscrub animations before starting the new transition
Winson Chung661d5f92018-05-21 18:41:39 -0700203 if (mTrackAnimator != null) {
204 mTrackAnimator.end();
205 mTrackAnimator = null;
Winson Chung0be8f082018-02-15 15:52:49 -0800206 }
Winson Chung661d5f92018-05-21 18:41:39 -0700207
208 mCurrentNavigationBarView = mNavigationBarView.getCurrentView();
209 mHitTarget = mNavigationBarView.getButtonAtPosition(x, y);
210 if (mHitTarget != null) {
211 // Pre-emptively delay the touch feedback for the button that we just touched
212 mHitTarget.setDelayTouchFeedback(true);
213 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000214 mTouchDownX = x;
215 mTouchDownY = y;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000216 mTransformGlobalMatrix.set(Matrix.IDENTITY_MATRIX);
217 mTransformLocalMatrix.set(Matrix.IDENTITY_MATRIX);
218 mNavigationBarView.transformMatrixToGlobal(mTransformGlobalMatrix);
219 mNavigationBarView.transformMatrixToLocal(mTransformLocalMatrix);
220 mQuickStepStarted = false;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000221 mAllowGestureDetection = true;
Matthew Nga8f24262017-12-19 11:54:24 -0800222 break;
223 }
224 case MotionEvent.ACTION_MOVE: {
Winson Chung661d5f92018-05-21 18:41:39 -0700225 if (mQuickStepStarted || !mAllowGestureDetection){
Matthew Ng2ea93b72018-03-14 19:43:18 +0000226 break;
227 }
228 int x = (int) event.getX();
229 int y = (int) event.getY();
230 int xDiff = Math.abs(x - mTouchDownX);
231 int yDiff = Math.abs(y - mTouchDownY);
Matthew Ng9a223632018-03-30 16:47:22 -0700232
Winson Chung661d5f92018-05-21 18:41:39 -0700233 boolean exceededScrubTouchSlop, exceededSwipeUpTouchSlop;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000234 int pos, touchDown, offset, trackSize;
Matthew Nge0903c92018-01-17 15:32:41 -0800235
Matthew Ng2ea93b72018-03-14 19:43:18 +0000236 if (mIsVertical) {
Matthew Ngf29ad752018-04-26 11:24:05 -0700237 exceededScrubTouchSlop =
238 yDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && yDiff > xDiff;
239 exceededSwipeUpTouchSlop =
240 xDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && xDiff > yDiff;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000241 pos = y;
242 touchDown = mTouchDownY;
243 offset = pos - mTrackRect.top;
244 trackSize = mTrackRect.height();
245 } else {
Matthew Ngf29ad752018-04-26 11:24:05 -0700246 exceededScrubTouchSlop =
247 xDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && xDiff > yDiff;
248 exceededSwipeUpTouchSlop =
249 yDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && yDiff > xDiff;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000250 pos = x;
251 touchDown = mTouchDownX;
252 offset = pos - mTrackRect.left;
253 trackSize = mTrackRect.width();
254 }
255 // Decide to start quickstep if dragging away from the navigation bar, otherwise in
256 // the parallel direction, decide to start quickscrub. Only one may run.
Matthew Ng9a223632018-03-30 16:47:22 -0700257 if (!mQuickScrubActive && exceededSwipeUpTouchSlop) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000258 if (mNavigationBarView.isQuickStepSwipeUpEnabled()) {
259 startQuickStep(event);
Winson Chung0e490d922018-03-14 16:08:43 +0000260 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000261 break;
262 }
Winson Chung0e490d922018-03-14 16:08:43 +0000263
Winson Chung661d5f92018-05-21 18:41:39 -0700264 // Do not handle quick scrub if disabled
265 if (!mNavigationBarView.isQuickScrubEnabled()) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000266 break;
267 }
268
269 if (!mDragPositive) {
270 offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width();
271 }
272
Matthew Ng9a223632018-03-30 16:47:22 -0700273 final boolean allowDrag = !mDragPositive
274 ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown;
Winson Chung661d5f92018-05-21 18:41:39 -0700275 float scrubFraction = Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1);
Matthew Ng9a223632018-03-30 16:47:22 -0700276 if (allowDrag) {
Matthew Ng9a223632018-03-30 16:47:22 -0700277 // Passing the drag slop then touch slop will start quick step
278 if (!mQuickScrubActive && exceededScrubTouchSlop) {
Matthew Ngfba39692018-03-13 18:08:34 -0700279 startQuickScrub();
Winson Chung0e490d922018-03-14 16:08:43 +0000280 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000281 }
Matthew Ng9a223632018-03-30 16:47:22 -0700282
Winson Chung661d5f92018-05-21 18:41:39 -0700283 if (mQuickScrubActive && (mDragPositive && offset >= 0
Matthew Ng2ea93b72018-03-14 19:43:18 +0000284 || !mDragPositive && offset <= 0)) {
Winson Chung661d5f92018-05-21 18:41:39 -0700285 try {
286 mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction);
287 if (DEBUG_OVERVIEW_PROXY) {
288 Log.d(TAG_OPS, "Quick Scrub Progress:" + scrubFraction);
Winson Chung0e490d922018-03-14 16:08:43 +0000289 }
Winson Chung661d5f92018-05-21 18:41:39 -0700290 } catch (RemoteException e) {
291 Log.e(TAG, "Failed to send progress of quick scrub.", e);
Matthew Nga8f24262017-12-19 11:54:24 -0800292 }
293 }
294 break;
295 }
296 case MotionEvent.ACTION_CANCEL:
297 case MotionEvent.ACTION_UP:
Winson Chungd10ca302018-02-14 10:13:41 -0800298 endQuickScrub(true /* animate */);
Matthew Nga8f24262017-12-19 11:54:24 -0800299 break;
300 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000301
Matthew Ngfba39692018-03-13 18:08:34 -0700302 // Proxy motion events to launcher if not handled by quick scrub
Matthew Ng9a223632018-03-30 16:47:22 -0700303 // Proxy motion events up/cancel that would be sent after long press on any nav button
304 if (!mQuickScrubActive && (mAllowGestureDetection || action == MotionEvent.ACTION_CANCEL
305 || action == MotionEvent.ACTION_UP)) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000306 proxyMotionEvents(event);
307 }
Matthew Ng472d3e42018-06-14 15:16:55 -0700308 return mQuickScrubActive || mQuickStepStarted || deadZoneConsumed;
Matthew Nga8f24262017-12-19 11:54:24 -0800309 }
310
311 @Override
312 public void onDraw(Canvas canvas) {
Matthew Ngf781bbd2018-03-21 14:58:55 -0700313 if (!mNavigationBarView.isQuickScrubEnabled()) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000314 return;
315 }
Matthew Ng7090a802018-01-19 13:36:22 -0800316 int color = (int) mTrackColorEvaluator.evaluate(mDarkIntensity, mLightTrackColor,
317 mDarkTrackColor);
Winson Chung4baf1242018-05-24 14:21:57 -0700318 int colorAlpha = ColorUtils.setAlphaComponent(color,
319 (int) (Color.alpha(color) * mTrackAlpha));
320 mTrackDrawable.setTint(colorAlpha);
321
322 // Scale the track, but apply the inverse scale from the nav bar
323 canvas.save();
324 canvas.scale(mTrackScale / mNavigationBarView.getScaleX(),
325 1f / mNavigationBarView.getScaleY(),
326 mTrackRect.centerX(), mTrackRect.centerY());
327 mTrackDrawable.draw(canvas);
328 canvas.restore();
Matthew Nga8f24262017-12-19 11:54:24 -0800329 }
330
331 @Override
332 public void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson Chung661d5f92018-05-21 18:41:39 -0700333 final int paddingLeft = mNavigationBarView.getPaddingLeft();
334 final int paddingTop = mNavigationBarView.getPaddingTop();
335 final int paddingRight = mNavigationBarView.getPaddingRight();
336 final int paddingBottom = mNavigationBarView.getPaddingBottom();
337 final int width = (right - left) - paddingRight - paddingLeft;
338 final int height = (bottom - top) - paddingBottom - paddingTop;
Matthew Nga8f24262017-12-19 11:54:24 -0800339 final int x1, x2, y1, y2;
340 if (mIsVertical) {
Winson Chung661d5f92018-05-21 18:41:39 -0700341 x1 = (width - mTrackThickness) / 2 + paddingLeft;
Matthew Nga8f24262017-12-19 11:54:24 -0800342 x2 = x1 + mTrackThickness;
Winson Chung661d5f92018-05-21 18:41:39 -0700343 y1 = paddingTop + mTrackEndPadding;
344 y2 = y1 + height - 2 * mTrackEndPadding;
Matthew Nga8f24262017-12-19 11:54:24 -0800345 } else {
Winson Chung661d5f92018-05-21 18:41:39 -0700346 y1 = (height - mTrackThickness) / 2 + paddingTop;
Matthew Nga8f24262017-12-19 11:54:24 -0800347 y2 = y1 + mTrackThickness;
Winson Chung661d5f92018-05-21 18:41:39 -0700348 x1 = mNavigationBarView.getPaddingStart() + mTrackEndPadding;
349 x2 = x1 + width - 2 * mTrackEndPadding;
Matthew Nga8f24262017-12-19 11:54:24 -0800350 }
351 mTrackRect.set(x1, y1, x2, y2);
Winson Chung4baf1242018-05-24 14:21:57 -0700352 mTrackDrawable.setBounds(mTrackRect);
Matthew Nga8f24262017-12-19 11:54:24 -0800353 }
354
355 @Override
356 public void onDarkIntensityChange(float intensity) {
Matthew Ng7090a802018-01-19 13:36:22 -0800357 mDarkIntensity = intensity;
358 mNavigationBarView.invalidate();
Matthew Nga8f24262017-12-19 11:54:24 -0800359 }
360
361 @Override
Matthew Nga8f24262017-12-19 11:54:24 -0800362 public void setBarState(boolean isVertical, boolean isRTL) {
Winson Chungd10ca302018-02-14 10:13:41 -0800363 final boolean changed = (mIsVertical != isVertical) || (mIsRTL != isRTL);
364 if (changed) {
365 // End quickscrub if the state changes mid-transition
366 endQuickScrub(false /* animate */);
367 }
Matthew Nga8f24262017-12-19 11:54:24 -0800368 mIsVertical = isVertical;
369 mIsRTL = isRTL;
370 try {
371 int navbarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition();
372 mDragPositive = navbarPos == NAV_BAR_LEFT || navbarPos == NAV_BAR_BOTTOM;
373 if (isRTL) {
374 mDragPositive = !mDragPositive;
375 }
376 } catch (RemoteException e) {
377 Slog.e(TAG, "Failed to get nav bar position.", e);
378 }
379 }
380
Matthew Ng2ea93b72018-03-14 19:43:18 +0000381 @Override
382 public void onNavigationButtonLongPress(View v) {
383 mAllowGestureDetection = false;
384 mHandler.removeCallbacksAndMessages(null);
385 }
386
387 private void startQuickStep(MotionEvent event) {
388 mQuickStepStarted = true;
389 event.transform(mTransformGlobalMatrix);
390 try {
391 mOverviewEventSender.getProxy().onQuickStep(event);
392 if (DEBUG_OVERVIEW_PROXY) {
393 Log.d(TAG_OPS, "Quick Step Start");
394 }
395 } catch (RemoteException e) {
396 Log.e(TAG, "Failed to send quick step started.", e);
397 } finally {
398 event.transform(mTransformLocalMatrix);
399 }
400 mOverviewEventSender.notifyQuickStepStarted();
Matthew Ng2ea93b72018-03-14 19:43:18 +0000401 mHandler.removeCallbacksAndMessages(null);
Matthew Ng9a223632018-03-30 16:47:22 -0700402
Winson Chung661d5f92018-05-21 18:41:39 -0700403 if (mHitTarget != null) {
404 mHitTarget.abortCurrentGesture();
405 }
406
407 if (mQuickScrubActive) {
Matthew Ng9a223632018-03-30 16:47:22 -0700408 animateEnd();
409 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000410 }
411
Matthew Nga8f24262017-12-19 11:54:24 -0800412 private void startQuickScrub() {
Winson Chung661d5f92018-05-21 18:41:39 -0700413 if (!mQuickScrubActive) {
Matthew Nga8f24262017-12-19 11:54:24 -0800414 mQuickScrubActive = true;
Matthew Ng7090a802018-01-19 13:36:22 -0800415 mLightTrackColor = mContext.getColor(R.color.quick_step_track_background_light);
416 mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark);
Matthew Ng6607c3d2018-04-26 15:23:27 -0700417
Winson Chung4baf1242018-05-24 14:21:57 -0700418 ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this,
419 PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 1f),
420 PropertyValuesHolder.ofFloat(mTrackScaleProperty, 1f));
Winson Chung661d5f92018-05-21 18:41:39 -0700421 trackAnimator.setInterpolator(ALPHA_IN);
422 trackAnimator.setDuration(ANIM_IN_DURATION_MS);
423 ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 0f);
424 navBarAnimator.setInterpolator(ALPHA_OUT);
425 navBarAnimator.setDuration(ANIM_OUT_DURATION_MS);
426 mTrackAnimator = new AnimatorSet();
427 mTrackAnimator.playTogether(trackAnimator, navBarAnimator);
428 mTrackAnimator.start();
Matthew Ng6607c3d2018-04-26 15:23:27 -0700429
Matthew Ng472d3e42018-06-14 15:16:55 -0700430 // Disable slippery for quick scrub to not cancel outside the nav bar
431 mNavigationBarView.updateSlippery();
432
Matthew Nga8f24262017-12-19 11:54:24 -0800433 try {
434 mOverviewEventSender.getProxy().onQuickScrubStart();
Matthew Ngbd824572018-01-17 16:25:56 -0800435 if (DEBUG_OVERVIEW_PROXY) {
436 Log.d(TAG_OPS, "Quick Scrub Start");
437 }
Matthew Nga8f24262017-12-19 11:54:24 -0800438 } catch (RemoteException e) {
439 Log.e(TAG, "Failed to send start of quick scrub.", e);
440 }
Tracy Zhou27599052018-04-16 15:47:29 -0700441 mOverviewEventSender.notifyQuickScrubStarted();
Winson Chung661d5f92018-05-21 18:41:39 -0700442
443 if (mHitTarget != null) {
444 mHitTarget.abortCurrentGesture();
445 }
Matthew Nga8f24262017-12-19 11:54:24 -0800446 }
447 }
448
Winson Chungd10ca302018-02-14 10:13:41 -0800449 private void endQuickScrub(boolean animate) {
Winson Chung661d5f92018-05-21 18:41:39 -0700450 if (mQuickScrubActive) {
Matthew Nged166f92018-02-20 16:22:09 -0800451 animateEnd();
Winson Chung661d5f92018-05-21 18:41:39 -0700452 try {
453 mOverviewEventSender.getProxy().onQuickScrubEnd();
454 if (DEBUG_OVERVIEW_PROXY) {
455 Log.d(TAG_OPS, "Quick Scrub End");
Matthew Ngbd824572018-01-17 16:25:56 -0800456 }
Winson Chung661d5f92018-05-21 18:41:39 -0700457 } catch (RemoteException e) {
458 Log.e(TAG, "Failed to send end of quick scrub.", e);
Matthew Nga8f24262017-12-19 11:54:24 -0800459 }
Matthew Nged166f92018-02-20 16:22:09 -0800460 }
Winson Chung661d5f92018-05-21 18:41:39 -0700461 if (!animate) {
462 if (mTrackAnimator != null) {
463 mTrackAnimator.end();
464 mTrackAnimator = null;
465 }
Matthew Nga8f24262017-12-19 11:54:24 -0800466 }
Matthew Nga8f24262017-12-19 11:54:24 -0800467 }
468
Winson Chung661d5f92018-05-21 18:41:39 -0700469 private void animateEnd() {
470 if (mTrackAnimator != null) {
471 mTrackAnimator.cancel();
472 }
473
Winson Chung4baf1242018-05-24 14:21:57 -0700474 ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this,
475 PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 0f),
476 PropertyValuesHolder.ofFloat(mTrackScaleProperty, TRACK_SCALE));
Winson Chung661d5f92018-05-21 18:41:39 -0700477 trackAnimator.setInterpolator(ALPHA_OUT);
478 trackAnimator.setDuration(ANIM_OUT_DURATION_MS);
479 ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 1f);
480 navBarAnimator.setInterpolator(ALPHA_IN);
481 navBarAnimator.setDuration(ANIM_IN_DURATION_MS);
482 mTrackAnimator = new AnimatorSet();
483 mTrackAnimator.playTogether(trackAnimator, navBarAnimator);
484 mTrackAnimator.addListener(mQuickScrubEndListener);
485 mTrackAnimator.start();
486 }
487
488 private void resetQuickScrub() {
489 mQuickScrubActive = false;
490 mAllowGestureDetection = false;
491 mCurrentNavigationBarView = null;
492 }
493
Matthew Ng2ea93b72018-03-14 19:43:18 +0000494 private boolean proxyMotionEvents(MotionEvent event) {
495 final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy();
496 event.transform(mTransformGlobalMatrix);
497 try {
498 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
499 overviewProxy.onPreMotionEvent(mNavigationBarView.getDownHitTarget());
500 }
501 overviewProxy.onMotionEvent(event);
502 if (DEBUG_OVERVIEW_PROXY) {
503 Log.d(TAG_OPS, "Send MotionEvent: " + event.toString());
504 }
505 return true;
506 } catch (RemoteException e) {
507 Log.e(TAG, "Callback failed", e);
508 } finally {
509 event.transform(mTransformLocalMatrix);
Matthew Ngdb2734c2018-02-16 16:02:20 -0800510 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000511 return false;
Matthew Ngdb2734c2018-02-16 16:02:20 -0800512 }
Matthew Nga8f24262017-12-19 11:54:24 -0800513}