Here are the examples of the java api class com.google.bitcoin.core.Address taken from open source projects.
1. AbstractTradePanel#processDecodedString()
Project: multibit
File: AbstractTradePanel.java
File: AbstractTradePanel.java
public boolean processDecodedString(String decodedString, ImageIcon icon) { // check to see if the wallet files have changed WalletData perWalletModelData = this.bitcoinController.getModel().getActivePerWalletModelData(); // decode the string to an WalletAddressBookData // Early MultiBit versions did not URL encode the label hence may // have illegal embedded spaces - convert to ENCODED_SPACE_CHARACTER // i.e be lenient String uriString = decodedString.replace(" ", BitcoinController.ENCODED_SPACE_CHARACTER); BitcoinURI bitcoinURI; try { bitcoinURI = new BitcoinURI(this.bitcoinController.getModel().getNetworkParameters(), uriString); } catch (BitcoinURIParseException e) { Message message = new Message(e.getClass().getName() + " " + e.getMessage()); MessageManager.INSTANCE.addMessage(message); return false; } log.debug("AbstractTradePanel - ping 1"); Address address = bitcoinURI.getAddress(); log.debug("AbstractTradePanel - ping 2"); String addressString = address.toString(); log.debug("AbstractTradePanel - ping 3"); String amountString = ""; String amountStringLocalised = ""; if (amountBTCTextField != null) { CurrencyConverterResult converterResult = CurrencyConverter.INSTANCE.parseToBTC(amountBTCTextField.getText()); if (converterResult.isBtcMoneyValid()) { parsedAmountBTC = converterResult.getBtcMoney(); amountString = controller.getLocaliser().bitcoinValueToStringNotLocalised(parsedAmountBTC.getAmount().toBigInteger(), false, false); amountStringLocalised = CurrencyConverter.INSTANCE.getBTCAsLocalisedString(parsedAmountBTC); } else { parsedAmountBTC = null; if (notificationLabel != null) { notificationLabel.setText(converterResult.getBtcMessage()); } } } if (bitcoinURI.getAmount() != null) { amountString = controller.getLocaliser().bitcoinValueToStringNotLocalised(bitcoinURI.getAmount(), false, false); parsedAmountBTC = Money.of(CurrencyConverter.INSTANCE.BITCOIN_CURRENCY_UNIT, new BigDecimal(bitcoinURI.getAmount())); amountStringLocalised = CurrencyConverter.INSTANCE.getBTCAsLocalisedString(parsedAmountBTC); } log.debug("AbstractTradePanel - ping 4"); String decodedLabel = ""; try { if (bitcoinURI.getLabel() != null) { decodedLabel = java.net.URLDecoder.decode(bitcoinURI.getLabel(), "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } log.debug("AbstractTradePanel#processDecodedString addressString = " + addressString + ", amountString = " + amountString + ", label = " + decodedLabel); log.debug("AbstractTradePanel - ping 5"); WalletAddressBookData addressBookData = new WalletAddressBookData(decodedLabel, addressString); log.debug("AbstractTradePanel - ping 6"); // see if the address is already in the address book // see if the current address is on the table and // select it int rowToSelectModel = addressesTableModel.findRowByAddress(addressBookData.getAddress(), false); if (rowToSelectModel >= 0) { addressesTableModel.setAddressBookDataByRow(addressBookData, rowToSelectModel, false); selectedAddressRowModel = rowToSelectModel; selectRowInTableFromModelRow(rowToSelectModel); } else { // add a new row to the table this.bitcoinController.getModel().getActiveWalletWalletInfo().addSendingAddress(addressBookData); this.bitcoinController.getModel().getActivePerWalletModelData().setDirty(true); addressesTableModel.fireTableDataChanged(); // select new row rowToSelectModel = addressesTableModel.findRowByAddress(addressBookData.getAddress(), false); if (rowToSelectModel >= 0) { selectedAddressRowModel = rowToSelectModel; selectRowInTableFromModelRow(rowToSelectModel); } } addressesTable.invalidate(); addressesTable.validate(); addressesTable.repaint(); mainFrame.invalidate(); mainFrame.validate(); mainFrame.repaint(); log.debug("AbstractTradePanel - ping 7"); this.bitcoinController.getModel().setActiveWalletPreference(BitcoinModel.SEND_ADDRESS, addressString); log.debug("AbstractTradePanel - ping 8"); this.bitcoinController.getModel().setActiveWalletPreference(BitcoinModel.SEND_LABEL, decodedLabel); log.debug("AbstractTradePanel - ping 9"); this.bitcoinController.getModel().setActiveWalletPreference(BitcoinModel.SEND_AMOUNT, amountString); log.debug("AbstractTradePanel - ping 10"); addressTextField.setText(addressString); log.debug("AbstractTradePanel - ping 11"); amountBTCTextField.setText(amountStringLocalised); log.debug("AbstractTradePanel - ping 12"); labelTextArea.setText(decodedLabel); log.debug("AbstractTradePanel - ping 13"); updateFiatAmount(); log.debug("AbstractTradePanel - ping 14"); Message message = new Message(""); MessageManager.INSTANCE.addMessage(message); if (icon != null) { qrCodeLabel.setIcon(icon); setDragLabelTextAndTooltip(); } else { displayQRCode(addressString, amountString, decodedLabel); } checkDeleteSendingEnabled(); return true; }
2. BitcoinWallet#moneyReceived()
Project: bitcoin-android
File: BitcoinWallet.java
File: BitcoinWallet.java
private void moneyReceived(Transaction tx) { appState.saveWallet(); updateUI(); if (appState.notifiedUserOfTheseTransactions.contains(tx.getHash())) { //this could be called multiple times by separate peers return; } else { appState.notifiedUserOfTheseTransactions.add(tx.getHash()); } TransactionInput input = tx.getInputs().get(0); Address from; try { from = input.getFromAddress(); } catch (ScriptException e) { return; } BigInteger value = tx.getValueSentToMe(appState.wallet); Log.d("Wallet", "Received " + Utils.bitcoinValueToFriendlyString(value) + " from " + from.toString()); String ticker = Utils.bitcoinValueToFriendlyString(value) + " Bitcoins Received!"; String ns = Context.NOTIFICATION_SERVICE; NotificationManager notificationManager = (NotificationManager) getSystemService(ns); Notification notification = new Notification(R.drawable.my_notification_icon, ticker, System.currentTimeMillis()); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.flags |= Notification.FLAG_AUTO_CANCEL; Context context = getApplicationContext(); CharSequence contentTitle = ticker; CharSequence contentText = "From " + from.toString(); Intent notificationIntent = new Intent(this, BitcoinWallet.class); //don't open a new one if it's already on top notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notificationManager.notify(1, notification); }