public static void populatePriceDetails( Context context, View root, boolean isBuyer, boolean isSelf, String currency, PriceFormula priceFormula, long satoshisAtMarketPrice, long satoshisTraded, int fiatTraded, MbwManager mbwManager) { Locale locale = new Locale("en", "US"); // Price double oneBtcPrice = (double) fiatTraded * Constants.ONE_BTC_IN_SATOSHIS / (double) satoshisTraded; String price = Utils.getFiatValueAsString(Constants.ONE_BTC_IN_SATOSHIS, oneBtcPrice); ((TextView) root.findViewById(R.id.tvPriceValue)) .setText(context.getResources().getString(R.string.lt_btc_price, price, currency)); String fiatAmountString = String.format(locale, "%s %s", fiatTraded, currency); String btcAmountString = mbwManager.getBtcValueString(satoshisTraded); // You Pay / You Get Values if (isBuyer) { ((TextView) root.findViewById(R.id.tvPayValue)).setText(fiatAmountString); ((TextView) root.findViewById(R.id.tvGetValue)).setText(btcAmountString); } else { ((TextView) root.findViewById(R.id.tvPayValue)).setText(btcAmountString); ((TextView) root.findViewById(R.id.tvGetValue)).setText(fiatAmountString); } // You Pay / You Get Labels if (isSelf) { if (isBuyer) { ((TextView) root.findViewById(R.id.tvPriceLabel)).setText(R.string.lt_you_buy_at_label); } else { ((TextView) root.findViewById(R.id.tvPriceLabel)).setText(R.string.lt_you_sell_at_label); } ((TextView) root.findViewById(R.id.tvPayLabel)).setText(R.string.lt_you_pay_label); ((TextView) root.findViewById(R.id.tvGetLabel)).setText(R.string.lt_you_get_label); } else { if (isBuyer) { ((TextView) root.findViewById(R.id.tvPriceLabel)).setText(R.string.lt_buyer_buys_at_label); ((TextView) root.findViewById(R.id.tvPayLabel)).setText(R.string.lt_buyer_pays_label); ((TextView) root.findViewById(R.id.tvGetLabel)).setText(R.string.lt_buyer_gets_label); } else { ((TextView) root.findViewById(R.id.tvPriceLabel)) .setText(R.string.lt_seller_sells_at_label); ((TextView) root.findViewById(R.id.tvPayLabel)).setText(R.string.lt_seller_pays_label); ((TextView) root.findViewById(R.id.tvGetLabel)).setText(R.string.lt_seller_gets_label); } } }
private void switchCurrency() { int newDecimalPlaces; BigDecimal newAmount; if (_enterFiatAmount) { // We are switching from Fiat to BTC // Set BTC button Button btCurrency = (Button) findViewById(R.id.btCurrency); btCurrency.setText(_mbwManager.getBitcoinDenomination().getUnicodeName()); // Set BTC balance ((TextView) findViewById(R.id.tvMaxAmount)).setText(getBalanceString(_balance)); newDecimalPlaces = _mbwManager.getBitcoinDenomination().getDecimalPlaces(); Long satoshis = getSatoshisToSend(); if (satoshis == null) { newAmount = null; } else { newAmount = BigDecimal.valueOf(satoshis).divide(BigDecimal.TEN.pow(newDecimalPlaces)); } } else { // We are switching from BTC to Fiat // Set Fiat button Button btCurrency = (Button) findViewById(R.id.btCurrency); btCurrency.setText(_mbwManager.getFiatCurrency()); // Set Fiat balance String fiatBalance = Utils.getFiatValueAsString(_balance, _oneBtcInFiat); String balanceString = getResources().getString(R.string.max_fiat, fiatBalance, _mbwManager.getFiatCurrency()); ((TextView) findViewById(R.id.tvMaxAmount)).setText(balanceString); newDecimalPlaces = 2; Long fiatCents = getFiatCentsToSend(); if (fiatCents == null) { newAmount = null; } else { newAmount = BigDecimal.valueOf(fiatCents).divide(BigDecimal.TEN.pow(newDecimalPlaces)); } } // Note: Do the boolean switch before updating numberEntry, as there is // feedback from numberEntry back to ourselves _enterFiatAmount = !_enterFiatAmount; _numberEntry.setEntry(newAmount, newDecimalPlaces); // Check whether we can enable the paste button findViewById(R.id.btPaste).setEnabled(enablePaste()); }
private void updateAmounts(String amountText) { ((TextView) findViewById(R.id.tvAmount)).setText(amountText); TextView tvAlternateAmount = ((TextView) findViewById(R.id.tvAlternateAmount)); Long satoshis = getSatoshisToSend(); // enable/disable Max button findViewById(R.id.btMax).setEnabled(satoshis == null || _maxSendable != satoshis); // Set alternate amount if we can if (satoshis == null || _oneBtcInFiat == null) { tvAlternateAmount.setText(""); } else { if (_enterFiatAmount) { // Show BTC as alternate amount tvAlternateAmount.setText(_mbwManager.getBtcValueString(satoshis)); } else { // Show Fiat as alternate amount String converted = Utils.getFiatValueAsString(satoshis, _oneBtcInFiat); String currency = MbwManager.getInstance(getApplication()).getFiatCurrency(); tvAlternateAmount.setText( getResources().getString(R.string.approximate_fiat_value, currency, converted)); } } }