Search in sources :

Example 56 with Interpolator

use of android.view.animation.Interpolator in project httpclient by pixmob.

the class IntKeyframeSet method getIntValue.

public int getIntValue(float fraction) {
    if (mNumKeyframes == 2) {
        if (firstTime) {
            firstTime = false;
            firstValue = ((IntKeyframe) mKeyframes.get(0)).getIntValue();
            lastValue = ((IntKeyframe) mKeyframes.get(1)).getIntValue();
            deltaValue = lastValue - firstValue;
        }
        if (mInterpolator != null) {
            fraction = mInterpolator.getInterpolation(fraction);
        }
        if (mEvaluator == null) {
            return firstValue + (int) (fraction * deltaValue);
        } else {
            return ((Number) mEvaluator.evaluate(fraction, firstValue, lastValue)).intValue();
        }
    }
    if (fraction <= 0f) {
        final IntKeyframe prevKeyframe = (IntKeyframe) mKeyframes.get(0);
        final IntKeyframe nextKeyframe = (IntKeyframe) mKeyframes.get(1);
        int prevValue = prevKeyframe.getIntValue();
        int nextValue = nextKeyframe.getIntValue();
        float prevFraction = prevKeyframe.getFraction();
        float nextFraction = nextKeyframe.getFraction();
        final Interpolator /*Time*/
        interpolator = nextKeyframe.getInterpolator();
        if (interpolator != null) {
            fraction = interpolator.getInterpolation(fraction);
        }
        float intervalFraction = (fraction - prevFraction) / (nextFraction - prevFraction);
        return mEvaluator == null ? prevValue + (int) (intervalFraction * (nextValue - prevValue)) : ((Number) mEvaluator.evaluate(intervalFraction, prevValue, nextValue)).intValue();
    } else if (fraction >= 1f) {
        final IntKeyframe prevKeyframe = (IntKeyframe) mKeyframes.get(mNumKeyframes - 2);
        final IntKeyframe nextKeyframe = (IntKeyframe) mKeyframes.get(mNumKeyframes - 1);
        int prevValue = prevKeyframe.getIntValue();
        int nextValue = nextKeyframe.getIntValue();
        float prevFraction = prevKeyframe.getFraction();
        float nextFraction = nextKeyframe.getFraction();
        final Interpolator /*Time*/
        interpolator = nextKeyframe.getInterpolator();
        if (interpolator != null) {
            fraction = interpolator.getInterpolation(fraction);
        }
        float intervalFraction = (fraction - prevFraction) / (nextFraction - prevFraction);
        return mEvaluator == null ? prevValue + (int) (intervalFraction * (nextValue - prevValue)) : ((Number) mEvaluator.evaluate(intervalFraction, prevValue, nextValue)).intValue();
    }
    IntKeyframe prevKeyframe = (IntKeyframe) mKeyframes.get(0);
    for (int i = 1; i < mNumKeyframes; ++i) {
        IntKeyframe nextKeyframe = (IntKeyframe) mKeyframes.get(i);
        if (fraction < nextKeyframe.getFraction()) {
            final Interpolator /*Time*/
            interpolator = nextKeyframe.getInterpolator();
            if (interpolator != null) {
                fraction = interpolator.getInterpolation(fraction);
            }
            float intervalFraction = (fraction - prevKeyframe.getFraction()) / (nextKeyframe.getFraction() - prevKeyframe.getFraction());
            int prevValue = prevKeyframe.getIntValue();
            int nextValue = nextKeyframe.getIntValue();
            return mEvaluator == null ? prevValue + (int) (intervalFraction * (nextValue - prevValue)) : ((Number) mEvaluator.evaluate(intervalFraction, prevValue, nextValue)).intValue();
        }
        prevKeyframe = nextKeyframe;
    }
    // shouldn't get here
    return ((Number) mKeyframes.get(mNumKeyframes - 1).getValue()).intValue();
}
Also used : Interpolator(android.view.animation.Interpolator) IntKeyframe(com.actionbarsherlock.internal.nineoldandroids.animation.Keyframe.IntKeyframe)

Example 57 with Interpolator

use of android.view.animation.Interpolator in project smooth-app-bar-layout by henrytao-me.

the class SmoothAppBarLayout method onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
    int i = 0;
    for (int z = this.getChildCount(); i < z; ++i) {
        View child = this.getChildAt(i);
        LayoutParams childLp = (LayoutParams) child.getLayoutParams();
        Interpolator interpolator = childLp.getScrollInterpolator();
        if (interpolator != null) {
            mHaveChildWithInterpolator = true;
            break;
        }
    }
}
Also used : Interpolator(android.view.animation.Interpolator) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 58 with Interpolator

use of android.view.animation.Interpolator in project material-components-android by material-components.

the class AppBarLayout method onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
    invalidateScrollRanges();
    mHaveChildWithInterpolator = false;
    for (int i = 0, z = getChildCount(); i < z; i++) {
        final View child = getChildAt(i);
        final LayoutParams childLp = (LayoutParams) child.getLayoutParams();
        final Interpolator interpolator = childLp.getScrollInterpolator();
        if (interpolator != null) {
            mHaveChildWithInterpolator = true;
            break;
        }
    }
    updateCollapsible();
}
Also used : Interpolator(android.view.animation.Interpolator) View(android.view.View)

Example 59 with Interpolator

use of android.view.animation.Interpolator in project TransitionPlayer by linfaxin.

the class XiaoMaIntroDemo method initSmoothScrollToViewPager.

private void initSmoothScrollToViewPager(ViewPager viewPager) {
    try {
        Interpolator sInterpolator = new Interpolator() {

            public float getInterpolation(float t) {
                t -= 1.0f;
                return t * t * t * t * t + 1.0f;
            }
        };
        Field field = ViewPager.class.getDeclaredField("mScroller");
        field.setAccessible(true);
        field.set(viewPager, new Scroller(this, sInterpolator) {

            @Override
            public void startScroll(int startX, int startY, int dx, int dy, int duration) {
                super.startScroll(startX, startY, dx, dy, duration * 2);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) Interpolator(android.view.animation.Interpolator) Scroller(android.widget.Scroller)

Example 60 with Interpolator

use of android.view.animation.Interpolator in project MLib by DaoBillTang.

the class RollPagerView method setAnimationDurtion.

/**
 * 设置viewager滑动动画持续时间
 *
 * @param during
 */
public void setAnimationDurtion(final int during) {
    try {
        // viePager平移动画事件
        Field mField = ViewPager.class.getDeclaredField("mScroller");
        mField.setAccessible(true);
        Scroller mScroller = new Scroller(getContext(), new Interpolator() {

            @Override
            public // 动画效果与ViewPager的一致
            float getInterpolation(float t) {
                t -= 1.0f;
                return t * t * t * t * t + 1.0f;
            }
        }) {

            @Override
            public void startScroll(int startX, int startY, int dx, int dy, int duration) {
                // 如果手工滚动,则加速滚动
                if (System.currentTimeMillis() - mRecentTouchTime > delay) {
                    duration = during;
                } else {
                    duration /= 2;
                }
                super.startScroll(startX, startY, dx, dy, duration);
            }

            @Override
            public void startScroll(int startX, int startY, int dx, int dy) {
                super.startScroll(startX, startY, dx, dy, during);
            }
        };
        mField.set(mViewPager, mScroller);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) Interpolator(android.view.animation.Interpolator) Scroller(android.widget.Scroller)

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