From cae6b1060e0c8547f9f7f64fbbf3a18a76035a53 Mon Sep 17 00:00:00 2001 From: satok Date: Mon, 25 Apr 2011 20:55:58 +0900 Subject: [PATCH] Display the language name on the spacebar if the full display locale name is too longer than the space bar Bug: 4329512 Change-Id: I477684747bf9e70a6909c25877fbe9e622571fd4 --- .../inputmethod/keyboard/LatinKeyboard.java | 27 ++++++++++--------- .../inputmethod/latin/SubtypeSwitcher.java | 4 +++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index a1d0607bf..28593676f 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -194,8 +194,7 @@ public class LatinKeyboard extends Keyboard { // Layout local language name and left and right arrow on spacebar. private static String layoutSpacebar(Paint paint, Locale locale, Drawable lArrow, - Drawable rArrow, int width, int height, float origTextSize, - boolean allowVariableTextSize) { + Drawable rArrow, int width, int height, float origTextSize) { final float arrowWidth = lArrow.getIntrinsicWidth(); final float arrowHeight = lArrow.getIntrinsicHeight(); final float maxTextWidth = width - (arrowWidth + arrowWidth); @@ -206,17 +205,23 @@ public class LatinKeyboard extends Keyboard { int textWidth = getTextWidth(paint, language, origTextSize, bounds); // Assuming text width and text size are proportional to each other. float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); + // allow variable text size + textWidth = getTextWidth(paint, language, textSize, bounds); + // If text size goes too small or text does not fit, use middle or short name + final boolean useMiddleName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) + || (textWidth > maxTextWidth); final boolean useShortName; - if (allowVariableTextSize) { - textWidth = getTextWidth(paint, language, textSize, bounds); - // If text size goes too small or text does not fit, use short name - useShortName = textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME - || textWidth > maxTextWidth; + if (useMiddleName) { + language = SubtypeSwitcher.getMiddleDisplayLanguage(locale); + textWidth = getTextWidth(paint, language, origTextSize, bounds); + textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); + useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) + || (textWidth > maxTextWidth); } else { - useShortName = textWidth > maxTextWidth; - textSize = origTextSize; + useShortName = false; } + if (useShortName) { language = SubtypeSwitcher.getShortDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize, bounds); @@ -276,11 +281,9 @@ public class LatinKeyboard extends Keyboard { defaultTextSize = 14; } - final boolean allowVariableTextSize = true; final String language = layoutSpacebar(paint, inputLocale, mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height, - getTextSizeFromTheme(mContext.getTheme(), textStyle, defaultTextSize), - allowVariableTextSize); + getTextSizeFromTheme(mContext.getTheme(), textStyle, defaultTextSize)); // Draw language text with shadow // In case there is no space icon, we will place the language text at the center of diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 160b677e1..158977927 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -607,6 +607,10 @@ public class SubtypeSwitcher { return toTitleCase(locale.getDisplayLanguage(locale)); } + public static String getMiddleDisplayLanguage(Locale locale) { + return toTitleCase(locale.getDisplayLanguage(new Locale(locale.getLanguage()))); + } + public static String getShortDisplayLanguage(Locale locale) { return toTitleCase(locale.getLanguage()); }