Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.view; |
| 18 | |
Kweku Adams | 87c60a0 | 2018-06-13 12:13:52 -0700 | [diff] [blame] | 19 | import static android.view.RemoteAnimationTargetProto.CLIP_RECT; |
| 20 | import static android.view.RemoteAnimationTargetProto.CONTENT_INSETS; |
| 21 | import static android.view.RemoteAnimationTargetProto.IS_TRANSLUCENT; |
| 22 | import static android.view.RemoteAnimationTargetProto.LEASH; |
| 23 | import static android.view.RemoteAnimationTargetProto.MODE; |
| 24 | import static android.view.RemoteAnimationTargetProto.POSITION; |
| 25 | import static android.view.RemoteAnimationTargetProto.PREFIX_ORDER_INDEX; |
| 26 | import static android.view.RemoteAnimationTargetProto.SOURCE_CONTAINER_BOUNDS; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 27 | import static android.view.RemoteAnimationTargetProto.START_BOUNDS; |
| 28 | import static android.view.RemoteAnimationTargetProto.START_LEASH; |
Kweku Adams | 87c60a0 | 2018-06-13 12:13:52 -0700 | [diff] [blame] | 29 | import static android.view.RemoteAnimationTargetProto.TASK_ID; |
| 30 | import static android.view.RemoteAnimationTargetProto.WINDOW_CONFIGURATION; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 31 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 32 | import android.annotation.IntDef; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 33 | import android.annotation.UnsupportedAppUsage; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 34 | import android.app.WindowConfiguration; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 35 | import android.graphics.Point; |
| 36 | import android.graphics.Rect; |
| 37 | import android.os.Parcel; |
| 38 | import android.os.Parcelable; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 39 | import android.util.proto.ProtoOutputStream; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 40 | |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 41 | import java.io.PrintWriter; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 42 | import java.lang.annotation.Retention; |
| 43 | import java.lang.annotation.RetentionPolicy; |
| 44 | |
| 45 | /** |
| 46 | * Describes an activity to be animated as part of a remote animation. |
| 47 | * |
| 48 | * @hide |
| 49 | */ |
| 50 | public 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 Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 62 | /** |
| 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 Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 67 | @IntDef(prefix = { "MODE_" }, value = { |
| 68 | MODE_OPENING, |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 69 | MODE_CLOSING, |
| 70 | MODE_CHANGING |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 71 | }) |
| 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 Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 78 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 79 | public final @Mode int mode; |
| 80 | |
| 81 | /** |
| 82 | * The id of the task this app belongs to. |
| 83 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 84 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 85 | public final int taskId; |
| 86 | |
| 87 | /** |
| 88 | * The {@link SurfaceControl} object to actually control the transform of the app. |
| 89 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 90 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 91 | public final SurfaceControl leash; |
| 92 | |
| 93 | /** |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 94 | * 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 Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 101 | * Whether the app is translucent and may reveal apps behind. |
| 102 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 103 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 104 | 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 Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 112 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 113 | public final Rect clipRect; |
| 114 | |
| 115 | /** |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 116 | * The insets of the main app window. |
| 117 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 118 | @UnsupportedAppUsage |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 119 | public final Rect contentInsets; |
| 120 | |
| 121 | /** |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 122 | * 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 Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 126 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 127 | 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 Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 134 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 135 | 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 Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 142 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 143 | public final Rect sourceContainerBounds; |
| 144 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 145 | /** |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 146 | * 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 Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 155 | * The window configuration for the target. |
| 156 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 157 | @UnsupportedAppUsage |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 158 | public final WindowConfiguration windowConfiguration; |
| 159 | |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 160 | /** |
| 161 | * Whether the task is not presented in Recents UI. |
| 162 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 163 | @UnsupportedAppUsage |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 164 | public boolean isNotInRecents; |
| 165 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 166 | public RemoteAnimationTarget(int taskId, int mode, SurfaceControl leash, boolean isTranslucent, |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 167 | Rect clipRect, Rect contentInsets, int prefixOrderIndex, Point position, |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 168 | Rect sourceContainerBounds, WindowConfiguration windowConfig, boolean isNotInRecents, |
| 169 | SurfaceControl startLeash, Rect startBounds) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 170 | this.mode = mode; |
| 171 | this.taskId = taskId; |
| 172 | this.leash = leash; |
| 173 | this.isTranslucent = isTranslucent; |
| 174 | this.clipRect = new Rect(clipRect); |
Winson Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 175 | this.contentInsets = new Rect(contentInsets); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 176 | this.prefixOrderIndex = prefixOrderIndex; |
| 177 | this.position = new Point(position); |
| 178 | this.sourceContainerBounds = new Rect(sourceContainerBounds); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 179 | this.windowConfiguration = windowConfig; |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 180 | this.isNotInRecents = isNotInRecents; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 181 | this.startLeash = startLeash; |
| 182 | this.startBounds = startBounds == null ? null : new Rect(startBounds); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 183 | } |
| 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 Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 191 | contentInsets = in.readParcelable(null); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 192 | prefixOrderIndex = in.readInt(); |
| 193 | position = in.readParcelable(null); |
| 194 | sourceContainerBounds = in.readParcelable(null); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 195 | windowConfiguration = in.readParcelable(null); |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 196 | isNotInRecents = in.readBoolean(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 197 | startLeash = in.readParcelable(null); |
| 198 | startBounds = in.readParcelable(null); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 199 | } |
| 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 Chung | 584d652 | 2018-02-07 23:57:38 +0000 | [diff] [blame] | 213 | dest.writeParcelable(contentInsets, 0 /* flags */); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 214 | dest.writeInt(prefixOrderIndex); |
| 215 | dest.writeParcelable(position, 0 /* flags */); |
| 216 | dest.writeParcelable(sourceContainerBounds, 0 /* flags */); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 217 | dest.writeParcelable(windowConfiguration, 0 /* flags */); |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 218 | dest.writeBoolean(isNotInRecents); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 219 | dest.writeParcelable(startLeash, 0 /* flags */); |
| 220 | dest.writeParcelable(startBounds, 0 /* flags */); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 223 | 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 Rosky | baca819 | 2019-01-29 18:44:28 -0800 | [diff] [blame] | 249 | if (startLeash != null) { |
| 250 | startLeash.writeToProto(proto, START_LEASH); |
| 251 | } |
| 252 | if (startBounds != null) { |
| 253 | startBounds.writeToProto(proto, START_BOUNDS); |
| 254 | } |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 255 | proto.end(token); |
| 256 | } |
| 257 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 258 | public static final @android.annotation.NonNull Creator<RemoteAnimationTarget> CREATOR |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 259 | = 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 | } |