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:fr.julienvermet.bugdroid.ui.tablet.AbsBugsMultiPaneFragment.java

public void expandBugsPane() {
    showLeftToolbox();//from  w  ww  .ja va2 s  .com
    int targetWidth = mExpandedBugsWidth;
    ValueAnimator animator = ValueAnimator.ofObject(new WidthEvaluator(mBugsPane), mBugsPane.getWidth(),
            targetWidth);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mIsBugShown = false;
        }
    });
    animator.setDuration(ANIMATION_DURATION);
    animator.start();
}

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

public void collapseLeftPane(int speed) {
    int targetWidth = mMinLeftWidth;
    ValueAnimator animator = ValueAnimator.ofObject(new WidthEvaluator(mLeftPane), mLeftPane.getWidth(),
            targetWidth);//from w  w  w. ja v  a 2 s.  co  m
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mLeftName.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mLeftView.setVisibility(View.GONE);
            mIsLeftCollapsed = true;
        }
    });
    animator.setInterpolator(new DecelerateInterpolator());
    animator.setDuration(speed);
    animator.start();
}

From source file:com.waz.zclient.pages.main.conversation.views.row.footer.FooterViewController.java

private void collapse() {
    if (shouldBeExpanded()) {
        return;//from   ww w.j  a  va2  s .c  om
    }
    if (message.getId().equals(container.getExpandedMessageId())) {
        container.setExpandedMessageId(null);
    }
    int origHeight = view.getHeight();

    ValueAnimator animator = createHeightAnimator(view, origHeight, 0);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(final Animator animator) {
            view.setVisibility(View.GONE);
        }
    });
    animator.start();
}

From source file:arun.com.chromer.browsing.article.util.ArticleScrollListener.java

private void animateBackgroundColor(int from, int to, Interpolator interpolator) {
    final ValueAnimator anim = new ValueAnimator();
    anim.setIntValues(from, to);//from  w  w w . ja va  2s . c  o  m
    anim.setEvaluator(new ArgbEvaluator());
    anim.setInterpolator(interpolator);
    anim.addUpdateListener(valueAnimator -> {
        toolbar.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
        statusBar.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
    });
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            isUpdatingBackground = false;
        }
    });

    anim.setDuration(ANIMATION_DURATION);
    anim.start();
    isUpdatingBackground = true;
}

From source file:edu.uark.spARK.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  a2  s.  c o 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;
                }
                mCallbacks.onDismiss(mListView, dismissPositions);

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(1f);
                    pendingDismiss.view.setTranslationX(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:br.com.halph.agendafeliz.util.SwipeableRecyclerViewTouchListener.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/* w  ww  .  j  ava 2s  .  com*/
        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:org.secuso.privacyfriendlypasswordgenerator.helpers.SwipeableRecyclerViewTouchListener.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//  w  ww. ja va2s  .c  o 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:com.itude.mobile.mobbl.blueprint.app.view.listeners.SwipeDismissRecyclerViewTouchListener.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;
    if (mIsVertical)
        originalHeight = dismissView.getWidth();
    else/*from  w w w.ja v a 2 s . co  m*/
        originalHeight = dismissView.getHeight();

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

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        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;
                }
                mCallbacks.onDismiss(dismissView, dismissPosition);

                // 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(1f);
                    if (mIsVertical)
                        pendingDismiss.view.setTranslationY(0);
                    else
                        pendingDismiss.view.setTranslationX(0);
                    lp = pendingDismiss.view.getLayoutParams();
                    if (mIsVertical)
                        lp.width = originalHeight;
                    else
                        lp.height = originalHeight;

                    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();
            }
        }
    });

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

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

From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButtonImpl.java

private ValueAnimator createAnimator(@NonNull ShadowAnimatorImpl impl) {
    final ValueAnimator animator = new ValueAnimator();
    animator.setInterpolator(ANIM_INTERPOLATOR);
    animator.setDuration(PRESSED_ANIM_DURATION);
    animator.addListener(impl);
    animator.addUpdateListener(impl);/*from w w w.j  a v a2  s .  com*/
    animator.setFloatValues(0, 1);
    return animator;
}

From source file:org.catrobat.paintroid.ui.BottomBar.java

private void delayedAnimateSelectedTool(int startDelay) {
    ImageButton button = getToolButtonByToolType(mCurrentToolType);
    int color = ContextCompat.getColor(button.getContext(), R.color.bottom_bar_button_activated);
    int fadedColor = color & 0x00ffffff;
    ValueAnimator valueAnimator = ObjectAnimator.ofInt(button, "backgroundColor", color, fadedColor);
    valueAnimator.setEvaluator(new ArgbEvaluator());
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.setDuration(500);/*from   w  ww  . java  2  s.  c  o m*/
    valueAnimator.setRepeatCount(5);
    valueAnimator.setRepeatMode(ValueAnimator.REVERSE);
    valueAnimator.setStartDelay(startDelay);
    valueAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (PaintroidApplication.currentTool != null) {
                setActivatedToolButton(PaintroidApplication.currentTool.getToolType());
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    valueAnimator.start();
}