diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-07 04:05:40 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-07 04:05:40 -0400 |
commit | 42d03f38e3cccad38a1e3000e180662b378343c3 (patch) | |
tree | 9847331c4276b6b93a1c56444ec3c5982974d51a /src/us/minak/IMEGestureOverlayView.java | |
parent | c2badb0447accaa39e4f7b3d8ebb43601f2f5d8f (diff) |
Get the modifier keys working
Diffstat (limited to 'src/us/minak/IMEGestureOverlayView.java')
-rw-r--r-- | src/us/minak/IMEGestureOverlayView.java | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/us/minak/IMEGestureOverlayView.java b/src/us/minak/IMEGestureOverlayView.java index 4cfc4b5..35fe1eb 100644 --- a/src/us/minak/IMEGestureOverlayView.java +++ b/src/us/minak/IMEGestureOverlayView.java @@ -9,6 +9,7 @@ import android.gesture.Prediction; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.KeyEvent; +import android.view.KeyCharacterMap; import android.view.MotionEvent; import android.view.inputmethod.InputConnection; @@ -19,7 +20,12 @@ public class IMEGestureOverlayView extends GestureOverlayView implements OnGestu private final GestureLibrary mGestureLibrary; private InputConnectionGetter icGetter = new InputConnectionGetter.NullGetter(); private final IMEModifiers modifiers = new IMEModifiers(); + private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); float x = -1, y = -1; + int meta = 0; + + // cache for repeated calls + InputConnection ic = null; public IMEGestureOverlayView(Context context, AttributeSet attrs) { super(context, attrs); @@ -32,6 +38,18 @@ public class IMEGestureOverlayView extends GestureOverlayView implements OnGestu this.icGetter = icGetter; } + private void sendKeyEvent(KeyEvent keyEvent) { + if (ic != null) { + ic.sendKeyEvent(new KeyEvent( + keyEvent.getDownTime(), + keyEvent.getEventTime(), + keyEvent.getAction(), + keyEvent.getKeyCode(), + keyEvent.getRepeatCount(), + keyEvent.getMetaState() | meta)); + } + } + /** * This function is pretty strongly based on the code in * Samsung's "Penboard" whitepaper. @@ -44,20 +62,22 @@ public class IMEGestureOverlayView extends GestureOverlayView implements OnGestu bestPrediction = predictions.get(0); } - InputConnection ic = icGetter.getCurrentInputConnection(); + ic = icGetter.getCurrentInputConnection(); if (ic != null) { if (bestPrediction != null) { if (bestPrediction.score > SCORE_TRESHOLD) { - ic.commitText(bestPrediction.name, 1); + for (KeyEvent keyEvent : charMap.getEvents(bestPrediction.name.toCharArray())) + sendKeyEvent(keyEvent); } else { clear(false); } } for (IMEModifier modifier : modifiers.getSelection()) { - ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, modifier.keycode)); + sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, modifier.keycode)); } } modifiers.clearSelection(); + meta = 0; invalidate(); x = y = -1; } @@ -76,10 +96,11 @@ public class IMEGestureOverlayView extends GestureOverlayView implements OnGestu modifiers.setSelectionPoint(x, y); invalidate(); - InputConnection ic = icGetter.getCurrentInputConnection(); + ic = icGetter.getCurrentInputConnection(); if (ic != null) { for (IMEModifier modifier : modifiers.getSelection()) { - ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, modifier.keycode)); + sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, modifier.keycode)); + meta |= modifier.metamask; } return true; } |