diff options
author | 2012-12-15 09:44:39 +0900 | |
---|---|---|
committer | 2012-12-15 09:44:39 +0900 | |
commit | 8c15e91344a5e97ca069200070745c4384f40750 (patch) | |
tree | 6015501e538a2865cf88c27fcc29d4511adbc3d6 /java/src/com/android/inputmethod/latin/UserBinaryDictionary.java | |
parent | 39b5396f8e70eaac73d4c5eaa2bfede32a3f1f49 (diff) | |
parent | d48d6feedd18f0fe334e8f167c5b0ff240a402ea (diff) | |
download | latinime-8c15e91344a5e97ca069200070745c4384f40750.tar.gz latinime-8c15e91344a5e97ca069200070745c4384f40750.tar.xz latinime-8c15e91344a5e97ca069200070745c4384f40750.zip |
resolved conflicts for merge of d48d6fee to master
Change-Id: I21141956135debe737453dba87617671b1716d0a
Diffstat (limited to 'java/src/com/android/inputmethod/latin/UserBinaryDictionary.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/UserBinaryDictionary.java | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java index 00c3cbe0a..ddae5ac48 100644 --- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java @@ -18,10 +18,12 @@ package com.android.inputmethod.latin; import android.content.ContentProviderClient; import android.content.ContentResolver; +import android.content.ContentUris; import android.content.Context; import android.content.Intent; import android.database.ContentObserver; import android.database.Cursor; +import android.net.Uri; import android.provider.UserDictionary.Words; import android.text.TextUtils; @@ -87,8 +89,25 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { mObserver = new ContentObserver(null) { @Override - public void onChange(boolean self) { + public void onChange(final boolean self) { + // This hook is deprecated as of API level 16, but should still be supported for + // cases where the IME is running on an older version of the platform. + onChange(self, null); + } + // The following hook is only available as of API level 16, and as such it will only + // work on JellyBean+ devices. On older versions of the platform, the hook + // above will be called instead. + @Override + public void onChange(final boolean self, final Uri uri) { setRequiresReload(true); + // We want to report back to Latin IME in case the user just entered the word. + // If the user changed the word in the dialog box, then we want to replace + // what was entered in the text field. + if (null == uri || !(context instanceof LatinIME)) return; + final long changedRowId = ContentUris.parseId(uri); + if (-1 == changedRowId) return; // Unknown content... Not sure why we're here + final String changedWord = getChangedWordForUri(uri); + ((LatinIME)context).onWordAddedToUserDictionary(changedWord); } }; cres.registerContentObserver(Words.CONTENT_URI, true, mObserver); @@ -96,6 +115,19 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { loadDictionary(); } + private String getChangedWordForUri(final Uri uri) { + final Cursor cursor = mContext.getContentResolver().query(uri, + PROJECTION_QUERY, null, null, null); + if (cursor == null) return null; + try { + if (!cursor.moveToFirst()) return null; + final int indexWord = cursor.getColumnIndex(Words.WORD); + return cursor.getString(indexWord); + } finally { + cursor.close(); + } + } + @Override public synchronized void close() { if (mObserver != null) { |