Fix vibration when pointer move slightly

Fix the bug introduced in the parent commit.
This commit is contained in:
Jules Aguillon 2022-05-08 16:53:33 +02:00
parent b15ca662c2
commit 82d3290c6a
2 changed files with 17 additions and 24 deletions

View File

@ -96,24 +96,15 @@ public class Keyboard2View extends View
invalidate(); invalidate();
} }
public KeyValue onPointerDown(KeyValue k, int flags) public KeyValue modifyKey(KeyValue k, int flags)
{ {
k = KeyModifier.handleFlags(k, flags); return KeyModifier.handleFlags(k, flags);
invalidate();
if (k != null)
vibrate();
return k;
} }
public KeyValue onPointerSwipe(KeyValue k, int flags) public void onPointerDown(boolean isSwipe)
{ {
k = KeyModifier.handleFlags(k, flags); invalidate();
if (k != null) vibrate();
{
invalidate();
vibrate();
}
return k;
} }
public void onPointerUp(KeyValue k, int flags) public void onPointerUp(KeyValue k, int flags)

View File

@ -134,11 +134,12 @@ public final class Pointers implements Handler.Callback
if (isModulatedKeyPressed()) if (isModulatedKeyPressed())
return; return;
int mflags = getFlags(isOtherPointerDown()); int mflags = getFlags(isOtherPointerDown());
KeyValue value = _handler.onPointerDown(key.key0, mflags); KeyValue value = _handler.modifyKey(key.key0, mflags);
Pointer ptr = new Pointer(pointerId, key, value, x, y, mflags); Pointer ptr = new Pointer(pointerId, key, value, x, y, mflags);
_ptrs.add(ptr); _ptrs.add(ptr);
if (value != null && (value.flags & KeyValue.FLAG_SPECIAL) == 0) if (value != null && (value.flags & KeyValue.FLAG_SPECIAL) == 0)
startKeyRepeat(ptr); startKeyRepeat(ptr);
_handler.onPointerDown(false);
} }
/* /*
@ -152,14 +153,14 @@ public final class Pointers implements Handler.Callback
private KeyValue getKeyAtDirection(Pointer ptr, int direction) private KeyValue getKeyAtDirection(Pointer ptr, int direction)
{ {
if (direction == 0) if (direction == 0)
return _handler.onPointerSwipe(ptr.key.key0, ptr.modifier_flags); return _handler.modifyKey(ptr.key.key0, ptr.modifier_flags);
KeyValue k; KeyValue k;
for (int i = 0; i > -2; i = (~i>>31) - i) for (int i = 0; i > -2; i = (~i>>31) - i)
{ {
int d = Math.floorMod(direction + i - 1, 8) + 1; int d = Math.floorMod(direction + i - 1, 8) + 1;
// Don't make the difference between a key that doesn't exist and a key // Don't make the difference between a key that doesn't exist and a key
// that is removed by [_handler]. Triggers side effects. // that is removed by [_handler]. Triggers side effects.
k = _handler.onPointerSwipe(ptr.key.getAtDirection(d), ptr.modifier_flags); k = _handler.modifyKey(ptr.key.getAtDirection(d), ptr.modifier_flags);
if (k != null) if (k != null)
return k; return k;
} }
@ -216,6 +217,7 @@ public final class Pointers implements Handler.Callback
if ((newValue.flags & KeyValue.FLAG_SPECIAL) == 0) if ((newValue.flags & KeyValue.FLAG_SPECIAL) == 0)
startKeyRepeat(ptr); startKeyRepeat(ptr);
} }
_handler.onPointerDown(true);
} }
} }
} }
@ -372,15 +374,15 @@ public final class Pointers implements Handler.Callback
public interface IPointerEventHandler public interface IPointerEventHandler
{ {
/** A key is pressed. Key can be modified or removed by returning [null]. /** Key can be modified or removed by returning [null]. */
[getFlags()] is not uptodate. */ public KeyValue modifyKey(KeyValue k, int flags);
public KeyValue onPointerDown(KeyValue k, int flags);
/** Pointer swipes into a corner. Key can be modified or removed. */ /** A key is pressed. [getFlags()] is uptodate. Might be called after a
public KeyValue onPointerSwipe(KeyValue k, int flags); press or a swipe to a different value. */
public void onPointerDown(boolean isSwipe);
/** Key is released. [k] is the key that was returned by [onPointerDown] or /** Key is released. [k] is the key that was returned by
[onPointerSwipe]. */ [modifySelectedKey] or [modifySelectedKey]. */
public void onPointerUp(KeyValue k, int flags); public void onPointerUp(KeyValue k, int flags);
/** Flags changed because latched or locked keys or cancelled pointers. */ /** Flags changed because latched or locked keys or cancelled pointers. */