Example usage for android.view.animation Animation setInterpolator

List of usage examples for android.view.animation Animation setInterpolator

Introduction

In this page you can find the example usage for android.view.animation Animation setInterpolator.

Prototype

public void setInterpolator(Interpolator i) 

Source Link

Document

Sets the acceleration curve for this animation.

Usage

From source file:Main.java

public static void expand(final View v, final int targetHeight, int duration, Interpolator interpolator,
        final Animation.AnimationListener listener) {
    final int initialHeight = v.getMeasuredHeight();
    Animation a = new Animation() {
        @Override/*from   w ww . j  a va2  s. c  o m*/
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = initialHeight + (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    a.setDuration(duration);
    if (interpolator != null) {
        a.setInterpolator(interpolator);
    }
    a.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            if (listener != null)
                listener.onAnimationStart(animation);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            v.setLayerType(View.LAYER_TYPE_NONE, null);
            if (listener != null)
                listener.onAnimationEnd(animation);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            if (listener != null)
                onAnimationRepeat(animation);
        }
    });

    v.startAnimation(a);
}

From source file:Main.java

/**
 * Creates an animation that rotates an {@link ImageView}
 * around the Y axis by 180 degrees and changes the image
 * resource shown when the view is rotated 90 degrees to the user.
 *
 * @param imageView   the view to rotate.
 * @param drawableRes the drawable to set when the view
 *                    is rotated by 90 degrees.
 * @return an animation that will change the image shown by the view.
 */// w ww  . j a va  2  s  .  c  om
@NonNull
public static Animation createRotationTransitionAnimation(@NonNull final ImageView imageView,
        @DrawableRes final int drawableRes) {
    Animation animation = new Animation() {

        private boolean mSetFinalDrawable;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime < 0.5f) {
                imageView.setRotationY(90 * interpolatedTime * 2f);
            } else {
                if (!mSetFinalDrawable) {
                    mSetFinalDrawable = true;
                    imageView.setImageResource(drawableRes);
                }
                imageView.setRotationY((-90) + (90 * (interpolatedTime - 0.5f) * 2f));
            }
        }
    };

    animation.setDuration(300);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());

    return animation;
}

From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java

private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation,
        float ratio, float anchor, int source) {
    bm = filter(iv, bm, fallback);/* www.j a v  a 2s  . c o  m*/
    if (bm == null) {
        iv.setImageBitmap(null);
        return;
    }
    Drawable d = makeDrawable(iv, bm, ratio, anchor);
    Animation anim = null;
    if (fadeIn(animation, source)) {
        if (preset == null) {
            anim = new AlphaAnimation(0, 1);
            anim.setInterpolator(new DecelerateInterpolator());
            anim.setDuration(FADE_DUR);
        } else {
            Drawable pd = makeDrawable(iv, preset, ratio, anchor);
            Drawable[] ds = new Drawable[] { pd, d };
            TransitionDrawable td = new TransitionDrawable(ds);
            td.setCrossFadeEnabled(true);
            td.startTransition(FADE_DUR);
            d = td;
        }
    } else if (animation > 0) {
        anim = AnimationUtils.loadAnimation(iv.getContext(), animation);
    }
    iv.setImageDrawable(d);
    if (anim != null) {
        anim.setStartTime(AnimationUtils.currentAnimationTimeMillis());
        iv.startAnimation(anim);
    } else {
        iv.setAnimation(null);
    }
}

From source file:com.webianks.library.ShowHideAnimation.java

public void animateOut(final RelativeLayout view) {
    Animation anim = AnimationUtils.loadAnimation(view.getContext(), R.anim.pop_out);
    anim.setInterpolator(INTERPOLATOR_OUT);
    anim.setDuration(250L);/*from w w w  .  j av  a 2 s  .c  om*/
    anim.setAnimationListener(new Animation.AnimationListener() {
        public void onAnimationStart(Animation animation) {
            //ScrollAwareFABBehavior.this.mIsAnimatingOut = true;
        }

        public void onAnimationEnd(Animation animation) {
            //ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
            view.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(final Animation animation) {
        }
    });
    view.startAnimation(anim);

}

From source file:com.webianks.library.ShowHideAnimation.java

public void animateIn(RelativeLayout view) {
    view.setVisibility(View.VISIBLE);
    Animation anim = AnimationUtils.loadAnimation(view.getContext(), R.anim.pop_in);
    anim.setDuration(300L);/*from  ww w. j a v a2 s.c  o m*/
    anim.setInterpolator(INTERPOLATOR);
    view.startAnimation(anim);
}

From source file:at.wada811.imageslider.ImageSliderFragment.java

public void setInterpolator(Interpolator interpolator) {
    Animation inAnimation = mImageSwitcher.getInAnimation();
    inAnimation.setInterpolator(interpolator);
    Animation outAnimation = mImageSwitcher.getOutAnimation();
    outAnimation.setInterpolator(interpolator);
    setInOutAnimation(inAnimation, outAnimation);
}

From source file:com.architjn.acjmusicplayer.elements.ScrollAwareFABBehavior.java

private void animateOut(final FloatingActionButton button) {
    Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.abc_slide_out_bottom);
    anim.setInterpolator(INTERPOLATOR);
    anim.setDuration(600L);/*from  w w  w.  j  a va2  s.  co  m*/
    anim.setAnimationListener(new Animation.AnimationListener() {
        public void onAnimationStart(Animation animation) {
            ScrollAwareFABBehavior.this.mIsAnimatingOut = true;
        }

        public void onAnimationEnd(Animation animation) {
            ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
            button.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(final Animation animation) {
        }
    });
    button.startAnimation(anim);
}

From source file:com.architjn.acjmusicplayer.elements.ScrollAwareFABBehavior.java

private void animateIn(FloatingActionButton button) {
    button.setVisibility(View.VISIBLE);
    Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.abc_slide_in_bottom);
    anim.setDuration(600L);/* ww w .  j a  va  2s .c om*/
    anim.setInterpolator(INTERPOLATOR);
    button.startAnimation(anim);
}

From source file:com.iven.lfflfeedreader.mainact.fabscroll.java

private void animateOut(final FloatingActionButton button) {
    if (Build.VERSION.SDK_INT >= 14) {
        ViewCompat.animate(button).scaleX(0.0F).scaleY(0.0F).alpha(0.0F).setInterpolator(INTERPOLATOR)
                .withLayer().setListener(new ViewPropertyAnimatorListener() {
                    public void onAnimationStart(View view) {
                        fabscroll.this.mIsAnimatingOut = true;
                    }//  w  ww . ja v a2 s . c om

                    public void onAnimationCancel(View view) {
                        fabscroll.this.mIsAnimatingOut = false;
                    }

                    public void onAnimationEnd(View view) {
                        fabscroll.this.mIsAnimatingOut = false;
                        view.setVisibility(View.GONE);
                    }
                }).start();
    } else {
        Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.fab_out);
        anim.setInterpolator(INTERPOLATOR);
        anim.setDuration(200L);
        anim.setAnimationListener(new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
                fabscroll.this.mIsAnimatingOut = true;
            }

            public void onAnimationEnd(Animation animation) {
                fabscroll.this.mIsAnimatingOut = false;
                button.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(final Animation animation) {
            }
        });
        button.startAnimation(anim);
    }
}

From source file:it.bellotti.android.materialdesignsample.ui.widget.ScrollAwareFABBehavior.java

private void animateFabOut(final FloatingActionButton button) {
    if (Build.VERSION.SDK_INT >= 14) {
        ViewCompat.animate(button).scaleX(0.0F).scaleY(0.0F).alpha(0.0F).setInterpolator(INTERPOLATOR)
                .withLayer().setListener(new ViewPropertyAnimatorListener() {
                    public void onAnimationStart(View view) {
                        ScrollAwareFABBehavior.this.mIsAnimatingOut = true;
                    }//from  w w w .j a  va2 s .c  om

                    public void onAnimationCancel(View view) {
                        ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
                    }

                    public void onAnimationEnd(View view) {
                        ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
                        view.setVisibility(View.GONE);
                    }
                }).start();
    } else {
        Animation anim = new ScaleAnimation(1.0F, 1.0F, 0.0F, 0.0F);
        anim.setInterpolator(INTERPOLATOR);
        anim.setDuration(200L);
        anim.setAnimationListener(new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
                ScrollAwareFABBehavior.this.mIsAnimatingOut = true;
            }

            public void onAnimationEnd(Animation animation) {
                ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
                button.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(final Animation animation) {
            }
        });
        button.startAnimation(anim);
    }
}