aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/utils
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2014-10-08 00:07:40 +0900
committerYohei Yukawa <yukawa@google.com>2014-10-09 15:54:34 +0900
commitdac49f9f6de83d9a0cb4d9e290340cde5297e0b3 (patch)
treec3af4de443e52a5a6444623a0e7f3f8fd89306bf /java/src/com/android/inputmethod/latin/utils
parent847735fdfacfda3fda0e3a1370a35896832cb8bb (diff)
downloadlatinime-dac49f9f6de83d9a0cb4d9e290340cde5297e0b3.tar.gz
latinime-dac49f9f6de83d9a0cb4d9e290340cde5297e0b3.tar.xz
latinime-dac49f9f6de83d9a0cb4d9e290340cde5297e0b3.zip
Simplify CursorAnchorInfoCompatWrapper
With this CL, we will use CursorAnchorInfoCompatWrapper just to avoid unexpected NoClassDefFoundError due to the direct dependency CursorAnchorInfo class, which is available only on API level 21 and later. Change-Id: I254ff83f1ca41daa21d0666b5824af22ba529022
Diffstat (limited to 'java/src/com/android/inputmethod/latin/utils')
-rw-r--r--java/src/com/android/inputmethod/latin/utils/CursorAnchorInfoUtils.java31
1 files changed, 29 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/latin/utils/CursorAnchorInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/CursorAnchorInfoUtils.java
index 9dc0524a2..e05618901 100644
--- a/java/src/com/android/inputmethod/latin/utils/CursorAnchorInfoUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/CursorAnchorInfoUtils.java
@@ -16,10 +16,12 @@
package com.android.inputmethod.latin.utils;
+import android.annotation.TargetApi;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.inputmethodservice.ExtractEditText;
import android.inputmethodservice.InputMethodService;
+import android.os.Build;
import android.text.Layout;
import android.text.Spannable;
import android.view.View;
@@ -27,6 +29,12 @@ import android.view.ViewParent;
import android.view.inputmethod.CursorAnchorInfo;
import android.widget.TextView;
+import com.android.inputmethod.compat.BuildCompatUtils;
+import com.android.inputmethod.compat.CursorAnchorInfoCompatWrapper;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* This class allows input methods to extract {@link CursorAnchorInfo} directly from the given
* {@link TextView}. This is useful and even necessary to support full-screen mode where the default
@@ -77,13 +85,32 @@ public final class CursorAnchorInfoUtils {
}
/**
+ * Extracts {@link CursorAnchorInfoCompatWrapper} from the given {@link TextView}.
+ * @param textView the target text view from which {@link CursorAnchorInfoCompatWrapper} is to
+ * be extracted.
+ * @return the {@link CursorAnchorInfoCompatWrapper} object based on the current layout.
+ * {@code null} if {@code Build.VERSION.SDK_INT} is 20 or prior or {@link TextView} is not
+ * ready to provide layout information.
+ */
+ @Nullable
+ public static CursorAnchorInfoCompatWrapper extractFromTextView(
+ @Nonnull final TextView textView) {
+ if (Build.VERSION.SDK_INT < BuildCompatUtils.VERSION_CODES_LXX) {
+ return null;
+ }
+ return CursorAnchorInfoCompatWrapper.wrap(extractFromTextViewInternal(textView));
+ }
+
+ /**
* Returns {@link CursorAnchorInfo} from the given {@link TextView}.
* @param textView the target text view from which {@link CursorAnchorInfo} is to be extracted.
* @return the {@link CursorAnchorInfo} object based on the current layout. {@code null} if it
* is not feasible.
*/
- public static CursorAnchorInfo getCursorAnchorInfo(final TextView textView) {
- Layout layout = textView.getLayout();
+ @TargetApi(BuildCompatUtils.VERSION_CODES_LXX)
+ @Nullable
+ private static CursorAnchorInfo extractFromTextViewInternal(@Nonnull final TextView textView) {
+ final Layout layout = textView.getLayout();
if (layout == null) {
return null;
}