Java Code Examples for com.nineoldandroids.animation.ValueAnimator#ofInt()

The following examples show how to use com.nineoldandroids.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: PopBackgroundView.java    From AndroidColorPop with Apache License 2.0 6 votes vote down vote up
/**
 * Internal void to start the circles animation.
 * <p>
 * when this void is called the circles radius would be updated by a
 * {@link ValueAnimator} and then it will call the {@link View}'s
 * invalidate() void witch calls the onDraw void each time so a bigger
 * circle would be drawn each time till the cirlce's fill the whole screen.
 * </p>
 */
private void animateCirlce() {
	if (circles_fill_type == CIRLCES_FILL_HEIGHT_TYPE) {
		circle_max_radius = screen_height + (screen_height / 4);
	} else {
		circle_max_radius = screen_width + (screen_width / 4);
	}
	ValueAnimator va = ValueAnimator.ofInt(0, circle_max_radius / 3);
	va.setDuration(1000);
	va.addListener(this);
	va.setInterpolator(new AccelerateInterpolator());
	va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
		public void onAnimationUpdate(ValueAnimator animation) {
			int value = (int) animation.getAnimatedValue();
			circle_radius = value * 3;
			invalidate();
		}
	});
	va.start();
}
 
Example 2
Source File: PopBackgroundView.java    From AndroidColorPop with Apache License 2.0 6 votes vote down vote up
/**
 * Internal void to start the rectangle animation.
 * <p>
 * when this void is called the space at the top of the rectangle would be
 * updated by a {@link ValueAnimator} and then it will call the {@link View}
 * 's invalidate() void witch calls the onDraw void each time so a bigger
 * rectangle would be drawn each time till the it the rectangles height is
 * enough
 * </p>
 */
private void animateRect() {
	ValueAnimator va = ValueAnimator.ofInt(rect_space_top / 2,
			screen_height / 2);
	va.setDuration(500);
	va.addListener(this);
	va.setInterpolator(new DecelerateInterpolator());
	va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
		public void onAnimationUpdate(ValueAnimator animation) {
			int value = ((int) animation.getAnimatedValue()) * 2;
			int rect_top = -((value - rect_space_top) - screen_height);
			rect.top = rect_top;
			invalidate();
		}
	});
	va.start();
}
 
Example 3
Source File: DemoActivity_1.java    From android-art-res with Apache License 2.0 6 votes vote down vote up
private void performAnimate(final View target, final int start, final int end) {
    ValueAnimator valueAnimator = ValueAnimator.ofInt(1, 100);
    valueAnimator.addUpdateListener(new AnimatorUpdateListener() {

        // 持有一个IntEvaluator对象,方便下面估值的时候使用
        private IntEvaluator mEvaluator = new IntEvaluator();

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            // 获得当前动画的进度值,整型,1-100之间
            int currentValue = (Integer) animator.getAnimatedValue();
            Log.d(TAG, "current value: " + currentValue);

            // 获得当前进度占整个动画过程的比例,浮点型,0-1之间
            float fraction = animator.getAnimatedFraction();
            // 直接调用整型估值器通过比例计算出宽度,然后再设给Button
            target.getLayoutParams().width = mEvaluator.evaluate(fraction, start, end);
            target.requestLayout();
        }
    });

    valueAnimator.setDuration(5000).start();
}
 
Example 4
Source File: CardView.java    From example with Apache License 2.0 6 votes vote down vote up
/**
 * Create the Slide Animator invoked when the expand/collapse button is clicked
 */
protected ValueAnimator createSlideAnimator(int start, int end) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);

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

            ViewGroup.LayoutParams layoutParams = mInternalExpandLayout.getLayoutParams();
            layoutParams.height = value;
            mInternalExpandLayout.setLayoutParams(layoutParams);
        }
    });
    return animator;
}
 
Example 5
Source File: ExpandableListItemAdapter.java    From ListViewAnimations with Apache License 2.0 6 votes vote down vote up
public static ValueAnimator createHeightAnimator(final View view, final int start, final int end) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(final ValueAnimator animation) {
                    int value = (Integer) animation.getAnimatedValue();

                    LayoutParams layoutParams = view.getLayoutParams();
                    layoutParams.height = value;
                    view.setLayoutParams(layoutParams);
                }
            }
    );
    return animator;
}
 
Example 6
Source File: ArrowRefreshHeader.java    From Xrv with Apache License 2.0 5 votes vote down vote up
private void smoothScrollTo(int destHeight) {
    ValueAnimator animator = ValueAnimator.ofInt(getVisibleHeight(), destHeight);
    animator.setDuration(300).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            setVisibleHeight((int) animation.getAnimatedValue());
        }
    });
    animator.start();
}
 
Example 7
Source File: BGARefreshLayout.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
public void startChangeWholeHeaderViewPaddingTop(int distance) {
    ValueAnimator animator = ValueAnimator.ofInt(mWholeHeaderView.getPaddingTop(), mWholeHeaderView.getPaddingTop() - distance);
    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 8
Source File: BGARefreshLayout.java    From AndroidStudyDemo with GNU General Public License v2.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 9
Source File: BGARefreshLayout.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置下拉刷新控件的paddingTop到0,带动画
 */
private void changeRefreshHeaderViewToZero() {
    ValueAnimator animator = ValueAnimator.ofInt(mWholeHeaderView.getPaddingTop(), 0);
    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 10
Source File: TransferControlView.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private Animator getWidthAnimator(final int from, final int to) {
  final ValueAnimator anim = ValueAnimator.ofInt(from, to);
  anim.addUpdateListener(new AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
      final int val = (Integer)animation.getAnimatedValue();
      final ViewGroup.LayoutParams layoutParams = getLayoutParams();
      layoutParams.width = val;
      setLayoutParams(layoutParams);
    }
  });
  anim.setInterpolator(new FastOutSlowInInterpolator());
  anim.setDuration(TRANSITION_MS);
  return anim;
}
 
Example 11
Source File: RoundProgressBar.java    From Conquer with Apache License 2.0 5 votes vote down vote up
/**
     * 设置进度,此为线程安全控件,由于考虑多线的问题,需要同步 刷新界面调用postInvalidate()能在非UI线程刷新
     *
     * @param progress
     */

    public synchronized void setProgress(int progress) {
        if (this.progress == progress) {
            return;
        }

//        hasShowing = true;
        if (progress < 0) {
//			throw new IllegalArgumentException("progress not less than 0");
            return;
        }
        if (progress > max) {
            progress = max;
        }
        ValueAnimator va = ValueAnimator.ofInt(this.progress, progress);
        va.setDuration(1000);
        va.setInterpolator(new AccelerateInterpolator());
        va.start();
        va.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator arg0) {
                int value = (Integer) arg0.getAnimatedValue();
                if (value <= max) {
                    RoundProgressBar.this.progress = value;
                    invalidate();
                }
            }
        });

    }
 
Example 12
Source File: ExpandableListItemAdapter.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
public static ValueAnimator createHeightAnimator(final View view, int start, int end) {
	ValueAnimator animator = ValueAnimator.ofInt(start, end);
	animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

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

			ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
			layoutParams.height = value;
			view.setLayoutParams(layoutParams);
		}
	});
	return animator;
}
 
Example 13
Source File: ExpandableListItemAdapter.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public static ValueAnimator createHeightAnimator(final View view, final int start, final int end) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            int value = (Integer) valueAnimator.getAnimatedValue();

            LayoutParams layoutParams = view.getLayoutParams();
            layoutParams.height = value;
            view.setLayoutParams(layoutParams);
        }
    });
    return animator;
}
 
Example 14
Source File: ExpandableListItemAdapter.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static ValueAnimator createHeightAnimator(final View view, final int start, final int end) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            int value = (Integer) valueAnimator.getAnimatedValue();

            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            layoutParams.height = value;
            view.setLayoutParams(layoutParams);
        }
    });
    return animator;
}
 
Example 15
Source File: AnimateAdditionAdapter.java    From ListViewAnimations with Apache License 2.0 5 votes vote down vote up
@Override
@NonNull
public View getView(final int position, @Nullable final View convertView, @NonNull final ViewGroup parent) {
    final View view = super.getView(position, convertView, parent);

    if (mInsertQueue.getActiveIndexes().contains(position)) {
        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.MATCH_PARENT, View.MeasureSpec.AT_MOST);
        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED);
        view.measure(widthMeasureSpec, heightMeasureSpec);

        int originalHeight = view.getMeasuredHeight();

        ValueAnimator heightAnimator = ValueAnimator.ofInt(1, originalHeight);
        heightAnimator.addUpdateListener(new HeightUpdater(view));

        Animator[] customAnimators = getAdditionalAnimators(view, parent);
        Animator[] animators = new Animator[customAnimators.length + 1];
        animators[0] = heightAnimator;
        System.arraycopy(customAnimators, 0, animators, 1, customAnimators.length);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(animators);

        ViewHelper.setAlpha(view, 0);
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);

        AnimatorSet allAnimatorsSet = new AnimatorSet();
        allAnimatorsSet.playSequentially(animatorSet, alphaAnimator);

        allAnimatorsSet.setDuration(mInsertionAnimationDurationMs);
        allAnimatorsSet.addListener(new ExpandAnimationListener(position));
        allAnimatorsSet.start();
    }

    return view;
}