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