Search in sources :

Example 76 with Interpolator

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

the class ActivatableNotificationView method startActivateAnimation.

private void startActivateAnimation(final boolean reverse) {
    if (!isAttachedToWindow()) {
        return;
    }
    int widthHalf = mBackgroundNormal.getWidth() / 2;
    int heightHalf = mBackgroundNormal.getActualHeight() / 2;
    float radius = (float) Math.sqrt(widthHalf * widthHalf + heightHalf * heightHalf);
    Animator animator;
    if (reverse) {
        animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, radius, 0);
    } else {
        animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, 0, radius);
    }
    mBackgroundNormal.setVisibility(View.VISIBLE);
    Interpolator interpolator;
    Interpolator alphaInterpolator;
    if (!reverse) {
        interpolator = Interpolators.LINEAR_OUT_SLOW_IN;
        alphaInterpolator = Interpolators.LINEAR_OUT_SLOW_IN;
    } else {
        interpolator = ACTIVATE_INVERSE_INTERPOLATOR;
        alphaInterpolator = ACTIVATE_INVERSE_ALPHA_INTERPOLATOR;
    }
    animator.setInterpolator(interpolator);
    animator.setDuration(ACTIVATE_ANIMATION_LENGTH);
    if (reverse) {
        mBackgroundNormal.setAlpha(1f);
        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                updateBackground();
            }
        });
        animator.start();
    } else {
        mBackgroundNormal.setAlpha(0.4f);
        animator.start();
    }
    mBackgroundNormal.animate().alpha(reverse ? 0f : 1f).setInterpolator(alphaInterpolator).setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float animatedFraction = animation.getAnimatedFraction();
            if (reverse) {
                animatedFraction = 1.0f - animatedFraction;
            }
            setNormalBackgroundVisibilityAmount(animatedFraction);
        }
    }).setDuration(ACTIVATE_ANIMATION_LENGTH);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) StackStateAnimator(com.android.systemui.statusbar.stack.StackStateAnimator) TimeAnimator(android.animation.TimeAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PathInterpolator(android.view.animation.PathInterpolator) Interpolator(android.view.animation.Interpolator) ValueAnimator(android.animation.ValueAnimator)

Example 77 with Interpolator

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

the class NotificationStackScrollLayout method startBottomAnimation.

private void startBottomAnimation() {
    int previousStartValue = mStartAnimationRect.bottom;
    int previousEndValue = mEndAnimationRect.bottom;
    int newEndValue = mBackgroundBounds.bottom;
    ObjectAnimator previousAnimator = mBottomAnimator;
    if (previousAnimator != null && previousEndValue == newEndValue) {
        return;
    }
    if (!mAnimateNextBackgroundBottom) {
        // just a local update was performed
        if (previousAnimator != null) {
            // we need to increase all animation keyframes of the previous animator by the
            // relative change to the end value
            PropertyValuesHolder[] values = previousAnimator.getValues();
            values[0].setIntValues(previousStartValue, newEndValue);
            mStartAnimationRect.bottom = previousStartValue;
            mEndAnimationRect.bottom = newEndValue;
            previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            return;
        } else {
            // no new animation needed, let's just apply the value
            setBackgroundBottom(newEndValue);
            return;
        }
    }
    if (previousAnimator != null) {
        previousAnimator.cancel();
    }
    ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundBottom", mCurrentBounds.bottom, newEndValue);
    Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN;
    animator.setInterpolator(interpolator);
    animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
    // remove the tag when the animation is finished
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mStartAnimationRect.bottom = -1;
            mEndAnimationRect.bottom = -1;
            mBottomAnimator = null;
        }
    });
    animator.start();
    mStartAnimationRect.bottom = mCurrentBounds.bottom;
    mEndAnimationRect.bottom = newEndValue;
    mBottomAnimator = animator;
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) TimeAnimator(android.animation.TimeAnimator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) Interpolator(android.view.animation.Interpolator) Paint(android.graphics.Paint)

Example 78 with Interpolator

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

the class GlobalScreenshot method createScreenshotDropInAnimation.

private ValueAnimator createScreenshotDropInAnimation() {
    final float flashPeakDurationPct = ((float) (SCREENSHOT_FLASH_TO_PEAK_DURATION) / SCREENSHOT_DROP_IN_DURATION);
    final float flashDurationPct = 2f * flashPeakDurationPct;
    final Interpolator flashAlphaInterpolator = new Interpolator() {

        @Override
        public float getInterpolation(float x) {
            // Flash the flash view in and out quickly
            if (x <= flashDurationPct) {
                return (float) Math.sin(Math.PI * (x / flashDurationPct));
            }
            return 0;
        }
    };
    final Interpolator scaleInterpolator = new Interpolator() {

        @Override
        public float getInterpolation(float x) {
            // We start scaling when the flash is at it's peak
            if (x < flashPeakDurationPct) {
                return 0;
            }
            return (x - flashDurationPct) / (1f - flashDurationPct);
        }
    };
    ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
    anim.setDuration(SCREENSHOT_DROP_IN_DURATION);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mBackgroundView.setAlpha(0f);
            mBackgroundView.setVisibility(View.VISIBLE);
            mScreenshotView.setAlpha(0f);
            mScreenshotView.setTranslationX(0f);
            mScreenshotView.setTranslationY(0f);
            mScreenshotView.setScaleX(SCREENSHOT_SCALE + mBgPaddingScale);
            mScreenshotView.setScaleY(SCREENSHOT_SCALE + mBgPaddingScale);
            mScreenshotView.setVisibility(View.VISIBLE);
            mScreenshotFlash.setAlpha(0f);
            mScreenshotFlash.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            mScreenshotFlash.setVisibility(View.GONE);
        }
    });
    anim.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float t = (Float) animation.getAnimatedValue();
            float scaleT = (SCREENSHOT_SCALE + mBgPaddingScale) - scaleInterpolator.getInterpolation(t) * (SCREENSHOT_SCALE - SCREENSHOT_DROP_IN_MIN_SCALE);
            mBackgroundView.setAlpha(scaleInterpolator.getInterpolation(t) * BACKGROUND_ALPHA);
            mScreenshotView.setAlpha(t);
            mScreenshotView.setScaleX(scaleT);
            mScreenshotView.setScaleY(scaleT);
            mScreenshotFlash.setAlpha(flashAlphaInterpolator.getInterpolation(t));
        }
    });
    return anim;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Interpolator(android.view.animation.Interpolator) Animator(android.animation.Animator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 79 with Interpolator

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

the class ActivatableNotificationView method startActivateAnimation.

private void startActivateAnimation(final boolean reverse) {
    if (!isAttachedToWindow()) {
        return;
    }
    int widthHalf = mBackgroundNormal.getWidth() / 2;
    int heightHalf = mBackgroundNormal.getActualHeight() / 2;
    float radius = (float) Math.sqrt(widthHalf * widthHalf + heightHalf * heightHalf);
    Animator animator;
    if (reverse) {
        animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, radius, 0);
    } else {
        animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, 0, radius);
    }
    mBackgroundNormal.setVisibility(View.VISIBLE);
    Interpolator interpolator;
    Interpolator alphaInterpolator;
    if (!reverse) {
        interpolator = Interpolators.LINEAR_OUT_SLOW_IN;
        alphaInterpolator = Interpolators.LINEAR_OUT_SLOW_IN;
    } else {
        interpolator = ACTIVATE_INVERSE_INTERPOLATOR;
        alphaInterpolator = ACTIVATE_INVERSE_ALPHA_INTERPOLATOR;
    }
    animator.setInterpolator(interpolator);
    animator.setDuration(ACTIVATE_ANIMATION_LENGTH);
    if (reverse) {
        mBackgroundNormal.setAlpha(1f);
        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                updateBackground();
            }
        });
        animator.start();
    } else {
        mBackgroundNormal.setAlpha(0.4f);
        animator.start();
    }
    mBackgroundNormal.animate().alpha(reverse ? 0f : 1f).setInterpolator(alphaInterpolator).setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float animatedFraction = animation.getAnimatedFraction();
            if (reverse) {
                animatedFraction = 1.0f - animatedFraction;
            }
            setNormalBackgroundVisibilityAmount(animatedFraction);
        }
    }).setDuration(ACTIVATE_ANIMATION_LENGTH);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) StackStateAnimator(com.android.systemui.statusbar.stack.StackStateAnimator) TimeAnimator(android.animation.TimeAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PathInterpolator(android.view.animation.PathInterpolator) Interpolator(android.view.animation.Interpolator) ValueAnimator(android.animation.ValueAnimator)

Example 80 with Interpolator

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

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)

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