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.
|
// Layout local language name and left and right arrow on spacebar.
|
||||||
private static String layoutSpacebar(Paint paint, Locale locale, Drawable lArrow,
|
private static String layoutSpacebar(Paint paint, Locale locale, Drawable lArrow,
|
||||||
Drawable rArrow, int width, int height, float origTextSize,
|
Drawable rArrow, int width, int height, float origTextSize) {
|
||||||
boolean allowVariableTextSize) {
|
|
||||||
final float arrowWidth = lArrow.getIntrinsicWidth();
|
final float arrowWidth = lArrow.getIntrinsicWidth();
|
||||||
final float arrowHeight = lArrow.getIntrinsicHeight();
|
final float arrowHeight = lArrow.getIntrinsicHeight();
|
||||||
final float maxTextWidth = width - (arrowWidth + arrowWidth);
|
final float maxTextWidth = width - (arrowWidth + arrowWidth);
|
||||||
|
@ -206,17 +205,23 @@ public class LatinKeyboard extends Keyboard {
|
||||||
int textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
int textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||||
// Assuming text width and text size are proportional to each other.
|
// Assuming text width and text size are proportional to each other.
|
||||||
float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
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;
|
final boolean useShortName;
|
||||||
if (allowVariableTextSize) {
|
if (useMiddleName) {
|
||||||
textWidth = getTextWidth(paint, language, textSize, bounds);
|
language = SubtypeSwitcher.getMiddleDisplayLanguage(locale);
|
||||||
// If text size goes too small or text does not fit, use short name
|
textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||||
useShortName = textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME
|
textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
||||||
|| textWidth > maxTextWidth;
|
useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME)
|
||||||
|
|| (textWidth > maxTextWidth);
|
||||||
} else {
|
} else {
|
||||||
useShortName = textWidth > maxTextWidth;
|
useShortName = false;
|
||||||
textSize = origTextSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useShortName) {
|
if (useShortName) {
|
||||||
language = SubtypeSwitcher.getShortDisplayLanguage(locale);
|
language = SubtypeSwitcher.getShortDisplayLanguage(locale);
|
||||||
textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||||
|
@ -276,11 +281,9 @@ public class LatinKeyboard extends Keyboard {
|
||||||
defaultTextSize = 14;
|
defaultTextSize = 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean allowVariableTextSize = true;
|
|
||||||
final String language = layoutSpacebar(paint, inputLocale,
|
final String language = layoutSpacebar(paint, inputLocale,
|
||||||
mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height,
|
mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height,
|
||||||
getTextSizeFromTheme(mContext.getTheme(), textStyle, defaultTextSize),
|
getTextSizeFromTheme(mContext.getTheme(), textStyle, defaultTextSize));
|
||||||
allowVariableTextSize);
|
|
||||||
|
|
||||||
// Draw language text with shadow
|
// Draw language text with shadow
|
||||||
// In case there is no space icon, we will place the language text at the center of
|
// 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));
|
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) {
|
public static String getShortDisplayLanguage(Locale locale) {
|
||||||
return toTitleCase(locale.getLanguage());
|
return toTitleCase(locale.getLanguage());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue