use of android.text.SpannableStringBuilder in project plaid by nickbutcher.
the class ImageSpanTarget method onResourceReady.
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
TextView tv = textView.get();
if (tv != null) {
BitmapDrawable bitmapDrawable = new BitmapDrawable(tv.getResources(), bitmap);
// image span doesn't handle scaling so we manually set bounds
if (bitmap.getWidth() > tv.getWidth()) {
float aspectRatio = (float) bitmap.getHeight() / (float) bitmap.getWidth();
bitmapDrawable.setBounds(0, 0, tv.getWidth(), (int) (aspectRatio * tv.getWidth()));
} else {
bitmapDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
}
ImageSpan span = new ImageSpan(bitmapDrawable);
// add the image span and remove our marker
SpannableStringBuilder ssb = new SpannableStringBuilder(tv.getText());
int start = ssb.getSpanStart(loadingSpan);
int end = ssb.getSpanEnd(loadingSpan);
if (start >= 0 && end >= 0) {
ssb.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
ssb.removeSpan(loadingSpan);
// animate the change
TransitionManager.beginDelayedTransition((ViewGroup) tv.getParent());
tv.setText(ssb);
}
}
use of android.text.SpannableStringBuilder in project KeepScore by nolanlawson.
the class AutofitTextView method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int height = getHeight() - getCompoundPaddingBottom() - getCompoundPaddingTop();
int maxNumLines = (height / getLineHeight());
if (maxNumLines >= 2) {
String oldText = getText().toString();
int cutoffIndex = StringUtil.getNthIndexOf('\n', oldText, maxNumLines);
if (cutoffIndex != -1) {
// cut off the text
int startOfLastLine = StringUtil.getNthIndexOf('\n', oldText, maxNumLines - 1);
// make the last line semi-transparent, to indicate that there
// are more results left
// (similar to the ellipsize effect in normal text views, but
// vertical)
// get the original color (blue or red)
ForegroundColorSpan[] foregroundColorSpans = ((SpannedString) getText()).getSpans(startOfLastLine + 1, cutoffIndex, ForegroundColorSpan.class);
// make an alpha-ized gradient out of the original color
int originalColor = foregroundColorSpans[0].getForegroundColor();
int startColor = (START_ALPHA << 24) | (0x00FFFFFF & originalColor);
int endColor = (END_ALPHA << 24) | (0x00FFFFFF & originalColor);
int numLines = StringUtil.count(getText().subSequence(0, cutoffIndex).toString(), "\n");
float startY = (numLines * getLineHeight());
float endY = startY + getLineHeight();
// build up a new spannable
SpannableStringBuilder builder = new SpannableStringBuilder().append(getText().subSequence(0, startOfLastLine)).append(getText().subSequence(startOfLastLine, cutoffIndex).toString());
builder.setSpan(new TopDownGradientSpan(startColor, endColor, startY, endY), startOfLastLine, cutoffIndex, 0);
setText(builder);
}
}
}
use of android.text.SpannableStringBuilder in project k-9 by k9mail.
the class NotificationContentCreator method buildMessageSummary.
private CharSequence buildMessageSummary(String sender, String subject) {
if (sender == null) {
return subject;
}
SpannableStringBuilder summary = new SpannableStringBuilder();
summary.append(sender);
summary.append(" ");
summary.append(subject);
summary.setSpan(getEmphasizedSpan(), 0, sender.length(), 0);
return summary;
}
use of android.text.SpannableStringBuilder in project k-9 by k9mail.
the class MessageHeader method populateAdditionalHeadersView.
/**
* Set up the additional headers text view with the supplied header data.
*
* @param additionalHeaders List of header entries. Each entry consists of a header
* name and a header value. Header names may appear multiple
* times.
* <p/>
* This method is always called from within the UI thread by
* {@link #showAdditionalHeaders()}.
*/
private void populateAdditionalHeadersView(final List<HeaderEntry> additionalHeaders) {
SpannableStringBuilder sb = new SpannableStringBuilder();
boolean first = true;
for (HeaderEntry additionalHeader : additionalHeaders) {
if (!first) {
sb.append("\n");
} else {
first = false;
}
StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
SpannableString label = new SpannableString(additionalHeader.label + ": ");
label.setSpan(boldSpan, 0, label.length(), 0);
sb.append(label);
sb.append(MimeUtility.unfoldAndDecode(additionalHeader.value));
}
mAdditionalHeadersView.setText(sb);
}
use of android.text.SpannableStringBuilder in project plaid by nickbutcher.
the class HomeActivity method setNoFiltersEmptyTextVisibility.
private void setNoFiltersEmptyTextVisibility(int visibility) {
if (visibility == View.VISIBLE) {
if (noFiltersEmptyText == null) {
// create the no filters empty text
ViewStub stub = (ViewStub) findViewById(R.id.stub_no_filters);
noFiltersEmptyText = (TextView) stub.inflate();
String emptyText = getString(R.string.no_filters_selected);
int filterPlaceholderStart = emptyText.indexOf('ࢴ');
int altMethodStart = filterPlaceholderStart + 3;
SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText);
// show an image of the filter icon
ssb.setSpan(new ImageSpan(this, R.drawable.ic_filter_small, ImageSpan.ALIGN_BASELINE), filterPlaceholderStart, filterPlaceholderStart + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// make the alt method (swipe from right) less prominent and italic
ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.text_secondary_light)), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(new StyleSpan(Typeface.ITALIC), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
noFiltersEmptyText.setText(ssb);
noFiltersEmptyText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawer.openDrawer(GravityCompat.END);
}
});
}
noFiltersEmptyText.setVisibility(visibility);
} else if (noFiltersEmptyText != null) {
noFiltersEmptyText.setVisibility(visibility);
}
}
Aggregations