get ( )源码实例Demo

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

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

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();
}
 
源代码2 项目: enterprise-samples   文件: CompatUtils.java
/**
 * Retrieves the primary locale from the specified {@link Configuration}.
 *
 * @param configuration The current {@link Configuration}.
 * @return The primary locale.
 */
public static Locale getPrimaryLocale(Configuration configuration) {
    if (Build.VERSION.SDK_INT >= 24) {
        final LocaleList locales = configuration.getLocales();
        if (locales.size() > 0) {
            return locales.get(0);
        }
    }
    //noinspection deprecation
    return configuration.locale;
}
 
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;
}
 
@NonNull
private static Locale chooseAvailableLocale(@NonNull LocaleList localeList) {
    for (int i = 0; i < localeList.size(); i++) {
        final Locale locale = localeList.get(i);
        if (sEditActionTextFormats.containsKey(locale)) {
            return locale;
        }
        for (Locale loc : sEditActionTextFormats.keySet()) {
            if (loc.getLanguage().equals(locale.getLanguage())) {
                return loc;
            }
        }
    }
    return Locale.ENGLISH;
}
 
源代码5 项目: LaunchEnr   文件: AlphabeticIndexCompat.java
AlphabeticIndexVN(Context context) {
    LocaleList locales = context.getResources().getConfiguration().getLocales();
    int localeCount = locales.size();

    Locale primaryLocale = localeCount == 0 ? Locale.ENGLISH : locales.get(0);
    AlphabeticIndex indexBuilder = new AlphabeticIndex(primaryLocale);
    for (int i = 1; i < localeCount; i++) {
        indexBuilder.addLabels(locales.get(i));
    }
    indexBuilder.addLabels(Locale.ENGLISH);

    mAlphabeticIndex = indexBuilder.buildImmutableIndex();
}
 
源代码6 项目: 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;
}
 
源代码7 项目: 365browser   文件: DateTimePickerDialog.java
private Locale getLocale() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        LocaleList locales = getConfiguration().getLocales();
        if (locales.size() > 0) {
            return locales.get(0);
        }
    }
    return getConfiguration().locale;
}
 
源代码8 项目: android-NfcProvisioning   文件: CompatUtils.java
/**
 * Retrieves the primary locale from the specified {@link Configuration}.
 *
 * @param configuration The current {@link Configuration}.
 * @return The primary locale.
 */
public static Locale getPrimaryLocale(Configuration configuration) {
    if (Build.VERSION.SDK_INT >= 24) {
        final LocaleList locales = configuration.getLocales();
        if (locales.size() > 0) {
            return locales.get(0);
        }
    }
    //noinspection deprecation
    return configuration.locale;
}
 
源代码9 项目: 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;
}
 
源代码10 项目: android_9.0.0_r45   文件: Configuration.java
/**
 *
 * @hide
 */
public static String localesToResourceQualifier(LocaleList locs) {
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < locs.size(); i++) {
        final Locale loc = locs.get(i);
        final int l = loc.getLanguage().length();
        if (l == 0) {
            continue;
        }
        final int s = loc.getScript().length();
        final int c = loc.getCountry().length();
        final int v = loc.getVariant().length();
        // We ignore locale extensions, since they are not supported by AAPT

        if (sb.length() != 0) {
            sb.append(",");
        }
        if (l == 2 && s == 0 && (c == 0 || c == 2) && v == 0) {
            // Traditional locale format: xx or xx-rYY
            sb.append(loc.getLanguage());
            if (c == 2) {
                sb.append("-r").append(loc.getCountry());
            }
        } else {
            sb.append("b+");
            sb.append(loc.getLanguage());
            if (s != 0) {
                sb.append("+");
                sb.append(loc.getScript());
            }
            if (c != 0) {
                sb.append("+");
                sb.append(loc.getCountry());
            }
            if (v != 0) {
                sb.append("+");
                sb.append(loc.getVariant());
            }
        }
    }
    return sb.toString();
}
 
源代码评论
动弹
沙发等你来抢
 方法所在类