package com.jimulabs.mirrorsandbox;

import android.animation.Animator;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;

import java.util.Arrays;
import java.util.List;

/**
 * Created by lintonye on 14-12-16.
 */
public class AnimatorUtils {
    private static double sSpeed = 1;

    public synchronized static void setGlobalSpeed(double speed) {
        sSpeed = speed;
    }

    static synchronized long computeDuration(long duration1x) {
        return (long) (duration1x * 1/sSpeed);
    }

    public static MirrorAnimator together(Context context, MirrorAnimator... animators) {
        return together(context, Arrays.asList(animators));
    }

    public static MirrorAnimator sequence(Context context, MirrorAnimator... animators) {
        return sequence(context, Arrays.asList(animators));
    }

    public static MirrorAnimator together(Context context, List<MirrorAnimator> animators) {
        return new MirrorAnimatorSet(context, animators,
                MirrorAnimatorSet.Ordering.Together);
    }

    public static MirrorAnimator sequence(Context context, List<MirrorAnimator> animators) {
        return new MirrorAnimatorSet(context, animators,
                MirrorAnimatorSet.Ordering.Sequentially);
    }

    public static MirrorAnimator animator(Context context, Object target, String property, int... values) {
        ObjectAnimator animator = ObjectAnimator.ofInt(target, property, values);
        Keyframe firstFrame = Keyframe.ofInt(0, values[0]);
        Keyframe lastFrame = Keyframe.ofInt(0, values[values.length-1]);
        return new MirrorObjectAnimator(context, animator, firstFrame, lastFrame);
    }

    public static MirrorAnimator animator(Context context, Object target, String property, float... values) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(target, property, values);
        Keyframe firstFrame = Keyframe.ofFloat(0, values[0]);
        Keyframe lastFrame = Keyframe.ofFloat(0, values[values.length-1]);
        return new MirrorObjectAnimator(context, animator, firstFrame, lastFrame);
    }

    public static void setInterpolator(Context context, Animator animator, int resId) {
        Interpolator interpolator = AnimationUtils.loadInterpolator(context, resId);
        animator.setInterpolator(interpolator);
    }
}

@@ -692,32 +692,37 @@
 ontext context, 
+List%3C
 MirrorAnimator..
@@ -711,35 +711,33 @@
 t%3CMirrorAnimator
-...
+%3E
  animators) %7B%0A  
@@ -753,50 +753,101 @@
 urn 
-together(context, Arrays.asList(animators)
+new MirrorAnimatorSet(context, animators,%0A                MirrorAnimatorSet.Ordering.Together
 );%0A 
@@ -881,32 +881,32 @@
 rorAnimator 
-sequence
+together
 (Context con
@@ -957,24 +957,24 @@
  return 
-sequence
+together
 (context
@@ -1038,32 +1038,32 @@
 rorAnimator 
-together
+sequence
 (Context con
@@ -1198,32 +1198,36 @@
 et.Ordering.
-Together
+Sequentially
 );%0A    %7D%0A%0A  
@@ -1275,37 +1275,32 @@
 ontext context, 
-List%3C
 MirrorAnimator%3E 
@@ -1289,33 +1289,35 @@
 , MirrorAnimator
-%3E
+...
  animators) %7B%0A  
@@ -1333,105 +1333,50 @@
 urn 
-new MirrorAnimatorSet(context, animators,%0A                MirrorAnimatorSet.Ordering.Sequentially
+sequence(context, Arrays.asList(animators)
 );%0A 

Rearrange methods