diff options
19 files changed, 274 insertions, 148 deletions
diff --git a/boot/preloaded-classes b/boot/preloaded-classes index d8b348e9caf4..528ce867d10a 100644 --- a/boot/preloaded-classes +++ b/boot/preloaded-classes @@ -9358,8 +9358,8 @@ android.widget.inline.InlinePresentationSpec$1 android.widget.inline.InlinePresentationSpec$BaseBuilder android.widget.inline.InlinePresentationSpec$Builder android.widget.inline.InlinePresentationSpec -android.window.BackEvent$1 -android.window.BackEvent +android.window.BackMotionEvent$1 +android.window.BackMotionEvent android.window.ClientWindowFrames$1 android.window.ClientWindowFrames android.window.CompatOnBackInvokedCallback diff --git a/config/preloaded-classes b/config/preloaded-classes index f750249f3408..fa60140ec068 100644 --- a/config/preloaded-classes +++ b/config/preloaded-classes @@ -9389,8 +9389,8 @@ android.widget.inline.InlinePresentationSpec$1 android.widget.inline.InlinePresentationSpec$BaseBuilder android.widget.inline.InlinePresentationSpec$Builder android.widget.inline.InlinePresentationSpec -android.window.BackEvent$1 -android.window.BackEvent +android.window.BackMotionEvent$1 +android.window.BackMotionEvent android.window.ClientWindowFrames$1 android.window.ClientWindowFrames android.window.CompatOnBackInvokedCallback diff --git a/core/api/current.txt b/core/api/current.txt index f83ba9b9a07c..a010a6b615f1 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -59158,6 +59158,22 @@ package android.widget.inline { package android.window { + public final class BackEvent { + ctor public BackEvent(float, float, float, int); + method @FloatRange(from=0, to=1) public float getProgress(); + method public int getSwipeEdge(); + method public float getTouchX(); + method public float getTouchY(); + field public static final int EDGE_LEFT = 0; // 0x0 + field public static final int EDGE_RIGHT = 1; // 0x1 + } + + public interface OnBackAnimationCallback extends android.window.OnBackInvokedCallback { + method public default void onBackCancelled(); + method public default void onBackProgressed(@NonNull android.window.BackEvent); + method public default void onBackStarted(@NonNull android.window.BackEvent); + } + public interface OnBackInvokedCallback { method public void onBackInvoked(); } diff --git a/core/java/android/window/BackEvent.java b/core/java/android/window/BackEvent.java index 85b288113b45..40c0feee7c94 100644 --- a/core/java/android/window/BackEvent.java +++ b/core/java/android/window/BackEvent.java @@ -16,29 +16,24 @@ package android.window; +import android.annotation.FloatRange; import android.annotation.IntDef; -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.os.Parcel; -import android.os.Parcelable; -import android.view.RemoteAnimationTarget; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** - * Represents an event that is sent out by the system during back navigation gesture. - * Holds information about the touch event, swipe direction and overall progress of the gesture - * interaction. - * - * @hide + * Object used to report back gesture progress. + * Holds information about the touch event, swipe direction and the animation progress that + * predictive back animations should seek to. */ -public class BackEvent implements Parcelable { +public final class BackEvent { /** Indicates that the edge swipe starts from the left edge of the screen */ public static final int EDGE_LEFT = 0; /** Indicates that the edge swipe starts from the right edge of the screen */ public static final int EDGE_RIGHT = 1; + /** @hide */ @IntDef({ EDGE_LEFT, EDGE_RIGHT, @@ -52,78 +47,52 @@ public class BackEvent implements Parcelable { @SwipeEdge private final int mSwipeEdge; - @Nullable - private final RemoteAnimationTarget mDepartingAnimationTarget; /** - * Creates a new {@link BackEvent} instance. + * Creates a new {@link BackMotionEvent} 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 departingAnimationTarget The remote animation target of the departing - * application window. */ - public BackEvent(float touchX, float touchY, float progress, @SwipeEdge int swipeEdge, - @Nullable RemoteAnimationTarget departingAnimationTarget) { + public BackEvent(float touchX, float touchY, float progress, @SwipeEdge int swipeEdge) { mTouchX = touchX; mTouchY = touchY; mProgress = progress; mSwipeEdge = swipeEdge; - mDepartingAnimationTarget = departingAnimationTarget; - } - - private BackEvent(@NonNull Parcel in) { - mTouchX = in.readFloat(); - mTouchY = in.readFloat(); - mProgress = in.readFloat(); - mSwipeEdge = in.readInt(); - mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR); - } - - public static final Creator<BackEvent> CREATOR = new Creator<BackEvent>() { - @Override - public BackEvent createFromParcel(Parcel in) { - return new BackEvent(in); - } - - @Override - public BackEvent[] newArray(int size) { - return new BackEvent[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeFloat(mTouchX); - dest.writeFloat(mTouchY); - dest.writeFloat(mProgress); - dest.writeInt(mSwipeEdge); - dest.writeTypedObject(mDepartingAnimationTarget, flags); } /** - * Returns a value between 0 and 1 on how far along the back gesture is. + * Returns a value between 0 and 1 on how far along the back gesture is. This value is + * driven by the horizontal location of the touch point, and should be used as the fraction to + * seek the predictive back animation with. Specifically, + * <ol> + * <li>The progress is 0 when the touch is at the starting edge of the screen (left or right), + * and animation should seek to its start state. + * <li>The progress is approximately 1 when the touch is at the opposite side of the screen, + * and animation should seek to its end state. Exact end value may vary depending on + * screen size. + * </ol> + * In-between locations are linearly interpolated based on horizontal distance from the starting + * edge and smooth clamped to 1 when the distance exceeds a system-wide threshold. */ + @FloatRange(from = 0, to = 1) public float getProgress() { return mProgress; } /** - * Returns the absolute X location of the touch point. + * Returns the absolute X location of the touch point, or NaN if the event is from + * a button press. */ public float getTouchX() { return mTouchX; } /** - * Returns the absolute Y location of the touch point. + * Returns the absolute Y location of the touch point, or NaN if the event is from + * a button press. */ public float getTouchY() { return mTouchY; @@ -132,20 +101,11 @@ public class BackEvent implements Parcelable { /** * Returns the screen edge that the swipe starts from. */ + @SwipeEdge public int getSwipeEdge() { return mSwipeEdge; } - /** - * 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 - * destination. - */ - @Nullable - public RemoteAnimationTarget getDepartingAnimationTarget() { - return mDepartingAnimationTarget; - } - @Override public String toString() { return "BackEvent{" diff --git a/core/java/android/window/BackEvent.aidl b/core/java/android/window/BackMotionEvent.aidl index 821f1fa9830f..7c675c35c073 100644 --- a/core/java/android/window/BackEvent.aidl +++ b/core/java/android/window/BackMotionEvent.aidl @@ -19,4 +19,4 @@ package android.window; /** * @hide */ -parcelable BackEvent; +parcelable BackMotionEvent; diff --git a/core/java/android/window/BackMotionEvent.java b/core/java/android/window/BackMotionEvent.java new file mode 100644 index 000000000000..8012a1c26bac --- /dev/null +++ b/core/java/android/window/BackMotionEvent.java @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.window; + +import android.annotation.FloatRange; +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.os.Parcel; +import android.os.Parcelable; +import android.view.RemoteAnimationTarget; + +/** + * Object used to report back gesture progress. Holds information about a {@link BackEvent} plus + * any {@link RemoteAnimationTarget} the gesture manipulates. + * + * @see BackEvent + * @hide + */ +public final class BackMotionEvent implements Parcelable { + private final float mTouchX; + private final float mTouchY; + private final float mProgress; + + @BackEvent.SwipeEdge + private final int mSwipeEdge; + @Nullable + private final RemoteAnimationTarget mDepartingAnimationTarget; + + /** + * Creates a new {@link BackMotionEvent} 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 departingAnimationTarget The remote animation target of the departing + * application window. + */ + public BackMotionEvent(float touchX, float touchY, float progress, + @BackEvent.SwipeEdge int swipeEdge, + @Nullable RemoteAnimationTarget departingAnimationTarget) { + mTouchX = touchX; + mTouchY = touchY; + mProgress = progress; + mSwipeEdge = swipeEdge; + mDepartingAnimationTarget = departingAnimationTarget; + } + + private BackMotionEvent(@NonNull Parcel in) { + mTouchX = in.readFloat(); + mTouchY = in.readFloat(); + mProgress = in.readFloat(); + mSwipeEdge = in.readInt(); + mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR); + } + + @NonNull + public static final Creator<BackMotionEvent> CREATOR = new Creator<BackMotionEvent>() { + @Override + public BackMotionEvent createFromParcel(Parcel in) { + return new BackMotionEvent(in); + } + + @Override + public BackMotionEvent[] newArray(int size) { + return new BackMotionEvent[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeFloat(mTouchX); + dest.writeFloat(mTouchY); + dest.writeFloat(mProgress); + dest.writeInt(mSwipeEdge); + dest.writeTypedObject(mDepartingAnimationTarget, flags); + } + + /** + * Returns the progress of a {@link BackEvent}. + * + * @see BackEvent#getProgress() + */ + @FloatRange(from = 0, to = 1) + public float getProgress() { + return mProgress; + } + + /** + * Returns the absolute X location of the touch point. + */ + public float getTouchX() { + return mTouchX; + } + + /** + * Returns the absolute Y location of the touch point. + */ + public float getTouchY() { + return mTouchY; + } + + /** + * Returns the screen edge that the swipe starts from. + */ + @BackEvent.SwipeEdge + public int getSwipeEdge() { + return mSwipeEdge; + } + + /** + * 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 + * destination. + */ + @Nullable + public RemoteAnimationTarget getDepartingAnimationTarget() { + return mDepartingAnimationTarget; + } + + @Override + public String toString() { + return "BackMotionEvent{" + + "mTouchX=" + mTouchX + + ", mTouchY=" + mTouchY + + ", mProgress=" + mProgress + + ", mSwipeEdge" + mSwipeEdge + + ", mDepartingAnimationTarget" + mDepartingAnimationTarget + + "}"; + } +} diff --git a/core/java/android/window/BackProgressAnimator.java b/core/java/android/window/BackProgressAnimator.java index 2e3afde1a78a..14a57e047a08 100644 --- a/core/java/android/window/BackProgressAnimator.java +++ b/core/java/android/window/BackProgressAnimator.java @@ -40,7 +40,7 @@ public class BackProgressAnimator { private final SpringAnimation mSpring; private ProgressCallback mCallback; private float mProgress = 0; - private BackEvent mLastBackEvent; + private BackMotionEvent mLastBackEvent; private boolean mStarted = false; private void setProgress(float progress) { @@ -82,9 +82,9 @@ public class BackProgressAnimator { /** * Sets a new target position for the back progress. * - * @param event the {@link BackEvent} containing the latest target progress. + * @param event the {@link BackMotionEvent} containing the latest target progress. */ - public void onBackProgressed(BackEvent event) { + public void onBackProgressed(BackMotionEvent event) { if (!mStarted) { return; } @@ -98,11 +98,11 @@ public class BackProgressAnimator { /** * Starts the back progress animation. * - * @param event the {@link BackEvent} that started the gesture. + * @param event the {@link BackMotionEvent} that started the gesture. * @param callback the back callback to invoke for the gesture. It will receive back progress * dispatches as the progress animation updates. */ - public void onBackStarted(BackEvent event, ProgressCallback callback) { + public void onBackStarted(BackMotionEvent event, ProgressCallback callback) { reset(); mLastBackEvent = event; mCallback = callback; @@ -132,8 +132,7 @@ public class BackProgressAnimator { } mCallback.onProgressUpdate( new BackEvent(mLastBackEvent.getTouchX(), mLastBackEvent.getTouchY(), - progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge(), - mLastBackEvent.getDepartingAnimationTarget())); + progress / SCALE_FACTOR, mLastBackEvent.getSwipeEdge())); } } diff --git a/core/java/android/window/IOnBackInvokedCallback.aidl b/core/java/android/window/IOnBackInvokedCallback.aidl index 6af8ddda3a62..159c0e8afed0 100644 --- a/core/java/android/window/IOnBackInvokedCallback.aidl +++ b/core/java/android/window/IOnBackInvokedCallback.aidl @@ -17,7 +17,7 @@ package android.window; -import android.window.BackEvent; +import android.window.BackMotionEvent; /** * Interface that wraps a {@link OnBackInvokedCallback} object, to be stored in window manager @@ -30,18 +30,19 @@ oneway interface IOnBackInvokedCallback { * Called when a back gesture has been started, or back button has been pressed down. * Wraps {@link OnBackInvokedCallback#onBackStarted(BackEvent)}. * - * @param backEvent The {@link BackEvent} containing information about the touch or button press. + * @param backMotionEvent The {@link BackMotionEvent} containing information about the touch + * or button press. */ - void onBackStarted(in BackEvent backEvent); + void onBackStarted(in BackMotionEvent backMotionEvent); /** * Called on back gesture progress. * Wraps {@link OnBackInvokedCallback#onBackProgressed(BackEvent)}. * - * @param backEvent The {@link BackEvent} containing information about the latest touch point - * and the progress that the back animation should seek to. + * @param backMotionEvent The {@link BackMotionEvent} containing information about the latest + * touch point and the progress that the back animation should seek to. */ - void onBackProgressed(in BackEvent backEvent); + void onBackProgressed(in BackMotionEvent backMotionEvent); /** * Called when a back gesture or back button press has been cancelled. diff --git a/core/java/android/window/OnBackAnimationCallback.java b/core/java/android/window/OnBackAnimationCallback.java index c05809bca4a5..9119e71cc655 100644 --- a/core/java/android/window/OnBackAnimationCallback.java +++ b/core/java/android/window/OnBackAnimationCallback.java @@ -18,6 +18,8 @@ import android.annotation.NonNull; import android.app.Activity; import android.app.Dialog; import android.view.View; +import android.view.Window; + /** * Interface for applications to register back animation callbacks along their custom back * handling. @@ -25,24 +27,29 @@ import android.view.View; * This allows the client to customize various back behaviors by overriding the corresponding * callback methods. * <p> - * Callback instances can be added to and removed from {@link OnBackInvokedDispatcher}, held - * by classes that implement {@link OnBackInvokedDispatcherOwner} (such as {@link Activity}, - * {@link Dialog} and {@link View}). + * Callback instances can be added to and removed from {@link OnBackInvokedDispatcher}, which + * is held at window level and accessible through {@link Activity#getOnBackInvokedDispatcher()}, + * {@link Dialog#getOnBackInvokedDispatcher()}, {@link Window#getOnBackInvokedDispatcher()} + * and {@link View#findOnBackInvokedDispatcher()}. * <p> * When back is triggered, callbacks on the in-focus window are invoked in reverse order in which * they are added within the same priority. Between different priorities, callbacks with higher * priority are invoked first. * <p> * @see OnBackInvokedCallback - * @hide */ public interface OnBackAnimationCallback extends OnBackInvokedCallback { /** * Called when a back gesture has been started, or back button has been pressed down. + * + * @param backEvent The {@link BackEvent} containing information about the touch or + * button press. + * @see BackEvent */ - default void onBackStarted() { } + default void onBackStarted(@NonNull BackEvent backEvent) {} + /** - * Called on back gesture progress. + * Called when a back gesture progresses. * * @param backEvent An {@link BackEvent} object describing the progress event. * diff --git a/core/java/android/window/OnBackInvokedCallback.java b/core/java/android/window/OnBackInvokedCallback.java index 62c41bfb0681..6beaad339b1d 100644 --- a/core/java/android/window/OnBackInvokedCallback.java +++ b/core/java/android/window/OnBackInvokedCallback.java @@ -16,9 +16,9 @@ package android.window; -import android.annotation.NonNull; import android.app.Activity; import android.app.Dialog; +import android.view.View; import android.view.Window; /** @@ -26,7 +26,8 @@ import android.view.Window; * <p> * Callback instances can be added to and removed from {@link OnBackInvokedDispatcher}, which * is held at window level and accessible through {@link Activity#getOnBackInvokedDispatcher()}, - * {@link Dialog#getOnBackInvokedDispatcher()} and {@link Window#getOnBackInvokedDispatcher()}. + * {@link Dialog#getOnBackInvokedDispatcher()}, {@link Window#getOnBackInvokedDispatcher()} + * and {@link View#findOnBackInvokedDispatcher()}. * <p> * When back is triggered, callbacks on the in-focus window are invoked in reverse order in which * they are added within the same priority. Between different priorities, callbacks with higher @@ -35,6 +36,9 @@ import android.view.Window; * This replaces {@link Activity#onBackPressed()}, {@link Dialog#onBackPressed()} and * {@link android.view.KeyEvent#KEYCODE_BACK} * <p> + * If you want to customize back animation behaviors, in addition to handling back invocations, + * register its subclass instances {@link OnBackAnimationCallback} instead. + * <p> * @see OnBackInvokedDispatcher#registerOnBackInvokedCallback(int, OnBackInvokedCallback) * registerOnBackInvokedCallback(priority, OnBackInvokedCallback) * to specify callback priority. @@ -42,35 +46,8 @@ import android.view.Window; @SuppressWarnings("deprecation") public interface OnBackInvokedCallback { /** - * Called when a back gesture has been started, or back button has been pressed down. - * - * @param backEvent The {@link BackEvent} containing information about the touch or - * button press. - * - * @hide - */ - default void onBackStarted(@NonNull BackEvent backEvent) {} - - /** - * Called when a back gesture has been progressed. - * - * @param backEvent The {@link BackEvent} containing information about the latest touch point - * and the progress that the back animation should seek to. - * - * @hide - */ - default void onBackProgressed(@NonNull BackEvent backEvent) {} - - /** * Called when a back gesture has been completed and committed, or back button pressed * has been released and committed. */ void onBackInvoked(); - - /** - * Called when a back gesture or button press has been cancelled. - * - * @hide - */ - default void onBackCancelled() {} } diff --git a/core/java/android/window/WindowOnBackInvokedDispatcher.java b/core/java/android/window/WindowOnBackInvokedDispatcher.java index fda39c14dac7..dd9483a9c759 100644 --- a/core/java/android/window/WindowOnBackInvokedDispatcher.java +++ b/core/java/android/window/WindowOnBackInvokedDispatcher.java @@ -229,19 +229,21 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { } @Override - public void onBackStarted(BackEvent backEvent) { + public void onBackStarted(BackMotionEvent backEvent) { Handler.getMain().post(() -> { final OnBackAnimationCallback callback = getBackAnimationCallback(); if (callback != null) { mProgressAnimator.onBackStarted(backEvent, event -> callback.onBackProgressed(event)); - callback.onBackStarted(backEvent); + callback.onBackStarted(new BackEvent( + backEvent.getTouchX(), backEvent.getTouchY(), + backEvent.getProgress(), backEvent.getSwipeEdge())); } }); } @Override - public void onBackProgressed(BackEvent backEvent) { + public void onBackProgressed(BackMotionEvent backEvent) { Handler.getMain().post(() -> { final OnBackAnimationCallback callback = getBackAnimationCallback(); if (callback != null) { diff --git a/core/tests/coretests/src/android/window/WindowOnBackInvokedDispatcherTest.java b/core/tests/coretests/src/android/window/WindowOnBackInvokedDispatcherTest.java index f370ebd94545..9d6b29e5c072 100644 --- a/core/tests/coretests/src/android/window/WindowOnBackInvokedDispatcherTest.java +++ b/core/tests/coretests/src/android/window/WindowOnBackInvokedDispatcherTest.java @@ -17,6 +17,7 @@ package android.window; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; @@ -60,8 +61,8 @@ public class WindowOnBackInvokedDispatcherTest { private OnBackAnimationCallback mCallback1; @Mock private OnBackAnimationCallback mCallback2; - @Mock - private BackEvent mBackEvent; + private final BackMotionEvent mBackEvent = new BackMotionEvent( + 0, 0, 0, BackEvent.EDGE_LEFT, null); @Before public void setUp() throws Exception { @@ -89,12 +90,12 @@ public class WindowOnBackInvokedDispatcherTest { captor.capture()); captor.getAllValues().get(0).getCallback().onBackStarted(mBackEvent); waitForIdle(); - verify(mCallback1).onBackStarted(mBackEvent); + verify(mCallback1).onBackStarted(any(BackEvent.class)); verifyZeroInteractions(mCallback2); captor.getAllValues().get(1).getCallback().onBackStarted(mBackEvent); waitForIdle(); - verify(mCallback2).onBackStarted(mBackEvent); + verify(mCallback2).onBackStarted(any(BackEvent.class)); verifyNoMoreInteractions(mCallback1); } @@ -114,7 +115,7 @@ public class WindowOnBackInvokedDispatcherTest { assertEquals(captor.getValue().getPriority(), OnBackInvokedDispatcher.PRIORITY_OVERLAY); captor.getValue().getCallback().onBackStarted(mBackEvent); waitForIdle(); - verify(mCallback1).onBackStarted(mBackEvent); + verify(mCallback1).onBackStarted(any(BackEvent.class)); } @Test @@ -152,6 +153,6 @@ public class WindowOnBackInvokedDispatcherTest { verify(mWindowSession).setOnBackInvokedCallbackInfo(Mockito.eq(mWindow), captor.capture()); captor.getValue().getCallback().onBackStarted(mBackEvent); waitForIdle(); - verify(mCallback2).onBackStarted(mBackEvent); + verify(mCallback2).onBackStarted(any(BackEvent.class)); } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java index 0133f6b44d2b..57a0fd593551 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java @@ -47,6 +47,7 @@ import android.view.MotionEvent; import android.view.RemoteAnimationTarget; import android.window.BackAnimationAdapter; import android.window.BackEvent; +import android.window.BackMotionEvent; import android.window.BackNavigationInfo; import android.window.IBackAnimationFinishedCallback; import android.window.IBackAnimationRunner; @@ -385,7 +386,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont return; } - final BackEvent backEvent = mTouchTracker.createProgressEvent(); + final BackMotionEvent backEvent = mTouchTracker.createProgressEvent(); dispatchOnBackProgressed(mActiveCallback, backEvent); } @@ -415,7 +416,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont } private void dispatchOnBackStarted(IOnBackInvokedCallback callback, - BackEvent backEvent) { + BackMotionEvent backEvent) { if (callback == null) { return; } @@ -453,7 +454,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont } private void dispatchOnBackProgressed(IOnBackInvokedCallback callback, - BackEvent backEvent) { + BackMotionEvent backEvent) { if (callback == null) { return; } @@ -466,6 +467,11 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont } } + private boolean shouldDispatchAnimation(IOnBackInvokedCallback callback) { + // TODO(b/258698745): Only dispatch to animation callbacks. + return mEnableAnimations.get(); + } + /** * Sets to true when the back gesture has passed the triggering threshold, false otherwise. */ @@ -640,7 +646,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont if (!mBackGestureStarted) { // if the down -> up gesture happened before animation start, we have to // trigger the uninterruptible transition to finish the back animation. - final BackEvent backFinish = mTouchTracker.createProgressEvent(); + final BackMotionEvent backFinish = mTouchTracker.createProgressEvent(); dispatchOnBackProgressed(mActiveCallback, backFinish); startPostCommitAnimation(); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityAnimation.java index 9f6bc5d89e10..e36e16c82da6 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityAnimation.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityAnimation.java @@ -39,6 +39,7 @@ import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.window.BackEvent; +import android.window.BackMotionEvent; import android.window.BackProgressAnimator; import android.window.IOnBackInvokedCallback; @@ -315,13 +316,13 @@ class CrossActivityAnimation { private final class Callback extends IOnBackInvokedCallback.Default { @Override - public void onBackStarted(BackEvent backEvent) { + public void onBackStarted(BackMotionEvent backEvent) { mProgressAnimator.onBackStarted(backEvent, CrossActivityAnimation.this::onGestureProgress); } @Override - public void onBackProgressed(@NonNull BackEvent backEvent) { + public void onBackProgressed(@NonNull BackMotionEvent backEvent) { mProgressAnimator.onBackProgressed(backEvent); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossTaskBackAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossTaskBackAnimation.java index a9a7b7742d2f..676e25923301 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossTaskBackAnimation.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossTaskBackAnimation.java @@ -39,6 +39,7 @@ import android.view.SurfaceControl; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.window.BackEvent; +import android.window.BackMotionEvent; import android.window.BackProgressAnimator; import android.window.IOnBackInvokedCallback; @@ -316,13 +317,13 @@ class CrossTaskBackAnimation { private final class Callback extends IOnBackInvokedCallback.Default { @Override - public void onBackStarted(BackEvent backEvent) { + public void onBackStarted(BackMotionEvent backEvent) { mProgressAnimator.onBackStarted(backEvent, CrossTaskBackAnimation.this::onGestureProgress); } @Override - public void onBackProgressed(@NonNull BackEvent backEvent) { + public void onBackProgressed(@NonNull BackMotionEvent backEvent) { mProgressAnimator.onBackProgressed(backEvent); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/TouchTracker.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/TouchTracker.java index ccfac65d6342..695ef4e66302 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/TouchTracker.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/TouchTracker.java @@ -19,6 +19,7 @@ package com.android.wm.shell.back; import android.os.SystemProperties; import android.view.RemoteAnimationTarget; import android.window.BackEvent; +import android.window.BackMotionEvent; /** * Helper class to record the touch location for gesture and generate back events. @@ -82,11 +83,11 @@ class TouchTracker { mSwipeEdge = BackEvent.EDGE_LEFT; } - BackEvent createStartEvent(RemoteAnimationTarget target) { - return new BackEvent(mInitTouchX, mInitTouchY, 0, mSwipeEdge, target); + BackMotionEvent createStartEvent(RemoteAnimationTarget target) { + return new BackMotionEvent(mInitTouchX, mInitTouchY, 0, mSwipeEdge, target); } - BackEvent createProgressEvent() { + BackMotionEvent createProgressEvent() { float progressThreshold = PROGRESS_THRESHOLD >= 0 ? PROGRESS_THRESHOLD : mProgressThreshold; progressThreshold = progressThreshold == 0 ? 1 : progressThreshold; @@ -109,8 +110,8 @@ class TouchTracker { return createProgressEvent(progress); } - BackEvent createProgressEvent(float progress) { - return new BackEvent(mLatestTouchX, mLatestTouchY, progress, mSwipeEdge, null); + BackMotionEvent createProgressEvent(float progress) { + return new BackMotionEvent(mLatestTouchX, mLatestTouchY, progress, mSwipeEdge, null); } public void setProgressThreshold(float progressThreshold) { diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java index bee9a90ec6b8..8a5b4901ed96 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java @@ -53,6 +53,7 @@ import android.view.MotionEvent; import android.view.RemoteAnimationTarget; import android.view.SurfaceControl; import android.window.BackEvent; +import android.window.BackMotionEvent; import android.window.BackNavigationInfo; import android.window.IBackAnimationFinishedCallback; import android.window.IOnBackInvokedCallback; @@ -223,9 +224,10 @@ public class BackAnimationControllerTest extends ShellTestCase { simulateRemoteAnimationStart(BackNavigationInfo.TYPE_RETURN_TO_HOME); - verify(mAnimatorCallback).onBackStarted(any(BackEvent.class)); + verify(mAnimatorCallback).onBackStarted(any(BackMotionEvent.class)); verify(mBackAnimationRunner).onAnimationStart(anyInt(), any(), any(), any(), any()); - ArgumentCaptor<BackEvent> backEventCaptor = ArgumentCaptor.forClass(BackEvent.class); + ArgumentCaptor<BackMotionEvent> backEventCaptor = + ArgumentCaptor.forClass(BackMotionEvent.class); verify(mAnimatorCallback, atLeastOnce()).onBackProgressed(backEventCaptor.capture()); // Check that back invocation is dispatched. @@ -246,7 +248,8 @@ public class BackAnimationControllerTest extends ShellTestCase { shellInit.init(); registerAnimation(BackNavigationInfo.TYPE_RETURN_TO_HOME); - ArgumentCaptor<BackEvent> backEventCaptor = ArgumentCaptor.forClass(BackEvent.class); + ArgumentCaptor<BackMotionEvent> backEventCaptor = + ArgumentCaptor.forClass(BackMotionEvent.class); createNavigationInfo(BackNavigationInfo.TYPE_RETURN_TO_HOME, false); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/TouchTrackerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/TouchTrackerTest.java index 3aefc3f03a8a..ba9c159bad28 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/TouchTrackerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/TouchTrackerTest.java @@ -19,6 +19,7 @@ package com.android.wm.shell.back; import static org.junit.Assert.assertEquals; import android.window.BackEvent; +import android.window.BackMotionEvent; import org.junit.Before; import org.junit.Test; @@ -38,7 +39,7 @@ public class TouchTrackerTest { @Test public void generatesProgress_onStart() { mTouchTracker.setGestureStartLocation(INITIAL_X_LEFT_EDGE, 0, BackEvent.EDGE_LEFT); - BackEvent event = mTouchTracker.createStartEvent(null); + BackMotionEvent event = mTouchTracker.createStartEvent(null); assertEquals(event.getProgress(), 0f, 0f); } diff --git a/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java index dc3515dec2f5..a3fb717e1287 100644 --- a/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java @@ -42,7 +42,7 @@ import android.os.RemoteException; import android.platform.test.annotations.Presubmit; import android.view.WindowManager; import android.window.BackAnimationAdapter; -import android.window.BackEvent; +import android.window.BackMotionEvent; import android.window.BackNavigationInfo; import android.window.IOnBackInvokedCallback; import android.window.OnBackInvokedCallback; @@ -259,11 +259,11 @@ public class BackNavigationControllerTests extends WindowTestsBase { private IOnBackInvokedCallback createOnBackInvokedCallback() { return new IOnBackInvokedCallback.Stub() { @Override - public void onBackStarted(BackEvent backEvent) { + public void onBackStarted(BackMotionEvent backMotionEvent) { } @Override - public void onBackProgressed(BackEvent backEvent) { + public void onBackProgressed(BackMotionEvent backMotionEvent) { } @Override |