当前位置: 首页>>代码示例>>Java>>正文


Java ReplacementSpan类代码示例

本文整理汇总了Java中android.text.style.ReplacementSpan的典型用法代码示例。如果您正苦于以下问题:Java ReplacementSpan类的具体用法?Java ReplacementSpan怎么用?Java ReplacementSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ReplacementSpan类属于android.text.style包,在下文中一共展示了ReplacementSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recursiveGetSizeWithReplacementSpan

import android.text.style.ReplacementSpan; //导入依赖的package包/类
/**
 * Do not support cross Span.
 *
 * @param text       text
 * @param parentSpan parentSpan
 * @param start      start index of parentSpan
 * @param end        end index of parentSpan
 * @param paint      TextPaint
 * @return recursive calculated width
 */
public int recursiveGetSizeWithReplacementSpan(CharSequence text, ReplacementSpan parentSpan, @IntRange(from = 0) int start, @IntRange(from = 0) int end, Paint paint) {
  if (text instanceof Spanned) {
    Spanned spannedText = (Spanned) text;
    List<ReplacementSpan> spans = getSortedReplacementSpans(spannedText, start, end);
    if (!spans.isEmpty()) {
      int lastIndexCursor = 0;
      int width = 0;
      for (ReplacementSpan span : spans) {
        if (span == parentSpan) {
          continue;
        }
        int spanStart = spannedText.getSpanStart(span);
        int spanEnd = spannedText.getSpanEnd(span);
        width += parentSpan.getSize(paint, text, lastIndexCursor, spanStart, null);
        width += span.getSize(paint, text, spanStart, spanEnd, null);
        lastIndexCursor = spanEnd;
      }
      if (lastIndexCursor < end) {
        width += parentSpan.getSize(paint, text, lastIndexCursor, end, null);
      }
      return width;
    }
  }
  return parentSpan.getSize(paint, text, start, end, null);
}
 
开发者ID:lsjwzh,项目名称:FastTextView,代码行数:36,代码来源:TextMeasureUtil.java

示例2: getSpans

import android.text.style.ReplacementSpan; //导入依赖的package包/类
@Override
public <T> T[] getSpans(int start, int end, Class<T> type) {
  if (mEllipsisEnd >= end && mEllipsisStart <= end) {
    T[] spans1 = mSourceSpanned.getSpans(start, Math.max(mEllipsisStart, start), type);
    T[] spans2 = mSourceSpanned.getSpans(Math.min(end, mEllipsisEnd), end, type);
    int offset = mCustomEllipsisSpan != null
        && (type.isAssignableFrom(ReplacementSpan.class) || type == mCustomEllipsisSpan.getClass()) ?
        1 : 0;
    int minLen = spans1.length + spans2.length + offset;
    T[] spans = (T[]) Array.newInstance(type, minLen);
    if (spans.length > minLen) {
      spans = Arrays.copyOf(spans, minLen);
    }
    System.arraycopy(spans1, 0, spans, 0, spans1.length);
    if (offset > 0) {
      spans[spans1.length] =  (T) mCustomEllipsisSpan;
    }
    System.arraycopy(spans2, 0, spans, spans1.length + offset, spans2.length);
    return spans;
  }
  return mSourceSpanned.getSpans(start, end, type);
}
 
开发者ID:lsjwzh,项目名称:FastTextView,代码行数:23,代码来源:EllipsisSpannedContainer.java

示例3: getTranslateTxt

import android.text.style.ReplacementSpan; //导入依赖的package包/类
/**
 * get real translate charsequence
 * @param content
 * @return
 */
public static CharSequence getTranslateTxt(CharSequence content) {
    StringBuilder sBuilder = new StringBuilder();
    if (content instanceof SpannableStringBuilder) {
        SpannableStringBuilder spanSb = (SpannableStringBuilder) content;
        if (spanSb.toString().contains(EMHolderEntity.FINAL_HOLDER)) {
            for (int i = 0; i < spanSb.length(); i++) {
                ReplacementSpan[] spans = spanSb.getSpans(i, i + 1, ReplacementSpan.class);
                if (spans.length > 0) {
                    if (spans[0] instanceof EMImageSpan) {
                        EMImageSpan imgSpan = (EMImageSpan) spans[0];
                        sBuilder.append(imgSpan.mTransferTxt);
                    } else if (spans[0] instanceof DefEmojSpan) {
                        DefEmojSpan defSpan = (DefEmojSpan) spans[0];
                        sBuilder.append(defSpan.mTransferTxt);
                    }
                } else {
                    sBuilder.append(spanSb.subSequence(i, i + 1));
                }
            }
        } else {
            sBuilder.append(content);
        }
    }
    return sBuilder;
}
 
开发者ID:zhangdatao,项目名称:Emojier-Andriod,代码行数:31,代码来源:SpanableUtil.java

示例4: getTranslateTxt

import android.text.style.ReplacementSpan; //导入依赖的package包/类
public static CharSequence getTranslateTxt(CharSequence content) {
    StringBuilder sBuilder = new StringBuilder();
    if (content instanceof SpannableStringBuilder) {
        SpannableStringBuilder spanSb = (SpannableStringBuilder) content;
        if (spanSb.toString().contains(EMHolderEntity.FINAL_HOLDER)) {
            for (int i = 0; i < spanSb.length(); i++) {
                ReplacementSpan[] spans = spanSb.getSpans(i, i + 1, ReplacementSpan.class);
                if (spans.length > 0) {
                    if (spans[0] instanceof EMImageSpan) {
                        EMImageSpan imgSpan = (EMImageSpan) spans[0];
                        sBuilder.append(imgSpan.mTransferTxt);
                    } else if (spans[0] instanceof DefEmojSpan) {
                        DefEmojSpan defSpan = (DefEmojSpan) spans[0];
                        sBuilder.append(defSpan.mTransferTxt);
                    }
                } else {
                    sBuilder.append(spanSb.subSequence(i, i + 1));
                }
            }
        } else {
            sBuilder.append(content);
        }
    }
    return sBuilder;
}
 
开发者ID:zhangdatao,项目名称:Emojier-Andriod,代码行数:26,代码来源:EMContentUtil.java

示例5: getSize

import android.text.style.ReplacementSpan; //导入依赖的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

示例6: getSize

import android.text.style.ReplacementSpan; //导入依赖的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

示例7: draw

import android.text.style.ReplacementSpan; //导入依赖的package包/类
@Override
        public void draw(@NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
//            bitmapCanvas.drawColor(Color.GRAY, PorterDuff.Mode.CLEAR);
            int color = /*paint instanceof TextPaint ? ((TextPaint) paint).bgColor :*/ paint.getColor();
            bitmapCanvas.drawColor(color);
            for (CharacterStyle style : styles) {
                if (style instanceof ReplacementSpan) {
                    ((ReplacementSpan) style).draw(bitmapCanvas, text, start, end, 0, top, y, bottom, paint);
                } else if (paint instanceof TextPaint) {
                    style.updateDrawState((TextPaint) paint);
                }
            }
            paint.setXfermode(xfermode);
            bitmapCanvas.drawText(text, start, end, 0, y, paint);
            canvas.drawBitmap(bitmap, x, 0, null);
        }
 
开发者ID:baoti,项目名称:Pioneer,代码行数:17,代码来源:SpansV1.java

示例8: getSortedReplacementSpans

import android.text.style.ReplacementSpan; //导入依赖的package包/类
public static List<ReplacementSpan> getSortedReplacementSpans(final Spanned spanned, int start, int end) {
  List<ReplacementSpan> sortedSpans = new LinkedList<>();
  ReplacementSpan[] spans = spanned.getSpans(start, end, ReplacementSpan.class);
  if (spans.length > 0) {
    sortedSpans.addAll(Arrays.asList(spans));
  }
  Collections.sort(sortedSpans, new Comparator<ReplacementSpan>() {
    @Override
    public int compare(ReplacementSpan span1, ReplacementSpan span2) {
      return spanned.getSpanStart(span1) - spanned.getSpanStart(span2);
    }
  });
  return sortedSpans;
}
 
开发者ID:lsjwzh,项目名称:FastTextView,代码行数:15,代码来源:TextMeasureUtil.java

示例9: draw

import android.text.style.ReplacementSpan; //导入依赖的package包/类
@Override
public void draw(@NonNull Rect outRect, @NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
    for (CharacterStyle style : styles) {
        if (style instanceof SupportSpan) {
            ((SupportSpan) style).draw(frame, canvas, text, start, end, x, top, y, bottom, paint);
        } else if (style instanceof ReplacementSpan) {
            ((ReplacementSpan) style).draw(canvas, text, start, end, x, top, y, bottom, paint);
        } else if (paint instanceof TextPaint) {
            style.updateDrawState((TextPaint) paint);
        }
    }
}
 
开发者ID:baoti,项目名称:Pioneer,代码行数:13,代码来源:Spans.java

示例10: pushSpan

import android.text.style.ReplacementSpan; //导入依赖的package包/类
/** Starts {@code span} at the current position in the builder. */
public Truss pushSpan(Object span) {
    if (span instanceof ReplacementSpan) {
        replacements++;
    } else if (replacements > 0 && span instanceof CharacterStyle) {
        span = convert((CharacterStyle) span);
    }
    stack.addLast(new Span(builder.length(), span));
    return this;
}
 
开发者ID:baoti,项目名称:Pioneer,代码行数:11,代码来源:Truss.java

示例11: popSpan

import android.text.style.ReplacementSpan; //导入依赖的package包/类
/** End the most recently pushed span at the current position in the builder. */
public Truss popSpan() {
    Span span = stack.removeLast();
    if (span.span instanceof ReplacementSpan) {
        replacements--;
    }
    builder.setSpan(span.span, span.start, builder.length(), SPAN_INCLUSIVE_EXCLUSIVE);
    return this;
}
 
开发者ID:baoti,项目名称:Pioneer,代码行数:10,代码来源:Truss.java

示例12: onSpanAdded

import android.text.style.ReplacementSpan; //导入依赖的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

示例13: beforeTextChanged

import android.text.style.ReplacementSpan; //导入依赖的package包/类
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    manipulatedSpan = null;
    if (after < count && !manualModeOn) {
        ReplacementSpan[] spans = ((Spannable)s).getSpans(start, start+count, ReplacementSpan.class);
        if (spans.length == 1) {
            manipulatedSpan = spans[0];
        } else {
            manipulatedSpan = null;
        }
    }
}
 
开发者ID:ghophp,项目名称:android-bubble-text,代码行数:13,代码来源:ChipsEditText.java

示例14: setCustomEllipsisSpan

import android.text.style.ReplacementSpan; //导入依赖的package包/类
public void setCustomEllipsisSpan(ReplacementSpan customEllipsisSpan) {
  mCustomEllipsisSpan = customEllipsisSpan;
}
 
开发者ID:lsjwzh,项目名称:FastTextView,代码行数:4,代码来源:FastTextView.java

示例15: getCustomEllipsisSpan

import android.text.style.ReplacementSpan; //导入依赖的package包/类
public ReplacementSpan getCustomEllipsisSpan() {
  return mCustomEllipsisSpan;
}
 
开发者ID:lsjwzh,项目名称:FastTextView,代码行数:4,代码来源:FastTextView.java


注:本文中的android.text.style.ReplacementSpan类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。