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

The following examples show how to use android.animation.ValueAnimator#getAnimatedFraction() . 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: ViewAnim.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
	
	if (valueAnimator.getCurrentPlayTime() <= valueAnimator.getDuration()) {
		float fraction = valueAnimator.getAnimatedFraction();// 动画进度
		
		float scaleXDuration = mFinalBounds.width() - mStartBounds.width();
		float scaleYDuration = mFinalBounds.height() - mStartBounds.height();
		mView.getLayoutParams().width = (int)(mStartBounds.width() + (scaleXDuration * fraction));
		mView.getLayoutParams().height = (int)(mStartBounds.height() + (scaleYDuration * fraction));
		
		if (mListener != null) {
			mListener.onViewAnimationUpdate(mView, valueAnimator, fraction);
		}
	}
	mView.requestLayout();
}
 
Example 2
Source File: PaddingChangeListener.java    From ViewPropertyObjectAnimator with Apache License 2.0 6 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
    if (hasView()) {
        float animatedFraction = valueAnimator.getAnimatedFraction();
        int leftPadding = currentLeftPadding();
        int topPadding = currentTopPadding();
        int rightPadding = currentRightPadding();
        int bottomPadding = currentBottomPadding();

        if (mLeftPadding != null) {
            leftPadding = (int) calculateAnimatedValue(mLeftPadding.mFrom, mLeftPadding.mTo, animatedFraction);
        }
        if (mTopPadding != null) {
            topPadding = (int) calculateAnimatedValue(mTopPadding.mFrom, mTopPadding.mTo, animatedFraction);
        }
        if (mRightPadding != null) {
            rightPadding = (int) calculateAnimatedValue(mRightPadding.mFrom, mRightPadding.mTo, animatedFraction);
        }
        if (mBottomPadding != null) {
            bottomPadding = (int) calculateAnimatedValue(mBottomPadding.mFrom, mBottomPadding.mTo, animatedFraction);
        }
        mView.get().setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    }
}
 
Example 3
Source File: MarginChangeListener.java    From ViewPropertyObjectAnimator with Apache License 2.0 6 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
    if (hasView()) {
        float animatedFraction = valueAnimator.getAnimatedFraction();
        if (mLeftMargin != null) {
            mParams.leftMargin = (int) calculateAnimatedValue(mLeftMargin.mFrom, mLeftMargin.mTo, animatedFraction);
        }
        if (mTopMargin != null) {
            mParams.topMargin = (int) calculateAnimatedValue(mTopMargin.mFrom, mTopMargin.mTo, animatedFraction);
        }
        if (mRightMargin != null) {
            mParams.rightMargin = (int) calculateAnimatedValue(mRightMargin.mFrom, mRightMargin.mTo, animatedFraction);
        }
        if (mBottomMargin != null) {
            mParams.bottomMargin = (int) calculateAnimatedValue(mBottomMargin.mFrom, mBottomMargin.mTo, animatedFraction);
        }
        mView.get().requestLayout();
    }
}
 
Example 4
Source File: DimensionUpdateListener.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
  if (view.getLayoutParams() != null) {
    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    TimeInterpolator interpolator = animation.getInterpolator();
    float fraction = animation.getAnimatedFraction();
    int preWidth = layoutParams.width;
    int preHeight = layoutParams.height;
    if (width != null) {
      layoutParams.width = intEvaluator.evaluate(interpolator.getInterpolation(fraction),
                                                 width.first,
                                                 width.second);
    }
    if (height != null) {
      layoutParams.height = intEvaluator.evaluate(interpolator.getInterpolation(fraction),
                                                  height.first,
                                                  height.second);
    }
    if (preHeight != layoutParams.height || preWidth != layoutParams.width) {
      view.requestLayout();
    }
  }
}
 
Example 5
Source File: PieLayout.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    if (DEBUG) {
        log("Animation update "
                + animation.getAnimatedFraction() + " on: "
                + Thread.currentThread().getName());
    }

    mBackgroundFraction = animation.getAnimatedFraction();

    // propagate the animation event to all listeners
    for (ValueAnimator.AnimatorUpdateListener listener : mAnimationListenerCache) {
        listener.onAnimationUpdate(animation);
    }

    // animation updates occur on the main thread. it is save to call invalidate here.
    PieLayout.this.invalidate();
}
 
Example 6
Source File: ViewAnim.java    From ActivityOptionsICS with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
	
	if (valueAnimator.getCurrentPlayTime() <= valueAnimator.getDuration()) {
		float fraction = valueAnimator.getAnimatedFraction();// 动画进度
		
		float scaleXDuration = mFinalBounds.width() - mStartBounds.width();
		float scaleYDuration = mFinalBounds.height() - mStartBounds.height();
		mView.getLayoutParams().width = (int)(mStartBounds.width() + (scaleXDuration * fraction));
		mView.getLayoutParams().height = (int)(mStartBounds.height() + (scaleYDuration * fraction));
		
		if (mListener != null) {
			mListener.onViewAnimationUpdate(mView, valueAnimator, fraction);
		}
	}
	mView.requestLayout();
}
 
Example 7
Source File: FabView.java    From fabuless with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
	final float factor = animation.getAnimatedFraction();
	mTouchSpotRadius = (int) (mTargetRadius * factor);
	mTouchSpotPaint.setColor(transformAlpha(mTouchSpotColor, 0x00, 0x38, factor));
	mBackgroundDrawable.getPaint().setColor(transformColor(mBackgroundColorDarker, mBackgroundColor, factor));
	invalidate();
}
 
Example 8
Source File: FlingAnimation.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    float t = animation.getAnimatedFraction();
    if (t > mAnimationTimeFraction) {
        t = 1;
    } else {
        t = t / mAnimationTimeFraction;
    }
    final DragView dragView = (DragView) mDragLayer.getAnimatedView();
    final float time = t * mDuration;
    dragView.setTranslationX(time * mUX + mFrom.left + mAX * time * time / 2);
    dragView.setTranslationY(time * mUY + mFrom.top + mAY * time * time / 2);
    dragView.setAlpha(1f - mAlphaInterpolator.getInterpolation(t));
}
 
Example 9
Source File: DefaultClusterRenderer.java    From react-native-baidu-map with MIT License 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
    float fraction = valueAnimator.getAnimatedFraction();
    double lat = (to.latitude - from.latitude) * fraction + from.latitude;
    double lngDelta = to.longitude - from.longitude;

    // Take the shortest path across the 180th meridian.
    if (Math.abs(lngDelta) > 180) {
        lngDelta -= Math.signum(lngDelta) * 360;
    }
    double lng = lngDelta * fraction + from.longitude;
    LatLng position = new LatLng(lat, lng);
    marker.setPosition(position);
}
 
Example 10
Source File: PieSysInfo.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    int alpha = (int) (255 * animation.getAnimatedFraction());
    mClockPaint.setAlpha(alpha);
    mInfoPaint.setAlpha(alpha);

    // if we are going to get displayed update data
    if (alpha > 0 && mStaleData) {
        updateData();
        mStaleData = false;
    }
}
 
Example 11
Source File: PieChartRotationAnimatorV14.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    float scale = animation.getAnimatedFraction();
    float rotation = startRotation + (targetRotation - startRotation) * scale;
    rotation = (rotation % 360 + 360) % 360;
    chart.setChartRotation((int) rotation, false);
}
 
Example 12
Source File: PieChartRotationAnimatorV14.java    From SmartChart with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    float scale = animation.getAnimatedFraction();
    float rotation = startRotation + (targetRotation - startRotation) * scale;
    rotation = (rotation % 360 + 360) % 360;
    chart.setChartRotation((int) rotation, false);
}
 
Example 13
Source File: ChartViewportAnimatorV14.java    From SmartChart with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    float scale = animation.getAnimatedFraction();
    float diffLeft = (targetViewport.left - startViewport.left) * scale;
    float diffTop = (targetViewport.top - startViewport.top) * scale;
    float diffRight = (targetViewport.right - startViewport.right) * scale;
    float diffBottom = (targetViewport.bottom - startViewport.bottom) * scale;
    newViewport.set(startViewport.left + diffLeft, startViewport.top + diffTop, startViewport.right + diffRight,
            startViewport.bottom + diffBottom);
    chart.setCurrentViewport(newViewport);
}
 
Example 14
Source File: ManualControlActivity.java    From Scrollable with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    final float fraction = animation.getAnimatedFraction();
    final int height = mRecyclerHeight + (int)(mHeightDelta * fraction + .5F);
    final ViewGroup.LayoutParams params = mRecyclerView.getLayoutParams();
    params.height = height;
    mRecyclerView.requestLayout();
}
 
Example 15
Source File: DimensionChangeListener.java    From ViewPropertyObjectAnimator with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
    if (hasView()) {
        float animatedFraction = valueAnimator.getAnimatedFraction();
        if (mWidth != null) {
            mParams.width = (int) calculateAnimatedValue(mWidth.mFrom, mWidth.mTo, animatedFraction);
        }
        if (mHeight != null) {
            mParams.height = (int) calculateAnimatedValue(mHeight.mFrom, mHeight.mTo, animatedFraction);
        }
        mView.get().requestLayout();
    }
}
 
Example 16
Source File: FlingAnimation.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    float t = animation.getAnimatedFraction();
    if (t > mAnimationTimeFraction) {
        t = 1;
    } else {
        t = t / mAnimationTimeFraction;
    }
    final DragView dragView = (DragView) mDragLayer.getAnimatedView();
    final float time = t * mDuration;
    dragView.setTranslationX(time * mUX + mFrom.left + mAX * time * time / 2);
    dragView.setTranslationY(time * mUY + mFrom.top + mAY * time * time / 2);
    dragView.setAlpha(1f - mAlphaInterpolator.getInterpolation(t));
}
 
Example 17
Source File: PercentChangeListener.java    From ViewPropertyObjectAnimator with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
    if (hasView()) {
        float animatedFraction = valueAnimator.getAnimatedFraction();
        if (mWidthPercent != null) {
            mPercentLayoutInfo.widthPercent = calculateAnimatedValue(mWidthPercent.mFrom, mWidthPercent.mTo, animatedFraction);
        }
        if (mHeightPercent != null) {
            mPercentLayoutInfo.heightPercent = calculateAnimatedValue(mHeightPercent.mFrom, mHeightPercent.mTo, animatedFraction);
        }
        if (mLeftMarginPercent != null) {
            mPercentLayoutInfo.leftMarginPercent = calculateAnimatedValue(mLeftMarginPercent.mFrom, mLeftMarginPercent.mTo, animatedFraction);
        }
        if (mTopMarginPercent != null) {
            mPercentLayoutInfo.topMarginPercent = calculateAnimatedValue(mTopMarginPercent.mFrom, mTopMarginPercent.mTo, animatedFraction);
        }
        if (mRightMarginPercent != null) {
            mPercentLayoutInfo.rightMarginPercent = calculateAnimatedValue(mRightMarginPercent.mFrom, mRightMarginPercent.mTo, animatedFraction);
        }
        if (mBottomMarginPercent != null) {
            mPercentLayoutInfo.bottomMarginPercent = calculateAnimatedValue(mBottomMarginPercent.mFrom, mBottomMarginPercent.mTo, animatedFraction);
        }
        if (mAspectRatio != null) {
            mPercentLayoutInfo.aspectRatio = calculateAnimatedValue(mAspectRatio.mFrom, mAspectRatio.mTo, animatedFraction);
        }
        mView.get().requestLayout();
    }
}
 
Example 18
Source File: DefaultClusterRenderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
    float fraction = valueAnimator.getAnimatedFraction();
    double lat = (to.latitude - from.latitude) * fraction + from.latitude;
    double lngDelta = to.longitude - from.longitude;

    // Take the shortest path across the 180th meridian.
    if (Math.abs(lngDelta) > 180) {
        lngDelta -= Math.signum(lngDelta) * 360;
    }
    double lng = lngDelta * fraction + from.longitude;
    LatLng position = new LatLng(lat, lng);
    marker.setPosition(position);
}
 
Example 19
Source File: ToolbarProgressBarAnimatingView.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    mLastUpdatedAnimation = animation;
    mLastAnimatedFraction = animation.getAnimatedFraction();
    updateAnimation(mLastUpdatedAnimation, mLastAnimatedFraction);
}
 
Example 20
Source File: PopupItemView.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
    mOpenAnimationProgress = valueAnimator.getAnimatedFraction();
}