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-07-01 10:40:31 +00:00
|
|
|
import android.app.Activity;
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
2011-07-01 10:40:31 +00:00
|
|
|
import android.app.Fragment;
|
2010-03-05 23:49:16 +00:00
|
|
|
import android.app.backup.BackupManager;
|
2011-05-10 06:51:43 +00:00
|
|
|
import android.content.Context;
|
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;
|
2011-05-10 06:51:43 +00:00
|
|
|
import android.content.res.Resources;
|
2011-10-11 07:39:11 +00:00
|
|
|
import android.media.AudioManager;
|
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.PreferenceGroup;
|
2011-01-14 05:02:46 +00:00
|
|
|
import android.preference.PreferenceScreen;
|
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;
|
2011-09-28 11:11:05 +00:00
|
|
|
import android.view.View;
|
2011-07-21 05:57:28 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2011-09-28 11:11:05 +00:00
|
|
|
import android.widget.SeekBar;
|
|
|
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
2010-11-30 14:35:56 +00:00
|
|
|
import android.widget.TextView;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2011-07-21 05:57:28 +00:00
|
|
|
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;
|
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
import java.util.Arrays;
|
2010-11-29 08:57:48 +00:00
|
|
|
import java.util.Locale;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2011-07-10 22:47:09 +00:00
|
|
|
public class Settings extends InputMethodSettingsActivity
|
2010-01-16 20:21:23 +00:00
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
2011-01-14 05:02:46 +00:00
|
|
|
DialogInterface.OnDismissListener, OnPreferenceClickListener {
|
2011-08-22 03:19:37 +00:00
|
|
|
private static final String TAG = Settings.class.getSimpleName();
|
2009-07-05 20:17:13 +00:00
|
|
|
|
2011-09-14 05:07:10 +00:00
|
|
|
public static final boolean ENABLE_EXPERIMENTAL_SETTINGS = false;
|
|
|
|
|
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";
|
2011-05-11 11:51:07 +00:00
|
|
|
public static final String PREF_KEY_PREVIEW_POPUP_ON = "popup_on";
|
2010-12-09 12:06:26 +00:00
|
|
|
public static final String PREF_AUTO_CAP = "auto_cap";
|
2011-07-30 01:19:51 +00:00
|
|
|
public static final String PREF_SHOW_SETTINGS_KEY = "show_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
|
|
|
|
2011-06-24 11:17:38 +00:00
|
|
|
public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key";
|
2011-04-22 04:08:35 +00:00
|
|
|
public static final String PREF_CORRECTION_SETTINGS_KEY = "correction_settings";
|
2010-12-09 12:06:26 +00:00
|
|
|
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";
|
2011-04-01 10:31:30 +00:00
|
|
|
public static final String PREF_DEBUG_SETTINGS = "debug_settings";
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-04-22 04:08:35 +00:00
|
|
|
public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
|
|
|
|
public static final String PREF_BIGRAM_PREDICTIONS = "bigram_prediction";
|
|
|
|
|
|
|
|
public static final String PREF_MISC_SETTINGS_KEY = "misc_settings";
|
|
|
|
|
2011-05-11 11:51:07 +00:00
|
|
|
public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY =
|
|
|
|
"pref_key_preview_popup_dismiss_delay";
|
2011-06-10 09:16:21 +00:00
|
|
|
public static final String PREF_KEY_USE_CONTACTS_DICT =
|
|
|
|
"pref_key_use_contacts_dict";
|
2011-09-02 05:09:10 +00:00
|
|
|
public static final String PREF_KEY_ENABLE_SPAN_INSERT =
|
|
|
|
"enable_span_insert";
|
2011-05-11 11:51:07 +00:00
|
|
|
|
2011-01-19 08:44:39 +00:00
|
|
|
public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
|
|
|
|
|
2011-10-11 07:39:11 +00:00
|
|
|
public static final String PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS =
|
2011-09-28 11:11:05 +00:00
|
|
|
"pref_vibration_duration_settings";
|
|
|
|
|
2011-10-11 07:39:11 +00:00
|
|
|
public static final String PREF_KEYPRESS_SOUND_VOLUME =
|
|
|
|
"pref_keypress_sound_volume";
|
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-05-10 06:51:43 +00:00
|
|
|
public static class Values {
|
|
|
|
// From resources:
|
|
|
|
public final int mDelayUpdateOldSuggestions;
|
|
|
|
public final String mWordSeparators;
|
|
|
|
public final String mMagicSpaceStrippers;
|
|
|
|
public final String mMagicSpaceSwappers;
|
|
|
|
public final String mSuggestPuncs;
|
|
|
|
public final SuggestedWords mSuggestPuncList;
|
2011-08-03 15:23:17 +00:00
|
|
|
private final String mSymbolsExcludedFromWordSeparators;
|
2011-10-27 15:33:15 +00:00
|
|
|
public final CharSequence mHintToSaveText;
|
2011-05-10 06:51:43 +00:00
|
|
|
|
|
|
|
// From preferences:
|
|
|
|
public final boolean mSoundOn; // Sound setting private to Latin IME (see mSilentModeOn)
|
|
|
|
public final boolean mVibrateOn;
|
2011-05-11 11:51:07 +00:00
|
|
|
public final boolean mKeyPreviewPopupOn;
|
|
|
|
public final int mKeyPreviewPopupDismissDelay;
|
2011-05-10 06:51:43 +00:00
|
|
|
public final boolean mAutoCap;
|
|
|
|
public final boolean mAutoCorrectEnabled;
|
|
|
|
public final double mAutoCorrectionThreshold;
|
|
|
|
// Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary
|
|
|
|
public final boolean mBigramSuggestionEnabled;
|
|
|
|
// Prediction: use bigrams to predict the next word when there is no input for it yet
|
|
|
|
public final boolean mBigramPredictionEnabled;
|
2011-06-10 09:16:21 +00:00
|
|
|
public final boolean mUseContactsDict;
|
2011-09-02 05:09:10 +00:00
|
|
|
public final boolean mEnableSuggestionSpanInsertion;
|
2011-05-10 06:51:43 +00:00
|
|
|
|
2011-07-30 01:19:51 +00:00
|
|
|
private final boolean mShowSettingsKey;
|
2011-07-27 00:22:58 +00:00
|
|
|
private final boolean mVoiceKeyEnabled;
|
|
|
|
private final boolean mVoiceKeyOnMain;
|
2011-07-21 05:57:28 +00:00
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
public Values(final SharedPreferences prefs, final Context context,
|
|
|
|
final String localeStr) {
|
|
|
|
final Resources res = context.getResources();
|
|
|
|
final Locale savedLocale;
|
|
|
|
if (null != localeStr) {
|
2011-08-26 11:22:47 +00:00
|
|
|
final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr);
|
|
|
|
savedLocale = LocaleUtils.setSystemLocale(res, keyboardLocale);
|
2011-05-10 06:51:43 +00:00
|
|
|
} else {
|
|
|
|
savedLocale = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the resources
|
|
|
|
mDelayUpdateOldSuggestions = res.getInteger(
|
|
|
|
R.integer.config_delay_update_old_suggestions);
|
|
|
|
mMagicSpaceStrippers = res.getString(R.string.magic_space_stripping_symbols);
|
|
|
|
mMagicSpaceSwappers = res.getString(R.string.magic_space_swapping_symbols);
|
|
|
|
String wordSeparators = mMagicSpaceStrippers + mMagicSpaceSwappers
|
|
|
|
+ res.getString(R.string.magic_space_promoting_symbols);
|
2011-08-03 15:23:17 +00:00
|
|
|
final String symbolsExcludedFromWordSeparators =
|
|
|
|
res.getString(R.string.symbols_excluded_from_word_separators);
|
|
|
|
for (int i = symbolsExcludedFromWordSeparators.length() - 1; i >= 0; --i) {
|
|
|
|
wordSeparators = wordSeparators.replace(
|
|
|
|
symbolsExcludedFromWordSeparators.substring(i, i + 1), "");
|
2011-05-10 06:51:43 +00:00
|
|
|
}
|
2011-08-03 15:23:17 +00:00
|
|
|
mSymbolsExcludedFromWordSeparators = symbolsExcludedFromWordSeparators;
|
2011-05-10 06:51:43 +00:00
|
|
|
mWordSeparators = wordSeparators;
|
|
|
|
mSuggestPuncs = res.getString(R.string.suggested_punctuations);
|
|
|
|
// TODO: it would be nice not to recreate this each time we change the configuration
|
|
|
|
mSuggestPuncList = createSuggestPuncList(mSuggestPuncs);
|
2011-10-27 15:33:15 +00:00
|
|
|
mHintToSaveText = context.getText(R.string.hint_add_to_dictionary);
|
2011-05-10 06:51:43 +00:00
|
|
|
|
|
|
|
// Get the settings preferences
|
|
|
|
final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator();
|
2011-09-20 11:16:11 +00:00
|
|
|
mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON,
|
|
|
|
res.getBoolean(R.bool.config_default_vibration_enabled));
|
2011-05-10 06:51:43 +00:00
|
|
|
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
|
|
|
|
res.getBoolean(R.bool.config_default_sound_enabled));
|
2011-05-11 11:51:07 +00:00
|
|
|
mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res);
|
|
|
|
mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res);
|
2011-05-10 06:51:43 +00:00
|
|
|
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
|
|
|
|
mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res);
|
|
|
|
mBigramSuggestionEnabled = mAutoCorrectEnabled
|
|
|
|
&& isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled);
|
|
|
|
mBigramPredictionEnabled = mBigramSuggestionEnabled
|
|
|
|
&& isBigramPredictionEnabled(prefs, res);
|
|
|
|
mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res);
|
2011-06-10 09:16:21 +00:00
|
|
|
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
|
2011-09-02 05:09:10 +00:00
|
|
|
mEnableSuggestionSpanInsertion =
|
|
|
|
prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true);
|
2011-08-03 08:00:14 +00:00
|
|
|
final boolean defaultShowSettingsKey = res.getBoolean(
|
|
|
|
R.bool.config_default_show_settings_key);
|
2011-08-22 03:19:37 +00:00
|
|
|
mShowSettingsKey = isShowSettingsKeyOption(res)
|
|
|
|
? prefs.getBoolean(Settings.PREF_SHOW_SETTINGS_KEY, defaultShowSettingsKey)
|
|
|
|
: defaultShowSettingsKey;
|
2011-07-25 21:44:47 +00:00
|
|
|
final String voiceModeMain = res.getString(R.string.voice_mode_main);
|
|
|
|
final String voiceModeOff = res.getString(R.string.voice_mode_off);
|
|
|
|
final String voiceMode = prefs.getString(PREF_VOICE_SETTINGS_KEY, voiceModeMain);
|
2011-07-27 00:22:58 +00:00
|
|
|
mVoiceKeyEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff);
|
|
|
|
mVoiceKeyOnMain = voiceMode != null && voiceMode.equals(voiceModeMain);
|
2011-07-21 05:57:28 +00:00
|
|
|
|
2011-08-26 11:22:47 +00:00
|
|
|
LocaleUtils.setSystemLocale(res, savedLocale);
|
2011-05-10 06:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSuggestedPunctuation(int code) {
|
|
|
|
return mSuggestPuncs.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isWordSeparator(int code) {
|
|
|
|
return mWordSeparators.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
2011-08-03 15:23:17 +00:00
|
|
|
public boolean isSymbolExcludedFromWordSeparators(int code) {
|
|
|
|
return mSymbolsExcludedFromWordSeparators.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
public boolean isMagicSpaceStripper(int code) {
|
|
|
|
return mMagicSpaceStrippers.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isMagicSpaceSwapper(int code) {
|
|
|
|
return mMagicSpaceSwappers.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isAutoCorrectEnabled(SharedPreferences sp, Resources resources) {
|
|
|
|
final String currentAutoCorrectionSetting = sp.getString(
|
|
|
|
Settings.PREF_AUTO_CORRECTION_THRESHOLD,
|
|
|
|
resources.getString(R.string.auto_correction_threshold_mode_index_modest));
|
|
|
|
final String autoCorrectionOff = resources.getString(
|
|
|
|
R.string.auto_correction_threshold_mode_index_off);
|
|
|
|
return !currentAutoCorrectionSetting.equals(autoCorrectionOff);
|
|
|
|
}
|
2011-05-11 11:51:07 +00:00
|
|
|
|
|
|
|
// Public to access from KeyboardSwitcher. Should it have access to some
|
|
|
|
// process-global instance instead?
|
|
|
|
public static boolean isKeyPreviewPopupEnabled(SharedPreferences sp, Resources resources) {
|
2011-05-10 06:51:43 +00:00
|
|
|
final boolean showPopupOption = resources.getBoolean(
|
|
|
|
R.bool.config_enable_show_popup_on_keypress_option);
|
|
|
|
if (!showPopupOption) return resources.getBoolean(R.bool.config_default_popup_preview);
|
2011-05-11 11:51:07 +00:00
|
|
|
return sp.getBoolean(Settings.PREF_KEY_PREVIEW_POPUP_ON,
|
2011-05-10 06:51:43 +00:00
|
|
|
resources.getBoolean(R.bool.config_default_popup_preview));
|
|
|
|
}
|
2011-05-11 11:51:07 +00:00
|
|
|
|
|
|
|
// Likewise
|
|
|
|
public static int getKeyPreviewPopupDismissDelay(SharedPreferences sp,
|
|
|
|
Resources resources) {
|
|
|
|
return Integer.parseInt(sp.getString(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,
|
|
|
|
Integer.toString(resources.getInteger(R.integer.config_delay_after_preview))));
|
|
|
|
}
|
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
private static boolean isBigramSuggestionEnabled(SharedPreferences sp, Resources resources,
|
|
|
|
boolean autoCorrectEnabled) {
|
|
|
|
final boolean showBigramSuggestionsOption = resources.getBoolean(
|
|
|
|
R.bool.config_enable_bigram_suggestions_option);
|
|
|
|
if (!showBigramSuggestionsOption) {
|
|
|
|
return autoCorrectEnabled;
|
|
|
|
}
|
|
|
|
return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTIONS, resources.getBoolean(
|
|
|
|
R.bool.config_default_bigram_suggestions));
|
|
|
|
}
|
2011-05-11 11:51:07 +00:00
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
private static boolean isBigramPredictionEnabled(SharedPreferences sp,
|
|
|
|
Resources resources) {
|
|
|
|
return sp.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, resources.getBoolean(
|
|
|
|
R.bool.config_default_bigram_prediction));
|
|
|
|
}
|
2011-05-11 11:51:07 +00:00
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
private static double getAutoCorrectionThreshold(SharedPreferences sp,
|
|
|
|
Resources resources) {
|
|
|
|
final String currentAutoCorrectionSetting = sp.getString(
|
|
|
|
Settings.PREF_AUTO_CORRECTION_THRESHOLD,
|
|
|
|
resources.getString(R.string.auto_correction_threshold_mode_index_modest));
|
|
|
|
final String[] autoCorrectionThresholdValues = resources.getStringArray(
|
|
|
|
R.array.auto_correction_threshold_values);
|
|
|
|
// When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off.
|
|
|
|
double autoCorrectionThreshold = Double.MAX_VALUE;
|
|
|
|
try {
|
|
|
|
final int arrayIndex = Integer.valueOf(currentAutoCorrectionSetting);
|
|
|
|
if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) {
|
|
|
|
autoCorrectionThreshold = Double.parseDouble(
|
|
|
|
autoCorrectionThresholdValues[arrayIndex]);
|
|
|
|
}
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
// Whenever the threshold settings are correct, never come here.
|
|
|
|
autoCorrectionThreshold = Double.MAX_VALUE;
|
|
|
|
Log.w(TAG, "Cannot load auto correction threshold setting."
|
|
|
|
+ " currentAutoCorrectionSetting: " + currentAutoCorrectionSetting
|
|
|
|
+ ", autoCorrectionThresholdValues: "
|
|
|
|
+ Arrays.toString(autoCorrectionThresholdValues));
|
|
|
|
}
|
|
|
|
return autoCorrectionThreshold;
|
|
|
|
}
|
2011-05-11 11:51:07 +00:00
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
private static SuggestedWords createSuggestPuncList(final String puncs) {
|
|
|
|
SuggestedWords.Builder builder = new SuggestedWords.Builder();
|
|
|
|
if (puncs != null) {
|
|
|
|
for (int i = 0; i < puncs.length(); i++) {
|
|
|
|
builder.addWord(puncs.subSequence(i, i + 1));
|
|
|
|
}
|
|
|
|
}
|
2011-06-30 01:09:21 +00:00
|
|
|
return builder.setIsPunctuationSuggestions().build();
|
2011-05-10 06:51:43 +00:00
|
|
|
}
|
2011-07-21 05:57:28 +00:00
|
|
|
|
2011-08-22 03:19:37 +00:00
|
|
|
public static boolean isShowSettingsKeyOption(final Resources resources) {
|
|
|
|
return resources.getBoolean(R.bool.config_enable_show_settings_key_option);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSettingsKeyEnabled() {
|
2011-07-30 01:19:51 +00:00
|
|
|
return mShowSettingsKey;
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
public boolean isVoiceKeyEnabled(EditorInfo editorInfo) {
|
2011-07-21 05:57:28 +00:00
|
|
|
final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
|
2011-11-21 22:58:32 +00:00
|
|
|
final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
|
2011-07-27 00:22:58 +00:00
|
|
|
return shortcutImeEnabled && mVoiceKeyEnabled
|
2011-07-21 05:57:28 +00:00
|
|
|
&& !InputTypeCompatUtils.isPasswordInputType(inputType);
|
|
|
|
}
|
|
|
|
|
2011-07-27 00:22:58 +00:00
|
|
|
public boolean isVoiceKeyOnMain() {
|
|
|
|
return mVoiceKeyOnMain;
|
2011-07-21 05:57:28 +00:00
|
|
|
}
|
2011-05-10 06:51:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 05:02:46 +00:00
|
|
|
private PreferenceScreen mInputLanguageSelection;
|
2011-10-11 07:39:11 +00:00
|
|
|
private PreferenceScreen mKeypressVibrationDurationSettingsPref;
|
|
|
|
private PreferenceScreen mKeypressSoundVolumeSettingsPref;
|
2010-02-09 22:17:30 +00:00
|
|
|
private ListPreference mVoicePreference;
|
2011-07-30 01:19:51 +00:00
|
|
|
private CheckBoxPreference mShowSettingsKeyPreference;
|
2011-01-25 08:23:46 +00:00
|
|
|
private ListPreference mShowCorrectionSuggestionsPreference;
|
2011-08-03 08:00:14 +00:00
|
|
|
private ListPreference mAutoCorrectionThresholdPreference;
|
2011-05-11 11:51:07 +00:00
|
|
|
private ListPreference mKeyPreviewPopupDismissDelay;
|
2011-04-22 04:08:35 +00:00
|
|
|
// Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary
|
2010-09-28 03:23:26 +00:00
|
|
|
private CheckBoxPreference mBigramSuggestion;
|
2011-04-22 04:08:35 +00:00
|
|
|
// Prediction: use bigrams to predict the next word when there is no input for it yet
|
|
|
|
private CheckBoxPreference mBigramPrediction;
|
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-10-11 07:39:11 +00:00
|
|
|
private TextView mKeypressVibrationDurationSettingsTextView;
|
|
|
|
private TextView mKeypressSoundVolumeSettingsTextView;
|
2010-11-30 14:35:56 +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);
|
2011-08-03 08:00:14 +00:00
|
|
|
final String currentSetting = mAutoCorrectionThresholdPreference.getValue();
|
2010-12-11 08:06:24 +00:00
|
|
|
mBigramSuggestion.setEnabled(!currentSetting.equals(autoCorrectionOff));
|
2011-08-31 10:02:50 +00:00
|
|
|
if (null != mBigramPrediction) {
|
|
|
|
mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff));
|
|
|
|
}
|
2010-09-28 03:23:26 +00:00
|
|
|
}
|
2011-01-14 05:02:46 +00:00
|
|
|
|
2011-07-01 10:40:31 +00:00
|
|
|
public Activity getActivityInternal() {
|
|
|
|
Object thisObject = (Object) this;
|
|
|
|
if (thisObject instanceof Activity) {
|
|
|
|
return (Activity) thisObject;
|
|
|
|
} else if (thisObject instanceof Fragment) {
|
|
|
|
return ((Fragment) thisObject).getActivity();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
2011-07-01 10:40:31 +00:00
|
|
|
public void onCreate(Bundle icicle) {
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onCreate(icicle);
|
2011-07-08 23:15:06 +00:00
|
|
|
setInputMethodSettingsCategoryTitle(R.string.language_selection_title);
|
|
|
|
setSubtypeEnablerTitle(R.string.select_language);
|
2011-05-11 11:51:07 +00:00
|
|
|
final Resources res = getResources();
|
2011-07-01 10:40:31 +00:00
|
|
|
final Context context = getActivityInternal();
|
2011-05-11 11:51:07 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
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
|
|
|
mVoicePreference = (ListPreference) findPreference(PREF_VOICE_SETTINGS_KEY);
|
2011-07-30 01:19:51 +00:00
|
|
|
mShowSettingsKeyPreference = (CheckBoxPreference) findPreference(PREF_SHOW_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));
|
2010-09-28 03:23:26 +00:00
|
|
|
|
2011-08-03 08:00:14 +00:00
|
|
|
mAutoCorrectionThresholdPreference =
|
|
|
|
(ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD);
|
2010-09-28 03:23:26 +00:00
|
|
|
mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
|
2011-04-22 04:08:35 +00:00
|
|
|
mBigramPrediction = (CheckBoxPreference) findPreference(PREF_BIGRAM_PREDICTIONS);
|
2011-04-01 10:31:30 +00:00
|
|
|
mDebugSettingsPreference = findPreference(PREF_DEBUG_SETTINGS);
|
|
|
|
if (mDebugSettingsPreference != null) {
|
|
|
|
final Intent debugSettingsIntent = new Intent(Intent.ACTION_MAIN);
|
2011-07-01 10:40:31 +00:00
|
|
|
debugSettingsIntent.setClassName(
|
|
|
|
context.getPackageName(), DebugSettings.class.getName());
|
2011-04-01 10:31:30 +00:00
|
|
|
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 =
|
2011-04-22 04:08:35 +00:00
|
|
|
(PreferenceGroup) findPreference(PREF_CORRECTION_SETTINGS_KEY);
|
2011-09-14 05:07:10 +00:00
|
|
|
final PreferenceGroup miscSettings =
|
|
|
|
(PreferenceGroup) findPreference(PREF_MISC_SETTINGS_KEY);
|
2011-01-19 06:07:14 +00:00
|
|
|
|
2011-08-22 03:19:37 +00:00
|
|
|
if (!Values.isShowSettingsKeyOption(res)) {
|
2011-07-30 01:19:51 +00:00
|
|
|
generalSettings.removePreference(mShowSettingsKeyPreference);
|
2010-11-30 14:35:56 +00:00
|
|
|
}
|
|
|
|
|
2011-05-11 11:51:07 +00:00
|
|
|
final boolean showVoiceKeyOption = res.getBoolean(
|
2010-11-30 14:35:56 +00:00
|
|
|
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-07-01 10:40:31 +00:00
|
|
|
if (!VibratorCompatWrapper.getInstance(context).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
|
|
|
|
2011-07-09 00:20:47 +00:00
|
|
|
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
|
|
|
|
generalSettings.removePreference(findPreference(PREF_SUBTYPES));
|
|
|
|
}
|
|
|
|
|
2011-05-11 11:51:07 +00:00
|
|
|
final boolean showPopupOption = res.getBoolean(
|
2011-01-18 06:20:35 +00:00
|
|
|
R.bool.config_enable_show_popup_on_keypress_option);
|
|
|
|
if (!showPopupOption) {
|
2011-05-11 11:51:07 +00:00
|
|
|
generalSettings.removePreference(findPreference(PREF_KEY_PREVIEW_POPUP_ON));
|
2011-01-18 06:20:35 +00:00
|
|
|
}
|
2011-01-18 08:45:22 +00:00
|
|
|
|
2011-05-11 11:51:07 +00:00
|
|
|
final boolean showBigramSuggestionsOption = res.getBoolean(
|
2011-01-19 08:44:39 +00:00
|
|
|
R.bool.config_enable_bigram_suggestions_option);
|
|
|
|
if (!showBigramSuggestionsOption) {
|
2011-09-02 06:35:23 +00:00
|
|
|
textCorrectionGroup.removePreference(mBigramSuggestion);
|
|
|
|
if (null != mBigramPrediction) {
|
|
|
|
textCorrectionGroup.removePreference(mBigramPrediction);
|
|
|
|
}
|
2011-01-19 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2011-05-11 11:51:07 +00:00
|
|
|
mKeyPreviewPopupDismissDelay =
|
|
|
|
(ListPreference)findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
|
|
|
final String[] entries = new String[] {
|
|
|
|
res.getString(R.string.key_preview_popup_dismiss_no_delay),
|
|
|
|
res.getString(R.string.key_preview_popup_dismiss_default_delay),
|
|
|
|
};
|
|
|
|
final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
|
|
|
|
R.integer.config_delay_after_preview));
|
|
|
|
mKeyPreviewPopupDismissDelay.setEntries(entries);
|
|
|
|
mKeyPreviewPopupDismissDelay.setEntryValues(
|
|
|
|
new String[] { "0", popupDismissDelayDefaultValue });
|
|
|
|
if (null == mKeyPreviewPopupDismissDelay.getValue()) {
|
|
|
|
mKeyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
|
|
|
|
}
|
2011-08-22 03:19:37 +00:00
|
|
|
mKeyPreviewPopupDismissDelay.setEnabled(Values.isKeyPreviewPopupEnabled(prefs, res));
|
2011-06-24 11:17:38 +00:00
|
|
|
|
|
|
|
final PreferenceScreen dictionaryLink =
|
|
|
|
(PreferenceScreen) findPreference(PREF_CONFIGURE_DICTIONARIES_KEY);
|
|
|
|
final Intent intent = dictionaryLink.getIntent();
|
|
|
|
|
2011-07-01 10:40:31 +00:00
|
|
|
final int number = context.getPackageManager().queryIntentActivities(intent, 0).size();
|
2011-06-24 11:17:38 +00:00
|
|
|
if (0 >= number) {
|
|
|
|
textCorrectionGroup.removePreference(dictionaryLink);
|
|
|
|
}
|
2011-09-14 05:07:10 +00:00
|
|
|
|
|
|
|
final boolean showUsabilityModeStudyOption = res.getBoolean(
|
|
|
|
R.bool.config_enable_usability_study_mode_option);
|
|
|
|
if (!showUsabilityModeStudyOption || !ENABLE_EXPERIMENTAL_SETTINGS) {
|
|
|
|
final Preference pref = findPreference(PREF_USABILITY_STUDY_MODE);
|
|
|
|
if (pref != null) {
|
|
|
|
miscSettings.removePreference(pref);
|
|
|
|
}
|
|
|
|
}
|
2011-09-28 11:11:05 +00:00
|
|
|
|
2011-10-11 07:39:11 +00:00
|
|
|
mKeypressVibrationDurationSettingsPref =
|
|
|
|
(PreferenceScreen) findPreference(PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS);
|
|
|
|
if (mKeypressVibrationDurationSettingsPref != null) {
|
|
|
|
mKeypressVibrationDurationSettingsPref.setOnPreferenceClickListener(
|
2011-09-28 11:11:05 +00:00
|
|
|
new OnPreferenceClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference arg0) {
|
2011-10-11 07:39:11 +00:00
|
|
|
showKeypressVibrationDurationSettingsDialog();
|
2011-09-28 11:11:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2011-10-11 07:39:11 +00:00
|
|
|
updateKeypressVibrationDurationSettingsSummary(prefs, res);
|
2011-09-28 11:11:05 +00:00
|
|
|
}
|
2011-10-11 07:39:11 +00:00
|
|
|
|
|
|
|
mKeypressSoundVolumeSettingsPref =
|
|
|
|
(PreferenceScreen) findPreference(PREF_KEYPRESS_SOUND_VOLUME);
|
|
|
|
if (mKeypressSoundVolumeSettingsPref != null) {
|
|
|
|
mKeypressSoundVolumeSettingsPref.setOnPreferenceClickListener(
|
|
|
|
new OnPreferenceClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference arg0) {
|
|
|
|
showKeypressSoundVolumeSettingDialog();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
updateKeypressSoundVolumeSummary(prefs, res);
|
|
|
|
}
|
|
|
|
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, res);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 05:57:28 +00:00
|
|
|
@SuppressWarnings("unused")
|
2009-03-26 00:39:38 +00:00
|
|
|
@Override
|
2011-07-01 10:40:31 +00:00
|
|
|
public void onResume() {
|
2009-03-26 00:39:38 +00:00
|
|
|
super.onResume();
|
2011-07-21 05:57:28 +00:00
|
|
|
final boolean isShortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
|
|
|
|
if (isShortcutImeEnabled
|
|
|
|
|| (VoiceProxy.VOICE_INSTALLED
|
|
|
|
&& VoiceProxy.isRecognitionAvailable(getActivityInternal()))) {
|
2010-02-09 22:17:30 +00:00
|
|
|
updateVoiceModeSummary();
|
2011-07-21 05:57:28 +00:00
|
|
|
} else {
|
|
|
|
getPreferenceScreen().removePreference(mVoicePreference);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2011-01-25 08:23:46 +00:00
|
|
|
updateShowCorrectionSuggestionsSummary();
|
2011-05-11 11:51:07 +00:00
|
|
|
updateKeyPreviewPopupDelaySummary();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-07-05 20:17:13 +00:00
|
|
|
|
|
|
|
@Override
|
2011-07-01 10:40:31 +00:00
|
|
|
public void onDestroy() {
|
2009-07-05 20:17:13 +00:00
|
|
|
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) {
|
2011-07-01 10:40:31 +00:00
|
|
|
(new BackupManager(getActivityInternal())).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
|
|
|
}
|
2011-05-11 11:51:07 +00:00
|
|
|
} else if (key.equals(PREF_KEY_PREVIEW_POPUP_ON)) {
|
|
|
|
final ListPreference popupDismissDelay =
|
|
|
|
(ListPreference)findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
|
|
|
if (null != popupDismissDelay) {
|
|
|
|
popupDismissDelay.setEnabled(prefs.getBoolean(PREF_KEY_PREVIEW_POPUP_ON, true));
|
|
|
|
}
|
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();
|
2011-01-25 08:23:46 +00:00
|
|
|
updateShowCorrectionSuggestionsSummary();
|
2011-05-11 11:51:07 +00:00
|
|
|
updateKeyPreviewPopupDelaySummary();
|
2011-10-11 07:39:11 +00:00
|
|
|
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
|
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-07-01 10:40:31 +00:00
|
|
|
Utils.getInputMethodId(
|
2011-07-18 04:18:47 +00:00
|
|
|
InputMethodManagerCompatWrapper.getInstance(),
|
2011-07-01 10:40:31 +00:00
|
|
|
getActivityInternal().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())]);
|
|
|
|
}
|
|
|
|
|
2011-05-11 11:51:07 +00:00
|
|
|
private void updateKeyPreviewPopupDelaySummary() {
|
|
|
|
final ListPreference lp = mKeyPreviewPopupDismissDelay;
|
|
|
|
lp.setSummary(lp.getEntries()[lp.findIndexOfValue(lp.getValue())]);
|
|
|
|
}
|
|
|
|
|
2010-02-09 22:17:30 +00:00
|
|
|
private void showVoiceConfirmation() {
|
|
|
|
mOkClicked = false;
|
2011-07-01 10:40:31 +00:00
|
|
|
getActivityInternal().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
|
|
|
|
2011-07-21 05:57:28 +00:00
|
|
|
@Override
|
2010-01-16 20:21:23 +00:00
|
|
|
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);
|
2010-01-16 20:21:23 +00:00
|
|
|
} else if (whichButton == DialogInterface.BUTTON_POSITIVE) {
|
|
|
|
mOkClicked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2011-07-01 10:40:31 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivityInternal())
|
2010-01-16 20:21:23 +00:00
|
|
|
.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.
|
2011-09-07 03:36:07 +00:00
|
|
|
boolean localeSupported = SubtypeSwitcher.isVoiceSupported(
|
|
|
|
this, Locale.getDefault().toString());
|
2010-01-16 20:21:23 +00:00
|
|
|
|
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);
|
|
|
|
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) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2011-09-28 11:11:05 +00:00
|
|
|
|
2011-10-11 07:39:11 +00:00
|
|
|
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
|
|
|
|
SharedPreferences sp, Resources res) {
|
|
|
|
if (mKeypressVibrationDurationSettingsPref != null) {
|
|
|
|
final boolean hasVibrator = VibratorCompatWrapper.getInstance(this).hasVibrator();
|
|
|
|
final boolean vibrateOn = hasVibrator && sp.getBoolean(Settings.PREF_VIBRATE_ON,
|
|
|
|
res.getBoolean(R.bool.config_default_vibration_enabled));
|
|
|
|
mKeypressVibrationDurationSettingsPref.setEnabled(vibrateOn);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mKeypressSoundVolumeSettingsPref != null) {
|
|
|
|
final boolean soundOn = sp.getBoolean(Settings.PREF_SOUND_ON,
|
|
|
|
res.getBoolean(R.bool.config_default_sound_enabled));
|
|
|
|
mKeypressSoundVolumeSettingsPref.setEnabled(soundOn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateKeypressVibrationDurationSettingsSummary(
|
|
|
|
SharedPreferences sp, Resources res) {
|
|
|
|
if (mKeypressVibrationDurationSettingsPref != null) {
|
|
|
|
mKeypressVibrationDurationSettingsPref.setSummary(
|
2011-09-30 10:59:04 +00:00
|
|
|
Utils.getCurrentVibrationDuration(sp, res)
|
|
|
|
+ res.getString(R.string.settings_ms));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-11 07:39:11 +00:00
|
|
|
private void showKeypressVibrationDurationSettingsDialog() {
|
2011-09-28 11:11:05 +00:00
|
|
|
final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
|
|
|
|
final Activity context = getActivityInternal();
|
2011-09-30 10:59:04 +00:00
|
|
|
final Resources res = context.getResources();
|
2011-09-28 11:11:05 +00:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
2011-10-11 07:39:11 +00:00
|
|
|
builder.setTitle(R.string.prefs_keypress_vibration_duration_settings);
|
2011-09-28 11:11:05 +00:00
|
|
|
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
2011-10-11 07:39:11 +00:00
|
|
|
final int ms = Integer.valueOf(
|
|
|
|
mKeypressVibrationDurationSettingsTextView.getText().toString());
|
|
|
|
sp.edit().putInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, ms).apply();
|
|
|
|
updateKeypressVibrationDurationSettingsSummary(sp, res);
|
2011-09-28 11:11:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
final View v = context.getLayoutInflater().inflate(
|
|
|
|
R.layout.vibration_settings_dialog, null);
|
|
|
|
final int currentMs = Utils.getCurrentVibrationDuration(
|
|
|
|
getPreferenceManager().getSharedPreferences(), getResources());
|
2011-10-11 07:39:11 +00:00
|
|
|
mKeypressVibrationDurationSettingsTextView = (TextView)v.findViewById(R.id.vibration_value);
|
2011-09-28 11:11:05 +00:00
|
|
|
final SeekBar sb = (SeekBar)v.findViewById(R.id.vibration_settings);
|
|
|
|
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
|
|
|
|
final int tempMs = arg1;
|
2011-10-11 07:39:11 +00:00
|
|
|
mKeypressVibrationDurationSettingsTextView.setText(String.valueOf(tempMs));
|
2011-09-28 11:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStartTrackingTouch(SeekBar arg0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStopTrackingTouch(SeekBar arg0) {
|
|
|
|
final int tempMs = arg0.getProgress();
|
|
|
|
VibratorCompatWrapper.getInstance(context).vibrate(tempMs);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sb.setProgress(currentMs);
|
2011-10-11 07:39:11 +00:00
|
|
|
mKeypressVibrationDurationSettingsTextView.setText(String.valueOf(currentMs));
|
|
|
|
builder.setView(v);
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateKeypressSoundVolumeSummary(SharedPreferences sp, Resources res) {
|
|
|
|
if (mKeypressSoundVolumeSettingsPref != null) {
|
|
|
|
mKeypressSoundVolumeSettingsPref.setSummary(
|
|
|
|
String.valueOf((int)(Utils.getCurrentKeypressSoundVolume(sp, res) * 100)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showKeypressSoundVolumeSettingDialog() {
|
|
|
|
final AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
|
|
final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
|
|
|
|
final Activity context = getActivityInternal();
|
|
|
|
final Resources res = context.getResources();
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
builder.setTitle(R.string.prefs_keypress_sound_volume_settings);
|
|
|
|
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
|
final float volume =
|
|
|
|
((float)Integer.valueOf(
|
|
|
|
mKeypressSoundVolumeSettingsTextView.getText().toString())) / 100;
|
|
|
|
sp.edit().putFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, volume).apply();
|
|
|
|
updateKeypressSoundVolumeSummary(sp, res);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
final View v = context.getLayoutInflater().inflate(
|
|
|
|
R.layout.sound_effect_volume_dialog, null);
|
|
|
|
final int currentVolumeInt = (int)(Utils.getCurrentKeypressSoundVolume(
|
|
|
|
getPreferenceManager().getSharedPreferences(), getResources()) * 100);
|
|
|
|
mKeypressSoundVolumeSettingsTextView =
|
|
|
|
(TextView)v.findViewById(R.id.sound_effect_volume_value);
|
|
|
|
final SeekBar sb = (SeekBar)v.findViewById(R.id.sound_effect_volume_bar);
|
|
|
|
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
|
|
|
|
final int tempVolume = arg1;
|
|
|
|
mKeypressSoundVolumeSettingsTextView.setText(String.valueOf(tempVolume));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStartTrackingTouch(SeekBar arg0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStopTrackingTouch(SeekBar arg0) {
|
|
|
|
final float tempVolume = ((float)arg0.getProgress()) / 100;
|
|
|
|
am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, tempVolume);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sb.setProgress(currentVolumeInt);
|
|
|
|
mKeypressSoundVolumeSettingsTextView.setText(String.valueOf(currentVolumeInt));
|
2011-09-28 11:11:05 +00:00
|
|
|
builder.setView(v);
|
|
|
|
builder.create().show();
|
|
|
|
}
|
2011-10-27 15:33:15 +00:00
|
|
|
}
|