Loading core/api/current.txt +2 −0 Original line number Diff line number Diff line Loading @@ -61687,6 +61687,8 @@ package android.window { public final class BackEvent { ctor public BackEvent(float, float, float, int); ctor @FlaggedApi("com.android.window.flags.predictive_back_timestamp_api") public BackEvent(float, float, float, int, long); method @FlaggedApi("com.android.window.flags.predictive_back_timestamp_api") public long getFrameTime(); method @FloatRange(from=0, to=1) public float getProgress(); method public int getSwipeEdge(); method public float getTouchX(); core/java/android/window/BackEvent.java +45 −4 Original line number Diff line number Diff line Loading @@ -16,8 +16,13 @@ package android.window; import static com.android.window.flags.Flags.FLAG_PREDICTIVE_BACK_TIMESTAMP_API; import static com.android.window.flags.Flags.predictiveBackTimestampApi; import android.annotation.FlaggedApi; import android.annotation.FloatRange; import android.annotation.IntDef; import android.util.TimeUtils; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; Loading @@ -44,18 +49,25 @@ public final class BackEvent { private final float mTouchX; private final float mTouchY; private final float mProgress; private final long mFrameTime; @SwipeEdge private final int mSwipeEdge; /** @hide */ public static BackEvent fromBackMotionEvent(BackMotionEvent backMotionEvent) { if (predictiveBackTimestampApi()) { return new BackEvent(backMotionEvent.getTouchX(), backMotionEvent.getTouchY(), backMotionEvent.getProgress(), backMotionEvent.getSwipeEdge(), backMotionEvent.getFrameTime()); } else { return new BackEvent(backMotionEvent.getTouchX(), backMotionEvent.getTouchY(), backMotionEvent.getProgress(), backMotionEvent.getSwipeEdge()); } } /** * Creates a new {@link BackEvent} instance. * Creates a new {@link BackEvent} instance with the current uptime as frame time. * * @param touchX Absolute X location of the touch point of this event. * @param touchY Absolute Y location of the touch point of this event. Loading @@ -67,6 +79,26 @@ public final class BackEvent { mTouchY = touchY; mProgress = progress; mSwipeEdge = swipeEdge; mFrameTime = System.nanoTime() / TimeUtils.NANOS_PER_MS; } /** * Creates a new {@link BackEvent} instance. * * @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 swipeEdge Indicates which edge the swipe starts from. * @param frameTime frame time of the back event. */ @FlaggedApi(FLAG_PREDICTIVE_BACK_TIMESTAMP_API) public BackEvent(float touchX, float touchY, float progress, @SwipeEdge int swipeEdge, long frameTime) { mTouchX = touchX; mTouchY = touchY; mProgress = progress; mSwipeEdge = swipeEdge; mFrameTime = frameTime; } /** Loading Loading @@ -115,13 +147,22 @@ public final class BackEvent { return mSwipeEdge; } /** * Returns the frameTime of the BackEvent in milliseconds. Useful for calculating velocity. */ @FlaggedApi(FLAG_PREDICTIVE_BACK_TIMESTAMP_API) public long getFrameTime() { return mFrameTime; } @Override public String toString() { return "BackEvent{" + "mTouchX=" + mTouchX + ", mTouchY=" + mTouchY + ", mProgress=" + mProgress + ", mSwipeEdge" + mSwipeEdge + ", mSwipeEdge=" + mSwipeEdge + ", mFrameTime=" + mFrameTime + "ms" + "}"; } } core/java/android/window/BackMotionEvent.java +16 −2 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.view.RemoteAnimationTarget; public final class BackMotionEvent implements Parcelable { private final float mTouchX; private final float mTouchY; private final long mFrameTime; private final float mProgress; private final boolean mTriggerBack; Loading @@ -48,6 +49,7 @@ 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 frameTime Event time of the corresponding touch event. * @param progress Value between 0 and 1 on how far along the back gesture is. * @param triggerBack Indicates whether the back arrow is in the triggered state or not * @param swipeEdge Indicates which edge the swipe starts from. Loading @@ -57,12 +59,14 @@ public final class BackMotionEvent implements Parcelable { public BackMotionEvent( float touchX, float touchY, long frameTime, float progress, boolean triggerBack, @BackEvent.SwipeEdge int swipeEdge, @Nullable RemoteAnimationTarget departingAnimationTarget) { mTouchX = touchX; mTouchY = touchY; mFrameTime = frameTime; mProgress = progress; mTriggerBack = triggerBack; mSwipeEdge = swipeEdge; Loading @@ -76,6 +80,7 @@ public final class BackMotionEvent implements Parcelable { mTriggerBack = in.readBoolean(); mSwipeEdge = in.readInt(); mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR); mFrameTime = in.readLong(); } @NonNull Loading Loading @@ -104,6 +109,7 @@ public final class BackMotionEvent implements Parcelable { dest.writeBoolean(mTriggerBack); dest.writeInt(mSwipeEdge); dest.writeTypedObject(mDepartingAnimationTarget, flags); dest.writeLong(mFrameTime); } /** Loading Loading @@ -147,6 +153,13 @@ public final class BackMotionEvent implements Parcelable { return mSwipeEdge; } /** * Returns the frame time of the BackMotionEvent in milliseconds. */ public long getFrameTime() { return mFrameTime; } /** * Returns the {@link RemoteAnimationTarget} of the top departing application window, * or {@code null} if the top window should not be moved for the current type of back Loading @@ -162,10 +175,11 @@ public final class BackMotionEvent implements Parcelable { return "BackMotionEvent{" + "mTouchX=" + mTouchX + ", mTouchY=" + mTouchY + ", mFrameTime=" + mFrameTime + "ms" + ", mProgress=" + mProgress + ", mTriggerBack=" + mTriggerBack + ", mSwipeEdge" + mSwipeEdge + ", mDepartingAnimationTarget" + mDepartingAnimationTarget + ", mSwipeEdge=" + mSwipeEdge + ", mDepartingAnimationTarget=" + mDepartingAnimationTarget + "}"; } } core/java/android/window/BackProgressAnimator.java +21 −8 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.window; import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE; import static com.android.window.flags.Flags.predictiveBackTimestampApi; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -66,7 +67,8 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL reset(); }; private final DynamicAnimation.OnAnimationUpdateListener mOnBackInvokedFlingUpdateListener = (animation, progress, velocity) -> updateProgressValue(progress, velocity); (animation, progress, velocity) -> updateProgressValue(progress, velocity, animation.getLastFrameTime()); private void setProgress(float progress) { Loading @@ -92,7 +94,9 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL @Override public void onAnimationUpdate(DynamicAnimation animation, float value, float velocity) { if (mBackInvokedFinishRunnable == null) updateProgressValue(value, velocity); if (mBackInvokedFinishRunnable == null) { updateProgressValue(value, velocity, animation.getLastFrameTime()); } } Loading Loading @@ -137,7 +141,9 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL mLastBackEvent = event; mCallback = callback; mBackAnimationInProgress = true; updateProgressValue(0, 0); updateProgressValue(/* progress */ 0, /* velocity */ 0, /* frameTime */ System.nanoTime() / TimeUtils.NANOS_PER_MS); onBackProgressed(event); } /** Loading @@ -146,7 +152,8 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL public void reset() { if (mBackCancelledFinishRunnable != null) { // Ensure that last progress value that apps see is 0 updateProgressValue(0, 0); updateProgressValue(/* progress */ 0, /* velocity */ 0, /* frameTime */ System.nanoTime() / TimeUtils.NANOS_PER_MS); invokeBackCancelledRunnable(); } else if (mBackInvokedFinishRunnable != null) { invokeBackInvokedRunnable(); Loading Loading @@ -236,14 +243,20 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL return mVelocity / SCALE_FACTOR; } private void updateProgressValue(float progress, float velocity) { private void updateProgressValue(float progress, float velocity, long frameTime) { mVelocity = velocity; if (mLastBackEvent == null || mCallback == null || !mBackAnimationInProgress) { return; } mCallback.onProgressUpdate( new BackEvent(mLastBackEvent.getTouchX(), mLastBackEvent.getTouchY(), progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge())); BackEvent backEvent; if (predictiveBackTimestampApi()) { backEvent = new BackEvent(mLastBackEvent.getTouchX(), mLastBackEvent.getTouchY(), progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge(), frameTime); } else { backEvent = new BackEvent(mLastBackEvent.getTouchX(), mLastBackEvent.getTouchY(), progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge()); } mCallback.onProgressUpdate(backEvent); } private void invokeBackCancelledRunnable() { Loading core/java/android/window/BackTouchTracker.java +2 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,7 @@ public class BackTouchTracker { return new BackMotionEvent( /* touchX = */ mInitTouchX, /* touchY = */ mInitTouchY, /* frameTime = */ 0, /* progress = */ 0, /* triggerBack = */ mTriggerBack, /* swipeEdge = */ mSwipeEdge, Loading Loading @@ -235,6 +236,7 @@ public class BackTouchTracker { return new BackMotionEvent( /* touchX = */ mLatestTouchX, /* touchY = */ mLatestTouchY, /* frameTime = */ 0, /* progress = */ progress, /* triggerBack = */ mTriggerBack, /* swipeEdge = */ mSwipeEdge, Loading Loading
core/api/current.txt +2 −0 Original line number Diff line number Diff line Loading @@ -61687,6 +61687,8 @@ package android.window { public final class BackEvent { ctor public BackEvent(float, float, float, int); ctor @FlaggedApi("com.android.window.flags.predictive_back_timestamp_api") public BackEvent(float, float, float, int, long); method @FlaggedApi("com.android.window.flags.predictive_back_timestamp_api") public long getFrameTime(); method @FloatRange(from=0, to=1) public float getProgress(); method public int getSwipeEdge(); method public float getTouchX();
core/java/android/window/BackEvent.java +45 −4 Original line number Diff line number Diff line Loading @@ -16,8 +16,13 @@ package android.window; import static com.android.window.flags.Flags.FLAG_PREDICTIVE_BACK_TIMESTAMP_API; import static com.android.window.flags.Flags.predictiveBackTimestampApi; import android.annotation.FlaggedApi; import android.annotation.FloatRange; import android.annotation.IntDef; import android.util.TimeUtils; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; Loading @@ -44,18 +49,25 @@ public final class BackEvent { private final float mTouchX; private final float mTouchY; private final float mProgress; private final long mFrameTime; @SwipeEdge private final int mSwipeEdge; /** @hide */ public static BackEvent fromBackMotionEvent(BackMotionEvent backMotionEvent) { if (predictiveBackTimestampApi()) { return new BackEvent(backMotionEvent.getTouchX(), backMotionEvent.getTouchY(), backMotionEvent.getProgress(), backMotionEvent.getSwipeEdge(), backMotionEvent.getFrameTime()); } else { return new BackEvent(backMotionEvent.getTouchX(), backMotionEvent.getTouchY(), backMotionEvent.getProgress(), backMotionEvent.getSwipeEdge()); } } /** * Creates a new {@link BackEvent} instance. * Creates a new {@link BackEvent} instance with the current uptime as frame time. * * @param touchX Absolute X location of the touch point of this event. * @param touchY Absolute Y location of the touch point of this event. Loading @@ -67,6 +79,26 @@ public final class BackEvent { mTouchY = touchY; mProgress = progress; mSwipeEdge = swipeEdge; mFrameTime = System.nanoTime() / TimeUtils.NANOS_PER_MS; } /** * Creates a new {@link BackEvent} instance. * * @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 swipeEdge Indicates which edge the swipe starts from. * @param frameTime frame time of the back event. */ @FlaggedApi(FLAG_PREDICTIVE_BACK_TIMESTAMP_API) public BackEvent(float touchX, float touchY, float progress, @SwipeEdge int swipeEdge, long frameTime) { mTouchX = touchX; mTouchY = touchY; mProgress = progress; mSwipeEdge = swipeEdge; mFrameTime = frameTime; } /** Loading Loading @@ -115,13 +147,22 @@ public final class BackEvent { return mSwipeEdge; } /** * Returns the frameTime of the BackEvent in milliseconds. Useful for calculating velocity. */ @FlaggedApi(FLAG_PREDICTIVE_BACK_TIMESTAMP_API) public long getFrameTime() { return mFrameTime; } @Override public String toString() { return "BackEvent{" + "mTouchX=" + mTouchX + ", mTouchY=" + mTouchY + ", mProgress=" + mProgress + ", mSwipeEdge" + mSwipeEdge + ", mSwipeEdge=" + mSwipeEdge + ", mFrameTime=" + mFrameTime + "ms" + "}"; } }
core/java/android/window/BackMotionEvent.java +16 −2 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.view.RemoteAnimationTarget; public final class BackMotionEvent implements Parcelable { private final float mTouchX; private final float mTouchY; private final long mFrameTime; private final float mProgress; private final boolean mTriggerBack; Loading @@ -48,6 +49,7 @@ 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 frameTime Event time of the corresponding touch event. * @param progress Value between 0 and 1 on how far along the back gesture is. * @param triggerBack Indicates whether the back arrow is in the triggered state or not * @param swipeEdge Indicates which edge the swipe starts from. Loading @@ -57,12 +59,14 @@ public final class BackMotionEvent implements Parcelable { public BackMotionEvent( float touchX, float touchY, long frameTime, float progress, boolean triggerBack, @BackEvent.SwipeEdge int swipeEdge, @Nullable RemoteAnimationTarget departingAnimationTarget) { mTouchX = touchX; mTouchY = touchY; mFrameTime = frameTime; mProgress = progress; mTriggerBack = triggerBack; mSwipeEdge = swipeEdge; Loading @@ -76,6 +80,7 @@ public final class BackMotionEvent implements Parcelable { mTriggerBack = in.readBoolean(); mSwipeEdge = in.readInt(); mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR); mFrameTime = in.readLong(); } @NonNull Loading Loading @@ -104,6 +109,7 @@ public final class BackMotionEvent implements Parcelable { dest.writeBoolean(mTriggerBack); dest.writeInt(mSwipeEdge); dest.writeTypedObject(mDepartingAnimationTarget, flags); dest.writeLong(mFrameTime); } /** Loading Loading @@ -147,6 +153,13 @@ public final class BackMotionEvent implements Parcelable { return mSwipeEdge; } /** * Returns the frame time of the BackMotionEvent in milliseconds. */ public long getFrameTime() { return mFrameTime; } /** * Returns the {@link RemoteAnimationTarget} of the top departing application window, * or {@code null} if the top window should not be moved for the current type of back Loading @@ -162,10 +175,11 @@ public final class BackMotionEvent implements Parcelable { return "BackMotionEvent{" + "mTouchX=" + mTouchX + ", mTouchY=" + mTouchY + ", mFrameTime=" + mFrameTime + "ms" + ", mProgress=" + mProgress + ", mTriggerBack=" + mTriggerBack + ", mSwipeEdge" + mSwipeEdge + ", mDepartingAnimationTarget" + mDepartingAnimationTarget + ", mSwipeEdge=" + mSwipeEdge + ", mDepartingAnimationTarget=" + mDepartingAnimationTarget + "}"; } }
core/java/android/window/BackProgressAnimator.java +21 −8 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.window; import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE; import static com.android.window.flags.Flags.predictiveBackTimestampApi; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -66,7 +67,8 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL reset(); }; private final DynamicAnimation.OnAnimationUpdateListener mOnBackInvokedFlingUpdateListener = (animation, progress, velocity) -> updateProgressValue(progress, velocity); (animation, progress, velocity) -> updateProgressValue(progress, velocity, animation.getLastFrameTime()); private void setProgress(float progress) { Loading @@ -92,7 +94,9 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL @Override public void onAnimationUpdate(DynamicAnimation animation, float value, float velocity) { if (mBackInvokedFinishRunnable == null) updateProgressValue(value, velocity); if (mBackInvokedFinishRunnable == null) { updateProgressValue(value, velocity, animation.getLastFrameTime()); } } Loading Loading @@ -137,7 +141,9 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL mLastBackEvent = event; mCallback = callback; mBackAnimationInProgress = true; updateProgressValue(0, 0); updateProgressValue(/* progress */ 0, /* velocity */ 0, /* frameTime */ System.nanoTime() / TimeUtils.NANOS_PER_MS); onBackProgressed(event); } /** Loading @@ -146,7 +152,8 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL public void reset() { if (mBackCancelledFinishRunnable != null) { // Ensure that last progress value that apps see is 0 updateProgressValue(0, 0); updateProgressValue(/* progress */ 0, /* velocity */ 0, /* frameTime */ System.nanoTime() / TimeUtils.NANOS_PER_MS); invokeBackCancelledRunnable(); } else if (mBackInvokedFinishRunnable != null) { invokeBackInvokedRunnable(); Loading Loading @@ -236,14 +243,20 @@ public class BackProgressAnimator implements DynamicAnimation.OnAnimationUpdateL return mVelocity / SCALE_FACTOR; } private void updateProgressValue(float progress, float velocity) { private void updateProgressValue(float progress, float velocity, long frameTime) { mVelocity = velocity; if (mLastBackEvent == null || mCallback == null || !mBackAnimationInProgress) { return; } mCallback.onProgressUpdate( new BackEvent(mLastBackEvent.getTouchX(), mLastBackEvent.getTouchY(), progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge())); BackEvent backEvent; if (predictiveBackTimestampApi()) { backEvent = new BackEvent(mLastBackEvent.getTouchX(), mLastBackEvent.getTouchY(), progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge(), frameTime); } else { backEvent = new BackEvent(mLastBackEvent.getTouchX(), mLastBackEvent.getTouchY(), progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge()); } mCallback.onProgressUpdate(backEvent); } private void invokeBackCancelledRunnable() { Loading
core/java/android/window/BackTouchTracker.java +2 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,7 @@ public class BackTouchTracker { return new BackMotionEvent( /* touchX = */ mInitTouchX, /* touchY = */ mInitTouchY, /* frameTime = */ 0, /* progress = */ 0, /* triggerBack = */ mTriggerBack, /* swipeEdge = */ mSwipeEdge, Loading Loading @@ -235,6 +236,7 @@ public class BackTouchTracker { return new BackMotionEvent( /* touchX = */ mLatestTouchX, /* touchY = */ mLatestTouchY, /* frameTime = */ 0, /* progress = */ progress, /* triggerBack = */ mTriggerBack, /* swipeEdge = */ mSwipeEdge, Loading