Example usage for android.animation Animator addListener

List of usage examples for android.animation Animator addListener

Introduction

In this page you can find the example usage for android.animation Animator 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:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void show(final View view, final int cornerType, int normalAnimRes,
        final AnimatorListenerAdapter listener) {
    try {/*www  .ja  v  a  2s  .c o  m*/
        int[] amaya = calulateCorner(view, cornerType);
        Animator anim = ViewAnimationUtils.createCircularReveal(view, amaya[0], amaya[1], 0, amaya[2]);
        anim.setInterpolator(new LinearInterpolator());
        anim.setDuration(300);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                view.setVisibility(View.VISIBLE);
                if (listener != null) {
                    listener.onAnimationStart(animation);
                }
            }

        });
        anim.start();
    } catch (Exception e) {
        e.printStackTrace();
        view.setVisibility(View.VISIBLE);
    }
}

From source file:com.andryr.guitartuner.Utils.java

public static void hide(final View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // get the center for the clipping circle
        int cx = view.getWidth() / 2;
        int cy = view.getHeight() / 2;

        // get the initial radius for the clipping circle
        float initialRadius = (float) Math.hypot(cx, cy);

        // create the animation (the final radius is zero)
        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0);

        // make the view invisible when the animation is done
        anim.addListener(new AnimatorListenerAdapter() {
            @Override/*from   w ww  .  j av  a2s  .co m*/
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });

        // start the animation
        anim.start();
    } else {
        view.animate().alpha(0f).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        }).start();
    }
}

From source file:Main.java

public static void circleReveal(final View targetView, int centerX, int centerY, boolean isReverse) {
    if (targetView == null || !targetView.isAttachedToWindow())
        return;//from   w w  w .j a va2  s.  co  m
    int radius = (int) Math.hypot(targetView.getHeight(), targetView.getWidth());

    Animator animator;
    if (isReverse) {
        animator = isCircleRevealSupported()
                ? ViewAnimationUtils.createCircularReveal(targetView, centerX, centerY, radius, 0)
                : createFade(targetView, 1, 0);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                targetView.setVisibility(View.GONE);
            }
        });
    } else {
        animator = isCircleRevealSupported()
                ? ViewAnimationUtils.createCircularReveal(targetView, centerX, centerY, 0, radius)
                : createFade(targetView, 0, 1);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                targetView.setVisibility(View.VISIBLE);
            }
        });
    }
    animator.setDuration(DURATION);
    animator.start();
}

From source file:im.ene.ribbon.AnimUtil.java

static void animate(BottomNavigationView parent, View view, final View backgroundOverlay,
        final ColorDrawable backgroundDrawable, final int newColor, long duration) {
    int centerX = (int) (ViewCompat.getX(view) + (view.getWidth() / 2));
    int centerY = parent.getPaddingTop() + view.getHeight() / 2;

    backgroundOverlay.clearAnimation();/*w  w  w.  j a  v a2s .co m*/

    final Object animator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Animator currentAnimator = (Animator) backgroundOverlay.getTag(R.id.ribbon_background_overlay_animator);
        if (currentAnimator != null) {
            //currentAnimator.end();
            currentAnimator.cancel();
        }

        final float startRadius = 1;
        final float finalRadius = centerX > parent.getWidth() / 2 ? centerX : parent.getWidth() - centerX;
        animator = ViewAnimationUtils.createCircularReveal(backgroundOverlay, centerX, centerY, startRadius,
                finalRadius);
        backgroundOverlay.setTag(R.id.ribbon_background_overlay_animator, animator);
    } else {
        ViewCompat.setAlpha(backgroundOverlay, 0);
        animator = ViewCompat.animate(backgroundOverlay).alpha(1);
    }

    backgroundOverlay.setBackgroundColor(newColor);
    backgroundOverlay.setVisibility(View.VISIBLE);

    if (animator instanceof ViewPropertyAnimatorCompat) {
        ((ViewPropertyAnimatorCompat) animator).setListener(new ViewPropertyAnimatorListener() {
            boolean cancelled;

            @Override
            public void onAnimationStart(final View view) {
            }

            @Override
            public void onAnimationEnd(final View view) {
                if (!cancelled) {
                    backgroundDrawable.setColor(newColor);
                    backgroundOverlay.setVisibility(View.INVISIBLE);
                    ViewCompat.setAlpha(backgroundOverlay, 1);
                }
            }

            @Override
            public void onAnimationCancel(final View view) {
                cancelled = true;
            }
        }).setDuration(duration).start();
    } else {
        Animator animator1 = (Animator) animator;
        animator1.setDuration(duration);
        animator1.setInterpolator(new DecelerateInterpolator());
        animator1.addListener(new Animator.AnimatorListener() {
            boolean cancelled;

            @Override
            public void onAnimationStart(final Animator animation) {
            }

            @Override
            public void onAnimationEnd(final Animator animation) {
                if (!cancelled) {
                    backgroundDrawable.setColor(newColor);
                    backgroundOverlay.setVisibility(View.INVISIBLE);
                    ViewCompat.setAlpha(backgroundOverlay, 1);
                }
            }

            @Override
            public void onAnimationCancel(final Animator animation) {
                cancelled = true;
            }

            @Override
            public void onAnimationRepeat(final Animator animation) {
            }
        });

        animator1.start();
    }
}

From source file:com.chromium.fontinstaller.util.ViewUtils.java

public static void reveal(Activity activity, View view, View sourceView, int colorRes) {
    if (activity == null || view == null || sourceView == null)
        return;//from   ww w.  ja v a 2  s. c  o m
    if (isLollipop()) {
        final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) activity.getWindow().getDecorView()
                .getOverlay();

        final Rect displayRect = new Rect();
        view.getGlobalVisibleRect(displayRect);

        // Make reveal cover the display and status bar.
        final View revealView = new View(activity);
        revealView.setTop(displayRect.top);
        revealView.setBottom(displayRect.bottom);
        revealView.setLeft(displayRect.left);
        revealView.setRight(displayRect.right);
        revealView.setBackgroundColor(ContextCompat.getColor(activity, colorRes));
        groupOverlay.add(revealView);

        final int[] clearLocation = new int[2];
        sourceView.getLocationInWindow(clearLocation);
        clearLocation[0] += sourceView.getWidth() / 2;
        clearLocation[1] += sourceView.getHeight() / 2;

        final int revealCenterX = clearLocation[0] - revealView.getLeft();
        final int revealCenterY = clearLocation[1] - revealView.getTop();

        final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
        final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
        final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
        final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

        try {
            final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
                    revealCenterY, 0.0f, revealRadius);
            revealAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_mediumAnimTime));

            final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
            alphaAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_shortAnimTime));
            alphaAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.abc_fade_in));
                    view.setVisibility(View.VISIBLE);
                }
            });

            final AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.play(revealAnimator).before(alphaAnimator);
            animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    groupOverlay.remove(revealView);
                }
            });

            animatorSet.start();
        } catch (IllegalStateException e) {
            Timber.i("View is detached - not animating");
        }
    } else {
        view.setVisibility(View.VISIBLE);
    }
}

From source file:Main.java

public static void enterReveal(final View view) {
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override//  w  w w  .  j  a v  a  2 s.  c om
        public void onGlobalLayout() {
            Animator animator = null;

            view.getViewTreeObserver().removeOnGlobalLayoutListener(this);

            int cx = view.getMeasuredWidth() / 2;
            int cy = view.getMeasuredHeight() / 2;

            try {
                final int finalRadius = Math.max(view.getWidth(), view.getHeight()) / 2 + 125;
                animator = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);

                animator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                    }
                });
            } catch (Exception ignored) {
            }

            view.setVisibility(View.VISIBLE);
            if (animator != null) {
                animator.start();
            }
        }
    });
}

From source file:com.yoloo.android.util.AnimUtils.java

public static Animator createCircularReveal(RevealFrameLayout view, int x, int y, float startRadius,
        float endRadius) {
    if (VersionUtil.hasL()) {
        return ViewAnimationUtils.createCircularReveal(view, x, y, startRadius, endRadius);
    } else {//  w w  w . j av a  2s. c  o  m
        view.setClipOutLines(true);
        view.setClipCenter(x, y);
        final Animator reveal = ObjectAnimator.ofFloat(view, "ClipRadius", startRadius, endRadius);
        reveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setClipOutLines(false);
            }
        });

        return reveal;
    }
}

From source file:com.adkdevelopment.rssreader.utils.Utilities.java

/**
 * Animates RecyclerView card on click with revealing effect
 * @param viewHolder to make animation on
 *//*from  www. ja  v a 2  s  . c  o m*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void animationCard(RecyclerView.ViewHolder viewHolder) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (sBlueColor == 0) {
            sBlueColor = ContextCompat.getColor(viewHolder.itemView.getContext(), R.color.colorPrimary);
        }
        if (sWhiteColor == 0) {
            sWhiteColor = ContextCompat.getColor(viewHolder.itemView.getContext(), R.color.white);
        }

        int finalRadius = (int) Math.hypot(viewHolder.itemView.getWidth() / 2,
                viewHolder.itemView.getHeight() / 2);

        Animator anim = ViewAnimationUtils.createCircularReveal(viewHolder.itemView,
                viewHolder.itemView.getWidth() / 2, viewHolder.itemView.getHeight() / 2, 0, finalRadius);

        viewHolder.itemView.setBackgroundColor(sBlueColor);
        anim.start();
        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                viewHolder.itemView.setBackgroundColor(sWhiteColor);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
    }
}

From source file:com.syncedsynapse.kore2.utils.UIUtils.java

/**
 * Launches the remote activity, performing a circular reveal animation if
 * Lollipop or later/*from   ww  w .  ja  v a  2  s .  c o m*/
 *
 * @param context Context
 * @param centerX Center X of the animation
 * @param centerY Center Y of the animation
 * @param exitTransitionView View to reveal. Should occupy the whole screen and
 *                           be invisible before calling this
 */
@TargetApi(21)
public static void switchToRemoteWithAnimation(final Context context, int centerX, int centerY,
        final View exitTransitionView) {
    final Intent launchIntent = new Intent(context, RemoteActivity.class);
    if (Utils.isLollipopOrLater()) {
        // Show the animation
        int endRadius = Math.max(exitTransitionView.getHeight(), exitTransitionView.getWidth());
        Animator exitAnim = ViewAnimationUtils.createCircularReveal(exitTransitionView, centerX, centerY, 0,
                endRadius);

        exitAnim.setDuration(200);
        exitAnim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                // Launch remote activity
                context.startActivity(launchIntent);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        exitTransitionView.setVisibility(View.VISIBLE);
        exitAnim.start();
    } else {
        // No animation show, just launch the remote
        context.startActivity(launchIntent);
    }
}

From source file:com.hippo.android.animator.AnimatorsBase.java

static Animator circularReveal(View view, int centerX, int centerY, float startRadius, float endRadius) {
    if (view instanceof Revealable && startRadius != endRadius) {
        Animator animator = ObjectAnimator.ofFloat((Revealable) view, new RevealProperty(centerX, centerY),
                startRadius, endRadius);
        animator.addListener(new RevealAnimatorListener((Revealable) view));
        return animator;
    } else {// www .  j a  v  a2 s  . c o  m
        return null;
    }
}