Add precise repeat on some keys

Repeat speed increase as the pointer is away from the initial position.
On arrows, backspace and delete.
This commit is contained in:
Jules Aguillon 2021-04-20 00:10:45 +02:00
parent d04e078816
commit 83b3212d3d
2 changed files with 47 additions and 28 deletions

View File

@ -15,26 +15,32 @@ class KeyValue
public static final int EVENT_CHANGE_METHOD = -7;
public static final char CHAR_NONE = '\0';
public static final int FLAG_KEEP_ON = 1;
public static final int FLAG_LOCK = (1 << 1);
public static final int FLAG_CTRL = (1 << 2);
public static final int FLAG_SHIFT = (1 << 3);
public static final int FLAG_ALT = (1 << 4);
public static final int FLAG_NOREPEAT = (1 << 5);
public static final int FLAG_NOCHAR = (1 << 6);
public static final int FLAG_LOCKED = (1 << 8);
public static final int FLAG_FN = (1 << 9);
// Behavior flags
public static final int FLAG_KEEP_ON = 1;
public static final int FLAG_LOCK = (1 << 1);
public static final int FLAG_NOREPEAT = (1 << 2);
public static final int FLAG_NOCHAR = (1 << 3);
public static final int FLAG_PRECISE_REPEAT = (1 << 4);
public static final int FLAG_KEY_FONT = (1 << 5);
public static final int FLAG_KEY_FONT = (1 << 12);
// Internal flags
public static final int FLAG_LOCKED = (1 << 8);
public static final int FLAG_ACCENT1 = (1 << 16);
public static final int FLAG_ACCENT2 = (1 << 17); // Accent aigu
public static final int FLAG_ACCENT3 = (1 << 18); // Circonflexe
public static final int FLAG_ACCENT4 = (1 << 19);
public static final int FLAG_ACCENT5 = (1 << 20); // Cédille
public static final int FLAG_ACCENT6 = (1 << 21);
// Modifier flags
public static final int FLAG_CTRL = (1 << 10);
public static final int FLAG_SHIFT = (1 << 11);
public static final int FLAG_ALT = (1 << 12);
public static final int FLAG_FN = (1 << 13);
public static final int FLAGS_ACCENTS = FLAG_ACCENT1 | FLAG_ACCENT2 |
// Accent flags
public static final int FLAG_ACCENT1 = (1 << 16); // Grave
public static final int FLAG_ACCENT2 = (1 << 17); // Aigu
public static final int FLAG_ACCENT3 = (1 << 18); // Circonflexe
public static final int FLAG_ACCENT4 = (1 << 19); // Tilde
public static final int FLAG_ACCENT5 = (1 << 20); // Cédille
public static final int FLAG_ACCENT6 = (1 << 21); // Tréma
public static final int FLAGS_ACCENTS = FLAG_ACCENT1 | FLAG_ACCENT2 |
FLAG_ACCENT3 | FLAG_ACCENT4 | FLAG_ACCENT5 | FLAG_ACCENT6;
public final String name;
@ -161,16 +167,16 @@ class KeyValue
addEventKey("esc", "Esc", KeyEvent.KEYCODE_ESCAPE);
addEventKey("enter", "\uE800", KeyEvent.KEYCODE_ENTER, FLAG_KEY_FONT);
addEventKey("up", "\uE80B", KeyEvent.KEYCODE_DPAD_UP, FLAG_KEY_FONT);
addEventKey("right", "\uE80C", KeyEvent.KEYCODE_DPAD_RIGHT, FLAG_KEY_FONT);
addEventKey("down", "\uE809", KeyEvent.KEYCODE_DPAD_DOWN, FLAG_KEY_FONT);
addEventKey("left", "\uE80A", KeyEvent.KEYCODE_DPAD_LEFT, FLAG_KEY_FONT);
addEventKey("up", "\uE80B", KeyEvent.KEYCODE_DPAD_UP, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
addEventKey("right", "\uE80C", KeyEvent.KEYCODE_DPAD_RIGHT, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
addEventKey("down", "\uE809", KeyEvent.KEYCODE_DPAD_DOWN, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
addEventKey("left", "\uE80A", KeyEvent.KEYCODE_DPAD_LEFT, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
addEventKey("page_up", "", KeyEvent.KEYCODE_PAGE_DOWN);
addEventKey("page_down", "", KeyEvent.KEYCODE_PAGE_UP);
addEventKey("home", "", KeyEvent.KEYCODE_HOME);
addEventKey("end", "", KeyEvent.KEYCODE_MOVE_END);
addEventKey("backspace", "", KeyEvent.KEYCODE_DEL);
addEventKey("delete", "", KeyEvent.KEYCODE_FORWARD_DEL);
addEventKey("backspace", "", KeyEvent.KEYCODE_DEL, FLAG_PRECISE_REPEAT);
addEventKey("delete", "", KeyEvent.KEYCODE_FORWARD_DEL, FLAG_PRECISE_REPEAT);
addEventKey("insert", "Ins", KeyEvent.KEYCODE_INSERT);
addEventKey("f1", "F1", KeyEvent.KEYCODE_F1);
addEventKey("f2", "F2", KeyEvent.KEYCODE_F2);

View File

@ -159,7 +159,9 @@ public class Keyboard2View extends View
{
moveX -= key.downX;
moveY -= key.downY;
if ((Math.abs(moveX) + Math.abs(moveY)) < _config.subValueDist)
float absDist = Math.abs(moveX) + Math.abs(moveY);
key.ptrDist = absDist;
if (absDist < _config.subValueDist)
newValue = key.key.key0;
else if (moveX < 0)
newValue = (moveY < 0) ? key.key.key1 : key.key.key3;
@ -302,15 +304,23 @@ public class Keyboard2View extends View
@Override
public boolean handleMessage(Message msg)
{
long now = System.currentTimeMillis();
for (KeyDown key : _downKeys)
{
if (key.timeoutWhat == msg.what)
{
_handler.sendEmptyMessageDelayed(msg.what, _config.longPressInterval);
long nextInterval = _config.longPressInterval;
boolean doVibrate = true;
if ((key.flags & KeyValue.FLAG_PRECISE_REPEAT) != 0)
{
// Modulate repeat interval depending on the distance of the pointer
float accel = Math.min(4.f, Math.max(0.3f, key.ptrDist / (_config.subValueDist * 15.f)));
nextInterval = (long)((float)nextInterval / accel);
doVibrate = false;
}
_handler.sendEmptyMessageDelayed(msg.what, nextInterval);
((Keyboard2)getContext()).handleKeyUp(key.value, _flags);
vibrate();
if (doVibrate)
vibrate();
return (true);
}
}
@ -399,6 +409,8 @@ public class Keyboard2View extends View
public KeyboardData.Key key;
public float downX;
public float downY;
/* Manhattan distance of the pointer to the center of the key */
public float ptrDist;
public int flags;
public int timeoutWhat;
@ -409,6 +421,7 @@ public class Keyboard2View extends View
this.key = key;
downX = x;
downY = y;
ptrDist = 0.f;
flags = (value == null) ? 0 : value.flags;
timeoutWhat = what;
}