From 5ead1b9b7742203fc0f08bee39fee79939cbfed3 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 15 Aug 2014 16:36:44 -0700 Subject: Add a changeDimensions method which animates a width/height change. Bug: 16399233 Change-Id: I1b5f9b2e487fcb95c380b9eb94f7cbbbf2d98571 --- .../android/phone/common/animation/AnimUtils.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/com/android') diff --git a/src/com/android/phone/common/animation/AnimUtils.java b/src/com/android/phone/common/animation/AnimUtils.java index 35ac107..3a5f679 100644 --- a/src/com/android/phone/common/animation/AnimUtils.java +++ b/src/com/android/phone/common/animation/AnimUtils.java @@ -18,11 +18,14 @@ package com.android.phone.common.animation; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; +import android.animation.ValueAnimator; import android.view.View; import android.view.ViewPropertyAnimator; import android.view.animation.Interpolator; import android.view.animation.PathInterpolator; +import java.lang.Float; + public class AnimUtils { public static final int DEFAULT_DURATION = -1; public static final Interpolator EASE_IN = new PathInterpolator(0.0f, 0.0f, 0.2f, 1.0f); @@ -105,4 +108,31 @@ public class AnimUtils { } 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. + * @param newHeight The new height of the view. + */ + public static void changeDimensions(final View view, final int newWidth, final int newHeight) { + ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f); + + final int oldWidth = view.getWidth(); + final int oldHeight = view.getHeight(); + final int deltaWidth = newWidth - oldWidth; + final int deltaHeight = newHeight - oldHeight; + + animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animator) { + Float value = (Float) animator.getAnimatedValue(); + + view.getLayoutParams().width = (int) (value * deltaWidth + oldWidth); + view.getLayoutParams().height = (int) (value * deltaHeight + oldHeight); + view.requestLayout(); + } + }); + animator.start(); + } } -- cgit v1.2.3