Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 19 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM; |
| 20 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT; |
| 21 | import static com.android.systemui.Interpolators.ALPHA_IN; |
| 22 | import static com.android.systemui.Interpolators.ALPHA_OUT; |
| 23 | import static com.android.systemui.OverviewProxyService.DEBUG_OVERVIEW_PROXY; |
| 24 | import static com.android.systemui.OverviewProxyService.TAG_OPS; |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 25 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_DEAD_ZONE; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 26 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 27 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 28 | import android.animation.Animator; |
| 29 | import android.animation.AnimatorListenerAdapter; |
| 30 | import android.animation.AnimatorSet; |
| 31 | import android.animation.ObjectAnimator; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 32 | import android.animation.PropertyValuesHolder; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 33 | import android.content.Context; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 34 | import android.content.res.Resources; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 35 | import android.graphics.Canvas; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 36 | import android.graphics.Matrix; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 37 | import android.graphics.Paint; |
| 38 | import android.graphics.RadialGradient; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 39 | import android.graphics.Rect; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 40 | import android.graphics.Shader; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 41 | import android.hardware.input.InputManager; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 42 | import android.os.Handler; |
| 43 | import android.os.RemoteException; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 44 | import android.os.SystemClock; |
| 45 | import android.os.SystemProperties; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 46 | import android.util.FloatProperty; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 47 | import android.util.Log; |
| 48 | import android.util.Slog; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 49 | import android.view.HapticFeedbackConstants; |
| 50 | import android.view.InputDevice; |
| 51 | import android.view.KeyCharacterMap; |
| 52 | import android.view.KeyEvent; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 53 | import android.view.MotionEvent; |
| 54 | import android.view.View; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 55 | import android.view.ViewPropertyAnimator; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 56 | import android.view.WindowManagerGlobal; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 57 | import com.android.systemui.Dependency; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 58 | import com.android.systemui.Interpolators; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 59 | import com.android.systemui.OverviewProxyService; |
| 60 | import com.android.systemui.R; |
| 61 | import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper; |
| 62 | import com.android.systemui.shared.recents.IOverviewProxy; |
| 63 | import com.android.systemui.shared.recents.utilities.Utilities; |
Matthew Ng | f29ad75 | 2018-04-26 11:24:05 -0700 | [diff] [blame] | 64 | import com.android.systemui.shared.system.NavigationBarCompat; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 65 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 66 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 67 | * Class to detect gestures on the navigation bar and implement quick scrub. |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 68 | */ |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 69 | public class QuickStepController implements GestureHelper { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 70 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 71 | private static final String TAG = "QuickStepController"; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 72 | private static final int ANIM_IN_DURATION_MS = 150; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 73 | private static final int ANIM_OUT_DURATION_MS = 134; |
| 74 | private static final float TRACK_SCALE = 0.95f; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 75 | private static final float GRADIENT_WIDTH = .75f; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 76 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 77 | /** Experiment to swipe home button left to execute a back key press */ |
| 78 | private static final String PULL_HOME_GO_BACK_PROP = "persist.quickstepcontroller.homegoesback"; |
| 79 | private static final String HIDE_BACK_BUTTON_PROP = "persist.quickstepcontroller.hideback"; |
| 80 | private static final long BACK_BUTTON_FADE_OUT_ALPHA = 60; |
| 81 | private static final long BACK_BUTTON_FADE_IN_ALPHA = 150; |
| 82 | private static final long BACK_GESTURE_POLL_TIMEOUT = 1000; |
| 83 | |
| 84 | /** When the home-swipe-back gesture is disallowed, make it harder to pull */ |
| 85 | private static final float DISALLOW_GESTURE_DAMPING_FACTOR = 0.16f; |
| 86 | |
| 87 | /** When dragging the home button too far during back gesture, make it harder to pull */ |
| 88 | private static final float EXCEED_DRAG_HOME_DAMPING_FACTOR = 0.33f; |
| 89 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 90 | private NavigationBarView mNavigationBarView; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 91 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 92 | private boolean mQuickScrubActive; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 93 | private boolean mAllowGestureDetection; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 94 | private boolean mBackGestureActive; |
| 95 | private boolean mCanPerformBack; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 96 | private boolean mQuickStepStarted; |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 97 | private boolean mNotificationsVisibleOnDown; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 98 | private int mTouchDownX; |
| 99 | private int mTouchDownY; |
| 100 | private boolean mDragPositive; |
| 101 | private boolean mIsVertical; |
| 102 | private boolean mIsRTL; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 103 | private float mTrackAlpha; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 104 | private float mTrackScale = TRACK_SCALE; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 105 | private float mDarkIntensity; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 106 | private RadialGradient mHighlight; |
| 107 | private float mHighlightCenter; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 108 | private AnimatorSet mTrackAnimator; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 109 | private ViewPropertyAnimator mHomeAnimator; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 110 | private ButtonDispatcher mHitTarget; |
| 111 | private View mCurrentNavigationBarView; |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 112 | private boolean mIsInScreenPinning; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 113 | |
| 114 | private final Handler mHandler = new Handler(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 115 | private final Rect mTrackRect = new Rect(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 116 | private final OverviewProxyService mOverviewEventSender; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 117 | private final int mTrackThickness; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 118 | private final int mTrackEndPadding; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 119 | private final int mHomeBackGestureDragLimit; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 120 | private final Context mContext; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 121 | private final Matrix mTransformGlobalMatrix = new Matrix(); |
| 122 | private final Matrix mTransformLocalMatrix = new Matrix(); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 123 | private final Paint mTrackPaint = new Paint(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 124 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 125 | public static boolean swipeHomeGoBackGestureEnabled() { |
| 126 | return SystemProperties.getBoolean(PULL_HOME_GO_BACK_PROP, false); |
| 127 | } |
| 128 | public static boolean shouldhideBackButton() { |
| 129 | return swipeHomeGoBackGestureEnabled() |
| 130 | && SystemProperties.getBoolean(HIDE_BACK_BUTTON_PROP, false); |
| 131 | } |
| 132 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 133 | private final FloatProperty<QuickStepController> mTrackAlphaProperty = |
| 134 | new FloatProperty<QuickStepController>("TrackAlpha") { |
| 135 | @Override |
| 136 | public void setValue(QuickStepController controller, float alpha) { |
| 137 | mTrackAlpha = alpha; |
| 138 | mNavigationBarView.invalidate(); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public Float get(QuickStepController controller) { |
| 143 | return mTrackAlpha; |
| 144 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 145 | }; |
| 146 | |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 147 | private final FloatProperty<QuickStepController> mTrackScaleProperty = |
| 148 | new FloatProperty<QuickStepController>("TrackScale") { |
| 149 | @Override |
| 150 | public void setValue(QuickStepController controller, float scale) { |
| 151 | mTrackScale = scale; |
| 152 | mNavigationBarView.invalidate(); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public Float get(QuickStepController controller) { |
| 157 | return mTrackScale; |
| 158 | } |
| 159 | }; |
| 160 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 161 | private final FloatProperty<QuickStepController> mNavBarAlphaProperty = |
| 162 | new FloatProperty<QuickStepController>("NavBarAlpha") { |
| 163 | @Override |
| 164 | public void setValue(QuickStepController controller, float alpha) { |
| 165 | if (mCurrentNavigationBarView != null) { |
| 166 | mCurrentNavigationBarView.setAlpha(alpha); |
| 167 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 168 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 169 | |
| 170 | @Override |
| 171 | public Float get(QuickStepController controller) { |
| 172 | if (mCurrentNavigationBarView != null) { |
| 173 | return mCurrentNavigationBarView.getAlpha(); |
| 174 | } |
| 175 | return 1f; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 176 | } |
| 177 | }; |
| 178 | |
| 179 | private AnimatorListenerAdapter mQuickScrubEndListener = new AnimatorListenerAdapter() { |
| 180 | @Override |
| 181 | public void onAnimationEnd(Animator animation) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 182 | resetQuickScrub(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 183 | } |
| 184 | }; |
| 185 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 186 | private final Runnable mExecuteBackRunnable = new Runnable() { |
| 187 | @Override |
| 188 | public void run() { |
| 189 | if (canPerformHomeBackGesture()) { |
| 190 | performBack(); |
| 191 | mHandler.postDelayed(this, BACK_GESTURE_POLL_TIMEOUT); |
| 192 | } |
| 193 | } |
| 194 | }; |
| 195 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 196 | public QuickStepController(Context context) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 197 | final Resources res = context.getResources(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 198 | mContext = context; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 199 | mOverviewEventSender = Dependency.get(OverviewProxyService.class); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 200 | mTrackThickness = res.getDimensionPixelSize(R.dimen.nav_quick_scrub_track_thickness); |
| 201 | mTrackEndPadding = res.getDimensionPixelSize(R.dimen.nav_quick_scrub_track_edge_padding); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 202 | mHomeBackGestureDragLimit = |
| 203 | res.getDimensionPixelSize(R.dimen.nav_home_back_gesture_drag_limit); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 204 | mTrackPaint.setAntiAlias(true); |
| 205 | mTrackPaint.setDither(true); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | public void setComponents(NavigationBarView navigationBarView) { |
| 209 | mNavigationBarView = navigationBarView; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 210 | |
| 211 | mNavigationBarView.getBackButton().setVisibility(shouldhideBackButton() |
| 212 | ? View.GONE |
| 213 | : View.VISIBLE); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 216 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 217 | * @return true if we want to intercept touch events for quick scrub and prevent proxying the |
| 218 | * event to the overview service. |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 219 | */ |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 220 | @Override |
| 221 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 222 | return handleTouchEvent(event); |
| 223 | } |
| 224 | |
| 225 | /** |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 226 | * @return true if we want to handle touch events for quick scrub or if down event (that will |
| 227 | * 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] | 228 | */ |
| 229 | @Override |
| 230 | public boolean onTouchEvent(MotionEvent event) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 231 | // The same down event was just sent on intercept and therefore can be ignored here |
| 232 | final boolean ignoreProxyDownEvent = event.getAction() == MotionEvent.ACTION_DOWN |
| 233 | && mOverviewEventSender.getProxy() != null; |
| 234 | return ignoreProxyDownEvent || handleTouchEvent(event); |
Winson Chung | de2a124 | 2018-02-07 15:59:43 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | private boolean handleTouchEvent(MotionEvent event) { |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 238 | final boolean deadZoneConsumed = |
| 239 | mNavigationBarView.getDownHitTarget() == HIT_TARGET_DEAD_ZONE; |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 240 | if (mOverviewEventSender.getProxy() == null || (!mNavigationBarView.isQuickScrubEnabled() |
| 241 | && !mNavigationBarView.isQuickStepSwipeUpEnabled())) { |
Matthew Ng | 2cbe8cd | 2018-08-20 11:27:40 -0700 | [diff] [blame] | 242 | return deadZoneConsumed; |
Matthew Ng | 22cf514 | 2018-03-14 12:26:14 -0700 | [diff] [blame] | 243 | } |
| 244 | mNavigationBarView.requestUnbufferedDispatch(event); |
| 245 | |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 246 | int action = event.getActionMasked(); |
| 247 | switch (action) { |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 248 | case MotionEvent.ACTION_DOWN: { |
| 249 | int x = (int) event.getX(); |
| 250 | int y = (int) event.getY(); |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 251 | mIsInScreenPinning = mNavigationBarView.inScreenPinning(); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 252 | |
Winson Chung | 0be8f08 | 2018-02-15 15:52:49 -0800 | [diff] [blame] | 253 | // End any existing quickscrub animations before starting the new transition |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 254 | if (mTrackAnimator != null) { |
| 255 | mTrackAnimator.end(); |
| 256 | mTrackAnimator = null; |
Winson Chung | 0be8f08 | 2018-02-15 15:52:49 -0800 | [diff] [blame] | 257 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 258 | |
| 259 | mCurrentNavigationBarView = mNavigationBarView.getCurrentView(); |
| 260 | mHitTarget = mNavigationBarView.getButtonAtPosition(x, y); |
| 261 | if (mHitTarget != null) { |
| 262 | // Pre-emptively delay the touch feedback for the button that we just touched |
| 263 | mHitTarget.setDelayTouchFeedback(true); |
| 264 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 265 | mTouchDownX = x; |
| 266 | mTouchDownY = y; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 267 | mTransformGlobalMatrix.set(Matrix.IDENTITY_MATRIX); |
| 268 | mTransformLocalMatrix.set(Matrix.IDENTITY_MATRIX); |
| 269 | mNavigationBarView.transformMatrixToGlobal(mTransformGlobalMatrix); |
| 270 | mNavigationBarView.transformMatrixToLocal(mTransformLocalMatrix); |
| 271 | mQuickStepStarted = false; |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 272 | mBackGestureActive = false; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 273 | mAllowGestureDetection = true; |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 274 | mNotificationsVisibleOnDown = !mNavigationBarView.isNotificationsFullyCollapsed(); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 275 | mCanPerformBack = canPerformHomeBackGesture(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 276 | break; |
| 277 | } |
| 278 | case MotionEvent.ACTION_MOVE: { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 279 | if (mQuickStepStarted || !mAllowGestureDetection){ |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 280 | break; |
| 281 | } |
| 282 | int x = (int) event.getX(); |
| 283 | int y = (int) event.getY(); |
| 284 | int xDiff = Math.abs(x - mTouchDownX); |
| 285 | int yDiff = Math.abs(y - mTouchDownY); |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 286 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 287 | boolean exceededScrubTouchSlop, exceededSwipeUpTouchSlop; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 288 | int pos, touchDown, offset, trackSize; |
Matthew Ng | e0903c9 | 2018-01-17 15:32:41 -0800 | [diff] [blame] | 289 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 290 | if (mIsVertical) { |
Matthew Ng | f29ad75 | 2018-04-26 11:24:05 -0700 | [diff] [blame] | 291 | exceededScrubTouchSlop = |
| 292 | yDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && yDiff > xDiff; |
| 293 | exceededSwipeUpTouchSlop = |
| 294 | xDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && xDiff > yDiff; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 295 | pos = y; |
| 296 | touchDown = mTouchDownY; |
| 297 | offset = pos - mTrackRect.top; |
| 298 | trackSize = mTrackRect.height(); |
| 299 | } else { |
Matthew Ng | f29ad75 | 2018-04-26 11:24:05 -0700 | [diff] [blame] | 300 | exceededScrubTouchSlop = |
| 301 | xDiff > NavigationBarCompat.getQuickScrubTouchSlopPx() && xDiff > yDiff; |
| 302 | exceededSwipeUpTouchSlop = |
| 303 | yDiff > NavigationBarCompat.getQuickStepTouchSlopPx() && yDiff > xDiff; |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 304 | pos = x; |
| 305 | touchDown = mTouchDownX; |
| 306 | offset = pos - mTrackRect.left; |
| 307 | trackSize = mTrackRect.width(); |
| 308 | } |
| 309 | // Decide to start quickstep if dragging away from the navigation bar, otherwise in |
| 310 | // the parallel direction, decide to start quickscrub. Only one may run. |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 311 | if (!mBackGestureActive && !mQuickScrubActive && exceededSwipeUpTouchSlop) { |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 312 | if (mNavigationBarView.isQuickStepSwipeUpEnabled() |
| 313 | && !mNotificationsVisibleOnDown) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 314 | startQuickStep(event); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 315 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 316 | break; |
| 317 | } |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 318 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 319 | // Do not handle quick scrub if disabled |
| 320 | if (!mNavigationBarView.isQuickScrubEnabled()) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 321 | break; |
| 322 | } |
| 323 | |
| 324 | if (!mDragPositive) { |
| 325 | offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width(); |
| 326 | } |
| 327 | |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 328 | final boolean allowDrag = !mDragPositive |
| 329 | ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 330 | float scrubFraction = Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 331 | if (!mQuickScrubActive && !mBackGestureActive && exceededScrubTouchSlop) { |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 332 | // Passing the drag slop then touch slop will start quick step |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 333 | if (allowDrag) { |
Matthew Ng | fba3969 | 2018-03-13 18:08:34 -0700 | [diff] [blame] | 334 | startQuickScrub(); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 335 | } else if (swipeHomeGoBackGestureEnabled() |
| 336 | && mNavigationBarView.getDownHitTarget() == HIT_TARGET_HOME |
| 337 | && mDragPositive ? pos < touchDown : pos > touchDown) { |
| 338 | startBackGesture(); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 339 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 340 | } |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 341 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 342 | if (mQuickScrubActive && (mDragPositive && offset >= 0 |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 343 | || !mDragPositive && offset <= 0)) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 344 | try { |
| 345 | mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction); |
| 346 | if (DEBUG_OVERVIEW_PROXY) { |
| 347 | Log.d(TAG_OPS, "Quick Scrub Progress:" + scrubFraction); |
Winson Chung | 0e490d92 | 2018-03-14 16:08:43 +0000 | [diff] [blame] | 348 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 349 | } catch (RemoteException e) { |
| 350 | Log.e(TAG, "Failed to send progress of quick scrub.", e); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 351 | } |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 352 | mHighlightCenter = x; |
| 353 | mNavigationBarView.invalidate(); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 354 | } else if (mBackGestureActive) { |
| 355 | int diff = pos - touchDown; |
| 356 | // If dragging the incorrect direction after starting back gesture or unable |
| 357 | // to execute back functionality, then move home but dampen its distance |
| 358 | if (!mCanPerformBack || (mDragPositive ? diff > 0 : diff < 0)) { |
| 359 | diff *= DISALLOW_GESTURE_DAMPING_FACTOR; |
| 360 | } if (Math.abs(diff) > mHomeBackGestureDragLimit) { |
| 361 | // Once the user drags the home button past a certain limit, the distance |
| 362 | // will lessen as the home button dampens showing that it was pulled too far |
| 363 | float distanceAfterDragLimit = (Math.abs(diff) - mHomeBackGestureDragLimit) |
| 364 | * EXCEED_DRAG_HOME_DAMPING_FACTOR; |
| 365 | diff = (int)(distanceAfterDragLimit + mHomeBackGestureDragLimit); |
| 366 | if (mDragPositive) { |
| 367 | diff *= -1; |
| 368 | } |
| 369 | } |
| 370 | moveHomeButton(diff); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 371 | } |
| 372 | break; |
| 373 | } |
| 374 | case MotionEvent.ACTION_CANCEL: |
| 375 | case MotionEvent.ACTION_UP: |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 376 | endQuickScrub(true /* animate */); |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 377 | endBackGesture(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 378 | break; |
| 379 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 380 | |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 381 | if (shouldProxyEvents(action)) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 382 | proxyMotionEvents(event); |
| 383 | } |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 384 | return mBackGestureActive || mQuickScrubActive || mQuickStepStarted || deadZoneConsumed; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 387 | private boolean shouldProxyEvents(int action) { |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 388 | if (!mBackGestureActive && !mQuickScrubActive && !mIsInScreenPinning) { |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 389 | // Allow down, cancel and up events, move and other events are passed if notifications |
| 390 | // are not showing and disabled gestures (such as long press) are not executed |
| 391 | switch (action) { |
| 392 | case MotionEvent.ACTION_DOWN: |
| 393 | case MotionEvent.ACTION_CANCEL: |
| 394 | case MotionEvent.ACTION_UP: |
| 395 | return true; |
| 396 | default: |
| 397 | return !mNotificationsVisibleOnDown && mAllowGestureDetection; |
| 398 | } |
| 399 | } |
| 400 | return false; |
| 401 | } |
| 402 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 403 | @Override |
| 404 | public void onDraw(Canvas canvas) { |
Matthew Ng | f781bbd | 2018-03-21 14:58:55 -0700 | [diff] [blame] | 405 | if (!mNavigationBarView.isQuickScrubEnabled()) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 406 | return; |
| 407 | } |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 408 | mTrackPaint.setAlpha(Math.round(255f * mTrackAlpha)); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 409 | |
| 410 | // Scale the track, but apply the inverse scale from the nav bar |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 411 | final float radius = mTrackRect.height() / 2; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 412 | canvas.save(); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 413 | float translate = Utilities.clamp(mHighlightCenter, mTrackRect.left, mTrackRect.right); |
| 414 | canvas.translate(translate, 0); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 415 | canvas.scale(mTrackScale / mNavigationBarView.getScaleX(), |
| 416 | 1f / mNavigationBarView.getScaleY(), |
| 417 | mTrackRect.centerX(), mTrackRect.centerY()); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 418 | canvas.drawRoundRect(mTrackRect.left - translate, mTrackRect.top, |
| 419 | mTrackRect.right - translate, mTrackRect.bottom, radius, radius, mTrackPaint); |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 420 | canvas.restore(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 425 | final int paddingLeft = mNavigationBarView.getPaddingLeft(); |
| 426 | final int paddingTop = mNavigationBarView.getPaddingTop(); |
| 427 | final int paddingRight = mNavigationBarView.getPaddingRight(); |
| 428 | final int paddingBottom = mNavigationBarView.getPaddingBottom(); |
| 429 | final int width = (right - left) - paddingRight - paddingLeft; |
| 430 | final int height = (bottom - top) - paddingBottom - paddingTop; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 431 | final int x1, x2, y1, y2; |
| 432 | if (mIsVertical) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 433 | x1 = (width - mTrackThickness) / 2 + paddingLeft; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 434 | x2 = x1 + mTrackThickness; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 435 | y1 = paddingTop + mTrackEndPadding; |
| 436 | y2 = y1 + height - 2 * mTrackEndPadding; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 437 | } else { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 438 | y1 = (height - mTrackThickness) / 2 + paddingTop; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 439 | y2 = y1 + mTrackThickness; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 440 | x1 = mNavigationBarView.getPaddingStart() + mTrackEndPadding; |
| 441 | x2 = x1 + width - 2 * mTrackEndPadding; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 442 | } |
| 443 | mTrackRect.set(x1, y1, x2, y2); |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 444 | updateHighlight(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | @Override |
| 448 | public void onDarkIntensityChange(float intensity) { |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 449 | final float oldIntensity = mDarkIntensity; |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 450 | mDarkIntensity = intensity; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 451 | |
| 452 | // When in quick scrub, invalidate gradient if changing intensity from black to white and |
| 453 | // vice-versa |
| 454 | if (mNavigationBarView.isQuickScrubEnabled() |
| 455 | && Math.round(intensity) != Math.round(oldIntensity)) { |
| 456 | updateHighlight(); |
| 457 | } |
Matthew Ng | 7090a80 | 2018-01-19 13:36:22 -0800 | [diff] [blame] | 458 | mNavigationBarView.invalidate(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | @Override |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 462 | public void setBarState(boolean isVertical, boolean isRTL) { |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 463 | final boolean changed = (mIsVertical != isVertical) || (mIsRTL != isRTL); |
| 464 | if (changed) { |
| 465 | // End quickscrub if the state changes mid-transition |
| 466 | endQuickScrub(false /* animate */); |
| 467 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 468 | mIsVertical = isVertical; |
| 469 | mIsRTL = isRTL; |
| 470 | try { |
| 471 | int navbarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition(); |
| 472 | mDragPositive = navbarPos == NAV_BAR_LEFT || navbarPos == NAV_BAR_BOTTOM; |
| 473 | if (isRTL) { |
| 474 | mDragPositive = !mDragPositive; |
| 475 | } |
| 476 | } catch (RemoteException e) { |
| 477 | Slog.e(TAG, "Failed to get nav bar position.", e); |
| 478 | } |
| 479 | } |
| 480 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 481 | @Override |
| 482 | public void onNavigationButtonLongPress(View v) { |
| 483 | mAllowGestureDetection = false; |
| 484 | mHandler.removeCallbacksAndMessages(null); |
| 485 | } |
| 486 | |
| 487 | private void startQuickStep(MotionEvent event) { |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 488 | if (mIsInScreenPinning) { |
| 489 | mNavigationBarView.showPinningEscapeToast(); |
| 490 | mAllowGestureDetection = false; |
| 491 | return; |
| 492 | } |
| 493 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 494 | mQuickStepStarted = true; |
| 495 | event.transform(mTransformGlobalMatrix); |
| 496 | try { |
| 497 | mOverviewEventSender.getProxy().onQuickStep(event); |
| 498 | if (DEBUG_OVERVIEW_PROXY) { |
| 499 | Log.d(TAG_OPS, "Quick Step Start"); |
| 500 | } |
| 501 | } catch (RemoteException e) { |
| 502 | Log.e(TAG, "Failed to send quick step started.", e); |
| 503 | } finally { |
| 504 | event.transform(mTransformLocalMatrix); |
| 505 | } |
| 506 | mOverviewEventSender.notifyQuickStepStarted(); |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 507 | mHandler.removeCallbacksAndMessages(null); |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 508 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 509 | if (mHitTarget != null) { |
| 510 | mHitTarget.abortCurrentGesture(); |
| 511 | } |
| 512 | |
| 513 | if (mQuickScrubActive) { |
Matthew Ng | 9a22363 | 2018-03-30 16:47:22 -0700 | [diff] [blame] | 514 | animateEnd(); |
| 515 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 518 | private void startQuickScrub() { |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 519 | if (mIsInScreenPinning) { |
| 520 | mNavigationBarView.showPinningEscapeToast(); |
| 521 | mAllowGestureDetection = false; |
| 522 | return; |
| 523 | } |
| 524 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 525 | if (!mQuickScrubActive) { |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 526 | updateHighlight(); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 527 | mQuickScrubActive = true; |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 528 | ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this, |
| 529 | PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 1f), |
| 530 | PropertyValuesHolder.ofFloat(mTrackScaleProperty, 1f)); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 531 | trackAnimator.setInterpolator(ALPHA_IN); |
| 532 | trackAnimator.setDuration(ANIM_IN_DURATION_MS); |
| 533 | ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 0f); |
| 534 | navBarAnimator.setInterpolator(ALPHA_OUT); |
| 535 | navBarAnimator.setDuration(ANIM_OUT_DURATION_MS); |
| 536 | mTrackAnimator = new AnimatorSet(); |
| 537 | mTrackAnimator.playTogether(trackAnimator, navBarAnimator); |
| 538 | mTrackAnimator.start(); |
Matthew Ng | 6607c3d | 2018-04-26 15:23:27 -0700 | [diff] [blame] | 539 | |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 540 | // Disable slippery for quick scrub to not cancel outside the nav bar |
| 541 | mNavigationBarView.updateSlippery(); |
| 542 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 543 | try { |
| 544 | mOverviewEventSender.getProxy().onQuickScrubStart(); |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 545 | if (DEBUG_OVERVIEW_PROXY) { |
| 546 | Log.d(TAG_OPS, "Quick Scrub Start"); |
| 547 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 548 | } catch (RemoteException e) { |
| 549 | Log.e(TAG, "Failed to send start of quick scrub.", e); |
| 550 | } |
Tracy Zhou | 2759905 | 2018-04-16 15:47:29 -0700 | [diff] [blame] | 551 | mOverviewEventSender.notifyQuickScrubStarted(); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 552 | |
| 553 | if (mHitTarget != null) { |
| 554 | mHitTarget.abortCurrentGesture(); |
| 555 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | |
Winson Chung | d10ca30 | 2018-02-14 10:13:41 -0800 | [diff] [blame] | 559 | private void endQuickScrub(boolean animate) { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 560 | if (mQuickScrubActive) { |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 561 | animateEnd(); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 562 | try { |
| 563 | mOverviewEventSender.getProxy().onQuickScrubEnd(); |
| 564 | if (DEBUG_OVERVIEW_PROXY) { |
| 565 | Log.d(TAG_OPS, "Quick Scrub End"); |
Matthew Ng | bd82457 | 2018-01-17 16:25:56 -0800 | [diff] [blame] | 566 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 567 | } catch (RemoteException e) { |
| 568 | Log.e(TAG, "Failed to send end of quick scrub.", e); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 569 | } |
Matthew Ng | ed166f9 | 2018-02-20 16:22:09 -0800 | [diff] [blame] | 570 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 571 | if (!animate) { |
| 572 | if (mTrackAnimator != null) { |
| 573 | mTrackAnimator.end(); |
| 574 | mTrackAnimator = null; |
| 575 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 576 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 577 | } |
| 578 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 579 | private void startBackGesture() { |
| 580 | if (!mBackGestureActive) { |
| 581 | mBackGestureActive = true; |
| 582 | mNavigationBarView.getHomeButton().abortCurrentGesture(); |
| 583 | if (mCanPerformBack) { |
| 584 | if (!shouldhideBackButton()) { |
| 585 | mNavigationBarView.getBackButton().setAlpha(0 /* alpha */, true /* animate */, |
| 586 | BACK_BUTTON_FADE_OUT_ALPHA); |
| 587 | } |
| 588 | performBack(); |
| 589 | } |
| 590 | mHandler.removeCallbacks(mExecuteBackRunnable); |
| 591 | mHandler.postDelayed(mExecuteBackRunnable, BACK_GESTURE_POLL_TIMEOUT); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | private void endBackGesture() { |
| 596 | if (mBackGestureActive) { |
| 597 | mHandler.removeCallbacks(mExecuteBackRunnable); |
| 598 | mHomeAnimator = mNavigationBarView.getHomeButton().getCurrentView() |
| 599 | .animate() |
| 600 | .setDuration(BACK_BUTTON_FADE_IN_ALPHA) |
| 601 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 602 | if (mIsVertical) { |
| 603 | mHomeAnimator.translationY(0); |
| 604 | } else { |
| 605 | mHomeAnimator.translationX(0); |
| 606 | } |
| 607 | mHomeAnimator.start(); |
| 608 | if (!shouldhideBackButton()) { |
| 609 | mNavigationBarView.getBackButton().setAlpha( |
| 610 | mOverviewEventSender.getBackButtonAlpha(), true /* animate */); |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 615 | private void animateEnd() { |
| 616 | if (mTrackAnimator != null) { |
| 617 | mTrackAnimator.cancel(); |
| 618 | } |
| 619 | |
Winson Chung | 4baf124 | 2018-05-24 14:21:57 -0700 | [diff] [blame] | 620 | ObjectAnimator trackAnimator = ObjectAnimator.ofPropertyValuesHolder(this, |
| 621 | PropertyValuesHolder.ofFloat(mTrackAlphaProperty, 0f), |
| 622 | PropertyValuesHolder.ofFloat(mTrackScaleProperty, TRACK_SCALE)); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 623 | trackAnimator.setInterpolator(ALPHA_OUT); |
| 624 | trackAnimator.setDuration(ANIM_OUT_DURATION_MS); |
| 625 | ObjectAnimator navBarAnimator = ObjectAnimator.ofFloat(this, mNavBarAlphaProperty, 1f); |
| 626 | navBarAnimator.setInterpolator(ALPHA_IN); |
| 627 | navBarAnimator.setDuration(ANIM_IN_DURATION_MS); |
| 628 | mTrackAnimator = new AnimatorSet(); |
| 629 | mTrackAnimator.playTogether(trackAnimator, navBarAnimator); |
| 630 | mTrackAnimator.addListener(mQuickScrubEndListener); |
| 631 | mTrackAnimator.start(); |
| 632 | } |
| 633 | |
| 634 | private void resetQuickScrub() { |
| 635 | mQuickScrubActive = false; |
| 636 | mAllowGestureDetection = false; |
Matthew Ng | 819daaa | 2018-07-23 15:12:57 -0700 | [diff] [blame] | 637 | if (mCurrentNavigationBarView != null) { |
| 638 | mCurrentNavigationBarView.setAlpha(1f); |
| 639 | } |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 640 | mCurrentNavigationBarView = null; |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 641 | updateHighlight(); |
| 642 | } |
| 643 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 644 | private void moveHomeButton(float pos) { |
| 645 | if (mHomeAnimator != null) { |
| 646 | mHomeAnimator.cancel(); |
| 647 | mHomeAnimator = null; |
| 648 | } |
| 649 | final View homeButton = mNavigationBarView.getHomeButton().getCurrentView(); |
| 650 | if (mIsVertical) { |
| 651 | homeButton.setTranslationY(pos); |
| 652 | } else { |
| 653 | homeButton.setTranslationX(pos); |
| 654 | } |
| 655 | } |
| 656 | |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 657 | private void updateHighlight() { |
Matthew Ng | 908111d | 2018-06-26 15:22:56 -0700 | [diff] [blame] | 658 | if (mTrackRect.isEmpty()) { |
| 659 | return; |
| 660 | } |
Matthew Ng | 4fa3a9d | 2018-06-12 16:42:11 -0700 | [diff] [blame] | 661 | int colorBase, colorGrad; |
| 662 | if (mDarkIntensity > 0.5f) { |
| 663 | colorBase = mContext.getColor(R.color.quick_step_track_background_background_dark); |
| 664 | colorGrad = mContext.getColor(R.color.quick_step_track_background_foreground_dark); |
| 665 | } else { |
| 666 | colorBase = mContext.getColor(R.color.quick_step_track_background_background_light); |
| 667 | colorGrad = mContext.getColor(R.color.quick_step_track_background_foreground_light); |
| 668 | } |
| 669 | mHighlight = new RadialGradient(0, mTrackRect.height() / 2, |
| 670 | mTrackRect.width() * GRADIENT_WIDTH, colorGrad, colorBase, |
| 671 | Shader.TileMode.CLAMP); |
| 672 | mTrackPaint.setShader(mHighlight); |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame^] | 675 | private boolean canPerformHomeBackGesture() { |
| 676 | return swipeHomeGoBackGestureEnabled() && mOverviewEventSender.getBackButtonAlpha() > 0; |
| 677 | } |
| 678 | |
| 679 | private void performBack() { |
| 680 | sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); |
| 681 | sendEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK); |
| 682 | mNavigationBarView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 683 | } |
| 684 | |
| 685 | private void sendEvent(int action, int code) { |
| 686 | long when = SystemClock.uptimeMillis(); |
| 687 | final KeyEvent ev = new KeyEvent(when, when, action, code, 0 /* repeat */, |
| 688 | 0 /* metaState */, KeyCharacterMap.VIRTUAL_KEYBOARD, 0 /* scancode */, |
| 689 | KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY, |
| 690 | InputDevice.SOURCE_KEYBOARD); |
| 691 | InputManager.getInstance().injectInputEvent(ev, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); |
| 692 | } |
| 693 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 694 | private boolean proxyMotionEvents(MotionEvent event) { |
| 695 | final IOverviewProxy overviewProxy = mOverviewEventSender.getProxy(); |
| 696 | event.transform(mTransformGlobalMatrix); |
| 697 | try { |
| 698 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 699 | overviewProxy.onPreMotionEvent(mNavigationBarView.getDownHitTarget()); |
| 700 | } |
| 701 | overviewProxy.onMotionEvent(event); |
| 702 | if (DEBUG_OVERVIEW_PROXY) { |
| 703 | Log.d(TAG_OPS, "Send MotionEvent: " + event.toString()); |
| 704 | } |
| 705 | return true; |
| 706 | } catch (RemoteException e) { |
| 707 | Log.e(TAG, "Callback failed", e); |
| 708 | } finally { |
| 709 | event.transform(mTransformLocalMatrix); |
Matthew Ng | db2734c | 2018-02-16 16:02:20 -0800 | [diff] [blame] | 710 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 711 | return false; |
Matthew Ng | db2734c | 2018-02-16 16:02:20 -0800 | [diff] [blame] | 712 | } |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 713 | } |