Example usage for java.text DecimalFormatSymbols setDecimalSeparator

List of usage examples for java.text DecimalFormatSymbols setDecimalSeparator

Introduction

In this page you can find the example usage for java.text DecimalFormatSymbols setDecimalSeparator.

Prototype

public void setDecimalSeparator(char decimalSeparator) 

Source Link

Document

Sets the character used for decimal sign.

Usage

From source file:LPGoogleFunctions.LPGoogleFunctions.java

public DecimalFormat coordinateDecimalFormat() {
    DecimalFormatSymbols separator = new DecimalFormatSymbols();
    separator.setDecimalSeparator('.');
    DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######");
    coordinateDecimalFormat.setDecimalFormatSymbols(separator);

    return coordinateDecimalFormat;
}

From source file:LPGoogleFunctions.LPGoogleFunctions.java

/**
 * The Google Maps Image APIs make it easy to embed a street view image into your image view.
 * @param address - The address (such as Chagrin Falls, OH).
 * @param imageWidth - Specifies width size of the image in pixels.
 * @param imageHeight - Specifies height size of the image in pixels.
 * @param heading - Indicates the compass heading of the camera. Accepted values are from 0 to 360 (both values indicating North, with 90 indicating East, and 180 South). 
 * If no heading is specified, a value will be calculated that directs the camera towards the specified location, from the point at which the closest photograph was taken.
 * @param fov - Determines the horizontal field of view of the image. The field of view is expressed in degrees, with a maximum allowed value of 120.
 * When dealing with a fixed-size viewport, as with a Street View image of a set size, field of view in essence represents zoom, with smaller numbers indicating a higher level of zoom.
 * @param pitch- Specifies the up or down angle of the camera relative to the Street View vehicle. This is often, but not always, flat horizontal.
 * Positive values angle the camera up (with 90 degrees indicating straight up).
 * Negative values angle the camera down (with -90 indicating straight down).
 * @param responseHandler//from w  w w  .j av  a  2  s  . co m
 * @Override public void willLoadStreetViewImage();
 * @Override public void didLoadStreetViewImage(Bitmap bmp)
 * @Override public void errorLoadingStreetViewImage(Throwable error);
 */

public void loadStreetViewImageForAddress(String address, int imageWidth, int imageHeight, float heading,
        float fov, float pitch, final StreetViewImageListener responseHandler) {
    if (responseHandler != null)
        responseHandler.willLoadStreetViewImage();

    RequestParams parameters = new RequestParams();

    DecimalFormatSymbols separator = new DecimalFormatSymbols();
    separator.setDecimalSeparator('.');
    DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######");
    coordinateDecimalFormat.setDecimalFormatSymbols(separator);

    DecimalFormat twoDecimalFormat = new DecimalFormat(".##");
    twoDecimalFormat.setDecimalFormatSymbols(separator);

    parameters.put("key", this.googleAPIBrowserKey);
    parameters.put("sensor", sensor ? "true" : "false");
    parameters.put("size", String.format("%dx%d", imageWidth, imageHeight));
    if (address != null)
        parameters.put("location", address);
    parameters.put("heading", twoDecimalFormat.format(heading));
    parameters.put("fov", twoDecimalFormat.format(fov));
    parameters.put("pitch", twoDecimalFormat.format(pitch));

    this.client.get(googleAPIStreetViewImageURL, parameters, new BinaryHttpResponseHandler() {
        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            if (responseHandler != null)
                responseHandler.errorLoadingStreetViewImage(arg3);
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            try {
                Bitmap bmp = BitmapFactory.decodeByteArray(arg2, 0, arg2.length);

                if (responseHandler != null)
                    responseHandler.didLoadStreetViewImage(bmp);
            } catch (Exception e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingStreetViewImage(e.getCause());
            }
        }
    });
}

From source file:LPGoogleFunctions.LPGoogleFunctions.java

/**
 * The Google Maps Image APIs make it easy to embed a street view image into your image view.
 * @param location - The location (such as 40.457375,-80.009353).
 * @param imageWidth - Specifies width size of the image in pixels.
 * @param imageHeight - Specifies height size of the image in pixels.
 * @param heading - Indicates the compass heading of the camera. Accepted values are from 0 to 360 (both values indicating North, with 90 indicating East, and 180 South). 
 * If no heading is specified, a value will be calculated that directs the camera towards the specified location, from the point at which the closest photograph was taken.
 * @param fov - Determines the horizontal field of view of the image. The field of view is expressed in degrees, with a maximum allowed value of 120.
 * When dealing with a fixed-size viewport, as with a Street View image of a set size, field of view in essence represents zoom, with smaller numbers indicating a higher level of zoom.
 * @param pitch- Specifies the up or down angle of the camera relative to the Street View vehicle. This is often, but not always, flat horizontal.
 * Positive values angle the camera up (with 90 degrees indicating straight up).
 * Negative values angle the camera down (with -90 indicating straight down).
 * @param responseHandler/*from   w ww. j a  va  2s  .c om*/
 * @Override public void willLoadStreetViewImage();
 * @Override public void didLoadStreetViewImage(Bitmap bmp)
 * @Override public void errorLoadingStreetViewImage(Throwable error);
 */

public void loadStreetViewImageForLocation(LPLocation location, int imageWidth, int imageHeight, float heading,
        float fov, float pitch, final StreetViewImageListener responseHandler) {
    if (responseHandler != null)
        responseHandler.willLoadStreetViewImage();

    RequestParams parameters = new RequestParams();

    DecimalFormatSymbols separator = new DecimalFormatSymbols();
    separator.setDecimalSeparator('.');
    DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######");
    coordinateDecimalFormat.setDecimalFormatSymbols(separator);

    DecimalFormat twoDecimalFormat = new DecimalFormat(".##");
    twoDecimalFormat.setDecimalFormatSymbols(separator);

    parameters.put("key", this.googleAPIBrowserKey);
    parameters.put("sensor", sensor ? "true" : "false");
    parameters.put("size", String.format("%dx%d", imageWidth, imageHeight));
    if (location != null)
        parameters.put("location", String.format("%s,%s", coordinateDecimalFormat.format(location.latitude),
                coordinateDecimalFormat.format(location.longitude)));
    parameters.put("heading", twoDecimalFormat.format(heading));
    parameters.put("fov", twoDecimalFormat.format(fov));
    parameters.put("pitch", twoDecimalFormat.format(pitch));

    this.client.get(googleAPIStreetViewImageURL, parameters, new BinaryHttpResponseHandler() {
        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            if (responseHandler != null)
                responseHandler.errorLoadingStreetViewImage(arg3);
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            try {
                Bitmap bmp = BitmapFactory.decodeByteArray(arg2, 0, arg2.length);

                if (responseHandler != null)
                    responseHandler.didLoadStreetViewImage(bmp);
            } catch (Exception e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingStreetViewImage(e.getCause());
            }
        }
    });
}

From source file:LPGoogleFunctions.LPGoogleFunctions.java

/**
 * The Google Maps Image APIs make it easy to embed a static Google Maps image into your image view.
 * @param address - The address (such as Chagrin Falls, OH).
 * @param zoomLevel - (required if markers not present) defines the zoom level of the map, which determines the magnification level of the map.
 * This parameter takes a numerical value corresponding to the zoom level of the region desired.
 * @param imageWidth - Specifies width size of the image in pixels.
 * @param imageHeight - Specifies height size of the image in pixels.
 * @param imageScale - (optional) affects the number of pixels that are returned. scale=2 returns twice as many pixels as scale=1 while retaining the same coverage area and level of detail (i.e. the contents of the map don't change).
 * This is useful when developing for high-resolution displays, or when generating a map for printing. The default value is 1.
 * @param mapType - (optional) defines the type of map to construct. There are several possible maptype values, including roadmap, satellite, hybrid, and terrain. Use LPGoogleMapType.
 * @param markers - (optional) define one or more markers to attach to the image at specified locations. This parameter takes a single marker definition with parameters separated by the pipe character (|).
 * Multiple markers may be placed within the same markers parameter as long as they exhibit the same style; you may add additional markers of differing styles by adding additional markers parameters.
 * Note that if you supply markers for a map, you do not need to specify the (normally required) center and zoom parameters. Use LPMapImageMarker.
 * @param responseHandler/*from  w  w w  . ja v a  2  s.  c  o  m*/
 * @Override public void willLoadStaticMapImage()
 * @Override public void didLoadStaticMapImage(Bitmap bmp)
 * @Override public void errorLoadingStaticMapImage(Throwable error)
 */

public void loadStaticMapImageForAddress(String address, int zoomLevel, int imageWidth, int imageHeight,
        int imageScale, LPGoogleMapType mapType, ArrayList<LPMapImageMarker> markers,
        final StaticMapImageListener responseHandler) {
    if (responseHandler != null)
        responseHandler.willLoadStaticMapImage();

    StringBuilder URL = new StringBuilder(googleAPIStaticMapImageURL);

    DecimalFormatSymbols separator = new DecimalFormatSymbols();
    separator.setDecimalSeparator('.');
    DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######");
    coordinateDecimalFormat.setDecimalFormatSymbols(separator);

    if (address != null)
        URL.append(String.format("center=%s&", address));
    URL.append(String.format("sensor=%s&", this.sensor ? "true" : "false"));
    URL.append(String.format("zoom=%d&", zoomLevel));
    URL.append(String.format("scale=%d&", imageScale));
    URL.append(String.format("size=%dx%d&", imageWidth, imageHeight));
    URL.append(String.format("maptype=%s&", LPGoogleFunctions.getMapType(mapType)));

    if (markers != null) {
        for (int i = 0; i < markers.size(); i++) {
            LPMapImageMarker marker = markers.get(i);

            URL.append(String.format("markers=%s&", marker.getMarkerURLString()));
        }
    }

    this.client.get(URL.toString(), new BinaryHttpResponseHandler() {
        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            if (responseHandler != null)
                responseHandler.errorLoadingStaticMapImage(arg3);
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            try {
                Bitmap bmp = BitmapFactory.decodeByteArray(arg2, 0, arg2.length);

                if (responseHandler != null)
                    responseHandler.didLoadStaticMapImage(bmp);
            } catch (Exception e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingStaticMapImage(e.getCause());
            }
        }
    });
}

From source file:LPGoogleFunctions.LPGoogleFunctions.java

/**
 * The Google Maps Image APIs make it easy to embed a static Google Maps image into your image view.
 * @param location - The location (such as 40.457375,-80.009353).
 * @param zoomLevel - (required if markers not present) defines the zoom level of the map, which determines the magnification level of the map.
 * This parameter takes a numerical value corresponding to the zoom level of the region desired.
 * @param imageWidth - Specifies width size of the image in pixels.
 * @param imageHeight - Specifies height size of the image in pixels.
 * @param imageScale - (optional) affects the number of pixels that are returned. scale=2 returns twice as many pixels as scale=1 while retaining the same coverage area and level of detail (i.e. the contents of the map don't change).
 * This is useful when developing for high-resolution displays, or when generating a map for printing. The default value is 1.
 * @param mapType - (optional) defines the type of map to construct. There are several possible maptype values, including roadmap, satellite, hybrid, and terrain. Use LPGoogleMapType.
 * @param markers - (optional) define one or more markers to attach to the image at specified locations. This parameter takes a single marker definition with parameters separated by the pipe character (|).
 * Multiple markers may be placed within the same markers parameter as long as they exhibit the same style; you may add additional markers of differing styles by adding additional markers parameters.
 * Note that if you supply markers for a map, you do not need to specify the (normally required) center and zoom parameters. Use LPMapImageMarker.
 * @param responseHandler//from w w w  . j a va  2  s .  com
 * @Override public void willLoadStaticMapImage()
 * @Override public void didLoadStaticMapImage(Bitmap bmp)
 * @Override public void errorLoadingStaticMapImage(Throwable error)
 */

public void loadStaticMapImageForLocation(LPLocation location, int zoomLevel, int imageWidth, int imageHeight,
        int imageScale, LPGoogleMapType mapType, ArrayList<LPMapImageMarker> markers,
        final StaticMapImageListener responseHandler) {
    if (responseHandler != null)
        responseHandler.willLoadStaticMapImage();

    StringBuilder URL = new StringBuilder(googleAPIStaticMapImageURL);

    DecimalFormatSymbols separator = new DecimalFormatSymbols();
    separator.setDecimalSeparator('.');
    DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######");
    coordinateDecimalFormat.setDecimalFormatSymbols(separator);

    if (location != null)
        URL.append(String.format("center=%s,%s&", coordinateDecimalFormat.format(location.latitude),
                coordinateDecimalFormat.format(location.longitude)));
    URL.append(String.format("sensor=%s&", this.sensor ? "true" : "false"));
    URL.append(String.format("zoom=%d&", zoomLevel));
    URL.append(String.format("scale=%d&", imageScale));
    URL.append(String.format("size=%dx%d&", imageWidth, imageHeight));
    URL.append(String.format("maptype=%s&", LPGoogleFunctions.getMapType(mapType)));

    if (markers != null) {
        for (int i = 0; i < markers.size(); i++) {
            LPMapImageMarker marker = markers.get(i);

            URL.append(String.format("markers=%s&", marker.getMarkerURLString()));
        }
    }

    this.client.get(URL.toString(), new BinaryHttpResponseHandler() {
        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            if (responseHandler != null)
                responseHandler.errorLoadingStaticMapImage(arg3);
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            try {
                Bitmap bmp = BitmapFactory.decodeByteArray(arg2, 0, arg2.length);

                if (responseHandler != null)
                    responseHandler.didLoadStaticMapImage(bmp);
            } catch (Exception e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingStaticMapImage(e.getCause());
            }
        }
    });
}

From source file:LPGoogleFunctions.LPGoogleFunctions.java

/**
 * The Google Places Autocomplete API is a web service that returns Place information based on text search terms, and, optionally, geographic bounds.
 * The API can be used to provide autocomplete functionality for text-based geographic searches, by returning Places such as businesses, addresses, and points of interest as a user types.
 * @param input - The text string on which to search. The Place service will return candidate matches based on this string and order results based on their perceived relevance.
 * @param offset - The character position in the input term at which the service uses text for predictions. For example, if the input is 'Googl' and the completion point is 3, the service will match on 'Goo'. The offset should generally be set to the position of the text caret. If no offset is supplied, the service will use the entire term.
 * @param radius - The distance (in meters) within which to return Place results. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area.
 * @param location - The point around which you wish to retrieve Place information. Must be specified as latitude,longitude.
 * @param placeType - The types of Place results to return. If no type is specified, all types will be returned. See LPPrediction.h for types.
 * @param countryRestriction - The country must be passed as a two character.
 * @param responseHandler/*from w  ww  . j av  a 2s  .  c  o m*/
 * @Override public void willLoadPlacesAutocomplete()
 * @Override public void didLoadPlacesAutocomplete(LPPlacesAutocomplete placesAutocomplete)
 * @Override public void errorLoadingPlacesAutocomplete(LPGoogleStatus status)
 */

public void loadPlacesAutocompleteForInput(String input, int offset, int radius, LPLocation location,
        LPGooglePlaceType placeType, String countryRestriction,
        final PlacesAutocompleteListener responseHandler) {
    if (responseHandler != null)
        responseHandler.willLoadPlacesAutocomplete();

    RequestParams parameters = new RequestParams();

    DecimalFormatSymbols separator = new DecimalFormatSymbols();
    separator.setDecimalSeparator('.');
    DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######");
    coordinateDecimalFormat.setDecimalFormatSymbols(separator);

    parameters.put("key", this.googleAPIBrowserKey);
    if (input != null)
        parameters.put("input", input);
    parameters.put("types", LPPrediction.getStringFromGooglePlaceType(placeType));
    parameters.put("offset", String.format("%d", offset));
    parameters.put("radius", String.format("%d", radius));
    if (location != null)
        parameters.put("location", String.format("%s,%s", coordinateDecimalFormat.format(location.latitude),
                coordinateDecimalFormat.format(location.longitude)));
    parameters.put("sensor", this.sensor ? "true" : "false");
    parameters.put("language", this.languageCode);

    if (countryRestriction != null) {
        parameters.put("components", String.format("country:%s", countryRestriction));
    }

    this.client.get(googleAPIPlacesAutocompleteURL, parameters, new AsyncHttpResponseHandler() {
        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            if (responseHandler != null)
                responseHandler.errorLoadingPlacesAutocomplete(LPGoogleStatus.LPGoogleStatusUnknownError);
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            try {
                String response = new String(arg2, "UTF-8");

                JSONObject object = new JSONObject(response);

                LPPlacesAutocomplete placesAutocomplete = new LPPlacesAutocomplete(object);

                LPGoogleStatus status = LPGoogleFunctions
                        .getGoogleStatusFromString(placesAutocomplete.statusCode);

                if (status == LPGoogleStatus.LPGoogleStatusOK) {
                    if (responseHandler != null)
                        responseHandler.didLoadPlacesAutocomplete(placesAutocomplete);
                } else {
                    if (responseHandler != null)
                        responseHandler.errorLoadingPlacesAutocomplete(status);
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingPlacesAutocomplete(LPGoogleStatus.LPGoogleStatusUnknownError);
            } catch (JSONException e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingPlacesAutocomplete(LPGoogleStatus.LPGoogleStatusUnknownError);
            }
        }
    });
}

From source file:LPGoogleFunctions.LPGoogleFunctions.java

/**
 * Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates 
 * (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map.
 * @param address - The location (such as 40.457375,-80.009353).
 * @param filterComponents - A component filter for which you wish to obtain a geocode.
 * The components filter will also be accepted as an optional parameter if an address is provided. See LPGeocodingFilter.h for components.
 * @param responseHandler//from w  w w .  j  a v a 2  s. co  m
 * @Override public void willLoadGeocoding()
 * @Override public void didLoadGeocoding(LPGeocodingResults geocodingResults)
 * @Override public void errorLoadingGeocoding(LPGoogleStatus status)
 */

public void loadGeocodingForLocation(LPLocation location, ArrayList<LPGeocodingFilter> filterComponents,
        final GeocodingListener responseHandler) {
    if (responseHandler != null)
        responseHandler.willLoadGeocoding();

    RequestParams parameters = new RequestParams();

    DecimalFormatSymbols separator = new DecimalFormatSymbols();
    separator.setDecimalSeparator('.');
    DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######");
    coordinateDecimalFormat.setDecimalFormatSymbols(separator);

    if (location != null)
        parameters.put("latlng", String.format("%s,%s", coordinateDecimalFormat.format(location.latitude),
                coordinateDecimalFormat.format(location.longitude)));
    parameters.put("sensor", this.sensor ? "true" : "false");
    parameters.put("language", this.languageCode);

    //COMPONENTS FILTER
    if (filterComponents != null) {
        if (filterComponents.size() > 0) {
            StringBuilder comString = new StringBuilder("components=");

            for (int i = 0; i < filterComponents.size(); i++) {
                LPGeocodingFilter filter = filterComponents.get(i);

                comString.append(String.format("%s:%s", LPGeocodingFilter.getGeocodingFilter(filter.filter),
                        filter.value));
            }
        }
    }

    this.client.get(googleAPIGeocodingURL, parameters, new AsyncHttpResponseHandler() {
        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            if (responseHandler != null)
                responseHandler.errorLoadingGeocoding(LPGoogleStatus.LPGoogleStatusUnknownError);
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            try {
                String response = new String(arg2, "UTF-8");

                JSONObject object = new JSONObject(response);

                LPGeocodingResults geocodingResults = new LPGeocodingResults(object);

                LPGoogleStatus status = LPGoogleFunctions
                        .getGoogleStatusFromString(geocodingResults.statusCode);

                if (status == LPGoogleStatus.LPGoogleStatusOK) {
                    if (responseHandler != null)
                        responseHandler.didLoadGeocoding(geocodingResults);
                } else {
                    if (responseHandler != null)
                        responseHandler.errorLoadingGeocoding(status);
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingGeocoding(LPGoogleStatus.LPGoogleStatusUnknownError);
            } catch (JSONException e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingGeocoding(LPGoogleStatus.LPGoogleStatusUnknownError);
            }
        }
    });
}

From source file:LPGoogleFunctions.LPGoogleFunctions.java

/**
 * The Google Directions API is a service that calculates directions between locations using an HTTP request.
 * You can search for directions for several modes of transportation, include transit, driving, walking or cycling. 
 * Directions may specify origins, destinations and waypoints either as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude coordinates.
 * The Directions API can return multi-part directions using a series of waypoints.
 * @param origin - The latitude/longitude value from which you wish to calculate directions.
 * @param destination - The latitude/longitude value from which you wish to calculate directions.
 * @param travelMode - Specifies the mode of transport to use when calculating directions. If you set the mode to "transit" you must also specify either a departure time or an arrival time.
 * @param avoid - Indicates that the calculated route(s) should avoid the indicated features.
 * @param unit - Specifies the unit system to use when displaying results.
 * @param alternatives - If set to true, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server.
 * @param departureTimeSeconds - Specifies the desired time of departure.
 * @param arrivalTimeSeconds - Specifies the desired time of arrival.
 * @param waypoints - Specifies an array of waypoints. Waypoints alter a route by routing it through the specified location(s). A waypoint is specified as either a latitude/longitude coordinate or as an address which will be geocoded.
 * @param responseHandler//w w  w  .j a  v a2  s. c om
 * @Override public void willLoadDirections()
 * @Override public void didLoadDirections(LPDirections directions)
 * @Override public void errorLoadingDirections(LPGoogleStatus status)
 */

public void loadDirectionsForOrigin(LPLocation origin, LPLocation destination,
        final LPGoogleDirectionsTravelMode travelMode, LPGoogleDirectionsAvoid avoid,
        LPGoogleDirectionsUnit unit, boolean alternatives, long departureTimeSeconds, long arrivalTimeSeconds,
        ArrayList<LPWaypoint> waypoints, final DirectionsListener responseHandler) {
    if (responseHandler != null)
        responseHandler.willLoadDirections();

    RequestParams parameters = new RequestParams();

    DecimalFormatSymbols separator = new DecimalFormatSymbols();
    separator.setDecimalSeparator('.');
    DecimalFormat coordinateDecimalFormat = new DecimalFormat("##.######");
    coordinateDecimalFormat.setDecimalFormatSymbols(separator);

    if (origin != null)
        parameters.put("origin", String.format("%s,%s", coordinateDecimalFormat.format(origin.latitude),
                coordinateDecimalFormat.format(origin.longitude)));
    if (destination != null)
        parameters.put("destination",
                String.format("%s,%s", coordinateDecimalFormat.format(destination.latitude),
                        coordinateDecimalFormat.format(destination.longitude)));
    parameters.put("sensor", this.sensor ? "true" : "false");
    parameters.put("language", this.languageCode);

    if (travelMode != null) {
        parameters.put("mode", LPStep.getDirectionsTravelMode(travelMode));
    }

    if (avoid != null) {
        parameters.put("avoid", LPDirections.getDirectionsAvoid(avoid));
    }

    if (unit != null) {
        parameters.put("units", LPDirections.getDirectionsUnit(unit));
    }

    parameters.put("alternatives", alternatives ? "true" : "false");

    if (departureTimeSeconds > 0) {
        parameters.put("departure_time", String.valueOf(departureTimeSeconds));
    }

    if (arrivalTimeSeconds > 0) {
        parameters.put("arrival_time", String.valueOf(arrivalTimeSeconds));
    }

    if (waypoints != null) {
        StringBuilder waypointsString = new StringBuilder();

        for (int i = 0; i < waypoints.size(); i++) {
            LPWaypoint waypoint = waypoints.get(i);

            waypointsString
                    .append(String.format("%s,%s|", coordinateDecimalFormat.format(waypoint.location.latitude),
                            coordinateDecimalFormat.format(waypoint.location.longitude)));
        }

        parameters.put("waypoints", waypointsString.toString());
    }

    this.client.get(googleAPIDirectionsURL, parameters, new AsyncHttpResponseHandler() {
        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            if (responseHandler != null)
                responseHandler.errorLoadingDirections(LPGoogleStatus.LPGoogleStatusUnknownError);
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            try {
                String response = new String(arg2, "UTF-8");

                JSONObject object = new JSONObject(response);

                LPDirections directions = new LPDirections(object);
                directions.requestTravelMode = travelMode;

                LPGoogleStatus status = LPGoogleFunctions.getGoogleStatusFromString(directions.statusCode);

                if (status == LPGoogleStatus.LPGoogleStatusOK) {
                    if (responseHandler != null)
                        responseHandler.didLoadDirections(directions);
                } else {
                    if (responseHandler != null)
                        responseHandler.errorLoadingDirections(status);
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingDirections(LPGoogleStatus.LPGoogleStatusUnknownError);
            } catch (JSONException e) {
                e.printStackTrace();

                if (responseHandler != null)
                    responseHandler.errorLoadingDirections(LPGoogleStatus.LPGoogleStatusUnknownError);
            }
        }
    });
}

From source file:org.openbravo.erpCommon.utility.Utility.java

/**
 * Returns a DecimalFormat for the given formatting type contained in the Format.xml file
 *//*from w  w w .j  av  a 2 s  .  c  o m*/
public static DecimalFormat getFormat(VariablesSecureApp vars, String typeName) {
    String format = vars.getSessionValue("#FormatOutput|" + typeName);
    String decimal = vars.getSessionValue("#DecimalSeparator|" + typeName);
    String group = vars.getSessionValue("#GroupSeparator|" + typeName);
    DecimalFormat numberFormatDecimal = null;
    if (format != null && !format.equals("") && decimal != null && !decimal.equals("") && group != null
            && !group.equals("")) {
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        dfs.setDecimalSeparator(decimal.charAt(0));
        dfs.setGroupingSeparator(group.charAt(0));
        numberFormatDecimal = new DecimalFormat(format, dfs);
    }
    return numberFormatDecimal;
}

From source file:it.greenvulcano.gvesb.datahandling.dbo.DBOCallSP.java

/**
 * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
 *      java.lang.String, java.lang.String)
 *//*from w  ww .j  a  va 2s  .  c  om*/
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (ROW_NAME.equals(localName)) {
        if (!currCriticalError) {
            executeStatement();
        } else {
            rowDisc++;
            // aggiunta DiscardCause al dhr...
            String msg = currentXSLMessage;

            dhr.addDiscardCause(new DiscardCause(rowCounter, msg));

            resultMessage.append("Data error on row ").append(rowCounter).append(": ").append(msg);
            resultMessage.append("SQL Statement Informations:\n").append(sqlStatementInfo);
            resultMessage.append("Record parameters:\n").append(dumpCurrentRowFields());
            resultStatus = STATUS_PARTIAL;
        }
    } else if (COL_NAME.equals(localName)) {
        CallableStatement cs = (CallableStatement) sqlStatementInfo.getStatement();
        try {
            if (!outOnly) {
                colDataExpecting = false;
                String text = textBuffer.toString();
                if ((currentUUID != null) && (currentUUID.trim().length() > 0) && (text.length() == 0)) {
                    text = uuids.get(currentUUID);
                    if (text == null) {
                        text = currentUUID;
                    }
                }
                if (TIMESTAMP_TYPE.equals(currType) || DATE_TYPE.equals(currType)
                        || TIME_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (TIMESTAMP_TYPE.equals(currType))
                            setNull(cs, Types.TIMESTAMP);
                        else if (DATE_TYPE.equals(currType))
                            setNull(cs, Types.DATE);
                        else
                            setNull(cs, Types.TIME);
                        currentRowFields.add(null);
                    } else {
                        dateFormatter.applyPattern(currDateFormat);
                        Date formattedDate = dateFormatter.parse(text);
                        if (TIMESTAMP_TYPE.equals(currType)) {
                            Timestamp ts = new Timestamp(formattedDate.getTime());
                            setTimestamp(cs, ts);
                            currentRowFields.add(ts);
                        } else if (DATE_TYPE.equals(currType)) {
                            java.sql.Date d = new java.sql.Date(formattedDate.getTime());
                            setDate(cs, d);
                            currentRowFields.add(d);
                        } else {
                            java.sql.Time t = new java.sql.Time(formattedDate.getTime());
                            setTime(cs, t);
                            currentRowFields.add(t);
                        }
                    }
                } else if (INTEGER_TYPE.equals(currType) || SMALLINT_TYPE.equals(currType)
                        || BIGINT_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (INTEGER_TYPE.equals(currType))
                            setNull(cs, Types.INTEGER);
                        else if (SMALLINT_TYPE.equals(currType))
                            setNull(cs, Types.SMALLINT);
                        else
                            setNull(cs, Types.BIGINT);
                        currentRowFields.add(null);
                    } else {
                        if (INTEGER_TYPE.equals(currType))
                            setInt(cs, Integer.parseInt(text, 10));
                        else if (SMALLINT_TYPE.equals(currType))
                            setShort(cs, Short.parseShort(text, 10));
                        else
                            setLong(cs, Long.parseLong(text, 10));
                        currentRowFields.add(text);
                    }
                } else if (FLOAT_TYPE.equals(currType) || DOUBLE_TYPE.equals(currType)
                        || DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType))
                            setNull(cs, Types.NUMERIC);
                        else if (FLOAT_TYPE.equals(currType))
                            setNull(cs, Types.FLOAT);
                        else
                            setNull(cs, Types.DOUBLE);
                        currentRowFields.add(null);
                    } else {
                        DecimalFormatSymbols dfs = numberFormatter.getDecimalFormatSymbols();
                        dfs.setDecimalSeparator(currDecSeparator.charAt(0));
                        dfs.setGroupingSeparator(currGroupSeparator.charAt(0));
                        numberFormatter.setDecimalFormatSymbols(dfs);
                        numberFormatter.applyPattern(currNumberFormat);
                        boolean isBigDecimal = numberFormatter.isParseBigDecimal();
                        try {
                            numberFormatter.setParseBigDecimal(true);
                            BigDecimal formattedNumber = (BigDecimal) numberFormatter.parse(text);
                            if (DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType)) {
                                setBigDecimal(cs, formattedNumber);
                                currentRowFields.add(formattedNumber);
                            } else if (FLOAT_TYPE.equals(currType)) {
                                setFloat(cs, formattedNumber.floatValue());
                                currentRowFields.add(formattedNumber.floatValue());
                            } else {
                                setDouble(cs, formattedNumber.doubleValue());
                                currentRowFields.add(formattedNumber.doubleValue());
                            }
                        } finally {
                            numberFormatter.setParseBigDecimal(isBigDecimal);
                        }
                    }
                } else if (LONG_STRING_TYPE.equals(currType) || LONG_NSTRING_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (LONG_STRING_TYPE.equals(currType))
                            setNull(cs, Types.CLOB);
                        else
                            setNull(cs, Types.NCLOB);
                        currentRowFields.add(null);
                    } else {
                        if (LONG_STRING_TYPE.equals(currType)) {
                            setCharacterStream(cs, new StringReader(text));
                            currentRowFields.add(text);
                        } else {
                            setNCharacterStream(cs, new StringReader(text));
                            currentRowFields.add(text);
                        }
                    }
                } else if (BASE64_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BLOB);
                        currentRowFields.add(null);
                    } else {
                        byte[] data = text.getBytes();
                        data = Base64.getDecoder().decode(data);
                        ByteArrayInputStream bais = new ByteArrayInputStream(data);
                        setBinaryStream(cs, bais, data.length);
                        currentRowFields.add(text);
                    }
                } else if (BINARY_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BLOB);
                        currentRowFields.add(null);
                    } else {
                        byte[] data = text.getBytes();
                        ByteArrayInputStream bais = new ByteArrayInputStream(data);
                        setBinaryStream(cs, bais, data.length);
                        currentRowFields.add(text);
                    }
                } else if (BOOLEAN_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BOOLEAN);
                        currentRowFields.add(null);
                    } else {
                        setBoolean(cs, TextUtils.parseBoolean(text));
                        currentRowFields.add(text);
                    }
                } else if (XML_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.SQLXML);
                        currentRowFields.add(null);
                    } else {
                        SQLXML xml = cs.getConnection().createSQLXML();
                        xml.setString(text);
                        setSQLXML(cs, xml);
                        currentRowFields.add(text);
                    }
                } else if (NSTRING_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.NVARCHAR);
                        currentRowFields.add(null);
                    } else {
                        setNString(cs, text);
                        currentRowFields.add(text);
                    }
                } else {
                    if (text.equals("")) {
                        setNull(cs, Types.VARCHAR);
                        currentRowFields.add(null);
                    } else {
                        setString(cs, text);
                        currentRowFields.add(text);
                    }
                }
            } else {
                currentRowFields.add(currentUUID);
            }
        } catch (ParseException exc) {
            throw new SAXException(exc);
        } catch (SQLException exc) {
            OracleExceptionHandler.handleSQLException(exc);
            throw new SAXException(exc);
        }
    }
}