mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-08-02 18:08:34 +00:00
Merge branch 'main' into 29-vivoactive-4s-crashes-user-reported-error
This commit is contained in:
@ -78,11 +78,10 @@ class ErrorView extends ScalableView {
|
||||
function onUpdate(dc as Graphics.Dc) as Void {
|
||||
var w = dc.getWidth();
|
||||
var hw = w/2;
|
||||
var bg = 0x3B444C;
|
||||
if(dc has :setAntiAlias) {
|
||||
dc.setAntiAlias(true);
|
||||
}
|
||||
dc.setColor(Graphics.COLOR_WHITE, bg);
|
||||
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLUE);
|
||||
dc.clear();
|
||||
dc.drawBitmap(hw - mErrorIcon.getWidth()/2, mErrorIconMargin, mErrorIcon);
|
||||
mTextArea.draw(dc);
|
||||
@ -143,4 +142,4 @@ class ErrorDelegate extends WatchUi.BehaviorDelegate {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -24,24 +24,71 @@ 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 mQuitTimer 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();
|
||||
|
||||
// ATTENTION when adding stuff into this block:
|
||||
// Because of the >>GlanceView<<, it should contain only
|
||||
// code, which is used as well for the glance:
|
||||
// - https://developer.garmin.com/connect-iq/core-topics/glances/
|
||||
//
|
||||
// Also dealing with resources "Rez" needs attention, too. See
|
||||
// "Resource Scopes":
|
||||
// - https://developer.garmin.com/connect-iq/core-topics/resources/
|
||||
//
|
||||
// Classes which are used for the glance view, needed to be tagged
|
||||
// with "(:glance)".
|
||||
}
|
||||
|
||||
// onStart() is called on application start up
|
||||
function onStart(state as Lang.Dictionary?) as Void {
|
||||
// ATTENTION when adding stuff into this block:
|
||||
// Because of the >>GlanceView<<, it should contain only
|
||||
// code, which is used as well for the glance:
|
||||
// - https://developer.garmin.com/connect-iq/core-topics/glances/
|
||||
//
|
||||
// Also dealing with resources "Rez" needs attention, too. See
|
||||
// "Resource Scopes":
|
||||
// - https://developer.garmin.com/connect-iq/core-topics/resources/
|
||||
//
|
||||
// Classes which are used for the glance view, needed to be tagged
|
||||
// with "(:glance)".
|
||||
}
|
||||
|
||||
// onStop() is called when your application is exiting
|
||||
function onStop(state as Lang.Dictionary?) as Void {
|
||||
// ATTENTION when adding stuff into this block:
|
||||
// Because of the >>GlanceView<<, it should contain only
|
||||
// code, which is used as well for the glance:
|
||||
// - https://developer.garmin.com/connect-iq/core-topics/glances/
|
||||
//
|
||||
// Also dealing with resources "Rez" needs attention, too. See
|
||||
// "Resource Scopes":
|
||||
// - https://developer.garmin.com/connect-iq/core-topics/resources/
|
||||
//
|
||||
// Classes which are used for the glance view, needed to be tagged
|
||||
// with "(:glance)".
|
||||
}
|
||||
|
||||
// Return the initial view of your application here
|
||||
function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
|
||||
|
||||
strNoApiKey = WatchUi.loadResource($.Rez.Strings.NoAPIKey);
|
||||
strNoApiUrl = WatchUi.loadResource($.Rez.Strings.NoApiUrl);
|
||||
strNoConfigUrl = WatchUi.loadResource($.Rez.Strings.NoConfigUrl);
|
||||
@ -53,21 +100,8 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
strConfigUrlNotFound = WatchUi.loadResource($.Rez.Strings.ConfigUrlNotFound);
|
||||
strUnhandledHttpErr = WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr);
|
||||
strTrailingSlashErr = WatchUi.loadResource($.Rez.Strings.TrailingSlashErr);
|
||||
quitTimer = new QuitTimer();
|
||||
}
|
||||
mQuitTimer = 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<WatchUi.Views or WatchUi.InputDelegates>? {
|
||||
var api_url = Properties.getValue("api_url") as Lang.String;
|
||||
|
||||
if ((Properties.getValue("api_key") as Lang.String).length() == 0) {
|
||||
@ -102,7 +136,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
return ErrorView.create(strNoInternet + ".");
|
||||
} else {
|
||||
fetchMenuConfig();
|
||||
return [new WatchUi.View(), new WatchUi.BehaviorDelegate()] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
return [new RootView(self), new RootViewDelegate(self)] as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>;
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +170,8 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
ErrorView.show(strConfigUrlNotFound);
|
||||
} else if (responseCode == 200) {
|
||||
mHaMenu = new HomeAssistantView(data, null);
|
||||
WatchUi.switchToView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE);
|
||||
mQuitTimer.begin();
|
||||
pushHomeAssistantMenuView();
|
||||
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.
|
||||
@ -169,6 +204,14 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
);
|
||||
}
|
||||
|
||||
function homeAssistantMenuIsLoaded() as Lang.Boolean{
|
||||
return mHaMenu!=null;
|
||||
}
|
||||
|
||||
function pushHomeAssistantMenuView() as Void{
|
||||
WatchUi.pushView(mHaMenu, new HomeAssistantViewDelegate(true), WatchUi.SLIDE_IMMEDIATE);
|
||||
}
|
||||
|
||||
// We need to spread out the API calls so as not to overload the results queue and cause Communications.BLE_QUEUE_FULL (-101) error.
|
||||
// This function is called by a timer every Globals.menuItemUpdateInterval ms.
|
||||
function updateNextMenuItem() as Void {
|
||||
@ -178,9 +221,13 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
}
|
||||
|
||||
function getQuitTimer() as QuitTimer{
|
||||
return quitTimer;
|
||||
return mQuitTimer;
|
||||
}
|
||||
|
||||
(:glance)
|
||||
function getGlanceView() {
|
||||
return [new HomeAssistantGlanceView()];
|
||||
}
|
||||
}
|
||||
|
||||
function getApp() as HomeAssistantApp {
|
||||
|
42
source/HomeAssistantGlanceView.mc
Normal file
42
source/HomeAssistantGlanceView.mc
Normal file
@ -0,0 +1,42 @@
|
||||
//-----------------------------------------------------------------------------------
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// Glance view for GarminHomeAssistant
|
||||
//
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
using Toybox.Lang;
|
||||
using Toybox.WatchUi;
|
||||
using Toybox.Graphics;
|
||||
|
||||
(:glance)
|
||||
class HomeAssistantGlanceView extends WatchUi.GlanceView {
|
||||
|
||||
private var mText as Lang.String;
|
||||
|
||||
function initialize() {
|
||||
GlanceView.initialize();
|
||||
|
||||
mText = WatchUi.loadResource($.Rez.Strings.AppName);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
using Toybox.Application;
|
||||
using Toybox.Lang;
|
||||
using Toybox.Graphics;
|
||||
using Toybox.System;
|
||||
using Toybox.WatchUi;
|
||||
|
||||
class HomeAssistantView extends WatchUi.Menu2 {
|
||||
@ -103,12 +104,23 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
//
|
||||
class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
|
||||
|
||||
function initialize() {
|
||||
private var mIsRootMenuView = false;
|
||||
|
||||
function initialize(isRootMenuView as Lang.Boolean) {
|
||||
Menu2InputDelegate.initialize();
|
||||
mIsRootMenuView = isRootMenuView;
|
||||
}
|
||||
|
||||
function onBack() {
|
||||
getApp().getQuitTimer().reset();
|
||||
|
||||
if (mIsRootMenuView){
|
||||
// If its started from glance or as an activity, directly exit the widget/app
|
||||
// (on widgets without glance, this exit() won`t do anything,
|
||||
// so the base view will be shown instead, through the popView below this "if body")
|
||||
System.exit();
|
||||
}
|
||||
|
||||
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
||||
}
|
||||
|
||||
@ -147,15 +159,13 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
|
||||
if (Globals.scDebug) {
|
||||
System.println("Menu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
|
||||
}
|
||||
// No delegate state to be amended, so re-use 'self'.
|
||||
WatchUi.pushView(haMenuItem.getMenuView(), self, WatchUi.SLIDE_LEFT);
|
||||
WatchUi.pushView(haMenuItem.getMenuView(), new HomeAssistantViewDelegate(false), WatchUi.SLIDE_LEFT);
|
||||
} else if (item instanceof HomeAssistantViewIconMenuItem) {
|
||||
var haMenuItem = item as HomeAssistantViewIconMenuItem;
|
||||
if (Globals.scDebug) {
|
||||
System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
|
||||
}
|
||||
// No delegate state to be amended, so re-use 'self'.
|
||||
WatchUi.pushView(haMenuItem.getMenuView(), self, WatchUi.SLIDE_LEFT);
|
||||
WatchUi.pushView(haMenuItem.getMenuView(), new HomeAssistantViewDelegate(false), WatchUi.SLIDE_LEFT);
|
||||
} else {
|
||||
if (Globals.scDebug) {
|
||||
System.println(item.getLabel() + " " + item.getId());
|
||||
|
129
source/RootView.mc
Normal file
129
source/RootView.mc
Normal file
@ -0,0 +1,129 @@
|
||||
//-----------------------------------------------------------------------------------
|
||||
//
|
||||
// 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, 5 December 2023
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// Application root view for GarminHomeAssistant
|
||||
//
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
using Toybox.Graphics;
|
||||
using Toybox.Lang;
|
||||
using Toybox.WatchUi;
|
||||
|
||||
class RootView extends ScalableView {
|
||||
|
||||
// ATTENTION when the app is running as a "widget" (that means, it runs on devices
|
||||
// without glance view support), the input events in this view are limited, as
|
||||
// described under "Base View and the Widget Carousel" on:
|
||||
//
|
||||
// https://developer.garmin.com/connect-iq/connect-iq-basics/app-types/
|
||||
//
|
||||
// Also the view type of the base view is limited too (for example "WatchUi.Menu2"
|
||||
// is not possible)).
|
||||
//
|
||||
// Also System.exit() is not working/do nothing when running as a widget: A widget will be
|
||||
// terminated automatically by OS after some time or can be quit manually, when on the base
|
||||
// view a swipe to left / "back button" press is done.
|
||||
|
||||
private var mApp as HomeAssistantApp;
|
||||
private var strFetchingMenuConfig as Lang.String;
|
||||
private var strExit as Lang.String;
|
||||
private var mTextAreaExit as WatchUi.TextArea or Null;
|
||||
private var mTextAreaFetching as WatchUi.TextArea or Null;
|
||||
|
||||
function initialize(app as HomeAssistantApp) {
|
||||
ScalableView.initialize();
|
||||
mApp=app;
|
||||
|
||||
strFetchingMenuConfig = WatchUi.loadResource($.Rez.Strings.FetchingMenuConfig);
|
||||
|
||||
if (System.getDeviceSettings().isTouchScreen){
|
||||
strExit = WatchUi.loadResource($.Rez.Strings.ExitViewTouch);
|
||||
} else {
|
||||
strExit = WatchUi.loadResource($.Rez.Strings.ExitViewButtons);
|
||||
}
|
||||
}
|
||||
|
||||
function onLayout(dc as Graphics.Dc) as Void {
|
||||
var w = dc.getWidth();
|
||||
var h = dc.getHeight();
|
||||
|
||||
mTextAreaExit = new WatchUi.TextArea({
|
||||
:text => strExit,
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:font => Graphics.FONT_XTINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
:locX => 0,
|
||||
:locY => 83,
|
||||
:width => w,
|
||||
:height => h - 166
|
||||
});
|
||||
|
||||
mTextAreaFetching = new WatchUi.TextArea({
|
||||
:text => strFetchingMenuConfig,
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:font => Graphics.FONT_XTINY,
|
||||
:justification => Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER,
|
||||
:locX => 0,
|
||||
:locY => 83,
|
||||
:width => w,
|
||||
:height => h - 166
|
||||
});
|
||||
}
|
||||
|
||||
function onUpdate(dc as Graphics.Dc) as Void {
|
||||
if(dc has :setAntiAlias) {
|
||||
dc.setAntiAlias(true);
|
||||
}
|
||||
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK);
|
||||
dc.clear();
|
||||
|
||||
if(mApp.homeAssistantMenuIsLoaded()) {
|
||||
mTextAreaExit.draw(dc);
|
||||
} else {
|
||||
mTextAreaFetching.draw(dc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RootViewDelegate extends WatchUi.BehaviorDelegate {
|
||||
|
||||
var mApp as HomeAssistantApp;
|
||||
|
||||
function initialize(app as HomeAssistantApp ) {
|
||||
BehaviorDelegate.initialize();
|
||||
mApp=app;
|
||||
}
|
||||
|
||||
function onTap(evt as WatchUi.ClickEvent) as Lang.Boolean {
|
||||
return backToMainMenu();
|
||||
}
|
||||
|
||||
function onSelect() as Lang.Boolean {
|
||||
return backToMainMenu();
|
||||
}
|
||||
|
||||
function onMenu() as Lang.Boolean{
|
||||
return backToMainMenu();
|
||||
}
|
||||
|
||||
private function backToMainMenu() as Lang.Boolean{
|
||||
if(mApp.homeAssistantMenuIsLoaded()){
|
||||
mApp.pushHomeAssistantMenuView();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user