Example usage for org.json JSONObject optDouble

List of usage examples for org.json JSONObject optDouble

Introduction

In this page you can find the example usage for org.json JSONObject optDouble.

Prototype

public double optDouble(String key) 

Source Link

Document

Get an optional double associated with a key, or NaN if there is no such key or if its value is not a number.

Usage

From source file:com.vk.sdkweb.api.model.VKApiPlace.java

/**
 * Fills a Place instance from JSONObject.
 *//*from  ww w  .  j ava  2s. c o m*/
public VKApiPlace parse(JSONObject from) {
    id = from.optInt("id");
    title = from.optString("title");
    latitude = from.optDouble("latitude");
    longitude = from.optDouble("longitude");
    created = from.optLong("created");
    checkins = from.optInt("checkins");
    updated = from.optLong("updated");
    country_id = from.optInt("country");
    city_id = from.optInt("city");
    address = from.optString("address");
    return this;
}

From source file:com.example.SmartBoard.DrawingView.java

private JSONObject getTouchedObject(final int xTouch, final int yTouch) {
    JSONObject touched = null;/* w w  w.  j  av  a  2 s  .c  om*/

    //makes textObjects preferable on selection for drag
    //search for text object first
    for (JSONObject textObject : textObjects.values()) {
        Rect region = Rect.unflattenFromString(textObject.optString("region"));
        //System.out.println(region);
        if (region.contains(xTouch, yTouch)) {

            touched = textObject;
            return touched;
        }
    }

    for (JSONObject object : objectDrawables.values()) {

        if (object.optString("type").compareTo("Circle") == 0) {
            int x = object.optInt("x");
            int y = object.optInt("y");
            int radius = object.optInt("radius");

            if ((x - xTouch) * (x - xTouch) + (y - yTouch) * (y - yTouch) <= radius * radius) {
                touched = object;
                break;
            }
        } else if (object.optString("type").compareTo("Rectangle") == 0) {
            Rect tempRect = Rect.unflattenFromString(object.optString("dimens"));
            if (tempRect.contains(xTouch, yTouch)) {
                touched = object;
                break;
            }
        } else if (object.optString("type").compareTo("Line") == 0) {

            double tempGradient = gradient(object.optInt("startx"), object.optInt("starty"), xTouch, yTouch);
            int startx = object.optInt("startx");
            int stopx = object.optInt("stopx");
            int starty = object.optInt("starty");
            int stopy = object.optInt("stopy");

            if (lengthOfLine(startx, starty, xTouch, yTouch)
                    + lengthOfLine(stopx, stopy, xTouch, yTouch) <= object.optDouble("length") + 5) {
                touched = object;
                break;
            }

        } else if (object.optString("type").compareTo("Text") == 0) {

            Rect region = Rect.unflattenFromString(object.optString("region"));
            //System.out.println(region);
            if (region.contains(xTouch, yTouch)) {

                touched = object;
                break;
            }
        }
    }

    return touched;
}