From a57bdf8cfb76e8680f77b95c1ad84f2e76e087a9 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 13 Mar 2022 00:35:15 +0100 Subject: [PATCH] Avoid showing some symbols twice in Fn mode --- srcs/juloo.keyboard2/KeyEventHandler.java | 2 ++ srcs/juloo.keyboard2/KeyModifier.java | 9 +++-- srcs/juloo.keyboard2/Keyboard2View.java | 41 ++++++++++------------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java index 86cfc8c..822cd85 100644 --- a/srcs/juloo.keyboard2/KeyEventHandler.java +++ b/srcs/juloo.keyboard2/KeyEventHandler.java @@ -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; diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index 21925fe..a44794e 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -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 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); diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index e282b0f..43274a9 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -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);