aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-12-14 11:01:56 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2012-12-14 11:01:56 -0800
commitd48d6feedd18f0fe334e8f167c5b0ff240a402ea (patch)
treeeb894b8ac0b7f5a1a0e501704a6defe8c0f19fe9 /java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
parentf33c33097bafd263ec1c1fe1515c42f8569a6e1d (diff)
parentdb6f21c6792fe07a733572e1d4978f46b5462c35 (diff)
downloadlatinime-d48d6feedd18f0fe334e8f167c5b0ff240a402ea.tar.gz
latinime-d48d6feedd18f0fe334e8f167c5b0ff240a402ea.tar.xz
latinime-d48d6feedd18f0fe334e8f167c5b0ff240a402ea.zip
am db6f21c6: am 18d688c9: Use the amended user dictionary word for insertion
* commit 'db6f21c6792fe07a733572e1d4978f46b5462c35': Use the amended user dictionary word for insertion
Diffstat (limited to 'java/src/com/android/inputmethod/latin/UserBinaryDictionary.java')
-rw-r--r--java/src/com/android/inputmethod/latin/UserBinaryDictionary.java34
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) {