summaryrefslogtreecommitdiff
path: root/source/ui/PinView.mc
diff options
context:
space:
mode:
Diffstat (limited to 'source/ui/PinView.mc')
-rw-r--r--source/ui/PinView.mc33
1 files changed, 22 insertions, 11 deletions
diff --git a/source/ui/PinView.mc b/source/ui/PinView.mc
index fa58bfe..47b12fd 100644
--- a/source/ui/PinView.mc
+++ b/source/ui/PinView.mc
@@ -4,7 +4,8 @@
// README 13.1 and 13.4:
// * A PIN has exactly 4 digits (KeyManager.PIN_DIGITS) and is submitted
// as soon as the 4th is entered; there is no OK key.
-// * Touch screens get a keypad (1-9, delete, 0). The START button does
+// * Touch screens get a keypad (1-9, then 0 and delete in the bottom row,
+// delete on the right as on phone keypads). The START button does
// nothing there: a tap can also arrive as START, which used to submit a
// PIN early. Watches without a touch screen get a digit selector:
// UP/DOWN change the digit, START adds it, BACK deletes.
@@ -32,9 +33,11 @@ class PinView extends WatchUi.View {
// Selector positions 0-9 are digits; this one is "OK" (legacy PINs only).
static const SELECT_OK = 10;
- // Keypad keys besides the digits (OK for legacy PINs only).
+ // Keypad keys besides the digits (OK for legacy PINs only), and an
+ // empty slot.
static const KEY_DELETE = -1;
static const KEY_OK = -2;
+ static const KEY_NONE = -3;
// Calibrate the PIN derivation to about this long on this watch.
static const DERIVATION_TARGET_MS = 1000;
static const CALIBRATION_SAMPLE = 200;
@@ -358,7 +361,7 @@ class PinView extends WatchUi.View {
var message = wait > 0 ? "Wrong PINs. Wait " + Ui.minutesSeconds(wait) : _message;
if (message != null) {
- dc.setColor(_messageIsError || wait > 0 ? Ui.WARN_COLOR : Ui.accent(), Graphics.COLOR_TRANSPARENT);
+ dc.setColor(_messageIsError || wait > 0 ? Ui.warn() : Ui.accent(), Graphics.COLOR_TRANSPARENT);
dc.drawText(cx, y, Graphics.FONT_XTINY, Ui.fit(dc, message, Graphics.FONT_XTINY, 2 * Ui.halfWidthAt(dc, y)),
Graphics.TEXT_JUSTIFY_CENTER);
}
@@ -372,6 +375,9 @@ class PinView extends WatchUi.View {
if (!_shownLogged) {
_shownLogged = true;
+ // For UI scripts: the state the dots and the title show (never digits).
+ Diag.data("pin_state", "mode=" + mode + " digits=" + _digits.size() + " repeat=" + (_first != null ? 1 : 0)
+ + " busy=" + (busy ? 1 : 0));
Diag.shown(wait > 0 ? "pin_wait" : (_message != null && _messageIsError ? "pin_error" : "pin"));
}
}
@@ -394,19 +400,21 @@ class PinView extends WatchUi.View {
keyW = keyH * 2;
}
var left = w / 2 - 3 * keyW / 2;
- var labels = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "", "0", "OK"];
- var values = [1, 2, 3, 4, 5, 6, 7, 8, 9, KEY_DELETE, 0, KEY_OK];
+ // A legacy PIN needs OK: delete, 0, OK. Otherwise the 4th digit
+ // submits, and the bottom row is an empty slot, 0 and delete.
+ var values = legacy ? [1, 2, 3, 4, 5, 6, 7, 8, 9, KEY_DELETE, 0, KEY_OK]
+ : [1, 2, 3, 4, 5, 6, 7, 8, 9, KEY_NONE, 0, KEY_DELETE];
var font = Graphics.FONT_MEDIUM;
_keys = [] as Array<Array<Number>>;
var log = "";
for (var i = 0; i < 12; i++) {
- if (values[i] == KEY_OK && !legacy) {
- continue; // no OK key: the 4th digit submits; the slot stays empty
+ if (values[i] == KEY_NONE) {
+ continue;
}
var kx = left + (i % 3) * keyW;
var ky = top + (i / 3) * keyH;
_keys.add([kx, ky, keyW, keyH, values[i] as Number]);
- var label = labels[i] as String;
+ var label = values[i] == KEY_OK ? "OK" : (values[i] as Number).toString();
var isAction = (values[i] as Number) < 0;
dc.setColor(disabled ? (Ui.dark() ? 0x444444 : Graphics.COLOR_LT_GRAY) : (isAction ? Ui.accent() : Ui.fg()),
Graphics.COLOR_TRANSPARENT);
@@ -416,7 +424,7 @@ class PinView extends WatchUi.View {
var f = isAction ? Graphics.FONT_SMALL : font;
dc.drawText(kx + keyW / 2, ky + (keyH - dc.getFontHeight(f)) / 2, f, label, Graphics.TEXT_JUSTIFY_CENTER);
}
- log += (i > 0 ? ";" : "") + (values[i] as Number) + "=" + (kx + keyW / 2) + "," + (ky + keyH / 2);
+ log += (log.length() > 0 ? ";" : "") + (values[i] as Number) + "=" + (kx + keyW / 2) + "," + (ky + keyH / 2);
}
if (!_shownLogged) {
Diag.data("pin_keys", log);
@@ -444,7 +452,10 @@ class PinView extends WatchUi.View {
private function drawSelector(dc as Graphics.Dc, top as Number, bottom as Number, disabled as Boolean) as Void {
var cx = dc.getWidth() / 2;
- var mid = (top + bottom) / 2;
+ // Centred above the hint, so the lower arrow never touches it (it
+ // did on the Forerunner 255S).
+ var hintTop = bottom - dc.getFontHeight(Graphics.FONT_XTINY);
+ var mid = (top + hintTop) / 2;
var font = Graphics.FONT_NUMBER_MEDIUM;
var label = _selector == SELECT_OK ? "OK" : _selector.toString();
if (_selector == SELECT_OK) {
@@ -458,7 +469,7 @@ class PinView extends WatchUi.View {
dc.fillPolygon([[cx - 8, mid + a], [cx + 8, mid + a], [cx, mid + a + 8]] as Array<Graphics.Point2D>);
dc.setColor(Ui.dim(), Graphics.COLOR_TRANSPARENT);
var hint = "START: add";
- dc.drawText(cx, bottom - dc.getFontHeight(Graphics.FONT_XTINY), Graphics.FONT_XTINY,
+ dc.drawText(cx, hintTop, Graphics.FONT_XTINY,
Ui.fit(dc, hint, Graphics.FONT_XTINY, 2 * Ui.halfWidthAt(dc, bottom)), Graphics.TEXT_JUSTIFY_CENTER);
}
}