Home | History | Annotate | Download | only in stack
      1 /*
      2  * Copyright (C) 2014 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.support.v4.util.ArraySet;
     20 import android.util.Property;
     21 import android.view.View;
     22 
     23 import java.util.ArrayList;
     24 import java.util.Set;
     25 
     26 /**
     27  * Filters the animations for only a certain type of properties.
     28  */
     29 public class AnimationFilter {
     30     boolean animateAlpha;
     31     boolean animateX;
     32     boolean animateY;
     33     ArraySet<View> animateYViews = new ArraySet<>();
     34     boolean animateZ;
     35     boolean animateHeight;
     36     boolean animateTopInset;
     37     boolean animateDimmed;
     38     boolean animateDark;
     39     boolean animateHideSensitive;
     40     public boolean animateShadowAlpha;
     41     boolean hasDelays;
     42     boolean hasGoToFullShadeEvent;
     43     boolean hasHeadsUpDisappearClickEvent;
     44     private ArraySet<Property> mAnimatedProperties = new ArraySet<>();
     45 
     46     public AnimationFilter animateAlpha() {
     47         animateAlpha = true;
     48         return this;
     49     }
     50 
     51     public AnimationFilter animateScale() {
     52         animate(View.SCALE_X);
     53         animate(View.SCALE_Y);
     54         return this;
     55     }
     56 
     57     public AnimationFilter animateX() {
     58         animateX = true;
     59         return this;
     60     }
     61 
     62     public AnimationFilter animateY() {
     63         animateY = true;
     64         return this;
     65     }
     66 
     67     public AnimationFilter hasDelays() {
     68         hasDelays = true;
     69         return this;
     70     }
     71 
     72     public AnimationFilter animateZ() {
     73         animateZ = true;
     74         return this;
     75     }
     76 
     77     public AnimationFilter animateHeight() {
     78         animateHeight = true;
     79         return this;
     80     }
     81 
     82     public AnimationFilter animateTopInset() {
     83         animateTopInset = true;
     84         return this;
     85     }
     86 
     87     public AnimationFilter animateDimmed() {
     88         animateDimmed = true;
     89         return this;
     90     }
     91 
     92     public AnimationFilter animateDark() {
     93         animateDark = true;
     94         return this;
     95     }
     96 
     97     public AnimationFilter animateHideSensitive() {
     98         animateHideSensitive = true;
     99         return this;
    100     }
    101 
    102     public AnimationFilter animateShadowAlpha() {
    103         animateShadowAlpha = true;
    104         return this;
    105     }
    106 
    107     public AnimationFilter animateY(View view) {
    108         animateYViews.add(view);
    109         return this;
    110     }
    111 
    112     public boolean shouldAnimateY(View view) {
    113         return animateY || animateYViews.contains(view);
    114     }
    115 
    116     /**
    117      * Combines multiple filters into {@code this} filter, using or as the operand .
    118      *
    119      * @param events The animation events from the filters to combine.
    120      */
    121     public void applyCombination(ArrayList<NotificationStackScrollLayout.AnimationEvent> events) {
    122         reset();
    123         int size = events.size();
    124         for (int i = 0; i < size; i++) {
    125             NotificationStackScrollLayout.AnimationEvent ev = events.get(i);
    126             combineFilter(events.get(i).filter);
    127             if (ev.animationType ==
    128                     NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) {
    129                 hasGoToFullShadeEvent = true;
    130             }
    131             if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
    132                     .ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) {
    133                 hasHeadsUpDisappearClickEvent = true;
    134             }
    135         }
    136     }
    137 
    138     public void combineFilter(AnimationFilter filter) {
    139         animateAlpha |= filter.animateAlpha;
    140         animateX |= filter.animateX;
    141         animateY |= filter.animateY;
    142         animateYViews.addAll(filter.animateYViews);
    143         animateZ |= filter.animateZ;
    144         animateHeight |= filter.animateHeight;
    145         animateTopInset |= filter.animateTopInset;
    146         animateDimmed |= filter.animateDimmed;
    147         animateDark |= filter.animateDark;
    148         animateHideSensitive |= filter.animateHideSensitive;
    149         animateShadowAlpha |= filter.animateShadowAlpha;
    150         hasDelays |= filter.hasDelays;
    151         mAnimatedProperties.addAll(filter.mAnimatedProperties);
    152     }
    153 
    154     public void reset() {
    155         animateAlpha = false;
    156         animateX = false;
    157         animateY = false;
    158         animateYViews.clear();
    159         animateZ = false;
    160         animateHeight = false;
    161         animateShadowAlpha = false;
    162         animateTopInset = false;
    163         animateDimmed = false;
    164         animateDark = false;
    165         animateHideSensitive = false;
    166         hasDelays = false;
    167         hasGoToFullShadeEvent = false;
    168         hasHeadsUpDisappearClickEvent = false;
    169         mAnimatedProperties.clear();
    170     }
    171 
    172     public AnimationFilter animate(Property property) {
    173         mAnimatedProperties.add(property);
    174         return this;
    175     }
    176 
    177     public boolean shouldAnimateProperty(Property property) {
    178         // TODO: migrate all existing animators to properties
    179         return mAnimatedProperties.contains(property);
    180     }
    181 }
    182