Java Code Examples for android.animation.ValueAnimator#ofInt()

The following examples show how to use android.animation.ValueAnimator#ofInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Hasher.java    From crystal-preloaders with Apache License 2.0 6 votes vote down vote up
@Override
protected List<ValueAnimator> setupAnimation(){

    valueAnimator = ValueAnimator.ofInt(0, 360);
    valueAnimator.setDuration(1500);
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.setRepeatMode(ValueAnimator.RESTART);
    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            degree = (int) animation.getAnimatedValue();
            getTarget().invalidate();
        }
    });

    final List<ValueAnimator> animators = new ArrayList<>();
    animators.add(valueAnimator);

    return animators;
}
 
Example 2
Source File: AnimatedCircleDrawable.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
public void animateToSmallRadius()
{
    int smallLevel = map(mSmallRadiusTarget,
            0, diagonalLength(mCanvasWidth, mCanvasHeight) / 2,
            0, DRAWABLE_MAX_LEVEL);
    final ValueAnimator animator =
            ValueAnimator.ofInt(getLevel(), smallLevel);
    animator.setDuration(CIRCLE_ANIM_DURATION_MS);
    animator.setInterpolator(Gusterpolator.INSTANCE);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
    {
        @Override
        public void onAnimationUpdate(ValueAnimator animation)
        {
            setLevel((Integer) animation.getAnimatedValue());
        }
    });
    animator.start();
}
 
Example 3
Source File: GestureLockView.java    From GestureLockView with Apache License 2.0 6 votes vote down vote up
/**
 * 开启动画
 *
 * @param point    单位点
 * @param duration 持续时长
 */
private void startAnimation(final Point point, long duration) {
    ValueAnimator valueAnimator;
    // 1.判断是否有按下状态的图片的资源ID,采用不同策略的属性动画
    if (mPressImageId == 0) {
        // 2.判断动画缩放模式,采用不同策略的属性动画
        if (mAnimationScaleMode == 1) {
            valueAnimator = ValueAnimator.ofInt(point.radius, (int) (mAnimationScaleRate * point.radius), point.radius);
        } else {
            valueAnimator = ValueAnimator.ofInt((int) (mAnimationScaleRate * point.radius), point.radius);
        }
    } else {
        valueAnimator = ValueAnimator.ofInt(0, point.radius);
    }
    valueAnimator.setDuration(duration);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            point.radius = (int) animation.getAnimatedValue();
            postInvalidate();
        }
    });
    valueAnimator.start();
    // 3.添加ValueAnimator至动画列表
    mPointAnimators.add(valueAnimator);
}
 
Example 4
Source File: FloatingView.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
void run() {
    if (mDynamicUpdate == null) {
        mDraggableIcon.animate()
                .translationX(mDestX)
                .translationY(mDestY)
                .setDuration(mDuration)
                .setInterpolator(mInterpolator)
                .setListener(mAnimationFinishedListener);
    } else {
        ValueAnimator animator = ValueAnimator.ofInt(0, 100);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float percent = valueAnimator.getAnimatedFraction();
                mDraggableIcon.setTranslationX(mDynamicUpdate.getTranslationX(percent));
                mDraggableIcon.setTranslationY(mDynamicUpdate.getTranslationY(percent));
            }
        });
        animator.setDuration(mDuration);
        animator.setInterpolator(mInterpolator);
        animator.addListener(mAnimationFinishedListener);
        animator.start();
    }
}
 
Example 5
Source File: MaterialWaveView.java    From styT with Apache License 2.0 6 votes vote down vote up
@Override
public void onRefreshing(MaterialRefreshLayout br) {
    setHeadHeight((int) (Util.dip2px(getContext(), DefaulHeadHeight)));
    ValueAnimator animator = ValueAnimator.ofInt(getWaveHeight(),0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Log.i("anim", "value--->" + (int) animation.getAnimatedValue());
            setWaveHeight((int) animation.getAnimatedValue());
            invalidate();
        }
    });
    animator.setInterpolator(new BounceInterpolator());
    animator.setDuration(200);
    animator.start();
}
 
Example 6
Source File: BallGridBeatIndicator.java    From LRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public ArrayList<ValueAnimator> onCreateAnimators() {
    ArrayList<ValueAnimator> animators=new ArrayList<>();

    int[] durations={960, 930, 1190, 1130, 1340, 940, 1200, 820, 1190};
    int[] delays= {360, 400, 680, 410, 710, -150, -120, 10, 320};

    for (int i = 0; i < 9; i++) {
        final int index=i;
        ValueAnimator alphaAnim= ValueAnimator.ofInt(255, 168,255);
        alphaAnim.setDuration(durations[i]);
        alphaAnim.setRepeatCount(-1);
        alphaAnim.setStartDelay(delays[i]);
        addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                alphas[index] = (int) animation.getAnimatedValue();
                postInvalidate();
            }
        });
        animators.add(alphaAnim);
    }
    return animators;
}
 
Example 7
Source File: CourseActivity.java    From ClassSchedule with Apache License 2.0 6 votes vote down vote up
private void animSelectWeek(boolean show) {
    mSelectWeekIsShow = show;

    int start = 0, end = 0;
    if (show) {
        start = -mHeightSelectWeek;
    } else {
        end = -mHeightSelectWeek;
    }

    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.setDuration(300);
    animator.setInterpolator(new DecelerateInterpolator());

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mRvSelectWeek.getLayoutParams();
            params.topMargin = (int) animation.getAnimatedValue();
            mRvSelectWeek.setLayoutParams(params);
        }
    });
    animator.start();
}
 
Example 8
Source File: CircleRunnerView.java    From ToyView with MIT License 6 votes vote down vote up
private void startAnimation() {
    if (valueAnimator == null) {
        valueAnimator = ValueAnimator.ofInt(60);
        valueAnimator.setDuration(1000);
        valueAnimator.setInterpolator(new LinearInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if (animatedValue != (int) animation.getAnimatedValue()) {
                    animatedValue = (int) animation.getAnimatedValue();
                    drawMe(getWidth(), getHeight());
                    n += 0.03;
                }
            }
        });
        valueAnimator.setRepeatMode(ValueAnimator.REVERSE);
        valueAnimator.setRepeatCount(-1);
        valueAnimator.start();
    }
}
 
Example 9
Source File: CreateCardView.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
private static ValueAnimator slideAnimator(int start, int end, final View v) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.setInterpolator(new FastOutSlowInInterpolator());

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            //Update Height
            int value = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
            layoutParams.height = value;
            v.setLayoutParams(layoutParams);
        }
    });
    return animator;
}
 
Example 10
Source File: NumberPadTimePickerBottomSheetComponent.java    From BottomSheetPickers with Apache License 2.0 5 votes vote down vote up
@NonNull
private static ValueAnimator newArgbValueAnimator(int[] colors) {
    // Equivalent to ValueAnimator.ofArgb() which is only for API 21+.
    ValueAnimator animator = ValueAnimator.ofInt(colors);
    animator.setEvaluator(new ArgbEvaluator());
    return animator;
}
 
Example 11
Source File: DPullRefreshLayout.java    From Pas with Apache License 2.0 5 votes vote down vote up
/**
 * 隐藏下拉刷新控件,带动画
 */
private void hiddenRefreshHeaderView() {
    ValueAnimator animator = ValueAnimator.ofInt(mWholeHeaderView.getPaddingTop(), mMinWholeHeaderViewPaddingTop);
    animator.setDuration(mRefreshViewHolder.getTopAnimDuration());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int paddingTop = (int) animation.getAnimatedValue();
            mWholeHeaderView.setPadding(0, paddingTop, 0, 0);
        }
    });
    animator.start();
}
 
Example 12
Source File: BottomNavigationTab.java    From JD-Test with Apache License 2.0 5 votes vote down vote up
public void select(boolean setActiveColor, int animationDuration) {
    isActive = true;

    ValueAnimator animator = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        animator = ValueAnimator.ofInt(containerView.getPaddingTop(), paddingTopActive);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                    containerView.setPadding(containerView.getPaddingLeft(),
                            (Integer) valueAnimator.getAnimatedValue(),
                            containerView.getPaddingRight(),
                            containerView.getPaddingBottom());
                }
            }
        });
        animator.setDuration(animationDuration);
        animator.start();
    }

    iconView.setSelected(true);
    if (setActiveColor) {
        labelView.setTextColor(mActiveColor);
    } else {
        labelView.setTextColor(mBackgroundColor);
    }

    if (badgeItem != null) {
        badgeItem.select();
    }
}
 
Example 13
Source File: BottomBarTab.java    From BottomNavigationBar with MIT License 5 votes vote down vote up
public void widthAnimator(int startWidth, int endWidth) {
    final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams();
    ValueAnimator w = ValueAnimator.ofInt(startWidth, endWidth);
    w.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            params.width = (int) animation.getAnimatedValue();
            requestLayout();
        }
    });
    animatorList.add(w);
}
 
Example 14
Source File: ExpandableView.java    From ExpandableView with Apache License 2.0 5 votes vote down vote up
private ValueAnimator slideAnimator(int start, int end) {

        ValueAnimator animator = ValueAnimator.ofInt(start, end);
        animator.setDuration(DURATION);

        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int value = (Integer) valueAnimator.getAnimatedValue();

                ViewGroup.LayoutParams layoutParams = contentLayout.getLayoutParams();
                layoutParams.height = value;

                contentLayout.setLayoutParams(layoutParams);
                contentLayout.invalidate();

                if (outsideContentLayoutList != null && !outsideContentLayoutList.isEmpty()) {

                    for (ViewGroup outsideParam : outsideContentLayoutList) {
                        ViewGroup.LayoutParams params = outsideParam.getLayoutParams();

                        if (outsideContentHeight == 0) {
                            outsideContentHeight = params.height;
                        }

                        params.height = outsideContentHeight + value;
                        outsideParam.setLayoutParams(params);
                        outsideParam.invalidate();
                    }
                }
            }
        });
        return animator;
    }
 
Example 15
Source File: BallPainter.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initColorAnimator() {
  colorAnimator = ValueAnimator.ofInt(0, 255);
  colorAnimator.setDuration(ballMovementRange);
  colorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override public void onAnimationUpdate(ValueAnimator animation) {
      toBgPainter.setAlpha((Integer) animation.getAnimatedValue());
    }
  });
}
 
Example 16
Source File: ProgressDrawable.java    From CollapsingRefresh with Apache License 2.0 5 votes vote down vote up
private void setupAnimators() {
    mValueAnimator = ValueAnimator.ofInt(30, 3600);
    mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int value = (int) animation.getAnimatedValue();
            mProgressDegree = 30 * (value / 30);
            invalidateSelf();
        }
    });
    mValueAnimator.setDuration(10000);
    mValueAnimator.setInterpolator(new LinearInterpolator());
    mValueAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mValueAnimator.setRepeatMode(ValueAnimator.RESTART);
}
 
Example 17
Source File: CirclBigView.java    From SmartLoadingView with MIT License 5 votes vote down vote up
public void setXY(int x, int y) {
    this.x = x;
    this.y = y;
    int y_true = y + fatherRadius;
    //知道了view圆心,计算出到手机4个角的距离,以最大距离为准
    int left_top = (int) Math.sqrt((x * x) + (y_true * y_true));
    int left_bottom = (int) Math.sqrt((x * x) + ((UIUtil.getHeight(getContext()) - y_true) * (UIUtil.getHeight(getContext()) - y_true)));

    int right_top = (int) Math.sqrt(((UIUtil.getWidth(getContext()) - x) * (UIUtil.getWidth(getContext()) - x)) + (y_true * y_true));
    int right_bottom = (int) Math.sqrt(((UIUtil.getWidth(getContext()) - x) * (UIUtil.getWidth(getContext()) - x)) + ((UIUtil.getHeight(getContext()) - y_true) * (UIUtil.getHeight(getContext()) - y_true)));

    int left_big = left_top >= left_bottom ? left_top : left_bottom;
    int right_big = right_top >= right_bottom ? right_top : right_bottom;
    maxRadius = left_big >= right_big ? left_big : right_big;
    //这里虚拟键有个bug,我们把半径大小稍加长
    maxRadius = maxRadius + UIUtil.getWidth(getContext()) / 6;


    animator_big = ValueAnimator.ofInt(myRadius, maxRadius);
    animator_big.setDuration(200);
    animator_big.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            myRadius = (int) valueAnimator.getAnimatedValue();
            postInvalidate();
        }
    });

    invalidate();
}
 
Example 18
Source File: BindBaseRefreshHeader.java    From LazyRecyclerAdapter with MIT License 5 votes vote down vote up
protected void smoothScrollTo(int destHeight) {
    ValueAnimator animator = ValueAnimator.ofInt(getVisibleHeight(), destHeight);
    animator.setDuration(mScrollTime).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            setVisibleHeight((int) animation.getAnimatedValue());
        }
    });
    animator.start();
}
 
Example 19
Source File: ShimmerLayout.java    From ShimmerLayout with Apache License 2.0 5 votes vote down vote up
private Animator getShimmerAnimation() {
    if (maskAnimator != null) {
        return maskAnimator;
    }

    if (maskRect == null) {
        maskRect = calculateBitmapMaskRect();
    }

    final int animationToX = getWidth();
    final int animationFromX;

    if (getWidth() > maskRect.width()) {
        animationFromX = -animationToX;
    } else {
        animationFromX = -maskRect.width();
    }

    final int shimmerBitmapWidth = maskRect.width();
    final int shimmerAnimationFullLength = animationToX - animationFromX;

    maskAnimator = isAnimationReversed ? ValueAnimator.ofInt(shimmerAnimationFullLength, 0)
            : ValueAnimator.ofInt(0, shimmerAnimationFullLength);
    maskAnimator.setDuration(shimmerAnimationDuration);
    maskAnimator.setRepeatCount(ObjectAnimator.INFINITE);

    maskAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            maskOffsetX = animationFromX + (int) animation.getAnimatedValue();

            if (maskOffsetX + shimmerBitmapWidth >= 0) {
                invalidate();
            }
        }
    });

    return maskAnimator;
}
 
Example 20
Source File: LoadingAnimView.java    From ReadMark with Apache License 2.0 5 votes vote down vote up
private void initRepeatAnim(){
    //16ms重绘一次
    mRepeatAnim = ValueAnimator.ofInt(0, 1);
    mRepeatAnim.setRepeatCount(ValueAnimator.INFINITE);
    mRepeatAnim.setDuration(16);
    mRepeatAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationRepeat(Animator animation) {
            super.onAnimationRepeat(animation);
            invalidate();
        }
    });
    mRepeatAnim.start();
    isRepeatOn = true;
}