From 79b3bc6c21bed57c7e9245c95cb68a3fd9e1c979 Mon Sep 17 00:00:00 2001 From: SomeoneOnEarth Date: Fri, 1 Dec 2023 15:36:05 +0100 Subject: [PATCH] Quick and dirty widget/glance implementation --- manifest.xml | 327 ++++++++++++------------------ source/HomeAssistantApp.mc | 64 +++--- source/HomeAssistantGlanceView.mc | 46 +++++ 3 files changed, 217 insertions(+), 220 deletions(-) create mode 100644 source/HomeAssistantGlanceView.mc diff --git a/manifest.xml b/manifest.xml index 6c011ed..1570e30 100644 --- a/manifest.xml +++ b/manifest.xml @@ -11,17 +11,17 @@ P A Abbey & J D Abbey, 31 October 2023 - Test Application id="98c36259-498a-4458-9cef-74a273ad2bc3" - Live Application id="40131e87-31ff-454b-a8e2-92276ee399d6" + Widget/Glance App id="bf69be91-5833-4d96-92ea-c5f1a9db5dcc" + Test Application id="98c36259-498a-4458-9cef-74a273ad2bc3" + Live Application id="40131e87-31ff-454b-a8e2-92276ee399d6" --> - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ara - bul - zhs - zht - hrv - ces - dan - dut - deu - gre - eng - est - fin - fre - heb - hun - ind - ita - jpn - kor - lav - lit - zsm - nob - pol - por - slo - ron - - slv - spa - swe - tha - tur - ukr - vie - - - - - \ No newline at end of file + + + diff --git a/source/HomeAssistantApp.mc b/source/HomeAssistantApp.mc index dc1651f..cfbc9e8 100644 --- a/source/HomeAssistantApp.mc +++ b/source/HomeAssistantApp.mc @@ -24,24 +24,37 @@ using Toybox.WatchUi; using Toybox.Application.Properties; class HomeAssistantApp extends Application.AppBase { - private var mHaMenu; - private var quitTimer as QuitTimer; - private var strNoApiKey as Lang.String; - private var strNoApiUrl as Lang.String; - private var strNoConfigUrl as Lang.String; - private var strNoPhone as Lang.String; - private var strNoInternet as Lang.String; - private var strNoResponse as Lang.String; - private var strNoMenu as Lang.String; - private var strApiFlood as Lang.String; - private var strConfigUrlNotFound as Lang.String; - private var strUnhandledHttpErr as Lang.String; - private var strTrailingSlashErr as Lang.String; + private var mHaMenu as HomeAssistantView or Null; + private var quitTimer as QuitTimer or Null; + private var strNoApiKey as Lang.String or Null; + private var strNoApiUrl as Lang.String or Null; + private var strNoConfigUrl as Lang.String or Null; + private var strNoPhone as Lang.String or Null; + private var strNoInternet as Lang.String or Null; + private var strNoResponse as Lang.String or Null; + private var strNoMenu as Lang.String or Null; + private var strApiFlood as Lang.String or Null; + private var strConfigUrlNotFound as Lang.String or Null; + private var strUnhandledHttpErr as Lang.String or Null; + private var strTrailingSlashErr as Lang.String or Null; private var mItemsToUpdate; // Array initialised by onReturnFetchMenuConfig() private var mNextItemToUpdate = 0; // Index into the above array function initialize() { AppBase.initialize(); + } + + // onStart() is called on application start up + function onStart(state as Lang.Dictionary?) as Void { + } + + // onStop() is called when your application is exiting + function onStop(state as Lang.Dictionary?) as Void { + } + + // Return the initial view of your application here + function getInitialView() as Lang.Array? { + strNoApiKey = WatchUi.loadResource($.Rez.Strings.NoAPIKey); strNoApiUrl = WatchUi.loadResource($.Rez.Strings.NoApiUrl); strNoConfigUrl = WatchUi.loadResource($.Rez.Strings.NoConfigUrl); @@ -54,20 +67,7 @@ class HomeAssistantApp extends Application.AppBase { strUnhandledHttpErr = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr); strTrailingSlashErr = WatchUi.loadResource($.Rez.Strings.TrailingSlashErr); quitTimer = new QuitTimer(); - } - // onStart() is called on application start up - function onStart(state as Lang.Dictionary?) as Void { - quitTimer.begin(); - } - - // onStop() is called when your application is exiting - function onStop(state as Lang.Dictionary?) as Void { - quitTimer.stop(); - } - - // Return the initial view of your application here - function getInitialView() as Lang.Array? { var api_url = Properties.getValue("api_url") as Lang.String; if ((Properties.getValue("api_key") as Lang.String).length() == 0) { @@ -100,6 +100,11 @@ class HomeAssistantApp extends Application.AppBase { System.println("HomeAssistantApp fetchMenuConfig(): No Internet connection, skipping API call."); } return [new ErrorView(strNoInternet + "."), new ErrorDelegate()] as Lang.Array; + }else if (mHaMenu != null ){ + // App.getApp().launchInitialView(); + return [mHaMenu, new WatchUi.BehaviorDelegate()] as Lang.Array; + // return mHaMenu.View; + // WatchUi.pushView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE); } else { fetchMenuConfig(); return [new WatchUi.View(), new WatchUi.BehaviorDelegate()] as Lang.Array; @@ -138,7 +143,8 @@ class HomeAssistantApp extends Application.AppBase { WatchUi.pushView(new ErrorView(strConfigUrlNotFound), new ErrorDelegate(), WatchUi.SLIDE_UP); } else if (responseCode == 200) { mHaMenu = new HomeAssistantView(data, null); - WatchUi.switchToView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE); + quitTimer.begin(); + WatchUi.pushView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE); mItemsToUpdate = mHaMenu.getItemsToUpdate(); // Start the continuous update process that continues for as long as the application is running. // The chain of functions from 'updateNextMenuItem()' calls 'updateNextMenuItem()' on completion. @@ -183,6 +189,10 @@ class HomeAssistantApp extends Application.AppBase { return quitTimer; } + (:glance) + function getGlanceView() { + return [new HomeAssistantGlanceView()]; + } } function getApp() as HomeAssistantApp { diff --git a/source/HomeAssistantGlanceView.mc b/source/HomeAssistantGlanceView.mc new file mode 100644 index 0000000..9d2237e --- /dev/null +++ b/source/HomeAssistantGlanceView.mc @@ -0,0 +1,46 @@ +//----------------------------------------------------------------------------------- +// +// Distributed under MIT Licence +// See https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/LICENSE. +// +//----------------------------------------------------------------------------------- +// +// GarminHomeAssistant is a Garmin IQ application written in Monkey C and routinely +// tested on a Venu 2 device. The source code is provided at: +// https://github.com/house-of-abbey/GarminHomeAssistant. +// +// P A Abbey & J D Abbey & SomeoneOnEarth, 23 November 2023 +// +// +// Description: +// +// Application root for GarminHomeAssistant +// +//----------------------------------------------------------------------------------- + +import Toybox.WatchUi; +import Toybox.Graphics; + +(:glance) +class HomeAssistantGlanceView extends WatchUi.GlanceView { + + function initialize() { + GlanceView.initialize(); + } + + function onShow() { + } + + function onHide() { + } + + function onUpdate(dc) { + GlanceView.onUpdate(dc); + + var font = Graphics.FONT_TINY; + var text = "GarminHomeAssistant"; + + dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK); + dc.drawText(0, dc.getHeight() / 2, font, text, Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER); + } +}