use of java.util.Locale in project android_frameworks_base by ParanoidAndroid.
the class TextToSpeechTests method testGetLanguage_validReturnValues.
public void testGetLanguage_validReturnValues() {
IDelegate delegate = LittleMock.mock(IDelegate.class);
MockableTextToSpeechService.setMocker(delegate);
// A correct value.
LittleMock.doReturn(new String[] { "eng", "usa", "" }).when(delegate).onGetLanguage();
Locale returnVal = mTts.getLanguage();
// Note: This is not the same as Locale.US . Well tough luck for
// being the only component of the entire framework that standardized
// three letter country and language codes.
assertEquals(new Locale("eng", "USA", ""), returnVal);
}
use of java.util.Locale in project android_frameworks_base by ParanoidAndroid.
the class Configuration method updateFrom.
/**
* Copy the fields from delta into this Configuration object, keeping
* track of which ones have changed. Any undefined fields in
* <var>delta</var> are ignored and not copied in to the current
* Configuration.
* @return Returns a bit mask of the changed fields, as per
* {@link #diff}.
*/
public int updateFrom(Configuration delta) {
int changed = 0;
if (delta.fontScale > 0 && fontScale != delta.fontScale) {
changed |= ActivityInfo.CONFIG_FONT_SCALE;
fontScale = delta.fontScale;
}
if (delta.mcc != 0 && mcc != delta.mcc) {
changed |= ActivityInfo.CONFIG_MCC;
mcc = delta.mcc;
}
if (delta.mnc != 0 && mnc != delta.mnc) {
changed |= ActivityInfo.CONFIG_MNC;
mnc = delta.mnc;
}
if (delta.locale != null && (locale == null || !locale.equals(delta.locale))) {
changed |= ActivityInfo.CONFIG_LOCALE;
locale = delta.locale != null ? (Locale) delta.locale.clone() : null;
// If locale has changed, then layout direction is also changed ...
changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
// ... and we need to update the layout direction (represented by the first
// 2 most significant bits in screenLayout).
setLayoutDirection(locale);
}
if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0))) {
userSetLocale = true;
changed |= ActivityInfo.CONFIG_LOCALE;
}
if (delta.touchscreen != TOUCHSCREEN_UNDEFINED && touchscreen != delta.touchscreen) {
changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
touchscreen = delta.touchscreen;
}
if (delta.keyboard != KEYBOARD_UNDEFINED && keyboard != delta.keyboard) {
changed |= ActivityInfo.CONFIG_KEYBOARD;
keyboard = delta.keyboard;
}
if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED && keyboardHidden != delta.keyboardHidden) {
changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
keyboardHidden = delta.keyboardHidden;
}
if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED && hardKeyboardHidden != delta.hardKeyboardHidden) {
changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
hardKeyboardHidden = delta.hardKeyboardHidden;
}
if (delta.navigation != NAVIGATION_UNDEFINED && navigation != delta.navigation) {
changed |= ActivityInfo.CONFIG_NAVIGATION;
navigation = delta.navigation;
}
if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED && navigationHidden != delta.navigationHidden) {
changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
navigationHidden = delta.navigationHidden;
}
if (delta.orientation != ORIENTATION_UNDEFINED && orientation != delta.orientation) {
changed |= ActivityInfo.CONFIG_ORIENTATION;
orientation = delta.orientation;
}
if (getScreenLayoutNoDirection(delta.screenLayout) != (SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED) && (getScreenLayoutNoDirection(screenLayout) != getScreenLayoutNoDirection(delta.screenLayout))) {
changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
// We need to preserve the previous layout dir bits if they were defined
if ((delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK) == 0) {
screenLayout = (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK) | delta.screenLayout;
} else {
screenLayout = delta.screenLayout;
}
}
if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED | UI_MODE_NIGHT_UNDEFINED) && uiMode != delta.uiMode) {
changed |= ActivityInfo.CONFIG_UI_MODE;
if ((delta.uiMode & UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) {
uiMode = (uiMode & ~UI_MODE_TYPE_MASK) | (delta.uiMode & UI_MODE_TYPE_MASK);
}
if ((delta.uiMode & UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) {
uiMode = (uiMode & ~UI_MODE_NIGHT_MASK) | (delta.uiMode & UI_MODE_NIGHT_MASK);
}
}
if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED && screenWidthDp != delta.screenWidthDp) {
changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
screenWidthDp = delta.screenWidthDp;
}
if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED && screenHeightDp != delta.screenHeightDp) {
changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
screenHeightDp = delta.screenHeightDp;
}
if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED && smallestScreenWidthDp != delta.smallestScreenWidthDp) {
changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
smallestScreenWidthDp = delta.smallestScreenWidthDp;
}
if (delta.densityDpi != DENSITY_DPI_UNDEFINED && densityDpi != delta.densityDpi) {
changed |= ActivityInfo.CONFIG_DENSITY;
densityDpi = delta.densityDpi;
}
if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
compatScreenWidthDp = delta.compatScreenWidthDp;
}
if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
compatScreenHeightDp = delta.compatScreenHeightDp;
}
if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp;
}
if (delta.seq != 0) {
seq = delta.seq;
}
if (delta.customTheme != null && (customTheme == null || !customTheme.equals(delta.customTheme))) {
changed |= ActivityInfo.CONFIG_THEME_RESOURCE;
customTheme = (CustomTheme) delta.customTheme.clone();
}
return changed;
}
use of java.util.Locale in project android_frameworks_base by ParanoidAndroid.
the class TtsEngines method getDefaultLocale.
private String getDefaultLocale() {
final Locale locale = Locale.getDefault();
// Note that the default locale might have an empty variant
// or language, and we take care that the construction is
// the same as {@link #getV1Locale} i.e no trailing delimiters
// or spaces.
String defaultLocale = locale.getISO3Language();
if (TextUtils.isEmpty(defaultLocale)) {
Log.w(TAG, "Default locale is empty.");
return "";
}
if (!TextUtils.isEmpty(locale.getISO3Country())) {
defaultLocale += LOCALE_DELIMITER + locale.getISO3Country();
} else {
// an empty country.
return defaultLocale;
}
if (!TextUtils.isEmpty(locale.getVariant())) {
defaultLocale += LOCALE_DELIMITER + locale.getVariant();
}
return defaultLocale;
}
use of java.util.Locale in project android_frameworks_base by ParanoidAndroid.
the class OverlayBaseTest method setLocale.
private void setLocale(String code) {
Locale locale = new Locale(code);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
mResources.updateConfiguration(config, mResources.getDisplayMetrics());
}
use of java.util.Locale in project jersey by jersey.
the class OutboundMessageContext method getAcceptableLanguages.
/**
* Get a list of languages that are acceptable for the message.
*
* @return a read-only list of acceptable languages sorted according
* to their q-value, with highest preference first.
*/
public List<Locale> getAcceptableLanguages() {
final List<Object> values = headers.get(HttpHeaders.ACCEPT_LANGUAGE);
if (values == null || values.isEmpty()) {
return Collections.singletonList(new AcceptableLanguageTag("*", null).getAsLocale());
}
final List<Locale> result = new ArrayList<Locale>(values.size());
final RuntimeDelegate rd = RuntimeDelegate.getInstance();
boolean conversionApplied = false;
for (final Object value : values) {
if (value instanceof Locale) {
result.add((Locale) value);
} else {
conversionApplied = true;
try {
result.addAll(HttpHeaderReader.readAcceptLanguage(HeaderUtils.asString(value, rd)).stream().map(LanguageTag::getAsLocale).collect(Collectors.toList()));
} catch (java.text.ParseException e) {
throw exception(HttpHeaders.ACCEPT_LANGUAGE, value, e);
}
}
}
if (conversionApplied) {
// cache converted
headers.put(HttpHeaders.ACCEPT_LANGUAGE, result.stream().map((Function<Locale, Object>) locale -> locale).collect(Collectors.toList()));
}
return Collections.unmodifiableList(result);
}
Aggregations