Java 类org.bitcoinj.core.Monetary 实例源码

项目:okwallet    文件:CurrencyAmountView.java   
private boolean isValidAmount(final boolean zeroIsValid) {
    final String str = textView.getText().toString().trim();

    try {
        if (!str.isEmpty()) {
            final Monetary amount;
            if (localCurrencyCode == null) {
                amount = inputFormat.parse(str);
                if (((Coin) amount).isGreaterThan(Constants.NETWORK_PARAMETERS.getMaxMoney()))
                    return false;
            } else {
                amount = inputFormat.parseFiat(localCurrencyCode, str);
            }

            // exactly zero
            return zeroIsValid || amount.signum() > 0;
        }
    } catch (final Exception x) {
    }

    return false;
}
项目:ombuds-android    文件:CurrencyAmountView.java   
private boolean isValidAmount(final boolean zeroIsValid)
{
    final String str = textView.getText().toString().trim();

    try
    {
        if (!str.isEmpty())
        {
            final Monetary amount;
            if (localCurrencyCode == null)
                amount = inputFormat.parse(str);
            else
                amount = inputFormat.parseFiat(localCurrencyCode, str);

            // exactly zero
            return zeroIsValid || amount.signum() > 0;
        }
    }
    catch (final Exception x)
    {
    }

    return false;
}
项目:okwallet    文件:CurrencyAmountView.java   
@Nullable
public Monetary getAmount() {
    if (!isValidAmount(false))
        return null;

    final String amountStr = textView.getText().toString().trim();
    if (localCurrencyCode == null)
        return inputFormat.parse(amountStr);
    else
        return inputFormat.parseFiat(localCurrencyCode, amountStr);
}
项目:okwallet    文件:CurrencyAmountView.java   
public void setAmount(@Nullable final Monetary amount, final boolean fireListener) {
    if (!fireListener)
        textViewListener.setFire(false);

    if (amount != null)
        textView.setText(new MonetarySpannable(inputFormat, amountSigned, amount));
    else
        textView.setText(null);

    if (!fireListener)
        textViewListener.setFire(true);
}
项目:okwallet    文件:CurrencyAmountView.java   
@Override
protected void onRestoreInstanceState(final Parcelable state) {
    if (state instanceof Bundle) {
        final Bundle bundle = (Bundle) state;
        super.onRestoreInstanceState(bundle.getParcelable("super_state"));
        textView.onRestoreInstanceState(bundle.getParcelable("child_textview"));
        setAmount((Monetary) bundle.getSerializable("amount"), false);
    } else {
        super.onRestoreInstanceState(state);
    }
}
项目:okwallet    文件:CurrencyAmountView.java   
@Override
public void onFocusChange(final View v, final boolean hasFocus) {
    if (!hasFocus) {
        final Monetary amount = getAmount();
        if (amount != null)
            setAmount(amount, false);
    }

    if (listener != null && fire)
        listener.focusChanged(hasFocus);
}
项目:ombuds-android    文件:CurrencyAmountView.java   
@Nullable
public Monetary getAmount()
{
    if (!isValidAmount(false))
        return null;

    final String amountStr = textView.getText().toString().trim();
    if (localCurrencyCode == null)
        return inputFormat.parse(amountStr);
    else
        return inputFormat.parseFiat(localCurrencyCode, amountStr);
}
项目:ombuds-android    文件:CurrencyAmountView.java   
public void setAmount(@Nullable final Monetary amount, final boolean fireListener)
{
    if (!fireListener)
        textViewListener.setFire(false);

    if (amount != null)
        textView.setText(new MonetarySpannable(inputFormat, amountSigned, amount));
    else
        textView.setText(null);

    if (!fireListener)
        textViewListener.setFire(true);
}
项目:ombuds-android    文件:CurrencyAmountView.java   
@Override
protected void onRestoreInstanceState(final Parcelable state)
{
    if (state instanceof Bundle)
    {
        final Bundle bundle = (Bundle) state;
        super.onRestoreInstanceState(bundle.getParcelable("super_state"));
        textView.onRestoreInstanceState(bundle.getParcelable("child_textview"));
        setAmount((Monetary) bundle.getSerializable("amount"), false);
    }
    else
    {
        super.onRestoreInstanceState(state);
    }
}
项目:ombuds-android    文件:CurrencyAmountView.java   
@Override
public void onFocusChange(final View v, final boolean hasFocus)
{
    if (!hasFocus)
    {
        final Monetary amount = getAmount();
        if (amount != null)
            setAmount(amount, false);
    }

    if (listener != null && fire)
        listener.focusChanged(hasFocus);
}
项目:exchange    文件:MonetaryWrapper.java   
@Override
public boolean equals(final Object o) {
    if (o == this)
        return true;
    if (o == null || o.getClass() != getClass())
        return false;
    final Monetary otherMonetary = ((MonetaryWrapper) o).getMonetary();
    return monetary.getValue() == otherMonetary.getValue();
}
项目:exchange    文件:Price.java   
public Coin getAmountByVolume(Volume volume) {
    Monetary monetary = volume.getMonetary();
    if (monetary instanceof Fiat && this.monetary instanceof Fiat)
        return new ExchangeRate((Fiat) this.monetary).fiatToCoin((Fiat) monetary);
    else if (monetary instanceof Altcoin && this.monetary instanceof Altcoin)
        return new AltcoinExchangeRate((Altcoin) this.monetary).altcoinToCoin((Altcoin) monetary);
    else
        return Coin.ZERO;
}
项目:exchange    文件:BSFormatter.java   
public String formatVolume(Volume volume, MonetaryFormat fiatVolumeFormat, boolean appendCurrencyCode) {
    if (volume != null) {
        Monetary monetary = volume.getMonetary();
        if (monetary instanceof Fiat)
            return formatFiat((Fiat) monetary, fiatVolumeFormat, appendCurrencyCode);
        else
            return formatAltcoinVolume((Altcoin) monetary, appendCurrencyCode);
    } else {
        return "";
    }
}
项目:exchange    文件:BSFormatter.java   
public String formatPrice(Price price, MonetaryFormat fiatPriceFormat, boolean appendCurrencyCode) {
    if (price != null) {
        Monetary monetary = price.getMonetary();
        if (monetary instanceof Fiat)
            return formatFiat((Fiat) monetary, fiatPriceFormat, appendCurrencyCode);
        else
            return formatAltcoin((Altcoin) monetary, appendCurrencyCode);
    } else {
        return Res.get("shared.na");
    }
}
项目:exchange    文件:BSFormatter.java   
public String formatPriceWithCode(Price price) {
    Monetary monetary = price.getMonetary();
    if (monetary instanceof Fiat)
        return formatFiat((Fiat) monetary, fiatPriceFormat, true);
    else {
        return formatAltcoinWithCode((Altcoin) monetary);
    }
    //return formatPrice(fiat) + " " + getCurrencyPair(fiat.getCurrencyCode());
}
项目:okwallet    文件:CurrencyTextView.java   
public void setAmount(final Monetary amount) {
    this.amount = amount;
    updateView();
}
项目:okwallet    文件:CurrencyAmountView.java   
public void setHint(@Nullable final Monetary hint) {
    this.hint = hint;
    updateAppearance();
}
项目:okwallet    文件:MonetarySpannable.java   
public MonetarySpannable(final MonetaryFormat format, final boolean signed, @Nullable final Monetary monetary) {
    super(format(format, signed, monetary));
}
项目:okwallet    文件:MonetarySpannable.java   
public MonetarySpannable(final MonetaryFormat format, @Nullable final Monetary monetary) {
    super(format(format, false, monetary));
}
项目:lbry-android    文件:MonetarySpannable.java   
public MonetarySpannable(final MonetaryFormat format, final boolean signed, @Nullable final Monetary value) {
    super(format(format, signed, value));
}
项目:lbry-android    文件:MonetarySpannable.java   
public MonetarySpannable(final MonetaryFormat format, @Nullable final Monetary value) {
    super(format(format, false, value));
}
项目:lbry-android    文件:MonetaryFormat.java   
/**
 * Format the given monetary value to a human readable form.
 */
public CharSequence format(Monetary monetary) {
    return format(monetary, monetary.smallestUnitExponent());
}
项目:lbry-android    文件:GenericUtils.java   
public static String formatCoinValue(@Nonnull final ValueType type, @Nonnull final Monetary value) {
    return formatCoinValue(type, value, "", "-", 8, 0);
}
项目:lbry-android    文件:GenericUtils.java   
public static String formatCoinValue(@Nonnull final ValueType type, @Nonnull final Monetary value,
                                     final int precision, final int shift) {
    return formatCoinValue(type, value, "", "-", precision, shift);
}
项目:lbry-android    文件:GenericUtils.java   
public static String formatCoinValue(@Nonnull final ValueType type, @Nonnull final Monetary value,
                                     @Nonnull final String plusSign, @Nonnull final String minusSign,
                                     final int precision, final int shift) {
    return formatValue(type.getUnitExponent(), value, plusSign, minusSign, precision, shift, false);
}
项目:lbry-android    文件:GenericUtils.java   
public static String formatCoinValue(@Nonnull final ValueType type, @Nonnull final Monetary value,
                                     boolean removeFinalZeroes) {
    return formatValue(type.getUnitExponent(), value, "", "-", 8, 0, removeFinalZeroes);
}
项目:lbry-android    文件:GenericUtils.java   
private static String formatValue(final long unitExponent, @Nonnull final Monetary value,
                                  @Nonnull final String plusSign, @Nonnull final String minusSign,
                                  final int precision, final int shift, boolean removeFinalZeroes) {
    long longValue = value.getValue();

    final String sign = value.signum() == -1 ? minusSign : plusSign;

    String formatedValue;

    if (shift == 0) {
        long units = Math.round(Math.pow(10, unitExponent));
        long precisionUnits = (long) (units / Math.pow(10, precision));
        long roundingPrecisionUnits = precisionUnits / 2;

        if (precision == 2 || precision == 4 || precision == 6 || precision == 8) {
            if (roundingPrecisionUnits > 0) {
                longValue = longValue - longValue % precisionUnits + longValue % precisionUnits / roundingPrecisionUnits * precisionUnits;
            }
        } else {
            throw new IllegalArgumentException("cannot handle precision/shift: " + precision + "/" + shift);
        }

        final long absValue = Math.abs(longValue);
        final long coins = absValue / units;
        final int satoshis = (int) (absValue % units);

        if (isShiftPossible(units, satoshis, 100)) {
            formatedValue = String.format(Locale.US, "%d.%02d",
                    coins, getShiftedCents(units, satoshis, 100));

        } else if (isShiftPossible(units, satoshis, 10000)) {
            formatedValue = String.format(Locale.US, "%d.%04d",
                    coins, getShiftedCents(units, satoshis, 10000));

        } else if (isShiftPossible(units, satoshis, 1000000)) {
            formatedValue = String.format(Locale.US, "%d.%06d", coins,
                    getShiftedCents(units, satoshis, 1000000));

        } else {
            formatedValue = String.format(Locale.US, "%d.%08d", coins, satoshis);
        }

    } else {
        throw new IllegalArgumentException("cannot handle shift: " + shift);
    }

    // Relax precision if incorrectly shows value as 0.00 but is in reality not zero
    if (formatedValue.equals("0.00") && value.getValue() != 0) {
        return formatValue(unitExponent, value, plusSign, minusSign, precision + 2, shift, removeFinalZeroes);
    }

    // Remove final zeroes if requested
    while (removeFinalZeroes && formatedValue.length() > 0 &&
            formatedValue.contains(".") && formatedValue.endsWith("0")) {
        formatedValue = formatedValue.substring(0, formatedValue.length() - 1);
    }
    if (removeFinalZeroes && formatedValue.length() > 0 && formatedValue.endsWith(".")) {
        formatedValue = formatedValue.substring(0, formatedValue.length() - 1);
    }

    // Add the sign if needed
    formatedValue = String.format(Locale.US, "%s%s", sign, formatedValue);

    return formatedValue;
}
项目:ombuds-android    文件:CurrencyTextView.java   
public void setAmount(final Monetary amount)
{
    this.amount = amount;
    updateView();
}
项目:ombuds-android    文件:CurrencyAmountView.java   
public void setHint(@Nullable final Monetary hint)
{
    this.hint = hint;
    updateAppearance();
}
项目:ombuds-android    文件:MonetarySpannable.java   
public MonetarySpannable(final MonetaryFormat format, final boolean signed, @Nullable final Monetary monetary)
{
    super(format(format, signed, monetary));
}
项目:ombuds-android    文件:MonetarySpannable.java   
public MonetarySpannable(final MonetaryFormat format, @Nullable final Monetary monetary)
{
    super(format(format, false, monetary));
}
项目:exchange    文件:MonetaryWrapper.java   
public MonetaryWrapper(Monetary monetary) {
    this.monetary = monetary;
}
项目:exchange    文件:MonetaryWrapper.java   
public Monetary getMonetary() {
    return monetary;
}
项目:exchange    文件:Price.java   
public Price(Monetary monetary) {
    super(monetary);
}
项目:exchange    文件:Volume.java   
public Volume(Monetary monetary) {
    super(monetary);
}