Example usage for java.math BigInteger signum

List of usage examples for java.math BigInteger signum

Introduction

In this page you can find the example usage for java.math BigInteger signum.

Prototype

int signum

To view the source code for java.math BigInteger signum.

Click Source Link

Document

The signum of this BigInteger: -1 for negative, 0 for zero, or 1 for positive.

Usage

From source file:de.schildbach.litecoinwallet.ui.SendCoinsFragment.java

private void popupAvailable(@Nonnull final View anchor, @Nonnull final BigInteger available,
        @Nonnull final BigInteger pending) {
    dismissPopup();//from  ww w  .j a  v  a 2  s .  c o  m

    final CurrencyTextView viewAvailable = (CurrencyTextView) popupAvailableView
            .findViewById(R.id.send_coins_popup_available_amount);
    viewAvailable.setPrefix(btcShift == 0 ? Constants.CURRENCY_CODE_BTC : Constants.CURRENCY_CODE_MBTC);
    viewAvailable.setPrecision(btcPrecision, btcShift);
    viewAvailable.setAmount(available);

    final TextView viewPending = (TextView) popupAvailableView
            .findViewById(R.id.send_coins_popup_available_pending);
    viewPending.setVisibility(pending.signum() > 0 ? View.VISIBLE : View.GONE);
    final int precision = btcShift == 0 ? Constants.BTC_MAX_PRECISION : Constants.MBTC_MAX_PRECISION;
    viewPending.setText(getString(R.string.send_coins_fragment_pending,
            GenericUtils.formatValue(pending, precision, btcShift)));

    popup(anchor, popupAvailableView);
}

From source file:com.guldencoin.androidwallet.nlg.ui.SendCoinsFragment.java

private void handleGo() {
    state = State.PREPARATION;/*from  w w w .  jav a2s  .  com*/
    updateView();

    // final payment intent
    final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(
            amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
    final BigInteger finalAmount = finalPaymentIntent.getAmount();

    // prepare send request
    final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
    final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS);
    sendRequest.changeAddress = returnAddress;
    sendRequest.emptyWallet = paymentIntent.mayEditAmount()
            && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE));

    new SendCoinsOfflineTask(wallet, backgroundHandler) {
        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;

            state = State.SENDING;
            updateView();

            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);

            directPay(sentTransaction);

            application.broadcastTransaction(sentTransaction);

            final Intent result = new Intent();
            BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString());
            activity.setResult(Activity.RESULT_OK, result);
        }

        private void directPay(final Transaction transaction) {
            if (directPaymentEnableView.isChecked()) {
                final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
                    @Override
                    public void onResult(final boolean ack) {
                        directPaymentAck = ack;

                        if (state == State.SENDING)
                            state = State.SENT;

                        updateView();
                    }

                    @Override
                    public void onFail(final int messageResId, final Object... messageArgs) {
                        final DialogBuilder dialog = DialogBuilder.warn(activity,
                                R.string.send_coins_fragment_direct_payment_failed_title);
                        dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs)
                                + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
                        dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                directPay(transaction);
                            }
                        });
                        dialog.setNegativeButton(R.string.button_dismiss, null);
                        dialog.show();
                    }
                };

                if (paymentIntent.isHttpPaymentUrl()) {
                    new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl)
                            .send(paymentIntent.standard, transaction, returnAddress, finalAmount,
                                    paymentIntent.payeeData);
                } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null
                        && bluetoothAdapter.isEnabled()) {
                    new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter,
                            paymentIntent.getBluetoothMac()).send(paymentIntent.standard, transaction,
                                    returnAddress, finalAmount, paymentIntent.payeeData);
                }
            }
        }

        @Override
        protected void onInsufficientMoney(final BigInteger missing) {
            state = State.INPUT;
            updateView();

            final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED);
            final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE);
            final BigInteger pending = estimated.subtract(available);

            final int btcShift = config.getBtcShift();
            final int btcPrecision = config.getBtcMaxPrecision();
            final String btcPrefix = config.getBtcPrefix();

            final DialogBuilder dialog = DialogBuilder.warn(activity,
                    R.string.send_coins_fragment_insufficient_money_title);
            final StringBuilder msg = new StringBuilder(
                    String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1),
                            btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift)));
            if (pending.signum() > 0)
                msg.append("\n\n").append(getString(R.string.send_coins_fragment_pending,
                        GenericUtils.formatValue(pending, btcPrecision, btcShift)));
            msg.append("\n\n").append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
            dialog.setMessage(msg);
            dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    handleEmpty();
                }
            });
            dialog.setNegativeButton(R.string.button_cancel, null);
            dialog.show();
        }

        @Override
        protected void onFailure() {
            state = State.FAILED;
            updateView();

            activity.longToast(R.string.send_coins_error_msg);
        }
    }.sendCoinsOffline(sendRequest); // send asynchronously
}

From source file:de.schildbach.wallet.ui.SendCoinsFragment.java

private void handleGo() {
    state = State.PREPARATION;//from   w ww  . j a  v  a  2 s. co m
    updateView();

    // final payment intent
    final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(
            amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
    final BigInteger finalAmount = finalPaymentIntent.getAmount();

    // prepare send request
    final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
    final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS);
    sendRequest.changeAddress = returnAddress;
    sendRequest.emptyWallet = paymentIntent.mayEditAmount()
            && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE));

    new SendCoinsOfflineTask(wallet, backgroundHandler) {
        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;

            state = State.SENDING;
            updateView();

            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);

            directPay(sentTransaction);

            application.broadcastTransaction(sentTransaction);

            final Intent result = new Intent();
            BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString());
            activity.setResult(Activity.RESULT_OK, result);
        }

        private void directPay(final Transaction transaction) {
            if (directPaymentEnableView.isChecked()) {
                final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
                    @Override
                    public void onResult(final boolean ack) {
                        directPaymentAck = ack;

                        if (state == State.SENDING)
                            state = State.SENT;

                        updateView();
                    }

                    @Override
                    public void onFail(final String message) {
                        final DialogBuilder dialog = new DialogBuilder(activity);
                        dialog.setIcon(R.drawable.ic_menu_warning);
                        dialog.setTitle(R.string.send_coins_fragment_direct_payment_failed_title);
                        dialog.setMessage(paymentIntent.paymentUrl + "\n" + message + "\n\n"
                                + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
                        dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                directPay(transaction);
                            }
                        });
                        dialog.setNegativeButton(R.string.button_dismiss, null);
                        dialog.show();
                    }
                };

                if (paymentIntent.isHttpPaymentUrl()) {
                    new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl)
                            .send(paymentIntent.standard, transaction, returnAddress, finalAmount,
                                    paymentIntent.payeeData);
                } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null
                        && bluetoothAdapter.isEnabled()) {
                    new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter,
                            paymentIntent.getBluetoothMac()).send(paymentIntent.standard, transaction,
                                    returnAddress, finalAmount, paymentIntent.payeeData);
                }
            }
        }

        @Override
        protected void onInsufficientMoney(final BigInteger missing) {
            state = State.INPUT;
            updateView();

            final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED);
            final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE);
            final BigInteger pending = estimated.subtract(available);

            final int btcShift = config.getBtcShift();
            final int btcPrecision = config.getBtcMaxPrecision();
            final String btcPrefix = config.getBtcPrefix();

            final DialogBuilder dialog = new DialogBuilder(activity);
            dialog.setIcon(R.drawable.ic_menu_warning);
            dialog.setTitle(R.string.send_coins_fragment_insufficient_money_title);
            final StringBuilder msg = new StringBuilder(
                    String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1),
                            btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift)));
            if (pending.signum() > 0)
                msg.append("\n\n").append(getString(R.string.send_coins_fragment_pending,
                        GenericUtils.formatValue(pending, btcPrecision, btcShift)));
            msg.append("\n\n").append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
            dialog.setMessage(msg);
            dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    handleEmpty();
                }
            });
            dialog.setNegativeButton(R.string.button_cancel, null);
            dialog.show();
        }

        @Override
        protected void onFailure() {
            state = State.FAILED;
            updateView();

            activity.longToast(R.string.send_coins_error_msg);
        }
    }.sendCoinsOffline(sendRequest); // send asynchronously
}

From source file:de.schildbach.wallet.ui.SendCoinsFragmentBackup.java

private void handleGo() {
    state = State.PREPARATION;//from  w ww.j a  v  a2 s  .c o m
    updateView();

    // final payment intent
    final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(
            amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
    final BigInteger finalAmount = finalPaymentIntent.getAmount();

    // prepare send request
    final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
    final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS);
    sendRequest.changeAddress = returnAddress;
    sendRequest.emptyWallet = paymentIntent.mayEditAmount()
            && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE));

    new SendCoinsOfflineTask(wallet, backgroundHandler) {
        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;

            state = State.SENDING;
            updateView();

            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);

            final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress,
                    finalAmount, null, paymentIntent.payeeData);

            directPay(payment);

            application.broadcastTransaction(sentTransaction);

            final ComponentName callingActivity = activity.getCallingActivity();
            if (callingActivity != null) {
                log.info("returning result to calling activity: {}", callingActivity.flattenToString());

                final Intent result = new Intent();
                BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString());
                if (paymentIntent.standard == Standard.BIP70)
                    BitcoinIntegration.paymentToResult(result, payment.toByteArray());
                activity.setResult(Activity.RESULT_OK, result);
            }
        }

        private void directPay(final Payment payment) {
            if (directPaymentEnableView.isChecked()) {
                final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
                    @Override
                    public void onResult(final boolean ack) {
                        directPaymentAck = ack;

                        if (state == State.SENDING)
                            state = State.SENT;

                        updateView();
                    }

                    @Override
                    public void onFail(final int messageResId, final Object... messageArgs) {
                        final DialogBuilder dialog = DialogBuilder.warn(activity,
                                R.string.send_coins_fragment_direct_payment_failed_title);
                        dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs)
                                + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
                        dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                directPay(payment);
                            }
                        });
                        dialog.setNegativeButton(R.string.button_dismiss, null);
                        dialog.show();
                    }
                };

                if (paymentIntent.isHttpPaymentUrl()) {
                    new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl,
                            application.httpUserAgent()).send(paymentIntent.standard, payment);
                } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null
                        && bluetoothAdapter.isEnabled()) {
                    new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter,
                            paymentIntent.getBluetoothMac()).send(paymentIntent.standard, payment);
                }
            }
        }

        @Override
        protected void onInsufficientMoney(@Nullable final BigInteger missing) {
            state = State.INPUT;
            updateView();

            final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED);
            final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE);
            final BigInteger pending = estimated.subtract(available);

            final int btcShift = config.getBtcShift();
            final int btcPrecision = config.getBtcMaxPrecision();
            final String btcPrefix = config.getBtcPrefix();

            final DialogBuilder dialog = DialogBuilder.warn(activity,
                    R.string.send_coins_fragment_insufficient_money_title);
            final StringBuilder msg = new StringBuilder();
            if (missing != null)
                msg.append(String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1),
                        btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift)))
                        .append("\n\n");
            if (pending.signum() > 0)
                msg.append(getString(R.string.send_coins_fragment_pending,
                        GenericUtils.formatValue(pending, btcPrecision, btcShift))).append("\n\n");
            msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
            dialog.setMessage(msg);
            dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    handleEmpty();
                }
            });
            dialog.setNegativeButton(R.string.button_cancel, null);
            dialog.show();
        }

        @Override
        protected void onFailure() {
            state = State.FAILED;
            updateView();

            activity.longToast(R.string.send_coins_error_msg);
        }
    }.sendCoinsOffline(sendRequest); // send asynchronously
}

From source file:com.jculb.wallet.ui.SendCoinsFragment.java

private void handleGo() {
    state = State.PREPARATION;/*from   w  ww  .  j  av  a 2s  . co  m*/
    updateView();

    // final payment intent
    final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(
            amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
    final BigInteger finalAmount = finalPaymentIntent.getAmount();

    // prepare send request
    final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
    final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS);
    sendRequest.changeAddress = returnAddress;
    sendRequest.emptyWallet = paymentIntent.mayEditAmount()
            && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE));

    //Emptying a wallet with less than 2 DOGE can't be possible due to min fee 2 DOGE of such a tx.
    /*        if (amount.compareTo(BigInteger.valueOf(200000000)) < 0 && sendRequest.emptyWallet)
            {
    AlertDialog.Builder bld = new AlertDialog.Builder(activity);
        bld.setTitle(R.string.send_coins_error_msg);
        bld.setMessage(R.string.send_coins_error_desc);
        bld.setNeutralButton(activity.getResources().getString(android.R.string.ok), null);
        bld.setCancelable(false);
        bld.create().show();
    state = State.FAILED;
    updateView();
    return;
            }*/

    new SendCoinsOfflineTask(wallet, backgroundHandler) {
        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;

            state = State.SENDING;
            updateView();

            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);

            final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress,
                    finalAmount, null, paymentIntent.payeeData);

            directPay(payment);

            application.broadcastTransaction(sentTransaction);

            final ComponentName callingActivity = activity.getCallingActivity();
            if (callingActivity != null) {
                log.info("returning result to calling activity: {}", callingActivity.flattenToString());

                final Intent result = new Intent();
                BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString());
                if (paymentIntent.standard == Standard.BIP70)
                    BitcoinIntegration.paymentToResult(result, payment.toByteArray());
                activity.setResult(Activity.RESULT_OK, result);
            }
        }

        private void directPay(final Payment payment) {
            if (directPaymentEnableView.isChecked()) {
                final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
                    @Override
                    public void onResult(final boolean ack) {
                        directPaymentAck = ack;

                        if (state == State.SENDING)
                            state = State.SENT;

                        updateView();
                    }

                    @Override
                    public void onFail(final int messageResId, final Object... messageArgs) {
                        final DialogBuilder dialog = DialogBuilder.warn(activity,
                                R.string.send_coins_fragment_direct_payment_failed_title);
                        dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs)
                                + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
                        dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                directPay(payment);
                            }
                        });
                        dialog.setNegativeButton(R.string.button_dismiss, null);
                        dialog.show();
                    }
                };

                if (paymentIntent.isHttpPaymentUrl()) {
                    new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl,
                            application.httpUserAgent()).send(paymentIntent.standard, payment);
                } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null
                        && bluetoothAdapter.isEnabled()) {
                    new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter,
                            paymentIntent.getBluetoothMac()).send(paymentIntent.standard, payment);
                }
            }
        }

        @Override
        protected void onInsufficientMoney(@Nullable final BigInteger missing) {
            state = State.INPUT;
            updateView();

            final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED);
            final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE);
            final BigInteger pending = estimated.subtract(available);

            final int btcShift = config.getBtcShift();
            final int btcPrecision = config.getBtcMaxPrecision();
            final String btcPrefix = config.getBtcPrefix();

            final DialogBuilder dialog = DialogBuilder.warn(activity,
                    R.string.send_coins_fragment_insufficient_money_title);
            final StringBuilder msg = new StringBuilder();
            if (missing != null)
                msg.append(String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1),
                        btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift)))
                        .append("\n\n");
            if (pending.signum() > 0)
                msg.append(getString(R.string.send_coins_fragment_pending,
                        GenericUtils.formatValue(pending, btcPrecision, btcShift))).append("\n\n");
            msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
            dialog.setMessage(msg);
            dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    handleEmpty();
                }
            });
            dialog.setNegativeButton(R.string.button_cancel, null);
            dialog.show();
        }

        @Override
        protected void onFailure() {
            state = State.FAILED;
            updateView();

            activity.longToast(R.string.send_coins_error_msg);
        }
    }.sendCoinsOffline(sendRequest); // send asynchronously
}

From source file:de.jdellay.wallet.ui.SendCoinsFragment.java

private void handleGo() {
    state = State.PREPARATION;/* w w  w  .  j  ava 2s  . co m*/
    updateView();

    // final payment intent
    final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(
            amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
    final BigInteger finalAmount = finalPaymentIntent.getAmount();

    // prepare send request
    final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
    final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS);
    sendRequest.changeAddress = returnAddress;
    sendRequest.emptyWallet = paymentIntent.mayEditAmount()
            && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE));

    //Emptying a wallet with less than 2 CCN can't be possible due to min fee 2 CCN of such a tx.
    /*        if (amount.compareTo(BigInteger.valueOf(200000000)) < 0 && sendRequest.emptyWallet)
            {
    AlertDialog.Builder bld = new AlertDialog.Builder(activity);
        bld.setTitle(R.string.send_coins_error_msg);
        bld.setMessage(R.string.send_coins_error_desc);
        bld.setNeutralButton(activity.getResources().getString(android.R.string.ok), null);
        bld.setCancelable(false);
        bld.create().show();
    state = State.FAILED;
    updateView();
    return;
            }*/

    new SendCoinsOfflineTask(wallet, backgroundHandler) {
        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;

            state = State.SENDING;
            updateView();

            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);

            final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress,
                    finalAmount, null, paymentIntent.payeeData);

            directPay(payment);

            application.broadcastTransaction(sentTransaction);

            final ComponentName callingActivity = activity.getCallingActivity();
            if (callingActivity != null) {
                log.info("returning result to calling activity: {}", callingActivity.flattenToString());

                final Intent result = new Intent();
                BitcoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString());
                if (paymentIntent.standard == Standard.BIP70)
                    BitcoinIntegration.paymentToResult(result, payment.toByteArray());
                activity.setResult(Activity.RESULT_OK, result);
            }
        }

        private void directPay(final Payment payment) {
            if (directPaymentEnableView.isChecked()) {
                final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
                    @Override
                    public void onResult(final boolean ack) {
                        directPaymentAck = ack;

                        if (state == State.SENDING)
                            state = State.SENT;

                        updateView();
                    }

                    @Override
                    public void onFail(final int messageResId, final Object... messageArgs) {
                        final DialogBuilder dialog = DialogBuilder.warn(activity,
                                R.string.send_coins_fragment_direct_payment_failed_title);
                        dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs)
                                + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
                        dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                directPay(payment);
                            }
                        });
                        dialog.setNegativeButton(R.string.button_dismiss, null);
                        dialog.show();
                    }
                };

                if (paymentIntent.isHttpPaymentUrl()) {
                    new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl,
                            application.httpUserAgent()).send(paymentIntent.standard, payment);
                } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null
                        && bluetoothAdapter.isEnabled()) {
                    new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter,
                            paymentIntent.getBluetoothMac()).send(paymentIntent.standard, payment);
                }
            }
        }

        @Override
        protected void onInsufficientMoney(@Nullable final BigInteger missing) {
            state = State.INPUT;
            updateView();

            final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED);
            final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE);
            final BigInteger pending = estimated.subtract(available);

            final int btcShift = config.getBtcShift();
            final int btcPrecision = config.getBtcMaxPrecision();
            final String btcPrefix = config.getBtcPrefix();

            final DialogBuilder dialog = DialogBuilder.warn(activity,
                    R.string.send_coins_fragment_insufficient_money_title);
            final StringBuilder msg = new StringBuilder();
            if (missing != null)
                msg.append(String.format(getString(R.string.send_coins_fragment_insufficient_money_msg1),
                        btcPrefix + ' ' + GenericUtils.formatValue(missing, btcPrecision, btcShift)))
                        .append("\n\n");
            if (pending.signum() > 0)
                msg.append(getString(R.string.send_coins_fragment_pending,
                        GenericUtils.formatValue(pending, btcPrecision, btcShift))).append("\n\n");
            msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
            dialog.setMessage(msg);
            dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    handleEmpty();
                }
            });
            dialog.setNegativeButton(R.string.button_cancel, null);
            dialog.show();
        }

        @Override
        protected void onFailure() {
            state = State.FAILED;
            updateView();

            activity.longToast(R.string.send_coins_error_msg);
        }
    }.sendCoinsOffline(sendRequest); // send asynchronously
}

From source file:com.matthewmitchell.nubits_android_wallet.ui.SendCoinsFragment.java

private void handleGo() {
    state = State.PREPARATION;/*from  www. j  ava  2s  .c  om*/
    updateView();

    // final payment intent
    final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(
            amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
    final BigInteger finalAmount = finalPaymentIntent.getAmount();

    // prepare send request
    final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
    final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS);
    sendRequest.changeAddress = returnAddress;
    sendRequest.emptyWallet = paymentIntent.mayEditAmount()
            && finalAmount.equals(wallet.getBalance(BalanceType.ESTMINUSFEE));

    new SendCoinsOfflineTask(wallet, backgroundHandler) {
        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;

            state = State.SENDING;
            updateView();

            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);

            final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress,
                    finalAmount, null, paymentIntent.payeeData);

            directPay(payment);

            application.broadcastTransaction(sentTransaction);

            final ComponentName callingActivity = activity.getCallingActivity();
            if (callingActivity != null) {
                log.info("returning result to calling activity: {}", callingActivity.flattenToString());

                final Intent result = new Intent();
                NubitsIntegration.transactionHashToResult(result, sentTransaction.getHashAsString());
                if (paymentIntent.standard == Standard.BIP70)
                    NubitsIntegration.paymentToResult(result, payment.toByteArray());
                activity.setResult(Activity.RESULT_OK, result);
            }
        }

        private void directPay(final Payment payment) {
            if (directPaymentEnableView.isChecked()) {
                final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
                    @Override
                    public void onResult(final boolean ack) {
                        directPaymentAck = ack;

                        if (state == State.SENDING)
                            state = State.SENT;

                        updateView();
                    }

                    @Override
                    public void onFail(final int messageResId, final Object... messageArgs) {
                        final DialogBuilder dialog = DialogBuilder.warn(activity,
                                R.string.send_coins_fragment_direct_payment_failed_title);
                        dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs)
                                + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
                        dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                directPay(payment);
                            }
                        });
                        dialog.setNegativeButton(R.string.button_dismiss, null);
                        dialog.show();
                    }
                };

                if (paymentIntent.isHttpPaymentUrl()) {
                    new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl,
                            application.httpUserAgent()).send(payment);
                } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null
                        && bluetoothAdapter.isEnabled()) {
                    new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter,
                            Bluetooth.getBluetoothMac(paymentIntent.paymentUrl)).send(payment);
                }
            }
        }

        @Override
        protected void onInsufficientMoney(@Nullable final BigInteger missing) {
            state = State.INPUT;
            updateView();

            final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED);
            final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE);
            final BigInteger pending = estimated.subtract(available);

            final int NBTShift = config.getNBTShift();
            final int NBTPrecision = config.getNBTMaxPrecision();
            final String NBTPrefix = config.getNBTPrefix();

            final DialogBuilder dialog = DialogBuilder.warn(activity,
                    R.string.send_coins_fragment_insufficient_money_title);
            final StringBuilder msg = new StringBuilder();
            if (missing != null)
                msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg1,
                        NBTPrefix + ' ' + GenericUtils.formatValue(missing, NBTPrecision, NBTShift)))
                        .append("\n\n");
            if (pending.signum() > 0)
                msg.append(getString(R.string.send_coins_fragment_pending,
                        NBTPrefix + ' ' + GenericUtils.formatValue(pending, NBTPrecision, NBTShift)))
                        .append("\n\n");
            msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
            dialog.setMessage(msg);
            dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    handleEmpty();
                }
            });
            dialog.setNegativeButton(R.string.button_cancel, null);
            dialog.show();
        }

        @Override
        protected void onFailure() {
            state = State.FAILED;
            updateView();

            activity.longToast(R.string.send_coins_error_msg);
        }
    }.sendCoinsOffline(sendRequest); // send asynchronously
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.SendCoinsFragment.java

private void handleGo() {
    state = State.PREPARATION;/*from ww  w.  j a  v  a 2s .c  om*/
    updateView();

    // final payment intent
    final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(
            amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
    final BigInteger finalAmount = finalPaymentIntent.getAmount();

    // prepare send request
    final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
    final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS);
    sendRequest.changeAddress = returnAddress;
    sendRequest.emptyWallet = paymentIntent.mayEditAmount()
            && finalAmount.equals(wallet.getBalance(BalanceType.ESTMINUSFEE));

    new SendCoinsOfflineTask(wallet, backgroundHandler) {
        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;

            state = State.SENDING;
            updateView();

            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);

            final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress,
                    finalAmount, null, paymentIntent.payeeData);

            directPay(payment);

            application.broadcastTransaction(sentTransaction);

            final ComponentName callingActivity = activity.getCallingActivity();
            if (callingActivity != null) {
                log.info("returning result to calling activity: {}", callingActivity.flattenToString());

                final Intent result = new Intent();
                PeercoinIntegration.transactionHashToResult(result, sentTransaction.getHashAsString());
                if (paymentIntent.standard == Standard.BIP70)
                    PeercoinIntegration.paymentToResult(result, payment.toByteArray());
                activity.setResult(Activity.RESULT_OK, result);
            }
        }

        private void directPay(final Payment payment) {
            if (directPaymentEnableView.isChecked()) {
                final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
                    @Override
                    public void onResult(final boolean ack) {
                        directPaymentAck = ack;

                        if (state == State.SENDING)
                            state = State.SENT;

                        updateView();
                    }

                    @Override
                    public void onFail(final int messageResId, final Object... messageArgs) {
                        final DialogBuilder dialog = DialogBuilder.warn(activity,
                                R.string.send_coins_fragment_direct_payment_failed_title);
                        dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs)
                                + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
                        dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                directPay(payment);
                            }
                        });
                        dialog.setNegativeButton(R.string.button_dismiss, null);
                        dialog.show();
                    }
                };

                if (paymentIntent.isHttpPaymentUrl()) {
                    new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl,
                            application.httpUserAgent()).send(payment);
                } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null
                        && bluetoothAdapter.isEnabled()) {
                    new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter,
                            Bluetooth.getBluetoothMac(paymentIntent.paymentUrl)).send(payment);
                }
            }
        }

        @Override
        protected void onInsufficientMoney(@Nullable final BigInteger missing) {
            state = State.INPUT;
            updateView();

            final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED);
            final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE);
            final BigInteger pending = estimated.subtract(available);

            final int PPCShift = config.getPPCShift();
            final int PPCPrecision = config.getPPCMaxPrecision();
            final String PPCPrefix = config.getPPCPrefix();

            final DialogBuilder dialog = DialogBuilder.warn(activity,
                    R.string.send_coins_fragment_insufficient_money_title);
            final StringBuilder msg = new StringBuilder();
            if (missing != null)
                msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg1,
                        PPCPrefix + ' ' + GenericUtils.formatValue(missing, PPCPrecision, PPCShift)))
                        .append("\n\n");
            if (pending.signum() > 0)
                msg.append(getString(R.string.send_coins_fragment_pending,
                        PPCPrefix + ' ' + GenericUtils.formatValue(pending, PPCPrecision, PPCShift)))
                        .append("\n\n");
            msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
            dialog.setMessage(msg);
            dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    handleEmpty();
                }
            });
            dialog.setNegativeButton(R.string.button_cancel, null);
            dialog.show();
        }

        @Override
        protected void onFailure() {
            state = State.FAILED;
            updateView();

            activity.longToast(R.string.send_coins_error_msg);
        }
    }.sendCoinsOffline(sendRequest); // send asynchronously
}

From source file:com.rimbit.android_wallet.ui.SendCoinsFragment.java

private void handleGo() {
    state = State.PREPARATION;/*from  w w  w  .jav a 2  s .co m*/
    updateView();

    // final payment intent
    final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(
            amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
    final BigInteger finalAmount = finalPaymentIntent.getAmount();

    // prepare send request
    final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
    final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS);
    sendRequest.changeAddress = returnAddress;
    sendRequest.emptyWallet = paymentIntent.mayEditAmount()
            && finalAmount.equals(wallet.getBalance(BalanceType.ESTMINUSFEE));

    new SendCoinsOfflineTask(wallet, backgroundHandler) {
        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;

            state = State.SENDING;
            updateView();

            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);

            final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress,
                    finalAmount, null, paymentIntent.payeeData);

            directPay(payment);

            application.broadcastTransaction(sentTransaction);

            final ComponentName callingActivity = activity.getCallingActivity();
            if (callingActivity != null) {
                log.info("returning result to calling activity: {}", callingActivity.flattenToString());

                final Intent result = new Intent();
                RimbitIntegration.transactionHashToResult(result, sentTransaction.getHashAsString());
                if (paymentIntent.standard == Standard.BIP70)
                    RimbitIntegration.paymentToResult(result, payment.toByteArray());
                activity.setResult(Activity.RESULT_OK, result);
            }
        }

        private void directPay(final Payment payment) {
            if (directPaymentEnableView.isChecked()) {
                final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
                    @Override
                    public void onResult(final boolean ack) {
                        directPaymentAck = ack;

                        if (state == State.SENDING)
                            state = State.SENT;

                        updateView();
                    }

                    @Override
                    public void onFail(final int messageResId, final Object... messageArgs) {
                        final DialogBuilder dialog = DialogBuilder.warn(activity,
                                R.string.send_coins_fragment_direct_payment_failed_title);
                        dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs)
                                + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
                        dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                directPay(payment);
                            }
                        });
                        dialog.setNegativeButton(R.string.button_dismiss, null);
                        dialog.show();
                    }
                };

                if (paymentIntent.isHttpPaymentUrl()) {
                    new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl,
                            application.httpUserAgent()).send(payment);
                } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null
                        && bluetoothAdapter.isEnabled()) {
                    new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter,
                            Bluetooth.getBluetoothMac(paymentIntent.paymentUrl)).send(payment);
                }
            }
        }

        @Override
        protected void onInsufficientMoney(@Nullable final BigInteger missing) {
            state = State.INPUT;
            updateView();

            final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED);
            final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE);
            final BigInteger pending = estimated.subtract(available);

            final int RBTShift = config.getRBTShift();
            final int RBTPrecision = config.getRBTMaxPrecision();
            final String RBTPrefix = config.getRBTPrefix();

            final DialogBuilder dialog = DialogBuilder.warn(activity,
                    R.string.send_coins_fragment_insufficient_money_title);
            final StringBuilder msg = new StringBuilder();
            if (missing != null)
                msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg1,
                        RBTPrefix + ' ' + GenericUtils.formatValue(missing, RBTPrecision, RBTShift)))
                        .append("\n\n");
            if (pending.signum() > 0)
                msg.append(getString(R.string.send_coins_fragment_pending,
                        RBTPrefix + ' ' + GenericUtils.formatValue(pending, RBTPrecision, RBTShift)))
                        .append("\n\n");
            msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
            dialog.setMessage(msg);
            dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    handleEmpty();
                }
            });
            dialog.setNegativeButton(R.string.button_cancel, null);
            dialog.show();
        }

        @Override
        protected void onFailure() {
            state = State.FAILED;
            updateView();

            activity.longToast(R.string.send_coins_error_msg);
        }
    }.sendCoinsOffline(sendRequest); // send asynchronously
}

From source file:com.woollysammoth.nubit_android_wallet.ui.SendCoinsFragment.java

private void handleGo() {
    state = State.PREPARATION;//from w  ww . j  a  va 2s.c  o m
    updateView();

    // final payment intent
    final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(
            amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
    final BigInteger finalAmount = finalPaymentIntent.getAmount();

    // prepare send request
    final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
    final Address returnAddress = WalletUtils.pickOldestKey(wallet).toAddress(Constants.NETWORK_PARAMETERS);
    sendRequest.changeAddress = returnAddress;
    sendRequest.emptyWallet = paymentIntent.mayEditAmount()
            && finalAmount.equals(wallet.getBalance(BalanceType.ESTMINUSFEE));

    new SendCoinsOfflineTask(wallet, backgroundHandler) {
        @Override
        protected void onSuccess(final Transaction transaction) {
            sentTransaction = transaction;

            state = State.SENDING;
            updateView();

            sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);

            final Payment payment = PaymentProtocol.createPaymentMessage(sentTransaction, returnAddress,
                    finalAmount, null, paymentIntent.payeeData);

            directPay(payment);

            application.broadcastTransaction(sentTransaction);

            final ComponentName callingActivity = activity.getCallingActivity();
            if (callingActivity != null) {
                log.info("returning result to calling activity: {}", callingActivity.flattenToString());

                final Intent result = new Intent();
                NubitIntegration.transactionHashToResult(result, sentTransaction.getHashAsString());
                if (paymentIntent.standard == Standard.BIP70)
                    NubitIntegration.paymentToResult(result, payment.toByteArray());
                activity.setResult(Activity.RESULT_OK, result);
            }
        }

        private void directPay(final Payment payment) {
            if (directPaymentEnableView.isChecked()) {
                final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
                    @Override
                    public void onResult(final boolean ack) {
                        directPaymentAck = ack;

                        if (state == State.SENDING)
                            state = State.SENT;

                        updateView();
                    }

                    @Override
                    public void onFail(final int messageResId, final Object... messageArgs) {
                        final DialogBuilder dialog = DialogBuilder.warn(activity,
                                R.string.send_coins_fragment_direct_payment_failed_title);
                        dialog.setMessage(paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs)
                                + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
                        dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, final int which) {
                                directPay(payment);
                            }
                        });
                        dialog.setNegativeButton(R.string.button_dismiss, null);
                        dialog.show();
                    }
                };

                if (paymentIntent.isHttpPaymentUrl()) {
                    new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, paymentIntent.paymentUrl,
                            application.httpUserAgent()).send(payment);
                } else if (paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null
                        && bluetoothAdapter.isEnabled()) {
                    new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter,
                            Bluetooth.getBluetoothMac(paymentIntent.paymentUrl)).send(payment);
                }
            }
        }

        @Override
        protected void onInsufficientMoney(@Nullable final BigInteger missing) {
            state = State.INPUT;
            updateView();

            final BigInteger estimated = wallet.getBalance(BalanceType.ESTIMATED);
            final BigInteger available = wallet.getBalance(BalanceType.AVAILABLE);
            final BigInteger pending = estimated.subtract(available);

            final int NBTShift = config.getNBTShift();
            final int NBTPrecision = config.getNBTMaxPrecision();
            final String NBTPrefix = config.getNBTPrefix();

            final DialogBuilder dialog = DialogBuilder.warn(activity,
                    R.string.send_coins_fragment_insufficient_money_title);
            final StringBuilder msg = new StringBuilder();
            if (missing != null)
                msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg1,
                        NBTPrefix + ' ' + GenericUtils.formatValue(missing, NBTPrecision, NBTShift)))
                        .append("\n\n");
            if (pending.signum() > 0)
                msg.append(getString(R.string.send_coins_fragment_pending,
                        NBTPrefix + ' ' + GenericUtils.formatValue(pending, NBTPrecision, NBTShift)))
                        .append("\n\n");
            msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
            dialog.setMessage(msg);
            dialog.setPositiveButton(R.string.send_coins_options_empty, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    handleEmpty();
                }
            });
            dialog.setNegativeButton(R.string.button_cancel, null);
            dialog.show();
        }

        @Override
        protected void onFailure() {
            state = State.FAILED;
            updateView();

            activity.longToast(R.string.send_coins_error_msg);
        }
    }.sendCoinsOffline(sendRequest); // send asynchronously
}