aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-10-29 00:37:41 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-10-29 00:37:43 +0000
commit48ee473c1e4d6eb1c76eeadce4a1fa3e101867a1 (patch)
treef7109cd4b1c6c6eb87b7d2a7d36df37d68a606d2
parent4beeb9253a06482299e0c67467531d30436a02fc (diff)
parentdccf4f2a41f3aeb5961e390c9ab7cd800ca14598 (diff)
downloadlatinime-48ee473c1e4d6eb1c76eeadce4a1fa3e101867a1.tar.gz
latinime-48ee473c1e4d6eb1c76eeadce4a1fa3e101867a1.tar.xz
latinime-48ee473c1e4d6eb1c76eeadce4a1fa3e101867a1.zip
Merge "Clean up UserDictionaryCompatUtils"
-rw-r--r--java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java43
1 files changed, 17 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java
index 1fb597ba6..b78c357ab 100644
--- a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java
@@ -16,42 +16,33 @@
package com.android.inputmethod.compat;
+import android.annotation.TargetApi;
import android.content.Context;
-import android.provider.UserDictionary.Words;
+import android.os.Build;
+import android.provider.UserDictionary;
-import java.lang.reflect.Method;
import java.util.Locale;
public final class UserDictionaryCompatUtils {
- // UserDictionary.Words#addWord(Context, String, int, String, Locale) was introduced
- // in API level 16 (Build.VERSION_CODES.JELLY_BEAN).
- private static final Method METHOD_addWord = CompatUtils.getMethod(Words.class, "addWord",
- Context.class, String.class, int.class, String.class, Locale.class);
-
@SuppressWarnings("deprecation")
public static void addWord(final Context context, final String word,
final int freq, final String shortcut, final Locale locale) {
- if (hasNewerAddWord()) {
- CompatUtils.invoke(Words.class, null, METHOD_addWord, context, word, freq, shortcut,
- locale);
- } else {
- // Fall back to the pre-JellyBean method.
- final int localeType;
- if (null == locale) {
- localeType = Words.LOCALE_TYPE_ALL;
- } else {
- final Locale currentLocale = context.getResources().getConfiguration().locale;
- if (locale.equals(currentLocale)) {
- localeType = Words.LOCALE_TYPE_CURRENT;
- } else {
- localeType = Words.LOCALE_TYPE_ALL;
- }
- }
- Words.addWord(context, word, freq, localeType);
+ if (BuildCompatUtils.EFFECTIVE_SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ addWordWithShortcut(context, word, freq, shortcut, locale);
+ return;
}
+ // Fall back to the pre-JellyBean method.
+ final Locale currentLocale = context.getResources().getConfiguration().locale;
+ final int localeType = currentLocale.equals(locale)
+ ? UserDictionary.Words.LOCALE_TYPE_CURRENT : UserDictionary.Words.LOCALE_TYPE_ALL;
+ UserDictionary.Words.addWord(context, word, freq, localeType);
}
- public static final boolean hasNewerAddWord() {
- return null != METHOD_addWord;
+ // {@link UserDictionary.Words#addWord(Context,String,int,String,Locale)} was introduced
+ // in API level 16 (Build.VERSION_CODES.JELLY_BEAN).
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+ private static void addWordWithShortcut(final Context context, final String word,
+ final int freq, final String shortcut, final Locale locale) {
+ UserDictionary.Words.addWord(context, word, freq, shortcut, locale);
}
}