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