private void initAnimations() { searchAnimation = ValueAnimator.ofFloat(0f, 1f); searchAnimation.setDuration(50000); searchAnimation.setRepeatCount(ValueAnimator.INFINITE); searchAnimation.setRepeatMode(ValueAnimator.RESTART); searchAnimation.setInterpolator(new LinearInterpolator()); searchAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float angle = (valueAnimator.getAnimatedFraction() * 360); ViewHelper.setTranslationX(ivSearch, (float) Math.sin(angle) * radius); ViewHelper.setTranslationY(ivSearch, (float) Math.cos(angle) * radius); } }); scanAnimation = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_PARENT, 0f, TranslateAnimation.RELATIVE_TO_PARENT, 0f, TranslateAnimation.RELATIVE_TO_PARENT, 0f, TranslateAnimation.RELATIVE_TO_PARENT, 0.61f); scanAnimation.setDuration(2000); scanAnimation.setRepeatCount(TranslateAnimation.INFINITE); scanAnimation.setRepeatMode(TranslateAnimation.RESTART); }
/** * Starts the underlying Animator for a set of properties. We use a single animator that * simply runs from 0 to 1, and then use that fractional value to set each property * value accordingly. */ private void startAnimation() { ValueAnimator animator = ValueAnimator.ofFloat(1.0f); ArrayList<NameValuesHolder> nameValueList = (ArrayList<NameValuesHolder>) mPendingAnimations.clone(); mPendingAnimations.clear(); int propertyMask = 0; int propertyCount = nameValueList.size(); for (int i = 0; i < propertyCount; ++i) { NameValuesHolder nameValuesHolder = nameValueList.get(i); propertyMask |= nameValuesHolder.mNameConstant; } mAnimatorMap.put(animator, new PropertyBundle(propertyMask, nameValueList)); animator.addUpdateListener(mAnimatorEventListener); animator.addListener(mAnimatorEventListener); if (mStartDelaySet) { animator.setStartDelay(mStartDelay); } if (mDurationSet) { animator.setDuration(mDuration); } if (mInterpolatorSet) { animator.setInterpolator(mInterpolator); } animator.start(); }
/** * Custom animation builder. * * @param update the update * @param values the values * @return the animation builder */ public AnimationBuilder custom(final AnimationListener.Update update, float... values) { for (final View view : views) { ValueAnimator valueAnimator = ValueAnimator.ofFloat(getValues(values)); if (update != null) valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { //noinspection unchecked update.update(view, (Float) animation.getAnimatedValue()); } }); add(valueAnimator); } return this; }
@Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_UP) { // 恢复高度 final ValueAnimator animator = ValueAnimator.ofInt(parallaxImageView.getHeight(), originalHeight); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { Integer animateValue = (Integer) animator.getAnimatedValue(); // 给 ImageView 设置值 parallaxImageView.getLayoutParams().height = animateValue; parallaxImageView.requestLayout(); } }); animator.setInterpolator(new OvershootInterpolator()); // 弹性差值器 animator.setDuration(450); animator.start(); } return super.onTouchEvent(ev); }
private void startAnimation() { ValueAnimator animator = ValueAnimator.ofFloat(new float[]{1.0f}); ArrayList<NameValuesHolder> nameValueList = (ArrayList) this.mPendingAnimations.clone(); this.mPendingAnimations.clear(); int propertyMask = 0; for (int i = 0; i < nameValueList.size(); i++) { propertyMask |= ((NameValuesHolder) nameValueList.get(i)).mNameConstant; } this.mAnimatorMap.put(animator, new PropertyBundle(propertyMask, nameValueList)); animator.addUpdateListener(this.mAnimatorEventListener); animator.addListener(this.mAnimatorEventListener); if (this.mStartDelaySet) { animator.setStartDelay(this.mStartDelay); } if (this.mDurationSet) { animator.setDuration(this.mDuration); } if (this.mInterpolatorSet) { animator.setInterpolator(this.mInterpolator); } animator.start(); }
private void hideBubble() { if (mBubbleAnimator == null) { mBubbleAnimator = ValueAnimator.ofFloat(1.0F, 0.0F); mBubbleAnimator.addUpdateListener(mBubbleAnimatorListener); mBubbleAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mBubbleVisible = false; invalidate(); } }); } else { mBubbleAnimator.cancel(); } mBubbleAnimator.start(); }
private void hideScroller() { if (mScrollerAnimator == null) { mScrollerAnimator = ValueAnimator.ofFloat(1.0F, 0.0F); mScrollerAnimator.addUpdateListener(mHandleAnimatorListener); mScrollerAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mScrollerVisible = false; invalidate(); } }); } else { mScrollerAnimator.cancel(); } mScrollerAnimator.start(); }
private void dropTempWindow() { mInputBox.setVisibility(View.INVISIBLE); ValueAnimator va = ValueAnimator.ofInt(mEnterLayoutAnimSupportContainer.softkeyboardOpenY, mEnterLayoutAnimSupportContainer.openY); va.setDuration(300); va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int y = (int) animation.getAnimatedValue(); int b = (y - mEnterLayoutAnimSupportContainer.softkeyboardOpenY) * panelHeight / (mEnterLayoutAnimSupportContainer.openY - mEnterLayoutAnimSupportContainer.softkeyboardOpenY) - panelHeight; moveTempWindow(y); updateEnterLayoutBottom(b); if (y == mEnterLayoutAnimSupportContainer.openY) { removeTempWindow(); mInputBox.setVisibility(View.VISIBLE); } } }); va.start(); }
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; }
private void animateToolbar(final float toY) { float layoutTranslationY = ViewHelper.getTranslationY(mInterceptionLayout); if (layoutTranslationY != toY) { ValueAnimator animator = ValueAnimator.ofFloat(ViewHelper.getTranslationY(mInterceptionLayout), toY).setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float translationY = (float) animation.getAnimatedValue(); ViewHelper.setTranslationY(mInterceptionLayout, translationY); if (translationY < 0) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams(); lp.height = (int) (-translationY + getScreenHeight()); mInterceptionLayout.requestLayout(); } } }); animator.start(); } }
private void moveToolbar(float toTranslationY) { if (ViewHelper.getTranslationY(mToolbar) == toTranslationY) { return; } ValueAnimator animator = ValueAnimator.ofFloat(ViewHelper.getTranslationY(mToolbar), toTranslationY).setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float translationY = (float) animation.getAnimatedValue(); ViewHelper.setTranslationY(mToolbar, translationY); ViewHelper.setTranslationY((View) mScrollable, translationY); FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) ((View) mScrollable).getLayoutParams(); lp.height = (int) -translationY + getScreenHeight() - lp.topMargin; ((View) mScrollable).requestLayout(); } }); animator.start(); }
private void animateToolbar(final float toY) { float layoutTranslationY = ViewHelper.getTranslationY(mInterceptionLayout); if (layoutTranslationY != toY) { ValueAnimator animator = ValueAnimator.ofFloat(ViewHelper.getTranslationY(mInterceptionLayout), toY).setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float translationY = (float) animation.getAnimatedValue(); View toolbarView = getActivity().findViewById(R.id.toolbar); ViewHelper.setTranslationY(mInterceptionLayout, translationY); ViewHelper.setTranslationY(toolbarView, translationY); if (translationY < 0) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams(); lp.height = (int) (-translationY + getScreenHeight()); mInterceptionLayout.requestLayout(); } } }); animator.start(); } }
/** * 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(); }
/** * 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(); }
private void performRemovalIfNecessary() { if (mCurrentRemovedId == -1) { return; } ContextualUndoView currentRemovedView = getCurrentRemovedView(mCurrentRemovedView, mCurrentRemovedId); if (currentRemovedView != null) { ValueAnimator animator = ValueAnimator.ofInt(currentRemovedView.getHeight(), 1).setDuration(ANIMATION_DURATION); RemoveViewAnimatorListenerAdapter listener = new RemoveViewAnimatorListenerAdapter(currentRemovedView, mCurrentRemovedId); RemoveViewAnimatorUpdateListener updateListener = new RemoveViewAnimatorUpdateListener(listener); animator.addListener(listener); animator.addUpdateListener(updateListener); animator.start(); } else { // The hard way. deleteItemGivenId(mCurrentRemovedId); } clearCurrentRemovedView(); }
protected void performDismiss(final PendingDismissData data) { // Animate the dismissed list item to zero-height and fire the // dismiss callback when all dismissed list item animations have // completed. final ViewGroup.LayoutParams lp = data.view.getLayoutParams(); final int originalHeight = data.view.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); data.view.setLayoutParams(lp); } }); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { finalizeDismiss(); } }); animator.start(); }
@Override public void onAnimationUpdate(ValueAnimator animation) { View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab); IndicatorPoint p = (IndicatorPoint) animation.getAnimatedValue(); mIndicatorRect.left = (int) p.left; mIndicatorRect.right = (int) p.right; if (mIndicatorWidth < 0) { //indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip } else {//indicatorWidth大于0时,圆角矩形以及三角形 float indicatorLeft = p.left + (currentTabView.getWidth() - mIndicatorWidth) / 2; mIndicatorRect.left = (int) indicatorLeft; mIndicatorRect.right = (int) (mIndicatorRect.left + mIndicatorWidth); } invalidate(); }
private void startDiscAnimator(float animatedValue) { mDiscLayoutAnimator = ObjectAnimator.ofFloat(mDiscLayout, "rotation", animatedValue, 360 + animatedValue); mDiscLayoutAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator arg0) { mDiscLayoutAnimatorValue = (Float) arg0.getAnimatedValue(); } }); mDiscLayoutAnimator.setDuration(DISC_ANIMATOR_TIME); mDiscLayoutAnimator.setRepeatCount(DISC_ANIMATOR_REPEAT_COUNT); mDiscLayoutAnimator.setInterpolator(new LinearInterpolator()); if (mDiscLayoutAnimator.isRunning() || mDiscLayoutAnimator.isStarted()) { mDiscLayoutAnimator.cancel(); } mDiscLayoutAnimator.start(); }
private void reverseDiscAnimator() { mDiscLayoutAnimator = ObjectAnimator.ofFloat(mDiscLayout, "rotation", mDiscLayoutAnimatorValue, 360); mDiscLayoutAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator arg0) { mDiscLayoutAnimatorValue = (Float) arg0.getAnimatedValue(); } }); mDiscLayoutAnimator.setDuration(DISC_REVERSE_ANIMATOR_TIME); mDiscLayoutAnimator.setInterpolator(new AccelerateInterpolator()); if (mDiscLayoutAnimator.isRunning() || mDiscLayoutAnimator.isStarted()) { mDiscLayoutAnimator.cancel(); } mDiscLayoutAnimator.start(); }
@Override public List<Animator> createAnimation() { List<Animator> animators=new ArrayList<>(); long[] delays=new long[]{500,250,0,250,500}; for (int i = 0; i < 5; i++) { final int index=i; ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.3f,1); scaleAnim.setDuration(900); scaleAnim.setRepeatCount(-1); scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleYFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); animators.add(scaleAnim); } return animators; }
@Override public List<Animator> createAnimation() { List<Animator> animators=new ArrayList<>(); long[] durations=new long[]{1260, 430, 1010, 730}; long[] delays=new long[]{770, 290, 280, 740}; for (int i = 0; i < 4; i++) { final int index=i; ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.4f,1); scaleAnim.setDuration(durations[i]); scaleAnim.setRepeatCount(-1); scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); animators.add(scaleAnim); } return animators; }
@Override public List<Animator> createAnimation() { List<Animator> animators=new ArrayList<>(); float circleSpacing=4; float radius=(getWidth()-circleSpacing*2)/6; int[] delays=new int[]{70,140,210}; for (int i = 0; i < 3; i++) { final int index=i; ValueAnimator scaleAnim=ValueAnimator.ofFloat(getHeight()/2,getHeight()/2-radius*2,getHeight()/2); scaleAnim.setDuration(600); scaleAnim.setRepeatCount(-1); scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { translateYFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); animators.add(scaleAnim); } return animators; }
@Override public List<Animator> createAnimation() { List<Animator> animators=new ArrayList<>(); long[] delays=new long[]{400,200,0,200,400}; for (int i = 0; i < 5; i++) { final int index=i; ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.4f,1); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleYFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); animators.add(scaleAnim); } return animators; }
@Override public List<Animator> createAnimation() { List<Animator> animators=new ArrayList<>(); ValueAnimator scaleAnim=ValueAnimator.ofFloat(0.5f,1,0.5f); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloat = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); ObjectAnimator rotateAnim=ObjectAnimator.ofFloat(getTarget(),"rotation",0,180,360); rotateAnim.setDuration(1000); rotateAnim.setRepeatCount(-1); rotateAnim.start(); animators.add(scaleAnim); animators.add(rotateAnim); return animators; }
@Override public List<Animator> createAnimation() { List<Animator> 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]); alphaAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { alphas[index] = (int) animation.getAnimatedValue(); postInvalidate(); } }); alphaAnim.start(); animators.add(alphaAnim); } return animators; }
@Override public List<Animator> createAnimation() { List<Animator> animators=new ArrayList<>(); int[] delays=new int[]{120,240,360}; for (int i = 0; i < 3; i++) { final int index=i; ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.3f,1); scaleAnim.setDuration(750); scaleAnim.setRepeatCount(-1); scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); animators.add(scaleAnim); } return animators; }
@Override public List<Animator> createAnimation() { List<Animator> animators=new ArrayList<>(); long[] delays=new long[]{100,200,300,400,500}; for (int i = 0; i < 5; i++) { final int index=i; ValueAnimator scaleAnim=ValueAnimator.ofFloat(1, 0.4f, 1); scaleAnim.setDuration(1000); scaleAnim.setRepeatCount(-1); scaleAnim.setStartDelay(delays[i]); scaleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleYFloats[index] = (float) animation.getAnimatedValue(); postInvalidate(); } }); scaleAnim.start(); animators.add(scaleAnim); } return animators; }
public void expandView(final View view) { ValueAnimator animator = ValueAnimator.ofFloat(0, 1); animator.setInterpolator(new DecelerateInterpolator()); animator.setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { ViewHelper.setRotation(view,180 * (float) (animation.getAnimatedValue())); view.postInvalidate(); } }); animator.start(); }
public void collapseView(final View view) { ValueAnimator animator = ValueAnimator.ofFloat(1, 0); animator.setInterpolator(new DecelerateInterpolator()); animator.setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { ViewHelper.setRotation(view,180 * (float) (animation.getAnimatedValue())); view.postInvalidate(); } }); animator.start(); }
public void setState(State state) { this.state = state; if (state == State.GetMatrix) { if (animator == null) animator = ValueAnimatorProxy.ofFloat(0, 1).setInterpolator(new LinearInterpolator()).setDuration(3000).setRepeatCount(-1) .addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { currentValue = (Float) animation.getAnimatedValue(); invalidate(); } }).source(); animator.start(); } else if (animator != null) animator.cancel(); invalidate(); }
@Override public void onAnimationUpdate(ValueAnimator animation) { long currentTime = SystemClock.uptimeMillis(); long costTime = currentTime - mLastTime; mLastTime = currentTime; speedOffsetX += mSpeed * costTime / 1000; if (speedOffsetX >= mLength) speedOffsetX = speedOffsetX % mLength; if (callback != null) callback.refresh(getWave()); else getWave(); }
/** * 属性动画循环一定次数 * @param count * @param animator * @return */ @NonNull public static Animator valueAnimatorRepeat(final int count, @NonNull Animator animator) { if (count <= 1 && count != -1) return animator; if (animator instanceof ValueAnimator) { ValueAnimator valueAnimator = (ValueAnimator) animator; valueAnimator.setRepeatCount(Math.max(-1, count - 1)); return valueAnimator; } return animator; }
private void initAnim() { stopAnim(); //animator = ObjectAnimator.ofInt(this, "maskHeight", 0, imageHeight); animator = ObjectAnimator.ofInt(clipDrawable, "level", 0, 10000); animator.setDuration(animDuration); animator.setRepeatCount(ValueAnimator.INFINITE); animator.setRepeatMode(ValueAnimator.RESTART); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { invalidate(); } }); if(autoStart){ animator.start(); } }