Merge "Show full display names in the popup of the spacebar language swicher"

main
satok 2011-05-18 02:34:37 -07:00 committed by Android (Google) Code Review
commit 0b47f3af83
8 changed files with 47 additions and 29 deletions

View File

@ -20,6 +20,7 @@ import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.Settings; import com.android.inputmethod.latin.Settings;
import com.android.inputmethod.latin.SharedPreferencesCompat; import com.android.inputmethod.latin.SharedPreferencesCompat;
import com.android.inputmethod.latin.Utils;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
@ -125,8 +126,7 @@ public class LanguageSwitcher {
private void constructLocales() { private void constructLocales() {
mLocales.clear(); mLocales.clear();
for (final String lang : mSelectedLanguageArray) { for (final String lang : mSelectedLanguageArray) {
final Locale locale = new Locale(lang.substring(0, 2), final Locale locale = Utils.constructLocaleFromString(lang);
lang.length() > 4 ? lang.substring(3, 5) : "");
mLocales.add(locale); mLocales.add(locale);
} }
} }

View File

@ -78,7 +78,7 @@ public class LatinKeyboard extends Keyboard {
// of the most common key width of this keyboard). // of the most common key width of this keyboard).
private static final int SPACEBAR_DRAG_WIDTH = 3; private static final int SPACEBAR_DRAG_WIDTH = 3;
// Minimum width of space key preview (proportional to keyboard width). // Minimum width of space key preview (proportional to keyboard width).
private static final float SPACEBAR_POPUP_MIN_RATIO = 0.4f; private static final float SPACEBAR_POPUP_MIN_RATIO = 0.5f;
// Height in space key the language name will be drawn. (proportional to space key height) // Height in space key the language name will be drawn. (proportional to space key height)
public static final float SPACEBAR_LANGUAGE_BASELINE = 0.6f; public static final float SPACEBAR_LANGUAGE_BASELINE = 0.6f;
// If the full language name needs to be smaller than this value to be drawn on space key, // If the full language name needs to be smaller than this value to be drawn on space key,

View File

@ -38,7 +38,7 @@ import android.view.ViewConfiguration;
* movement on the spacebar. * movement on the spacebar.
*/ */
public class SlidingLocaleDrawable extends Drawable { public class SlidingLocaleDrawable extends Drawable {
private static final int SLIDE_SPEED_MULTIPLIER_RATIO = 150;
private final Context mContext; private final Context mContext;
private final Resources mRes; private final Resources mRes;
private final int mWidth; private final int mWidth;
@ -90,7 +90,7 @@ public class SlidingLocaleDrawable extends Drawable {
mCurrentLanguage = null; mCurrentLanguage = null;
return; return;
} }
mDiff = diff; mDiff = Math.max(diff, diff * SLIDE_SPEED_MULTIPLIER_RATIO / 100);
if (mDiff > mWidth) mDiff = mWidth; if (mDiff > mWidth) mDiff = mWidth;
if (mDiff < -mWidth) mDiff = -mWidth; if (mDiff < -mWidth) mDiff = -mWidth;
if (Math.abs(mDiff) > mThreshold) mHitThreshold = true; if (Math.abs(mDiff) > mThreshold) mHitThreshold = true;

View File

@ -406,7 +406,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private void initSuggest() { private void initSuggest() {
final String localeStr = mSubtypeSwitcher.getInputLocaleStr(); final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
final Locale keyboardLocale = new Locale(localeStr); final Locale keyboardLocale = Utils.constructLocaleFromString(localeStr);
final Resources res = mResources; final Resources res = mResources;
final Locale savedLocale = Utils.setSystemLocale(res, keyboardLocale); final Locale savedLocale = Utils.setSystemLocale(res, keyboardLocale);
@ -440,7 +440,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
/* package private */ void resetSuggestMainDict() { /* package private */ void resetSuggestMainDict() {
final String localeStr = mSubtypeSwitcher.getInputLocaleStr(); final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
final Locale keyboardLocale = new Locale(localeStr); final Locale keyboardLocale = Utils.constructLocaleFromString(localeStr);
int mainDicResId = Utils.getMainDictionaryResourceId(mResources); int mainDicResId = Utils.getMainDictionaryResourceId(mResources);
mSuggest.resetMainDict(this, mainDicResId, keyboardLocale); mSuggest.resetMainDict(this, mainDicResId, keyboardLocale);
} }
@ -1553,7 +1553,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// a magic space even if it was a normal space. This is meant to help in case the user // a magic space even if it was a normal space. This is meant to help in case the user
// pressed space on purpose of displaying the suggestion strip punctuation. // pressed space on purpose of displaying the suggestion strip punctuation.
final char primaryCode = suggestion.charAt(0); final char primaryCode = suggestion.charAt(0);
final CharSequence beforeText = ic.getTextBeforeCursor(1, 0); final CharSequence beforeText = ic != null ? ic.getTextBeforeCursor(1, 0) : "";
final int toLeft = (ic == null || TextUtils.isEmpty(beforeText)) final int toLeft = (ic == null || TextUtils.isEmpty(beforeText))
? 0 : beforeText.charAt(0); ? 0 : beforeText.charAt(0);
final boolean oldMagicSpace = mJustAddedMagicSpace; final boolean oldMagicSpace = mJustAddedMagicSpace;

View File

@ -121,7 +121,7 @@ public class Settings extends PreferenceActivity
final Resources res = context.getResources(); final Resources res = context.getResources();
final Locale savedLocale; final Locale savedLocale;
if (null != localeStr) { if (null != localeStr) {
final Locale keyboardLocale = new Locale(localeStr); final Locale keyboardLocale = Utils.constructLocaleFromString(localeStr);
savedLocale = Utils.setSystemLocale(res, keyboardLocale); savedLocale = Utils.setSystemLocale(res, keyboardLocale);
} else { } else {
savedLocale = null; savedLocale = null;
@ -354,8 +354,6 @@ public class Settings extends PreferenceActivity
(PreferenceGroup) findPreference(PREF_GENERAL_SETTINGS_KEY); (PreferenceGroup) findPreference(PREF_GENERAL_SETTINGS_KEY);
final PreferenceGroup textCorrectionGroup = final PreferenceGroup textCorrectionGroup =
(PreferenceGroup) findPreference(PREF_CORRECTION_SETTINGS_KEY); (PreferenceGroup) findPreference(PREF_CORRECTION_SETTINGS_KEY);
final PreferenceGroup bigramGroup =
(PreferenceGroup) findPreference(PREF_NGRAM_SETTINGS_KEY);
final boolean showSettingsKeyOption = res.getBoolean( final boolean showSettingsKeyOption = res.getBoolean(
R.bool.config_enable_show_settings_key_option); R.bool.config_enable_show_settings_key_option);
@ -499,7 +497,6 @@ public class Settings extends PreferenceActivity
} }
private void updateSettingsKeySummary() { private void updateSettingsKeySummary() {
final ListPreference lp = mSettingsKeyPreference;
mSettingsKeyPreference.setSummary( mSettingsKeyPreference.setSummary(
getResources().getStringArray(R.array.settings_key_modes) getResources().getStringArray(R.array.settings_key_modes)
[mSettingsKeyPreference.findIndexOfValue(mSettingsKeyPreference.getValue())]); [mSettingsKeyPreference.findIndexOfValue(mSettingsKeyPreference.getValue())]);

View File

@ -92,10 +92,9 @@ public class SubtypeSwitcher {
} }
public static void init(LatinIME service, SharedPreferences prefs) { public static void init(LatinIME service, SharedPreferences prefs) {
SubtypeLocale.init(service);
sInstance.initialize(service, prefs); sInstance.initialize(service, prefs);
sInstance.updateAllParameters(); sInstance.updateAllParameters();
SubtypeLocale.init(service);
} }
private SubtypeSwitcher() { private SubtypeSwitcher() {
@ -281,14 +280,8 @@ public class SubtypeSwitcher {
// "en_US" --> language: en & country: US // "en_US" --> language: en & country: US
// "en" --> language: en // "en" --> language: en
// "" --> the system locale // "" --> the system locale
mLocaleSplitter.setString(inputLocaleStr); if (!TextUtils.isEmpty(inputLocaleStr)) {
if (mLocaleSplitter.hasNext()) { mInputLocale = Utils.constructLocaleFromString(inputLocaleStr);
String language = mLocaleSplitter.next();
if (mLocaleSplitter.hasNext()) {
mInputLocale = new Locale(language, mLocaleSplitter.next());
} else {
mInputLocale = new Locale(language);
}
mInputLocaleStr = inputLocaleStr; mInputLocaleStr = inputLocaleStr;
} else { } else {
mInputLocale = mSystemLocale; mInputLocale = mSystemLocale;
@ -549,12 +542,12 @@ public class SubtypeSwitcher {
|| mEnabledKeyboardSubtypesOfCurrentInputMethod.size() == 0) return; || mEnabledKeyboardSubtypesOfCurrentInputMethod.size() == 0) return;
mCurrentKeyboardSubtypeIndex = getCurrentIndex(); mCurrentKeyboardSubtypeIndex = getCurrentIndex();
mNextKeyboardSubtype = getNextKeyboardSubtypeInternal(mCurrentKeyboardSubtypeIndex); mNextKeyboardSubtype = getNextKeyboardSubtypeInternal(mCurrentKeyboardSubtypeIndex);
Locale locale = new Locale(mNextKeyboardSubtype.getLocale()); Locale locale = Utils.constructLocaleFromString(mNextKeyboardSubtype.getLocale());
mNextLanguage = getDisplayLanguage(locale); mNextLanguage = getFullDisplayName(locale, true);
mPreviousKeyboardSubtype = getPreviousKeyboardSubtypeInternal( mPreviousKeyboardSubtype = getPreviousKeyboardSubtypeInternal(
mCurrentKeyboardSubtypeIndex); mCurrentKeyboardSubtypeIndex);
locale = new Locale(mPreviousKeyboardSubtype.getLocale()); locale = Utils.constructLocaleFromString(mPreviousKeyboardSubtype.getLocale());
mPreviousLanguage = getDisplayLanguage(locale); mPreviousLanguage = getFullDisplayName(locale, true);
} }
private int normalize(int index) { private int normalize(int index) {
@ -591,11 +584,12 @@ public class SubtypeSwitcher {
} }
public static String getDisplayLanguage(Locale locale) { public static String getDisplayLanguage(Locale locale) {
return toTitleCase(locale.getDisplayLanguage(locale)); return toTitleCase(SubtypeLocale.getFullDisplayName(locale));
} }
public static String getMiddleDisplayLanguage(Locale locale) { public static String getMiddleDisplayLanguage(Locale locale) {
return toTitleCase((new Locale(locale.getLanguage()).getDisplayLanguage(locale))); return toTitleCase((Utils.constructLocaleFromString(
locale.getLanguage()).getDisplayLanguage(locale)));
} }
public static String getShortDisplayLanguage(Locale locale) { public static String getShortDisplayLanguage(Locale locale) {

View File

@ -44,6 +44,7 @@ import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
public class Utils { public class Utils {
@ -662,4 +663,28 @@ public class Utils {
res.updateConfiguration(conf, res.getDisplayMetrics()); res.updateConfiguration(conf, res.getDisplayMetrics());
return saveLocale; return saveLocale;
} }
private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>();
public static Locale constructLocaleFromString(String localeStr) {
if (localeStr == null)
return null;
synchronized (sLocaleCache) {
if (sLocaleCache.containsKey(localeStr))
return sLocaleCache.get(localeStr);
Locale retval = null;
String[] localeParams = localeStr.split("_", 3);
if (localeParams.length == 1) {
retval = new Locale(localeParams[0]);
} else if (localeParams.length == 2) {
retval = new Locale(localeParams[0], localeParams[1]);
} else if (localeParams.length == 3) {
retval = new Locale(localeParams[0], localeParams[1], localeParams[2]);
}
if (retval != null) {
sLocaleCache.put(localeStr, retval);
}
return retval;
}
}
} }

View File

@ -16,6 +16,8 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.latin.Utils;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
@ -75,7 +77,7 @@ public class SubtypeLocaleTests extends AndroidTestCase {
int failedCount = 0; int failedCount = 0;
for (final InputMethodSubtype subtype : mKeyboardSubtypes) { for (final InputMethodSubtype subtype : mKeyboardSubtypes) {
final String localeCode = subtype.getLocale(); final String localeCode = subtype.getLocale();
final Locale locale = new Locale(localeCode); final Locale locale = Utils.constructLocaleFromString(localeCode);
// The locale name which will be displayed on spacebar. For example 'English (US)' or // The locale name which will be displayed on spacebar. For example 'English (US)' or
// 'Francais (Canada)'. (c=\u008d) // 'Francais (Canada)'. (c=\u008d)
final String displayName = SubtypeLocale.getFullDisplayName(locale); final String displayName = SubtypeLocale.getFullDisplayName(locale);