Merge "Some cleanup and reinforcement"
commit
ec29147375
|
@ -50,23 +50,15 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
// to auto-correct, so we set this to the highest frequency that won't, i.e. 14.
|
// 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;
|
private static final int USER_DICT_SHORTCUT_FREQUENCY = 14;
|
||||||
|
|
||||||
// TODO: use Words.SHORTCUT when we target JellyBean or above
|
private static final String[] PROJECTION_QUERY_WITH_SHORTCUT = new String[] {
|
||||||
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,
|
Words.WORD,
|
||||||
SHORTCUT,
|
Words.SHORTCUT,
|
||||||
Words.FREQUENCY,
|
Words.FREQUENCY,
|
||||||
};
|
};
|
||||||
} else {
|
private static final String[] PROJECTION_QUERY_WITHOUT_SHORTCUT = new String[] {
|
||||||
PROJECTION_QUERY = new String[] {
|
|
||||||
Words.WORD,
|
Words.WORD,
|
||||||
Words.FREQUENCY,
|
Words.FREQUENCY,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String NAME = "userunigram";
|
private static final String NAME = "userunigram";
|
||||||
|
|
||||||
|
@ -179,10 +171,29 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
} else {
|
} else {
|
||||||
requestArguments = localeElements;
|
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;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = mContext.getContentResolver().query(
|
cursor = mContext.getContentResolver().query(
|
||||||
Words.CONTENT_URI, PROJECTION_QUERY, request.toString(), requestArguments, null);
|
Words.CONTENT_URI, query, request, requestArguments, null);
|
||||||
addWordsLocked(cursor);
|
addWordsLocked(cursor);
|
||||||
} catch (final SQLiteException e) {
|
} catch (final SQLiteException e) {
|
||||||
Log.e(TAG, "SQLiteException in the remote User dictionary process.", e);
|
Log.e(TAG, "SQLiteException in the remote User dictionary process.", e);
|
||||||
|
@ -239,7 +250,7 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
if (cursor == null) return;
|
if (cursor == null) return;
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
final int indexWord = cursor.getColumnIndex(Words.WORD);
|
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);
|
final int indexFrequency = cursor.getColumnIndex(Words.FREQUENCY);
|
||||||
while (!cursor.isAfterLast()) {
|
while (!cursor.isAfterLast()) {
|
||||||
final String word = cursor.getString(indexWord);
|
final String word = cursor.getString(indexWord);
|
||||||
|
|
Loading…
Reference in New Issue