Home | History | Annotate | Download | only in stack
      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 
     35     /**
     36      * @return an animation filter for this animation.
     37      */
     38     public AnimationFilter getAnimationFilter() {
     39         return new AnimationFilter();
     40     }
     41 
     42     /**
     43      * @return a listener that should be run whenever any property finished its animation
     44      */
     45     public AnimatorListenerAdapter getAnimationFinishListener() {
     46         return null;
     47     }
     48 
     49     public boolean wasAdded(View view) {
     50         return false;
     51     }
     52 
     53     /**
     54      * Get a custom interpolator for a property instead of the normal one.
     55      */
     56     public Interpolator getCustomInterpolator(View child, Property property) {
     57         return mInterpolatorMap != null ? mInterpolatorMap.get(property) : null;
     58     }
     59 
     60 
     61     public void combineCustomInterpolators(AnimationProperties iconAnimationProperties) {
     62         ArrayMap<Property, Interpolator> map = iconAnimationProperties.mInterpolatorMap;
     63         if (map != null) {
     64             if (mInterpolatorMap == null) {
     65                 mInterpolatorMap = new ArrayMap<>();
     66             }
     67             mInterpolatorMap.putAll(map);
     68         }
     69     }
     70 
     71     /**
     72      * Set a custom interpolator to use for all views for a property.
     73      */
     74     public AnimationProperties setCustomInterpolator(Property property, Interpolator interpolator) {
     75         if (mInterpolatorMap == null) {
     76             mInterpolatorMap = new ArrayMap<>();
     77         }
     78         mInterpolatorMap.put(property, interpolator);
     79         return this;
     80     }
     81 
     82     public AnimationProperties setDuration(long duration) {
     83         this.duration = duration;
     84         return this;
     85     }
     86 
     87     public AnimationProperties setDelay(long delay) {
     88         this.delay = delay;
     89         return this;
     90     }
     91 
     92     public AnimationProperties resetCustomInterpolators() {
     93         mInterpolatorMap = null;
     94         return this;
     95     }
     96 }
     97