コード例 #1
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;
   }
 }
コード例 #2
0
    public AddDialog(final Activity activity) {
      super(activity);
      this.setContentView(R.layout.add_to_address_book_dialog);
      this.setTitle(R.string.add_to_address_book_dialog_title);

      findViewById(R.id.btScan)
          .setOnClickListener(
              new android.view.View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  Utils.startScannerIntent(activity, SCANNER_RESULT_CODE);
                  AddDialog.this.dismiss();
                }
              });

      Address address = Utils.addressFromString(Utils.getClipboardString(AddressBookActivity.this));
      findViewById(R.id.btClipboard).setEnabled(address != null);
      findViewById(R.id.btClipboard)
          .setOnClickListener(
              new android.view.View.OnClickListener() {

                @Override
                public void onClick(View v) {
                  String addressString = Utils.getClipboardString(AddressBookActivity.this);
                  addFromString(addressString);
                  AddDialog.this.dismiss();
                }
              });
    }
コード例 #3
0
 private void addFromString(String addressString) {
   Address address = Utils.addressFromString(addressString);
   if (address == null) {
     return;
   }
   Utils.showSetAddressLabelDialog(
       AddressBookActivity.this, _addressBook, address.toString(), updateRunnable);
 }
コード例 #4
0
 private void doShowQrCode() {
   String address = "bitcoin:" + mSelectedAddress;
   Bitmap bitmap = Utils.getLargeQRCodeBitmap(address, _mbwManager);
   _qrCodeDialog =
       Utils.showQrCode(
           this,
           R.string.bitcoin_address_title,
           bitmap,
           mSelectedAddress,
           R.string.copy_address_to_clipboard);
 }
コード例 #5
0
ファイル: PopActivity.java プロジェクト: badzso/wallet
 // onPostExecute displays the results of the AsyncTask.
 @Override
 protected void onPostExecute(String result) {
   if (result.equals("valid")) {
     Toast.makeText(PopActivity.this, R.string.pop_success, Toast.LENGTH_LONG).show();
     finish();
   } else {
     String serverMessage = result;
     String prefix = "invalid\n";
     if (result.startsWith(prefix)) {
       serverMessage = result.substring(prefix.length());
     }
     String message =
         s(R.string.pop_invalid_pop)
             + " "
             + s(R.string.pop_message_from_server)
             + "\n"
             + serverMessage;
     Utils.showSimpleMessageDialog(
         PopActivity.this,
         message,
         new Runnable() {
           @Override
           public void run() {
             launchSelectTransactionActivity();
           }
         },
         R.string.pop_select_other_tx,
         null);
   }
 }
コード例 #6
0
  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);
      }
    }
  }
コード例 #7
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;
   }
 }
コード例 #8
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());
  }
コード例 #9
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();
 }
コード例 #10
0
  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));
      }
    }
  }
コード例 #11
0
 private static String formatAddress(String address) {
   return StringUtils.join(Utils.stringChopper(address, 12), "\r\n");
 }
コード例 #12
0
 private void doEditEntry() {
   Utils.showSetAddressLabelDialog(this, _addressBook, mSelectedAddress, updateRunnable);
 }
コード例 #13
0
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
      if (convertView == null) {
        convertView = inflater.inflate(R.layout.ext_cashila_pending_row, null);
      }

      final BillPay billPay = getItem(position);

      TextView tvName = ButterKnife.findById(convertView, R.id.tvName);
      TextView tvAmount = ButterKnife.findById(convertView, R.id.tvAmount);
      TextView tvOutstandingAmount = ButterKnife.findById(convertView, R.id.tvOutstandingAmount);
      TextView tvStatus = ButterKnife.findById(convertView, R.id.tvStatus);
      TextView tvFee = ButterKnife.findById(convertView, R.id.tvFee);
      TextView tvSectionHeader = ButterKnife.findById(convertView, R.id.tvSectionHeader);
      TextView tvReference = ButterKnife.findById(convertView, R.id.tvReference);
      TextView tvDate = ButterKnife.findById(convertView, R.id.tvDate);

      if (billPay.recipient != null) {
        tvName.setText(billPay.recipient.name);
      } else {
        tvName.setText("");
      }

      if (billPay.payment != null) {
        tvAmount.setText(
            Utils.formatFiatValueAsString(billPay.payment.amount) + " " + billPay.payment.currency);
        tvReference.setText(billPay.payment.reference);
      }

      tvStatus.setText(billPay.status.getLocalizedString(getActivity()));

      if (billPay.details != null) {
        String fee;
        if (billPay.details.fee != null) {
          fee = Utils.formatFiatValueAsString(billPay.details.fee) + " " + billPay.payment.currency;
        } else {
          fee = "???";
        }
        tvFee.setText(getResources().getString(R.string.cashila_fee, fee));

        // if there is already an amount deposited but still outstanding we have underpaid (maybe
        // because of some latency of
        // the bitcoin network and/or changes in exchange rate)

        BigDecimal amountDeposited =
            billPay.details.amountDeposited == null
                ? BigDecimal.ZERO
                : billPay.details.amountDeposited;
        BigDecimal amountToDeposit =
            billPay.details.amountToDeposit == null
                ? BigDecimal.ZERO
                : billPay.details.amountToDeposit;
        if (BigDecimal.ZERO.compareTo(amountDeposited) < 0
            && BigDecimal.ZERO.compareTo(amountToDeposit) < 0) {
          tvOutstandingAmount.setVisibility(View.VISIBLE);
          long satoshisOutstanding = Bitcoins.nearestValue(amountToDeposit).getLongValue();
          tvOutstandingAmount.setText(
              String.format(
                  getResources().getString(R.string.cashila_amount_outstanding),
                  mbw.getBtcValueString(satoshisOutstanding)));
        } else {
          tvOutstandingAmount.setVisibility(View.GONE);
        }
        tvDate.setText(Utils.getFormattedDate(getContext(), billPay.details.createdAt));
      }

      if (position == 0) {
        tvSectionHeader.setVisibility(View.VISIBLE);
      } else if (getItem(position - 1).getSortOrder() != billPay.getSortOrder()) {
        tvSectionHeader.setVisibility(View.VISIBLE);
      } else {
        tvSectionHeader.setVisibility(View.GONE);
      }
      if (billPay.isPayable()) {
        tvSectionHeader.setText(getResources().getString(R.string.cashila_pending));
      } else if (billPay.status.equals(BillPayStatus.uploaded)) {
        tvSectionHeader.setText(getResources().getString(R.string.cashila_uploaded_title));
      } else {
        tvSectionHeader.setText(getResources().getString(R.string.cashila_done));
      }

      final ActionBarActivity actionBarActivity = (ActionBarActivity) getActivity();

      final RelativeLayout rlReference = ButterKnife.findById(convertView, R.id.rlReference);
      convertView.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              currentActionMode =
                  actionBarActivity.startSupportActionMode(
                      new ActionMode.Callback() {
                        @Override
                        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                          if (billPay.isPayable()) {
                            actionMode
                                .getMenuInflater()
                                .inflate(R.menu.ext_cashila_pending_payments_menu, menu);
                            currentActionMode = actionMode;
                          }
                          rlReference.setVisibility(View.VISIBLE);
                          lvPending.setItemChecked(position, true);
                          return true;
                        }

                        @Override
                        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
                          rlReference.setVisibility(View.VISIBLE);
                          return billPay.isPayable();
                        }

                        @Override
                        public boolean onActionItemClicked(
                            ActionMode actionMode, MenuItem menuItem) {
                          final int itemId = menuItem.getItemId();
                          if (itemId == R.id.miDeletePayment) {
                            deletePayment(billPay);
                            return true;
                          } else if (itemId == R.id.miPayNow) {
                            payNow(billPay);
                            return true;
                          }

                          return false;
                        }

                        @Override
                        public void onDestroyActionMode(ActionMode actionMode) {
                          lvPending.setItemChecked(position, false);
                          rlReference.setVisibility(View.GONE);
                          currentActionMode = null;
                        }
                      });
            }
          });

      return convertView;
    }
コード例 #14
0
 @Override
 public boolean onNoLtConnection() {
   Utils.toastConnectionError(SolveCaptchaActivity.this);
   finish();
   return true;
 }