aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2012-04-25 14:17:49 +0900
committerTadashi G. Takaoka <takaoka@google.com>2012-04-26 11:50:28 +0900
commit27b42ced86e1c85de3d59d91a9e5c577fa552569 (patch)
tree320d2e6c6429eded514f9c1c75f422d53c47ecee /java
parent49caddbdabe5ca666bdef9f842f134e30e7ffed9 (diff)
downloadlatinime-27b42ced86e1c85de3d59d91a9e5c577fa552569.tar.gz
latinime-27b42ced86e1c85de3d59d91a9e5c577fa552569.tar.xz
latinime-27b42ced86e1c85de3d59d91a9e5c577fa552569.zip
Fix "no language" subtype name (DO NOT MERGE)
* Move SubtypeLocale.get{Full,Middle,Short}DisplayName() to LatinLeyboardView and add unit tests (SpacebarTextTests). * Add SubtypeLocale.getSubtypeDisplayName() This is a cherry-pick of I57420c6a from Master. Bug: 6393865 Change-Id: I68748189c17c73984ac4ae05a5a40fb54bf46453
Diffstat (limited to 'java')
-rw-r--r--java/res/values/donottranslate.xml4
-rw-r--r--java/res/values/strings.xml10
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java51
-rw-r--r--java/src/com/android/inputmethod/latin/AdditionalSubtype.java3
-rw-r--r--java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java11
-rw-r--r--java/src/com/android/inputmethod/latin/LocaleUtils.java4
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java5
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeLocale.java93
8 files changed, 111 insertions, 70 deletions
diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml
index 0be886015..4fe447e20 100644
--- a/java/res/values/donottranslate.xml
+++ b/java/res/values/donottranslate.xml
@@ -166,7 +166,9 @@
<item>PC</item>
</string-array>
<!-- Description for generic subtype that has predefined layout.
- The string resource name must be "subtype_generic_<layout name>". -->
+ The string resource name must be "subtype_generic_<layout name>".
+ The string resource with "No language" also must be added to strings.xml and the resource
+ name must be "subtype_no_language_<layout name>" -->
<string name="subtype_generic_qwerty">%s (QWERTY)</string>
<string name="subtype_generic_qwertz">%s (QWERTZ)</string>
<string name="subtype_generic_azerty">%s (AZERTY)</string>
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
index 93bd26867..0d6eaee09 100644
--- a/java/res/values/strings.xml
+++ b/java/res/values/strings.xml
@@ -256,6 +256,16 @@
<string name="subtype_no_language">No language</string>
<!-- Description for language agnostic QWERTY keyboard subtype [CHAR LIMIT=22] -->
<string name="subtype_no_language_qwerty">No language (QWERTY)</string>
+ <!-- Description for language agnostic QWERTZ keyboard subtype [CHAR LIMIT=22] -->
+ <string name="subtype_no_language_qwertz">No language (QWERTZ)</string>
+ <!-- Description for language agnostic AZERTY keyboard subtype [CHAR LIMIT=22] -->
+ <string name="subtype_no_language_azerty">No language (AZERTY)</string>
+ <!-- Description for language agnostic Dvorak keyboard subtype [CHAR LIMIT=22] -->
+ <string name="subtype_no_language_dvorak">No language (Dvorak)</string>
+ <!-- Description for language agnostic Colemak keyboard subtype [CHAR LIMIT=22] -->
+ <string name="subtype_no_language_colemak">No language (Colemak)</string>
+ <!-- Description for language agnostic PC QWERTY keyboard subtype [CHAR LIMIT=22] -->
+ <string name="subtype_no_language_pcqwerty">No language (PC)</string>
<!-- Title of the preference settings for custom input styles (language and keyboard layout pairs) [CHAR LIMIT=22]-->
<string name="custom_input_styles_title">Custom input styles</string>
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index d50d096c6..9aaaff0c4 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -20,6 +20,7 @@ import android.animation.AnimatorInflater;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
@@ -48,11 +49,13 @@ import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.ResearchLogger;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
+import com.android.inputmethod.latin.StringUtils;
import com.android.inputmethod.latin.SubtypeLocale;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils;
import com.android.inputmethod.latin.define.ProductionFlag;
+import java.util.Locale;
import java.util.WeakHashMap;
/**
@@ -907,7 +910,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
paint.setTextAlign(Align.CENTER);
paint.setTypeface(Typeface.DEFAULT);
// Estimate appropriate language name text size to fit in maxTextWidth.
- String language = SubtypeLocale.getFullDisplayName(subtype);
+ String language = getFullDisplayName(subtype, getResources());
int textWidth = getTextWidth(paint, language, origTextSize);
// Assuming text width and text size are proportional to each other.
float textSize = origTextSize * Math.min(width / textWidth, 1.0f);
@@ -919,7 +922,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
final boolean useShortName;
if (useMiddleName) {
- language = SubtypeLocale.getMiddleDisplayName(subtype);
+ language = getMiddleDisplayName(subtype);
textWidth = getTextWidth(paint, language, origTextSize);
textSize = origTextSize * Math.min(width / textWidth, 1.0f);
useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME)
@@ -929,7 +932,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
}
if (useShortName) {
- language = SubtypeLocale.getShortDisplayName(subtype);
+ language = getShortDisplayName(subtype);
textWidth = getTextWidth(paint, language, origTextSize);
textSize = origTextSize * Math.min(width / textWidth, 1.0f);
}
@@ -975,4 +978,46 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
drawIcon(canvas, mSpaceIcon, x, y, iconWidth, iconHeight);
}
}
+
+ // InputMethodSubtype's display name for spacebar text in its locale.
+ // isAdditionalSubtype (T=true, F=false)
+ // locale layout | Short Middle Full
+ // ------ ------ - ---- --------- ----------------------
+ // en_US qwerty F En English English (US) exception
+ // en_GB qwerty F En English English (UK) exception
+ // fr azerty F Fr Français Français
+ // fr_CA qwerty F Fr Français Français (Canada)
+ // de qwertz F De Deutsch Deutsch
+ // zz qwerty F QWERTY QWERTY
+ // fr qwertz T Fr Français Français (QWERTZ)
+ // de qwerty T De Deutsch Deutsch (QWERTY)
+ // en_US azerty T En English English (US) (AZERTY)
+ // zz azerty T AZERTY AZERTY
+
+ // Get InputMethodSubtype's full display name in its locale.
+ static String getFullDisplayName(InputMethodSubtype subtype, Resources res) {
+ if (SubtypeLocale.isNoLanguage(subtype)) {
+ return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype);
+ }
+
+ return SubtypeLocale.getSubtypeDisplayName(subtype, res);
+ }
+
+ // Get InputMethodSubtype's short display name in its locale.
+ static String getShortDisplayName(InputMethodSubtype subtype) {
+ if (SubtypeLocale.isNoLanguage(subtype)) {
+ return "";
+ }
+ final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
+ return StringUtils.toTitleCase(locale.getLanguage(), locale);
+ }
+
+ // Get InputMethodSubtype's middle display name in its locale.
+ static String getMiddleDisplayName(InputMethodSubtype subtype) {
+ if (SubtypeLocale.isNoLanguage(subtype)) {
+ return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype);
+ }
+ final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
+ return StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtype.java b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java
index b9023aef9..06d33154f 100644
--- a/java/src/com/android/inputmethod/latin/AdditionalSubtype.java
+++ b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java
@@ -42,8 +42,7 @@ public class AdditionalSubtype {
final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName;
final String filteredExtraValue = StringUtils.appendToCsvIfNotExists(
IS_ADDITIONAL_SUBTYPE, extraValue);
- final int nameId = SubtypeLocale.getSubtypeNameIdFromKeyboardLayoutName(
- keyboardLayoutSetName);
+ final int nameId = SubtypeLocale.getSubtypeNameId(localeString, keyboardLayoutSetName);
return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
localeString, KEYBOARD_MODE,
layoutExtraValue + "," + filteredExtraValue, false, false);
diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
index 8ce91fd2d..be807ab0c 100644
--- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
+++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
@@ -41,7 +41,6 @@ import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
-import java.util.Locale;
import java.util.TreeSet;
public class AdditionalSubtypeSettings extends PreferenceFragment {
@@ -61,7 +60,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
}
public SubtypeLocaleItem(String localeString) {
- this(localeString, getDisplayName(localeString));
+ this(localeString, SubtypeLocale.getSubtypeLocaleDisplayName(localeString));
}
@Override
@@ -73,11 +72,6 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
public int compareTo(SubtypeLocaleItem o) {
return first.compareTo(o.first);
}
-
- private static String getDisplayName(String localeString) {
- final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
- return StringUtils.toTitleCase(locale.getDisplayName(locale), locale);
- }
}
static class SubtypeLocaleAdapter extends ArrayAdapter<SubtypeLocaleItem> {
@@ -185,7 +179,8 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
setDialogTitle(R.string.add_style);
setKey(KEY_NEW_SUBTYPE);
} else {
- final String displayName = SubtypeLocale.getFullDisplayName(subtype);
+ final String displayName = SubtypeLocale.getSubtypeDisplayName(
+ subtype, getContext().getResources());
setTitle(displayName);
setDialogTitle(displayName);
setKey(KEY_PREFIX + subtype.getLocale() + "_"
diff --git a/java/src/com/android/inputmethod/latin/LocaleUtils.java b/java/src/com/android/inputmethod/latin/LocaleUtils.java
index f19c59a6a..b938dd336 100644
--- a/java/src/com/android/inputmethod/latin/LocaleUtils.java
+++ b/java/src/com/android/inputmethod/latin/LocaleUtils.java
@@ -180,13 +180,13 @@ public class LocaleUtils {
try {
if (newLocale != null && !newLocale.equals(oldLocale)) {
conf.locale = newLocale;
- res.updateConfiguration(conf, res.getDisplayMetrics());
+ res.updateConfiguration(conf, null);
}
return job(res);
} finally {
if (newLocale != null && !newLocale.equals(oldLocale)) {
conf.locale = oldLocale;
- res.updateConfiguration(conf, res.getDisplayMetrics());
+ res.updateConfiguration(conf, null);
}
}
}
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 13264f7e8..74c4aea0c 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -300,13 +300,14 @@ public class Settings extends InputMethodSettingsFragment
final PreferenceScreen customInputStyles =
(PreferenceScreen)findPreference(PREF_CUSTOM_INPUT_STYLES);
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
- final String prefSubtype = SettingsValues.getPrefAdditionalSubtypes(prefs, getResources());
+ final Resources res = getResources();
+ final String prefSubtype = SettingsValues.getPrefAdditionalSubtypes(prefs, res);
final InputMethodSubtype[] subtypes =
AdditionalSubtype.createAdditionalSubtypesArray(prefSubtype);
final StringBuilder styles = new StringBuilder();
for (final InputMethodSubtype subtype : subtypes) {
if (styles.length() > 0) styles.append(", ");
- styles.append(SubtypeLocale.getFullDisplayName(subtype));
+ styles.append(SubtypeLocale.getSubtypeDisplayName(subtype, res));
}
customInputStyles.setSummary(styles);
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
index 88d3c3f4f..d10c42ccd 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
@@ -45,7 +45,10 @@ public class SubtypeLocale {
// Keyboard layout to subtype name resource id map.
private static final HashMap<String, Integer> sKeyboardLayoutToNameIdsMap =
new HashMap<String, Integer>();
- private static final String SUBTYPE_RESOURCE_GENERIC_NAME_PREFIX = "string/subtype_generic_";
+ private static final String SUBTYPE_NAME_RESOURCE_GENERIC_PREFIX =
+ "string/subtype_generic_";
+ 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 =
new HashMap<String, String>();
@@ -64,9 +67,15 @@ public class SubtypeLocale {
for (int i = 0; i < predefinedLayoutSet.length; i++) {
final String layoutName = predefinedLayoutSet[i];
sKeyboardKayoutToDisplayNameMap.put(layoutName, layoutDisplayNames[i]);
- final String resourceName = SUBTYPE_RESOURCE_GENERIC_NAME_PREFIX + layoutName;
+ final String resourceName = SUBTYPE_NAME_RESOURCE_GENERIC_PREFIX + layoutName;
final int resId = res.getIdentifier(resourceName, null, RESOURCE_PACKAGE_NAME);
sKeyboardLayoutToNameIdsMap.put(layoutName, resId);
+ // Register subtype name resource id of "No language" with key "zz_<layout>"
+ final String noLanguageResName = SUBTYPE_NAME_RESOURCE_NO_LANGUAGE_PREFIX + layoutName;
+ final int noLanguageResId = res.getIdentifier(
+ noLanguageResName, null, RESOURCE_PACKAGE_NAME);
+ final String key = getNoLanguageLayoutKey(layoutName);
+ sKeyboardLayoutToNameIdsMap.put(key, noLanguageResId);
}
final String[] exceptionalLocales = res.getStringArray(
@@ -82,65 +91,45 @@ public class SubtypeLocale {
return sPredefinedKeyboardLayoutSet;
}
- public static int getSubtypeNameIdFromKeyboardLayoutName(String keyboardLayoutName) {
- final Integer nameId = sKeyboardLayoutToNameIdsMap.get(keyboardLayoutName);
- return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId;
+ private static final String getNoLanguageLayoutKey(String keyboardLayoutName) {
+ return NO_LANGUAGE + "_" + keyboardLayoutName;
}
- // Get InputMethodSubtype's display name in its locale.
- // isAdditionalSubtype (T=true, F=false)
- // locale layout | Short Middle Full
- // ------ ------ - ---- --------- -----------------
- // en_US qwerty F En English English (US) exception
- // en_GB qwerty F En English English (UK) exception
- // fr azerty F Fr Français Français
- // fr_CA qwerty F Fr Français Français (Canada)
- // de qwertz F De Deutsch Deutsch
- // zz qwerty F QWERTY QWERTY
- // fr qwertz T Fr Français Français (QWERTZ)
- // de qwerty T De Deutsch Deutsch (QWERTY)
- // en_US azerty T En English English (US) (AZERTY)
- // zz azerty T AZERTY AZERTY
-
- // Get InputMethodSubtype's full display name in its locale.
- public static String getFullDisplayName(InputMethodSubtype subtype) {
- if (isNoLanguage(subtype)) {
- return getKeyboardLayoutSetDisplayName(subtype);
- }
-
- final String exceptionalValue = sExceptionalDisplayNamesMap.get(subtype.getLocale());
-
- final Locale locale = getSubtypeLocale(subtype);
- if (AdditionalSubtype.isAdditionalSubtype(subtype)) {
- final String language = (exceptionalValue != null) ? exceptionalValue
- : StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
- final String layout = getKeyboardLayoutSetDisplayName(subtype);
- return String.format("%s (%s)", language, layout);
- }
+ public static int getSubtypeNameId(String localeString, String keyboardLayoutName) {
+ final String key = localeString.equals(NO_LANGUAGE)
+ ? getNoLanguageLayoutKey(keyboardLayoutName)
+ : keyboardLayoutName;
+ final Integer nameId = sKeyboardLayoutToNameIdsMap.get(key);
+ return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId;
+ }
+ public static String getSubtypeLocaleDisplayName(String localeString) {
+ final String exceptionalValue = sExceptionalDisplayNamesMap.get(localeString);
if (exceptionalValue != null) {
return exceptionalValue;
}
-
+ final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
return StringUtils.toTitleCase(locale.getDisplayName(locale), locale);
}
- // Get InputMethodSubtype's middle display name in its locale.
- public static String getMiddleDisplayName(InputMethodSubtype subtype) {
- if (isNoLanguage(subtype)) {
- return getKeyboardLayoutSetDisplayName(subtype);
- }
- final Locale locale = getSubtypeLocale(subtype);
- return StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
- }
-
- // Get InputMethodSubtype's short display name in its locale.
- public static String getShortDisplayName(InputMethodSubtype subtype) {
- if (isNoLanguage(subtype)) {
- return "";
- }
- final Locale locale = getSubtypeLocale(subtype);
- return StringUtils.toTitleCase(locale.getLanguage(), locale);
+ // InputMethodSubtype's display name in its locale.
+ // isAdditionalSubtype (T=true, F=false)
+ // locale layout | display name
+ // ------ ------ - ----------------------
+ // en_US qwerty F English (US) exception
+ // en_GB qwerty F English (UK) exception
+ // fr azerty F Français
+ // fr_CA qwerty F Français (Canada)
+ // de qwertz F Deutsch
+ // zz qwerty F No language (QWERTY)
+ // fr qwertz T Français (QWERTZ)
+ // de qwerty T Deutsch (QWERTY)
+ // en_US azerty T English (US) (AZERTY)
+ // zz azerty T No language (AZERTY)
+
+ public static String getSubtypeDisplayName(InputMethodSubtype subtype, Resources res) {
+ final String language = getSubtypeLocaleDisplayName(subtype.getLocale());
+ return res.getString(subtype.getNameResId(), language);
}
public static boolean isNoLanguage(InputMethodSubtype subtype) {