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.dedipower.portal.android.InvoiceLanding.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.invoicelanding);
    final ListView list = (ListView) findViewById(R.id.InvoiceList);

    final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....",
            true);/* w  ww . j a v  a 2  s. c o m*/
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                InvoiceAdaptor adapter = new InvoiceAdaptor(InvoiceLanding.this, listOfInvoices, API.SessionID);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                InvoiceAPIReturn = API.PortalQueryHack("invoices", "", "");
                Success = InvoiceAPIReturn.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occured.";
                Success = "false";
            }

            if (Success.equals("false")) {
                Log.i("API", "Success was false");
                try {
                    ErrorMessage = InvoiceAPIReturn.getJSONObject("hackReturn").getString("msg");
                } catch (JSONException e) {
                    ErrorMessage = "A JSON parsing error prevented an exact error message to be determined.";
                }
            } else {
                int InvoiceCount = 0;
                Log.i("APIFuncs", InvoiceAPIReturn.toString());
                try {
                    Invoices = InvoiceAPIReturn.getJSONObject("hackReturn").getJSONArray("data");
                    InvoiceCount = Invoices.length();
                    ErrorMessage = "";
                } catch (JSONException e) {
                    ErrorMessage = "There don't appear to be any invoices for your account.....";
                    InvoiceCount = 0;
                    Log.e("API", "There was an eror parsing the array");
                    Log.e("API", e.getMessage());
                }

                //OK lets actually do something useful

                if (InvoiceCount == 0) {
                    Success = "false";
                    ErrorMessage = "There are no invoices for your account.";
                    handler.sendEmptyMessage(0);
                    return;
                }

                for (int i = 0; i < InvoiceCount; i++) {
                    JSONObject CurrentInvoice = null;
                    try {
                        CurrentInvoice = Invoices.getJSONObject(i);
                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }
                    try {
                        if (CurrentInvoice.getString("type").equals("invoice"))
                            listOfInvoices.add(new Invoices(CurrentInvoice.getString("ref"),
                                    CurrentInvoice.getDouble("amount"), CurrentInvoice.getString("details"),
                                    CurrentInvoice.getLong("date")));
                    } catch (JSONException e) {
                        Log.e("APIFuncs", e.getMessage());
                    }
                }
            }

            handler.sendEmptyMessage(0);
        }
    };

    dataPreload.start();
}

From source file:com.justinbull.ichnaeachecker.MainActivity.java

public RequestHandle getIchnaeaLookup(final Snackbar snack) {
    Log.i(TAG, "getIchnaeaLookup: Looking up " + mSelectedCell);
    return IchnaeaRestClient.geolocate(mSelectedCell, new JsonHttpResponseHandler() {
        @Override//  w  w w  . j ava 2  s  .c  o  m
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                Log.i(TAG, "onSuccess: Cell in database! Location is: " + response.get("location") + " for "
                        + mSelectedCell);
                TextView text = (TextView) findViewById(R.id.topLevelText);
                assert text != null;
                text.setText("Cell " + mSelectedCell.getFriendlyCellIdentity() + " in database!");
                TextView textLat = (TextView) findViewById(R.id.latitudeText);
                TextView textLng = (TextView) findViewById(R.id.longitudeText);
                TextView textAcurracy = (TextView) findViewById(R.id.accuracyText);
                assert textLat != null;
                assert textLng != null;
                assert textAcurracy != null;
                textLat.setText(
                        "Latitude: " + Double.toString(response.getJSONObject("location").getDouble("lat")));
                textLng.setText(
                        "Longitude: " + Double.toString(response.getJSONObject("location").getDouble("lng")));
                textAcurracy
                        .setText("Accuracy: " + Double.toString(response.getDouble("accuracy")) + " meters");
                textLat.setVisibility(View.VISIBLE);
                textLng.setVisibility(View.VISIBLE);
                textAcurracy.setVisibility(View.VISIBLE);
                Snackbar snackSuccess = Snackbar.make(
                        snack.getView(), mSelectedCell.getCellType() + " Cell "
                                + mSelectedCell.getFriendlyCellIdentity() + " in Ichnaea database!",
                        Snackbar.LENGTH_LONG);
                snackSuccess.getView()
                        .setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorSuccess));
                snackSuccess.show();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            try {
                if (statusCode == 404 && errorResponse.getJSONObject("error").getInt("code") == 404) {
                    Log.i(TAG, "onFailure: Cell is not in database: " + mSelectedCell);
                    TextView text = (TextView) findViewById(R.id.topLevelText);
                    assert text != null;
                    text.setText("NOT IN DATABASE!");
                    TextView textLat = (TextView) findViewById(R.id.latitudeText);
                    TextView textLng = (TextView) findViewById(R.id.longitudeText);
                    TextView textAcurracy = (TextView) findViewById(R.id.accuracyText);
                    textLat.setVisibility(View.INVISIBLE);
                    textLng.setVisibility(View.INVISIBLE);
                    textAcurracy.setVisibility(View.INVISIBLE);
                } else {
                    Toast.makeText(MainActivity.this, "Unknown error occurred", Toast.LENGTH_SHORT).show();
                }
            } catch (JSONException e) {
                Toast.makeText(MainActivity.this, "Unknown error occurred", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
            snack.dismiss();
        }

        @Override
        public void onCancel() {
            super.onCancel();
            snack.dismiss();
        }
    });
}

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

public void drawQuoteWin(Canvas canvas, JSONObject quoteData, int idx) throws JSONException {
    Paint mPaint = new Paint();
    mPaint.setTextAlign(Paint.Align.LEFT);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mPaint.setAntiAlias(true);//  w w  w  .j a v a2 s  . co  m

    mPaint.setColor(GlobalColor.colorKlinePopub);
    mPaint.setTextSize(sTextSize);
    canvas.drawText(":", 0, axisLabelHeight, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 3, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 5, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 7, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 9, mPaint);
    canvas.drawText(":", 0, axisLabelHeight * 11, mPaint);

    mPaint.setTextAlign(Paint.Align.RIGHT);
    String qt = quoteData.getJSONArray("K").getJSONArray(idx).getString(0);
    double jrkp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(1);
    double zg = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(2);
    double zd = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(3);
    double sp = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4);
    double preclose;
    if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) {
        switch (idx) {
        case 0:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(7);
            break;
        default:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(7);
            break;
        }
        if (quoteData.getJSONArray("K").length() == 1) {
            preclose = quoteData.getJSONArray("K").getJSONArray(0).getDouble(7);
        }
    } else {
        switch (idx) {
        case 0:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx).getDouble(4);
            break;
        default:
            preclose = quoteData.getJSONArray("K").getJSONArray(idx - 1).getDouble(4);
            break;
        }
        if (quoteData.getJSONArray("K").length() == 1) {
            preclose = quoteData.getDouble("zrsp");//quoteData.getJSONArray("K").getJSONArray(0).getDouble(4);
        }
    }
    //      if(quoteData.getJSONArray("K").length()==1 && quoteData.getJSONObject("todayData")!=null){
    //         preclose = quoteData.getJSONObject("todayData").getDouble("zrsp");
    //      }
    mPaint.setColor(getcolor(jrkp, preclose));
    canvas.drawText(Utils.dataFormation(jrkp, stockdigit), klineX, axisLabelHeight * 2, mPaint);
    mPaint.setColor(getcolor(zg, preclose));
    canvas.drawText(Utils.dataFormation(zg, stockdigit), klineX, axisLabelHeight * 4, mPaint);
    mPaint.setColor(getcolor(zd, preclose));
    canvas.drawText(Utils.dataFormation(zd, stockdigit), klineX, axisLabelHeight * 6, mPaint);
    mPaint.setColor(getcolor(sp, preclose));
    canvas.drawText(Utils.dataFormation(sp, stockdigit), klineX, axisLabelHeight * 8, mPaint);
    double zhangdie = sp - preclose;
    if (zhangdie > 0)
        mPaint.setColor(GlobalColor.colorpriceUp);
    else if (zhangdie < 0)
        mPaint.setColor(GlobalColor.colorPriceDown);
    else
        mPaint.setColor(GlobalColor.colorPriceEqual);
    canvas.drawText(Utils.dataFormation(zhangdie, 1), klineX, axisLabelHeight * 10, mPaint);
    if (quoteData.getString("period").equals("min5") || quoteData.getString("period").equals("min15")
            || quoteData.getString("period").equals("min30") || quoteData.getString("period").equals("min60")) {
        qt = qt.substring(4, 6) + '/' + qt.substring(6, 8) + ' ' + qt.substring(8);
    } else {
        qt = qt.substring(2, 4) + qt.substring(4, 6) + qt.substring(6, 8);
    }
    mPaint.setColor(GlobalColor.colorLabelName);
    canvas.drawText(qt, klineX, axisLabelHeight * 12, mPaint);
}

From source file:com.jennifer.ui.chart.ChartBuilder.java

@Override
public void drawBefore() {

    JSONObject series = cloneObject("series");
    JSONObject grid = cloneObject("grid");
    Object brush = clone("brush");
    Object widget = clone("widget");

    JSONArray data = cloneArray("data");

    // series ?? 
    for (int i = 0, len = data.length(); i < len; i++) {
        JSONObject row = (JSONObject) data.getJSONObject(i);

        Iterator it = row.keys();

        while (it.hasNext()) {
            String key = (String) it.next();

            if (!series.has(key)) {
                series.put(key, new JSONObject());
            }//from w  ww.  j a va 2s .  com

            JSONObject obj = JSONUtil.clone(series.getJSONObject(key));

            if (obj == null)
                continue;

            Object valueObject = row.get(key);

            if (valueObject instanceof String)
                continue;

            if (valueObject instanceof Double || valueObject instanceof Integer) {
                double value = row.getDouble(key);

                if (!obj.has("min"))
                    obj.put("min", value);
                if (!obj.has("max"))
                    obj.put("max", value);

                if (value < obj.getDouble("min"))
                    obj.put("min", value);
                if (value > obj.getDouble("max"))
                    obj.put("max", value);
            } else if (row.get(key) instanceof Long) {
                long value = row.getLong(key);

                if (!obj.has("min"))
                    obj.put("min", value);
                if (!obj.has("max"))
                    obj.put("max", value);

                if (value < obj.getLong("min"))
                    obj.put("min", value);
                if (value > obj.getLong("max"))
                    obj.put("max", value);
            }

            series.put(key, obj);
        }
    }
    // series_list
    barray("brush", createBrushData(brush, series.names()));
    barray("widget", createBrushData(widget, series.names()));
    bobject("grid", grid);
    bobject("hash", null);
    barray("data", data);
    bobject("series", series);

}

From source file:uk.co.senab.photup.model.PhotoTag.java

public PhotoTag(JSONObject object) throws JSONException {
    this((float) object.getDouble("x"), (float) object.getDouble("y"));
    mFriendId = object.getString("tag_uid");
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java

public static Object saveOrUpdateCurrencyRateFromJSON(JSONObject jsonObjectEntity) {

    if (!jsonObjectEntity.has("effective_date")) {
        //return null;
    }//from ww  w. j av a  2 s.co  m
    try {
        long toCurrencyId = getLocalKey(DatabaseHelper.CURRENCY_TABLE,
                jsonObjectEntity.getString("to_currency"));
        long fromCurrencyId = getLocalKey(DatabaseHelper.CURRENCY_TABLE,
                jsonObjectEntity.getString("from_currency"));
        if (toCurrencyId > -1 && fromCurrencyId > -1) {
            Currency toCurrency = em.load(Currency.class, toCurrencyId);
            Currency fromCurrency = em.load(Currency.class, fromCurrencyId);
            long effective_date = jsonObjectEntity.getLong("effective_date") * 1000;
            double rate = jsonObjectEntity.getDouble("rate");
            ExchangeRate exRate = new ExchangeRate();
            exRate.toCurrencyId = toCurrency.id;
            exRate.fromCurrencyId = fromCurrency.id;
            exRate.rate = rate;
            exRate.date = effective_date;
            dba.saveRate(exRate);
        }
    } catch (Exception e) {
        Log.e(TAG, "unable to load a currency rate from server...");
        e.printStackTrace();

    }
    return null;
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java

public static Object saveOrUpdateLocationFromJSON(long id, JSONObject jsonObjectEntity) {
    MyLocation tEntity = em.get(MyLocation.class, id);
    if (tEntity == null) {
        tEntity = new MyLocation();
        tEntity.id = KEY_CREATE;/* w w w .  j  a  va 2s.c  o m*/
    }
    try {
        tEntity.remoteKey = jsonObjectEntity.getString("key");
        if (jsonObjectEntity.has("name")) {
            tEntity.name = jsonObjectEntity.getString("name");
        } else {
            tEntity.name = "---";
        }
        if (jsonObjectEntity.has("provider")) {
            tEntity.provider = jsonObjectEntity.getString("provider");
        }
        if (jsonObjectEntity.has("accuracy")) {
            try {
                tEntity.accuracy = Float.valueOf(jsonObjectEntity.getString("accuracy"));
            } catch (Exception e) {
                Log.e(TAG,
                        "Error parsing MyLocation.accuracy with : " + jsonObjectEntity.getString("accuracy"));
            }
        }
        if (jsonObjectEntity.has("lon")) {
            tEntity.longitude = jsonObjectEntity.getDouble("lon");
        }
        if (jsonObjectEntity.has("lat")) {
            tEntity.latitude = jsonObjectEntity.getDouble("lat");
        }
        if (jsonObjectEntity.has("is_payee")) {
            if (jsonObjectEntity.getBoolean("is_payee")) {
                tEntity.isPayee = true;
            } else {
                tEntity.isPayee = false;
            }
        }
        if (jsonObjectEntity.has("resolved_adress")) {
            tEntity.resolvedAddress = jsonObjectEntity.getString("resolved_adress");
        }
        if (jsonObjectEntity.has("dateOfEmission")) {
            try {
                tEntity.dateTime = jsonObjectEntity.getLong("dateOfEmission");
            } catch (Exception e1) {
                Log.e(TAG, "Error parsing MyLocation.dateTime with : "
                        + jsonObjectEntity.getString("dateOfEmission"));
            }
        }
        if (jsonObjectEntity.has("count")) {
            tEntity.count = jsonObjectEntity.getInt("count");
        }
        if (jsonObjectEntity.has("dateTime")) {
            tEntity.dateTime = jsonObjectEntity.getLong("dateTime");
        }
        if (jsonObjectEntity.has("dateTime")) {
            tEntity.dateTime = jsonObjectEntity.getLong("dateTime");
        }
        em.saveOrUpdate(tEntity);
        return tEntity;
    } catch (Exception e) {
        e.printStackTrace();
        return e;
    }
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java

public static Object saveOrUpdateTransactionFromJSON(long id, JSONObject jsonObjectResponse)
        throws JSONException, Exception {
    Transaction tEntity = em.get(Transaction.class, id);
    if (tEntity == null) {
        tEntity = new Transaction();
        tEntity.id = KEY_CREATE;/* w w  w  . java 2  s.  c o  m*/
    }
    //from_account_id,
    try {
        tEntity.fromAccountId = getLocalKey(DatabaseHelper.ACCOUNT_TABLE,
                jsonObjectResponse.getString("account"));
    } catch (Exception e1) {
        Log.e("flowzr", "Error parsing Transaction.fromAccount");
        return null; //REQUIRED
    }
    if (jsonObjectResponse.has("dateTime")) {
        tEntity.dateTime = jsonObjectResponse.getLong("dateTime") * 1000;
    } else {
        return null; //REQUIRED
    }
    //parent_tr
    if (jsonObjectResponse.has("parent_tr")) {
        long pid = getLocalKey(DatabaseHelper.TRANSACTION_TABLE, jsonObjectResponse.getString("parent_tr"));
        if (pid > KEY_CREATE) {
            tEntity.parentId = pid;
            Transaction parent_tr = em.load(Transaction.class, tEntity.parentId);
            if (parent_tr.categoryId != Category.SPLIT_CATEGORY_ID) {
                parent_tr.categoryId = Category.SPLIT_CATEGORY_ID;
                em.saveOrUpdate(parent_tr);
            }
        } else {
            try {
                String key = jsonObjectResponse.getString("parent_tr");
                requery(DatabaseHelper.TRANSACTION_TABLE, Transaction.class, key);
                long pid2 = getLocalKey(DatabaseHelper.TRANSACTION_TABLE,
                        jsonObjectResponse.getString("parent_tr"));
                tEntity.parentId = pid2;
                Transaction parent_tr = em.load(Transaction.class, tEntity.parentId);
                if (parent_tr.categoryId != Category.SPLIT_CATEGORY_ID) {
                    parent_tr.categoryId = Category.SPLIT_CATEGORY_ID;
                    em.saveOrUpdate(parent_tr);
                }
            } catch (Exception e) {
                //add to delete log ?
                e.printStackTrace();
                //throw new Exception("Got key " + jsonObjectResponse.getString("parent_tr") + " but couldn't find related parent tr");
            }

        }
    }
    //to_account_id,
    if (jsonObjectResponse.has("to_account")) {
        try {
            tEntity.toAccountId = getLocalKey(DatabaseHelper.ACCOUNT_TABLE,
                    jsonObjectResponse.getString("to_account"));
        } catch (Exception e1) {
            Log.e("flowzr",
                    "Error parsing Transaction.toAccount with : " + jsonObjectResponse.getString("to_account"));
        }
    }
    if (jsonObjectResponse.has("key")) {
        tEntity.remoteKey = jsonObjectResponse.getString("key");
    }
    if (jsonObjectResponse.has("amount")) {
        tEntity.fromAmount = jsonObjectResponse.getLong("amount");
    }
    if (jsonObjectResponse.has("to_amount")) {
        tEntity.toAmount = jsonObjectResponse.getLong("to_amount");
    }
    if (jsonObjectResponse.has("original_currency_id")) {
        try {
            tEntity.originalCurrencyId = getLocalKey(DatabaseHelper.CURRENCY_TABLE,
                    jsonObjectResponse.getString("original_currency_id"));
        } catch (Exception e) {
            Log.e("flowzr", "Error parsing Transaction.original_currency_id with : "
                    + jsonObjectResponse.getString("original_currency_id"));
        }
    }
    if (jsonObjectResponse.has("original_from_amount")) {
        tEntity.originalFromAmount = (long) jsonObjectResponse.getDouble("original_from_amount");
    }

    if (jsonObjectResponse.has("description")) {
        tEntity.note = jsonObjectResponse.getString("description");
    }
    //category_id,
    if (jsonObjectResponse.has("cat")) {
        try {
            long l = getLocalKey(DatabaseHelper.CATEGORY_TABLE, jsonObjectResponse.getString("cat"));
            if (l >= KEY_CREATE) {
                tEntity.categoryId = l;
            } else {
                requery(DatabaseHelper.CATEGORY_TABLE, Category.class, jsonObjectResponse.getString("cat"));
                tEntity.categoryId = getLocalKey(DatabaseHelper.CATEGORY_TABLE,
                        jsonObjectResponse.getString("cat"));
            }
        } catch (Exception e1) {
            tEntity.categoryId = Category.NO_CATEGORY_ID;
            e1.printStackTrace();
            Log.e("flowzr",
                    "Error parsing Transaction.categoryId with : " + jsonObjectResponse.getString("cat"));
        }
    } else {
        tEntity.categoryId = Category.NO_CATEGORY_ID;
    }
    //project_id,
    if (jsonObjectResponse.has("project")) {
        try {
            tEntity.projectId = getLocalKey(DatabaseHelper.PROJECT_TABLE,
                    jsonObjectResponse.getString("project"));
            if (tEntity.projectId <= KEY_CREATE) {
                requery(DatabaseHelper.PROJECT_TABLE, Project.class, jsonObjectResponse.getString("project"));
                tEntity.projectId = getLocalKey(DatabaseHelper.PROJECT_TABLE,
                        jsonObjectResponse.getString("project"));
            }
        } catch (Exception e1) {
            Log.e("flowzr",
                    "Error parsing Transaction.ProjectId with : " + jsonObjectResponse.getString("project"));
        }
    }
    //payee_id,
    if (jsonObjectResponse.has("payee_id")) {
        try {
            tEntity.payeeId = getLocalKey(DatabaseHelper.PAYEE_TABLE, jsonObjectResponse.getString("payee_id"));
            if (tEntity.payeeId <= KEY_CREATE) {
                requery(DatabaseHelper.PAYEE_TABLE, Payee.class, jsonObjectResponse.getString("payee_id"));
                tEntity.payeeId = getLocalKey(DatabaseHelper.PAYEE_TABLE,
                        jsonObjectResponse.getString("payee_id"));
            }
        } catch (Exception e1) {
            Log.e("flowzr",
                    "Error parsing Transaction.PayeeId with : " + jsonObjectResponse.getString("payee_id"));
        }
    }
    //location_id
    if (jsonObjectResponse.has("location_id")) {
        try {
            long lid = getLocalKey(DatabaseHelper.LOCATIONS_TABLE, jsonObjectResponse.getString("location_id"));
            if (lid > 0) {
                tEntity.locationId = lid;
            } else {
                requery(DatabaseHelper.LOCATIONS_TABLE, MyLocation.class,
                        jsonObjectResponse.getString("location_id"));
                tEntity.locationId = getLocalKey(DatabaseHelper.LOCATIONS_TABLE,
                        jsonObjectResponse.getString("location_id"));
            }
        } catch (Exception e1) {
            Log.e("flowzr", "Error parsing Transaction.location_id with : "
                    + jsonObjectResponse.getString("location_id"));
        }
    }
    //accuracy,provider,latitude,longitude
    if (jsonObjectResponse.has("provider")) {
        tEntity.provider = jsonObjectResponse.getString("provider");
    }
    if (jsonObjectResponse.has("accuracy")) {
        try {
            tEntity.accuracy = jsonObjectResponse.getLong("accuracy");
        } catch (Exception e) {
            Log.e("flowzr", "Error getting accuracy value for transaction with:"
                    + jsonObjectResponse.getString("accuracy"));
        }
    }
    if (jsonObjectResponse.has("lat") && jsonObjectResponse.has("lon")) {
        try {
            tEntity.latitude = jsonObjectResponse.getDouble("lat");
            tEntity.longitude = jsonObjectResponse.getDouble("lon");
        } catch (Exception e) {
            Log.e("flowzr", "Error getting geo_point value for transaction with:"
                    + jsonObjectResponse.getString("lat") + " " + jsonObjectResponse.getDouble("lon"));
        }
    }
    tEntity.status = TransactionStatus.UR;
    if (jsonObjectResponse.has("status")) {
        if (jsonObjectResponse.getString("status").equals("UR")) {
            tEntity.status = TransactionStatus.UR;
        } else if (jsonObjectResponse.getString("status").equals("RC")) {
            tEntity.status = TransactionStatus.RC;
        } else if (jsonObjectResponse.getString("status").equals("CL")) {
            tEntity.status = TransactionStatus.CL;
        } else if (jsonObjectResponse.getString("status").equals("PN")) {
            tEntity.status = TransactionStatus.PN;
        } else if (jsonObjectResponse.getString("status").equals("RS")) {
            tEntity.status = TransactionStatus.RS;
        } else {
            tEntity.status = TransactionStatus.UR;
        }
    }
    //is_ccard_payment,
    if (jsonObjectResponse.has("is_ccard_payment")) {
        tEntity.isCCardPayment = jsonObjectResponse.getInt("is_ccard_payment");
    }
    List<TransactionAttribute> attributes = null;
    if (jsonObjectResponse.has("transaction_attribute")) {
        attributes = new LinkedList<TransactionAttribute>();
        for (String pair : jsonObjectResponse.getString("transaction_attribute").split(";")) {
            String[] strArrAttr = pair.split("=");
            if (strArrAttr.length == 2) {
                TransactionAttribute a = new TransactionAttribute();
                a.value = strArrAttr[1];
                a.attributeId = getLocalKey(DatabaseHelper.ATTRIBUTES_TABLE, strArrAttr[0]);
                a.transactionId = tEntity.id;
                attributes.add(a);
            }
        }
    }
    //blob url,
    if (jsonObjectResponse.has("blob_url") && tEntity.attachedPicture == null) {
        tEntity.blobKey = jsonObjectResponse.getString("blob_url");
    }

    id = em.saveOrUpdate(tEntity);
    if (attributes != null) {
        dba.db().delete(DatabaseHelper.TRANSACTION_ATTRIBUTE_TABLE,
                DatabaseHelper.TransactionAttributeColumns.TRANSACTION_ID + "=?",
                new String[] { String.valueOf(id) });
        for (TransactionAttribute a : attributes) {
            a.transactionId = id;
            ContentValues values = a.toValues();
            dba.db().insert(DatabaseHelper.TRANSACTION_ATTRIBUTE_TABLE, null, values);
        }
    }
    return tEntity;
}

From source file:com.lgallardo.qbittorrentclient.ContentFileTask.java

protected ArrayList<TorrentDetailsItem> doInBackground(String... params) {

    hash = params[0];/*from   ww w. j a v a  2s .co  m*/

    // Get torrent's files
    if (MainActivity.qb_version.equals("2.x")) {
        qbQueryString = "json";
    }

    if (MainActivity.qb_version.equals("3.1.x")) {
        qbQueryString = "json";
    }

    if (MainActivity.qb_version.equals("3.2.x")) {
        qbQueryString = "query";
    }

    url = qbQueryString + "/propertiesFiles/";

    contentFiles = new ArrayList<TorrentDetailsItem>();

    try {

        JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder,
                MainActivity.protocol, MainActivity.port, MainActivity.keystore_path,
                MainActivity.keystore_password, MainActivity.username, MainActivity.password,
                MainActivity.connection_timeout, MainActivity.data_timeout);

        jParser.setCookie(MainActivity.cookie);

        JSONArray jArray = jParser.getJSONArrayFromUrl(url + hash);

        if (jArray != null) {

            for (int i = 0; i < MAX_CONTENT_FILES && i < jArray.length(); i++) {

                JSONObject json = jArray.getJSONObject(i);

                name = json.getString(MainActivity.TAG_NAME);
                size = json.getString(MainActivity.TAG_SIZE).replace(",", ".");
                progress = json.getDouble(MainActivity.TAG_PROGRESS);
                priority = json.getInt(MainActivity.TAG_PRIORITY);

                if (MainActivity.qb_version.equals("3.2.x")) {
                    size = Common.calculateSize(json.getString(MainActivity.TAG_SIZE)).replace(",", ".");
                }

                // Add ContentFiles
                contentFiles.add(new TorrentDetailsItem(name, size, progress, priority, null,
                        TorrentDetailsItem.FILE, "setFilePriority"));

            }

        }

    } catch (Exception e) {

        Log.e("ContentFileTask:", e.toString());

    }

    //        Log.d("Debug", "contentFiles.size: " + contentFiles.size());

    return contentFiles;

}