Search in sources :

Example 1 with ValueAnimator

use of android.animation.ValueAnimator in project qksms by moezbhatti.

the class ThemeManager method setTheme.

public static void setTheme(Theme theme) {
    final int startColor = mBackgroundColor;
    initializeTheme(theme);
    final int endColor = mBackgroundColor;
    if (startColor != endColor) {
        ValueAnimator backgroundAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor);
        backgroundAnimation.setDuration(TRANSITION_LENGTH);
        backgroundAnimation.addUpdateListener(animation -> {
            mBackgroundColor = (Integer) animation.getAnimatedValue();
            LiveViewManager.refreshViews(QKPreference.BACKGROUND);
        });
        backgroundAnimation.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                mBackgroundColor = endColor;
                LiveViewManager.refreshViews(QKPreference.BACKGROUND);
                WidgetProvider.notifyThemeChanged(mContext);
            }
        });
        backgroundAnimation.start();
    } else {
        LiveViewManager.refreshViews(QKPreference.BACKGROUND);
        WidgetProvider.notifyThemeChanged(mContext);
    }
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ArgbEvaluator(android.animation.ArgbEvaluator) ValueAnimator(android.animation.ValueAnimator)

Example 2 with ValueAnimator

use of android.animation.ValueAnimator in project lottie-android by airbnb.

the class AnimationFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_animation, container, false);
    ButterKnife.bind(this, view);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_back);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getFragmentManager().popBackStack();
        }
    });
    postUpdatePlayButtonText();
    onLoopChanged();
    animationView.addAnimatorListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
            startRecordingDroppedFrames();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            recordDroppedFrames();
            postUpdatePlayButtonText();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            postUpdatePlayButtonText();
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            recordDroppedFrames();
            startRecordingDroppedFrames();
        }
    });
    animationView.addAnimatorUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            seekBar.setProgress((int) (animation.getAnimatedFraction() * 100));
        }
    });
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (!animationView.isAnimating()) {
                animationView.setProgress(progress / 100f);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    return view;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) SeekBar(android.widget.SeekBar) AppCompatSeekBar(android.support.v7.widget.AppCompatSeekBar) AppCompatActivity(android.support.v7.app.AppCompatActivity) ValueAnimator(android.animation.ValueAnimator) LottieAnimationView(com.airbnb.lottie.LottieAnimationView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable)

Example 3 with ValueAnimator

use of android.animation.ValueAnimator 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 4 with ValueAnimator

use of android.animation.ValueAnimator 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 5 with ValueAnimator

use of android.animation.ValueAnimator 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)

Aggregations

ValueAnimator (android.animation.ValueAnimator)1224 Animator (android.animation.Animator)625 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)455 ObjectAnimator (android.animation.ObjectAnimator)187 ArrayList (java.util.ArrayList)128 Paint (android.graphics.Paint)124 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)111 LinearInterpolator (android.view.animation.LinearInterpolator)102 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)91 View (android.view.View)90 AnimatorSet (android.animation.AnimatorSet)87 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)74 ArgbEvaluator (android.animation.ArgbEvaluator)57 ViewGroup (android.view.ViewGroup)44 TextView (android.widget.TextView)44 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)40 PropertyValuesHolder (android.animation.PropertyValuesHolder)36 ImageView (android.widget.ImageView)34 Interpolator (android.view.animation.Interpolator)31 SuppressLint (android.annotation.SuppressLint)25