List of usage examples for java.util Locale getDefault
public static Locale getDefault()
From source file:Main.java
public static void updateConfiguration(Context context) { Resources resources = context.getResources(); Configuration conf = resources.getConfiguration(); Locale current = Locale.getDefault(); String currentLanguage = current.getDisplayLanguage(); if (Locale.CHINESE.getDisplayLanguage().equals(currentLanguage) || Locale.ENGLISH.getDisplayLanguage().equals(currentLanguage)) { return;// w w w . ja va 2 s.c om } conf.locale = Locale.ENGLISH; resources.updateConfiguration(conf, resources.getDisplayMetrics()); }
From source file:Main.java
/** * getDateAsString// www.j a v a 2 s . c om * Convert a date into a string * * @param date the date * @param format the format in which to return the string * @return the new formatted date string */ public static String getDateAsString(Date date, String format, String timezone) { DateFormat formatter = new SimpleDateFormat(format, Locale.getDefault()); if (timezone == null) { formatter.setTimeZone(TimeZone.getDefault()); } else { formatter.setTimeZone(TimeZone.getTimeZone(timezone)); } return formatter.format(date); }
From source file:net.foreworld.util.RestUtil.java
public static String genSignature(String data, String key) { byte[] byteHMAC = null; try {// w ww . j av a 2 s . c o m Mac mac = Mac.getInstance(ALGORITHM); SecretKeySpec spec = new SecretKeySpec(key.getBytes(), ALGORITHM); mac.init(spec); byteHMAC = mac.doFinal(data.toLowerCase(Locale.getDefault()).getBytes()); } catch (InvalidKeyException ignore) { return null; } catch (NoSuchAlgorithmException ignore) { return null; } // END if (null == byteHMAC) return null; // String code = new BASE64Encoder().encode(byteHMAC); String code = Base64.encodeBase64String(byteHMAC); try { return URLEncoder.encode(code, ENC); } catch (UnsupportedEncodingException ignore) { } return null; }
From source file:Main.java
public static void init(@NonNull final Context context) { if (DateFormat.is24HourFormat(context)) { sFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.getDefault()); } else {/* www . j a v a2 s. c o m*/ sFormat = new SimpleDateFormat("dd/MM/yyyy KK:mm aa", Locale.getDefault()); } }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public static Locale getLocaleForLanguageTag(@Nullable String locale) { Locale parsedLocale = Locale.getDefault(); if (!TextUtils.isEmpty(locale)) { try {//from www . ja va 2 s. c om if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { parsedLocale = Locale.forLanguageTag(locale); } else { parsedLocale = new Locale(locale); } } catch (Exception e) { Log.d(TAG, "Failed to parse locale " + locale + ". Defaulting to " + parsedLocale); } } return parsedLocale; }
From source file:Main.java
public static File newFile() { Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd_HH-mm-ss", Locale.getDefault()); String filename = dateFormat.format(date) + ".jpg"; return new File( Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/" + filename); }
From source file:Main.java
/** * Create acceptLanguage.// w w w . jav a 2s .c o m * * @return Returns the client can accept the language types. Such as:zh-CN,zh. */ public static String systemAcceptLanguage() { if (TextUtils.isEmpty(acceptLanguageInstance)) { Locale locale = Locale.getDefault(); String language = locale.getLanguage(); String country = locale.getCountry(); StringBuilder acceptLanguageBuilder = new StringBuilder(language); if (!TextUtils.isEmpty(country)) acceptLanguageBuilder.append('-').append(country).append(',').append(language); acceptLanguageInstance = acceptLanguageBuilder.toString(); } return acceptLanguageInstance; }
From source file:Main.java
static String localize(String messageId, Object... parameters) { return localize(Locale.getDefault(), DEFAULT_LOCALIZATION_BASE_NAME, messageId, parameters); }
From source file:Main.java
/** * Convert color value to RGB string/*from w ww. ja va2 s.c om*/ * * @param color The color to convert * @return The rgb value as string */ public static String getColorRgbString(int color) { return String.format(Locale.getDefault(), "%d %d %d", Color.red(color), Color.green(color), Color.blue(color)); }
From source file:Main.java
private static void writeJpegCompressedImage(BufferedImage image, String outFile) throws IOException { float qualityFloat = 1f; ByteArrayOutputStream outStream = new ByteArrayOutputStream(); ImageWriter imgWriter = ImageIO.getImageWritersByFormatName("jpg").next(); ImageOutputStream ioStream = ImageIO.createImageOutputStream(outStream); imgWriter.setOutput(ioStream);//from w ww. java2 s .c o m JPEGImageWriteParam jpegParams = new JPEGImageWriteParam(Locale.getDefault()); jpegParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpegParams.setCompressionQuality(qualityFloat); imgWriter.write(null, new IIOImage(image, null, null), jpegParams); ioStream.flush(); ioStream.close(); imgWriter.dispose(); OutputStream outputStream = new FileOutputStream(outFile); outStream.writeTo(outputStream); }