use the closest swipe key on swipe

fix a direction
This commit is contained in:
Rodrigo Batista de Moraes 2022-05-06 13:38:43 -03:00 committed by Jules Aguillon
parent 7da7a5082d
commit a27c64479f
2 changed files with 107 additions and 20 deletions

View File

@ -197,14 +197,98 @@ class KeyboardData
public KeyValue getValue(int index)
{
switch (index)
{
case 1: return key1;
case 2: return key2;
case 3: return key3;
case 4: return key4;
default: case 0: return key0;
if (index == 0 || index > 8) return key0;
KeyValue key = null;
if (edgekeys) {
// \ 1 /
// \ /
// 3 0 2
// / \
// / 4 \
// first closer
switch (index)
{
case 2: case 3: key = key1; break;
case 4: case 8: key = key2; break;
case 1: case 5: key = key3; break;
case 6: case 7: key = key4; break;
}
if (key != null) return key;
// second closer
switch (index)
{
case 1: case 4: key = key1; break;
case 3: case 7: key = key2; break;
case 2: case 6: key = key3; break;
case 5: case 8: key = key4; break;
}
if (key != null) return key;
// third closer
switch (index)
{
case 5: case 8: key = key1; break;
case 2: case 6: key = key2; break;
case 3: case 7: key = key3; break;
case 1: case 4: key = key4; break;
}
if (key != null) return key;
// fourth closer
switch (index)
{
case 6: case 7: key = key1; break;
case 1: case 5: key = key2; break;
case 4: case 8: key = key3; break;
case 2: case 3: key = key4; break;
}
if (key != null) return key;
}
else
{
// 1 | 2
// |
// --0--
// |
// 3 | 4
// first closer
switch (index)
{
case 1: case 2: key = key1; break;
case 3: case 4: key = key2; break;
case 5: case 6: key = key3; break;
case 7: case 8: key = key4; break;
}
if (key != null) return key;
// second closer
switch (index)
{
case 3: case 5: key = key1; break;
case 2: case 8: key = key2; break;
case 1: case 7: key = key3; break;
case 4: case 6: key = key4; break;
}
if (key != null) return key;
// third closer
switch (index)
{
case 4: case 6: key = key1; break;
case 1: case 7: key = key2; break;
case 2: case 8: key = key3; break;
case 3: case 5: key = key4; break;
}
if (key != null) return key;
// fourth closer
switch (index)
{
case 7: case 8: key = key1; break;
case 3: case 4: key = key2; break;
case 5: case 6: key = key3; break;
case 1: case 2: key = key4; break;
}
if (key != null) return key;
}
return key0;
}
}

View File

@ -146,6 +146,11 @@ public final class Pointers implements Handler.Callback
Pointer ptr = getPtr(pointerId);
if (ptr == null)
return;
// The position in a IME windows is clampled to view.
// For a better up swipe behaviour, set the y position to a negative value when clamped.
if (y == 0.0) y = -400;
float dx = x - ptr.downX;
float dy = y - ptr.downY;
float dist = Math.abs(dx) + Math.abs(dy);
@ -155,19 +160,17 @@ public final class Pointers implements Handler.Callback
{
newIndex = 0;
}
else if (ptr.key.edgekeys)
{
if (Math.abs(dy) > Math.abs(dx)) // vertical swipe
newIndex = (dy < 0) ? 1 : 4;
else // horizontal swipe
newIndex = (dx < 0) ? 3 : 2;
}
else
{
if (dx < 0) // left side
newIndex = (dy < 0) ? 1 : 3;
else // right side
newIndex = (dy < 0) ? 2 : 4;
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;
}
if (newIndex != ptr.value_index)
{