use of android.view.animation.Interpolator in project android_frameworks_base by ResurrectionRemix.
the class FlingAnimationUtils method getDismissingProperties.
private AnimatorProperties getDismissingProperties(float currValue, float endValue, float velocity, float maxDistance) {
float maxLengthSeconds = (float) (mMaxLengthSeconds * Math.pow(Math.abs(endValue - currValue) / maxDistance, 0.5f));
float diff = Math.abs(endValue - currValue);
float velAbs = Math.abs(velocity);
float y2 = calculateLinearOutFasterInY2(velAbs);
float startGradient = y2 / LINEAR_OUT_FASTER_IN_X2;
Interpolator mLinearOutFasterIn = new PathInterpolator(0, 0, LINEAR_OUT_FASTER_IN_X2, y2);
float durationSeconds = startGradient * diff / velAbs;
if (durationSeconds <= maxLengthSeconds) {
mAnimatorProperties.interpolator = mLinearOutFasterIn;
} else if (velAbs >= mMinVelocityPxPerSecond) {
// Cross fade between linear-out-faster-in and linear interpolator with current
// velocity.
durationSeconds = maxLengthSeconds;
VelocityInterpolator velocityInterpolator = new VelocityInterpolator(durationSeconds, velAbs, diff);
InterpolatorInterpolator superInterpolator = new InterpolatorInterpolator(velocityInterpolator, mLinearOutFasterIn, mLinearOutSlowIn);
mAnimatorProperties.interpolator = superInterpolator;
} else {
// Just use a normal interpolator which doesn't take the velocity into account.
durationSeconds = maxLengthSeconds;
mAnimatorProperties.interpolator = Interpolators.FAST_OUT_LINEAR_IN;
}
mAnimatorProperties.duration = (long) (durationSeconds * 1000);
return mAnimatorProperties;
}
use of android.view.animation.Interpolator in project Bitocle by mthli.
the class SmoothProgressBar method applyStyle.
public void applyStyle(int styleResId) {
TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.SmoothProgressBar, 0, styleResId);
if (a.hasValue(R.styleable.SmoothProgressBar_spb_color)) {
setSmoothProgressDrawableColor(a.getColor(R.styleable.SmoothProgressBar_spb_color, 0));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_colors)) {
int colorsId = a.getResourceId(R.styleable.SmoothProgressBar_spb_colors, 0);
if (colorsId != 0) {
int[] colors = getResources().getIntArray(colorsId);
if (colors != null && colors.length > 0)
setSmoothProgressDrawableColors(colors);
}
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_sections_count)) {
setSmoothProgressDrawableSectionsCount(a.getInteger(R.styleable.SmoothProgressBar_spb_sections_count, 0));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_stroke_separator_length)) {
setSmoothProgressDrawableSeparatorLength(a.getDimensionPixelSize(R.styleable.SmoothProgressBar_spb_stroke_separator_length, 0));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_stroke_width)) {
setSmoothProgressDrawableStrokeWidth(a.getDimension(R.styleable.SmoothProgressBar_spb_stroke_width, 0));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_speed)) {
setSmoothProgressDrawableSpeed(a.getFloat(R.styleable.SmoothProgressBar_spb_speed, 0));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_progressiveStart_speed)) {
setSmoothProgressDrawableProgressiveStartSpeed(a.getFloat(R.styleable.SmoothProgressBar_spb_progressiveStart_speed, 0));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_progressiveStop_speed)) {
setSmoothProgressDrawableProgressiveStopSpeed(a.getFloat(R.styleable.SmoothProgressBar_spb_progressiveStop_speed, 0));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_reversed)) {
setSmoothProgressDrawableReversed(a.getBoolean(R.styleable.SmoothProgressBar_spb_reversed, false));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_mirror_mode)) {
setSmoothProgressDrawableMirrorMode(a.getBoolean(R.styleable.SmoothProgressBar_spb_mirror_mode, false));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_progressiveStart_activated)) {
setProgressiveStartActivated(a.getBoolean(R.styleable.SmoothProgressBar_spb_progressiveStart_activated, false));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_progressiveStart_activated)) {
setProgressiveStartActivated(a.getBoolean(R.styleable.SmoothProgressBar_spb_progressiveStart_activated, false));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_gradients)) {
setSmoothProgressDrawableUseGradients(a.getBoolean(R.styleable.SmoothProgressBar_spb_gradients, false));
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_generate_background_with_colors)) {
if (a.getBoolean(R.styleable.SmoothProgressBar_spb_generate_background_with_colors, false)) {
setSmoothProgressDrawableBackgroundDrawable(SmoothProgressBarUtils.generateDrawableWithColors(checkIndeterminateDrawable().getColors(), checkIndeterminateDrawable().getStrokeWidth()));
}
}
if (a.hasValue(R.styleable.SmoothProgressBar_spb_interpolator)) {
int iInterpolator = a.getInteger(R.styleable.SmoothProgressBar_spb_interpolator, -1);
Interpolator interpolator;
switch(iInterpolator) {
case INTERPOLATOR_ACCELERATEDECELERATE:
interpolator = new AccelerateDecelerateInterpolator();
break;
case INTERPOLATOR_DECELERATE:
interpolator = new DecelerateInterpolator();
break;
case INTERPOLATOR_LINEAR:
interpolator = new LinearInterpolator();
break;
case INTERPOLATOR_ACCELERATE:
interpolator = new AccelerateInterpolator();
break;
default:
interpolator = null;
}
if (interpolator != null) {
setInterpolator(interpolator);
}
}
a.recycle();
}
use of android.view.animation.Interpolator in project InfiniteCycleViewPager by Devlight.
the class InfiniteCycleManager method processAttributeSet.
public void processAttributeSet(final AttributeSet attributeSet) {
if (attributeSet == null)
return;
final TypedArray typedArray = mContext.obtainStyledAttributes(attributeSet, mIsVertical ? R.styleable.VerticalInfiniteCycleViewPager : R.styleable.HorizontalInfiniteCycleViewPager);
try {
setMinPageScaleOffset(typedArray.getDimension(mIsVertical ? R.styleable.VerticalInfiniteCycleViewPager_icvp_min_page_scale_offset : R.styleable.HorizontalInfiniteCycleViewPager_icvp_min_page_scale_offset, DEFAULT_MIN_PAGE_SCALE_OFFSET));
setCenterPageScaleOffset(typedArray.getDimension(mIsVertical ? R.styleable.VerticalInfiniteCycleViewPager_icvp_center_page_scale_offset : R.styleable.HorizontalInfiniteCycleViewPager_icvp_center_page_scale_offset, DEFAULT_CENTER_PAGE_SCALE_OFFSET));
setMinPageScale(typedArray.getFloat(mIsVertical ? R.styleable.VerticalInfiniteCycleViewPager_icvp_min_page_scale : R.styleable.HorizontalInfiniteCycleViewPager_icvp_min_page_scale, DEFAULT_MIN_SCALE));
setMaxPageScale(typedArray.getFloat(mIsVertical ? R.styleable.VerticalInfiniteCycleViewPager_icvp_max_page_scale : R.styleable.HorizontalInfiniteCycleViewPager_icvp_max_page_scale, DEFAULT_MAX_SCALE));
setMediumScaled(typedArray.getBoolean(mIsVertical ? R.styleable.VerticalInfiniteCycleViewPager_icvp_medium_scaled : R.styleable.HorizontalInfiniteCycleViewPager_icvp_medium_scaled, DEFAULT_IS_MEDIUM_SCALED));
setScrollDuration(typedArray.getInteger(mIsVertical ? R.styleable.VerticalInfiniteCycleViewPager_icvp_scroll_duration : R.styleable.HorizontalInfiniteCycleViewPager_icvp_scroll_duration, DEFAULT_SCROLL_DURATION));
// Retrieve interpolator
Interpolator interpolator = null;
try {
final int interpolatorId = typedArray.getResourceId(mIsVertical ? R.styleable.VerticalInfiniteCycleViewPager_icvp_interpolator : R.styleable.HorizontalInfiniteCycleViewPager_icvp_interpolator, 0);
interpolator = interpolatorId == 0 ? null : AnimationUtils.loadInterpolator(mContext, interpolatorId);
} catch (Resources.NotFoundException exception) {
interpolator = null;
exception.printStackTrace();
} finally {
setInterpolator(interpolator);
}
} finally {
typedArray.recycle();
}
}
use of android.view.animation.Interpolator in project UltimateAndroid by cymcsg.
the class CustomViewPager method postInitViewPager.
/**
* Override the Scroller instance with our own class so we can change the
* duration
*/
private void postInitViewPager() {
try {
Field scroller = ViewPager.class.getDeclaredField("mScroller");
scroller.setAccessible(true);
Field interpolator = ViewPager.class.getDeclaredField("sInterpolator");
interpolator.setAccessible(true);
mScroller = new FixSpeedScroller(getContext(), (Interpolator) interpolator.get(null));
scroller.set(this, mScroller);
} catch (Exception e) {
Logs.e(e, "");
}
}
use of android.view.animation.Interpolator in project UltimateAndroid by cymcsg.
the class ArcLayout method bindChildAnimation.
private void bindChildAnimation(final View child, final int index, final long duration) {
final boolean expanded = mExpanded;
final int centerX = getWidth() / 2;
final int centerY = getHeight() / 2;
final int radius = expanded ? 0 : mRadius;
final int childCount = getChildCount();
final float perDegrees = (mToDegrees - mFromDegrees) / (childCount - 1);
Rect frame = computeChildFrame(centerX, centerY, radius, mFromDegrees + index * perDegrees, mChildSize);
final int toXDelta = frame.left - child.getLeft();
final int toYDelta = frame.top - child.getTop();
Interpolator interpolator = mExpanded ? new AccelerateInterpolator() : new OvershootInterpolator(1.5f);
final long startOffset = computeStartOffset(childCount, mExpanded, index, 0.1f, duration, interpolator);
Animation animation = mExpanded ? createShrinkAnimation(0, toXDelta, 0, toYDelta, startOffset, duration, interpolator) : createExpandAnimation(0, toXDelta, 0, toYDelta, startOffset, duration, interpolator);
final boolean isLast = getTransformedIndex(expanded, childCount, index) == childCount - 1;
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (isLast) {
postDelayed(new Runnable() {
@Override
public void run() {
onAllAnimationsEnd();
}
}, 0);
}
}
});
child.setAnimation(animation);
}
Aggregations