package com.jld.vod.ui.animator

import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.content.Context
import android.os.Build
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import android.widget.RelativeLayout

/**
 * 播放动画
 */
class RatateRobotArm(context: Context?, discMagneticStripe: ImageView) {
    private var neddleObjectAnimator :ObjectAnimator?=null//机械臂动画
    private var discMagneticStripe: ImageView? =null
    var isSpin = false
        private set

    fun startSpin() {
        neddleObjectAnimator = ObjectAnimator.ofFloat(discMagneticStripe, "rotation", 0f, 25f)
        discMagneticStripe!!.setPivotX(0f)
        discMagneticStripe!!.setPivotY(0f)
        neddleObjectAnimator!!.setDuration(500)
        neddleObjectAnimator!!.setInterpolator( LinearInterpolator())
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (neddleObjectAnimator!!.isPaused) {
                neddleObjectAnimator!!.resume()
            } else {
                neddleObjectAnimator!!.start()
            }
        } else {
            neddleObjectAnimator!!.start()
        }
        isSpin = true
    }

    fun stopSpin() {
        neddleObjectAnimator = ObjectAnimator.ofFloat(discMagneticStripe, "rotation", 0f, 0f)
        discMagneticStripe!!.setPivotX(0f)
        discMagneticStripe!!.setPivotY(0f)
        neddleObjectAnimator!!.setDuration(500)
        neddleObjectAnimator!!.setInterpolator( LinearInterpolator())
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (neddleObjectAnimator!!.isPaused) {
                neddleObjectAnimator!!.resume()
            } else {
                neddleObjectAnimator!!.start()
            }
        } else {
            neddleObjectAnimator!!.start()
        }
    }

    init {
        this.discMagneticStripe = discMagneticStripe
        neddleObjectAnimator = ObjectAnimator.ofFloat(discMagneticStripe, "rotation", 0f, 25f)
        discMagneticStripe!!.setPivotX(0f)
        discMagneticStripe!!.setPivotY(0f)
        neddleObjectAnimator!!.setDuration(500)
        neddleObjectAnimator!!.setInterpolator( LinearInterpolator())
    }
}