Example usage for android.animation ValueAnimator ValueAnimator

List of usage examples for android.animation ValueAnimator ValueAnimator

Introduction

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

Prototype

public ValueAnimator() 

Source Link

Document

Creates a new ValueAnimator object.

Usage

From source file:Main.java

public static ValueAnimator ofFloat(float... values) {
    ValueAnimator anim = new ValueAnimator();
    anim.setFloatValues(values);/*from   w  w w .  j a v a  2 s .  c o m*/
    cancelOnDestroyActivity(anim);
    return anim;
}

From source file:com.hippo.nimingban.widget.PostLayout.java

private void init(Context context) {
    mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback());
    mShadowTop = context.getResources().getDrawable(R.drawable.shadow_top);
    mShadowHeight = LayoutUtils.dp2pix(context, 8);
    mThreshold = LayoutUtils.dp2pix(context, 48);

    mHideTypeSendAnimation = new ValueAnimator();
    mHideTypeSendAnimation.setDuration(300);
    mHideTypeSendAnimation.setInterpolator(AnimationUtils2.FAST_SLOW_INTERPOLATOR);
    mHideTypeSendAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*ww w  .  ja  v a 2 s  .  c  om*/
        public void onAnimationUpdate(ValueAnimator animation) {
            View view = getChildAt(1);
            if (view != null) {
                int value = (Integer) animation.getAnimatedValue();
                view.offsetTopAndBottom(value - view.getTop());
                ((LayoutParams) view.getLayoutParams()).offsetY = value;
                invalidate();
            }
        }
    });

    mShowTypeSendAnimation = new ValueAnimator();
    mShowTypeSendAnimation.setDuration(300);
    mShowTypeSendAnimation.setInterpolator(AnimationUtils2.FAST_SLOW_INTERPOLATOR);
    mShowTypeSendAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            View view = getChildAt(1);
            if (view != null) {
                int value = (Integer) animation.getAnimatedValue();
                view.offsetTopAndBottom(value - view.getTop());
                ((LayoutParams) view.getLayoutParams()).offsetY = value;
                invalidate();
            }
        }
    });
}

From source file:com.yoloo.android.util.AnimUtils.java

public static ValueAnimator ofArgb(int... values) {
    if (VersionUtil.hasL()) {
        return ValueAnimator.ofArgb(values);
    } else {//  ww w.  j  a  va2s.c o m
        ValueAnimator anim = new ValueAnimator();
        anim.setIntValues(values);
        anim.setEvaluator(AnimUtils.getArgbEvaluator());
        return anim;
    }
}

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);/*w  w  w  .j  av  a 2s  .c o  m*/
    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: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  ww w .  j a va 2s  .com*/
    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:com.hippo.widget.Slider.java

@SuppressWarnings("deprecation")
private void init(Context context, AttributeSet attrs) {
    mContext = context;/*from w w  w.  j ava  2s .c om*/
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextAlign(Paint.Align.CENTER);

    Resources resources = context.getResources();
    mBubbleMinWidth = resources.getDimensionPixelOffset(R.dimen.slider_bubble_width);
    mBubbleMinHeight = resources.getDimensionPixelOffset(R.dimen.slider_bubble_height);

    mBubble = new BubbleView(context, textPaint);
    mBubble.setScaleX(0.0f);
    mBubble.setScaleY(0.0f);
    AbsoluteLayout absoluteLayout = new AbsoluteLayout(context);
    absoluteLayout.addView(mBubble);
    absoluteLayout.setBackgroundDrawable(null);
    mPopup = new PopupWindow(absoluteLayout);
    mPopup.setOutsideTouchable(false);
    mPopup.setTouchable(false);
    mPopup.setFocusable(false);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider);
    textPaint.setColor(a.getColor(R.styleable.Slider_textColor, Color.WHITE));
    textPaint.setTextSize(a.getDimensionPixelSize(R.styleable.Slider_textSize, 12));

    updateTextSize();

    setRange(a.getInteger(R.styleable.Slider_start, 0), a.getInteger(R.styleable.Slider_end, 0));
    setProgress(a.getInteger(R.styleable.Slider_slider_progress, 0));
    mThickness = a.getDimension(R.styleable.Slider_thickness, 2);
    mRadius = a.getDimension(R.styleable.Slider_radius, 6);
    setColor(a.getColor(R.styleable.Slider_color, Color.BLACK));

    mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBgPaint.setColor(a.getBoolean(R.styleable.Slider_dark, false) ? 0x4dffffff : 0x42000000);

    a.recycle();

    mProgressAnimation = new ValueAnimator();
    mProgressAnimation.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
    mProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(@NonNull ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            mDrawPercent = value;
            mDrawProgress = Math.round(MathUtils.lerp((float) mStart, mEnd, value));
            updateBubblePosition();
            mBubble.setProgress(mDrawProgress);
            invalidate();
        }
    });

    mBubbleScaleAnimation = new ValueAnimator();
    mBubbleScaleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(@NonNull ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            mDrawBubbleScale = value;
            mBubble.setScaleX(value);
            mBubble.setScaleY(value);
            invalidate();
        }
    });
}

From source file:info.awesomedevelopment.tvgrid.library.TVGridView.java

@SuppressWarnings("deprecation")
private void init(AttributeSet attrs) {
    ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
    mCache = new LruCache<>(am.getMemoryClass() * 1024);

    mYSize = new ValueAnimator();
    mXSize = new ValueAnimator();
    mYLocation = new ValueAnimator();
    mXLocation = new ValueAnimator();

    mXSize.addUpdateListener(xSizeListener);
    mYSize.addUpdateListener(ySizeListener);
    mYLocation.addUpdateListener(yLocationListener);
    mXLocation.addUpdateListener(xLocationListener);

    mSelectorAnimationSet.playTogether(mXLocation, mYLocation, mXSize, mYSize);
    mSelectorAnimationSet.setInterpolator(new AccelerateDecelerateInterpolator());
    mSelectorAnimationSet.setDuration(ANIMATION_DURATION);

    TypedValue fillAlpha = new TypedValue();
    getResources().getValue(R.dimen.tvg_defFillAlpha, fillAlpha, true);

    TypedValue fillAlphaSelected = new TypedValue();
    getResources().getValue(R.dimen.tvg_defFillAlphaSelected, fillAlphaSelected, true);

    if (attrs != null) {
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.TVGridView, 0, 0);

        try {// w w w  . jav a  2 s  .  c  o m
            //noinspection ResourceType
            mStrokePosition = a.getInteger(R.styleable.TVGridView_tvg_strokePosition, OUTSIDE);
            //noinspection ResourceType
            mSelectorPosition = a.getInteger(R.styleable.TVGridView_tvg_selectorPosition, OVER);
            //noinspection ResourceType
            mSelectorShape = a.getInteger(R.styleable.TVGridView_tvg_selectorShape, RECTANGLE);

            mAnimateSelectorChanges = a.getBoolean(R.styleable.TVGridView_tvg_animateSelectorChanges,
                    getResources().getInteger(R.integer.tvg_defAnimateSelectorChanges) == 1);
            mIsFilled = a.getBoolean(R.styleable.TVGridView_tvg_filled,
                    getResources().getInteger(R.integer.tvg_defIsFilled) == 1);
            mFillAlpha = a.getFloat(R.styleable.TVGridView_tvg_fillAlpha, fillAlpha.getFloat());
            mFillAlphaSelected = a.getFloat(R.styleable.TVGridView_tvg_fillAlphaSelected,
                    fillAlphaSelected.getFloat());
            mFillColor = a.getColor(R.styleable.TVGridView_tvg_fillColor,
                    getResources().getColor(R.color.tvg_defFillColor));
            mFillColorSelected = a.getColor(R.styleable.TVGridView_tvg_fillColorSelected,
                    getResources().getColor(R.color.tvg_defFillColorSelected));
            mCornerRadiusX = a.getDimension(R.styleable.TVGridView_tvg_cornerRadius,
                    getResources().getDimension(R.dimen.tvg_defCornerRadius));
            mCornerRadiusY = a.getDimension(R.styleable.TVGridView_tvg_cornerRadius,
                    getResources().getDimension(R.dimen.tvg_defCornerRadius));
            mStrokeWidth = a.getDimension(R.styleable.TVGridView_tvg_strokeWidth,
                    getResources().getDimension(R.dimen.tvg_defStrokeWidth));
            mStrokeColor = a.getColor(R.styleable.TVGridView_tvg_strokeColor,
                    getResources().getColor(R.color.tvg_defStrokeColor));
            mStrokeColorSelected = a.getColor(R.styleable.TVGridView_tvg_strokeColorSelected,
                    getResources().getColor(R.color.tvg_defStrokeColorSelected));
            mStrokeMarginLeft = a.getDimension(R.styleable.TVGridView_tvg_marginLeft,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginLeft));
            mStrokeMarginTop = a.getDimension(R.styleable.TVGridView_tvg_marginTop,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginTop));
            mStrokeMarginRight = a.getDimension(R.styleable.TVGridView_tvg_marginRight,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginRight));
            mStrokeMarginBottom = a.getDimension(R.styleable.TVGridView_tvg_marginBottom,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginBottom));
            mStrokeSpacingLeft = a.getDimension(R.styleable.TVGridView_tvg_spacingLeft,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingLeft));
            mStrokeSpacingTop = a.getDimension(R.styleable.TVGridView_tvg_spacingTop,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingTop));
            mStrokeSpacingRight = a.getDimension(R.styleable.TVGridView_tvg_spacingRight,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingRight));
            mStrokeSpacingBottom = a.getDimension(R.styleable.TVGridView_tvg_spacingBottom,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingBottom));
        } finally {
            a.recycle();
        }
    } else {
        mStrokePosition = OUTSIDE;
        mSelectorPosition = OVER;
        mSelectorShape = RECTANGLE;

        mAnimateSelectorChanges = getResources().getInteger(R.integer.tvg_defAnimateSelectorChanges) == 1;
        mIsFilled = getResources().getInteger(R.integer.tvg_defIsFilled) == 1;
        mFillAlpha = fillAlpha.getFloat();
        mFillAlphaSelected = fillAlphaSelected.getFloat();
        mFillColor = getResources().getColor(R.color.tvg_defFillColor);
        mFillColorSelected = getResources().getColor(R.color.tvg_defFillColorSelected);
        mCornerRadiusX = getResources().getDimension(R.dimen.tvg_defCornerRadius);
        mCornerRadiusY = getResources().getDimension(R.dimen.tvg_defCornerRadius);
        mStrokeWidth = getResources().getDimension(R.dimen.tvg_defStrokeWidth);
        mStrokeColor = getResources().getColor(R.color.tvg_defStrokeColor);
        mStrokeColorSelected = getResources().getColor(R.color.tvg_defStrokeColorSelected);
        mStrokeMarginLeft = getResources().getDimension(R.dimen.tvg_defStrokeMarginLeft);
        mStrokeMarginTop = getResources().getDimension(R.dimen.tvg_defStrokeMarginTop);
        mStrokeMarginRight = getResources().getDimension(R.dimen.tvg_defStrokeMarginRight);
        mStrokeMarginBottom = getResources().getDimension(R.dimen.tvg_defStrokeMarginBottom);
        mStrokeSpacingLeft = getResources().getDimension(R.dimen.tvg_defStrokeSpacingLeft);
        mStrokeSpacingTop = getResources().getDimension(R.dimen.tvg_defStrokeSpacingTop);
        mStrokeSpacingRight = getResources().getDimension(R.dimen.tvg_defStrokeSpacingRight);
        mStrokeSpacingBottom = getResources().getDimension(R.dimen.tvg_defStrokeSpacingBottom);
    }

    addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == SCROLL_STATE_IDLE) {
                mEdgeChange = false;
                mHardScrollChange = false;
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            mScrollY = mScrollY + dy;

            if (mStrokeCellCurrentBounds == null || mStrokeCell == null)
                return;

            if (useAnimations()) {
                mSelectorAnimationSet.cancel();

                mStrokeCellCurrentBounds.offsetTo(mStrokeCellCurrentBounds.left - dx,
                        mStrokeCellCurrentBounds.top - dy);

                performSelectorAnimation();
            } else if (mHardScrollChange || mEdgeChange) {
                mStrokeCellCurrentBounds.offsetTo(mStrokeCellCurrentBounds.left - dx,
                        mStrokeCellCurrentBounds.top - dy);
                setPrevBounds();

                mStrokeCell.setBounds(mStrokeCellPrevBounds);
                invalidate();
            }
        }
    });

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            clearHighlightedView();
            return false;
        }
    });
}

From source file:com.hippo.drawerlayout.DrawerLayout.java

private void init(Context context) {
    mLeftOpened = false;/*from  www.j  ava2  s  . c  om*/
    mRightOpened = false;
    mLeftState = STATE_CLOSED;
    mRightState = STATE_CLOSED;
    mLeftPercent = 0.0f;
    mRightPercent = 0.0f;
    mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * context.getResources().getDisplayMetrics().density + 0.5f);
    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mAnimator = new ValueAnimator();
    mAnimator.setFloatValues(0.0f, 1.0f);
    mAnimator.addUpdateListener(this);
    mAnimator.addListener(this);
    mAnimator.setInterpolator(DRAWER_INTERPOLATOR);
    mCancelAnimation = false;
    mStatusBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mStatusBarPaint.setColor(mStatusBarColor);
    mNavigationBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mNavigationBarPaint.setColor(mNavigationBarColor);

    setWillNotDraw(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (ViewCompat.getFitsSystemWindows(this)) {
            // Now set the sys ui flags to enable us to lay out in the window insets
            setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
    }
}

From source file:nuclei.ui.view.ButtonBarView.java

private void setSelected(final Item item, boolean selected) {
    if (mItems.length < 5)
        return;/* ww w  .  j  av a2  s. co m*/
    if (selected) {
        item.imageView.setColorFilter(mSelectedTint, PorterDuff.Mode.SRC_ATOP);
        if (item.textView != null) {
            item.textView.setTextColor(mSelectedTint);
            item.textView.setVisibility(View.VISIBLE);
            item.textView.setTextSize(0);
            ValueAnimator animator = mLabelAnimators.get(item);
            if (animator != null)
                animator.cancel();
            animator = new ValueAnimator();
            mLabelAnimators.put(item, animator);
            animator.setDuration(200);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    int animatedValue = (Integer) valueAnimator.getAnimatedValue();
                    item.textView.setTextSize(animatedValue);
                }
            });
            animator.setIntValues(0, 14);
            animator.start();
        }
    } else {
        item.imageView.setColorFilter(mUnselectedTint, PorterDuff.Mode.SRC_ATOP);
        if (item.textView != null) {
            item.textView.setTextColor(mUnselectedTint);
            ValueAnimator animator = mLabelAnimators.get(item);
            if (animator != null)
                animator.cancel();
            animator = new ValueAnimator();
            mLabelAnimators.put(item, animator);
            animator.setDuration(200);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    int animatedValue = (Integer) valueAnimator.getAnimatedValue();
                    item.textView.setTextSize(animatedValue);
                    if (animatedValue == 0)
                        item.textView.setVisibility(View.GONE);
                }
            });
            animator.setIntValues(14, 0);
            animator.start();
        }
    }
}

From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java

/**
 * /*from w  w  w.j  av  a2  s . c o  m*/
 * @param view
 */
@Override
public void onClick(View view) {
    if (mTvExpandCollapse.getVisibility() != View.VISIBLE) {
        return;
    }
    mCollapsed = !mCollapsed;
    ///?
    if (showExpandCollapseDrawable) {
        mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null,
                mCollapsed ? mExpandDrawable : mCollapseDrawable, null);
    }
    mTvExpandCollapse.setText(
            mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink));
    //???
    if (mCollapsedStatus != null) {
        mCollapsedStatus.put(mPosition, mCollapsed);
    }
    // /
    mAnimating = true;
    ValueAnimator valueAnimator;
    if (mCollapsed) {
        //            mTvContent.setMaxLines(mMaxCollapsedLines);
        valueAnimator = new ValueAnimator().ofInt(getHeight(), mCollapsedHeight);
    } else {
        valueAnimator = new ValueAnimator().ofInt(getHeight(),
                getHeight() + mTextHeightWithMaxLines - mTvContent.getHeight());
    }
    valueAnimator.addUpdateListener(valueAnimator1 -> {
        int animatedValue = (int) valueAnimator1.getAnimatedValue();
        mTvContent.setMaxHeight(animatedValue - mMarginBetweenTxtAndBottom);
        getLayoutParams().height = animatedValue;
        requestLayout();
    });
    valueAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {

        }

        @Override
        public void onAnimationEnd(Animator animator) {
            // ??????
            /// clear the animation flag
            mAnimating = false;
            // notify the listener
            if (mListener != null) {
                mListener.onExpandStateChanged(mTvContent, !mCollapsed);
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {

        }

        @Override
        public void onAnimationRepeat(Animator animator) {

        }
    });
    valueAnimator.setDuration(mAnimationDuration);
    valueAnimator.start();
}