aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-03-28 18:45:49 -0700
committersatok <satok@google.com>2011-04-01 16:09:06 +0900
commit6f18a1fbcccf9cf5ca937b08098601a4fafead29 (patch)
treef851b277ddb2ffda5f51785d549574d4f6d3f5d3 /java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
parenta1f9cdd6f5328224e926335f2beeb27b1bc166fe (diff)
downloadlatinime-6f18a1fbcccf9cf5ca937b08098601a4fafead29.tar.gz
latinime-6f18a1fbcccf9cf5ca937b08098601a4fafead29.tar.xz
latinime-6f18a1fbcccf9cf5ca937b08098601a4fafead29.zip
Disable Recorrection when APIs are not supported.
Change-Id: I3b8fdc149d350215fd4852a50456824fe3fabe0b
Diffstat (limited to 'java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java')
-rw-r--r--java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java b/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
index b4fe32765..c926be06f 100644
--- a/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java
@@ -16,6 +16,8 @@
package com.android.inputmethod.compat;
+import com.android.inputmethod.latin.EditingUtils.SelectedWord;
+
import android.util.Log;
import android.view.inputmethod.InputConnection;
@@ -33,6 +35,16 @@ public class InputConnectionCompatUtils {
.getConstructor(CLASS_CorrectionInfo, INPUT_TYPE_CorrectionInfo);
private static final Method METHOD_InputConnection_commitCorrection = CompatUtils
.getMethod(InputConnection.class, "commitCorrection", CLASS_CorrectionInfo);
+ private static final Method METHOD_getSelectedText = CompatUtils
+ .getMethod(InputConnection.class, "getSelectedText", int.class);
+ private static final Method METHOD_setComposingRegion = CompatUtils
+ .getMethod(InputConnection.class, "setComposingRegion", int.class, int.class);
+ public static final boolean RECORRECTION_SUPPORTED;
+
+ static {
+ RECORRECTION_SUPPORTED = METHOD_getSelectedText != null
+ && METHOD_setComposingRegion != null;
+ }
public static void commitCorrection(InputConnection ic, int offset, CharSequence oldText,
CharSequence newText) {
@@ -55,4 +67,25 @@ public class InputConnectionCompatUtils {
Log.e(TAG, "Error in commitCorrection: InvocationTargetException");
}
}
+
+
+ /**
+ * Returns the selected text between the selStart and selEnd positions.
+ */
+ public static CharSequence getSelectedText(InputConnection ic, int selStart, int selEnd) {
+ // Use reflection, for backward compatibility
+ return (CharSequence) CompatUtils.invoke(
+ ic, null, METHOD_getSelectedText, 0);
+ }
+
+ /**
+ * Tries to set the text into composition mode if there is support for it in the framework.
+ */
+ public static void underlineWord(InputConnection ic, SelectedWord word) {
+ // Use reflection, for backward compatibility
+ // If method not found, there's nothing we can do. It still works but just wont underline
+ // the word.
+ CompatUtils.invoke(
+ ic, null, METHOD_setComposingRegion, word.mStart, word.mEnd);
+ }
}