diff options
author | 2012-12-13 21:59:13 +0900 | |
---|---|---|
committer | 2012-12-14 20:28:22 +0900 | |
commit | 18d688c94bb8e1e26de2d12445cb3096c6126f75 (patch) | |
tree | 3a2d0c289e0ead79c8df7d582fa043bc8f975f0c /java/src/com/android/inputmethod/latin/UserBinaryDictionary.java | |
parent | 5cb40f8a767c529af41836d33274ea3043e25011 (diff) | |
download | latinime-18d688c94bb8e1e26de2d12445cb3096c6126f75.tar.gz latinime-18d688c94bb8e1e26de2d12445cb3096c6126f75.tar.xz latinime-18d688c94bb8e1e26de2d12445cb3096c6126f75.zip |
Use the amended user dictionary word for insertion
When the user edits a word before adding it to the user
dictionary, the keyboard should replace whatever was
committed before with the amended version.
Bug: 7725834
Change-Id: I1a417be6c5a86d6a96bc2c76aca314ad8f1202a9
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 60e6fa127..8570746b1 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) { |