use of android.os.LocaleList in project android_frameworks_base by crdroidandroid.
the class InputManagerService method visitKeyboardLayoutsInPackage.
private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver, String keyboardName, int requestedPriority, KeyboardLayoutVisitor visitor) {
Bundle metaData = receiver.metaData;
if (metaData == null) {
return;
}
int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS);
if (configResId == 0) {
Slog.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS + "' on receiver " + receiver.packageName + "/" + receiver.name);
return;
}
CharSequence receiverLabel = receiver.loadLabel(pm);
String collection = receiverLabel != null ? receiverLabel.toString() : "";
int priority;
if ((receiver.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
priority = requestedPriority;
} else {
priority = 0;
}
try {
Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
XmlResourceParser parser = resources.getXml(configResId);
try {
XmlUtils.beginDocument(parser, "keyboard-layouts");
for (; ; ) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null) {
break;
}
if (element.equals("keyboard-layout")) {
TypedArray a = resources.obtainAttributes(parser, com.android.internal.R.styleable.KeyboardLayout);
try {
String name = a.getString(com.android.internal.R.styleable.KeyboardLayout_name);
String label = a.getString(com.android.internal.R.styleable.KeyboardLayout_label);
int keyboardLayoutResId = a.getResourceId(com.android.internal.R.styleable.KeyboardLayout_keyboardLayout, 0);
String languageTags = a.getString(com.android.internal.R.styleable.KeyboardLayout_locale);
LocaleList locales = getLocalesFromLanguageTags(languageTags);
int vid = a.getInt(com.android.internal.R.styleable.KeyboardLayout_vendorId, -1);
int pid = a.getInt(com.android.internal.R.styleable.KeyboardLayout_productId, -1);
if (name == null || label == null || keyboardLayoutResId == 0) {
Slog.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' " + "attributes in keyboard layout " + "resource from receiver " + receiver.packageName + "/" + receiver.name);
} else {
String descriptor = KeyboardLayoutDescriptor.format(receiver.packageName, receiver.name, name);
if (keyboardName == null || name.equals(keyboardName)) {
KeyboardLayout layout = new KeyboardLayout(descriptor, label, collection, priority, locales, vid, pid);
visitor.visitKeyboardLayout(resources, keyboardLayoutResId, layout);
}
}
} finally {
a.recycle();
}
} else {
Slog.w(TAG, "Skipping unrecognized element '" + element + "' in keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name);
}
}
} finally {
parser.close();
}
} catch (Exception ex) {
Slog.w(TAG, "Could not parse keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name, ex);
}
}
use of android.os.LocaleList in project android_frameworks_base by ResurrectionRemix.
the class ResourcesLocaleTest method testSelectFirstSupportedLanguage.
@SmallTest
public void testSelectFirstSupportedLanguage() throws Exception {
final Resources resources = createResourcesWithApk(R.raw.locales);
ensureNoLanguage(resources, "fr");
final LocaleList preferredLocales = LocaleList.forLanguageTags("fr-FR,pl-PL");
final Configuration config = new Configuration();
config.setLocales(preferredLocales);
resources.updateConfiguration(config, null);
// The APK we loaded has default and Polish languages. We expect the Polish language to
// therefore be chosen.
assertEquals(Locale.forLanguageTag("pl-PL"), resources.getConfiguration().getLocales().get(0));
}
use of android.os.LocaleList in project android_frameworks_base by ResurrectionRemix.
the class AutoReinflateContainer method onConfigurationChanged.
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
boolean shouldInflateLayout = false;
final int density = newConfig.densityDpi;
if (density != mDensity) {
mDensity = density;
shouldInflateLayout = true;
}
final LocaleList localeList = newConfig.getLocales();
if (localeList != mLocaleList) {
mLocaleList = localeList;
shouldInflateLayout = true;
}
if (shouldInflateLayout) {
inflateLayout();
}
}
use of android.os.LocaleList in project platform_frameworks_base by android.
the class ActivityThread method updateLocaleListFromAppContext.
/**
* The LocaleList set for the app's resources may have been shuffled so that the preferred
* Locale is at position 0. We must find the index of this preferred Locale in the
* original LocaleList.
*/
private void updateLocaleListFromAppContext(Context context, LocaleList newLocaleList) {
final Locale bestLocale = context.getResources().getConfiguration().getLocales().get(0);
final int newLocaleListSize = newLocaleList.size();
for (int i = 0; i < newLocaleListSize; i++) {
if (bestLocale.equals(newLocaleList.get(i))) {
LocaleList.setDefault(newLocaleList, i);
return;
}
}
// The app may have overridden the LocaleList with its own Locale
// (not present in the available list). Push the chosen Locale
// to the front of the list.
LocaleList.setDefault(new LocaleList(bestLocale, newLocaleList));
}
use of android.os.LocaleList in project platform_frameworks_base by android.
the class InputMethodUtils method getImplicitlyApplicableSubtypesLockedImpl.
private static ArrayList<InputMethodSubtype> getImplicitlyApplicableSubtypesLockedImpl(Resources res, InputMethodInfo imi) {
final List<InputMethodSubtype> subtypes = InputMethodUtils.getSubtypes(imi);
final LocaleList systemLocales = res.getConfiguration().getLocales();
final String systemLocale = systemLocales.get(0).toString();
if (TextUtils.isEmpty(systemLocale))
return new ArrayList<>();
final int numSubtypes = subtypes.size();
// Handle overridesImplicitlyEnabledSubtype mechanism.
final HashMap<String, InputMethodSubtype> applicableModeAndSubtypesMap = new HashMap<>();
for (int i = 0; i < numSubtypes; ++i) {
// scan overriding implicitly enabled subtypes.
final InputMethodSubtype subtype = subtypes.get(i);
if (subtype.overridesImplicitlyEnabledSubtype()) {
final String mode = subtype.getMode();
if (!applicableModeAndSubtypesMap.containsKey(mode)) {
applicableModeAndSubtypesMap.put(mode, subtype);
}
}
}
if (applicableModeAndSubtypesMap.size() > 0) {
return new ArrayList<>(applicableModeAndSubtypesMap.values());
}
final HashMap<String, ArrayList<InputMethodSubtype>> nonKeyboardSubtypesMap = new HashMap<>();
final ArrayList<InputMethodSubtype> keyboardSubtypes = new ArrayList<>();
for (int i = 0; i < numSubtypes; ++i) {
final InputMethodSubtype subtype = subtypes.get(i);
final String mode = subtype.getMode();
if (SUBTYPE_MODE_KEYBOARD.equals(mode)) {
keyboardSubtypes.add(subtype);
} else {
if (!nonKeyboardSubtypesMap.containsKey(mode)) {
nonKeyboardSubtypesMap.put(mode, new ArrayList<>());
}
nonKeyboardSubtypesMap.get(mode).add(subtype);
}
}
final ArrayList<InputMethodSubtype> applicableSubtypes = new ArrayList<>();
LocaleUtils.filterByLanguage(keyboardSubtypes, sSubtypeToLocale, systemLocales, applicableSubtypes);
if (!applicableSubtypes.isEmpty()) {
boolean hasAsciiCapableKeyboard = false;
final int numApplicationSubtypes = applicableSubtypes.size();
for (int i = 0; i < numApplicationSubtypes; ++i) {
final InputMethodSubtype subtype = applicableSubtypes.get(i);
if (subtype.containsExtraValueKey(TAG_ASCII_CAPABLE)) {
hasAsciiCapableKeyboard = true;
break;
}
}
if (!hasAsciiCapableKeyboard) {
final int numKeyboardSubtypes = keyboardSubtypes.size();
for (int i = 0; i < numKeyboardSubtypes; ++i) {
final InputMethodSubtype subtype = keyboardSubtypes.get(i);
final String mode = subtype.getMode();
if (SUBTYPE_MODE_KEYBOARD.equals(mode) && subtype.containsExtraValueKey(TAG_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)) {
applicableSubtypes.add(subtype);
}
}
}
}
if (applicableSubtypes.isEmpty()) {
InputMethodSubtype lastResortKeyboardSubtype = findLastResortApplicableSubtypeLocked(res, subtypes, SUBTYPE_MODE_KEYBOARD, systemLocale, true);
if (lastResortKeyboardSubtype != null) {
applicableSubtypes.add(lastResortKeyboardSubtype);
}
}
// For each non-keyboard mode, extract subtypes with system locales.
for (final ArrayList<InputMethodSubtype> subtypeList : nonKeyboardSubtypesMap.values()) {
LocaleUtils.filterByLanguage(subtypeList, sSubtypeToLocale, systemLocales, applicableSubtypes);
}
return applicableSubtypes;
}
Aggregations