本文整理汇总了Java中android.text.style.MetricAffectingSpan类的典型用法代码示例。如果您正苦于以下问题:Java MetricAffectingSpan类的具体用法?Java MetricAffectingSpan怎么用?Java MetricAffectingSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetricAffectingSpan类属于android.text.style包,在下文中一共展示了MetricAffectingSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TextRun
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
TextRun(int offset, int length, boolean isRotated, boolean isSpanned) {
this.offset = offset;
this.length = length;
this.isRotated = isRotated;
TextPaint wp;
if (isSpanned) {
wp = mWorkPaint;
wp.set(mPaint);
MetricAffectingSpan[] spans = ((Spanned) mText).getSpans(offset, offset + length, MetricAffectingSpan.class);
for(MetricAffectingSpan span : spans) {
span.updateDrawState(wp);
}
} else {
wp = mPaint;
}
// just record the normal non-rotated values here
// measure and draw will take rotation into account
measuredWidth = wp.measureText(mText, offset, offset + length);
measuredHeight = wp.getFontMetrics().bottom - wp.getFontMetrics().top;
}
示例2: ascent
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
/**
* Returns the ascent of the text at start. This is used for scaling
* emoji.
*
* @param pos the line-relative position
* @return the ascent of the text at start
*/
float ascent(int pos) {
if (mSpanned == null) {
return mPaint.ascent();
}
pos += mStart;
MetricAffectingSpan[] spans = mSpanned.getSpans(pos, pos + 1, MetricAffectingSpan.class);
if (spans.length == 0) {
return mPaint.ascent();
}
TextPaint wp = mWorkPaint;
wp.set(mPaint);
for (MetricAffectingSpan span : spans) {
span.updateMeasureState(wp);
}
return wp.ascent();
}
示例3: applyTypefaceToString
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
/**
* Apply typeface to a plane text and return spannableString
*
* @param text Text that you want to apply typeface
* @param typeface Typeface that you want to apply to your text
* @return spannableString
*/
public static SpannableString applyTypefaceToString(String text, final Typeface typeface) {
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(new MetricAffectingSpan() {
@Override
public void updateMeasureState(TextPaint p) {
p.setTypeface(typeface);
// Note: This flag is required for proper typeface rendering
p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setTypeface(typeface);
// Note: This flag is required for proper typeface rendering
tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
}, 0, spannableString.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannableString;
}
示例4: getSize
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
@Override
public int getSize(@NonNull Rect outRect, @NonNull Paint paint, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, @Nullable Paint.FontMetricsInt fm) {
int width = super.getSize(outRect, paint, text, start, end, fm);
if (styles != null) {
for (CharacterStyle style : styles) {
if (style instanceof SupportSpan) {
width = Math.max(width, ((SupportSpan) style).getSize(frame, paint, text, start, end, fm));
} else if (style instanceof ReplacementSpan) {
width = Math.max(width, ((ReplacementSpan) style).getSize(paint, text, start, end, fm));
} else if (paint instanceof TextPaint) {
if (style instanceof MetricAffectingSpan) {
((MetricAffectingSpan) style).updateMeasureState((TextPaint) paint);
}
}
}
}
frame.right = width;
return width;
}
示例5: getSize
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, @Nullable Paint.FontMetricsInt fm) {
width = 0;
for (CharacterStyle style : styles) {
if (style instanceof ReplacementSpan) {
width = Math.max(width, ((ReplacementSpan) style).getSize(paint, text, start, end, fm));
} else if (paint instanceof TextPaint) {
if (style instanceof MetricAffectingSpan) {
((MetricAffectingSpan) style).updateMeasureState((TextPaint) paint);
}
}
}
if (fm != null) {
paint.getFontMetricsInt(fm);
}
paint.getFontMetricsInt(fontMetricsInt);
width = Math.max(width, (int) Math.ceil(paint.measureText(text, start, end)));
frame.right = width;
frame.top = fontMetricsInt.top;
frame.bottom = fontMetricsInt.bottom;
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, frame.bottom - frame.top, Bitmap.Config.ARGB_8888);
bitmapCanvas = new Canvas(bitmap);
}
return width;
}
示例6: getCharSize
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
private static final float getCharSize(MetricAffectingSpan[] sizeSpans, int char_idx, float size, Spanned source){
float res = 0;
final TextPaint p = new TextPaint();
if(sizeSpans == null) return size;
boolean found = false;
for(MetricAffectingSpan span: sizeSpans){
final int s = source.getSpanStart(span);
final int e = source.getSpanEnd(span);
if((s <= char_idx) && (char_idx <= e)){
span.updateMeasureState(p);
found = true;
}
}
if(!found) return size;
res = p.getTextSize();
return res;
}
示例7: getTextPaint
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
/**
* Get new text paint.
*
* @param p init paint object
* @param text some text
* @param startInText start position in text
* @param endInText end position in text
* @return new instance of TextPaint
*/
@NonNull
private TextPaint getTextPaint(Paint p, CharSequence text, int startInText, int endInText) {
final TextPaint textPaint = new TextPaint(p);
if (text instanceof SpannedString) {
SpannedString spanned = (SpannedString) text;
final MetricAffectingSpan[] spans = spanned.getSpans(startInText, endInText, MetricAffectingSpan.class);
if (spans.length > 0) {
for (MetricAffectingSpan span : spans) {
span.updateMeasureState(textPaint);
}
}
}
return textPaint;
}
示例8: mCustomiseScriptSpan
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
private void mCustomiseScriptSpan(MetricAffectingSpan[] spanArray, SpannableStringBuilder builder) {
for(MetricAffectingSpan metricAffectingSpan : spanArray) {
int start = builder.getSpanStart(metricAffectingSpan);
int end = builder.getSpanEnd(metricAffectingSpan);
RelativeSizeSpan sizeSpan = new RelativeSizeSpan(0.6f);
builder.setSpan(sizeSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new CalligraphyTypefaceSpan(mBoldItalicTypeface), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
示例9: convert
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
private static MetricAffectingSpan convert(CharacterStyle style) {
if (style instanceof MetricAffectingSpan) {
return (MetricAffectingSpan) style;
} else {
return new MetricAffectAdapter(style);
}
}
示例10: onSpanAdded
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
private void onSpanAdded(Object span) {
if (span instanceof MetricAffectingSpan) {
mHasMetricAffectingSpan = true;
}
if (span instanceof ReplacementSpan) {
mHasReplacementSpan = true;
}
if (span instanceof ParagraphStyle) {
mHasParagraphStyle = true;
}
}
示例11: wrap
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
public static MetricAffectingSpan wrap(CharacterStyle style) {
return new MetricAffectAdapter(style);
}
示例12: updateMeasureState
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
@Override
public void updateMeasureState(TextPaint p) {
if (style instanceof MetricAffectingSpan) {
((MetricAffectingSpan) style).updateMeasureState(p);
}
}
示例13: getCharIndexFromCoordinate
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
public int getCharIndexFromCoordinate(float x, float y) {
// Offset the top padding
int height = getPaddingTop();
boolean need_break = false;
final CharSequence text = getText();
final Layout layout = getLayout();
for (int i = 0; i < layout.getLineCount(); i++) {
if(need_break) break;
final float size = getTextSize();
Rect bounds = new Rect();
layout.getLineBounds(i, bounds);
//Log.e("Bounds", i+": "+(bounds.right-bounds.left));
height += bounds.height();
if (height >= y) {
need_break = true;
int lineStart = layout.getLineStart(i);
int lineEnd = layout.getLineEnd(i);
//Log.e("LineLength", ""+(lineEnd - lineStart));
Spanned span = (Spanned)text;
MetricAffectingSpan[] sizeSpans = span.getSpans(lineStart, lineEnd, MetricAffectingSpan.class);
float scaleFactor = 1;
/*final TextPaint p = new TextPaint();
if ( sizeSpans != null ) {
for (int j = 0; j < sizeSpans.length; j++) {
sizeSpans[j].updateMeasureState(p);
scaleFactor = p.getTextSize()/size;
}
}*/
span = (Spanned)text.subSequence(lineStart, lineEnd);
String lineSpan = text.subSequence(lineStart, lineEnd).toString();
//Log.e("Line1", lineSpan);
float[] widths = new float[lineSpan.length()];
TextPaint paint = getPaint();
paint.getTextWidths(lineSpan, widths);
float width = 0;
for (int j = 0; j < lineSpan.length(); j++) {
final float sz = getCharSize(sizeSpans, j, size, span);
//Log.e("MyTextView", "Size: "+size+" CharSpannedSize: "+sz);
scaleFactor = sz/size;
width += widths[j] * scaleFactor;
if (width >= x) {
return lineStart + j;
}
}
}
}
return -1;
}
示例14: getUnderlying
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
@Override
public MetricAffectingSpan getUnderlying() {
return this;
}
示例15: getSpans
import android.text.style.MetricAffectingSpan; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T[] getSpans(int start, int end, Class<T> type) {
// Fast path for common time-critical spans that aren't there
if (type == MetricAffectingSpan.class && !mHasMetricAffectingSpan) {
return (T[]) EMPTY_METRIC_AFFECTING_SPAN_ARRAY;
}
if (type == ReplacementSpan.class && !mHasReplacementSpan) {
return (T[]) EMPTY_REPLACEMENT_SPAN_ARRAY;
}
if (!mHasParagraphStyle) {
if (type == LeadingMarginSpan.class) {
return (T[]) EMPTY_LEADING_MARGIN_SPAN_ARRAY;
}
if (type == LineHeightSpan.class) {
return (T[]) EMPTY_LINE_HEIGHT_SPAN_ARRAY;
}
if (type == TabStopSpan.class) {
return (T[]) EMPTY_TAB_STOP_SPAN_ARRAY;
}
}
T[] spansFromSuperclass = mSpannableString.getSpans(start, end, type);
if (
mSpansArr.length == 0 || // We have no optimized spans
isExcludedSpanType(type)) { // Query is about unoptimized span
return spansFromSuperclass;
}
// Based on Arrays.binarySearch()
int lo = 0;
int hi = mSpansArr.length - 1;
int mid = -2;
while (lo <= hi) {
mid = (lo + hi) >>> 1;
int midVal = mSpansArr[mid].end;
if (midVal < start) {
lo = mid + 1;
} else if (midVal > start) {
hi = mid - 1;
} else {
break;
}
}
// Iterate over spans in range
List<T> result = null;
for (; mid < mSpansArr.length && mSpansArr[mid].start < end; mid++) {
if (mSpansArr[mid].end > start && type.isInstance(mSpansArr[mid].span)) {
if (result == null) {
result = LIST_POOL.acquire();
if (spansFromSuperclass.length != 0) {
result.addAll(Arrays.asList(spansFromSuperclass));
}
}
result.add((T) mSpansArr[mid].span);
}
}
// If we have list then make array and pass to superclass
if (result == null) {
return spansFromSuperclass;
} else {
T[] resultArray = result.toArray((T[]) Array.newInstance(type, result.size()));
LIST_POOL.release(result);
return resultArray;
}
}