Search in sources :

Example 71 with LocaleList

use of android.os.LocaleList in project android_frameworks_base by ResurrectionRemix.

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);
    }
}
Also used : LocaleList(android.os.LocaleList) XmlResourceParser(android.content.res.XmlResourceParser) Bundle(android.os.Bundle) TypedArray(android.content.res.TypedArray) Resources(android.content.res.Resources) KeyboardLayout(android.hardware.input.KeyboardLayout) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 72 with LocaleList

use of android.os.LocaleList in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class LocaleListEditor method getUserLocaleList.

private static List<LocaleStore.LocaleInfo> getUserLocaleList(Context context) {
    final List<LocaleStore.LocaleInfo> result = new ArrayList<>();
    final LocaleList localeList = LocalePicker.getLocales();
    for (int i = 0; i < localeList.size(); i++) {
        Locale locale = localeList.get(i);
        result.add(LocaleStore.getLocaleInfo(locale));
    }
    return result;
}
Also used : Locale(java.util.Locale) LocaleList(android.os.LocaleList) ArrayList(java.util.ArrayList)

Example 73 with LocaleList

use of android.os.LocaleList in project android_frameworks_base by ResurrectionRemix.

the class InputMethodUtils method getImplicitlyApplicableSubtypesLocked.

@VisibleForTesting
public static ArrayList<InputMethodSubtype> getImplicitlyApplicableSubtypesLocked(Resources res, InputMethodInfo imi) {
    final LocaleList systemLocales = res.getConfiguration().getLocales();
    synchronized (sCacheLock) {
        // it does not check if subtypes are also identical.
        if (systemLocales.equals(sCachedSystemLocales) && sCachedInputMethodInfo == imi) {
            return new ArrayList<>(sCachedResult);
        }
    }
    // Note: Only resource info in "res" is used in getImplicitlyApplicableSubtypesLockedImpl().
    // TODO: Refactor getImplicitlyApplicableSubtypesLockedImpl() so that it can receive
    // LocaleList rather than Resource.
    final ArrayList<InputMethodSubtype> result = getImplicitlyApplicableSubtypesLockedImpl(res, imi);
    synchronized (sCacheLock) {
        // Both LocaleList and InputMethodInfo are immutable. No need to copy them here.
        sCachedSystemLocales = systemLocales;
        sCachedInputMethodInfo = imi;
        sCachedResult = new ArrayList<>(result);
    }
    return result;
}
Also used : LocaleList(android.os.LocaleList) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ArrayList(java.util.ArrayList) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 74 with LocaleList

use of android.os.LocaleList in project android_frameworks_base by ResurrectionRemix.

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;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) LocaleList(android.os.LocaleList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 75 with LocaleList

use of android.os.LocaleList in project android_frameworks_base by ResurrectionRemix.

the class InputMethodUtilsTest method assertDefaultEnabledImes.

private void assertDefaultEnabledImes(final ArrayList<InputMethodInfo> preinstalledImes, final Locale systemLocale, final boolean isSystemReady, String... expectedImeNames) {
    final Context context = createTargetContextWithLocales(new LocaleList(systemLocale));
    final String[] actualImeNames = getPackageNames(InputMethodUtils.getDefaultEnabledImes(context, isSystemReady, preinstalledImes));
    assertEquals(expectedImeNames.length, actualImeNames.length);
    for (int i = 0; i < expectedImeNames.length; ++i) {
        assertEquals(expectedImeNames[i], actualImeNames[i]);
    }
}
Also used : Context(android.content.Context) LocaleList(android.os.LocaleList)

Aggregations

LocaleList (android.os.LocaleList)91 Locale (java.util.Locale)39 ArrayList (java.util.ArrayList)31 SmallTest (android.test.suitebuilder.annotation.SmallTest)15 Resources (android.content.res.Resources)10 KeyboardLayout (android.hardware.input.KeyboardLayout)10 SmallTest (android.support.test.filters.SmallTest)10 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)10 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 RemoteException (android.os.RemoteException)7 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 Context (android.content.Context)5 Config (android.content.pm.ActivityInfo.Config)5 NotFoundException (android.content.res.Resources.NotFoundException)5 TypedArray (android.content.res.TypedArray)5 XmlResourceParser (android.content.res.XmlResourceParser)5 Bundle (android.os.Bundle)5 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)5 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)5