@Override
  public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractBindServiceActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.wallet = application.getWallet();
    this.loaderManager = getLoaderManager();
    this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  }
  @Override
  public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractWalletActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.wallet = application.getWallet();
    this.contentUri = ExchangeRatesProvider.contentUri(activity.getPackageName(), false);
    this.loaderManager = getLoaderManager();
  }
  private void updateView() {
    balance = application.getWallet().getBalance(BalanceType.ESTIMATED);

    if (adapter != null) {
      final int btcShift = config.getBtcShift();

      final Coin base = btcShift == 0 ? Coin.COIN : Coin.MILLICOIN;

      adapter.setRateBase(base);
    }
  }
  @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;
  }