Loading res/values/dimens.xml +3 −0 Original line number Diff line number Diff line Loading @@ -321,6 +321,9 @@ <!-- Size of the maximum radius for the enforced rounded rectangles. --> <dimen name="enforced_rounded_corner_max_radius">16dp</dimen> <!-- Base Swipe Detector, speed in dp/s --> <dimen name="base_swift_detector_fling_release_velocity">1dp</dimen> <!-- Overview placeholder to compile in Launcher3 without Quickstep --> <dimen name="task_thumbnail_icon_size">0dp</dimen> <dimen name="task_thumbnail_icon_drawable_size">0dp</dimen> Loading src/com/android/launcher3/touch/BaseSwipeDetector.java +12 −5 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.touch; import static android.view.MotionEvent.INVALID_POINTER_ID; import android.content.Context; import android.graphics.PointF; import android.util.Log; import android.view.MotionEvent; Loading @@ -26,6 +27,8 @@ import android.view.ViewConfiguration; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import com.android.launcher3.R; import java.util.LinkedList; import java.util.Queue; Loading @@ -44,10 +47,9 @@ public abstract class BaseSwipeDetector { private static final boolean DBG = false; private static final String TAG = "BaseSwipeDetector"; private static final float ANIMATION_DURATION = 1200; /** The minimum release velocity in pixels per millisecond that triggers fling.*/ private static final float RELEASE_VELOCITY_PX_MS = 1.0f; private static final PointF sTempPoint = new PointF(); private final float mReleaseVelocity; private final PointF mDownPos = new PointF(); private final PointF mLastPos = new PointF(); protected final boolean mIsRtl; Loading @@ -64,6 +66,7 @@ public abstract class BaseSwipeDetector { private boolean mIsSettingState; protected boolean mIgnoreSlopWhenSettling; protected Context mContext; private enum ScrollState { IDLE, Loading @@ -71,10 +74,14 @@ public abstract class BaseSwipeDetector { SETTLING // onDragEnd } protected BaseSwipeDetector(@NonNull ViewConfiguration config, boolean isRtl) { protected BaseSwipeDetector(@NonNull Context context, @NonNull ViewConfiguration config, boolean isRtl) { mTouchSlop = config.getScaledTouchSlop(); mMaxVelocity = config.getScaledMaximumFlingVelocity(); mIsRtl = isRtl; mContext = context; mReleaseVelocity = mContext.getResources() .getDimensionPixelSize(R.dimen.base_swift_detector_fling_release_velocity); } public static long calculateDuration(float velocity, float progressNeeded) { Loading Loading @@ -120,7 +127,7 @@ public abstract class BaseSwipeDetector { } public boolean isFling(float velocity) { return Math.abs(velocity) > RELEASE_VELOCITY_PX_MS; return Math.abs(velocity) > mReleaseVelocity; } public boolean onTouchEvent(MotionEvent ev) { Loading src/com/android/launcher3/touch/BothAxesSwipeDetector.java +1 −8 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.view.MotionEvent; import android.view.ViewConfiguration; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import com.android.launcher3.Utilities; Loading @@ -43,13 +42,7 @@ public class BothAxesSwipeDetector extends BaseSwipeDetector { private int mScrollDirections; public BothAxesSwipeDetector(@NonNull Context context, @NonNull Listener l) { this(ViewConfiguration.get(context), l, Utilities.isRtl(context.getResources())); } @VisibleForTesting protected BothAxesSwipeDetector(@NonNull ViewConfiguration config, @NonNull Listener l, boolean isRtl) { super(config, isRtl); super(context, ViewConfiguration.get(context), Utilities.isRtl(context.getResources())); mListener = l; } Loading src/com/android/launcher3/touch/SingleAxisSwipeDetector.java +6 −4 Original line number Diff line number Diff line Loading @@ -106,13 +106,15 @@ public class SingleAxisSwipeDetector extends BaseSwipeDetector { public SingleAxisSwipeDetector(@NonNull Context context, @NonNull Listener l, @NonNull Direction dir) { this(ViewConfiguration.get(context), l, dir, Utilities.isRtl(context.getResources())); super(context, ViewConfiguration.get(context), Utilities.isRtl(context.getResources())); mListener = l; mDir = dir; } @VisibleForTesting protected SingleAxisSwipeDetector(@NonNull ViewConfiguration config, @NonNull Listener l, @NonNull Direction dir, boolean isRtl) { super(config, isRtl); protected SingleAxisSwipeDetector(@NonNull Context context, @NonNull ViewConfiguration config, @NonNull Listener l, @NonNull Direction dir, boolean isRtl) { super(context, config, isRtl); mListener = l; mDir = dir; } Loading tests/src/com/android/launcher3/touch/SingleAxisSwipeDetectorTest.java +18 −9 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import android.content.Context; import android.util.Log; import android.view.MotionEvent; import android.view.ViewConfiguration; Loading Loading @@ -58,6 +59,7 @@ public class SingleAxisSwipeDetectorTest { private TouchEventGenerator mGenerator; private SingleAxisSwipeDetector mDetector; private int mTouchSlop; Context mContext; @Mock private SingleAxisSwipeDetector.Listener mMockListener; Loading @@ -69,12 +71,13 @@ public class SingleAxisSwipeDetectorTest { public void setup() { MockitoAnnotations.initMocks(this); mGenerator = new TouchEventGenerator((ev) -> mDetector.onTouchEvent(ev)); ViewConfiguration orgConfig = ViewConfiguration .get(InstrumentationRegistry.getTargetContext()); mContext = InstrumentationRegistry.getTargetContext(); ViewConfiguration orgConfig = ViewConfiguration.get(mContext); doReturn(orgConfig.getScaledMaximumFlingVelocity()).when(mMockConfig) .getScaledMaximumFlingVelocity(); mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, VERTICAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, VERTICAL, false); mDetector.setDetectableScrollConditions(DIRECTION_BOTH, false); mTouchSlop = orgConfig.getScaledTouchSlop(); doReturn(mTouchSlop).when(mMockConfig).getScaledTouchSlop(); Loading @@ -84,7 +87,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_verticalPositive() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, VERTICAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, VERTICAL, false); mDetector.setDetectableScrollConditions(DIRECTION_POSITIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100, 100 - mTouchSlop); Loading @@ -94,7 +98,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_verticalNegative() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, VERTICAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, VERTICAL, false); mDetector.setDetectableScrollConditions(DIRECTION_NEGATIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100, 100 + mTouchSlop); Loading @@ -112,7 +117,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_horizontalPositive() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, HORIZONTAL, false); mDetector.setDetectableScrollConditions(DIRECTION_POSITIVE, false); mGenerator.put(0, 100, 100); Loading @@ -123,7 +129,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_horizontalNegative() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, HORIZONTAL, false); mDetector.setDetectableScrollConditions(DIRECTION_NEGATIVE, false); mGenerator.put(0, 100, 100); Loading @@ -134,7 +141,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_horizontalRtlPositive() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, true); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, HORIZONTAL, true); mDetector.setDetectableScrollConditions(DIRECTION_POSITIVE, false); mGenerator.put(0, 100, 100); Loading @@ -145,7 +153,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_horizontalRtlNegative() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, true); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, HORIZONTAL, true); mDetector.setDetectableScrollConditions(DIRECTION_NEGATIVE, false); mGenerator.put(0, 100, 100); Loading Loading
res/values/dimens.xml +3 −0 Original line number Diff line number Diff line Loading @@ -321,6 +321,9 @@ <!-- Size of the maximum radius for the enforced rounded rectangles. --> <dimen name="enforced_rounded_corner_max_radius">16dp</dimen> <!-- Base Swipe Detector, speed in dp/s --> <dimen name="base_swift_detector_fling_release_velocity">1dp</dimen> <!-- Overview placeholder to compile in Launcher3 without Quickstep --> <dimen name="task_thumbnail_icon_size">0dp</dimen> <dimen name="task_thumbnail_icon_drawable_size">0dp</dimen> Loading
src/com/android/launcher3/touch/BaseSwipeDetector.java +12 −5 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.touch; import static android.view.MotionEvent.INVALID_POINTER_ID; import android.content.Context; import android.graphics.PointF; import android.util.Log; import android.view.MotionEvent; Loading @@ -26,6 +27,8 @@ import android.view.ViewConfiguration; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import com.android.launcher3.R; import java.util.LinkedList; import java.util.Queue; Loading @@ -44,10 +47,9 @@ public abstract class BaseSwipeDetector { private static final boolean DBG = false; private static final String TAG = "BaseSwipeDetector"; private static final float ANIMATION_DURATION = 1200; /** The minimum release velocity in pixels per millisecond that triggers fling.*/ private static final float RELEASE_VELOCITY_PX_MS = 1.0f; private static final PointF sTempPoint = new PointF(); private final float mReleaseVelocity; private final PointF mDownPos = new PointF(); private final PointF mLastPos = new PointF(); protected final boolean mIsRtl; Loading @@ -64,6 +66,7 @@ public abstract class BaseSwipeDetector { private boolean mIsSettingState; protected boolean mIgnoreSlopWhenSettling; protected Context mContext; private enum ScrollState { IDLE, Loading @@ -71,10 +74,14 @@ public abstract class BaseSwipeDetector { SETTLING // onDragEnd } protected BaseSwipeDetector(@NonNull ViewConfiguration config, boolean isRtl) { protected BaseSwipeDetector(@NonNull Context context, @NonNull ViewConfiguration config, boolean isRtl) { mTouchSlop = config.getScaledTouchSlop(); mMaxVelocity = config.getScaledMaximumFlingVelocity(); mIsRtl = isRtl; mContext = context; mReleaseVelocity = mContext.getResources() .getDimensionPixelSize(R.dimen.base_swift_detector_fling_release_velocity); } public static long calculateDuration(float velocity, float progressNeeded) { Loading Loading @@ -120,7 +127,7 @@ public abstract class BaseSwipeDetector { } public boolean isFling(float velocity) { return Math.abs(velocity) > RELEASE_VELOCITY_PX_MS; return Math.abs(velocity) > mReleaseVelocity; } public boolean onTouchEvent(MotionEvent ev) { Loading
src/com/android/launcher3/touch/BothAxesSwipeDetector.java +1 −8 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.view.MotionEvent; import android.view.ViewConfiguration; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import com.android.launcher3.Utilities; Loading @@ -43,13 +42,7 @@ public class BothAxesSwipeDetector extends BaseSwipeDetector { private int mScrollDirections; public BothAxesSwipeDetector(@NonNull Context context, @NonNull Listener l) { this(ViewConfiguration.get(context), l, Utilities.isRtl(context.getResources())); } @VisibleForTesting protected BothAxesSwipeDetector(@NonNull ViewConfiguration config, @NonNull Listener l, boolean isRtl) { super(config, isRtl); super(context, ViewConfiguration.get(context), Utilities.isRtl(context.getResources())); mListener = l; } Loading
src/com/android/launcher3/touch/SingleAxisSwipeDetector.java +6 −4 Original line number Diff line number Diff line Loading @@ -106,13 +106,15 @@ public class SingleAxisSwipeDetector extends BaseSwipeDetector { public SingleAxisSwipeDetector(@NonNull Context context, @NonNull Listener l, @NonNull Direction dir) { this(ViewConfiguration.get(context), l, dir, Utilities.isRtl(context.getResources())); super(context, ViewConfiguration.get(context), Utilities.isRtl(context.getResources())); mListener = l; mDir = dir; } @VisibleForTesting protected SingleAxisSwipeDetector(@NonNull ViewConfiguration config, @NonNull Listener l, @NonNull Direction dir, boolean isRtl) { super(config, isRtl); protected SingleAxisSwipeDetector(@NonNull Context context, @NonNull ViewConfiguration config, @NonNull Listener l, @NonNull Direction dir, boolean isRtl) { super(context, config, isRtl); mListener = l; mDir = dir; } Loading
tests/src/com/android/launcher3/touch/SingleAxisSwipeDetectorTest.java +18 −9 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import android.content.Context; import android.util.Log; import android.view.MotionEvent; import android.view.ViewConfiguration; Loading Loading @@ -58,6 +59,7 @@ public class SingleAxisSwipeDetectorTest { private TouchEventGenerator mGenerator; private SingleAxisSwipeDetector mDetector; private int mTouchSlop; Context mContext; @Mock private SingleAxisSwipeDetector.Listener mMockListener; Loading @@ -69,12 +71,13 @@ public class SingleAxisSwipeDetectorTest { public void setup() { MockitoAnnotations.initMocks(this); mGenerator = new TouchEventGenerator((ev) -> mDetector.onTouchEvent(ev)); ViewConfiguration orgConfig = ViewConfiguration .get(InstrumentationRegistry.getTargetContext()); mContext = InstrumentationRegistry.getTargetContext(); ViewConfiguration orgConfig = ViewConfiguration.get(mContext); doReturn(orgConfig.getScaledMaximumFlingVelocity()).when(mMockConfig) .getScaledMaximumFlingVelocity(); mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, VERTICAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, VERTICAL, false); mDetector.setDetectableScrollConditions(DIRECTION_BOTH, false); mTouchSlop = orgConfig.getScaledTouchSlop(); doReturn(mTouchSlop).when(mMockConfig).getScaledTouchSlop(); Loading @@ -84,7 +87,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_verticalPositive() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, VERTICAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, VERTICAL, false); mDetector.setDetectableScrollConditions(DIRECTION_POSITIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100, 100 - mTouchSlop); Loading @@ -94,7 +98,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_verticalNegative() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, VERTICAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, VERTICAL, false); mDetector.setDetectableScrollConditions(DIRECTION_NEGATIVE, false); mGenerator.put(0, 100, 100); mGenerator.move(0, 100, 100 + mTouchSlop); Loading @@ -112,7 +117,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_horizontalPositive() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, HORIZONTAL, false); mDetector.setDetectableScrollConditions(DIRECTION_POSITIVE, false); mGenerator.put(0, 100, 100); Loading @@ -123,7 +129,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_horizontalNegative() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, false); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, HORIZONTAL, false); mDetector.setDetectableScrollConditions(DIRECTION_NEGATIVE, false); mGenerator.put(0, 100, 100); Loading @@ -134,7 +141,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_horizontalRtlPositive() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, true); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, HORIZONTAL, true); mDetector.setDetectableScrollConditions(DIRECTION_POSITIVE, false); mGenerator.put(0, 100, 100); Loading @@ -145,7 +153,8 @@ public class SingleAxisSwipeDetectorTest { @Test public void testDragStart_horizontalRtlNegative() { mDetector = new SingleAxisSwipeDetector(mMockConfig, mMockListener, HORIZONTAL, true); mDetector = new SingleAxisSwipeDetector(mContext, mMockConfig, mMockListener, HORIZONTAL, true); mDetector.setDetectableScrollConditions(DIRECTION_NEGATIVE, false); mGenerator.put(0, 100, 100); Loading