Skip to content

Commit eed585b

Browse files
author
Tony Wickham
committed
Refactor SwipeDetector to track both axes
Existing clients now use the SingleAxisSwipeDetector subclass. A followup CL will add BothAxesSwipeDetector, whose first client will be the quick switch from home controller. Bug: 126596417 Change-Id: I54c71088cfe99ff28cdc719a1eb7a7d06ac95d2d Merged-In: I54c71088cfe99ff28cdc719a1eb7a7d06ac95d2d
1 parent 7fcbd23 commit eed585b

File tree

15 files changed

+344
-261
lines changed

15 files changed

+344
-261
lines changed

quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/FlingAndHoldTouchController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public boolean onDrag(float displacement, MotionEvent event) {
173173
}
174174

175175
@Override
176-
public void onDragEnd(float velocity, boolean fling) {
176+
public void onDragEnd(float velocity) {
177177
if (mMotionPauseDetector.isPaused() && handlingOverviewAnim()) {
178178
if (mPeekAnim != null) {
179179
mPeekAnim.cancel();
@@ -196,7 +196,7 @@ public void onAnimationEnd(Animator animation) {
196196
});
197197
overviewAnim.start();
198198
} else {
199-
super.onDragEnd(velocity, fling);
199+
super.onDragEnd(velocity);
200200
}
201201

202202
View searchView = mLauncher.getAppsView().getSearchView();

quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NavBarToHomeTouchController.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import com.android.launcher3.anim.AnimatorSetBuilder;
4444
import com.android.launcher3.anim.Interpolators;
4545
import com.android.launcher3.compat.AccessibilityManagerCompat;
46-
import com.android.launcher3.touch.SwipeDetector;
46+
import com.android.launcher3.touch.SingleAxisSwipeDetector;
4747
import com.android.launcher3.userevent.nano.LauncherLogProto;
4848
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
4949
import com.android.launcher3.util.TouchController;
@@ -52,12 +52,13 @@
5252
/**
5353
* Handles swiping up on the nav bar to go home from launcher, e.g. overview or all apps.
5454
*/
55-
public class NavBarToHomeTouchController implements TouchController, SwipeDetector.Listener {
55+
public class NavBarToHomeTouchController implements TouchController,
56+
SingleAxisSwipeDetector.Listener {
5657

5758
private static final Interpolator PULLBACK_INTERPOLATOR = DEACCEL_3;
5859

5960
private final Launcher mLauncher;
60-
private final SwipeDetector mSwipeDetector;
61+
private final SingleAxisSwipeDetector mSwipeDetector;
6162
private final float mPullbackDistance;
6263

6364
private boolean mNoIntercept;
@@ -67,7 +68,8 @@ public class NavBarToHomeTouchController implements TouchController, SwipeDetect
6768

6869
public NavBarToHomeTouchController(Launcher launcher) {
6970
mLauncher = launcher;
70-
mSwipeDetector = new SwipeDetector(mLauncher, this, SwipeDetector.VERTICAL);
71+
mSwipeDetector = new SingleAxisSwipeDetector(mLauncher, this,
72+
SingleAxisSwipeDetector.VERTICAL);
7173
mPullbackDistance = mLauncher.getResources().getDimension(R.dimen.home_pullback_distance);
7274
}
7375

@@ -79,7 +81,8 @@ public final boolean onControllerInterceptTouchEvent(MotionEvent ev) {
7981
if (mNoIntercept) {
8082
return false;
8183
}
82-
mSwipeDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_POSITIVE, false);
84+
mSwipeDetector.setDetectableScrollConditions(SingleAxisSwipeDetector.DIRECTION_POSITIVE,
85+
false /* ignoreSlop */);
8386
}
8487

8588
if (mNoIntercept) {
@@ -173,7 +176,8 @@ public boolean onDrag(float displacement) {
173176
}
174177

175178
@Override
176-
public void onDragEnd(float velocity, boolean fling) {
179+
public void onDragEnd(float velocity) {
180+
boolean fling = mSwipeDetector.isFling(velocity);
177181
final int logAction = fling ? Touch.FLING : Touch.SWIPE;
178182
float progress = mCurrentAnimation.getProgressFraction();
179183
float interpolatedProgress = PULLBACK_INTERPOLATOR.getInterpolation(progress);

quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/QuickSwitchTouchController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import com.android.launcher3.Utilities;
4343
import com.android.launcher3.anim.AnimatorSetBuilder;
4444
import com.android.launcher3.touch.AbstractStateChangeTouchController;
45-
import com.android.launcher3.touch.SwipeDetector;
45+
import com.android.launcher3.touch.SingleAxisSwipeDetector;
4646
import com.android.launcher3.userevent.nano.LauncherLogProto;
4747
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
4848
import com.android.quickstep.OverviewInteractionState;
@@ -59,10 +59,10 @@ public class QuickSwitchTouchController extends AbstractStateChangeTouchControll
5959
private @Nullable TaskView mTaskToLaunch;
6060

6161
public QuickSwitchTouchController(Launcher launcher) {
62-
this(launcher, SwipeDetector.HORIZONTAL);
62+
this(launcher, SingleAxisSwipeDetector.HORIZONTAL);
6363
}
6464

65-
protected QuickSwitchTouchController(Launcher l, SwipeDetector.Direction dir) {
65+
protected QuickSwitchTouchController(Launcher l, SingleAxisSwipeDetector.Direction dir) {
6666
super(l, dir);
6767
}
6868

quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java

+17-13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
2020
import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
2121
import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS;
22+
import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_BOTH;
23+
import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_NEGATIVE;
24+
import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_POSITIVE;
2225
import static com.android.launcher3.util.DefaultDisplay.getSingleFrameMs;
2326

2427
import android.animation.Animator;
@@ -32,7 +35,8 @@
3235
import com.android.launcher3.Utilities;
3336
import com.android.launcher3.anim.AnimatorPlaybackController;
3437
import com.android.launcher3.anim.Interpolators;
35-
import com.android.launcher3.touch.SwipeDetector;
38+
import com.android.launcher3.touch.BaseSwipeDetector;
39+
import com.android.launcher3.touch.SingleAxisSwipeDetector;
3640
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
3741
import com.android.launcher3.util.FlingBlockCheck;
3842
import com.android.launcher3.util.PendingAnimation;
@@ -46,15 +50,14 @@
4650
* Touch controller for handling task view card swipes
4751
*/
4852
public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
49-
extends AnimatorListenerAdapter implements TouchController, SwipeDetector.Listener {
50-
51-
private static final String TAG = "OverviewSwipeController";
53+
extends AnimatorListenerAdapter implements TouchController,
54+
SingleAxisSwipeDetector.Listener {
5255

5356
// Progress after which the transition is assumed to be a success in case user does not fling
5457
public static final float SUCCESS_TRANSITION_PROGRESS = 0.5f;
5558

5659
protected final T mActivity;
57-
private final SwipeDetector mDetector;
60+
private final SingleAxisSwipeDetector mDetector;
5861
private final RecentsView mRecentsView;
5962
private final int[] mTempCords = new int[2];
6063

@@ -74,7 +77,7 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
7477
public TaskViewTouchController(T activity) {
7578
mActivity = activity;
7679
mRecentsView = activity.getOverviewPanel();
77-
mDetector = new SwipeDetector(activity, this, SwipeDetector.VERTICAL);
80+
mDetector = new SingleAxisSwipeDetector(activity, this, SingleAxisSwipeDetector.VERTICAL);
7881
}
7982

8083
private boolean canInterceptTouch() {
@@ -113,7 +116,7 @@ public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
113116
int directionsToDetectScroll = 0;
114117
boolean ignoreSlopWhenSettling = false;
115118
if (mCurrentAnimation != null) {
116-
directionsToDetectScroll = SwipeDetector.DIRECTION_BOTH;
119+
directionsToDetectScroll = DIRECTION_BOTH;
117120
ignoreSlopWhenSettling = true;
118121
} else {
119122
mTaskBeingDragged = null;
@@ -126,12 +129,12 @@ public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
126129
if (!SysUINavigationMode.getMode(mActivity).hasGestures) {
127130
// Don't allow swipe down to open if we don't support swipe up
128131
// to enter overview.
129-
directionsToDetectScroll = SwipeDetector.DIRECTION_POSITIVE;
132+
directionsToDetectScroll = DIRECTION_POSITIVE;
130133
} else {
131134
// The task can be dragged up to dismiss it,
132135
// and down to open if it's the current page.
133136
directionsToDetectScroll = i == mRecentsView.getCurrentPage()
134-
? SwipeDetector.DIRECTION_BOTH : SwipeDetector.DIRECTION_POSITIVE;
137+
? DIRECTION_BOTH : DIRECTION_POSITIVE;
135138
}
136139
break;
137140
}
@@ -165,8 +168,8 @@ private void reInitAnimationController(boolean goingUp) {
165168
return;
166169
}
167170
int scrollDirections = mDetector.getScrollDirections();
168-
if (goingUp && ((scrollDirections & SwipeDetector.DIRECTION_POSITIVE) == 0)
169-
|| !goingUp && ((scrollDirections & SwipeDetector.DIRECTION_NEGATIVE) == 0)) {
171+
if (goingUp && ((scrollDirections & DIRECTION_POSITIVE) == 0)
172+
|| !goingUp && ((scrollDirections & DIRECTION_NEGATIVE) == 0)) {
170173
// Trying to re-init in an unsupported direction.
171174
return;
172175
}
@@ -243,7 +246,8 @@ public boolean onDrag(float displacement) {
243246
}
244247

245248
@Override
246-
public void onDragEnd(float velocity, boolean fling) {
249+
public void onDragEnd(float velocity) {
250+
boolean fling = mDetector.isFling(velocity);
247251
final boolean goingToEnd;
248252
final int logAction;
249253
boolean blockedFling = fling && mFlingBlockCheck.isBlocked();
@@ -260,7 +264,7 @@ public void onDragEnd(float velocity, boolean fling) {
260264
logAction = Touch.SWIPE;
261265
goingToEnd = interpolatedProgress > SUCCESS_TRANSITION_PROGRESS;
262266
}
263-
long animationDuration = SwipeDetector.calculateDuration(
267+
long animationDuration = BaseSwipeDetector.calculateDuration(
264268
velocity, goingToEnd ? (1 - progress) : progress);
265269
if (blockedFling && !goingToEnd) {
266270
animationDuration *= LauncherAnimUtils.blockedFlingDurationFactor(velocity);

quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/TransposedQuickSwitchTouchController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
import com.android.launcher3.Launcher;
1919
import com.android.launcher3.LauncherState;
20-
import com.android.launcher3.touch.SwipeDetector;
20+
import com.android.launcher3.touch.SingleAxisSwipeDetector;
2121

2222
public class TransposedQuickSwitchTouchController extends QuickSwitchTouchController {
2323

2424
public TransposedQuickSwitchTouchController(Launcher launcher) {
25-
super(launcher, SwipeDetector.VERTICAL);
25+
super(launcher, SingleAxisSwipeDetector.VERTICAL);
2626
}
2727

2828
@Override

quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/LandscapeEdgeSwipeController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.android.launcher3.LauncherState;
1212
import com.android.launcher3.LauncherStateManager.AnimationComponents;
1313
import com.android.launcher3.touch.AbstractStateChangeTouchController;
14-
import com.android.launcher3.touch.SwipeDetector;
14+
import com.android.launcher3.touch.SingleAxisSwipeDetector;
1515
import com.android.launcher3.userevent.nano.LauncherLogProto;
1616
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
1717
import com.android.quickstep.RecentsModel;
@@ -24,7 +24,7 @@ public class LandscapeEdgeSwipeController extends AbstractStateChangeTouchContro
2424
private static final String TAG = "LandscapeEdgeSwipeCtrl";
2525

2626
public LandscapeEdgeSwipeController(Launcher l) {
27-
super(l, SwipeDetector.HORIZONTAL);
27+
super(l, SingleAxisSwipeDetector.HORIZONTAL);
2828
}
2929

3030
@Override

quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/PortraitStatesTouchController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import com.android.launcher3.anim.AnimatorSetBuilder;
4444
import com.android.launcher3.anim.Interpolators;
4545
import com.android.launcher3.touch.AbstractStateChangeTouchController;
46-
import com.android.launcher3.touch.SwipeDetector;
46+
import com.android.launcher3.touch.SingleAxisSwipeDetector;
4747
import com.android.launcher3.uioverrides.states.OverviewState;
4848
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
4949
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@@ -79,7 +79,7 @@ public class PortraitStatesTouchController extends AbstractStateChangeTouchContr
7979
private boolean mFinishFastOnSecondTouch;
8080

8181
public PortraitStatesTouchController(Launcher l, boolean allowDragToOverview) {
82-
super(l, SwipeDetector.VERTICAL);
82+
super(l, SingleAxisSwipeDetector.VERTICAL);
8383
mOverviewPortraitStateTouchHelper = new PortraitOverviewStateTouchHelper(l);
8484
mAllowDragToOverview = allowDragToOverview;
8585
}

src/com/android/launcher3/notification/NotificationItemView.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.android.launcher3.notification;
1818

19-
import static com.android.launcher3.touch.SwipeDetector.HORIZONTAL;
19+
import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL;
2020

2121
import android.app.Notification;
2222
import android.content.Context;
@@ -30,7 +30,7 @@
3030
import com.android.launcher3.R;
3131
import com.android.launcher3.graphics.IconPalette;
3232
import com.android.launcher3.popup.PopupContainerWithArrow;
33-
import com.android.launcher3.touch.SwipeDetector;
33+
import com.android.launcher3.touch.SingleAxisSwipeDetector;
3434
import com.android.launcher3.util.Themes;
3535

3636
import java.util.List;
@@ -49,7 +49,7 @@ public class NotificationItemView {
4949
private final TextView mHeaderCount;
5050
private final NotificationMainView mMainView;
5151
private final NotificationFooterLayout mFooter;
52-
private final SwipeDetector mSwipeDetector;
52+
private final SingleAxisSwipeDetector mSwipeDetector;
5353
private final View mIconView;
5454

5555
private final View mHeader;
@@ -74,8 +74,8 @@ public NotificationItemView(PopupContainerWithArrow container) {
7474
mHeader = container.findViewById(R.id.header);
7575
mDivider = container.findViewById(R.id.divider);
7676

77-
mSwipeDetector = new SwipeDetector(mContext, mMainView, HORIZONTAL);
78-
mSwipeDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_BOTH, false);
77+
mSwipeDetector = new SingleAxisSwipeDetector(mContext, mMainView, HORIZONTAL);
78+
mSwipeDetector.setDetectableScrollConditions(SingleAxisSwipeDetector.DIRECTION_BOTH, false);
7979
mMainView.setSwipeDetector(mSwipeDetector);
8080
mFooter.setContainer(this);
8181
}

src/com/android/launcher3/notification/NotificationMainView.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
import com.android.launcher3.Launcher;
3939
import com.android.launcher3.R;
4040
import com.android.launcher3.anim.AnimationSuccessListener;
41+
import com.android.launcher3.touch.BaseSwipeDetector;
4142
import com.android.launcher3.touch.OverScroll;
42-
import com.android.launcher3.touch.SwipeDetector;
43+
import com.android.launcher3.touch.SingleAxisSwipeDetector;
4344
import com.android.launcher3.userevent.nano.LauncherLogProto;
4445
import com.android.launcher3.util.Themes;
4546

@@ -48,7 +49,7 @@
4849
* e.g. icon + title + text.
4950
*/
5051
@TargetApi(Build.VERSION_CODES.N)
51-
public class NotificationMainView extends FrameLayout implements SwipeDetector.Listener {
52+
public class NotificationMainView extends FrameLayout implements SingleAxisSwipeDetector.Listener {
5253

5354
private static FloatProperty<NotificationMainView> CONTENT_TRANSLATION =
5455
new FloatProperty<NotificationMainView>("contentTranslation") {
@@ -75,7 +76,7 @@ public Float get(NotificationMainView view) {
7576
private TextView mTextView;
7677
private View mIconView;
7778

78-
private SwipeDetector mSwipeDetector;
79+
private SingleAxisSwipeDetector mSwipeDetector;
7980

8081
public NotificationMainView(Context context) {
8182
this(context, null, 0);
@@ -107,7 +108,7 @@ protected void onFinishInflate() {
107108
mIconView = findViewById(R.id.popup_item_icon);
108109
}
109110

110-
public void setSwipeDetector(SwipeDetector swipeDetector) {
111+
public void setSwipeDetector(SingleAxisSwipeDetector swipeDetector) {
111112
mSwipeDetector = swipeDetector;
112113
}
113114

@@ -173,7 +174,7 @@ public void onChildDismissed() {
173174
LauncherLogProto.ItemType.NOTIFICATION);
174175
}
175176

176-
// SwipeDetector.Listener's
177+
// SingleAxisSwipeDetector.Listener's
177178
@Override
178179
public void onDragStart(boolean start) { }
179180

@@ -187,15 +188,15 @@ public boolean onDrag(float displacement) {
187188
}
188189

189190
@Override
190-
public void onDragEnd(float velocity, boolean fling) {
191+
public void onDragEnd(float velocity) {
191192
final boolean willExit;
192193
final float endTranslation;
193194
final float startTranslation = mTextAndBackground.getTranslationX();
194195

195196
if (!canChildBeDismissed()) {
196197
willExit = false;
197198
endTranslation = 0;
198-
} else if (fling) {
199+
} else if (mSwipeDetector.isFling(velocity)) {
199200
willExit = true;
200201
endTranslation = velocity < 0 ? - getWidth() : getWidth();
201202
} else if (Math.abs(startTranslation) > getWidth() / 2) {
@@ -206,7 +207,7 @@ public void onDragEnd(float velocity, boolean fling) {
206207
endTranslation = 0;
207208
}
208209

209-
long duration = SwipeDetector.calculateDuration(velocity,
210+
long duration = BaseSwipeDetector.calculateDuration(velocity,
210211
(endTranslation - startTranslation) / getWidth());
211212

212213
mContentTranslateAnimator.removeAllListeners();

0 commit comments

Comments
 (0)