How can i animate a line
on a canvas in WearOS
every 5 seconds?
I know that we have to use an AnimatorTask with a call to postInvalidate()
. However since I am directly drawing the line
on the canvas
, I do not have a View
object.
public class AnimatorTask extends TimerTask {
private WatchEventInfo eventInfo;
public AnimatorTask(WatchEventInfo eventInfo) {
this.eventInfo = eventInfo;
}
@Override
public void run() {
drawAndAnimate();
}
public WatchEventInfo getEventInfo() {
return eventInfo;
}
private void drawAndAnimate() {
Canvas canvas = eventInfo.getCanvas();
// For testing
canvas.drawLine(100, 100, 300, 300 markerPaint);
}
}
How do get access to the canvas.drawLine()
method object and notify the canvas
to redraw itself from the TimerTask
assuming that my TimerTask
exists in CanvasWatchFaceService
subclass?