/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lt_solve_captcha_activity);
    _mbwManager = MbwManager.getInstance(this);
    _ltManager = _mbwManager.getLocalTraderManager();

    _tvSolution = ((TextView) findViewById(R.id.tvSolution));
    _btDone = (Button) findViewById(R.id.btDone);
    _btNew = (ImageButton) findViewById(R.id.btNew);
    _pbSolving = ((ProgressBar) findViewById(R.id.pbSolving));
    _pbWait = ((ProgressBar) findViewById(R.id.pbWait));
    _btNew = ((ImageButton) findViewById(R.id.btNew));

    _btDone.setOnClickListener(doneClickListener);
    _btNew.setOnClickListener(newClickListener);

    // Load saved state
    Integer solution = null;
    if (savedInstanceState != null) {
      _captcha = (Captcha) savedInstanceState.getSerializable("captcha");
      _isSolving = savedInstanceState.getBoolean("isSolving");
      solution = savedInstanceState.getInt("solution");
    }
    _numberEntry = new NumberEntry(0, this, this, solution == null ? "" : solution.toString());
  }
Exemple #2
0
  public void sendPop(View view) {
    try {
      if (txidToProve == null) {
        Toast.makeText(this, R.string.pop_no_transaction_selected, Toast.LENGTH_LONG).show();
      }
      WalletAccount account = _mbwManager.getSelectedAccount();

      final UnsignedTransaction unsignedPop =
          account.createUnsignedPop(txidToProve, popRequest.getN());

      _mbwManager.runPinProtectedFunction(
          PopActivity.this,
          new Runnable() {

            @Override
            public void run() {
              disableButtons();
              SignTransactionActivity.callMe(
                  PopActivity.this,
                  _mbwManager.getSelectedAccount().getId(),
                  false,
                  unsignedPop,
                  SIGN_TRANSACTION_REQUEST_CODE);
            }
          });
    } catch (Exception e) {
      Toast.makeText(this, "An internal error occurred:" + e.getMessage(), Toast.LENGTH_LONG)
          .show();
    }
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.address_book);
   registerForContextMenu(getListView());
   _mbwManager = MbwManager.getInstance(getApplication());
   _addressBook = _mbwManager.getAddressBookManager();
   findViewById(R.id.btAdd).setOnClickListener(new AddClicked());
   this.getListView().setLongClickable(false);
 }
  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());
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView =
        inflater.inflate(R.layout.ext_cashila_payments_fragment_pending, container, false);
    ButterKnife.inject(this, rootView);

    mbw = MbwManager.getInstance(this.getActivity());
    cs = ((CashilaPaymentsActivity) getActivity()).getCashilaService();
    eventBus = mbw.getEventBus();
    lvPending.setEmptyView(tvEmpty);

    getBillPays(true, true);

    return rootView;
  }
 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;
   }
 }
 @Override
 public void onClick(View arg0) {
   BigDecimal clipboardValue = getAmountFromClipboard();
   if (clipboardValue == null) {
     return;
   }
   _numberEntry.setEntry(
       clipboardValue, _mbwManager.getBitcoinDenomination().getDecimalPlaces());
 }
 private InMemoryPrivateKey getLocalTraderPrivateKey() {
   if (_localTraderPrivateKeyString == null) {
     return null;
   }
   if (_localTraderPrivateKey == null) {
     _localTraderPrivateKey =
         new InMemoryPrivateKey(_localTraderPrivateKeyString, _mbwManager.getNetwork());
   }
   return _localTraderPrivateKey;
 }
Exemple #9
0
 private long getPaymentAmountSatoshis(TransactionSummary transactionSummary) {
   long amountSatoshis = transactionSummary.value;
   if (amountSatoshis < 0) {
     amountSatoshis = -amountSatoshis;
   }
   TransactionDetails transactionDetails =
       _mbwManager.getSelectedAccount().getTransactionDetails(transactionSummary.txid);
   amountSatoshis -= getFee(transactionDetails);
   return amountSatoshis;
 }
Exemple #10
0
  private void updateUi(TransactionSummary transactionSummary) {
    MetadataStorage metadataStorage = _mbwManager.getMetadataStorage();

    // Set Date
    Date date = new Date(transactionSummary.time * 1000L);
    DateFormat dateFormat = new AdaptiveDateFormat(getApplicationContext());
    setText(R.id.pop_transaction_date, dateFormat.format(date));

    // Set amount
    long amountSatoshis = getPaymentAmountSatoshis(transactionSummary);
    String value = _mbwManager.getBtcValueString(amountSatoshis);
    String fiatValue =
        _mbwManager.getCurrencySwitcher().getFormattedFiatValue(amountSatoshis, true);
    String fiatAppendment = "";
    if (!Strings.isNullOrEmpty(fiatValue)) {
      fiatAppendment = " (" + fiatValue + ")";
    }
    setText(R.id.pop_transaction_amount, value + fiatAppendment);

    // Set label
    String label = metadataStorage.getLabelByTransaction(transactionSummary.txid);
    setText(R.id.pop_transaction_label, label);

    URL url = getUrl(popRequest.getP());
    if (url == null) {
      Toast.makeText(this, "Invalid URL:" + popRequest.getP(), Toast.LENGTH_LONG).show();
      finish();
      return;
    }

    TextView textView = (TextView) findViewById(R.id.pop_recipient_host);
    textView.setText(url.getHost());
    String protocol = url.getProtocol();
    if ("https".equals(protocol)) {
      textView.setCompoundDrawablesWithIntrinsicBounds(
          R.drawable.holo_dark_ic_action_secure, 0, 0, 0);
    } else if ("http".equals(protocol)) {
      textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    } else {
      Toast.makeText(this, "Unsupported protocol:" + url.getProtocol(), Toast.LENGTH_LONG).show();
      finish();
    }
  }
Exemple #11
0
 private TransactionSummary findFirstMatchingTransaction(
     PopRequest popRequest, List<TransactionSummary> transactions) {
   MetadataStorage metadataStorage = _mbwManager.getMetadataStorage();
   for (TransactionSummary transactionSummary : transactions) {
     if (PopUtils.matches(popRequest, metadataStorage, transactionSummary)) {
       return transactionSummary;
     }
   }
   return null;
 }
Exemple #12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pop_activity);
    _mbwManager = MbwManager.getInstance(getApplication());

    if (savedInstanceState != null) {
      popRequest = (PopRequest) savedInstanceState.getSerializable("popRequest");
      txidToProve = (Sha256Hash) savedInstanceState.getSerializable("txidToProve");
      updateUi(_mbwManager.getSelectedAccount().getTransactionSummary(txidToProve));
      return;
    }

    popRequest = (PopRequest) getIntent().getSerializableExtra("popRequest");
    if (popRequest == null) {
      finish();
    }

    Sha256Hash userSelectedTransaction =
        (Sha256Hash) getIntent().getSerializableExtra("selectedTransactionToProve");
    TransactionSummary txToProve;
    if (userSelectedTransaction != null) {
      txidToProve = userSelectedTransaction;
      txToProve = _mbwManager.getSelectedAccount().getTransactionSummary(txidToProve);
    } else {
      // Get history ordered by block height descending
      List<TransactionSummary> transactionHistory =
          _mbwManager.getSelectedAccount().getTransactionHistory(0, 10000);
      TransactionSummary matchingTransaction =
          findFirstMatchingTransaction(popRequest, transactionHistory);
      if (matchingTransaction == null) {
        launchSelectTransactionActivity();
        return;
      }
      txidToProve = matchingTransaction.txid;
      txToProve = matchingTransaction;
    }

    updateUi(txToProve);
  }
  /**
   * Check that the amount is large enough for the network to accept it, and that we have enough
   * funds to send it.
   */
  private AmountValidation checkSendAmount(long satoshis) {
    // Create transaction builder
    StandardTransactionBuilder stb = new StandardTransactionBuilder(_mbwManager.getNetwork());

    // Try and add the output
    try {
      // Note, null address used here, we just use it for measuring the
      // transaction size
      stb.addOutput(Address.getNullAddress(_mbwManager.getNetwork()), satoshis);
    } catch (OutputTooSmallException e1) {
      return AmountValidation.ValueTooSmall;
    }

    // Try to create an unsigned transaction
    try {
      stb.createUnsignedTransaction(_outputs, null, _privateKeyRing, _mbwManager.getNetwork());
    } catch (InsufficientFundsException e) {
      return AmountValidation.NotEnoughFunds;
    }
    return AmountValidation.Ok;
  }
  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 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;
   }
 }
  public static Transaction createSignedTransaction(TradeSession ts, MbwManager mbwManager) {
    Preconditions.checkNotNull(ts.buyerAddress);

    // Create default wallet
    Wallet wallet = mbwManager.getRecordManager().getWallet(mbwManager.getWalletMode());

    // Get spendable outputs
    SpendableOutputs spendable =
        wallet.getLocalSpendableOutputs(mbwManager.getBlockChainAddressTracker());

    // Extract private key ring
    PrivateKeyRing keyRing = wallet.getPrivateKeyRing();

    // Create unsigned transaction
    UnsignedTransaction unsigned =
        createUnsignedTransaction(
            ts.satoshisFromSeller,
            ts.satoshisForBuyer,
            ts.buyerAddress,
            ts.feeAddress,
            mbwManager,
            spendable,
            keyRing,
            mbwManager.getNetwork());

    if (unsigned == null) {
      return null;
    }

    // Make signatures
    List<byte[]> signatures =
        StandardTransactionBuilder.generateSignatures(
            unsigned.getSignatureInfo(), keyRing, mbwManager.getRecordManager().getRandomSource());

    // Sign transaction
    Transaction tx = StandardTransactionBuilder.finalizeTransaction(unsigned, signatures);
    return tx;
  }
  public static boolean canAffordTrade(TradeSession ts, MbwManager mbwManager) {
    // Create default wallet
    Wallet wallet = mbwManager.getRecordManager().getWallet(mbwManager.getWalletMode());

    // Get spendable outputs
    SpendableOutputs spendable =
        wallet.getLocalSpendableOutputs(mbwManager.getBlockChainAddressTracker());

    // Extract private key ring
    PrivateKeyRing keyRing = wallet.getPrivateKeyRing();

    Address nullAddress = Address.getNullAddress(mbwManager.getNetwork());

    return createUnsignedTransaction(
            ts.satoshisFromSeller,
            ts.satoshisForBuyer,
            nullAddress,
            nullAddress,
            mbwManager,
            spendable,
            keyRing,
            mbwManager.getNetwork())
        != null;
  }
  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));
      }
    }
  }
 public void setLocalTraderData(
     UUID accountId, InMemoryPrivateKey privateKey, Address address, String nickname) {
   _session = null;
   _localTraderAddress = Preconditions.checkNotNull(address);
   _localTraderAccountId = Preconditions.checkNotNull(accountId);
   _localTraderPrivateKey = Preconditions.checkNotNull(privateKey);
   _localTraderPrivateKeyString = privateKey.getBase58EncodedPrivateKey(_mbwManager.getNetwork());
   _nickname = Preconditions.checkNotNull(nickname);
   SharedPreferences.Editor editor = getEditor();
   editor.putString(Constants.LOCAL_TRADER_KEY_SETTING, _localTraderPrivateKeyString);
   editor.putString(Constants.LOCAL_TRADER_ACCOUNT_ID_SETTING, accountId.toString());
   editor.putString(Constants.LOCAL_TRADER_ADDRESS_SETTING, address.toString());
   editor.putString(Constants.LOCAL_TRADER_NICKNAME_SETTING, nickname);
   editor.commit();
 }
 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);
   }
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView =
        inflater.inflate(R.layout.ext_cashila_payments_fragment_pending, container, false);
    ButterKnife.inject(this, rootView);

    mbw = MbwManager.getInstance(this.getActivity());
    cs = ((CashilaPaymentsActivity) getActivity()).getCashilaService();
    eventBus = mbw.getEventBus();

    getBillPays(true);

    lvPending.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {}

          @Override
          public void onNothingSelected(AdapterView<?> adapterView) {}
        });

    return rootView;
  }
 // 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();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ViewPager viewPager = new ViewPager(this);
    viewPager.setId(R.id.pager);
    setContentView(viewPager);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayOptions(1, ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setDisplayHomeAsUpEnabled(true);

    TabsAdapter tabsAdapter = new TabsAdapter(this, viewPager, MbwManager.getInstance(this));

    buyBitcoinTab = actionBar.newTab();
    tabsAdapter.addTab(
        buyBitcoinTab.setText(getString(R.string.gd_buy_tab)), GlideraBuyFragment.class, null);

    Tab sellBitcoinTab = actionBar.newTab();
    tabsAdapter.addTab(
        sellBitcoinTab.setText(getString(R.string.gd_sell_tab)), GlideraSellFragment.class, null);

    Tab transactionHistoryTab = actionBar.newTab();
    tabsAdapter.addTab(
        transactionHistoryTab.setText(getString(R.string.gd_transaction_history_tab)),
        GlideraTransactionHistoryFragment.class,
        null);

    Bundle bundle = getIntent().getExtras();

    if (bundle != null) {
      String tab = getIntent().getExtras().getString("tab");

      if (tab.equals("buy")) {
        actionBar.selectTab(buyBitcoinTab);
      } else if (tab.equals("sell")) {
        actionBar.selectTab(sellBitcoinTab);
      } else if (tab.equals("history")) {
        actionBar.selectTab(transactionHistoryTab);
      } else {
        actionBar.selectTab(buyBitcoinTab);
      }
    } else {
      actionBar.selectTab(buyBitcoinTab);
    }
  }
  @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);
  }
 private String getBalanceString(long balance) {
   String balanceString = _mbwManager.getBtcValueString(balance);
   String balanceText = getResources().getString(R.string.max_btc, balanceString);
   return balanceText;
 }
 public Bitcoins getMinerFeeEstimation() {
   // choose a fee to get included within the next block
   return _mbwManager.getWalletManager(false).getLastFeeEstimations().getEstimation(1);
 }
  public LocalTraderManager(Context context, TradeSessionDb db, LtApi api, MbwManager mbwManager) {
    _notificationsEnabled = true;
    _context = context;
    _db = db;
    _api = api;
    _mbwManager = mbwManager;
    _subscribers = new HashSet<LocalTraderEventSubscriber>();
    _requests = new LinkedList<Request>();

    // Preferences
    SharedPreferences preferences =
        _context.getSharedPreferences(Constants.LOCAL_TRADER_SETTINGS_NAME, Activity.MODE_PRIVATE);

    // Nick name
    _nickname = preferences.getString(Constants.LOCAL_TRADER_NICKNAME_SETTING, null);

    // Address
    String addressString = preferences.getString(Constants.LOCAL_TRADER_ADDRESS_SETTING, null);
    if (addressString != null) {
      _localTraderAddress = Address.fromString(addressString, _mbwManager.getNetwork());
      // May be null
    }
    // Private key, may be null even if we have an address. This happens in the upgrade scenario
    // where it is set later
    _localTraderPrivateKeyString = preferences.getString(Constants.LOCAL_TRADER_KEY_SETTING, null);
    // Account ID, may be null even if we have an address. This happens in the upgrade scenario
    // where it is set later
    String localTraderAccountIdString =
        preferences.getString(Constants.LOCAL_TRADER_ACCOUNT_ID_SETTING, null); // May be null
    if (localTraderAccountIdString != null) {
      _localTraderAccountId = UUID.fromString(localTraderAccountIdString);
    }

    // Load location from preferences or use default
    _currentLocation =
        new GpsLocationEx(
            preferences.getFloat(
                Constants.LOCAL_TRADER_LATITUDE_SETTING,
                (float) Constants.LOCAL_TRADER_DEFAULT_LOCATION.latitude),
            preferences.getFloat(
                Constants.LOCAL_TRADER_LONGITUDE_SETTING,
                (float) Constants.LOCAL_TRADER_DEFAULT_LOCATION.longitude),
            preferences.getString(
                Constants.LOCAL_TRADER_LOCATION_NAME_SETTING,
                Constants.LOCAL_TRADER_DEFAULT_LOCATION.name),
            preferences.getString(
                Constants.LOCAL_TRADER_LOCATION_COUNTRY_CODE_SETTING,
                Constants.LOCAL_TRADER_DEFAULT_LOCATION.name));

    _isLocalTraderDisabled = preferences.getBoolean(Constants.LOCAL_TRADER_DISABLED_SETTING, false);
    _playSoundOnTradeNotification =
        preferences.getBoolean(
            Constants.LOCAL_TRADER_PLAY_SOUND_ON_TRADE_NOTIFICATION_SETTING, true);
    _useMiles = preferences.getBoolean(Constants.LOCAL_TRADER_USE_MILES_SETTING, false);
    _lastTraderSynchronization =
        preferences.getLong(Constants.LOCAL_TRADER_LAST_TRADER_SYNCHRONIZATION_SETTING, 0);
    _lastTraderNotification =
        preferences.getLong(Constants.LOCAL_TRADER_LAST_TRADER_NOTIFICATION_SETTING, 0);

    _executer = new Thread(new Executor());
    _executer.setDaemon(true);
    _executer.start();

    _traderChangeMonitor = new TraderChangeMonitor(this, _api);
    _tradeSessionChangeMonitor = new TradeSessionChangeMonitor(this, _api);

    _geocoder = new FallBackGeocoder(_mbwManager);
  }
 @Override
 public void onAttach(Activity activity) {
   _mbwManager = MbwManager.getInstance(getActivity().getApplication());
   _ltManager = _mbwManager.getLocalTraderManager();
   super.onAttach(activity);
 }