Search in sources :

Example 81 with LocaleList

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

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)

Example 82 with LocaleList

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

the class LocaleUtilsTest method testFilterDoesNotMatchAnything.

@SmallTest
public void testFilterDoesNotMatchAnything() throws Exception {
    final ArrayList<Locale> availableLocales = new ArrayList<>();
    availableLocales.add(Locale.forLanguageTag("en-US"));
    availableLocales.add(Locale.forLanguageTag("fr-CA"));
    availableLocales.add(Locale.forLanguageTag("in"));
    availableLocales.add(Locale.forLanguageTag("ja"));
    availableLocales.add(Locale.forLanguageTag("fil"));
    final LocaleList preferredLocales = LocaleList.forLanguageTags("zh-Hans-TW");
    final ArrayList<Locale> dest = new ArrayList<>();
    LocaleUtils.filterByLanguage(availableLocales, sIdentityMapper, preferredLocales, dest);
    assertEquals(0, dest.size());
}
Also used : Locale(java.util.Locale) LocaleList(android.os.LocaleList) ArrayList(java.util.ArrayList) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 83 with LocaleList

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

the class InputMethodManagerService method resetAllInternalStateLocked.

private void resetAllInternalStateLocked(final boolean updateOnlyWhenLocaleChanged, final boolean resetDefaultEnabledIme) {
    if (!mSystemReady) {
        // not system ready
        return;
    }
    final LocaleList newLocales = mRes.getConfiguration().getLocales();
    if (!updateOnlyWhenLocaleChanged || (newLocales != null && !newLocales.equals(mLastSystemLocales))) {
        if (!updateOnlyWhenLocaleChanged) {
            hideCurrentInputLocked(0, null);
            resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_RESET_IME);
        }
        if (DEBUG) {
            Slog.i(TAG, "LocaleList has been changed to " + newLocales);
        }
        buildInputMethodListLocked(resetDefaultEnabledIme);
        if (!updateOnlyWhenLocaleChanged) {
            final String selectedImiId = mSettings.getSelectedInputMethod();
            if (TextUtils.isEmpty(selectedImiId)) {
                // This is the first time of the user switch and
                // set the current ime to the proper one.
                resetDefaultImeLocked(mContext);
            }
        } else {
            // If the locale is changed, needs to reset the default ime
            resetDefaultImeLocked(mContext);
        }
        updateFromSettingsLocked(true);
        mLastSystemLocales = newLocales;
        if (!updateOnlyWhenLocaleChanged) {
            try {
                startInputInnerLocked();
            } catch (RuntimeException e) {
                Slog.w(TAG, "Unexpected exception", e);
            }
        }
    }
}
Also used : LocaleList(android.os.LocaleList)

Example 84 with LocaleList

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

the class LocalePickerWithRegion method setListener.

/**
     * Sets the listener and initializes the locale list.
     *
     * <p>Returns true if we need to show the list, false if not.</p>
     *
     * <p>Can return false because of an error, trying to show a list of countries,
     * but no parent locale was provided.</p>
     *
     * <p>It can also return false if the caller tries to show the list in country mode and
     * there is only one country available (i.e. Japanese => Japan).
     * In this case we don't even show the list, we call the listener with that locale,
     * "pretending" it was selected, and return false.</p>
     */
private boolean setListener(Context context, LocaleSelectedListener listener, LocaleStore.LocaleInfo parent, boolean translatedOnly) {
    this.mParentLocale = parent;
    this.mListener = listener;
    this.mTranslatedOnly = translatedOnly;
    setRetainInstance(true);
    final HashSet<String> langTagsToIgnore = new HashSet<>();
    if (!translatedOnly) {
        final LocaleList userLocales = LocalePicker.getLocales();
        final String[] langTags = userLocales.toLanguageTags().split(",");
        Collections.addAll(langTagsToIgnore, langTags);
    }
    if (parent != null) {
        mLocaleList = LocaleStore.getLevelLocales(context, langTagsToIgnore, parent, translatedOnly);
        if (mLocaleList.size() <= 1) {
            if (listener != null && (mLocaleList.size() == 1)) {
                listener.onLocaleSelected(mLocaleList.iterator().next());
            }
            return false;
        }
    } else {
        mLocaleList = LocaleStore.getLevelLocales(context, langTagsToIgnore, null, /* no parent */
        translatedOnly);
    }
    return true;
}
Also used : LocaleList(android.os.LocaleList) HashSet(java.util.HashSet)

Example 85 with LocaleList

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

the class InputManagerService method getDefaultKeyboardLayout.

private String getDefaultKeyboardLayout(final InputDevice d) {
    final Locale systemLocale = mContext.getResources().getConfiguration().locale;
    // reasonable default.
    if (TextUtils.isEmpty(systemLocale.getLanguage())) {
        return null;
    }
    final List<KeyboardLayout> layouts = new ArrayList<>();
    visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {

        @Override
        public void visitKeyboardLayout(Resources resources, int keyboardLayoutResId, KeyboardLayout layout) {
            // means its a custom layout for a specific keyboard.
            if (layout.getVendorId() != d.getVendorId() || layout.getProductId() != d.getProductId()) {
                return;
            }
            final LocaleList locales = layout.getLocales();
            final int numLocales = locales.size();
            for (int localeIndex = 0; localeIndex < numLocales; ++localeIndex) {
                if (isCompatibleLocale(systemLocale, locales.get(localeIndex))) {
                    layouts.add(layout);
                    break;
                }
            }
        }
    });
    if (layouts.isEmpty()) {
        return null;
    }
    // First sort so that ones with higher priority are listed at the top
    Collections.sort(layouts);
    // Next we want to try to find an exact match of language, country and variant.
    final int N = layouts.size();
    for (int i = 0; i < N; i++) {
        KeyboardLayout layout = layouts.get(i);
        final LocaleList locales = layout.getLocales();
        final int numLocales = locales.size();
        for (int localeIndex = 0; localeIndex < numLocales; ++localeIndex) {
            final Locale locale = locales.get(localeIndex);
            if (locale.getCountry().equals(systemLocale.getCountry()) && locale.getVariant().equals(systemLocale.getVariant())) {
                return layout.getDescriptor();
            }
        }
    }
    // Then try an exact match of language and country
    for (int i = 0; i < N; i++) {
        KeyboardLayout layout = layouts.get(i);
        final LocaleList locales = layout.getLocales();
        final int numLocales = locales.size();
        for (int localeIndex = 0; localeIndex < numLocales; ++localeIndex) {
            final Locale locale = locales.get(localeIndex);
            if (locale.getCountry().equals(systemLocale.getCountry())) {
                return layout.getDescriptor();
            }
        }
    }
    // Give up and just use the highest priority layout with matching language
    return layouts.get(0).getDescriptor();
}
Also used : Locale(java.util.Locale) LocaleList(android.os.LocaleList) ArrayList(java.util.ArrayList) KeyboardLayout(android.hardware.input.KeyboardLayout) Resources(android.content.res.Resources)

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