Avoid showing some symbols twice in Fn mode

This commit is contained in:
Jules Aguillon 2022-03-13 00:35:15 +01:00
parent ee6e892ef4
commit a57bdf8cfb
3 changed files with 25 additions and 27 deletions

View File

@ -14,6 +14,8 @@ class KeyEventHandler implements Config.IKeyEventHandler
public void handleKeyUp(KeyValue key, int flags)
{
key = KeyModifier.handleFlags(key, flags);
if (key == null || (key.flags & KeyValue.FLAG_NOCHAR) != 0)
return;
switch (key.eventCode)
{
case KeyValue.EVENT_CONFIG: _recv.showKeyboardConfig(); return;

View File

@ -14,7 +14,7 @@ class KeyModifier
/* Modify a key according to modifiers. */
public static KeyValue handleFlags(KeyValue k, int flags)
{
if (flags == 0) // No modifier
if (k == null || flags == 0) // No modifier
return k;
SparseArray<KeyValue> ks = cacheEntry(k);
KeyValue r = ks.get(flags);
@ -22,8 +22,10 @@ class KeyModifier
return r;
r = k;
r = handleFn(r, flags);
r = handleShift(r, flags);
r = handleAccents(r, flags);
if (r != null)
r = handleShift(r, flags);
if (r != null)
r = handleAccents(r, flags);
ks.put(flags, r);
return r;
}
@ -211,6 +213,7 @@ class KeyModifier
case "#": name = "£"; break;
case "*": name = "°"; break;
case "tab": name = "\\t"; break;
case "": case "£": return null; // Avoid showing these twice
default: return k;
}
return KeyValue.getKeyByName(name);

View File

@ -85,16 +85,14 @@ public class Keyboard2View extends View
public void onPointerUp(KeyValue k)
{
if (k != null && (k.flags & KeyValue.FLAG_NOCHAR) == 0)
_config.handler.handleKeyUp(k, _flags);
_config.handler.handleKeyUp(k, _flags);
updateFlags();
invalidate();
}
public void onPointerHold(KeyValue k)
{
if (k != null)
_config.handler.handleKeyUp(k, _flags);
_config.handler.handleKeyUp(k, _flags);
}
public void onPointerFlagsChanged()
@ -215,29 +213,20 @@ public class Keyboard2View extends View
_tmpRect.set(x, y, x + keyW, y + keyH);
canvas.drawRoundRect(_tmpRect, _theme.keyBorderRadius, _theme.keyBorderRadius,
isKeyDown ? _theme.keyDownBgPaint : _theme.keyBgPaint);
if (k.key0 != null)
drawLabel(canvas, k.key0, keyW / 2f + x, y, keyH, isKeyDown);
drawLabel(canvas, k.key0, keyW / 2f + x, y, keyH, isKeyDown);
if (k.edgekeys)
{
if (k.key1 != null) // top key
drawSubLabel(canvas, k.key1, x, y, keyW, keyH, Paint.Align.CENTER, Vertical.TOP, isKeyDown);
if (k.key3 != null) // left key
drawSubLabel(canvas, k.key3, x, y, keyW, keyH, Paint.Align.LEFT, Vertical.CENTER, isKeyDown);
if (k.key2 != null) // right key
drawSubLabel(canvas, k.key2, x, y, keyW, keyH, Paint.Align.RIGHT, Vertical.CENTER, isKeyDown);
if (k.key4 != null) // bottom key
drawSubLabel(canvas, k.key4, x, y, keyW, keyH, Paint.Align.CENTER, Vertical.BOTTOM, isKeyDown);
drawSubLabel(canvas, k.key1, x, y, keyW, keyH, Paint.Align.CENTER, Vertical.TOP, isKeyDown);
drawSubLabel(canvas, k.key3, x, y, keyW, keyH, Paint.Align.LEFT, Vertical.CENTER, isKeyDown);
drawSubLabel(canvas, k.key2, x, y, keyW, keyH, Paint.Align.RIGHT, Vertical.CENTER, isKeyDown);
drawSubLabel(canvas, k.key4, x, y, keyW, keyH, Paint.Align.CENTER, Vertical.BOTTOM, isKeyDown);
}
else
{
if (k.key1 != null) // top left key
drawSubLabel(canvas, k.key1, x, y, keyW, keyH, Paint.Align.LEFT, Vertical.TOP, isKeyDown);
if (k.key3 != null) // bottom left key
drawSubLabel(canvas, k.key3, x, y, keyW, keyH, Paint.Align.LEFT, Vertical.BOTTOM, isKeyDown);
if (k.key2 != null) // top right key
drawSubLabel(canvas, k.key2, x, y, keyW, keyH, Paint.Align.RIGHT, Vertical.TOP, isKeyDown);
if (k.key4 != null) // bottom right key
drawSubLabel(canvas, k.key4, x, y, keyW, keyH, Paint.Align.RIGHT, Vertical.BOTTOM, isKeyDown);
drawSubLabel(canvas, k.key1, x, y, keyW, keyH, Paint.Align.LEFT, Vertical.TOP, isKeyDown);
drawSubLabel(canvas, k.key3, x, y, keyW, keyH, Paint.Align.LEFT, Vertical.BOTTOM, isKeyDown);
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);
}
x += _keyWidth * k.width;
}
@ -269,8 +258,10 @@ public class Keyboard2View extends View
private void drawLabel(Canvas canvas, KeyValue k, float x, float y, float keyH, boolean isKeyDown)
{
float textSize = scaleTextSize(k, _config.labelTextSize, keyH);
k = KeyModifier.handleFlags(k, _flags);
if (k == null)
return;
float textSize = scaleTextSize(k, _config.labelTextSize, keyH);
Paint p = _theme.labelPaint(((k.flags & KeyValue.FLAG_KEY_FONT) != 0));
p.setColor(labelColor(k, isKeyDown, _theme.labelColor));
p.setTextSize(textSize);
@ -279,8 +270,10 @@ public class Keyboard2View extends View
private void drawSubLabel(Canvas canvas, KeyValue k, float x, float y, float keyW, float keyH, Paint.Align a, Vertical v, boolean isKeyDown)
{
float textSize = scaleTextSize(k, _config.sublabelTextSize, keyH);
k = KeyModifier.handleFlags(k, _flags);
if (k == null)
return;
float textSize = scaleTextSize(k, _config.sublabelTextSize, keyH);
Paint p = _theme.subLabelPaint(((k.flags & KeyValue.FLAG_KEY_FONT) != 0), a);
p.setColor(labelColor(k, isKeyDown, _theme.subLabelColor));
p.setTextSize(textSize);