Loading java/src/com/android/inputmethod/compat/CompatUtils.java +32 −21 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.util.Log; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public final class CompatUtils { Loading @@ -33,31 +34,31 @@ public final class CompatUtils { public static Class<?> getClass(final String className) { try { return Class.forName(className); } catch (ClassNotFoundException e) { } catch (final ClassNotFoundException e) { return null; } } public static Method getMethod(final Class<?> targetClass, final String name, final Class<?>... parameterTypes) { if (targetClass == null || TextUtils.isEmpty(name)) return null; if (targetClass == null || TextUtils.isEmpty(name)) { return null; } try { return targetClass.getMethod(name, parameterTypes); } catch (SecurityException e) { // ignore } catch (NoSuchMethodException e) { } catch (final SecurityException | NoSuchMethodException e) { // ignore } return null; } public static Field getField(final Class<?> targetClass, final String name) { if (targetClass == null || TextUtils.isEmpty(name)) return null; if (targetClass == null || TextUtils.isEmpty(name)) { return null; } try { return targetClass.getField(name); } catch (SecurityException e) { // ignore } catch (NoSuchFieldException e) { } catch (final SecurityException | NoSuchFieldException e) { // ignore } return null; Loading @@ -65,22 +66,25 @@ public final class CompatUtils { public static Constructor<?> getConstructor(final Class<?> targetClass, final Class<?> ... types) { if (targetClass == null || types == null) return null; if (targetClass == null || types == null) { return null; } try { return targetClass.getConstructor(types); } catch (SecurityException e) { // ignore } catch (NoSuchMethodException e) { } catch (final SecurityException | NoSuchMethodException e) { // ignore } return null; } public static Object newInstance(final Constructor<?> constructor, final Object ... args) { if (constructor == null) return null; if (constructor == null) { return null; } try { return constructor.newInstance(args); } catch (Exception e) { } catch (final InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { Log.e(TAG, "Exception in newInstance", e); } return null; Loading @@ -88,10 +92,13 @@ public final class CompatUtils { public static Object invoke(final Object receiver, final Object defaultValue, final Method method, final Object... args) { if (method == null) return defaultValue; if (method == null) { return defaultValue; } try { return method.invoke(receiver, args); } catch (Exception e) { } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { Log.e(TAG, "Exception in invoke", e); } return defaultValue; Loading @@ -99,20 +106,24 @@ public final class CompatUtils { public static Object getFieldValue(final Object receiver, final Object defaultValue, final Field field) { if (field == null) return defaultValue; if (field == null) { return defaultValue; } try { return field.get(receiver); } catch (Exception e) { } catch (final IllegalAccessException | IllegalArgumentException e) { Log.e(TAG, "Exception in getFieldValue", e); } return defaultValue; } public static void setFieldValue(final Object receiver, final Field field, final Object value) { if (field == null) return; if (field == null) { return; } try { field.set(receiver, value); } catch (Exception e) { } catch (final IllegalAccessException | IllegalArgumentException e) { Log.e(TAG, "Exception in setFieldValue", e); } } Loading java/src/com/android/inputmethod/compat/DownloadManagerCompatUtils.java +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ public final class DownloadManagerCompatUtils { // DownloadManager.Request#setAllowedOverMetered() has been introduced // in API level 16 (Build.VERSION_CODES.JELLY_BEAN). private static final Method METHOD_setAllowedOverMetered = CompatUtils.getMethod( DownloadManager.Request.class, "setAllowedOverMetered", Boolean.TYPE); DownloadManager.Request.class, "setAllowedOverMetered", boolean.class); public static DownloadManager.Request setAllowedOverMetered( final DownloadManager.Request request, final boolean allowOverMetered) { Loading java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ 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); InputMethodManager.class, "switchToNextInputMethod", IBinder.class, boolean.class); // Note that InputMethodManager.shouldOfferSwitchingToNextInputMethod() has been introduced // in API level 19 (Build.VERSION_CODES.KITKAT). Loading java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ public final class InputMethodSubtypeCompatUtils { // has been introduced in API level 17 (Build.VERSION_CODE.JELLY_BEAN_MR1). private static final Constructor<?> CONSTRUCTOR_INPUT_METHOD_SUBTYPE = CompatUtils.getConstructor(InputMethodSubtype.class, Integer.TYPE, Integer.TYPE, String.class, String.class, String.class, Boolean.TYPE, Boolean.TYPE, Integer.TYPE); int.class, int.class, String.class, String.class, String.class, boolean.class, boolean.class, int.class); static { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (CONSTRUCTOR_INPUT_METHOD_SUBTYPE == null) { Loading java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -34,9 +34,9 @@ import java.util.ArrayList; public final class SuggestionSpanUtils { // 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( private 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( private static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils.getFieldValue( null /* receiver */, null /* defaultValue */, FIELD_FLAG_AUTO_CORRECTION); static { Loading Loading
java/src/com/android/inputmethod/compat/CompatUtils.java +32 −21 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.util.Log; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public final class CompatUtils { Loading @@ -33,31 +34,31 @@ public final class CompatUtils { public static Class<?> getClass(final String className) { try { return Class.forName(className); } catch (ClassNotFoundException e) { } catch (final ClassNotFoundException e) { return null; } } public static Method getMethod(final Class<?> targetClass, final String name, final Class<?>... parameterTypes) { if (targetClass == null || TextUtils.isEmpty(name)) return null; if (targetClass == null || TextUtils.isEmpty(name)) { return null; } try { return targetClass.getMethod(name, parameterTypes); } catch (SecurityException e) { // ignore } catch (NoSuchMethodException e) { } catch (final SecurityException | NoSuchMethodException e) { // ignore } return null; } public static Field getField(final Class<?> targetClass, final String name) { if (targetClass == null || TextUtils.isEmpty(name)) return null; if (targetClass == null || TextUtils.isEmpty(name)) { return null; } try { return targetClass.getField(name); } catch (SecurityException e) { // ignore } catch (NoSuchFieldException e) { } catch (final SecurityException | NoSuchFieldException e) { // ignore } return null; Loading @@ -65,22 +66,25 @@ public final class CompatUtils { public static Constructor<?> getConstructor(final Class<?> targetClass, final Class<?> ... types) { if (targetClass == null || types == null) return null; if (targetClass == null || types == null) { return null; } try { return targetClass.getConstructor(types); } catch (SecurityException e) { // ignore } catch (NoSuchMethodException e) { } catch (final SecurityException | NoSuchMethodException e) { // ignore } return null; } public static Object newInstance(final Constructor<?> constructor, final Object ... args) { if (constructor == null) return null; if (constructor == null) { return null; } try { return constructor.newInstance(args); } catch (Exception e) { } catch (final InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { Log.e(TAG, "Exception in newInstance", e); } return null; Loading @@ -88,10 +92,13 @@ public final class CompatUtils { public static Object invoke(final Object receiver, final Object defaultValue, final Method method, final Object... args) { if (method == null) return defaultValue; if (method == null) { return defaultValue; } try { return method.invoke(receiver, args); } catch (Exception e) { } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { Log.e(TAG, "Exception in invoke", e); } return defaultValue; Loading @@ -99,20 +106,24 @@ public final class CompatUtils { public static Object getFieldValue(final Object receiver, final Object defaultValue, final Field field) { if (field == null) return defaultValue; if (field == null) { return defaultValue; } try { return field.get(receiver); } catch (Exception e) { } catch (final IllegalAccessException | IllegalArgumentException e) { Log.e(TAG, "Exception in getFieldValue", e); } return defaultValue; } public static void setFieldValue(final Object receiver, final Field field, final Object value) { if (field == null) return; if (field == null) { return; } try { field.set(receiver, value); } catch (Exception e) { } catch (final IllegalAccessException | IllegalArgumentException e) { Log.e(TAG, "Exception in setFieldValue", e); } } Loading
java/src/com/android/inputmethod/compat/DownloadManagerCompatUtils.java +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ public final class DownloadManagerCompatUtils { // DownloadManager.Request#setAllowedOverMetered() has been introduced // in API level 16 (Build.VERSION_CODES.JELLY_BEAN). private static final Method METHOD_setAllowedOverMetered = CompatUtils.getMethod( DownloadManager.Request.class, "setAllowedOverMetered", Boolean.TYPE); DownloadManager.Request.class, "setAllowedOverMetered", boolean.class); public static DownloadManager.Request setAllowedOverMetered( final DownloadManager.Request request, final boolean allowOverMetered) { Loading
java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ 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); InputMethodManager.class, "switchToNextInputMethod", IBinder.class, boolean.class); // Note that InputMethodManager.shouldOfferSwitchingToNextInputMethod() has been introduced // in API level 19 (Build.VERSION_CODES.KITKAT). Loading
java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ public final class InputMethodSubtypeCompatUtils { // has been introduced in API level 17 (Build.VERSION_CODE.JELLY_BEAN_MR1). private static final Constructor<?> CONSTRUCTOR_INPUT_METHOD_SUBTYPE = CompatUtils.getConstructor(InputMethodSubtype.class, Integer.TYPE, Integer.TYPE, String.class, String.class, String.class, Boolean.TYPE, Boolean.TYPE, Integer.TYPE); int.class, int.class, String.class, String.class, String.class, boolean.class, boolean.class, int.class); static { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (CONSTRUCTOR_INPUT_METHOD_SUBTYPE == null) { Loading
java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -34,9 +34,9 @@ import java.util.ArrayList; public final class SuggestionSpanUtils { // 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( private 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( private static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils.getFieldValue( null /* receiver */, null /* defaultValue */, FIELD_FLAG_AUTO_CORRECTION); static { Loading