List of usage examples for java.util Locale getDefault
public static Locale getDefault()
From source file:Main.java
public static String stringForTime(int timeMs) { if (timeMs <= 0 || timeMs >= 24 * 60 * 60 * 1000) { return "00:00"; }//from www. j ava2s . co m int totalSeconds = timeMs / 1000; int seconds = totalSeconds % 60; int minutes = (totalSeconds / 60) % 60; int hours = totalSeconds / 3600; StringBuilder stringBuilder = new StringBuilder(); Formatter mFormatter = new Formatter(stringBuilder, Locale.getDefault()); if (hours > 0) { return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString(); } else { return mFormatter.format("%02d:%02d", minutes, seconds).toString(); } }
From source file:Main.java
public static Date parse(String fullDate) throws ParseException { return parse(fullDate, Locale.getDefault()); }
From source file:Main.java
public static String getAddressFromLocation(@NonNull Context context, @NonNull Location location) { final Geocoder geocoder = new Geocoder(context, Locale.getDefault()); final StringBuilder builder = new StringBuilder(); try {// w w w . j a va2 s . c o m final List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5 // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex() final String address = addresses.get(0).getAddressLine(0); if (addIfNotEmpty(builder, address)) { builder.append(", "); } final String city = addresses.get(0).getLocality(); if (addIfNotEmpty(builder, city)) { builder.append(", "); } final String postalCode = addresses.get(0).getPostalCode(); if (addIfNotEmpty(builder, postalCode)) { builder.append(", "); } final String state = addresses.get(0).getAdminArea(); if (addIfNotEmpty(builder, state)) { builder.append(", "); } final String country = addresses.get(0).getCountryName(); if (addIfNotEmpty(builder, country)) { builder.append(", "); } // final String knownName = addresses.get(0).getFeatureName(); // addIfNotEmpty(builder, knownName); } catch (IOException e) { e.printStackTrace(); } return builder.toString(); }
From source file:Main.java
/** * getStringAsDate/*w w w. j ava 2 s . c o m*/ * * @param dateString a string in date format * @param format the resulting date format * @return a new date in the specified format */ public static Date getStringAsDate(String dateString, String format, String timezone) { SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault()); if (timezone == null) { formatter.setTimeZone(TimeZone.getDefault()); } else { formatter.setTimeZone(TimeZone.getTimeZone("UTC")); } Date date = new Date(); try { date = formatter.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static void reloadLocale(Context context) { SharedPreferences sharedPrefs = PreferenceManager .getDefaultSharedPreferences(context.getApplicationContext()); String lang = sharedPrefs.getString(PREF_APP_LANGUAGE, Locale.getDefault().getLanguage()); if (sharedPrefs.getString(PREF_APP_LANGUAGE, "").equalsIgnoreCase("")) { sharedPrefs.edit().putString(PREF_APP_LANGUAGE, lang).commit(); }/* www .j a v a2s .co m*/ Configuration newConfig = context.getResources().getConfiguration(); if (!newConfig.locale.getLanguage().equals(lang)) { locale = new Locale(lang); } if (locale != null) { Locale.setDefault(locale); newConfig.locale = locale; context.getResources().updateConfiguration(newConfig, context.getResources().getDisplayMetrics()); } }
From source file:Main.java
/** * @return the system language and country info like zh-CN,en-US * *//*from w w w . j a va 2 s . c om*/ public static final String getSystemLanguageAndCountry(Context context) { String str = Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry(); return str; }
From source file:Main.java
public static String toHex(byte abyte0[]) { StringBuilder stringbuilder = new StringBuilder(2 * abyte0.length); int i = 0;//from w ww. j a v a 2 s . c om while (i < abyte0.length) { String s = Integer.toHexString(abyte0[i]); if (s.length() == 1) { stringbuilder.append("0"); } else if (s.length() == 8) { s = s.substring(6); } stringbuilder.append(s); i++; } return stringbuilder.toString().toLowerCase(Locale.getDefault()); }
From source file:Main.java
private static Method getColumnGetMethod(Class<?> entityType, Field field, String suffix) { String fieldName = field.getName(); Method getMethod = null;/*from w w w. j a v a 2 s . c o m*/ if (field.getType() == boolean.class) { getMethod = getBooleanColumnGetMethod(entityType, fieldName, suffix); } if (getMethod == null) { String methodName = "get" + fieldName.substring(0, 1).toUpperCase(Locale.getDefault()) + fieldName.substring(1) + suffix; try { getMethod = entityType.getDeclaredMethod(methodName); } catch (NoSuchMethodException e) { Log.d("T", methodName + " not exist"); } } return getMethod; }
From source file:Main.java
public static Date getFirstDayOfMonth(Date date) { if (date == null) { return null; }//from w w w . ja va 2 s. c o m Calendar calendar = Calendar.getInstance(Locale.getDefault()); calendar.setTime(date); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.getTime(); }
From source file:Main.java
private static Method getColumnSetMethod(Class<?> entityType, Field field, Class<?> typeClass, String suffix) { String fieldName = field.getName(); Method setMethod = null;/* w w w . j a va 2 s . c o m*/ if (field.getType() == boolean.class) { setMethod = getBooleanColumnSetMethod(entityType, field, typeClass, suffix); } if (setMethod == null) { String methodName = "set" + fieldName.substring(0, 1).toUpperCase(Locale.getDefault()) + fieldName.substring(1) + suffix; try { setMethod = entityType.getDeclaredMethod(methodName, typeClass); } catch (NoSuchMethodException e) { Log.d("T", methodName + " not exist"); } } return setMethod; }