diff options
Diffstat (limited to 'java/src/com/android/inputmethod/voice/VoiceInput.java')
-rw-r--r-- | java/src/com/android/inputmethod/voice/VoiceInput.java | 137 |
1 files changed, 118 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/voice/VoiceInput.java b/java/src/com/android/inputmethod/voice/VoiceInput.java index e881856dd..ac06ab50d 100644 --- a/java/src/com/android/inputmethod/voice/VoiceInput.java +++ b/java/src/com/android/inputmethod/voice/VoiceInput.java @@ -26,7 +26,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.speech.RecognitionListener; -import android.speech.RecognitionManager; +import android.speech.SpeechRecognizer; import android.speech.RecognizerIntent; import android.util.Log; import android.view.View; @@ -94,6 +94,12 @@ public class VoiceInput implements OnClickListener { public static final int WORKING = 2; public static final int ERROR = 3; + private int mAfterVoiceInputDeleteCount = 0; + private int mAfterVoiceInputInsertCount = 0; + private int mAfterVoiceInputInsertPunctuationCount = 0; + private int mAfterVoiceInputCursorPos = 0; + private int mAfterVoiceInputSelectionSpan = 0; + private int mState = DEFAULT; private final static int MSG_CLOSE_ERROR_DIALOG = 1; @@ -128,7 +134,7 @@ public class VoiceInput implements OnClickListener { public void onCancelVoice(); } - private RecognitionManager mRecognitionManager; + private SpeechRecognizer mSpeechRecognizer; private RecognitionListener mRecognitionListener; private RecognitionView mRecognitionView; private UiListener mUiListener; @@ -141,8 +147,8 @@ public class VoiceInput implements OnClickListener { public VoiceInput(Context context, UiListener uiHandler) { mLogger = VoiceInputLogger.getLogger(context); mRecognitionListener = new ImeRecognitionListener(); - mRecognitionManager = RecognitionManager.createRecognitionManager(context); - mRecognitionManager.setRecognitionListener(mRecognitionListener); + mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(context); + mSpeechRecognizer.setRecognitionListener(mRecognitionListener); mUiListener = uiHandler; mContext = context; newView(); @@ -161,6 +167,87 @@ public class VoiceInput implements OnClickListener { mBlacklist.addApp("com.android.setupwizard"); } + public void setCursorPos(int pos) { + mAfterVoiceInputCursorPos = pos; + } + + public int getCursorPos() { + return mAfterVoiceInputCursorPos; + } + + public void setSelectionSpan(int span) { + mAfterVoiceInputSelectionSpan = span; + } + + public int getSelectionSpan() { + return mAfterVoiceInputSelectionSpan; + } + + public void incrementTextModificationDeleteCount(int count){ + mAfterVoiceInputDeleteCount += count; + // Send up intents for other text modification types + if (mAfterVoiceInputInsertCount > 0) { + logTextModifiedByTypingInsertion(mAfterVoiceInputInsertCount); + mAfterVoiceInputInsertCount = 0; + } + if (mAfterVoiceInputInsertPunctuationCount > 0) { + logTextModifiedByTypingInsertionPunctuation(mAfterVoiceInputInsertPunctuationCount); + mAfterVoiceInputInsertPunctuationCount = 0; + } + + } + + public void incrementTextModificationInsertCount(int count){ + mAfterVoiceInputInsertCount += count; + if (mAfterVoiceInputSelectionSpan > 0) { + // If text was highlighted before inserting the char, count this as + // a delete. + mAfterVoiceInputDeleteCount += mAfterVoiceInputSelectionSpan; + } + // Send up intents for other text modification types + if (mAfterVoiceInputDeleteCount > 0) { + logTextModifiedByTypingDeletion(mAfterVoiceInputDeleteCount); + mAfterVoiceInputDeleteCount = 0; + } + if (mAfterVoiceInputInsertPunctuationCount > 0) { + logTextModifiedByTypingInsertionPunctuation(mAfterVoiceInputInsertPunctuationCount); + mAfterVoiceInputInsertPunctuationCount = 0; + } + } + + public void incrementTextModificationInsertPunctuationCount(int count){ + mAfterVoiceInputInsertPunctuationCount += 1; + if (mAfterVoiceInputSelectionSpan > 0) { + // If text was highlighted before inserting the char, count this as + // a delete. + mAfterVoiceInputDeleteCount += mAfterVoiceInputSelectionSpan; + } + // Send up intents for aggregated non-punctuation insertions + if (mAfterVoiceInputDeleteCount > 0) { + logTextModifiedByTypingDeletion(mAfterVoiceInputDeleteCount); + mAfterVoiceInputDeleteCount = 0; + } + if (mAfterVoiceInputInsertCount > 0) { + logTextModifiedByTypingInsertion(mAfterVoiceInputInsertCount); + mAfterVoiceInputInsertCount = 0; + } + } + + public void flushAllTextModificationCounters() { + if (mAfterVoiceInputInsertCount > 0) { + logTextModifiedByTypingInsertion(mAfterVoiceInputInsertCount); + mAfterVoiceInputInsertCount = 0; + } + if (mAfterVoiceInputDeleteCount > 0) { + logTextModifiedByTypingDeletion(mAfterVoiceInputDeleteCount); + mAfterVoiceInputDeleteCount = 0; + } + if (mAfterVoiceInputInsertPunctuationCount > 0) { + logTextModifiedByTypingInsertionPunctuation(mAfterVoiceInputInsertPunctuationCount); + mAfterVoiceInputInsertPunctuationCount = 0; + } + } + /** * The configuration of the IME changed and may have caused the views to be layed out * again. Restore the state of the recognition view. @@ -247,7 +334,7 @@ public class VoiceInput implements OnClickListener { EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, null /* rely on endpointer default */); - mRecognitionManager.startListening(intent); + mSpeechRecognizer.startListening(intent); } /** @@ -270,7 +357,7 @@ public class VoiceInput implements OnClickListener { } public void destroy() { - mRecognitionManager.destroy(); + mSpeechRecognizer.destroy(); } /** @@ -302,8 +389,20 @@ public class VoiceInput implements OnClickListener { } } - public void logTextModified() { - mLogger.textModified(); + public void logTextModifiedByTypingInsertion(int length) { + mLogger.textModifiedByTypingInsertion(length); + } + + public void logTextModifiedByTypingInsertionPunctuation(int length) { + mLogger.textModifiedByTypingInsertionPunctuation(length); + } + + public void logTextModifiedByTypingDeletion(int length) { + mLogger.textModifiedByTypingDeletion(length); + } + + public void logTextModifiedByChooseSuggestion(int length) { + mLogger.textModifiedByChooseSuggestion(length); } public void logKeyboardWarningDialogShown() { @@ -330,8 +429,8 @@ public class VoiceInput implements OnClickListener { mLogger.punctuationHintDisplayed(); } - public void logVoiceInputDelivered() { - mLogger.voiceInputDelivered(); + public void logVoiceInputDelivered(int length) { + mLogger.voiceInputDelivered(length); } public void logNBestChoose(int index) { @@ -385,7 +484,7 @@ public class VoiceInput implements OnClickListener { // Remove all pending tasks (e.g., timers to cancel voice input) mHandler.removeMessages(MSG_CLOSE_ERROR_DIALOG); - mRecognitionManager.cancel(); + mSpeechRecognizer.cancel(); mUiListener.onCancelVoice(); mRecognitionView.finish(); } @@ -393,20 +492,20 @@ public class VoiceInput implements OnClickListener { private int getErrorStringId(int errorType, boolean endpointed) { switch (errorType) { // We use CLIENT_ERROR to signify that voice search is not available on the device. - case RecognitionManager.ERROR_CLIENT: + case SpeechRecognizer.ERROR_CLIENT: return R.string.voice_not_installed; - case RecognitionManager.ERROR_NETWORK: + case SpeechRecognizer.ERROR_NETWORK: return R.string.voice_network_error; - case RecognitionManager.ERROR_NETWORK_TIMEOUT: + case SpeechRecognizer.ERROR_NETWORK_TIMEOUT: return endpointed ? R.string.voice_network_error : R.string.voice_too_much_speech; - case RecognitionManager.ERROR_AUDIO: + case SpeechRecognizer.ERROR_AUDIO: return R.string.voice_audio_error; - case RecognitionManager.ERROR_SERVER: + case SpeechRecognizer.ERROR_SERVER: return R.string.voice_server_error; - case RecognitionManager.ERROR_SPEECH_TIMEOUT: + case SpeechRecognizer.ERROR_SPEECH_TIMEOUT: return R.string.voice_speech_timeout; - case RecognitionManager.ERROR_NO_MATCH: + case SpeechRecognizer.ERROR_NO_MATCH: return R.string.voice_no_match; default: return R.string.voice_error; } @@ -463,7 +562,7 @@ public class VoiceInput implements OnClickListener { public void onResults(Bundle resultsBundle) { List<String> results = resultsBundle - .getStringArrayList(RecognitionManager.RESULTS_RECOGNITION); + .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); mState = DEFAULT; final Map<String, List<CharSequence>> alternatives = |