Example usage for java.util Locale setDefault

List of usage examples for java.util Locale setDefault

Introduction

In this page you can find the example usage for java.util Locale setDefault.

Prototype

public static synchronized void setDefault(Locale newLocale) 

Source Link

Document

Sets the default locale for this instance of the Java Virtual Machine.

Usage

From source file:com.example.adbird.MenuTabActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_menu);//from w w  w  .  j  a v a 2  s. c om
    mContext = this.getApplicationContext();

    SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
    String lang = prefs.getString("lang", null);
    Locale locale = new Locale(lang);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    SpannableString s = new SpannableString(mContext.getResources().getString(R.string.ads_title));
    s.setSpan(new TypefaceSpan(this, "GothaProReg.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setTitle(s);
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);

            SpannableString s = new SpannableString(mAppSectionsPagerAdapter.getPageTitle(position));
            s.setSpan(new TypefaceSpan(getApplicationContext(), "GothaProReg.otf"), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            actionBar.setTitle(s);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setIcon(mAppSectionsPagerAdapter.getPageIcon(i)).setTabListener(this));

    }

}

From source file:edu.mit.ll.dcds.android.AboutActivity.java

private void setLocale() {
    Locale locale = DataManager.getInstance().getLocale();
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    Resources res = getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    config.locale = locale;/*from  w w  w  .j a v  a2s. c  om*/

    res.updateConfiguration(config, dm);
}

From source file:org.opendatakit.utilities.LocalizationUtilsTest.java

@Test
public void testNormalizeDisplayName() throws JsonProcessingException {
    Map<String, Object> langMap = new TreeMap<String, Object>();
    langMap.put("en_US", "This is a test");
    langMap.put("en_GB", "Test is This");
    langMap.put("en", "Huh Test");
    langMap.put("fr", "Je suis");
    langMap.put("default", "No way!");
    Map<String, Object> topMap = new TreeMap<String, Object>();
    topMap.put("text", langMap);
    String value = ODKFileUtils.mapper.writeValueAsString(topMap);

    Locale defaultLocale;//from  w  w w.ja  v a  2s. c  o m
    String full_locale;
    String match;

    Locale.setDefault(Locale.US);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("This is a test", match);

    Locale.setDefault(Locale.UK);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("Test is This", match);

    Locale.setDefault(Locale.CANADA);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("Huh Test", match);

    Locale.setDefault(Locale.CANADA_FRENCH);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("Je suis", match);

    Locale.setDefault(Locale.GERMANY);
    defaultLocale = Locale.getDefault();
    full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value);
    assertEquals("No way!", match);

    Locale.setDefault(Locale.US);
}

From source file:de.grobox.transportr.TransportrActivity.java

private void useLanguage() {
    Locale locale = settingsManager.getLocale();
    Locale.setDefault(locale);
    Configuration config = getResources().getConfiguration();
    config.locale = locale;//from  w  w  w .  j  a  v a 2 s  . com
    getResources().updateConfiguration(config, getResources().getDisplayMetrics());
}

From source file:com.iisigroup.cap.message.CapReloadableResourceBundleMessageSource.java

@Override
public void afterPropertiesSet() throws Exception {
    Set<String> l = new HashSet<String>();
    String i18nPattern = basePath + "/**/*.properties";
    String i18nFileREG = "(" + StringUtils.join(languages, '|') + ").properties$";
    if (defaultLocale != null) {/* w w  w .  j  a  v  a  2s. c o m*/
        Locale.setDefault(this.defaultLocale);
    }
    try {
        Resource[] resources = applicationContext.getResources(i18nPattern);
        for (Resource resource : resources) {
            String path = resource.getURI().toString();
            if (CapString.checkRegularMatch(path, i18nFileREG)) {
                path = path.replaceAll(i18nFileREG, "").replaceAll(".*/i18n/", "classpath:/i18n/")
                        // for windows
                        .replaceAll(".*\\\\i18n\\\\", "classpath:\\\\i18n\\\\").replaceAll("\\\\", "/");
                if (!l.contains(path)) {
                    l.add(path);
                    logger.debug("set message path:" + path);
                }
            }

        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    super.setBasenames(l.toArray(new String[l.size()]));

}

From source file:com.tactfactory.harmony.Harmony.java

/** Constructor.
 * @throws Exception PluginManager failure
 *//*from  ww w .  j av a  2 s .com*/
private Harmony() throws Exception {
    this.loadPluginsAndTemplate(new File(this.harmonyContext.getBundlesPath()));

    Locale.setDefault(Locale.US);
}

From source file:io.apiman.manager.test.es.ESMetricsAccessorTest.java

@BeforeClass
@Ignore/*from  w w  w  . j  ava  2 s. c om*/
public static void setup() throws Exception {
    System.out.println("----------- Creating the ES node.");
    ImmutableSettings.Builder settings = NodeBuilder.nodeBuilder().settings();
    settings.put("http.port", "6500-6600");
    settings.put("transport.tcp.port", "6600-6700");

    String clusterName = System.getProperty("apiman.test.es-cluster-name", "apiman");

    settings.put("index.store.type", "memory").put("gateway.type", "none").put("index.number_of_shards", 1)
            .put("index.number_of_replicas", 1);
    node = NodeBuilder.nodeBuilder().client(false).clusterName(clusterName).data(true).local(true)
            .settings(settings).build();

    System.out.println("----------- Starting the ES node.");
    node.start();
    System.out.println("----------- ES node was successfully started.");
    System.out.println("--- Fixing locale for testing purposes");
    locale = Locale.getDefault();
    Locale.setDefault(Locale.US);

    client = createJestClient();
    loadTestData();
}

From source file:org.rhq.enterprise.server.plugins.alertMobicents.MobicentsSender.java

@Override
public SenderResult send(Alert alert) {

    String baseUrl = preferences.getSimpleValue("mobicentsServerUrl", "http://localhost:8080/mobicents");
    String tel = alertParameters.getSimpleValue("targetAddress", null);
    if (tel == null) {
        log.warn("No number to call given, not sending");
        return SenderResult.getSimpleFailure("No target address given");
    }//from  w w  w.  j  ava 2 s . c o m
    String kindString = alertParameters.getSimpleValue("kind", "VOICE");
    MobiKind kind = MobiKind.valueOf(kindString);

    Integer alertId = alert.getId();
    StringBuilder b = new StringBuilder("alertText=");
    Resource res = alert.getAlertDefinition().getResource();
    AlertManagerLocal alertManager = LookupUtil.getAlertManager();

    switch (kind) {
    case VOICE:
        b.append("Alert on resource ");
        do {
            b.append(res.getName());
            res = res.getParentResource();
            if (res != null)
                b.append(" with parent ");
        } while (res != null);
        b.append(". Cause is ");

        // Switch locale to english, as the voice synthesizer expects this for now
        Locale currentLocale = Locale.getDefault();
        Locale.setDefault(Locale.ENGLISH);
        b.append(alertManager.prettyPrintAlertConditions(alert, false));
        Locale.setDefault(currentLocale);

        boolean willBeDisabled = alertManager.willDefinitionBeDisabled(alert);

        if (willBeDisabled)
            b.append(" The alert definition will now be disabled. \n\n");

        //            b.append(" Please press ");
        //
        //            if (willBeDisabled) {
        //                b.append(AlertFeedback.REENABLE.getText());
        //            } else {
        //                b.append(AlertFeedback.DISABLE.getText());
        //            }
        //            b.append(", ");
        //            b.append(AlertFeedback.DELETE.getText());
        //            b.append(" or just hang up to do nothing.");
        break;
    case SMS:
        b.append("Alert: ");
        b.append(res.getName());
        b.append(",id=(").append(res.getId()).append(")");
        b.append("Brought by RHQ");
        break;
    default:
        log.warn("Unsupported Mobicents notification type for now");
    }

    URL url;
    int code = 0;
    HttpURLConnection conn = null;
    try {
        tel = tel.trim();
        String telEnc = URLEncoder.encode(tel, "UTF-8"); // url encode tel-no, as it can contain '+'
        switch (kind) {
        case SMS:
            baseUrl = baseUrl + "sms"; // No trailing '/' !
            break;
        case VOICE:
            baseUrl = baseUrl + "call"; // No trailing '/' !
            break;
        default:
            baseUrl = baseUrl + "--not-supported-yet--";
        }
        baseUrl = baseUrl + "?alertId=" + alertId;
        baseUrl = baseUrl + "&tel=";
        if (kind == MobiKind.VOICE) {
            if (!tel.startsWith("sip:")) {
                baseUrl = baseUrl + "sip:";
            }
        }
        baseUrl = baseUrl + telEnc;
        if (kind == MobiKind.VOICE) {
            if (!tel.contains("@")) { // Append domain from preferences if user has none provided
                String domain = preferences.getSimpleValue("defaultVoipDomain", "localhost");
                baseUrl = baseUrl + "@" + domain;
            }
        }
        // TODO SMS url

        log.info("Mobicents alert [" + kind + "] to baseUrl [" + baseUrl + "] with message:\n" + b.toString());
        url = new URL(baseUrl);
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.setDoInput(true);
        OutputStream out = conn.getOutputStream();

        //conn.addRequestProperty("text",b.toString());
        // TODO encode?
        out.write(b.toString().getBytes());
        out.flush();
        conn.connect();
        code = conn.getResponseCode();
    } catch (Exception e) {
        log.warn("Notification via VoIP failed: " + e);
        return SenderResult.getSimpleFailure("Sending failed " + e.getMessage());
    } finally {
        if (conn != null)
            conn.disconnect();
    }

    if (code != 200) {
        log.info("Notification via Mobicents returned code " + code);
        return SenderResult.getSimpleFailure("Notification via Mobicents returned code " + code);
    } else {
        return SenderResult.getSimpleSuccess("Mobicents alert [" + kind + "] to baseUrl [" + baseUrl + "]");
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.rm.RMRestTest.java

@Test
public void testStatsHistory_Locale_Fr() throws Exception {
    Locale.setDefault(Locale.FRANCE);

    JSONObject jsonObject = callGetStatHistory();

    assertEquals(EXPECTED_RRD_VALUE, (Double) ((JSONArray) jsonObject.get("AverageActivity")).get(0), 0.001);

}

From source file:org.talend.dataprep.schema.xls.XlsSerializerTest.java

@Before
public void setUp() {
    super.setUp();
    previousLocale = Locale.getDefault();
    Locale.setDefault(ENGLISH);
}