Java Code Examples for android.text.TextUtils#getChars()

The following examples show how to use android.text.TextUtils#getChars() . 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: RecordingCanvas.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public final void drawText(@NonNull CharSequence text, int start, int end, float x, float y,
        @NonNull Paint paint) {
    if ((start | end | (end - start) | (text.length() - end)) < 0) {
        throw new IndexOutOfBoundsException();
    }
    if (text instanceof String || text instanceof SpannedString
            || text instanceof SpannableString) {
        nDrawText(mNativeCanvasWrapper, text.toString(), start, end, x, y,
                paint.mBidiFlags, paint.getNativeInstance());
    } else if (text instanceof GraphicsOperations) {
        ((GraphicsOperations) text).drawText(this, start, end, x, y,
                paint);
    } else {
        char[] buf = TemporaryBuffer.obtain(end - start);
        TextUtils.getChars(text, start, end, buf, 0);
        nDrawText(mNativeCanvasWrapper, buf, 0, end - start, x, y,
                paint.mBidiFlags, paint.getNativeInstance());
        TemporaryBuffer.recycle(buf);
    }
}
 
Example 2
Source File: EmojiFilter.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
  char[] v = new char[end - start];
  TextUtils.getChars(source, start, end, v, 0);

  Spannable emojified = EmojiProvider.getInstance(view.getContext()).emojify(new String(v), view);

  if (source instanceof Spanned && emojified != null) {
    TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
  }

  return emojified;
}
 
Example 3
Source File: EmojiFilter.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
  char[] v = new char[end - start];
  TextUtils.getChars(source, start, end, v, 0);

  Spannable emojified = EmojiProvider.getInstance(view.getContext()).emojify(new String(v), view);

  if (source instanceof Spanned && emojified != null) {
    TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
  }

  return emojified;
}
 
Example 4
Source File: ReplacementTransformationMethod.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void getChars(int start, int end, char[] dest, int off) {
    TextUtils.getChars(mSource, start, end, dest, off);
    int offend = end - start + off;
    int n = mOriginal.length;

    for (int i = off; i < offend; i++) {
        char c = dest[i];

        for (int j = 0; j < n; j++) {
            if (c == mOriginal[j]) {
                dest[i] = mReplacement[j];
            }
        }
    }
}
 
Example 5
Source File: EmojiFilter.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
  char[] v = new char[end - start];
  TextUtils.getChars(source, start, end, v, 0);

  Spannable emojified = EmojiProvider.getInstance(view.getContext()).emojify(new String(v), view);

  if (source instanceof Spanned && emojified != null) {
    TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
  }

  return emojified;
}
 
Example 6
Source File: EmojiFilter.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
  char[] v = new char[end - start];
  TextUtils.getChars(source, start, end, v, 0);

  Spannable emojified = EmojiProvider.getInstance(view.getContext()).emojify(new String(v), view);

  if (source instanceof Spanned && emojified != null) {
    TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
  }

  return emojified;
}
 
Example 7
Source File: RecordingCanvas.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public final void drawTextRun(@NonNull CharSequence text, int start, int end, int contextStart,
        int contextEnd, float x, float y, boolean isRtl, @NonNull Paint paint) {

    if (text == null) {
        throw new NullPointerException("text is null");
    }
    if (paint == null) {
        throw new NullPointerException("paint is null");
    }
    if ((start | end | contextStart | contextEnd | start - contextStart | end - start
            | contextEnd - end | text.length() - contextEnd) < 0) {
        throw new IndexOutOfBoundsException();
    }

    if (text instanceof String || text instanceof SpannedString
            || text instanceof SpannableString) {
        nDrawTextRun(mNativeCanvasWrapper, text.toString(), start, end, contextStart,
                contextEnd, x, y, isRtl, paint.getNativeInstance());
    } else if (text instanceof GraphicsOperations) {
        ((GraphicsOperations) text).drawTextRun(this, start, end,
                contextStart, contextEnd, x, y, isRtl, paint);
    } else {
        int contextLen = contextEnd - contextStart;
        int len = end - start;
        char[] buf = TemporaryBuffer.obtain(contextLen);
        TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
        long measuredTextPtr = 0;
        if (text instanceof PrecomputedText) {
            PrecomputedText mt = (PrecomputedText) text;
            int paraIndex = mt.findParaIndex(start);
            if (end <= mt.getParagraphEnd(paraIndex)) {
                // Only support if the target is in the same paragraph.
                measuredTextPtr = mt.getMeasuredParagraph(paraIndex).getNativePtr();
            }
        }
        nDrawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len,
                0, contextLen, x, y, isRtl, paint.getNativeInstance(), measuredTextPtr);
        TemporaryBuffer.recycle(buf);
    }
}
 
Example 8
Source File: TextMeasureUtil.java    From FastTextView with Apache License 2.0 4 votes vote down vote up
public static void getTextBounds(Paint paint, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, Rect rect) {
  char[] currentText = new char[end - start];
  TextUtils.getChars(text, start, end, currentText, 0);
  paint.getTextBounds(currentText, 0, end - start, rect);
}