diff options
author | Andrew Lee <anwlee@google.com> | 2014-08-19 12:19:13 -0700 |
---|---|---|
committer | Andrew Lee <anwlee@google.com> | 2014-08-19 14:16:45 -0700 |
commit | b652c8c99a729edac5c090d866cea578db02e77b (patch) | |
tree | 5c402a7e201e8875ac5eab2308f74eab595bf8df /src/com/android/phone | |
parent | c099585dda8585300f05b8be1d48d0ddea52260e (diff) | |
download | packages_apps_PhoneCommon-b652c8c99a729edac5c090d866cea578db02e77b.tar.gz packages_apps_PhoneCommon-b652c8c99a729edac5c090d866cea578db02e77b.tar.bz2 packages_apps_PhoneCommon-b652c8c99a729edac5c090d866cea578db02e77b.zip |
Add scaleIn/scaleOut animation utils. Add delay field to fadeIn.
Bug: 16399233
Change-Id: I915c5b76875b9cc947822bc786cde49f375fde56
Diffstat (limited to 'src/com/android/phone')
-rw-r--r-- | src/com/android/phone/common/animation/AnimUtils.java | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/com/android/phone/common/animation/AnimUtils.java b/src/com/android/phone/common/animation/AnimUtils.java index 3a5f679..7db5810 100644 --- a/src/com/android/phone/common/animation/AnimUtils.java +++ b/src/com/android/phone/common/animation/AnimUtils.java @@ -75,13 +75,20 @@ public class AnimUtils { } public static void fadeIn(View fadeIn, int duration) { - fadeIn(fadeIn, duration, null); + fadeIn(fadeIn, duration, 0 /* delay */, null); } public static void fadeIn(final View fadeIn, int duration, final AnimationCallback callback) { + fadeIn(fadeIn, duration, 0 /* delay */, callback); + } + + public static void fadeIn( + final View fadeIn, int duration, int delay, final AnimationCallback callback) { fadeIn.setAlpha(0); final ViewPropertyAnimator animator = fadeIn.animate(); animator.cancel(); + + animator.setStartDelay(delay); animator.alpha(1).withLayer().setListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { @@ -110,6 +117,70 @@ public class AnimUtils { } /** + * Scales in the view from scale of 0 to actual dimensions. + * @param view The view to scale. + * @param duration The duration of the scaling. + */ + public static void scaleIn(final View view, int duration) { + AnimatorListenerAdapter listener = (new AnimatorListenerAdapter() { + @Override + public void onAnimationStart(Animator animation) { + view.setVisibility(View.VISIBLE); + } + + @Override + public void onAnimationCancel(Animator animation) { + view.setScaleX(1); + view.setScaleY(1); + } + }); + scaleInternal(view, duration, 0 /* startScaleValue */, 1 /* endScaleValue */, listener); + } + + + /** + * Scales out the view from actual dimensions to 0. + * @param view The view to scale. + * @param duration The duration of the scaling. + */ + public static void scaleOut(final View view, int duration) { + AnimatorListenerAdapter listener = new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + view.setVisibility(View.GONE); + } + + @Override + public void onAnimationCancel(Animator animation) { + view.setVisibility(View.GONE); + view.setScaleX(0); + view.setScaleY(0); + } + }; + + scaleInternal(view, duration, 1 /* startScaleValue */, 0 /* endScaleValue */, listener); + } + + private static void scaleInternal(final View view, int duration, int startScaleValue, + int endScaleValue, AnimatorListenerAdapter listener) { + view.setScaleX(startScaleValue); + view.setScaleY(startScaleValue); + + final ViewPropertyAnimator animator = view.animate(); + animator.cancel(); + + animator.setInterpolator(EASE_OUT_EASE_IN) + .scaleX(endScaleValue) + .scaleY(endScaleValue) + .setListener(listener); + + if (duration != DEFAULT_DURATION) { + animator.setDuration(duration); + } + animator.start(); + } + + /** * Animates a view to the new specified dimensions. * @param view The view to change the dimensions of. * @param newWidth The new width of the view. |