Example usage for java.text DecimalFormat setDecimalFormatSymbols

List of usage examples for java.text DecimalFormat setDecimalFormatSymbols

Introduction

In this page you can find the example usage for java.text DecimalFormat setDecimalFormatSymbols.

Prototype

public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) 

Source Link

Document

Sets the decimal format symbols, which is generally not changed by the programmer or user.

Usage

From source file:nl.nn.adapterframework.parameters.Parameter.java

public void configure() throws ConfigurationException {
    if (StringUtils.isNotEmpty(getXpathExpression()) || StringUtils.isNotEmpty(styleSheetName)) {
        if (paramList != null) {
            paramList.configure();//from   w w  w  .j a  v  a2 s.  c  om
        }
        String outputType = TYPE_XML.equalsIgnoreCase(getType()) || TYPE_NODE.equalsIgnoreCase(getType())
                || TYPE_DOMDOC.equalsIgnoreCase(getType()) ? "xml" : "text";
        boolean includeXmlDeclaration = false;

        transformerPool = TransformerPool.configureTransformer0("Parameter [" + getName() + "] ", classLoader,
                getNamespaceDefs(), getXpathExpression(), styleSheetName, outputType, includeXmlDeclaration,
                paramList, isXslt2());
    } else {
        if (paramList != null && StringUtils.isEmpty(getXpathExpression())) {
            throw new ConfigurationException("Parameter [" + getName()
                    + "] can only have parameters itself if a styleSheetName or xpathExpression is specified");
        }
    }
    if (isRemoveNamespaces()) {
        String removeNamespaces_xslt = XmlUtils.makeRemoveNamespacesXslt(true, false);
        try {
            transformerPoolRemoveNamespaces = new TransformerPool(removeNamespaces_xslt);
        } catch (TransformerConfigurationException te) {
            throw new ConfigurationException("Got error creating transformer from removeNamespaces", te);
        }
    }
    if (TYPE_DATE.equals(getType()) && StringUtils.isEmpty(getFormatString())) {
        setFormatString(TYPE_DATE_PATTERN);
    }
    if (TYPE_DATETIME.equals(getType()) && StringUtils.isEmpty(getFormatString())) {
        setFormatString(TYPE_DATETIME_PATTERN);
    }
    if (TYPE_TIMESTAMP.equals(getType()) && StringUtils.isEmpty(getFormatString())) {
        setFormatString(TYPE_TIMESTAMP_PATTERN);
    }
    if (TYPE_TIME.equals(getType()) && StringUtils.isEmpty(getFormatString())) {
        setFormatString(TYPE_TIME_PATTERN);
    }
    if (TYPE_NUMBER.equals(getType())) {
        decimalFormatSymbols = new DecimalFormatSymbols();
        if (StringUtils.isNotEmpty(getDecimalSeparator())) {
            decimalFormatSymbols.setDecimalSeparator(getDecimalSeparator().charAt(0));
        }
        if (StringUtils.isNotEmpty(getGroupingSeparator())) {
            decimalFormatSymbols.setGroupingSeparator(getGroupingSeparator().charAt(0));
        }
    }
    configured = true;

    if (getMinInclusive() != null || getMaxInclusive() != null) {
        if (!TYPE_NUMBER.equals(getType())) {
            throw new ConfigurationException(
                    "minInclusive and minInclusive only allowed in combination with type [" + TYPE_NUMBER
                            + "]");
        }
        if (getMinInclusive() != null) {
            DecimalFormat df = new DecimalFormat();
            df.setDecimalFormatSymbols(decimalFormatSymbols);
            try {
                minInclusive = df.parse(getMinInclusive());
            } catch (ParseException e) {
                throw new ConfigurationException(
                        "Attribute [minInclusive] could not parse result [" + getMinInclusive()
                                + "] to number decimalSeparator [" + decimalFormatSymbols.getDecimalSeparator()
                                + "] groupingSeparator [" + decimalFormatSymbols.getGroupingSeparator() + "]",
                        e);
            }
        }
        if (getMaxInclusive() != null) {
            DecimalFormat df = new DecimalFormat();
            df.setDecimalFormatSymbols(decimalFormatSymbols);
            try {
                maxInclusive = df.parse(getMaxInclusive());
            } catch (ParseException e) {
                throw new ConfigurationException(
                        "Attribute [maxInclusive] could not parse result [" + getMinInclusive()
                                + "] to number decimalSeparator [" + decimalFormatSymbols.getDecimalSeparator()
                                + "] groupingSeparator [" + decimalFormatSymbols.getGroupingSeparator() + "]",
                        e);
            }
        }
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final CategoryPlot cpl = chart.getCategoryPlot();
    final CategoryItemRenderer renderer = cpl.getRenderer();
    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        renderer.setBaseToolTipGenerator(
                new FormulaCategoryTooltipGenerator(getRuntime(), getTooltipFormula()));
    }//from   www.j  av a2 s .  co m
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        renderer.setBaseItemURLGenerator(new FormulaCategoryURLGenerator(getRuntime(), getUrlFormula()));
    }
    if (this.categoricalLabelFormat != null) {
        final StandardCategoryItemLabelGenerator scilg;
        if (categoricalLabelDecimalFormat != null) {
            final DecimalFormat numFormat = new DecimalFormat(categoricalLabelDecimalFormat,
                    new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale()));
            numFormat.setRoundingMode(RoundingMode.HALF_UP);
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, numFormat);
        } else if (categoricalLabelDateFormat != null) {
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, new SimpleDateFormat(
                    categoricalLabelDateFormat, getRuntime().getResourceBundleFactory().getLocale()));
        } else {
            final DecimalFormat formatter = new DecimalFormat();
            formatter.setDecimalFormatSymbols(
                    new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale()));
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, formatter);
        }
        renderer.setBaseItemLabelGenerator(scilg);
    }
    renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible()));
    if (getItemLabelFont() != null) {
        renderer.setBaseItemLabelFont(getItemLabelFont());
    }

    if (categoricalItemLabelRotation != null) {
        final ItemLabelPosition orgPosItemLabelPos = renderer.getBasePositiveItemLabelPosition();
        if (orgPosItemLabelPos == null) {
            final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
            renderer.setBasePositiveItemLabelPosition(pos2);
        } else {
            final ItemLabelPosition pos2 = new ItemLabelPosition(orgPosItemLabelPos.getItemLabelAnchor(),
                    orgPosItemLabelPos.getTextAnchor(), orgPosItemLabelPos.getRotationAnchor(),
                    categoricalItemLabelRotation.doubleValue());
            renderer.setBasePositiveItemLabelPosition(pos2);
        }

        final ItemLabelPosition orgNegItemLabelPos = renderer.getBaseNegativeItemLabelPosition();
        if (orgNegItemLabelPos == null) {
            final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
            renderer.setBaseNegativeItemLabelPosition(pos2);
        } else {
            final ItemLabelPosition neg2 = new ItemLabelPosition(orgNegItemLabelPos.getItemLabelAnchor(),
                    orgNegItemLabelPos.getTextAnchor(), orgNegItemLabelPos.getRotationAnchor(),
                    categoricalItemLabelRotation.doubleValue());
            renderer.setBaseNegativeItemLabelPosition(neg2);
        }
    }

    final Font labelFont = Font.decode(getLabelFont());

    final CategoryAxis categoryAxis = cpl.getDomainAxis();
    categoryAxis.setLabelFont(labelFont);
    categoryAxis.setTickLabelFont(labelFont);
    if (getCategoryTitleFont() != null) {
        categoryAxis.setLabelFont(getCategoryTitleFont());
    }
    if (getCategoryTickFont() != null) {
        categoryAxis.setTickLabelFont(getCategoryTickFont());
    }

    if (maxCategoryLabelWidthRatio != null) {
        categoryAxis.setMaximumCategoryLabelWidthRatio(maxCategoryLabelWidthRatio.floatValue());
    }
    cpl.setDomainGridlinesVisible(showGridlines);
    if (labelRotation != null) {
        double angle = labelRotation.doubleValue();
        CategoryLabelPosition top = createUpRotationCategoryLabelPosition(PlaneDirection.TOP, angle);
        CategoryLabelPosition bottom = createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, angle);
        CategoryLabelPosition left = createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, angle);
        CategoryLabelPosition right = createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT, angle);
        CategoryLabelPositions rotationLabelPositions = new CategoryLabelPositions(top, bottom, left, right);
        categoryAxis.setCategoryLabelPositions(rotationLabelPositions);
    }

    final String[] colors = getSeriesColor();
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, parseColorFromString(colors[i]));
    }

    if (lowerMargin != null) {
        categoryAxis.setLowerMargin(lowerMargin.doubleValue());
    }
    if (upperMargin != null) {
        categoryAxis.setUpperMargin(upperMargin.doubleValue());
    }
    if (categoryMargin != null) {
        categoryAxis.setCategoryMargin(categoryMargin.doubleValue());
    }

    configureRangeAxis(cpl, labelFont);
}

From source file:com.physphil.android.unitconverterultimate.fragments.ConversionFragment.java

/**
 * Get DecimalFormat used to format result
 *
 * @return DecimalFormat/*from  ww w .  j av  a 2s. co m*/
 */
private DecimalFormat getDecimalFormat() {
    DecimalFormat formatter = new DecimalFormat();

    //Set maximum number of decimal places
    formatter.setMaximumFractionDigits(mPrefs.getNumberDecimals());

    //Set group and decimal separators
    DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
    symbols.setDecimalSeparator(mPrefs.getDecimalSeparator().charAt(0));

    String groupSeparator = mPrefs.getGroupSeparator();
    boolean isSeparatorUsed = !groupSeparator.equals(getString(R.string.group_separator_none));
    formatter.setGroupingUsed(isSeparatorUsed);
    if (isSeparatorUsed) {
        symbols.setGroupingSeparator(groupSeparator.charAt(0));
    }

    formatter.setDecimalFormatSymbols(symbols);
    return formatter;
}

From source file:org.talend.dataprep.transformation.actions.math.ChangeNumberFormat.java

/**
 * Return the custom format out of the parameters.
 *
 * @param parameters the action parameters.
 * @return the custom format out of the parameters.
 *//* w w  w  .j  a v  a 2  s  .  c o m*/
private NumberFormat getCustomFormat(Map<String, String> parameters) {
    final DecimalFormat decimalFormat = new DecimalFormat(parameters.get(TARGET_PATTERN + "_" + CUSTOM));

    DecimalFormatSymbols decimalFormatSymbols = decimalFormat.getDecimalFormatSymbols();

    String decimalSeparator = getCustomizableParam(TARGET + DECIMAL + SEPARATOR, parameters);
    if (!StringUtils.isEmpty(decimalSeparator)) {
        decimalFormatSymbols.setDecimalSeparator(decimalSeparator.charAt(0));
    }

    String groupingSeparator = getCustomizableParam(TARGET + GROUPING + SEPARATOR, parameters);
    if (StringUtils.isEmpty(groupingSeparator) || groupingSeparator.equals(decimalSeparator)) {
        decimalFormat.setGroupingUsed(false);
    } else {
        decimalFormatSymbols.setGroupingSeparator(groupingSeparator.charAt(0));
    }

    decimalFormat.setDecimalFormatSymbols(decimalFormatSymbols);

    return decimalFormat;
}

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   ww w .  j a va 2s  .  c  om*/
 * @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  w  w. jav  a  2s .c  o m*/
 * @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// w  w  w  .  j av  a 2  s .  c  om
 * @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 av a 2s.  co  m*/
 * @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/*  w ww . java  2 s . c  om*/
 * @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);
            }
        }
    });
}