Search in sources :

Example 41 with Interpolator

use of android.view.animation.Interpolator in project weex-example by KalicyZhou.

the class WXAnimationModule method startAnimation.

public static void startAnimation(WXSDKInstance mWXSDKInstance, WXComponent component, @NonNull WXAnimationBean animationBean, @Nullable String callback) {
    if (component == null) {
        return;
    }
    if (component.getHostView() == null) {
        AnimationHolder holder = new AnimationHolder(animationBean, callback);
        component.postAnimation(holder);
        return;
    }
    try {
        Animator animator = createAnimator(animationBean, component.getHostView(), mWXSDKInstance.getViewPortWidth());
        if (animator != null) {
            Animator.AnimatorListener animatorCallback = createAnimatorListener(mWXSDKInstance, callback);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
                component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
            }
            Interpolator interpolator = createTimeInterpolator(animationBean);
            if (animatorCallback != null) {
                animator.addListener(animatorCallback);
            }
            if (interpolator != null) {
                animator.setInterpolator(interpolator);
            }
            animator.setDuration(animationBean.duration);
            animator.start();
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
        WXLogUtils.e("", e);
    }
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) Interpolator(android.view.animation.Interpolator) LinearInterpolator(android.view.animation.LinearInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator)

Example 42 with Interpolator

use of android.view.animation.Interpolator in project android_frameworks_base by AOSPA.

the class KeyguardAffordanceView method setCircleRadius.

private void setCircleRadius(float circleRadius, boolean slowAnimation, boolean noAnimation) {
    // Check if we need a new animation
    boolean radiusHidden = (mCircleAnimator != null && mCircleWillBeHidden) || (mCircleAnimator == null && mCircleRadius == 0.0f);
    boolean nowHidden = circleRadius == 0.0f;
    boolean radiusNeedsAnimation = (radiusHidden != nowHidden) && !noAnimation;
    if (!radiusNeedsAnimation) {
        if (mCircleAnimator == null) {
            mCircleRadius = circleRadius;
            updateIconColor();
            invalidate();
            if (nowHidden) {
                if (mPreviewView != null) {
                    mPreviewView.setVisibility(View.INVISIBLE);
                }
            }
        } else if (!mCircleWillBeHidden) {
            // We just update the end value
            float diff = circleRadius - mMinBackgroundRadius;
            PropertyValuesHolder[] values = mCircleAnimator.getValues();
            values[0].setFloatValues(mCircleStartValue + diff, circleRadius);
            mCircleAnimator.setCurrentPlayTime(mCircleAnimator.getCurrentPlayTime());
        }
    } else {
        cancelAnimator(mCircleAnimator);
        cancelAnimator(mPreviewClipper);
        ValueAnimator animator = getAnimatorToRadius(circleRadius);
        Interpolator interpolator = circleRadius == 0.0f ? Interpolators.FAST_OUT_LINEAR_IN : Interpolators.LINEAR_OUT_SLOW_IN;
        animator.setInterpolator(interpolator);
        long duration = 250;
        if (!slowAnimation) {
            float durationFactor = Math.abs(mCircleRadius - circleRadius) / (float) mMinBackgroundRadius;
            duration = (long) (CIRCLE_APPEAR_DURATION * durationFactor);
            duration = Math.min(duration, CIRCLE_DISAPPEAR_MAX_DURATION);
        }
        animator.setDuration(duration);
        animator.start();
        if (mPreviewView != null && mPreviewView.getVisibility() == View.VISIBLE) {
            mPreviewView.setVisibility(View.VISIBLE);
            mPreviewClipper = ViewAnimationUtils.createCircularReveal(mPreviewView, getLeft() + mCenterX, getTop() + mCenterY, mCircleRadius, circleRadius);
            mPreviewClipper.setInterpolator(interpolator);
            mPreviewClipper.setDuration(duration);
            mPreviewClipper.addListener(mClipEndListener);
            mPreviewClipper.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    mPreviewView.setVisibility(View.INVISIBLE);
                }
            });
            mPreviewClipper.start();
        }
    }
}
Also used : Animator(android.animation.Animator) RenderNodeAnimator(android.view.RenderNodeAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Interpolator(android.view.animation.Interpolator) ValueAnimator(android.animation.ValueAnimator)

Example 43 with Interpolator

use of android.view.animation.Interpolator in project android_frameworks_base by AOSPA.

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

use of android.view.animation.Interpolator in project android_frameworks_base by AOSPA.

the class GlobalScreenshot method createScreenshotDropOutAnimation.

private ValueAnimator createScreenshotDropOutAnimation(int w, int h, boolean statusBarVisible, boolean navBarVisible) {
    ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
    anim.setStartDelay(SCREENSHOT_DROP_OUT_DELAY);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mBackgroundView.setVisibility(View.GONE);
            mScreenshotView.setVisibility(View.GONE);
            mScreenshotView.setLayerType(View.LAYER_TYPE_NONE, null);
        }
    });
    if (!statusBarVisible || !navBarVisible) {
        // There is no status bar/nav bar, so just fade the screenshot away in place
        anim.setDuration(SCREENSHOT_FAST_DROP_OUT_DURATION);
        anim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float t = (Float) animation.getAnimatedValue();
                float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale) - t * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_FAST_DROP_OUT_MIN_SCALE);
                mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
                mScreenshotView.setAlpha(1f - t);
                mScreenshotView.setScaleX(scaleT);
                mScreenshotView.setScaleY(scaleT);
            }
        });
    } else {
        // In the case where there is a status bar, animate to the origin of the bar (top-left)
        final float scaleDurationPct = (float) SCREENSHOT_DROP_OUT_SCALE_DURATION / SCREENSHOT_DROP_OUT_DURATION;
        final Interpolator scaleInterpolator = new Interpolator() {

            @Override
            public float getInterpolation(float x) {
                if (x < scaleDurationPct) {
                    // Decelerate, and scale the input accordingly
                    return (float) (1f - Math.pow(1f - (x / scaleDurationPct), 2f));
                }
                return 1f;
            }
        };
        // Determine the bounds of how to scale
        float halfScreenWidth = (w - 2f * mBgPadding) / 2f;
        float halfScreenHeight = (h - 2f * mBgPadding) / 2f;
        final float offsetPct = SCREENSHOT_DROP_OUT_MIN_SCALE_OFFSET;
        final PointF finalPos = new PointF(-halfScreenWidth + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenWidth, -halfScreenHeight + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenHeight);
        // Animate the screenshot to the status bar
        anim.setDuration(SCREENSHOT_DROP_OUT_DURATION);
        anim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float t = (Float) animation.getAnimatedValue();
                float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale) - scaleInterpolator.getInterpolation(t) * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_DROP_OUT_MIN_SCALE);
                mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
                mScreenshotView.setAlpha(1f - scaleInterpolator.getInterpolation(t));
                mScreenshotView.setScaleX(scaleT);
                mScreenshotView.setScaleY(scaleT);
                mScreenshotView.setTranslationX(t * finalPos.x);
                mScreenshotView.setTranslationY(t * finalPos.y);
            }
        });
    }
    return anim;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PointF(android.graphics.PointF) Interpolator(android.view.animation.Interpolator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 45 with Interpolator

use of android.view.animation.Interpolator in project android_frameworks_base by AOSPA.

the class AnimatorInflater method loadAnimator.

/**
     * Creates a new animation whose parameters come from the specified context
     * and attributes set.
     *
     * @param res The resources
     * @param attrs The set of attributes holding the animation parameters
     * @param anim Null if this is a ValueAnimator, otherwise this is an
     *            ObjectAnimator
     */
private static ValueAnimator loadAnimator(Resources res, Theme theme, AttributeSet attrs, ValueAnimator anim, float pathErrorScale) throws NotFoundException {
    TypedArray arrayAnimator = null;
    TypedArray arrayObjectAnimator = null;
    if (theme != null) {
        arrayAnimator = theme.obtainStyledAttributes(attrs, R.styleable.Animator, 0, 0);
    } else {
        arrayAnimator = res.obtainAttributes(attrs, R.styleable.Animator);
    }
    // If anim is not null, then it is an object animator.
    if (anim != null) {
        if (theme != null) {
            arrayObjectAnimator = theme.obtainStyledAttributes(attrs, R.styleable.PropertyAnimator, 0, 0);
        } else {
            arrayObjectAnimator = res.obtainAttributes(attrs, R.styleable.PropertyAnimator);
        }
        anim.appendChangingConfigurations(arrayObjectAnimator.getChangingConfigurations());
    }
    if (anim == null) {
        anim = new ValueAnimator();
    }
    anim.appendChangingConfigurations(arrayAnimator.getChangingConfigurations());
    parseAnimatorFromTypeArray(anim, arrayAnimator, arrayObjectAnimator, pathErrorScale);
    final int resID = arrayAnimator.getResourceId(R.styleable.Animator_interpolator, 0);
    if (resID > 0) {
        final Interpolator interpolator = AnimationUtils.loadInterpolator(res, theme, resID);
        if (interpolator instanceof BaseInterpolator) {
            anim.appendChangingConfigurations(((BaseInterpolator) interpolator).getChangingConfiguration());
        }
        anim.setInterpolator(interpolator);
    }
    arrayAnimator.recycle();
    if (arrayObjectAnimator != null) {
        arrayObjectAnimator.recycle();
    }
    return anim;
}
Also used : TypedArray(android.content.res.TypedArray) BaseInterpolator(android.view.animation.BaseInterpolator) Interpolator(android.view.animation.Interpolator) BaseInterpolator(android.view.animation.BaseInterpolator)

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