Loading core/java/android/window/BackMotionEvent.java +0 −34 Original line number Diff line number Diff line Loading @@ -34,8 +34,6 @@ public final class BackMotionEvent implements Parcelable { private final float mTouchX; private final float mTouchY; private final float mProgress; private final float mVelocityX; private final float mVelocityY; private final boolean mTriggerBack; @BackEvent.SwipeEdge Loading @@ -51,10 +49,6 @@ public final class BackMotionEvent implements Parcelable { * @param touchX Absolute X location of the touch point of this event. * @param touchY Absolute Y location of the touch point of this event. * @param progress Value between 0 and 1 on how far along the back gesture is. * @param velocityX X velocity computed from the touch point of this event. * Value in pixels/second. {@link Float#NaN} if was not computed. * @param velocityY Y velocity computed from the touch point of this event. * Value in pixels/second. {@link Float#NaN} if was not computed. * @param triggerBack Indicates whether the back arrow is in the triggered state or not * @param swipeEdge Indicates which edge the swipe starts from. * @param departingAnimationTarget The remote animation target of the departing Loading @@ -64,16 +58,12 @@ public final class BackMotionEvent implements Parcelable { float touchX, float touchY, float progress, float velocityX, float velocityY, boolean triggerBack, @BackEvent.SwipeEdge int swipeEdge, @Nullable RemoteAnimationTarget departingAnimationTarget) { mTouchX = touchX; mTouchY = touchY; mProgress = progress; mVelocityX = velocityX; mVelocityY = velocityY; mTriggerBack = triggerBack; mSwipeEdge = swipeEdge; mDepartingAnimationTarget = departingAnimationTarget; Loading @@ -83,8 +73,6 @@ public final class BackMotionEvent implements Parcelable { mTouchX = in.readFloat(); mTouchY = in.readFloat(); mProgress = in.readFloat(); mVelocityX = in.readFloat(); mVelocityY = in.readFloat(); mTriggerBack = in.readBoolean(); mSwipeEdge = in.readInt(); mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR); Loading Loading @@ -113,8 +101,6 @@ public final class BackMotionEvent implements Parcelable { dest.writeFloat(mTouchX); dest.writeFloat(mTouchY); dest.writeFloat(mProgress); dest.writeFloat(mVelocityX); dest.writeFloat(mVelocityY); dest.writeBoolean(mTriggerBack); dest.writeInt(mSwipeEdge); dest.writeTypedObject(mDepartingAnimationTarget, flags); Loading Loading @@ -144,24 +130,6 @@ public final class BackMotionEvent implements Parcelable { return mProgress; } /** * Returns the X velocity computed from the touch point. * * @return value in pixels/second or {@link Float#NaN} if was not computed. */ public float getVelocityX() { return mVelocityX; } /** * Returns the Y velocity computed from the touch point. * * @return value in pixels/second or {@link Float#NaN} if was not computed. */ public float getVelocityY() { return mVelocityY; } /** * Returns whether the back arrow is in the triggered state or not * Loading Loading @@ -195,8 +163,6 @@ public final class BackMotionEvent implements Parcelable { + "mTouchX=" + mTouchX + ", mTouchY=" + mTouchY + ", mProgress=" + mProgress + ", mVelocityX=" + mVelocityX + ", mVelocityY=" + mVelocityY + ", mTriggerBack=" + mTriggerBack + ", mSwipeEdge" + mSwipeEdge + ", mDepartingAnimationTarget" + mDepartingAnimationTarget Loading core/java/android/window/BackTouchTracker.java +1 −9 Original line number Diff line number Diff line Loading @@ -48,8 +48,6 @@ public class BackTouchTracker { */ private float mInitTouchX; private float mInitTouchY; private float mLatestVelocityX; private float mLatestVelocityY; private float mStartThresholdX; private int mSwipeEdge; private boolean mShouldUpdateStartLocation = false; Loading @@ -58,7 +56,7 @@ public class BackTouchTracker { /** * Updates the tracker with a new motion event. */ public void update(float touchX, float touchY, float velocityX, float velocityY) { public void update(float touchX, float touchY) { /** * If back was previously cancelled but the user has started swiping in the forward * direction again, restart back. Loading @@ -73,8 +71,6 @@ public class BackTouchTracker { } mLatestTouchX = touchX; mLatestTouchY = touchY; mLatestVelocityX = velocityX; mLatestVelocityY = velocityY; } /** Sets whether the back gesture is past the trigger threshold. */ Loading Loading @@ -156,8 +152,6 @@ public class BackTouchTracker { /* touchX = */ mInitTouchX, /* touchY = */ mInitTouchY, /* progress = */ 0, /* velocityX = */ 0, /* velocityY = */ 0, /* triggerBack = */ mTriggerBack, /* swipeEdge = */ mSwipeEdge, /* departingAnimationTarget = */ target); Loading Loading @@ -242,8 +236,6 @@ public class BackTouchTracker { /* touchX = */ mLatestTouchX, /* touchY = */ mLatestTouchY, /* progress = */ progress, /* velocityX = */ mLatestVelocityX, /* velocityY = */ mLatestVelocityY, /* triggerBack = */ mTriggerBack, /* swipeEdge = */ mSwipeEdge, /* departingAnimationTarget = */ null); Loading core/java/android/window/ImeOnBackInvokedDispatcher.java +2 −2 Original line number Diff line number Diff line Loading @@ -237,7 +237,7 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc try { mIOnBackInvokedCallback.onBackStarted( new BackMotionEvent(backEvent.getTouchX(), backEvent.getTouchY(), backEvent.getProgress(), 0f, 0f, false, backEvent.getSwipeEdge(), backEvent.getProgress(), false, backEvent.getSwipeEdge(), null)); } catch (RemoteException e) { Log.e(TAG, "Exception when invoking forwarded callback. e: ", e); Loading @@ -249,7 +249,7 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc try { mIOnBackInvokedCallback.onBackProgressed( new BackMotionEvent(backEvent.getTouchX(), backEvent.getTouchY(), backEvent.getProgress(), 0f, 0f, false, backEvent.getSwipeEdge(), backEvent.getProgress(), false, backEvent.getSwipeEdge(), null)); } catch (RemoteException e) { Log.e(TAG, "Exception when invoking forwarded callback. e: ", e); Loading core/java/android/window/WindowOnBackInvokedDispatcher.java +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { if (!isBackGestureInProgress() || ev == null || ev.getAction() != MotionEvent.ACTION_MOVE) { return; } mTouchTracker.update(ev.getX(), ev.getY(), Float.NaN, Float.NaN); mTouchTracker.update(ev.getX(), ev.getY()); if (mTouchTracker.shouldUpdateStartLocation()) { // Reset the start location on the first event after starting back, so that // the beginning of the animation feels smooth. Loading core/tests/coretests/src/android/window/BackTouchTrackerTest.kt +24 −33 Original line number Diff line number Diff line Loading @@ -46,45 +46,43 @@ class BackTouchTrackerTest { val linearTracker = linearTouchTracker() linearTracker.setGestureStartLocation(INITIAL_X_LEFT_EDGE, 0f, BackEvent.EDGE_LEFT) var touchX = 10f val velocityX = 0f val velocityY = 0f // Pre-commit linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / MAX_DISTANCE) // Post-commit touchX += 100f linearTracker.setTriggerBack(true) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / MAX_DISTANCE) // Cancel touchX -= 10f linearTracker.setTriggerBack(false) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // Cancel more touchX -= 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // Restarted, but pre-commit val restartX = touchX touchX += 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - restartX) / MAX_DISTANCE) // continue restart within pre-commit touchX += 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - restartX) / MAX_DISTANCE) // Restarted, post-commit touchX += 10f linearTracker.setTriggerBack(true) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / MAX_DISTANCE) } Loading @@ -93,46 +91,44 @@ class BackTouchTrackerTest { val linearTracker = linearTouchTracker() linearTracker.setGestureStartLocation(INITIAL_X_RIGHT_EDGE, 0f, BackEvent.EDGE_RIGHT) var touchX = INITIAL_X_RIGHT_EDGE - 10 // Fake right edge val velocityX = 0f val velocityY = 0f val target = MAX_DISTANCE // Pre-commit linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((INITIAL_X_RIGHT_EDGE - touchX) / target) // Post-commit touchX -= 100f linearTracker.setTriggerBack(true) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((INITIAL_X_RIGHT_EDGE - touchX) / target) // Cancel touchX += 10f linearTracker.setTriggerBack(false) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // Cancel more touchX += 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // Restarted, but pre-commit val restartX = touchX touchX -= 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((restartX - touchX) / target) // continue restart within pre-commit touchX -= 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((restartX - touchX) / target) // Restarted, post-commit touchX -= 10f linearTracker.setTriggerBack(true) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((INITIAL_X_RIGHT_EDGE - touchX) / target) } Loading @@ -141,28 +137,26 @@ class BackTouchTrackerTest { val nonLinearTracker = nonLinearTouchTracker() nonLinearTracker.setGestureStartLocation(INITIAL_X_LEFT_EDGE, 0f, BackEvent.EDGE_LEFT) var touchX = 10f val velocityX = 0f val velocityY = 0f val linearTarget = LINEAR_DISTANCE + (MAX_DISTANCE - LINEAR_DISTANCE) * NON_LINEAR_FACTOR // Pre-commit: linear progress nonLinearTracker.update(touchX, 0f, velocityX, velocityY) nonLinearTracker.update(touchX, 0f) nonLinearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / linearTarget) // Post-commit: still linear progress touchX += 100f nonLinearTracker.setTriggerBack(true) nonLinearTracker.update(touchX, 0f, velocityX, velocityY) nonLinearTracker.update(touchX, 0f) nonLinearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / linearTarget) // still linear progress touchX = INITIAL_X_LEFT_EDGE + LINEAR_DISTANCE nonLinearTracker.update(touchX, 0f, velocityX, velocityY) nonLinearTracker.update(touchX, 0f) nonLinearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / linearTarget) // non linear progress touchX += 10 nonLinearTracker.update(touchX, 0f, velocityX, velocityY) nonLinearTracker.update(touchX, 0f) val nonLinearTouch = (touchX - INITIAL_X_LEFT_EDGE) - LINEAR_DISTANCE val nonLinearProgress = nonLinearTouch / NON_LINEAR_DISTANCE val nonLinearTarget = MathUtils.lerp(linearTarget, MAX_DISTANCE, nonLinearProgress) Loading @@ -178,7 +172,7 @@ class BackTouchTrackerTest { val velocityY = 0f // assert that progress is increased when increasing touchX linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / MAX_DISTANCE) // assert that progress is reset to 0 when start location is updated Loading @@ -187,13 +181,13 @@ class BackTouchTrackerTest { // assert that progress remains 0 when touchX is decreased touchX -= 50 linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // assert that progress uses new minimal touchX for progress calculation val newInitialTouchX = touchX touchX += 100 linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - newInitialTouchX) / MAX_DISTANCE) // assert the same for triggerBack==true Loading @@ -207,11 +201,8 @@ class BackTouchTrackerTest { linearTracker.setGestureStartLocation(INITIAL_X_RIGHT_EDGE, 0f, BackEvent.EDGE_RIGHT) var touchX = INITIAL_X_RIGHT_EDGE - 100f val velocityX = 0f val velocityY = 0f // assert that progress is increased when decreasing touchX linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((INITIAL_X_RIGHT_EDGE - touchX) / MAX_DISTANCE) // assert that progress is reset to 0 when start location is updated Loading @@ -220,13 +211,13 @@ class BackTouchTrackerTest { // assert that progress remains 0 when touchX is increased touchX += 50 linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // assert that progress uses new maximal touchX for progress calculation val newInitialTouchX = touchX touchX -= 100 linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((newInitialTouchX - touchX) / MAX_DISTANCE) // assert the same for triggerBack==true Loading Loading
core/java/android/window/BackMotionEvent.java +0 −34 Original line number Diff line number Diff line Loading @@ -34,8 +34,6 @@ public final class BackMotionEvent implements Parcelable { private final float mTouchX; private final float mTouchY; private final float mProgress; private final float mVelocityX; private final float mVelocityY; private final boolean mTriggerBack; @BackEvent.SwipeEdge Loading @@ -51,10 +49,6 @@ public final class BackMotionEvent implements Parcelable { * @param touchX Absolute X location of the touch point of this event. * @param touchY Absolute Y location of the touch point of this event. * @param progress Value between 0 and 1 on how far along the back gesture is. * @param velocityX X velocity computed from the touch point of this event. * Value in pixels/second. {@link Float#NaN} if was not computed. * @param velocityY Y velocity computed from the touch point of this event. * Value in pixels/second. {@link Float#NaN} if was not computed. * @param triggerBack Indicates whether the back arrow is in the triggered state or not * @param swipeEdge Indicates which edge the swipe starts from. * @param departingAnimationTarget The remote animation target of the departing Loading @@ -64,16 +58,12 @@ public final class BackMotionEvent implements Parcelable { float touchX, float touchY, float progress, float velocityX, float velocityY, boolean triggerBack, @BackEvent.SwipeEdge int swipeEdge, @Nullable RemoteAnimationTarget departingAnimationTarget) { mTouchX = touchX; mTouchY = touchY; mProgress = progress; mVelocityX = velocityX; mVelocityY = velocityY; mTriggerBack = triggerBack; mSwipeEdge = swipeEdge; mDepartingAnimationTarget = departingAnimationTarget; Loading @@ -83,8 +73,6 @@ public final class BackMotionEvent implements Parcelable { mTouchX = in.readFloat(); mTouchY = in.readFloat(); mProgress = in.readFloat(); mVelocityX = in.readFloat(); mVelocityY = in.readFloat(); mTriggerBack = in.readBoolean(); mSwipeEdge = in.readInt(); mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR); Loading Loading @@ -113,8 +101,6 @@ public final class BackMotionEvent implements Parcelable { dest.writeFloat(mTouchX); dest.writeFloat(mTouchY); dest.writeFloat(mProgress); dest.writeFloat(mVelocityX); dest.writeFloat(mVelocityY); dest.writeBoolean(mTriggerBack); dest.writeInt(mSwipeEdge); dest.writeTypedObject(mDepartingAnimationTarget, flags); Loading Loading @@ -144,24 +130,6 @@ public final class BackMotionEvent implements Parcelable { return mProgress; } /** * Returns the X velocity computed from the touch point. * * @return value in pixels/second or {@link Float#NaN} if was not computed. */ public float getVelocityX() { return mVelocityX; } /** * Returns the Y velocity computed from the touch point. * * @return value in pixels/second or {@link Float#NaN} if was not computed. */ public float getVelocityY() { return mVelocityY; } /** * Returns whether the back arrow is in the triggered state or not * Loading Loading @@ -195,8 +163,6 @@ public final class BackMotionEvent implements Parcelable { + "mTouchX=" + mTouchX + ", mTouchY=" + mTouchY + ", mProgress=" + mProgress + ", mVelocityX=" + mVelocityX + ", mVelocityY=" + mVelocityY + ", mTriggerBack=" + mTriggerBack + ", mSwipeEdge" + mSwipeEdge + ", mDepartingAnimationTarget" + mDepartingAnimationTarget Loading
core/java/android/window/BackTouchTracker.java +1 −9 Original line number Diff line number Diff line Loading @@ -48,8 +48,6 @@ public class BackTouchTracker { */ private float mInitTouchX; private float mInitTouchY; private float mLatestVelocityX; private float mLatestVelocityY; private float mStartThresholdX; private int mSwipeEdge; private boolean mShouldUpdateStartLocation = false; Loading @@ -58,7 +56,7 @@ public class BackTouchTracker { /** * Updates the tracker with a new motion event. */ public void update(float touchX, float touchY, float velocityX, float velocityY) { public void update(float touchX, float touchY) { /** * If back was previously cancelled but the user has started swiping in the forward * direction again, restart back. Loading @@ -73,8 +71,6 @@ public class BackTouchTracker { } mLatestTouchX = touchX; mLatestTouchY = touchY; mLatestVelocityX = velocityX; mLatestVelocityY = velocityY; } /** Sets whether the back gesture is past the trigger threshold. */ Loading Loading @@ -156,8 +152,6 @@ public class BackTouchTracker { /* touchX = */ mInitTouchX, /* touchY = */ mInitTouchY, /* progress = */ 0, /* velocityX = */ 0, /* velocityY = */ 0, /* triggerBack = */ mTriggerBack, /* swipeEdge = */ mSwipeEdge, /* departingAnimationTarget = */ target); Loading Loading @@ -242,8 +236,6 @@ public class BackTouchTracker { /* touchX = */ mLatestTouchX, /* touchY = */ mLatestTouchY, /* progress = */ progress, /* velocityX = */ mLatestVelocityX, /* velocityY = */ mLatestVelocityY, /* triggerBack = */ mTriggerBack, /* swipeEdge = */ mSwipeEdge, /* departingAnimationTarget = */ null); Loading
core/java/android/window/ImeOnBackInvokedDispatcher.java +2 −2 Original line number Diff line number Diff line Loading @@ -237,7 +237,7 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc try { mIOnBackInvokedCallback.onBackStarted( new BackMotionEvent(backEvent.getTouchX(), backEvent.getTouchY(), backEvent.getProgress(), 0f, 0f, false, backEvent.getSwipeEdge(), backEvent.getProgress(), false, backEvent.getSwipeEdge(), null)); } catch (RemoteException e) { Log.e(TAG, "Exception when invoking forwarded callback. e: ", e); Loading @@ -249,7 +249,7 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc try { mIOnBackInvokedCallback.onBackProgressed( new BackMotionEvent(backEvent.getTouchX(), backEvent.getTouchY(), backEvent.getProgress(), 0f, 0f, false, backEvent.getSwipeEdge(), backEvent.getProgress(), false, backEvent.getSwipeEdge(), null)); } catch (RemoteException e) { Log.e(TAG, "Exception when invoking forwarded callback. e: ", e); Loading
core/java/android/window/WindowOnBackInvokedDispatcher.java +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { if (!isBackGestureInProgress() || ev == null || ev.getAction() != MotionEvent.ACTION_MOVE) { return; } mTouchTracker.update(ev.getX(), ev.getY(), Float.NaN, Float.NaN); mTouchTracker.update(ev.getX(), ev.getY()); if (mTouchTracker.shouldUpdateStartLocation()) { // Reset the start location on the first event after starting back, so that // the beginning of the animation feels smooth. Loading
core/tests/coretests/src/android/window/BackTouchTrackerTest.kt +24 −33 Original line number Diff line number Diff line Loading @@ -46,45 +46,43 @@ class BackTouchTrackerTest { val linearTracker = linearTouchTracker() linearTracker.setGestureStartLocation(INITIAL_X_LEFT_EDGE, 0f, BackEvent.EDGE_LEFT) var touchX = 10f val velocityX = 0f val velocityY = 0f // Pre-commit linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / MAX_DISTANCE) // Post-commit touchX += 100f linearTracker.setTriggerBack(true) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / MAX_DISTANCE) // Cancel touchX -= 10f linearTracker.setTriggerBack(false) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // Cancel more touchX -= 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // Restarted, but pre-commit val restartX = touchX touchX += 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - restartX) / MAX_DISTANCE) // continue restart within pre-commit touchX += 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - restartX) / MAX_DISTANCE) // Restarted, post-commit touchX += 10f linearTracker.setTriggerBack(true) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / MAX_DISTANCE) } Loading @@ -93,46 +91,44 @@ class BackTouchTrackerTest { val linearTracker = linearTouchTracker() linearTracker.setGestureStartLocation(INITIAL_X_RIGHT_EDGE, 0f, BackEvent.EDGE_RIGHT) var touchX = INITIAL_X_RIGHT_EDGE - 10 // Fake right edge val velocityX = 0f val velocityY = 0f val target = MAX_DISTANCE // Pre-commit linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((INITIAL_X_RIGHT_EDGE - touchX) / target) // Post-commit touchX -= 100f linearTracker.setTriggerBack(true) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((INITIAL_X_RIGHT_EDGE - touchX) / target) // Cancel touchX += 10f linearTracker.setTriggerBack(false) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // Cancel more touchX += 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // Restarted, but pre-commit val restartX = touchX touchX -= 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((restartX - touchX) / target) // continue restart within pre-commit touchX -= 10f linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((restartX - touchX) / target) // Restarted, post-commit touchX -= 10f linearTracker.setTriggerBack(true) linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((INITIAL_X_RIGHT_EDGE - touchX) / target) } Loading @@ -141,28 +137,26 @@ class BackTouchTrackerTest { val nonLinearTracker = nonLinearTouchTracker() nonLinearTracker.setGestureStartLocation(INITIAL_X_LEFT_EDGE, 0f, BackEvent.EDGE_LEFT) var touchX = 10f val velocityX = 0f val velocityY = 0f val linearTarget = LINEAR_DISTANCE + (MAX_DISTANCE - LINEAR_DISTANCE) * NON_LINEAR_FACTOR // Pre-commit: linear progress nonLinearTracker.update(touchX, 0f, velocityX, velocityY) nonLinearTracker.update(touchX, 0f) nonLinearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / linearTarget) // Post-commit: still linear progress touchX += 100f nonLinearTracker.setTriggerBack(true) nonLinearTracker.update(touchX, 0f, velocityX, velocityY) nonLinearTracker.update(touchX, 0f) nonLinearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / linearTarget) // still linear progress touchX = INITIAL_X_LEFT_EDGE + LINEAR_DISTANCE nonLinearTracker.update(touchX, 0f, velocityX, velocityY) nonLinearTracker.update(touchX, 0f) nonLinearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / linearTarget) // non linear progress touchX += 10 nonLinearTracker.update(touchX, 0f, velocityX, velocityY) nonLinearTracker.update(touchX, 0f) val nonLinearTouch = (touchX - INITIAL_X_LEFT_EDGE) - LINEAR_DISTANCE val nonLinearProgress = nonLinearTouch / NON_LINEAR_DISTANCE val nonLinearTarget = MathUtils.lerp(linearTarget, MAX_DISTANCE, nonLinearProgress) Loading @@ -178,7 +172,7 @@ class BackTouchTrackerTest { val velocityY = 0f // assert that progress is increased when increasing touchX linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - INITIAL_X_LEFT_EDGE) / MAX_DISTANCE) // assert that progress is reset to 0 when start location is updated Loading @@ -187,13 +181,13 @@ class BackTouchTrackerTest { // assert that progress remains 0 when touchX is decreased touchX -= 50 linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // assert that progress uses new minimal touchX for progress calculation val newInitialTouchX = touchX touchX += 100 linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((touchX - newInitialTouchX) / MAX_DISTANCE) // assert the same for triggerBack==true Loading @@ -207,11 +201,8 @@ class BackTouchTrackerTest { linearTracker.setGestureStartLocation(INITIAL_X_RIGHT_EDGE, 0f, BackEvent.EDGE_RIGHT) var touchX = INITIAL_X_RIGHT_EDGE - 100f val velocityX = 0f val velocityY = 0f // assert that progress is increased when decreasing touchX linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((INITIAL_X_RIGHT_EDGE - touchX) / MAX_DISTANCE) // assert that progress is reset to 0 when start location is updated Loading @@ -220,13 +211,13 @@ class BackTouchTrackerTest { // assert that progress remains 0 when touchX is increased touchX += 50 linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress(0f) // assert that progress uses new maximal touchX for progress calculation val newInitialTouchX = touchX touchX -= 100 linearTracker.update(touchX, 0f, velocityX, velocityY) linearTracker.update(touchX, 0f) linearTracker.assertProgress((newInitialTouchX - touchX) / MAX_DISTANCE) // assert the same for triggerBack==true Loading