blob: 15790d4f827755915844767dc033aadd8cf9eab1 [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;
25
Matthew Nga8f24262017-12-19 11:54:24 -080026import android.animation.Animator;
27import android.animation.AnimatorListenerAdapter;
28import android.animation.AnimatorSet;
Matthew Ng7090a802018-01-19 13:36:22 -080029import android.animation.ArgbEvaluator;
Matthew Nga8f24262017-12-19 11:54:24 -080030import android.animation.ObjectAnimator;
Winson Chung661d5f92018-05-21 18:41:39 -070031import android.animation.PropertyValuesHolder;
Matthew Nga8f24262017-12-19 11:54:24 -080032import android.content.Context;
Winson Chung661d5f92018-05-21 18:41:39 -070033import android.content.res.Resources;
Matthew Nga8f24262017-12-19 11:54:24 -080034import android.graphics.Canvas;
Winson Chung4baf1242018-05-24 14:21:57 -070035import android.graphics.Color;
Matthew Ng2ea93b72018-03-14 19:43:18 +000036import android.graphics.Matrix;
Matthew Nga8f24262017-12-19 11:54:24 -080037import android.graphics.Rect;
Winson Chung4baf1242018-05-24 14:21:57 -070038import android.graphics.drawable.Drawable;
Matthew Nga8f24262017-12-19 11:54:24 -080039import android.os.Handler;
40import android.os.RemoteException;
Winson Chung661d5f92018-05-21 18:41:39 -070041import android.util.FloatProperty;
Matthew Nga8f24262017-12-19 11:54:24 -080042import android.util.Log;
43import android.util.Slog;
Matthew Nga8f24262017-12-19 11:54:24 -080044import android.view.MotionEvent;
45import android.view.View;
Matthew Nga8f24262017-12-19 11:54:24 -080046import android.view.WindowManagerGlobal;
47import android.view.animation.DecelerateInterpolator;
48import android.view.animation.Interpolator;
Aurimas Liutikasfd52c142018-04-17 09:50:46 -070049import androidx.annotation.DimenRes;
Matthew Nga8f24262017-12-19 11:54:24 -080050import com.android.systemui.Dependency;
51import com.android.systemui.OverviewProxyService;
52import com.android.systemui.R;
53import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper;
54import com.android.systemui.shared.recents.IOverviewProxy;
55import com.android.systemui.shared.recents.utilities.Utilities;
Matthew Ngf29ad752018-04-26 11:24:05 -070056import com.android.systemui.shared.system.NavigationBarCompat;
Winson Chung4baf1242018-05-24 14:21:57 -070057import com.android.internal.graphics.ColorUtils;
Matthew Nga8f24262017-12-19 11:54:24 -080058
Matthew Nga8f24262017-12-19 11:54:24 -080059/**
Matthew Ngfba39692018-03-13 18:08:34 -070060 * Class to detect gestures on the navigation bar and implement quick scrub.
Matthew Nga8f24262017-12-19 11:54:24 -080061 */
Matthew Ngfba39692018-03-13 18:08:34 -070062public class QuickStepController implements GestureHelper {
Matthew Nga8f24262017-12-19 11:54:24 -080063
Matthew Ng2ea93b72018-03-14 19:43:18 +000064 private static final String TAG = "QuickStepController";
Winson Chung661d5f92018-05-21 18:41:39 -070065 private static final int ANIM_IN_DURATION_MS = 150;
Winson Chung4baf1242018-05-24 14:21:57 -070066 private static final int ANIM_OUT_DURATION_MS = 134;
67 private static final float TRACK_SCALE = 0.95f;
Matthew Nga8f24262017-12-19 11:54:24 -080068
69 private NavigationBarView mNavigationBarView;
Matthew Nga8f24262017-12-19 11:54:24 -080070
Matthew Nga8f24262017-12-19 11:54:24 -080071 private boolean mQuickScrubActive;
Matthew Ng2ea93b72018-03-14 19:43:18 +000072 private boolean mAllowGestureDetection;
73 private boolean mQuickStepStarted;
Matthew Nga8f24262017-12-19 11:54:24 -080074 private int mTouchDownX;
75 private int mTouchDownY;
76 private boolean mDragPositive;
77 private boolean mIsVertical;
78 private boolean mIsRTL;
Matthew Ng7090a802018-01-19 13:36:22 -080079 private float mTrackAlpha;
Winson Chung4baf1242018-05-24 14:21:57 -070080 private float mTrackScale = TRACK_SCALE;
Matthew Ng7090a802018-01-19 13:36:22 -080081 private int mLightTrackColor;
82 private int mDarkTrackColor;
83 private float mDarkIntensity;
Winson Chung661d5f92018-05-21 18:41:39 -070084 private AnimatorSet mTrackAnimator;
85 private ButtonDispatcher mHitTarget;
86 private View mCurrentNavigationBarView;
Matthew Ng20136e62018-05-30 12:20:31 -070087 private boolean mIsInScreenPinning;
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) {
Winson Chungd95a2252018-04-04 17:02:29 +0000188 if (mOverviewEventSender.getProxy() == null || (!mNavigationBarView.isQuickScrubEnabled()
189 && !mNavigationBarView.isQuickStepSwipeUpEnabled())) {
Matthew Ng22cf5142018-03-14 12:26:14 -0700190 return false;
191 }
192 mNavigationBarView.requestUnbufferedDispatch(event);
193
Matthew Ng9a223632018-03-30 16:47:22 -0700194 int action = event.getActionMasked();
195 switch (action) {
Matthew Nga8f24262017-12-19 11:54:24 -0800196 case MotionEvent.ACTION_DOWN: {
197 int x = (int) event.getX();
198 int y = (int) event.getY();
Matthew Ng20136e62018-05-30 12:20:31 -0700199 mIsInScreenPinning = mNavigationBarView.inScreenPinning();
Winson Chung661d5f92018-05-21 18:41:39 -0700200
Winson Chung0be8f082018-02-15 15:52:49 -0800201 // End any existing quickscrub animations before starting the new transition
Winson Chung661d5f92018-05-21 18:41:39 -0700202 if (mTrackAnimator != null) {
203 mTrackAnimator.end();
204 mTrackAnimator = null;
Winson Chung0be8f082018-02-15 15:52:49 -0800205 }
Winson Chung661d5f92018-05-21 18:41:39 -0700206
207 mCurrentNavigationBarView = mNavigationBarView.getCurrentView();
208 mHitTarget = mNavigationBarView.getButtonAtPosition(x, y);
209 if (mHitTarget != null) {
210 // Pre-emptively delay the touch feedback for the button that we just touched
211 mHitTarget.setDelayTouchFeedback(true);
212 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000213 mTouchDownX = x;
214 mTouchDownY = y;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000215 mTransformGlobalMatrix.set(Matrix.IDENTITY_MATRIX);
216 mTransformLocalMatrix.set(Matrix.IDENTITY_MATRIX);
217 mNavigationBarView.transformMatrixToGlobal(mTransformGlobalMatrix);
218 mNavigationBarView.transformMatrixToLocal(mTransformLocalMatrix);
219 mQuickStepStarted = false;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000220 mAllowGestureDetection = true;
Matthew Nga8f24262017-12-19 11:54:24 -0800221 break;
222 }
223 case MotionEvent.ACTION_MOVE: {
Winson Chung661d5f92018-05-21 18:41:39 -0700224 if (mQuickStepStarted || !mAllowGestureDetection){
Matthew Ng2ea93b72018-03-14 19:43:18 +0000225 break;
226 }
227 int x = (int) event.getX();
228 int y = (int) event.getY();
229 int xDiff = Math.abs(x - mTouchDownX);
230 int yDiff = Math.abs(y - mTouchDownY);
Matthew Ng9a223632018-03-30 16:47:22 -0700231
Winson Chung661d5f92018-05-21 18:41:39 -0700232 boolean exceededScrubTouchSlop, exceededSwipeUpTouchSlop;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000233 int pos, touchDown, offset, trackSize;
Matthew Nge0903c92018-01-17 15:32:41 -0800234
Matthew Ng2ea93b72018-03-14 19:43:18 +0000235 if (mIsVertical) {
Matthew Ngf29ad752018-04-26 11:24:05 -0700236 exceededScrubTouchSlop =
237 yDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && yDiff > xDiff;
238 exceededSwipeUpTouchSlop =
239 xDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && xDiff > yDiff;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000240 pos = y;
241 touchDown = mTouchDownY;
242 offset = pos - mTrackRect.top;
243 trackSize = mTrackRect.height();
244 } else {
Matthew Ngf29ad752018-04-26 11:24:05 -0700245 exceededScrubTouchSlop =
246 xDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && xDiff > yDiff;
247 exceededSwipeUpTouchSlop =
248 yDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && yDiff > xDiff;
Matthew Ng2ea93b72018-03-14 19:43:18 +0000249 pos = x;
250 touchDown = mTouchDownX;
251 offset = pos - mTrackRect.left;
252 trackSize = mTrackRect.width();
253 }
254 // Decide to start quickstep if dragging away from the navigation bar, otherwise in
255 // the parallel direction, decide to start quickscrub. Only one may run.
Matthew Ng9a223632018-03-30 16:47:22 -0700256 if (!mQuickScrubActive && exceededSwipeUpTouchSlop) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000257 if (mNavigationBarView.isQuickStepSwipeUpEnabled()) {
258 startQuickStep(event);
Winson Chung0e490d922018-03-14 16:08:43 +0000259 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000260 break;
261 }
Winson Chung0e490d922018-03-14 16:08:43 +0000262
Winson Chung661d5f92018-05-21 18:41:39 -0700263 // Do not handle quick scrub if disabled
264 if (!mNavigationBarView.isQuickScrubEnabled()) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000265 break;
266 }
267
268 if (!mDragPositive) {
269 offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width();
270 }
271
Matthew Ng9a223632018-03-30 16:47:22 -0700272 final boolean allowDrag = !mDragPositive
273 ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown;
Winson Chung661d5f92018-05-21 18:41:39 -0700274 float scrubFraction = Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1);
Matthew Ng9a223632018-03-30 16:47:22 -0700275 if (allowDrag) {
Matthew Ng9a223632018-03-30 16:47:22 -0700276 // Passing the drag slop then touch slop will start quick step
277 if (!mQuickScrubActive && exceededScrubTouchSlop) {
Matthew Ngfba39692018-03-13 18:08:34 -0700278 startQuickScrub();
Winson Chung0e490d922018-03-14 16:08:43 +0000279 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000280 }
Matthew Ng9a223632018-03-30 16:47:22 -0700281
Winson Chung661d5f92018-05-21 18:41:39 -0700282 if (mQuickScrubActive && (mDragPositive && offset >= 0
Matthew Ng2ea93b72018-03-14 19:43:18 +0000283 || !mDragPositive && offset <= 0)) {
Winson Chung661d5f92018-05-21 18:41:39 -0700284 try {
285 mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction);
286 if (DEBUG_OVERVIEW_PROXY) {
287 Log.d(TAG_OPS, "Quick Scrub Progress:" + scrubFraction);
Winson Chung0e490d922018-03-14 16:08:43 +0000288 }
Winson Chung661d5f92018-05-21 18:41:39 -0700289 } catch (RemoteException e) {
290 Log.e(TAG, "Failed to send progress of quick scrub.", e);
Matthew Nga8f24262017-12-19 11:54:24 -0800291 }
292 }
293 break;
294 }
295 case MotionEvent.ACTION_CANCEL:
296 case MotionEvent.ACTION_UP:
Winson Chungd10ca302018-02-14 10:13:41 -0800297 endQuickScrub(true /* animate */);
Matthew Nga8f24262017-12-19 11:54:24 -0800298 break;
299 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000300
Matthew Ngfba39692018-03-13 18:08:34 -0700301 // Proxy motion events to launcher if not handled by quick scrub
Matthew Ng9a223632018-03-30 16:47:22 -0700302 // Proxy motion events up/cancel that would be sent after long press on any nav button
Matthew Ng20136e62018-05-30 12:20:31 -0700303 if (!mQuickScrubActive && !mIsInScreenPinning && (mAllowGestureDetection
304 || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP)) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000305 proxyMotionEvents(event);
306 }
Matthew Ngfba39692018-03-13 18:08:34 -0700307 return mQuickScrubActive || mQuickStepStarted;
Matthew Nga8f24262017-12-19 11:54:24 -0800308 }
309
310 @Override
311 public void onDraw(Canvas canvas) {
Matthew Ngf781bbd2018-03-21 14:58:55 -0700312 if (!mNavigationBarView.isQuickScrubEnabled()) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000313 return;
314 }
Matthew Ng7090a802018-01-19 13:36:22 -0800315 int color = (int) mTrackColorEvaluator.evaluate(mDarkIntensity, mLightTrackColor,
316 mDarkTrackColor);
Winson Chung4baf1242018-05-24 14:21:57 -0700317 int colorAlpha = ColorUtils.setAlphaComponent(color,
318 (int) (Color.alpha(color) * mTrackAlpha));
319 mTrackDrawable.setTint(colorAlpha);
320
321 // Scale the track, but apply the inverse scale from the nav bar
322 canvas.save();
323 canvas.scale(mTrackScale / mNavigationBarView.getScaleX(),
324 1f / mNavigationBarView.getScaleY(),
325 mTrackRect.centerX(), mTrackRect.centerY());
326 mTrackDrawable.draw(canvas);
327 canvas.restore();
Matthew Nga8f24262017-12-19 11:54:24 -0800328 }
329
330 @Override
331 public void onLayout(boolean changed, int left, int top, int right, int bottom) {
Winson Chung661d5f92018-05-21 18:41:39 -0700332 final int paddingLeft = mNavigationBarView.getPaddingLeft();
333 final int paddingTop = mNavigationBarView.getPaddingTop();
334 final int paddingRight = mNavigationBarView.getPaddingRight();
335 final int paddingBottom = mNavigationBarView.getPaddingBottom();
336 final int width = (right - left) - paddingRight - paddingLeft;
337 final int height = (bottom - top) - paddingBottom - paddingTop;
Matthew Nga8f24262017-12-19 11:54:24 -0800338 final int x1, x2, y1, y2;
339 if (mIsVertical) {
Winson Chung661d5f92018-05-21 18:41:39 -0700340 x1 = (width - mTrackThickness) / 2 + paddingLeft;
Matthew Nga8f24262017-12-19 11:54:24 -0800341 x2 = x1 + mTrackThickness;
Winson Chung661d5f92018-05-21 18:41:39 -0700342 y1 = paddingTop + mTrackEndPadding;
343 y2 = y1 + height - 2 * mTrackEndPadding;
Matthew Nga8f24262017-12-19 11:54:24 -0800344 } else {
Winson Chung661d5f92018-05-21 18:41:39 -0700345 y1 = (height - mTrackThickness) / 2 + paddingTop;
Matthew Nga8f24262017-12-19 11:54:24 -0800346 y2 = y1 + mTrackThickness;
Winson Chung661d5f92018-05-21 18:41:39 -0700347 x1 = mNavigationBarView.getPaddingStart() + mTrackEndPadding;
348 x2 = x1 + width - 2 * mTrackEndPadding;
Matthew Nga8f24262017-12-19 11:54:24 -0800349 }
350 mTrackRect.set(x1, y1, x2, y2);
Winson Chung4baf1242018-05-24 14:21:57 -0700351 mTrackDrawable.setBounds(mTrackRect);
Matthew Nga8f24262017-12-19 11:54:24 -0800352 }
353
354 @Override
355 public void onDarkIntensityChange(float intensity) {
Matthew Ng7090a802018-01-19 13:36:22 -0800356 mDarkIntensity = intensity;
357 mNavigationBarView.invalidate();
Matthew Nga8f24262017-12-19 11:54:24 -0800358 }
359
360 @Override
Matthew Nga8f24262017-12-19 11:54:24 -0800361 public void setBarState(boolean isVertical, boolean isRTL) {
Winson Chungd10ca302018-02-14 10:13:41 -0800362 final boolean changed = (mIsVertical != isVertical) || (mIsRTL != isRTL);
363 if (changed) {
364 // End quickscrub if the state changes mid-transition
365 endQuickScrub(false /* animate */);
366 }
Matthew Nga8f24262017-12-19 11:54:24 -0800367 mIsVertical = isVertical;
368 mIsRTL = isRTL;
369 try {
370 int navbarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition();
371 mDragPositive = navbarPos == NAV_BAR_LEFT || navbarPos == NAV_BAR_BOTTOM;
372 if (isRTL) {
373 mDragPositive = !mDragPositive;
374 }
375 } catch (RemoteException e) {
376 Slog.e(TAG, "Failed to get nav bar position.", e);
377 }
378 }
379
Matthew Ng2ea93b72018-03-14 19:43:18 +0000380 @Override
381 public void onNavigationButtonLongPress(View v) {
382 mAllowGestureDetection = false;
383 mHandler.removeCallbacksAndMessages(null);
384 }
385
386 private void startQuickStep(MotionEvent event) {
Matthew Ng20136e62018-05-30 12:20:31 -0700387 if (mIsInScreenPinning) {
388 mNavigationBarView.showPinningEscapeToast();
389 mAllowGestureDetection = false;
390 return;
391 }
392
Matthew Ng2ea93b72018-03-14 19:43:18 +0000393 mQuickStepStarted = true;
394 event.transform(mTransformGlobalMatrix);
395 try {
396 mOverviewEventSender.getProxy().onQuickStep(event);
397 if (DEBUG_OVERVIEW_PROXY) {
398 Log.d(TAG_OPS, "Quick Step Start");
399 }
400 } catch (RemoteException e) {
401 Log.e(TAG, "Failed to send quick step started.", e);
402 } finally {
403 event.transform(mTransformLocalMatrix);
404 }
405 mOverviewEventSender.notifyQuickStepStarted();
Matthew Ng2ea93b72018-03-14 19:43:18 +0000406 mHandler.removeCallbacksAndMessages(null);
Matthew Ng9a223632018-03-30 16:47:22 -0700407
Winson Chung661d5f92018-05-21 18:41:39 -0700408 if (mHitTarget != null) {
409 mHitTarget.abortCurrentGesture();
410 }
411
412 if (mQuickScrubActive) {
Matthew Ng9a223632018-03-30 16:47:22 -0700413 animateEnd();
414 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000415 }
416
Matthew Nga8f24262017-12-19 11:54:24 -0800417 private void startQuickScrub() {
Matthew Ng20136e62018-05-30 12:20:31 -0700418 if (mIsInScreenPinning) {
419 mNavigationBarView.showPinningEscapeToast();
420 mAllowGestureDetection = false;
421 return;
422 }
423
Winson Chung661d5f92018-05-21 18:41:39 -0700424 if (!mQuickScrubActive) {
Matthew Nga8f24262017-12-19 11:54:24 -0800425 mQuickScrubActive = true;
Matthew Ng7090a802018-01-19 13:36:22 -0800426 mLightTrackColor = mContext.getColor(R.color.quick_step_track_background_light);
427 mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark);
Matthew Ng6607c3d2018-04-26 15:23:27 -0700428
Winson Chung4baf1242018-05-24 14:21:57 -0700429 ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this,
430 PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 1f),
431 PropertyValuesHolder.ofFloat(mTrackScaleProperty, 1f));
Winson Chung661d5f92018-05-21 18:41:39 -0700432 trackAnimator.setInterpolator(ALPHA_IN);
433 trackAnimator.setDuration(ANIM_IN_DURATION_MS);
434 ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 0f);
435 navBarAnimator.setInterpolator(ALPHA_OUT);
436 navBarAnimator.setDuration(ANIM_OUT_DURATION_MS);
437 mTrackAnimator = new AnimatorSet();
438 mTrackAnimator.playTogether(trackAnimator, navBarAnimator);
439 mTrackAnimator.start();
Matthew Ng6607c3d2018-04-26 15:23:27 -0700440
Matthew Nga8f24262017-12-19 11:54:24 -0800441 try {
442 mOverviewEventSender.getProxy().onQuickScrubStart();
Matthew Ngbd824572018-01-17 16:25:56 -0800443 if (DEBUG_OVERVIEW_PROXY) {
444 Log.d(TAG_OPS, "Quick Scrub Start");
445 }
Matthew Nga8f24262017-12-19 11:54:24 -0800446 } catch (RemoteException e) {
447 Log.e(TAG, "Failed to send start of quick scrub.", e);
448 }
Tracy Zhou27599052018-04-16 15:47:29 -0700449 mOverviewEventSender.notifyQuickScrubStarted();
Winson Chung661d5f92018-05-21 18:41:39 -0700450
451 if (mHitTarget != null) {
452 mHitTarget.abortCurrentGesture();
453 }
Matthew Nga8f24262017-12-19 11:54:24 -0800454 }
455 }
456
Winson Chungd10ca302018-02-14 10:13:41 -0800457 private void endQuickScrub(boolean animate) {
Winson Chung661d5f92018-05-21 18:41:39 -0700458 if (mQuickScrubActive) {
Matthew Nged166f92018-02-20 16:22:09 -0800459 animateEnd();
Winson Chung661d5f92018-05-21 18:41:39 -0700460 try {
461 mOverviewEventSender.getProxy().onQuickScrubEnd();
462 if (DEBUG_OVERVIEW_PROXY) {
463 Log.d(TAG_OPS, "Quick Scrub End");
Matthew Ngbd824572018-01-17 16:25:56 -0800464 }
Winson Chung661d5f92018-05-21 18:41:39 -0700465 } catch (RemoteException e) {
466 Log.e(TAG, "Failed to send end of quick scrub.", e);
Matthew Nga8f24262017-12-19 11:54:24 -0800467 }
Matthew Nged166f92018-02-20 16:22:09 -0800468 }
Winson Chung661d5f92018-05-21 18:41:39 -0700469 if (!animate) {
470 if (mTrackAnimator != null) {
471 mTrackAnimator.end();
472 mTrackAnimator = null;
473 }
Matthew Nga8f24262017-12-19 11:54:24 -0800474 }
Matthew Nga8f24262017-12-19 11:54:24 -0800475 }
476
Winson Chung661d5f92018-05-21 18:41:39 -0700477 private void animateEnd() {
478 if (mTrackAnimator != null) {
479 mTrackAnimator.cancel();
480 }
481
Winson Chung4baf1242018-05-24 14:21:57 -0700482 ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this,
483 PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 0f),
484 PropertyValuesHolder.ofFloat(mTrackScaleProperty, TRACK_SCALE));
Winson Chung661d5f92018-05-21 18:41:39 -0700485 trackAnimator.setInterpolator(ALPHA_OUT);
486 trackAnimator.setDuration(ANIM_OUT_DURATION_MS);
487 ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 1f);
488 navBarAnimator.setInterpolator(ALPHA_IN);
489 navBarAnimator.setDuration(ANIM_IN_DURATION_MS);
490 mTrackAnimator = new AnimatorSet();
491 mTrackAnimator.playTogether(trackAnimator, navBarAnimator);
492 mTrackAnimator.addListener(mQuickScrubEndListener);
493 mTrackAnimator.start();
494 }
495
496 private void resetQuickScrub() {
497 mQuickScrubActive = false;
498 mAllowGestureDetection = false;
499 mCurrentNavigationBarView = null;
500 }
501
Matthew Ng2ea93b72018-03-14 19:43:18 +0000502 private boolean proxyMotionEvents(MotionEvent event) {
503 final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy();
504 event.transform(mTransformGlobalMatrix);
505 try {
506 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
507 overviewProxy.onPreMotionEvent(mNavigationBarView.getDownHitTarget());
508 }
509 overviewProxy.onMotionEvent(event);
510 if (DEBUG_OVERVIEW_PROXY) {
511 Log.d(TAG_OPS, "Send MotionEvent: " + event.toString());
512 }
513 return true;
514 } catch (RemoteException e) {
515 Log.e(TAG, "Callback failed", e);
516 } finally {
517 event.transform(mTransformLocalMatrix);
Matthew Ngdb2734c2018-02-16 16:02:20 -0800518 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000519 return false;
Matthew Ngdb2734c2018-02-16 16:02:20 -0800520 }
Matthew Nga8f24262017-12-19 11:54:24 -0800521}