Merge "Disable VoiceInputLogger inside LatinIME"

This commit is contained in:
Tadashi G. Takaoka 2011-07-22 02:41:31 -07:00 committed by Android (Google) Code Review
commit f3e7688361
4 changed files with 114 additions and 91 deletions

View file

@ -17,11 +17,11 @@
package com.android.inputmethod.deprecated; package com.android.inputmethod.deprecated;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
import com.android.inputmethod.deprecated.voice.FieldContext; import com.android.inputmethod.deprecated.voice.FieldContext;
import com.android.inputmethod.deprecated.voice.Hints; import com.android.inputmethod.deprecated.voice.Hints;
import com.android.inputmethod.deprecated.voice.SettingsUtil; import com.android.inputmethod.deprecated.voice.SettingsUtil;
import com.android.inputmethod.deprecated.voice.VoiceInput; import com.android.inputmethod.deprecated.voice.VoiceInput;
import com.android.inputmethod.deprecated.voice.VoiceInputLogger;
import com.android.inputmethod.keyboard.KeyboardSwitcher; 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;
@ -71,7 +71,8 @@ import java.util.Map;
public class VoiceProxy implements VoiceInput.UiListener { public class VoiceProxy implements VoiceInput.UiListener {
private static final VoiceProxy sInstance = new VoiceProxy(); private static final VoiceProxy sInstance = new VoiceProxy();
public static final boolean VOICE_INSTALLED = true; public static final boolean VOICE_INSTALLED =
!InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED;
private static final boolean ENABLE_VOICE_BUTTON = true; private static final boolean ENABLE_VOICE_BUTTON = true;
private static final String PREF_VOICE_MODE = "voice_mode"; private static final String PREF_VOICE_MODE = "voice_mode";
// Whether or not the user has used voice input before (and thus, whether to show the // Whether or not the user has used voice input before (and thus, whether to show the
@ -125,24 +126,23 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
private void initInternal(LatinIME service, SharedPreferences prefs, UIHandler h) { private void initInternal(LatinIME service, SharedPreferences prefs, UIHandler h) {
if (!VOICE_INSTALLED) {
return;
}
mService = service; mService = service;
mHandler = h; mHandler = h;
mMinimumVoiceRecognitionViewHeightPixel = Utils.dipToPixel( mMinimumVoiceRecognitionViewHeightPixel = Utils.dipToPixel(
Utils.getDipScale(service), RECOGNITIONVIEW_MINIMUM_HEIGHT_DIP); Utils.getDipScale(service), RECOGNITIONVIEW_MINIMUM_HEIGHT_DIP);
mImm = InputMethodManagerCompatWrapper.getInstance(); mImm = InputMethodManagerCompatWrapper.getInstance();
mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance();
if (VOICE_INSTALLED) { mVoiceInput = new VoiceInput(service, this);
mVoiceInput = new VoiceInput(service, this); mHints = new Hints(service, prefs, new Hints.Display() {
mHints = new Hints(service, prefs, new Hints.Display() { @Override
@Override public void showHint(int viewResource) {
public void showHint(int viewResource) { View view = LayoutInflater.from(mService).inflate(viewResource, null);
View view = LayoutInflater.from(mService).inflate(viewResource, null); mIsShowingHint = true;
// mService.setCandidatesView(view); }
// mService.setCandidatesViewShown(true); });
mIsShowingHint = true;
}
});
}
} }
private VoiceProxy() { private VoiceProxy() {
@ -170,6 +170,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
public void flushAndLogAllTextModificationCounters(int index, CharSequence suggestion, public void flushAndLogAllTextModificationCounters(int index, CharSequence suggestion,
String wordSeparators) { String wordSeparators) {
if (!VOICE_INSTALLED) {
return;
}
if (mAfterVoiceInput && mShowingVoiceSuggestions) { if (mAfterVoiceInput && mShowingVoiceSuggestions) {
mVoiceInput.flushAllTextModificationCounters(); mVoiceInput.flushAllTextModificationCounters();
// send this intent AFTER logging any prior aggregated edits. // send this intent AFTER logging any prior aggregated edits.
@ -308,6 +311,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
public void hideVoiceWindow(boolean configurationChanging) { public void hideVoiceWindow(boolean configurationChanging) {
if (!VOICE_INSTALLED) {
return;
}
if (!configurationChanging) { if (!configurationChanging) {
if (mAfterVoiceInput) if (mAfterVoiceInput)
mVoiceInput.logInputEnded(); mVoiceInput.logInputEnded();
@ -324,6 +330,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
public void setCursorAndSelection(int newSelEnd, int newSelStart) { public void setCursorAndSelection(int newSelEnd, int newSelStart) {
if (!VOICE_INSTALLED) {
return;
}
if (mAfterVoiceInput) { if (mAfterVoiceInput) {
mVoiceInput.setCursorPos(newSelEnd); mVoiceInput.setCursorPos(newSelEnd);
mVoiceInput.setSelectionSpan(newSelEnd - newSelStart); mVoiceInput.setSelectionSpan(newSelEnd - newSelStart);
@ -366,6 +375,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
private void revertVoiceInput() { private void revertVoiceInput() {
if (!VOICE_INSTALLED) {
return;
}
InputConnection ic = mService.getCurrentInputConnection(); InputConnection ic = mService.getCurrentInputConnection();
if (ic != null) ic.commitText("", 1); if (ic != null) ic.commitText("", 1);
mService.updateSuggestions(); mService.updateSuggestions();
@ -393,6 +405,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
public void rememberReplacedWord(CharSequence suggestion,String wordSeparators) { public void rememberReplacedWord(CharSequence suggestion,String wordSeparators) {
if (!VOICE_INSTALLED) {
return;
}
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(
@ -419,6 +434,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
* @return true if an alternative was found, false otherwise. * @return true if an alternative was found, false otherwise.
*/ */
public boolean applyVoiceAlternatives(EditingUtils.SelectedWord touching) { public boolean applyVoiceAlternatives(EditingUtils.SelectedWord touching) {
if (!VOICE_INSTALLED) {
return false;
}
// Search for result in spoken word alternatives // Search for result in spoken word alternatives
String selectedWord = touching.mWord.toString().trim(); String selectedWord = touching.mWord.toString().trim();
if (!mWordToSuggestions.containsKey(selectedWord)) { if (!mWordToSuggestions.containsKey(selectedWord)) {
@ -448,6 +466,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
public void handleBackspace() { public void handleBackspace() {
if (!VOICE_INSTALLED) {
return;
}
if (mAfterVoiceInput) { if (mAfterVoiceInput) {
// Don't log delete if the user is pressing delete at // Don't log delete if the user is pressing delete at
// the beginning of the text box (hence not deleting anything) // the beginning of the text box (hence not deleting anything)
@ -462,6 +483,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
public void handleCharacter() { public void handleCharacter() {
if (!VOICE_INSTALLED) {
return;
}
commitVoiceInput(); commitVoiceInput();
if (mAfterVoiceInput) { if (mAfterVoiceInput) {
// Assume input length is 1. This assumption fails for smiley face insertions. // Assume input length is 1. This assumption fails for smiley face insertions.
@ -470,6 +494,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
public void handleSeparator() { public void handleSeparator() {
if (!VOICE_INSTALLED) {
return;
}
commitVoiceInput(); commitVoiceInput();
if (mAfterVoiceInput){ if (mAfterVoiceInput){
// Assume input length is 1. This assumption fails for smiley face insertions. // Assume input length is 1. This assumption fails for smiley face insertions.
@ -485,6 +512,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
public void handleVoiceResults(boolean capitalizeFirstWord) { public void handleVoiceResults(boolean capitalizeFirstWord) {
if (!VOICE_INSTALLED) {
return;
}
mAfterVoiceInput = true; mAfterVoiceInput = true;
mImmediatelyAfterVoiceInput = true; mImmediatelyAfterVoiceInput = true;
@ -659,7 +689,14 @@ public class VoiceProxy implements VoiceInput.UiListener {
&& SpeechRecognizer.isRecognitionAvailable(mService); && SpeechRecognizer.isRecognitionAvailable(mService);
} }
public static boolean isRecognitionAvailable(Context context) {
return SpeechRecognizer.isRecognitionAvailable(context);
}
public void loadSettings(EditorInfo attribute, SharedPreferences sp) { public void loadSettings(EditorInfo attribute, SharedPreferences sp) {
if (!VOICE_INSTALLED) {
return;
}
mHasUsedVoiceInput = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT, false); mHasUsedVoiceInput = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT, false);
mHasUsedVoiceInputUnsupportedLocale = mHasUsedVoiceInputUnsupportedLocale =
sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false); sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false);
@ -683,6 +720,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
public void onStartInputView(IBinder keyboardViewToken) { public void onStartInputView(IBinder keyboardViewToken) {
if (!VOICE_INSTALLED) {
return;
}
// If keyboardViewToken is null, keyboardView is not attached but voiceView is attached. // If keyboardViewToken is null, keyboardView is not attached but voiceView is attached.
IBinder windowToken = keyboardViewToken != null ? keyboardViewToken IBinder windowToken = keyboardViewToken != null ? keyboardViewToken
: mVoiceInput.getView().getWindowToken(); : mVoiceInput.getView().getWindowToken();
@ -699,12 +739,18 @@ public class VoiceProxy implements VoiceInput.UiListener {
} }
public void onAttachedToWindow() { public void onAttachedToWindow() {
if (!VOICE_INSTALLED) {
return;
}
// After onAttachedToWindow, we can show the voice warning dialog. See startListening() // After onAttachedToWindow, we can show the voice warning dialog. See startListening()
// above. // above.
VoiceInputWrapper.getInstance().setVoiceInput(mVoiceInput, mSubtypeSwitcher); VoiceInputWrapper.getInstance().setVoiceInput(mVoiceInput, mSubtypeSwitcher);
} }
public void onConfigurationChanged(Configuration configuration) { public void onConfigurationChanged(Configuration configuration) {
if (!VOICE_INSTALLED) {
return;
}
if (mRecognizing) { if (mRecognizing) {
switchToRecognitionStatusView(configuration); switchToRecognitionStatusView(configuration);
} }
@ -712,6 +758,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
@Override @Override
public void onCancelVoice() { public void onCancelVoice() {
if (!VOICE_INSTALLED) {
return;
}
if (mRecognizing) { if (mRecognizing) {
if (mSubtypeSwitcher.isVoiceMode()) { if (mSubtypeSwitcher.isVoiceMode()) {
// If voice mode is being canceled within LatinIME (i.e. time-out or user // If voice mode is being canceled within LatinIME (i.e. time-out or user
@ -733,6 +782,9 @@ public class VoiceProxy implements VoiceInput.UiListener {
@Override @Override
public void onVoiceResults(List<String> candidates, public void onVoiceResults(List<String> candidates,
Map<String, List<CharSequence>> alternatives) { Map<String, List<CharSequence>> alternatives) {
if (!VOICE_INSTALLED) {
return;
}
if (!mRecognizing) { if (!mRecognizing) {
return; return;
} }
@ -748,59 +800,22 @@ public class VoiceProxy implements VoiceInput.UiListener {
switcher.getEnabledLanguages()); switcher.getEnabledLanguages());
} }
private class VoiceResults { // TODO: make this private (proguard issue)
public static class VoiceResults {
List<String> candidates; List<String> candidates;
Map<String, List<CharSequence>> alternatives; Map<String, List<CharSequence>> alternatives;
} }
public static class VoiceLoggerWrapper {
private static final VoiceLoggerWrapper sLoggerWrapperInstance = new VoiceLoggerWrapper();
private VoiceInputLogger mLogger;
public static VoiceLoggerWrapper getInstance(Context context) {
if (sLoggerWrapperInstance.mLogger == null) {
// Not thread safe, but it's ok.
sLoggerWrapperInstance.mLogger = VoiceInputLogger.getLogger(context);
}
return sLoggerWrapperInstance;
}
// private for the singleton
private VoiceLoggerWrapper() {
}
public void settingsWarningDialogCancel() {
mLogger.settingsWarningDialogCancel();
}
public void settingsWarningDialogOk() {
mLogger.settingsWarningDialogOk();
}
public void settingsWarningDialogShown() {
mLogger.settingsWarningDialogShown();
}
public void settingsWarningDialogDismissed() {
mLogger.settingsWarningDialogDismissed();
}
public void voiceInputSettingEnabled(boolean enabled) {
if (enabled) {
mLogger.voiceInputSettingEnabled();
} else {
mLogger.voiceInputSettingDisabled();
}
}
}
public static class VoiceInputWrapper { public static class VoiceInputWrapper {
private static final VoiceInputWrapper sInputWrapperInstance = new VoiceInputWrapper(); private static final VoiceInputWrapper sInputWrapperInstance = new VoiceInputWrapper();
private VoiceInput mVoiceInput; private VoiceInput mVoiceInput;
public static VoiceInputWrapper getInstance() { public static VoiceInputWrapper getInstance() {
return sInputWrapperInstance; return sInputWrapperInstance;
} }
public void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) { private void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) {
if (!VOICE_INSTALLED) {
return;
}
if (mVoiceInput == null && voiceInput != null) { if (mVoiceInput == null && voiceInput != null) {
mVoiceInput = voiceInput; mVoiceInput = voiceInput;
} }

View file

@ -148,11 +148,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
public void loadKeyboard(EditorInfo attribute, boolean voiceKeyEnabled, public void loadKeyboard(EditorInfo attribute, Settings.Values settings) {
boolean voiceButtonOnPrimary) {
mSwitchState = SWITCH_STATE_ALPHA; mSwitchState = SWITCH_STATE_ALPHA;
try { try {
loadKeyboardInternal(attribute, voiceKeyEnabled, voiceButtonOnPrimary, false); loadKeyboardInternal(attribute, settings.isVoiceButtonEnabled(attribute),
settings.isVoiceButtonOnPrimary(), false);
} catch (RuntimeException e) { } catch (RuntimeException e) {
// Get KeyboardId to record which keyboard has been failed to load. // Get KeyboardId to record which keyboard has been failed to load.
final KeyboardId id = getKeyboardId(attribute, false); final KeyboardId id = getKeyboardId(attribute, false);

View file

@ -575,9 +575,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
LanguageSwitcherProxy.loadSettings(); LanguageSwitcherProxy.loadSettings();
if (mSubtypeSwitcher.isKeyboardMode()) { if (mSubtypeSwitcher.isKeyboardMode()) {
switcher.loadKeyboard(attribute, switcher.loadKeyboard(attribute, mSettingsValues);
mSubtypeSwitcher.isShortcutImeEnabled() && voiceIme.isVoiceButtonEnabled(),
voiceIme.isVoiceButtonOnPrimary());
switcher.updateShiftState(); switcher.updateShiftState();
} }
@ -1900,9 +1898,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
setInputView(mKeyboardSwitcher.onCreateInputView()); setInputView(mKeyboardSwitcher.onCreateInputView());
} }
// Reload keyboard because the current language has been changed. // Reload keyboard because the current language has been changed.
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettingsValues);
mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceProxy.isVoiceButtonEnabled(),
mVoiceProxy.isVoiceButtonOnPrimary());
initSuggest(); initSuggest();
loadSettings(); loadSettings();
mKeyboardSwitcher.updateShiftState(); mKeyboardSwitcher.updateShiftState();

View file

@ -16,13 +16,6 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethodcommon.InputMethodSettingsActivity;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
@ -40,12 +33,20 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceGroup; import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.speech.SpeechRecognizer;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log; import android.util.Log;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView; import android.widget.TextView;
import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethodcommon.InputMethodSettingsActivity;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
@ -119,6 +120,9 @@ public class Settings extends InputMethodSettingsActivity
public final boolean mBigramPredictionEnabled; public final boolean mBigramPredictionEnabled;
public final boolean mUseContactsDict; public final boolean mUseContactsDict;
private final boolean mVoiceButtonEnabled;
private final boolean mVoiceButtonOnPrimary;
public Values(final SharedPreferences prefs, final Context context, public Values(final SharedPreferences prefs, final Context context,
final String localeStr) { final String localeStr) {
final Resources res = context.getResources(); final Resources res = context.getResources();
@ -179,6 +183,12 @@ public class Settings extends InputMethodSettingsActivity
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
final String voiceMode = prefs.getString(PREF_VOICE_SETTINGS_KEY, null);
mVoiceButtonEnabled = voiceMode != null && !voiceMode.equals(
res.getString(R.string.voice_mode_off));
mVoiceButtonOnPrimary = voiceMode != null && voiceMode.equals(
res.getString(R.string.voice_mode_main));
Utils.setSystemLocale(res, savedLocale); Utils.setSystemLocale(res, savedLocale);
} }
@ -287,6 +297,17 @@ public class Settings extends InputMethodSettingsActivity
} }
return builder.setIsPunctuationSuggestions().build(); return builder.setIsPunctuationSuggestions().build();
} }
public boolean isVoiceButtonEnabled(EditorInfo attribute) {
final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
final int inputType = (attribute != null) ? attribute.inputType : 0;
return shortcutImeEnabled && mVoiceButtonEnabled
&& !InputTypeCompatUtils.isPasswordInputType(inputType);
}
public boolean isVoiceButtonOnPrimary() {
return mVoiceButtonOnPrimary;
}
} }
private PreferenceScreen mInputLanguageSelection; private PreferenceScreen mInputLanguageSelection;
@ -304,8 +325,6 @@ public class Settings extends InputMethodSettingsActivity
private AlertDialog mDialog; private AlertDialog mDialog;
private VoiceProxy.VoiceLoggerWrapper mVoiceLogger;
private boolean mOkClicked = false; private boolean mOkClicked = false;
private String mVoiceModeOff; private String mVoiceModeOff;
@ -349,7 +368,6 @@ public class Settings extends InputMethodSettingsActivity
mVoiceModeOff = getString(R.string.voice_mode_off); mVoiceModeOff = getString(R.string.voice_mode_off);
mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff) mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff)
.equals(mVoiceModeOff)); .equals(mVoiceModeOff));
mVoiceLogger = VoiceProxy.VoiceLoggerWrapper.getInstance(context);
mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD); mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD);
mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS); mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
@ -447,14 +465,17 @@ public class Settings extends InputMethodSettingsActivity
} }
} }
@SuppressWarnings("unused")
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (!VoiceProxy.VOICE_INSTALLED final boolean isShortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
|| !SpeechRecognizer.isRecognitionAvailable(getActivityInternal())) { if (isShortcutImeEnabled
getPreferenceScreen().removePreference(mVoicePreference); || (VoiceProxy.VOICE_INSTALLED
} else { && VoiceProxy.isRecognitionAvailable(getActivityInternal()))) {
updateVoiceModeSummary(); updateVoiceModeSummary();
} else {
getPreferenceScreen().removePreference(mVoicePreference);
} }
updateSettingsKeySummary(); updateSettingsKeySummary();
updateShowCorrectionSuggestionsSummary(); updateShowCorrectionSuggestionsSummary();
@ -541,6 +562,7 @@ public class Settings extends InputMethodSettingsActivity
[mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]); [mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]);
} }
@Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { switch (id) {
case VOICE_INPUT_CONFIRM_DIALOG: case VOICE_INPUT_CONFIRM_DIALOG:
@ -549,12 +571,9 @@ public class Settings extends InputMethodSettingsActivity
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
if (whichButton == DialogInterface.BUTTON_NEGATIVE) { if (whichButton == DialogInterface.BUTTON_NEGATIVE) {
mVoicePreference.setValue(mVoiceModeOff); mVoicePreference.setValue(mVoiceModeOff);
mVoiceLogger.settingsWarningDialogCancel();
} else if (whichButton == DialogInterface.BUTTON_POSITIVE) { } else if (whichButton == DialogInterface.BUTTON_POSITIVE) {
mOkClicked = true; mOkClicked = true;
mVoiceLogger.settingsWarningDialogOk();
} }
updateVoicePreference();
} }
}; };
AlertDialog.Builder builder = new AlertDialog.Builder(getActivityInternal()) AlertDialog.Builder builder = new AlertDialog.Builder(getActivityInternal())
@ -583,7 +602,6 @@ public class Settings extends InputMethodSettingsActivity
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
mDialog = dialog; mDialog = dialog;
dialog.setOnDismissListener(this); dialog.setOnDismissListener(this);
mVoiceLogger.settingsWarningDialogShown();
return dialog; return dialog;
default: default:
Log.e(TAG, "unknown dialog " + id); Log.e(TAG, "unknown dialog " + id);
@ -593,16 +611,10 @@ public class Settings extends InputMethodSettingsActivity
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
mVoiceLogger.settingsWarningDialogDismissed();
if (!mOkClicked) { if (!mOkClicked) {
// This assumes that onPreferenceClick gets called first, and this if the user // This assumes that onPreferenceClick gets called first, and this if the user
// agreed after the warning, we set the mOkClicked value to true. // agreed after the warning, we set the mOkClicked value to true.
mVoicePreference.setValue(mVoiceModeOff); mVoicePreference.setValue(mVoiceModeOff);
} }
} }
private void updateVoicePreference() {
boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff);
mVoiceLogger.voiceInputSettingEnabled(isChecked);
}
} }