| 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 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 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 | |
|
| 35 | |
|
| 36 | |
private AnimationUtils() { |
| 37 | 0 | super(); |
| 38 | 0 | } |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 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 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 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 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 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 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 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 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public static void startFadeIn(Object view) { |
| 109 | 0 | createFadeInAnimator(view).start(); |
| 110 | 0 | } |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
public static void startFadeOut(Object view) { |
| 118 | 0 | createFadeOutAnimator(view).start(); |
| 119 | 0 | } |
| 120 | |
} |