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.musenkishi.wally.activities.ImageDetailsActivity.java

private void setupPaddings(final Size size, boolean animate) {

    int animationDuration = animate ? 300 : 0;

    photoView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    photoViewAttacher.setScaleType(ImageView.ScaleType.CENTER_CROP);

    final int sidePadding = getResources()
            .getDimensionPixelSize(R.dimen.activity_details_scrollview_side_padding);
    int fabPadding = getResources().getDimensionPixelSize(R.dimen.fab_padding_positive);

    int minimumAllowedHeight = fabPadding;

    if (size.getHeight() < minimumAllowedHeight) {
        size.setHeight(size.getHeight());
        ValueAnimator valueAnimator = ValueAnimator.ofInt(photoLayoutHolder.getPaddingTop());
        valueAnimator.setInterpolator(new EaseInOutBezierInterpolator());
        valueAnimator.setDuration(animationDuration);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override/*from  ww w.  j av a2 s  .c  o  m*/
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                photoLayoutHolder.setPadding(0, (Integer) valueAnimator.getAnimatedValue(), 0, 0);
            }
        });
        valueAnimator.start();
    } else {
        photoLayoutHolder.setPadding(0, 0, 0, 0);
    }

    scrollView.setPadding(0, 0, 0, -fabPadding);
    specsLayout.setPadding(0, 0, 0, fabPadding);

    ValueAnimator valueAnimator = ValueAnimator.ofInt(detailsViewGroup.getPaddingTop(), size.getHeight());
    valueAnimator.setInterpolator(new EaseInOutBezierInterpolator());
    valueAnimator.setDuration(animationDuration);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            detailsViewGroup.setPadding(sidePadding, (Integer) valueAnimator.getAnimatedValue(), sidePadding,
                    detailsViewGroup.getPaddingBottom());
        }
    });
    valueAnimator.start();
}

From source file:com.tengio.FloatingSearchView.java

private void fadeInBackground() {
    ValueAnimator anim = ValueAnimator.ofInt(BACKGROUND_DRAWABLE_ALPHA_SEARCH_NOT_FOCUSED,
            BACKGROUND_DRAWABLE_ALPHA_SEARCH_FOCUSED);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*  www  .  j a v a 2  s  .c o  m*/
        public void onAnimationUpdate(ValueAnimator animation) {

            int value = (Integer) animation.getAnimatedValue();
        }
    });
    anim.setDuration(BACKGROUND_FADE_ANIM_DURATION);
    anim.start();
}

From source file:com.gigamole.library.NavigationTabBar.java

public void setModels(final ArrayList<Model> models) {
    //Set update listeners to badge model animation
    for (final Model model : models) {
        model.mBadgeAnimator.removeAllUpdateListeners();
        model.mBadgeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override// www  . ja  va2  s .  c o  m
            public void onAnimationUpdate(final ValueAnimator animation) {
                model.mBadgeFraction = (float) animation.getAnimatedValue();
                postInvalidate();
            }
        });
    }

    mModels.clear();
    mModels = models;
    requestLayout();
}

From source file:com.tengio.FloatingSearchView.java

private void refreshLeftIcon(boolean showAnim) {
    int leftActionWidthAndMarginLeft = Util.dpToPx(LEFT_MENU_WIDTH_AND_MARGIN_START);
    int queryTranslationX = 0;

    mLeftAction.setVisibility(VISIBLE);/*w ww  .j  a  va 2s .  co  m*/
    switch (mLeftActionMode) {
    case LEFT_ACTION_MODE_SHOW_HAMBURGER:
        if (showAnim && mMenuBtnDrawable.getProgress() == 1.0f) {
            ValueAnimator anim = ValueAnimator.ofFloat(1.0f, 0.0f);
            anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float value = (Float) animation.getAnimatedValue();
                    mMenuBtnDrawable.setProgress(value);
                }
            });
            anim.setDuration(MENU_ICON_ANIM_DURATION);
            anim.start();
            break;
        }
        mLeftAction.setImageDrawable(mMenuBtnDrawable);
        mMenuBtnDrawable.setProgress(0.0f);
        break;
    case LEFT_ACTION_MODE_SHOW_SEARCH:
        mLeftAction.setImageDrawable(mIconSearch);
        break;
    case LEFT_ACTION_MODE_SHOW_HOME:
        if (showAnim && mMenuBtnDrawable.getProgress() == 0.0f) {
            ValueAnimator anim = ValueAnimator.ofFloat(0.0f, 1.0f);
            anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float value = (Float) animation.getAnimatedValue();
                    mMenuBtnDrawable.setProgress(value);
                }
            });
            anim.setDuration(MENU_ICON_ANIM_DURATION);
            anim.start();
            break;
        }
        mLeftAction.setImageDrawable(mMenuBtnDrawable);
        mMenuBtnDrawable.setProgress(1.0f);
        break;
    case LEFT_ACTION_MODE_NO_LEFT_ACTION:
        mLeftAction.setVisibility(View.INVISIBLE);
        queryTranslationX = -leftActionWidthAndMarginLeft;
        break;
    }
    mSearchInputParent.setTranslationX(queryTranslationX);
}

From source file:com.bitants.wally.activities.ImageDetailsActivity.java

private void setupPaddings(final Size size, boolean animate) {

    int animationDuration = animate ? 300 : 0;

    final int sidePadding = getResources()
            .getDimensionPixelSize(R.dimen.activity_details_scrollview_side_padding);
    int fabPadding = getResources().getDimensionPixelSize(R.dimen.fab_padding_positive);

    int minimumAllowedHeight = fabPadding;

    if (size.getHeight() < minimumAllowedHeight) {
        size.setHeight(size.getHeight());
        ValueAnimator valueAnimator = ValueAnimator.ofInt(photoLayoutHolder.getPaddingTop());
        valueAnimator.setInterpolator(new EaseInOutBezierInterpolator());
        valueAnimator.setDuration(animationDuration);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override// w  w  w  .  j  a v  a 2s  .  c  o  m
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                photoLayoutHolder.setPadding(0, (Integer) valueAnimator.getAnimatedValue(), 0, 0);
            }
        });
        valueAnimator.start();
    } else {
        photoLayoutHolder.setPadding(0, 0, 0, 0);
    }

    scrollView.setPadding(0, 0, 0, -fabPadding);
    specsLayout.setPadding(0, 0, 0, fabPadding);

    ValueAnimator valueAnimator = ValueAnimator.ofInt(detailsViewGroup.getPaddingTop(), size.getHeight());
    valueAnimator.setInterpolator(new EaseInOutBezierInterpolator());
    valueAnimator.setDuration(animationDuration);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            detailsViewGroup.setPadding(sidePadding, (Integer) valueAnimator.getAnimatedValue(), sidePadding,
                    detailsViewGroup.getPaddingBottom());
        }
    });
    valueAnimator.start();
}

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

@TargetApi(11)
private void startRevealAnimation() {
    mPaintSecondaryText.setAlpha(0);//  ww  w  .  j a v  a  2  s .  c o  m
    mPaintPrimaryText.setAlpha(0);
    mView.mPaintBackground.setAlpha(0);
    mView.mPaintFocal.setAlpha(0);
    mView.mFocalRadius = 0;
    mView.mBackgroundRadius = 0;
    if (mView.mIconDrawable != null) {
        mView.mIconDrawable.setAlpha(0);
    }
    mRevealedAmount = 0f;
    mAnimationCurrent = ValueAnimator.ofFloat(0f, 1f);
    mAnimationCurrent.setInterpolator(mAnimationInterpolator);
    mAnimationCurrent.setDuration(225);
    mAnimationCurrent.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mRevealedAmount = (float) animation.getAnimatedValue();
            mView.mBackgroundRadius = mBaseBackgroundRadius * mRevealedAmount;
            mView.mFocalRadius = mBaseFocalRadius * mRevealedAmount;
            mView.mPaintFocal.setAlpha((int) (255 * mRevealedAmount));
            mView.mPaintBackground.setAlpha((int) (244 * mRevealedAmount));
            mPaintSecondaryText.setAlpha((int) (mSecondaryTextColourAlpha * mRevealedAmount));
            mPaintPrimaryText.setAlpha((int) (mPrimaryTextColourAlpha * mRevealedAmount));
            if (mView.mIconDrawable != null) {
                mView.mIconDrawable.setAlpha(mView.mPaintBackground.getAlpha());
            }
            mView.invalidate();
        }
    });
    mAnimationCurrent.addListener(new AnimatorListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onAnimationEnd(Animator animation) {
            animation.removeAllListeners();
            mAnimationCurrent = null;
            mRevealedAmount = 1;
            startIdleAnimations();
        }

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onAnimationCancel(Animator animation) {
            animation.removeAllListeners();
            mRevealedAmount = 1;
            mAnimationCurrent = null;
        }
    });
    mAnimationCurrent.start();
}

From source file:com.bitants.wally.activities.ImageDetailsActivity.java

/**
 * Animations animations animations./* ww w  .  j a  v  a2 s.c om*/
 * @param visibility if VISIBLE, expands toolbar.
 */
private void animateToolbar(int visibility) {
    float from;
    float to;
    int toolbarOffset;
    int fabOffset;
    if (visibility == View.VISIBLE) {
        from = 0.0f;
        to = 1.0f;
        fabOffset = 200;
        toolbarOffset = 0;
    } else {
        from = 1.0f;
        to = 0.0f;
        fabOffset = 0;
        toolbarOffset = 200;
    }

    buttonFullscreen.animate().scaleX(to).scaleY(to).setDuration(400).setStartDelay(fabOffset)
            .setInterpolator(new EaseInOutBezierInterpolator()).setListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animator) {
                    buttonFullscreen.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animator animator) {

                }

                @Override
                public void onAnimationCancel(Animator animator) {

                }

                @Override
                public void onAnimationRepeat(Animator animator) {

                }
            }).start();

    int toolbarFrom;
    int toolbarTo;

    if (from > 0.0f) {
        toolbarFrom = getResources().getDimensionPixelSize(R.dimen.details_toolbar_height);
        toolbarTo = 0;
    } else {
        toolbarFrom = 0;
        toolbarTo = getResources().getDimensionPixelSize(R.dimen.details_toolbar_height);
    }

    ValueAnimator valueAnimator = ValueAnimator.ofInt(toolbarFrom, toolbarTo);
    valueAnimator.setDuration(400);
    valueAnimator.setStartDelay(toolbarOffset);
    valueAnimator.setInterpolator(new EaseInOutBezierInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            RelativeLayout.LayoutParams toolbarParams = (RelativeLayout.LayoutParams) toolbar.getLayoutParams();
            toolbarParams.height = val;
            toolbar.setLayoutParams(toolbarParams);
        }
    });
    valueAnimator.start();

}

From source file:com.gigamole.library.NavigationTabBar.java

public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB//from w ww.jav a2  s .c  o m

    // Always draw
    setWillNotDraw(false);
    // More speed!
    setLayerType(LAYER_TYPE_HARDWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));
        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, ALL_INDEX));
        setBadgePosition(typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, RIGHT_INDEX));
        setBadgeGravity(typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, TOP_INDEX));
        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0f));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model(null, Color.parseColor(previewColor)));
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

/**
 * Removes the prompt from view, using a contract and fade animation.
 * <p>//w w  w. j  a  v  a2s.  c  o  m
 * This is treated as if the user has touched outside the target focal point.
 */
public void dismiss() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (mDismissing) {
            return;
        }
        mDismissing = true;
        if (mAnimationCurrent != null) {
            mAnimationCurrent.removeAllListeners();
            mAnimationCurrent.cancel();
            mAnimationCurrent = null;
        }
        mAnimationCurrent = ValueAnimator.ofFloat(1f, 0f);
        mAnimationCurrent.setDuration(225);
        mAnimationCurrent.setInterpolator(mAnimationInterpolator);
        mAnimationCurrent.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mRevealedAmount = (float) animation.getAnimatedValue();
                mView.mBackgroundRadius = mBaseBackgroundRadius * mRevealedAmount;
                mView.mFocalRadius = mBaseFocalRadius * mRevealedAmount;
                mView.mPaintBackground.setAlpha((int) (244 * mRevealedAmount));
                mPaintSecondaryText.setAlpha((int) (mSecondaryTextColourAlpha * mRevealedAmount));
                mPaintPrimaryText.setAlpha((int) (mPrimaryTextColourAlpha * mRevealedAmount));
                if (mView.mIconDrawable != null) {
                    mView.mIconDrawable.setAlpha(mView.mPaintBackground.getAlpha());
                }
                mView.invalidate();
            }
        });
        mAnimationCurrent.addListener(new AnimatorListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onAnimationEnd(Animator animation) {
                removeGlobalLayoutListener();
                getParentView().removeView(mView);
                mAnimationCurrent.removeAllListeners();
                mAnimationCurrent = null;
                mDismissing = false;
                onHidePromptComplete();
                mParentView = null;
            }

            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onAnimationCancel(Animator animation) {
                removeGlobalLayoutListener();
                getParentView().removeView(mView);
                mAnimationCurrent.removeAllListeners();
                mAnimationCurrent = null;
                mDismissing = false;
                onHidePromptComplete();
                mParentView = null;
            }
        });
        mAnimationCurrent.start();
    } else {
        removeGlobalLayoutListener();
        getParentView().removeView(mView);
        onHidePromptComplete();
        mParentView = null;
    }
}

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

/**
 * Removes the prompt from view, using a expand and fade animation.
 * <p>/*from w w  w  .jav  a  2  s. c  o m*/
 * This is treated as if the user has touched the target focal point.
 */
public void finish() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (mDismissing) {
            return;
        }
        mDismissing = true;
        if (mAnimationCurrent != null) {
            mAnimationCurrent.removeAllListeners();
            mAnimationCurrent.cancel();
            mAnimationCurrent = null;
        }
        mAnimationCurrent = ValueAnimator.ofFloat(1f, 0f);
        mAnimationCurrent.setDuration(225);
        mAnimationCurrent.setInterpolator(mAnimationInterpolator);
        mAnimationCurrent.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                final float value = (float) animation.getAnimatedValue();
                mRevealedAmount = 1f + ((1f - value) / 4);
                mView.mBackgroundRadius = mBaseBackgroundRadius * mRevealedAmount;
                mView.mFocalRadius = mBaseFocalRadius * mRevealedAmount;
                mView.mPaintFocal.setAlpha((int) (255 * value));
                mView.mPaintBackground.setAlpha((int) (244 * value));
                mPaintSecondaryText.setAlpha((int) (mSecondaryTextColourAlpha * value));
                mPaintPrimaryText.setAlpha((int) (mPrimaryTextColourAlpha * value));
                if (mView.mIconDrawable != null) {
                    mView.mIconDrawable.setAlpha(mView.mPaintBackground.getAlpha());
                }
                mView.invalidate();
            }
        });
        mAnimationCurrent.addListener(new AnimatorListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onAnimationEnd(Animator animation) {
                removeGlobalLayoutListener();
                getParentView().removeView(mView);
                mAnimationCurrent.removeAllListeners();
                mAnimationCurrent = null;
                mDismissing = false;
                onHidePromptComplete();
                mParentView = null;
            }

            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onAnimationCancel(Animator animation) {
                removeGlobalLayoutListener();
                getParentView().removeView(mView);
                mAnimationCurrent.removeAllListeners();
                mAnimationCurrent = null;
                mDismissing = false;
                onHidePromptComplete();
                mParentView = null;
            }
        });
        mAnimationCurrent.start();
    } else {
        removeGlobalLayoutListener();
        getParentView().removeView(mView);
        onHidePromptComplete();
        mParentView = null;
    }
}