• 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 com.android.launcher3.LauncherAnimUtils;
24 
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 /**
29  * Utility class for building animator set
30  */
31 public class AnimatorSetBuilder {
32 
33     public static final int ANIM_VERTICAL_PROGRESS = 0;
34     public static final int ANIM_WORKSPACE_SCALE = 1;
35     public static final int ANIM_WORKSPACE_FADE = 2;
36     public static final int ANIM_OVERVIEW_SCALE = 3;
37     public static final int ANIM_OVERVIEW_FADE = 4;
38 
39     protected final ArrayList<Animator> mAnims = new ArrayList<>();
40 
41     private final SparseArray<Interpolator> mInterpolators = new SparseArray<>();
42     private List<Runnable> mOnFinishRunnables = new ArrayList<>();
43 
44     /**
45      * Associates a tag with all the animations added after this call.
46      */
startTag(Object obj)47     public void startTag(Object obj) { }
48 
play(Animator anim)49     public void play(Animator anim) {
50         mAnims.add(anim);
51     }
52 
addOnFinishRunnable(Runnable onFinishRunnable)53     public void addOnFinishRunnable(Runnable onFinishRunnable) {
54         mOnFinishRunnables.add(onFinishRunnable);
55     }
56 
build()57     public AnimatorSet build() {
58         AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
59         anim.playTogether(mAnims);
60         if (!mOnFinishRunnables.isEmpty()) {
61             anim.addListener(new AnimationSuccessListener() {
62                 @Override
63                 public void onAnimationSuccess(Animator animation) {
64                     for (Runnable onFinishRunnable : mOnFinishRunnables) {
65                         onFinishRunnable.run();
66                     }
67                     mOnFinishRunnables.clear();
68                 }
69             });
70         }
71         return anim;
72     }
73 
getInterpolator(int animId, Interpolator fallback)74     public Interpolator getInterpolator(int animId, Interpolator fallback) {
75         return mInterpolators.get(animId, fallback);
76     }
77 
setInterpolator(int animId, Interpolator interpolator)78     public void setInterpolator(int animId, Interpolator interpolator) {
79         mInterpolators.put(animId, interpolator);
80     }
81 }
82