public ObjectAnimator getDisappearAnimator() { if (!mIsInitialized || !mDrawValuesReady) { Log.e(TAG, "RadialSelectorView was not ready for animation."); return null; } Keyframe kf0, kf1, kf2; float midwayPoint = 0.2f; int duration = 500; kf0 = Keyframe.ofFloat(0f, 1); kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier); kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier); PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe( "animationRadiusMultiplier", kf0, kf1, kf2); kf0 = Keyframe.ofFloat(0f, 1f); kf1 = Keyframe.ofFloat(1f, 0f); PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1); ObjectAnimator disappearAnimator = ObjectAnimator.ofPropertyValuesHolder( this, radiusDisappear, fadeOut).setDuration(duration); disappearAnimator.addUpdateListener(mInvalidateUpdateListener); return disappearAnimator; }
private void slideTo(int slideOffset, boolean forceInstant) { if (animator != null) { animator.cancel(); animator = null; } if (!forceInstant) { animator = ObjectAnimator.ofInt(this, "slideOffset", this.slideOffset, slideOffset); animator.setInterpolator(new FastOutSlowInInterpolator()); animator.setDuration(400); animator.start(); ViewCompat.postInvalidateOnAnimation(this); } else { this.slideOffset = slideOffset; requestLayout(); invalidate(); } }
/** * Returns an Animator which can animate a clipping circle. * <p/> * Any shadow cast by the View will respect the circular clip from this animator. * <p/> * Only a single non-rectangular clip can be applied on a View at any time. * Views clipped by a circular reveal animation take priority over * {@link View#setClipToOutline(boolean) View Outline clipping}. * <p/> * Note that the animation returned here is a one-shot animation. It cannot * be re-used, and once started it cannot be paused or resumed. * * @param view The View will be clipped to the animating circle. * @param centerX The x coordinate of the center of the animating circle. * @param centerY The y coordinate of the center of the animating circle. * @param startRadius The starting radius of the animating circle. * @param endRadius The ending radius of the animating circle. */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static SupportAnimator createCircularReveal(View view, int centerX, int centerY, float startRadius, float endRadius) { if (!(view.getParent() instanceof RevealAnimator)) { throw new IllegalArgumentException("View must be inside RevealFrameLayout or RevealLinearLayout."); } RevealAnimator revealLayout = (RevealAnimator) view.getParent(); revealLayout.attachRevealInfo(new RevealInfo(centerX, centerY, startRadius, endRadius, new WeakReference<>(view))); if (LOLLIPOP_PLUS) { return new SupportAnimatorLollipop(android.view.ViewAnimationUtils .createCircularReveal(view, centerX, centerY, startRadius, endRadius), revealLayout); } ObjectAnimator reveal = ObjectAnimator.ofFloat(revealLayout, CLIP_RADIUS, startRadius, endRadius); reveal.addListener(getRevealFinishListener(revealLayout)); return new SupportAnimatorPreL(reveal, revealLayout); }
public static ObjectAnimator getPulseAnimator(View labelToAnimate, float decreaseRatio, float increaseRatio) { Keyframe k0 = Keyframe.ofFloat(0f, 1f); Keyframe k1 = Keyframe.ofFloat(0.275f, decreaseRatio); Keyframe k2 = Keyframe.ofFloat(0.69f, increaseRatio); Keyframe k3 = Keyframe.ofFloat(1f, 1f); PropertyValuesHolder scaleX = PropertyValuesHolder.ofKeyframe("scaleX", k0, k1, k2, k3); PropertyValuesHolder scaleY = PropertyValuesHolder.ofKeyframe("scaleY", k0, k1, k2, k3); ObjectAnimator pulseAnimator = ObjectAnimator.ofPropertyValuesHolder( labelToAnimate, scaleX, scaleY); pulseAnimator.setDuration(PULSE_ANIMATOR_DURATION); return pulseAnimator; }
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 protected void onStateChange(int state) { this.state = state; ObjectAnimator.clearAllAnimations(); stateImg.setVisibility(View.INVISIBLE); progress.setVisibility(View.INVISIBLE); ViewHelper.setAlpha(progress, 1f); switch (state) { case NONE: break; case PULLING: break; case LOOSENT_O_LOAD: break; case LOADING: AnimUtil.startShow(progress, 0.1f, 200, 0); AnimUtil.startRotation(progress, ViewHelper.getRotation(progress) + 359.99f, 500, 0, -1); break; case LOAD_CLONE: AnimUtil.startShow(stateImg, 0.1f, 400, 200); AnimUtil.startHide(progress); break; } }
@Override protected void onStateChange(int state) { this.state = state; ObjectAnimator.clearAllAnimations(); stateImg.setVisibility(View.INVISIBLE); progress.setVisibility(View.VISIBLE); ViewHelper.setAlpha(progress, 1f); switch (state) { case NONE: break; case PULLING: break; case LOOSENT_O_REFRESH: break; case REFRESHING: AnimUtil.startRotation(progress, ViewHelper.getRotation(progress) + 359.99f, 500, 0, -1); break; case REFRESH_CLONE: AnimUtil.startShow(stateImg, 0.1f, 400, 200); AnimUtil.startHide(progress); break; } }
private void startNeedleAnimator() { if (isPlaying) { mNeedleAnimator = ObjectAnimator.ofFloat(mNeedle, "rotation", 0, NEEDLE_ROTATE_CIRCLE); } else { mNeedleAnimator = ObjectAnimator.ofFloat(mNeedle, "rotation", NEEDLE_ROTATE_CIRCLE, 0); } mNeedleAnimator.setDuration(NEEDLE_ANIMATOR_TIME); mNeedleAnimator.setInterpolator(new DecelerateInterpolator()); if (mNeedleAnimator.isRunning() || mNeedleAnimator.isStarted()) { mNeedleAnimator.cancel(); } mNeedleAnimator.start(); }
/** * 隐藏模糊背景 */ protected void dismissShowdown() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mBg, "alpha", 1, 0); objectAnimator.setDuration(400); objectAnimator.start(); objectAnimator.addListener(new SimpleAnimationListener() { @Override public void onAnimationEnd(Animator animation) { mParentVG.removeView(mBg); } }); }
@Override protected void initData(Context context) { super.initData(context); // creating animators mDimSelectorWheelAnimator = ObjectAnimator.ofFloat(this, PROPERTY_SELECTOR_PAINT_COEFF, 1, 0); mDimSeparatorsAnimator = ObjectAnimator.ofInt(this, PROPERTY_SEPARATORS_PAINT_ALPHA, mSelectionDividerActiveAlpha, mSelectionDividerDimmedAlpha ); // creating paints mSeparatorsPaint = new Paint(); mSeparatorsPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mSeparatorsPaint.setAlpha(mSelectionDividerDimmedAlpha); mSelectorWheelPaint = new Paint(); mSelectorWheelPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); }
/** * Animates transition between current rotation to target rotation * * @param fromRotation * @param toRotation * @param duration * @param interpolator * @param isFrom * @return */ @NonNull public Animator rotate(float fromRotation, float toRotation, float duration, @Nullable Interpolator interpolator, boolean isFrom) { Animator animator; if (isFrom) { animator = ObjectAnimator.ofFloat(mView, "rotation", toRotation, fromRotation); } else { animator = ObjectAnimator.ofFloat(mView, "rotation", fromRotation, toRotation); } setProperties(animator, duration, interpolator); return animator; }
private void animateView(final ViewGroup parent, final View view) { if (mAnimationStartMillis == -1) { mAnimationStartMillis = System.currentTimeMillis(); } ViewHelper.setAlpha(view, 0); Animator[] childAnimators; if (mDecoratedBaseAdapter instanceof AnimationAdapter) { childAnimators = ((AnimationAdapter) mDecoratedBaseAdapter).getAnimators(parent, view); } else { childAnimators = new Animator[0]; } Animator[] animators = getAnimators(parent, view); Animator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1); AnimatorSet set = new AnimatorSet(); set.playTogether(concatAnimators(childAnimators, animators, alphaAnimator)); set.setStartDelay(calculateAnimationDelay()); set.setDuration(getAnimationDurationMillis()); set.start(); mAnimators.put(view.hashCode(), set); }
/** * Animates transition between current alpha to target alpha * * @param fromAlpha * @param toAlpha * @param duration * @param interpolator * @param isFrom * @return */ @NonNull public Animator alpha(float fromAlpha, float toAlpha, float duration, @Nullable Interpolator interpolator, boolean isFrom) { Animator animator; if (isFrom) { animator = ObjectAnimator.ofFloat(mView, "alpha", toAlpha, fromAlpha); } else { animator = ObjectAnimator.ofFloat(mView, "alpha", fromAlpha, toAlpha); } setProperties(animator, duration, interpolator); return animator; }
public void onCollapseAnimator(AnimatorSet animatorSet) { int count = this.contentView.getChildCount(); for(int i = 0; i < count; ++i) { View rootView = this.contentView.getChildAt(i); ImageView iconIv = (ImageView)ABViewUtil.obtainView(rootView, com.wangjie.rapidfloatingactionbutton.R.id.rfab__content_label_list_icon_iv); if(null == iconIv) { return; } ObjectAnimator animator = new ObjectAnimator(); animator.setTarget(iconIv); animator.setFloatValues(new float[]{0.0F, 45.0F}); animator.setPropertyName("rotation"); animator.setInterpolator(this.mOvershootInterpolator); //animator.setStartDelay((long)(count * i * 20)); animatorSet.playTogether(new Animator[]{animator}); } }
/** * 显示模糊背景 */ protected void showShowdown() { ViewHelper.setTranslationY(mRootView, 0); mEffect.effect(mParentVG,mBg); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); if(mBg.getParent()!= null){ mParentVG.removeView(mBg); } mParentVG.addView(mBg, lp); ViewHelper.setAlpha(mBg, 0); ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mBg, "alpha", 0, 1); objectAnimator.setDuration(400); objectAnimator.start(); }
void onFingerDown(View v, float x, float y) { mTouchRipple.cx = mBackgroundRipple.cx = x; mTouchRipple.cy = mBackgroundRipple.cy = y; mTouchRipple.radius = mBackgroundRipple.radius = 0f; mViewSize = Math.max(v.getWidth(), v.getHeight()); if (mCurrentAnimator == null) { mRippleBackgroundPaint.setAlpha(RIPPLE_BACKGROUND_ALPHA); mCurrentAnimator = ObjectAnimator.ofFloat(this, CREATE_TOUCH_RIPPLE, 0f, 1f); mCurrentAnimator.setDuration(DEFAULT_ANIM_DURATION); } if (!mCurrentAnimator.isRunning()) { mCurrentAnimator.start(); } }
/** * Animates transition between current rotationX to target rotationX * * @param rotationX * @param duration * @param interpolator * @param isFrom * @return */ @NonNull public Animator rotateX(float rotationX, float duration, @Nullable Interpolator interpolator, boolean isFrom) { Animator animator; if (isFrom) { animator = ObjectAnimator.ofFloat(mView, "rotationX", rotationX, ViewHelper.getRotationX(mView)); } else { animator = ObjectAnimator.ofFloat(mView, "rotationX", ViewHelper.getRotationX(mView), rotationX); } setProperties(animator, duration, interpolator); return animator; }
private ObjectAnimator getLabelAnimator() { if (labelAnimator == null) { labelAnimator = ObjectAnimator.ofFloat(this, "floatingLabelFraction", 0f, 1f); } labelAnimator.setDuration(floatingLabelAnimating ? 300 : 0); return labelAnimator; }
private ObjectAnimator getBottomLinesAnimator(float destBottomLines) { if (bottomLinesAnimator == null) { bottomLinesAnimator = ObjectAnimator.ofFloat(this, "currentBottomLines", destBottomLines); } else { bottomLinesAnimator.cancel(); bottomLinesAnimator.setFloatValues(destBottomLines); } return bottomLinesAnimator; }
public static ObjectAnimator getPulseAnimator(View labelToAnimate, float decreaseRatio, float increaseRatio) { Keyframe k0 = Keyframe.ofFloat(0f, 1f); Keyframe k1 = Keyframe.ofFloat(0.275f, decreaseRatio); Keyframe k2 = Keyframe.ofFloat(0.69f, increaseRatio); Keyframe k3 = Keyframe.ofFloat(1f, 1f); PropertyValuesHolder scaleX = PropertyValuesHolder.ofKeyframe("scaleX", k0, k1, k2, k3); PropertyValuesHolder scaleY = PropertyValuesHolder.ofKeyframe("scaleY", k0, k1, k2, k3); ObjectAnimator pulseAnimator = ObjectAnimator.ofPropertyValuesHolder(labelToAnimate, scaleX, scaleY); pulseAnimator.setDuration(PULSE_ANIMATOR_DURATION); return pulseAnimator; }
public ObjectAnimator getReappearAnimator() { if (!mIsInitialized || !mDrawValuesReady) { Log.e(TAG, "RadialSelectorView was not ready for animation."); return null; } Keyframe kf0, kf1, kf2, kf3; float midwayPoint = 0.2f; int duration = 500; // The time points are half of what they would normally be, because this animation is // staggered against the disappear so they happen seamlessly. The reappear starts // halfway into the disappear. float delayMultiplier = 0.25f; float transitionDurationMultiplier = 1f; float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier; int totalDuration = (int) (duration * totalDurationMultiplier); float delayPoint = (delayMultiplier * duration) / totalDuration; midwayPoint = 1 - (midwayPoint * (1 - delayPoint)); kf0 = Keyframe.ofFloat(0f, mTransitionEndRadiusMultiplier); kf1 = Keyframe.ofFloat(delayPoint, mTransitionEndRadiusMultiplier); kf2 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier); kf3 = Keyframe.ofFloat(1f, 1); PropertyValuesHolder radiusReappear = PropertyValuesHolder.ofKeyframe( "animationRadiusMultiplier", kf0, kf1, kf2, kf3); kf0 = Keyframe.ofFloat(0f, 0f); kf1 = Keyframe.ofFloat(delayPoint, 0f); kf2 = Keyframe.ofFloat(1f, 1f); PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2); ObjectAnimator reappearAnimator = ObjectAnimator.ofPropertyValuesHolder( this, radiusReappear, fadeIn).setDuration(totalDuration); reappearAnimator.addUpdateListener(mInvalidateUpdateListener); return reappearAnimator; }
public ObjectAnimator getDisappearAnimator() { if (!mIsInitialized || !mDrawValuesReady || mDisappearAnimator == null) { Log.e(TAG, "RadialTextView was not ready for animation."); return null; } return mDisappearAnimator; }
public ObjectAnimator getReappearAnimator() { if (!mIsInitialized || !mDrawValuesReady || mReappearAnimator == null) { Log.e(TAG, "RadialTextView was not ready for animation."); return null; } return mReappearAnimator; }
private void handleActionUp(MotionEvent event) { if (!isPanelOnTouch) { return; } long pressDuration = System.currentTimeMillis() - mPressStartTime; computeVelocity(); if (!isPanelShowing && ((event.getY() - firstDownY) < 0 && (Math.abs(event.getY() - firstDownY) > mMoveDistanceToTrigger)) || (yVelocity < 0 && Math.abs(yVelocity) > Math.abs(xVelocity) && Math.abs(yVelocity) > mMinVelocity)) { displayPanel(); } else if (!isPanelShowing && pressDuration < MAX_CLICK_TIME && distance(firstDownX, firstDownY, event.getX(), event.getY()) < MAX_CLICK_DISTANCE) { displayPanel(); } else if (!isPanelShowing && isDragging && ((event.getY() - firstDownY > 0) || Math.abs(event.getY() - firstDownY) < mMoveDistanceToTrigger)){ hidePanel(); } if (isPanelShowing) { View mPanel = findViewWithTag(TAG_PANEL); float currentY = ViewHelper.getY(mPanel); if (currentY < (mMeasureHeight - mPanelHeight) || currentY < (mMeasureHeight - mPanelHeight + mMoveDistanceToTrigger)) { ObjectAnimator.ofFloat(mPanel, "y", currentY, mMeasureHeight - mPanelHeight) .setDuration(mAnimationDuration).start(); } else if (currentY > mMeasureHeight - mPanelHeight + mMoveDistanceToTrigger){ hidePanel(); } } isPanelOnTouch = false; isDragging = false; deltaY = 0; }
private void startErrorScrollingAnimator() { int textWidth = Math.round(textPaint.measureText(error.toString())); if (errorLabelAnimator == null) { errorLabelAnimator = ObjectAnimator.ofInt(this, "errorLabelPosX", 0, (textWidth + getWidth() / 2)); errorLabelAnimator.setStartDelay(1000); errorLabelAnimator.setInterpolator(new LinearInterpolator()); errorLabelAnimator.setDuration(150 * error.length()); errorLabelAnimator.addUpdateListener(this); errorLabelAnimator.setRepeatCount(ValueAnimator.INFINITE); } else { errorLabelAnimator.setIntValues(0, textWidth + getWidth() / 2); } errorLabelAnimator.start(); }
private void startErrorMultilineAnimator(float destLines) { if (errorLabelAnimator == null) { errorLabelAnimator = ObjectAnimator.ofFloat(this, "currentNbErrorLines", destLines); } else { errorLabelAnimator.setFloatValues(destLines); } errorLabelAnimator.start(); }
public void animateCheck() { changeBackground(); ObjectAnimator objectAnimator; if (iSchecked) { objectAnimator = ObjectAnimator.ofFloat(this, "x", ball.xFin); } else { objectAnimator = ObjectAnimator.ofFloat(this, "x", ball.xIni); } objectAnimator.setDuration(300); objectAnimator.start(); }
/** * float的动画 */ private void playAnimation() { post(new Runnable() { @Override public void run() { float originalY = ViewHelper.getY(ButtonFloat.this) - Utils.dpToPx(24, getResources()); ViewHelper.setY(ButtonFloat.this, ViewHelper.getY(ButtonFloat.this) + getHeight() * 3); ObjectAnimator animator = ObjectAnimator.ofFloat(ButtonFloat.this, "y", originalY); animator.setInterpolator(new BounceInterpolator()); animator.setDuration(1500);// 动画持续时间 animator.start(); } }); }
private void startErrorScrollingAnimator() { int textWidth = Math.round(textPaint.measureText(error.toString())); if (errorLabelAnimator == null) { errorLabelAnimator = ObjectAnimator.ofInt(this, "errorLabelPosX", 0, textWidth + getWidth() / 2); errorLabelAnimator.setStartDelay(1000); errorLabelAnimator.setInterpolator(new LinearInterpolator()); errorLabelAnimator.setDuration(150 * error.length()); errorLabelAnimator.addUpdateListener(this); errorLabelAnimator.setRepeatCount(ValueAnimator.INFINITE); } else { errorLabelAnimator.setIntValues(0, textWidth + getWidth() / 2); } errorLabelAnimator.start(); }