2009-03-13 22:11:42 +00:00
|
|
|
/*
|
2010-03-26 22:07:10 +00:00
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
2011-01-19 08:44:39 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
* use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at
|
2010-01-28 18:09:44 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-01-28 18:09:44 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations under
|
|
|
|
* the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2011-03-17 02:37:51 +00:00
|
|
|
import com.android.inputmethod.compat.CompatUtils;
|
2011-03-18 05:49:06 +00:00
|
|
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
2011-04-21 06:35:07 +00:00
|
|
|
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
|
2011-03-25 00:42:09 +00:00
|
|
|
import com.android.inputmethod.deprecated.VoiceProxy;
|
2011-03-23 21:36:37 +00:00
|
|
|
import com.android.inputmethod.compat.VibratorCompatWrapper;
|
2010-02-09 22:17:30 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
2010-03-05 23:49:16 +00:00
|
|
|
import android.app.backup.BackupManager;
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.content.DialogInterface;
|
2011-04-01 10:31:30 +00:00
|
|
|
import android.content.Intent;
|
2009-07-05 20:17:13 +00:00
|
|
|
import android.content.SharedPreferences;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Bundle;
|
2009-03-26 00:39:38 +00:00
|
|
|
import android.preference.CheckBoxPreference;
|
2010-02-09 22:17:30 +00:00
|
|
|
import android.preference.ListPreference;
|
2011-01-14 05:02:46 +00:00
|
|
|
import android.preference.Preference;
|
|
|
|
import android.preference.Preference.OnPreferenceClickListener;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.preference.PreferenceActivity;
|
|
|
|
import android.preference.PreferenceGroup;
|
2011-01-14 05:02:46 +00:00
|
|
|
import android.preference.PreferenceScreen;
|
2010-03-30 17:05:53 +00:00
|
|
|
import android.speech.SpeechRecognizer;
|
2009-03-26 00:39:38 +00:00
|
|
|
import android.text.AutoText;
|
2010-11-30 14:35:56 +00:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.util.Log;
|
2010-11-30 14:35:56 +00:00
|
|
|
import android.widget.TextView;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-11-29 08:57:48 +00:00
|
|
|
import java.util.Locale;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-12-09 12:06:26 +00:00
|
|
|
public class Settings extends PreferenceActivity
|
2010-01-16 20:21:23 +00:00
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
2011-01-14 05:02:46 +00:00
|
|
|
DialogInterface.OnDismissListener, OnPreferenceClickListener {
|
2010-12-09 12:06:26 +00:00
|
|
|
private static final String TAG = "Settings";
|
2009-07-05 20:17:13 +00:00
|
|
|
|
2011-01-19 06:07:14 +00:00
|
|
|
public static final String PREF_GENERAL_SETTINGS_KEY = "general_settings";
|
2010-12-09 12:06:26 +00:00
|
|
|
public static final String PREF_VIBRATE_ON = "vibrate_on";
|
|
|
|
public static final String PREF_SOUND_ON = "sound_on";
|
|
|
|
public static final String PREF_POPUP_ON = "popup_on";
|
|
|
|
public static final String PREF_RECORRECTION_ENABLED = "recorrection_enabled";
|
|
|
|
public static final String PREF_AUTO_CAP = "auto_cap";
|
2010-12-02 11:54:32 +00:00
|
|
|
public static final String PREF_SETTINGS_KEY = "settings_key";
|
2010-12-09 12:06:26 +00:00
|
|
|
public static final String PREF_VOICE_SETTINGS_KEY = "voice_mode";
|
|
|
|
public static final String PREF_INPUT_LANGUAGE = "input_language";
|
|
|
|
public static final String PREF_SELECTED_LANGUAGES = "selected_languages";
|
2010-12-13 03:06:57 +00:00
|
|
|
public static final String PREF_SUBTYPES = "subtype_settings";
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-09 12:06:26 +00:00
|
|
|
public static final String PREF_PREDICTION_SETTINGS_KEY = "prediction_settings";
|
|
|
|
public static final String PREF_QUICK_FIXES = "quick_fixes";
|
|
|
|
public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting";
|
2010-12-11 08:06:24 +00:00
|
|
|
public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold";
|
2010-12-09 12:06:26 +00:00
|
|
|
public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
|
2011-04-01 10:31:30 +00:00
|
|
|
public static final String PREF_DEBUG_SETTINGS = "debug_settings";
|
2011-04-21 06:35:07 +00:00
|
|
|
public static final String PREF_LANGUAGE_SELECTION = "language_selection";
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-01-19 08:44:39 +00:00
|
|
|
public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Dialog ids
|
|
|
|
private static final int VOICE_INPUT_CONFIRM_DIALOG = 0;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-01-14 05:02:46 +00:00
|
|
|
private PreferenceScreen mInputLanguageSelection;
|
2009-03-26 00:39:38 +00:00
|
|
|
private CheckBoxPreference mQuickFixes;
|
2010-02-09 22:17:30 +00:00
|
|
|
private ListPreference mVoicePreference;
|
2010-09-15 04:37:52 +00:00
|
|
|
private ListPreference mSettingsKeyPreference;
|
2011-01-25 08:23:46 +00:00
|
|
|
private ListPreference mShowCorrectionSuggestionsPreference;
|
2010-12-11 08:06:24 +00:00
|
|
|
private ListPreference mAutoCorrectionThreshold;
|
2010-09-28 03:23:26 +00:00
|
|
|
private CheckBoxPreference mBigramSuggestion;
|
2011-04-01 10:31:30 +00:00
|
|
|
private Preference mDebugSettingsPreference;
|
2010-02-09 22:17:30 +00:00
|
|
|
private boolean mVoiceOn;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-11-30 14:35:56 +00:00
|
|
|
private AlertDialog mDialog;
|
|
|
|
|
2011-03-25 00:42:09 +00:00
|
|
|
private VoiceProxy.VoiceLoggerWrapper mVoiceLogger;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean mOkClicked = false;
|
2010-02-09 22:17:30 +00:00
|
|
|
private String mVoiceModeOff;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-11 08:06:24 +00:00
|
|
|
private void ensureConsistencyOfAutoCorrectionSettings() {
|
|
|
|
final String autoCorrectionOff = getResources().getString(
|
2010-12-13 03:37:23 +00:00
|
|
|
R.string.auto_correction_threshold_mode_index_off);
|
2010-12-11 08:06:24 +00:00
|
|
|
final String currentSetting = mAutoCorrectionThreshold.getValue();
|
|
|
|
mBigramSuggestion.setEnabled(!currentSetting.equals(autoCorrectionOff));
|
2010-09-28 03:23:26 +00:00
|
|
|
}
|
2011-01-14 05:02:46 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle icicle) {
|
|
|
|
super.onCreate(icicle);
|
|
|
|
addPreferencesFromResource(R.xml.prefs);
|
2011-01-14 05:02:46 +00:00
|
|
|
mInputLanguageSelection = (PreferenceScreen) findPreference(PREF_SUBTYPES);
|
|
|
|
mInputLanguageSelection.setOnPreferenceClickListener(this);
|
2010-12-09 12:06:26 +00:00
|
|
|
mQuickFixes = (CheckBoxPreference) findPreference(PREF_QUICK_FIXES);
|
|
|
|
mVoicePreference = (ListPreference) findPreference(PREF_VOICE_SETTINGS_KEY);
|
2010-09-15 04:37:52 +00:00
|
|
|
mSettingsKeyPreference = (ListPreference) findPreference(PREF_SETTINGS_KEY);
|
2011-01-25 08:23:46 +00:00
|
|
|
mShowCorrectionSuggestionsPreference =
|
|
|
|
(ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING);
|
2010-01-16 20:21:23 +00:00
|
|
|
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-02-09 22:17:30 +00:00
|
|
|
mVoiceModeOff = getString(R.string.voice_mode_off);
|
2010-12-09 12:06:26 +00:00
|
|
|
mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff)
|
|
|
|
.equals(mVoiceModeOff));
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceLogger = VoiceProxy.VoiceLoggerWrapper.getInstance(this);
|
2010-09-28 03:23:26 +00:00
|
|
|
|
2010-12-11 08:06:24 +00:00
|
|
|
mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD);
|
2010-09-28 03:23:26 +00:00
|
|
|
mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
|
2011-04-01 10:31:30 +00:00
|
|
|
mDebugSettingsPreference = findPreference(PREF_DEBUG_SETTINGS);
|
|
|
|
if (mDebugSettingsPreference != null) {
|
|
|
|
final Intent debugSettingsIntent = new Intent(Intent.ACTION_MAIN);
|
|
|
|
debugSettingsIntent.setClassName(getPackageName(), DebugSettings.class.getName());
|
|
|
|
mDebugSettingsPreference.setIntent(debugSettingsIntent);
|
|
|
|
}
|
|
|
|
|
2010-12-11 08:06:24 +00:00
|
|
|
ensureConsistencyOfAutoCorrectionSettings();
|
2010-10-22 05:28:12 +00:00
|
|
|
|
2011-01-19 06:07:14 +00:00
|
|
|
final PreferenceGroup generalSettings =
|
2011-01-19 08:44:39 +00:00
|
|
|
(PreferenceGroup) findPreference(PREF_GENERAL_SETTINGS_KEY);
|
|
|
|
final PreferenceGroup textCorrectionGroup =
|
|
|
|
(PreferenceGroup) findPreference(PREF_PREDICTION_SETTINGS_KEY);
|
2011-01-19 06:07:14 +00:00
|
|
|
|
2010-10-22 05:28:12 +00:00
|
|
|
final boolean showSettingsKeyOption = getResources().getBoolean(
|
|
|
|
R.bool.config_enable_show_settings_key_option);
|
2010-11-30 14:35:56 +00:00
|
|
|
if (!showSettingsKeyOption) {
|
2011-01-19 06:07:14 +00:00
|
|
|
generalSettings.removePreference(mSettingsKeyPreference);
|
2010-11-30 14:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final boolean showVoiceKeyOption = getResources().getBoolean(
|
|
|
|
R.bool.config_enable_show_voice_key_option);
|
|
|
|
if (!showVoiceKeyOption) {
|
2011-01-19 06:07:14 +00:00
|
|
|
generalSettings.removePreference(mVoicePreference);
|
2010-11-30 14:35:56 +00:00
|
|
|
}
|
2010-11-11 09:15:41 +00:00
|
|
|
|
2011-03-23 21:36:37 +00:00
|
|
|
if (!VibratorCompatWrapper.getInstance(this).hasVibrator()) {
|
2011-01-19 06:07:14 +00:00
|
|
|
generalSettings.removePreference(findPreference(PREF_VIBRATE_ON));
|
2010-11-11 09:15:41 +00:00
|
|
|
}
|
2010-12-13 03:06:57 +00:00
|
|
|
|
|
|
|
final boolean showSubtypeSettings = getResources().getBoolean(
|
|
|
|
R.bool.config_enable_show_subtype_settings);
|
|
|
|
if (!showSubtypeSettings) {
|
2011-01-19 06:07:14 +00:00
|
|
|
generalSettings.removePreference(findPreference(PREF_SUBTYPES));
|
2010-12-13 03:06:57 +00:00
|
|
|
}
|
2011-01-18 06:20:35 +00:00
|
|
|
|
|
|
|
final boolean showPopupOption = getResources().getBoolean(
|
|
|
|
R.bool.config_enable_show_popup_on_keypress_option);
|
|
|
|
if (!showPopupOption) {
|
2011-01-19 06:07:14 +00:00
|
|
|
generalSettings.removePreference(findPreference(PREF_POPUP_ON));
|
2011-01-18 06:20:35 +00:00
|
|
|
}
|
2011-01-18 08:45:22 +00:00
|
|
|
|
|
|
|
final boolean showRecorrectionOption = getResources().getBoolean(
|
|
|
|
R.bool.config_enable_show_recorrection_option);
|
|
|
|
if (!showRecorrectionOption) {
|
2011-01-19 06:07:14 +00:00
|
|
|
generalSettings.removePreference(findPreference(PREF_RECORRECTION_ENABLED));
|
2011-01-18 08:45:22 +00:00
|
|
|
}
|
2011-01-19 08:44:39 +00:00
|
|
|
|
|
|
|
final boolean showQuickFixesOption = getResources().getBoolean(
|
|
|
|
R.bool.config_enable_quick_fixes_option);
|
|
|
|
if (!showQuickFixesOption) {
|
|
|
|
textCorrectionGroup.removePreference(findPreference(PREF_QUICK_FIXES));
|
|
|
|
}
|
|
|
|
|
|
|
|
final boolean showBigramSuggestionsOption = getResources().getBoolean(
|
|
|
|
R.bool.config_enable_bigram_suggestions_option);
|
|
|
|
if (!showBigramSuggestionsOption) {
|
|
|
|
textCorrectionGroup.removePreference(findPreference(PREF_BIGRAM_SUGGESTIONS));
|
|
|
|
}
|
|
|
|
|
|
|
|
final boolean showUsabilityModeStudyOption = getResources().getBoolean(
|
|
|
|
R.bool.config_enable_usability_study_mode_option);
|
|
|
|
if (!showUsabilityModeStudyOption) {
|
|
|
|
getPreferenceScreen().removePreference(findPreference(PREF_USABILITY_STUDY_MODE));
|
|
|
|
}
|
2011-04-21 06:35:07 +00:00
|
|
|
|
|
|
|
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
|
|
|
|
generalSettings.removePreference(findPreference(PREF_LANGUAGE_SELECTION));
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-26 00:39:38 +00:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
int autoTextSize = AutoText.getSize(getListView());
|
|
|
|
if (autoTextSize < 1) {
|
2010-12-09 12:06:26 +00:00
|
|
|
((PreferenceGroup) findPreference(PREF_PREDICTION_SETTINGS_KEY))
|
2010-01-16 20:21:23 +00:00
|
|
|
.removePreference(mQuickFixes);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-03-25 00:42:09 +00:00
|
|
|
if (!VoiceProxy.VOICE_INSTALLED
|
2010-03-30 17:05:53 +00:00
|
|
|
|| !SpeechRecognizer.isRecognitionAvailable(this)) {
|
2010-01-16 20:21:23 +00:00
|
|
|
getPreferenceScreen().removePreference(mVoicePreference);
|
2010-02-09 22:17:30 +00:00
|
|
|
} else {
|
|
|
|
updateVoiceModeSummary();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2010-09-15 04:37:52 +00:00
|
|
|
updateSettingsKeySummary();
|
2011-01-25 08:23:46 +00:00
|
|
|
updateShowCorrectionSuggestionsSummary();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-07-05 20:17:13 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
|
|
|
|
this);
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-02-09 22:17:30 +00:00
|
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
2009-07-05 20:17:13 +00:00
|
|
|
(new BackupManager(this)).dataChanged();
|
2010-02-09 22:17:30 +00:00
|
|
|
// If turning on voice input, show dialog
|
2010-12-09 12:06:26 +00:00
|
|
|
if (key.equals(PREF_VOICE_SETTINGS_KEY) && !mVoiceOn) {
|
|
|
|
if (!prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff)
|
2010-02-09 22:17:30 +00:00
|
|
|
.equals(mVoiceModeOff)) {
|
|
|
|
showVoiceConfirmation();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-11 08:06:24 +00:00
|
|
|
ensureConsistencyOfAutoCorrectionSettings();
|
2010-12-09 12:06:26 +00:00
|
|
|
mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff)
|
|
|
|
.equals(mVoiceModeOff));
|
2010-02-09 22:17:30 +00:00
|
|
|
updateVoiceModeSummary();
|
2010-09-15 04:37:52 +00:00
|
|
|
updateSettingsKeySummary();
|
2011-01-25 08:23:46 +00:00
|
|
|
updateShowCorrectionSuggestionsSummary();
|
2010-09-15 04:37:52 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 05:02:46 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference pref) {
|
|
|
|
if (pref == mInputLanguageSelection) {
|
2011-03-17 02:37:51 +00:00
|
|
|
startActivity(CompatUtils.getInputLanguageSelectionIntent(
|
2011-03-18 05:49:06 +00:00
|
|
|
Utils.getInputMethodId(InputMethodManagerCompatWrapper.getInstance(this),
|
2011-03-17 02:37:51 +00:00
|
|
|
getApplicationInfo().packageName), 0));
|
2011-01-14 05:02:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-25 08:23:46 +00:00
|
|
|
private void updateShowCorrectionSuggestionsSummary() {
|
|
|
|
mShowCorrectionSuggestionsPreference.setSummary(
|
|
|
|
getResources().getStringArray(R.array.prefs_suggestion_visibilities)
|
|
|
|
[mShowCorrectionSuggestionsPreference.findIndexOfValue(
|
|
|
|
mShowCorrectionSuggestionsPreference.getValue())]);
|
|
|
|
}
|
|
|
|
|
2010-09-15 04:37:52 +00:00
|
|
|
private void updateSettingsKeySummary() {
|
|
|
|
mSettingsKeyPreference.setSummary(
|
|
|
|
getResources().getStringArray(R.array.settings_key_modes)
|
|
|
|
[mSettingsKeyPreference.findIndexOfValue(mSettingsKeyPreference.getValue())]);
|
2010-02-09 22:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void showVoiceConfirmation() {
|
|
|
|
mOkClicked = false;
|
|
|
|
showDialog(VOICE_INPUT_CONFIRM_DIALOG);
|
2010-11-30 14:35:56 +00:00
|
|
|
// Make URL in the dialog message clickable
|
|
|
|
if (mDialog != null) {
|
|
|
|
TextView textView = (TextView) mDialog.findViewById(android.R.id.message);
|
|
|
|
if (textView != null) {
|
|
|
|
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
}
|
|
|
|
}
|
2010-02-09 22:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVoiceModeSummary() {
|
|
|
|
mVoicePreference.setSummary(
|
|
|
|
getResources().getStringArray(R.array.voice_input_modes_summary)
|
|
|
|
[mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
protected Dialog onCreateDialog(int id) {
|
|
|
|
switch (id) {
|
|
|
|
case VOICE_INPUT_CONFIRM_DIALOG:
|
|
|
|
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-01-16 20:21:23 +00:00
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
|
if (whichButton == DialogInterface.BUTTON_NEGATIVE) {
|
2010-02-09 22:17:30 +00:00
|
|
|
mVoicePreference.setValue(mVoiceModeOff);
|
2011-03-16 21:57:08 +00:00
|
|
|
mVoiceLogger.settingsWarningDialogCancel();
|
2010-01-16 20:21:23 +00:00
|
|
|
} else if (whichButton == DialogInterface.BUTTON_POSITIVE) {
|
|
|
|
mOkClicked = true;
|
2011-03-16 21:57:08 +00:00
|
|
|
mVoiceLogger.settingsWarningDialogOk();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
updateVoicePreference();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
|
|
.setTitle(R.string.voice_warning_title)
|
|
|
|
.setPositiveButton(android.R.string.ok, listener)
|
|
|
|
.setNegativeButton(android.R.string.cancel, listener);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Get the current list of supported locales and check the current locale against
|
|
|
|
// that list, to decide whether to put a warning that voice input will not work in
|
|
|
|
// the current language as part of the pop-up confirmation dialog.
|
2010-11-17 07:35:35 +00:00
|
|
|
boolean localeSupported = SubtypeSwitcher.getInstance().isVoiceSupported(
|
2010-01-16 20:21:23 +00:00
|
|
|
Locale.getDefault().toString());
|
|
|
|
|
2010-11-30 14:35:56 +00:00
|
|
|
final CharSequence message;
|
2010-01-16 20:21:23 +00:00
|
|
|
if (localeSupported) {
|
2010-11-30 14:35:56 +00:00
|
|
|
message = TextUtils.concat(
|
|
|
|
getText(R.string.voice_warning_may_not_understand), "\n\n",
|
|
|
|
getText(R.string.voice_hint_dialog_message));
|
2010-01-16 20:21:23 +00:00
|
|
|
} else {
|
2010-11-30 14:35:56 +00:00
|
|
|
message = TextUtils.concat(
|
|
|
|
getText(R.string.voice_warning_locale_not_supported), "\n\n",
|
|
|
|
getText(R.string.voice_warning_may_not_understand), "\n\n",
|
|
|
|
getText(R.string.voice_hint_dialog_message));
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2010-11-30 14:35:56 +00:00
|
|
|
builder.setMessage(message);
|
2010-01-16 20:21:23 +00:00
|
|
|
AlertDialog dialog = builder.create();
|
2010-11-30 14:35:56 +00:00
|
|
|
mDialog = dialog;
|
2010-01-16 20:21:23 +00:00
|
|
|
dialog.setOnDismissListener(this);
|
2011-03-16 21:57:08 +00:00
|
|
|
mVoiceLogger.settingsWarningDialogShown();
|
2010-01-16 20:21:23 +00:00
|
|
|
return dialog;
|
|
|
|
default:
|
|
|
|
Log.e(TAG, "unknown dialog " + id);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-01-16 20:21:23 +00:00
|
|
|
public void onDismiss(DialogInterface dialog) {
|
2011-03-16 21:57:08 +00:00
|
|
|
mVoiceLogger.settingsWarningDialogDismissed();
|
2010-01-16 20:21:23 +00:00
|
|
|
if (!mOkClicked) {
|
|
|
|
// This assumes that onPreferenceClick gets called first, and this if the user
|
|
|
|
// agreed after the warning, we set the mOkClicked value to true.
|
2010-02-09 22:17:30 +00:00
|
|
|
mVoicePreference.setValue(mVoiceModeOff);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private void updateVoicePreference() {
|
2010-02-09 22:17:30 +00:00
|
|
|
boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff);
|
2011-03-16 21:57:08 +00:00
|
|
|
mVoiceLogger.voiceInputSettingEnabled(isChecked);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|