blob: 3c22ed80cb86f74b60920ad9c1e3a348ce777ca1 [file] [log] [blame]
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001/*
2 * Copyright (C) 2018 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
17package android.view;
18
Kweku Adams87c60a02018-06-13 12:13:52 -070019import static android.view.RemoteAnimationTargetProto.CLIP_RECT;
20import static android.view.RemoteAnimationTargetProto.CONTENT_INSETS;
21import static android.view.RemoteAnimationTargetProto.IS_TRANSLUCENT;
22import static android.view.RemoteAnimationTargetProto.LEASH;
lumark2ec19122020-01-23 00:09:04 +080023import static android.view.RemoteAnimationTargetProto.LOCAL_BOUNDS;
Kweku Adams87c60a02018-06-13 12:13:52 -070024import static android.view.RemoteAnimationTargetProto.MODE;
25import static android.view.RemoteAnimationTargetProto.POSITION;
26import static android.view.RemoteAnimationTargetProto.PREFIX_ORDER_INDEX;
lumark2ec19122020-01-23 00:09:04 +080027import static android.view.RemoteAnimationTargetProto.SCREEN_SPACE_BOUNDS;
Kweku Adams87c60a02018-06-13 12:13:52 -070028import static android.view.RemoteAnimationTargetProto.SOURCE_CONTAINER_BOUNDS;
Evan Rosky2289ba12018-11-19 18:28:18 -080029import static android.view.RemoteAnimationTargetProto.START_BOUNDS;
30import static android.view.RemoteAnimationTargetProto.START_LEASH;
Kweku Adams87c60a02018-06-13 12:13:52 -070031import static android.view.RemoteAnimationTargetProto.TASK_ID;
32import static android.view.RemoteAnimationTargetProto.WINDOW_CONFIGURATION;
Jorim Jaggif75d1612018-02-27 15:05:21 +010033
Jorim Jaggi33a701a2017-12-01 14:58:18 +010034import android.annotation.IntDef;
Winson Chunge2d72172018-01-25 17:46:20 +000035import android.app.WindowConfiguration;
Artur Satayevad9254c2019-12-10 17:47:54 +000036import android.compat.annotation.UnsupportedAppUsage;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010037import android.graphics.Point;
38import android.graphics.Rect;
39import android.os.Parcel;
40import android.os.Parcelable;
Jorim Jaggif75d1612018-02-27 15:05:21 +010041import android.util.proto.ProtoOutputStream;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010042
Jorim Jaggif75d1612018-02-27 15:05:21 +010043import java.io.PrintWriter;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010044import java.lang.annotation.Retention;
45import java.lang.annotation.RetentionPolicy;
46
47/**
48 * Describes an activity to be animated as part of a remote animation.
49 *
50 * @hide
51 */
52public class RemoteAnimationTarget implements Parcelable {
53
54 /**
55 * The app is in the set of opening apps of this transition.
56 */
57 public static final int MODE_OPENING = 0;
58
59 /**
60 * The app is in the set of closing apps of this transition.
61 */
62 public static final int MODE_CLOSING = 1;
63
Evan Rosky2289ba12018-11-19 18:28:18 -080064 /**
65 * The app is in the set of resizing apps (eg. mode change) of this transition.
66 */
67 public static final int MODE_CHANGING = 2;
68
Jorim Jaggi33a701a2017-12-01 14:58:18 +010069 @IntDef(prefix = { "MODE_" }, value = {
70 MODE_OPENING,
Evan Rosky2289ba12018-11-19 18:28:18 -080071 MODE_CLOSING,
72 MODE_CHANGING
Jorim Jaggi33a701a2017-12-01 14:58:18 +010073 })
74 @Retention(RetentionPolicy.SOURCE)
75 public @interface Mode {}
76
77 /**
78 * The {@link Mode} to describe whether this app is opening or closing.
79 */
Mathew Inwooda570dee2018-08-17 14:56:00 +010080 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +010081 public final @Mode int mode;
82
83 /**
84 * The id of the task this app belongs to.
85 */
Mathew Inwooda570dee2018-08-17 14:56:00 +010086 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +010087 public final int taskId;
88
89 /**
90 * The {@link SurfaceControl} object to actually control the transform of the app.
91 */
Mathew Inwooda570dee2018-08-17 14:56:00 +010092 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +010093 public final SurfaceControl leash;
94
95 /**
Evan Rosky2289ba12018-11-19 18:28:18 -080096 * The {@link SurfaceControl} for the starting state of a target if this transition is
97 * MODE_CHANGING, {@code null)} otherwise. This is relative to the app window.
98 */
99 @UnsupportedAppUsage
100 public final SurfaceControl startLeash;
101
102 /**
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100103 * Whether the app is translucent and may reveal apps behind.
104 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100105 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100106 public final boolean isTranslucent;
107
108 /**
109 * The clip rect window manager applies when clipping the app's main surface in screen space
110 * coordinates. This is just a hint to the animation runner: If running a clip-rect animation,
111 * anything that extends beyond these bounds will not have any effect. This implies that any
112 * clip-rect animation should likely stop at these bounds.
113 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100114 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100115 public final Rect clipRect;
116
117 /**
Winson Chung584d6522018-02-07 23:57:38 +0000118 * The insets of the main app window.
119 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100120 @UnsupportedAppUsage
Winson Chung584d6522018-02-07 23:57:38 +0000121 public final Rect contentInsets;
122
123 /**
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100124 * The index of the element in the tree in prefix order. This should be used for z-layering
125 * to preserve original z-layer order in the hierarchy tree assuming no "boosting" needs to
126 * happen.
127 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100128 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100129 public final int prefixOrderIndex;
130
131 /**
132 * The source position of the app, in screen spaces coordinates. If the position of the leash
133 * is modified from the controlling app, any animation transform needs to be offset by this
134 * amount.
lumark2ec19122020-01-23 00:09:04 +0800135 * @deprecated Use {@link #localBounds} instead.
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100136 */
lumark2ec19122020-01-23 00:09:04 +0800137 @Deprecated
Mathew Inwooda570dee2018-08-17 14:56:00 +0100138 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100139 public final Point position;
140
141 /**
lumark2ec19122020-01-23 00:09:04 +0800142 * Bounds of the target relative to its parent.
143 * When the app target animating on its parent, we need to use the local coordinates relative to
144 * its parent with {@code localBounds.left} & {@code localBounds.top} rather than using
145 * {@code position} in screen coordinates.
146 */
147 public final Rect localBounds;
148
149 /**
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100150 * The bounds of the source container the app lives in, in screen space coordinates. If the crop
151 * of the leash is modified from the controlling app, it needs to take the source container
152 * bounds into account when calculating the crop.
lumark2ec19122020-01-23 00:09:04 +0800153 * @deprecated Renamed to {@link #screenSpaceBounds}
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100154 */
lumark2ec19122020-01-23 00:09:04 +0800155 @Deprecated
Mathew Inwooda570dee2018-08-17 14:56:00 +0100156 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100157 public final Rect sourceContainerBounds;
158
Winson Chunge2d72172018-01-25 17:46:20 +0000159 /**
lumark2ec19122020-01-23 00:09:04 +0800160 * Bounds of the target relative to the screen. If the crop of the leash is modified from the
161 * controlling app, it needs to take the screen space bounds into account when calculating the
162 * crop.
163 */
164 public final Rect screenSpaceBounds;
165
166 /**
Evan Rosky2289ba12018-11-19 18:28:18 -0800167 * The starting bounds of the source container in screen space coordinates. This is {@code null}
168 * if the animation target isn't MODE_CHANGING. Since this is the starting bounds, it's size
169 * should be equivalent to the size of the starting thumbnail. Note that sourceContainerBounds
170 * is the end bounds of a change transition.
171 */
172 @UnsupportedAppUsage
173 public final Rect startBounds;
174
175 /**
Winson Chunge2d72172018-01-25 17:46:20 +0000176 * The window configuration for the target.
177 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100178 @UnsupportedAppUsage
Winson Chunge2d72172018-01-25 17:46:20 +0000179 public final WindowConfiguration windowConfiguration;
180
Vadim Tryshev593e9562018-03-08 17:15:45 -0800181 /**
182 * Whether the task is not presented in Recents UI.
183 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100184 @UnsupportedAppUsage
Vadim Tryshev593e9562018-03-08 17:15:45 -0800185 public boolean isNotInRecents;
186
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100187 public RemoteAnimationTarget(int taskId, int mode, SurfaceControl leash, boolean isTranslucent,
Winson Chung584d6522018-02-07 23:57:38 +0000188 Rect clipRect, Rect contentInsets, int prefixOrderIndex, Point position,
lumark2ec19122020-01-23 00:09:04 +0800189 Rect localBounds, Rect screenSpaceBounds,
190 WindowConfiguration windowConfig, boolean isNotInRecents,
Evan Rosky2289ba12018-11-19 18:28:18 -0800191 SurfaceControl startLeash, Rect startBounds) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100192 this.mode = mode;
193 this.taskId = taskId;
194 this.leash = leash;
195 this.isTranslucent = isTranslucent;
196 this.clipRect = new Rect(clipRect);
Winson Chung584d6522018-02-07 23:57:38 +0000197 this.contentInsets = new Rect(contentInsets);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100198 this.prefixOrderIndex = prefixOrderIndex;
199 this.position = new Point(position);
lumark2ec19122020-01-23 00:09:04 +0800200 this.localBounds = new Rect(localBounds);
201 this.sourceContainerBounds = new Rect(screenSpaceBounds);
202 this.screenSpaceBounds = new Rect(screenSpaceBounds);
Winson Chunge2d72172018-01-25 17:46:20 +0000203 this.windowConfiguration = windowConfig;
Vadim Tryshev593e9562018-03-08 17:15:45 -0800204 this.isNotInRecents = isNotInRecents;
Evan Rosky2289ba12018-11-19 18:28:18 -0800205 this.startLeash = startLeash;
206 this.startBounds = startBounds == null ? null : new Rect(startBounds);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100207 }
208
209 public RemoteAnimationTarget(Parcel in) {
210 taskId = in.readInt();
211 mode = in.readInt();
212 leash = in.readParcelable(null);
213 isTranslucent = in.readBoolean();
214 clipRect = in.readParcelable(null);
Winson Chung584d6522018-02-07 23:57:38 +0000215 contentInsets = in.readParcelable(null);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100216 prefixOrderIndex = in.readInt();
217 position = in.readParcelable(null);
lumark2ec19122020-01-23 00:09:04 +0800218 localBounds = in.readParcelable(null);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100219 sourceContainerBounds = in.readParcelable(null);
lumark2ec19122020-01-23 00:09:04 +0800220 screenSpaceBounds = in.readParcelable(null);
Winson Chunge2d72172018-01-25 17:46:20 +0000221 windowConfiguration = in.readParcelable(null);
Vadim Tryshev593e9562018-03-08 17:15:45 -0800222 isNotInRecents = in.readBoolean();
Evan Rosky2289ba12018-11-19 18:28:18 -0800223 startLeash = in.readParcelable(null);
224 startBounds = in.readParcelable(null);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100225 }
226
227 @Override
228 public int describeContents() {
229 return 0;
230 }
231
232 @Override
233 public void writeToParcel(Parcel dest, int flags) {
234 dest.writeInt(taskId);
235 dest.writeInt(mode);
236 dest.writeParcelable(leash, 0 /* flags */);
237 dest.writeBoolean(isTranslucent);
238 dest.writeParcelable(clipRect, 0 /* flags */);
Winson Chung584d6522018-02-07 23:57:38 +0000239 dest.writeParcelable(contentInsets, 0 /* flags */);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100240 dest.writeInt(prefixOrderIndex);
241 dest.writeParcelable(position, 0 /* flags */);
lumark2ec19122020-01-23 00:09:04 +0800242 dest.writeParcelable(localBounds, 0 /* flags */);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100243 dest.writeParcelable(sourceContainerBounds, 0 /* flags */);
lumark2ec19122020-01-23 00:09:04 +0800244 dest.writeParcelable(screenSpaceBounds, 0 /* flags */);
Winson Chunge2d72172018-01-25 17:46:20 +0000245 dest.writeParcelable(windowConfiguration, 0 /* flags */);
Vadim Tryshev593e9562018-03-08 17:15:45 -0800246 dest.writeBoolean(isNotInRecents);
Evan Rosky2289ba12018-11-19 18:28:18 -0800247 dest.writeParcelable(startLeash, 0 /* flags */);
248 dest.writeParcelable(startBounds, 0 /* flags */);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100249 }
250
Jorim Jaggif75d1612018-02-27 15:05:21 +0100251 public void dump(PrintWriter pw, String prefix) {
252 pw.print(prefix); pw.print("mode="); pw.print(mode);
253 pw.print(" taskId="); pw.print(taskId);
254 pw.print(" isTranslucent="); pw.print(isTranslucent);
255 pw.print(" clipRect="); clipRect.printShortString(pw);
256 pw.print(" contentInsets="); contentInsets.printShortString(pw);
257 pw.print(" prefixOrderIndex="); pw.print(prefixOrderIndex);
258 pw.print(" position="); position.printShortString(pw);
259 pw.print(" sourceContainerBounds="); sourceContainerBounds.printShortString(pw);
lumark2ec19122020-01-23 00:09:04 +0800260 pw.print(" screenSpaceBounds="); screenSpaceBounds.printShortString(pw);
261 pw.print(" localBounds="); localBounds.printShortString(pw);
Jorim Jaggif75d1612018-02-27 15:05:21 +0100262 pw.println();
263 pw.print(prefix); pw.print("windowConfiguration="); pw.println(windowConfiguration);
264 pw.print(prefix); pw.print("leash="); pw.println(leash);
265 }
266
Jeffrey Huangcb782852019-12-05 11:28:11 -0800267 public void dumpDebug(ProtoOutputStream proto, long fieldId) {
Jorim Jaggif75d1612018-02-27 15:05:21 +0100268 final long token = proto.start(fieldId);
269 proto.write(TASK_ID, taskId);
270 proto.write(MODE, mode);
Jeffrey Huangcb782852019-12-05 11:28:11 -0800271 leash.dumpDebug(proto, LEASH);
Jorim Jaggif75d1612018-02-27 15:05:21 +0100272 proto.write(IS_TRANSLUCENT, isTranslucent);
Jeffrey Huangcb782852019-12-05 11:28:11 -0800273 clipRect.dumpDebug(proto, CLIP_RECT);
274 contentInsets.dumpDebug(proto, CONTENT_INSETS);
Jorim Jaggif75d1612018-02-27 15:05:21 +0100275 proto.write(PREFIX_ORDER_INDEX, prefixOrderIndex);
Jeffrey Huangcb782852019-12-05 11:28:11 -0800276 position.dumpDebug(proto, POSITION);
277 sourceContainerBounds.dumpDebug(proto, SOURCE_CONTAINER_BOUNDS);
lumark2ec19122020-01-23 00:09:04 +0800278 screenSpaceBounds.dumpDebug(proto, SCREEN_SPACE_BOUNDS);
279 localBounds.dumpDebug(proto, LOCAL_BOUNDS);
Jeffrey Huangcb782852019-12-05 11:28:11 -0800280 windowConfiguration.dumpDebug(proto, WINDOW_CONFIGURATION);
Evan Roskybaca8192019-01-29 18:44:28 -0800281 if (startLeash != null) {
Jeffrey Huangcb782852019-12-05 11:28:11 -0800282 startLeash.dumpDebug(proto, START_LEASH);
Evan Roskybaca8192019-01-29 18:44:28 -0800283 }
284 if (startBounds != null) {
Jeffrey Huangcb782852019-12-05 11:28:11 -0800285 startBounds.dumpDebug(proto, START_BOUNDS);
Evan Roskybaca8192019-01-29 18:44:28 -0800286 }
Jorim Jaggif75d1612018-02-27 15:05:21 +0100287 proto.end(token);
288 }
289
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700290 public static final @android.annotation.NonNull Creator<RemoteAnimationTarget> CREATOR
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100291 = new Creator<RemoteAnimationTarget>() {
292 public RemoteAnimationTarget createFromParcel(Parcel in) {
293 return new RemoteAnimationTarget(in);
294 }
295
296 public RemoteAnimationTarget[] newArray(int size) {
297 return new RemoteAnimationTarget[size];
298 }
299 };
300}