use of android.text.style.StrikethroughSpan in project Android-Rich-text-Editor by chinalwb.
the class AREditText method onSelectionChanged.
/*
* ----------------------------------------- * Rich Text Style Area
* -----------------------------------------
*/
@Override
public void onSelectionChanged(int selStart, int selEnd) {
if (sToolbar == null) {
return;
}
Util.log(" on Selection changed == " + this);
boolean boldExists = false;
boolean italicsExists = false;
boolean underlinedExists = false;
boolean striketrhoughExists = false;
boolean backgroundColorExists = false;
boolean quoteExists = false;
//
// Two cases:
// 1. Selection is just a pure cursor
// 2. Selection is a range
Editable editable = this.getEditableText();
if (selStart > 0 && selStart == selEnd) {
CharacterStyle[] styleSpans = editable.getSpans(selStart - 1, selStart, CharacterStyle.class);
for (int i = 0; i < styleSpans.length; i++) {
if (styleSpans[i] instanceof StyleSpan) {
if (((StyleSpan) styleSpans[i]).getStyle() == android.graphics.Typeface.BOLD) {
boldExists = true;
} else if (((StyleSpan) styleSpans[i]).getStyle() == android.graphics.Typeface.ITALIC) {
italicsExists = true;
} else if (((StyleSpan) styleSpans[i]).getStyle() == android.graphics.Typeface.BOLD_ITALIC) {
// TODO
}
} else if (styleSpans[i] instanceof AreUnderlineSpan) {
underlinedExists = true;
} else if (styleSpans[i] instanceof StrikethroughSpan) {
striketrhoughExists = true;
} else if (styleSpans[i] instanceof BackgroundColorSpan) {
backgroundColorExists = true;
}
}
QuoteSpan[] quoteSpans = editable.getSpans(selStart - 1, selStart, QuoteSpan.class);
if (quoteSpans != null && quoteSpans.length > 0) {
quoteExists = true;
}
// To check Quote!!
} else {
//
// Selection is a range
CharacterStyle[] styleSpans = editable.getSpans(selStart, selEnd, CharacterStyle.class);
for (int i = 0; i < styleSpans.length; i++) {
if (styleSpans[i] instanceof StyleSpan) {
if (((StyleSpan) styleSpans[i]).getStyle() == android.graphics.Typeface.BOLD) {
if (editable.getSpanStart(styleSpans[i]) <= selStart && editable.getSpanEnd(styleSpans[i]) >= selEnd) {
boldExists = true;
}
} else if (((StyleSpan) styleSpans[i]).getStyle() == android.graphics.Typeface.ITALIC) {
if (editable.getSpanStart(styleSpans[i]) <= selStart && editable.getSpanEnd(styleSpans[i]) >= selEnd) {
italicsExists = true;
}
} else if (((StyleSpan) styleSpans[i]).getStyle() == android.graphics.Typeface.BOLD_ITALIC) {
if (editable.getSpanStart(styleSpans[i]) <= selStart && editable.getSpanEnd(styleSpans[i]) >= selEnd) {
italicsExists = true;
boldExists = true;
}
}
} else if (styleSpans[i] instanceof AreUnderlineSpan) {
if (editable.getSpanStart(styleSpans[i]) <= selStart && editable.getSpanEnd(styleSpans[i]) >= selEnd) {
underlinedExists = true;
}
} else if (styleSpans[i] instanceof StrikethroughSpan) {
if (editable.getSpanStart(styleSpans[i]) <= selStart && editable.getSpanEnd(styleSpans[i]) >= selEnd) {
striketrhoughExists = true;
}
} else if (styleSpans[i] instanceof BackgroundColorSpan) {
if (editable.getSpanStart(styleSpans[i]) <= selStart && editable.getSpanEnd(styleSpans[i]) >= selEnd) {
backgroundColorExists = true;
}
}
}
}
QuoteSpan[] quoteSpans = editable.getSpans(selStart, selEnd, QuoteSpan.class);
if (quoteSpans != null && quoteSpans.length > 0) {
if (editable.getSpanStart(quoteSpans[0]) <= selStart && editable.getSpanEnd(quoteSpans[0]) >= selEnd) {
quoteExists = true;
}
}
//
// Set style checked status
ARE_Helper.updateCheckStatus(sToolbar.getBoldStyle(), boldExists);
ARE_Helper.updateCheckStatus(sToolbar.getItalicStyle(), italicsExists);
ARE_Helper.updateCheckStatus(sToolbar.getUnderlineStyle(), underlinedExists);
ARE_Helper.updateCheckStatus(sToolbar.getStrikethroughStyle(), striketrhoughExists);
ARE_Helper.updateCheckStatus(sToolbar.getBackgroundColoStyle(), backgroundColorExists);
ARE_Helper.updateCheckStatus(sToolbar.getQuoteStyle(), quoteExists);
}
use of android.text.style.StrikethroughSpan in project ExoPlayer by google.
the class CueSerializationTest method serializingBitmapCueAndCueWithAndroidSpans.
@Test
public void serializingBitmapCueAndCueWithAndroidSpans() {
CueEncoder encoder = new CueEncoder();
CueDecoder decoder = new CueDecoder();
Spannable spannable = SpannableString.valueOf("text text");
spannable.setSpan(new StrikethroughSpan(), 0, "text".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, "text text".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new StyleSpan(Typeface.ITALIC), 0, "text text".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new UnderlineSpan(), "text ".length(), "text text".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Cue textCue = new Cue.Builder().setText(spannable).build();
Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
Cue bitmapCue = new Cue.Builder().setBitmap(bitmap).build();
// encoding and decoding
byte[] encodedCues = encoder.encode(ImmutableList.of(textCue, bitmapCue));
List<Cue> cuesAfterDecoding = decoder.decode(encodedCues);
assertThat(cuesAfterDecoding).hasSize(2);
Cue textCueAfterDecoding = cuesAfterDecoding.get(0);
Cue bitmapCueAfterDecoding = cuesAfterDecoding.get(1);
assertThat(textCueAfterDecoding.text.toString()).isEqualTo(textCue.text.toString());
SpannedSubject.assertThat((Spanned) textCueAfterDecoding.text).hasStrikethroughSpanBetween(0, "text".length());
SpannedSubject.assertThat((Spanned) textCueAfterDecoding.text).hasBoldSpanBetween(0, "text text".length());
SpannedSubject.assertThat((Spanned) textCueAfterDecoding.text).hasItalicSpanBetween(0, "text text".length());
SpannedSubject.assertThat((Spanned) textCueAfterDecoding.text).hasUnderlineSpanBetween("text ".length(), "text text".length());
assertThat(bitmapCueAfterDecoding.bitmap.sameAs(bitmap)).isTrue();
}
use of android.text.style.StrikethroughSpan in project ExoPlayer by google.
the class UtilTest method truncateAscii_preservesStylingSpans.
@Test
public void truncateAscii_preservesStylingSpans() {
SpannableString input = new SpannableString("a short string");
input.setSpan(new UnderlineSpan(), 0, 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
input.setSpan(new StrikethroughSpan(), 4, 10, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
CharSequence result = Util.truncateAscii(input, 7);
assertThat(result).isInstanceOf(SpannableString.class);
assertThat(result.toString()).isEqualTo("a short");
// TODO(internal b/161804035): Use SpannedSubject when it's available in a dependency we can use
// from here.
Spanned spannedResult = (Spanned) result;
Object[] spans = spannedResult.getSpans(0, result.length(), Object.class);
assertThat(spans).hasLength(2);
assertThat(spans[0]).isInstanceOf(UnderlineSpan.class);
assertThat(spannedResult.getSpanStart(spans[0])).isEqualTo(0);
assertThat(spannedResult.getSpanEnd(spans[0])).isEqualTo(7);
assertThat(spannedResult.getSpanFlags(spans[0])).isEqualTo(Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
assertThat(spans[1]).isInstanceOf(StrikethroughSpan.class);
assertThat(spannedResult.getSpanStart(spans[1])).isEqualTo(4);
assertThat(spannedResult.getSpanEnd(spans[1])).isEqualTo(7);
assertThat(spannedResult.getSpanFlags(spans[1])).isEqualTo(Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
use of android.text.style.StrikethroughSpan in project ExoPlayer by google.
the class SpannedSubjectTest method strikethroughSpan_success.
@Test
public void strikethroughSpan_success() {
SpannableString spannable = createSpannable(new StrikethroughSpan(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
assertThat(spannable).hasStrikethroughSpanBetween(SPAN_START, SPAN_END).withFlags(Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
use of android.text.style.StrikethroughSpan in project ExoPlayer by google.
the class SsaDecoder method createCue.
private static Cue createCue(String text, @Nullable SsaStyle style, SsaStyle.Overrides styleOverrides, float screenWidth, float screenHeight) {
SpannableString spannableText = new SpannableString(text);
Cue.Builder cue = new Cue.Builder().setText(spannableText);
if (style != null) {
if (style.primaryColor != null) {
spannableText.setSpan(new ForegroundColorSpan(style.primaryColor), /* start= */
0, /* end= */
spannableText.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (style.fontSize != Cue.DIMEN_UNSET && screenHeight != Cue.DIMEN_UNSET) {
cue.setTextSize(style.fontSize / screenHeight, Cue.TEXT_SIZE_TYPE_FRACTIONAL_IGNORE_PADDING);
}
if (style.bold && style.italic) {
spannableText.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), /* start= */
0, /* end= */
spannableText.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (style.bold) {
spannableText.setSpan(new StyleSpan(Typeface.BOLD), /* start= */
0, /* end= */
spannableText.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (style.italic) {
spannableText.setSpan(new StyleSpan(Typeface.ITALIC), /* start= */
0, /* end= */
spannableText.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (style.underline) {
spannableText.setSpan(new UnderlineSpan(), /* start= */
0, /* end= */
spannableText.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (style.strikeout) {
spannableText.setSpan(new StrikethroughSpan(), /* start= */
0, /* end= */
spannableText.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
@SsaStyle.SsaAlignment int alignment;
if (styleOverrides.alignment != SsaStyle.SSA_ALIGNMENT_UNKNOWN) {
alignment = styleOverrides.alignment;
} else if (style != null) {
alignment = style.alignment;
} else {
alignment = SsaStyle.SSA_ALIGNMENT_UNKNOWN;
}
cue.setTextAlignment(toTextAlignment(alignment)).setPositionAnchor(toPositionAnchor(alignment)).setLineAnchor(toLineAnchor(alignment));
if (styleOverrides.position != null && screenHeight != Cue.DIMEN_UNSET && screenWidth != Cue.DIMEN_UNSET) {
cue.setPosition(styleOverrides.position.x / screenWidth);
cue.setLine(styleOverrides.position.y / screenHeight, LINE_TYPE_FRACTION);
} else {
// TODO: Read the MarginL, MarginR and MarginV values from the Style & Dialogue lines.
cue.setPosition(computeDefaultLineOrPosition(cue.getPositionAnchor()));
cue.setLine(computeDefaultLineOrPosition(cue.getLineAnchor()), LINE_TYPE_FRACTION);
}
return cue.build();
}
Aggregations