0

I'm trying to add an animation to a watch face that I'm building in Android Studio and I'm facing some issues. I'm totally new to this type of programming so if I say something dumb please correct me.

First, I learned how to draw a layout in the face canvas like this:


inner class Engine : CanvasWatchFaceService.Engine() {
    private var myLayout: View? = null
    private var day: TextView? = null
    .
    .
    .
    override fun onDraw(canvas: Canvas, bounds: Rect) {
                day?.text = "TEST"
                myLayout?.measure(specW, specH)
                myLayout?.layout(0, 0, myLayout!!.getMeasuredWidth(), myLayout!!.getMeasuredHeight())
                canvas.drawColor(Color.BLUE)

                myLayout?.draw(canvas)
    }
}

And my onCreate looks like this:


override fun onCreate(holder: SurfaceHolder) {
            super.onCreate(holder)
            val inflater = getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
            myLayout = inflater.inflate(R.layout.main_layout, null)

            val display: Display = (getSystemService(WINDOW_SERVICE) as WindowManager)
                .defaultDisplay
            display.getSize(displaySize)

            specW = View.MeasureSpec.makeMeasureSpec(
                displaySize.x,
                View.MeasureSpec.EXACTLY
            )
            specH = View.MeasureSpec.makeMeasureSpec(
                displaySize.y,
                View.MeasureSpec.EXACTLY
            )

            day = myLayout?.findViewById<View>(R.id.day) as TextView

            aguAnimation = myLayout?.findViewById(R.id.agu) as ImageView
            aguAnimation.background = resources.getDrawable(R.drawable.agu_idle)
            animaDraw = aguAnimation.background as AnimationDrawable?
}

And I put the animaDraw.start() at the tap command:

override fun onTapCommand(tapType: Int, x: Int, y: Int, eventTime: Long) {
            when (tapType) {
                WatchFaceService.TAP_TYPE_TAP ->{
                    animaDraw!!.start()
                    Toast.makeText(applicationContext, R.string.message, Toast.LENGTH_SHORT)
                        .show()
                }
}

Everything looks fine for me, everything is being draw on the watch face... BUT the animation doesn't do anything, it stands still in its first frame.

Am I doing something wrong? Could someone help me?

OBS: The xml file is below.

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/agu_idle_1" android:duration="1000" />
    <item android:drawable="@drawable/agu_idle_2" android:duration="1000" />
    <item android:drawable="@drawable/agu_idle_3" android:duration="1000" />
</animation-list>
TofferJ
  • 4,678
  • 1
  • 37
  • 49
Blodht
  • 1
  • 1

0 Answers0