aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-04-25 22:22:00 +0900
committersatok <satok@google.com>2011-04-25 22:22:00 +0900
commit0dbb7e26d1e719251f66bf2f5034330e13bb5c3f (patch)
tree143ef17b43c175af401fabdc8fc77225478bfc95 /java/src
parentc55aaaf26e550925f5f3f07e1e049d061a751063 (diff)
parent1123bcaf2e371fe99703e54a2716e4329016aec4 (diff)
downloadlatinime-0dbb7e26d1e719251f66bf2f5034330e13bb5c3f.tar.gz
latinime-0dbb7e26d1e719251f66bf2f5034330e13bb5c3f.tar.xz
latinime-0dbb7e26d1e719251f66bf2f5034330e13bb5c3f.zip
Merge remote-tracking branch 'goog/master' into merge
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboard.java38
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java4
3 files changed, 33 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java b/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java
index 73f0b7a2d..e14a49c49 100644
--- a/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java
+++ b/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java
@@ -29,6 +29,7 @@ import java.util.Locale;
// This class is used only when the IME doesn't use method.xml for language switching.
public class LanguageSwitcherProxy implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final LanguageSwitcherProxy sInstance = new LanguageSwitcherProxy();
+ private LatinIME mService;
private LanguageSwitcher mLanguageSwitcher;
private SharedPreferences mPrefs;
@@ -43,6 +44,7 @@ public class LanguageSwitcherProxy implements SharedPreferences.OnSharedPreferen
sInstance.mLanguageSwitcher = new LanguageSwitcher(service);
sInstance.mLanguageSwitcher.loadLocales(prefs, conf.locale);
sInstance.mPrefs = prefs;
+ sInstance.mService = service;
prefs.registerOnSharedPreferenceChangeListener(sInstance);
}
@@ -80,6 +82,9 @@ public class LanguageSwitcherProxy implements SharedPreferences.OnSharedPreferen
if (key.equals(Settings.PREF_SELECTED_LANGUAGES)
|| key.equals(Settings.PREF_INPUT_LANGUAGE)) {
mLanguageSwitcher.loadLocales(prefs, null);
+ if (mService != null) {
+ mService.onRefreshKeyboard();
+ }
}
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index a1d0607bf..c279769f6 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
@@ -294,9 +297,12 @@ public class LatinKeyboard extends Keyboard {
paint.setColor(getSpacebarTextColor(mSpacebarTextColor, textFadeFactor));
canvas.drawText(language, width / 2, baseline - descent, paint);
- // Put arrows that are already layed out on either side of the text
+ // Put arrows that are already laid out on either side of the text
+ // Because language switch is disabled on phone and number layouts, hide arrows.
+ // TODO: Sort out how to enable language switch on these layouts.
if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()
- && mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) {
+ && mSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1
+ && !(isPhoneKeyboard() || isNumberKeyboard())) {
mButtonArrowLeftIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor));
mButtonArrowRightIcon.setColorFilter(getSpacebarDrawableFilter(textFadeFactor));
mButtonArrowLeftIcon.draw(canvas);
@@ -349,6 +355,10 @@ public class LatinKeyboard extends Keyboard {
}
public boolean shouldTriggerSpacebarSlidingLanguageSwitch(int diff) {
+ // On phone and number layouts, sliding language switch is disabled.
+ // TODO: Sort out how to enable language switch on these layouts.
+ if (isPhoneKeyboard() || isNumberKeyboard())
+ return false;
return Math.abs(diff) > mSpacebarLanguageSwitchThreshold;
}
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());
}