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:com.hippo.android.animator.AnimatorsBase.java

static Animator crossFade(final View from, final View to, ViewGroup ancestor, final boolean toIsTop) {
    // Ensure views is laid out
    if (!ViewCompat.isLaidOut(from) || !ViewCompat.isLaidOut(to)) {
        Log.w(LOG_TAG, "From view and to view must be laid out before calling crossFade().");
        return null;
    }//  w w w  .  j a v a2s .  c  om

    // Get overlay
    final ViewOverlayCompat overlay = ViewOverlayCompat.from(ancestor);
    if (overlay == null) {
        Log.w(LOG_TAG, "The ancestor in crossFade() must be able to create a ViewOverlay.");
        return null;
    }

    // Get the location of from view
    if (!Utils.getLocationInAncestor(from, ancestor, TEMP_LOCATION)) {
        Log.w(LOG_TAG, "From view must be in ancestor in crossFade().");
        return null;
    }
    int fromX = TEMP_LOCATION[0];
    int fromY = TEMP_LOCATION[1];

    // Get the location of to view
    if (!Utils.getLocationInAncestor(to, ancestor, TEMP_LOCATION)) {
        Log.w(LOG_TAG, "From view must be in ancestor in crossFade().");
        return null;
    }
    int toX = TEMP_LOCATION[0];
    int toY = TEMP_LOCATION[1];

    // Get the screenshot of from view
    final Bitmap fromBitmap = Utils.screenshot(from);
    if (fromBitmap == null) {
        Log.w(LOG_TAG, "Can't screenshot from view in crossFade().");
        return null;
    }

    // Get the screenshot of to view
    final Bitmap toBitmap = Utils.screenshot(to);
    if (toBitmap == null) {
        Log.w(LOG_TAG, "Can't screenshot to view in crossFade().");
        fromBitmap.recycle();
        return null;
    }

    // Create start drawables
    final Drawable fromDrawable = new BitmapDrawable(from.getContext().getResources(), fromBitmap);
    int fromWidth = fromBitmap.getWidth();
    int fromHeight = fromBitmap.getHeight();
    fromDrawable.setBounds(fromX, fromY, fromX + fromWidth, fromY + fromHeight);

    int fromCenterX = fromX + fromWidth / 2;
    int fromCenterY = fromY + fromHeight / 2;

    // Create end drawable
    final Drawable toDrawable = new BitmapDrawable(to.getContext().getResources(), toBitmap);
    int toWidth = toBitmap.getWidth();
    int toHeight = toBitmap.getHeight();
    int toStartX = fromCenterX - toWidth / 2;
    int toStartY = fromCenterY - toHeight / 2;
    toDrawable.setBounds(toStartX, toStartY, toStartX + toWidth, toStartY + toHeight);

    int toCenterX = toX + toWidth / 2;
    int toCenterY = toY + toHeight / 2;

    List<Animator> set = new ArrayList<>(4);

    // Create alpha animators
    Animator fromAlpha = ObjectAnimator.ofInt(fromDrawable, DRAWABLE_ALPHA_PROPERTY, 255, 0);
    Animator toAlpha = ObjectAnimator.ofInt(toDrawable, DRAWABLE_ALPHA_PROPERTY, 0, 255);
    set.add(fromAlpha);
    set.add(toAlpha);

    // Create position animators
    if (fromCenterX != toCenterX || fromCenterY != toCenterY) {
        Path path = ACR_PATH_MOTION.getPath(fromCenterX, fromCenterY, toCenterX, toCenterY);
        Animator fromPosition = Animators.ofPointF(fromDrawable, DRAWABLE_POSITION_PROPERTY, path);
        Animator toPosition = Animators.ofPointF(toDrawable, DRAWABLE_POSITION_PROPERTY, path);
        set.add(fromPosition);
        set.add(toPosition);
    }

    Animator animator = Animators.playTogether(set);
    animator.addListener(new AnimatorListenerAdapter() {
        float fromAlpha;
        float toAlpha;

        @Override
        public void onAnimationStart(Animator animation) {
            // Add drawables to overlay
            if (toIsTop) {
                overlay.add(fromDrawable);
                overlay.add(toDrawable);
            } else {
                overlay.add(toDrawable);
                overlay.add(fromDrawable);
            }
            // Hide from view and to view
            fromAlpha = from.getAlpha();
            toAlpha = to.getAlpha();
            from.setAlpha(0.0f);
            to.setAlpha(0.0f);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // Remove drawables from overlay
            overlay.remove(fromDrawable);
            overlay.remove(toDrawable);
            // Show from view and to view
            from.setAlpha(fromAlpha);
            to.setAlpha(toAlpha);
            // Recycle bitmaps
            fromBitmap.recycle();
            toBitmap.recycle();
        }
    });

    return animator;
}

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

/**
 * Animates RecyclerView card on click with revealing effect
 * @param viewHolder to make animation on
 *///from w  ww. j  av  a2 s  .c o m
public static void animationCard(RecyclerView.ViewHolder viewHolder) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        if (mBlueColor == 0) {
            mBlueColor = ContextCompat.getColor(viewHolder.itemView.getContext(), R.color.colorPrimary);
        }
        if (mWhiteColor == 0) {
            mWhiteColor = 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(mBlueColor);
        anim.start();
        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

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

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
    }
}

From source file:com.fastbootmobile.encore.utils.Utils.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Animator animateCircleReveal(final View view, final int cx, final int cy, final int startRadius,
        final int endRadius, final long duration, final long startDelay) {
    Animator animator = ViewAnimationUtils.createCircularReveal(view, cx, cy, startRadius, endRadius)
            .setDuration(duration);/*from w w w. java2s  .c  om*/
    animator.setStartDelay(startDelay);
    animator.setInterpolator(new DecelerateInterpolator());
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (startRadius > endRadius) {
                view.setVisibility(View.INVISIBLE);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    animator.start();

    return animator;
}

From source file:com.taobao.weex.ui.animation.WXAnimationModule.java

public static void startAnimation(WXSDKInstance mWXSDKInstance, WXComponent component,
        @NonNull WXAnimationBean animationBean, @Nullable String callback) {
    if (component == null) {
        return;/*from  w ww  .j av a 2s  . c o  m*/
    }
    if (component.getHostView() == null) {
        AnimationHolder holder = new AnimationHolder(animationBean, callback);
        component.postAnimation(holder);
        return;
    }
    try {
        Animator animator = createAnimator(animationBean, component.getHostView(),
                mWXSDKInstance.getViewPortWidth());
        if (animator != null) {
            Animator.AnimatorListener animatorCallback = createAnimatorListener(mWXSDKInstance, callback);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
                component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
            }
            Interpolator interpolator = createTimeInterpolator(animationBean);
            if (animatorCallback != null) {
                animator.addListener(animatorCallback);
            }
            if (interpolator != null) {
                animator.setInterpolator(interpolator);
            }
            animator.setDuration(animationBean.duration);
            animator.start();
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
        WXLogUtils.e("", e);
    }
}

From source file:ooo.oxo.apps.materialize.SearchPanelController.java

public void close() {
    if (container.getVisibility() == View.INVISIBLE) {
        return;/* ww  w .j a v  a 2  s  . co m*/
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Animator animator = makeSearchPanelAnimator(true);

        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                container.setVisibility(View.INVISIBLE);
                keyword.clearFocus();
            }
        });

        animator.start();
    } else {
        container.setVisibility(View.INVISIBLE);
    }

    softInputManager.hide();
}

From source file:com.angelatech.yeyelive.view.PeriscopeLayout.java

public void addHeart() {
    ImageView imageView = new ImageView(getContext());
    //?//from w w  w  .  j  ava  2s . c  o  m
    imageView.setImageDrawable(drawables[random.nextInt(7)]);
    imageView.setLayoutParams(lp);
    addView(imageView);
    Animator set = getAnimator(imageView);
    set.addListener(new AnimEndListener(imageView));
    set.start();
}

From source file:com.mvcoding.financius.feature.RevealTransition.java

@Override
public Animator onAppear(ViewGroup sceneRoot, final View view, TransitionValues startValues,
        TransitionValues endValues) {//from  w  w w .  j a  va2 s  .c o m
    float radius = calculateMaxRadius(view);
    final float originalAlpha = 1; // TODO: For some reason this returns 0 view.getAlpha();
    view.setAlpha(0f);

    Animator reveal = createAnimator(view, 0, radius);
    reveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            view.setAlpha(originalAlpha);
        }
    });
    return reveal;
}

From source file:org.amahi.anywhere.tv.fragment.IntroFragment.java

@Override
protected void onPageChanged(final int newPage, int previousPage) {
    if (mContentAnimator != null) {
        mContentAnimator.end();/*from   w w w .  j a  v a2  s  .c o m*/
    }

    ArrayList<Animator> animators = new ArrayList<>();

    Animator fadeOut = createFadeOutAnimator(mContentView);

    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            Log.d(getClass().getName(), String.valueOf(newPage));
            mContentView.setImageResource(CONTENT_IMAGES[newPage]);
            switch (newPage) {
            case 0:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 1:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 2:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 3:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 4:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 5:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            }
        }
    });

    animators.add(fadeOut);

    animators.add(createFadeInAnimator(mContentView));

    AnimatorSet set = new AnimatorSet();

    set.playSequentially(animators);

    set.start();

    mContentAnimator = set;
}

From source file:com.google.samples.apps.ourstreets.fragment.StreetViewFragment.java

@Override
public void onBackPressed() {
    if (isRestored) {
        getFragmentManager().popBackStack();
    } else {/*from www  .j a v  a2s .  c o  m*/
        // Perform a circular conceal, then pop this fragment off the back stack.
        final FrameLayout view = ((FrameLayout) getView());
        //noinspection ConstantConditions
        Animator circularConceal = ViewUtils.createCircularConceal(mRevealCenter, mRevealWidth, view,
                INTERPOLATOR);
        circularConceal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
                getFragmentManager().popBackStack();
            }
        });
        circularConceal.start();
    }
}

From source file:com.ruesga.rview.fragments.RevealDialogFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void performEnterRevealTransition() {
    if (!mDoReveal || getDialog() == null || getDialog().getWindow() == null) {
        mDoReveal = false;/*from  w ww .j  av a 2s .c  om*/
        return;
    }

    final View v = getDialog().getWindow().getDecorView();
    if (!v.isAttachedToWindow()) {
        mDoReveal = false;
        return;
    }
    v.setVisibility(View.VISIBLE);
    Rect dialogRect = computeViewOnScreen(v);

    int cx = v.getMeasuredWidth() / 2;
    int cy = v.getMeasuredHeight() / 2;
    if (mAnchorRect != null) {
        cx = Math.min(Math.max(mAnchorRect.centerX(), dialogRect.left), dialogRect.right) - dialogRect.left;
        cy = Math.min(Math.max(mAnchorRect.centerY(), dialogRect.top), dialogRect.bottom) - dialogRect.top;
    }

    int finalRadius = Math.max(v.getWidth(), v.getHeight());
    Animator anim = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, finalRadius);
    anim.setDuration(350);
    anim.setInterpolator(new AccelerateInterpolator());
    anim.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            onDialogReveled();
            mDoReveal = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    anim.start();
}