diff options
| author | Tadashi G. Takaoka <takaoka@google.com> | 2012-04-25 14:17:49 +0900 |
|---|---|---|
| committer | Tadashi G. Takaoka <takaoka@google.com> | 2012-04-26 11:50:28 +0900 |
| commit | 27b42ced86e1c85de3d59d91a9e5c577fa552569 (patch) | |
| tree | 320d2e6c6429eded514f9c1c75f422d53c47ecee /java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java | |
| parent | 49caddbdabe5ca666bdef9f842f134e30e7ffed9 (diff) | |
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/src/com/android/inputmethod/keyboard/LatinKeyboardView.java')
| -rw-r--r-- | java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java | 51 |
1 files changed, 48 insertions, 3 deletions
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); + } } |
