Fix newly created custom input style display name

This will revert I4263632e

Bug: 6443665
Bug: 6410653
Change-Id: Id9ad1a204ed9802488abfc2c536a95d62d55afe0
main
Tadashi G. Takaoka 2012-05-05 16:33:51 +09:00
parent 4c9bdcc957
commit ca93442026
2 changed files with 14 additions and 18 deletions

View File

@ -20,6 +20,7 @@ import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOAR
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.util.Log;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.LocaleUtils.RunInLocale; import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
@ -28,7 +29,7 @@ import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
public class SubtypeLocale { public class SubtypeLocale {
private static final String TAG = SubtypeLocale.class.getSimpleName(); static final String TAG = SubtypeLocale.class.getSimpleName();
// This class must be located in the same package as LatinIME.java. // This class must be located in the same package as LatinIME.java.
private static final String RESOURCE_PACKAGE_NAME = private static final String RESOURCE_PACKAGE_NAME =
DictionaryFactory.class.getPackage().getName(); DictionaryFactory.class.getPackage().getName();
@ -38,7 +39,6 @@ public class SubtypeLocale {
public static final String QWERTY = "qwerty"; public static final String QWERTY = "qwerty";
public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic; public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic;
private static Context sContext;
private static String[] sPredefinedKeyboardLayoutSet; private static String[] sPredefinedKeyboardLayoutSet;
// Keyboard layout to its display name map. // Keyboard layout to its display name map.
private static final HashMap<String, String> sKeyboardKayoutToDisplayNameMap = private static final HashMap<String, String> sKeyboardKayoutToDisplayNameMap =
@ -59,7 +59,6 @@ public class SubtypeLocale {
} }
public static void init(Context context) { public static void init(Context context) {
sContext = context;
final Resources res = context.getResources(); final Resources res = context.getResources();
final String[] predefinedLayoutSet = res.getStringArray(R.array.predefined_layouts); final String[] predefinedLayoutSet = res.getStringArray(R.array.predefined_layouts);
@ -129,16 +128,23 @@ public class SubtypeLocale {
// en_US azerty T English (US) (AZERTY) // en_US azerty T English (US) (AZERTY)
// zz azerty T No language (AZERTY) in system locale // zz azerty T No language (AZERTY) in system locale
public static String getSubtypeDisplayName(InputMethodSubtype subtype, Resources res) { public static String getSubtypeDisplayName(final InputMethodSubtype subtype, Resources res) {
// TODO: Remove this check when InputMethodManager.getLastInputMethodSubtype is
// fixed.
if (!ImfUtils.checkIfSubtypeBelongsToThisIme(sContext, subtype)) return "";
final String language = getSubtypeLocaleDisplayName(subtype.getLocale()); final String language = getSubtypeLocaleDisplayName(subtype.getLocale());
final int nameResId = subtype.getNameResId(); final int nameResId = subtype.getNameResId();
final RunInLocale<String> getSubtypeName = new RunInLocale<String>() { final RunInLocale<String> getSubtypeName = new RunInLocale<String>() {
@Override @Override
protected String job(Resources res) { protected String job(Resources res) {
return res.getString(nameResId, language); try {
return res.getString(nameResId, language);
} catch (Resources.NotFoundException e) {
// TODO: Remove this catch when InputMethodManager.getCurrentInputMethodSubtype
// is fixed.
Log.w(TAG, "Unknown subtype: mode=" + subtype.getMode()
+ " locale=" + subtype.getLocale()
+ " extra=" + subtype.getExtraValue()
+ "\n" + Utils.getStackTrace());
return "";
}
} }
}; };
final Locale locale = isNoLanguage(subtype) final Locale locale = isNoLanguage(subtype)

View File

@ -30,14 +30,12 @@ public class SubtypeLocaleTests extends AndroidTestCase {
// Locale to subtypes list. // Locale to subtypes list.
private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<InputMethodSubtype>(); private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<InputMethodSubtype>();
private Context mContext;
private Resources mRes; private Resources mRes;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
final Context context = getContext(); final Context context = getContext();
mContext = context;
mRes = context.getResources(); mRes = context.getResources();
SubtypeLocale.init(context); SubtypeLocale.init(context);
} }
@ -124,10 +122,6 @@ public class SubtypeLocaleTests extends AndroidTestCase {
final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype( final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
SubtypeLocale.NO_LANGUAGE, "azerty", null); SubtypeLocale.NO_LANGUAGE, "azerty", null);
ImfUtils.setAdditionalInputMethodSubtypes(mContext, new InputMethodSubtype[] {
DE_QWERTY, FR_QWERTZ, US_AZERTY, ZZ_AZERTY
});
final RunInLocale<Void> tests = new RunInLocale<Void>() { final RunInLocale<Void> tests = new RunInLocale<Void>() {
@Override @Override
protected Void job(Resources res) { protected Void job(Resources res) {
@ -191,10 +185,6 @@ public class SubtypeLocaleTests extends AndroidTestCase {
final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype( final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
SubtypeLocale.NO_LANGUAGE, "azerty", null); SubtypeLocale.NO_LANGUAGE, "azerty", null);
ImfUtils.setAdditionalInputMethodSubtypes(mContext, new InputMethodSubtype[] {
DE_QWERTY, FR_QWERTZ, US_AZERTY, ZZ_AZERTY
});
final RunInLocale<Void> tests = new RunInLocale<Void>() { final RunInLocale<Void> tests = new RunInLocale<Void>() {
@Override @Override
protected Void job(Resources res) { protected Void job(Resources res) {