Search in sources :

Example 1 with MonetarySpannable

use of de.schildbach.wallet.util.MonetarySpannable in project bitcoin-wallet by bitcoin-wallet.

the class SweepWalletFragment method updateView.

private void updateView() {
    final MonetaryFormat btcFormat = config.getFormat();
    if (walletToSweep != null) {
        balanceView.setVisibility(View.VISIBLE);
        final MonetarySpannable balanceSpannable = new MonetarySpannable(btcFormat, walletToSweep.getBalance(BalanceType.ESTIMATED));
        balanceSpannable.applyMarkup(null, null);
        final SpannableStringBuilder balance = new SpannableStringBuilder(balanceSpannable);
        balance.insert(0, ": ");
        balance.insert(0, getString(R.string.sweep_wallet_fragment_balance));
        balanceView.setText(balance);
    } else {
        balanceView.setVisibility(View.GONE);
    }
    if (state == State.DECODE_KEY && privateKeyToSweep == null) {
        messageView.setVisibility(View.VISIBLE);
        messageView.setText(R.string.sweep_wallet_fragment_wallet_unknown);
    } else if (state == State.DECODE_KEY && privateKeyToSweep != null) {
        messageView.setVisibility(View.VISIBLE);
        messageView.setText(R.string.sweep_wallet_fragment_encrypted);
    } else if (privateKeyToSweep != null) {
        messageView.setVisibility(View.GONE);
    }
    passwordViewGroup.setVisibility(state == State.DECODE_KEY && privateKeyToSweep != null ? View.VISIBLE : View.GONE);
    hintView.setVisibility(state == State.DECODE_KEY && privateKeyToSweep == null ? View.VISIBLE : View.GONE);
    if (sentTransaction != null) {
        sweepTransactionView.setVisibility(View.VISIBLE);
        sweepTransactionAdapter.setFormat(btcFormat);
        sweepTransactionAdapter.replace(sentTransaction);
        sweepTransactionAdapter.bindViewHolder(sweepTransactionViewHolder, 0);
    } else {
        sweepTransactionView.setVisibility(View.GONE);
    }
    if (state == State.DECODE_KEY) {
        viewCancel.setText(R.string.button_cancel);
        viewGo.setText(R.string.sweep_wallet_fragment_button_decrypt);
        viewGo.setEnabled(privateKeyToSweep != null);
    } else if (state == State.CONFIRM_SWEEP) {
        viewCancel.setText(R.string.button_cancel);
        viewGo.setText(R.string.sweep_wallet_fragment_button_sweep);
        viewGo.setEnabled(walletToSweep != null && walletToSweep.getBalance(BalanceType.ESTIMATED).signum() > 0 && fees != null);
    } else if (state == State.PREPARATION) {
        viewCancel.setText(R.string.button_cancel);
        viewGo.setText(R.string.send_coins_preparation_msg);
        viewGo.setEnabled(false);
    } else if (state == State.SENDING) {
        viewCancel.setText(R.string.send_coins_fragment_button_back);
        viewGo.setText(R.string.send_coins_sending_msg);
        viewGo.setEnabled(false);
    } else if (state == State.SENT) {
        viewCancel.setText(R.string.send_coins_fragment_button_back);
        viewGo.setText(R.string.send_coins_sent_msg);
        viewGo.setEnabled(false);
    } else if (state == State.FAILED) {
        viewCancel.setText(R.string.send_coins_fragment_button_back);
        viewGo.setText(R.string.send_coins_failed_msg);
        viewGo.setEnabled(false);
    }
    viewCancel.setEnabled(state != State.PREPARATION);
    // enable actions
    if (reloadAction != null)
        reloadAction.setEnabled(state == State.CONFIRM_SWEEP && walletToSweep != null);
    if (scanAction != null)
        scanAction.setEnabled(state == State.DECODE_KEY || state == State.CONFIRM_SWEEP);
}
Also used : MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 2 with MonetarySpannable

use of de.schildbach.wallet.util.MonetarySpannable in project bitcoin-wallet by bitcoin-wallet.

the class CurrencyAmountView method updateAppearance.

private void updateAppearance() {
    final boolean enabled = textView.isEnabled();
    contextButton.setEnabled(enabled);
    final String amount = textView.getText().toString().trim();
    if (enabled && !amount.isEmpty()) {
        textView.setCompoundDrawablesWithIntrinsicBounds(currencySymbolDrawable, null, deleteButtonDrawable, null);
        contextButton.setOnClickListener(deleteClickListener);
    } else if (enabled && contextButtonDrawable != null) {
        textView.setCompoundDrawablesWithIntrinsicBounds(currencySymbolDrawable, null, contextButtonDrawable, null);
        contextButton.setOnClickListener(contextButtonClickListener);
    } else {
        textView.setCompoundDrawablesWithIntrinsicBounds(currencySymbolDrawable, null, null, null);
        contextButton.setOnClickListener(null);
    }
    contextButton.requestLayout();
    textView.setTextColor(!validateAmount || isValidAmount(true) ? significantColor : errorColor);
    final Spannable hintSpannable = new MonetarySpannable(hintFormat, hint != null ? hint : Coin.ZERO).applyMarkup(null, MonetarySpannable.STANDARD_INSIGNIFICANT_SPANS);
    textView.setHint(hintSpannable);
}
Also used : MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) Spannable(android.text.Spannable)

Example 3 with MonetarySpannable

use of de.schildbach.wallet.util.MonetarySpannable in project bitcoin-wallet by bitcoin-wallet.

the class CurrencyTextView method updateView.

private void updateView() {
    final MonetarySpannable text;
    if (amount != null)
        text = new MonetarySpannable(format, alwaysSigned, amount).applyMarkup(new Object[] { prefixRelativeSizeSpan, prefixScaleXSpan, prefixColorSpan }, new Object[] { insignificantRelativeSizeSpan });
    else
        text = null;
    setText(text);
}
Also used : MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable)

Example 4 with MonetarySpannable

use of de.schildbach.wallet.util.MonetarySpannable in project bitcoin-wallet by bitcoin-wallet.

the class WalletBalanceWidgetProvider method updateWidget.

private static void updateWidget(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId, final Bundle appWidgetOptions, final Coin balance) {
    final WalletApplication application = (WalletApplication) context.getApplicationContext();
    final Configuration config = application.getConfiguration();
    final MonetaryFormat btcFormat = config.getFormat();
    final Spannable balanceStr = new MonetarySpannable(btcFormat.noCode(), balance).applyMarkup(null, MonetarySpannable.STANDARD_INSIGNIFICANT_SPANS);
    final Cursor data = context.getContentResolver().query(ExchangeRatesProvider.contentUri(context.getPackageName(), true), null, ExchangeRatesProvider.KEY_CURRENCY_CODE, new String[] { config.getExchangeCurrencyCode() }, null);
    final Spannable localBalanceStr;
    if (data != null) {
        if (data.moveToFirst()) {
            final ExchangeRate exchangeRate = ExchangeRatesProvider.getExchangeRate(data);
            final Fiat localBalance = exchangeRate.rate.coinToFiat(balance);
            final MonetaryFormat localFormat = Constants.LOCAL_FORMAT.code(0, Constants.PREFIX_ALMOST_EQUAL_TO + GenericUtils.currencySymbol(exchangeRate.getCurrencyCode()));
            final Object[] prefixSpans = new Object[] { MonetarySpannable.SMALLER_SPAN, new ForegroundColorSpan(context.getResources().getColor(R.color.fg_less_significant)) };
            localBalanceStr = new MonetarySpannable(localFormat, localBalance).applyMarkup(prefixSpans, MonetarySpannable.STANDARD_INSIGNIFICANT_SPANS);
        } else {
            localBalanceStr = null;
        }
        data.close();
    } else {
        localBalanceStr = null;
    }
    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.wallet_balance_widget_content);
    final String currencyCode = btcFormat.code();
    if (MonetaryFormat.CODE_BTC.equals(currencyCode))
        views.setImageViewResource(R.id.widget_wallet_prefix, R.drawable.currency_symbol_btc);
    else if (MonetaryFormat.CODE_MBTC.equals(currencyCode))
        views.setImageViewResource(R.id.widget_wallet_prefix, R.drawable.currency_symbol_mbtc);
    else if (MonetaryFormat.CODE_UBTC.equals(currencyCode))
        views.setImageViewResource(R.id.widget_wallet_prefix, R.drawable.currency_symbol_ubtc);
    views.setTextViewText(R.id.widget_wallet_balance_btc, balanceStr);
    views.setViewVisibility(R.id.widget_wallet_balance_local, localBalanceStr != null ? View.VISIBLE : View.GONE);
    views.setTextViewText(R.id.widget_wallet_balance_local, localBalanceStr);
    if (appWidgetOptions != null) {
        final int minWidth = appWidgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
        views.setViewVisibility(R.id.widget_app_icon, minWidth > 400 ? View.VISIBLE : View.GONE);
        views.setViewVisibility(R.id.widget_button_request, minWidth > 300 ? View.VISIBLE : View.GONE);
        views.setViewVisibility(R.id.widget_button_send, minWidth > 300 ? View.VISIBLE : View.GONE);
        views.setViewVisibility(R.id.widget_button_send_qr, minWidth > 200 ? View.VISIBLE : View.GONE);
    }
    views.setOnClickPendingIntent(R.id.widget_button_balance, PendingIntent.getActivity(context, 0, new Intent(context, WalletActivity.class), 0));
    views.setOnClickPendingIntent(R.id.widget_button_request, PendingIntent.getActivity(context, 0, new Intent(context, RequestCoinsActivity.class), 0));
    views.setOnClickPendingIntent(R.id.widget_button_send, PendingIntent.getActivity(context, 0, new Intent(context, SendCoinsActivity.class), 0));
    views.setOnClickPendingIntent(R.id.widget_button_send_qr, PendingIntent.getActivity(context, 0, new Intent(context, SendCoinsQrActivity.class), 0));
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
Also used : ExchangeRate(de.schildbach.wallet.data.ExchangeRate) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Cursor(android.database.Cursor) MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) RemoteViews(android.widget.RemoteViews) Fiat(org.bitcoinj.utils.Fiat) MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) Spannable(android.text.Spannable)

Aggregations

MonetarySpannable (de.schildbach.wallet.util.MonetarySpannable)4 Spannable (android.text.Spannable)2 MonetaryFormat (org.bitcoinj.utils.MonetaryFormat)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 RemoteViews (android.widget.RemoteViews)1 ExchangeRate (de.schildbach.wallet.data.ExchangeRate)1 Fiat (org.bitcoinj.utils.Fiat)1