aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-04-30 17:32:43 +0900
committerJean Chalard <jchalard@google.com>2014-05-01 12:00:20 +0900
commit49d78712907142300285c339ea862c355e9d1fb1 (patch)
treeca59d50b937623da9f751b559f25fa13a9cb3485 /java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
parent879629af3c375608464a6cc8f4c18e08f5e2d7b3 (diff)
downloadlatinime-49d78712907142300285c339ea862c355e9d1fb1.tar.gz
latinime-49d78712907142300285c339ea862c355e9d1fb1.tar.xz
latinime-49d78712907142300285c339ea862c355e9d1fb1.zip
Some cleanup and reinforcement
Bug: 9520584 Change-Id: I1c0f9e1b530d4d5bf5f52c2905c20f5ab7c26442
Diffstat (limited to 'java/src/com/android/inputmethod/latin/UserBinaryDictionary.java')
-rw-r--r--java/src/com/android/inputmethod/latin/UserBinaryDictionary.java49
1 files changed, 30 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
index 9d9ce0138..9a1cd4da5 100644
--- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
@@ -51,23 +51,15 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
// to auto-correct, so we set this to the highest frequency that won't, i.e. 14.
private static final int USER_DICT_SHORTCUT_FREQUENCY = 14;
- // TODO: use Words.SHORTCUT when we target JellyBean or above
- final static String SHORTCUT = "shortcut";
- private static final String[] PROJECTION_QUERY;
- static {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- PROJECTION_QUERY = new String[] {
- Words.WORD,
- SHORTCUT,
- Words.FREQUENCY,
- };
- } else {
- PROJECTION_QUERY = new String[] {
- Words.WORD,
- Words.FREQUENCY,
- };
- }
- }
+ private static final String[] PROJECTION_QUERY_WITH_SHORTCUT = new String[] {
+ Words.WORD,
+ Words.SHORTCUT,
+ Words.FREQUENCY,
+ };
+ private static final String[] PROJECTION_QUERY_WITHOUT_SHORTCUT = new String[] {
+ Words.WORD,
+ Words.FREQUENCY,
+ };
private static final String NAME = "userunigram";
@@ -182,10 +174,29 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
} else {
requestArguments = localeElements;
}
+ final String requestString = request.toString();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ try {
+ addWordsFromProjectionLocked(PROJECTION_QUERY_WITH_SHORTCUT, requestString,
+ requestArguments);
+ } catch (IllegalArgumentException e) {
+ // This may happen on some non-compliant devices where the declared API is JB+ but
+ // the SHORTCUT column is not present for some reason.
+ addWordsFromProjectionLocked(PROJECTION_QUERY_WITHOUT_SHORTCUT, requestString,
+ requestArguments);
+ }
+ } else {
+ addWordsFromProjectionLocked(PROJECTION_QUERY_WITHOUT_SHORTCUT, requestString,
+ requestArguments);
+ }
+ }
+
+ private void addWordsFromProjectionLocked(final String[] query, String request,
+ final String[] requestArguments) throws IllegalArgumentException {
Cursor cursor = null;
try {
cursor = mContext.getContentResolver().query(
- Words.CONTENT_URI, PROJECTION_QUERY, request.toString(), requestArguments, null);
+ Words.CONTENT_URI, query, request, requestArguments, null);
addWordsLocked(cursor);
} catch (final SQLiteException e) {
Log.e(TAG, "SQLiteException in the remote User dictionary process.", e);
@@ -245,7 +256,7 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
if (cursor == null) return;
if (cursor.moveToFirst()) {
final int indexWord = cursor.getColumnIndex(Words.WORD);
- final int indexShortcut = hasShortcutColumn ? cursor.getColumnIndex(SHORTCUT) : 0;
+ final int indexShortcut = hasShortcutColumn ? cursor.getColumnIndex(Words.SHORTCUT) : 0;
final int indexFrequency = cursor.getColumnIndex(Words.FREQUENCY);
while (!cursor.isAfterLast()) {
final String word = cursor.getString(indexWord);