Search in sources :

Example 6 with QRCode

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();
    }
}
Also used : QRCode(run.wallet.iota.model.QRCode) Gson(com.google.gson.Gson) OnClick(butterknife.OnClick)

Example 7 with QRCode

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

Example 8 with QRCode

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();
}
Also used : ClipboardManager(android.content.ClipboardManager) Wallet(run.wallet.iota.model.Wallet) Bundle(android.os.Bundle) AppCompatActivity(android.support.v7.app.AppCompatActivity) InputMethodManager(android.view.inputmethod.InputMethodManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) MotionEvent(android.view.MotionEvent) QRCode(run.wallet.iota.model.QRCode) IotaUnits(jota.utils.IotaUnits) ClipData(android.content.ClipData)

Aggregations

QRCode (run.wallet.iota.model.QRCode)8 Bundle (android.os.Bundle)7 Fragment (android.app.Fragment)3 FragmentManager (android.app.FragmentManager)3 FragmentTransaction (android.app.FragmentTransaction)3 OnClick (butterknife.OnClick)3 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2 GenerateQRCodeFragment (run.wallet.iota.ui.fragment.GenerateQRCodeFragment)2 DialogFragment (android.app.DialogFragment)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1