aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/compat/CompatUtils.java
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2014-08-20 04:51:21 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-08-20 04:51:21 +0000
commit17aeaa75780591f1bf7fefcc887869fd90c88a9f (patch)
tree20d24693f1ce25357aa92e596beedba57a44a6b8 /java/src/com/android/inputmethod/compat/CompatUtils.java
parentdb818ecd849897633785621995ae75c0fc4f02d9 (diff)
parentfa39ffcf8461ad6e53a86d8957ab892a3e367d16 (diff)
downloadlatinime-17aeaa75780591f1bf7fefcc887869fd90c88a9f.tar.gz
latinime-17aeaa75780591f1bf7fefcc887869fd90c88a9f.tar.xz
latinime-17aeaa75780591f1bf7fefcc887869fd90c88a9f.zip
am fa39ffcf: Support more methods in the wrapper of CursorAnchorInfo
* commit 'fa39ffcf8461ad6e53a86d8957ab892a3e367d16': Support more methods in the wrapper of CursorAnchorInfo
Diffstat (limited to 'java/src/com/android/inputmethod/compat/CompatUtils.java')
-rw-r--r--java/src/com/android/inputmethod/compat/CompatUtils.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/compat/CompatUtils.java b/java/src/com/android/inputmethod/compat/CompatUtils.java
index 4fd2a6936..6aa2736c1 100644
--- a/java/src/com/android/inputmethod/compat/CompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/CompatUtils.java
@@ -127,4 +127,92 @@ public final class CompatUtils {
Log.e(TAG, "Exception in setFieldValue", e);
}
}
+
+ public static ClassWrapper getClassWrapper(final String className) {
+ return new ClassWrapper(getClass(className));
+ }
+
+ public static final class ClassWrapper {
+ private final Class<?> mClass;
+ public ClassWrapper(final Class<?> targetClass) {
+ mClass = targetClass;
+ }
+
+ public boolean exists() {
+ return mClass != null;
+ }
+
+ public <T> ToObjectMethodWrapper<T> getMethod(final String name,
+ final T defaultValue, final Class<?>... parameterTypes) {
+ return new ToObjectMethodWrapper<T>(CompatUtils.getMethod(mClass, name, parameterTypes),
+ defaultValue);
+ }
+
+ public ToIntMethodWrapper getPrimitiveMethod(final String name, final int defaultValue,
+ final Class<?>... parameterTypes) {
+ return new ToIntMethodWrapper(CompatUtils.getMethod(mClass, name, parameterTypes),
+ defaultValue);
+ }
+
+ public ToFloatMethodWrapper getPrimitiveMethod(final String name, final float defaultValue,
+ final Class<?>... parameterTypes) {
+ return new ToFloatMethodWrapper(CompatUtils.getMethod(mClass, name, parameterTypes),
+ defaultValue);
+ }
+
+ public ToBooleanMethodWrapper getPrimitiveMethod(final String name,
+ final boolean defaultValue, final Class<?>... parameterTypes) {
+ return new ToBooleanMethodWrapper(CompatUtils.getMethod(mClass, name, parameterTypes),
+ defaultValue);
+ }
+ }
+
+ public static final class ToObjectMethodWrapper<T> {
+ private final Method mMethod;
+ private final T mDefaultValue;
+ public ToObjectMethodWrapper(final Method method, final T defaultValue) {
+ mMethod = method;
+ mDefaultValue = defaultValue;
+ }
+ @SuppressWarnings("unchecked")
+ public T invoke(final Object receiver, final Object... args) {
+ return (T) CompatUtils.invoke(receiver, mDefaultValue, mMethod, args);
+ }
+ }
+
+ public static final class ToIntMethodWrapper {
+ private final Method mMethod;
+ private final int mDefaultValue;
+ public ToIntMethodWrapper(final Method method, final int defaultValue) {
+ mMethod = method;
+ mDefaultValue = defaultValue;
+ }
+ public int invoke(final Object receiver, final Object... args) {
+ return (int) CompatUtils.invoke(receiver, mDefaultValue, mMethod, args);
+ }
+ }
+
+ public static final class ToFloatMethodWrapper {
+ private final Method mMethod;
+ private final float mDefaultValue;
+ public ToFloatMethodWrapper(final Method method, final float defaultValue) {
+ mMethod = method;
+ mDefaultValue = defaultValue;
+ }
+ public float invoke(final Object receiver, final Object... args) {
+ return (float) CompatUtils.invoke(receiver, mDefaultValue, mMethod, args);
+ }
+ }
+
+ public static final class ToBooleanMethodWrapper {
+ private final Method mMethod;
+ private final boolean mDefaultValue;
+ public ToBooleanMethodWrapper(final Method method, final boolean defaultValue) {
+ mMethod = method;
+ mDefaultValue = defaultValue;
+ }
+ public boolean invoke(final Object receiver, final Object... args) {
+ return (boolean) CompatUtils.invoke(receiver, mDefaultValue, mMethod, args);
+ }
+ }
}