aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/settings
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/settings')
-rw-r--r--java/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java43
-rw-r--r--java/src/com/android/inputmethod/latin/settings/AdvancedSettingsFragment.java248
-rw-r--r--java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java41
-rw-r--r--java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java123
-rw-r--r--java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java52
-rw-r--r--java/src/com/android/inputmethod/latin/settings/DebugSettings.java286
-rw-r--r--java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java294
-rw-r--r--java/src/com/android/inputmethod/latin/settings/GestureSettingsFragment.java39
-rw-r--r--java/src/com/android/inputmethod/latin/settings/MultiLingualSettingsFragment.java48
-rw-r--r--java/src/com/android/inputmethod/latin/settings/PreferencesSettingsFragment.java (renamed from java/src/com/android/inputmethod/latin/settings/InputSettingsFragment.java)6
-rw-r--r--java/src/com/android/inputmethod/latin/settings/RadioButtonPreference.java93
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java26
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsActivity.java27
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsFragment.java386
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java75
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java17
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SubScreenFragment.java5
-rw-r--r--java/src/com/android/inputmethod/latin/settings/ThemeSettingsFragment.java114
18 files changed, 1156 insertions, 767 deletions
diff --git a/java/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java b/java/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java
deleted file mode 100644
index 6543003e8..000000000
--- a/java/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.settings;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-
-import com.android.inputmethodcommon.InputMethodSettingsFragment;
-
-/**
- * Utility class for managing additional features settings.
- */
-public class AdditionalFeaturesSettingUtils {
- public static final int ADDITIONAL_FEATURES_SETTINGS_SIZE = 0;
-
- private AdditionalFeaturesSettingUtils() {
- // This utility class is not publicly instantiable.
- }
-
- public static void addAdditionalFeaturesPreferences(
- final Context context, final InputMethodSettingsFragment settingsFragment) {
- // do nothing.
- }
-
- public static void readAdditionalFeaturesPreferencesIntoArray(
- final SharedPreferences prefs, final int[] additionalFeaturesPreferences) {
- // do nothing.
- }
-}
diff --git a/java/src/com/android/inputmethod/latin/settings/AdvancedSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AdvancedSettingsFragment.java
new file mode 100644
index 000000000..00f2c73dd
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/settings/AdvancedSettingsFragment.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.settings;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.media.AudioManager;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.TwoStatePreference;
+
+import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.define.ProductionFlags;
+import com.android.inputmethod.latin.setup.LauncherIconVisibilityManager;
+
+/**
+ * "Advanced" settings sub screen.
+ *
+ * This settings sub screen handles the following advanced preferences.
+ * - Key popup dismiss delay
+ * - Keypress vibration duration
+ * - Keypress sound volume
+ * - Show app icon
+ * - Improve keyboard
+ * - Debug settings
+ */
+public final class AdvancedSettingsFragment extends SubScreenFragment {
+ @Override
+ public void onCreate(final Bundle icicle) {
+ super.onCreate(icicle);
+ addPreferencesFromResource(R.xml.prefs_screen_advanced);
+
+ final Resources res = getResources();
+ final Context context = getActivity();
+
+ // When we are called from the Settings application but we are not already running, some
+ // singleton and utility classes may not have been initialized. We have to call
+ // initialization method of these classes here. See {@link LatinIME#onCreate()}.
+ AudioAndHapticFeedbackManager.init(context);
+
+ final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
+
+ if (!Settings.isInternal(prefs)) {
+ removePreference(Settings.SCREEN_DEBUG);
+ }
+
+ if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
+ removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
+ }
+
+ // TODO: consolidate key preview dismiss delay with the key preview animation parameters.
+ if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
+ removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
+ } else {
+ // TODO: Cleanup this setup.
+ final ListPreference keyPreviewPopupDismissDelay =
+ (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
+ final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
+ R.integer.config_key_preview_linger_timeout));
+ keyPreviewPopupDismissDelay.setEntries(new String[] {
+ res.getString(R.string.key_preview_popup_dismiss_no_delay),
+ res.getString(R.string.key_preview_popup_dismiss_default_delay),
+ });
+ keyPreviewPopupDismissDelay.setEntryValues(new String[] {
+ "0",
+ popupDismissDelayDefaultValue
+ });
+ if (null == keyPreviewPopupDismissDelay.getValue()) {
+ keyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
+ }
+ keyPreviewPopupDismissDelay.setEnabled(
+ Settings.readKeyPreviewPopupEnabled(prefs, res));
+ }
+
+ if (!res.getBoolean(R.bool.config_setup_wizard_available)) {
+ removePreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON);
+ }
+
+ if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
+ final Preference enableMetricsLogging =
+ findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
+ if (enableMetricsLogging != null) {
+ final int applicationLabelRes = context.getApplicationInfo().labelRes;
+ final String applicationName = res.getString(applicationLabelRes);
+ final String enableMetricsLoggingTitle = res.getString(
+ R.string.enable_metrics_logging, applicationName);
+ enableMetricsLogging.setTitle(enableMetricsLoggingTitle);
+ }
+ } else {
+ removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
+ }
+
+ setupKeypressVibrationDurationSettings();
+ setupKeypressSoundVolumeSettings();
+ refreshEnablingsOfKeypressSoundAndVibrationSettings();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
+ final TwoStatePreference showSetupWizardIcon =
+ (TwoStatePreference)findPreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON);
+ if (showSetupWizardIcon != null) {
+ showSetupWizardIcon.setChecked(Settings.readShowSetupWizardIcon(prefs, getActivity()));
+ }
+ updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
+ final Resources res = getResources();
+ if (key.equals(Settings.PREF_POPUP_ON)) {
+ setPreferenceEnabled(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,
+ Settings.readKeyPreviewPopupEnabled(prefs, res));
+ } else if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
+ LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
+ }
+ updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
+ refreshEnablingsOfKeypressSoundAndVibrationSettings();
+ }
+
+ private void refreshEnablingsOfKeypressSoundAndVibrationSettings() {
+ final SharedPreferences prefs = getSharedPreferences();
+ final Resources res = getResources();
+ setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,
+ Settings.readVibrationEnabled(prefs, res));
+ setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME,
+ Settings.readKeypressSoundEnabled(prefs, res));
+ }
+
+ private void setupKeypressVibrationDurationSettings() {
+ final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
+ Settings.PREF_VIBRATION_DURATION_SETTINGS);
+ if (pref == null) {
+ return;
+ }
+ final SharedPreferences prefs = getSharedPreferences();
+ final Resources res = getResources();
+ pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
+ @Override
+ public void writeValue(final int value, final String key) {
+ prefs.edit().putInt(key, value).apply();
+ }
+
+ @Override
+ public void writeDefaultValue(final String key) {
+ prefs.edit().remove(key).apply();
+ }
+
+ @Override
+ public int readValue(final String key) {
+ return Settings.readKeypressVibrationDuration(prefs, res);
+ }
+
+ @Override
+ public int readDefaultValue(final String key) {
+ return Settings.readDefaultKeypressVibrationDuration(res);
+ }
+
+ @Override
+ public void feedbackValue(final int value) {
+ AudioAndHapticFeedbackManager.getInstance().vibrate(value);
+ }
+
+ @Override
+ public String getValueText(final int value) {
+ if (value < 0) {
+ return res.getString(R.string.settings_system_default);
+ }
+ return res.getString(R.string.abbreviation_unit_milliseconds, value);
+ }
+ });
+ }
+
+ private void setupKeypressSoundVolumeSettings() {
+ final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
+ Settings.PREF_KEYPRESS_SOUND_VOLUME);
+ if (pref == null) {
+ return;
+ }
+ final SharedPreferences prefs = getSharedPreferences();
+ final Resources res = getResources();
+ final AudioManager am = (AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
+ pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
+ private static final float PERCENTAGE_FLOAT = 100.0f;
+
+ private float getValueFromPercentage(final int percentage) {
+ return percentage / PERCENTAGE_FLOAT;
+ }
+
+ private int getPercentageFromValue(final float floatValue) {
+ return (int)(floatValue * PERCENTAGE_FLOAT);
+ }
+
+ @Override
+ public void writeValue(final int value, final String key) {
+ prefs.edit().putFloat(key, getValueFromPercentage(value)).apply();
+ }
+
+ @Override
+ public void writeDefaultValue(final String key) {
+ prefs.edit().remove(key).apply();
+ }
+
+ @Override
+ public int readValue(final String key) {
+ return getPercentageFromValue(Settings.readKeypressSoundVolume(prefs, res));
+ }
+
+ @Override
+ public int readDefaultValue(final String key) {
+ return getPercentageFromValue(Settings.readDefaultKeypressSoundVolume(res));
+ }
+
+ @Override
+ public String getValueText(final int value) {
+ if (value < 0) {
+ return res.getString(R.string.settings_system_default);
+ }
+ return Integer.toString(value);
+ }
+
+ @Override
+ public void feedbackValue(final int value) {
+ am.playSoundEffect(
+ AudioManager.FX_KEYPRESS_STANDARD, getValueFromPercentage(value));
+ }
+ });
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java
new file mode 100644
index 000000000..f5e4d33a2
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.settings;
+
+import android.os.Bundle;
+
+import com.android.inputmethod.latin.R;
+
+
+/**
+ * "Appearance" settings sub screen.
+ */
+public final class AppearanceSettingsFragment extends SubScreenFragment {
+ @Override
+ public void onCreate(final Bundle icicle) {
+ super.onCreate(icicle);
+ addPreferencesFromResource(R.xml.prefs_screen_appearance);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ CustomInputStyleSettingsFragment.updateCustomInputStylesSummary(
+ findPreference(Settings.PREF_CUSTOM_INPUT_STYLES));
+ ThemeSettingsFragment.updateKeyboardThemeSummary(findPreference(Settings.SCREEN_THEME));
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java
new file mode 100644
index 000000000..ec29a7eb2
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.settings;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.Build;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+
+import com.android.inputmethod.dictionarypack.DictionarySettingsActivity;
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.userdictionary.UserDictionaryList;
+import com.android.inputmethod.latin.userdictionary.UserDictionarySettings;
+
+import java.util.TreeSet;
+
+/**
+ * "Text correction" settings sub screen.
+ *
+ * This settings sub screen handles the following text correction preferences.
+ * - Personal dictionary
+ * - Add-on dictionaries
+ * - Block offensive words
+ * - Auto-correction
+ * - Show correction suggestions
+ * - Personalized suggestions
+ * - Suggest Contact names
+ * - Next-word suggestions
+ */
+public final class CorrectionSettingsFragment extends SubScreenFragment {
+ private static final boolean DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS = false;
+ private static final boolean USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS =
+ DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS
+ || Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2;
+
+ @Override
+ public void onCreate(final Bundle icicle) {
+ super.onCreate(icicle);
+ addPreferencesFromResource(R.xml.prefs_screen_correction);
+
+ final Context context = getActivity();
+ final PackageManager pm = context.getPackageManager();
+
+ ensureConsistencyOfAutoCorrectionSettings();
+
+ final Preference dictionaryLink = findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
+ final Intent intent = dictionaryLink.getIntent();
+ intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName());
+ final int number = pm.queryIntentActivities(intent, 0).size();
+ if (0 >= number) {
+ removePreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
+ }
+
+ final Preference editPersonalDictionary =
+ findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY);
+ final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent();
+ final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS ? null
+ : pm.resolveActivity(
+ editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY);
+ if (ri == null) {
+ overwriteUserDictionaryPreference(editPersonalDictionary);
+ }
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
+ ensureConsistencyOfAutoCorrectionSettings();
+ }
+
+ private void ensureConsistencyOfAutoCorrectionSettings() {
+ final String autoCorrectionOff = getString(
+ R.string.auto_correction_threshold_mode_index_off);
+ final ListPreference autoCorrectionThresholdPref = (ListPreference)findPreference(
+ Settings.PREF_AUTO_CORRECTION_THRESHOLD);
+ final String currentSetting = autoCorrectionThresholdPref.getValue();
+ setPreferenceEnabled(
+ Settings.PREF_BIGRAM_PREDICTIONS, !currentSetting.equals(autoCorrectionOff));
+ }
+
+ private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {
+ final Activity activity = getActivity();
+ final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
+ if (null == localeList) {
+ // The locale list is null if and only if the user dictionary service is
+ // not present or disabled. In this case we need to remove the preference.
+ getPreferenceScreen().removePreference(userDictionaryPreference);
+ } else if (localeList.size() <= 1) {
+ userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
+ // If the size of localeList is 0, we don't set the locale parameter in the
+ // extras. This will be interpreted by the UserDictionarySettings class as
+ // meaning "the current locale".
+ // Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
+ // the locale list always has at least one element, since it always includes the current
+ // locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
+ if (localeList.size() == 1) {
+ final String locale = (String)localeList.toArray()[0];
+ userDictionaryPreference.getExtras().putString("locale", locale);
+ }
+ } else {
+ userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
+ }
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java
index 21f2afd01..9bc398654 100644
--- a/java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/CustomInputStyleSettingsFragment.java
@@ -30,11 +30,15 @@ import android.preference.DialogPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
+import android.support.v4.view.ViewCompat;
+import android.text.TextUtils;
import android.util.Pair;
+import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewGroup;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import android.widget.ArrayAdapter;
@@ -43,6 +47,7 @@ import android.widget.SpinnerAdapter;
import android.widget.Toast;
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
+import com.android.inputmethod.compat.ViewCompatUtils;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
@@ -63,7 +68,6 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
private AlertDialog mSubtypeEnablerNotificationDialog;
private String mSubtypePreferenceKeyForSubtypeEnabler;
- private static final int MENU_ADD_SUBTYPE = Menu.FIRST;
private static final String KEY_IS_ADDING_NEW_SUBTYPE = "is_adding_new_subtype";
private static final String KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN =
"is_subtype_enabler_notification_dialog_open";
@@ -234,6 +238,12 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
mSubtypeLocaleSpinner.setAdapter(mProxy.getSubtypeLocaleAdapter());
mKeyboardLayoutSetSpinner = (Spinner) v.findViewById(R.id.keyboard_layout_set_spinner);
mKeyboardLayoutSetSpinner.setAdapter(mProxy.getKeyboardLayoutSetAdapter());
+ // All keyboard layout names are in the Latin script and thus left to right. That means
+ // the view would align them to the left even if the system locale is RTL, but that
+ // would look strange. To fix this, we align them to the view's start, which will be
+ // natural for any direction.
+ ViewCompatUtils.setTextAlignment(
+ mKeyboardLayoutSetSpinner, ViewCompatUtils.TEXT_ALIGNMENT_VIEW_START);
return v;
}
@@ -387,6 +397,25 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
// Empty constructor for fragment generation.
}
+ static void updateCustomInputStylesSummary(final Preference pref) {
+ // When we are called from the Settings application but we are not already running, some
+ // singleton and utility classes may not have been initialized. We have to call
+ // initialization method of these classes here. See {@link LatinIME#onCreate()}.
+ SubtypeLocaleUtils.init(pref.getContext());
+
+ final Resources res = pref.getContext().getResources();
+ final SharedPreferences prefs = pref.getSharedPreferences();
+ final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
+ final InputMethodSubtype[] subtypes =
+ AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
+ final ArrayList<String> subtypeNames = new ArrayList<>();
+ for (final InputMethodSubtype subtype : subtypes) {
+ subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype));
+ }
+ // TODO: A delimiter of custom input styles should be localized.
+ pref.setSummary(TextUtils.join(", ", subtypeNames));
+ }
+
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -399,6 +428,16 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
}
@Override
+ public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
+ final Bundle savedInstanceState) {
+ final View view = super.onCreateView(inflater, container, savedInstanceState);
+ // For correct display in RTL locales, we need to set the layout direction of the
+ // fragment's top view.
+ ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_LOCALE);
+ return view;
+ }
+
+ @Override
public void onActivityCreated(final Bundle savedInstanceState) {
final Context context = getActivity();
mSubtypeLocaleAdapter = new SubtypeLocaleAdapter(context);
@@ -423,7 +462,7 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
KEY_SUBTYPE_FOR_SUBTYPE_ENABLER);
final SubtypePreference subtypePref = (SubtypePreference)findPreference(
mSubtypePreferenceKeyForSubtypeEnabler);
- mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
+ mSubtypeEnablerNotificationDialog = createDialog();
mSubtypeEnablerNotificationDialog.show();
}
}
@@ -477,7 +516,7 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
if (findDuplicatedSubtype(subtype) == null) {
mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey();
- mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
+ mSubtypeEnablerNotificationDialog = createDialog();
mSubtypeEnablerNotificationDialog.show();
return;
}
@@ -514,7 +553,7 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
localeString, keyboardLayoutSetName);
}
- private AlertDialog createDialog(final SubtypePreference subtypePref) {
+ private AlertDialog createDialog() {
final AlertDialog.Builder builder = new AlertDialog.Builder(
DialogUtils.getPlatformDialogThemeContext(getActivity()));
builder.setTitle(R.string.custom_input_styles_title)
@@ -581,14 +620,13 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
- final MenuItem addSubtypeMenu = menu.add(0, MENU_ADD_SUBTYPE, 0, R.string.add_style);
- addSubtypeMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ inflater.inflate(R.menu.add_style, menu);
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
- if (itemId == MENU_ADD_SUBTYPE) {
+ if (itemId == R.id.action_add_style) {
final SubtypePreference newSubtype =
SubtypePreference.newIncompleteSubtypePreference(getActivity(), mSubtypeProxy);
getPreferenceScreen().addPreference(newSubtype);
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
index e4271adac..48f4c758c 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
@@ -16,283 +16,31 @@
package com.android.inputmethod.latin.settings;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
-import android.os.Bundle;
-import android.os.Process;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceClickListener;
-import android.preference.PreferenceFragment;
-import android.preference.PreferenceGroup;
-import android.preference.PreferenceScreen;
-import android.preference.TwoStatePreference;
-
-import com.android.inputmethod.latin.DictionaryDumpBroadcastReceiver;
-import com.android.inputmethod.latin.DictionaryFacilitator;
-import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.debug.ExternalDictionaryGetterForDebug;
-import com.android.inputmethod.latin.utils.ApplicationUtils;
-import com.android.inputmethod.latin.utils.ResourceUtils;
-
-public final class DebugSettings extends PreferenceFragment
- implements SharedPreferences.OnSharedPreferenceChangeListener {
-
+public final class DebugSettings {
public static final String PREF_DEBUG_MODE = "debug_mode";
public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch";
- public static final String PREF_KEY_PREVIEW_SHOW_UP_START_SCALE =
- "pref_key_preview_show_up_start_scale";
- public static final String PREF_KEY_PREVIEW_DISMISS_END_SCALE =
- "pref_key_preview_dismiss_end_scale";
+ public static final String PREF_FORCE_PHYSICAL_KEYBOARD_SPECIAL_KEY =
+ "force_physical_keyboard_special_key";
+ public static final String PREF_SHOW_UI_TO_ACCEPT_TYPED_WORD =
+ "pref_show_ui_to_accept_typed_word";
+ public static final String PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS =
+ "pref_has_custom_key_preview_animation_params";
+ public static final String PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE =
+ "pref_key_preview_show_up_start_x_scale";
+ public static final String PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE =
+ "pref_key_preview_show_up_start_y_scale";
+ public static final String PREF_KEY_PREVIEW_DISMISS_END_X_SCALE =
+ "pref_key_preview_dismiss_end_x_scale";
+ public static final String PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE =
+ "pref_key_preview_dismiss_end_y_scale";
public static final String PREF_KEY_PREVIEW_SHOW_UP_DURATION =
"pref_key_preview_show_up_duration";
public static final String PREF_KEY_PREVIEW_DISMISS_DURATION =
"pref_key_preview_dismiss_duration";
- private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary";
- private static final String PREF_KEY_DUMP_DICTS = "pref_key_dump_dictionaries";
- private static final String PREF_KEY_DUMP_DICT_PREFIX = "pref_key_dump_dictionaries";
- private static final String DICT_NAME_KEY_FOR_EXTRAS = "dict_name";
public static final String PREF_SLIDING_KEY_INPUT_PREVIEW = "pref_sliding_key_input_preview";
public static final String PREF_KEY_LONGPRESS_TIMEOUT = "pref_key_longpress_timeout";
- private boolean mServiceNeedsRestart = false;
- private TwoStatePreference mDebugMode;
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- addPreferencesFromResource(R.xml.prefs_screen_debug);
- TwoStatePreferenceHelper.replaceCheckBoxPreferencesBySwitchPreferences(
- getPreferenceScreen());
- SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
- prefs.registerOnSharedPreferenceChangeListener(this);
-
- final PreferenceScreen readExternalDictionary =
- (PreferenceScreen) findPreference(PREF_READ_EXTERNAL_DICTIONARY);
- if (null != readExternalDictionary) {
- readExternalDictionary.setOnPreferenceClickListener(
- new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(final Preference arg0) {
- ExternalDictionaryGetterForDebug.chooseAndInstallDictionary(
- getActivity());
- mServiceNeedsRestart = true;
- return true;
- }
- });
- }
-
- final PreferenceGroup dictDumpPreferenceGroup =
- (PreferenceGroup)findPreference(PREF_KEY_DUMP_DICTS);
- final OnPreferenceClickListener dictDumpPrefClickListener =
- new DictDumpPrefClickListener(this);
- for (final String dictName : DictionaryFacilitator.DICT_TYPE_TO_CLASS.keySet()) {
- final Preference preference = new Preference(getActivity());
- preference.setKey(PREF_KEY_DUMP_DICT_PREFIX + dictName);
- preference.setTitle("Dump " + dictName + " dictionary");
- preference.setOnPreferenceClickListener(dictDumpPrefClickListener);
- preference.getExtras().putString(DICT_NAME_KEY_FOR_EXTRAS, dictName);
- dictDumpPreferenceGroup.addPreference(preference);
- }
- final Resources res = getResources();
- setupKeyLongpressTimeoutSettings(prefs, res);
- setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_SHOW_UP_DURATION,
- res.getInteger(R.integer.config_key_preview_show_up_duration));
- setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_DISMISS_DURATION,
- res.getInteger(R.integer.config_key_preview_dismiss_duration));
- setupKeyPreviewAnimationScale(prefs, res, PREF_KEY_PREVIEW_SHOW_UP_START_SCALE,
- ResourceUtils.getFloatFromFraction(
- res, R.fraction.config_key_preview_show_up_start_scale));
- setupKeyPreviewAnimationScale(prefs, res, PREF_KEY_PREVIEW_DISMISS_END_SCALE,
- ResourceUtils.getFloatFromFraction(
- res, R.fraction.config_key_preview_dismiss_end_scale));
-
- mServiceNeedsRestart = false;
- mDebugMode = (TwoStatePreference) findPreference(PREF_DEBUG_MODE);
- updateDebugMode();
- }
-
- private static class DictDumpPrefClickListener implements OnPreferenceClickListener {
- final PreferenceFragment mPreferenceFragment;
-
- public DictDumpPrefClickListener(final PreferenceFragment preferenceFragment) {
- mPreferenceFragment = preferenceFragment;
- }
-
- @Override
- public boolean onPreferenceClick(final Preference arg0) {
- final String dictName = arg0.getExtras().getString(DICT_NAME_KEY_FOR_EXTRAS);
- if (dictName != null) {
- final Intent intent =
- new Intent(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION);
- intent.putExtra(DictionaryDumpBroadcastReceiver.DICTIONARY_NAME_KEY, dictName);
- mPreferenceFragment.getActivity().sendBroadcast(intent);
- }
- return true;
- }
- }
-
- @Override
- public void onStop() {
- super.onStop();
- if (mServiceNeedsRestart) {
- Process.killProcess(Process.myPid());
- }
- }
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
- if (key.equals(PREF_DEBUG_MODE) && mDebugMode != null) {
- mDebugMode.setChecked(prefs.getBoolean(PREF_DEBUG_MODE, false));
- updateDebugMode();
- mServiceNeedsRestart = true;
- return;
- }
- if (key.equals(PREF_FORCE_NON_DISTINCT_MULTITOUCH)) {
- mServiceNeedsRestart = true;
- return;
- }
- }
-
- private void updateDebugMode() {
- if (mDebugMode == null) {
- return;
- }
- boolean isDebugMode = mDebugMode.isChecked();
- final String version = getResources().getString(
- R.string.version_text, ApplicationUtils.getVersionName(getActivity()));
- if (!isDebugMode) {
- mDebugMode.setTitle(version);
- mDebugMode.setSummary("");
- } else {
- mDebugMode.setTitle(getResources().getString(R.string.prefs_debug_mode));
- mDebugMode.setSummary(version);
- }
- }
-
- private void setupKeyLongpressTimeoutSettings(final SharedPreferences sp,
- final Resources res) {
- final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
- PREF_KEY_LONGPRESS_TIMEOUT);
- if (pref == null) {
- return;
- }
- pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
- @Override
- public void writeValue(final int value, final String key) {
- sp.edit().putInt(key, value).apply();
- }
-
- @Override
- public void writeDefaultValue(final String key) {
- sp.edit().remove(key).apply();
- }
-
- @Override
- public int readValue(final String key) {
- return Settings.readKeyLongpressTimeout(sp, res);
- }
-
- @Override
- public int readDefaultValue(final String key) {
- return Settings.readDefaultKeyLongpressTimeout(res);
- }
-
- @Override
- public String getValueText(final int value) {
- return res.getString(R.string.abbreviation_unit_milliseconds, value);
- }
-
- @Override
- public void feedbackValue(final int value) {}
- });
- }
-
- private void setupKeyPreviewAnimationScale(final SharedPreferences sp, final Resources res,
- final String prefKey, final float defaultValue) {
- final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
- if (pref == null) {
- return;
- }
- pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
- private static final float PERCENTAGE_FLOAT = 100.0f;
-
- private float getValueFromPercentage(final int percentage) {
- return percentage / PERCENTAGE_FLOAT;
- }
-
- private int getPercentageFromValue(final float floatValue) {
- return (int)(floatValue * PERCENTAGE_FLOAT);
- }
-
- @Override
- public void writeValue(final int value, final String key) {
- sp.edit().putFloat(key, getValueFromPercentage(value)).apply();
- }
-
- @Override
- public void writeDefaultValue(final String key) {
- sp.edit().remove(key).apply();
- }
-
- @Override
- public int readValue(final String key) {
- return getPercentageFromValue(
- Settings.readKeyPreviewAnimationScale(sp, key, defaultValue));
- }
-
- @Override
- public int readDefaultValue(final String key) {
- return getPercentageFromValue(defaultValue);
- }
-
- @Override
- public String getValueText(final int value) {
- if (value < 0) {
- return res.getString(R.string.settings_system_default);
- }
- return String.format("%d%%", value);
- }
-
- @Override
- public void feedbackValue(final int value) {}
- });
- }
-
- private void setupKeyPreviewAnimationDuration(final SharedPreferences sp, final Resources res,
- final String prefKey, final int defaultValue) {
- final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
- if (pref == null) {
- return;
- }
- pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
- @Override
- public void writeValue(final int value, final String key) {
- sp.edit().putInt(key, value).apply();
- }
-
- @Override
- public void writeDefaultValue(final String key) {
- sp.edit().remove(key).apply();
- }
-
- @Override
- public int readValue(final String key) {
- return Settings.readKeyPreviewAnimationDuration(sp, key, defaultValue);
- }
-
- @Override
- public int readDefaultValue(final String key) {
- return defaultValue;
- }
-
- @Override
- public String getValueText(final int value) {
- return res.getString(R.string.abbreviation_unit_milliseconds, value);
- }
-
- @Override
- public void feedbackValue(final int value) {}
- });
+ private DebugSettings() {
+ // This class is not publicly instantiable.
}
}
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java
new file mode 100644
index 000000000..5640e2039
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java
@@ -0,0 +1,294 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.settings;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.os.Process;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceGroup;
+import android.preference.TwoStatePreference;
+
+import com.android.inputmethod.latin.DictionaryDumpBroadcastReceiver;
+import com.android.inputmethod.latin.DictionaryFacilitator;
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.debug.ExternalDictionaryGetterForDebug;
+import com.android.inputmethod.latin.utils.ApplicationUtils;
+import com.android.inputmethod.latin.utils.ResourceUtils;
+
+import java.util.Locale;
+
+/**
+ * "Debug mode" settings sub screen.
+ *
+ * This settings sub screen handles a several preference options for debugging.
+ */
+public final class DebugSettingsFragment extends SubScreenFragment
+ implements OnPreferenceClickListener {
+ private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary";
+ private static final String PREF_KEY_DUMP_DICTS = "pref_key_dump_dictionaries";
+ private static final String PREF_KEY_DUMP_DICT_PREFIX = "pref_key_dump_dictionaries";
+
+ private boolean mServiceNeedsRestart = false;
+ private Preference mReadExternalDictionaryPref;
+ private TwoStatePreference mDebugMode;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ addPreferencesFromResource(R.xml.prefs_screen_debug);
+
+ if (!Settings.HAS_UI_TO_ACCEPT_TYPED_WORD) {
+ removePreference(DebugSettings.PREF_SHOW_UI_TO_ACCEPT_TYPED_WORD);
+ }
+
+ mReadExternalDictionaryPref = findPreference(PREF_READ_EXTERNAL_DICTIONARY);
+ if (mReadExternalDictionaryPref != null) {
+ mReadExternalDictionaryPref.setOnPreferenceClickListener(this);
+ }
+
+ final PreferenceGroup dictDumpPreferenceGroup =
+ (PreferenceGroup)findPreference(PREF_KEY_DUMP_DICTS);
+ for (final String dictName : DictionaryFacilitator.DICT_TYPE_TO_CLASS.keySet()) {
+ final Preference pref = new DictDumpPreference(getActivity(), dictName);
+ pref.setOnPreferenceClickListener(this);
+ dictDumpPreferenceGroup.addPreference(pref);
+ }
+ final Resources res = getResources();
+ setupKeyLongpressTimeoutSettings();
+ setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION,
+ res.getInteger(R.integer.config_key_preview_show_up_duration));
+ setupKeyPreviewAnimationDuration(DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION,
+ res.getInteger(R.integer.config_key_preview_dismiss_duration));
+ final float defaultKeyPreviewShowUpStartScale = ResourceUtils.getFloatFromFraction(
+ res, R.fraction.config_key_preview_show_up_start_scale);
+ final float defaultKeyPreviewDismissEndScale = ResourceUtils.getFloatFromFraction(
+ res, R.fraction.config_key_preview_dismiss_end_scale);
+ setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE,
+ defaultKeyPreviewShowUpStartScale);
+ setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE,
+ defaultKeyPreviewShowUpStartScale);
+ setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_X_SCALE,
+ defaultKeyPreviewDismissEndScale);
+ setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE,
+ defaultKeyPreviewDismissEndScale);
+
+ mServiceNeedsRestart = false;
+ mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE);
+ updateDebugMode();
+ }
+
+ private static class DictDumpPreference extends Preference {
+ public final String mDictName;
+
+ public DictDumpPreference(final Context context, final String dictName) {
+ super(context);
+ setKey(PREF_KEY_DUMP_DICT_PREFIX + dictName);
+ setTitle("Dump " + dictName + " dictionary");
+ mDictName = dictName;
+ }
+ }
+
+ @Override
+ public boolean onPreferenceClick(final Preference pref) {
+ final Context context = getActivity();
+ if (pref == mReadExternalDictionaryPref) {
+ ExternalDictionaryGetterForDebug.chooseAndInstallDictionary(context);
+ mServiceNeedsRestart = true;
+ return true;
+ }
+ if (pref instanceof DictDumpPreference) {
+ final DictDumpPreference dictDumpPref = (DictDumpPreference)pref;
+ final String dictName = dictDumpPref.mDictName;
+ final Intent intent = new Intent(
+ DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION);
+ intent.putExtra(DictionaryDumpBroadcastReceiver.DICTIONARY_NAME_KEY, dictName);
+ context.sendBroadcast(intent);
+ return true;
+ }
+ return true;
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ if (mServiceNeedsRestart) {
+ Process.killProcess(Process.myPid());
+ }
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
+ if (key.equals(DebugSettings.PREF_DEBUG_MODE) && mDebugMode != null) {
+ mDebugMode.setChecked(prefs.getBoolean(DebugSettings.PREF_DEBUG_MODE, false));
+ updateDebugMode();
+ mServiceNeedsRestart = true;
+ return;
+ }
+ if (key.equals(DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH)
+ || key.equals(DebugSettings.PREF_FORCE_PHYSICAL_KEYBOARD_SPECIAL_KEY)) {
+ mServiceNeedsRestart = true;
+ return;
+ }
+ }
+
+ private void updateDebugMode() {
+ boolean isDebugMode = mDebugMode.isChecked();
+ final String version = getString(
+ R.string.version_text, ApplicationUtils.getVersionName(getActivity()));
+ if (!isDebugMode) {
+ mDebugMode.setTitle(version);
+ mDebugMode.setSummary(null);
+ } else {
+ mDebugMode.setTitle(getString(R.string.prefs_debug_mode));
+ mDebugMode.setSummary(version);
+ }
+ }
+
+ private void setupKeyLongpressTimeoutSettings() {
+ final SharedPreferences prefs = getSharedPreferences();
+ final Resources res = getResources();
+ final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
+ DebugSettings.PREF_KEY_LONGPRESS_TIMEOUT);
+ if (pref == null) {
+ return;
+ }
+ pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
+ @Override
+ public void writeValue(final int value, final String key) {
+ prefs.edit().putInt(key, value).apply();
+ }
+
+ @Override
+ public void writeDefaultValue(final String key) {
+ prefs.edit().remove(key).apply();
+ }
+
+ @Override
+ public int readValue(final String key) {
+ return Settings.readKeyLongpressTimeout(prefs, res);
+ }
+
+ @Override
+ public int readDefaultValue(final String key) {
+ return Settings.readDefaultKeyLongpressTimeout(res);
+ }
+
+ @Override
+ public String getValueText(final int value) {
+ return res.getString(R.string.abbreviation_unit_milliseconds, value);
+ }
+
+ @Override
+ public void feedbackValue(final int value) {}
+ });
+ }
+
+ private void setupKeyPreviewAnimationScale(final String prefKey, final float defaultValue) {
+ final SharedPreferences prefs = getSharedPreferences();
+ final Resources res = getResources();
+ final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
+ if (pref == null) {
+ return;
+ }
+ pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
+ private static final float PERCENTAGE_FLOAT = 100.0f;
+
+ private float getValueFromPercentage(final int percentage) {
+ return percentage / PERCENTAGE_FLOAT;
+ }
+
+ private int getPercentageFromValue(final float floatValue) {
+ return (int)(floatValue * PERCENTAGE_FLOAT);
+ }
+
+ @Override
+ public void writeValue(final int value, final String key) {
+ prefs.edit().putFloat(key, getValueFromPercentage(value)).apply();
+ }
+
+ @Override
+ public void writeDefaultValue(final String key) {
+ prefs.edit().remove(key).apply();
+ }
+
+ @Override
+ public int readValue(final String key) {
+ return getPercentageFromValue(
+ Settings.readKeyPreviewAnimationScale(prefs, key, defaultValue));
+ }
+
+ @Override
+ public int readDefaultValue(final String key) {
+ return getPercentageFromValue(defaultValue);
+ }
+
+ @Override
+ public String getValueText(final int value) {
+ if (value < 0) {
+ return res.getString(R.string.settings_system_default);
+ }
+ return String.format(Locale.ROOT, "%d%%", value);
+ }
+
+ @Override
+ public void feedbackValue(final int value) {}
+ });
+ }
+
+ private void setupKeyPreviewAnimationDuration(final String prefKey, final int defaultValue) {
+ final SharedPreferences prefs = getSharedPreferences();
+ final Resources res = getResources();
+ final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
+ if (pref == null) {
+ return;
+ }
+ pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
+ @Override
+ public void writeValue(final int value, final String key) {
+ prefs.edit().putInt(key, value).apply();
+ }
+
+ @Override
+ public void writeDefaultValue(final String key) {
+ prefs.edit().remove(key).apply();
+ }
+
+ @Override
+ public int readValue(final String key) {
+ return Settings.readKeyPreviewAnimationDuration(prefs, key, defaultValue);
+ }
+
+ @Override
+ public int readDefaultValue(final String key) {
+ return defaultValue;
+ }
+
+ @Override
+ public String getValueText(final int value) {
+ return res.getString(R.string.abbreviation_unit_milliseconds, value);
+ }
+
+ @Override
+ public void feedbackValue(final int value) {}
+ });
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/GestureSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/GestureSettingsFragment.java
new file mode 100644
index 000000000..832fbf65a
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/settings/GestureSettingsFragment.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.settings;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+
+import com.android.inputmethod.latin.R;
+
+/**
+ * "Gesture typing preferences" settings sub screen.
+ *
+ * This settings sub screen handles the following gesture typing preferences.
+ * - Enable gesture typing
+ * - Dynamic floating preview
+ * - Show gesture trail
+ * - Phrase gesture
+ */
+public final class GestureSettingsFragment extends SubScreenFragment {
+ @Override
+ public void onCreate(final Bundle icicle) {
+ super.onCreate(icicle);
+ addPreferencesFromResource(R.xml.prefs_screen_gesture);
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/MultiLingualSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/MultiLingualSettingsFragment.java
index f40106ba9..b073c50a4 100644
--- a/java/src/com/android/inputmethod/latin/settings/MultiLingualSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/MultiLingualSettingsFragment.java
@@ -16,71 +16,27 @@
package com.android.inputmethod.latin.settings;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
import android.os.Bundle;
-import android.preference.PreferenceScreen;
-import android.text.TextUtils;
-import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
-import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import java.util.ArrayList;
/**
- * "Multi lingual options" settings sub screen.
+ * "Multilingual options" settings sub screen.
*
* This settings sub screen handles the following input preferences.
* - Language switch key
* - Switch to other input methods
- * - Custom input styles
*/
public final class MultiLingualSettingsFragment extends SubScreenFragment {
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
- addPreferencesFromResource(R.xml.prefs_screen_multi_lingual);
-
- final Context context = getActivity();
-
- // When we are called from the Settings application but we are not already running, some
- // singleton and utility classes may not have been initialized. We have to call
- // initialization method of these classes here. See {@link LatinIME#onCreate()}.
- SubtypeLocaleUtils.init(context);
-
+ addPreferencesFromResource(R.xml.prefs_screen_multilingual);
if (!Settings.ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS) {
removePreference(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY);
removePreference(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST);
}
}
-
- @Override
- public void onResume() {
- super.onResume();
- updateCustomInputStylesSummary();
- }
-
- @Override
- public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
- // Nothing to do here.
- }
-
- private void updateCustomInputStylesSummary() {
- final SharedPreferences prefs = getSharedPreferences();
- final Resources res = getResources();
- final PreferenceScreen customInputStyles =
- (PreferenceScreen)findPreference(Settings.PREF_CUSTOM_INPUT_STYLES);
- final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
- final InputMethodSubtype[] subtypes =
- AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
- final ArrayList<String> subtypeNames = new ArrayList<>();
- for (final InputMethodSubtype subtype : subtypes) {
- subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype));
- }
- // TODO: A delimiter of custom input styles should be localized.
- customInputStyles.setSummary(TextUtils.join(", ", subtypeNames));
- }
}
diff --git a/java/src/com/android/inputmethod/latin/settings/InputSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/PreferencesSettingsFragment.java
index f459d68dd..49db2bdc0 100644
--- a/java/src/com/android/inputmethod/latin/settings/InputSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/PreferencesSettingsFragment.java
@@ -27,7 +27,7 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SubtypeSwitcher;
/**
- * "Input preferences" settings sub screen.
+ * "Preferences" settings sub screen.
*
* This settings sub screen handles the following input preferences.
* - Auto-capitalization
@@ -37,11 +37,11 @@ import com.android.inputmethod.latin.SubtypeSwitcher;
* - Popup on keypress
* - Voice input key
*/
-public final class InputSettingsFragment extends SubScreenFragment {
+public final class PreferencesSettingsFragment extends SubScreenFragment {
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
- addPreferencesFromResource(R.xml.prefs_screen_input);
+ addPreferencesFromResource(R.xml.prefs_screen_preferences);
final Resources res = getResources();
final Context context = getActivity();
diff --git a/java/src/com/android/inputmethod/latin/settings/RadioButtonPreference.java b/java/src/com/android/inputmethod/latin/settings/RadioButtonPreference.java
new file mode 100644
index 000000000..c173d4706
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/settings/RadioButtonPreference.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.settings;
+
+import android.content.Context;
+import android.preference.Preference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.RadioButton;
+
+import com.android.inputmethod.latin.R;
+
+/**
+ * Radio Button preference
+ */
+public class RadioButtonPreference extends Preference {
+ interface OnRadioButtonClickedListener {
+ /**
+ * Called when this preference needs to be saved its state.
+ *
+ * @param preference This preference.
+ */
+ public void onRadioButtonClicked(RadioButtonPreference preference);
+ }
+
+ private boolean mIsSelected;
+ private RadioButton mRadioButton;
+ private OnRadioButtonClickedListener mListener;
+ private final View.OnClickListener mClickListener = new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ if (mListener != null) {
+ mListener.onRadioButtonClicked(RadioButtonPreference.this);
+ }
+ }
+ };
+
+ public RadioButtonPreference(final Context context) {
+ this(context, null);
+ }
+
+ public RadioButtonPreference(final Context context, final AttributeSet attrs) {
+ this(context, attrs, android.R.attr.preferenceStyle);
+ }
+
+ public RadioButtonPreference(final Context context, final AttributeSet attrs,
+ final int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ setWidgetLayoutResource(R.layout.radio_button_preference_widget);
+ }
+
+ public void setOnRadioButtonClickedListener(final OnRadioButtonClickedListener listener) {
+ mListener = listener;
+ }
+
+ @Override
+ protected void onBindView(final View view) {
+ super.onBindView(view);
+ mRadioButton = (RadioButton)view.findViewById(R.id.radio_button);
+ mRadioButton.setChecked(mIsSelected);
+ mRadioButton.setOnClickListener(mClickListener);
+ view.setOnClickListener(mClickListener);
+ }
+
+ public boolean isSelected() {
+ return mIsSelected;
+ }
+
+ public void setSelected(final boolean selected) {
+ if (selected == mIsSelected) {
+ return;
+ }
+ mIsSelected = selected;
+ if (mRadioButton != null) {
+ mRadioButton.setChecked(selected);
+ }
+ notifyChanged();
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 0e6a15a7e..0de2d8831 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -19,11 +19,13 @@ package com.android.inputmethod.latin.settings;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
+import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
+import com.android.inputmethod.compat.BuildCompatUtils;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
@@ -40,8 +42,10 @@ import java.util.concurrent.locks.ReentrantLock;
public final class Settings implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = Settings.class.getSimpleName();
// Settings screens
- public static final String SCREEN_INPUT = "screen_input";
- public static final String SCREEN_MULTI_LINGUAL = "screen_multi_lingual";
+ public static final String SCREEN_PREFERENCES = "screen_preferences";
+ public static final String SCREEN_APPEARANCE = "screen_appearance";
+ public static final String SCREEN_THEME = "screen_theme";
+ public static final String SCREEN_MULTILINGUAL = "screen_multilingual";
public static final String SCREEN_GESTURE = "screen_gesture";
public static final String SCREEN_CORRECTION = "screen_correction";
public static final String SCREEN_ADVANCED = "screen_advanced";
@@ -66,10 +70,13 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
"pref_key_use_double_space_period";
public static final String PREF_BLOCK_POTENTIALLY_OFFENSIVE =
"pref_key_block_potentially_offensive";
+ // No multilingual options in Android L and above for now.
+ public static final boolean SHOW_MULTILINGUAL_SETTINGS =
+ BuildCompatUtils.EFFECTIVE_SDK_INT <= Build.VERSION_CODES.KITKAT;
public static final boolean ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS =
- (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
- || (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT
- && Build.VERSION.CODENAME.equals("REL"));
+ BuildCompatUtils.EFFECTIVE_SDK_INT <= Build.VERSION_CODES.KITKAT;
+ public static final boolean HAS_UI_TO_ACCEPT_TYPED_WORD =
+ BuildCompatUtils.EFFECTIVE_SDK_INT >= BuildCompatUtils.VERSION_CODES_LXX;
public static final String PREF_SHOW_LANGUAGE_SWITCH_KEY =
"pref_show_language_switch_key";
public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
@@ -366,6 +373,15 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return prefs.getBoolean(PREF_SHOW_SETUP_WIZARD_ICON, false);
}
+ public static boolean readHasHardwareKeyboard(final Configuration conf) {
+ // The standard way of finding out whether we have a hardware keyboard. This code is taken
+ // from InputMethodService#onEvaluateInputShown, which canonically determines this.
+ // In a nutshell, we have a keyboard if the configuration says the type of hardware keyboard
+ // is NOKEYS and if it's not hidden (e.g. folded inside the device).
+ return conf.keyboard != Configuration.KEYBOARD_NOKEYS
+ && conf.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_YES;
+ }
+
public static boolean isInternal(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_KEY_IS_INTERNAL, false);
}
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsActivity.java b/java/src/com/android/inputmethod/latin/settings/SettingsActivity.java
index c7b9dcdd9..b0c494098 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsActivity.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsActivity.java
@@ -18,11 +18,36 @@ package com.android.inputmethod.latin.settings;
import com.android.inputmethod.latin.utils.FragmentUtils;
+import android.app.ActionBar;
import android.content.Intent;
+import android.os.Bundle;
import android.preference.PreferenceActivity;
+import android.view.MenuItem;
public final class SettingsActivity extends PreferenceActivity {
+ public static final String EXTRA_SHOW_HOME_AS_UP = "show_home_as_up";
private static final String DEFAULT_FRAGMENT = SettingsFragment.class.getName();
+ private boolean mShowHomeAsUp;
+
+ @Override
+ protected void onCreate(final Bundle savedState) {
+ super.onCreate(savedState);
+ final ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ mShowHomeAsUp = getIntent().getBooleanExtra(EXTRA_SHOW_HOME_AS_UP, true);
+ actionBar.setDisplayHomeAsUpEnabled(mShowHomeAsUp);
+ actionBar.setHomeButtonEnabled(mShowHomeAsUp);
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(final MenuItem item) {
+ if (mShowHomeAsUp && item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
@Override
public Intent getIntent() {
@@ -36,7 +61,7 @@ public final class SettingsActivity extends PreferenceActivity {
}
@Override
- public boolean isValidFragment(String fragmentName) {
+ public boolean isValidFragment(final String fragmentName) {
return FragmentUtils.isValidFragment(fragmentName);
}
}
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
index f0bc27972..4fc17387f 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
@@ -16,81 +16,26 @@
package com.android.inputmethod.latin.settings;
-import android.app.Activity;
-import android.app.backup.BackupManager;
-import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.media.AudioManager;
-import android.os.Build;
import android.os.Bundle;
-import android.preference.ListPreference;
import android.preference.Preference;
-import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
-import android.preference.TwoStatePreference;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
-import com.android.inputmethod.dictionarypack.DictionarySettingsActivity;
-import com.android.inputmethod.keyboard.KeyboardTheme;
-import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.define.ProductionFlags;
-import com.android.inputmethod.latin.setup.LauncherIconVisibilityManager;
-import com.android.inputmethod.latin.userdictionary.UserDictionaryList;
-import com.android.inputmethod.latin.userdictionary.UserDictionarySettings;
import com.android.inputmethod.latin.utils.ApplicationUtils;
import com.android.inputmethod.latin.utils.FeedbackUtils;
import com.android.inputmethodcommon.InputMethodSettingsFragment;
-import java.util.TreeSet;
-
-public final class SettingsFragment extends InputMethodSettingsFragment
- implements SharedPreferences.OnSharedPreferenceChangeListener {
- private static final String TAG = SettingsFragment.class.getSimpleName();
- private static final boolean DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS = false;
- private static final boolean USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS =
- DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS
- || Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2;
-
- private static final int NO_MENU_GROUP = Menu.NONE; // We don't care about menu grouping.
- private static final int MENU_FEEDBACK = Menu.FIRST; // The first menu item id and order.
- private static final int MENU_ABOUT = Menu.FIRST + 1; // The second menu item id and order.
-
- private void setPreferenceEnabled(final String preferenceKey, final boolean enabled) {
- final Preference preference = findPreference(preferenceKey);
- if (preference != null) {
- preference.setEnabled(enabled);
- }
- }
-
- private void updateListPreferenceSummaryToCurrentValue(final String prefKey) {
- // Because the "%s" summary trick of {@link ListPreference} doesn't work properly before
- // KitKat, we need to update the summary programmatically.
- final ListPreference listPreference = (ListPreference)findPreference(prefKey);
- if (listPreference == null) {
- return;
- }
- final CharSequence entries[] = listPreference.getEntries();
- final int entryIndex = listPreference.findIndexOfValue(listPreference.getValue());
- listPreference.setSummary(entryIndex < 0 ? null : entries[entryIndex]);
- }
-
- private static void removePreference(final String preferenceKey, final PreferenceGroup parent) {
- if (parent == null) {
- return;
- }
- final Preference preference = parent.findPreference(preferenceKey);
- if (preference != null) {
- parent.removePreference(preference);
- }
- }
+public final class SettingsFragment extends InputMethodSettingsFragment {
+ // We don't care about menu grouping.
+ private static final int NO_MENU_GROUP = Menu.NONE;
+ // The first menu item id and order.
+ private static final int MENU_ABOUT = Menu.FIRST;
+ // The second menu item id and order.
+ private static final int MENU_HELP_AND_FEEDBACK = Menu.FIRST + 1;
@Override
public void onCreate(final Bundle icicle) {
@@ -100,320 +45,19 @@ public final class SettingsFragment extends InputMethodSettingsFragment
setSubtypeEnablerTitle(R.string.select_language);
addPreferencesFromResource(R.xml.prefs);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
- TwoStatePreferenceHelper.replaceCheckBoxPreferencesBySwitchPreferences(preferenceScreen);
preferenceScreen.setTitle(
ApplicationUtils.getActivityTitleResId(getActivity(), SettingsActivity.class));
-
- final Resources res = getResources();
- final Context context = getActivity();
-
- // When we are called from the Settings application but we are not already running, some
- // singleton and utility classes may not have been initialized. We have to call
- // initialization method of these classes here. See {@link LatinIME#onCreate()}.
- AudioAndHapticFeedbackManager.init(context);
-
- final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
- prefs.registerOnSharedPreferenceChangeListener(this);
-
- ensureConsistencyOfAutoCorrectionSettings();
-
- final PreferenceScreen gestureScreen =
- (PreferenceScreen) findPreference(Settings.SCREEN_GESTURE);
- final PreferenceScreen correctionScreen =
- (PreferenceScreen) findPreference(Settings.SCREEN_CORRECTION);
- final PreferenceScreen advancedScreen =
- (PreferenceScreen) findPreference(Settings.SCREEN_ADVANCED);
- final PreferenceScreen debugScreen =
- (PreferenceScreen) findPreference(Settings.SCREEN_DEBUG);
-
- if (!Settings.isInternal(prefs)) {
- advancedScreen.removePreference(debugScreen);
- }
-
- if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
- removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS, advancedScreen);
- }
-
- // TODO: consolidate key preview dismiss delay with the key preview animation parameters.
- if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
- removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, advancedScreen);
- } else {
- // TODO: Cleanup this setup.
- final ListPreference keyPreviewPopupDismissDelay =
- (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
- final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger(
- R.integer.config_key_preview_linger_timeout));
- keyPreviewPopupDismissDelay.setEntries(new String[] {
- res.getString(R.string.key_preview_popup_dismiss_no_delay),
- res.getString(R.string.key_preview_popup_dismiss_default_delay),
- });
- keyPreviewPopupDismissDelay.setEntryValues(new String[] {
- "0",
- popupDismissDelayDefaultValue
- });
- if (null == keyPreviewPopupDismissDelay.getValue()) {
- keyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
- }
- keyPreviewPopupDismissDelay.setEnabled(
- Settings.readKeyPreviewPopupEnabled(prefs, res));
- }
-
- if (!res.getBoolean(R.bool.config_setup_wizard_available)) {
- removePreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON, advancedScreen);
- }
-
- final PreferenceScreen dictionaryLink =
- (PreferenceScreen) findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
- final Intent intent = dictionaryLink.getIntent();
- intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName());
- final int number = context.getPackageManager().queryIntentActivities(intent, 0).size();
- if (0 >= number) {
- correctionScreen.removePreference(dictionaryLink);
- }
-
- if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
- final Preference enableMetricsLogging =
- findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
- if (enableMetricsLogging != null) {
- final int applicationLabelRes = context.getApplicationInfo().labelRes;
- final String applicationName = res.getString(applicationLabelRes);
- final String enableMetricsLoggingTitle = res.getString(
- R.string.enable_metrics_logging, applicationName);
- enableMetricsLogging.setTitle(enableMetricsLoggingTitle);
- }
- } else {
- removePreference(Settings.PREF_ENABLE_METRICS_LOGGING, advancedScreen);
- }
-
- final Preference editPersonalDictionary =
- findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY);
- final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent();
- final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS ? null
- : context.getPackageManager().resolveActivity(
- editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY);
- if (ri == null) {
- overwriteUserDictionaryPreference(editPersonalDictionary);
- }
-
- if (!Settings.readFromBuildConfigIfGestureInputEnabled(res)) {
- getPreferenceScreen().removePreference(gestureScreen);
- }
-
- AdditionalFeaturesSettingUtils.addAdditionalFeaturesPreferences(context, this);
-
- setupKeypressVibrationDurationSettings(prefs, res);
- setupKeypressSoundVolumeSettings(prefs, res);
- refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, res);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
- final Resources res = getResources();
- final TwoStatePreference showSetupWizardIcon =
- (TwoStatePreference)findPreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON);
- if (showSetupWizardIcon != null) {
- showSetupWizardIcon.setChecked(Settings.readShowSetupWizardIcon(prefs, getActivity()));
- }
- updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
- final ListPreference keyboardThemePref = (ListPreference)findPreference(
- Settings.PREF_KEYBOARD_THEME);
- if (keyboardThemePref != null) {
- final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs);
- final String value = Integer.toString(keyboardTheme.mThemeId);
- final CharSequence entries[] = keyboardThemePref.getEntries();
- final int entryIndex = keyboardThemePref.findIndexOfValue(value);
- keyboardThemePref.setSummary(entryIndex < 0 ? null : entries[entryIndex]);
- keyboardThemePref.setValue(value);
- }
- }
-
- @Override
- public void onPause() {
- super.onPause();
- final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
- final ListPreference keyboardThemePref = (ListPreference)findPreference(
- Settings.PREF_KEYBOARD_THEME);
- if (keyboardThemePref != null) {
- KeyboardTheme.saveKeyboardThemeId(keyboardThemePref.getValue(), prefs);
- }
- }
-
- @Override
- public void onDestroy() {
- getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
- this);
- super.onDestroy();
- }
-
- @Override
- public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
- final Activity activity = getActivity();
- if (activity == null) {
- // TODO: Introduce a static function to register this class and ensure that
- // onCreate must be called before "onSharedPreferenceChanged" is called.
- Log.w(TAG, "onSharedPreferenceChanged called before activity starts.");
- return;
- }
- (new BackupManager(activity)).dataChanged();
- final Resources res = getResources();
- if (key.equals(Settings.PREF_POPUP_ON)) {
- setPreferenceEnabled(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,
- Settings.readKeyPreviewPopupEnabled(prefs, res));
- } else if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
- LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
- }
- ensureConsistencyOfAutoCorrectionSettings();
- updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
- updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_THEME);
- refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
- }
-
- private void ensureConsistencyOfAutoCorrectionSettings() {
- final String autoCorrectionOff = getResources().getString(
- R.string.auto_correction_threshold_mode_index_off);
- final ListPreference autoCorrectionThresholdPref = (ListPreference)findPreference(
- Settings.PREF_AUTO_CORRECTION_THRESHOLD);
- final String currentSetting = autoCorrectionThresholdPref.getValue();
- setPreferenceEnabled(
- Settings.PREF_BIGRAM_PREDICTIONS, !currentSetting.equals(autoCorrectionOff));
- }
-
- private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
- final SharedPreferences sp, final Resources res) {
- setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,
- Settings.readVibrationEnabled(sp, res));
- setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME,
- Settings.readKeypressSoundEnabled(sp, res));
- }
-
- private void setupKeypressVibrationDurationSettings(final SharedPreferences sp,
- final Resources res) {
- final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
- Settings.PREF_VIBRATION_DURATION_SETTINGS);
- if (pref == null) {
- return;
- }
- pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
- @Override
- public void writeValue(final int value, final String key) {
- sp.edit().putInt(key, value).apply();
- }
-
- @Override
- public void writeDefaultValue(final String key) {
- sp.edit().remove(key).apply();
- }
-
- @Override
- public int readValue(final String key) {
- return Settings.readKeypressVibrationDuration(sp, res);
- }
-
- @Override
- public int readDefaultValue(final String key) {
- return Settings.readDefaultKeypressVibrationDuration(res);
- }
-
- @Override
- public void feedbackValue(final int value) {
- AudioAndHapticFeedbackManager.getInstance().vibrate(value);
- }
-
- @Override
- public String getValueText(final int value) {
- if (value < 0) {
- return res.getString(R.string.settings_system_default);
- }
- return res.getString(R.string.abbreviation_unit_milliseconds, value);
- }
- });
- }
-
- private void setupKeypressSoundVolumeSettings(final SharedPreferences sp, final Resources res) {
- final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
- Settings.PREF_KEYPRESS_SOUND_VOLUME);
- if (pref == null) {
- return;
- }
- final AudioManager am = (AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
- pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
- private static final float PERCENTAGE_FLOAT = 100.0f;
-
- private float getValueFromPercentage(final int percentage) {
- return percentage / PERCENTAGE_FLOAT;
- }
-
- private int getPercentageFromValue(final float floatValue) {
- return (int)(floatValue * PERCENTAGE_FLOAT);
- }
-
- @Override
- public void writeValue(final int value, final String key) {
- sp.edit().putFloat(key, getValueFromPercentage(value)).apply();
- }
-
- @Override
- public void writeDefaultValue(final String key) {
- sp.edit().remove(key).apply();
- }
-
- @Override
- public int readValue(final String key) {
- return getPercentageFromValue(Settings.readKeypressSoundVolume(sp, res));
- }
-
- @Override
- public int readDefaultValue(final String key) {
- return getPercentageFromValue(Settings.readDefaultKeypressSoundVolume(res));
- }
-
- @Override
- public String getValueText(final int value) {
- if (value < 0) {
- return res.getString(R.string.settings_system_default);
- }
- return Integer.toString(value);
- }
-
- @Override
- public void feedbackValue(final int value) {
- am.playSoundEffect(
- AudioManager.FX_KEYPRESS_STANDARD, getValueFromPercentage(value));
- }
- });
- }
-
- private void overwriteUserDictionaryPreference(Preference userDictionaryPreference) {
- final Activity activity = getActivity();
- final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
- if (null == localeList) {
- // The locale list is null if and only if the user dictionary service is
- // not present or disabled. In this case we need to remove the preference.
- getPreferenceScreen().removePreference(userDictionaryPreference);
- } else if (localeList.size() <= 1) {
- userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
- // If the size of localeList is 0, we don't set the locale parameter in the
- // extras. This will be interpreted by the UserDictionarySettings class as
- // meaning "the current locale".
- // Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
- // the locale list always has at least one element, since it always includes the current
- // locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
- if (localeList.size() == 1) {
- final String locale = (String)localeList.toArray()[0];
- userDictionaryPreference.getExtras().putString("locale", locale);
- }
- } else {
- userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
+ if (!Settings.SHOW_MULTILINGUAL_SETTINGS) {
+ final Preference multilingualOptions = findPreference(Settings.SCREEN_MULTILINGUAL);
+ preferenceScreen.removePreference(multilingualOptions);
}
}
@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
- if (FeedbackUtils.isFeedbackFormSupported()) {
- menu.add(NO_MENU_GROUP, MENU_FEEDBACK /* itemId */, MENU_FEEDBACK /* order */,
- R.string.send_feedback);
+ if (FeedbackUtils.isHelpAndFeedbackFormSupported()) {
+ menu.add(NO_MENU_GROUP, MENU_HELP_AND_FEEDBACK /* itemId */,
+ MENU_HELP_AND_FEEDBACK /* order */, R.string.help_and_feedback);
}
final int aboutResId = FeedbackUtils.getAboutKeyboardTitleResId();
if (aboutResId != 0) {
@@ -424,8 +68,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
- if (itemId == MENU_FEEDBACK) {
- FeedbackUtils.showFeedbackForm(getActivity());
+ if (itemId == MENU_HELP_AND_FEEDBACK) {
+ FeedbackUtils.showHelpAndFeedbackForm(getActivity());
return true;
}
if (itemId == MENU_ABOUT) {
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 39e834f84..d8c548d8b 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -50,9 +50,12 @@ public final class SettingsValues {
// From resources:
public final SpacingAndPunctuations mSpacingAndPunctuations;
- public final int mDelayUpdateOldSuggestions;
+ public final int mDelayInMillisecondsToUpdateOldSuggestions;
public final long mDoubleSpacePeriodTimeout;
-
+ // From configuration:
+ public final Locale mLocale;
+ public final boolean mHasHardwareKeyboard;
+ public final int mDisplayOrientation;
// From preferences, in the same order as xml/prefs.xml:
public final boolean mAutoCap;
public final boolean mVibrateOn;
@@ -73,8 +76,8 @@ public final class SettingsValues {
public final boolean mSlidingKeyInputPreviewEnabled;
public final boolean mPhraseGestureEnabled;
public final int mKeyLongpressTimeout;
- public final Locale mLocale;
public final boolean mEnableMetricsLogging;
+ public final boolean mShouldShowUiToAcceptTypedWord;
// From the input box
public final InputAttributes mInputAttributes;
@@ -87,25 +90,31 @@ public final class SettingsValues {
public final float mAutoCorrectionThreshold;
public final boolean mAutoCorrectionEnabledPerUserSettings;
private final boolean mSuggestionsEnabledPerUserSettings;
- public final int mDisplayOrientation;
private final AsyncResultHolder<AppWorkaroundsUtils> mAppWorkarounds;
// Setting values for additional features
public final int[] mAdditionalFeaturesSettingValues =
new int[AdditionalFeaturesSettingUtils.ADDITIONAL_FEATURES_SETTINGS_SIZE];
+ // TextDecorator
+ public final int mTextHighlightColorForAddToDictionaryIndicator;
+
// Debug settings
public final boolean mIsInternal;
+ public final boolean mHasCustomKeyPreviewAnimationParams;
public final int mKeyPreviewShowUpDuration;
public final int mKeyPreviewDismissDuration;
- public final float mKeyPreviewShowUpStartScale;
- public final float mKeyPreviewDismissEndScale;
+ public final float mKeyPreviewShowUpStartXScale;
+ public final float mKeyPreviewShowUpStartYScale;
+ public final float mKeyPreviewDismissEndXScale;
+ public final float mKeyPreviewDismissEndYScale;
public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
final InputAttributes inputAttributes) {
mLocale = res.getConfiguration().locale;
// Get the resources
- mDelayUpdateOldSuggestions = res.getInteger(R.integer.config_delay_update_old_suggestions);
+ mDelayInMillisecondsToUpdateOldSuggestions =
+ res.getInteger(R.integer.config_delay_in_milliseconds_to_update_old_suggestions);
mSpacingAndPunctuations = new SpacingAndPunctuations(res);
// Store the input attributes
@@ -136,12 +145,16 @@ public final class SettingsValues {
? Settings.readShowsLanguageSwitchKey(prefs) : true /* forcibly */;
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true);
- mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true);
+ mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true)
+ && inputAttributes.mIsGeneralTextInput;
mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res);
mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res);
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);
mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout);
+ mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true);
+ mShouldShowUiToAcceptTypedWord = Settings.HAS_UI_TO_ACCEPT_TYPED_WORD
+ && prefs.getBoolean(DebugSettings.PREF_SHOW_UI_TO_ACCEPT_TYPED_WORD, true);
// Compute other readable settings
mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res);
mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res);
@@ -159,21 +172,33 @@ public final class SettingsValues {
mSuggestionsEnabledPerUserSettings = readSuggestionsEnabled(prefs);
AdditionalFeaturesSettingUtils.readAdditionalFeaturesPreferencesIntoArray(
prefs, mAdditionalFeaturesSettingValues);
+ mTextHighlightColorForAddToDictionaryIndicator = res.getColor(
+ R.color.text_decorator_add_to_dictionary_indicator_text_highlight_color);
mIsInternal = Settings.isInternal(prefs);
+ mHasCustomKeyPreviewAnimationParams = prefs.getBoolean(
+ DebugSettings.PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS, false);
mKeyPreviewShowUpDuration = Settings.readKeyPreviewAnimationDuration(
prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION,
res.getInteger(R.integer.config_key_preview_show_up_duration));
mKeyPreviewDismissDuration = Settings.readKeyPreviewAnimationDuration(
prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION,
res.getInteger(R.integer.config_key_preview_dismiss_duration));
- mKeyPreviewShowUpStartScale = Settings.readKeyPreviewAnimationScale(
- prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_SCALE,
- ResourceUtils.getFloatFromFraction(
- res, R.fraction.config_key_preview_show_up_start_scale));
- mKeyPreviewDismissEndScale = Settings.readKeyPreviewAnimationScale(
- prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_SCALE,
- ResourceUtils.getFloatFromFraction(
- res, R.fraction.config_key_preview_dismiss_end_scale));
+ final float defaultKeyPreviewShowUpStartScale = ResourceUtils.getFloatFromFraction(
+ res, R.fraction.config_key_preview_show_up_start_scale);
+ final float defaultKeyPreviewDismissEndScale = ResourceUtils.getFloatFromFraction(
+ res, R.fraction.config_key_preview_dismiss_end_scale);
+ mKeyPreviewShowUpStartXScale = Settings.readKeyPreviewAnimationScale(
+ prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE,
+ defaultKeyPreviewShowUpStartScale);
+ mKeyPreviewShowUpStartYScale = Settings.readKeyPreviewAnimationScale(
+ prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_Y_SCALE,
+ defaultKeyPreviewShowUpStartScale);
+ mKeyPreviewDismissEndXScale = Settings.readKeyPreviewAnimationScale(
+ prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_X_SCALE,
+ defaultKeyPreviewDismissEndScale);
+ mKeyPreviewDismissEndYScale = Settings.readKeyPreviewAnimationScale(
+ prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE,
+ defaultKeyPreviewDismissEndScale);
mDisplayOrientation = res.getConfiguration().orientation;
mAppWorkarounds = new AsyncResultHolder<>();
final PackageInfo packageInfo = TargetPackageInfoGetterTask.getCachedPackageInfo(
@@ -329,8 +354,8 @@ public final class SettingsValues {
final StringBuilder sb = new StringBuilder("Current settings :");
sb.append("\n mSpacingAndPunctuations = ");
sb.append("" + mSpacingAndPunctuations.dump());
- sb.append("\n mDelayUpdateOldSuggestions = ");
- sb.append("" + mDelayUpdateOldSuggestions);
+ sb.append("\n mDelayInMillisecondsToUpdateOldSuggestions = ");
+ sb.append("" + mDelayInMillisecondsToUpdateOldSuggestions);
sb.append("\n mAutoCap = ");
sb.append("" + mAutoCap);
sb.append("\n mVibrateOn = ");
@@ -392,16 +417,22 @@ public final class SettingsValues {
sb.append("" + (null == awu ? "null" : awu.toString()));
sb.append("\n mAdditionalFeaturesSettingValues = ");
sb.append("" + Arrays.toString(mAdditionalFeaturesSettingValues));
+ sb.append("\n mTextHighlightColorForAddToDictionaryIndicator = ");
+ sb.append("" + mTextHighlightColorForAddToDictionaryIndicator);
sb.append("\n mIsInternal = ");
sb.append("" + mIsInternal);
sb.append("\n mKeyPreviewShowUpDuration = ");
sb.append("" + mKeyPreviewShowUpDuration);
sb.append("\n mKeyPreviewDismissDuration = ");
sb.append("" + mKeyPreviewDismissDuration);
- sb.append("\n mKeyPreviewShowUpStartScale = ");
- sb.append("" + mKeyPreviewShowUpStartScale);
- sb.append("\n mKeyPreviewDismissEndScale = ");
- sb.append("" + mKeyPreviewDismissEndScale);
+ sb.append("\n mKeyPreviewShowUpStartScaleX = ");
+ sb.append("" + mKeyPreviewShowUpStartXScale);
+ sb.append("\n mKeyPreviewShowUpStartScaleY = ");
+ sb.append("" + mKeyPreviewShowUpStartYScale);
+ sb.append("\n mKeyPreviewDismissEndScaleX = ");
+ sb.append("" + mKeyPreviewDismissEndXScale);
+ sb.append("\n mKeyPreviewDismissEndScaleY = ");
+ sb.append("" + mKeyPreviewDismissEndYScale);
return sb.toString();
}
}
diff --git a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
index b8d2a2248..49d81104d 100644
--- a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
+++ b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin.settings;
import android.content.res.Resources;
+import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.PunctuationSuggestions;
@@ -68,6 +69,22 @@ public final class SpacingAndPunctuations {
mSuggestPuncList = PunctuationSuggestions.newPunctuationSuggestions(suggestPuncsSpec);
}
+ @UsedForTesting
+ public SpacingAndPunctuations(final SpacingAndPunctuations model,
+ final int[] overrideSortedWordSeparators) {
+ mSortedSymbolsPrecededBySpace = model.mSortedSymbolsPrecededBySpace;
+ mSortedSymbolsFollowedBySpace = model.mSortedSymbolsFollowedBySpace;
+ mSortedSymbolsClusteringTogether = model.mSortedSymbolsClusteringTogether;
+ mSortedWordConnectors = model.mSortedWordConnectors;
+ mSortedWordSeparators = overrideSortedWordSeparators;
+ mSuggestPuncList = model.mSuggestPuncList;
+ mSentenceSeparator = model.mSentenceSeparator;
+ mSentenceSeparatorAndSpace = model.mSentenceSeparatorAndSpace;
+ mCurrentLanguageHasSpaces = model.mCurrentLanguageHasSpaces;
+ mUsesAmericanTypography = model.mUsesAmericanTypography;
+ mUsesGermanRules = model.mUsesGermanRules;
+ }
+
public boolean isWordSeparator(final int code) {
return Arrays.binarySearch(mSortedWordSeparators, code) >= 0;
}
diff --git a/java/src/com/android/inputmethod/latin/settings/SubScreenFragment.java b/java/src/com/android/inputmethod/latin/settings/SubScreenFragment.java
index c70bf2997..ca5b395ce 100644
--- a/java/src/com/android/inputmethod/latin/settings/SubScreenFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/SubScreenFragment.java
@@ -115,4 +115,9 @@ abstract class SubScreenFragment extends PreferenceFragment
mSharedPreferenceChangeListener);
super.onDestroy();
}
+
+ @Override
+ public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
+ // This method may be overridden by an extended class.
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/settings/ThemeSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/ThemeSettingsFragment.java
new file mode 100644
index 000000000..5a3fc3600
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/settings/ThemeSettingsFragment.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.settings;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+
+import com.android.inputmethod.keyboard.KeyboardTheme;
+import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.settings.RadioButtonPreference.OnRadioButtonClickedListener;
+
+/**
+ * "Keyboard theme" settings sub screen.
+ */
+public final class ThemeSettingsFragment extends SubScreenFragment
+ implements OnRadioButtonClickedListener {
+ private String mSelectedThemeId;
+
+ static class KeyboardThemePreference extends RadioButtonPreference {
+ final String mThemeId;
+
+ KeyboardThemePreference(final Context context, final String name, final String id) {
+ super(context);
+ setTitle(name);
+ mThemeId = id;
+ }
+ }
+
+ static void updateKeyboardThemeSummary(final Preference pref) {
+ final Resources res = pref.getContext().getResources();
+ final SharedPreferences prefs = pref.getSharedPreferences();
+ final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs);
+ final String keyboardThemeId = String.valueOf(keyboardTheme.mThemeId);
+ final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
+ final String[] keyboardThemeIds = res.getStringArray(R.array.keyboard_theme_ids);
+ for (int index = 0; index < keyboardThemeNames.length; index++) {
+ if (keyboardThemeId.equals(keyboardThemeIds[index])) {
+ pref.setSummary(keyboardThemeNames[index]);
+ return;
+ }
+ }
+ }
+
+ @Override
+ public void onCreate(final Bundle icicle) {
+ super.onCreate(icicle);
+ addPreferencesFromResource(R.xml.prefs_screen_theme);
+ final PreferenceScreen screen = getPreferenceScreen();
+ final Resources res = getResources();
+ final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
+ final String[] keyboardThemeIds = res.getStringArray(R.array.keyboard_theme_ids);
+ for (int index = 0; index < keyboardThemeNames.length; index++) {
+ final KeyboardThemePreference pref = new KeyboardThemePreference(
+ getActivity(), keyboardThemeNames[index], keyboardThemeIds[index]);
+ screen.addPreference(pref);
+ pref.setOnRadioButtonClickedListener(this);
+ }
+ final SharedPreferences prefs = getSharedPreferences();
+ final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs);
+ mSelectedThemeId = String.valueOf(keyboardTheme.mThemeId);
+ }
+
+ @Override
+ public void onRadioButtonClicked(final RadioButtonPreference preference) {
+ if (preference instanceof KeyboardThemePreference) {
+ final KeyboardThemePreference pref = (KeyboardThemePreference)preference;
+ mSelectedThemeId = pref.mThemeId;
+ updateSelected();
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ updateSelected();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ KeyboardTheme.saveKeyboardThemeId(mSelectedThemeId, getSharedPreferences());
+ }
+
+ private void updateSelected() {
+ final PreferenceScreen screen = getPreferenceScreen();
+ final int count = screen.getPreferenceCount();
+ for (int index = 0; index < count; index++) {
+ final Preference preference = screen.getPreference(index);
+ if (preference instanceof KeyboardThemePreference) {
+ final KeyboardThemePreference pref = (KeyboardThemePreference)preference;
+ final boolean selected = mSelectedThemeId.equals(pref.mThemeId);
+ pref.setSelected(selected);
+ }
+ }
+ }
+}