aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/voice/VoiceInput.java
diff options
context:
space:
mode:
authorLuca Zanolin <zano@google.com>2011-01-24 15:45:20 +0000
committerLuca Zanolin <zano@google.com>2011-01-24 15:45:20 +0000
commit35f1c6a73cef75c3a966ea8347e9ed70ad88a2ea (patch)
treefe475986a8da7f15bca1196fd49f2c3695e6e87e /java/src/com/android/inputmethod/voice/VoiceInput.java
parentbd0de0f15108f5d08e2a734807255c30ea3030c7 (diff)
downloadlatinime-35f1c6a73cef75c3a966ea8347e9ed70ad88a2ea.tar.gz
latinime-35f1c6a73cef75c3a966ea8347e9ed70ad88a2ea.tar.xz
latinime-35f1c6a73cef75c3a966ea8347e9ed70ad88a2ea.zip
Fix resetting the status of VoiceIME when the user is switching from one VoiceIME to another Voice IME
Change-Id: Ibbbe3ed6c4e2e7e3c1266daddf109742bd8d97b6
Diffstat (limited to 'java/src/com/android/inputmethod/voice/VoiceInput.java')
-rw-r--r--java/src/com/android/inputmethod/voice/VoiceInput.java42
1 files changed, 27 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/voice/VoiceInput.java b/java/src/com/android/inputmethod/voice/VoiceInput.java
index 20211d46c..2df9e8588 100644
--- a/java/src/com/android/inputmethod/voice/VoiceInput.java
+++ b/java/src/com/android/inputmethod/voice/VoiceInput.java
@@ -130,19 +130,14 @@ public class VoiceInput implements OnClickListener {
private int mState = DEFAULT;
- private final static int MSG_CLOSE_ERROR_DIALOG = 1;
-
- private final static int MSG_RESET = 2;
+ private final static int MSG_RESET = 1;
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
- if (msg.what == MSG_RESET || msg.what == MSG_CLOSE_ERROR_DIALOG) {
+ if (msg.what == MSG_RESET) {
mState = DEFAULT;
mRecognitionView.finish();
- }
-
- if (msg.what == MSG_CLOSE_ERROR_DIALOG) {
mUiListener.onCancelVoice();
}
}
@@ -318,7 +313,14 @@ public class VoiceInput implements OnClickListener {
if (DBG) {
Log.d(TAG, "startListening: " + context);
}
- mState = DEFAULT;
+
+ if (mState != DEFAULT) {
+ Log.w(TAG, "startListening in the wrong status " + mState);
+ }
+
+ // If everything works ok, the voice input should be already in the correct state. As this
+ // class can be called by third-party, we call reset just to be on the safe side.
+ reset();
Locale locale = Locale.getDefault();
String localeString = locale.getLanguage() + "-" + locale.getCountry();
@@ -504,6 +506,21 @@ public class VoiceInput implements OnClickListener {
}
/**
+ * Reset the current voice recognition.
+ */
+ public void reset() {
+ if (mState != DEFAULT) {
+ mState = DEFAULT;
+
+ // Remove all pending tasks (e.g., timers to cancel voice input)
+ mHandler.removeMessages(MSG_RESET);
+
+ mSpeechRecognizer.cancel();
+ mRecognitionView.finish();
+ }
+ }
+
+ /**
* Cancel in-progress speech recognition.
*/
public void cancel() {
@@ -518,14 +535,9 @@ public class VoiceInput implements OnClickListener {
mLogger.cancelDuringError();
break;
}
- mState = DEFAULT;
-
- // Remove all pending tasks (e.g., timers to cancel voice input)
- mHandler.removeMessages(MSG_RESET);
- mSpeechRecognizer.cancel();
+ reset();
mUiListener.onCancelVoice();
- mRecognitionView.finish();
}
private int getErrorStringId(int errorType, boolean endpointed) {
@@ -560,7 +572,7 @@ public class VoiceInput implements OnClickListener {
mState = ERROR;
mRecognitionView.showError(error);
// Wait a couple seconds and then automatically dismiss message.
- mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_CLOSE_ERROR_DIALOG), 2000);
+ mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_RESET), 2000);
}
private class ImeRecognitionListener implements RecognitionListener {