New glance and widget views

Added ability to test if we're a widget or a watch-app. Added troubleshooting documentation.
This commit is contained in:
Philip Abbey
2023-12-21 11:37:30 +00:00
parent 4e739e918e
commit 3934ca53ba
61 changed files with 1074 additions and 540 deletions

View File

@ -24,19 +24,86 @@ using Toybox.Graphics;
(:glance)
class HomeAssistantGlanceView extends WatchUi.GlanceView {
private static const scLeftMargin = 20; // in pixels
private static const scLeftIndent = 10; // Left Indent "_text:" in pixels
private static const scMidSep = 10; // Middle Separator "text:_text" in pixels
private var mApp as HomeAssistantApp;
private var mTitle as WatchUi.Text or Null;
private var mApiText as WatchUi.Text or Null;
private var mApiStatus as WatchUi.Text or Null;
private var mMenuText as WatchUi.Text or Null;
private var mMenuStatus as WatchUi.Text or Null;
private var mText as Lang.String;
function initialize() {
function initialize(app as HomeAssistantApp) {
GlanceView.initialize();
mApp = app;
}
mText = WatchUi.loadResource($.Rez.Strings.AppName);
function onLayout(dc as Graphics.Dc) as Void {
var strChecking = WatchUi.loadResource($.Rez.Strings.Checking);
var strGlanceMenu = WatchUi.loadResource($.Rez.Strings.GlanceMenu);
var h = dc.getHeight();
var tw = dc.getTextWidthInPixels(strGlanceMenu, Graphics.FONT_XTINY);
mTitle = new WatchUi.Text({
:text => WatchUi.loadResource($.Rez.Strings.AppName),
:color => Graphics.COLOR_WHITE,
:font => Graphics.FONT_TINY,
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
:locX => scLeftMargin,
:locY => 1 * h / 6
});
mApiText = new WatchUi.Text({
:text => "API:",
:color => Graphics.COLOR_WHITE,
:font => Graphics.FONT_XTINY,
:justification => Graphics.TEXT_JUSTIFY_RIGHT | Graphics.TEXT_JUSTIFY_VCENTER,
:locX => scLeftMargin + scLeftIndent + tw,
:locY => 3 * h / 6
});
mApiStatus = new WatchUi.Text({
:text => strChecking,
:color => Graphics.COLOR_WHITE,
:font => Graphics.FONT_XTINY,
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
:locX => scLeftMargin + scLeftIndent + scMidSep + tw,
:locY => 3 * h / 6
});
mMenuText = new WatchUi.Text({
:text => strGlanceMenu + ":",
:color => Graphics.COLOR_WHITE,
:font => Graphics.FONT_XTINY,
:justification => Graphics.TEXT_JUSTIFY_RIGHT | Graphics.TEXT_JUSTIFY_VCENTER,
:locX => scLeftMargin + scLeftIndent + tw,
:locY => 5 * h / 6
});
mMenuStatus = new WatchUi.Text({
:text => strChecking,
:color => Graphics.COLOR_WHITE,
:font => Graphics.FONT_XTINY,
:justification => Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER,
:locX => scLeftMargin + scLeftIndent + scMidSep + tw,
:locY => 5 * h / 6
});
}
function onUpdate(dc) as Void {
GlanceView.onUpdate(dc);
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK);
dc.drawText(0, dc.getHeight() / 2, Graphics.FONT_TINY, mText, Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER);
if(dc has :setAntiAlias) {
dc.setAntiAlias(true);
}
dc.setColor(
Graphics.COLOR_WHITE,
Graphics.COLOR_BLUE
);
dc.clear();
mTitle.draw(dc);
mApiText.draw(dc);
mApiStatus.setText(mApp.getApiStatus());
mApiStatus.draw(dc);
mMenuText.draw(dc);
mMenuStatus.setText(mApp.getMenuStatus());
mMenuStatus.draw(dc);
}
}