1 /*
2  * Copyright (C) 2016 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 com.android.systemui.statusbar.notification.stack;
18 
19 import android.animation.AnimatorListenerAdapter;
20 import android.util.ArrayMap;
21 import android.util.Property;
22 import android.view.View;
23 import android.view.animation.Interpolator;
24 
25 /**
26  * Properties for a View animation
27  */
28 public class AnimationProperties {
29     public long duration;
30     public long delay;
31     private ArrayMap<Property, Interpolator> mInterpolatorMap;
32     private AnimatorListenerAdapter mAnimatorListenerAdapter;
33 
34     /**
35      * @return an animation filter for this animation.
36      */
getAnimationFilter()37     public AnimationFilter getAnimationFilter() {
38         return new AnimationFilter() {
39             @Override
40             public boolean shouldAnimateProperty(Property property) {
41                 return true;
42             }
43         };
44     }
45 
46     /**
47      * @return a listener that should be run whenever any property finished its animation
48      */
49     public AnimatorListenerAdapter getAnimationFinishListener() {
50         return mAnimatorListenerAdapter;
51     }
52 
53     public AnimationProperties setAnimationFinishListener(AnimatorListenerAdapter listener) {
54         mAnimatorListenerAdapter = listener;
55         return this;
56     }
57 
58     public boolean wasAdded(View view) {
59         return false;
60     }
61 
62     /**
63      * Get a custom interpolator for a property instead of the normal one.
64      */
65     public Interpolator getCustomInterpolator(View child, Property property) {
66         return mInterpolatorMap != null ? mInterpolatorMap.get(property) : null;
67     }
68 
69 
70     public void combineCustomInterpolators(AnimationProperties iconAnimationProperties) {
71         ArrayMap<Property, Interpolator> map = iconAnimationProperties.mInterpolatorMap;
72         if (map != null) {
73             if (mInterpolatorMap == null) {
74                 mInterpolatorMap = new ArrayMap<>();
75             }
76             mInterpolatorMap.putAll(map);
77         }
78     }
79 
80     /**
81      * Set a custom interpolator to use for all views for a property.
82      */
83     public AnimationProperties setCustomInterpolator(Property property, Interpolator interpolator) {
84         if (mInterpolatorMap == null) {
85             mInterpolatorMap = new ArrayMap<>();
86         }
87         mInterpolatorMap.put(property, interpolator);
88         return this;
89     }
90 
91     public AnimationProperties setDuration(long duration) {
92         this.duration = duration;
93         return this;
94     }
95 
96     public AnimationProperties setDelay(long delay) {
97         this.delay = delay;
98         return this;
99     }
100 
101     public AnimationProperties resetCustomInterpolators() {
102         mInterpolatorMap = null;
103         return this;
104     }
105 }
106