Search in sources :

Example 66 with LocaleList

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

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 67 with LocaleList

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

the class Paint method setTextLocale.

/**
     * Set the text locale list to a one-member list consisting of just the locale.
     *
     * See {@link #setTextLocales(LocaleList)} for how the locale list affects
     * the way the text is drawn for some languages.
     *
     * @param locale the paint's locale value for drawing text, must not be null.
     */
public void setTextLocale(@NonNull Locale locale) {
    if (locale == null) {
        throw new IllegalArgumentException("locale cannot be null");
    }
    if (mLocales != null && mLocales.size() == 1 && locale.equals(mLocales.get(0))) {
        return;
    }
    mLocales = new LocaleList(locale);
    syncTextLocalesWithMinikin();
}
Also used : LocaleList(android.os.LocaleList)

Example 68 with LocaleList

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

the class LocaleUtilsTest method testFilterByLanguageEmptySource.

@SmallTest
public void testFilterByLanguageEmptySource() throws Exception {
    final ArrayList<Locale> availableLocales = new ArrayList<>();
    final LocaleList preferredLocales = LocaleList.forLanguageTags("fr,en-US,ja-JP");
    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 69 with LocaleList

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

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 70 with LocaleList

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

the class Paint method setTextLocale.

/**
     * Set the text locale list to a one-member list consisting of just the locale.
     *
     * See {@link #setTextLocales(LocaleList)} for how the locale list affects
     * the way the text is drawn for some languages.
     *
     * @param locale the paint's locale value for drawing text, must not be null.
     */
public void setTextLocale(@NonNull Locale locale) {
    if (locale == null) {
        throw new IllegalArgumentException("locale cannot be null");
    }
    if (mLocales != null && mLocales.size() == 1 && locale.equals(mLocales.get(0))) {
        return;
    }
    mLocales = new LocaleList(locale);
    syncTextLocalesWithMinikin();
}
Also used : 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