blob: ae3e1d0a96911f4e0d48f86520cb95ed22d36ce0 [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;
23import static android.view.RemoteAnimationTargetProto.MODE;
24import static android.view.RemoteAnimationTargetProto.POSITION;
25import static android.view.RemoteAnimationTargetProto.PREFIX_ORDER_INDEX;
26import static android.view.RemoteAnimationTargetProto.SOURCE_CONTAINER_BOUNDS;
Evan Rosky2289ba12018-11-19 18:28:18 -080027import static android.view.RemoteAnimationTargetProto.START_BOUNDS;
28import static android.view.RemoteAnimationTargetProto.START_LEASH;
Kweku Adams87c60a02018-06-13 12:13:52 -070029import static android.view.RemoteAnimationTargetProto.TASK_ID;
30import static android.view.RemoteAnimationTargetProto.WINDOW_CONFIGURATION;
Jorim Jaggif75d1612018-02-27 15:05:21 +010031
Jorim Jaggi33a701a2017-12-01 14:58:18 +010032import android.annotation.IntDef;
Mathew Inwooda570dee2018-08-17 14:56:00 +010033import android.annotation.UnsupportedAppUsage;
Winson Chunge2d72172018-01-25 17:46:20 +000034import android.app.WindowConfiguration;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010035import android.graphics.Point;
36import android.graphics.Rect;
37import android.os.Parcel;
38import android.os.Parcelable;
Jorim Jaggif75d1612018-02-27 15:05:21 +010039import android.util.proto.ProtoOutputStream;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010040
Jorim Jaggif75d1612018-02-27 15:05:21 +010041import java.io.PrintWriter;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010042import java.lang.annotation.Retention;
43import java.lang.annotation.RetentionPolicy;
44
45/**
46 * Describes an activity to be animated as part of a remote animation.
47 *
48 * @hide
49 */
50public class RemoteAnimationTarget implements Parcelable {
51
52 /**
53 * The app is in the set of opening apps of this transition.
54 */
55 public static final int MODE_OPENING = 0;
56
57 /**
58 * The app is in the set of closing apps of this transition.
59 */
60 public static final int MODE_CLOSING = 1;
61
Evan Rosky2289ba12018-11-19 18:28:18 -080062 /**
63 * The app is in the set of resizing apps (eg. mode change) of this transition.
64 */
65 public static final int MODE_CHANGING = 2;
66
Jorim Jaggi33a701a2017-12-01 14:58:18 +010067 @IntDef(prefix = { "MODE_" }, value = {
68 MODE_OPENING,
Evan Rosky2289ba12018-11-19 18:28:18 -080069 MODE_CLOSING,
70 MODE_CHANGING
Jorim Jaggi33a701a2017-12-01 14:58:18 +010071 })
72 @Retention(RetentionPolicy.SOURCE)
73 public @interface Mode {}
74
75 /**
76 * The {@link Mode} to describe whether this app is opening or closing.
77 */
Mathew Inwooda570dee2018-08-17 14:56:00 +010078 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +010079 public final @Mode int mode;
80
81 /**
82 * The id of the task this app belongs to.
83 */
Mathew Inwooda570dee2018-08-17 14:56:00 +010084 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +010085 public final int taskId;
86
87 /**
88 * The {@link SurfaceControl} object to actually control the transform of the app.
89 */
Mathew Inwooda570dee2018-08-17 14:56:00 +010090 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +010091 public final SurfaceControl leash;
92
93 /**
Evan Rosky2289ba12018-11-19 18:28:18 -080094 * The {@link SurfaceControl} for the starting state of a target if this transition is
95 * MODE_CHANGING, {@code null)} otherwise. This is relative to the app window.
96 */
97 @UnsupportedAppUsage
98 public final SurfaceControl startLeash;
99
100 /**
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100101 * Whether the app is translucent and may reveal apps behind.
102 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100103 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100104 public final boolean isTranslucent;
105
106 /**
107 * The clip rect window manager applies when clipping the app's main surface in screen space
108 * coordinates. This is just a hint to the animation runner: If running a clip-rect animation,
109 * anything that extends beyond these bounds will not have any effect. This implies that any
110 * clip-rect animation should likely stop at these bounds.
111 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100112 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100113 public final Rect clipRect;
114
115 /**
Winson Chung584d6522018-02-07 23:57:38 +0000116 * The insets of the main app window.
117 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100118 @UnsupportedAppUsage
Winson Chung584d6522018-02-07 23:57:38 +0000119 public final Rect contentInsets;
120
121 /**
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100122 * The index of the element in the tree in prefix order. This should be used for z-layering
123 * to preserve original z-layer order in the hierarchy tree assuming no "boosting" needs to
124 * happen.
125 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100126 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100127 public final int prefixOrderIndex;
128
129 /**
130 * The source position of the app, in screen spaces coordinates. If the position of the leash
131 * is modified from the controlling app, any animation transform needs to be offset by this
132 * amount.
133 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100134 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100135 public final Point position;
136
137 /**
138 * The bounds of the source container the app lives in, in screen space coordinates. If the crop
139 * of the leash is modified from the controlling app, it needs to take the source container
140 * bounds into account when calculating the crop.
141 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100142 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100143 public final Rect sourceContainerBounds;
144
Winson Chunge2d72172018-01-25 17:46:20 +0000145 /**
Evan Rosky2289ba12018-11-19 18:28:18 -0800146 * The starting bounds of the source container in screen space coordinates. This is {@code null}
147 * if the animation target isn't MODE_CHANGING. Since this is the starting bounds, it's size
148 * should be equivalent to the size of the starting thumbnail. Note that sourceContainerBounds
149 * is the end bounds of a change transition.
150 */
151 @UnsupportedAppUsage
152 public final Rect startBounds;
153
154 /**
Winson Chunge2d72172018-01-25 17:46:20 +0000155 * The window configuration for the target.
156 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100157 @UnsupportedAppUsage
Winson Chunge2d72172018-01-25 17:46:20 +0000158 public final WindowConfiguration windowConfiguration;
159
Vadim Tryshev593e9562018-03-08 17:15:45 -0800160 /**
161 * Whether the task is not presented in Recents UI.
162 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100163 @UnsupportedAppUsage
Vadim Tryshev593e9562018-03-08 17:15:45 -0800164 public boolean isNotInRecents;
165
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100166 public RemoteAnimationTarget(int taskId, int mode, SurfaceControl leash, boolean isTranslucent,
Winson Chung584d6522018-02-07 23:57:38 +0000167 Rect clipRect, Rect contentInsets, int prefixOrderIndex, Point position,
Evan Rosky2289ba12018-11-19 18:28:18 -0800168 Rect sourceContainerBounds, WindowConfiguration windowConfig, boolean isNotInRecents,
169 SurfaceControl startLeash, Rect startBounds) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100170 this.mode = mode;
171 this.taskId = taskId;
172 this.leash = leash;
173 this.isTranslucent = isTranslucent;
174 this.clipRect = new Rect(clipRect);
Winson Chung584d6522018-02-07 23:57:38 +0000175 this.contentInsets = new Rect(contentInsets);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100176 this.prefixOrderIndex = prefixOrderIndex;
177 this.position = new Point(position);
178 this.sourceContainerBounds = new Rect(sourceContainerBounds);
Winson Chunge2d72172018-01-25 17:46:20 +0000179 this.windowConfiguration = windowConfig;
Vadim Tryshev593e9562018-03-08 17:15:45 -0800180 this.isNotInRecents = isNotInRecents;
Evan Rosky2289ba12018-11-19 18:28:18 -0800181 this.startLeash = startLeash;
182 this.startBounds = startBounds == null ? null : new Rect(startBounds);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100183 }
184
185 public RemoteAnimationTarget(Parcel in) {
186 taskId = in.readInt();
187 mode = in.readInt();
188 leash = in.readParcelable(null);
189 isTranslucent = in.readBoolean();
190 clipRect = in.readParcelable(null);
Winson Chung584d6522018-02-07 23:57:38 +0000191 contentInsets = in.readParcelable(null);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100192 prefixOrderIndex = in.readInt();
193 position = in.readParcelable(null);
194 sourceContainerBounds = in.readParcelable(null);
Winson Chunge2d72172018-01-25 17:46:20 +0000195 windowConfiguration = in.readParcelable(null);
Vadim Tryshev593e9562018-03-08 17:15:45 -0800196 isNotInRecents = in.readBoolean();
Evan Rosky2289ba12018-11-19 18:28:18 -0800197 startLeash = in.readParcelable(null);
198 startBounds = in.readParcelable(null);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100199 }
200
201 @Override
202 public int describeContents() {
203 return 0;
204 }
205
206 @Override
207 public void writeToParcel(Parcel dest, int flags) {
208 dest.writeInt(taskId);
209 dest.writeInt(mode);
210 dest.writeParcelable(leash, 0 /* flags */);
211 dest.writeBoolean(isTranslucent);
212 dest.writeParcelable(clipRect, 0 /* flags */);
Winson Chung584d6522018-02-07 23:57:38 +0000213 dest.writeParcelable(contentInsets, 0 /* flags */);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100214 dest.writeInt(prefixOrderIndex);
215 dest.writeParcelable(position, 0 /* flags */);
216 dest.writeParcelable(sourceContainerBounds, 0 /* flags */);
Winson Chunge2d72172018-01-25 17:46:20 +0000217 dest.writeParcelable(windowConfiguration, 0 /* flags */);
Vadim Tryshev593e9562018-03-08 17:15:45 -0800218 dest.writeBoolean(isNotInRecents);
Evan Rosky2289ba12018-11-19 18:28:18 -0800219 dest.writeParcelable(startLeash, 0 /* flags */);
220 dest.writeParcelable(startBounds, 0 /* flags */);
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100221 }
222
Jorim Jaggif75d1612018-02-27 15:05:21 +0100223 public void dump(PrintWriter pw, String prefix) {
224 pw.print(prefix); pw.print("mode="); pw.print(mode);
225 pw.print(" taskId="); pw.print(taskId);
226 pw.print(" isTranslucent="); pw.print(isTranslucent);
227 pw.print(" clipRect="); clipRect.printShortString(pw);
228 pw.print(" contentInsets="); contentInsets.printShortString(pw);
229 pw.print(" prefixOrderIndex="); pw.print(prefixOrderIndex);
230 pw.print(" position="); position.printShortString(pw);
231 pw.print(" sourceContainerBounds="); sourceContainerBounds.printShortString(pw);
232 pw.println();
233 pw.print(prefix); pw.print("windowConfiguration="); pw.println(windowConfiguration);
234 pw.print(prefix); pw.print("leash="); pw.println(leash);
235 }
236
237 public void writeToProto(ProtoOutputStream proto, long fieldId) {
238 final long token = proto.start(fieldId);
239 proto.write(TASK_ID, taskId);
240 proto.write(MODE, mode);
241 leash.writeToProto(proto, LEASH);
242 proto.write(IS_TRANSLUCENT, isTranslucent);
243 clipRect.writeToProto(proto, CLIP_RECT);
244 contentInsets.writeToProto(proto, CONTENT_INSETS);
245 proto.write(PREFIX_ORDER_INDEX, prefixOrderIndex);
246 position.writeToProto(proto, POSITION);
247 sourceContainerBounds.writeToProto(proto, SOURCE_CONTAINER_BOUNDS);
248 windowConfiguration.writeToProto(proto, WINDOW_CONFIGURATION);
Evan Roskybaca8192019-01-29 18:44:28 -0800249 if (startLeash != null) {
250 startLeash.writeToProto(proto, START_LEASH);
251 }
252 if (startBounds != null) {
253 startBounds.writeToProto(proto, START_BOUNDS);
254 }
Jorim Jaggif75d1612018-02-27 15:05:21 +0100255 proto.end(token);
256 }
257
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700258 public static final @android.annotation.NonNull Creator<RemoteAnimationTarget> CREATOR
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100259 = new Creator<RemoteAnimationTarget>() {
260 public RemoteAnimationTarget createFromParcel(Parcel in) {
261 return new RemoteAnimationTarget(in);
262 }
263
264 public RemoteAnimationTarget[] newArray(int size) {
265 return new RemoteAnimationTarget[size];
266 }
267 };
268}