diff options
author | 2010-08-19 22:46:06 -0700 | |
---|---|---|
committer | 2010-08-19 22:46:06 -0700 | |
commit | d56f8f5c10d6a959c23fda6ba0a588198fe7412b (patch) | |
tree | 9c26f81aa39c45fc0f22ecb2d5337e622b6a4438 /java/src/com/android/inputmethod/latin/ContactsDictionary.java | |
parent | b608a93c0f3087b191c88cd75665886b7c52015e (diff) | |
parent | 979f8690967ff5409fe18f5085858ccdb8e0ccf1 (diff) | |
download | latinime-d56f8f5c10d6a959c23fda6ba0a588198fe7412b.tar.gz latinime-d56f8f5c10d6a959c23fda6ba0a588198fe7412b.tar.xz latinime-d56f8f5c10d6a959c23fda6ba0a588198fe7412b.zip |
am 979f8690: DO NOT MERGE. Backport LatinIME from master to Gingerbread
Merge commit '979f8690967ff5409fe18f5085858ccdb8e0ccf1' into gingerbread-plus-aosp
* commit '979f8690967ff5409fe18f5085858ccdb8e0ccf1':
DO NOT MERGE. Backport LatinIME from master to Gingerbread
Diffstat (limited to 'java/src/com/android/inputmethod/latin/ContactsDictionary.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/ContactsDictionary.java | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/latin/ContactsDictionary.java b/java/src/com/android/inputmethod/latin/ContactsDictionary.java index 15edb706a..ab75868cf 100644 --- a/java/src/com/android/inputmethod/latin/ContactsDictionary.java +++ b/java/src/com/android/inputmethod/latin/ContactsDictionary.java @@ -20,9 +20,10 @@ import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.database.Cursor; -import android.os.AsyncTask; import android.os.SystemClock; import android.provider.ContactsContract.Contacts; +import android.text.TextUtils; +import android.util.Log; public class ContactsDictionary extends ExpandableDictionary { @@ -31,27 +32,35 @@ public class ContactsDictionary extends ExpandableDictionary { Contacts.DISPLAY_NAME, }; + /** + * Frequency for contacts information into the dictionary + */ + private static final int FREQUENCY_FOR_CONTACTS = 128; + private static final int FREQUENCY_FOR_CONTACTS_BIGRAM = 90; + private static final int INDEX_NAME = 1; private ContentObserver mObserver; private long mLastLoadedContacts; - public ContactsDictionary(Context context) { - super(context); + public ContactsDictionary(Context context, int dicTypeId) { + super(context, dicTypeId); // Perform a managed query. The Activity will handle closing and requerying the cursor // when needed. ContentResolver cres = context.getContentResolver(); - cres.registerContentObserver(Contacts.CONTENT_URI, true, mObserver = new ContentObserver(null) { - @Override - public void onChange(boolean self) { - setRequiresReload(true); - } - }); + cres.registerContentObserver( + Contacts.CONTENT_URI, true,mObserver = new ContentObserver(null) { + @Override + public void onChange(boolean self) { + setRequiresReload(true); + } + }); loadDictionary(); } + @Override public synchronized void close() { if (mObserver != null) { getContext().getContentResolver().unregisterContentObserver(mObserver); @@ -89,6 +98,7 @@ public class ContactsDictionary extends ExpandableDictionary { if (name != null) { int len = name.length(); + String prevWord = null; // TODO: Better tokenization for non-Latin writing systems for (int i = 0; i < len; i++) { @@ -112,7 +122,13 @@ public class ContactsDictionary extends ExpandableDictionary { // capitalization of i. final int wordLen = word.length(); if (wordLen < maxWordLength && wordLen > 1) { - super.addWord(word, 128); + super.addWord(word, FREQUENCY_FOR_CONTACTS); + if (!TextUtils.isEmpty(prevWord)) { + // TODO Do not add email address + // Not so critical + super.setBigram(prevWord, word, FREQUENCY_FOR_CONTACTS_BIGRAM); + } + prevWord = word; } } } |