For my first device (watch) app, I would like to display some data in my view. As an example, I enabled Position on start of the app and defined the onPosition() method:
class MyApp extends Application.AppBase {
...
var myView;
// onStart() is called on application start up
function onStart(state) {
Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));
}
function onPosition(info) {
var pos = info.position.toDegrees();
myView.updatePosition(pos[1], myView.findDrawableById("PositionLayer"));
}
...
}
where updatePosition(pos,layer) is a method of myView. As you can see, I try to access the layer "PositionLayer" which I added in onLayout(dc). Then in this updatePosition method, I would like to update the position data like this:
class MyView extends Ui.View {
...
function onLayout(dc) {
var positionLayer = new Ui.Layer({:locX=>22, :locY=>60, :width=>120, :height=>20, :identifier=>"PositionLayer"});
addLayer(positionLayer);
}
function updatePosition(pos, lay) {
var dc = lay.getDc();
dc.setColor(foregroundColor, backgroundColor);
dc.drawText(0, 0, Gfx.FONT_XTINY, position.format("%d"), Gfx.TEXT_JUSTIFY_LEFT);
}
...
}
Apparently, myView.findDrawableById("PositionLayer") does not work. I guess that a layer is not a drawable. However, I wonder, why there is the possibility of adding an identifier to a layer, if it cannot be accessed.
So my question is, how shall I update the PositionLayer appropriately? Probably, Ui.requestUpdate() might be suited in general but this obviously does not transfer the new position data. Is there a better way for this? Shall I simply use drawables instead of layers?