aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/compat
diff options
context:
space:
mode:
authorKen Wakasa <kwakasa@google.com>2013-01-06 11:10:27 +0900
committerKen Wakasa <kwakasa@google.com>2013-01-07 12:13:42 +0900
commitb6ca354431367b625daf9fff5fbe4b1f5ef996ab (patch)
tree1358c683e123161cc04bc6ad83eb75c763ec53b3 /java/src/com/android/inputmethod/compat
parentf677681330143e3e50871222d33ade594e6348ce (diff)
downloadlatinime-b6ca354431367b625daf9fff5fbe4b1f5ef996ab.tar.gz
latinime-b6ca354431367b625daf9fff5fbe4b1f5ef996ab.tar.xz
latinime-b6ca354431367b625daf9fff5fbe4b1f5ef996ab.zip
Small code cleanups
Multi-project commit with I249d5fbe Change-Id: Ia28c4e970992aa1299a30e604eaa5d096655c3a5
Diffstat (limited to 'java/src/com/android/inputmethod/compat')
-rw-r--r--java/src/com/android/inputmethod/compat/CompatUtils.java26
-rw-r--r--java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java16
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java6
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java7
-rw-r--r--java/src/com/android/inputmethod/compat/SettingsSecureCompatUtils.java4
-rw-r--r--java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java20
-rw-r--r--java/src/com/android/inputmethod/compat/SuggestionsInfoCompatUtils.java11
7 files changed, 52 insertions, 38 deletions
diff --git a/java/src/com/android/inputmethod/compat/CompatUtils.java b/java/src/com/android/inputmethod/compat/CompatUtils.java
index ffed6ecb1..a82103ab3 100644
--- a/java/src/com/android/inputmethod/compat/CompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/CompatUtils.java
@@ -31,8 +31,8 @@ public final class CompatUtils {
private static final String INPUT_METHOD_SUBTYPE_SETTINGS =
"android.settings.INPUT_METHOD_SUBTYPE_SETTINGS";
- public static Intent getInputLanguageSelectionIntent(String inputMethodId,
- int flagsForSubtypeSettings) {
+ public static Intent getInputLanguageSelectionIntent(final String inputMethodId,
+ final int flagsForSubtypeSettings) {
// Refer to android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS
final String action = INPUT_METHOD_SUBTYPE_SETTINGS;
final Intent intent = new Intent(action);
@@ -45,7 +45,7 @@ public final class CompatUtils {
return intent;
}
- public static Class<?> getClass(String className) {
+ public static Class<?> getClass(final String className) {
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
@@ -53,8 +53,8 @@ public final class CompatUtils {
}
}
- public static Method getMethod(Class<?> targetClass, String name,
- Class<?>... parameterTypes) {
+ public static Method getMethod(final Class<?> targetClass, final String name,
+ final Class<?>... parameterTypes) {
if (targetClass == null || TextUtils.isEmpty(name)) return null;
try {
return targetClass.getMethod(name, parameterTypes);
@@ -66,7 +66,7 @@ public final class CompatUtils {
return null;
}
- public static Field getField(Class<?> targetClass, String name) {
+ public static Field getField(final Class<?> targetClass, final String name) {
if (targetClass == null || TextUtils.isEmpty(name)) return null;
try {
return targetClass.getField(name);
@@ -78,7 +78,8 @@ public final class CompatUtils {
return null;
}
- public static Constructor<?> getConstructor(Class<?> targetClass, Class<?> ... types) {
+ public static Constructor<?> getConstructor(final Class<?> targetClass,
+ final Class<?> ... types) {
if (targetClass == null || types == null) return null;
try {
return targetClass.getConstructor(types);
@@ -90,7 +91,7 @@ public final class CompatUtils {
return null;
}
- public static Object newInstance(Constructor<?> constructor, Object ... args) {
+ public static Object newInstance(final Constructor<?> constructor, final Object ... args) {
if (constructor == null) return null;
try {
return constructor.newInstance(args);
@@ -100,8 +101,8 @@ public final class CompatUtils {
return null;
}
- public static Object invoke(
- Object receiver, Object defaultValue, Method method, Object... args) {
+ public static Object invoke(final Object receiver, final Object defaultValue,
+ final Method method, final Object... args) {
if (method == null) return defaultValue;
try {
return method.invoke(receiver, args);
@@ -111,7 +112,8 @@ public final class CompatUtils {
return defaultValue;
}
- public static Object getFieldValue(Object receiver, Object defaultValue, Field field) {
+ public static Object getFieldValue(final Object receiver, final Object defaultValue,
+ final Field field) {
if (field == null) return defaultValue;
try {
return field.get(receiver);
@@ -121,7 +123,7 @@ public final class CompatUtils {
return defaultValue;
}
- public static void setFieldValue(Object receiver, Field field, Object value) {
+ public static void setFieldValue(final Object receiver, final Field field, final Object value) {
if (field == null) return;
try {
field.set(receiver, value);
diff --git a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
index 210058bec..7eefa221a 100644
--- a/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/EditorInfoCompatUtils.java
@@ -21,23 +21,23 @@ import android.view.inputmethod.EditorInfo;
import java.lang.reflect.Field;
public final class EditorInfoCompatUtils {
- // EditorInfo.IME_FLAG_FORCE_ASCII has been introduced since API#16 (JellyBean).
+ // Note that EditorInfo.IME_FLAG_FORCE_ASCII has been introduced
+ // in API level 16 (Build.VERSION_CODES.JELLY_BEAN).
private static final Field FIELD_IME_FLAG_FORCE_ASCII = CompatUtils.getField(
EditorInfo.class, "IME_FLAG_FORCE_ASCII");
- private static final Integer OBJ_IME_FLAG_FORCE_ASCII = (Integer) CompatUtils
- .getFieldValue(null, null, FIELD_IME_FLAG_FORCE_ASCII);
+ private static final Integer OBJ_IME_FLAG_FORCE_ASCII = (Integer) CompatUtils.getFieldValue(
+ null /* receiver */, null /* defaultValue */, FIELD_IME_FLAG_FORCE_ASCII);
private EditorInfoCompatUtils() {
// This utility class is not publicly instantiable.
}
- public static boolean hasFlagForceAscii(int imeOptions) {
- if (OBJ_IME_FLAG_FORCE_ASCII == null)
- return false;
+ public static boolean hasFlagForceAscii(final int imeOptions) {
+ if (OBJ_IME_FLAG_FORCE_ASCII == null) return false;
return (imeOptions & OBJ_IME_FLAG_FORCE_ASCII) != 0;
}
- public static String imeActionName(int imeOptions) {
+ public static String imeActionName(final int imeOptions) {
final int actionId = imeOptions & EditorInfo.IME_MASK_ACTION;
switch (actionId) {
case EditorInfo.IME_ACTION_UNSPECIFIED:
@@ -61,7 +61,7 @@ public final class EditorInfoCompatUtils {
}
}
- public static String imeOptionsName(int imeOptions) {
+ public static String imeOptionsName(final int imeOptions) {
final String action = imeActionName(imeOptions);
final StringBuilder flags = new StringBuilder();
if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
index 8bd1e5208..a80c3fefe 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
@@ -23,6 +23,8 @@ import android.view.inputmethod.InputMethodManager;
import java.lang.reflect.Method;
public final class InputMethodManagerCompatWrapper {
+ // Note that InputMethodManager.switchToNextInputMethod() has been introduced
+ // in API level 16 (Build.VERSION_CODES.JELLY_BEAN).
private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod(
InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE);
@@ -33,7 +35,7 @@ public final class InputMethodManagerCompatWrapper {
}
public boolean switchToNextInputMethod(final IBinder token, final boolean onlyCurrentIme) {
- return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToNextInputMethod, token,
- onlyCurrentIme);
+ return (Boolean)CompatUtils.invoke(mImm, false /* defaultValue */,
+ METHOD_switchToNextInputMethod, token, onlyCurrentIme);
}
}
diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java
index 8eea31ed2..14ee654f3 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java
@@ -21,6 +21,8 @@ import android.inputmethodservice.InputMethodService;
import java.lang.reflect.Method;
public final class InputMethodServiceCompatUtils {
+ // Note that InputMethodService.enableHardwareAcceleration() has been introduced
+ // in API level 17 (Build.VERSION_CODES.JELLY_BEAN_MR1).
private static final Method METHOD_enableHardwareAcceleration =
CompatUtils.getMethod(InputMethodService.class, "enableHardwareAcceleration");
@@ -28,7 +30,8 @@ public final class InputMethodServiceCompatUtils {
// This utility class is not publicly instantiable.
}
- public static boolean enableHardwareAcceleration(InputMethodService ims) {
- return (Boolean)CompatUtils.invoke(ims, false, METHOD_enableHardwareAcceleration);
+ public static boolean enableHardwareAcceleration(final InputMethodService ims) {
+ return (Boolean)CompatUtils.invoke(ims, false /* defaultValue */,
+ METHOD_enableHardwareAcceleration);
}
}
diff --git a/java/src/com/android/inputmethod/compat/SettingsSecureCompatUtils.java b/java/src/com/android/inputmethod/compat/SettingsSecureCompatUtils.java
index db5abd0fe..cfaf7ec77 100644
--- a/java/src/com/android/inputmethod/compat/SettingsSecureCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/SettingsSecureCompatUtils.java
@@ -19,6 +19,8 @@ package com.android.inputmethod.compat;
import java.lang.reflect.Field;
public final class SettingsSecureCompatUtils {
+ // Note that Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD has been introduced
+ // in API level 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1).
private static final Field FIELD_ACCESSIBILITY_SPEAK_PASSWORD = CompatUtils.getField(
android.provider.Settings.Secure.class, "ACCESSIBILITY_SPEAK_PASSWORD");
@@ -30,5 +32,5 @@ public final class SettingsSecureCompatUtils {
* Whether to speak passwords while in accessibility mode.
*/
public static final String ACCESSIBILITY_SPEAK_PASSWORD = (String) CompatUtils.getFieldValue(
- null, null, FIELD_ACCESSIBILITY_SPEAK_PASSWORD);
+ null /* receiver */, null /* defaultValue */, FIELD_ACCESSIBILITY_SPEAK_PASSWORD);
}
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
index 0e3634d52..141e08a8d 100644
--- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
+++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
@@ -34,11 +34,12 @@ import java.util.ArrayList;
public final class SuggestionSpanUtils {
private static final String TAG = SuggestionSpanUtils.class.getSimpleName();
- // Note that SuggestionSpan.FLAG_AUTO_CORRECTION was added in API level 15.
- public static final Field FIELD_FLAG_AUTO_CORRECTION =
- CompatUtils.getField(SuggestionSpan.class, "FLAG_AUTO_CORRECTION");
- public static final Integer OBJ_FLAG_AUTO_CORRECTION =
- (Integer) CompatUtils.getFieldValue(null, null, FIELD_FLAG_AUTO_CORRECTION);
+ // Note that SuggestionSpan.FLAG_AUTO_CORRECTION has been introduced
+ // in API level 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1).
+ public static final Field FIELD_FLAG_AUTO_CORRECTION = CompatUtils.getField(
+ SuggestionSpan.class, "FLAG_AUTO_CORRECTION");
+ public static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils.getFieldValue(
+ null /* receiver */, null /* defaultValue */, FIELD_FLAG_AUTO_CORRECTION);
static {
if (LatinImeLogger.sDBG) {
@@ -58,8 +59,9 @@ public final class SuggestionSpanUtils {
return text;
}
final Spannable spannable = new SpannableString(text);
- final SuggestionSpan suggestionSpan = new SuggestionSpan(context, null, new String[] {},
- (int)OBJ_FLAG_AUTO_CORRECTION, SuggestionSpanPickedNotificationReceiver.class);
+ final SuggestionSpan suggestionSpan = new SuggestionSpan(context, null /* locale */,
+ new String[] {} /* suggestions */, (int)OBJ_FLAG_AUTO_CORRECTION,
+ SuggestionSpanPickedNotificationReceiver.class);
spannable.setSpan(suggestionSpan, 0, text.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
return spannable;
@@ -87,8 +89,8 @@ public final class SuggestionSpanUtils {
// TODO: We should avoid adding suggestion span candidates that came from the bigram
// prediction.
- final SuggestionSpan suggestionSpan = new SuggestionSpan(context, null,
- suggestionsList.toArray(new String[suggestionsList.size()]), 0,
+ final SuggestionSpan suggestionSpan = new SuggestionSpan(context, null /* locale */,
+ suggestionsList.toArray(new String[suggestionsList.size()]), 0 /* flags */,
SuggestionSpanPickedNotificationReceiver.class);
spannable.setSpan(suggestionSpan, 0, pickedWord.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
diff --git a/java/src/com/android/inputmethod/compat/SuggestionsInfoCompatUtils.java b/java/src/com/android/inputmethod/compat/SuggestionsInfoCompatUtils.java
index 8314212c9..d8d2be04c 100644
--- a/java/src/com/android/inputmethod/compat/SuggestionsInfoCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/SuggestionsInfoCompatUtils.java
@@ -21,10 +21,13 @@ import android.view.textservice.SuggestionsInfo;
import java.lang.reflect.Field;
public final class SuggestionsInfoCompatUtils {
- private static final Field FIELD_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS = CompatUtils.getField(
- SuggestionsInfo.class, "RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS");
- private static final Integer OBJ_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS = (Integer) CompatUtils
- .getFieldValue(null, null, FIELD_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS);
+ // Note that SuggestionsInfo.RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS has been introduced
+ // in API level 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1).
+ private static final Field FIELD_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS =
+ CompatUtils.getField(SuggestionsInfo.class, "RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS");
+ private static final Integer OBJ_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS =
+ (Integer) CompatUtils.getFieldValue(null /* receiver */, null /* defaultValue */,
+ FIELD_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS);
private static final int RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS =
OBJ_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS != null
? OBJ_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS : 0;