From 6f18a1fbcccf9cf5ca937b08098601a4fafead29 Mon Sep 17 00:00:00 2001 From: satok Date: Mon, 28 Mar 2011 18:45:49 -0700 Subject: Disable Recorrection when APIs are not supported. Change-Id: I3b8fdc149d350215fd4852a50456824fe3fabe0b --- .../compat/InputConnectionCompatUtils.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java') 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); + } } -- cgit v1.2.3-83-g751a