Example usage for android.text SpannableStringBuilder clearSpans

List of usage examples for android.text SpannableStringBuilder clearSpans

Introduction

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

Prototype

public void clearSpans() 

Source Link

Usage

From source file:com.yek.keyboard.ui.settings.AboutAnySoftKeyboardFragment.java

@Override
public void onViewStateRestored(Bundle savedInstanceState) {
    super.onViewStateRestored(savedInstanceState);
    TextView additionalSoftware = (TextView) getView().findViewById(R.id.about_legal_stuff_link);
    SpannableStringBuilder sb = new SpannableStringBuilder(additionalSoftware.getText());
    sb.clearSpans();//removing any previously (from instance-state) set click spans.
    sb.setSpan(new ClickableSpan() {
        @Override//from   w  w w  . jav a2 s  .  com
        public void onClick(View widget) {
            FragmentChauffeurActivity activity = (FragmentChauffeurActivity) getActivity();
            activity.addFragmentToUi(new AdditionalSoftwareLicensesFragment(),
                    TransitionExperiences.DEEPER_EXPERIENCE_TRANSITION);
        }
    }, 0, additionalSoftware.getText().length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    additionalSoftware.setMovementMethod(LinkMovementMethod.getInstance());
    additionalSoftware.setText(sb);
}

From source file:com.anysoftkeyboard.ui.settings.AboutAnySoftKeyboardFragment.java

@Override
public void onViewStateRestored(Bundle savedInstanceState) {
    super.onViewStateRestored(savedInstanceState);
    TextView additionalSoftware = (TextView) getView().findViewById(R.id.about_legal_stuff_link);
    SpannableStringBuilder sb = new SpannableStringBuilder(additionalSoftware.getText());
    sb.clearSpans();//removing any previously (from instance-state) set click spans.
    sb.setSpan(new ClickableSpan() {
        @Override/*from w  ww .  j a  v  a  2  s. co m*/
        public void onClick(View widget) {
            FragmentChauffeurActivity activity = (FragmentChauffeurActivity) getActivity();
            activity.addFragmentToUi(new AdditionalSoftwareLicensesFragment(),
                    FragmentChauffeurActivity.FragmentUiContext.DeeperExperience);
        }
    }, 0, additionalSoftware.getText().length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    additionalSoftware.setMovementMethod(LinkMovementMethod.getInstance());
    additionalSoftware.setText(sb);
}

From source file:com.example.activity.ProfileActivity.java

private void setPlayer() {
    ImageLoader.getInstance().displayImage(playerModel.player.avatar_url, head, BeeFrameworkApp.options_head);
    name.setText(playerModel.player.name);
    location.setText(playerModel.player.location);

    shots_count.setText(playerModel.player.shots_count + "");
    likes_count.setText(playerModel.player.likes_count + "");
    following_count.setText(playerModel.player.following_count + "");
    followers_count.setText(playerModel.player.followers_count + "");

    net.setText(playerModel.player.website_url);

    CharSequence text = net.getText();
    if (text instanceof Spannable) {
        int end = text.length();
        Spannable sp = (Spannable) net.getText();
        URLSpan[] spans = sp.getSpans(0, end, URLSpan.class);
        SpannableStringBuilder style = new SpannableStringBuilder(text);
        style.clearSpans();// should clear old spans
        for (URLSpan span : spans) {
            JayceSpan mySpan = new JayceSpan(span.getURL());
            style.setSpan(mySpan, sp.getSpanStart(span), sp.getSpanEnd(span),
                    Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        }//from   w  ww  .jav a 2s . c om
        net.setText(style);
    }
}

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;//from   w  w w  .  j  av  a  2s. com
    } 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);
}