List of usage examples for java.util Locale getDefault
public static Locale getDefault()
From source file:Main.java
/** * @param context 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/* ww w . java2 s .c om*/ */ 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:com.clustercontrol.repository.util.NodeFilterProperty.java
/** * ??? * * @param locale * @return */ public static Property getProperty() { return getProperty(Locale.getDefault()); }
From source file:org.talend.components.service.rest.i18n.LocaleProviderSpring.java
@Override public Locale getLocale() { return Locale.getDefault(); }
From source file:I18N.java
/** * Given a message and parameters, resolve all message's parameter * placeholders with the parameter value. The firstParam can change which * parameter relates to {0} placeholder in the message, and all increment * from this index. If any of the parameters also have placeholders, this * recursively calls itself to fill their placeholders, setting the * firstParam to the index following all parameters that are used by the * current message so params must be in the order p0..pN, p00..p0N..pMN, * p000..p00N..p0MN..pLMN... where each additional index is for nested * placeholders (ones in params) and assumes every message/param contains * N M L placeholders; any that don't contain placeholders can have their * pXXX.. taken out, so long as the order of remaining params don't change * @param message Message to format/* w w w . ja v a 2 s. co m*/ * @param firstParam Index of parameter that relates to {0} placeholder, * all parameters following this one relate to incrementing placeholders * @param params The parameters used to fill the placeholders * @return Message with all placeholders filled with relative parameters */ private static String formatMessage(String message, int firstParam, Object[] params) { // Only need to do any formatting if there are parameters to do the // formatting with. If there are none, the message input is returned // unmodified if (params != null && firstParam < params.length) { MessageFormat parser; Locale locale = Locale.getDefault(); Format[] formats; // Set up parser = new MessageFormat(""); parser.setLocale(locale); parser.applyPattern(message); // Used only to count how many parameters are needed by this message formats = parser.getFormatsByArgumentIndex(); // Recursively format the parameters used by this message for (int paramIndex = 0; paramIndex < formats.length; paramIndex++) if (params[firstParam + paramIndex] instanceof String) params[firstParam + paramIndex] = formatMessage(params[firstParam + paramIndex].toString(), firstParam + formats.length, params); // Format the message using the formatted parameters message = parser.format(getParams(params, firstParam, firstParam + formats.length)); } return message; }
From source file:Main.java
/*** * Fetch the estimate current time of arrival at the destination * @param timeZone - The timezone at the destination * @param distance - how far to the target * @param speed - how fast we are moving * @return String - "HH:MM" current time at the target *///w w w. j ava2s . c o m public static String calculateEta(TimeZone timeZone, double distance, double speed) { // If no speed, then return an empty display string if (0 == speed) { return "--:--"; } // fetch the raw ETE Time eteRaw = fetchRawEte(distance, speed, 0, true); // If the eteRaw is meaningless, then return an empty display string if (null == eteRaw) { return "--:--"; } // Break the hours and minutes out int eteHr = eteRaw.hour; int eteMin = eteRaw.minute; // Hours greater than 99 are not displayable if (eteHr > 99) { return "XX:XX"; } // Get the current local time hours and minutes int etaHr = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int etaMin = Calendar.getInstance().get(Calendar.MINUTE); // Add in our ETE to the current time, accounting for rollovers etaMin += eteMin; // Add the estimated minutes enroute to "now" if (etaMin > 59) { etaMin -= 60; etaHr++; } // account for minute rollover etaHr += eteHr; // Now add the hours enroute while (etaHr > 23) { etaHr -= 24; } // account for midnight rollover // Format the hours and minutes String strHr = String.format(Locale.getDefault(), "%02d", etaHr); String strMn = String.format(Locale.getDefault(), "%02d", etaMin); // Build string of return return strHr + ":" + strMn; }
From source file:Main.java
/*** * Fetch the estimate current time of arrival at the destination * @param timeZone - The timezone at the destination * @param distance - how far to the target * @param speed - how fast we are moving * @param bearing - direction to target/* ww w. ja v a2 s. c o m*/ * @param heading - direction of movement * @return String - "HH:MM" current time at the target */ public static String calculateEta(TimeZone timeZone, double distance, double speed, double bearing, double heading) { // fetch the raw ETE int eteRaw = fetchRawEte(distance, speed, bearing, heading); // If no speed, or the eteRaw is meaningless, then return an empty display string if (0 == speed || eteRaw == -1) { return "--:--"; } // Break the hours and minutes out int eteHr = eteRaw / 100; int eteMin = eteRaw % 100; // Hours greater than 99 are not displayable if (eteHr > 99) { return "XX:XX"; } // Get the current local time hours and minutes int etaHr = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int etaMin = Calendar.getInstance().get(Calendar.MINUTE); // Add in our ETE to the current time, accounting for rollovers etaMin += eteMin; // Add the estimated minutes enroute to "now" if (etaMin > 59) { etaMin -= 60; etaHr++; } // account for minute rollover etaHr += eteHr; // Now add the hours enroute while (etaHr > 23) { etaHr -= 24; } // account for midnight rollover // Format the hours and minutes String strHr = String.format(Locale.getDefault(), "%02d", etaHr); String strMn = String.format(Locale.getDefault(), "%02d", etaMin); // Build string of return return strHr + ":" + strMn; }
From source file:Main.java
public static final Date stringToDate(String paramString1, String paramString2, boolean paramBoolean) { SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(paramString2, Locale.getDefault()); localSimpleDateFormat.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID())); try {/* w ww . j ava 2 s . co m*/ Date localDate = localSimpleDateFormat.parse(paramString1); return localDate; } catch (Throwable localThrowable) { if (!paramBoolean) { return new Date(1000L + System.currentTimeMillis()); } } return null; }
From source file:com.mk4droid.IMC_Utils.GEO.java
public static String ConvertGeoPointToAddress(LatLng pt, Context ctx) { Address maddress = null;/*from w ww . ja v a 2 s. c o m*/ try { Geocoder geocoder = new Geocoder(ctx, Locale.getDefault()); List<Address> list = geocoder.getFromLocation(pt.latitude, pt.longitude, 1); if (list != null && list.size() > 0) { maddress = list.get(0); } } catch (Exception e) { Log.e(Constants_API.TAG, "Gecoder falied: I will try with REST"); new RevGEO_Try2_Asynch(pt.latitude, pt.longitude).execute(); } String Address_STR = ""; if (maddress != null) { for (int i = 0; i < maddress.getMaxAddressLineIndex(); i++) Address_STR += maddress.getAddressLine(i) + ", "; Address_STR += maddress.getCountryName(); } return Address_STR; }
From source file:com.vmware.bdd.exception.BddException.java
protected static String formatErrorMessage(final String errorId, Object... args) { String msg = messageSource.getMessage(errorId, args, Locale.getDefault()); if (msg == null) { return "Error: Invalid Serengeti error message Id " + errorId; }/*from w w w . j a v a 2 s .c o m*/ return String.format(msg, args); }
From source file:Main.java
public static String toUpperCase(String str, int beginIndex, int endIndex) { return str.replaceFirst(str.substring(beginIndex, endIndex), str.substring(beginIndex, endIndex).toUpperCase(Locale.getDefault())); }