From 610f1dc8553cf2ed97e763a06a19380c4a6cd636 Mon Sep 17 00:00:00 2001 From: satok Date: Thu, 17 Mar 2011 22:49:06 -0700 Subject: Use reflections for classes related to InputMethodSubtype Change-Id: Ica53ce879c2b4c5eb47f757fb788a795a881c30e --- .../android/inputmethod/compat/CompatUtils.java | 56 ++++++++++++++++++++++ 1 file changed, 56 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 e1e812d83..157446654 100644 --- a/java/src/com/android/inputmethod/compat/CompatUtils.java +++ b/java/src/com/android/inputmethod/compat/CompatUtils.java @@ -18,8 +18,15 @@ package com.android.inputmethod.compat; import android.content.Intent; import android.text.TextUtils; +import android.util.Log; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; public class CompatUtils { + private static final String TAG = CompatUtils.class.getSimpleName(); private static final String EXTRA_INPUT_METHOD_ID = "input_method_id"; // TODO: Can these be constants instead of literal String constants? private static final String INPUT_METHOD_SUBTYPE_SETTINGS = @@ -48,4 +55,53 @@ public class CompatUtils { } return intent; } + + public static Class getClass(String className) { + try { + return Class.forName(className); + } catch (ClassNotFoundException e) { + return null; + } + } + + public static Method getMethod(Class targetClass, String name, + Class... parameterTypes) { + try { + return targetClass.getMethod(name, parameterTypes); + } catch (SecurityException e) { + // ignore + return null; + } catch (NoSuchMethodException e) { + // ignore + return null; + } + } + + public static Object invoke( + Object receiver, Object defaultValue, Method method, Object... args) { + if (receiver == null || method == null) return defaultValue; + try { + return method.invoke(receiver, args); + } catch (IllegalArgumentException e) { + Log.e(TAG, "Exception in invoke: IllegalArgmentException"); + return defaultValue; + } catch (IllegalAccessException e) { + Log.e(TAG, "Exception in invoke: IllegalAccessException"); + return defaultValue; + } catch (InvocationTargetException e) { + Log.e(TAG, "Exception in invoke: IllegalTargetException"); + return defaultValue; + } + } + + public static List copyInputMethodSubtypeListToWrappler( + Object listObject) { + if (!(listObject instanceof List)) return null; + final List subtypes = + new ArrayList(); + for (Object o: (List)listObject) { + subtypes.add(new InputMethodSubtypeCompatWrapper(o)); + } + return subtypes; + } } -- cgit v1.2.3-83-g751a