158 lines
3.6 KiB
MonkeyC
158 lines
3.6 KiB
MonkeyC
|
import Toybox.Lang;
|
||
|
|
||
|
|
||
|
class Theme
|
||
|
{
|
||
|
public var BackgroundHi;
|
||
|
public var BackgroundLo;
|
||
|
|
||
|
public var ArmHour;
|
||
|
public var ArmMinute;
|
||
|
public var ArmSecond;
|
||
|
|
||
|
public var ArmHourTintHi;
|
||
|
public var ArmHourTintLo;
|
||
|
public var ArmMinuteTintHi;
|
||
|
public var ArmMinuteTintLo;
|
||
|
|
||
|
|
||
|
function initialize(backgroundHi, backgroundLo, armHour, armMinute, armSecond, variablesJsonResource)
|
||
|
{
|
||
|
self.BackgroundHi = backgroundHi;
|
||
|
self.BackgroundLo = backgroundLo;
|
||
|
|
||
|
self.ArmHour = armHour;
|
||
|
self.ArmMinute = armMinute;
|
||
|
self.ArmSecond = armSecond;
|
||
|
|
||
|
var variables = Application.loadResource(variablesJsonResource) as Dictionary<String, Object>;
|
||
|
self.ArmHourTintHi = variables["ArmHourTintHi"];
|
||
|
self.ArmHourTintLo = variables["ArmHourTintLo"];
|
||
|
self.ArmMinuteTintHi = variables["ArmMinuteTintHi"];
|
||
|
self.ArmMinuteTintLo = variables["ArmMinuteTintLo"];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
class ThemeInfo
|
||
|
{
|
||
|
public var Id;
|
||
|
public var Name;
|
||
|
|
||
|
|
||
|
function initialize(id, name)
|
||
|
{
|
||
|
self.Id = id;
|
||
|
self.Name = name;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
class ThemeManager
|
||
|
{
|
||
|
private static var instance = null;
|
||
|
|
||
|
private var currentThemeId = "default";
|
||
|
private var themes as Dictionary<String, Theme> = {};
|
||
|
private var localizedThemes as Array<ThemeInfo> or Null = null;
|
||
|
|
||
|
|
||
|
public function initialize()
|
||
|
{
|
||
|
self.themes["default"] = new Theme(
|
||
|
Rez.Drawables.Background,
|
||
|
Rez.Drawables.Ticks,
|
||
|
|
||
|
Rez.Drawables.ArmHour,
|
||
|
Rez.Drawables.ArmMinute,
|
||
|
Rez.Drawables.ArmSecond,
|
||
|
|
||
|
Rez.JsonData.ThemeDefault
|
||
|
);
|
||
|
|
||
|
self.themes["xmas"] = new Theme(
|
||
|
Rez.Drawables.BackgroundXmas,
|
||
|
Rez.Drawables.Ticks,
|
||
|
|
||
|
Rez.Drawables.ArmHour,
|
||
|
Rez.Drawables.ArmMinute,
|
||
|
Rez.Drawables.ArmSecond,
|
||
|
|
||
|
Rez.JsonData.ThemeXMas
|
||
|
);
|
||
|
|
||
|
|
||
|
var settingsThemeId = Application.Storage.getValue("theme");
|
||
|
if (settingsThemeId != null && self.themes.hasKey(settingsThemeId))
|
||
|
{
|
||
|
self.currentThemeId = settingsThemeId;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
public function getCurrentThemeId() as Lang.String
|
||
|
{
|
||
|
return self.currentThemeId;
|
||
|
}
|
||
|
|
||
|
|
||
|
public function setCurrentThemeId(id as Lang.String) as Void
|
||
|
{
|
||
|
if (self.themes.hasKey(id))
|
||
|
{
|
||
|
self.currentThemeId = id;
|
||
|
Application.Storage.setValue("theme", id);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
public function getCurrentTheme() as Theme
|
||
|
{
|
||
|
return self.themes[self.getCurrentThemeId()];
|
||
|
}
|
||
|
|
||
|
|
||
|
public function getLocalizedThemes() as Array<ThemeInfo>
|
||
|
{
|
||
|
if (self.localizedThemes == null)
|
||
|
{
|
||
|
var themes = Application.loadResource(Rez.JsonData.ThemeInfo) as Array<Dictionary<String, String>>;
|
||
|
self.localizedThemes = [];
|
||
|
|
||
|
for (var i = 0; i < themes.size(); i++)
|
||
|
{
|
||
|
self.localizedThemes.add(new ThemeInfo(themes[i]["id"], themes[i]["name"]));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return self.localizedThemes;
|
||
|
}
|
||
|
|
||
|
|
||
|
public function getLocalizedCurrentTheme() as ThemeInfo
|
||
|
{
|
||
|
var themes = self.getLocalizedThemes();
|
||
|
var currentThemeId = self.getCurrentThemeId();
|
||
|
|
||
|
for (var i = 0; i < themes.size(); i++)
|
||
|
{
|
||
|
if (themes[i].Id.equals(currentThemeId))
|
||
|
{
|
||
|
return themes[i];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return themes[0];
|
||
|
}
|
||
|
|
||
|
|
||
|
public static function getInstance()
|
||
|
{
|
||
|
if (instance == null)
|
||
|
{
|
||
|
instance = new ThemeManager();
|
||
|
}
|
||
|
|
||
|
return instance;
|
||
|
}
|
||
|
}
|