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, double defaultValue) 

Source Link

Document

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

Usage

From source file:com.google.fpl.liquidfunpaint.ScreenRenderer.java

public ScreenRenderer(Context context, JSONObject json, Texture fboTexture) {
    mMaterial = new Material(new ShaderProgram("texture.glslv", "screen.glslf"));

    mMaterial.addAttribute("aPosition", 3, Material.AttrComponentType.FLOAT, 4, false,
            RenderHelper.SCREEN_QUAD_VERTEX_STRIDE);
    mMaterial.addAttribute("aTexCoord", 2, Material.AttrComponentType.FLOAT, 4, false,
            RenderHelper.SCREEN_QUAD_VERTEX_STRIDE);

    // Add the diffuse texture: particle FBO
    mMaterial.addTexture("uDiffuseTexture", fboTexture);

    mMaterial.setBlendFunc(Material.BlendFactor.SRC_ALPHA, Material.BlendFactor.ONE_MINUS_SRC_ALPHA);

    // Read in values from the JSON file

    // Alpha threshold
    mAlphaThreshold = (float) (json.optDouble("alphaThreshold", 0.0));
}

From source file:com.facebook.notifications.internal.content.TextContent.java

public TextContent(@NonNull JSONObject json) throws JSONException {
    text = json.optString("text", "");
    textColor = ColorAssetHandler.fromRGBAHex(json.optString("color"));

    typeface = json.optString("font");
    typefaceSize = (float) json.optDouble("size", 18); // Default to 18sp, or 'medium' size.

    textAlignment = Alignment.parse(json.optString("align", "center"));
}

From source file:fr.cobaltians.cobalt.fragments.CobaltWebLayerFragment.java

/********************************************************************************************
 * DISMISS/*  ww  w.  jav a  2  s. c o m*/
 *******************************************************************************************/

protected void dismissWebLayer(JSONObject jsonObject) {
    if (getActivity() != null) {
        FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();

        if (jsonObject != null) {
            mData = jsonObject.optJSONObject(Cobalt.kJSData);
            double fadeDuration = jsonObject.optDouble(Cobalt.kJSWebLayerFadeDuration, 0);

            if (fadeDuration > 0) {
                fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
                        android.R.anim.fade_in, android.R.anim.fade_out);
            } else {
                fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_NONE);
            }
        } else {
            fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_NONE);
        }

        fragmentTransaction.remove(this);
        fragmentTransaction.commit();
    } else if (Cobalt.DEBUG)
        Log.e(Cobalt.TAG, TAG + " - dismissWebLayer: Web layer is not attached to an activity.");
}

From source file:com.hichinaschool.flashcards.libanki.Storage.java

private static void _upgrade(Collection col, int ver) {
    try {//from  w  w w . j  av  a 2  s  . c om
        if (ver < 3) {
            // new deck properties
            for (JSONObject d : col.getDecks().all()) {
                d.put("dyn", 0);
                d.put("collapsed", false);
                col.getDecks().save(d);
            }
        }
        if (ver < 4) {
            col.modSchema();
            ArrayList<JSONObject> clozes = new ArrayList<JSONObject>();
            for (JSONObject m : col.getModels().all()) {
                if (!m.getJSONArray("tmpls").getJSONObject(0).getString("qfmt").contains("{{cloze:")) {
                    m.put("type", Sched.MODEL_STD);
                } else {
                    clozes.add(m);
                }
            }
            for (JSONObject m : clozes) {
                _upgradeClozeModel(col, m);
            }
            col.getDb().execute("UPDATE col SET ver = 4");
        }
        if (ver < 5) {
            col.getDb().execute("UPDATE cards SET odue = 0 WHERE queue = 2");
            col.getDb().execute("UPDATE col SET ver = 5");
        }
        if (ver < 6) {
            col.modSchema();
            for (JSONObject m : col.getModels().all()) {
                m.put("css", new JSONObject(Models.defaultModel).getString("css"));
                JSONArray ar = m.getJSONArray("tmpls");
                for (int i = 0; i < ar.length(); i++) {
                    JSONObject t = ar.getJSONObject(i);
                    if (!t.has("css")) {
                        continue;
                    }
                    m.put("css", m.getString("css") + "\n"
                            + t.getString("css").replace(".card ", ".card" + t.getInt("ord") + 1));
                    t.remove("css");
                }
                col.getModels().save(m);
            }
            col.getDb().execute("UPDATE col SET ver = 6");
        }
        if (ver < 7) {
            col.modSchema();
            col.getDb().execute("UPDATE cards SET odue = 0 WHERE (type = 1 OR queue = 2) AND NOT odid");
            col.getDb().execute("UPDATE col SET ver = 7");
        }
        if (ver < 8) {
            col.modSchema();
            col.getDb().execute("UPDATE cards SET due = due / 1000 WHERE due > 4294967296");
            col.getDb().execute("UPDATE col SET ver = 8");
        }
        if (ver < 9) {
            col.getDb().execute("UPDATE col SET ver = 9");
        }
        if (ver < 10) {
            col.getDb().execute("UPDATE cards SET left = left + left * 1000 WHERE queue = 1");
            col.getDb().execute("UPDATE col SET ver = 10");
        }
        if (ver < 11) {
            col.modSchema();
            for (JSONObject d : col.getDecks().all()) {
                if (d.getInt("dyn") != 0) {
                    int order = d.getInt("order");
                    // failed order was removed
                    if (order >= 5) {
                        order -= 1;
                    }
                    JSONArray ja = new JSONArray(
                            Arrays.asList(new Object[] { d.getString("search"), d.getInt("limit"), order }));
                    d.put("terms", new JSONArray());
                    d.getJSONArray("terms").put(0, ja);
                    d.remove("search");
                    d.remove("limit");
                    d.remove("order");
                    d.put("resched", true);
                    d.put("return", true);
                } else {
                    if (!d.has("extendNew")) {
                        d.put("extendNew", 10);
                        d.put("extendRev", 50);
                    }
                }
                col.getDecks().save(d);
            }
            for (JSONObject c : col.getDecks().allConf()) {
                JSONObject r = c.getJSONObject("rev");
                r.put("ivlFct", r.optDouble("ivlFct", 1));
                if (r.has("ivlfct")) {
                    r.remove("ivlfct");
                }
                r.put("maxIvl", 36500);
                col.getDecks().save(c);
            }
            for (JSONObject m : col.getModels().all()) {
                JSONArray tmpls = m.getJSONArray("tmpls");
                for (int ti = 0; ti < tmpls.length(); ++ti) {
                    JSONObject t = tmpls.getJSONObject(ti);
                    t.put("bqfmt", "");
                    t.put("bafmt", "");
                }
                col.getModels().save(m);
            }
            col.getDb().execute("update col set ver = 11");
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlock.java

static final PaperPiecedBlock createFromJSONObject(JSONObject jsonObject) throws JSONException {

    float width = (float) jsonObject.optDouble("width", 0);
    float height = (float) jsonObject.optDouble("height", 0);
    int backgroundColor = jsonObject.optInt("backgroundColor", Color.WHITE);

    PaperPiecedBlock block = new PaperPiecedBlock(width, height, backgroundColor);

    JSONArray jsonPieces = jsonObject.getJSONArray("pieces");
    for (int idx = 0; idx < jsonPieces.length(); ++idx) {
        JSONObject jsonPiece = jsonPieces.getJSONObject(idx);
        block.m_pieces.add(PaperPiecedBlockPiece.createFromJSONObject(jsonPiece));
    }/*from w ww. java  2s.com*/

    return block;
}

From source file:piuk.blockchain.android.ExchangeRatesProvider.java

private static Map<String, Double> getExchangeRates() {
    try {//from   w ww  .j  a  v a 2  s.c o m
        final URLConnection connection = new URL("http://bitcoincharts.com/t/weighted_prices.json")
                .openConnection();
        // https://mtgox.com/code/data/ticker.php
        // https://bitmarket.eu/api/ticker
        // http://bitcoincharts.com/t/weighted_prices.json

        connection.connect();
        final Reader is = new InputStreamReader(new BufferedInputStream(connection.getInputStream()));
        final StringBuilder content = new StringBuilder();
        IOUtils.copy(is, content);
        is.close();

        final Map<String, Double> rates = new TreeMap<String, Double>();

        final JSONObject head = new JSONObject(content.toString());
        for (@SuppressWarnings("unchecked")
        final Iterator<String> i = head.keys(); i.hasNext();) {
            final String currencyCode = i.next();
            if (!"timestamp".equals(currencyCode)) {
                final JSONObject o = head.getJSONObject(currencyCode);
                double rate = o.optDouble("24h", 0);
                if (rate == 0)
                    rate = o.optDouble("7d", 0);
                if (rate == 0)
                    rate = o.optDouble("30d", 0);

                if (rate != 0)
                    rates.put(currencyCode, rate);
            }
        }

        return rates;
    } catch (final IOException x) {
        x.printStackTrace();
    } catch (final JSONException x) {
        x.printStackTrace();
    }

    return null;
}