get Rotate Animators - Android android.animation

Android examples for android.animation:Animator

Description

get Rotate Animators

Demo Code


//package com.java2s;
import android.animation.Animator;

import android.animation.ObjectAnimator;

import android.support.annotation.NonNull;

import android.view.View;

import android.view.animation.Animation;

import java.util.ArrayList;

public class Main {
    @NonNull/*from   w  w  w  .  j  a  va  2 s.  c  o m*/
    @SafeVarargs
    public static ArrayList<Animator> getRotateAnimators(long duration,
            int repeatCount, ArrayList<View>... items) {
        final ArrayList<Animator> animators = new ArrayList<>();
        if (items != null && items.length > 0) {
            for (ArrayList<View> item : items) {
                if (item != null) {
                    for (View view : item) {
                        animators.add(getRotateAnimator(view, duration,
                                repeatCount));
                    }
                }
            }
        }
        return animators;
    }

    @NonNull
    public static ObjectAnimator getRotateAnimator(View view,
            long duration, int repeatCount) {
        final ObjectAnimator rotate = ObjectAnimator.ofFloat(view,
                "rotation", 0, 360);
        rotate.setDuration(duration);
        rotate.setRepeatCount(repeatCount);
        rotate.setRepeatMode(Animation.INFINITE);
        return rotate;
    }
}

Related Tutorials