Search in sources :

Example 16 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Xposed-Tinted-Status-Bar by MohammadAG.

the class ColourChangerMod method setNavigationBarTint.

@SuppressLint("NewApi")
private void setNavigationBarTint(final int tintColor, boolean force) {
    if (mNavigationBarView == null)
        return;
    if (mSettingsHelper.shouldLinkStatusBarAndNavBar() && !force) {
        log("Ignoring manual navigation bar color change cause we're linked");
        return;
    }
    log("Setting navigation bar color to " + tintColor);
    if (mSettingsHelper.animateStatusBarTintChange()) {
        int animateFrom = mLastSetColor == KITKAT_TRANSPARENT_COLOR ? Color.TRANSPARENT : mLastSetNavBarTint;
        int animateTo = tintColor == KITKAT_TRANSPARENT_COLOR ? Color.TRANSPARENT : tintColor;
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), animateFrom, animateTo);
        colorAnimation.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                mNavGradientDrawable.setColor((Integer) animator.getAnimatedValue());
            }
        });
        Utils.setViewBackground(mNavigationBarView, mNavGradientDrawable);
        colorAnimation.start();
    } else {
        mNavigationBarView.setAlpha(1f);
        if (tintColor == KITKAT_TRANSPARENT_COLOR) {
            Utils.setViewBackground(mNavigationBarView, mNavGradientDrawable);
            mNavGradientDrawable.setColor(Color.TRANSPARENT);
        } else {
            Utils.setViewBackground(mNavigationBarView, mNavGradientDrawable);
            mNavGradientDrawable.setColor(tintColor);
        }
    }
    mNavGradientDrawable.setMode(mSettingsHelper.getOverlayMode(), mSettingsHelper.getSemiTransparentOverlayOpacity());
    mNavGradientDrawable.setIsTransparentCauseOfKitKatApi(tintColor == KITKAT_TRANSPARENT_COLOR && mSettingsHelper.isLegacyGradientMode());
    if (mNavigationBarView != null && tintColor != KITKAT_TRANSPARENT_COLOR) {
        Intent intent = new Intent("gravitybox.intent.action.ACTION_NAVBAR_CHANGED");
        intent.putExtra("navbarBgColor", tintColor);
        intent.putExtra("navbarColorEnable", true);
        mNavigationBarView.getContext().sendBroadcast(intent);
    }
    mLastSetNavBarTint = tintColor;
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) Intent(android.content.Intent) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) SuppressLint(android.annotation.SuppressLint) Tint(com.mohammadag.colouredstatusbar.SettingsHelper.Tint) SuppressLint(android.annotation.SuppressLint)

Example 17 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Signal-Android by WhisperSystems.

the class Tweener method to.

@SuppressLint("NewApi")
public static Tweener to(Object object, long duration, Object... vars) {
    long delay = 0;
    AnimatorUpdateListener updateListener = null;
    AnimatorListener listener = null;
    TimeInterpolator interpolator = null;
    // Iterate through arguments and discover properties to animate
    ArrayList<PropertyValuesHolder> props = new ArrayList<PropertyValuesHolder>(vars.length / 2);
    for (int i = 0; i < vars.length; i += 2) {
        if (!(vars[i] instanceof String)) {
            throw new IllegalArgumentException("Key must be a string: " + vars[i]);
        }
        String key = (String) vars[i];
        Object value = vars[i + 1];
        if ("simultaneousTween".equals(key)) {
        // TODO
        } else if ("ease".equals(key)) {
            // TODO: multiple interpolators?
            interpolator = (TimeInterpolator) value;
        } else if ("onUpdate".equals(key) || "onUpdateListener".equals(key)) {
            updateListener = (AnimatorUpdateListener) value;
        } else if ("onComplete".equals(key) || "onCompleteListener".equals(key)) {
            listener = (AnimatorListener) value;
        } else if ("delay".equals(key)) {
            delay = ((Number) value).longValue();
        } else if ("syncWith".equals(key)) {
        // TODO
        } else if (value instanceof float[]) {
            props.add(PropertyValuesHolder.ofFloat(key, ((float[]) value)[0], ((float[]) value)[1]));
        } else if (value instanceof Number) {
            float floatValue = ((Number) value).floatValue();
            props.add(PropertyValuesHolder.ofFloat(key, floatValue));
        } else {
            throw new IllegalArgumentException("Bad argument for key \"" + key + "\" with value " + value.getClass());
        }
    }
    // Re-use existing tween, if present
    Tweener tween = sTweens.get(object);
    ObjectAnimator anim = null;
    if (tween == null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(object, props.toArray(new PropertyValuesHolder[props.size()]));
        tween = new Tweener(anim);
        sTweens.put(object, tween);
        if (DEBUG)
            Log.v(TAG, "Added new Tweener " + tween);
    } else {
        anim = sTweens.get(object).animator;
        // Cancel all animators for given object
        replace(props, object);
    }
    if (interpolator != null) {
        anim.setInterpolator(interpolator);
    }
    // Update animation with properties discovered in loop above
    anim.setStartDelay(delay);
    anim.setDuration(duration);
    if (updateListener != null) {
        // There should be only one
        anim.removeAllUpdateListeners();
        anim.addUpdateListener(updateListener);
    }
    if (listener != null) {
        // There should be only one.
        anim.removeAllListeners();
        anim.addListener(listener);
    }
    anim.addListener(mCleanupListener);
    anim.start();
    return tween;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) TimeInterpolator(android.animation.TimeInterpolator) SuppressLint(android.annotation.SuppressLint) AnimatorListener(android.animation.Animator.AnimatorListener) PropertyValuesHolder(android.animation.PropertyValuesHolder) SuppressLint(android.annotation.SuppressLint)

Example 18 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project Leonids by plattysoft.

the class ParticleSystem method startAnimator.

private void startAnimator(Interpolator interpolator, long animnationTime) {
    mAnimator = ValueAnimator.ofInt(0, (int) animnationTime);
    mAnimator.setDuration(animnationTime);
    mAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int miliseconds = (Integer) animation.getAnimatedValue();
            onUpdate(miliseconds);
        }
    });
    mAnimator.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

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

        @Override
        public void onAnimationCancel(Animator animation) {
            cleanupAnimation();
        }
    });
    mAnimator.setInterpolator(interpolator);
    mAnimator.start();
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 19 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project platform_frameworks_base by android.

the class VolumeDialogMotion method startShowAnimation.

private void startShowAnimation() {
    if (D.BUG)
        Log.d(TAG, "startShowAnimation");
    mDialogView.animate().translationY(0).setDuration(scaledDuration(300)).setInterpolator(new LogDecelerateInterpolator()).setListener(null).setUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            if (mChevronPositionAnimator == null)
                return;
            // reposition chevron
            final float v = (Float) mChevronPositionAnimator.getAnimatedValue();
            final int posY = chevronPosY();
            mChevron.setTranslationY(posY + v + -mDialogView.getTranslationY());
        }
    }).start();
    mContentsPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(400));
    mContentsPositionAnimator.addListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCancelled)
                return;
            if (D.BUG)
                Log.d(TAG, "show.onAnimationEnd");
            setShowing(false);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (D.BUG)
                Log.d(TAG, "show.onAnimationCancel");
            mCancelled = true;
        }
    });
    mContentsPositionAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float v = (Float) animation.getAnimatedValue();
            mContents.setTranslationY(v + -mDialogView.getTranslationY());
        }
    });
    mContentsPositionAnimator.setInterpolator(new LogDecelerateInterpolator());
    mContentsPositionAnimator.start();
    mContents.setAlpha(0);
    mContents.animate().alpha(1).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(0f, 0f, .2f, 1f)).start();
    mChevronPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(250));
    mChevronPositionAnimator.setInterpolator(new PathInterpolator(.4f, 0f, .2f, 1f));
    mChevronPositionAnimator.start();
    mChevron.setAlpha(0);
    mChevron.animate().alpha(1).setStartDelay(scaledDuration(50)).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(.4f, 0f, 1f, 1f)).start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) PathInterpolator(android.view.animation.PathInterpolator)

Example 20 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project platform_frameworks_base by android.

the class VolumeDialogMotion method startDismiss.

public void startDismiss(final Runnable onComplete) {
    if (D.BUG)
        Log.d(TAG, "startDismiss");
    if (mDismissing)
        return;
    setDismissing(true);
    if (mShowing) {
        mDialogView.animate().cancel();
        if (mContentsPositionAnimator != null) {
            mContentsPositionAnimator.cancel();
        }
        mContents.animate().cancel();
        if (mChevronPositionAnimator != null) {
            mChevronPositionAnimator.cancel();
        }
        mChevron.animate().cancel();
        setShowing(false);
    }
    mDialogView.animate().translationY(-mDialogView.getHeight()).setDuration(scaledDuration(250)).setInterpolator(new LogAccelerateInterpolator()).setUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mContents.setTranslationY(-mDialogView.getTranslationY());
            final int posY = chevronPosY();
            mChevron.setTranslationY(posY + -mDialogView.getTranslationY());
        }
    }).setListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCancelled)
                return;
            if (D.BUG)
                Log.d(TAG, "dismiss.onAnimationEnd");
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (D.BUG)
                        Log.d(TAG, "mDialog.dismiss()");
                    mDialog.dismiss();
                    onComplete.run();
                    setDismissing(false);
                }
            }, PRE_DISMISS_DELAY);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (D.BUG)
                Log.d(TAG, "dismiss.onAnimationCancel");
            mCancelled = true;
        }
    }).start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

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