I try to add a glance view in the WebRequest SDK sample.
I want to display the received data in the glance view.
The glance view is showing up but the message string in the view is never updated.
But the System.println("message: "+_message); in the onReceive function does print the correct message.
I have tried it with multiple devices in the simulator but somehow it displays always the initial "123" message string.
I have read that the device needs to have liveUpdates true like the fenix6pro.
But it does also not work in the fenix6pro simulator.
Can someone tell me what I do wrong?
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
(:glance)
class WidgetGlanceView extends Ui.GlanceView {
hidden var _message as String = "123";
function initialize() {
WatchUi.GlanceView.initialize();
}
function onUpdate(dc) {
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK);
dc.clear();
dc.drawText(dc.getWidth() / 2, dc.getHeight() / 2, Graphics.FONT_MEDIUM, _message, Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
//dc.drawRectangle(0, 0, dc.getWidth(), dc.getHeight());
}
//! Show the result or status of the web request
//! @param args Data from the web request, or error message
public function onReceive(args as Dictionary or String or Null) as Void {
System.println("onReceiveGlanceView");
System.println("args "+args);
if (args instanceof String) {
_message = args;
System.println("args1 "+args);
} else if (args instanceof Dictionary) {
// Print the arguments duplicated and returned by jsonplaceholder.typicode.com
var keys = args.keys();
System.println("args2 "+args);
for (var i = 0; i < keys.size(); i++) {
//_message += Lang.format("$1$: $2$\n", [keys[i], args[keys[i]]]);
_message += Lang.format("$1$: $2$", [keys[i], args[keys[i]]]);
}
}
System.println("message: "+_message);
Ui.requestUpdate();
}
}//
// Copyright 2015-2021 by Garmin Ltd. or its subsidiaries.
// Subject to Garmin SDK License Agreement and Wearables
// Application Developer Agreement.
//
import Toybox.Application;
import Toybox.Lang;
import Toybox.WatchUi;
//! This app demonstrates how to make web requests through GCM.
class WebRequestApp extends Application.AppBase {
//! Constructor
public function initialize() {
AppBase.initialize();
}
//! Handle app startup
//! @param state Startup arguments
public function onStart(state as Dictionary?) as Void {
}
//! Handle app shutdown
//! @param state Shutdown arguments
public function onStop(state as Dictionary?) as Void {
}
(:glance)
function getGlanceView() {
var view = new $.WidgetGlanceView();
var delegate = new $.WebRequestDelegate(view.method(:onReceive));
return [ new WidgetGlanceView() ];
}
//! Return the initial view for the app
//! @return Array Pair [View, Delegate]
public function getInitialView() as Array<Views or InputDelegates>? {
var view = new $.WebRequestView();
var delegate = new $.WebRequestDelegate(view.method(:onReceive));
return [view, delegate] as Array<Views or InputDelegates>;
}
}