Retain voice input across orientation changes. Fixes 2428545

If an configuration change happens when voice is being captured or
processed, it keeps the voice input state intact and reattaches the
recognition view to the input method.
main
Amith Yamasani 2010-03-07 07:27:05 -08:00
parent abd5e5867c
commit 81c52293f8
4 changed files with 67 additions and 50 deletions

View File

@ -67,6 +67,7 @@
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:visibility="gone" android:visibility="gone"
android:indeterminate="true" android:indeterminate="true"
android:indeterminateOnly="false"
/> />

View File

@ -50,6 +50,8 @@ import android.view.HapticFeedbackConstants;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewParent;
import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo;
@ -221,6 +223,7 @@ public class LatinIME extends InputMethodService
private VoiceInput mVoiceInput; private VoiceInput mVoiceInput;
private VoiceResults mVoiceResults = new VoiceResults(); private VoiceResults mVoiceResults = new VoiceResults();
private long mSwipeTriggerTimeMillis; private long mSwipeTriggerTimeMillis;
private boolean mConfigurationChanging;
// For each word, a list of potential replacements, usually from voice. // For each word, a list of potential replacements, usually from voice.
private Map<String, List<CharSequence>> mWordToSuggestions = private Map<String, List<CharSequence>> mWordToSuggestions =
@ -371,7 +374,12 @@ public class LatinIME extends InputMethodService
mOrientation = conf.orientation; mOrientation = conf.orientation;
reloadKeyboards(); reloadKeyboards();
} }
mConfigurationChanging = true;
super.onConfigurationChanged(conf); super.onConfigurationChanged(conf);
if (mRecognizing) {
switchToRecognitionStatusView();
}
mConfigurationChanging = false;
} }
@Override @Override
@ -387,21 +395,6 @@ public class LatinIME extends InputMethodService
return mInputView; return mInputView;
} }
@Override
public void onInitializeInterface() {
// Create a new view associated with voice input if the old
// view is stuck in another layout (e.g. if switching from
// portrait to landscape while speaking)
// NOTE: This must be done here because for some reason
// onCreateInputView isn't called after an orientation change while
// speech rec is in progress.
if (mVoiceInput != null && mVoiceInput.getView().getParent() != null) {
mVoiceInput.newView();
}
super.onInitializeInterface();
}
@Override @Override
public View onCreateCandidatesView() { public View onCreateCandidatesView() {
mKeyboardSwitcher.makeKeyboards(true); mKeyboardSwitcher.makeKeyboards(true);
@ -554,20 +547,16 @@ public class LatinIME extends InputMethodService
public void onFinishInput() { public void onFinishInput() {
super.onFinishInput(); super.onFinishInput();
if (VOICE_INSTALLED && mAfterVoiceInput) { if (VOICE_INSTALLED && !mConfigurationChanging) {
mVoiceInput.logInputEnded(); if (mAfterVoiceInput) {
} mVoiceInput.logInputEnded();
}
if (VOICE_INSTALLED) {
mVoiceInput.flushLogs(); mVoiceInput.flushLogs();
mVoiceInput.cancel();
} }
if (mInputView != null) { if (mInputView != null) {
mInputView.closing(); mInputView.closing();
} }
if (VOICE_INSTALLED && mRecognizing) {
mVoiceInput.cancel();
}
} }
@Override @Override
@ -654,23 +643,21 @@ public class LatinIME extends InputMethodService
@Override @Override
public void hideWindow() { public void hideWindow() {
if (mAfterVoiceInput) mVoiceInput.logInputEnded();
if (TRACE) Debug.stopMethodTracing(); if (TRACE) Debug.stopMethodTracing();
if (mOptionsDialog != null && mOptionsDialog.isShowing()) { if (mOptionsDialog != null && mOptionsDialog.isShowing()) {
mOptionsDialog.dismiss(); mOptionsDialog.dismiss();
mOptionsDialog = null; mOptionsDialog = null;
} }
if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) { if (!mConfigurationChanging) {
mVoiceInput.logKeyboardWarningDialogDismissed(); if (mAfterVoiceInput) mVoiceInput.logInputEnded();
mVoiceWarningDialog.dismiss(); if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) {
mVoiceWarningDialog = null; mVoiceInput.logKeyboardWarningDialogDismissed();
} mVoiceWarningDialog.dismiss();
if (mTutorial != null) { mVoiceWarningDialog = null;
mTutorial.close(); }
mTutorial = null; if (VOICE_INSTALLED & mRecognizing) {
} mVoiceInput.cancel();
if (VOICE_INSTALLED & mRecognizing) { }
mVoiceInput.cancel();
} }
super.hideWindow(); super.hideWindow();
TextEntryState.endSession(); TextEntryState.endSession();
@ -1211,12 +1198,21 @@ public class LatinIME extends InputMethodService
} }
private void switchToRecognitionStatusView() { private void switchToRecognitionStatusView() {
mHandler.post(new Runnable() { final boolean configChanged = mConfigurationChanging;
public void run() { mHandler.post(new Runnable() {
mRecognizing = true; public void run() {
setInputView(mVoiceInput.getView()); mRecognizing = true;
updateInputViewShown(); View v = mVoiceInput.getView();
}}); ViewParent p = v.getParent();
if (p != null && p instanceof ViewGroup) {
((ViewGroup)v.getParent()).removeView(v);
}
setInputView(v);
updateInputViewShown();
if (configChanged) {
mVoiceInput.onConfigurationChanged();
}
}});
} }
private void startListening(boolean swipe) { private void startListening(boolean swipe) {

View File

@ -16,7 +16,12 @@
package com.android.inputmethod.voice; package com.android.inputmethod.voice;
import com.android.inputmethod.latin.R; import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
@ -35,14 +40,10 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewGroup.MarginLayoutParams;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import java.io.ByteArrayOutputStream; import com.android.inputmethod.latin.R;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.List;
/** /**
* The user interface for the "Speak now" and "working" states. * The user interface for the "Speak now" and "working" states.
@ -103,7 +104,6 @@ public class RecognitionView {
LayoutInflater inflater = (LayoutInflater) context.getSystemService( LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE); Context.LAYOUT_INFLATER_SERVICE);
mView = inflater.inflate(R.layout.recognition_status, null); mView = inflater.inflate(R.layout.recognition_status, null);
ContentResolver cr = context.getContentResolver(); ContentResolver cr = context.getContentResolver();
mMinMicrophoneLevel = SettingsUtil.getSettingsFloat( mMinMicrophoneLevel = SettingsUtil.getSettingsFloat(
cr, SettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f); cr, SettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f);
@ -139,6 +139,18 @@ public class RecognitionView {
return mView; return mView;
} }
public void restoreState() {
mUiHandler.post(new Runnable() {
public void run() {
// Restart the spinner
if (mState == State.WORKING) {
((ProgressBar)mProgress).setIndeterminate(false);
((ProgressBar)mProgress).setIndeterminate(true);
}
}
});
}
public void showInitializing() { public void showInitializing() {
mUiHandler.post(new Runnable() { mUiHandler.post(new Runnable() {
public void run() { public void run() {

View File

@ -161,6 +161,14 @@ public class VoiceInput implements OnClickListener {
mBlacklist.addApp("com.android.setupwizard"); mBlacklist.addApp("com.android.setupwizard");
} }
/**
* The configuration of the IME changed and may have caused the views to be layed out
* again. Restore the state of the recognition view.
*/
public void onConfigurationChanged() {
mRecognitionView.restoreState();
}
/** /**
* @return true if field is blacklisted for voice * @return true if field is blacklisted for voice
*/ */