am 8bb1696c: am a0ff7663: Merge "Make sure that keyboard is not displayed when voice mode" into honeycomb

* commit '8bb1696cff3178405532129954d066f6a4d7402e':
  Make sure that keyboard is not displayed when voice mode
main
Tadashi G. Takaoka 2011-01-17 05:52:18 -08:00 committed by Android Git Automerger
commit ea727ed3ed
4 changed files with 53 additions and 60 deletions

View File

@ -298,8 +298,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
TypedArray a = context.obtainStyledAttributes( TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView); attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
LayoutInflater inflate =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int previewLayout = 0; int previewLayout = 0;
int keyTextSize = 0; int keyTextSize = 0;
@ -365,7 +363,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mPreviewPopup = new PopupWindow(context); mPreviewPopup = new PopupWindow(context);
if (previewLayout != 0) { if (previewLayout != 0) {
mPreviewText = (TextView) inflate.inflate(previewLayout, null); mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null);
mPreviewTextSizeLarge = (int) res.getDimension(R.dimen.key_preview_text_size_large); mPreviewTextSizeLarge = (int) res.getDimension(R.dimen.key_preview_text_size_large);
mPreviewPopup.setContentView(mPreviewText); mPreviewPopup.setContentView(mPreviewText);
mPreviewPopup.setBackgroundDrawable(null); mPreviewPopup.setBackgroundDrawable(null);
@ -1080,9 +1078,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
private View inflateMiniKeyboardContainer(Key popupKey) { private View inflateMiniKeyboardContainer(Key popupKey) {
int popupKeyboardResId = mKeyboard.getPopupKeyboardResId(); int popupKeyboardResId = mKeyboard.getPopupKeyboardResId();
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService( View container = LayoutInflater.from(getContext()).inflate(mPopupLayout, null);
Context.LAYOUT_INFLATER_SERVICE);
View container = inflater.inflate(mPopupLayout, null);
if (container == null) if (container == null)
throw new NullPointerException(); throw new NullPointerException();
@ -1408,7 +1404,9 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
dismissPopupKeyboard(); dismissPopupKeyboard();
mBuffer = null; mBuffer = null;
mCanvas = null; mCanvas = null;
mKeyboard = null;
mMiniKeyboardCache.clear(); mMiniKeyboardCache.clear();
requestLayout();
} }
@Override @Override

View File

@ -615,7 +615,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
checkReCorrectionOnStart(); checkReCorrectionOnStart();
inputView.setForeground(true); inputView.setForeground(true);
mVoiceConnector.onStartInputView(mKeyboardSwitcher.getInputView().getWindowToken()); mVoiceConnector.onStartInputView(inputView.getWindowToken());
if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
} }

View File

@ -103,9 +103,7 @@ public class RecognitionView {
public RecognitionView(Context context, OnClickListener clickListener) { public RecognitionView(Context context, OnClickListener clickListener) {
mUiHandler = new Handler(); mUiHandler = new Handler();
LayoutInflater inflater = (LayoutInflater) context.getSystemService( mView = LayoutInflater.from(context).inflate(R.layout.recognition_status, null);
Context.LAYOUT_INFLATER_SERVICE);
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);

View File

@ -16,6 +16,7 @@
package com.android.inputmethod.voice; package com.android.inputmethod.voice;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.latin.EditingUtils; import com.android.inputmethod.latin.EditingUtils;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinIME.UIHandler; import com.android.inputmethod.latin.LatinIME.UIHandler;
@ -91,7 +92,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
private boolean mVoiceInputHighlighted; private boolean mVoiceInputHighlighted;
private InputMethodManager mImm; private InputMethodManager mImm;
private LatinIME mContext; private LatinIME mService;
private AlertDialog mVoiceWarningDialog; private AlertDialog mVoiceWarningDialog;
private VoiceInput mVoiceInput; private VoiceInput mVoiceInput;
private final VoiceResults mVoiceResults = new VoiceResults(); private final VoiceResults mVoiceResults = new VoiceResults();
@ -111,21 +112,19 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
return sInstance; return sInstance;
} }
private void initInternal(LatinIME context, SharedPreferences prefs, UIHandler h) { private void initInternal(LatinIME service, SharedPreferences prefs, UIHandler h) {
mContext = context; mService = service;
mHandler = h; mHandler = h;
mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); mImm = (InputMethodManager) service.getSystemService(Context.INPUT_METHOD_SERVICE);
mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance();
if (VOICE_INSTALLED) { if (VOICE_INSTALLED) {
mVoiceInput = new VoiceInput(context, this); mVoiceInput = new VoiceInput(service, this);
mHints = new Hints(context, prefs, new Hints.Display() { mHints = new Hints(service, prefs, new Hints.Display() {
@Override @Override
public void showHint(int viewResource) { public void showHint(int viewResource) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( View view = LayoutInflater.from(mService).inflate(viewResource, null);
Context.LAYOUT_INFLATER_SERVICE); mService.setCandidatesView(view);
View view = inflater.inflate(viewResource, null); mService.setCandidatesViewShown(true);
mContext.setCandidatesView(view);
mContext.setCandidatesViewShown(true);
mIsShowingHint = true; mIsShowingHint = true;
} }
}); });
@ -161,7 +160,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
mVoiceInput.flushAllTextModificationCounters(); mVoiceInput.flushAllTextModificationCounters();
// send this intent AFTER logging any prior aggregated edits. // send this intent AFTER logging any prior aggregated edits.
mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.toString(), index, mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.toString(), index,
wordSeparators, mContext.getCurrentInputConnection()); wordSeparators, mService.getCurrentInputConnection());
} }
} }
@ -170,7 +169,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) { if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) {
return; return;
} }
AlertDialog.Builder builder = new AlertDialog.Builder(mContext); AlertDialog.Builder builder = new AlertDialog.Builder(mService);
builder.setCancelable(true); builder.setCancelable(true);
builder.setIcon(R.drawable.ic_mic_dialog); builder.setIcon(R.drawable.ic_mic_dialog);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@ -199,13 +198,13 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
final CharSequence message; final CharSequence message;
if (mLocaleSupportedForVoiceInput) { if (mLocaleSupportedForVoiceInput) {
message = TextUtils.concat( message = TextUtils.concat(
mContext.getText(R.string.voice_warning_may_not_understand), "\n\n", mService.getText(R.string.voice_warning_may_not_understand), "\n\n",
mContext.getText(R.string.voice_warning_how_to_turn_off)); mService.getText(R.string.voice_warning_how_to_turn_off));
} else { } else {
message = TextUtils.concat( message = TextUtils.concat(
mContext.getText(R.string.voice_warning_locale_not_supported), "\n\n", mService.getText(R.string.voice_warning_locale_not_supported), "\n\n",
mContext.getText(R.string.voice_warning_may_not_understand), "\n\n", mService.getText(R.string.voice_warning_may_not_understand), "\n\n",
mContext.getText(R.string.voice_warning_how_to_turn_off)); mService.getText(R.string.voice_warning_how_to_turn_off));
} }
builder.setMessage(message); builder.setMessage(message);
@ -296,7 +295,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
} }
public void showPunctuationHintIfNecessary() { public void showPunctuationHintIfNecessary() {
InputConnection ic = mContext.getCurrentInputConnection(); InputConnection ic = mService.getCurrentInputConnection();
if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) { if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) {
if (mHints.showPunctuationHintIfNecessary(ic)) { if (mHints.showPunctuationHintIfNecessary(ic)) {
mVoiceInput.logPunctuationHintDisplayed(); mVoiceInput.logPunctuationHintDisplayed();
@ -364,17 +363,17 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
} }
private void revertVoiceInput() { private void revertVoiceInput() {
InputConnection ic = mContext.getCurrentInputConnection(); InputConnection ic = mService.getCurrentInputConnection();
if (ic != null) ic.commitText("", 1); if (ic != null) ic.commitText("", 1);
mContext.updateSuggestions(); mService.updateSuggestions();
mVoiceInputHighlighted = false; mVoiceInputHighlighted = false;
} }
public void commitVoiceInput() { public void commitVoiceInput() {
if (VOICE_INSTALLED && mVoiceInputHighlighted) { if (VOICE_INSTALLED && mVoiceInputHighlighted) {
InputConnection ic = mContext.getCurrentInputConnection(); InputConnection ic = mService.getCurrentInputConnection();
if (ic != null) ic.finishComposingText(); if (ic != null) ic.finishComposingText();
mContext.updateSuggestions(); mService.updateSuggestions();
mVoiceInputHighlighted = false; mVoiceInputHighlighted = false;
} }
} }
@ -394,7 +393,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
if (mShowingVoiceSuggestions) { if (mShowingVoiceSuggestions) {
// Retain the replaced word in the alternatives array. // Retain the replaced word in the alternatives array.
String wordToBeReplaced = EditingUtils.getWordAtCursor( String wordToBeReplaced = EditingUtils.getWordAtCursor(
mContext.getCurrentInputConnection(), wordSeparators); mService.getCurrentInputConnection(), wordSeparators);
if (!mWordToSuggestions.containsKey(wordToBeReplaced)) { if (!mWordToSuggestions.containsKey(wordToBeReplaced)) {
wordToBeReplaced = wordToBeReplaced.toLowerCase(); wordToBeReplaced = wordToBeReplaced.toLowerCase();
} }
@ -438,8 +437,8 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
builder.addWords(suggestions); builder.addWords(suggestions);
} }
builder.setTypedWordValid(true).setHasMinimalSuggestion(true); builder.setTypedWordValid(true).setHasMinimalSuggestion(true);
mContext.setSuggestions(builder.build()); mService.setSuggestions(builder.build());
mContext.setCandidatesViewShown(true); mService.setCandidatesViewShown(true);
return true; return true;
} }
return false; return false;
@ -486,15 +485,15 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
mAfterVoiceInput = true; mAfterVoiceInput = true;
mImmediatelyAfterVoiceInput = true; mImmediatelyAfterVoiceInput = true;
InputConnection ic = mContext.getCurrentInputConnection(); InputConnection ic = mService.getCurrentInputConnection();
if (!mContext.isFullscreenMode()) { if (!mService.isFullscreenMode()) {
// Start listening for updates to the text from typing, etc. // Start listening for updates to the text from typing, etc.
if (ic != null) { if (ic != null) {
ExtractedTextRequest req = new ExtractedTextRequest(); ExtractedTextRequest req = new ExtractedTextRequest();
ic.getExtractedText(req, InputConnection.GET_EXTRACTED_TEXT_MONITOR); ic.getExtractedText(req, InputConnection.GET_EXTRACTED_TEXT_MONITOR);
} }
} }
mContext.vibrate(); mService.vibrate();
final List<CharSequence> nBest = new ArrayList<CharSequence>(); final List<CharSequence> nBest = new ArrayList<CharSequence>();
for (String c : mVoiceResults.candidates) { for (String c : mVoiceResults.candidates) {
@ -511,7 +510,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
mHints.registerVoiceResult(bestResult); mHints.registerVoiceResult(bestResult);
if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text
mContext.commitTyped(ic); mService.commitTyped(ic);
EditingUtils.appendText(ic, bestResult); EditingUtils.appendText(ic, bestResult);
if (ic != null) ic.endBatchEdit(); if (ic != null) ic.endBatchEdit();
@ -525,15 +524,15 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
mContext.setCandidatesViewShown(false); mService.setCandidatesViewShown(false);
mRecognizing = true; mRecognizing = true;
View v = mVoiceInput.getView(); View v = mVoiceInput.getView();
ViewParent p = v.getParent(); ViewParent p = v.getParent();
if (p != null && p instanceof ViewGroup) { if (p != null && p instanceof ViewGroup) {
((ViewGroup)p).removeView(v); ((ViewGroup)p).removeView(v);
} }
mContext.setInputView(v); mService.setInputView(v);
mContext.updateInputViewShown(); mService.updateInputViewShown();
if (configChanged) { if (configChanged) {
mVoiceInput.onConfigurationChanged(); mVoiceInput.onConfigurationChanged();
} }
@ -541,7 +540,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
} }
private void switchToLastInputMethod() { private void switchToLastInputMethod() {
IBinder token = mContext.getWindow().getWindow().getAttributes().token; IBinder token = mService.getWindow().getWindow().getAttributes().token;
mImm.switchToLastInputMethod(token); mImm.switchToLastInputMethod(token);
} }
@ -553,7 +552,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
// The user has started a voice input, so remember that in the // The user has started a voice input, so remember that in the
// future (so we don't show the warning dialog after the first run). // future (so we don't show the warning dialog after the first run).
SharedPreferences.Editor editor = SharedPreferences.Editor editor =
PreferenceManager.getDefaultSharedPreferences(mContext).edit(); PreferenceManager.getDefaultSharedPreferences(mService).edit();
editor.putBoolean(PREF_HAS_USED_VOICE_INPUT, true); editor.putBoolean(PREF_HAS_USED_VOICE_INPUT, true);
SharedPreferencesCompat.apply(editor); SharedPreferencesCompat.apply(editor);
mHasUsedVoiceInput = true; mHasUsedVoiceInput = true;
@ -563,14 +562,14 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
// The user has started a voice input from an unsupported locale, so remember that // The user has started a voice input from an unsupported locale, so remember that
// in the future (so we don't show the warning dialog the next time they do this). // in the future (so we don't show the warning dialog the next time they do this).
SharedPreferences.Editor editor = SharedPreferences.Editor editor =
PreferenceManager.getDefaultSharedPreferences(mContext).edit(); PreferenceManager.getDefaultSharedPreferences(mService).edit();
editor.putBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, true); editor.putBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, true);
SharedPreferencesCompat.apply(editor); SharedPreferencesCompat.apply(editor);
mHasUsedVoiceInputUnsupportedLocale = true; mHasUsedVoiceInputUnsupportedLocale = true;
} }
// Clear N-best suggestions // Clear N-best suggestions
mContext.clearSuggestions(); mService.clearSuggestions();
FieldContext context = makeFieldContext(); FieldContext context = makeFieldContext();
mVoiceInput.startListening(context, swipe); mVoiceInput.startListening(context, swipe);
@ -579,7 +578,6 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
public void startListening(final boolean swipe, IBinder token, public void startListening(final boolean swipe, IBinder token,
final boolean configurationChanging) { final boolean configurationChanging) {
// TODO: remove swipe which is no longer used.
if (VOICE_INSTALLED) { if (VOICE_INSTALLED) {
if (needsToShowWarningDialog()) { if (needsToShowWarningDialog()) {
// Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel. // Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel.
@ -601,7 +599,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext)
&& !(attribute != null && !(attribute != null
&& IME_OPTION_NO_MICROPHONE.equals(attribute.privateImeOptions)) && IME_OPTION_NO_MICROPHONE.equals(attribute.privateImeOptions))
&& SpeechRecognizer.isRecognitionAvailable(mContext); && SpeechRecognizer.isRecognitionAvailable(mService);
} }
public void loadSettings(EditorInfo attribute, SharedPreferences sp) { public void loadSettings(EditorInfo attribute, SharedPreferences sp) {
@ -614,10 +612,10 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
if (VOICE_INSTALLED) { if (VOICE_INSTALLED) {
final String voiceMode = sp.getString(PREF_VOICE_MODE, final String voiceMode = sp.getString(PREF_VOICE_MODE,
mContext.getString(R.string.voice_mode_main)); mService.getString(R.string.voice_mode_main));
mVoiceButtonEnabled = !voiceMode.equals(mContext.getString(R.string.voice_mode_off)) mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off))
&& shouldShowVoiceButton(makeFieldContext(), attribute); && shouldShowVoiceButton(makeFieldContext(), attribute);
mVoiceButtonOnPrimary = voiceMode.equals(mContext.getString(R.string.voice_mode_main)); mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main));
} }
} }
@ -631,11 +629,10 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
// If IME is in voice mode, but still needs to show the voice warning dialog, // If IME is in voice mode, but still needs to show the voice warning dialog,
// keep showing the warning. // keep showing the warning.
if (mSubtypeSwitcher.isVoiceMode() && token != null) { if (mSubtypeSwitcher.isVoiceMode() && token != null) {
if (needsToShowWarningDialog()) { // Close keyboard view if it is been shown.
showVoiceWarningDialog(false, token, false); if (KeyboardSwitcher.getInstance().isInputViewShown())
} else { KeyboardSwitcher.getInstance().getInputView().closing();
startListening(false, token, false); startListening(false, token, false);
}
} }
// If we have no token, onAttachedToWindow will take care of showing dialog and start // If we have no token, onAttachedToWindow will take care of showing dialog and start
// listening. // listening.
@ -668,7 +665,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
// onCurrentInputMethodSubtypeChanged() will be called first. LatinIME will know // onCurrentInputMethodSubtypeChanged() will be called first. LatinIME will know
// that it's in keyboard mode and SubtypeSwitcher will call onCancelVoice(). // that it's in keyboard mode and SubtypeSwitcher will call onCancelVoice().
mRecognizing = false; mRecognizing = false;
mContext.switchToKeyboardView(); mService.switchToKeyboardView();
} }
} }
} }
@ -686,8 +683,8 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
public FieldContext makeFieldContext() { public FieldContext makeFieldContext() {
SubtypeSwitcher switcher = SubtypeSwitcher.getInstance(); SubtypeSwitcher switcher = SubtypeSwitcher.getInstance();
return new FieldContext(mContext.getCurrentInputConnection(), return new FieldContext(mService.getCurrentInputConnection(),
mContext.getCurrentInputEditorInfo(), switcher.getInputLocaleStr(), mService.getCurrentInputEditorInfo(), switcher.getInputLocaleStr(),
switcher.getEnabledLanguages()); switcher.getEnabledLanguages());
} }