Search in sources :

Example 91 with Interpolator

use of android.view.animation.Interpolator in project Dxditor by kimi2009.

the class MapPageActivity method jumpPoint.

/**
 * marker点击时跳动一下
 */
public void jumpPoint(final Marker marker) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = aMap.getProjection();
    final LatLng markerLatlng = marker.getPosition();
    Point markerPoint = proj.toScreenLocation(markerLatlng);
    markerPoint.offset(0, -100);
    final LatLng startLatLng = proj.fromScreenLocation(markerPoint);
    final long duration = 1500;
    final Interpolator interpolator = new BounceInterpolator();
    handler.post(new Runnable() {

        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            double lng = t * markerLatlng.longitude + (1 - t) * startLatLng.longitude;
            double lat = t * markerLatlng.latitude + (1 - t) * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));
            if (t < 1.0) {
                handler.postDelayed(this, 16);
            }
        }
    });
}
Also used : BounceInterpolator(android.view.animation.BounceInterpolator) Handler(android.os.Handler) Projection(com.amap.api.maps.Projection) BounceInterpolator(android.view.animation.BounceInterpolator) Interpolator(android.view.animation.Interpolator) LatLng(com.amap.api.maps.model.LatLng) Point(android.graphics.Point)

Example 92 with Interpolator

use of android.view.animation.Interpolator in project MDM-Android-Agent by wso2-attic.

the class FloatKeyframeSet method getFloatValue.

public float getFloatValue(float fraction) {
    if (mNumKeyframes == 2) {
        if (firstTime) {
            firstTime = false;
            firstValue = ((FloatKeyframe) mKeyframes.get(0)).getFloatValue();
            lastValue = ((FloatKeyframe) mKeyframes.get(1)).getFloatValue();
            deltaValue = lastValue - firstValue;
        }
        if (mInterpolator != null) {
            fraction = mInterpolator.getInterpolation(fraction);
        }
        if (mEvaluator == null) {
            return firstValue + fraction * deltaValue;
        } else {
            return ((Number) mEvaluator.evaluate(fraction, firstValue, lastValue)).floatValue();
        }
    }
    if (fraction <= 0f) {
        final FloatKeyframe prevKeyframe = (FloatKeyframe) mKeyframes.get(0);
        final FloatKeyframe nextKeyframe = (FloatKeyframe) mKeyframes.get(1);
        float prevValue = prevKeyframe.getFloatValue();
        float nextValue = nextKeyframe.getFloatValue();
        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 + intervalFraction * (nextValue - prevValue) : ((Number) mEvaluator.evaluate(intervalFraction, prevValue, nextValue)).floatValue();
    } else if (fraction >= 1f) {
        final FloatKeyframe prevKeyframe = (FloatKeyframe) mKeyframes.get(mNumKeyframes - 2);
        final FloatKeyframe nextKeyframe = (FloatKeyframe) mKeyframes.get(mNumKeyframes - 1);
        float prevValue = prevKeyframe.getFloatValue();
        float nextValue = nextKeyframe.getFloatValue();
        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 + intervalFraction * (nextValue - prevValue) : ((Number) mEvaluator.evaluate(intervalFraction, prevValue, nextValue)).floatValue();
    }
    FloatKeyframe prevKeyframe = (FloatKeyframe) mKeyframes.get(0);
    for (int i = 1; i < mNumKeyframes; ++i) {
        FloatKeyframe nextKeyframe = (FloatKeyframe) 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());
            float prevValue = prevKeyframe.getFloatValue();
            float nextValue = nextKeyframe.getFloatValue();
            return mEvaluator == null ? prevValue + intervalFraction * (nextValue - prevValue) : ((Number) mEvaluator.evaluate(intervalFraction, prevValue, nextValue)).floatValue();
        }
        prevKeyframe = nextKeyframe;
    }
    // shouldn't get here
    return ((Number) mKeyframes.get(mNumKeyframes - 1).getValue()).floatValue();
}
Also used : FloatKeyframe(com.actionbarsherlock.internal.nineoldandroids.animation.Keyframe.FloatKeyframe) Interpolator(android.view.animation.Interpolator)

Example 93 with Interpolator

use of android.view.animation.Interpolator in project MDM-Android-Agent by wso2-attic.

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 94 with Interpolator

use of android.view.animation.Interpolator in project incubator-weex by apache.

the class WXCircleViewPager method postInitViewPager.

/**
 * Override the Scroller instance with our own class so we can change the
 * duration
 */
private void postInitViewPager() {
    if (isInEditMode()) {
        return;
    }
    try {
        Field scroller = ViewPager.class.getDeclaredField("mScroller");
        scroller.setAccessible(true);
        Field interpolator = ViewPager.class.getDeclaredField("sInterpolator");
        interpolator.setAccessible(true);
        mScroller = new WXSmoothScroller(getContext(), (Interpolator) interpolator.get(null));
        scroller.set(this, mScroller);
    } catch (Exception e) {
        WXLogUtils.e("[CircleViewPager] postInitViewPager: ", e);
    }
}
Also used : Field(java.lang.reflect.Field) Interpolator(android.view.animation.Interpolator)

Example 95 with Interpolator

use of android.view.animation.Interpolator in project android-toolbox by Knickedi.

the class SwipeableHiddenView method dispatchDraw.

/**
 * <i>Overridden for internal use!</i>
 */
@Override
public void dispatchDraw(Canvas canvas) {
    long drawingTime = getDrawingTime();
    if (!isHiddenViewCovered()) {
        canvas.save();
        Interpolator interpolator = mAnimateForward ? mData.openAnimation : mData.closeAnimation;
        float offset = getWidth() * interpolator.getInterpolation(Math.abs(mOffset));
        if (mOffset >= 0) {
            // clip from left edge towards right edge
            canvas.clipRect(0, 0, offset, getHeight());
        } else {
            // clip from right edge towards left edge
            canvas.clipRect(getWidth() - offset, 0, getWidth(), getHeight());
        }
        if (mHiddenView == null) {
            // if hidden view is controlled by another swipeable hidden view we draw its
            // cached bitmap (view witch contains it)
            drawChild(canvas, mHiddenViewCache, drawingTime);
        } else {
            drawChild(canvas, mHiddenView, drawingTime);
        }
        canvas.restore();
        int overlayOffset = Math.round(offset);
        overlayOffset = mOffset >= 0 ? overlayOffset : -overlayOffset;
        mOverlayView.offsetLeftAndRight(overlayOffset);
        drawChild(canvas, mOverlayView, drawingTime);
        mOverlayView.offsetLeftAndRight(-overlayOffset);
    } else {
        drawChild(canvas, mOverlayView, drawingTime);
    }
}
Also used : Interpolator(android.view.animation.Interpolator) LinearInterpolator(android.view.animation.LinearInterpolator)

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