blob: 8def43512e513513b7af6cf56fc8473b5e44dd06 [file] [log] [blame]
Jorim Jaggif84e2f62018-01-16 14:17:59 +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
19import android.annotation.Nullable;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.util.ArrayMap;
23import android.util.SparseArray;
24import android.view.WindowManager.TransitionType;
25
26/**
27 * Defines which animation types should be overridden by which remote animation.
28 *
29 * @hide
30 */
31public class RemoteAnimationDefinition implements Parcelable {
32
33 private final SparseArray<RemoteAnimationAdapter> mTransitionAnimationMap;
34
35 public RemoteAnimationDefinition() {
36 mTransitionAnimationMap = new SparseArray<>();
37 }
38
39 /**
40 * Registers a remote animation for a specific transition.
41 *
42 * @param transition The transition type. Must be one of WindowManager.TRANSIT_* values.
43 * @param adapter The adapter that described how to run the remote animation.
44 */
45 public void addRemoteAnimation(@TransitionType int transition, RemoteAnimationAdapter adapter) {
46 mTransitionAnimationMap.put(transition, adapter);
47 }
48
49 /**
50 * Checks whether a remote animation for specific transition is defined.
51 *
52 * @param transition The transition type. Must be one of WindowManager.TRANSIT_* values.
53 * @return Whether this definition has defined a remote animation for the specified transition.
54 */
55 public boolean hasTransition(@TransitionType int transition) {
56 return mTransitionAnimationMap.get(transition) != null;
57 }
58
59 /**
60 * Retrieves the remote animation for a specific transition.
61 *
62 * @param transition The transition type. Must be one of WindowManager.TRANSIT_* values.
63 * @return The remote animation adapter for the specified transition.
64 */
65 public @Nullable RemoteAnimationAdapter getAdapter(@TransitionType int transition) {
66 return mTransitionAnimationMap.get(transition);
67 }
68
69 public RemoteAnimationDefinition(Parcel in) {
70 mTransitionAnimationMap = in.readSparseArray(null /* loader */);
71 }
72
Jorim Jaggibc2aabe2018-03-08 17:27:43 +010073 /**
74 * To be called by system_server to keep track which pid is running the remote animations inside
75 * this definition.
76 */
77 public void setCallingPid(int pid) {
78 for (int i = mTransitionAnimationMap.size() - 1; i >= 0; i--) {
79 mTransitionAnimationMap.valueAt(i).setCallingPid(pid);
80 }
81 }
82
Jorim Jaggif84e2f62018-01-16 14:17:59 +010083 @Override
84 public int describeContents() {
85 return 0;
86 }
87
88 @Override
89 public void writeToParcel(Parcel dest, int flags) {
90 dest.writeSparseArray((SparseArray) mTransitionAnimationMap);
91 }
92
93 public static final Creator<RemoteAnimationDefinition> CREATOR =
94 new Creator<RemoteAnimationDefinition>() {
95 public RemoteAnimationDefinition createFromParcel(Parcel in) {
96 return new RemoteAnimationDefinition(in);
97 }
98
99 public RemoteAnimationDefinition[] newArray(int size) {
100 return new RemoteAnimationDefinition[size];
101 }
102 };
103}