From 2e598a4d476fde86484cb551c4be77dc5298e7b0 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 24 Oct 2022 00:27:49 +0200 Subject: [PATCH] Draw letter indication on the pin layout There is no way to type letters on the pin layout, the indication are decoration only. Use the E.161 standard. --- res/xml/pin.xml | 16 ++++++++-------- srcs/juloo.keyboard2/Keyboard2View.java | 19 ++++++++++++++++++- srcs/juloo.keyboard2/KeyboardData.java | 17 +++++++++++------ srcs/juloo.keyboard2/Theme.java | 7 +++++++ 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/res/xml/pin.xml b/res/xml/pin.xml index 0f0b3c6..bd14f19 100644 --- a/res/xml/pin.xml +++ b/res/xml/pin.xml @@ -2,20 +2,20 @@ - - + + - - - + + + - - - + + + diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 7955aca..d82b58a 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -267,6 +267,10 @@ public class Keyboard2View extends View drawSubLabel(canvas, k.key2, x, y, keyW, keyH, Paint.Align.RIGHT, Vertical.TOP, isKeyDown); drawSubLabel(canvas, k.key4, x, y, keyW, keyH, Paint.Align.RIGHT, Vertical.BOTTOM, isKeyDown); } + if (k.indication != null) + { + drawIndication(canvas, k.indication, keyW / 2f + x, y, keyH); + } x += _keyWidth * k.width; } y += row.height * _config.keyHeight; @@ -309,7 +313,9 @@ public class Keyboard2View extends View canvas.drawText(kv.getString(), x, (keyH - p.ascent() - p.descent()) / 2f + y, p); } - private void drawSubLabel(Canvas canvas, KeyboardData.Corner k, float x, float y, float keyW, float keyH, Paint.Align a, Vertical v, boolean isKeyDown) + private void drawSubLabel(Canvas canvas, KeyboardData.Corner k, float x, + float y, float keyW, float keyH, Paint.Align a, Vertical v, + boolean isKeyDown) { if (k == null) return; @@ -332,6 +338,17 @@ public class Keyboard2View extends View canvas.drawText(kv.getString(), x, y, p); } + private void drawIndication(Canvas canvas, String indication, float x, + float y, float keyH) + { + float textSize = keyH * _config.sublabelTextSize * _config.characterSize; + Paint p = _theme.indicationPaint(); + p.setColor(_theme.subLabelColor); + p.setTextSize(textSize); + canvas.drawText(indication, x, + (keyH - p.ascent() - p.descent()) * 4/5 + y, p); + } + private float scaleTextSize(KeyValue k, float rel_size, float keyH) { float smaller_font = k.hasFlags(KeyValue.FLAG_SMALLER_FONT) ? 0.75f : 1.f; diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 0d0a85b..eaaf702 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -249,8 +249,9 @@ class KeyboardData public final float shift; /** Put keys 1 to 4 on the edges instead of the corners. */ public final boolean edgekeys; + public final String indication; - protected Key(Corner k0, Corner k1, Corner k2, Corner k3, Corner k4, float w, float s, boolean e) + protected Key(Corner k0, Corner k1, Corner k2, Corner k3, Corner k4, float w, float s, boolean e, String i) { key0 = k0; key1 = k1; @@ -260,6 +261,7 @@ class KeyboardData width = w; shift = s; edgekeys = e; + indication = i; } public static Key parse(XmlResourceParser parser) throws Exception @@ -272,15 +274,17 @@ class KeyboardData float width = parser.getAttributeFloatValue(null, "width", 1f); float shift = parser.getAttributeFloatValue(null, "shift", 0.f); boolean edgekeys = parser.getAttributeBooleanValue(null, "edgekeys", false); + String indication = parser.getAttributeValue(null, "indication"); while (parser.next() != XmlResourceParser.END_TAG) continue ; - return new Key(k0, k1, k2, k3, k4, width, shift, edgekeys); + return new Key(k0, k1, k2, k3, k4, width, shift, edgekeys, indication); } /** New key with the width multiplied by 's'. */ public Key scaleWidth(float s) { - return new Key(key0, key1, key2, key3, key4, width * s, shift, edgekeys); + return new Key(key0, key1, key2, key3, key4, width * s, shift, edgekeys, + indication); } public KeyValue getKeyValue(int i) @@ -310,12 +314,12 @@ class KeyboardData case 3: k3 = k; break; case 4: k4 = k; break; } - return new Key(k0, k1, k2, k3, k4, width, shift, edgekeys); + return new Key(k0, k1, k2, k3, k4, width, shift, edgekeys, indication); } public Key withShift(float s) { - return new Key(key0, key1, key2, key3, key4, width, s, edgekeys); + return new Key(key0, key1, key2, key3, key4, width, s, edgekeys, indication); } /** @@ -423,7 +427,8 @@ class KeyboardData public Key apply(Key k) { return new Key(apply(k.key0), apply(k.key1), apply(k.key2), - apply(k.key3), apply(k.key4), k.width, k.shift, k.edgekeys); + apply(k.key3), apply(k.key4), k.width, k.shift, k.edgekeys, + k.indication); } private Corner apply(Corner c) diff --git a/srcs/juloo.keyboard2/Theme.java b/srcs/juloo.keyboard2/Theme.java index e7c7e7f..0adc977 100644 --- a/srcs/juloo.keyboard2/Theme.java +++ b/srcs/juloo.keyboard2/Theme.java @@ -25,6 +25,7 @@ public class Theme private final Paint _specialKeyLabelPaint; private final Paint _keySubLabelPaint; private final Paint _specialKeySubLabelPaint; + private final Paint _indicationPaint; public Theme(Context context, AttributeSet attrs) { @@ -45,6 +46,7 @@ public class Theme Typeface specialKeyFont = getKeyFont(context); _specialKeyLabelPaint = initLabelPaint(Paint.Align.CENTER, specialKeyFont); _specialKeySubLabelPaint = initLabelPaint(Paint.Align.LEFT, specialKeyFont); + _indicationPaint = initLabelPaint(Paint.Align.CENTER, null); } public Paint labelPaint(boolean special_font) @@ -60,6 +62,11 @@ public class Theme return p; } + public Paint indicationPaint() + { + return _indicationPaint; + } + private Paint initLabelPaint(Paint.Align align, Typeface font) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);