Merge "Consolidate voice input key options no.1"

main
Satoshi Kataoka 2013-09-05 07:33:59 +00:00 committed by Android (Google) Code Review
commit 80fe84b3a4
6 changed files with 35 additions and 37 deletions

View File

@ -42,13 +42,11 @@
android:title="@string/popup_on_keypress" android:title="@string/popup_on_keypress"
android:persistent="true" android:persistent="true"
android:defaultValue="@bool/config_default_key_preview_popup" /> android:defaultValue="@bool/config_default_key_preview_popup" />
<ListPreference <CheckBoxPreference
android:key="voice_mode" android:key="pref_voice_input_key"
android:title="@string/voice_input" android:title="@string/voice_input"
android:persistent="true" android:persistent="true"
android:entryValues="@array/voice_input_modes_values" android:defaultValue="true" />
android:entries="@array/voice_input_modes"
android:defaultValue="@string/voice_mode_main" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/correction_category" android:title="@string/correction_category"

View File

@ -106,6 +106,8 @@ public final class KeyboardLayoutSet {
EditorInfo mEditorInfo; EditorInfo mEditorInfo;
boolean mDisableTouchPositionCorrectionDataForTest; boolean mDisableTouchPositionCorrectionDataForTest;
boolean mVoiceKeyEnabled; boolean mVoiceKeyEnabled;
// TODO: Remove mVoiceKeyOnMain when it's certainly confirmed that we no longer show
// the voice input key on the symbol layout
boolean mVoiceKeyOnMain; boolean mVoiceKeyOnMain;
boolean mNoSettingsKey; boolean mNoSettingsKey;
boolean mLanguageSwitchKeyEnabled; boolean mLanguageSwitchKeyEnabled;
@ -259,6 +261,8 @@ public final class KeyboardLayoutSet {
return this; return this;
} }
// TODO: Remove mVoiceKeyOnMain when it's certainly confirmed that we no longer show
// the voice input key on the symbol layout
public Builder setOptions(final boolean voiceKeyEnabled, final boolean voiceKeyOnMain, public Builder setOptions(final boolean voiceKeyEnabled, final boolean voiceKeyOnMain,
final boolean languageSwitchKeyEnabled) { final boolean languageSwitchKeyEnabled) {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View File

@ -142,7 +142,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype()); builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
builder.setOptions( builder.setOptions(
settingsValues.isVoiceKeyEnabled(editorInfo), settingsValues.isVoiceKeyEnabled(editorInfo),
settingsValues.isVoiceKeyOnMain(), true /* always show a voice key on the main keyboard */,
settingsValues.isLanguageSwitchKeyEnabled()); settingsValues.isLanguageSwitchKeyEnabled());
mKeyboardLayoutSet = builder.build(); mKeyboardLayoutSet = builder.build();
try { try {

View File

@ -44,7 +44,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_VIBRATE_ON = "vibrate_on"; public static final String PREF_VIBRATE_ON = "vibrate_on";
public static final String PREF_SOUND_ON = "sound_on"; public static final String PREF_SOUND_ON = "sound_on";
public static final String PREF_POPUP_ON = "popup_on"; public static final String PREF_POPUP_ON = "popup_on";
public static final String PREF_VOICE_MODE = "voice_mode"; // PREF_VOICE_MODE_OBSOLETE is obsolete. Use PREF_VOICE_INPUT_KEY instead.
public static final String PREF_VOICE_MODE_OBSOLETE = "voice_mode";
public static final String PREF_VOICE_INPUT_KEY = "pref_voice_input_key";
public static final String PREF_CORRECTION_SETTINGS = "correction_settings"; public static final String PREF_CORRECTION_SETTINGS = "correction_settings";
public static final String PREF_EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary"; public static final String PREF_EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary";
public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key"; public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key";

View File

@ -61,7 +61,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS
|| Build.VERSION.SDK_INT <= 18 /* Build.VERSION.JELLY_BEAN_MR2 */; || Build.VERSION.SDK_INT <= 18 /* Build.VERSION.JELLY_BEAN_MR2 */;
private ListPreference mVoicePreference; private CheckBoxPreference mVoiceInputKeyPreference;
private ListPreference mShowCorrectionSuggestionsPreference; private ListPreference mShowCorrectionSuggestionsPreference;
private ListPreference mAutoCorrectionThresholdPreference; private ListPreference mAutoCorrectionThresholdPreference;
private ListPreference mKeyPreviewPopupDismissDelay; private ListPreference mKeyPreviewPopupDismissDelay;
@ -107,7 +107,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
SubtypeLocaleUtils.init(context); SubtypeLocaleUtils.init(context);
AudioAndHapticFeedbackManager.init(context); AudioAndHapticFeedbackManager.init(context);
mVoicePreference = (ListPreference) findPreference(Settings.PREF_VOICE_MODE); mVoiceInputKeyPreference =
(CheckBoxPreference) findPreference(Settings.PREF_VOICE_INPUT_KEY);
mShowCorrectionSuggestionsPreference = mShowCorrectionSuggestionsPreference =
(ListPreference) findPreference(Settings.PREF_SHOW_SUGGESTIONS_SETTING); (ListPreference) findPreference(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
@ -166,7 +167,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final boolean showVoiceKeyOption = res.getBoolean( final boolean showVoiceKeyOption = res.getBoolean(
R.bool.config_enable_show_voice_key_option); R.bool.config_enable_show_voice_key_option);
if (!showVoiceKeyOption) { if (!showVoiceKeyOption) {
generalSettings.removePreference(mVoicePreference); generalSettings.removePreference(mVoiceInputKeyPreference);
} }
final PreferenceGroup advancedSettings = final PreferenceGroup advancedSettings =
@ -243,10 +244,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
final boolean isShortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); final boolean isShortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
if (isShortcutImeEnabled) { if (!isShortcutImeEnabled) {
updateVoiceModeSummary(); getPreferenceScreen().removePreference(mVoiceInputKeyPreference);
} else {
getPreferenceScreen().removePreference(mVoicePreference);
} }
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
final CheckBoxPreference showSetupWizardIcon = final CheckBoxPreference showSetupWizardIcon =
@ -287,7 +286,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity()); LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
} }
ensureConsistencyOfAutoCorrectionSettings(); ensureConsistencyOfAutoCorrectionSettings();
updateVoiceModeSummary();
updateShowCorrectionSuggestionsSummary(); updateShowCorrectionSuggestionsSummary();
updateKeyPreviewPopupDelaySummary(); updateKeyPreviewPopupDelaySummary();
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources()); refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
@ -330,12 +328,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
lp.setSummary(entries[lp.findIndexOfValue(lp.getValue())]); lp.setSummary(entries[lp.findIndexOfValue(lp.getValue())]);
} }
private void updateVoiceModeSummary() {
mVoicePreference.setSummary(
getResources().getStringArray(R.array.voice_input_modes_summary)
[mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]);
}
private void refreshEnablingsOfKeypressSoundAndVibrationSettings( private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
final SharedPreferences sp, final Resources res) { final SharedPreferences sp, final Resources res) {
setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS, setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,

View File

@ -64,7 +64,7 @@ public final class SettingsValues {
public final boolean mVibrateOn; public final boolean mVibrateOn;
public final boolean mSoundOn; public final boolean mSoundOn;
public final boolean mKeyPreviewPopupOn; public final boolean mKeyPreviewPopupOn;
private final String mVoiceMode; private final boolean mShowsVoiceInputKey;
public final boolean mIncludesOtherImesInLanguageSwitchList; public final boolean mIncludesOtherImesInLanguageSwitchList;
public final boolean mShowsLanguageSwitchKey; public final boolean mShowsLanguageSwitchKey;
public final boolean mUseContactsDict; public final boolean mUseContactsDict;
@ -90,8 +90,6 @@ public final class SettingsValues {
public final float mAutoCorrectionThreshold; public final float mAutoCorrectionThreshold;
public final boolean mCorrectionEnabled; public final boolean mCorrectionEnabled;
public final int mSuggestionVisibility; public final int mSuggestionVisibility;
private final boolean mVoiceKeyEnabled;
private final boolean mVoiceKeyOnMain;
public final boolean mBoostPersonalizationDictionaryForDebug; public final boolean mBoostPersonalizationDictionaryForDebug;
public final boolean mUseOnlyPersonalizationDictionaryForDebug; public final boolean mUseOnlyPersonalizationDictionaryForDebug;
@ -137,9 +135,7 @@ public final class SettingsValues {
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res); mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
mSlidingKeyInputPreviewEnabled = prefs.getBoolean( mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
Settings.PREF_SLIDING_KEY_INPUT_PREVIEW, true); Settings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
final String voiceModeMain = res.getString(R.string.voice_mode_main); mShowsVoiceInputKey = needsToShowVoiceInputKey(prefs, res);
final String voiceModeOff = res.getString(R.string.voice_mode_off);
mVoiceMode = prefs.getString(Settings.PREF_VOICE_MODE, voiceModeMain);
final String autoCorrectionThresholdRawValue = prefs.getString( final String autoCorrectionThresholdRawValue = prefs.getString(
Settings.PREF_AUTO_CORRECTION_THRESHOLD, Settings.PREF_AUTO_CORRECTION_THRESHOLD,
res.getString(R.string.auto_correction_threshold_mode_index_modest)); res.getString(R.string.auto_correction_threshold_mode_index_modest));
@ -159,8 +155,6 @@ public final class SettingsValues {
mKeyPreviewPopupDismissDelay = Settings.readKeyPreviewPopupDismissDelay(prefs, res); mKeyPreviewPopupDismissDelay = Settings.readKeyPreviewPopupDismissDelay(prefs, res);
mAutoCorrectionThreshold = readAutoCorrectionThreshold(res, mAutoCorrectionThreshold = readAutoCorrectionThreshold(res,
autoCorrectionThresholdRawValue); autoCorrectionThresholdRawValue);
mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
mGestureInputEnabled = Settings.readGestureInputEnabled(prefs, res); mGestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true); mGestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
mGestureFloatingPreviewTextEnabled = prefs.getBoolean( mGestureFloatingPreviewTextEnabled = prefs.getBoolean(
@ -201,7 +195,7 @@ public final class SettingsValues {
mSoundOn = true; mSoundOn = true;
mKeyPreviewPopupOn = true; mKeyPreviewPopupOn = true;
mSlidingKeyInputPreviewEnabled = true; mSlidingKeyInputPreviewEnabled = true;
mVoiceMode = "0"; mShowsVoiceInputKey = true;
mIncludesOtherImesInLanguageSwitchList = false; mIncludesOtherImesInLanguageSwitchList = false;
mShowsLanguageSwitchKey = true; mShowsLanguageSwitchKey = true;
mUseContactsDict = true; mUseContactsDict = true;
@ -214,8 +208,6 @@ public final class SettingsValues {
mKeypressSoundVolume = 1; mKeypressSoundVolume = 1;
mKeyPreviewPopupDismissDelay = 70; mKeyPreviewPopupDismissDelay = 70;
mAutoCorrectionThreshold = 1; mAutoCorrectionThreshold = 1;
mVoiceKeyEnabled = true;
mVoiceKeyOnMain = true;
mGestureInputEnabled = true; mGestureInputEnabled = true;
mGestureTrailEnabled = true; mGestureTrailEnabled = true;
mGestureFloatingPreviewTextEnabled = true; mGestureFloatingPreviewTextEnabled = true;
@ -274,14 +266,10 @@ public final class SettingsValues {
public boolean isVoiceKeyEnabled(final EditorInfo editorInfo) { public boolean isVoiceKeyEnabled(final EditorInfo editorInfo) {
final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
final int inputType = (editorInfo != null) ? editorInfo.inputType : 0; final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
return shortcutImeEnabled && mVoiceKeyEnabled return shortcutImeEnabled && mShowsVoiceInputKey
&& !InputTypeUtils.isPasswordInputType(inputType); && !InputTypeUtils.isPasswordInputType(inputType);
} }
public boolean isVoiceKeyOnMain() {
return mVoiceKeyOnMain;
}
public boolean isLanguageSwitchKeyEnabled() { public boolean isLanguageSwitchKeyEnabled() {
if (!mShowsLanguageSwitchKey) { if (!mShowsLanguageSwitchKey) {
return false; return false;
@ -372,4 +360,18 @@ public final class SettingsValues {
} }
return autoCorrectionThreshold; return autoCorrectionThreshold;
} }
private static boolean needsToShowVoiceInputKey(SharedPreferences prefs, Resources res) {
final String voiceModeMain = res.getString(R.string.voice_mode_main);
final String voiceMode = prefs.getString(Settings.PREF_VOICE_MODE_OBSOLETE, voiceModeMain);
final boolean showsVoiceInputKey = voiceMode == null || voiceMode.equals(voiceModeMain);
if (!showsVoiceInputKey) {
// Migrate settings from PREF_VOICE_MODE_OBSOLETE to PREF_VOICE_INPUT_KEY
// Set voiceModeMain as a value of obsolete voice mode settings.
prefs.edit().putString(Settings.PREF_VOICE_MODE_OBSOLETE, voiceModeMain).apply();
// Disable voice input key.
prefs.edit().putBoolean(Settings.PREF_VOICE_INPUT_KEY, false).apply();
}
return prefs.getBoolean(Settings.PREF_VOICE_INPUT_KEY, true);
}
} }