android.text.style.ScaleXSpan Java Examples

The following examples show how to use android.text.style.ScaleXSpan. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Version1Button.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
private void applySpacing() {
    final CharSequence originalText = getText();
    if (originalText == null || originalText.equals("")) return;
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < originalText.length(); i++) {
        builder.append(originalText.charAt(i));
        if (i + 1 < originalText.length()) {
            builder.append("\u00A0");
        }
    }
    SpannableString finalText = new SpannableString(builder.toString());
    if (builder.toString().length() > 1) {
        for (int i = 1; i < builder.toString().length(); i += 2) {
            finalText.setSpan(new ScaleXSpan((spacing + 1) / 10), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    super.setText(finalText, BufferType.SPANNABLE);
}
 
Example #2
Source File: ChangeTextSpaceView.java    From FimiX8-RE with MIT License 6 votes vote down vote up
private void applySpacing() {
    if (this != null && this.originalText != null) {
        int i;
        StringBuilder builder = new StringBuilder();
        for (i = 0; i < this.originalText.length(); i++) {
            builder.append(this.originalText.charAt(i));
            if (i + 1 < this.originalText.length()) {
                builder.append(" ");
            }
        }
        SpannableString finalText = new SpannableString(builder.toString());
        if (builder.toString().length() > 1) {
            for (i = 1; i < builder.toString().length(); i += 2) {
                finalText.setSpan(new ScaleXSpan((this.spacing + 1.0f) / 10.0f), i, i + 1, 33);
            }
        }
        super.setText(finalText, BufferType.SPANNABLE);
    }
}
 
Example #3
Source File: LetterSpacingTextView.java    From FimiX8-RE with MIT License 6 votes vote down vote up
private void applySpacing() {
    CharSequence originalText = getText();
    if (this != null && originalText != null) {
        int i;
        StringBuilder builder = new StringBuilder();
        for (i = 0; i < originalText.length(); i++) {
            builder.append(originalText.charAt(i));
            if (i + 1 < originalText.length()) {
                builder.append(" ");
            }
        }
        SpannableString finalText = new SpannableString(builder.toString());
        if (builder.toString().length() > 1) {
            for (i = 1; i < builder.toString().length(); i += 2) {
                finalText.setSpan(new ScaleXSpan((this.spacing + 1.0f) / 10.0f), i, i + 1, 33);
            }
        }
        super.setText(finalText, BufferType.SPANNABLE);
    }
}
 
Example #4
Source File: Version1EditText.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
private void applySpacing() {

        if (this == null || this.originalText == null) return;

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < originalText.length(); i++) {
            builder.append(originalText.charAt(i));
            if (i + 1 < originalText.length()) {
                builder.append("\u00A0");
            }
        }
        SpannableString finalText = new SpannableString(builder.toString());

        if (builder.toString().length() > 1) {
            for (int i = 1; i < builder.toString().length(); i += 2) {
                finalText.setSpan(new ScaleXSpan((spacing + 1) / 10), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        super.setText(finalText, BufferType.SPANNABLE);
    }
 
Example #5
Source File: SpacedEditTextTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
/**
 * 1. Tests whether the content is set to the expected value.
 * 2. Tests whether the original content is set to the original value.
 * 3. Tests that the styles applied have the expected proportion
 * 4. Tests that the styles have been applied only on the spaces to preserve fonts appearance.
 */
private void testSpacing(String expectedSpacedText, String expectedOriginalText,
                         SpacedEditText editText) {
    final Editable editable = editText.getText();
    final ScaleXSpan[] spans = editable.getSpans(0, editText.length(), ScaleXSpan.class);

    assertEquals(expectedSpacedText, editable.toString());
    assertEquals(expectedOriginalText, editText.getUnspacedText().toString());

    for (ScaleXSpan span : spans) {
        assertEquals(SPACING_PROPORTION, span.getScaleX());

        final int spanStart = editable.getSpanStart(span);
        final int spanEnd = editable.getSpanEnd(span);

        assertEquals(" ", editable.toString().substring(spanStart, spanEnd));
    }
}
 
Example #6
Source File: SpacedEditText.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
private SpannableStringBuilder getSpacedOutString(CharSequence text) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    int textLength = text.length();
    int lastSpaceIndex = -1;

    //Insert a space in front of all characters upto the last character
    //Scale the space without scaling the character to preserve font appearance
    for (int i = 0; i < textLength - 1; i++) {
        builder.append(text.charAt(i));
        builder.append(" ");
        lastSpaceIndex += 2;
        builder.setSpan(new ScaleXSpan(mProportion), lastSpaceIndex, lastSpaceIndex + 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    //Append the last character
    if (textLength != 0) builder.append(text.charAt(textLength - 1));

    return builder;
}
 
Example #7
Source File: KerningTextView.java    From KerningViews with Apache License 2.0 6 votes vote down vote up
private void applyKerning() {
    if (originalText == null) {
        return;
    }

    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < originalText.length(); i++) {
        builder.append(originalText.charAt(i));
        if (i + 1 < originalText.length()) {
            builder.append("\u00A0");
        }
    }

    SpannableString finalText = new SpannableString(builder.toString());
    if (builder.toString().length() > 1) {
        for (int i = 1; i < builder.toString().length(); i += 2) {
            finalText.setSpan(
                    new ScaleXSpan((kerningFactor) / 10),
                    i,
                    i + 1,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    super.setText(finalText, BufferType.SPANNABLE);
}
 
Example #8
Source File: ColorDialogPreference.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Update the summary of the preference.
 */
private void updateSummary() {
	SpannableString summary = new SpannableString(getContext().getString(R.string.button_select_color));
	int overlayColor = PreferenceUtil.getSharedPreferenceInt(R.string.key_overlay_color, Color.RED);
	summary.setSpan(new ForegroundColorSpan(overlayColor), 0, summary.length(), 0);
	summary.setSpan(new RelativeSizeSpan(1.2f), 0, summary.length(), 0); // MAGIC_NUMBER
	summary.setSpan(new ScaleXSpan(5), 0, summary.length(), 0); // MAGIC_NUMBER
	setSummary(summary);
}
 
Example #9
Source File: Trestle.java    From Trestle with Apache License 2.0 5 votes vote down vote up
private static void setUpScaleXSpan(Span span, SpannableString ss, int start, int end) {
    float scaleX = span.getScaleX();
    if (Float.floatToRawIntBits(scaleX) != 0) {
        ss.setSpan(
                new ScaleXSpan(scaleX),
                start,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example #10
Source File: MainActivity.java    From auid2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final SpannableStringBuilder ssb = new SpannableStringBuilder();
    final int flag = Spannable.SPAN_EXCLUSIVE_EXCLUSIVE;
    int start;
    int end;

    // Regular text
    ssb.append("This text is normal, but ");

    // Bold text
    start = ssb.length();
    ssb.append("this text is bold");
    end = ssb.length();
    ssb.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);

    // Inline image
    ssb.append('\n');
    start = end + 1;
    ssb.append('\uFFFC'); // Unicode replacement character
    end = ssb.length();
    ssb.setSpan(new ImageSpan(this, R.mipmap.ic_launcher), start, end, flag);

    // Stretched text
    start = end;
    ssb.append("This text is wide");
    end = ssb.length();
    ssb.setSpan(new ScaleXSpan(2f), start, end, flag);

    // Assign to TextView
    final TextView tv = (TextView) findViewById(R.id.textView);
    tv.setText(ssb);
}
 
Example #11
Source File: TextDecorator.java    From text-decorator with Apache License 2.0 5 votes vote down vote up
public TextDecorator scaleX(final float proportion, final String... texts) {
  int index;

  for (String text : texts) {
    if (content.contains(text)) {
      index = content.indexOf(text);
      decoratedContent.setSpan(new ScaleXSpan(proportion), index, index + text.length(), flags);
    }
  }

  return this;
}
 
Example #12
Source File: Spans.java    From spanner with Apache License 2.0 5 votes vote down vote up
/**
 * @see android.text.style.ScaleXSpan#ScaleXSpan(float)
 */
public static Span scaleXSize(@FloatRange(from = 0.0) final float proportion) {
    return new Span(new SpanBuilder() {
        @Override
        public Object build() {
            return new ScaleXSpan(proportion);
        }
    });
}
 
Example #13
Source File: SpanEZTest.java    From SpanEZ with Apache License 2.0 5 votes vote down vote up
@Test
public void scale_x_should_add_only_one_span() {
    spanBuilder.scaleX(range, INTEGER_ARG)
               .apply();

    verify((SpanEZ) spanBuilder, times(1))
            .addSpan(isA(TargetRange.class), isA(ScaleXSpan.class));
}
 
Example #14
Source File: TextDecorator.java    From text-decorator with Apache License 2.0 4 votes vote down vote up
public TextDecorator scaleX(final float proportion, final int start, final int end) {
  checkIndexOutOfBoundsException(start, end);
  decoratedContent.setSpan(new ScaleXSpan(proportion), start, end, flags);

  return this;
}
 
Example #15
Source File: SpanEZ.java    From SpanEZ with Apache License 2.0 4 votes vote down vote up
@Override
public StyleEZ scaleX(@NonNull Locator locator, @FloatRange(from = 0.f) float proportion) {
    ScaleXSpan scaleXSpan = new ScaleXSpan(proportion);
    addMultipleSpan(locator, scaleXSpan);
    return this;
}
 
Example #16
Source File: Span.java    From Android-Spans with Apache License 2.0 4 votes vote down vote up
public static Node scaleX(Float proportion, Object... nodes) {
    return new SpanNode(new ScaleXSpan(proportion), nodes);
}
 
Example #17
Source File: SpanUtils.java    From styT with Apache License 2.0 4 votes vote down vote up
public static SpannableString getScaleXSpan() {
    SpannableString spannableString = new SpannableString("媳妇你长胖了");
    ScaleXSpan scaleXSpan = new ScaleXSpan(2);
    spannableString.setSpan(scaleXSpan, 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    return spannableString;
}
 
Example #18
Source File: SpanOptions.java    From AndroidSpan with Apache License 2.0 4 votes vote down vote up
public SpanOptions addScaleXSpan(float proportion) {
    ScaleXSpan span = new ScaleXSpan(proportion);
    listSpan.add(span);
    return this;
}
 
Example #19
Source File: SpannableStringUtils.java    From DevUtils with Apache License 2.0 4 votes vote down vote up
/**
 * 更新 CharSequence 字符
 */
private void updateCharCharSequence() {
    if (mText.length() == 0) return;
    int start = mBuilder.length();
    if (start == 0 && lineHeight != -1) { // bug of LineHeightSpan when first line
        mBuilder.append(Character.toString((char) 2)).append("\n")
                .setSpan(new AbsoluteSizeSpan(0), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        start = 2;
    }
    mBuilder.append(mText);
    int end = mBuilder.length();
    if (verticalAlign != -1) {
        mBuilder.setSpan(new VerticalAlignSpan(verticalAlign), start, end, flag);
    }
    if (foregroundColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new ForegroundColorSpan(foregroundColor), start, end, flag);
    }
    if (backgroundColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new BackgroundColorSpan(backgroundColor), start, end, flag);
    }
    if (first != -1) {
        mBuilder.setSpan(new LeadingMarginSpan.Standard(first, rest), start, end, flag);
    }
    if (quoteColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new CustomQuoteSpan(quoteColor, stripeWidth, quoteGapWidth), start, end, flag);
    }
    if (bulletColor != COLOR_DEFAULT) {
        mBuilder.setSpan(new CustomBulletSpan(bulletColor, bulletRadius, bulletGapWidth), start, end, flag);
    }
    if (fontSize != -1) {
        mBuilder.setSpan(new AbsoluteSizeSpan(fontSize, fontSizeIsDp), start, end, flag);
    }
    if (proportion != -1) {
        mBuilder.setSpan(new RelativeSizeSpan(proportion), start, end, flag);
    }
    if (xProportion != -1) {
        mBuilder.setSpan(new ScaleXSpan(xProportion), start, end, flag);
    }
    if (lineHeight != -1) {
        mBuilder.setSpan(new CustomLineHeightSpan(lineHeight, alignLine), start, end, flag);
    }
    if (isStrikethrough) {
        mBuilder.setSpan(new StrikethroughSpan(), start, end, flag);
    }
    if (isUnderline) {
        mBuilder.setSpan(new UnderlineSpan(), start, end, flag);
    }
    if (isSuperscript) {
        mBuilder.setSpan(new SuperscriptSpan(), start, end, flag);
    }
    if (isSubscript) {
        mBuilder.setSpan(new SubscriptSpan(), start, end, flag);
    }
    if (isBold) {
        mBuilder.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);
    }
    if (isItalic) {
        mBuilder.setSpan(new StyleSpan(Typeface.ITALIC), start, end, flag);
    }
    if (isBoldItalic) {
        mBuilder.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, end, flag);
    }
    if (fontFamily != null) {
        mBuilder.setSpan(new TypefaceSpan(fontFamily), start, end, flag);
    }
    if (typeface != null) {
        mBuilder.setSpan(new CustomTypefaceSpan(typeface), start, end, flag);
    }
    if (alignment != null) {
        mBuilder.setSpan(new AlignmentSpan.Standard(alignment), start, end, flag);
    }
    if (clickSpan != null) {
        mBuilder.setSpan(clickSpan, start, end, flag);
    }
    if (url != null) {
        mBuilder.setSpan(new URLSpan(url), start, end, flag);
    }
    if (blurRadius != -1) {
        mBuilder.setSpan(new MaskFilterSpan(new BlurMaskFilter(blurRadius, style)), start, end, flag);
    }
    if (shader != null) {
        mBuilder.setSpan(new ShaderSpan(shader), start, end, flag);
    }
    if (shadowRadius != -1) {
        mBuilder.setSpan(new ShadowSpan(shadowRadius, shadowDx, shadowDy, shadowColor), start, end, flag);
    }
    if (spans != null) {
        for (Object span : spans) {
            mBuilder.setSpan(span, start, end, flag);
        }
    }
}
 
Example #20
Source File: AndroidSpan.java    From AndroidSpan with Apache License 2.0 2 votes vote down vote up
/**
 * 缩放X大小
 * @param text
 * @param proportion
 * @return
 */
public AndroidSpan drawScaleXSpan(String text, float proportion) {
    ScaleXSpan span = new ScaleXSpan(proportion);
    drawSpan(text, span);
    return this;
}