Example usage for android.animation ObjectAnimator addListener

List of usage examples for android.animation ObjectAnimator addListener

Introduction

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

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:by.gdgminsk.animationguide.util.AnimUtils.java

public static void scaleOut(final View view, int delay) {
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.0f);
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0.4f);
    ObjectAnimator scaleOutAnimation = ObjectAnimator.ofPropertyValuesHolder(view, alpha, scaleX, scaleY);
    scaleOutAnimation.setInterpolator(EASE_OUT_INTERPOLATOR);
    scaleOutAnimation.addListener(new AnimatorListenerAdapter() {
        @Override/*from w w w .j  a v  a  2 s. c om*/
        public void onAnimationEnd(Animator animation) {
            view.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationStart(Animator animation) {
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            view.setScaleX(0.0f);
            view.setScaleY(0.0f);
            view.setVisibility(View.GONE);
        }
    });
    scaleOutAnimation.setDuration(view.getResources().getInteger(R.integer.duration_fab_scale_out));
    scaleOutAnimation.setStartDelay(delay);

    scaleOutAnimation.start();
}

From source file:by.gdgminsk.animationguide.util.AnimUtils.java

public static void scaleIn(final View view, int delay) {
    view.setAlpha(0.0f);// w  w  w .ja v a  2s  .  c  o  m
    view.setScaleX(0.0f);
    view.setScaleY(0.0f);
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
    ObjectAnimator scaleInAnimation = ObjectAnimator.ofPropertyValuesHolder(view, alpha, scaleX, scaleY);
    scaleInAnimation.setDuration(view.getResources().getInteger(R.integer.duration_fab_scale_in));
    scaleInAnimation.setStartDelay(delay);
    scaleInAnimation.setInterpolator(EASE_IN_INTERPOLATOR);
    scaleInAnimation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            view.setAlpha(1.0f);
            view.setScaleX(1.0f);
            view.setScaleY(1.0f);
        }
    });
    scaleInAnimation.start();
}

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);//from   www.  j a  va2  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:Main.java

public static void animateTextChange(final TextView view, @IdRes final int toText, final Runnable rWhenEnd) {
    ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f);
    final ObjectAnimator restore = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
    alpha.setDuration(DURATION_SHORT);// w ww.j  a va2s. c  om
    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.
        }

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

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

        @Override
        public void onAnimationRepeat(Animator animation) {
            // Do nothing.
        }
    });
    if (rWhenEnd != null)
        restore.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                rWhenEnd.run();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                rWhenEnd.run();
            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
    alpha.start();
}

From source file:com.miz.utils.ViewUtils.java

public static void animateFabJump(View fab, Animator.AnimatorListener listener) {
    try {//from w  w  w .j  av  a  2s  .  c  om
        ObjectAnimator animation = ObjectAnimator.ofFloat(fab, "translationY", -10f, -5f, 0f, 5f, 10f, 5f, 0f,
                -5f, -10f, -5f, 0f);
        animation.setDuration(350);
        animation.addListener(listener);
        animation.start();
    } catch (Exception e) {
        // Some devices crash at runtime when using the ObjectAnimator
    }
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

public static void revealShow(final View view, boolean reveal) {
    if (reveal) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override/*  w  w w. ja  va  2 s . co  m*/
            public void onAnimationStart(Animator animation) {
                view.setVisibility(View.VISIBLE);
            }
        });
        animator.start();
    } else {

        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }
        });
        animator.start();
    }
}

From source file:ua.yyunikov.android.view.AdditionRemovalListView.java

public void removeWithAnimation(final AdditionRemovalAdapter.Item item, final View itemView) {
    final ObjectAnimator anim = ObjectAnimator.ofFloat(itemView, View.ALPHA, 0);

    anim.setDuration(ANIMATION_TIME);/* ww  w. ja v  a 2 s. c o  m*/
    ViewCompat.setHasTransientState(itemView, true);

    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            remove(item);
            itemView.setAlpha(1);
            ViewCompat.setHasTransientState(itemView, false);
        }
    });
    anim.start();
}

From source file:de.persoapp.android.activity.fragment.InitializeAppFragment.java

private void playSuccessAnimation() {
    ObjectAnimator animator = ObjectAnimator.ofFloat(this, "saturation", 1F);
    animator.setDuration(1000L);//w  ww .  j ava 2  s  . c  o m
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mImageView.animate().alpha(0).setDuration(300l).withEndAction(new Runnable() {
                @Override
                public void run() {
                    mEventBus.post(new OnAppInitialized(true));
                }
            });
        }
    });
    animator.start();
}

From source file:cn.hjl.newspush.mvp.ui.activities.NewsPhotoDetailActivity.java

private void startAnimation(final int endState, float startValue, float endValue) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(mPhotoDetailTitleTv, "alpha", startValue, endValue)
            .setDuration(200);/*w w w.j ava2s  . c o  m*/
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mPhotoDetailTitleTv.setVisibility(endState);
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    animator.start();
}

From source file:android.support.transition.ChangeClipBounds.java

@Override
public Animator createAnimator(@NonNull final ViewGroup sceneRoot, TransitionValues startValues,
        TransitionValues endValues) {//from w  w  w.j a  va 2  s. co  m
    if (startValues == null || endValues == null || !startValues.values.containsKey(PROPNAME_CLIP)
            || !endValues.values.containsKey(PROPNAME_CLIP)) {
        return null;
    }
    Rect start = (Rect) startValues.values.get(PROPNAME_CLIP);
    Rect end = (Rect) endValues.values.get(PROPNAME_CLIP);
    final boolean endIsNull = end == null;
    if (start == null && end == null) {
        return null; // No animation required since there is no clip.
    }

    if (start == null) {
        start = (Rect) startValues.values.get(PROPNAME_BOUNDS);
    } else if (end == null) {
        end = (Rect) endValues.values.get(PROPNAME_BOUNDS);
    }
    if (start.equals(end)) {
        return null;
    }

    ViewCompat.setClipBounds(endValues.view, start);
    RectEvaluator evaluator = new RectEvaluator(new Rect());
    ObjectAnimator animator = ObjectAnimator.ofObject(endValues.view, ViewUtils.CLIP_BOUNDS, evaluator, start,
            end);
    if (endIsNull) {
        final View endView = endValues.view;
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                ViewCompat.setClipBounds(endView, null);
            }
        });
    }
    return animator;
}