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;
}
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();
}
Aggregations