From 24119dfd414f948b2da214c021cc76e06b3dd41c Mon Sep 17 00:00:00 2001 From: satok Date: Wed, 23 Mar 2011 16:15:07 -0700 Subject: Moved a functionality of setting touchableRegion to InputMethodServiceCompatWrapper. Change-Id: I8b9fe507885ef5ae7cb09db93a977e23b1bbd0db --- .../android/inputmethod/compat/CompatUtils.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'java/src/com/android/inputmethod/compat/CompatUtils.java') diff --git a/java/src/com/android/inputmethod/compat/CompatUtils.java b/java/src/com/android/inputmethod/compat/CompatUtils.java index fea15fda5..8bf59091f 100644 --- a/java/src/com/android/inputmethod/compat/CompatUtils.java +++ b/java/src/com/android/inputmethod/compat/CompatUtils.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.text.TextUtils; import android.util.Log; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -77,6 +78,18 @@ public class CompatUtils { } } + public static Field getField(Class targetClass, String name) { + try { + return targetClass.getField(name); + } catch (SecurityException e) { + // ignore + return null; + } catch (NoSuchFieldException e) { + // ignore + return null; + } + } + public static Object invoke( Object receiver, Object defaultValue, Method method, Object... args) { if (receiver == null || method == null) return defaultValue; @@ -94,6 +107,28 @@ public class CompatUtils { } } + public static Object getFieldValue(Object receiver, Object defaultValue, Field field) { + if (receiver == null || field == null) return defaultValue; + try { + return field.get(receiver); + } catch (IllegalArgumentException e) { + return defaultValue; + } catch (IllegalAccessException e) { + return defaultValue; + } + } + + public static void setFieldValue(Object receiver, Field field, Object value) { + if (receiver == null || field == null) return; + try { + field.set(receiver, value); + } catch (IllegalArgumentException e) { + // ignore + } catch (IllegalAccessException e) { + // ignore + } + } + public static List copyInputMethodSubtypeListToWrapper( Object listObject) { if (!(listObject instanceof List)) return null; -- cgit v1.2.3-83-g751a