blob: 182adf55f2dcc2c7b10ce89fb5921af28129473c [file] [log] [blame]
Michael Jurka2ecf9952012-06-18 12:52:28 -07001/*
2 * Copyright (C) 2012 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
17package com.android.launcher2;
18
19import android.animation.Animator;
20import android.animation.AnimatorSet;
21import android.animation.ObjectAnimator;
22import android.animation.PropertyValuesHolder;
23import android.animation.ValueAnimator;
24
25import java.util.HashSet;
26
27public class LauncherAnimUtils {
28 static HashSet<Animator> sAnimators = new HashSet<Animator>();
29 Animator.AnimatorListener sEndAnimListener = new Animator.AnimatorListener() {
30 public void onAnimationStart(Animator animation) {
31 }
32
33 public void onAnimationRepeat(Animator animation) {
34 }
35
36 public void onAnimationEnd(Animator animation) {
37 sAnimators.remove(animation);
38 }
39
40 public void onAnimationCancel(Animator animation) {
41 sAnimators.remove(animation);
42 }
43 };
44
45 public static void cancelOnDestroyActivity(Animator a) {
46 sAnimators.add(a);
47 }
48
49 public static void onDestroyActivity() {
50 for (Animator a : sAnimators) {
51 if (a.isRunning()) {
52 a.cancel();
53 }
54 }
55 }
56
57 public static AnimatorSet createAnimatorSet() {
58 AnimatorSet anim = new AnimatorSet();
59 cancelOnDestroyActivity(anim);
60 return anim;
61 }
62
63 public static ValueAnimator ofFloat(float... values) {
64 ValueAnimator anim = new ValueAnimator();
65 anim.setFloatValues(values);
66 cancelOnDestroyActivity(anim);
67 return anim;
68 }
69
70 public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
71 ObjectAnimator anim = new ObjectAnimator();
72 anim.setTarget(target);
73 anim.setPropertyName(propertyName);
74 anim.setFloatValues(values);
75 cancelOnDestroyActivity(anim);
76 return anim;
77 }
78
79 public static ObjectAnimator ofPropertyValuesHolder(Object target,
80 PropertyValuesHolder... values) {
81 ObjectAnimator anim = new ObjectAnimator();
82 anim.setTarget(target);
83 anim.setValues(values);
84 cancelOnDestroyActivity(anim);
85 return anim;
86 }
87}