use of android.os.LocaleList in project android_frameworks_base by crdroidandroid.
the class ResourcesLocaleTest method testEnglishIsAlwaysConsideredSupported.
@SmallTest
public void testEnglishIsAlwaysConsideredSupported() throws Exception {
final Resources resources = createResourcesWithApk(R.raw.locales);
ensureNoLanguage(resources, "en");
final LocaleList preferredLocales = LocaleList.forLanguageTags("en-US,pl-PL");
final Configuration config = new Configuration();
config.setLocales(preferredLocales);
resources.updateConfiguration(config, null);
// The APK we loaded has default and Polish languages. If English is first in the list,
// always take it the default (assumed to be English).
assertEquals(Locale.forLanguageTag("en-US"), resources.getConfiguration().getLocales().get(0));
}
use of android.os.LocaleList in project android_frameworks_base by crdroidandroid.
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;
}
use of android.os.LocaleList in project android_frameworks_base by crdroidandroid.
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();
}
use of android.os.LocaleList in project android_frameworks_base by crdroidandroid.
the class ResourcesImpl method updateConfiguration.
public void updateConfiguration(Configuration config, DisplayMetrics metrics, CompatibilityInfo compat) {
Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesImpl#updateConfiguration");
try {
synchronized (mAccessLock) {
if (false) {
Slog.i(TAG, "**** Updating config of " + this + ": old config is " + mConfiguration + " old compat is " + mDisplayAdjustments.getCompatibilityInfo());
Slog.i(TAG, "**** Updating config of " + this + ": new config is " + config + " new compat is " + compat);
}
if (compat != null) {
mDisplayAdjustments.setCompatibilityInfo(compat);
}
if (metrics != null) {
mMetrics.setTo(metrics);
}
// NOTE: We should re-arrange this code to create a Display
// with the CompatibilityInfo that is used everywhere we deal
// with the display in relation to this app, rather than
// doing the conversion here. This impl should be okay because
// we make sure to return a compatible display in the places
// where there are public APIs to retrieve the display... but
// it would be cleaner and more maintainable to just be
// consistently dealing with a compatible display everywhere in
// the framework.
mDisplayAdjustments.getCompatibilityInfo().applyToDisplayMetrics(mMetrics);
@Config final int configChanges = calcConfigChanges(config);
// If even after the update there are no Locales set, grab the default locales.
LocaleList locales = mConfiguration.getLocales();
if (locales.isEmpty()) {
locales = LocaleList.getDefault();
mConfiguration.setLocales(locales);
}
if ((configChanges & ActivityInfo.CONFIG_LOCALE) != 0) {
if (locales.size() > 1) {
// The LocaleList has changed. We must query the AssetManager's available
// Locales and figure out the best matching Locale in the new LocaleList.
String[] availableLocales = mAssets.getNonSystemLocales();
if (LocaleList.isPseudoLocalesOnly(availableLocales)) {
// No app defined locales, so grab the system locales.
availableLocales = mAssets.getLocales();
if (LocaleList.isPseudoLocalesOnly(availableLocales)) {
availableLocales = null;
}
}
if (availableLocales != null) {
final Locale bestLocale = locales.getFirstMatchWithEnglishSupported(availableLocales);
if (bestLocale != null && bestLocale != locales.get(0)) {
mConfiguration.setLocales(new LocaleList(bestLocale, locales));
}
}
}
}
if (mConfiguration.densityDpi != Configuration.DENSITY_DPI_UNDEFINED) {
mMetrics.densityDpi = mConfiguration.densityDpi;
mMetrics.density = mConfiguration.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
}
mMetrics.scaledDensity = mMetrics.density * mConfiguration.fontScale;
final int width, height;
if (mMetrics.widthPixels >= mMetrics.heightPixels) {
width = mMetrics.widthPixels;
height = mMetrics.heightPixels;
} else {
//noinspection SuspiciousNameCombination
width = mMetrics.heightPixels;
//noinspection SuspiciousNameCombination
height = mMetrics.widthPixels;
}
final int keyboardHidden;
if (mConfiguration.keyboardHidden == Configuration.KEYBOARDHIDDEN_NO && mConfiguration.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
keyboardHidden = Configuration.KEYBOARDHIDDEN_SOFT;
} else {
keyboardHidden = mConfiguration.keyboardHidden;
}
mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc, adjustLanguageTag(mConfiguration.getLocales().get(0).toLanguageTag()), mConfiguration.orientation, mConfiguration.touchscreen, mConfiguration.densityDpi, mConfiguration.keyboard, keyboardHidden, mConfiguration.navigation, width, height, mConfiguration.smallestScreenWidthDp, mConfiguration.screenWidthDp, mConfiguration.screenHeightDp, mConfiguration.screenLayout, mConfiguration.uiMode, Build.VERSION.RESOURCES_SDK_INT);
if (DEBUG_CONFIG) {
Slog.i(TAG, "**** Updating config of " + this + ": final config is " + mConfiguration + " final compat is " + mDisplayAdjustments.getCompatibilityInfo());
}
mDrawableCache.onConfigurationChange(configChanges);
mColorDrawableCache.onConfigurationChange(configChanges);
mComplexColorCache.onConfigurationChange(configChanges);
mAnimatorCache.onConfigurationChange(configChanges);
mStateListAnimatorCache.onConfigurationChange(configChanges);
flushLayoutCache();
}
synchronized (sSync) {
if (mPluralRule != null) {
mPluralRule = PluralRules.forLocale(mConfiguration.getLocales().get(0));
}
}
} finally {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
}
}
use of android.os.LocaleList in project android_frameworks_base by crdroidandroid.
the class InputMethodManagerService method resetAllInternalStateLocked.
private void resetAllInternalStateLocked(final boolean updateOnlyWhenLocaleChanged, final boolean resetDefaultEnabledIme) {
if (!mSystemReady) {
// not system ready
return;
}
final LocaleList newLocales = mRes.getConfiguration().getLocales();
if (!updateOnlyWhenLocaleChanged || (newLocales != null && !newLocales.equals(mLastSystemLocales))) {
if (!updateOnlyWhenLocaleChanged) {
hideCurrentInputLocked(0, null);
resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_RESET_IME);
}
if (DEBUG) {
Slog.i(TAG, "LocaleList has been changed to " + newLocales);
}
buildInputMethodListLocked(resetDefaultEnabledIme);
if (!updateOnlyWhenLocaleChanged) {
final String selectedImiId = mSettings.getSelectedInputMethod();
if (TextUtils.isEmpty(selectedImiId)) {
// This is the first time of the user switch and
// set the current ime to the proper one.
resetDefaultImeLocked(mContext);
}
} else {
// If the locale is changed, needs to reset the default ime
resetDefaultImeLocked(mContext);
}
updateFromSettingsLocked(true);
mLastSystemLocales = newLocales;
if (!updateOnlyWhenLocaleChanged) {
try {
startInputInnerLocked();
} catch (RuntimeException e) {
Slog.w(TAG, "Unexpected exception", e);
}
}
}
}
Aggregations