use of android.text.style.ScaleXSpan in project mongol-library by suragch.
the class MongolTextViewActivity method onSpanClick.
public void onSpanClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Add span");
final String[] spanTypes = { "BackgroundColorSpan", "ForegroundColorSpan", "RelativeSizeSpan", "TypefaceSpan", "ScaleXSpan", "StyleSpan", "SubscriptSpan", "SuperscriptSpan", "UnderlineSpan", "ClickableSpan" };
final SpannableString spannableString = new SpannableString(mtvExample.getText().toString());
// check boxes
builder.setMultiChoiceItems(spanTypes, null, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// user checked or unchecked a box
// select the middle third
int start = mtvExample.getText().length() / 3;
int end = mtvExample.getText().length() * 2 / 3;
switch(which) {
case // highlight
0:
if (isChecked) {
BackgroundColorSpan span = new BackgroundColorSpan(Color.YELLOW);
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
BackgroundColorSpan[] spans = spannableString.getSpans(0, spannableString.length(), BackgroundColorSpan.class);
for (BackgroundColorSpan span : spans) {
spannableString.removeSpan(span);
}
}
break;
case // text color
1:
if (isChecked) {
ForegroundColorSpan span = new ForegroundColorSpan(Color.GREEN);
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
ForegroundColorSpan[] spans = spannableString.getSpans(0, spannableString.length(), ForegroundColorSpan.class);
for (ForegroundColorSpan span : spans) {
spannableString.removeSpan(span);
}
}
break;
case // SIZE
2:
if (isChecked) {
RelativeSizeSpan span = new RelativeSizeSpan(2f);
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
RelativeSizeSpan[] spans = spannableString.getSpans(0, spannableString.length(), RelativeSizeSpan.class);
for (RelativeSizeSpan span : spans) {
spannableString.removeSpan(span);
}
}
break;
case // FONT
3:
// setting a custom font as a span requires the custom MongolTypefaceSpan
if (isChecked) {
Typeface font = MongolFont.get(MongolFontActivity.JCLGQ, getApplicationContext());
MongolTypefaceSpan span = new MongolTypefaceSpan(font);
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
MongolTypefaceSpan[] spans = spannableString.getSpans(0, spannableString.length(), MongolTypefaceSpan.class);
for (MongolTypefaceSpan span : spans) {
spannableString.removeSpan(span);
}
}
break;
case // scale X
4:
if (isChecked) {
ScaleXSpan span = new ScaleXSpan(2f);
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
ScaleXSpan[] spans = spannableString.getSpans(0, spannableString.length(), ScaleXSpan.class);
for (ScaleXSpan span : spans) {
spannableString.removeSpan(span);
}
}
break;
case // bold style
5:
if (isChecked) {
// TODO is there a correct way to apply ITALIC to Mongolian text (can adjust paint.setTextSkewX)
// StyleSpan span = new StyleSpan(Typeface.ITALIC);
StyleSpan span = new StyleSpan(Typeface.BOLD);
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
StyleSpan[] spans = spannableString.getSpans(0, spannableString.length(), StyleSpan.class);
for (StyleSpan span : spans) {
spannableString.removeSpan(span);
}
}
break;
case // Subscript
6:
if (isChecked) {
SubscriptSpan span = new SubscriptSpan();
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
SubscriptSpan[] spans = spannableString.getSpans(0, spannableString.length(), SubscriptSpan.class);
for (SubscriptSpan span : spans) {
spannableString.removeSpan(span);
}
}
break;
case // Superscript
7:
if (isChecked) {
SuperscriptSpan span = new SuperscriptSpan();
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
SuperscriptSpan[] spans = spannableString.getSpans(0, spannableString.length(), SuperscriptSpan.class);
for (SuperscriptSpan span : spans) {
spannableString.removeSpan(span);
}
}
break;
case // Underline
8:
if (isChecked) {
UnderlineSpan span = new UnderlineSpan();
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
UnderlineSpan[] spans = spannableString.getSpans(0, spannableString.length(), UnderlineSpan.class);
for (UnderlineSpan span : spans) {
spannableString.removeSpan(span);
}
}
break;
case // Clickable
9:
if (isChecked) {
ClickableSpan span = new ClickableSpan() {
@Override
public void onClick(View view) {
Toast.makeText(MongolTextViewActivity.this, "Clicked", Toast.LENGTH_SHORT).show();
}
};
spannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mtvExample.setMovementMethod(LinkMovementMethod.getInstance());
} else {
ClickableSpan[] spans = spannableString.getSpans(0, spannableString.length(), ClickableSpan.class);
for (ClickableSpan span : spans) {
spannableString.removeSpan(span);
}
}
}
}
});
// dialog buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mtvExample.setText(spannableString);
}
});
builder.setNegativeButton("Cancel", null);
AlertDialog dialog = builder.create();
dialog.show();
}
use of android.text.style.ScaleXSpan in project bitcoin-wallet by bitcoin-wallet.
the class CurrencyTextView method setPrefixScaleX.
public void setPrefixScaleX(final float prefixScaleX) {
this.prefixScaleXSpan = new ScaleXSpan(prefixScaleX);
updateView();
}
use of android.text.style.ScaleXSpan in project EnableHands by LeviWGG.
the class SpanUtils method updateCharCharSequence.
private void updateCharCharSequence() {
if (mText.length() == 0)
return;
int start = mBuilder.length();
mBuilder.append(mText);
int end = mBuilder.length();
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);
}
}
}
use of android.text.style.ScaleXSpan in project FirebaseUI-Android by firebase.
the class SpacedEditText method getSpacedOutString.
private SpannableStringBuilder getSpacedOutString(CharSequence text) {
SpannableStringBuilder builder = new SpannableStringBuilder();
int textLength = text.length();
int lastSpaceIndex = -1;
// 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;
}
use of android.text.style.ScaleXSpan in project Tehreer-Android by mta452.
the class ShapingRunLocator method resolveSpans.
private static void resolveSpans(@NonNull ShapingRun shapingRun, @NonNull Object[] spans) {
for (Object span : spans) {
if (span instanceof com.mta.tehreer.layout.style.TypefaceSpan) {
com.mta.tehreer.layout.style.TypefaceSpan typefaceSpan = (com.mta.tehreer.layout.style.TypefaceSpan) span;
shapingRun.typeface = typefaceSpan.getTypeface();
shapingRun.typeWeight = shapingRun.typeface.getWeight();
shapingRun.typeSlope = shapingRun.typeface.getSlope();
} else if (span instanceof TypeSizeSpan) {
TypeSizeSpan typeSizeSpan = (TypeSizeSpan) span;
shapingRun.typeSize = typeSizeSpan.getSize();
} else if (span instanceof TypefaceSpan) {
TypefaceSpan typefaceSpan = (TypefaceSpan) span;
resolveTypeface(shapingRun, typefaceSpan.getFamily(), TypeWidth.NORMAL);
} else if (span instanceof AbsoluteSizeSpan) {
AbsoluteSizeSpan absoluteSizeSpan = (AbsoluteSizeSpan) span;
shapingRun.typeSize = absoluteSizeSpan.getSize();
} else if (span instanceof RelativeSizeSpan) {
RelativeSizeSpan relativeSizeSpan = (RelativeSizeSpan) span;
shapingRun.typeSize *= relativeSizeSpan.getSizeChange();
} else if (span instanceof StyleSpan) {
StyleSpan styleSpan = (StyleSpan) span;
resolveStyle(shapingRun, styleSpan.getStyle());
updateTypeface(shapingRun);
} else if (span instanceof TextAppearanceSpan) {
TextAppearanceSpan appearanceSpan = (TextAppearanceSpan) span;
shapingRun.typeSize = appearanceSpan.getTextSize();
resolveStyle(shapingRun, appearanceSpan.getTextStyle());
String familyName = appearanceSpan.getFamily();
if (familyName != null) {
resolveTypeface(shapingRun, familyName, TypeWidth.NORMAL);
} else {
updateTypeface(shapingRun);
}
} else if (span instanceof ScaleXSpan) {
ScaleXSpan scaleXSpan = (ScaleXSpan) span;
shapingRun.scaleX = scaleXSpan.getScaleX();
} else if (span instanceof SuperscriptSpan) {
resolveBaselineShift(shapingRun, 0.5f);
} else if (span instanceof SubscriptSpan) {
resolveBaselineShift(shapingRun, -0.5f);
} else if (span instanceof ReplacementSpan) {
shapingRun.replacement = (ReplacementSpan) span;
}
}
if (shapingRun.typeSize < 0.0f) {
shapingRun.typeSize = 0.0f;
}
}
Aggregations