Change the voice checkboxes into a 3-state list.
Also add a language-switch hint
This commit is contained in:
parent
1b62ff1a3d
commit
457fdffce4
4 changed files with 76 additions and 60 deletions
|
@ -250,13 +250,34 @@
|
|||
<string name="ok">OK</string>
|
||||
|
||||
<!-- Preferences item for enabling speech input -->
|
||||
<string name="enable_voice">Voice input</string>
|
||||
<string name="voice_input">Voice input</string>
|
||||
|
||||
<!-- Preferences item for speech icon on primary keyboard -->
|
||||
<string name="voice_on_primary">Mic on primary</string>
|
||||
<!-- Array of Voice Input modes -->
|
||||
<string-array name="voice_input_modes">
|
||||
<item>On main keyboard</item>
|
||||
<item>On symbols keyboard</item>
|
||||
<item>Off</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Preferences item summary for speech icon on primary keyboard -->
|
||||
<string name="voice_on_primary_summary">Show the microphone on the primary keyboard</string>
|
||||
<!-- Don't translate -->
|
||||
<string name="voice_mode_main" translatable="false">0</string>
|
||||
<!-- Don't translate -->
|
||||
<string name="voice_mode_symbols" translatable="false">1</string>
|
||||
<!-- Don't translate -->
|
||||
<string name="voice_mode_off" translatable="false">2</string>
|
||||
|
||||
<string-array name="voice_input_modes_values" translatable="false">
|
||||
<item>@string/voice_mode_main</item>
|
||||
<item>@string/voice_mode_symbols</item>
|
||||
<item>@string/voice_mode_off</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Array of Voice Input modes summary -->
|
||||
<string-array name="voice_input_modes_summary">
|
||||
<item>Mic on main keyboard</item>
|
||||
<item>Mic on symbols keyboard</item>
|
||||
<item>Voice input is disabled</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Press the "enter" key after the user speaks. Option on settings.-->
|
||||
<string name="auto_submit">Auto submit after voice</string>
|
||||
|
@ -293,4 +314,6 @@
|
|||
|
||||
<!-- Title for input language selection screen -->
|
||||
<string name="language_selection_title">Select input languages</string>
|
||||
<!-- Title summary for input language selection screen -->
|
||||
<string name="language_selection_summary">Slide your finger across the spacebar to switch</string>
|
||||
</resources>
|
||||
|
|
|
@ -37,24 +37,18 @@
|
|||
android:defaultValue="true"
|
||||
/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="enable_voice_input"
|
||||
android:title="@string/enable_voice"
|
||||
android:persistent="false"
|
||||
android:defaultValue="@bool/voice_input_default"
|
||||
/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="voice_on_main"
|
||||
android:title="@string/voice_on_primary"
|
||||
android:summary="@string/voice_on_primary_summary"
|
||||
<ListPreference
|
||||
android:key="voice_mode"
|
||||
android:title="@string/voice_input"
|
||||
android:persistent="true"
|
||||
android:dependency="enable_voice_input"
|
||||
android:defaultValue="@bool/voice_input_default"
|
||||
android:entryValues="@array/voice_input_modes_values"
|
||||
android:entries="@array/voice_input_modes"
|
||||
android:defaultValue="@string/voice_mode_main"
|
||||
/>
|
||||
|
||||
<PreferenceScreen
|
||||
android:title="@string/language_selection_title">
|
||||
android:title="@string/language_selection_title"
|
||||
android:summary="@string/language_selection_summary">
|
||||
<intent
|
||||
android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.android.inputmethod.latin"
|
||||
|
|
|
@ -90,9 +90,8 @@ public class LatinIME extends InputMethodService
|
|||
private static final String PREF_QUICK_FIXES = "quick_fixes";
|
||||
private static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
|
||||
private static final String PREF_AUTO_COMPLETE = "auto_complete";
|
||||
private static final String PREF_ENABLE_VOICE = "enable_voice_input";
|
||||
private static final String PREF_VOICE_MODE = "voice_mode";
|
||||
private static final String PREF_VOICE_SERVER_URL = "voice_server_url";
|
||||
private static final String PREF_VOICE_MAIN = "voice_on_main";
|
||||
|
||||
// Whether or not the user has used voice input before (and thus, whether to show the
|
||||
// first-run warning dialog or not).
|
||||
|
@ -1771,8 +1770,9 @@ public class LatinIME extends InputMethodService
|
|||
mShowSuggestions = sp.getBoolean(PREF_SHOW_SUGGESTIONS, true) & mQuickFixes;
|
||||
|
||||
if (VOICE_INSTALLED) {
|
||||
boolean enableVoice = sp.getBoolean(PREF_ENABLE_VOICE, true);
|
||||
boolean voiceOnPrimary = sp.getBoolean(PREF_VOICE_MAIN, true);
|
||||
final String voiceMode = sp.getString(PREF_VOICE_MODE, "");
|
||||
boolean enableVoice = !voiceMode.equals(getString(R.string.voice_mode_off));
|
||||
boolean voiceOnPrimary = voiceMode.equals(getString(R.string.voice_mode_main));
|
||||
if (mKeyboardSwitcher != null &&
|
||||
(enableVoice != mEnableVoice || voiceOnPrimary != mVoiceOnPrimary)) {
|
||||
mKeyboardSwitcher.setVoiceMode(enableVoice, voiceOnPrimary);
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.backup.BackupManager;
|
||||
|
@ -23,6 +26,7 @@ import android.content.DialogInterface;
|
|||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceGroup;
|
||||
|
@ -31,23 +35,18 @@ import android.speech.RecognitionManager;
|
|||
import android.text.AutoText;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
import com.android.inputmethod.voice.SettingsUtil;
|
||||
import com.android.inputmethod.voice.VoiceInputLogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
public class LatinIMESettings extends PreferenceActivity
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
||||
OnPreferenceClickListener,
|
||||
DialogInterface.OnDismissListener {
|
||||
|
||||
private static final String QUICK_FIXES_KEY = "quick_fixes";
|
||||
private static final String SHOW_SUGGESTIONS_KEY = "show_suggestions";
|
||||
private static final String PREDICTION_SETTINGS_KEY = "prediction_settings";
|
||||
private static final String VOICE_SETTINGS_KEY = "enable_voice_input";
|
||||
private static final String VOICE_SETTINGS_KEY = "voice_mode";
|
||||
private static final String VOICE_ON_PRIMARY_KEY = "voice_on_main";
|
||||
private static final String VOICE_SERVER_KEY = "voice_server_url";
|
||||
|
||||
|
@ -58,12 +57,13 @@ public class LatinIMESettings extends PreferenceActivity
|
|||
|
||||
private CheckBoxPreference mQuickFixes;
|
||||
private CheckBoxPreference mShowSuggestions;
|
||||
private CheckBoxPreference mVoicePreference;
|
||||
private CheckBoxPreference mVoiceOnPrimary;
|
||||
private ListPreference mVoicePreference;
|
||||
private boolean mVoiceOn;
|
||||
|
||||
private VoiceInputLogger mLogger;
|
||||
|
||||
private boolean mOkClicked = false;
|
||||
private String mVoiceModeOff;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
|
@ -71,15 +71,12 @@ public class LatinIMESettings extends PreferenceActivity
|
|||
addPreferencesFromResource(R.xml.prefs);
|
||||
mQuickFixes = (CheckBoxPreference) findPreference(QUICK_FIXES_KEY);
|
||||
mShowSuggestions = (CheckBoxPreference) findPreference(SHOW_SUGGESTIONS_KEY);
|
||||
mVoicePreference = (CheckBoxPreference) findPreference(VOICE_SETTINGS_KEY);
|
||||
mVoiceOnPrimary = (CheckBoxPreference) findPreference(VOICE_ON_PRIMARY_KEY);
|
||||
mVoicePreference = (ListPreference) findPreference(VOICE_SETTINGS_KEY);
|
||||
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
mVoicePreference.setOnPreferenceClickListener(this);
|
||||
mVoicePreference.setChecked(prefs.getBoolean(
|
||||
VOICE_SETTINGS_KEY, getResources().getBoolean(R.bool.voice_input_default)));
|
||||
|
||||
mVoiceModeOff = getString(R.string.voice_mode_off);
|
||||
mVoiceOn = !(prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff).equals(mVoiceModeOff));
|
||||
mLogger = VoiceInputLogger.getLogger(this);
|
||||
}
|
||||
|
||||
|
@ -95,12 +92,10 @@ public class LatinIMESettings extends PreferenceActivity
|
|||
}
|
||||
if (!LatinIME.VOICE_INSTALLED
|
||||
|| !RecognitionManager.isRecognitionAvailable(this)) {
|
||||
getPreferenceScreen().removePreference(mVoiceOnPrimary);
|
||||
getPreferenceScreen().removePreference(mVoicePreference);
|
||||
} else {
|
||||
updateVoiceModeSummary();
|
||||
}
|
||||
|
||||
mVoicePreference.setChecked(
|
||||
getPreferenceManager().getSharedPreferences().getBoolean(VOICE_SETTINGS_KEY, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,21 +105,28 @@ public class LatinIMESettings extends PreferenceActivity
|
|||
super.onDestroy();
|
||||
}
|
||||
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||
String key) {
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
(new BackupManager(this)).dataChanged();
|
||||
}
|
||||
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference == mVoicePreference) {
|
||||
if (mVoicePreference.isChecked()) {
|
||||
mOkClicked = false;
|
||||
showDialog(VOICE_INPUT_CONFIRM_DIALOG);
|
||||
} else {
|
||||
updateVoicePreference();
|
||||
// If turning on voice input, show dialog
|
||||
if (key.equals(VOICE_SETTINGS_KEY) && !mVoiceOn) {
|
||||
if (! prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff)
|
||||
.equals(mVoiceModeOff)) {
|
||||
showVoiceConfirmation();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
mVoiceOn = !(prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff).equals(mVoiceModeOff));
|
||||
updateVoiceModeSummary();
|
||||
}
|
||||
|
||||
private void showVoiceConfirmation() {
|
||||
mOkClicked = false;
|
||||
showDialog(VOICE_INPUT_CONFIRM_DIALOG);
|
||||
}
|
||||
|
||||
private void updateVoiceModeSummary() {
|
||||
mVoicePreference.setSummary(
|
||||
getResources().getStringArray(R.array.voice_input_modes_summary)
|
||||
[mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,7 +136,7 @@ public class LatinIMESettings extends PreferenceActivity
|
|||
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
if (whichButton == DialogInterface.BUTTON_NEGATIVE) {
|
||||
mVoicePreference.setChecked(false);
|
||||
mVoicePreference.setValue(mVoiceModeOff);
|
||||
mLogger.settingsWarningDialogCancel();
|
||||
} else if (whichButton == DialogInterface.BUTTON_POSITIVE) {
|
||||
mOkClicked = true;
|
||||
|
@ -186,19 +188,16 @@ public class LatinIMESettings extends PreferenceActivity
|
|||
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.
|
||||
mVoicePreference.setChecked(false);
|
||||
mVoicePreference.setValue(mVoiceModeOff);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVoicePreference() {
|
||||
SharedPreferences.Editor editor = getPreferenceManager().getSharedPreferences().edit();
|
||||
boolean isChecked = mVoicePreference.isChecked();
|
||||
boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff);
|
||||
if (isChecked) {
|
||||
mLogger.voiceInputSettingEnabled();
|
||||
} else {
|
||||
mLogger.voiceInputSettingDisabled();
|
||||
}
|
||||
editor.putBoolean(VOICE_SETTINGS_KEY, isChecked);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue