diff options
author | 2012-06-20 16:49:04 -0700 | |
---|---|---|
committer | 2012-06-20 18:43:56 -0700 | |
commit | 9997b44846906e4a71be393694e37bf5fef86db5 (patch) | |
tree | 81cb2b137421dec6c480f02b658bcf11cea15a11 /java/src/com | |
parent | 6080f6878b10916013a8a5e1d5f58f8041452c56 (diff) | |
download | latinime-9997b44846906e4a71be393694e37bf5fef86db5.tar.gz latinime-9997b44846906e4a71be393694e37bf5fef86db5.tar.xz latinime-9997b44846906e4a71be393694e37bf5fef86db5.zip |
Improve compatibility for ICS.
ICS didn't have a SHORTCUT column in the user dictionary.
If running on a build under JellyBean, we should not ask
for it lest we crash.
Bug: 6600617
Change-Id: Iac0cbcc63c10064f01e2d51eec5931fd9cdd0922
Diffstat (limited to 'java/src/com')
-rw-r--r-- | java/src/com/android/inputmethod/latin/UserBinaryDictionary.java | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java index 6fa1a25a1..5bcdb57b5 100644 --- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java @@ -36,11 +36,22 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { // TODO: use Words.SHORTCUT when it's public in the SDK final static String SHORTCUT = "shortcut"; - private static final String[] PROJECTION_QUERY = { - Words.WORD, - SHORTCUT, - Words.FREQUENCY, - }; + private static final String[] PROJECTION_QUERY; + static { + // 16 is JellyBean, but we want this to compile against ICS. + if (android.os.Build.VERSION.SDK_INT >= 16) { + PROJECTION_QUERY = new String[] { + Words.WORD, + SHORTCUT, + Words.FREQUENCY, + }; + } else { + PROJECTION_QUERY = new String[] { + Words.WORD, + Words.FREQUENCY, + }; + } + } private static final String NAME = "userunigram"; @@ -136,7 +147,7 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { requestArguments = localeElements; } final Cursor cursor = mContext.getContentResolver().query( - Words.CONTENT_URI, PROJECTION_QUERY, request.toString(), requestArguments, null); + Words.CONTENT_URI, PROJECTION_QUERY, request.toString(), requestArguments, null); try { addWords(cursor); } finally { @@ -182,16 +193,18 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { } private void addWords(Cursor cursor) { + // 16 is JellyBean, but we want this to compile against ICS. + final boolean hasShortcutColumn = android.os.Build.VERSION.SDK_INT >= 16; clearFusionDictionary(); if (cursor == null) return; if (cursor.moveToFirst()) { final int indexWord = cursor.getColumnIndex(Words.WORD); - final int indexShortcut = cursor.getColumnIndex(SHORTCUT); + final int indexShortcut = hasShortcutColumn ? cursor.getColumnIndex(SHORTCUT) : 0; final int indexFrequency = cursor.getColumnIndex(Words.FREQUENCY); while (!cursor.isAfterLast()) { - String word = cursor.getString(indexWord); - String shortcut = cursor.getString(indexShortcut); - int frequency = cursor.getInt(indexFrequency); + final String word = cursor.getString(indexWord); + final String shortcut = hasShortcutColumn ? cursor.getString(indexShortcut) : null; + final int frequency = cursor.getInt(indexFrequency); // Safeguard against adding really long words. if (word.length() < MAX_WORD_LENGTH) { super.addWord(word, null, frequency); |