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:ru.tinkoff.acquiring.sdk.views.KeyView.java

private ValueAnimator createCircleAnimator() {
    final float maxDimen = Math.max(getWidth(), getHeight()) * 0.8F;
    final ValueAnimator animator = ValueAnimator.ofFloat(0F, maxDimen);
    animator.setDuration(CIRCLE_ANIMATION_DURATION_MILLIS);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from  w w  w . j av a 2  s  .c om*/
        public void onAnimationUpdate(ValueAnimator animation) {
            circleRadius = (Float) animation.getAnimatedValue();
            invalidate();
        }
    });

    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            drawingPressAnimation = false;
            invalidate();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

    return animator;
}

From source file:xyz.klinker.android.article.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 va2 s .com
    anim.setEvaluator(new ArgbEvaluator());
    anim.setInterpolator(interpolator);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator 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:es.ugr.swad.swadroid.gui.SwipeListViewTouchListener.java

private void performSwipeAction(final View swipeView, final int swipePosition, boolean toTheRight,
        boolean dismiss) {
    // 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 = swipeView.getLayoutParams();
    final int originalHeight = swipeView.getHeight();
    final boolean swipeRight = toTheRight;

    ValueAnimator animator;
    if (dismiss)/* w w  w. j a va2s  .  c  om*/
        animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    else
        animator = ValueAnimator.ofInt(originalHeight, 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(mPendingSwipes);

                int[] swipePositions = new int[mPendingSwipes.size()];
                for (int i = mPendingSwipes.size() - 1; i >= 0; i--) {
                    swipePositions[i] = mPendingSwipes.get(i).position;
                }
                if (swipeRight)
                    mCallback.onSwipeRight(mListView, swipePositions);
                else
                    mCallback.onSwipeLeft(mListView, swipePositions);

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

                mPendingSwipes.clear();
            }
        }
    });

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

    mPendingSwipes.add(new PendingSwipeData(swipePosition, swipeView));
    animator.start();
}

From source file:me.lizheng.deckview.views.DeckChildView.java

/**
 * Animates the deletion of this task view
 *///from  w ww  .jav a2 s .co  m
void startDeleteTaskAnimation(final Runnable r) {
    // Disabling clipping with the stack while the view is animating away
    setClipViewInStack(false);
    ValueAnimator anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, getSize());
    anim.setInterpolator(new LinearInterpolator());
    anim.setDuration(100);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            setClipViewInStack(true);

            setTouchEnabled(true);
            r.run();
        }
    });
    anim.start();
}

From source file:com.liujs.library.view.refresh.BGAStickinessRefreshView.java

public void smoothToIdle() {
    ValueAnimator animator = ValueAnimator.ofInt(mCurrentBottomHeight, 0);
    animator.setDuration(mStickinessRefreshViewHolder.getTopAnimDuration());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from  w ww. jav a2 s.c  o m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentBottomHeight = (int) animation.getAnimatedValue();
            postInvalidate();
        }
    });
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

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

        @Override
        public void onAnimationCancel(Animator animation) {
        }

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

From source file:com.dmallcott.progressfloatingactionbutton.ProgressView.java

public void setCurrentProgress(int currentProgress, boolean animate) {
    // If the view is animating no further actions are allowed
    if (isAnimating)
        return;//from  ww  w  .ja v a2s. c o m

    if (this.mTargetProgress >= mTotalProgress)
        this.mTargetProgress = mTotalProgress;
    else
        this.mTargetProgress = currentProgress;

    if (animate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // Animations are only available from API 11 and forth
        ValueAnimator va = ValueAnimator.ofInt(mCurrentProgress, mTargetProgress);
        va.setInterpolator(new AccelerateDecelerateInterpolator());
        va.setDuration(mAnimationDuration);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            public void onAnimationUpdate(ValueAnimator animation) {
                mCurrentProgress = (Integer) animation.getAnimatedValue();
                ProgressView.this.invalidate();
            }
        });
        va.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                isAnimating = true;
            }

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

            @Override
            public void onAnimationCancel(Animator animation) {
                isAnimating = false;
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                isAnimating = true;
            }
        });
        va.start();
    } else {
        mCurrentProgress = mTargetProgress;
        invalidate();
    }

    if (this.mTargetProgress == mTotalProgress)
        mListener.onProgressCompleted();
}

From source file:com.liujs.library.view.refresh.BGAStickinessRefreshView.java

public void startRefreshing() {
    ValueAnimator animator = ValueAnimator.ofInt(mCurrentBottomHeight, 0);
    animator.setDuration(mStickinessRefreshViewHolder.getTopAnimDuration());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from  w  w  w  .  j  a v a2 s . co  m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentBottomHeight = (int) animation.getAnimatedValue();
            postInvalidate();
        }
    });
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            mIsRefreshing = true;
            if (mCurrentBottomHeight != 0) {
                mStickinessRefreshViewHolder.startChangeWholeHeaderViewPaddingTop(mCurrentBottomHeight);
            } else {
                mStickinessRefreshViewHolder.startChangeWholeHeaderViewPaddingTop(
                        -(mTopSize + getPaddingTop() + getPaddingBottom()));
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mIsRotating = true;
            startRotating();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

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

From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java

private void continueAnimation(float horzOffset, int width) {
    ValueAnimator animator = ValueAnimator.ofFloat(horzOffset, width);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.setDuration((long) (150 * Math.abs(width - horzOffset) / width));
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from w  w  w .j a  v  a2 s .  c  o m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            updateSlideOffset(value);
        }
    });

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (mSlideListener != null) {
                mSlideListener.onSlideFinished();
            }
        }
    });

    animator.start();
}

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

private void expand() {
    if (container.getExpandedView() != null && container.getExpandedView() != this) {
        container.getExpandedView().close();
    }/*  ww w.j  a v  a 2 s  .c o m*/
    container.setExpandedMessageId(message.getId());
    container.setExpandedView(this);
    view.setVisibility(View.VISIBLE);
    if (shouldShowLikeButton()) {
        likeButton.setVisibility(View.VISIBLE);
    }

    View parent = (View) view.getParent();
    final int widthSpec;
    if (parent == null) {
        // needed for tests
        widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    } else {
        widthSpec = View.MeasureSpec.makeMeasureSpec(
                parent.getMeasuredWidth() - parent.getPaddingLeft() - parent.getPaddingRight(),
                View.MeasureSpec.AT_MOST);
    }
    final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(widthSpec, heightSpec);
    ValueAnimator animator = createHeightAnimator(view, 0, view.getMeasuredHeight());

    if (!message.isLiked() && !message.getUser().isMe() && !container.getControllerFactory()
            .getUserPreferencesController().hasPerformedAction(IUserPreferencesController.LIKED_MESSAGE)) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mainHandler.removeCallbacksAndMessages(null);
                mainHandler.postDelayed(showMessageStatusRunnable, LIKE_HINT_VISIBILITY_MIL_SEC);
            }

            @Override
            public void onAnimationStart(Animator animation) {
                showLikeDetails();
            }
        });
    }
    animator.start();
}

From source file:com.ofalvai.bpinfo.ui.alert.AlertDetailFragment.java

public void updateAlert(final Alert alert) {
    mAlert = alert;//ww  w .  j av  a  2 s.  c  o m
    mDisplayedRoutes.clear();
    mRouteIconsLayout.removeAllViews();

    // Updating views
    displayAlert(alert);

    // View animations
    // For some reason, ObjectAnimator doesn't work here (skips animation states, just shows the
    // last frame), we need to use ValueAnimators.
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(300);
    animatorSet.setInterpolator(new FastOutSlowInInterpolator());

    // We can't measure the TextView's height before a layout happens because of the setText() call
    // Note: even though displayAlert() was called earlier, the TextView's height is still 0.
    int heightEstimate = mDescriptionTextView.getLineHeight() * mDescriptionTextView.getLineCount() + 10;

    ValueAnimator descriptionHeight = ValueAnimator.ofInt(mDescriptionTextView.getHeight(), heightEstimate);
    descriptionHeight.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mDescriptionTextView.getLayoutParams().height = (int) animation.getAnimatedValue();
            mDescriptionTextView.requestLayout();
        }
    });
    descriptionHeight.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mDescriptionTextView.setAlpha(1.0f);
            mDescriptionTextView.setVisibility(View.VISIBLE);
        }
    });

    ValueAnimator descriptionAlpha = ValueAnimator.ofFloat(0, 1.0f);
    descriptionAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mDescriptionTextView.setAlpha((float) animation.getAnimatedValue());
        }
    });

    ValueAnimator progressHeight = ValueAnimator.ofInt(mProgressBar.getHeight(), 0);
    progressHeight.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mProgressBar.getLayoutParams().height = (int) animation.getAnimatedValue();
            mProgressBar.requestLayout();
        }
    });
    progressHeight.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mProgressBar.hide();
        }
    });

    animatorSet.playTogether(progressHeight, descriptionHeight, descriptionAlpha);
    animatorSet.start();
}