Search in sources :

Example 1 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder 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 2 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_frameworks_base by ParanoidAndroid.

the class KeyguardWidgetCarousel method animatePagesToCarousel.

void animatePagesToCarousel() {
    if (mChildrenTransformsAnimator != null) {
        mChildrenTransformsAnimator.cancel();
        mChildrenTransformsAnimator = null;
    }
    int count = getChildCount();
    PropertyValuesHolder alpha;
    PropertyValuesHolder outlineAlpha;
    PropertyValuesHolder rotationY;
    PropertyValuesHolder pivotX;
    PropertyValuesHolder pivotY;
    ArrayList<Animator> anims = new ArrayList<Animator>();
    for (int i = 0; i < count; i++) {
        KeyguardWidgetFrame child = getWidgetPageAt(i);
        float finalAlpha = getAlphaForPage(mScreenCenter, i, true);
        float finalOutlineAlpha = getOutlineAlphaForPage(mScreenCenter, i, true);
        getTransformForPage(mScreenCenter, i, mTmpTransform);
        boolean inVisibleRange = (i >= mCurrentPage - 1 && i <= mCurrentPage + 1);
        ObjectAnimator a;
        alpha = PropertyValuesHolder.ofFloat("contentAlpha", finalAlpha);
        outlineAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", finalOutlineAlpha);
        pivotX = PropertyValuesHolder.ofFloat("pivotX", mTmpTransform[0]);
        pivotY = PropertyValuesHolder.ofFloat("pivotY", mTmpTransform[1]);
        rotationY = PropertyValuesHolder.ofFloat("rotationY", mTmpTransform[2]);
        if (inVisibleRange) {
            // for the central pages we animate into a rotated state
            a = ObjectAnimator.ofPropertyValuesHolder(child, alpha, outlineAlpha, pivotX, pivotY, rotationY);
        } else {
            a = ObjectAnimator.ofPropertyValuesHolder(child, alpha, outlineAlpha);
            a.setInterpolator(mFastFadeInterpolator);
        }
        anims.add(a);
    }
    int duration = REORDERING_ZOOM_IN_OUT_DURATION;
    mChildrenTransformsAnimator = new AnimatorSet();
    mChildrenTransformsAnimator.playTogether(anims);
    mChildrenTransformsAnimator.setDuration(duration);
    mChildrenTransformsAnimator.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) PropertyValuesHolder(android.animation.PropertyValuesHolder) AnimatorSet(android.animation.AnimatorSet)

Example 3 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_frameworks_base by ParanoidAndroid.

the class KeyguardWidgetCarousel method animatePagesToNeutral.

void animatePagesToNeutral() {
    if (mChildrenTransformsAnimator != null) {
        mChildrenTransformsAnimator.cancel();
        mChildrenTransformsAnimator = null;
    }
    int count = getChildCount();
    PropertyValuesHolder alpha;
    PropertyValuesHolder outlineAlpha;
    PropertyValuesHolder rotationY;
    ArrayList<Animator> anims = new ArrayList<Animator>();
    for (int i = 0; i < count; i++) {
        KeyguardWidgetFrame child = getWidgetPageAt(i);
        boolean inVisibleRange = (i >= mCurrentPage - 1 && i <= mCurrentPage + 1);
        if (!inVisibleRange) {
            child.setRotationY(0f);
        }
        alpha = PropertyValuesHolder.ofFloat("contentAlpha", 1.0f);
        outlineAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", KeyguardWidgetFrame.OUTLINE_ALPHA_MULTIPLIER);
        rotationY = PropertyValuesHolder.ofFloat("rotationY", 0f);
        ObjectAnimator a = ObjectAnimator.ofPropertyValuesHolder(child, alpha, outlineAlpha, rotationY);
        child.setVisibility(VISIBLE);
        if (!inVisibleRange) {
            a.setInterpolator(mSlowFadeInterpolator);
        }
        anims.add(a);
    }
    int duration = REORDERING_ZOOM_IN_OUT_DURATION;
    mChildrenTransformsAnimator = new AnimatorSet();
    mChildrenTransformsAnimator.playTogether(anims);
    mChildrenTransformsAnimator.setDuration(duration);
    mChildrenTransformsAnimator.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) PropertyValuesHolder(android.animation.PropertyValuesHolder) AnimatorSet(android.animation.AnimatorSet)

Example 4 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_frameworks_base by ParanoidAndroid.

the class KeyguardWidgetPager method animateOutlinesAndSidePages.

void animateOutlinesAndSidePages(final boolean show, int duration) {
    if (mChildrenOutlineFadeAnimation != null) {
        mChildrenOutlineFadeAnimation.cancel();
        mChildrenOutlineFadeAnimation = null;
    }
    int count = getChildCount();
    PropertyValuesHolder alpha;
    ArrayList<Animator> anims = new ArrayList<Animator>();
    if (duration == -1) {
        duration = show ? CHILDREN_OUTLINE_FADE_IN_DURATION : CHILDREN_OUTLINE_FADE_OUT_DURATION;
    }
    int curPage = getNextPage();
    for (int i = 0; i < count; i++) {
        float finalContentAlpha;
        if (show) {
            finalContentAlpha = getAlphaForPage(mScreenCenter, i, true);
        } else if (!show && i == curPage) {
            finalContentAlpha = 1f;
        } else {
            finalContentAlpha = 0f;
        }
        KeyguardWidgetFrame child = getWidgetPageAt(i);
        alpha = PropertyValuesHolder.ofFloat("contentAlpha", finalContentAlpha);
        ObjectAnimator a = ObjectAnimator.ofPropertyValuesHolder(child, alpha);
        anims.add(a);
        float finalOutlineAlpha = show ? getOutlineAlphaForPage(mScreenCenter, i, true) : 0f;
        child.fadeFrame(this, show, finalOutlineAlpha, duration);
    }
    mChildrenOutlineFadeAnimation = new AnimatorSet();
    mChildrenOutlineFadeAnimation.playTogether(anims);
    mChildrenOutlineFadeAnimation.setDuration(duration);
    mChildrenOutlineFadeAnimation.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            if (show) {
                enablePageContentLayers();
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!show) {
                disablePageContentLayers();
                KeyguardWidgetFrame frame = getWidgetPageAt(mWidgetToResetAfterFadeOut);
                if (frame != null && !(frame == getWidgetPageAt(mCurrentPage) && mViewStateManager.isChallengeOverlapping())) {
                    frame.resetSize();
                }
                mWidgetToResetAfterFadeOut = -1;
                mShowingInitialHints = false;
            }
            updateWidgetFramesImportantForAccessibility();
        }
    });
    mChildrenOutlineFadeAnimation.start();
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ArrayList(java.util.ArrayList) PropertyValuesHolder(android.animation.PropertyValuesHolder) AnimatorSet(android.animation.AnimatorSet)

Example 5 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project UltimateAndroid by cymcsg.

the class AnimationUtils method leftRightShake.

/**
     * Shake the view from left to right
     *
     * @param view
     * @return
     */
public static ObjectAnimator leftRightShake(View view) {
    // int delta = view.getResources().getDimensionPixelOffset(R.dimen.spacing_medium);
    int delta = 40;
    PropertyValuesHolder pvhTranslateX = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X, Keyframe.ofFloat(0f, 0), Keyframe.ofFloat(.10f, -delta), Keyframe.ofFloat(.26f, delta), Keyframe.ofFloat(.42f, -delta), Keyframe.ofFloat(.58f, delta), Keyframe.ofFloat(.74f, -delta), Keyframe.ofFloat(.90f, delta), Keyframe.ofFloat(1f, 0f));
    return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX).setDuration(500);
}
Also used : PropertyValuesHolder(android.animation.PropertyValuesHolder)

Aggregations

PropertyValuesHolder (android.animation.PropertyValuesHolder)244 ObjectAnimator (android.animation.ObjectAnimator)170 Animator (android.animation.Animator)112 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)74 ValueAnimator (android.animation.ValueAnimator)72 Paint (android.graphics.Paint)38 AnimatorSet (android.animation.AnimatorSet)28 LinearInterpolator (android.view.animation.LinearInterpolator)25 ArrayList (java.util.ArrayList)25 Keyframe (android.animation.Keyframe)17 ViewGroup (android.view.ViewGroup)17 Interpolator (android.view.animation.Interpolator)16 View (android.view.View)15 NonNull (androidx.annotation.NonNull)14 Point (android.graphics.Point)12 IntEvaluator (android.animation.IntEvaluator)11 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)11 TimeAnimator (android.animation.TimeAnimator)10 Path (android.graphics.Path)10 NonNull (android.support.annotation.NonNull)9