Java Code Examples for android.view.animation.Interpolator#getInterpolation()

The following examples show how to use android.view.animation.Interpolator#getInterpolation() . 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: CanvasTransformerBuilder.java    From WeatherStream with Apache License 2.0 5 votes vote down vote up
public CanvasTransformer zoom(final int openedX, final int closedX, 
		final int openedY, final int closedY,
		final int px, final int py, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.scale((openedX - closedX) * f + closedX,
					(openedY - closedY) * f + closedY, px, py);
		}			
	};
	return mTrans;
}
 
Example 2
Source File: CollapsingTextHelper.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
private static float lerp(float startValue, float endValue, float fraction,
                          Interpolator interpolator) {
    if (interpolator != null) {
        fraction = interpolator.getInterpolation(fraction);
    }
    return AnimUtils.lerp(startValue, endValue, fraction);
}
 
Example 3
Source File: CanvasTransformerBuilder.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public CanvasTransformer rotate(final int openedDeg, final int closedDeg, 
		final int px, final int py, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.rotate((openedDeg - closedDeg) * f + closedDeg, 
					px, py);
		}			
	};
	return mTrans;
}
 
Example 4
Source File: CanvasTransformerBuilder.java    From Moring-Alarm with Apache License 2.0 5 votes vote down vote up
public CanvasTransformer rotate(final int openedDeg, final int closedDeg, 
		final int px, final int py, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.rotate((openedDeg - closedDeg) * f + closedDeg, 
					px, py);
		}			
	};
	return mTrans;
}
 
Example 5
Source File: ChatActivity.java    From belvedere with Apache License 2.0 5 votes vote down vote up
@Override
public void onScroll(int height, int scrollArea, float scrollPosition) {
    final Interpolator interpolator = PathInterpolatorCompat.create(.19f,0f,.2f,1f);
    final float interpolation = interpolator.getInterpolation((scrollPosition * .30f));
    final int bottomPadding = (int) (-1f * interpolation * scrollArea);
    findViewById(R.id.activity_input).setTranslationY(bottomPadding);
    findViewById(R.id.activity_recyclerview).setTranslationY(bottomPadding);
}
 
Example 6
Source File: CanvasTransformerBuilder.java    From Moring-Alarm with Apache License 2.0 5 votes vote down vote up
public CanvasTransformer translate(final int openedX, final int closedX, 
		final int openedY, final int closedY, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.translate((openedX - closedX) * f + closedX,
					(openedY - closedY) * f + closedY);
		}			
	};
	return mTrans;
}
 
Example 7
Source File: CanvasTransformerBuilder.java    From WeatherStream with Apache License 2.0 5 votes vote down vote up
public CanvasTransformer translate(final int openedX, final int closedX, 
		final int openedY, final int closedY, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.translate((openedX - closedX) * f + closedX,
					(openedY - closedY) * f + closedY);
		}			
	};
	return mTrans;
}
 
Example 8
Source File: CanvasTransformerBuilder.java    From WeatherStream with Apache License 2.0 5 votes vote down vote up
public CanvasTransformer rotate(final int openedDeg, final int closedDeg, 
		final int px, final int py, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.rotate((openedDeg - closedDeg) * f + closedDeg, 
					px, py);
		}			
	};
	return mTrans;
}
 
Example 9
Source File: CollapsingTextHelper.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
private static float lerp(float startValue, float endValue, float fraction,
                          Interpolator interpolator) {
    if (interpolator != null) {
        fraction = interpolator.getInterpolation(fraction);
    }
    return startValue + Math.round(fraction * (endValue - startValue));
}
 
Example 10
Source File: CollapsingTextHelper.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
private static float lerp(float startValue, float endValue, float fraction,
        Interpolator interpolator) {
    if (interpolator != null) {
        fraction = interpolator.getInterpolation(fraction);
    }
    return AnimationUtils.lerp(startValue, endValue, fraction);
}
 
Example 11
Source File: CanvasTransformerBuilder.java    From LiuAGeAndroid with MIT License 5 votes vote down vote up
public CanvasTransformer rotate(final int openedDeg, final int closedDeg, 
		final int px, final int py, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.rotate((openedDeg - closedDeg) * f + closedDeg, 
					px, py);
		}			
	};
	return mTrans;
}
 
Example 12
Source File: CanvasTransformerBuilder.java    From LiuAGeAndroid with MIT License 5 votes vote down vote up
public CanvasTransformer zoom(final int openedX, final int closedX, 
		final int openedY, final int closedY,
		final int px, final int py, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.scale((openedX - closedX) * f + closedX,
					(openedY - closedY) * f + closedY, px, py);
		}			
	};
	return mTrans;
}
 
Example 13
Source File: CanvasTransformerBuilder.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public CanvasTransformer translate(final int openedX, final int closedX, 
		final int openedY, final int closedY, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.translate((openedX - closedX) * f + closedX,
					(openedY - closedY) * f + closedY);
		}			
	};
	return mTrans;
}
 
Example 14
Source File: ArcLayout.java    From timecat with Apache License 2.0 5 votes vote down vote up
/**
 * 计算动画开始时的偏移量
 */
private static long computeStartOffset(final int childCount, final boolean expanded, final int index, final float delayPercent, final long duration, Interpolator interpolator) {
    final float delay = delayPercent * duration;
    final long viewDelay = (long) (getTransformedIndex(expanded, childCount, index) * delay);
    final float totalDelay = delay * childCount;

    float normalizedDelay = viewDelay / totalDelay;
    normalizedDelay = interpolator.getInterpolation(normalizedDelay);

    return (long) (normalizedDelay * totalDelay);
}
 
Example 15
Source File: CanvasTransformerBuilder.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
public CanvasTransformer zoom(final int openedX, final int closedX, 
		final int openedY, final int closedY,
		final int px, final int py, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.scale((openedX - closedX) * f + closedX,
					(openedY - closedY) * f + closedY, px, py);
		}			
	};
	return mTrans;
}
 
Example 16
Source File: WindowAnimationSpec.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Binary searches for a {@code t} such that there exists a {@code -0.01 < eps < 0.01} for which
 * {@code interpolator(t + eps) > 0.99}.
 */
private static float findAlmostThereFraction(Interpolator interpolator) {
    float val = 0.5f;
    float adj = 0.25f;
    while (adj >= 0.01f) {
        if (interpolator.getInterpolation(val) < 0.99f) {
            val += adj;
        } else {
            val -= adj;
        }
        adj /= 2;
    }
    return val;
}
 
Example 17
Source File: DragLayer.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This method animates a view at the end of a drag and drop animation.
 *
 * @param view The view to be animated. This view is drawn directly into DragLayer, and so
 *        doesn't need to be a child of DragLayer.
 * @param from The initial location of the view. Only the left and top parameters are used.
 * @param to The final location of the view. Only the left and top parameters are used. This
 *        location doesn't account for scaling, and so should be centered about the desired
 *        final location (including scaling).
 * @param finalAlpha The final alpha of the view, in case we want it to fade as it animates.
 * @param finalScale The final scale of the view. The view is scaled about its center.
 * @param duration The duration of the animation.
 * @param motionInterpolator The interpolator to use for the location of the view.
 * @param alphaInterpolator The interpolator to use for the alpha of the view.
 * @param onCompleteRunnable Optional runnable to run on animation completion.
 * @param fadeOut Whether or not to fade out the view once the animation completes. If true,
 *        the runnable will execute after the view is faded out.
 * @param anchorView If not null, this represents the view which the animated view stays
 *        anchored to in case scrolling is currently taking place. Note: currently this is
 *        only used for the X dimension for the case of the workspace.
 */
public void animateView(final DragView view, final Rect from, final Rect to,
        final float finalAlpha, final float initScaleX, final float initScaleY,
        final float finalScaleX, final float finalScaleY, int duration,
        final Interpolator motionInterpolator, final Interpolator alphaInterpolator,
        final Runnable onCompleteRunnable, final int animationEndStyle, View anchorView) {

    // Calculate the duration of the animation based on the object's distance
    final float dist = (float) Math.hypot(to.left - from.left, to.top - from.top);
    final Resources res = getResources();
    final float maxDist = (float) res.getInteger(R.integer.config_dropAnimMaxDist);

    // If duration < 0, this is a cue to compute the duration based on the distance
    if (duration < 0) {
        duration = res.getInteger(R.integer.config_dropAnimMaxDuration);
        if (dist < maxDist) {
            duration *= mCubicEaseOutInterpolator.getInterpolation(dist / maxDist);
        }
        duration = Math.max(duration, res.getInteger(R.integer.config_dropAnimMinDuration));
    }

    // Fall back to cubic ease out interpolator for the animation if none is specified
    TimeInterpolator interpolator = null;
    if (alphaInterpolator == null || motionInterpolator == null) {
        interpolator = mCubicEaseOutInterpolator;
    }

    // Animate the view
    final float initAlpha = view.getAlpha();
    final float dropViewScale = view.getScaleX();
    AnimatorUpdateListener updateCb = new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final float percent = (Float) animation.getAnimatedValue();
            final int width = view.getMeasuredWidth();
            final int height = view.getMeasuredHeight();

            float alphaPercent = alphaInterpolator == null ? percent :
                    alphaInterpolator.getInterpolation(percent);
            float motionPercent = motionInterpolator == null ? percent :
                    motionInterpolator.getInterpolation(percent);

            float initialScaleX = initScaleX * dropViewScale;
            float initialScaleY = initScaleY * dropViewScale;
            float scaleX = finalScaleX * percent + initialScaleX * (1 - percent);
            float scaleY = finalScaleY * percent + initialScaleY * (1 - percent);
            float alpha = finalAlpha * alphaPercent + initAlpha * (1 - alphaPercent);

            float fromLeft = from.left + (initialScaleX - 1f) * width / 2;
            float fromTop = from.top + (initialScaleY - 1f) * height / 2;

            int x = (int) (fromLeft + Math.round(((to.left - fromLeft) * motionPercent)));
            int y = (int) (fromTop + Math.round(((to.top - fromTop) * motionPercent)));

            int anchorAdjust = mAnchorView == null ? 0 : (int) (mAnchorView.getScaleX() *
                (mAnchorViewInitialScrollX - mAnchorView.getScrollX()));

            int xPos = x - mDropView.getScrollX() + anchorAdjust;
            int yPos = y - mDropView.getScrollY();

            mDropView.setTranslationX(xPos);
            mDropView.setTranslationY(yPos);
            mDropView.setScaleX(scaleX);
            mDropView.setScaleY(scaleY);
            mDropView.setAlpha(alpha);
        }
    };
    animateView(view, updateCb, duration, interpolator, onCompleteRunnable, animationEndStyle,
            anchorView);
}
 
Example 18
Source File: Interpolators.java    From Animer with Apache License 2.0 4 votes vote down vote up
/**
 * Given the input params, sets OvershootParams variables to be used by the caller.
 * @param startProgress The progress from 0 to 1 that the overshoot starts from.
 * @param overshootPastProgress The progress from 0 to 1 where we overshoot past (should
 *        either be equal to startProgress or endProgress, depending on if we want to
 *        overshoot immediately or only once we reach the end).
 * @param endProgress The final progress from 0 to 1 that we will settle to.
 * @param velocityPxPerMs The initial velocity that causes this overshoot.
 * @param totalDistancePx The distance against which progress is calculated.
 */
public OvershootParams(float startProgress, float overshootPastProgress,
                       float endProgress, float velocityPxPerMs, int totalDistancePx, Context context) {
    velocityPxPerMs = Math.abs(velocityPxPerMs);
    start = startProgress;
    int startPx = (int) (start * totalDistancePx);
    // Overshoot by about half a frame.
    float overshootBy = OVERSHOOT_FACTOR * velocityPxPerMs *
            singleFrameMs / totalDistancePx / 2; //getSingleFrameMs(context)
    overshootBy = boundToRange(overshootBy, 0.02f, 0.15f);
    end = overshootPastProgress + overshootBy;
    int endPx = (int) (end  * totalDistancePx);
    int overshootDistance = endPx - startPx;
    // Calculate deceleration necessary to reach overshoot distance.
    // Formula: velocityFinal^2 = velocityInitial^2 + 2 * acceleration * distance
    //          0 = v^2 + 2ad (velocityFinal == 0)
    //          a = v^2 / -2d
    float decelerationPxPerMs = velocityPxPerMs * velocityPxPerMs / (2 * overshootDistance);
    // Calculate time necessary to reach peak of overshoot.
    // Formula: acceleration = velocity / time
    //          time = velocity / acceleration
    duration = (long) (velocityPxPerMs / decelerationPxPerMs);
    // Now that we're at the top of the overshoot, need to settle back to endProgress.
    float settleDistance = end - endProgress;
    int settleDistancePx = (int) (settleDistance * totalDistancePx);
    // Calculate time necessary for the settle.
    // Formula: distance = velocityInitial * time + 1/2 * acceleration * time^2
    //          d = 1/2at^2 (velocityInitial = 0, since we just stopped at the top)
    //          t = sqrt(2d/a)
    // Above formula assumes constant acceleration. Since we use ACCEL_DEACCEL, we actually
    // have acceleration to halfway then deceleration the rest. So the formula becomes:
    //          t = sqrt(d/a) * 2 (half the distance for accel, half for deaccel)
    long settleDuration = (long) Math.sqrt(settleDistancePx / decelerationPxPerMs) * 4;
    settleDuration = Math.max(MIN_SETTLE_DURATION, settleDuration);
    // How much of the animation to devote to playing the overshoot (the rest is for settle).
    float overshootFraction = (float) duration / (duration + settleDuration);
    duration += settleDuration;
    // Finally, create the interpolator, composed of two interpolators: an overshoot, which
    // reaches end > 1, and then a settle to endProgress.
    Interpolator overshoot = Interpolators.clampToProgress(DEACCEL, 0, overshootFraction);
    // The settle starts at 1, where 1 is the top of the overshoot, and maps to a fraction
    // such that final progress is endProgress. For example, if we overshot to 1.1 but want
    // to end at 1, we need to map to 1/1.1.
    Interpolator settle = Interpolators.clampToProgress(Interpolators.mapToProgress(
            ACCEL_DEACCEL, 1, (endProgress - start) / (end - start)), overshootFraction, 1);
    interpolator = t -> t <= overshootFraction
            ? overshoot.getInterpolation(t)
            : settle.getInterpolation(t);
}
 
Example 19
Source File: AnimatedCircleProgressView.java    From animated-circle-progress-view with Apache License 2.0 4 votes vote down vote up
private float interpolateAnimation(float animationDuration, float initialValue, float finalValue, Interpolator interpolator) {
	mRelativeProgress = mAnimationAbsoluteTime / animationDuration;
	float interpolatedProgress = interpolator.getInterpolation(mRelativeProgress);
	float totalMovementNeeded = finalValue - initialValue;
	return initialValue + (interpolatedProgress * totalMovementNeeded);
}
 
Example 20
Source File: AnimationMatrix.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
private static Interpolator inverse(@NonNull Interpolator interpolator) {
  return input -> 1f - interpolator.getInterpolation(input);
}