Sub SetBorderColorAnimated(lblview As Label, duration As Long, toColor As Int)
Dim jo As JavaObject = lblview
' Create a Drawable with a border
Dim initialColor As Int = xui.Color_Transparent ' Default starting color
borderDrawable.InitializeNewInstance("android.graphics.drawable.GradientDrawable", Null)
borderDrawable.RunMethod("setShape", Array(0)) ' 0 = RECTANGLE
borderDrawable.RunMethod("setStroke", Array(5dip, initialColor)) ' 5dip border width, initial color
jo.RunMethod("setBackground", Array(borderDrawable))
' Use JavaObject to call the static ValueAnimator.ofArgb method
Dim clrs(2) As Int
clrs(0) = initialColor
clrs(1) = toColor
Dim animator As JavaObject
animator.InitializeStatic("android.animation.ValueAnimator")
animator = animator.RunMethod("ofArgb", Array As Object(clrs))
animator.RunMethod("setDuration", Array As Object(duration))
' Use CreateEvent to define the AnimatorUpdateListener
' Pass the `borderDrawable` JavaObject directly as the "Tag"
Dim wrapper As JavaObject
wrapper = animator.CreateEvent("android.animation.ValueAnimator.AnimatorUpdateListener", "AnimationUpdate", borderDrawable)
animator.RunMethod("addUpdateListener", Array(wrapper))
' Start the animation
animator.RunMethod("start", Null)
End Sub
' Handle the animation update in the Sub below
Sub AnimationUpdate_Event (Tag As Object, Args() As Object) As Object
Dim valueAnimator As JavaObject = Args(0) ' Get the ValueAnimator object
Dim animValue As Int = valueAnimator.RunMethod("getAnimatedValue", Null) ' Extract the animated value
' Update the border color
borderDrawable.RunMethod("setStroke", Array(5dip, animValue))
End Sub