List of usage examples for android.animation ValueAnimator getAnimatedValue
public Object getAnimatedValue()
ValueAnimator
when there is just one property being animated. From source file:despotoski.nikola.github.com.bottomnavigationlayout.BottomNavigationFloatingActionButtonBehavior.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override//from w w w . ja va 2s.c om public void onDependentViewRemoved(CoordinatorLayout parent, final FloatingActionButton child, View dependency) { if (!mIgnoreNestedScrollingEvents && dependency instanceof Snackbar.SnackbarLayout) { mReturnAnimator = ValueAnimator.ofFloat(ViewCompat.getTranslationY(child) + child.getHeight(), ViewCompat.getTranslationY(child) - mInitialTranslationY - child.getHeight()); mReturnAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { ViewCompat.setTranslationY(child, (Float) animation.getAnimatedValue()); } }); mReturnAnimator.setInterpolator(INTERPOLATOR); mReturnAnimator.setDuration(200); mReturnAnimator.addListener(mAnimatorListener); mReturnAnimator.start(); } }
From source file:com.lambdasoup.appbarsyncedfab.AppBarBoundFabBehavior.java
private void updateFabTranslationForSnackbar(CoordinatorLayout parent, final FloatingActionButton fab, View snackbar) {//from w ww .jav a 2 s. co m // We want to introduce additional y-translation (with respect to what's already there), // by the current visible height of any snackbar final float targetTransYByThis = getVisibleHeightOfOverlappingSnackbar(parent, fab); if (snackbarFabTranslationYByThis == targetTransYByThis) { // We're already at (or currently animating to) the target value, return... return; } final float currentTransY = ViewCompat.getTranslationY(fab); // Calculate difference between what we want now and what we wanted earlier final float stepTransYDelta = targetTransYByThis - snackbarFabTranslationYByThis; // ... and we're going to change the current state just by the difference final float targetTransY = currentTransY + stepTransYDelta; // Make sure that any current animation is cancelled if (snackbarFabTranslationYAnimator != null && snackbarFabTranslationYAnimator.isRunning()) { snackbarFabTranslationYAnimator.cancel(); } if (fab.isShown() && Math.abs(currentTransY - targetTransY) > (fab.getHeight() * 0.667f)) { // If the FAB will be travelling by more than 2/3 of it's height, let's animate // it instead if (snackbarFabTranslationYAnimator == null) { snackbarFabTranslationYAnimator = ValueAnimator.ofFloat(currentTransY, targetTransY); snackbarFabTranslationYAnimator.setInterpolator(new FastOutSlowInInterpolator()); snackbarFabTranslationYAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { ViewCompat.setTranslationY(fab, (Float) animator.getAnimatedValue()); } }); } snackbarFabTranslationYAnimator.start(); } else { // Now update the translation Y ViewCompat.setTranslationY(fab, targetTransY); } snackbarFabTranslationYByThis = targetTransYByThis; }
From source file:com.zhihu.android.app.mirror.widget.ArtboardView.java
private void onActionRelease() { if (mCallback != null && Math.abs(mDragDistance) > mDragDismissDistance) { mCallback.onDragDismiss(this, mIsDragDown); } else {/*from w w w .j a v a2 s .c o m*/ if (mTransYAnim != null && mTransYAnim.isRunning()) { mTransYAnim.cancel(); } mTransYAnim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, getTranslationY(), 0.0F); mTransYAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float dragTo = (Float) animation.getAnimatedValue(); if (mCallback != null) { mCallback.onDrag(ArtboardView.this, mDragDismissDistance, dragTo); } } }); mTransYAnim.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime)); mTransYAnim.setInterpolator(PathInterpolatorCompat.create(0.4F, 0.0F, 0.2F, 1.0F)); mTransYAnim.start(); } }
From source file:com.facebook.react.modules.statusbar.StatusBarModule.java
@ReactMethod public void setColor(final int color, final boolean animated, final Promise res) { final Activity activity = getCurrentActivity(); if (activity == null) { res.reject(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE); return;//w w w . j av a2s . c o m } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { UiThreadUtil.runOnUiThread(new Runnable() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void run() { if (animated) { int curColor = activity.getWindow().getStatusBarColor(); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), curColor, color); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { activity.getWindow().setStatusBarColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.setDuration(300).setStartDelay(0); colorAnimation.start(); } else { activity.getWindow().setStatusBarColor(color); } res.resolve(null); } }); } else { res.resolve(null); } }
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. j a v a 2s .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.grarak.kerneladiutor.views.recyclerview.DropDownView.java
public void expand() { mExpanded = true;//from w w w.j a va 2 s. c o m if (mArrow != null) { mArrow.animate().rotationX(0).setDuration(500).start(); if (mAnimator != null) { mAnimator.cancel(); } if (mItems == null) return; mAnimator = ValueAnimator.ofFloat(0, mItemHeight * mItems.size()); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { setHeight(Math.round((float) animation.getAnimatedValue())); } }); mAnimator.setDuration(500); mAnimator.start(); } }
From source file:com.grarak.kerneladiutor.views.recyclerview.DropDownView.java
public void collapse() { mExpanded = false;// w w w . ja v a2 s .co m if (mArrow != null) { mArrow.animate().rotationX(180).setDuration(500).start(); if (mAnimator != null) { mAnimator.cancel(); } if (mItems == null) return; mAnimator = ValueAnimator.ofFloat(mItemHeight * mItems.size(), 0); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { setHeight(Math.round((float) animation.getAnimatedValue())); } }); mAnimator.setDuration(500); mAnimator.start(); } }
From source file:com.android.launcher3.Hotseat.java
public void updateColor(ExtractedColors extractedColors, boolean animate) { if (!mHasVerticalHotseat) { int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT); if (mBackgroundColorAnimator != null) { mBackgroundColorAnimator.cancel(); }/*from www . j a va 2s. c o m*/ if (!animate) { setBackgroundColor(color); } else { mBackgroundColorAnimator = ValueAnimator.ofInt(mBackgroundColor, color); mBackgroundColorAnimator.setEvaluator(new ArgbEvaluator()); mBackgroundColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mBackground.setColor((Integer) animation.getAnimatedValue()); } }); mBackgroundColorAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mBackgroundColorAnimator = null; } }); mBackgroundColorAnimator.start(); } mBackgroundColor = color; } }
From source file:org.mozilla.focus.widget.AnimatedProgressBar.java
private void init(@NonNull Context context, @Nullable AttributeSet attrs) { tempRect = new Rect(); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedProgressBar); final int duration = a.getInteger(R.styleable.AnimatedProgressBar_shiftDuration, 1000); final int resID = a.getResourceId(R.styleable.AnimatedProgressBar_shiftInterpolator, 0); final boolean wrap = a.getBoolean(R.styleable.AnimatedProgressBar_wrapShiftDrawable, false); mPrimaryAnimator = ValueAnimator.ofInt(getProgress(), getMax()); mPrimaryAnimator.setInterpolator(new LinearInterpolator()); mPrimaryAnimator.setDuration(PROGRESS_DURATION); mPrimaryAnimator.addUpdateListener(mListener); mClosingAnimator.setDuration(CLOSING_DURATION); mClosingAnimator.setInterpolator(new LinearInterpolator()); mClosingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w . j a v a 2 s . co m public void onAnimationUpdate(ValueAnimator valueAnimator) { final float region = (float) valueAnimator.getAnimatedValue(); if (mClipRegion != region) { mClipRegion = region; invalidate(); } } }); mClosingAnimator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { mClipRegion = 0f; } @Override public void onAnimationEnd(Animator animator) { setVisibilityImmediately(GONE); } @Override public void onAnimationCancel(Animator animator) { mClipRegion = 0f; } @Override public void onAnimationRepeat(Animator animator) { } }); setProgressDrawable(buildWrapDrawable(getProgressDrawable(), wrap, duration, resID)); a.recycle(); }
From source file:co.com.parsoniisolutions.custombottomsheetbehavior.lib.ScrollingAppBarLayoutBehavior.java
public void setAppBarVisible(final AppBarLayout appBarLayout, final boolean visible) { if (visible == mVisible) return;//from ww w .jav a 2 s . c o m if (mAppBarYValueAnimator == null || !mAppBarYValueAnimator.isRunning()) { mAppBarYValueAnimator = ValueAnimator.ofFloat((int) appBarLayout.getY(), visible ? (int) appBarLayout.getY() + appBarLayout.getHeight() + getStatusBarHeight() : (int) appBarLayout.getY() - appBarLayout.getHeight() - getStatusBarHeight()); mAppBarYValueAnimator .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime)); mAppBarYValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { appBarLayout.setY((Float) animation.getAnimatedValue()); } }); mAppBarYValueAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); if (visible) setStatusBarBackgroundVisible(true); } @Override public void onAnimationEnd(Animator animation) { if (!visible) setStatusBarBackgroundVisible(false); mVisible = visible; super.onAnimationEnd(animation); } }); mAppBarYValueAnimator.start(); } }