コード例 #1
0
  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());
  }
コード例 #2
0
 private BigDecimal getAmountFromClipboard() {
   String content = Utils.getClipboardString(GetSendingAmountActivity.this);
   if (content.length() == 0) {
     return null;
   }
   String number = content.toString().trim();
   if (_enterFiatAmount) {
     number = Utils.truncateAndConvertDecimalString(number, 2);
     if (number == null) {
       return null;
     }
     BigDecimal value = new BigDecimal(number);
     if (value.compareTo(BigDecimal.ZERO) < 1) {
       return null;
     }
     return value;
   } else {
     number =
         Utils.truncateAndConvertDecimalString(
             number, _mbwManager.getBitcoinDenomination().getDecimalPlaces());
     if (number == null) {
       return null;
     }
     BigDecimal value = new BigDecimal(number);
     if (value.compareTo(BigDecimal.ZERO) < 1) {
       return null;
     }
     return value;
   }
 }
コード例 #3
0
 @Override
 public void onClick(View arg0) {
   BigDecimal clipboardValue = getAmountFromClipboard();
   if (clipboardValue == null) {
     return;
   }
   _numberEntry.setEntry(
       clipboardValue, _mbwManager.getBitcoinDenomination().getDecimalPlaces());
 }
コード例 #4
0
 private Long getSatoshisToSend() {
   BigDecimal entry = _numberEntry.getEntryAsBigDecimal();
   if (entry == null) {
     return null;
   }
   if (_enterFiatAmount) {
     return Utils.getSatoshis(entry, _oneBtcInFiat);
   } else {
     int decimals = _mbwManager.getBitcoinDenomination().getDecimalPlaces();
     Long satoshis = entry.movePointRight(decimals).longValue();
     return satoshis;
   }
 }
コード例 #5
0
 private void maximizeAmount() {
   if (_maxSendable == 0) {
     String msg = getResources().getString(R.string.insufficient_funds);
     _toast.setText(msg);
     _toast.show();
   } else {
     if (_enterFiatAmount) {
       switchCurrency();
     }
     int newDecimalPlaces = _mbwManager.getBitcoinDenomination().getDecimalPlaces();
     BigDecimal newAmount =
         BigDecimal.valueOf(_maxSendable).divide(BigDecimal.TEN.pow(newDecimalPlaces));
     _numberEntry.setEntry(newAmount, newDecimalPlaces);
   }
 }
コード例 #6
0
 // todo de-duplicate code
 private Long getFiatCentsToSend() {
   Double fiatAmount;
   BigDecimal entry = _numberEntry.getEntryAsBigDecimal();
   if (entry == null) {
     return null;
   }
   if (_enterFiatAmount) {
     fiatAmount = entry.doubleValue();
   } else {
     int decimals = _mbwManager.getBitcoinDenomination().getDecimalPlaces();
     Long satoshis = entry.movePointRight(decimals).longValue();
     fiatAmount = Utils.getFiatValue(satoshis, _oneBtcInFiat);
   }
   Double fiatCents = fiatAmount * 100;
   return fiatCents.longValue();
 }
コード例 #7
0
  @SuppressLint("ShowToast")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.get_sending_amount_activity);
    _toast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
    _mbwManager = MbwManager.getInstance(getApplication());

    // Get intent parameters
    _wallet = Preconditions.checkNotNull((Wallet) getIntent().getSerializableExtra("wallet"));
    _spendable =
        Preconditions.checkNotNull(
            (SpendableOutputs) getIntent().getSerializableExtra("spendable"));
    // May be null
    _oneBtcInFiat = (Double) getIntent().getSerializableExtra("oneBtcInFiat");
    Long amount = (Long) getIntent().getSerializableExtra("amountToSend");

    // Load saved state
    if (savedInstanceState != null) {
      amount = (Long) savedInstanceState.getSerializable("amountToSend");
    }

    // Construct list of outputs
    _outputs = new LinkedList<UnspentTransactionOutput>();
    _outputs.addAll(_spendable.unspent);
    _outputs.addAll(_spendable.change);

    // Construct private key ring
    _privateKeyRing = _wallet.getPrivateKeyRing();

    // Determine and set balance
    _balance = 0;
    for (UnspentTransactionOutput out : _outputs) {
      _balance += out.value;
    }
    ((TextView) findViewById(R.id.tvMaxAmount)).setText(getBalanceString(_balance));

    // Calculate the maximum amount we can send
    _maxSendable = getMaxAmount();

    // Set amount
    String amountString;
    if (amount != null) {
      amountString = CoinUtil.valueString(amount, _mbwManager.getBitcoinDenomination(), false);
    } else {
      amountString = "";
    }
    TextView tvAmount = (TextView) findViewById(R.id.tvAmount);
    tvAmount.setText(amountString);

    _numberEntry =
        new NumberEntry(
            _mbwManager.getBitcoinDenomination().getDecimalPlaces(), this, this, amountString);
    checkTransaction();

    // Make both currency button and invisible right button at top a listener
    // switch currency
    Button btCurrency = (Button) findViewById(R.id.btCurrency);
    btCurrency.setText(_mbwManager.getBitcoinDenomination().getUnicodeName());
    btCurrency.setEnabled(_oneBtcInFiat != null);
    btCurrency.setOnClickListener(switchCurrencyListener);
    findViewById(R.id.btRight).setOnClickListener(switchCurrencyListener);

    // Make both paste button and invisible left button at top a listener to
    // paste from clipboard
    Button btPaste = (Button) findViewById(R.id.btPaste);
    btPaste.setOnClickListener(pasteListener);
    findViewById(R.id.btLeft).setOnClickListener(pasteListener);

    // Next Button
    findViewById(R.id.btOk).setOnClickListener(okClickListener);

    // Max Button
    findViewById(R.id.btMax).setOnClickListener(maxClickListener);
  }