Search in sources :

Example 1 with AnimatorListener

use of android.animation.Animator.AnimatorListener 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 AnimatorListener

use of android.animation.Animator.AnimatorListener 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 3 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project android-tooltips by rharter.

the class ToolTipLayout method dismiss.

/**
     * Dismisses all tooltips currently being displayed.
     *
     * @param animate True to animate the transition.
     */
public void dismiss(boolean animate) {
    mToolTips.clear();
    if (animate) {
        final List<View> viewsToRemove = new ArrayList<>();
        List<Animator> a = new ArrayList<>();
        for (int i = 0; i < getChildCount(); i++) {
            a.add(ObjectAnimator.ofFloat(getChildAt(i), View.ALPHA, 0));
            viewsToRemove.add(getChildAt(i));
        }
        AnimatorSet s = new AnimatorSet();
        s.playTogether(a);
        s.addListener(new AnimatorListener() {

            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                for (View v : viewsToRemove) {
                    removeView(v);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        s.start();
    } else {
        removeAllViews();
    }
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) View(android.view.View)

Example 4 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project android-different-loading-animations by raweng.

the class AllAnimation method windowsAnimation.

public void windowsAnimation() {
    final ValueAnimator valueTvOne_x = ObjectAnimator.ofFloat(windowsTvOne, "x", windowsTvOne.getX() - 40, windowsTvOne.getX() - 50, (screenWidth / 2) + 10f, (screenWidth / 2) + 25f, //,(screenWidth / 2)+55f//,(screenWidth / 2)+80f//,(screenWidth/2 )+25f,(screenWidth / 2) +30f//, (screenWidth / 2)+35f,(screenWidth / 2)+40f,(screenWidth / 2)+45f //,(screenWidth / 2)+6.6f,(screenWidth / 2)+7.7f,(screenWidth / 2)+8.8f //, (screenWidth / 2)+9,(screenWidth / 2)+10,
    (screenWidth / 2) + 50f, screenWidth * .92f, screenWidth + 5);
    valueTvOne_x.setDuration(5200);
    valueTvOne_x.setRepeatCount(0);
    valueTvOne_x.setRepeatMode(ValueAnimator.REVERSE);
    valueTvOne_x.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
            windowsTvOne.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }
    });
    final ValueAnimator valueTvTwo_x = //, (screenWidth / 2.1f) +55f//, (screenWidth / 2.1f) +80f//, (screenWidth / 2.1f) +25f,(screenWidth / 2.1f) +30f
    ObjectAnimator.ofFloat(//, (screenWidth / 2.1f) +55f//, (screenWidth / 2.1f) +80f//, (screenWidth / 2.1f) +25f,(screenWidth / 2.1f) +30f
    windowsTvTwo, //, (screenWidth / 2.1f) +55f//, (screenWidth / 2.1f) +80f//, (screenWidth / 2.1f) +25f,(screenWidth / 2.1f) +30f
    "x", //, (screenWidth / 2.1f) +55f//, (screenWidth / 2.1f) +80f//, (screenWidth / 2.1f) +25f,(screenWidth / 2.1f) +30f
    windowsTvTwo.getX() - 50, //, (screenWidth / 2.1f) +55f//, (screenWidth / 2.1f) +80f//, (screenWidth / 2.1f) +25f,(screenWidth / 2.1f) +30f
    (screenWidth / 2.1f) + 10f, //, (screenWidth / 2.1f) +55f//, (screenWidth / 2.1f) +80f//, (screenWidth / 2.1f) +25f,(screenWidth / 2.1f) +30f
    (screenWidth / 2.1f) + 25f, //, (screenWidth / 2.1f) +55f//, (screenWidth / 2.1f) +80f//, (screenWidth / 2.1f) +25f,(screenWidth / 2.1f) +30f
    (screenWidth / 2.1f) + 50f, screenWidth * .94f, screenWidth + 5);
    valueTvTwo_x.setDuration(6000);
    valueTvTwo_x.setRepeatCount(0);
    valueTvTwo_x.setStartDelay(200);
    valueTvTwo_x.setRepeatMode(ValueAnimator.REVERSE);
    valueTvTwo_x.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
            windowsTvTwo.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }
    });
    final ValueAnimator valueTvThree_x = //,(screenWidth / 2.2f) +55f//,(screenWidth / 2.2f) +80f//,(screenWidth / 2.2f) +25f,(screenWidth / 2.2f) +30f
    ObjectAnimator.ofFloat(//,(screenWidth / 2.2f) +55f//,(screenWidth / 2.2f) +80f//,(screenWidth / 2.2f) +25f,(screenWidth / 2.2f) +30f
    windowsTvThree, //,(screenWidth / 2.2f) +55f//,(screenWidth / 2.2f) +80f//,(screenWidth / 2.2f) +25f,(screenWidth / 2.2f) +30f
    "x", //,(screenWidth / 2.2f) +55f//,(screenWidth / 2.2f) +80f//,(screenWidth / 2.2f) +25f,(screenWidth / 2.2f) +30f
    windowsTvThree.getX() - 50, //,(screenWidth / 2.2f) +55f//,(screenWidth / 2.2f) +80f//,(screenWidth / 2.2f) +25f,(screenWidth / 2.2f) +30f
    (screenWidth / 2.2f) + 10f, //,(screenWidth / 2.2f) +55f//,(screenWidth / 2.2f) +80f//,(screenWidth / 2.2f) +25f,(screenWidth / 2.2f) +30f
    (screenWidth / 2.2f) + 25f, //,(screenWidth / 2.2f) +55f//,(screenWidth / 2.2f) +80f//,(screenWidth / 2.2f) +25f,(screenWidth / 2.2f) +30f
    (screenWidth / 2.2f) + 50f, screenWidth * .94f, screenWidth + 5);
    valueTvThree_x.setDuration(6500);
    valueTvThree_x.setRepeatCount(0);
    valueTvTwo_x.setStartDelay(500);
    valueTvThree_x.setRepeatMode(ValueAnimator.REVERSE);
    valueTvThree_x.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
            windowsTvThree.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }
    });
    windowsAnimatorSet = new AnimatorSet();
    windowsAnimatorSet.playTogether(valueTvTwo_x, valueTvThree_x, valueTvOne_x);
    windowsAnimatorSet.start();
    windowsAnimatorSet.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            windowsAnimatorSet.start();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }
    });
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator)

Example 5 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project android-app by spark.

the class Pin method animateYourself.

public void animateYourself() {
    final ViewGroup parent = (ViewGroup) view.getParent();
    if (pinBackgroundAnim != null) {
        pinBackgroundAnim.end();
        pinBackgroundAnim = null;
    }
    pinBackgroundAnim = (ObjectAnimator) AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_start);
    pinBackgroundAnim.setTarget(parent);
    pinBackgroundAnim.setEvaluator(new ArgbEvaluator());
    pinBackgroundAnim.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        // NO OP
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            endAnimation = getCancelAnimator();
            endAnimation.start();
        }
    });
    pinBackgroundAnim.start();
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ViewGroup(android.view.ViewGroup) ArgbEvaluator(android.animation.ArgbEvaluator)

Aggregations

AnimatorListener (android.animation.Animator.AnimatorListener)32 ObjectAnimator (android.animation.ObjectAnimator)25 Animator (android.animation.Animator)24 AnimatorSet (android.animation.AnimatorSet)10 ValueAnimator (android.animation.ValueAnimator)8 View (android.view.View)8 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 BaseItemAnimator (com.dk.animation.effect.BaseItemAnimator)6 SegmentAnimator (com.dk.animation.effect.SegmentAnimator)6 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)5 Intent (android.content.Intent)5 ArrayList (java.util.ArrayList)4 PropertyValuesHolder (android.animation.PropertyValuesHolder)3 TimeInterpolator (android.animation.TimeInterpolator)3 ArgbEvaluator (android.animation.ArgbEvaluator)2 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)2 Comparator (java.util.Comparator)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1