当前位置: 首页>>代码示例>>Java>>正文


Java Fiat类代码示例

本文整理汇总了Java中org.bitcoinj.utils.Fiat的典型用法代码示例。如果您正苦于以下问题:Java Fiat类的具体用法?Java Fiat怎么用?Java Fiat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Fiat类属于org.bitcoinj.utils包,在下文中一共展示了Fiat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAmount

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
@Nullable
public Coin getAmount() {
    if (exchangeDirection) {
        return (Coin) btcAmountView.getAmount();
    } else if (exchangeRate != null) {
        final Fiat localAmount = (Fiat) localAmountView.getAmount();
        if (localAmount == null)
            return null;
        try {
            final Coin btcAmount = exchangeRate.fiatToCoin(localAmount);
            if (((Coin) btcAmount).isGreaterThan(Constants.NETWORK_PARAMETERS.getMaxMoney()))
                throw new ArithmeticException();
            return btcAmount;
        } catch (ArithmeticException x) {
            return null;
        }
    } else {
        return null;
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:21,代码来源:CurrencyCalculatorLink.java

示例2: coinFiatSpannable

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public static SpannableString coinFiatSpannable(Context context, Coin amountCoin, Fiat amountFiat, boolean primaryIsCoin, float secondaryRelativeSize) {
    String amountCoinStr = null, coinCode = null;
    if (amountCoin != null) {
        // For Coin: respect the BTC, mBTC, uBTC settings
        MonetaryFormat formatter = getMoneyFormat(context);
        amountCoinStr = formatter.noCode().format(amountCoin).toString();
        coinCode = formatter.code();
    }

    String amountFiatStr = null, fiatCode = null;
    if (amountFiat != null) {
        amountFiatStr = amountFiat.toPlainString();
        fiatCode = amountFiat.currencyCode;
    }

    if (primaryIsCoin) {
        return coinFiatSpannable(context, amountCoinStr, coinCode, amountFiatStr, fiatCode, secondaryRelativeSize);
    } else {
        return coinFiatSpannable(context, amountFiatStr, fiatCode, amountCoinStr, coinCode, secondaryRelativeSize);
    }
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:22,代码来源:UIUtils.java

示例3: getExchangeRate

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public static ExchangeRate getExchangeRate(Context context, String currencySymbol) {
    String key = context.getString(R.string.pref_exchange_rate, currencySymbol);
    long defaultValue = 0;
    if (!preferences(context).contains(key)) {
        String defaultResourceName = context.getString(R.string.pref_exchange_rate_default_key, currencySymbol);
        int defaultResourceId = context.getResources()
                .getIdentifier(defaultResourceName, "string", context.getPackageName());
        if (defaultResourceId != 0) {
            defaultValue = 10000 * Long.valueOf(context.getString(defaultResourceId));
        } else {
            defaultValue = 10000; // result: 1 coin = 1 amount of unknown currency
        }
    }
    long oneCoinInFiat = getLong(context, key, defaultValue);
    return new ExchangeRate(Fiat.valueOf(currencySymbol, oneCoinInFiat));
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:17,代码来源:SharedPrefUtils.java

示例4: coinConvert

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
private Coin coinConvert() {
    if(isBitcoinPrimary) {
        return Coin.valueOf(amountBTC);
    } else {
        //convert first
        String  currency = SharedPrefUtils.getCurrency(getActivity());
        Fiat fiat = Fiat.valueOf(currency, amountFiat);
        if(exchangeRate.fiat.currencyCode.equals(fiat.currencyCode)) {
            //exchange rate is set from the service, which may not have stared yet
            Coin retVal = exchangeRate.fiatToCoin(fiat);
            amountBTC = retVal.value;
            return retVal;
        }
        return Coin.ZERO;
    }
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:17,代码来源:KeyboardFragment.java

示例5: formatFiat

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public String formatFiat(Fiat fiat, MonetaryFormat format, boolean appendCurrencyCode) {
    if (fiat != null) {
        try {
            final String res = format.noCode().format(fiat).toString();
            if (appendCurrencyCode)
                return res + " " + fiat.getCurrencyCode();
            else
                return res;
        } catch (Throwable t) {
            log.warn("Exception at formatFiatWithCode: " + t.toString());
            return Res.get("shared.na") + " " + fiat.getCurrencyCode();
        }
    } else {
        return Res.get("shared.na");
    }
}
 
开发者ID:bisq-network,项目名称:exchange,代码行数:17,代码来源:BSFormatter.java

示例6: getCachedExchangeRate

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public ExchangeRate getCachedExchangeRate() {
    if (prefs.contains(PREFS_KEY_CACHED_EXCHANGE_CURRENCY) && prefs.contains(PREFS_KEY_CACHED_EXCHANGE_RATE_COIN)
            && prefs.contains(PREFS_KEY_CACHED_EXCHANGE_RATE_FIAT)) {
        final String cachedExchangeCurrency = prefs.getString(PREFS_KEY_CACHED_EXCHANGE_CURRENCY, null);
        final Coin cachedExchangeRateCoin = Coin.valueOf(prefs.getLong(PREFS_KEY_CACHED_EXCHANGE_RATE_COIN, 0));
        final Fiat cachedExchangeRateFiat = Fiat.valueOf(cachedExchangeCurrency,
                prefs.getLong(PREFS_KEY_CACHED_EXCHANGE_RATE_FIAT, 0));
        return new ExchangeRate(new org.bitcoinj.utils.ExchangeRate(cachedExchangeRateCoin, cachedExchangeRateFiat),
                null);
    } else {
        return null;
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:14,代码来源:Configuration.java

示例7: getExchangeRate

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public static ExchangeRate getExchangeRate(final Cursor cursor) {
    final String currencyCode = cursor
            .getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_CURRENCY_CODE));
    final Coin rateCoin = Coin
            .valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN)));
    final Fiat rateFiat = Fiat.valueOf(currencyCode,
            cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT)));
    final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE));

    return new ExchangeRate(new org.bitcoinj.utils.ExchangeRate(rateCoin, rateFiat), source);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:12,代码来源:ExchangeRatesProvider.java

示例8: amountFiat

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
private String amountFiat(TransactionWrapper transaction) {
    ExchangeRate rate = transaction.getTransaction().getExchangeRate();
    if (rate == null) {
        return null;
    }

    Fiat fiat = rate.coinToFiat(transaction.getAmount());
    return MonetaryFormat.FIAT
            .minDecimals(2)
            .repeatOptionalDecimals(0, 0)
            .code(0, fiat.currencyCode)
            .postfixCode()
            .format(fiat)
            .toString();
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:16,代码来源:TransactionWrapperRecyclerViewAdapter.java

示例9: getLargeBalance

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public static SpannableString getLargeBalance(Context context, Coin balanceCoin, Fiat balanceFiat) {
    SpannableString result;
    if (SharedPrefUtils.isBitcoinPrimaryBalance(context)) {
        String coinScale = SharedPrefUtils.getBitcoinScalePrefix(context);
        result = toLargeSpannable(context, scaleCoin(context, balanceCoin), coinScale);
    } else if (SharedPrefUtils.isFiatPrimaryBalance(context)) {
        result = toLargeSpannable(context, balanceFiat.toPlainString(), balanceFiat.getCurrencyCode());
    } else {
        Log.e(TAG, "Unknown setting for primary balance: " + SharedPrefUtils.getPrimaryBalance(context));
        result = new SpannableString("N/A");
    }
    return result;
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:14,代码来源:UIUtils.java

示例10: getSmallBalance

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public static SpannableString getSmallBalance(Context context, Coin balanceCoin, Fiat balanceFiat) {
    SpannableString result;
    if (SharedPrefUtils.isBitcoinPrimaryBalance(context)) {
        result = toSmallSpannable(balanceFiat.toPlainString(), balanceFiat.getCurrencyCode());
    } else if (SharedPrefUtils.isFiatPrimaryBalance(context)) {
        String btcSymbol = SharedPrefUtils.getBitcoinScalePrefix(context);
        result = toSmallSpannable(scaleCoin(context, balanceCoin), btcSymbol);
    } else {
        Log.e(TAG, "Unknown setting for primary balance: " + SharedPrefUtils.getPrimaryBalance(context));
        result = new SpannableString("N/A");
    }
    return result;
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:14,代码来源:UIUtils.java

示例11: toFriendlyAmountString

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public static SpannableString toFriendlyAmountString(Context context, TransactionWrapper transaction) {
    StringBuffer friendlyAmount = new StringBuffer();

    MonetaryFormat formatter = getMoneyFormat(context);
    String btcCode = formatter.code();
    String scaledAmount = formatter.noCode().format(transaction.getAmount()).toString();
    friendlyAmount.append(scaledAmount).append(" ");
    final int coinLength = friendlyAmount.length();

    friendlyAmount.append(btcCode).append(" ");
    final int codeLength = friendlyAmount.length();

    ExchangeRate exchangeRate = transaction.getTransaction().getExchangeRate();
    if (exchangeRate != null) {
        Fiat fiat = exchangeRate.coinToFiat(transaction.getAmount());
        friendlyAmount.append("~ " + fiat.toFriendlyString());
        friendlyAmount.append(System.getProperty("line.separator") + "(1 BTC = "
                + exchangeRate.fiat.toFriendlyString() + " as of now)");
    }
    final int amountLength = friendlyAmount.length();

    SpannableString friendlySpannable = new SpannableString(friendlyAmount);
    friendlySpannable.setSpan(new RelativeSizeSpan(2), 0, coinLength, 0);
    friendlySpannable.setSpan(
            new ForegroundColorSpan(context.getResources().getColor(R.color.colorAccent)),
            coinLength, codeLength, 0);
    friendlySpannable.setSpan(
            new ForegroundColorSpan(context.getResources().getColor(R.color.main_color_400)),
            codeLength, amountLength, 0);
    return friendlySpannable;

}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:33,代码来源:UIUtils.java

示例12: refreshBalance

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
private void refreshBalance() {
    if (walletService == null) {
        return;
    }
    //TODO: this may be called twice
    refreshConnectionIcons();
    final Coin coinBalance = walletService.getBalance();

    CompletableFuture<Coin> future = CompletableFuture.supplyAsync(new Supplier<Coin>() {
        @Override
        public Coin get() {
            try {
                Coin virtualBalance = walletService.virtualBalance();
                return coinBalance.add(virtualBalance);
            } catch (final Exception e) {
                Snackbar snackbar = Snackbar.make(getView(), e.getMessage(), Snackbar.LENGTH_LONG);
                snackbar.show();
                e.printStackTrace();
            }
            return Coin.ZERO;
        }
    });

    future.thenAccept(new Consumer<Coin>() {
        @Override
        public void accept(Coin coin) {
            Fiat fiatBalance = walletService.getExchangeRate().coinToFiat(coin);
            refreshBalance(coin, fiatBalance);
        }
    });







}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:39,代码来源:CurrentBalanceFragment.java

示例13: sendRequestExchangeRate

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
@Test
public void sendRequestExchangeRate() throws Exception {
    receiveATransaction(wallet, myAddress);
    SendRequest sendRequest = SendRequest.to(myAddress, Coin.COIN);
    sendRequest.exchangeRate = new ExchangeRate(Fiat.parseFiat("EUR", "500"));
    wallet.completeTx(sendRequest);
    assertEquals(sendRequest.exchangeRate, sendRequest.tx.getExchangeRate());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:9,代码来源:WalletTest.java

示例14: parse

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public static Price parse(String currencyCode, String inputValue) {
    final String cleaned = inputValue.replace(",", ".");
    if (CurrencyUtil.isFiatCurrency(currencyCode))
        return new Price(Fiat.parseFiat(currencyCode, cleaned));
    else
        return new Price(Altcoin.parseAltcoin(currencyCode, cleaned));
}
 
开发者ID:bisq-network,项目名称:exchange,代码行数:8,代码来源:Price.java

示例15: valueOf

import org.bitcoinj.utils.Fiat; //导入依赖的package包/类
public static Price valueOf(String currencyCode, long value) {
    if (CurrencyUtil.isFiatCurrency(currencyCode)) {
        return new Price(Fiat.valueOf(currencyCode, value));
    } else {
        return new Price(Altcoin.valueOf(currencyCode, value));
    }
}
 
开发者ID:bisq-network,项目名称:exchange,代码行数:8,代码来源:Price.java


注:本文中的org.bitcoinj.utils.Fiat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。