aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java85
1 files changed, 73 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ffa7b0a4b..d0baed52a 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2008-2009 Google Inc.
- *
+ * Copyright (C) 2008 The Android Open Source Project
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
@@ -39,7 +39,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.preference.PreferenceManager;
-import android.speech.RecognitionManager;
+import android.speech.SpeechRecognizer;
import android.text.AutoText;
import android.text.ClipboardManager;
import android.text.TextUtils;
@@ -158,7 +158,7 @@ public class LatinIME extends InputMethodService
private UserDictionary mUserDictionary;
private ContactsDictionary mContactsDictionary;
- private ExpandableDictionary mAutoDictionary;
+ private AutoDictionary mAutoDictionary;
private Hints mHints;
@@ -226,6 +226,9 @@ public class LatinIME extends InputMethodService
private long mSwipeTriggerTimeMillis;
private boolean mConfigurationChanging;
+ // Keeps track of most recently inserted text (multi-character key) for reverting
+ private CharSequence mEnteredText;
+
// For each word, a list of potential replacements, usually from voice.
private Map<String, List<CharSequence>> mWordToSuggestions =
new HashMap<String, List<CharSequence>>();
@@ -234,6 +237,7 @@ public class LatinIME extends InputMethodService
List<String> candidates;
Map<String, List<CharSequence>> alternatives;
}
+
private boolean mRefreshKeyboardRequired;
Handler mHandler = new Handler() {
@@ -451,6 +455,8 @@ public class LatinIME extends InputMethodService
mCompletions = null;
mCapsLock = false;
mEmailText = false;
+ mEnteredText = null;
+
switch (attribute.inputType & EditorInfo.TYPE_MASK_CLASS) {
case EditorInfo.TYPE_CLASS_NUMBER:
case EditorInfo.TYPE_CLASS_DATETIME:
@@ -552,6 +558,7 @@ public class LatinIME extends InputMethodService
if (VOICE_INSTALLED && !mConfigurationChanging) {
if (mAfterVoiceInput) {
+ mVoiceInput.flushAllTextModificationCounters();
mVoiceInput.logInputEnded();
}
mVoiceInput.flushLogs();
@@ -560,6 +567,7 @@ public class LatinIME extends InputMethodService
if (mInputView != null) {
mInputView.closing();
}
+ if (mAutoDictionary != null) mAutoDictionary.flushPendingWrites();
}
@Override
@@ -567,8 +575,6 @@ public class LatinIME extends InputMethodService
super.onUpdateExtractedText(token, text);
InputConnection ic = getCurrentInputConnection();
if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) {
- mVoiceInput.logTextModified();
-
if (mHints.showPunctuationHintIfNecessary(ic)) {
mVoiceInput.logPunctuationHintDisplayed();
}
@@ -592,6 +598,11 @@ public class LatinIME extends InputMethodService
+ ", ce=" + candidatesEnd);
}
+ if (mAfterVoiceInput) {
+ mVoiceInput.setCursorPos(newSelEnd);
+ mVoiceInput.setSelectionSpan(newSelEnd - newSelStart);
+ }
+
mSuggestionShouldReplaceCurrentWord = false;
// If the current selection in the text view changes, we should
// clear whatever candidate text we have.
@@ -975,6 +986,8 @@ public class LatinIME extends InputMethodService
if (mKeyboardSwitcher.onKey(primaryCode)) {
changeKeyboardMode();
}
+ // Reset after any single keystroke
+ mEnteredText = null;
}
public void onText(CharSequence text) {
@@ -993,16 +1006,32 @@ public class LatinIME extends InputMethodService
updateShiftKeyState(getCurrentInputEditorInfo());
mJustRevertedSeparator = null;
mJustAddedAutoSpace = false;
+ mEnteredText = text;
}
private void handleBackspace() {
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
+ mVoiceInput.incrementTextModificationDeleteCount(
+ mVoiceResults.candidates.get(0).toString().length());
revertVoiceInput();
return;
}
boolean deleteChar = false;
InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
+
+ if (mAfterVoiceInput) {
+ // Don't log delete if the user is pressing delete at
+ // the beginning of the text box (hence not deleting anything)
+ if (mVoiceInput.getCursorPos() > 0) {
+ // If anything was selected before the delete was pressed, increment the
+ // delete count by the length of the selection
+ int deleteLen = mVoiceInput.getSelectionSpan() > 0 ?
+ mVoiceInput.getSelectionSpan() : 1;
+ mVoiceInput.incrementTextModificationDeleteCount(deleteLen);
+ }
+ }
+
if (mPredicting) {
final int length = mComposing.length();
if (length > 0) {
@@ -1024,6 +1053,8 @@ public class LatinIME extends InputMethodService
if (TextEntryState.getState() == TextEntryState.STATE_UNDO_COMMIT) {
revertLastWord(deleteChar);
return;
+ } else if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
+ ic.deleteSurroundingText(mEnteredText.length(), 0);
} else if (deleteChar) {
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
if (mDeleteCount > DELETE_ACCELERATE_AT) {
@@ -1048,6 +1079,12 @@ public class LatinIME extends InputMethodService
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
commitVoiceInput();
}
+
+ if (mAfterVoiceInput) {
+ // Assume input length is 1. This assumption fails for smiley face insertions.
+ mVoiceInput.incrementTextModificationInsertCount(1);
+ }
+
if (isAlphabet(primaryCode) && isPredictionOn() && !isCursorTouchingWord()) {
if (!mPredicting) {
mPredicting = true;
@@ -1091,6 +1128,12 @@ public class LatinIME extends InputMethodService
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
commitVoiceInput();
}
+
+ if (mAfterVoiceInput){
+ // Assume input length is 1. This assumption fails for smiley face insertions.
+ mVoiceInput.incrementTextModificationInsertPunctuationCount(1);
+ }
+
boolean pickedDefault = false;
// Handle separator
InputConnection ic = getCurrentInputConnection();
@@ -1344,7 +1387,7 @@ public class LatinIME extends InputMethodService
String bestResult = nBest.get(0).toString();
- mVoiceInput.logVoiceInputDelivered();
+ mVoiceInput.logVoiceInputDelivered(bestResult.length());
mHints.registerVoiceResult(bestResult);
@@ -1405,7 +1448,7 @@ public class LatinIME extends InputMethodService
((LatinKeyboard) mInputView.getKeyboard()).setPreferredLetters(nextLettersFrequencies);
- boolean correctionAvailable = mSuggest.hasMinimalCorrection();
+ boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasMinimalCorrection();
//|| mCorrectionMode == mSuggest.CORRECTION_FULL;
CharSequence typedWord = mWord.getTypedWord();
// If we're in basic correct
@@ -1436,7 +1479,7 @@ public class LatinIME extends InputMethodService
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
updateSuggestions();
}
- if (mBestWord != null) {
+ if (mBestWord != null && mBestWord.length() > 0) {
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord);
mJustAccepted = true;
pickSuggestion(mBestWord);
@@ -1448,6 +1491,12 @@ public class LatinIME extends InputMethodService
public void pickSuggestionManually(int index, CharSequence suggestion) {
if (mAfterVoiceInput && mShowingVoiceSuggestions) mVoiceInput.logNBestChoose(index);
+ if (mAfterVoiceInput && !mShowingVoiceSuggestions) {
+ mVoiceInput.flushAllTextModificationCounters();
+ // send this intent AFTER logging any prior aggregated edits.
+ mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.length());
+ }
+
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.beginBatchEdit();
@@ -1480,7 +1529,9 @@ public class LatinIME extends InputMethodService
mJustAccepted = true;
pickSuggestion(suggestion);
// Add the word to the auto dictionary if it's not a known word
- checkAddToDictionary(suggestion, AutoDictionary.FREQUENCY_FOR_PICKED);
+ if (index == 0) {
+ checkAddToDictionary(suggestion, AutoDictionary.FREQUENCY_FOR_PICKED);
+ }
TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion);
// Follow it with a space
if (mAutoSpace) {
@@ -1526,8 +1577,13 @@ public class LatinIME extends InputMethodService
}
private void checkAddToDictionary(CharSequence suggestion, int frequencyDelta) {
+ // Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be
+ // adding words in situations where the user or application really didn't
+ // want corrections enabled or learned.
+ if (!(mCorrectionMode == Suggest.CORRECTION_FULL)) return;
if (mAutoDictionary.isValidWord(suggestion)
- || !mSuggest.isValidWord(suggestion.toString().toLowerCase())) {
+ || (!mSuggest.isValidWord(suggestion.toString())
+ && !mSuggest.isValidWord(suggestion.toString().toLowerCase()))) {
mAutoDictionary.addWord(suggestion.toString(), frequencyDelta);
}
}
@@ -1548,6 +1604,11 @@ public class LatinIME extends InputMethodService
return false;
}
+ private boolean sameAsTextBeforeCursor(InputConnection ic, CharSequence text) {
+ CharSequence beforeText = ic.getTextBeforeCursor(text.length(), 0);
+ return TextUtils.equals(text, beforeText);
+ }
+
public void revertLastWord(boolean deleteChar) {
final int length = mComposing.length();
if (!mPredicting && length > 0) {
@@ -1679,7 +1740,7 @@ public class LatinIME extends InputMethodService
return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext)
&& !(attribute != null && attribute.privateImeOptions != null
&& attribute.privateImeOptions.equals(IME_OPTION_NO_MICROPHONE))
- && RecognitionManager.isRecognitionAvailable(this);
+ && SpeechRecognizer.isRecognitionAvailable(this);
}
// receive ringer mode changes to detect silent mode