Search in sources :

Example 96 with Locale

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);
}
Also used : Locale(java.util.Locale) IDelegate(com.android.speech.tts.MockableTextToSpeechService.IDelegate)

Example 97 with Locale

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;
}
Also used : Locale(java.util.Locale) Point(android.graphics.Point)

Example 98 with Locale

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;
}
Also used : Locale(java.util.Locale) Secure.getString(android.provider.Settings.Secure.getString)

Example 99 with Locale

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());
}
Also used : Locale(java.util.Locale) Configuration(android.content.res.Configuration)

Example 100 with Locale

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);
}
Also used : Locale(java.util.Locale) CommonProperties(org.glassfish.jersey.CommonProperties) LocalizationMessages(org.glassfish.jersey.internal.LocalizationMessages) Date(java.util.Date) Configuration(javax.ws.rs.core.Configuration) HashMap(java.util.HashMap) NewCookie(javax.ws.rs.core.NewCookie) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) MediaType(javax.ws.rs.core.MediaType) RuntimeDelegate(javax.ws.rs.ext.RuntimeDelegate) Locale(java.util.Locale) Map(java.util.Map) URI(java.net.URI) ParseException(java.text.ParseException) OutputStream(java.io.OutputStream) GenericEntity(javax.ws.rs.core.GenericEntity) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) EntityTag(javax.ws.rs.core.EntityTag) Collectors(java.util.stream.Collectors) ReflectionHelper(org.glassfish.jersey.internal.util.ReflectionHelper) Cookie(javax.ws.rs.core.Cookie) GenericType(javax.ws.rs.core.GenericType) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) ProcessingException(javax.ws.rs.ProcessingException) Collections(java.util.Collections) Link(javax.ws.rs.core.Link) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) RuntimeDelegate(javax.ws.rs.ext.RuntimeDelegate)

Aggregations

Locale (java.util.Locale)5854 Test (org.junit.Test)902 HashMap (java.util.HashMap)548 GenericValue (org.apache.ofbiz.entity.GenericValue)504 ArrayList (java.util.ArrayList)486 Delegator (org.apache.ofbiz.entity.Delegator)484 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)398 IOException (java.io.IOException)313 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)296 Date (java.util.Date)273 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)271 Map (java.util.Map)244 BigDecimal (java.math.BigDecimal)214 SimpleDateFormat (java.text.SimpleDateFormat)198 ResourceBundle (java.util.ResourceBundle)197 File (java.io.File)166 LinkedList (java.util.LinkedList)158 ULocale (android.icu.util.ULocale)156 List (java.util.List)147 Test (org.junit.jupiter.api.Test)132