aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.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/LatinIME.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/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java41
1 files changed, 39 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index f416396e8..e2a76a456 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -149,6 +149,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private boolean mIsUserDictionaryAvailable;
private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
+ private PositionalInfoForUserDictPendingAddition
+ mPositionalInfoForUserDictPendingAddition = null;
private final WordComposer mWordComposer = new WordComposer();
private RichInputConnection mConnection = new RichInputConnection(this);
@@ -780,6 +782,19 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mainKeyboardView.setGesturePreviewMode(mCurrentSettings.mGesturePreviewTrailEnabled,
mCurrentSettings.mGestureFloatingPreviewTextEnabled);
+ // If we have a user dictionary addition in progress, we should check now if we should
+ // replace the previously committed string with the word that has actually been added
+ // to the user dictionary.
+ if (null != mPositionalInfoForUserDictPendingAddition
+ && mPositionalInfoForUserDictPendingAddition.tryReplaceWithActualWord(
+ mConnection, editorInfo, mLastSelectionEnd)) {
+ mPositionalInfoForUserDictPendingAddition = null;
+ }
+ // If tryReplaceWithActualWord returns false, we don't know what word was
+ // added to the user dictionary yet, so we keep the data and defer processing. The word will
+ // be replaced when the user dictionary reports back with the actual word, which ends
+ // up calling #onWordAddedToUserDictionary() in this class.
+
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
}
@@ -1208,9 +1223,31 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is
// pressed.
@Override
- public boolean addWordToUserDictionary(final String word) {
+ public void addWordToUserDictionary(final String word) {
+ if (TextUtils.isEmpty(word)) {
+ // Probably never supposed to happen, but just in case.
+ mPositionalInfoForUserDictPendingAddition = null;
+ return;
+ }
+ mPositionalInfoForUserDictPendingAddition =
+ new PositionalInfoForUserDictPendingAddition(
+ word, mLastSelectionEnd, getCurrentInputEditorInfo());
mUserDictionary.addWordToUserDictionary(word, 128);
- return true;
+ }
+
+ public void onWordAddedToUserDictionary(final String newSpelling) {
+ // If word was added but not by us, bail out
+ if (null == mPositionalInfoForUserDictPendingAddition) return;
+ if (mWordComposer.isComposingWord()) {
+ // We are late... give up and return
+ mPositionalInfoForUserDictPendingAddition = null;
+ return;
+ }
+ mPositionalInfoForUserDictPendingAddition.setActualWordBeingAdded(newSpelling);
+ if (mPositionalInfoForUserDictPendingAddition.tryReplaceWithActualWord(
+ mConnection, getCurrentInputEditorInfo(), mLastSelectionEnd)) {
+ mPositionalInfoForUserDictPendingAddition = null;
+ }
}
private static boolean isAlphabet(final int code) {