Debian Codegraph @

core/java/android/window/BackEvent.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package android.window;
18
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.view.RemoteAnimationTarget;
25
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28
29 /**
30 * Represents an event that is sent out by the system during back navigation gesture.
31 * Holds information about the touch event, swipe direction and overall progress of the gesture
32 * interaction.
33 *
34 * @hide
35 */
36 public class BackEvent implements Parcelable {
37 /** Indicates that the edge swipe starts from the left edge of the screen */
38 public static final int EDGE_LEFT = 0;
39 /** Indicates that the edge swipe starts from the right edge of the screen */
40 public static final int EDGE_RIGHT = 1;
41
42 @IntDef({
43 EDGE_LEFT,
44 EDGE_RIGHT,
45 })
46 @Retention(RetentionPolicy.SOURCE)
47 public @interface SwipeEdge{}
48
49 private final float mTouchX;
50 private final float mTouchY;
51 private final float mProgress;
52
53 @SwipeEdge
54 private final int mSwipeEdge;
55 @Nullable
56 private final RemoteAnimationTarget mDepartingAnimationTarget;
57
58 /**
59 * Creates a new {@link BackEvent} instance.
60 *
61 * @param touchX Absolute X location of the touch point of this event.
62 * @param touchY Absolute Y location of the touch point of this event.
63 * @param progress Value between 0 and 1 on how far along the back gesture is.
64 * @param swipeEdge Indicates which edge the swipe starts from.
65 * @param departingAnimationTarget The remote animation target of the departing application
66 * window.
67 */
68 public BackEvent(float touchX, float touchY, float progress, @SwipeEdge int swipeEdge,
69 @Nullable RemoteAnimationTarget departingAnimationTarget) {
70 mTouchX = touchX;
71 mTouchY = touchY;
72 mProgress = progress;
73 mSwipeEdge = swipeEdge;
74 mDepartingAnimationTarget = departingAnimationTarget;
75 }
76
77 private BackEvent(@NonNull Parcel in) {
78 mTouchX = in.readFloat();
79 mTouchY = in.readFloat();
80 mProgress = in.readFloat();
81 mSwipeEdge = in.readInt();
82 mDepartingAnimationTarget = in.readTypedObject(RemoteAnimationTarget.CREATOR);
83 }
84
85 public static final Creator<BackEvent> CREATOR = new Creator<BackEvent>() {
86 @Override
87 public BackEvent createFromParcel(Parcel in) {
88 return new BackEvent(in);
89 }
90
91 @Override
92 public BackEvent[] newArray(int size) {
93 return new BackEvent[size];
94 }
95 };
96
97 @Override
98 public int describeContents() {
99 return 0;
100 }
101
102 @Override
103 public void writeToParcel(@NonNull Parcel dest, int flags) {
104 dest.writeFloat(mTouchX);
105 dest.writeFloat(mTouchY);
106 dest.writeFloat(mProgress);
107 dest.writeInt(mSwipeEdge);
108 dest.writeTypedObject(mDepartingAnimationTarget, flags);
109 }
110
111 /**
112 * Returns a value between 0 and 1 on how far along the back gesture is.
113 */
114 public float getProgress() {
115 return mProgress;
116 }
117
118 /**
119 * Returns the absolute X location of the touch point.
120 */
121 public float getTouchX() {
122 return mTouchX;
123 }
124
125 /**
126 * Returns the absolute Y location of the touch point.
127 */
128 public float getTouchY() {
129 return mTouchY;
130 }
131
132 /**
133 * Returns the screen edge that the swipe starts from.
134 */
135 public int getSwipeEdge() {
136 return mSwipeEdge;
137 }
138
139 /**
140 * Returns the {@link RemoteAnimationTarget} of the top departing application window,
141 * or {@code null} if the top window should not be moved for the current type of back
142 * destination.
143 */
144 @Nullable
145 public RemoteAnimationTarget getDepartingAnimationTarget() {
146 return mDepartingAnimationTarget;
147 }
148
149 @Override
150 public String toString() {
151 return "BackEvent{"
152 + "mTouchX=" + mTouchX
153 + ", mTouchY=" + mTouchY
154 + ", mProgress=" + mProgress
155 + ", mSwipeEdge" + mSwipeEdge
156 + ", mDepartingAnimationTarget" + mDepartingAnimationTarget
157 + "}";
158 }
159 }