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;
  }
  @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);
  }