當前位置: 首頁>>代碼示例>>Java>>正文


Java MetricAffectingSpan類代碼示例

本文整理匯總了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;
        }
 
開發者ID:suragch,項目名稱:mongol-library,代碼行數:24,代碼來源:MongolTextLine.java

示例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();
}
 
開發者ID:lsjwzh,項目名稱:FastTextView,代碼行數:26,代碼來源:TextLineImpl15.java

示例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;
}
 
開發者ID:mirhoseini,項目名稱:android_utils,代碼行數:31,代碼來源:Utils.java

示例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;
}
 
開發者ID:baoti,項目名稱:Pioneer,代碼行數:20,代碼來源:Spans.java

示例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;
}
 
開發者ID:baoti,項目名稱:Pioneer,代碼行數:27,代碼來源:SpansV1.java

示例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;
}
 
開發者ID:zilgam,項目名稱:Bimoid-IM-Android,代碼行數:18,代碼來源:AutoRefreshTextView.java

示例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;
}
 
開發者ID:Applications-Development,項目名稱:SimpleRssReader,代碼行數:24,代碼來源:RoundedCornersBackgroundSpan.java

示例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);
    }
}
 
開發者ID:andrei-egeniq,項目名稱:android-tibits,代碼行數:12,代碼來源:MainActivity.java

示例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);
    }
}
 
開發者ID:baoti,項目名稱:Pioneer,代碼行數:8,代碼來源:Truss.java

示例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;
    }
}
 
開發者ID:michalbednarski,項目名稱:IntentsLab,代碼行數:12,代碼來源:FormattedTextBuilder.java

示例11: wrap

import android.text.style.MetricAffectingSpan; //導入依賴的package包/類
public static MetricAffectingSpan wrap(CharacterStyle style) {
    return new MetricAffectAdapter(style);
}
 
開發者ID:baoti,項目名稱:Pioneer,代碼行數:4,代碼來源:Truss.java

示例12: updateMeasureState

import android.text.style.MetricAffectingSpan; //導入依賴的package包/類
@Override
public void updateMeasureState(TextPaint p) {
    if (style instanceof MetricAffectingSpan) {
        ((MetricAffectingSpan) style).updateMeasureState(p);
    }
}
 
開發者ID:baoti,項目名稱:Pioneer,代碼行數:7,代碼來源:Truss.java

示例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;
}
 
開發者ID:zilgam,項目名稱:Bimoid-IM-Android,代碼行數:49,代碼來源:AutoRefreshTextView.java

示例14: getUnderlying

import android.text.style.MetricAffectingSpan; //導入依賴的package包/類
@Override
public MetricAffectingSpan getUnderlying() {
    return this;
}
 
開發者ID:lemberg,項目名稱:android-project-template,代碼行數:5,代碼來源:CustomFontTextSpan.java

示例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;
    }
}
 
開發者ID:michalbednarski,項目名稱:IntentsLab,代碼行數:72,代碼來源:FormattedTextBuilder.java


注:本文中的android.text.style.MetricAffectingSpan類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。