Merge "Display the language name on the spacebar if the full display locale name is too longer than the space bar"
This commit is contained in:
commit
1123bcaf2e
2 changed files with 19 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue