Fix adding user dictionary

This change is follow up of I9fe45a61

Bug: 3264920
Change-Id: Ic7b95892e36e30fd9fadd7bea011efad7f2f98ca
main
Tadashi G. Takaoka 2010-12-16 12:19:09 +09:00
parent 68b6932024
commit 1d11e7903f
1 changed files with 13 additions and 9 deletions

View File

@ -26,14 +26,16 @@ import android.provider.UserDictionary.Words;
public class UserDictionary extends ExpandableDictionary { public class UserDictionary extends ExpandableDictionary {
private static final String[] PROJECTION = { private static final String[] PROJECTION_QUERY = {
Words._ID,
Words.WORD, Words.WORD,
Words.FREQUENCY Words.FREQUENCY,
}; };
private static final int INDEX_WORD = 1; private static final String[] PROJECTION_ADD = {
private static final int INDEX_FREQUENCY = 2; Words._ID,
Words.FREQUENCY,
Words.LOCALE,
};
private ContentObserver mObserver; private ContentObserver mObserver;
private String mLocale; private String mLocale;
@ -67,7 +69,7 @@ public class UserDictionary extends ExpandableDictionary {
@Override @Override
public void loadDictionaryAsync() { public void loadDictionaryAsync() {
Cursor cursor = getContext().getContentResolver() Cursor cursor = getContext().getContentResolver()
.query(Words.CONTENT_URI, PROJECTION, "(locale IS NULL) or (locale=?)", .query(Words.CONTENT_URI, PROJECTION_QUERY, "(locale IS NULL) or (locale=?)",
new String[] { mLocale }, null); new String[] { mLocale }, null);
addWords(cursor); addWords(cursor);
} }
@ -100,7 +102,7 @@ public class UserDictionary extends ExpandableDictionary {
new Thread("addWord") { new Thread("addWord") {
@Override @Override
public void run() { public void run() {
Cursor cursor = contentResolver.query(Words.CONTENT_URI, PROJECTION, Cursor cursor = contentResolver.query(Words.CONTENT_URI, PROJECTION_ADD,
"word=? and ((locale IS NULL) or (locale=?))", "word=? and ((locale IS NULL) or (locale=?))",
new String[] { word, mLocale }, null); new String[] { word, mLocale }, null);
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
@ -139,9 +141,11 @@ public class UserDictionary extends ExpandableDictionary {
final int maxWordLength = getMaxWordLength(); final int maxWordLength = getMaxWordLength();
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
final int indexWord = cursor.getColumnIndex(Words.WORD);
final int indexFrequency = cursor.getColumnIndex(Words.FREQUENCY);
while (!cursor.isAfterLast()) { while (!cursor.isAfterLast()) {
String word = cursor.getString(INDEX_WORD); String word = cursor.getString(indexWord);
int frequency = cursor.getInt(INDEX_FREQUENCY); int frequency = cursor.getInt(indexFrequency);
// Safeguard against adding really long words. Stack may overflow due // Safeguard against adding really long words. Stack may overflow due
// to recursion // to recursion
if (word.length() < maxWordLength) { if (word.length() < maxWordLength) {