aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java')
-rw-r--r--java/src/com/android/inputmethod/deprecated/VoiceProxy.java112
1 files changed, 43 insertions, 69 deletions
diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
index 3f8c2ef8f..87d1c118b 100644
--- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
+++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java
@@ -16,23 +16,6 @@
package com.android.inputmethod.deprecated;
-import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
-import com.android.inputmethod.compat.SharedPreferencesCompat;
-import com.android.inputmethod.deprecated.voice.FieldContext;
-import com.android.inputmethod.deprecated.voice.Hints;
-import com.android.inputmethod.deprecated.voice.SettingsUtil;
-import com.android.inputmethod.deprecated.voice.VoiceInput;
-import com.android.inputmethod.keyboard.KeyboardSwitcher;
-import com.android.inputmethod.latin.EditingUtils;
-import com.android.inputmethod.latin.LatinIME;
-import com.android.inputmethod.latin.LatinIME.UIHandler;
-import com.android.inputmethod.latin.LatinImeLogger;
-import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.SubtypeSwitcher;
-import com.android.inputmethod.latin.SuggestedWords;
-import com.android.inputmethod.latin.Utils;
-
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
@@ -63,6 +46,25 @@ import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.widget.TextView;
+import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
+import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
+import com.android.inputmethod.compat.SharedPreferencesCompat;
+import com.android.inputmethod.deprecated.voice.FieldContext;
+import com.android.inputmethod.deprecated.voice.Hints;
+import com.android.inputmethod.deprecated.voice.SettingsUtil;
+import com.android.inputmethod.deprecated.voice.VoiceInput;
+import com.android.inputmethod.keyboard.KeyboardSwitcher;
+import com.android.inputmethod.keyboard.LatinKeyboardView;
+import com.android.inputmethod.latin.EditingUtils;
+import com.android.inputmethod.latin.LastComposedWord;
+import com.android.inputmethod.latin.LatinIME;
+import com.android.inputmethod.latin.LatinIME.UIHandler;
+import com.android.inputmethod.latin.LatinImeLogger;
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.StringUtils;
+import com.android.inputmethod.latin.SubtypeSwitcher;
+import com.android.inputmethod.latin.Utils;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -90,6 +92,7 @@ public class VoiceProxy implements VoiceInput.UiListener {
private static final boolean DEBUG = LatinImeLogger.sDBG;
private boolean mAfterVoiceInput;
+ private boolean mConfigurationChanging;
private boolean mHasUsedVoiceInput;
private boolean mHasUsedVoiceInputUnsupportedLocale;
private boolean mImmediatelyAfterVoiceInput;
@@ -157,11 +160,11 @@ public class VoiceProxy implements VoiceInput.UiListener {
mPasswordText = isPasswordText;
}
- public void flushVoiceInputLogs(boolean configurationChanged) {
+ public void flushVoiceInputLogs() {
if (!VOICE_INSTALLED) {
return;
}
- if (!configurationChanged) {
+ if (!mConfigurationChanging) {
if (mAfterVoiceInput) {
mVoiceInput.flushAllTextModificationCounters();
mVoiceInput.logInputEnded();
@@ -316,11 +319,11 @@ public class VoiceProxy implements VoiceInput.UiListener {
mImmediatelyAfterVoiceInput = false;
}
- public void hideVoiceWindow(boolean configurationChanging) {
+ public void hideVoiceWindow() {
if (!VOICE_INSTALLED) {
return;
}
- if (!configurationChanging) {
+ if (!mConfigurationChanging) {
if (mAfterVoiceInput)
mVoiceInput.logInputEnded();
if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) {
@@ -433,44 +436,6 @@ public class VoiceProxy implements VoiceInput.UiListener {
}
}
- /**
- * Tries to apply any voice alternatives for the word if this was a spoken word and
- * there are voice alternatives.
- * @param touching The word that the cursor is touching, with position information
- * @return true if an alternative was found, false otherwise.
- */
- public boolean applyVoiceAlternatives(EditingUtils.SelectedWord touching) {
- if (!VOICE_INSTALLED) {
- return false;
- }
- // Search for result in spoken word alternatives
- String selectedWord = touching.mWord.toString().trim();
- if (!mWordToSuggestions.containsKey(selectedWord)) {
- selectedWord = selectedWord.toLowerCase();
- }
- if (mWordToSuggestions.containsKey(selectedWord)) {
- mShowingVoiceSuggestions = true;
- List<CharSequence> suggestions = mWordToSuggestions.get(selectedWord);
- SuggestedWords.Builder builder = new SuggestedWords.Builder();
- // If the first letter of touching is capitalized, make all the suggestions
- // start with a capital letter.
- if (Character.isUpperCase(touching.mWord.charAt(0))) {
- for (CharSequence word : suggestions) {
- String str = word.toString();
- word = Character.toUpperCase(str.charAt(0)) + str.substring(1);
- builder.addWord(word);
- }
- } else {
- builder.addWords(suggestions, null);
- }
- builder.setTypedWordValid(true).setHasMinimalSuggestion(true);
- mService.setSuggestions(builder.build());
-// mService.setCandidatesViewShown(true);
- return true;
- }
- return false;
- }
-
public void handleBackspace() {
if (!VOICE_INSTALLED) {
return;
@@ -552,7 +517,7 @@ public class VoiceProxy implements VoiceInput.UiListener {
mHints.registerVoiceResult(bestResult);
if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text
- mService.commitTyped(ic);
+ mService.commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR);
EditingUtils.appendText(ic, bestResult);
if (ic != null) ic.endBatchEdit();
@@ -695,12 +660,12 @@ public class VoiceProxy implements VoiceInput.UiListener {
&& !mVoiceInput.isBlacklistedField(fieldContext);
}
- private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo attribute) {
+ private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo editorInfo) {
@SuppressWarnings("deprecation")
- final boolean noMic = Utils.inPrivateImeOptions(null,
- LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, attribute)
- || Utils.inPrivateImeOptions(mService.getPackageName(),
- LatinIME.IME_OPTION_NO_MICROPHONE, attribute);
+ final boolean noMic = StringUtils.inPrivateImeOptions(null,
+ LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)
+ || StringUtils.inPrivateImeOptions(mService.getPackageName(),
+ LatinIME.IME_OPTION_NO_MICROPHONE, editorInfo);
return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !noMic
&& SpeechRecognizer.isRecognitionAvailable(mService);
}
@@ -709,7 +674,7 @@ public class VoiceProxy implements VoiceInput.UiListener {
return SpeechRecognizer.isRecognitionAvailable(context);
}
- public void loadSettings(EditorInfo attribute, SharedPreferences sp) {
+ public void loadSettings(EditorInfo editorInfo, SharedPreferences sp) {
if (!VOICE_INSTALLED) {
return;
}
@@ -723,7 +688,7 @@ public class VoiceProxy implements VoiceInput.UiListener {
final String voiceMode = sp.getString(PREF_VOICE_MODE,
mService.getString(R.string.voice_mode_main));
mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off))
- && shouldShowVoiceButton(makeFieldContext(), attribute);
+ && shouldShowVoiceButton(makeFieldContext(), editorInfo);
mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main));
}
@@ -747,8 +712,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
// keep showing the warning.
if (mSubtypeSwitcher.isVoiceMode() && windowToken != null) {
// Close keyboard view if it is been shown.
- if (KeyboardSwitcher.getInstance().isInputViewShown())
- KeyboardSwitcher.getInstance().getKeyboardView().purgeKeyboardAndClosing();
+ final LatinKeyboardView keyboardView = KeyboardSwitcher.getInstance().getKeyboardView();
+ if (keyboardView != null && keyboardView.isShown())
+ keyboardView.purgeKeyboardAndClosing();
startListening(false, windowToken);
}
// If we have no token, onAttachedToWindow will take care of showing dialog and start
@@ -877,4 +843,12 @@ public class VoiceProxy implements VoiceInput.UiListener {
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
}
+
+ public void startChangingConfiguration() {
+ mConfigurationChanging = true;
+ }
+
+ public void finishChangingConfiguration() {
+ mConfigurationChanging = false;
+ }
}