Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +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 | |
| 19 | import android.annotation.Nullable; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | import android.util.ArrayMap; |
| 23 | import android.util.SparseArray; |
| 24 | import android.view.WindowManager.TransitionType; |
| 25 | |
| 26 | /** |
| 27 | * Defines which animation types should be overridden by which remote animation. |
| 28 | * |
| 29 | * @hide |
| 30 | */ |
| 31 | public 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 Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 73 | @Override |
| 74 | public int describeContents() { |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void writeToParcel(Parcel dest, int flags) { |
| 80 | dest.writeSparseArray((SparseArray) mTransitionAnimationMap); |
| 81 | } |
| 82 | |
| 83 | public static final Creator<RemoteAnimationDefinition> CREATOR = |
| 84 | new Creator<RemoteAnimationDefinition>() { |
| 85 | public RemoteAnimationDefinition createFromParcel(Parcel in) { |
| 86 | return new RemoteAnimationDefinition(in); |
| 87 | } |
| 88 | |
| 89 | public RemoteAnimationDefinition[] newArray(int size) { |
| 90 | return new RemoteAnimationDefinition[size]; |
| 91 | } |
| 92 | }; |
| 93 | } |