Initial commit
This commit is contained in:
28
source/terminalfaceApp.mc
Normal file
28
source/terminalfaceApp.mc
Normal file
@@ -0,0 +1,28 @@
|
||||
import Toybox.Application;
|
||||
import Toybox.Lang;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class terminalfaceApp extends Application.AppBase {
|
||||
|
||||
function initialize() {
|
||||
AppBase.initialize();
|
||||
}
|
||||
|
||||
// onStart() is called on application start up
|
||||
function onStart(state as Dictionary?) as Void {
|
||||
}
|
||||
|
||||
// onStop() is called when your application is exiting
|
||||
function onStop(state as Dictionary?) as Void {
|
||||
}
|
||||
|
||||
// Return the initial view of your application here
|
||||
function getInitialView() as Array<Views or InputDelegates>? {
|
||||
return [ new terminalfaceView() ] as Array<Views or InputDelegates>;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getApp() as terminalfaceApp {
|
||||
return Application.getApp() as terminalfaceApp;
|
||||
}
|
||||
152
source/terminalfaceView.mc
Normal file
152
source/terminalfaceView.mc
Normal file
@@ -0,0 +1,152 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.System;
|
||||
import Toybox.WatchUi;
|
||||
import Toybox.Time.Gregorian;
|
||||
|
||||
using Toybox.ActivityMonitor;
|
||||
|
||||
class terminalfaceView extends WatchUi.WatchFace {
|
||||
private var font as FontResource?;
|
||||
private var curY as Number?;
|
||||
private var lineSpace as Number?;
|
||||
private var blinking as Boolean?;
|
||||
private var lastBlink as Boolean?;
|
||||
|
||||
function initialize() {
|
||||
WatchFace.initialize();
|
||||
font = WatchUi.loadResource(Rez.Fonts.id_font_input) as FontResource;
|
||||
lineSpace = 23;
|
||||
blinking = false;
|
||||
lastBlink = false;
|
||||
}
|
||||
|
||||
// Load your resources here
|
||||
function onLayout(dc as Dc) as Void {
|
||||
setLayout(Rez.Layouts.WatchFace(dc));
|
||||
}
|
||||
|
||||
// Called when this View is brought to the foreground. Restore
|
||||
// the state of this View and prepare it to be shown. This includes
|
||||
// loading resources into memory.
|
||||
function onShow() as Void {
|
||||
}
|
||||
|
||||
private function prompt(dc as Dc, cmd as String) as Void {
|
||||
dc.setColor(Graphics.COLOR_GREEN, Graphics.COLOR_TRANSPARENT);
|
||||
dc.drawText(25, curY, font, "si", Graphics.TEXT_JUSTIFY_LEFT);
|
||||
|
||||
dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_TRANSPARENT);
|
||||
dc.drawText(50, curY, font, "@", Graphics.TEXT_JUSTIFY_LEFT);
|
||||
|
||||
dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_TRANSPARENT);
|
||||
dc.drawText(63, curY, font, "fnx", Graphics.TEXT_JUSTIFY_LEFT);
|
||||
|
||||
dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_TRANSPARENT);
|
||||
dc.drawText(113, curY, font, "~>", Graphics.TEXT_JUSTIFY_LEFT);
|
||||
|
||||
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
|
||||
dc.drawText(150, curY, font, Lang.format("$1$", [cmd]), Graphics.TEXT_JUSTIFY_LEFT);
|
||||
|
||||
curY += lineSpace;
|
||||
}
|
||||
|
||||
private function response(dc as Dc, text as String) as Void {
|
||||
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
|
||||
dc.drawText(25, curY, font, text, Graphics.TEXT_JUSTIFY_LEFT);
|
||||
|
||||
curY += lineSpace;
|
||||
}
|
||||
|
||||
private function makeBatteryString() {
|
||||
var stats = System.getSystemStats();
|
||||
var batteryLevel = stats.battery;
|
||||
var batteryDays = stats.batteryInDays;
|
||||
|
||||
var bar = new [10];
|
||||
for (var i = 0; i < 10; i += 1)
|
||||
{
|
||||
if (batteryLevel > i*10)
|
||||
{
|
||||
bar[i] = '#';
|
||||
}
|
||||
else
|
||||
{
|
||||
bar[i] = '-';
|
||||
}
|
||||
}
|
||||
|
||||
bar.add(batteryDays.toNumber());
|
||||
|
||||
return Lang.format("[$1$$2$$3$$4$$5$$6$$7$$8$$9$$10$] ($11$d)", bar);
|
||||
}
|
||||
|
||||
// Update the view
|
||||
function onUpdate(dc as Dc) as Void {
|
||||
curY = 50;
|
||||
|
||||
dc.setColor(Graphics.COLOR_TRANSPARENT, Graphics.COLOR_BLACK);
|
||||
dc.clear();
|
||||
|
||||
prompt(dc, "date");
|
||||
|
||||
var today = Gregorian.info(Time.now(), Time.FORMAT_MEDIUM);
|
||||
var dateString = Lang.format("$1$ $2$ $3$ $4$:$5$",
|
||||
[
|
||||
today.day_of_week,
|
||||
today.month,
|
||||
today.day,
|
||||
today.hour.format("%02d"),
|
||||
today.min.format("%02d"),
|
||||
]);
|
||||
|
||||
response(dc, dateString);
|
||||
|
||||
prompt(dc, "steps");
|
||||
var info = ActivityMonitor.getInfo();
|
||||
var steps = info.steps.toFloat();
|
||||
var stepGoal = info.stepGoal.toFloat();
|
||||
var ratio = (steps/stepGoal)*100;
|
||||
response(dc, Lang.format("$1$/$2$ ($3$%)", [steps.toNumber(), stepGoal.toNumber(), ratio.toNumber()]));
|
||||
|
||||
prompt(dc, "battery");
|
||||
var batteryString = makeBatteryString();
|
||||
response(dc, batteryString);
|
||||
|
||||
if (blinking)
|
||||
{
|
||||
if (lastBlink)
|
||||
{
|
||||
prompt(dc, "");
|
||||
lastBlink = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
prompt(dc, "_");
|
||||
lastBlink = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
prompt(dc, "_");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Called when this View is removed from the screen. Save the
|
||||
// state of this View here. This includes freeing resources from
|
||||
// memory.
|
||||
function onHide() as Void {
|
||||
}
|
||||
|
||||
// The user has just looked at their watch. Timers and animations may be started here.
|
||||
function onExitSleep() as Void {
|
||||
blinking = true;
|
||||
}
|
||||
|
||||
// Terminate any active timers and prepare for slow updates.
|
||||
function onEnterSleep() as Void {
|
||||
blinking = false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user