mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-05-01 21:22:40 +00:00
122 lines
4.1 KiB
MonkeyC
122 lines
4.1 KiB
MonkeyC
//-----------------------------------------------------------------------------------
|
|
//
|
|
// 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, 17 November 2023
|
|
//
|
|
//
|
|
// Description:
|
|
//
|
|
// MenuItems Factory.
|
|
//
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
using Toybox.Application;
|
|
using Toybox.Lang;
|
|
using Toybox.WatchUi;
|
|
|
|
class HomeAssistantMenuItemFactory {
|
|
|
|
private var mMenuItemAlignment;
|
|
private var mLabelToggle;
|
|
private var strMenuItemTap;
|
|
private var bRepresentTypesWithIcons;
|
|
|
|
private var mTapTypeIcon;
|
|
|
|
private var mGroupTypeIcon;
|
|
|
|
private static var instance;
|
|
|
|
private function initialize() {
|
|
mLabelToggle = {
|
|
:enabled => WatchUi.loadResource($.Rez.Strings.MenuItemOn) as Lang.String,
|
|
:disabled => WatchUi.loadResource($.Rez.Strings.MenuItemOff) as Lang.String
|
|
};
|
|
|
|
bRepresentTypesWithIcons = Application.Properties.getValue("types_representation") as Lang.Boolean;
|
|
|
|
var menuItemAlignment = Application.Properties.getValue("menu_alignment") as Lang.Boolean;
|
|
|
|
if(menuItemAlignment == true){
|
|
mMenuItemAlignment = {:alignment => WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_RIGHT};
|
|
} else {
|
|
mMenuItemAlignment = {:alignment => WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT};
|
|
}
|
|
|
|
|
|
strMenuItemTap = WatchUi.loadResource($.Rez.Strings.MenuItemTap);
|
|
mTapTypeIcon = new WatchUi.Bitmap({
|
|
:rezId=>$.Rez.Drawables.TapTypeIcon,
|
|
:locX=>WatchUi.LAYOUT_HALIGN_CENTER,
|
|
:locY=>WatchUi.LAYOUT_VALIGN_CENTER
|
|
});
|
|
|
|
mGroupTypeIcon = new WatchUi.Bitmap({
|
|
:rezId=>$.Rez.Drawables.GroupTypeIcon,
|
|
:locX=>WatchUi.LAYOUT_HALIGN_CENTER,
|
|
:locY=>WatchUi.LAYOUT_VALIGN_CENTER
|
|
});
|
|
}
|
|
|
|
static function create() {
|
|
if (instance == null) {
|
|
instance = new HomeAssistantMenuItemFactory();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
function toggle(label as Lang.String or Lang.Symbol, identifier as Lang.Object or Null) as WatchUi.MenuItem{
|
|
var subLabel = null;
|
|
|
|
if (bRepresentTypesWithIcons == false){
|
|
subLabel=mLabelToggle;
|
|
}
|
|
|
|
return new HomeAssistantToggleMenuItem(
|
|
label,
|
|
subLabel,
|
|
identifier,
|
|
false,
|
|
mMenuItemAlignment
|
|
);
|
|
}
|
|
|
|
function tap(label as Lang.String or Lang.Symbol, identifier as Lang.Object or Null, service as Lang.String or Null) as WatchUi.MenuItem{
|
|
if (bRepresentTypesWithIcons) {
|
|
return new HomeAssistantIconMenuItem(
|
|
label,
|
|
null,
|
|
identifier,
|
|
service,
|
|
mTapTypeIcon,
|
|
mMenuItemAlignment
|
|
);
|
|
|
|
} else {
|
|
return new HomeAssistantMenuItem(
|
|
label,
|
|
strMenuItemTap,
|
|
identifier,
|
|
service,
|
|
mMenuItemAlignment
|
|
);
|
|
}
|
|
}
|
|
|
|
function group(definition as Lang.Dictionary) as WatchUi.MenuItem{
|
|
if (bRepresentTypesWithIcons) {
|
|
return new HomeAssistantViewIconMenuItem(definition, mGroupTypeIcon, mMenuItemAlignment);
|
|
} else {
|
|
return new HomeAssistantViewMenuItem(definition);
|
|
}
|
|
}
|
|
}
|