Example usage for android.animation ValueAnimator getAnimatedValue

List of usage examples for android.animation ValueAnimator getAnimatedValue

Introduction

In this page you can find the example usage for android.animation ValueAnimator getAnimatedValue.

Prototype

public Object getAnimatedValue() 

Source Link

Document

The most recent value calculated by this ValueAnimator when there is just one property being animated.

Usage

From source file:com.telenav.expandablepager.SlidingContainer.java

/**
 * Animate translationY to the next stopValue
 * @param amount translationY amount//  w ww  .ja v  a 2s .c om
 * @param duration animation duration
 * @param interpolator  animation interpolator
 */
private void animate(final float amount, int duration, Interpolator interpolator) {
    ObjectAnimator oa = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, amount).setDuration(duration);
    oa.setInterpolator(interpolator);
    oa.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            notifySlideEvent(Math.round(((Float) animation.getAnimatedValue())));
        }
    });
    oa.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animator) {
            onSettled(stopValueIndex);
        }
    });
    oa.start();
}

From source file:com.myhexaville.iconanimations.gooey_fab.GooeyFabCompatImpl.java

public void showAnimation() {
    if (!mIsLargeFab) {
        if (!mIsExpanded) {
            mIcon.setAlpha(0f);/*  w  ww  . j av a2  s. c om*/
        }

        animate().translationYBy(mIsExpanded ? mAnimationTanslationY : -mAnimationTanslationY).setDuration(250)
                .start();

        mIcon.animate().alpha(!mIsExpanded ? 1f : 0f).setDuration(500).start();
        mGooeyPart = getGooeyPartHeight();
        invalidate();
    } else {
        mIcon.animate().rotationBy(mIsExpanded ? -45 : 45).setDuration(187).start();
        ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration(187);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float v = (float) animation.getAnimatedValue();
                mGooeyPart = getGooeyPartHeight() * v;
                invalidate();
            }
        });
        animator.start();
    }

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            ValueAnimator animator = ValueAnimator.ofFloat(1f, 0f).setDuration(187);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float v = (float) animation.getAnimatedValue();
                    mGooeyPart = getGooeyPartHeight() * v;
                    invalidate();
                }
            });
            animator.start();
        }
    }, 187);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            mIsExpanded = !mIsExpanded;
        }
    }, 250);

}

From source file:xyz.klinker.android.article.view.ElasticDragDismissFrameLayout.java

@Override
public void onStopNestedScroll(View child) {
    if (enabled) {
        if (Math.abs(totalDrag) >= dragDismissDistance) {
            dispatchDismissCallback();/*from  ww  w. j  a v  a  2s . com*/
        } else { // settle back to natural position
            if (fastOutSlowInInterpolator == null) {
                fastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(),
                        android.R.interpolator.fast_out_slow_in);
            }
            getChildAt(0).animate().translationY(0f).scaleX(1f).scaleY(1f).setDuration(200L)
                    .setInterpolator(fastOutSlowInInterpolator).setListener(null).start();

            ValueAnimator animator = null;
            if (draggingUp) {
                animator = ValueAnimator.ofFloat(draggingBackground.top, draggingBackground.bottom);
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        draggingBackground.top = (float) valueAnimator.getAnimatedValue();
                        invalidate();
                    }
                });
            } else if (draggingDown) {
                animator = ValueAnimator.ofFloat(draggingBackground.bottom, draggingBackground.top);
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        draggingBackground.bottom = (float) valueAnimator.getAnimatedValue();
                        invalidate();
                    }
                });
            }

            if (animator != null) {
                animator.setInterpolator(fastOutSlowInInterpolator);
                animator.setDuration(200L);
                animator.start();
            }

            totalDrag = 0;
            draggingDown = draggingUp = false;
            dispatchDragCallback(0f, 0f, 0f, 0f);
        }
    }
}

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

public void updateAlert(final Alert alert) {
    mAlert = alert;//from  w  w  w .  ja va2 s . c  om
    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();
}

From source file:io.github.sin3hz.wifispinnerview.WifiSpinnerDrawable.java

private void setupAnimators() {
    AnimatorSet set = new AnimatorSet();
    for (int i = 0; i < mSpinnerCount; i++) {
        final int index = i;
        final ValueAnimator sweepAnimator = ValueAnimator.ofFloat(0, MAX_SWEEP_ANGLE);
        sweepAnimator.setInterpolator(SWEEP_ANIMATOR_INTERPOLATOR);
        sweepAnimator.setDuration(mSweepAnimatorDuration);
        sweepAnimator.setRepeatMode(ValueAnimator.RESTART);
        sweepAnimator.setRepeatCount(ValueAnimator.INFINITE);
        sweepAnimator.setStartDelay(index * SWEEP_ANIMATOR_DELAY);
        sweepAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override/*from  w ww. ja v a 2s . com*/
            public void onAnimationUpdate(ValueAnimator animation) {
                mSpinners[index].sweepAngle = (float) animation.getAnimatedValue();
                mSpinners[index].updatePath();
                invalidateSelf();
            }
        });
        sweepAnimator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationRepeat(Animator animation) {
                mSpinners[index].sweepAngleOffset = (mSpinners[index].sweepAngleOffset + MAX_SWEEP_ANGLE) % 360;
                mSpinners[index].updatePath();
            }
        });
        set.playTogether(sweepAnimator);
    }
    mSweepAnimator = set;

    mAngleAnimator = ValueAnimator.ofFloat(0, 360);
    mAngleAnimator.setInterpolator(ANGLE_ANIMATOR_INTERPOLATOR);
    mAngleAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mAngleAnimator.setRepeatMode(ValueAnimator.RESTART);
    mAngleAnimator.setDuration(ANGLE_ANIMATOR_DURATION);
    mAngleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mGlobalAngle = (float) animation.getAnimatedValue();
            updatePath();
            invalidateSelf();
        }
    });
}

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

public ValueAnimator createHeightAnimator(final View view, final int start, final int end) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.setDuration(animationDuration);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from w  ww.  j ava  2 s . c o  m*/
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            layoutParams.height = (Integer) valueAnimator.getAnimatedValue();
            view.setLayoutParams(layoutParams);
        }
    });
    return animator;
}

From source file:com.rong.library.widget.mapsearchbar.MapSearchBar.java

private void animateSuggestionList(int from, int to) {
    suggestionsVisible = (to > 0);// w  ww.  ja  v a2 s.  c o m

    final ViewGroup.LayoutParams lp = containerSuggestion.getLayoutParams();
    if (to == 0 && lp.height == 0)
        return; // already collapsed

    if (to == 0)
        from = lp.height;

    ValueAnimator animator = ValueAnimator.ofInt(from, to);
    animator.setDuration(200);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            lp.height = (int) animation.getAnimatedValue();
            containerSuggestion.setLayoutParams(lp);
        }
    });

    animator.start();
}

From source file:pl.mrwojtek.sensrec.app.RecordsActivity.java

private void setupBarsColors() {
    int animationDuration = getResources().getInteger(R.integer.color_animation_duration);

    actionActiveColor = ContextCompat.getColor(this, R.color.material_red_500);
    actionInactiveColor = ContextCompat.getColor(this, R.color.colorPrimary);
    actionColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), actionInactiveColor, actionActiveColor);
    actionColorAnimation.setDuration(animationDuration);
    actionColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from   w  w  w .  j  ava  2 s. c  o m*/
        public void onAnimationUpdate(ValueAnimator animator) {
            toolbar.setBackgroundColor((Integer) animator.getAnimatedValue());
        }
    });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        statusActiveColor = ContextCompat.getColor(this, R.color.material_red_700);
        statusInactiveColor = ContextCompat.getColor(this, R.color.colorPrimaryDark);
        statusColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), statusInactiveColor,
                statusActiveColor);
        statusColorAnimation.setDuration(animationDuration);
        statusColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @SuppressLint("NewApi")
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                getWindow().setStatusBarColor((Integer) animator.getAnimatedValue());
            }
        });
    }
}

From source file:org.lib.ExpandableLinearLayout.java

private void animateHeight(final View view, final int targetHeight) {
    if (animatorSet == null) {
        animatorSet = new AnimatorSet();
        animatorSet.setInterpolator(interpolator);
        animatorSet.setDuration(duration);
    }/*w  w  w . j  a  v  a  2s. c  o m*/

    final LayoutParams lp = (LayoutParams) view.getLayoutParams();
    lp.weight = 0;
    int height = view.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(height, targetHeight);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            view.getLayoutParams().height = (Integer) valueAnimator.getAnimatedValue();
            view.requestLayout();

            if (listener != null) {
                float fraction = targetHeight == 0 ? 1 - valueAnimator.getAnimatedFraction()
                        : valueAnimator.getAnimatedFraction();
                listener.onExpansionUpdate(fraction);
            }
        }
    });
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            if (targetHeight == 0) {
                view.setVisibility(GONE);
            } else {
                lp.height = lp.originalHeight;
                lp.weight = lp.originalWeight;
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

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

    animatorSet.playTogether(animator);
}

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  w w . ja  v  a  2  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;
                }
                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();
}