aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java10
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsFragment.java53
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeLocale.java81
3 files changed, 92 insertions, 52 deletions
diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
index a56c78bcd..f7877226d 100644
--- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
+++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
@@ -72,7 +72,8 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
}
public SubtypeLocaleItem(final String localeString) {
- this(localeString, SubtypeLocale.getSubtypeLocaleDisplayName(localeString));
+ this(localeString,
+ SubtypeLocale.getSubtypeLocaleDisplayNameInSystemLocale(localeString));
}
@Override
@@ -103,7 +104,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
if (DEBUG_SUBTYPE_ID) {
android.util.Log.d(TAG, String.format("%-6s 0x%08x %11d %s",
subtype.getLocale(), subtype.hashCode(), subtype.hashCode(),
- SubtypeLocale.getSubtypeDisplayName(subtype)));
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(subtype)));
}
if (subtype.containsExtraValueKey(ASCII_CAPABLE)) {
items.add(createItem(context, subtype.getLocale()));
@@ -205,7 +206,8 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
setDialogTitle(R.string.add_style);
setKey(KEY_NEW_SUBTYPE);
} else {
- final String displayName = SubtypeLocale.getSubtypeDisplayName(subtype);
+ final String displayName =
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(subtype);
setTitle(displayName);
setDialogTitle(displayName);
setKey(KEY_PREFIX + subtype.getLocale() + "_"
@@ -497,7 +499,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
final Context context = getActivity();
final Resources res = context.getResources();
final String message = res.getString(R.string.custom_input_style_already_exists,
- SubtypeLocale.getSubtypeDisplayName(subtype));
+ SubtypeLocale.getSubtypeDisplayNameInSystemLocale(subtype));
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java
index 3ba24fb65..f0c51e194 100644
--- a/java/src/com/android/inputmethod/latin/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java
@@ -41,7 +41,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
private ListPreference mKeyPreviewPopupDismissDelay;
// Use bigrams to predict the next word when there is no input for it yet
private CheckBoxPreference mBigramPrediction;
- private Preference mDebugSettingsPreference;
private void setPreferenceEnabled(final String preferenceKey, final boolean enabled) {
final Preference preference = findPreference(preferenceKey);
@@ -50,11 +49,14 @@ public final class SettingsFragment extends InputMethodSettingsFragment
}
}
- private void ensureConsistencyOfAutoCorrectionSettings() {
- final String autoCorrectionOff = getResources().getString(
- R.string.auto_correction_threshold_mode_index_off);
- final String currentSetting = mAutoCorrectionThresholdPreference.getValue();
- mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff));
+ 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);
+ }
}
@Override
@@ -84,22 +86,18 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final PreferenceGroup generalSettings =
(PreferenceGroup) findPreference(Settings.PREF_GENERAL_SETTINGS);
- final PreferenceGroup textCorrectionGroup =
- (PreferenceGroup) findPreference(Settings.PREF_CORRECTION_SETTINGS);
- final PreferenceGroup gestureTypingSettings =
- (PreferenceGroup) findPreference(Settings.PREF_GESTURE_SETTINGS);
final PreferenceGroup miscSettings =
(PreferenceGroup) findPreference(Settings.PREF_MISC_SETTINGS);
- mDebugSettingsPreference = findPreference(Settings.PREF_DEBUG_SETTINGS);
- if (mDebugSettingsPreference != null) {
+ final Preference debugSettings = findPreference(Settings.PREF_DEBUG_SETTINGS);
+ if (debugSettings != null) {
if (ProductionFlag.IS_INTERNAL) {
final Intent debugSettingsIntent = new Intent(Intent.ACTION_MAIN);
debugSettingsIntent.setClassName(
context.getPackageName(), DebugSettingsActivity.class.getName());
- mDebugSettingsPreference.setIntent(debugSettingsIntent);
+ debugSettings.setIntent(debugSettingsIntent);
} else {
- miscSettings.removePreference(mDebugSettingsPreference);
+ miscSettings.removePreference(debugSettings);
}
}
@@ -112,11 +110,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final PreferenceGroup advancedSettings =
(PreferenceGroup) findPreference(Settings.PREF_ADVANCED_SETTINGS);
if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
- generalSettings.removePreference(findPreference(Settings.PREF_VIBRATE_ON));
- if (null != advancedSettings) { // Theoretically advancedSettings cannot be null
- advancedSettings.removePreference(
- findPreference(Settings.PREF_VIBRATION_DURATION_SETTINGS));
- }
+ removePreference(Settings.PREF_VIBRATE_ON, generalSettings);
+ removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS, advancedSettings);
}
final boolean showKeyPreviewPopupOption = res.getBoolean(
@@ -124,10 +119,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
mKeyPreviewPopupDismissDelay =
(ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
if (!showKeyPreviewPopupOption) {
- generalSettings.removePreference(findPreference(Settings.PREF_POPUP_ON));
- if (null != advancedSettings) { // Theoretically advancedSettings cannot be null
- advancedSettings.removePreference(mKeyPreviewPopupDismissDelay);
- }
+ removePreference(Settings.PREF_POPUP_ON, generalSettings);
+ removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, advancedSettings);
} else {
final String[] entries = new String[] {
res.getString(R.string.key_preview_popup_dismiss_no_delay),
@@ -148,10 +141,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
setPreferenceEnabled(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST,
Settings.readShowsLanguageSwitchKey(prefs));
+ final PreferenceGroup textCorrectionGroup =
+ (PreferenceGroup) findPreference(Settings.PREF_CORRECTION_SETTINGS);
final PreferenceScreen dictionaryLink =
(PreferenceScreen) findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
final Intent intent = dictionaryLink.getIntent();
-
final int number = context.getPackageManager().queryIntentActivities(intent, 0).size();
// TODO: The experimental version is not supported by the Dictionary Pack Service yet
if (ProductionFlag.IS_EXPERIMENTAL || 0 >= number) {
@@ -161,7 +155,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final boolean gestureInputEnabledByBuildConfig = res.getBoolean(
R.bool.config_gesture_input_enabled_by_build_config);
if (!gestureInputEnabledByBuildConfig) {
- getPreferenceScreen().removePreference(gestureTypingSettings);
+ removePreference(Settings.PREF_GESTURE_SETTINGS, getPreferenceScreen());
}
setupKeyLongpressTimeoutSettings(prefs, res);
@@ -219,6 +213,13 @@ public final class SettingsFragment extends InputMethodSettingsFragment
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
}
+ private void ensureConsistencyOfAutoCorrectionSettings() {
+ final String autoCorrectionOff = getResources().getString(
+ R.string.auto_correction_threshold_mode_index_off);
+ final String currentSetting = mAutoCorrectionThresholdPreference.getValue();
+ mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff));
+ }
+
private void updateShowCorrectionSuggestionsSummary() {
mShowCorrectionSuggestionsPreference.setSummary(
getResources().getStringArray(R.array.prefs_suggestion_visibilities)
@@ -237,7 +238,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final StringBuilder styles = new StringBuilder();
for (final InputMethodSubtype subtype : subtypes) {
if (styles.length() > 0) styles.append(", ");
- styles.append(SubtypeLocale.getSubtypeDisplayName(subtype));
+ styles.append(SubtypeLocale.getSubtypeDisplayNameInSystemLocale(subtype));
}
customInputStyles.setSummary(styles);
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
index 068c34ed6..2f26f9296 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
@@ -51,20 +51,22 @@ public final class SubtypeLocale {
private static final HashMap<String, Integer> sKeyboardLayoutToNameIdsMap =
CollectionUtils.newHashMap();
// Exceptional locale to subtype name resource id map.
+ private static final HashMap<String, Integer> sExceptionalLocaleToNameIdsMap =
+ CollectionUtils.newHashMap();
+ // Exceptional locale to subtype name with layout resource id map.
private static final HashMap<String, Integer> sExceptionalLocaleToWithLayoutNameIdsMap =
CollectionUtils.newHashMap();
+ private static final String SUBTYPE_NAME_RESOURCE_PREFIX =
+ "string/subtype_";
private static final String SUBTYPE_NAME_RESOURCE_GENERIC_PREFIX =
"string/subtype_generic_";
private static final String SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX =
"string/subtype_with_layout_";
private static final String SUBTYPE_NAME_RESOURCE_NO_LANGUAGE_PREFIX =
"string/subtype_no_language_";
- // Exceptional locales to display name map.
- private static final HashMap<String, String> sExceptionalDisplayNamesMap =
- CollectionUtils.newHashMap();
// Keyboard layout set name for the subtypes that don't have a keyboardLayoutSet extra value.
// This is for compatibility to keep the same subtype ids as pre-JellyBean.
- private static final HashMap<String,String> sLocaleAndExtraValueToKeyboardLayoutSetMap =
+ private static final HashMap<String, String> sLocaleAndExtraValueToKeyboardLayoutSetMap =
CollectionUtils.newHashMap();
private SubtypeLocale() {
@@ -98,14 +100,16 @@ public final class SubtypeLocale {
final String[] exceptionalLocales = res.getStringArray(
R.array.subtype_locale_exception_keys);
- final String[] exceptionalDisplayNames = res.getStringArray(
- R.array.subtype_locale_exception_values);
for (int i = 0; i < exceptionalLocales.length; i++) {
final String localeString = exceptionalLocales[i];
- sExceptionalDisplayNamesMap.put(localeString, exceptionalDisplayNames[i]);
- final String resourceName = SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX + localeString;
+ final String resourceName = SUBTYPE_NAME_RESOURCE_PREFIX + localeString;
final int resId = res.getIdentifier(resourceName, null, RESOURCE_PACKAGE_NAME);
- sExceptionalLocaleToWithLayoutNameIdsMap.put(localeString, resId);
+ sExceptionalLocaleToNameIdsMap.put(localeString, resId);
+ final String resourceNameWithLayout =
+ SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX + localeString;
+ final int resIdWithLayout = res.getIdentifier(
+ resourceNameWithLayout, null, RESOURCE_PACKAGE_NAME);
+ sExceptionalLocaleToWithLayoutNameIdsMap.put(localeString, resIdWithLayout);
}
final String[] keyboardLayoutSetMap = res.getStringArray(
@@ -124,7 +128,7 @@ public final class SubtypeLocale {
}
public static boolean isExceptionalLocale(final String localeString) {
- return sExceptionalLocaleToWithLayoutNameIdsMap.containsKey(localeString);
+ return sExceptionalLocaleToNameIdsMap.containsKey(localeString);
}
private static final String getNoLanguageLayoutKey(final String keyboardLayoutName) {
@@ -143,13 +147,33 @@ public final class SubtypeLocale {
return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId;
}
+ public static String getSubtypeLocaleDisplayNameInSystemLocale(final String localeString) {
+ final Locale displayLocale = sResources.getConfiguration().locale;
+ return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale);
+ }
+
public static String getSubtypeLocaleDisplayName(final String localeString) {
- final String exceptionalValue = sExceptionalDisplayNamesMap.get(localeString);
- if (exceptionalValue != null) {
- return exceptionalValue;
- }
+ final Locale displayLocale = LocaleUtils.constructLocaleFromString(localeString);
+ return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale);
+ }
+
+ private static String getSubtypeLocaleDisplayNameInternal(final String localeString,
+ final Locale displayLocale) {
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
- return StringUtils.toTitleCase(locale.getDisplayName(locale), locale);
+ final Integer exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString);
+ final String displayName;
+ if (exceptionalNameResId != null) {
+ final RunInLocale<String> getExceptionalName = new RunInLocale<String>() {
+ @Override
+ protected String job(final Resources res) {
+ return res.getString(exceptionalNameResId);
+ }
+ };
+ displayName = getExceptionalName.runInLocale(sResources, displayLocale);
+ } else {
+ displayName = locale.getDisplayName(displayLocale);
+ }
+ return StringUtils.toTitleCase(displayName, displayLocale);
}
// InputMethodSubtype's display name in its locale.
@@ -165,24 +189,36 @@ public final class SubtypeLocale {
// zz qwerty F No language (QWERTY) in system locale
// fr qwertz T Français (QWERTZ)
// de qwerty T Deutsch (QWERTY)
- // en_US azerty T English (US) (AZERTY)
+ // en_US azerty T English (US) (AZERTY) exception
// zz azerty T No language (AZERTY) in system locale
- private static String getReplacementString(final InputMethodSubtype subtype) {
+ private static String getReplacementString(final InputMethodSubtype subtype,
+ final Locale displayLocale) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
&& subtype.containsExtraValueKey(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)) {
return subtype.getExtraValueOf(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME);
} else {
- return getSubtypeLocaleDisplayName(subtype.getLocale());
+ return getSubtypeLocaleDisplayNameInternal(subtype.getLocale(), displayLocale);
}
}
+ public static String getSubtypeDisplayNameInSystemLocale(final InputMethodSubtype subtype) {
+ final Locale subtypeLocale = sResources.getConfiguration().locale;
+ return getSubtypeDisplayNameInternal(subtype, subtypeLocale);
+ }
+
public static String getSubtypeDisplayName(final InputMethodSubtype subtype) {
- final String replacementString = getReplacementString(subtype);
+ final Locale subtypeLocale = LocaleUtils.constructLocaleFromString(subtype.getLocale());
+ return getSubtypeDisplayNameInternal(subtype, subtypeLocale);
+ }
+
+ private static String getSubtypeDisplayNameInternal(final InputMethodSubtype subtype,
+ final Locale displayLocale) {
+ final String replacementString = getReplacementString(subtype, displayLocale);
final int nameResId = subtype.getNameResId();
final RunInLocale<String> getSubtypeName = new RunInLocale<String>() {
@Override
- protected String job(Resources res) {
+ protected String job(final Resources res) {
try {
return res.getString(nameResId, replacementString);
} catch (Resources.NotFoundException e) {
@@ -197,8 +233,9 @@ public final class SubtypeLocale {
}
};
final Locale locale = isNoLanguage(subtype)
- ? sResources.getConfiguration().locale : getSubtypeLocale(subtype);
- return getSubtypeName.runInLocale(sResources, locale);
+ ? sResources.getConfiguration().locale : displayLocale;
+ return StringUtils.toTitleCase(
+ getSubtypeName.runInLocale(sResources, locale), locale);
}
public static boolean isNoLanguage(final InputMethodSubtype subtype) {