Example usage for java.util Locale getDefault

List of usage examples for java.util Locale getDefault

Introduction

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

Prototype

public static Locale getDefault() 

Source Link

Document

Gets the current value of the default locale for this instance of the Java Virtual Machine.

Usage

From source file:Main.java

/**
 * @param s//from  ww  w .  j a  v a2  s.c  o m
 * @return
 */
public static String getFirstLetterUppercased(String s) {
    StringBuilder sb = new StringBuilder(s.substring(0, 1).toUpperCase(Locale.getDefault()));
    sb.append(s.substring(1));
    return sb.toString();
}

From source file:edu.ku.brc.specify.config.init.secwiz.SpecifyDBSecurityWizardFrame.java

/**
 * @param args/*from   w  w w. j  a v a 2s . c o m*/
 */
public static void main(String[] args) {
    // Set App Name, MUST be done very first thing!
    UIRegistry.setAppName("Specify"); //$NON-NLS-1$

    try {
        ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$

    } catch (MissingResourceException ex) {
        Locale.setDefault(Locale.ENGLISH);
        UIRegistry.setResourceLocale(Locale.ENGLISH);
    }

    try {
        if (!System.getProperty("os.name").equals("Mac OS X")) {
            UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
            PlasticLookAndFeel.setPlasticTheme(new DesertBlue());
        }
    } catch (Exception e) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifyDBSecurityWizard.class, e);
        e.printStackTrace();
    }

    AppBase.processArgs(args);
    AppBase.setupTeeForStdErrStdOut(true, false);

    System.setProperty("appdatadir", "..");

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            // Then set this
            IconManager.setApplicationClass(Specify.class);
            IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$
            IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$
            IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$

            // Load Local Prefs
            AppPreferences localPrefs = AppPreferences.getLocalPrefs();
            //try {
            //System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "+(new File(UIRegistry.getAppDataDir()).getCanonicalPath())+"]");
            //} catch (IOException ex) {}

            localPrefs.setDirPath(UIRegistry.getAppDataDir());

            // Check to see if we should check for a new version
            String VERSION_CHECK = "version_check.auto";
            if (localPrefs.getBoolean(VERSION_CHECK, null) == null) {
                localPrefs.putBoolean(VERSION_CHECK, true);
            }

            String EXTRA_CHECK = "extra.check";
            if (localPrefs.getBoolean(EXTRA_CHECK, null) == null) {
                localPrefs.putBoolean(EXTRA_CHECK, true);
            }

            if (UIHelper.isLinux()) {
                Specify.checkForSpecifyAppsRunning();
            }

            if (UIRegistry.isEmbedded()) {
                checkForMySQLProcesses();
            }

            Specify.setUpSystemProperties();

            final SpecifyDBSecurityWizardFrame wizardFrame = new SpecifyDBSecurityWizardFrame();

            if (localPrefs.getBoolean(VERSION_CHECK, true) && localPrefs.getBoolean(EXTRA_CHECK, true)) {
                try {
                    com.install4j.api.launcher.SplashScreen.hide();
                    ApplicationLauncher.Callback callback = new ApplicationLauncher.Callback() {
                        public void exited(int exitValue) {
                            UIHelper.centerAndShow(wizardFrame);
                        }

                        public void prepareShutdown() {

                        }
                    };
                    ApplicationLauncher.launchApplication("100", null, true, callback);

                } catch (Exception ex) {
                    UIHelper.centerAndShow(wizardFrame);
                }
            } else {
                UIHelper.centerAndShow(wizardFrame);
            }
        }
    });
}

From source file:org.opendatakit.common.android.utilities.ODKDataUtils.java

@SuppressWarnings("unchecked")
public static String getLocalizedDisplayName(String displayName) {
    Locale locale = Locale.getDefault();
    String full_locale = locale.toString();
    int underscore = full_locale.indexOf('_');
    String lang_only_locale = (underscore == -1) ? full_locale : full_locale.substring(0, underscore);

    if (displayName.startsWith("\"") && displayName.endsWith("\"")) {
        return displayName.substring(1, displayName.length() - 1);
    } else if (displayName.startsWith("{") && displayName.endsWith("}")) {
        try {/*from ww w.j  ava  2  s . com*/
            Map<String, Object> localeMap = ODKFileUtils.mapper.readValue(displayName, Map.class);
            String candidate = (String) localeMap.get(full_locale);
            if (candidate != null) {
                return candidate;
            }
            candidate = (String) localeMap.get(lang_only_locale);
            if (candidate != null) {
                return candidate;
            }
            candidate = (String) localeMap.get("default");
            if (candidate != null) {
                return candidate;
            }
            return null;
        } catch (JsonParseException e) {
            e.printStackTrace();
            throw new IllegalStateException("bad displayName: " + displayName);
        } catch (JsonMappingException e) {
            e.printStackTrace();
            throw new IllegalStateException("bad displayName: " + displayName);
        } catch (IOException e) {
            e.printStackTrace();
            throw new IllegalStateException("bad displayName: " + displayName);
        }
    } else {
        throw new IllegalStateException("bad displayName: " + displayName);
    }
}

From source file:Main.java

public static boolean hasSpeechToText(Context context) {
    try {/*w  w  w  . j  a  v  a  2  s . c om*/
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault());
        return intent.resolveActivity(context.getPackageManager()) != null;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.microsoft.windowsazure.core.tracing.util.JavaTracingInterceptorTest.java

@BeforeClass
public static void setUSLocale() {
    locale = Locale.getDefault();
    Locale.setDefault(Locale.US);
}

From source file:Main.java

/**
 * @param context//from   w ww .  ja  v a 2  s  . co  m
 *            if null, use the default format (Mozilla/5.0 (Linux; U;
 *            Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0
 *            %sSafari/534.30).
 * @return
 */

public static String getUserAgent(Context context) {
    String webUserAgent = null;
    if (context != null) {
        try {
            Class<?> sysResCls = Class.forName("com.android.internal.R$string");
            Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
            Integer resId = (Integer) webUserAgentField.get(null);
            webUserAgent = context.getString(resId);
        } catch (Throwable ignored) {
        }
    }
    if (TextUtils.isEmpty(webUserAgent)) {
        webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1";
    }

    Locale locale = Locale.getDefault();
    StringBuffer buffer = new StringBuffer();
    // Add version
    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        buffer.append(version);
    } else {
        // default to "1.0"
        buffer.append("1.0");
    }
    buffer.append("; ");
    final String language = locale.getLanguage();
    if (language != null) {
        buffer.append(language.toLowerCase());
        final String country = locale.getCountry();
        if (country != null) {
            buffer.append("-");
            buffer.append(country.toLowerCase());
        }
    } else {
        // default to "en"
        buffer.append("en");
    }
    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
        final String model = Build.MODEL;
        if (model.length() > 0) {
            buffer.append("; ");
            buffer.append(model);
        }
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        buffer.append(" Build/");
        buffer.append(id);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
}

From source file:Main.java

public static String getUserCountryCode(Context context) {
    String country = Locale.getDefault().getCountry();
    if (country.isEmpty()) {
        country = SERVER_VALUE_FOR_UNDEFINED_COUNTRY;
    }//  ww  w .j a v a2 s .com
    return country;
}

From source file:Main.java

public static String getMimeTypeForExtension(String path) {
    String extension = path;/*  w ww  . jav a2s  . co  m*/
    int lastDot = extension.lastIndexOf('.');
    if (lastDot != -1) {
        extension = extension.substring(lastDot + 1);
    }
    // Convert the URI string to lower case to ensure compatibility with MimeTypeMap (see CB-2185).
    extension = extension.toLowerCase(Locale.getDefault());
    if (extension.equals("3ga")) {
        return "audio/3gpp";
    }
    return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}

From source file:latexstudio.editor.remote.DbxUtil.java

public static DbxRequestConfig getDbxConfig() {
    return new DbxRequestConfig("Open LaTex Studio", Locale.getDefault().toString());
}

From source file:Main.java

public static String getDateCurrentTimeZone() {
    StringBuilder sb = new StringBuilder();
    try {//  w  w  w .  j  a va2 s  . co m
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT,
                Locale.getDefault());
        Date currentTimeZone = calendar.getTime();
        sb.append(dateFormat.format(currentTimeZone));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}