• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.android.launcher3.anim;
17 
18 import android.animation.Animator;
19 import android.animation.AnimatorSet;
20 import android.util.SparseArray;
21 import android.view.animation.Interpolator;
22 
23 import java.util.ArrayList;
24 import java.util.List;
25 
26 /**
27  * Utility class for building animator set
28  */
29 public class AnimatorSetBuilder {
30 
31     public static final int ANIM_VERTICAL_PROGRESS = 0;
32     public static final int ANIM_WORKSPACE_SCALE = 1;
33     public static final int ANIM_WORKSPACE_TRANSLATE = 2;
34     public static final int ANIM_WORKSPACE_FADE = 3;
35     public static final int ANIM_HOTSEAT_SCALE = 4;
36     public static final int ANIM_HOTSEAT_TRANSLATE = 5;
37     public static final int ANIM_OVERVIEW_SCALE = 6;
38     public static final int ANIM_OVERVIEW_TRANSLATE_X = 7;
39     public static final int ANIM_OVERVIEW_TRANSLATE_Y = 8;
40     public static final int ANIM_OVERVIEW_FADE = 9;
41     public static final int ANIM_ALL_APPS_FADE = 10;
42 
43     public static final int FLAG_DONT_ANIMATE_OVERVIEW = 1 << 0;
44 
45     protected final ArrayList<Animator> mAnims = new ArrayList<>();
46 
47     private final SparseArray<Interpolator> mInterpolators = new SparseArray<>();
48     private List<Runnable> mOnFinishRunnables = new ArrayList<>();
49     private int mFlags = 0;
50 
play(Animator anim)51     public void play(Animator anim) {
52         mAnims.add(anim);
53     }
54 
addOnFinishRunnable(Runnable onFinishRunnable)55     public void addOnFinishRunnable(Runnable onFinishRunnable) {
56         mOnFinishRunnables.add(onFinishRunnable);
57     }
58 
build()59     public AnimatorSet build() {
60         AnimatorSet anim = new AnimatorSet();
61         anim.playTogether(mAnims);
62         if (!mOnFinishRunnables.isEmpty()) {
63             anim.addListener(new AnimationSuccessListener() {
64                 @Override
65                 public void onAnimationSuccess(Animator animation) {
66                     for (Runnable onFinishRunnable : mOnFinishRunnables) {
67                         onFinishRunnable.run();
68                     }
69                     mOnFinishRunnables.clear();
70                 }
71             });
72         }
73         return anim;
74     }
75 
getInterpolator(int animId, Interpolator fallback)76     public Interpolator getInterpolator(int animId, Interpolator fallback) {
77         return mInterpolators.get(animId, fallback);
78     }
79 
setInterpolator(int animId, Interpolator interpolator)80     public void setInterpolator(int animId, Interpolator interpolator) {
81         mInterpolators.put(animId, interpolator);
82     }
83 
addFlag(int flag)84     public void addFlag(int flag) {
85         mFlags |= flag;
86     }
87 
hasFlag(int flag)88     public boolean hasFlag(int flag) {
89         return (mFlags & flag) != 0;
90     }
91 }
92