Example usage for android.animation ValueAnimator addListener

List of usage examples for android.animation ValueAnimator addListener

Introduction

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

public static void startScaleAnime(final View view, float newScale, Animator.AnimatorListener listener) {
    ValueAnimator anime = ValueAnimator.ofFloat(view.getScaleX(), newScale);
    anime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from w  w  w  . ja  v a 2s .  c om*/
        public void onAnimationUpdate(ValueAnimator animation) {
            float s = Float.parseFloat(animation.getAnimatedValue().toString());
            view.setScaleX(s);
            view.setScaleY(s);
        }
    });
    if (listener != null) {
        anime.addListener(listener);
    }
    anime.setDuration(mAnimeDuration);
    anime.start();
}

From source file:com.pdftron.pdf.utils.ViewerUtils.java

/**
 * Creates an Animator object that varies the alpha property of the view. The
 * interpolation used is linear.//from   w w w.  ja  v  a  2s.c om
 *
 * @param view the view to be animated
 * @param listener the listener to be used by this Animator
 *
 * @return a new Animator object that will change the "alpha" property
 * of the view.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static Animator createAlphaAnimator(View view, Animator.AnimatorListener listener) {
    if (view == null) {
        return null;
    }
    // We animate only the opacity of the view.
    ValueAnimator fader = ObjectAnimator.ofFloat(view, "alpha", 0.0f, 1.0f, 0.4f, 1.0f, 0.0f);
    fader.setDuration(1500);
    fader.setEvaluator(new FloatEvaluator());
    if (listener != null) {
        fader.addListener(listener);
    }
    return fader;
}

From source file:org.hawkular.client.android.util.ViewTransformer.java

@UiThread
public void collapse() {
    ValueAnimator animator = ValueAnimator.ofInt(Views.measureHeight(view), 0);
    animator.setInterpolator(new LinearOutSlowInInterpolator());
    animator.setDuration(Durations.MEDIUM);

    animator.addUpdateListener(this);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override/*from  w  w w  .  ja  v a  2  s .  c om*/
        public void onAnimationEnd(Animator animation) {
            view.setVisibility(View.GONE);
        }
    });

    animator.start();
}

From source file:com.waz.zclient.pages.main.conversation.views.row.message.views.TextMessageWithTimestamp.java

private void collapseTimestamp() {
    messageViewContainer.getTimestampShownSet().remove(messageId);
    int origHeight = timestampTextView.getHeight();

    ValueAnimator animator = createHeightAnimator(timestampTextView, origHeight, 0);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override/*  w  w  w . j  a  v a2 s .c o  m*/
        public void onAnimationEnd(final Animator animator) {
            timestampTextView.setVisibility(View.GONE);
        }
    });
    animator.start();
}

From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissTouchListener.java

private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss
    // callback.//  ww  w. j  a va 2  s. c  o  m
    // This triggers layout on each animation frame; in the future we may
    // want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCallback.onDismiss(mView, mToken);
            // Reset view presentation
            setAlpha(mView, 1f);
            setTranslationX(mView, 0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
        }
    });

    animator.start();
}

From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissListViewTouchListener.java

private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override//w  ww  . j  a v  a  2 s  . c  om
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                mCallback.onDismiss(mListView, dismissPositions);

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    setAlpha(pendingDismiss.view, 1f);
                    setTranslationX(pendingDismiss.view, 0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalHeight;
                    pendingDismiss.view.setLayoutParams(lp);
                }

                mPendingDismisses.clear();
            }
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:se.kth.csc.stayawhile.swipe.QueueTouchListener.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalLayoutParamsHeight = lp.height;
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override/*from   w  w  w .j a va 2s . c om*/
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }

                mQueueSwipeListener.onDismiss(mRecyclerView, dismissPositions);

                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;

                ViewGroup.LayoutParams lp;
                for (PendingActionData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(mAlpha);
                    pendingDismiss.view.setTranslationX(0);

                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalLayoutParamsHeight;

                    pendingDismiss.view.setLayoutParams(lp);
                }

                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);

                mPendingDismisses.clear();
                mAnimatingPosition = ListView.INVALID_POSITION;
            }
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingActionData(dismissPosition, dismissView));
    animator.start();
}

From source file:com.brandon.mailbox.RecyclerSwipeListener.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalLayoutParamsHeight = lp.height;
    final int originalHeight = dismissView.getHeight();
    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override//from   w  w w. j a v  a  2 s . co m
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);
                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                if (mFinalDelta < 0) {
                    mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions);
                } else {
                    mSwipeListener.onDismissedBySwipeRight(mRecyclerView, dismissPositions);
                }
                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;
                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(mAlpha);
                    pendingDismiss.view.setTranslationX(0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalLayoutParamsHeight;
                    pendingDismiss.view.setLayoutParams(lp);
                }
                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);
                mPendingDismisses.clear();
                mAnimatingPosition = ListView.INVALID_POSITION;
            }
        }
    });
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });
    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:fr.julienvermet.bugdroid.ui.tablet.AbsBugsMultiPaneFragment.java

public void collapseBugsPane() {
    int targetWidth = mCollapsedBugsWidth;
    ValueAnimator animator = ValueAnimator.ofObject(new WidthEvaluator(mBugsPane), mBugsPane.getWidth(),
            targetWidth);/*from   w w w.  j a  v a2 s.co m*/
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mIsBugShown = true;
        }
    });
    animator.setDuration(ANIMATION_DURATION);
    animator.start();
}

From source file:fr.julienvermet.bugdroid.ui.tablet.AbsBugsMultiPaneFragment.java

public void expandLeftPane(int speed) {
    int targetWidth = mMaxLeftWidth;
    ValueAnimator animator = ValueAnimator.ofObject(new WidthEvaluator(mLeftPane), mLeftPane.getWidth(),
            targetWidth);//from  w  w w .  j  ava  2  s. c  o m
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mIsLeftCollapsed = false;
        }
    });
    animator.setInterpolator(new DecelerateInterpolator());
    animator.setDuration(speed);
    animator.start();
}