Search in sources :

Example 6 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Launcher3 by chislon.

the class Workspace method animateBackgroundGradient.

private void animateBackgroundGradient(float finalAlpha, boolean animated) {
    if (mBackground == null)
        return;
    if (mBackgroundFadeInAnimation != null) {
        mBackgroundFadeInAnimation.cancel();
        mBackgroundFadeInAnimation = null;
    }
    if (mBackgroundFadeOutAnimation != null) {
        mBackgroundFadeOutAnimation.cancel();
        mBackgroundFadeOutAnimation = null;
    }
    float startAlpha = getBackgroundAlpha();
    if (finalAlpha != startAlpha) {
        if (animated) {
            mBackgroundFadeOutAnimation = LauncherAnimUtils.ofFloat(this, startAlpha, finalAlpha);
            mBackgroundFadeOutAnimation.addUpdateListener(new AnimatorUpdateListener() {

                public void onAnimationUpdate(ValueAnimator animation) {
                    setBackgroundAlpha(((Float) animation.getAnimatedValue()).floatValue());
                }
            });
            mBackgroundFadeOutAnimation.setInterpolator(new DecelerateInterpolator(1.5f));
            mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION);
            mBackgroundFadeOutAnimation.start();
        } else {
            setBackgroundAlpha(finalAlpha);
        }
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 7 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by ParanoidAndroid.

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 8 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by ParanoidAndroid.

the class KeyguardMultiUserAvatar method updateVisualsForActive.

void updateVisualsForActive(boolean active, boolean animate, int duration, final Runnable onComplete) {
    final float finalAlpha = active ? mActiveAlpha : mInactiveAlpha;
    final float initAlpha = active ? mInactiveAlpha : mActiveAlpha;
    final float finalScale = active ? 1f : 1f / mActiveScale;
    final float initScale = mFramed.getScale();
    final int finalTextAlpha = active ? (int) (mActiveTextAlpha * 255) : (int) (mInactiveTextAlpha * 255);
    final int initTextAlpha = active ? (int) (mInactiveTextAlpha * 255) : (int) (mActiveTextAlpha * 255);
    int textColor = mTextColor;
    mUserName.setTextColor(textColor);
    if (animate && mTouched) {
        ValueAnimator va = ValueAnimator.ofFloat(0f, 1f);
        va.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float r = animation.getAnimatedFraction();
                float scale = (1 - r) * initScale + r * finalScale;
                float alpha = (1 - r) * initAlpha + r * finalAlpha;
                int textAlpha = (int) ((1 - r) * initTextAlpha + r * finalTextAlpha);
                mFramed.setScale(scale);
                mUserImage.setAlpha(alpha);
                mUserName.setTextColor(Color.argb(textAlpha, 255, 255, 255));
                mUserImage.invalidate();
            }
        });
        va.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                if (onComplete != null) {
                    onComplete.run();
                }
            }
        });
        va.setDuration(duration);
        va.start();
    } else {
        mFramed.setScale(finalScale);
        mUserImage.setAlpha(finalAlpha);
        mUserName.setTextColor(Color.argb(finalTextAlpha, 255, 255, 255));
        if (onComplete != null) {
            post(onComplete);
        }
    }
    mTouched = true;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 9 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by ParanoidAndroid.

the class KeyguardGlowStripView method makeEmGo.

public void makeEmGo() {
    if (mAnimator != null) {
        mAnimator.cancel();
    }
    float from = mLeftToRight ? 0f : 1f;
    float to = mLeftToRight ? 1f : 0f;
    mAnimator = ValueAnimator.ofFloat(from, to);
    mAnimator.setDuration(DURATION);
    mAnimator.setInterpolator(new LinearInterpolator());
    mAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mDrawDots = false;
            // make sure we draw one frame at the end with everything gone.
            invalidate();
        }

        @Override
        public void onAnimationStart(Animator animation) {
            mDrawDots = true;
        }
    });
    mAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mAnimationProgress = (Float) animation.getAnimatedValue();
            invalidate();
        }
    });
    mAnimator.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) LinearInterpolator(android.view.animation.LinearInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 10 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project MPAndroidChart by PhilJay.

the class PieRadarChartBase method spin.

/**
     * ################ ################ ################ ################
     */
/** CODE BELOW THIS RELATED TO ANIMATION */
/**
     * Applys a spin animation to the Chart.
     *
     * @param durationmillis
     * @param fromangle
     * @param toangle
     */
@SuppressLint("NewApi")
public void spin(int durationmillis, float fromangle, float toangle, Easing.EasingOption easing) {
    if (android.os.Build.VERSION.SDK_INT < 11)
        return;
    setRotationAngle(fromangle);
    ObjectAnimator spinAnimator = ObjectAnimator.ofFloat(this, "rotationAngle", fromangle, toangle);
    spinAnimator.setDuration(durationmillis);
    spinAnimator.setInterpolator(Easing.getEasingFunctionFromOption(easing));
    spinAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            postInvalidate();
        }
    });
    spinAnimator.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) SuppressLint(android.annotation.SuppressLint)

Aggregations

AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)94 ValueAnimator (android.animation.ValueAnimator)88 Animator (android.animation.Animator)65 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)62 ObjectAnimator (android.animation.ObjectAnimator)31 TimeInterpolator (android.animation.TimeInterpolator)14 View (android.view.View)13 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)12 Interpolator (android.view.animation.Interpolator)12 Resources (android.content.res.Resources)9 SuppressLint (android.annotation.SuppressLint)8 AnimatorSet (android.animation.AnimatorSet)7 Rect (android.graphics.Rect)7 ImageView (android.widget.ImageView)7 PropertyValuesHolder (android.animation.PropertyValuesHolder)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)6 Point (android.graphics.Point)6 PointF (android.graphics.PointF)6 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)6 TextView (android.widget.TextView)6