Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

In this page you can find the example usage for android.animation ObjectAnimator ofFloat.

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty,
        Path path) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties.

Usage

From source file:Main.java

/**
 * translation x//ww  w. j  ava 2  s.c  om
 *
 * @param v
 * @param fromX
 * @param toX
 * @param duration
 * @param animatorListener
 */
public static void translationX(View v, float fromX, float toX, int duration,
        Animator.AnimatorListener animatorListener) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.TRANSLATION_X, fromX, toX);
    animator.setDuration(duration);
    if (animatorListener != null) {
        animator.addListener(animatorListener);
    }
    animator.start();
}

From source file:Main.java

/**
 * alpha/*from   ww w. j av a2s  .  c om*/
 *
 * @param v
 * @param fromAlpha
 * @param toAlpha
 * @param duration
 * @param animatorListener
 */
public static void alpha(View v, float fromAlpha, float toAlpha, int duration,
        Animator.AnimatorListener animatorListener) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.ALPHA, fromAlpha, toAlpha);
    animator.setDuration(duration);
    if (animatorListener != null) {
        animator.addListener(animatorListener);
    }
    animator.start();
}

From source file:com.flexible.flexibleadapter.helpers.AnimatorHelper.java

/**
 * This is the default animator.//  w  w  w.  j a  va  2 s .  c  o m
 *
 * @param animators user defined list of animators
 * @param view      itemView to animate
 * @param alphaFrom starting alpha value
 * @since 5.0.0-b1
 */
public static void alphaAnimator(@NonNull List<Animator> animators, @NonNull View view,
        @FloatRange(from = 0.0, to = 1.0) float alphaFrom) {
    ViewCompat.setAlpha(view, 0);
    animators.add(ObjectAnimator.ofFloat(view, "alpha", alphaFrom, 1f));
}

From source file:Main.java

@NonNull
private static AnimatorSet createDisappearAnim(View startBtn, View pick1, View pick2, View image,
        View headline) {//from   w w w. j  a va 2 s .com
    AnimatorSet animAll = new AnimatorSet();

    Animator anim1_1 = ObjectAnimator.ofFloat(headline, View.ALPHA, 1, 0);
    Animator anim1_2 = ObjectAnimator.ofFloat(startBtn, View.ALPHA, 1, 0);
    Animator anim1_3 = ObjectAnimator.ofFloat(startBtn, View.ALPHA, 1, 0);
    Animator anim1_4 = ObjectAnimator.ofFloat(pick1, View.ALPHA, 1, 0);
    Animator anim1_5 = ObjectAnimator.ofFloat(pick2, View.ALPHA, 1, 0);
    setBatchTiming(400, 0, anim1_1, anim1_2, anim1_3, anim1_4, anim1_5);
    animAll.play(anim1_1).with(anim1_2).with(anim1_3).with(anim1_4).with(anim1_5);

    Interpolator interpolator2 = new DecelerateInterpolator();
    Animator anim2_1 = ObjectAnimator.ofFloat(image, View.ALPHA, 1, 0);
    Animator anim2_2 = ObjectAnimator.ofFloat(image, View.SCALE_X, 1f, 2f);
    Animator anim2_3 = ObjectAnimator.ofFloat(image, View.SCALE_Y, 1f, 2f);
    anim2_1.setInterpolator(interpolator2);
    anim2_2.setInterpolator(interpolator2);
    anim2_3.setInterpolator(interpolator2);
    setBatchTiming(800, 0, anim2_1, anim2_2, anim2_3);
    animAll.play(anim2_1).with(anim2_2).with(anim2_3).after(anim1_1);
    return animAll;
}

From source file:Main.java

public static void animateTextChange(final TextView view, final String toText) {
    ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f);
    final ObjectAnimator restore = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
    alpha.setDuration(DURATION_SHORT);/*  w  w  w .  j  a  v a 2  s . c o  m*/
    alpha.setInterpolator(new AccelerateDecelerateInterpolator());
    restore.setDuration(DURATION_SHORT);
    restore.setInterpolator(new AccelerateDecelerateInterpolator());
    alpha.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            // Do nothing.
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            view.setText(toText);
            restore.start();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            view.setText(toText);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            // Do nothing.
        }
    });
    alpha.start();
}

From source file:com.flexible.flexibleadapter.helpers.AnimatorHelper.java

/**
 * Item will slide from Left to Right./*ww w . j a  va2  s. com*/
 *
 * @param animators user defined list of animators
 * @param view      itemView to animate
 * @param percent   any % multiplier (between 0 and 1) of the LayoutManager Width
 * @since 5.0.0-b1
 */
public static void slideInFromLeftAnimator(@NonNull List<Animator> animators, @NonNull View view,
        RecyclerView recyclerView, @FloatRange(from = 0.0, to = 1.0) float percent) {
    alphaAnimator(animators, view, 0f);
    animators.add(ObjectAnimator.ofFloat(view, "translationX",
            -recyclerView.getLayoutManager().getWidth() * percent, 0));
    if (FlexibleAdapter.DEBUG)
        Log.v(TAG, " Added LEFT Animator");
}

From source file:eu.davidea.flexibleadapter.helpers.AnimatorHelper.java

/**
 * Item will slide from Left to Right./* ww  w  . j  a  v a  2 s . co  m*/
 *
 * @param animators user defined list
 * @param view      itemView to animate
 * @param percent   any % multiplier (between 0 and 1) of the LayoutManager Width
 * @since 5.0.0-b1
 */
public static void slideInFromLeftAnimator(@NonNull List<Animator> animators, @NonNull View view,
        RecyclerView recyclerView, @FloatRange(from = 0.0, to = 1.0) float percent) {
    alphaAnimator(animators, view, 0f);
    animators.add(ObjectAnimator.ofFloat(view, "translationX",
            -recyclerView.getLayoutManager().getWidth() * percent, 0));
    if (FlexibleAdapter.DEBUG)
        Log.v(TAG, "Added LEFT Animator");
}

From source file:com.flexible.flexibleadapter.helpers.AnimatorHelper.java

/**
 * Item will slide from Right to Left./*from www .ja v  a  2s.  c o  m*/
 *
 * @param animators user defined list of animators
 * @param view      ItemView to animate
 * @param percent   Any % multiplier (between 0 and 1) of the LayoutManager Width
 * @since 5.0.0-b1
 */
public static void slideInFromRightAnimator(@NonNull List<Animator> animators, @NonNull View view,
        RecyclerView recyclerView, @FloatRange(from = 0.0, to = 1.0) float percent) {
    alphaAnimator(animators, view, 0f);
    animators.add(ObjectAnimator.ofFloat(view, "translationX",
            recyclerView.getLayoutManager().getWidth() * percent, 0));
    if (FlexibleAdapter.DEBUG)
        Log.v(TAG, " Added RIGHT Animator");
}

From source file:eu.davidea.flexibleadapter.helpers.AnimatorHelper.java

/**
 * Item will slide from Right to Left.//from   ww  w  .  ja  v  a2s . c o  m
 *
 * @param animators user defined list
 * @param view      ItemView to animate
 * @param percent   Any % multiplier (between 0 and 1) of the LayoutManager Width
 * @since 5.0.0-b1
 */
public static void slideInFromRightAnimator(@NonNull List<Animator> animators, @NonNull View view,
        RecyclerView recyclerView, @FloatRange(from = 0.0, to = 1.0) float percent) {
    alphaAnimator(animators, view, 0f);
    animators.add(ObjectAnimator.ofFloat(view, "translationX",
            recyclerView.getLayoutManager().getWidth() * percent, 0));
    if (FlexibleAdapter.DEBUG)
        Log.v(TAG, "Added RIGHT Animator");
}

From source file:com.h6ah4i.android.example.materialshadowninepatch.ZPositionAnimationDemoFragment.java

@Override
public void onClick(View v) {
    if (v == mCompatShadowItem) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(mCompatShadowItemContainer,
                MaterialShadowContainerViewProperties.SHADOW_TRANSLATION_Z, mDisplayDensity * 0.0f,
                mDisplayDensity * 8.0f);
        animator.setDuration(500);/*  w  w  w  .jav a 2s .c o m*/
        animator.setInterpolator(new CycleInterpolator(0.5f));
        animator.start();
    }
}