Android Open Source - RZAndroidBaseUtils Resize Animation






From Project

Back to project page RZAndroidBaseUtils.

License

The source code is released under:

MIT License

If you think the Android project RZAndroidBaseUtils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.raizlabs.view.animation;
/* w  ww .jav  a2  s.  c  o m*/
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Transformation;

import com.raizlabs.baseutils.Math;

/**
 * View Animation class which animates the size of a given {@link View}
 * from one set of values to another. This class alters the
 * {@link LayoutParams}, modifies the width and height, and calls
 * {@link View#requestLayout()}.
 * 
 * @author Dylan James
 */
public class ResizeAnimation extends Animation {
  private View view;
  private int fromWidth, fromHeight, toWidth, toHeight;
  private boolean finished;
  /**
   * @return True if this animation has run to completion.
   */
  public boolean isFinished() { return finished; }
  
  /**
   * Creates a {@link ResizeAnimation} for the given {@link View} between the
   * given sizes.
   * @param view The {@link View} to animate.
   * @param fromWidth The initial width to animate from.
   * @param fromHeight The initial height to animate from.
   * @param toWidth The target width to animate to.
   * @param toHeight The target height to animate to.
   */
  public ResizeAnimation(View view, int fromWidth, int fromHeight, int toWidth, int toHeight) {
    this.view = view;
    this.fromWidth = fromWidth;
    this.fromHeight = fromHeight;
    this.toWidth = toWidth;
    this.toHeight = toHeight;
    finished = false;
  }
  
  /**
   * Creates a {@link ResizeAnimation} for the given {@link View} between the
   * given sizes over the given duration
   * @param view The {@link View} to animate.
   * @param fromWidth The initial width to animate from.
   * @param fromHeight The initial height to animate from.
   * @param toWidth The target width to animate to.
   * @param toHeight The target height to animate to.
   * @param durationMillis The duration of the animation in milliseconds.
   */
  public ResizeAnimation(View view, int fromWidth, int fromHeight, int toWidth, int toHeight, long durationMillis) {
    this(view, fromWidth, fromHeight, toWidth, toHeight);
    setDuration(durationMillis);
  }

  @Override
  public void reset() {
    this.finished = false;
    super.reset();
  }
  
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    // Interpolate to get the values for the current time step
    int newWidth = (int) (Math.lerp(fromWidth, toWidth, interpolatedTime));
    int newHeight = (int) (Math.lerp(fromHeight, toHeight, interpolatedTime));

    // If the time is >= 1, we're done
    if (interpolatedTime >= 1) {
      // Clamp the sizes
      newWidth = toWidth;
      newHeight = toHeight;
      // Indicate we've finished
      finished = true;
    } else {
      finished = false;
    }

    if (view == null)
      return;
    
    // Update the Views layout params
    LayoutParams params = view.getLayoutParams();
    params.height = newHeight;
    params.width = newWidth;
    // Set the params and request a layout pass to size the view
    view.setLayoutParams(params);
    view.requestLayout();
  }

  @Override
  public void initialize(int width, int height, int parentWidth, int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
  }

  @Override
  public boolean willChangeBounds() {
    return true;
  }
}




Java Source Code List

com.raizlabs.baseutils.CompatibilityUtils.java
com.raizlabs.baseutils.IOUtils.java
com.raizlabs.baseutils.Logger.java
com.raizlabs.baseutils.Math.java
com.raizlabs.baseutils.StringUtils.java
com.raizlabs.baseutils.ThreadingUtils.java
com.raizlabs.baseutils.Wrapper.java
com.raizlabs.baseutils.examples.MainActivity.java
com.raizlabs.baseutils.examples.asyncdrawable.AsyncDrawableExampleActivity.java
com.raizlabs.baseutils.examples.asyncdrawable.AsyncDrawableListExampleActivity.java
com.raizlabs.baseutils.examples.simplegenericadapter.SimpleGenericAdapterExampleActivity.java
com.raizlabs.baseutils.examples.viewgroupadapter.ViewGroupAdapterExampleActivity.java
com.raizlabs.baseutils.examples.viewholderstrategy.SimpleViewHolderStrategyExampleActivity.java
com.raizlabs.collections.ListUtils.java
com.raizlabs.collections.MappableSet.java
com.raizlabs.collections.TransactionalHashSet.java
com.raizlabs.concurrent.BasePrioritizedRunnable.java
com.raizlabs.concurrent.ConcurrencyUtils.java
com.raizlabs.concurrent.PrioritizedRunnable.java
com.raizlabs.concurrent.Prioritized.java
com.raizlabs.content.sharing.SharingUtils.java
com.raizlabs.database.CursorIterable.java
com.raizlabs.database.CursorIterator.java
com.raizlabs.events.EventListener.java
com.raizlabs.events.Event.java
com.raizlabs.events.ProgressListener.java
com.raizlabs.events.SimpleEventListener.java
com.raizlabs.functions.Delegate.java
com.raizlabs.functions.Predicate.java
com.raizlabs.functions.Provider.java
com.raizlabs.graphics.ImageFactory.java
com.raizlabs.graphics.drawable.async.AsyncDrawableTask.java
com.raizlabs.graphics.drawable.async.AsyncDrawableUtils.java
com.raizlabs.graphics.drawable.async.AsyncDrawableWrapper.java
com.raizlabs.graphics.drawable.async.AsyncDrawable.java
com.raizlabs.graphics.drawable.async.BaseAsyncDrawableTask.java
com.raizlabs.imagecaching.ImageCache.java
com.raizlabs.imagecaching.PrefixedImageCacheAdapter.java
com.raizlabs.imagecaching.StubImageCache.java
com.raizlabs.json.JSONArrayParserDelegate.java
com.raizlabs.json.JSONHelper.java
com.raizlabs.synchronization.OneShotLock.java
com.raizlabs.tasks.RZAsyncTaskEvent.java
com.raizlabs.tasks.RZAsyncTaskListener.java
com.raizlabs.tasks.RZAsyncTask.java
com.raizlabs.util.observable.ObservableData.java
com.raizlabs.util.observable.ObservableListAdapter.java
com.raizlabs.util.observable.ObservableList.java
com.raizlabs.view.ViewCompatibility.java
com.raizlabs.view.animation.AnimationListenerWrapper.java
com.raizlabs.view.animation.RelativeLayoutParamsAnimation.java
com.raizlabs.view.animation.ResizeAnimation.java
com.raizlabs.widget.EvenLinearLayout.java
com.raizlabs.widget.ImageMixView.java
com.raizlabs.widget.SlideRevealLayout.java
com.raizlabs.widget.ViewUtils.java
com.raizlabs.widget.adapters.ListBasedAdapter.java
com.raizlabs.widget.adapters.SimpleGenericAdapter.java
com.raizlabs.widget.adapters.ViewGroupAdapter.java
com.raizlabs.widget.adapters.ViewHolderStrategyAdapter.java
com.raizlabs.widget.utils.SimpleViewHolderStrategy.java
com.raizlabs.widget.utils.ViewHolderStrategyConverter.java
com.raizlabs.widget.utils.ViewHolderStrategyUtils.java
com.raizlabs.widget.utils.ViewHolderStrategy.java