Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f0809b2 authored by Shan Huang's avatar Shan Huang Committed by Android (Google) Code Review
Browse files

Merge "Make OnBackAnimationCallback and BackEvent public."

parents a8bc50d4 79195a44
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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
+16 −0
Original line number Diff line number Diff line
@@ -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();
  }
+26 −66
Original line number Diff line number Diff line
@@ -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{"
+1 −1
Original line number Diff line number Diff line
@@ -19,4 +19,4 @@ package android.window;
/**
 * @hide
 */
parcelable BackEvent;
parcelable BackMotionEvent;
Loading