Example usage for org.json JSONObject getDouble

List of usage examples for org.json JSONObject getDouble

Introduction

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

Prototype

public double getDouble(String key) throws JSONException 

Source Link

Document

Get the double value associated with a key.

Usage

From source file:fr.cph.stock.android.entity.EntityBuilder.java

private List<Account> buildAccounts(JSONArray array) throws JSONException {
    List<Account> accounts = new ArrayList<Account>();
    boolean find = true;
    int i = 0;/*from   w w w.ja v  a 2s.c  om*/
    JSONObject temp;
    while (find) {
        temp = array.optJSONObject(i);
        if (temp != null) {
            Account account = new Account();
            account.setId(temp.getString("id"));
            account.setCurrency(temp.getString("currency"));
            double liquidity = temp.getDouble("liquidity");
            account.setLiquidity(formatLocaleOne.format(liquidity));
            account.setName(temp.getString("name"));
            accounts.add(account);
            i++;
        } else {
            find = false;
        }
    }
    return accounts;
}

From source file:fr.cph.stock.android.entity.EntityBuilder.java

private List<ShareValue> buildShareValues(JSONArray array) throws JSONException {
    List<ShareValue> shareValues = new ArrayList<ShareValue>();
    boolean find = true;
    int i = 0;//  www.j a  v a 2  s.c o m
    JSONObject temp;
    while (find) {
        temp = array.optJSONObject(i);
        if (temp != null) {
            ShareValue sv = new ShareValue();
            sv.setAccount(temp.getString("account"));
            sv.setCommentary(temp.optString("commentary"));

            JSONObject dateSON = temp.getJSONObject("date");
            sv.setDate(extractDate(dateSON, user.getDatePatternWithoutHourMin()));

            double share = temp.getDouble("shareValue");
            sv.setShareValue(formatLocaleOne.format(share));
            if (share > 100) {
                sv.setUp(true);
            } else {
                sv.setUp(false);
            }

            sv.setPortfolioValue(formatCurrencyOne.format(temp.getDouble("portfolioValue")));
            sv.setShareQuantity(formatLocaleOne.format(temp.getDouble("shareQuantity")));
            sv.setMonthlyYield(formatCurrencyOne.format(temp.getDouble("monthlyYield")));

            shareValues.add(sv);
            i++;
        } else {
            find = false;
        }
    }
    return shareValues;
}

From source file:fr.cph.stock.android.entity.EntityBuilder.java

private List<Equity> buildEquities(JSONArray array) throws JSONException {
    List<Equity> equities = new ArrayList<Equity>();
    boolean find = true;
    int i = 0;//from w  w  w  .j  a v a 2s  .  c  o m
    JSONObject temp;

    while (find) {
        temp = array.optJSONObject(i);
        if (temp != null) {
            Equity e = new Equity();
            e.setName(temp.getString("name"));

            double unitCostPrice = temp.getDouble("unitCostPrice");
            e.setUnitCostPrice(formatLocaleTwo.format(unitCostPrice));

            e.setValue(formatLocaleZero.format(temp.getDouble("value")));
            double plusMinusValue = temp.getDouble("plusMinusValue");
            String plusMinusValueStr = formatLocaleOne.format(plusMinusValue) + "%";
            if (plusMinusValue > 0) {
                e.setPlusMinusValue("+" + plusMinusValueStr);
            } else {
                e.setPlusMinusValue(plusMinusValueStr);
            }
            e.setUp(plusMinusValue > 0 ? true : false);

            double quantity = temp.getDouble("quantity");
            e.setQuantity(formatLocaleOne.format(quantity));

            double yieldYear = temp.getDouble("yieldYear");
            e.setYieldYear(formatLocaleOne.format(yieldYear) + "%");

            double yieldUnitCostPrice = temp.getDouble("yieldUnitCostPrice");
            e.setYieldUnitCostPrice(formatLocaleOne.format(yieldUnitCostPrice) + "%");

            double quote = temp.getDouble("quote");
            e.setQuote(formatLocaleTwo.format(quote));

            double plusMinusUnitCostPriceValue = temp.getDouble("plusMinusUnitCostPriceValue");
            if (plusMinusValue > 0) {
                e.setPlusMinusUnitCostPriceValue("+" + formatLocaleZero.format(plusMinusUnitCostPriceValue));
            } else {
                e.setPlusMinusUnitCostPriceValue(formatLocaleZero.format(plusMinusUnitCostPriceValue));
            }
            Double variation = temp.optDouble("variation");
            if (!variation.isNaN()) {
                if (variation >= 0) {
                    e.setUpVariation(true);
                    e.setVariation("+" + formatLocaleTwo.format(variation) + "%");
                } else {
                    e.setUpVariation(false);
                    e.setVariation(formatLocaleTwo.format(variation) + "%");
                }
            } else {
                e.setUpVariation(true);
                e.setVariation("+0%");
            }
            equities.add(e);
            i++;
        } else {
            find = false;
        }
    }
    return equities;
}

From source file:com.connectsdk.cordova.JSCommandDispatcher.java

@CommandMethod
public void mediaControl_seek(JSCommand command, JSONObject args) throws JSONException {
    MediaControl mediaControl = getMediaControl(command, args);

    double positionSeconds = args.getDouble("position");
    long positionMillis = (long) (1000L * positionSeconds);

    mediaControl.seek(positionMillis, command.getResponseListener());
}

From source file:com.connectsdk.cordova.JSCommandDispatcher.java

@CommandMethod
public void mouseControl_move(JSCommand command, JSONObject args) throws JSONException {
    double dx = args.getDouble("dx");
    double dy = args.getDouble("dy");

    device.getMouseControl().move(dx, dy);

    // FIXME check if this actually worked
    command.success();/*  ww  w. ja v  a 2 s . c  o m*/
}

From source file:com.connectsdk.cordova.JSCommandDispatcher.java

@CommandMethod
public void mouseControl_scroll(JSCommand command, JSONObject args) throws JSONException {
    double dx = args.getDouble("dx");
    double dy = args.getDouble("dy");

    device.getMouseControl().scroll(dx, dy);

    // FIXME check if this actually worked
    command.success();/*from www .j av  a 2s .co m*/
}

From source file:com.connectsdk.cordova.JSCommandDispatcher.java

@CommandMethod
public void volumeControl_setVolume(JSCommand command, JSONObject args) throws JSONException {
    float volume = (float) args.getDouble("volume");

    device.getVolumeControl().setVolume(volume, command.getResponseListener());
}

From source file:com.graphhopper.http.GraphHopperServletIT.java

@Test
public void testBasicQuery() throws Exception {
    JSONObject json = query("point=42.554851,1.536198&point=42.510071,1.548128");
    JSONObject infoJson = json.getJSONObject("info");
    assertFalse(infoJson.has("errors"));
    JSONObject path = json.getJSONArray("paths").getJSONObject(0);
    double distance = path.getDouble("distance");
    assertTrue("distance wasn't correct:" + distance, distance > 9000);
    assertTrue("distance wasn't correct:" + distance, distance < 9500);
}

From source file:com.rucker.weatherface.asynctask.GetWeatherInfoTask.java

@Override
protected HashMap<String, String> doInBackground(Location... params) {
    // A very sketchy, rough way of getting the local weather forecast from the phone's approximate location
    // using the OpenWeatherMap webservice: http://openweathermap.org/wiki/API/JSON_API
    double latitude = params[0].getLatitude();
    double longitude = params[0].getLongitude();
    HashMap<String, String> results = new HashMap<String, String>();

    Log.i(TAG, "Found latitude of " + latitude + " and longitude of " + longitude);

    try {/*from   ww w.j a  v  a2s .  c om*/
        URL u = new URL(String.format("http://api.openweathermap.org/data/2.1/find/city?lat=%f&lon=%f&cnt=1",
                latitude, longitude));

        HttpURLConnection urlConnection = (HttpURLConnection) u.openConnection();
        try {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(urlConnection.getInputStream(), "UTF-8"));
            String json = reader.readLine();

            JSONObject jsonObject = new JSONObject(json);
            JSONObject l = jsonObject.getJSONArray("list").getJSONObject(0);
            JSONObject m = l.getJSONObject("main");
            double temperature = m.getDouble("temp");
            String location = l.getString("name");
            int wtype = l.getJSONArray("weather").getJSONObject(0).getInt("id");

            int weatherIcon = getIconFromWeatherId(wtype);
            //Convert Kelvin to Fahrenheit
            String temp = String.format("%d\u00B0F", (int) (temperature * 9 / 5 - 459.67));

            results.put(MainActivity.KEY_LOCATION_NAME, location);
            results.put(MainActivity.KEY_TEMP, temp);

            Log.d("WeatherActivity", "Got temperature of " + temp + " for location: "
                    + String.format("%f, %f", latitude, longitude));
            sendWeatherDataToWatch(weatherIcon, temp);
        } finally {
            urlConnection.disconnect();
        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return results;
}

From source file:org.mozilla.gecko.gfx.ViewportMetrics.java

public ViewportMetrics(JSONObject json) throws JSONException {
    float x = (float) json.getDouble("x");
    float y = (float) json.getDouble("y");
    float width = (float) json.getDouble("width");
    float height = (float) json.getDouble("height");
    float pageWidth = (float) json.getDouble("pageWidth");
    float pageHeight = (float) json.getDouble("pageHeight");
    float offsetX = (float) json.getDouble("offsetX");
    float offsetY = (float) json.getDouble("offsetY");
    float zoom = (float) json.getDouble("zoom");

    mPageSize = new FloatSize(pageWidth, pageHeight);
    mViewportRect = new RectF(x, y, x + width, y + height);
    mViewportOffset = new PointF(offsetX, offsetY);
    mZoomFactor = zoom;//from w ww .j a v a 2s  .  c  o  m
    mViewportBias = new PointF(0.0f, 0.0f);
}