• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.window;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import java.util.ArrayList;
24 
25 /**
26  * Object that describes how to run a remote back animation.
27  *
28  * @hide
29  */
30 public class BackAnimationAdapter implements Parcelable {
31     private final IBackAnimationRunner mRunner;
32     private int[] mSupportedAnimators;
33 
BackAnimationAdapter(IBackAnimationRunner runner)34     public BackAnimationAdapter(IBackAnimationRunner runner) {
35         mRunner = runner;
36     }
37 
BackAnimationAdapter(Parcel in)38     public BackAnimationAdapter(Parcel in) {
39         mRunner = IBackAnimationRunner.Stub.asInterface(in.readStrongBinder());
40         mSupportedAnimators = new int[in.readInt()];
41         in.readIntArray(mSupportedAnimators);
42     }
43 
getRunner()44     public IBackAnimationRunner getRunner() {
45         return mRunner;
46     }
47 
48     /** Update the latest animators in the system. */
updateSupportedAnimators(@onNull ArrayList<Integer> animators)49     public void updateSupportedAnimators(@NonNull ArrayList<Integer> animators) {
50         final int size = animators.size();
51         mSupportedAnimators = new int[size];
52         for (int i = size - 1; i >= 0; --i) {
53             mSupportedAnimators[i] = animators.get(i);
54         }
55     }
56 
57     @Override
describeContents()58     public int describeContents() {
59         return 0;
60     }
61 
62     @Override
writeToParcel(Parcel dest, int flags)63     public void writeToParcel(Parcel dest, int flags) {
64         dest.writeStrongInterface(mRunner);
65         dest.writeInt(mSupportedAnimators.length);
66         dest.writeIntArray(mSupportedAnimators);
67     }
68 
69     public static final @android.annotation.NonNull Creator<BackAnimationAdapter> CREATOR =
70             new Creator<BackAnimationAdapter>() {
71         public BackAnimationAdapter createFromParcel(Parcel in) {
72             return new BackAnimationAdapter(in);
73         }
74 
75         public BackAnimationAdapter[] newArray(int size) {
76             return new BackAnimationAdapter[size];
77         }
78     };
79 
80     /**
81      * Check if the back type is animatable.
82      */
isAnimatable(@ackNavigationInfo.BackTargetType int backType)83     public boolean isAnimatable(@BackNavigationInfo.BackTargetType int backType) {
84         if (mSupportedAnimators == null) {
85             return false;
86         }
87         for (int i = mSupportedAnimators.length - 1; i >= 0; --i) {
88             if (backType == mSupportedAnimators[i]) {
89                 return true;
90             }
91         }
92         return false;
93     }
94 }
95