use of run.wallet.iota.model.QRCode in project run-wallet-android by runplay.
the class GenerateQRCodeFragment method onGenerateQrCodeClick.
@OnClick(R.id.generate_qr_code_fab_button)
public void onGenerateQrCodeClick(FloatingActionButton fab) {
inputManager.hideSoftInputFromWindow(fab.getWindowToken(), 0);
addressEditTextInputLayout.setError(null);
if (!isValidAddress()) {
} else {
QRCode qrCode = new QRCode();
qrCode.setAddress(addressEditText.getText().toString());
if (getAmount().isEmpty()) {
qrCode.setAmount("");
} else {
qrCode.setAmount(amountInSelectedUnit());
}
qrCode.setMessage(messageEditText.getText().toString());
qrCode.setTag(tagEditText.getText().toString());
String json = new Gson().toJson(qrCode);
SafeDeleteFiles sdf = new SafeDeleteFiles();
sdf.execute(json);
Snackbar.make(getActivity().findViewById(R.id.drawer_layout), R.string.fragment_generate_qr_code_active, Snackbar.LENGTH_SHORT).show();
// Bitmap bitmap = net.glxn.qrgen.android.QRCode.from(json).withSize(500, 500).bitmap();
}
}
use of run.wallet.iota.model.QRCode 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();
}
use of run.wallet.iota.model.QRCode in project run-wallet-android by runplay.
the class SnTrFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
((AppCompatActivity) getActivity()).setSupportActionBar(newTransferToolbar);
setHasOptionsMenu(false);
// paytoAddresses.clear();
newTransferToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.md_nav_back));
newTransferToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
initUnitsSpinner();
addMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageLayout.getVisibility() == View.GONE) {
messageLayout.setVisibility(View.VISIBLE);
} else {
messageLayout.setVisibility(View.GONE);
}
}
});
addTag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (tagLayout.getVisibility() == View.GONE) {
tagLayout.setVisibility(View.VISIBLE);
} else {
tagLayout.setVisibility(View.GONE);
}
}
});
qrSelect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openQRCodeScanner();
}
});
addPayment.setEnabled(false);
addPayment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addAdress();
}
});
next.setEnabled(false);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
goNext();
}
});
Wallet wallet = Store.getCurrentWallet();
balances = PayPacket.calculateAvailableBalances();
availableBalance.setText(IotaToText.convertRawIotaAmountToDisplayText(balances.available, true));
// if(wallet.getAvailableBalance()>0) {
availableBalance.setTextColor(B.getColor(getActivity(), R.color.green));
// }
pendingBalance.setText(IotaToText.convertRawIotaAmountToDisplayText(balances.locked, true));
pendingBalance.setAlpha(0.4F);
pendingLabel.setAlpha(0.5F);
if (wallet.getBalancePendingIn() > 0) {
pendingBalance.setTextColor(B.getColor(getActivity(), R.color.green));
}
addressEditText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
isLongClicked = true;
return false;
}
});
btnClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addressEditText.setText("");
amountEditText.setText("");
}
});
addressEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (isLongClicked) {
isLongClicked = false;
return false;
}
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
if (imm.isActive(addressEditText)) {
return false;
}
int inType = addressEditText.getInputType();
addressEditText.setInputType(InputType.TYPE_NULL);
addressEditText.onTouchEvent(event);
addressEditText.setInputType(inType);
// consume touch event
return true;
}
});
addressEditText.addTextChangedListener(inputWatcher);
amountEditText.addTextChangedListener(inputWatcher);
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goBackBtn();
}
});
keyboard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UiManager.setKeyboard(getActivity(), addressEditText, true);
scroller.postDelayed(new Runnable() {
@Override
public void run() {
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
addressEditText.requestFocus();
}
});
}
}, 500);
}
});
btnPaste.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData cd = clipboard.getPrimaryClip();
if (cd != null && cd.getItemCount() > 0) {
addressEditText.setText(cd.getItemAt(0).coerceToText(getActivity()));
}
}
});
Bundle bundle = getArguments();
if (getArguments() != null) {
QRCode qrCode = bundle.getParcelable(Constants.QRCODE);
if (qrCode != null) {
if (qrCode.getAddress() != null)
addressEditText.setText(qrCode.getAddress());
if (qrCode.getAmount() != null && !qrCode.getAmount().isEmpty()) {
Long amount = Long.parseLong((qrCode.getAmount()));
IotaUnits unit = IotaUnitConverter.findOptimalIotaUnitToDisplay(amount);
String amountText = Math.round(IotaUnitConverter.convertAmountTo(amount, unit)) + "";
amountEditText.setText(amountText);
unitsSpinner.setSelection(toSpinnerItemIndex(unit));
}
if (qrCode.getMessage() != null)
messageEditText.setText(qrCode.getMessage());
if (qrCode.getTag() != null)
tagEditText.setText(qrCode.getTag());
checkContinue();
}
}
checkContinue();
}
Aggregations