am 6f294c3d: am 17bc97c1: Merge "Fix resetting the status of VoiceIME when the user is switching from one VoiceIME to another Voice IME" into honeycomb

* commit '6f294c3de4e86b452ebde0259cb462d02503339a':
  Fix resetting the status of VoiceIME when the user is switching from one VoiceIME to another Voice IME
main
Satoshi Kataoka 2011-01-24 13:31:19 -08:00 committed by Android Git Automerger
commit 85f57c04a6
2 changed files with 40 additions and 19 deletions

View File

@ -223,6 +223,9 @@ public class SubtypeSwitcher {
} }
mMode = newMode; mMode = newMode;
} }
// If the old mode is voice input, we need to reset or cancel its status.
// We cancel its status when we change mode, while we reset otherwise.
if (isKeyboardMode()) { if (isKeyboardMode()) {
if (modeChanged) { if (modeChanged) {
if (VOICE_MODE.equals(oldMode) && mVoiceInput != null) { if (VOICE_MODE.equals(oldMode) && mVoiceInput != null) {
@ -233,17 +236,23 @@ public class SubtypeSwitcher {
updateShortcutIME(); updateShortcutIME();
mService.onRefreshKeyboard(); mService.onRefreshKeyboard();
} }
} else if (isVoiceMode()) { } else if (isVoiceMode() && mVoiceInput != null) {
if (VOICE_MODE.equals(oldMode)) {
mVoiceInput.reset();
}
// If needsToShowWarningDialog is true, voice input need to show warning before // If needsToShowWarningDialog is true, voice input need to show warning before
// show recognition view. // show recognition view.
if (languageChanged || modeChanged if (languageChanged || modeChanged
|| VoiceIMEConnector.getInstance().needsToShowWarningDialog()) { || VoiceIMEConnector.getInstance().needsToShowWarningDialog()) {
if (mVoiceInput != null) { triggerVoiceIME();
triggerVoiceIME();
}
} }
} else { } else {
Log.w(TAG, "Unknown subtype mode: " + mMode); Log.w(TAG, "Unknown subtype mode: " + mMode);
if (VOICE_MODE.equals(oldMode) && mVoiceInput != null) {
// We need to reset the voice input to release the resources and to reset its status
// as it is not the current input mode.
mVoiceInput.reset();
}
} }
} }

View File

@ -130,19 +130,14 @@ public class VoiceInput implements OnClickListener {
private int mState = DEFAULT; private int mState = DEFAULT;
private final static int MSG_CLOSE_ERROR_DIALOG = 1; private final static int MSG_RESET = 1;
private final static int MSG_RESET = 2;
private final Handler mHandler = new Handler() { private final Handler mHandler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
if (msg.what == MSG_RESET || msg.what == MSG_CLOSE_ERROR_DIALOG) { if (msg.what == MSG_RESET) {
mState = DEFAULT; mState = DEFAULT;
mRecognitionView.finish(); mRecognitionView.finish();
}
if (msg.what == MSG_CLOSE_ERROR_DIALOG) {
mUiListener.onCancelVoice(); mUiListener.onCancelVoice();
} }
} }
@ -318,7 +313,14 @@ public class VoiceInput implements OnClickListener {
if (DBG) { if (DBG) {
Log.d(TAG, "startListening: " + context); 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(); Locale locale = Locale.getDefault();
String localeString = locale.getLanguage() + "-" + locale.getCountry(); String localeString = locale.getLanguage() + "-" + locale.getCountry();
@ -503,6 +505,21 @@ public class VoiceInput implements OnClickListener {
return intent; return intent;
} }
/**
* 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. * Cancel in-progress speech recognition.
*/ */
@ -518,14 +535,9 @@ public class VoiceInput implements OnClickListener {
mLogger.cancelDuringError(); mLogger.cancelDuringError();
break; break;
} }
mState = DEFAULT;
// Remove all pending tasks (e.g., timers to cancel voice input) reset();
mHandler.removeMessages(MSG_RESET);
mSpeechRecognizer.cancel();
mUiListener.onCancelVoice(); mUiListener.onCancelVoice();
mRecognitionView.finish();
} }
private int getErrorStringId(int errorType, boolean endpointed) { private int getErrorStringId(int errorType, boolean endpointed) {
@ -560,7 +572,7 @@ public class VoiceInput implements OnClickListener {
mState = ERROR; mState = ERROR;
mRecognitionView.showError(error); mRecognitionView.showError(error);
// Wait a couple seconds and then automatically dismiss message. // 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 { private class ImeRecognitionListener implements RecognitionListener {