Example usage for java.util Locale US

List of usage examples for java.util Locale US

Introduction

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

Prototype

Locale US

To view the source code for java.util Locale US.

Click Source Link

Document

Useful constant for country.

Usage

From source file:Main.java

static String formatLatLon(double latLon, char positiveDirection, char negativeDirection) {
    boolean isPositive = (latLon >= 0.0);
    double absLatLon = Math.abs(latLon);
    if (absLatLon > 180.0) {
        return "?";
    }// www. j a v  a2  s .  c o  m
    double degrees = Math.floor(absLatLon);
    double degreeRemainder = absLatLon - degrees;
    double minutesAndSeconds = 60.0 * degreeRemainder;
    double minutes = Math.floor(minutesAndSeconds);
    double minuteRemainder = minutesAndSeconds - minutes;
    double seconds = 60.0 * minuteRemainder;

    return String.format(Locale.US, "%.0f\u00b0 %.0f\' %.3f\" %c", degrees, minutes, seconds,
            isPositive ? positiveDirection : negativeDirection);

}

From source file:Main.java

/**
 * Whether the given URL is one of the expected URLs used in the bootstrapping process
 * of the app.  Used for determining the app's "home page" URL.
 * @param url The URL to compare against the reserved list.
 * @return True if this URL is used in the bootstrapping process, false otherwise.
 *///ww  w. j  a va  2  s .c o  m
private static boolean isReservedUrl(String url) {
    if (url == null || url.trim().equals(""))
        return false;
    for (String reservedUrlPattern : RESERVED_URL_PATTERNS) {
        if (url.toLowerCase(Locale.US).contains(reservedUrlPattern.toLowerCase(Locale.US)))
            return true;
    }
    return false;
}

From source file:Main.java

private static DateTime getDateFromISO(String ISOString) {
    //DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
    DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
    try {// w  w w . jav  a 2 s. co m
        return parser.parseDateTime(ISOString);
    } catch (Throwable e) {
        try {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
            df.setTimeZone(TimeZone.getTimeZone("UTC"));
            return new DateTime(df.parse(ISOString));
        } catch (Throwable ignored) {
            Log.d("ERROR", "Failed parsing string into date");
            e.printStackTrace();
        }
    }
    return null;
}

From source file:Main.java

@NonNull
static String getBackupName() {
    SimpleDateFormat format = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.US);
    return "MyTargets_backup_" + format.format(new Date()) + ".zip";
}

From source file:Main.java

/**
 * Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
 *
 * @param context Context reference to get the TelephonyManager instance from
 * @return country code or null//  www  . jav a  2s .co  m
 */
public static String getDeviceCountry(Context context) {
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        final String simCountry = tm.getSimCountryIso();
        if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
            return simCountry.toLowerCase(Locale.US);
        } else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
            String networkCountry = tm.getNetworkCountryIso();
            if (networkCountry != null && networkCountry.length() == 2) { // network country code is available
                return networkCountry.toLowerCase(Locale.US);
            }
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:Main.java

/**
 * @param date/*from ww  w . j  av  a2  s .  co m*/
 * @param
 * @return String in the format passed
 */
public static String dateToString(Date date, String format) {
    if (date == null) {
        return "";
    }
    SimpleDateFormat df = new SimpleDateFormat(format, Locale.US);
    return df.format(date);
}

From source file:Main.java

public static void format(Temporal co, String pattern) {
    DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US);
    String str = fmt.format(co);//from  w  w w.  j  a va2s.co m
    System.out.println(pattern + ": " + str);
}

From source file:Main.java

public static CharSequence formatDegreesAsDecimalDegreesString(double fDegrees) {

    double[] degreesMinutes = decimalDegreesToDegreeMinutes(fDegrees);

    return String.format(Locale.US, (fDegrees < 0 ? "-" : "") + "%1$d %2$06.3f", (int) degreesMinutes[0],
            degreesMinutes[1]);/*ww  w  .  ja  v a2 s. co  m*/
}

From source file:Main.java

public static boolean isOGGFile(String in) {
    boolean retVal = false;

    in = in.toLowerCase(Locale.US);
    if (in.endsWith(".ogg"))
        retVal = true;/*from   ww  w .  j a v  a 2  s.  co m*/

    return retVal;
}

From source file:Main.java

public static String domainToAscii(String input) {
    try {/*from w  w w  .jav  a  2 s. c o  m*/
        String result = IDN.toASCII(input).toLowerCase(Locale.US);
        if (result.isEmpty())
            return null;
        if (containsInvalidHostnameAsciiCodes(result)) {
            return null;
        }
        return result;
    } catch (IllegalArgumentException e) {
        return null;
    }
}