aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIMESettings.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIMESettings.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIMESettings.java87
1 files changed, 66 insertions, 21 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIMESettings.java b/java/src/com/android/inputmethod/latin/LatinIMESettings.java
index ffff33da2..3aa89dd59 100644
--- a/java/src/com/android/inputmethod/latin/LatinIMESettings.java
+++ b/java/src/com/android/inputmethod/latin/LatinIMESettings.java
@@ -16,8 +16,8 @@
package com.android.inputmethod.latin;
-import java.util.ArrayList;
-import java.util.Locale;
+import com.android.inputmethod.voice.VoiceIMEConnector;
+import com.android.inputmethod.voice.VoiceInputLogger;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -25,16 +25,19 @@ import android.app.backup.BackupManager;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.os.Vibrator;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.speech.SpeechRecognizer;
import android.text.AutoText;
+import android.text.TextUtils;
+import android.text.method.LinkMovementMethod;
import android.util.Log;
+import android.widget.TextView;
-import com.android.inputmethod.voice.SettingsUtil;
-import com.android.inputmethod.voice.VoiceInputLogger;
+import java.util.Locale;
public class LatinIMESettings extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener,
@@ -43,7 +46,10 @@ public class LatinIMESettings extends PreferenceActivity
private static final String QUICK_FIXES_KEY = "quick_fixes";
private static final String PREDICTION_SETTINGS_KEY = "prediction_settings";
private static final String VOICE_SETTINGS_KEY = "voice_mode";
- /* package */ static final String PREF_SETTINGS_KEY = "settings_key";
+ private static final String PREF_AUTO_COMPLETION_THRESHOLD = "auto_completion_threshold";
+ private static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
+ public static final String PREF_SETTINGS_KEY = "settings_key";
+ /* package */ static final String PREF_VIBRATE_ON = "vibrate_on";
private static final String TAG = "LatinIMESettings";
@@ -53,13 +59,23 @@ public class LatinIMESettings extends PreferenceActivity
private CheckBoxPreference mQuickFixes;
private ListPreference mVoicePreference;
private ListPreference mSettingsKeyPreference;
+ private ListPreference mAutoCompletionThreshold;
+ private CheckBoxPreference mBigramSuggestion;
private boolean mVoiceOn;
+ private AlertDialog mDialog;
+
private VoiceInputLogger mLogger;
private boolean mOkClicked = false;
private String mVoiceModeOff;
+ private void ensureConsistencyOfAutoCompletionSettings() {
+ final String autoCompletionOff = getResources().getString(
+ R.string.auto_completion_threshold_mode_value_off);
+ final String currentSetting = mAutoCompletionThreshold.getValue();
+ mBigramSuggestion.setEnabled(!currentSetting.equals(autoCompletionOff));
+ }
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -73,6 +89,28 @@ public class LatinIMESettings extends PreferenceActivity
mVoiceModeOff = getString(R.string.voice_mode_off);
mVoiceOn = !(prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff).equals(mVoiceModeOff));
mLogger = VoiceInputLogger.getLogger(this);
+
+ mAutoCompletionThreshold = (ListPreference) findPreference(PREF_AUTO_COMPLETION_THRESHOLD);
+ mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
+ ensureConsistencyOfAutoCompletionSettings();
+
+ final boolean showSettingsKeyOption = getResources().getBoolean(
+ R.bool.config_enable_show_settings_key_option);
+ if (!showSettingsKeyOption) {
+ getPreferenceScreen().removePreference(mSettingsKeyPreference);
+ }
+
+ final boolean showVoiceKeyOption = getResources().getBoolean(
+ R.bool.config_enable_show_voice_key_option);
+ if (!showVoiceKeyOption) {
+ getPreferenceScreen().removePreference(mVoicePreference);
+ }
+
+ Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
+ if (vibrator == null || !vibrator.hasVibrator()) {
+ getPreferenceScreen().removePreference(
+ getPreferenceScreen().findPreference(PREF_VIBRATE_ON));
+ }
}
@Override
@@ -83,7 +121,7 @@ public class LatinIMESettings extends PreferenceActivity
((PreferenceGroup) findPreference(PREDICTION_SETTINGS_KEY))
.removePreference(mQuickFixes);
}
- if (!LatinIME.VOICE_INSTALLED
+ if (!VoiceIMEConnector.VOICE_INSTALLED
|| !SpeechRecognizer.isRecognitionAvailable(this)) {
getPreferenceScreen().removePreference(mVoicePreference);
} else {
@@ -99,6 +137,7 @@ public class LatinIMESettings extends PreferenceActivity
super.onDestroy();
}
+ @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
(new BackupManager(this)).dataChanged();
// If turning on voice input, show dialog
@@ -108,6 +147,7 @@ public class LatinIMESettings extends PreferenceActivity
showVoiceConfirmation();
}
}
+ ensureConsistencyOfAutoCompletionSettings();
mVoiceOn = !(prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff).equals(mVoiceModeOff));
updateVoiceModeSummary();
updateSettingsKeySummary();
@@ -122,6 +162,13 @@ public class LatinIMESettings extends PreferenceActivity
private void showVoiceConfirmation() {
mOkClicked = false;
showDialog(VOICE_INPUT_CONFIRM_DIALOG);
+ // 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());
+ }
+ }
}
private void updateVoiceModeSummary() {
@@ -135,6 +182,7 @@ public class LatinIMESettings extends PreferenceActivity
switch (id) {
case VOICE_INPUT_CONFIRM_DIALOG:
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
+ @Override
public void onClick(DialogInterface dialog, int whichButton) {
if (whichButton == DialogInterface.BUTTON_NEGATIVE) {
mVoicePreference.setValue(mVoiceModeOff);
@@ -154,27 +202,23 @@ public class LatinIMESettings extends PreferenceActivity
// 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.
- String supportedLocalesString = SettingsUtil.getSettingsString(
- getContentResolver(),
- SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
- LatinIME.DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
- ArrayList<String> voiceInputSupportedLocales =
- LatinIME.newArrayList(supportedLocalesString.split("\\s+"));
- boolean localeSupported = voiceInputSupportedLocales.contains(
+ boolean localeSupported = SubtypeSwitcher.getInstance().isVoiceSupported(
Locale.getDefault().toString());
+ final CharSequence message;
if (localeSupported) {
- String message = getString(R.string.voice_warning_may_not_understand) + "\n\n" +
- getString(R.string.voice_hint_dialog_message);
- builder.setMessage(message);
+ message = TextUtils.concat(
+ getText(R.string.voice_warning_may_not_understand), "\n\n",
+ getText(R.string.voice_hint_dialog_message));
} else {
- String message = getString(R.string.voice_warning_locale_not_supported) +
- "\n\n" + getString(R.string.voice_warning_may_not_understand) + "\n\n" +
- getString(R.string.voice_hint_dialog_message);
- builder.setMessage(message);
+ 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));
}
-
+ builder.setMessage(message);
AlertDialog dialog = builder.create();
+ mDialog = dialog;
dialog.setOnDismissListener(this);
mLogger.settingsWarningDialogShown();
return dialog;
@@ -184,6 +228,7 @@ public class LatinIMESettings extends PreferenceActivity
}
}
+ @Override
public void onDismiss(DialogInterface dialog) {
mLogger.settingsWarningDialogDismissed();
if (!mOkClicked) {