companion object {
/**
* Animation collection playback mode 1
*/
fun buttonAnimator (btn: View) {
var animator = ObjectAnimator.ofFloat( btn_pay , "button" , 100f , 80f , 100f ) // If there is no attribute, it is equivalent to valueAnimator, similar to
animator. duration = 300
animator.addUpdateListener { animation ->
run {
// var fraction = animation.animatedFraction
var value: Float = animation.animatedValue as Float
btn.alpha = value / 100
btn.scaleX = value / 100
btn.scaleY = value / 100
}
}
animator.start()
}
/**
* Animation collection playback mode 2
*/
fun viewAnimator (btn: View) {
var animator = ValueAnimator.ofFloat( 100f , 80f , 100f )
animator.duration = 300
animator.addUpdateListener { animation ->
run {
// var fraction = animation.animatedFraction
var value: Float = animation.animatedValue as Float
btn.alpha = value / 100
btn.scaleX = value / 100
btn.scaleY = value / 100
}
}
animator.start()
}
/**
* Animation collection playback mode three
*/
fun viewPropertyAnimator (view: View) {
var PropertyValues1 = PropertyValuesHolder.ofFloat( "alpha" , 1f , 0.5f , 1f )
val PropertyValues2 = PropertyValuesHolder.ofFloat( "scaleX" , 1f , 0.5f , 1f )
val PropertyValues3 = PropertyValuesHolder.ofFloat( "scaleY" , 1f , 0.5f , 1f )
varanimator = ObjectAnimator.ofPropertyValuesHolder(view, PropertyValues1, PropertyValues2, PropertyValues3)
animator.duration = 300
animator.start()
}
/**
* Animation set playback mode four
*/
fun viewSetAnimator (view: View) {
val animator1 = ObjectAnimator.ofFloat(view , "alpha" , 1f , 0.5f , 1f )
val animator2 = ObjectAnimator.ofFloat(view , "scaleX " , 1f , 0.5f , 1f )
val animator3 = ObjectAnimator.ofFloat(view , "scaleY" , 1f , 0.5f , 1f )
varanimatorSet = AnimatorSet()
animatorSet.duration = 300
animatorSet.playTogether(animator1, animator2, animator3)
animatorSet.start()
}
fun vibratorAnimator
(view: View) {
var
animator = ObjectAnimator.ofFloat(view
, "translationX" ,
-
100f , 0f , 100f , 0f
) animator.duration = 500 animator.start() Vibrate ( view.context as Activity , 500 ) } /** * final Activity activity : The Activity instance that calls this method long milliseconds : The duration of the vibration, in milliseconds * long[] pattern : Custom vibration mode. The meanings of the numbers in the array are [ Station duration, Vibration duration, Still duration, Vibration duration. . . ]The unit of duration is milliseconds * boolean isRepeat : whether to vibrate repeatedly, if it is true , vibrate repeatedly, if it is false , only vibrate once */ private fun Vibrate (activity: Activity , milliseconds: Long) { val vib = activity.getSystemService(Service .VIBRATOR_SERVICE ) as Vibrator vib.vibrate (milliseconds) } private fun Vibrate (activity: Activity , pattern: LongArray , isRepeat: Boolean) { val vib = activity.getSystemService(Service.VIBRATOR_SERVICE ) as Vibrator vib.vibrate (pattern , if
(isRepeat)
1 else
-
1
) }