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
This commit is contained in:
@@ -32,13 +32,14 @@ import com.android.launcher3.AbstractFloatingView;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.touch.SwipeDetector;
|
||||
import com.android.launcher3.touch.BaseSwipeDetector;
|
||||
import com.android.launcher3.touch.SingleAxisSwipeDetector;
|
||||
|
||||
/**
|
||||
* Extension of AbstractFloatingView with common methods for sliding in from bottom
|
||||
*/
|
||||
public abstract class AbstractSlideInView extends AbstractFloatingView
|
||||
implements SwipeDetector.Listener {
|
||||
implements SingleAxisSwipeDetector.Listener {
|
||||
|
||||
protected static Property<AbstractSlideInView, Float> TRANSLATION_SHIFT =
|
||||
new Property<AbstractSlideInView, Float>(Float.class, "translationShift") {
|
||||
@@ -57,7 +58,7 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
|
||||
protected static final float TRANSLATION_SHIFT_OPENED = 0f;
|
||||
|
||||
protected final Launcher mLauncher;
|
||||
protected final SwipeDetector mSwipeDetector;
|
||||
protected final SingleAxisSwipeDetector mSwipeDetector;
|
||||
protected final ObjectAnimator mOpenCloseAnimator;
|
||||
|
||||
protected View mContent;
|
||||
@@ -73,7 +74,8 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
|
||||
mLauncher = Launcher.getLauncher(context);
|
||||
|
||||
mScrollInterpolator = Interpolators.SCROLL_CUBIC;
|
||||
mSwipeDetector = new SwipeDetector(context, this, SwipeDetector.VERTICAL);
|
||||
mSwipeDetector = new SingleAxisSwipeDetector(context, this,
|
||||
SingleAxisSwipeDetector.VERTICAL);
|
||||
|
||||
mOpenCloseAnimator = ObjectAnimator.ofPropertyValuesHolder(this);
|
||||
mOpenCloseAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@@ -97,7 +99,7 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
|
||||
}
|
||||
|
||||
int directionsToDetectScroll = mSwipeDetector.isIdleState() ?
|
||||
SwipeDetector.DIRECTION_NEGATIVE : 0;
|
||||
SingleAxisSwipeDetector.DIRECTION_NEGATIVE : 0;
|
||||
mSwipeDetector.setDetectableScrollConditions(
|
||||
directionsToDetectScroll, false);
|
||||
mSwipeDetector.onTouchEvent(ev);
|
||||
@@ -122,7 +124,7 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
|
||||
return mIsOpen && mOpenCloseAnimator.isRunning();
|
||||
}
|
||||
|
||||
/* SwipeDetector.Listener */
|
||||
/* SingleAxisSwipeDetector.Listener */
|
||||
|
||||
@Override
|
||||
public void onDragStart(boolean start) { }
|
||||
@@ -136,17 +138,17 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDragEnd(float velocity, boolean fling) {
|
||||
if ((fling && velocity > 0) || mTranslationShift > 0.5f) {
|
||||
public void onDragEnd(float velocity) {
|
||||
if ((mSwipeDetector.isFling(velocity) && velocity > 0) || mTranslationShift > 0.5f) {
|
||||
mScrollInterpolator = scrollInterpolatorForVelocity(velocity);
|
||||
mOpenCloseAnimator.setDuration(SwipeDetector.calculateDuration(
|
||||
mOpenCloseAnimator.setDuration(BaseSwipeDetector.calculateDuration(
|
||||
velocity, TRANSLATION_SHIFT_CLOSED - mTranslationShift));
|
||||
close(true);
|
||||
} else {
|
||||
mOpenCloseAnimator.setValues(PropertyValuesHolder.ofFloat(
|
||||
TRANSLATION_SHIFT, TRANSLATION_SHIFT_OPENED));
|
||||
mOpenCloseAnimator.setDuration(
|
||||
SwipeDetector.calculateDuration(velocity, mTranslationShift))
|
||||
BaseSwipeDetector.calculateDuration(velocity, mTranslationShift))
|
||||
.setInterpolator(Interpolators.DEACCEL);
|
||||
mOpenCloseAnimator.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user