Search in sources :

Example 1 with IotaUnits

use of jota.utils.IotaUnits in project run-wallet-android by runplay.

the class GenerateQRCodeFragment method amountInSelectedUnit.

private String amountInSelectedUnit() {
    String inputAmount = amountEditText.getText().toString();
    IotaUnits unit = toIotaUnit(unitsSpinner.getSelectedItemPosition());
    Long iota = Long.parseLong(inputAmount) * (long) Math.pow(10, unit.getValue());
    return iota.toString();
}
Also used : IotaUnits(jota.utils.IotaUnits)

Example 2 with IotaUnits

use of jota.utils.IotaUnits 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)

Example 3 with IotaUnits

use of jota.utils.IotaUnits in project run-wallet-android by runplay.

the class SnTrFragment method amountInSelectedUnit.

private String amountInSelectedUnit() {
    String inputAmount = amountEditText.getText().toString();
    if (inputAmount.isEmpty())
        inputAmount = "0";
    inputAmount = Long.valueOf(Math.round(Sf.toDouble(inputAmount))).toString();
    // amountEditText.setText(inputAmount+"");
    IotaUnits unit = toIotaUnit(unitsSpinner.getSelectedItemPosition());
    Long iota = Long.parseLong(inputAmount) * (long) Math.pow(10, unit.getValue());
    return iota.toString();
}
Also used : IotaUnits(jota.utils.IotaUnits)

Aggregations

IotaUnits (jota.utils.IotaUnits)3 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Bundle (android.os.Bundle)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)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 BindView (butterknife.BindView)1 QRCode (run.wallet.iota.model.QRCode)1 Wallet (run.wallet.iota.model.Wallet)1