示例#1
0
  private void writeKeys(@Nonnull final OutputStream os) throws IOException {
    final List<ECKey> keys = new LinkedList<ECKey>();
    for (final ECKey key : wallet.getKeys()) if (!wallet.isKeyRotating(key)) keys.add(key);

    final Writer out = new OutputStreamWriter(os, Constants.UTF_8);
    WalletUtils.writeKeys(out, keys);
    out.close();
  }
示例#2
0
  public Address determineSelectedAddress() {
    final String selectedAddress = prefs.getString(Constants.PREFS_KEY_SELECTED_ADDRESS, null);

    Address firstAddress = null;
    for (final ECKey key : wallet.getKeys()) {
      if (!wallet.isKeyRotating(key)) {
        final Address address = key.toAddress(Constants.NETWORK_PARAMETERS);

        if (address.toString().equals(selectedAddress)) return address;

        if (firstAddress == null) firstAddress = address;
      }
    }

    return firstAddress;
  }
  @Override
  public View onCreateView(
      final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.request_coins_fragment, container, false);

    qrView = (ImageView) view.findViewById(R.id.request_coins_qr);
    qrView.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(final View v) {
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
          }
        });

    final CurrencyAmountView btcAmountView =
        (CurrencyAmountView) view.findViewById(R.id.request_coins_amount_btc);
    btcAmountView.setCurrencySymbol(config.getBtcPrefix());
    btcAmountView.setInputPrecision(config.getBtcMaxPrecision());
    btcAmountView.setHintPrecision(config.getBtcPrecision());
    btcAmountView.setShift(config.getBtcShift());

    final CurrencyAmountView localAmountView =
        (CurrencyAmountView) view.findViewById(R.id.request_coins_amount_local);
    localAmountView.setInputPrecision(Constants.LOCAL_PRECISION);
    localAmountView.setHintPrecision(Constants.LOCAL_PRECISION);
    amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView);

    addressView = (Spinner) view.findViewById(R.id.request_coins_fragment_address);
    final List<ECKey> keys = new LinkedList<ECKey>();
    for (final ECKey key : application.getWallet().getKeys())
      if (!wallet.isKeyRotating(key)) keys.add(key);
    final WalletAddressesAdapter adapter = new WalletAddressesAdapter(activity, wallet, false);
    adapter.replace(keys);
    addressView.setAdapter(adapter);
    final Address selectedAddress = application.determineSelectedAddress();
    for (int i = 0; i < keys.size(); i++) {
      final Address address = keys.get(i).toAddress(Constants.NETWORK_PARAMETERS);
      if (address.equals(selectedAddress)) {
        addressView.setSelection(i);
        break;
      }
    }

    acceptBluetoothPaymentView =
        (CheckBox) view.findViewById(R.id.request_coins_accept_bluetooth_payment);
    acceptBluetoothPaymentView.setVisibility(
        ENABLE_BLUETOOTH_LISTENING && bluetoothAdapter != null ? View.VISIBLE : View.GONE);
    acceptBluetoothPaymentView.setChecked(
        ENABLE_BLUETOOTH_LISTENING && bluetoothAdapter != null && bluetoothAdapter.isEnabled());
    acceptBluetoothPaymentView.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (ENABLE_BLUETOOTH_LISTENING && bluetoothAdapter != null && isChecked) {
              if (bluetoothAdapter.isEnabled()) {
                startBluetoothListening();
              } else {
                // ask for permission to enable bluetooth
                startActivityForResult(
                    new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                    REQUEST_CODE_ENABLE_BLUETOOTH);
              }
            } else {
              stopBluetoothListening();
            }

            updateView();
          }
        });

    initiateRequestView =
        (TextView) view.findViewById(R.id.request_coins_fragment_initiate_request);

    return view;
  }
示例#4
0
  private void ensureKey() {
    for (final ECKey key : wallet.getKeys()) if (!wallet.isKeyRotating(key)) return; // found

    log.info("wallet has no usable key - creating");
    addNewKeyToWallet();
  }