Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AnimationUtils |
|
| 1.0;1 |
1 | package org.jtheque.core.utils.ui; | |
2 | ||
3 | import org.jdesktop.animation.timing.Animator; | |
4 | import org.jdesktop.animation.timing.Animator.RepeatBehavior; | |
5 | import org.jdesktop.animation.timing.interpolation.PropertySetter; | |
6 | ||
7 | /* | |
8 | * This file is part of JTheque. | |
9 | * | |
10 | * JTheque is free software: you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation, either version 3 of the License. | |
13 | * | |
14 | * JTheque is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
21 | */ | |
22 | ||
23 | /** | |
24 | * An utility class for animation. | |
25 | * | |
26 | * @author Baptiste Wicht | |
27 | */ | |
28 | public final class AnimationUtils { | |
29 | private static final float LONG_ACCELERATION = 0.4f; | |
30 | private static final float SHORT_ACCELERATION = 0.2f; | |
31 | private static final int SPRING_EFFECT_DURATION = 400; | |
32 | ||
33 | /** | |
34 | * This is an utility class, not instanciable. | |
35 | */ | |
36 | private AnimationUtils() { | |
37 | 0 | super(); |
38 | 0 | } |
39 | ||
40 | /** | |
41 | * Create a Fade Out animator for the view. | |
42 | * | |
43 | * @param view The view to fade out. | |
44 | * @return The animator. | |
45 | */ | |
46 | public static Animator createFadeOutAnimator(Object view) { | |
47 | 0 | Animator fadeOut = PropertySetter.createAnimator(1000, view, "alpha", 0.0f); |
48 | ||
49 | 0 | fadeOut.setAcceleration(SHORT_ACCELERATION); |
50 | 0 | fadeOut.setDeceleration(LONG_ACCELERATION); |
51 | ||
52 | 0 | return fadeOut; |
53 | } | |
54 | ||
55 | /** | |
56 | * Create a fade in animator for a view. | |
57 | * | |
58 | * @param view The view to fade in. | |
59 | * @return The animator. | |
60 | */ | |
61 | public static Animator createFadeInAnimator(Object view) { | |
62 | 0 | Animator fadeIn = PropertySetter.createAnimator(1000, view, "alpha", 1.0f); |
63 | ||
64 | 0 | fadeIn.setAcceleration(LONG_ACCELERATION); |
65 | 0 | fadeIn.setDeceleration(SHORT_ACCELERATION); |
66 | ||
67 | 0 | return fadeIn; |
68 | } | |
69 | ||
70 | /** | |
71 | * Create a spring effect animator for a view. | |
72 | * | |
73 | * @param view The view to animate. | |
74 | * @return The animator. | |
75 | */ | |
76 | public static Animator createSpringEffectAnimator(Object view) { | |
77 | 0 | Animator springEffect = PropertySetter.createAnimator(SPRING_EFFECT_DURATION, view, "zoom", 0.0f, 1.0f); |
78 | ||
79 | 0 | springEffect.setAcceleration(SHORT_ACCELERATION); |
80 | 0 | springEffect.setDeceleration(LONG_ACCELERATION); |
81 | ||
82 | 0 | return springEffect; |
83 | } | |
84 | ||
85 | /** | |
86 | * Create a simple loop effect for the view. | |
87 | * | |
88 | * @param view The view to animate. | |
89 | * @param duration The duration of the animation. | |
90 | * @param property The property to loop. | |
91 | * @param to The to value. | |
92 | * @return The animator. | |
93 | */ | |
94 | public static Animator createLoopEffect(Object view, int duration, String property, int to) { | |
95 | 0 | Animator loop = PropertySetter.createAnimator(duration, view, property, to); |
96 | ||
97 | 0 | loop.setRepeatBehavior(RepeatBehavior.LOOP); |
98 | 0 | loop.setRepeatCount(Animator.INFINITE); |
99 | ||
100 | 0 | return loop; |
101 | } | |
102 | ||
103 | /** | |
104 | * Fade in the view. | |
105 | * | |
106 | * @param view The view to fade in. | |
107 | */ | |
108 | public static void startFadeIn(Object view) { | |
109 | 0 | createFadeInAnimator(view).start(); |
110 | 0 | } |
111 | ||
112 | /** | |
113 | * Fade out the view. | |
114 | * | |
115 | * @param view The view to fade out. | |
116 | */ | |
117 | public static void startFadeOut(Object view) { | |
118 | 0 | createFadeOutAnimator(view).start(); |
119 | 0 | } |
120 | } |