forked from extern/Unexpected-Keyboard
Compare commits
1 Commits
master
...
repeat-sen
Author | SHA1 | Date | |
---|---|---|---|
|
8662f3afd4 |
@ -15,4 +15,5 @@
|
|||||||
<dimen name="extra_horizontal_margin">0dp</dimen>
|
<dimen name="extra_horizontal_margin">0dp</dimen>
|
||||||
<bool name="debug_logs" product="debug">true</bool>
|
<bool name="debug_logs" product="debug">true</bool>
|
||||||
<bool name="debug_logs" product="default">false</bool>
|
<bool name="debug_logs" product="default">false</bool>
|
||||||
|
<dimen name="pointer_too_close">10dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -17,9 +17,10 @@ final class Config
|
|||||||
// From resources
|
// From resources
|
||||||
public final float marginTop;
|
public final float marginTop;
|
||||||
public final float keyPadding;
|
public final float keyPadding;
|
||||||
|
|
||||||
public final float labelTextSize;
|
public final float labelTextSize;
|
||||||
public final float sublabelTextSize;
|
public final float sublabelTextSize;
|
||||||
|
/** Presses within this radius of an other pointer are ignored */
|
||||||
|
public final float pointerTooClose;
|
||||||
|
|
||||||
// From preferences
|
// From preferences
|
||||||
public int layout; // Or '-1' for the system defaults
|
public int layout; // Or '-1' for the system defaults
|
||||||
@ -57,6 +58,7 @@ final class Config
|
|||||||
keyPadding = res.getDimension(R.dimen.key_padding);
|
keyPadding = res.getDimension(R.dimen.key_padding);
|
||||||
labelTextSize = res.getFloat(R.integer.label_text_size);
|
labelTextSize = res.getFloat(R.integer.label_text_size);
|
||||||
sublabelTextSize = res.getFloat(R.integer.sublabel_text_size);
|
sublabelTextSize = res.getFloat(R.integer.sublabel_text_size);
|
||||||
|
pointerTooClose = res.getDimension(R.dimen.pointer_too_close);
|
||||||
// default values
|
// default values
|
||||||
layout = -1;
|
layout = -1;
|
||||||
vibrateEnabled = true;
|
vibrateEnabled = true;
|
||||||
|
@ -107,6 +107,10 @@ public final class Pointers implements Handler.Callback
|
|||||||
|
|
||||||
public void onTouchDown(float x, float y, int pointerId, KeyboardData.Key key)
|
public void onTouchDown(float x, float y, int pointerId, KeyboardData.Key key)
|
||||||
{
|
{
|
||||||
|
// Ignore new pointers that are too close to an existing pointer. This
|
||||||
|
// might be glitches.
|
||||||
|
if (isPointerNearby(x, y))
|
||||||
|
return;
|
||||||
KeyValue value = key.key0;
|
KeyValue value = key.key0;
|
||||||
Pointer ptr = new Pointer(pointerId, key, value, x, y);
|
Pointer ptr = new Pointer(pointerId, key, value, x, y);
|
||||||
_ptrs.add(ptr);
|
_ptrs.add(ptr);
|
||||||
@ -123,7 +127,8 @@ public final class Pointers implements Handler.Callback
|
|||||||
float dx = x - ptr.downX;
|
float dx = x - ptr.downX;
|
||||||
float dy = y - ptr.downY;
|
float dy = y - ptr.downY;
|
||||||
float dist = Math.abs(dx) + Math.abs(dy);
|
float dist = Math.abs(dx) + Math.abs(dy);
|
||||||
ptr.ptrDist = dist;
|
ptr.ptrDistX = dx;
|
||||||
|
ptr.ptrDistY = dy;
|
||||||
KeyValue newValue;
|
KeyValue newValue;
|
||||||
if (dist < _config.swipe_dist_px)
|
if (dist < _config.swipe_dist_px)
|
||||||
{
|
{
|
||||||
@ -199,6 +204,20 @@ public final class Pointers implements Handler.Callback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check if a pointer is within a radius of 'pointerTooClose' */
|
||||||
|
private boolean isPointerNearby(float x, float y)
|
||||||
|
{
|
||||||
|
for (Pointer p : _ptrs)
|
||||||
|
{
|
||||||
|
float dx = p.downX + p.ptrDistX - x;
|
||||||
|
float dy = p.downY + p.ptrDistY - y;
|
||||||
|
float d = Math.abs(dx) + Math.abs(dy);
|
||||||
|
if (d < _config.pointerTooClose)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Key repeat
|
// Key repeat
|
||||||
|
|
||||||
/** Message from [_keyrepeat_handler]. */
|
/** Message from [_keyrepeat_handler]. */
|
||||||
@ -250,12 +269,13 @@ public final class Pointers implements Handler.Callback
|
|||||||
|
|
||||||
private float modulatePreciseRepeat(Pointer ptr)
|
private float modulatePreciseRepeat(Pointer ptr)
|
||||||
{
|
{
|
||||||
|
float ptrDist = Math.abs(ptr.ptrDistX) + Math.abs(ptr.ptrDistY);
|
||||||
if (ptr.repeatingPtrDist < 0.f)
|
if (ptr.repeatingPtrDist < 0.f)
|
||||||
ptr.repeatingPtrDist = ptr.ptrDist; // First repeat
|
ptr.repeatingPtrDist = ptrDist; // First repeat
|
||||||
if (ptr.ptrDist > ptr.repeatingPtrDist * 2.f)
|
if (ptrDist > ptr.repeatingPtrDist * 2.f)
|
||||||
ptr.repeatingPtrDist = ptr.ptrDist / 2.f; // Large swipe, move the middle point
|
ptr.repeatingPtrDist = ptrDist / 2.f; // Large swipe, move the middle point
|
||||||
float left = ptr.repeatingPtrDist / 2.f;
|
float left = ptr.repeatingPtrDist / 2.f;
|
||||||
float accel = (ptr.ptrDist - left) / (ptr.repeatingPtrDist - left);
|
float accel = (ptrDist - left) / (ptr.repeatingPtrDist - left);
|
||||||
return Math.min(8.f, Math.max(0.1f, accel));
|
return Math.min(8.f, Math.max(0.1f, accel));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +288,8 @@ public final class Pointers implements Handler.Callback
|
|||||||
public float downX;
|
public float downX;
|
||||||
public float downY;
|
public float downY;
|
||||||
/** Distance of the pointer to the initial press. */
|
/** Distance of the pointer to the initial press. */
|
||||||
public float ptrDist;
|
public float ptrDistX;
|
||||||
|
public float ptrDistY;
|
||||||
public int flags;
|
public int flags;
|
||||||
/** Identify timeout messages. */
|
/** Identify timeout messages. */
|
||||||
public int timeoutWhat;
|
public int timeoutWhat;
|
||||||
@ -282,7 +303,8 @@ public final class Pointers implements Handler.Callback
|
|||||||
value = v;
|
value = v;
|
||||||
downX = x;
|
downX = x;
|
||||||
downY = y;
|
downY = y;
|
||||||
ptrDist = 0.f;
|
ptrDistX = 0.f;
|
||||||
|
ptrDistY = 0.f;
|
||||||
flags = (v == null) ? 0 : v.flags;
|
flags = (v == null) ? 0 : v.flags;
|
||||||
timeoutWhat = -1;
|
timeoutWhat = -1;
|
||||||
repeatingPtrDist = -1.f;
|
repeatingPtrDist = -1.f;
|
||||||
|
Loading…
Reference in New Issue
Block a user