If you think the Android project bitfynd-wallet-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2013-2014 the original author or authors.
*/*www.java2s.com*/
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/package de.schildbach.wallet.ui;
import javax.annotation.Nonnull;
import org.bitcoinj.core.Monetary;
import org.bitcoinj.utils.MonetaryFormat;
import android.content.Context;
import android.graphics.Paint;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.util.AttributeSet;
import android.widget.TextView;
import de.schildbach.wallet.Constants;
import de.schildbach.wallet.util.MonetarySpannable;
import de.schildbach.wallet.R;
/**
* @author Andreas Schildbach
*/publicfinalclass CurrencyTextView extends TextView
{
private Monetary amount = null;
private MonetaryFormat format = null;
privateboolean alwaysSigned = false;
private RelativeSizeSpan prefixRelativeSizeSpan = null;
private ForegroundColorSpan prefixColorSpan = null;
private RelativeSizeSpan insignificantRelativeSizeSpan = null;
public CurrencyTextView(final Context context)
{
super(context);
}
public CurrencyTextView(final Context context, final AttributeSet attrs)
{
super(context, attrs);
}
publicvoid setAmount(@Nonnull final Monetary amount)
{
this.amount = amount;
updateView();
}
publicvoid setFormat(@Nonnull final MonetaryFormat format)
{
this.format = format.codeSeparator(Constants.CHAR_HAIR_SPACE);
updateView();
}
publicvoid setAlwaysSigned(finalboolean alwaysSigned)
{
this.alwaysSigned = alwaysSigned;
updateView();
}
publicvoid setStrikeThru(finalboolean strikeThru)
{
if (strikeThru)
setPaintFlags(getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
else
setPaintFlags(getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
publicvoid setInsignificantRelativeSize(finalfloat insignificantRelativeSize)
{
if (insignificantRelativeSize != 1)
{
this.prefixRelativeSizeSpan = new RelativeSizeSpan(insignificantRelativeSize);
this.insignificantRelativeSizeSpan = new RelativeSizeSpan(insignificantRelativeSize);
}
else
{
this.prefixRelativeSizeSpan = null;
this.insignificantRelativeSizeSpan = null;
}
}
publicvoid setPrefixColor(finalint prefixColor)
{
this.prefixColorSpan = new ForegroundColorSpan(prefixColor);
updateView();
}
@Override
protectedvoid onFinishInflate()
{
super.onFinishInflate();
setPrefixColor(getResources().getColor(R.color.balance_light));
setInsignificantRelativeSize(0.85f);
setSingleLine();
}
privatevoid updateView()
{
final MonetarySpannable text;
if (amount != null)
text = new MonetarySpannable(format, alwaysSigned, amount).applyMarkup(prefixRelativeSizeSpan, prefixColorSpan,
insignificantRelativeSizeSpan);
else
text = null;
setText(text);
}
}