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.
This commit is contained in:
Jules Aguillon 2022-10-24 00:27:49 +02:00
parent e01a2733b1
commit 2e598a4d47
4 changed files with 44 additions and 15 deletions

View File

@ -2,20 +2,20 @@
<keyboard width="6.0" bottom_row="false" extra_keys="false" num_pad="false">
<row>
<key shift="1.0" key0="1"/>
<key key0="2"/>
<key key0="3"/>
<key key0="2" indication="ABC"/>
<key key0="3" indication="DEF"/>
<key key0="backspace" key2="delete"/>
</row>
<row>
<key shift="1.0" key0="4"/>
<key key0="5"/>
<key key0="6"/>
<key shift="1.0" key0="4" indication="GHI"/>
<key key0="5" indication="JKL"/>
<key key0="6" indication="MNO"/>
<key key0="(" key3=":"/>
</row>
<row>
<key shift="1.0" key0="7"/>
<key key0="8"/>
<key key0="9"/>
<key shift="1.0" key0="7" indication="PQRS"/>
<key key0="8" indication="TUV"/>
<key key0="9" indication="WXYZ"/>
<key key0=")" key3="/"/>
</row>
<row>

View File

@ -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;

View File

@ -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)

View File

@ -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);