Search in sources :

Example 21 with Address

use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.

the class BlockListAdapter method bindView.

public void bindView(final View row, final Transaction tx) {
    final boolean isCoinBase = tx.isCoinBase();
    final boolean isInternal = tx.getPurpose() == Purpose.KEY_ROTATION;
    final Coin value = tx.getValue(wallet);
    final boolean sent = value.signum() < 0;
    final boolean self = WalletUtils.isEntirelySelf(tx, wallet);
    final Address address;
    if (sent)
        address = WalletUtils.getToAddressOfSent(tx, wallet);
    else
        address = WalletUtils.getWalletAddressOfReceived(tx, wallet);
    // receiving or sending
    final TextView rowFromTo = (TextView) row.findViewById(R.id.block_row_transaction_fromto);
    if (isInternal || self)
        rowFromTo.setText(R.string.symbol_internal);
    else if (sent)
        rowFromTo.setText(R.string.symbol_to);
    else
        rowFromTo.setText(R.string.symbol_from);
    // address
    final TextView rowAddress = (TextView) row.findViewById(R.id.block_row_transaction_address);
    final String label;
    if (isCoinBase)
        label = textCoinBase;
    else if (isInternal || self)
        label = textInternal;
    else if (address != null)
        label = AddressBookProvider.resolveLabel(context, address.toBase58());
    else
        label = "?";
    rowAddress.setText(label != null ? label : address.toBase58());
    rowAddress.setTypeface(label != null ? Typeface.DEFAULT : Typeface.MONOSPACE);
    // value
    final CurrencyTextView rowValue = (CurrencyTextView) row.findViewById(R.id.block_row_transaction_value);
    rowValue.setAlwaysSigned(true);
    rowValue.setFormat(format);
    rowValue.setAmount(value);
}
Also used : Coin(org.bitcoinj.core.Coin) Address(org.bitcoinj.core.Address) TextView(android.widget.TextView)

Example 22 with Address

use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.

the class EditAddressBookEntryFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Bundle args = getArguments();
    final Address address = Address.fromBase58(Constants.NETWORK_PARAMETERS, args.getString(KEY_ADDRESS));
    final String suggestedAddressLabel = args.getString(KEY_SUGGESTED_ADDRESS_LABEL);
    final LayoutInflater inflater = LayoutInflater.from(activity);
    final Uri uri = AddressBookProvider.contentUri(activity.getPackageName()).buildUpon().appendPath(address.toBase58()).build();
    final String label = AddressBookProvider.resolveLabel(activity, address.toBase58());
    final boolean isAdd = label == null;
    final boolean isOwn = wallet.isPubKeyHashMine(address.getHash160());
    final DialogBuilder dialog = new DialogBuilder(activity);
    if (isOwn)
        dialog.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add_receive : R.string.edit_address_book_entry_dialog_title_edit_receive);
    else
        dialog.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add : R.string.edit_address_book_entry_dialog_title_edit);
    final View view = inflater.inflate(R.layout.edit_address_book_entry_dialog, null);
    final TextView viewAddress = (TextView) view.findViewById(R.id.edit_address_book_entry_address);
    viewAddress.setText(WalletUtils.formatAddress(address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE));
    final TextView viewLabel = (TextView) view.findViewById(R.id.edit_address_book_entry_label);
    viewLabel.setText(label != null ? label : suggestedAddressLabel);
    dialog.setView(view);
    final DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                final String newLabel = viewLabel.getText().toString().trim();
                if (!newLabel.isEmpty()) {
                    final ContentValues values = new ContentValues();
                    values.put(AddressBookProvider.KEY_LABEL, newLabel);
                    if (isAdd)
                        contentResolver.insert(uri, values);
                    else
                        contentResolver.update(uri, values, null, null);
                } else if (!isAdd) {
                    contentResolver.delete(uri, null, null);
                }
            } else if (which == DialogInterface.BUTTON_NEUTRAL) {
                contentResolver.delete(uri, null, null);
            }
            dismiss();
        }
    };
    dialog.setPositiveButton(isAdd ? R.string.button_add : R.string.edit_address_book_entry_dialog_button_edit, onClickListener);
    if (!isAdd)
        dialog.setNeutralButton(R.string.button_delete, onClickListener);
    dialog.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            dismissAllowingStateLoss();
        }
    });
    return dialog.create();
}
Also used : ContentValues(android.content.ContentValues) Address(org.bitcoinj.core.Address) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) Uri(android.net.Uri) TextView(android.widget.TextView) View(android.view.View) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView)

Example 23 with Address

use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.

the class SendingAddressesFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    adapter = new SimpleCursorAdapter(activity, R.layout.address_book_row, null, new String[] { AddressBookProvider.KEY_LABEL, AddressBookProvider.KEY_ADDRESS }, new int[] { R.id.address_book_row_label, R.id.address_book_row_address }, 0);
    adapter.setViewBinder(new ViewBinder() {

        @Override
        public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
            if (!AddressBookProvider.KEY_ADDRESS.equals(cursor.getColumnName(columnIndex)))
                return false;
            ((TextView) view).setText(WalletUtils.formatHash(cursor.getString(columnIndex), Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE));
            return true;
        }
    });
    setListAdapter(adapter);
    final List<ECKey> derivedKeys = wallet.getIssuedReceiveKeys();
    Collections.sort(derivedKeys, DeterministicKey.CHILDNUM_ORDER);
    final List<ECKey> randomKeys = wallet.getImportedKeys();
    final StringBuilder builder = new StringBuilder();
    for (final ECKey key : Iterables.concat(derivedKeys, randomKeys)) {
        final Address address = key.toAddress(Constants.NETWORK_PARAMETERS);
        builder.append(address.toBase58()).append(",");
    }
    if (builder.length() > 0)
        builder.setLength(builder.length() - 1);
    walletAddressesSelection = builder.toString();
    loaderManager.initLoader(0, null, this);
}
Also used : WholeStringBuilder(de.schildbach.wallet.util.WholeStringBuilder) Address(org.bitcoinj.core.Address) SimpleCursorAdapter(android.widget.SimpleCursorAdapter) ECKey(org.bitcoinj.core.ECKey) ViewBinder(android.widget.SimpleCursorAdapter.ViewBinder) Cursor(android.database.Cursor) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 24 with Address

use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.

the class SendingAddressesFragment method onActivityResult.

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (requestCode == REQUEST_CODE_SCAN && resultCode == Activity.RESULT_OK) {
        final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
        new StringInputParser(input) {

            @Override
            protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
                // workaround for "IllegalStateException: Can not perform this action after
                // onSaveInstanceState"
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        if (paymentIntent.hasAddress()) {
                            final Address address = paymentIntent.getAddress();
                            if (!wallet.isPubKeyHashMine(address.getHash160()))
                                EditAddressBookEntryFragment.edit(getFragmentManager(), address);
                            else
                                dialog(activity, null, R.string.address_book_options_scan_title, R.string.address_book_options_scan_own_address);
                        } else {
                            dialog(activity, null, R.string.address_book_options_scan_title, R.string.address_book_options_scan_invalid);
                        }
                    }
                }, 500);
            }

            @Override
            protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
                cannotClassify(input);
            }

            @Override
            protected void error(final int messageResId, final Object... messageArgs) {
                dialog(activity, null, R.string.address_book_options_scan_title, messageResId, messageArgs);
            }
        }.parse();
    }
}
Also used : Address(org.bitcoinj.core.Address) Transaction(org.bitcoinj.core.Transaction) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) VerificationException(org.bitcoinj.core.VerificationException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent)

Example 25 with Address

use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.

the class WalletAddressesAdapter method rowKey.

private View rowKey(final int position, View row) {
    final ECKey key = (ECKey) getItem(position);
    final Address address = key.toAddress(Constants.NETWORK_PARAMETERS);
    final boolean isRotateKey = wallet.isKeyRotating(key);
    if (row == null)
        row = inflater.inflate(R.layout.address_book_row, null);
    final TextView addressView = (TextView) row.findViewById(R.id.address_book_row_address);
    addressView.setText(WalletUtils.formatAddress(address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE));
    addressView.setTextColor(isRotateKey ? colorInsignificant : colorSignificant);
    final TextView labelView = (TextView) row.findViewById(R.id.address_book_row_label);
    final String label = AddressBookProvider.resolveLabel(context, address.toBase58());
    if (label != null) {
        labelView.setText(label);
        labelView.setTextColor(isRotateKey ? colorInsignificant : colorLessSignificant);
    } else {
        labelView.setText(R.string.address_unlabeled);
        labelView.setTextColor(colorInsignificant);
    }
    final TextView messageView = (TextView) row.findViewById(R.id.address_book_row_message);
    messageView.setVisibility(isRotateKey ? View.VISIBLE : View.GONE);
    return row;
}
Also used : Address(org.bitcoinj.core.Address) ECKey(org.bitcoinj.core.ECKey) TextView(android.widget.TextView)

Aggregations

Address (org.bitcoinj.core.Address)26 WalletService (io.bitsquare.btc.WalletService)8 Coin (org.bitcoinj.core.Coin)8 Transaction (org.bitcoinj.core.Transaction)8 AddressEntry (io.bitsquare.btc.AddressEntry)7 TextView (android.widget.TextView)5 View (android.view.View)3 Offer (io.bitsquare.trade.offer.Offer)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 Inject (com.google.inject.Inject)2 Arbitrator (io.bitsquare.arbitration.Arbitrator)2 PreparedDepositTxAndOffererInputs (io.bitsquare.btc.data.PreparedDepositTxAndOffererInputs)2 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)2 UserThread (io.bitsquare.common.UserThread)2 NodeAddress (io.bitsquare.p2p.NodeAddress)2 Trade (io.bitsquare.trade.Trade)2 InetSocketAddress (java.net.InetSocketAddress)2