Java Examples for android.os.LocaleList
The following java examples will help you to understand the usage of android.os.LocaleList. These source code samples are taken from different open source projects.
Example 1
| Project: platform_frameworks_base-master File: Paint.java View source code |
/** Restores the paint to its default settings. */
public void reset() {
nReset(mNativePaint);
setFlags(HIDDEN_DEFAULT_PAINT_FLAGS);
// TODO: Turning off hinting has undesirable side effects, we need to
// revisit hinting once we add support for subpixel positioning
// setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
// ? HINTING_OFF : HINTING_ON);
mColorFilter = null;
mMaskFilter = null;
mPathEffect = null;
mRasterizer = null;
mShader = null;
mNativeShader = 0;
mTypeface = null;
mNativeTypeface = 0;
mXfermode = null;
mHasCompatScaling = false;
mCompatScaling = 1;
mInvCompatScaling = 1;
mBidiFlags = BIDI_DEFAULT_LTR;
setTextLocales(LocaleList.getAdjustedDefault());
setElegantTextHeight(false);
mFontFeatureSettings = null;
}Example 2
| Project: wallpaperboard-master File: LocaleHelper.java View source code |
public static void setLocale(@NonNull Context context) {
Locale locale = Preferences.get(context).getCurrentLocale();
Locale.setDefault(locale);
Configuration configuration = context.getResources().getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
LocaleList.setDefault(new LocaleList(locale));
configuration.setLocales(new LocaleList(locale));
configuration.setLocale(locale);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
configuration.setLocale(locale);
} else {
configuration.locale = locale;
}
//Todo:
// Find out a solution to use context.createConfigurationContext(configuration);
// It breaks onConfigurationChanged()
// Still can't find a way to fix that
// No other options, better use deprecated code for now
context.getResources().updateConfiguration(configuration, context.getResources().getDisplayMetrics());
}Example 3
| Project: apps-android-wikipedia-master File: ResourceUtil.java View source code |
private static void setConfigLocale(@NonNull Configuration config, @NonNull Locale... locales) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
config.setLocales(new LocaleList(locales));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLocale(locales[0]);
config.setLayoutDirection(locales[0]);
} else {
//noinspection deprecation
config.locale = locales[0];
}
}Example 4
| Project: packages_apps_settings-master File: ManageApplications.java View source code |
private void rebuildSections() {
if (mEntries != null && mManageApplications.mListView.isFastScrollEnabled()) {
// Rebuild sections
if (mIndex == null) {
LocaleList locales = mContext.getResources().getConfiguration().getLocales();
if (locales.size() == 0) {
locales = new LocaleList(Locale.ENGLISH);
}
AlphabeticIndex<Locale> index = new AlphabeticIndex<>(locales.get(0));
int localeCount = locales.size();
for (int i = 1; i < localeCount; i++) {
index.addLabels(locales.get(i));
}
// Ensure we always have some base English locale buckets
index.addLabels(Locale.ENGLISH);
mIndex = index.buildImmutableIndex();
}
ArrayList<SectionInfo> sections = new ArrayList<>();
int lastSecId = -1;
int totalEntries = mEntries.size();
mPositionToSectionIndex = new int[totalEntries];
for (int pos = 0; pos < totalEntries; pos++) {
String label = mEntries.get(pos).label;
int secId = mIndex.getBucketIndex(TextUtils.isEmpty(label) ? "" : label);
if (secId != lastSecId) {
lastSecId = secId;
sections.add(new SectionInfo(mIndex.getBucket(secId).getLabel(), pos));
}
mPositionToSectionIndex[pos] = sections.size() - 1;
}
mSections = sections.toArray(EMPTY_SECTIONS);
} else {
mSections = EMPTY_SECTIONS;
mPositionToSectionIndex = null;
}
}Example 5
| Project: android-galaxyzoo-master File: Singleton.java View source code |
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;
}Example 6
| Project: platform_packages_providers_contactsprovider-master File: ContactLocaleUtils.java View source code |
static List<Locale> getLocalesForBuckets(LocaleSet systemLocales) {
// Create a list of locales that should be used to generate the index buckets.
// - Source: the system locales and sDefaultLabelLocales.
// - Rules:
// - Don't add the same locale multiple times.
// - Also special rules for Chinese (b/31115382):
// - Don't add multiple Chinese locales.
// - Don't add any Chinese locales after Japanese.
// First, collect all the locales (allowing duplicates).
final LocaleList localeList = systemLocales.getAllLocales();
final List<Locale> locales = new ArrayList<>(localeList.size() + sDefaultLabelLocales.length);
for (int i = 0; i < localeList.size(); i++) {
locales.add(localeList.get(i));
}
for (int i = 0; i < sDefaultLabelLocales.length; i++) {
locales.add(sDefaultLabelLocales[i]);
}
// Then apply the rules to generate the final list.
final List<Locale> ret = new ArrayList<>(locales.size());
boolean allowChinese = true;
for (int i = 0; i < locales.size(); i++) {
final Locale locale = locales.get(i);
if (ret.contains(locale)) {
continue;
}
if (LocaleSet.isLanguageChinese(locale)) {
if (!allowChinese) {
continue;
}
allowChinese = false;
}
if (LocaleSet.isLanguageJapanese(locale)) {
allowChinese = false;
}
if (DEBUG) {
Log.d(TAG, " Adding locale: " + locale.toLanguageTag());
}
ret.add(locale);
}
return ret;
}Example 7
| Project: android_frameworks_base-master File: Paint.java View source code |
/** Restores the paint to its default settings. */
public void reset() {
nReset(mNativePaint);
setFlags(HIDDEN_DEFAULT_PAINT_FLAGS);
// TODO: Turning off hinting has undesirable side effects, we need to
// revisit hinting once we add support for subpixel positioning
// setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
// ? HINTING_OFF : HINTING_ON);
mColorFilter = null;
mMaskFilter = null;
mPathEffect = null;
mRasterizer = null;
mShader = null;
mNativeShader = 0;
mTypeface = null;
mNativeTypeface = 0;
mXfermode = null;
mHasCompatScaling = false;
mCompatScaling = 1;
mInvCompatScaling = 1;
mBidiFlags = BIDI_DEFAULT_LTR;
setTextLocales(LocaleList.getAdjustedDefault());
setElegantTextHeight(false);
mFontFeatureSettings = null;
}Example 8
| Project: platform_packages_apps_settings-master File: ManageApplications.java View source code |
private void rebuildSections() {
if (mEntries != null && mManageApplications.mListView.isFastScrollEnabled()) {
// Rebuild sections
if (mIndex == null) {
LocaleList locales = mContext.getResources().getConfiguration().getLocales();
if (locales.size() == 0) {
locales = new LocaleList(Locale.ENGLISH);
}
AlphabeticIndex<Locale> index = new AlphabeticIndex<>(locales.get(0));
int localeCount = locales.size();
for (int i = 1; i < localeCount; i++) {
index.addLabels(locales.get(i));
}
// Ensure we always have some base English locale buckets
index.addLabels(Locale.ENGLISH);
mIndex = index.buildImmutableIndex();
}
ArrayList<SectionInfo> sections = new ArrayList<>();
int lastSecId = -1;
int totalEntries = mEntries.size();
mPositionToSectionIndex = new int[totalEntries];
for (int pos = 0; pos < totalEntries; pos++) {
String label = mEntries.get(pos).label;
int secId = mIndex.getBucketIndex(TextUtils.isEmpty(label) ? "" : label);
if (secId != lastSecId) {
lastSecId = secId;
sections.add(new SectionInfo(mIndex.getBucket(secId).getLabel(), pos));
}
mPositionToSectionIndex[pos] = sections.size() - 1;
}
mSections = sections.toArray(EMPTY_SECTIONS);
} else {
mSections = EMPTY_SECTIONS;
mPositionToSectionIndex = null;
}
}Example 9
| Project: androidbible-master File: ConfigurationWrapper.java View source code |
@Nullable
public static Locale getLocale(Configuration config) {
if (Build.VERSION.SDK_INT >= 24) {
final LocaleList locales = config.getLocales();
if (locales.size() > 0) {
return locales.get(0);
} else {
return null;
}
} else {
return config.locale;
}
}