diff options
| author | Jules Aguillon | 2023-03-03 19:44:05 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2023-03-03 19:44:05 +0100 |
| commit | a6fe5cae00c58365d3ca261783cc745006b2f117 (patch) | |
| tree | ea61093d070a147c97114b0326ee2927fe74400b /srcs/juloo.keyboard2/Keyboard2View.java | |
| parent | 1f9e92ed60127baca11cd222a2851d01550bb71c (diff) | |
| download | unexpected-keyboard-a6fe5cae00c58365d3ca261783cc745006b2f117.tar.gz unexpected-keyboard-a6fe5cae00c58365d3ca261783cc745006b2f117.zip | |
Allow 8 symbols per key
'Keyboard.Key' now contains an array of size 9, giving each keyvalue an
index. The algorithm for finding the nearest key during a swipe now
needs 16 segments, which are now calculated as an angle.
The algorithm does one more interation instead of 2 more, slightly
reducing the sensitivity of corner values. The 'getAtDirection' function
is moved into the Pointers class to clearly separate the two systems.
The 'edgekey' attribute is now obsolete but is kept for compatibility.
The flag is removed internally, key index are simply translated.
Similarly, the 'slider' attribute now act on keys at index 5 and 6
instead of 2 and 3.
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2View.java')
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2View.java | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 3c642f0..0a75529 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -260,6 +260,19 @@ public class Keyboard2View extends View } } + /** Horizontal and vertical position of the 9 indexes. */ + static final Paint.Align[] LABEL_POSITION_H = new Paint.Align[]{ + Paint.Align.CENTER, Paint.Align.LEFT, Paint.Align.RIGHT, Paint.Align.LEFT, + Paint.Align.RIGHT, Paint.Align.LEFT, Paint.Align.RIGHT, + Paint.Align.CENTER, Paint.Align.CENTER + }; + + static final Vertical[] LABEL_POSITION_V = new Vertical[]{ + Vertical.CENTER, Vertical.TOP, Vertical.TOP, Vertical.BOTTOM, + Vertical.BOTTOM, Vertical.CENTER, Vertical.CENTER, Vertical.TOP, + Vertical.BOTTOM + }; + @Override protected void onDraw(Canvas canvas) { @@ -282,20 +295,12 @@ public class Keyboard2View extends View float keyW = _keyWidth * k.width - _config.keyHorizontalInterval; boolean isKeyDown = _pointers.isKeyDown(k); drawKeyFrame(canvas, x, y, keyW, keyH, isKeyDown); - drawLabel(canvas, k.key0, keyW / 2f + x, y, keyH, isKeyDown); - if (k.edgekeys) - { - 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.keys[0] != null) + drawLabel(canvas, k.keys[0], keyW / 2f + x, y, keyH, isKeyDown); + for (int i = 1; i < 9; i++) { - 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); + if (k.keys[i] != null) + drawSubLabel(canvas, k.keys[i], x, y, keyW, keyH, i, isKeyDown); } if (k.indication != null) { @@ -367,8 +372,6 @@ public class Keyboard2View extends View private void drawLabel(Canvas canvas, KeyboardData.Corner k, float x, float y, float keyH, boolean isKeyDown) { - if (k == null) - return; KeyValue kv = KeyModifier.modify(k.kv, _mods); if (kv == null) return; @@ -381,11 +384,10 @@ public class Keyboard2View extends View } private void drawSubLabel(Canvas canvas, KeyboardData.Corner k, float x, - float y, float keyW, float keyH, Paint.Align a, Vertical v, - boolean isKeyDown) + float y, float keyW, float keyH, int sub_index, boolean isKeyDown) { - if (k == null) - return; + Paint.Align a = LABEL_POSITION_H[sub_index]; + Vertical v = LABEL_POSITION_V[sub_index]; KeyValue kv = KeyModifier.modify(k.kv, _mods); if (kv == null) return; |
