Java Code Examples for android.os.LocaleList#isEmpty()

The following examples show how to use android.os.LocaleList#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorInfo.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public EditorInfo createFromParcel(Parcel source) {
    EditorInfo res = new EditorInfo();
    res.inputType = source.readInt();
    res.imeOptions = source.readInt();
    res.privateImeOptions = source.readString();
    res.actionLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
    res.actionId = source.readInt();
    res.initialSelStart = source.readInt();
    res.initialSelEnd = source.readInt();
    res.initialCapsMode = source.readInt();
    res.hintText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
    res.label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
    res.packageName = source.readString();
    res.fieldId = source.readInt();
    res.fieldName = source.readString();
    res.extras = source.readBundle();
    LocaleList hintLocales = LocaleList.CREATOR.createFromParcel(source);
    res.hintLocales = hintLocales.isEmpty() ? null : hintLocales;
    res.contentMimeTypes = source.readStringArray();
    return res;
}
 
Example 2
Source File: TextClassifierImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the most appropriate model to use for the given target locale list.
 *
 * The basic logic is: we ignore all models that don't support any of the target locales. For
 * the remaining candidates, we take the update model unless its version number is lower than
 * the factory version. It's assumed that factory models do not have overlapping locale ranges
 * and conflict resolution between these models hence doesn't matter.
 */
@GuardedBy("mLock") // Do not call outside this lock.
@Nullable
private ModelFile findBestModelLocked(LocaleList localeList) {
    // Specified localeList takes priority over the system default, so it is listed first.
    final String languages = localeList.isEmpty()
            ? LocaleList.getDefault().toLanguageTags()
            : localeList.toLanguageTags() + "," + LocaleList.getDefault().toLanguageTags();
    final List<Locale.LanguageRange> languageRangeList = Locale.LanguageRange.parse(languages);

    ModelFile bestModel = null;
    for (ModelFile model : listAllModelsLocked()) {
        if (model.isAnyLanguageSupported(languageRangeList)) {
            if (model.isPreferredTo(bestModel)) {
                bestModel = model;
            }
        }
    }
    return bestModel;
}
 
Example 3
Source File: DefaultAndroidEventProcessor.java    From sentry-android with MIT License 5 votes vote down vote up
private TimeZone getTimeZone() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    LocaleList locales = context.getResources().getConfiguration().getLocales();
    if (!locales.isEmpty()) {
      Locale locale = locales.get(0);
      return Calendar.getInstance(locale).getTimeZone();
    }
  }
  return Calendar.getInstance().getTimeZone();
}
 
Example 4
Source File: EditorInfoCompatUtils.java    From LokiBoard-Android-Keylogger with Apache License 2.0 5 votes vote down vote up
public static Locale getPrimaryHintLocale(final EditorInfo editorInfo) {
    if (editorInfo == null) {
        return null;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        LocaleList localeList = editorInfo.hintLocales;
        if (localeList != null && !localeList.isEmpty())
            return localeList.get(0);
    }
    return null;
}
 
Example 5
Source File: EditorInfoCompatUtils.java    From simple-keyboard with Apache License 2.0 5 votes vote down vote up
public static Locale getPrimaryHintLocale(final EditorInfo editorInfo) {
    if (editorInfo == null) {
        return null;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        LocaleList localeList = editorInfo.hintLocales;
        if (localeList != null && !localeList.isEmpty())
            return localeList.get(0);
    }
    return null;
}
 
Example 6
Source File: LocaleUtil.java    From px-android with MIT License 5 votes vote down vote up
public static String getLanguage(@NonNull final Context context) {
    final Configuration configuration = context.getResources().getConfiguration();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        final LocaleList locales = configuration.getLocales();
        if (!locales.isEmpty()) {
            return locales.get(0).toLanguageTag();
        }
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return configuration.locale.toLanguageTag();
    }
    return configuration.locale.getLanguage();
}
 
Example 7
Source File: Singleton.java    From android-galaxyzoo with GNU General Public License v3.0 5 votes vote down vote up
private static LocaleDetails getLocaleDetails(final Context context) {
    final Configuration config = context.getResources().getConfiguration();
    if (config == null) {
        return null;
    }

    Locale locale = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        final LocaleList locales = config.getLocales();
        if (locales == null || locales.isEmpty()) {
            return null;
        }

        locale = locales.get(0);
    } else {
        //noinspection deprecation
        locale = config.locale;
    }

    if (locale == null) {
        return null;
    }

    final LocaleDetails result = new LocaleDetails();
    result.language = locale.getLanguage();

    //The Galaxy zoo files, such as ch_cn.json are lowercase, instead of having the
    //country code in uppercase, such as ch_CN, like normal system locales.
    final String country = locale.getCountry();
    if (!TextUtils.isEmpty(country)) {
        result.countryCode = country.toLowerCase(new Locale(Utils.STRING_LANGUAGE));
    }

    return result;
}