From 4127aa6f033a258aa89ff3704a952505c8c056cb Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 5 Jun 2022 01:38:42 +0200 Subject: Stop using flags for modifiers There was no free bits left to add new modifiers. Instead of increasing the width of the 'flags' field, refactor the way modifiers are represented and used. Modifers are now represented as independent values and stored in the 'code' field. A flag is added to distinguish between modifiers and keys with a key event. The most notable change is that modifiers can no longer be or-ed into a single value but have to be represented as an array. --- srcs/juloo.keyboard2/Keyboard2View.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'srcs/juloo.keyboard2/Keyboard2View.java') diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index c0743bc..4863600 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -24,7 +24,7 @@ public class Keyboard2View extends View private Pointers _pointers; - private int _flags = 0; + private Pointers.Modifiers _mods; private Vibrator _vibratorService; private long _lastVibration = 0; @@ -90,15 +90,15 @@ public class Keyboard2View extends View public void reset() { - _flags = 0; + _mods = Pointers.Modifiers.EMPTY; _pointers.clear(); requestLayout(); invalidate(); } - public KeyValue modifyKey(KeyValue k, int flags) + public KeyValue modifyKey(KeyValue k, Pointers.Modifiers mods) { - return KeyModifier.handleFlags(k, flags); + return KeyModifier.modify(k, mods); } public void onPointerDown(boolean isSwipe) @@ -107,15 +107,15 @@ public class Keyboard2View extends View vibrate(); } - public void onPointerUp(KeyValue k, int flags) + public void onPointerUp(KeyValue k, Pointers.Modifiers mods) { - _config.handler.handleKeyUp(k, flags); + _config.handler.handleKeyUp(k, mods); invalidate(); } - public void onPointerHold(KeyValue k, int flags) + public void onPointerHold(KeyValue k, Pointers.Modifiers mods) { - _config.handler.handleKeyUp(k, flags); + _config.handler.handleKeyUp(k, mods); } public void onPointerFlagsChanged() @@ -125,7 +125,7 @@ public class Keyboard2View extends View private void updateFlags() { - _flags = _pointers.getFlags(); + _mods = _pointers.getModifiers(); } @Override @@ -284,7 +284,7 @@ public class Keyboard2View extends View private void drawLabel(Canvas canvas, KeyValue k, float x, float y, float keyH, boolean isKeyDown) { - k = KeyModifier.handleFlags(k, _flags); + k = KeyModifier.modify(k, _mods); if (k == null) return; float textSize = scaleTextSize(k, _config.labelTextSize, keyH); @@ -296,7 +296,7 @@ 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) { - k = KeyModifier.handleFlags(k, _flags); + k = KeyModifier.modify(k, _mods); if (k == null) return; float textSize = scaleTextSize(k, _config.sublabelTextSize, keyH); -- cgit v1.2.3