Search in sources :

Example 31 with Interpolator

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;
}
Also used : PathInterpolator(android.view.animation.PathInterpolator) Interpolator(android.view.animation.Interpolator) PathInterpolator(android.view.animation.PathInterpolator)

Example 32 with Interpolator

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();
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) LinearInterpolator(android.view.animation.LinearInterpolator) TypedArray(android.content.res.TypedArray) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Interpolator(android.view.animation.Interpolator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) LinearInterpolator(android.view.animation.LinearInterpolator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator)

Example 33 with Interpolator

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();
    }
}
Also used : TypedArray(android.content.res.TypedArray) Interpolator(android.view.animation.Interpolator) Resources(android.content.res.Resources)

Example 34 with Interpolator

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, "");
    }
}
Also used : Field(java.lang.reflect.Field) Interpolator(android.view.animation.Interpolator)

Example 35 with Interpolator

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);
}
Also used : Rect(android.graphics.Rect) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) RotateAnimation(android.view.animation.RotateAnimation) Animation(android.view.animation.Animation) Interpolator(android.view.animation.Interpolator) LinearInterpolator(android.view.animation.LinearInterpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) AnimationListener(android.view.animation.Animation.AnimationListener)

Aggregations

Interpolator (android.view.animation.Interpolator)229 Animator (android.animation.Animator)60 ValueAnimator (android.animation.ValueAnimator)49 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)46 ObjectAnimator (android.animation.ObjectAnimator)39 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)25 PathInterpolator (android.view.animation.PathInterpolator)25 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)23 LinearInterpolator (android.view.animation.LinearInterpolator)18 Paint (android.graphics.Paint)17 View (android.view.View)17 PropertyValuesHolder (android.animation.PropertyValuesHolder)16 FloatKeyframe (com.actionbarsherlock.internal.nineoldandroids.animation.Keyframe.FloatKeyframe)16 IntKeyframe (com.actionbarsherlock.internal.nineoldandroids.animation.Keyframe.IntKeyframe)16 TimeAnimator (android.animation.TimeAnimator)15 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)14 TypedArray (android.content.res.TypedArray)14 Animation (android.view.animation.Animation)13 AnimatorSet (android.animation.AnimatorSet)12 TimeInterpolator (android.animation.TimeInterpolator)11