Search in sources :

Example 36 with JSONObject

use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.

the class TransferTransaction method toJson.

public JSONObject toJson() {
    JSONObject job = new JSONObject();
    job.put("a", address);
    job.put("v", value);
    job.put("z", payFromAddressZero);
    return job;
}
Also used : JSONObject(run.wallet.common.json.JSONObject)

Example 37 with JSONObject

use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.

the class QRScannerFragment method handleResult.

@Override
public void handleResult(Result result) {
    QRCode qrCode = new QRCode();
    String strRes = String.valueOf(result);
    if (strRes != null && !strRes.isEmpty()) {
        if (strRes.length() == 81 || strRes.length() == 90) {
            qrCode.setAddress(strRes);
        } else if (strRes.startsWith("iota:")) {
            strRes = strRes.replaceFirst("iota:", "").replaceFirst("/", "");
            if (strRes.contains("?")) {
                String[] sp = strRes.split("\\?");
                qrCode.setAddress(sp[0]);
                try {
                    if (sp.length > 1) {
                        String[] params = sp[1].split("&");
                        if (params != null && params.length > 0) {
                            for (int i = 0; i < params.length; i++) {
                                if (params[i].startsWith("amount=")) {
                                    qrCode.setAmount(params[i].replaceFirst("amount=", ""));
                                } else if (params[i].startsWith("value=")) {
                                    qrCode.setAmount(params[i].replaceFirst("value=", ""));
                                } else if (params[i].startsWith("tag=")) {
                                    qrCode.setTag(params[i].replaceFirst("tag=", ""));
                                } else if (params[i].startsWith("message=")) {
                                    qrCode.setMessage(params[i].replaceFirst("message=", ""));
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                }
            } else {
                qrCode.setAddress(strRes);
            }
        } else {
            JSONObject json = new JSONObject(strRes);
            qrCode.setAddress(json.optString("address"));
            if (!json.optString("amount").isEmpty()) {
                qrCode.setAmount(json.optLong("amount") + "");
            } else if (!json.optString("value").isEmpty()) {
                qrCode.setAmount(json.optLong("value") + "");
            }
            if (!json.optString("message").isEmpty())
                qrCode.setMessage(json.optString("message"));
            else if (!json.optString("msg").isEmpty())
                qrCode.setMessage(json.optString("msg"));
            qrCode.setTag(json.optString("tag"));
        }
    }
    // remove all fragment from backStack, right, 2 times
    // getActivity().onBackPressed();
    // getActivity().onBackPressed();
    Bundle bundle = new Bundle();
    bundle.putParcelable(Constants.QRCODE, qrCode);
    FragmentManager fm = getActivity().getFragmentManager();
    FragmentTransaction tr = fm.beginTransaction();
    // fm.popBackStack();
    Fragment fragment = new SnTrFragment();
    fragment.setArguments(bundle);
    tr.replace(R.id.container, fragment, null).commit();
    scannerView.invalidate();
}
Also used : FragmentManager(android.app.FragmentManager) QRCode(run.wallet.iota.model.QRCode) FragmentTransaction(android.app.FragmentTransaction) JSONObject(run.wallet.common.json.JSONObject) Bundle(android.os.Bundle) Fragment(android.app.Fragment) JSONException(run.wallet.common.json.JSONException)

Aggregations

JSONObject (run.wallet.common.json.JSONObject)37 SharedPreferences (android.content.SharedPreferences)24 JSONArray (run.wallet.common.json.JSONArray)21 ArrayList (java.util.ArrayList)6 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 FragmentTransaction (android.app.FragmentTransaction)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 File (java.io.File)1 HttpURLConnection (java.net.HttpURLConnection)1 TextFile (run.wallet.common.TextFile)1 JSONException (run.wallet.common.json.JSONException)1 WebGetExchangeRatesHistoryRequest (run.wallet.iota.api.requests.WebGetExchangeRatesHistoryRequest)1