abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/Keyboard2View.java
diff options
context:
space:
mode:
authorJules Aguillon2021-04-20 00:10:45 +0200
committerJules Aguillon2021-04-20 00:10:45 +0200
commit83b3212d3d880e19ed6298d1182a88207d11be07 (patch)
tree89e0c6002b8659392d56e4b6138c4047304b9a99 /srcs/juloo.keyboard2/Keyboard2View.java
parentd04e0788167c64895a3db1475e0a450f60fa0c87 (diff)
downloadunexpected-keyboard-83b3212d3d880e19ed6298d1182a88207d11be07.tar.gz
unexpected-keyboard-83b3212d3d880e19ed6298d1182a88207d11be07.zip
Add precise repeat on some keys
Repeat speed increase as the pointer is away from the initial position. On arrows, backspace and delete.
Diffstat (limited to 'srcs/juloo.keyboard2/Keyboard2View.java')
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java23
1 files changed, 18 insertions, 5 deletions
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index d8a24d8..e59dd5f 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -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;
}