android.os.LocaleList#isEmpty ( )源码实例Demo

下面列出了android.os.LocaleList#isEmpty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: EditorInfo.java
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;
}
 
源代码2 项目: android_9.0.0_r45   文件: TextClassifierImpl.java
/**
 * 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;
}
 
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();
}
 
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;
}
 
源代码5 项目: simple-keyboard   文件: EditorInfoCompatUtils.java
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;
}
 
源代码6 项目: px-android   文件: LocaleUtil.java
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();
}
 
源代码7 项目: android-galaxyzoo   文件: Singleton.java
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;
}