1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
/*
* Copyright (C) 2020 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.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.SurfaceControl;
import android.view.WindowManager;
import java.util.ArrayList;
import java.util.List;
/**
* Used to communicate information about what is changing during a transition to a TransitionPlayer.
* @hide
*/
public final class TransitionInfo implements Parcelable {
/** No transition mode. This is a placeholder, don't use this as an actual mode. */
public static final int TRANSIT_NONE = 0;
/** The container didn't exist before but will exist and be visible after. */
public static final int TRANSIT_OPEN = 1;
/** The container existed and was visible before but won't exist after. */
public static final int TRANSIT_CLOSE = 2;
/** The container existed before but was invisible and will be visible after. */
public static final int TRANSIT_SHOW = 3;
/** The container is going from visible to invisible but it will still exist after. */
public static final int TRANSIT_HIDE = 4;
/** The container exists and is visible before and after but it changes. */
public static final int TRANSIT_CHANGE = 5;
/** @hide */
@IntDef(prefix = { "TRANSIT_" }, value = {
TRANSIT_NONE,
TRANSIT_OPEN,
TRANSIT_CLOSE,
TRANSIT_SHOW,
TRANSIT_HIDE,
TRANSIT_CHANGE
})
public @interface TransitionMode {}
private final @WindowManager.TransitionOldType int mType;
private final ArrayList<Change> mChanges = new ArrayList<>();
private SurfaceControl mRootLeash;
private final Point mRootOffset = new Point();
/** @hide */
public TransitionInfo(@WindowManager.TransitionOldType int type) {
mType = type;
}
private TransitionInfo(Parcel in) {
mType = in.readInt();
in.readList(mChanges, null /* classLoader */);
mRootLeash = new SurfaceControl();
mRootLeash.readFromParcel(in);
mRootOffset.readFromParcel(in);
}
@Override
/** @hide */
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mType);
dest.writeList(mChanges);
mRootLeash.writeToParcel(dest, flags);
mRootOffset.writeToParcel(dest, flags);
}
@NonNull
public static final Creator<TransitionInfo> CREATOR =
new Creator<TransitionInfo>() {
@Override
public TransitionInfo createFromParcel(Parcel in) {
return new TransitionInfo(in);
}
@Override
public TransitionInfo[] newArray(int size) {
return new TransitionInfo[size];
}
};
@Override
/** @hide */
public int describeContents() {
return 0;
}
/** @see #getRootLeash() */
public void setRootLeash(@NonNull SurfaceControl leash, int offsetLeft, int offsetTop) {
mRootLeash = leash;
mRootOffset.set(offsetLeft, offsetTop);
}
public int getType() {
return mType;
}
/**
* @return a surfacecontrol that can serve as a parent surfacecontrol for all the changing
* participants to animate within. This will generally be placed at the highest-z-order
* shared ancestor of all participants.
*/
@NonNull
public SurfaceControl getRootLeash() {
if (mRootLeash == null) {
throw new IllegalStateException("Trying to get a leash which wasn't set");
}
return mRootLeash;
}
/** @return the offset (relative to the screen) of the root leash. */
@NonNull
public Point getRootOffset() {
return mRootOffset;
}
@NonNull
public List<Change> getChanges() {
return mChanges;
}
/**
* @return the Change that a window is undergoing or {@code null} if not directly
* represented.
*/
@Nullable
public Change getChange(@NonNull WindowContainerToken token) {
for (int i = mChanges.size() - 1; i >= 0; --i) {
if (mChanges.get(i).mContainer == token) {
return mChanges.get(i);
}
}
return null;
}
/**
* Add a {@link Change} to this transition.
*/
public void addChange(@NonNull Change change) {
mChanges.add(change);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{t=" + mType + " ro=" + mRootOffset + " c=[");
for (int i = 0; i < mChanges.size(); ++i) {
if (i > 0) {
sb.append(',');
}
sb.append(mChanges.get(i));
}
sb.append("]}");
return sb.toString();
}
/** Converts a transition mode/action to its string representation. */
@NonNull
public static String modeToString(@TransitionMode int mode) {
switch(mode) {
case TRANSIT_NONE: return "NONE";
case TRANSIT_OPEN: return "OPEN";
case TRANSIT_CLOSE: return "CLOSE";
case TRANSIT_SHOW: return "SHOW";
case TRANSIT_HIDE: return "HIDE";
case TRANSIT_CHANGE: return "CHANGE";
default: return "<unknown:" + mode + ">";
}
}
/** Represents the change a WindowContainer undergoes during a transition */
public static final class Change implements Parcelable {
private final WindowContainerToken mContainer;
private WindowContainerToken mParent;
private final SurfaceControl mLeash;
private int mMode = TRANSIT_NONE;
private final Rect mStartAbsBounds = new Rect();
private final Rect mEndAbsBounds = new Rect();
private final Point mEndRelOffset = new Point();
public Change(@Nullable WindowContainerToken container, @NonNull SurfaceControl leash) {
mContainer = container;
mLeash = leash;
}
private Change(Parcel in) {
mContainer = in.readTypedObject(WindowContainerToken.CREATOR);
mParent = in.readTypedObject(WindowContainerToken.CREATOR);
mLeash = new SurfaceControl();
mLeash.readFromParcel(in);
mMode = in.readInt();
mStartAbsBounds.readFromParcel(in);
mEndAbsBounds.readFromParcel(in);
mEndRelOffset.readFromParcel(in);
}
/** Sets the parent of this change's container. The parent must be a participant or null. */
public void setParent(@Nullable WindowContainerToken parent) {
mParent = parent;
}
/** Sets the transition mode for this change */
public void setMode(@TransitionMode int mode) {
mMode = mode;
}
/** Sets the bounds this container occupied before the change in screen space */
public void setStartAbsBounds(@Nullable Rect rect) {
mStartAbsBounds.set(rect);
}
/** Sets the bounds this container will occupy after the change in screen space */
public void setEndAbsBounds(@Nullable Rect rect) {
mEndAbsBounds.set(rect);
}
/** Sets the offset of this container from its parent surface */
public void setEndRelOffset(int left, int top) {
mEndRelOffset.set(left, top);
}
/** @return the container that is changing. May be null if non-remotable (eg. activity) */
@Nullable
public WindowContainerToken getContainer() {
return mContainer;
}
/**
* @return the parent of the changing container. This is the parent within the participants,
* not necessarily the actual parent.
*/
@Nullable
public WindowContainerToken getParent() {
return mParent;
}
/** @return which action this change represents. */
public @TransitionMode int getMode() {
return mMode;
}
/**
* @return the bounds of the container before the change. It may be empty if the container
* is coming into existence.
*/
@NonNull
public Rect getStartAbsBounds() {
return mStartAbsBounds;
}
/**
* @return the bounds of the container after the change. It may be empty if the container
* is disappearing.
*/
@NonNull
public Rect getEndAbsBounds() {
return mEndAbsBounds;
}
/**
* @return the offset of the container's surface from its parent surface after the change.
*/
@NonNull
public Point getEndRelOffset() {
return mEndRelOffset;
}
/** @return the leash or surface to animate for this container */
@NonNull
public SurfaceControl getLeash() {
return mLeash;
}
@Override
/** @hide */
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeTypedObject(mContainer, flags);
dest.writeTypedObject(mParent, flags);
mLeash.writeToParcel(dest, flags);
dest.writeInt(mMode);
mStartAbsBounds.writeToParcel(dest, flags);
mEndAbsBounds.writeToParcel(dest, flags);
mEndRelOffset.writeToParcel(dest, flags);
}
@NonNull
public static final Creator<Change> CREATOR =
new Creator<Change>() {
@Override
public Change createFromParcel(Parcel in) {
return new Change(in);
}
@Override
public Change[] newArray(int size) {
return new Change[size];
}
};
@Override
/** @hide */
public int describeContents() {
return 0;
}
@Override
public String toString() {
return "{" + mContainer + "(" + mParent + ") leash=" + mLeash
+ " m=" + modeToString(mMode) + " sb=" + mStartAbsBounds
+ " eb=" + mEndAbsBounds + " eo=" + mEndRelOffset + "}";
}
}
}
|