diff options
| -rw-r--r-- | srcs/juloo.keyboard2/KeyboardData.java | 22 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/Pointers.java | 49 |
2 files changed, 40 insertions, 31 deletions
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index e996c50..d261725 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -195,9 +195,11 @@ class KeyboardData return new Key(key0, key1, key2, key3, key4, width * s, shift, edgekeys); } - public KeyValue getValue(int index) + + /* Get the KeyValue at the given direction. See Pointers.onTouchMove() for the represented direction */ + public KeyValue getAtDirection(int direction) { - if (index == 0 || index > 8) return key0; + if (direction == 0 || direction > 8) return key0; KeyValue key = null; if (edgekeys) { // \ 1 / @@ -207,7 +209,7 @@ class KeyboardData // / 4 \ // first closer - switch (index) + switch (direction) { case 2: case 3: key = key1; break; case 4: case 8: key = key2; break; @@ -216,7 +218,7 @@ class KeyboardData } if (key != null) return key; // second closer - switch (index) + switch (direction) { case 1: case 4: key = key1; break; case 3: case 7: key = key2; break; @@ -225,7 +227,7 @@ class KeyboardData } if (key != null) return key; // third closer - switch (index) + switch (direction) { case 5: case 8: key = key1; break; case 2: case 6: key = key2; break; @@ -234,7 +236,7 @@ class KeyboardData } if (key != null) return key; // fourth closer - switch (index) + switch (direction) { case 6: case 7: key = key1; break; case 1: case 5: key = key2; break; @@ -251,7 +253,7 @@ class KeyboardData // | // 3 | 4 // first closer - switch (index) + switch (direction) { case 1: case 2: key = key1; break; case 3: case 4: key = key2; break; @@ -260,7 +262,7 @@ class KeyboardData } if (key != null) return key; // second closer - switch (index) + switch (direction) { case 3: case 5: key = key1; break; case 2: case 8: key = key2; break; @@ -269,7 +271,7 @@ class KeyboardData } if (key != null) return key; // third closer - switch (index) + switch (direction) { case 4: case 6: key = key1; break; case 1: case 7: key = key2; break; @@ -278,7 +280,7 @@ class KeyboardData } if (key != null) return key; // fourth closer - switch (index) + switch (direction) { case 7: case 8: key = key1; break; case 3: case 4: key = key2; break; diff --git a/srcs/juloo.keyboard2/Pointers.java b/srcs/juloo.keyboard2/Pointers.java index 774ecf6..ac5ef84 100644 --- a/srcs/juloo.keyboard2/Pointers.java +++ b/srcs/juloo.keyboard2/Pointers.java @@ -135,7 +135,7 @@ public final class Pointers implements Handler.Callback return; int mflags = getFlags(isOtherPointerDown()); KeyValue value = _handler.onPointerDown(key.key0, mflags); - Pointer ptr = new Pointer(pointerId, key, 0, value, x, y, mflags); + Pointer ptr = new Pointer(pointerId, key, key.key0, value, x, y, mflags); _ptrs.add(ptr); if (value != null && (value.flags & KeyValue.FLAG_SPECIAL) == 0) startKeyRepeat(ptr); @@ -155,28 +155,33 @@ public final class Pointers implements Handler.Callback float dy = y - ptr.downY; float dist = Math.abs(dx) + Math.abs(dy); ptr.ptrDist = dist; - int newIndex; + + int direction; if (dist < _config.swipe_dist_px) { - newIndex = 0; + direction = 0; } - else { - // One of the 8 directions: - // |\2|3/| - // |1\|/4| - // |-----| - // |5/|\8| - // |/6|7\| - newIndex = 1; - if (dy > 0) newIndex += 4; - if (dx > 0) newIndex += 2; - if (dx > Math.abs(dy) || (dx < 0 && dx > -Math.abs(dy))) newIndex += 1; + else + { + // One of the 8 directions: + // |\2|3/| + // |1\|/4| + // |-----| + // |5/|\8| + // |/6|7\| + direction = 1; + if (dy > 0) direction += 4; + if (dx > 0) direction += 2; + if (dx > Math.abs(dy) || (dx < 0 && dx > -Math.abs(dy))) direction += 1; } - if (newIndex != ptr.value_index) + + KeyValue newSelectedValue = ptr.key.getAtDirection(direction); + if (newSelectedValue != ptr.selected_value) { - ptr.value_index = newIndex; + ptr.selected_value = newSelectedValue; + // apply modifier flags and trigger vibration. KeyValue newValue = - _handler.onPointerSwipe(ptr.key.getValue(newIndex), ptr.modifier_flags); + _handler.onPointerSwipe(ptr.selected_value, ptr.modifier_flags); if (newValue != null) { int old_flags = ptr.flags; @@ -308,9 +313,11 @@ public final class Pointers implements Handler.Callback { /** -1 when latched. */ public int pointerId; + /** The Key pressed by this Pointer */ public final KeyboardData.Key key; - public int value_index; - /** Modified value. Not equal to [key.getValue(value_index)]. */ + /** The current seletected KeyValue in key (any one of key0 to key4). */ + public KeyValue selected_value; + /** selected_value with modifier_flags applied. */ public KeyValue value; public float downX; public float downY; @@ -325,11 +332,11 @@ public final class Pointers implements Handler.Callback /** ptrDist at the first repeat, -1 otherwise. */ public float repeatingPtrDist; - public Pointer(int p, KeyboardData.Key k, int vi, KeyValue v, float x, float y, int mflags) + public Pointer(int p, KeyboardData.Key k, KeyValue sv, KeyValue v, float x, float y, int mflags) { pointerId = p; key = k; - value_index = vi; + selected_value = sv; value = v; downX = x; downY = y; |
