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
parent
abd5e5867c
commit
81c52293f8
|
@ -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"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
if (mAfterVoiceInput) {
|
||||||
mVoiceInput.logInputEnded();
|
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,24 +643,22 @@ 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 (!mConfigurationChanging) {
|
||||||
|
if (mAfterVoiceInput) mVoiceInput.logInputEnded();
|
||||||
if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) {
|
if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) {
|
||||||
mVoiceInput.logKeyboardWarningDialogDismissed();
|
mVoiceInput.logKeyboardWarningDialogDismissed();
|
||||||
mVoiceWarningDialog.dismiss();
|
mVoiceWarningDialog.dismiss();
|
||||||
mVoiceWarningDialog = null;
|
mVoiceWarningDialog = null;
|
||||||
}
|
}
|
||||||
if (mTutorial != null) {
|
|
||||||
mTutorial.close();
|
|
||||||
mTutorial = null;
|
|
||||||
}
|
|
||||||
if (VOICE_INSTALLED & mRecognizing) {
|
if (VOICE_INSTALLED & mRecognizing) {
|
||||||
mVoiceInput.cancel();
|
mVoiceInput.cancel();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
super.hideWindow();
|
super.hideWindow();
|
||||||
TextEntryState.endSession();
|
TextEntryState.endSession();
|
||||||
}
|
}
|
||||||
|
@ -1211,11 +1198,20 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchToRecognitionStatusView() {
|
private void switchToRecognitionStatusView() {
|
||||||
|
final boolean configChanged = mConfigurationChanging;
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mRecognizing = true;
|
mRecognizing = true;
|
||||||
setInputView(mVoiceInput.getView());
|
View v = mVoiceInput.getView();
|
||||||
|
ViewParent p = v.getParent();
|
||||||
|
if (p != null && p instanceof ViewGroup) {
|
||||||
|
((ViewGroup)v.getParent()).removeView(v);
|
||||||
|
}
|
||||||
|
setInputView(v);
|
||||||
updateInputViewShown();
|
updateInputViewShown();
|
||||||
|
if (configChanged) {
|
||||||
|
mVoiceInput.onConfigurationChanged();
|
||||||
|
}
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue