List of usage examples for java.math BigInteger signum
int signum
To view the source code for java.math BigInteger signum.
Click Source Link
From source file:com.rimbit.android_wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override// w w w. j a va2s . com public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final BigInteger value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafeRimbitSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { Nfc.unpublish(nfcManager, activity); } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = (int) (384 * getResources().getDisplayMetrics().density); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:com.woollysammoth.nubit_android_wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override// ww w . j a v a 2 s . c o m public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final BigInteger value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafeNubitSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { Nfc.unpublish(nfcManager, activity); } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = (int) (384 * getResources().getDisplayMetrics().density); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:de.schildbach.litecoinwallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override// w w w.j a v a 2 s .c o m public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final BigInteger value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafeBitcoinSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx, false); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_open_blockexplorer: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.BLOCKEXPLORER_BASE_URL + "tx/" + tx.getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { Nfc.unpublish(nfcManager, activity); } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = (int) (384 * getResources().getDisplayMetrics().density); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:com.hamradiocoin.wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override/* w ww . java2 s . c o m*/ public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final BigInteger value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafeBitcoinSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + Constants.EXPLORE_TRANSACTION_PATH + tx.getHashAsString()))); mode.finish(); return true; case R.id.wallet_transactions_context_show_transaction: TransactionActivity.show(activity, tx); } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { Nfc.unpublish(nfcManager, activity); } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = (int) (384 * getResources().getDisplayMetrics().density); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:com.cannabiscoin.wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override/*from w w w . j a v a 2s .c o m*/ public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final BigInteger value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafeBitcoinSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx, false); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + Constants.EXPLORE_TRANSACTION_PATH + tx.getHashAsString()))); mode.finish(); return true; case R.id.wallet_transactions_context_show_transaction: TransactionActivity.show(activity, tx); } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { Nfc.unpublish(nfcManager, activity); } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = (int) (384 * getResources().getDisplayMetrics().density); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:com.google.uzaygezen.core.LongBitVector.java
@Override public void copyFrom(BigInteger s) { Preconditions.checkArgument(s.signum() >= 0, s); Preconditions.checkArgument(s.bitLength() <= size()); // Note that the long value will be negative iff bitLength == 644 and bit 63 // is set./*from ww w .j a v a 2s .co m*/ copyFrom(s.longValue()); }
From source file:cc.mintcoin.wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override// w w w . jav a 2s.co m public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? activity.getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final BigInteger value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = activity.getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = activity.getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafeBitcoinSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx, false); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_open_blockexplorer: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.BLOCKEXPLORER_BASE_URL + "tx/" + tx.getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { try { Nfc.unpublish(nfcManager, activity); } catch (IllegalStateException ise) { // Swallow. Activity is probably paused currently. No need to unpublish. } } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = (int) (384 * getResources().getDisplayMetrics().density); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:com.hivewallet.androidclient.wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override//from w w w .j ava 2 s . com public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final BigInteger value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafeBitcoinSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { Nfc.unpublish(nfcManager, activity); } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = (int) (384 * getResources().getDisplayMetrics().density); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:com.kncwallet.wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override// w w w . ja va 2 s . co m public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final BigInteger value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getFirstToAddress(tx) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); MenuItem editIcon = menu.findItem(R.id.wallet_transactions_context_edit_address); editIcon.setVisible(address != null); if (address != null) { if (label != null) { //edit icon only if no number String number = AddressBookProvider.resolveRawTelephone(activity, address.toString()); editIcon.setVisible(true); if (number == null || number.equals("")) { editIcon.setIcon(R.drawable.ic_action_edit); } else { editIcon.setVisible(false); } } else { //this is an add editIcon.setIcon(R.drawable.ic_action_new_label); editIcon.setVisible(true); } } serializedTx = tx.unsafeBitcoinSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_TRANSACTION, serializedTx, false); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { Nfc.unpublish(nfcManager, activity); } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = (int) (384 * getResources().getDisplayMetrics().density); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:piuk.blockchain.android.ui.WalletTransactionsFragment.java
public void initAdapter() { adapter = new ArrayAdapter<Transaction>(activity, 0) { final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); final int colorSignificant = getResources().getColor(R.color.significant); final int colorInsignificant = getResources().getColor(R.color.insignificant); final int colorSent = getResources().getColor(R.color.color_sent); final int colorReceived = getResources().getColor(R.color.color_received); @Override// w w w . j av a 2 s .c o m public View getView(final int position, View row, final ViewGroup parent) { if (row == null) row = getLayoutInflater(null).inflate(R.layout.transaction_row, null); final CurrencyAmountView rowValue = (CurrencyAmountView) row .findViewById(R.id.transaction_row_value); final TextView rowLabel = (TextView) row.findViewById(R.id.transaction_row_address); final TextView rowTime = (TextView) row.findViewById(R.id.transaction_row_time); try { synchronized (adapter) { final Transaction tx = getItem(position); if (tx.getHash() == null) { rowLabel.setTextColor(Color.BLACK); rowLabel.setText(R.string.no_transactions); rowLabel.setTypeface(Typeface.DEFAULT); rowLabel.setTextColor(Color.BLACK); rowTime.setVisibility(View.INVISIBLE); rowValue.setVisibility(View.INVISIBLE); rowLabel.setGravity(Gravity.CENTER); return row; } else { rowTime.setVisibility(View.VISIBLE); rowValue.setVisibility(View.VISIBLE); rowLabel.setGravity(Gravity.LEFT); final TransactionConfidence confidence = tx.getConfidence(); final ConfidenceType confidenceType = confidence.getConfidenceType(); try { BigInteger value = null; if (tx instanceof MyTransaction) { value = ((MyTransaction) tx).getResult(); } else { value = tx.getValue(application.bitcoinjWallet); } final boolean sent = value.signum() < 0; final int textColor; if (confidenceType == ConfidenceType.NOT_SEEN_IN_CHAIN) { textColor = colorInsignificant; } else if (confidenceType == ConfidenceType.BUILDING) { textColor = colorSignificant; } else if (confidenceType == ConfidenceType.NOT_IN_BEST_CHAIN) { textColor = colorSignificant; } else if (confidenceType == ConfidenceType.DEAD) { textColor = Color.RED; } else { textColor = colorInsignificant; } final String address; if (sent) if (tx.getOutputs().size() == 0) address = "Unknown"; else address = tx.getOutputs().get(0).getScriptPubKey().getToAddress() .toString(); else if (tx.getInputs().size() == 0) address = "Generation"; else address = tx.getInputs().get(0).getFromAddress().toString(); String label = null; if (tx instanceof MyTransaction && ((MyTransaction) tx).getTag() != null) label = ((MyTransaction) tx).getTag(); else label = AddressBookProvider.resolveLabel(activity.getContentResolver(), address); final Date time = tx.getUpdateTime(); rowTime.setText( time != null ? (DateUtils.isToday(time.getTime()) ? timeFormat.format(time) : dateFormat.format(time)) : null); rowTime.setTextColor(textColor); rowLabel.setTextColor(textColor); rowLabel.setText(label != null ? label : address); rowLabel.setTypeface(label != null ? Typeface.DEFAULT : Typeface.MONOSPACE); rowValue.setCurrencyCode(null); rowValue.setAmountSigned(true); rowValue.setTextColor(textColor); rowValue.setAmount(value); if (sent) { rowValue.setTextColor(colorSent); } else { rowValue.setTextColor(colorReceived); } return row; } catch (final ScriptException x) { throw new RuntimeException(x); } } } } catch (Exception e) { e.printStackTrace(); rowLabel.setTextColor(Color.BLACK); rowLabel.setText(R.string.unknown_error); rowLabel.setTypeface(Typeface.DEFAULT); rowLabel.setTextColor(Color.BLACK); rowLabel.setGravity(Gravity.CENTER); rowTime.setVisibility(View.INVISIBLE); rowValue.setVisibility(View.INVISIBLE); return row; } } }; setAdapterContent(); setListAdapter(adapter); }