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:com.emuneee.nctrafficcams.tasks.GetLatestCameras.java

private Map<String, Camera> jsonToCamera(String cameraJson) throws JSONException {
    JSONArray cameraJsonArray = new JSONArray(cameraJson);
    Map<String, Camera> cameraSet = new HashMap<String, Camera>();

    for (int i = 0; i < cameraJsonArray.length(); i++) {
        JSONObject cameraJsonObj = cameraJsonArray.getJSONObject(i);
        Camera camera = new Camera();
        camera.setId(filterStrings(cameraJsonObj.getString("_id")));
        camera.setTitle(filterStrings(cameraJsonObj.getString("title")));
        camera.setUrl(filterStrings(cameraJsonObj.getString("url")));
        camera.setLatitude(cameraJsonObj.getDouble("latitude"));
        camera.setLongitude(cameraJsonObj.getDouble("longitude"));
        camera.setCity(filterStrings(cameraJsonObj.getString("city")));
        camera.setZipCode(filterStrings(cameraJsonObj.getString("zipcode")));
        cameraSet.put(camera.getId(), camera);
    }/*from   w ww  .  ja va  2s . co  m*/
    return cameraSet;
}

From source file:com.microsoft.research.webngram.service.impl.GenerationServiceImpl.java

@Override
public TokenSet generate(String authorizationToken, String modelUrn, String phraseContext, Integer maxN,
        String cookie) {//from   w w w .  j a  v a  2  s . c o m
    try {
        NgramServiceApiUrlBuilder urlBuilder = createNgramServiceApiUrlBuilder(
                NgramServiceApiUrls.GENERATE_URL);
        String apiUrl = urlBuilder.withParameter(ParameterNames.USER_TOKEN, authorizationToken)
                .withField(ParameterNames.MODEL_URL, modelUrn)
                .withParameter(ParameterNames.PHRASE, phraseContext)
                .withParameter(ParameterNames.MAX_TOKENS, maxN.toString())
                .withParameter(ParameterNames.COOKIE, cookie).buildUrl();
        TokenSet tokenSet = new TokenSet();
        JSONObject object = new JSONObject(convertStreamToString(callApiGet(apiUrl)));
        tokenSet.setBackoff(object.getDouble("backoff"));
        tokenSet.setCookie(object.getString("cookie"));
        JSONArray probabilities = object.getJSONArray("probabilities");
        for (int i = 0; i < probabilities.length(); i++) {
            tokenSet.getProbabilities().add(probabilities.getDouble(i));
        }
        JSONArray words = object.getJSONArray("words");
        for (int i = 0; i < words.length(); i++) {
            tokenSet.getWords().add(words.getString(i));
        }
        return tokenSet;
    } catch (Exception e) {
        throw new NgramServiceException("An error occurred while generating token set.", e);
    }
}

From source file:controllers.core.TimesheetController.java

/**
 * Save the weekly timesheet.//from w w w  . j a  v a  2s .  co  m
 */
@Restrict({ @Group(IMafConstants.TIMESHEET_ENTRY_PERMISSION) })
public Result weeklySave() {

    String[] dataString = request().body().asFormUrlEncoded().get("data");

    try {
        JSONObject dataJson = new JSONObject(dataString[0]);

        // get the report
        Long reportId = dataJson.getLong("reportId");
        TimesheetReport report = TimesheetDao.getTimesheetReportById(reportId);

        // create the date format
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        // get the actor
        Actor actor = getCurrentActor();

        // check the report belongs to the sign-in user
        if (!report.actor.id.equals(actor.id)) {
            return forbidden(views.html.error.access_forbidden.render(""));
        }

        // check the report is editable
        if (!report.isEditable()) {
            Utilities.sendErrorFlashMessage(Msg.get("core.timesheet.fill.save.error.non_editable"));
            return redirect(
                    controllers.core.routes.TimesheetController.weeklyFill(sdf.format(report.startDate)));
        }

        Ebean.beginTransaction();

        try {

            // get the entries
            JSONArray entriesJson = dataJson.getJSONArray("entries");

            for (int i = 0; i < entriesJson.length(); i++) {

                JSONObject entryJson;
                try {
                    entryJson = entriesJson.getJSONObject(i);
                } catch (JSONException e) {
                    entryJson = null;
                }

                if (entryJson != null) {

                    // get the attributes
                    boolean inDB = entryJson.getBoolean("inDB");

                    Boolean toRemove;
                    try {
                        toRemove = entryJson.getBoolean("toRemove");
                    } catch (JSONException e) {
                        toRemove = null;
                    }

                    Long entryId;
                    try {
                        entryId = entryJson.getLong("entryId");
                    } catch (JSONException e) {
                        entryId = null;
                    }

                    Long portfolioEntryId;
                    try {
                        portfolioEntryId = entryJson.getLong("portfolioEntryId");
                    } catch (JSONException e) {
                        portfolioEntryId = null;
                    }

                    Long packageId;
                    try {
                        packageId = entryJson.getLong("packageId");
                    } catch (JSONException e) {
                        packageId = null;
                    }

                    Long activityId;
                    try {
                        activityId = entryJson.getLong("activityId");
                    } catch (JSONException e) {
                        activityId = null;
                    }

                    // get the logs
                    JSONArray logsJson = entryJson.getJSONArray("logs");

                    if (logsJson.length() == 7) {

                        TimesheetEntry entry = null;
                        if (inDB) {
                            entry = TimesheetDao.getTimesheetEntryById(entryId);
                        } else {
                            entry = new TimesheetEntry();
                            entry.timesheetReport = report;
                        }

                        if (inDB && toRemove) {
                            entry.doDelete();
                        } else {

                            entry.portfolioEntry = null;
                            entry.portfolioEntryPlanningPackage = null;
                            entry.timesheetActivity = null;

                            if (portfolioEntryId != null) { // initiative
                                entry.portfolioEntry = PortfolioEntryDao.getPEById(portfolioEntryId);
                                if (packageId != null) {
                                    entry.portfolioEntryPlanningPackage = PortfolioEntryPlanningPackageDao
                                            .getPEPlanningPackageById(packageId);
                                }
                            } else { // activity
                                entry.timesheetActivity = TimesheetDao.getTimesheetActivityById(activityId);
                            }

                            entry.save();

                            for (int j = 0; j < logsJson.length(); j++) {

                                JSONObject logJson = logsJson.getJSONObject(j);

                                // get the attributes
                                double hours = logJson.getDouble("hours");

                                Long logId;
                                try {
                                    logId = logJson.getLong("logId");
                                } catch (JSONException e) {
                                    logId = null;
                                }

                                TimesheetLog log = null;
                                if (inDB) {
                                    log = TimesheetDao.getTimesheetLogById(logId);
                                } else {
                                    log = new TimesheetLog();
                                    log.timesheetEntry = entry;

                                    Calendar cal = Calendar.getInstance();
                                    cal.setTime(report.startDate);
                                    cal.add(Calendar.DAY_OF_YEAR, j);
                                    log.logDate = cal.getTime();
                                }

                                log.hours = hours;

                                log.save();

                            }
                        }

                    }

                }

            }

            Ebean.commitTransaction();

        } catch (Exception e) {
            Ebean.rollbackTransaction();
            return ControllersUtils.logAndReturnUnexpectedError(e, log, getConfiguration(),
                    getI18nMessagesPlugin());
        }

        Utilities.sendSuccessFlashMessage(Msg.get("core.timesheet.fill.save.successful"));

        return redirect(controllers.core.routes.TimesheetController.weeklyFill(sdf.format(report.startDate)));

    } catch (Exception e) {
        return ControllersUtils.logAndReturnUnexpectedError(e, log, getConfiguration(),
                getI18nMessagesPlugin());
    }

}

From source file:com.simas.vc.helpers.Utils.java

/**
 * Convenience method to fetch a double from a {@code JSONObject} or return null if it's not
 * found.//from   ww  w.  j a v  a2s  . c  om
 * @param obj    JSONObject to look in
 * @param key    String representing the key to look for
 * @return double for the given key or null if it wasn't found
 */
public static Double getJSONDouble(JSONObject obj, String key) {
    try {
        return obj.getDouble(key);
    } catch (JSONException e) {
        Log.w(TAG, "Error fetching double!", e);
        return null;
    }
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawPrice(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//from ww w  . j  a  v a2s .c  o  m
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            String str = "";
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(-DX / 2, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp"));
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 2.5f, 0);
            //String zhangfu = Utils.dataFormation(zhangf*100, stockdigit);
            //?????2?
            String zhangfu = Utils.dataFormation(zhangf * 100, 1, jo.getInt("tp"));
            if (zhangfu.equals("-") || zhangfu.equals(""))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(-DX * 3, DY * 1.2f);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            canvas.translate(DX * 2, -DY * 4);
            for (int i = 1; i <= 5; i++) {
                double temp2 = jo.getDouble("sjw" + i);
                setColor(paint, temp2, zrsp);
                str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
                canvas.drawText(str, x, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2 - DX * 2, -DY * 4);
            for (int i = 1; i <= 5; i++) {
                paint.setTextAlign(Paint.Align.RIGHT);
                canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl" + i), false), x - tips, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(0, -DY * 7);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            //paint.setTextAlign(Paint.Align.CENTER);
            canvas.translate(DX * 2, -DY * 7);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x, y, paint);

            canvas.translate(0, DY);
            for (int i = 1; i <= 5; i++) {
                double temp2 = jo.getDouble("bjw" + i);
                setColor(paint, temp2, zrsp);
                str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
                canvas.drawText(str, x, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2 - DX * 2, -DY * 4);
            for (int i = 1; i <= 5; i++) {
                paint.setTextAlign(Paint.Align.RIGHT);
                canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl" + i), false), x - tips, y, paint);
                if (i != 5)
                    canvas.translate(0, DY);
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 3, DY * 1.2f);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2, -DY * 7);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawQihuo(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/*  ww w  .  j a v a 2s . co  m*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            String str = "";
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(-DX / 2, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp"));
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 2.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, 1);
            if (zhangfu.equals("-") || zhangfu.equals(""))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);

            canvas.translate(-DX * 3, DY * 1.2f);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(" ", x, y, paint);

            canvas.translate(width / 2, -DY * 2);
            paint.setTextAlign(Paint.Align.RIGHT);
            double temp2 = jo.getDouble("sjw1");
            setColor(paint, temp2, zrsp);
            str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
            canvas.drawText(str, x - tips, y, paint);

            canvas.translate(0, DY);
            temp2 = jo.getDouble("bjw1");
            setColor(paint, temp2, zrsp);
            str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp"));
            canvas.drawText(str, x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0, jo.getInt("tp")), x - tips, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(0, -DY * 5);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(" ", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 5);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x - tips, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x - tips, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x - tips, y, paint);

            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl1"), false), x - tips, y, paint);

            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl1"), false), x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0, jo.getInt("tp")), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 3, DY * 1.2f);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText(" ", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2, -DY * 5);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("?", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText(" ", x, y, paint);
    }
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawHKIndex(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/* w  w w .jav  a  2s .com*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX * 0.5f, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(0, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 3.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);

            canvas.translate(-DX * 4f, DY * 1.2f);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);

            canvas.translate(width / 2, -DY * 1);
            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(0, -DY * 4);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 3);
            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit), x - tips, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit), x - tips, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 3, DY * 1.2f);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2, -DY * 4);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}

From source file:com.cssweb.android.view.PriceMini.java

public void drawIndex(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//from  www .  j a  v  a2  s  .c o  m
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);
            double zrsp = jo.getDouble("zrsp");

            double zjcj = jo.getDouble("zjcj");
            paint.setTextSize(mTextSize * 2);
            setColor(paint, zjcj, zrsp);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(DX * 0.5f, DY * 2f);
            canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint);

            paint.setStyle(Paint.Style.STROKE);
            paint.setTextSize(mTextSize);

            double zhangd = jo.getDouble("zd");
            if (zhangd < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangd > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(0, DY * 0.8f);
            String zhangdie = Utils.dataFormation(zhangd, stockdigit);
            if (zhangdie.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangdie, x, y, paint);

            double zhangf = jo.getDouble("zf");
            if (zhangf < 0) {
                paint.setColor(GlobalColor.colorPriceDown);
            } else if (zhangf > 0) {
                paint.setColor(GlobalColor.colorpriceUp);
            } else {
                paint.setColor(GlobalColor.colorPriceEqual);
            }
            canvas.translate(DX * 3.5f, 0);
            String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit);
            if (zhangfu.equals("-"))
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(zhangfu + "%", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(-DX * 3.5f, DY * 1.2f);
            //canvas.translate(-DX*0.5f, DY*2f);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("??", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setColor(GlobalColor.colorLabelName);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.translate(width / 2 - DX, -DY * 7);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, 0);
            canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x, y, paint);

            canvas.translate(width / 2, -DY * 3);
            paint.setTextAlign(Paint.Align.RIGHT);

            double jrkp = jo.getDouble("jrkp");
            setColor(paint, jrkp, zrsp);
            canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x, y, paint);

            canvas.translate(0, DY);
            double zg = jo.getDouble("zgcj");
            setColor(paint, zg, zrsp);
            canvas.drawText(Utils.dataFormation(zg, stockdigit), x, y, paint);

            canvas.translate(0, DY);
            double zd = jo.getDouble("zdcj");
            setColor(paint, zd, zrsp);
            canvas.drawText(Utils.dataFormation(zd, stockdigit), x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            double amp = jo.getDouble("amp");
            if (amp == 0)
                canvas.drawText("", x, y, paint);
            else
                canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x, y, paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x, y, paint);

            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.drawText(String.valueOf(jo.getInt("dj")), x, y, paint);

        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    } else {//?????
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setColor(GlobalColor.colorLabelName);

        canvas.translate(DX, DY * 2f);
        canvas.drawText("-", x, y, paint);

        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(mTextSize);

        canvas.translate(-DX / 2, DY * 0.8f);
        canvas.drawText("-", x, y, paint);

        canvas.translate(DX * 2.5f, 0);
        canvas.drawText("-", x, y, paint);
        canvas.translate(-DX * 2.5f, DY * 1.2f);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("??", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);

        paint.setTextAlign(Paint.Align.LEFT);
        canvas.translate(width / 2 - DX, -DY * 7);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
        canvas.translate(0, DY);
        canvas.drawText("", x, y, paint);
    }
}

From source file:fr.bde_eseo.eseomega.lacommande.model.LacmdCategory.java

public LacmdCategory(JSONObject obj) throws JSONException {
    this.name = obj.getString("name");
    this.imgUrl = obj.getString("imgUrl");
    this.beginPrice = obj.getDouble("firstPrice");
    this.catname = obj.getString("catname");
    this.smallText = obj.getString("briefText");
}

From source file:com.google.android.apps.santatracker.games.gumball.TiltGameFragment.java

/**
 * Loads a level from the levels json file and sets up the game world.
 */// www.ja va  2  s  .  c  om
private void loadLevel(int levelNumber) {

    // Reset the current game state
    if (mCountDownTimer != null) {
        mCountDownTimer.cancel();
    }
    mCountLevelBallRespawns = 0;
    mNumberCollected = 0;
    mViewPlayAgainLevel.setText(String.valueOf(levelNumber));
    Body body = mWorld.getWorld().getBodyList();
    while (body != null) {
        if (body.m_userData == null) {
            body = body.getNext();
            continue;
        }
        mWorld.mBodiesToBeRemoved.add(body);
        body = body.getNext();
    }
    mWorld.getWorld().step(1.0f / 60.0f, 10, 10);

    try {
        // Read the level file and extract the candy cane positions
        JSONObject level = readLevelFile(levelNumber);
        JSONArray canes = level.getJSONArray("candycanes");

        for (int i = 0; i < canes.length(); i++) {
            JSONObject canePart = canes.getJSONObject(i);
            int type = canePart.getInt("type");
            float xPos = (float) canePart.getDouble("xPos");
            float yPos = (float) canePart.getDouble("yPos");
            // Add the candy cane to the game world, the values represent the
            mWorld.addItem(xPos, yPos, Edges.getEdges(type), WORLD_OBJECT_BOUNCE, type, WORLD_OBJECT_DENSITY,
                    WORLD_OBJECT_FRICTION, BodyType.STATIC);
        }

        // Add the sides and floor to the game world to catch dropped balls.
        // Note that the WORLD_FRICTION is used as the bounce rate of the floors.
        mWorld.addItem(WORLD_FLOOR_X, WORLD_FLOOR_Y, Edges.getPipeSideEdges(), WORLD_OBJECT_BOUNCE,
                TiltGameView.PIPE_SIDES, WORLD_OBJECT_DENSITY, WORLD_OBJECT_FRICTION, BodyType.STATIC);
        mWorld.addFloor(WORLD_FLOOR_X, WORLD_FLOOR_Y, TiltGameView.GAME_FLOOR, WORLD_OBJECT_DENSITY,
                WORLD_OBJECT_FRICTION, WORLD_FLOOR_FRICTION, BodyType.STATIC);
        mWorld.addPipeBottom(WORLD_FLOOR_X, WORLD_FLOOR_Y, TiltGameView.PIPE_BOTTOM, WORLD_OBJECT_DENSITY,
                WORLD_OBJECT_FRICTION, WORLD_FLOOR_FRICTION, BodyType.STATIC);

        // Add the gumballs
        JSONArray gumballs = level.getJSONArray("gumballs");
        mGameBallsLeft = gumballs.length();
        setIndicators(mGameBallsLeft);
        for (int j = 0; j < gumballs.length(); j++) {
            JSONObject gumball = gumballs.getJSONObject(j);
            float xPos = (float) gumball.getDouble("xPos");
            float yPos = (float) gumball.getDouble("yPos");
            Gumball gumballObject = new Gumball();
            gumballObject.mXInitPos = xPos;
            gumballObject.mYInitPos = yPos;
            mGumballQueue.add(gumballObject);
        }
        mCurrentGumball = mGumballQueue.poll();

        // Start the timer
        if (mCurrentGumball != null) {
            if (mCurrentLevelNum > 1) {
                // Do not include gumball dropping time in countdown calculation.
                mTimeLeftInMillis += MatchingGameConstants.GUMBALL_ADDED_TIME;
            }
            mCountDownTimer = new GameCountdown(mFramesPerSecond, mTimeLeftInMillis);
            mCountDownTimer.start();
            mGameView.setGameCountDown(mCountDownTimer);

            // Move the outlet to its initial position
            moveOutlet((mCurrentGumball.mXInitPos));
        }
    } catch (IOException e) {
    } catch (JSONException e) {
    }

}