Example usage for android.view View animate

List of usage examples for android.view View animate

Introduction

In this page you can find the example usage for android.view View animate.

Prototype

public ViewPropertyAnimator animate() 

Source Link

Document

This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View.

Usage

From source file:Main.java

public static void rotate(final View view, float fromDegrees, float toDegrees, long duration) {
    if (Build.VERSION.SDK_INT >= 12) {
        if (duration == 0)
            view.setRotation(toDegrees);
        else//from  w w  w  . j  ava2  s.  c o  m
            view.animate().rotation(toDegrees).setDuration(duration).start();
    } else {
        RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(duration);
        rotate.setFillEnabled(true);
        rotate.setFillBefore(true);
        rotate.setFillAfter(true);
        addAnimation(view, rotate);
    }
}

From source file:com.dgsd.android.ShiftTracker.Util.PageTransformerUtils.java

public static ViewPager.PageTransformer getInnerCubeTransformer() {
    if (mInnerCubeTransformer == null) {
        mInnerCubeTransformer = new ViewPager.PageTransformer() {
            @Override//from   w  ww .j  av  a 2  s  .  c  om
            public void transformPage(View view, float position) {
                if (!Api.isMin(Api.HONEYCOMB))
                    return;

                final float distFromZero = Math.abs(position);
                view.animate().alpha(1.0f - distFromZero).rotationY(-45 * position).setDuration(0).start();
            }
        };
    }

    return mInnerCubeTransformer;
}

From source file:com.dgsd.android.ShiftTracker.Util.PageTransformerUtils.java

public static ViewPager.PageTransformer getOuterCubeTransformer() {
    if (mOuterCubeTransformer == null) {
        mOuterCubeTransformer = new ViewPager.PageTransformer() {
            @Override/*from w  w w .ja v  a  2s .co  m*/
            public void transformPage(View view, float position) {
                if (!Api.isMin(Api.HONEYCOMB))
                    return;

                final float distFromZero = Math.abs(position);
                view.animate().alpha(1.0f - distFromZero).rotationY(45 * position).setDuration(0).start();
            }
        };
    }

    return mOuterCubeTransformer;
}

From source file:com.dgsd.android.ShiftTracker.Util.PageTransformerUtils.java

public static ViewPager.PageTransformer getCompressTransformer() {
    if (mCompressTransformer == null) {
        mCompressTransformer = new ViewPager.PageTransformer() {
            @Override// ww w . j a v  a  2 s  .c o  m
            public void transformPage(View view, float position) {
                if (!Api.isMin(Api.HONEYCOMB))
                    return;

                final float distFromZero = Math.abs(position);
                view.animate().alpha(1.0f - distFromZero).scaleX(1.0f - distFromZero)
                        .scaleY(1.0f - distFromZero).setDuration(0).start();
            }
        };
    }

    return mCompressTransformer;
}

From source file:Main.java

/**
 * Cancel any previous animation.//from   w  ww.  j  a  v  a  2 s  .  com
 * @param view the view.
 */
public static void cancelAnimation(View view) {
    Animation animation = view.getAnimation();
    if (animation != null) {
        animation.reset();
        animation.cancel();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        view.animate().cancel();
    }
    view.clearAnimation();
}

From source file:Main.java

private static void scaleInternal(final View view, int startScaleValue, int endScaleValue, int durationMs,
        int startDelay, AnimatorListenerAdapter listener, Interpolator interpolator) {
    view.setScaleX(startScaleValue);/*from w ww.j a v  a2  s .co  m*/
    view.setScaleY(startScaleValue);

    final ViewPropertyAnimator animator = view.animate();
    animator.cancel();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue)
                .setListener(listener);
    } else {
        animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue).setListener(listener)
                .withLayer();
    }
    if (durationMs != DEFAULT_DURATION) {
        animator.setDuration(durationMs);
    }
    animator.setStartDelay(startDelay);

    animator.start();
}

From source file:com.erevacation.challenge.rxjavaanimator.ViewAnimatorCreator.java

private static ViewPropertyAnimator animateFadeIn(View view, int duration, int delay,
        TimeInterpolator interpolator) {
    view.setAlpha(0);//ww  w .  j a v  a2  s  .  com
    ViewPropertyAnimator propertyAnimator = view.animate().alpha(1).setStartDelay(delay).setDuration(duration);
    if (interpolator != null) {
        propertyAnimator.setInterpolator(interpolator);
    } else {
        propertyAnimator.setInterpolator(new LinearOutSlowInInterpolator());
    }

    return propertyAnimator;
}

From source file:com.erevacation.challenge.rxjavaanimator.ViewAnimatorCreator.java

private static ViewPropertyAnimator animateFadeOut(View view, int duration, int delay,
        TimeInterpolator interpolator) {
    view.setAlpha(1);/*from w  ww  . ja v  a  2 s . c o  m*/
    ViewPropertyAnimator propertyAnimator = view.animate().alpha(0).setStartDelay(delay).setDuration(duration);
    if (interpolator != null) {
        propertyAnimator.setInterpolator(interpolator);
    } else {
        propertyAnimator.setInterpolator(new FastOutLinearInInterpolator());
    }

    return propertyAnimator;
}

From source file:Main.java

private static void scaleInternal(final View view, int startScaleValue, int endScaleValue, int durationMs,
        int startDelay, AnimatorListenerAdapter listener, Interpolator interpolator) {
    view.setScaleX(startScaleValue);//from   w w w.  j a  va  2  s . c o m
    view.setScaleY(startScaleValue);

    final ViewPropertyAnimator animator = view.animate();
    animator.cancel();

    animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue).setListener(listener)
            .withLayer();

    if (durationMs != DEFAULT_DURATION) {
        animator.setDuration(durationMs);
    }
    animator.setStartDelay(startDelay);

    animator.start();
}

From source file:com.dgsd.android.ShiftTracker.Util.PageTransformerUtils.java

public static ViewPager.PageTransformer getTwistTransformer() {
    if (mTwistTransformer == null) {
        mTwistTransformer = new ViewPager.PageTransformer() {
            @Override//  w  w w .ja  va2 s .c  o  m
            public void transformPage(View view, float position) {
                if (!Api.isMin(Api.HONEYCOMB))
                    return;

                view.setPivotX(0);
                view.setPivotY(0);

                final float distFromZero = Math.abs(position);
                view.animate().alpha(1.0f - distFromZero).rotation(90 * position).setDuration(0).start();
            }
        };
    }

    return mTwistTransformer;
}