summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/us/minak/IMEGestureOverlayView.java31
-rw-r--r--src/us/minak/IMEModifier.java4
-rw-r--r--src/us/minak/IMEModifiers.java6
3 files changed, 32 insertions, 9 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;
}
diff --git a/src/us/minak/IMEModifier.java b/src/us/minak/IMEModifier.java
index a3ea3fc..50dc6d3 100644
--- a/src/us/minak/IMEModifier.java
+++ b/src/us/minak/IMEModifier.java
@@ -3,9 +3,11 @@ package us.minak;
public class IMEModifier {
public final String name;
public final int keycode;
+ public final int metamask;
- public IMEModifier(String name, int keycode) {
+ public IMEModifier(String name, int keycode, int metamask) {
this.name = name;
this.keycode = keycode;
+ this.metamask = metamask;
}
}
diff --git a/src/us/minak/IMEModifiers.java b/src/us/minak/IMEModifiers.java
index 645ae4a..2766c76 100644
--- a/src/us/minak/IMEModifiers.java
+++ b/src/us/minak/IMEModifiers.java
@@ -10,9 +10,9 @@ import java.util.List;
public class IMEModifiers {
// FIXME: hard-coded configuration
private final IMEModifier[] modifiers = {
- new IMEModifier("Shift", KeyEvent.KEYCODE_SHIFT_LEFT),
- new IMEModifier("Ctrl" , KeyEvent.KEYCODE_CTRL_LEFT ),
- new IMEModifier("Alt" , KeyEvent.KEYCODE_ALT_LEFT )};
+ new IMEModifier("Shift", KeyEvent.KEYCODE_SHIFT_LEFT, KeyEvent.META_SHIFT_ON),
+ new IMEModifier("Ctrl" , KeyEvent.KEYCODE_CTRL_LEFT , KeyEvent.META_CTRL_ON ),
+ new IMEModifier("Alt" , KeyEvent.KEYCODE_ALT_LEFT , KeyEvent.META_ALT_ON )};
// Static drawing resources
private final Paint colorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);