Example usage for android.text SpannableStringBuilder SpannableStringBuilder

List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder

Introduction

In this page you can find the example usage for android.text SpannableStringBuilder SpannableStringBuilder.

Prototype

public SpannableStringBuilder(CharSequence text, int start, int end) 

Source Link

Document

Create a new SpannableStringBuilder containing a copy of the specified slice of the specified text, including its spans if any.

Usage

From source file:com.abcs.haiwaigou.yyg.view.ReadMoreTextView.java

private CharSequence updateCollapsedText() {
    int trimEndIndex = text.length();
    switch (trimMode) {
    case TRIM_MODE_LINES:
        trimEndIndex = lineEndIndex - (ELLIPSIZE.length() + trimCollapsedText.length() + 1);
        if (trimEndIndex < 0) {
            trimEndIndex = trimLength + 1;
        }//  w w w  .  j  a  v a 2s  .  c  o  m
        break;
    case TRIM_MODE_LENGTH:
        trimEndIndex = trimLength + 1;
        break;
    }
    SpannableStringBuilder s = new SpannableStringBuilder(text, 0, trimEndIndex).append(ELLIPSIZE)
            .append(trimCollapsedText);
    return addClickableSpan(s, trimCollapsedText);
}

From source file:com.borjabravo.readmoretextview.ReadMoreTextView.java

private CharSequence updateCollapsedText() {
    int trimEndIndex = text.length();
    switch (trimMode) {
    case TRIM_MODE_LINES:
        trimEndIndex = lineEndIndex - (ELLIPSIZE.length() + trimCollapsedText.length() + 1);
        break;//  w w  w  .  j ava2 s  . c o  m
    case TRIM_MODE_LENGTH:
        trimEndIndex = trimLength + 1;
        break;
    }
    SpannableStringBuilder s;
    if (trimEndIndex < 0) {
        s = new SpannableStringBuilder(text, 0, text.length() - 1);
    } else {
        s = new SpannableStringBuilder(text, 0, trimEndIndex).append(ELLIPSIZE).append(trimCollapsedText);
    }
    return addClickableSpan(s, trimCollapsedText);
}

From source file:com.abcs.haiwaigou.yyg.view.ReadMoreTextView.java

private CharSequence updateExpandedText() {
    if (showTrimExpandedText) {
        SpannableStringBuilder s = new SpannableStringBuilder(text, 0, text.length()).append(trimExpandedText);
        return addClickableSpan(s, trimExpandedText);
    }/* w  ww. j  a v a 2 s. co m*/
    return text;
}

From source file:io.realm.realmtasks.list.ItemViewHolder.java

public void setStrikeThroughRatio(float strikeThroughRatio) {
    final CharSequence text = this.text.getText();
    final int textLength = text.length();
    int firstLength = (int) (textLength * strikeThroughRatio);
    if (firstLength > textLength) {
        firstLength = textLength;//w  w  w.ja va 2  s .c  om
    } else if (firstLength == textLength - 1) {
        firstLength = textLength;
    }
    if (firstLength == previousFirstLength) {
        return;
    }
    previousFirstLength = firstLength;
    final int appendedLength = textLength - firstLength;
    final SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text, 0, textLength);
    stringBuilder.clearSpans();
    this.text.setPaintFlags(this.text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
    final CharacterStyle firstCharStyle, secondCharStyle;
    if (completed) {
        firstCharStyle = new ForegroundColorSpan(cellCompletedColor);
        secondCharStyle = new StrikethroughSpan();
    } else {
        firstCharStyle = new StrikethroughSpan();
        secondCharStyle = new ForegroundColorSpan(cellDefaultColor);
    }
    stringBuilder.setSpan(firstCharStyle, 0, firstLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    stringBuilder.setSpan(secondCharStyle, textLength - appendedLength, textLength,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    this.text.setText(stringBuilder);
}