Search in sources :

Example 16 with Annotation

use of android.text.Annotation in project Signal-Android by WhisperSystems.

the class EmojiTextView method ellipsizeAnyTextForMaxLength.

private void ellipsizeAnyTextForMaxLength() {
    if (maxLength > 0 && getText().length() > maxLength + 1) {
        SpannableStringBuilder newContent = new SpannableStringBuilder();
        CharSequence shortenedText = getText().subSequence(0, maxLength);
        if (shortenedText instanceof Spanned) {
            Spanned spanned = (Spanned) shortenedText;
            List<Annotation> mentionAnnotations = MentionAnnotation.getMentionAnnotations(spanned, maxLength - 1, maxLength);
            if (!mentionAnnotations.isEmpty()) {
                shortenedText = shortenedText.subSequence(0, spanned.getSpanStart(mentionAnnotations.get(0)));
            }
        }
        newContent.append(shortenedText).append(ELLIPSIS).append(Util.emptyIfNull(overflowText));
        EmojiParser.CandidateList newCandidates = isInEditMode() ? null : EmojiProvider.getCandidates(newContent);
        if (useSystemEmoji || newCandidates == null || newCandidates.size() == 0) {
            super.setText(newContent, BufferType.SPANNABLE);
        } else {
            CharSequence emojified = EmojiProvider.emojify(newCandidates, newContent, this, isJumbomoji || forceJumboEmoji);
            super.setText(emojified, BufferType.SPANNABLE);
        }
    }
}
Also used : EmojiParser(org.thoughtcrime.securesms.components.emoji.parsing.EmojiParser) Spanned(android.text.Spanned) SpannableStringBuilder(android.text.SpannableStringBuilder) Annotation(android.text.Annotation) MentionAnnotation(org.thoughtcrime.securesms.components.mention.MentionAnnotation)

Example 17 with Annotation

use of android.text.Annotation in project Signal-Android by WhisperSystems.

the class MentionValidatorWatcher method afterTextChanged.

@Override
public void afterTextChanged(Editable editable) {
    if (invalidMentionAnnotations == null) {
        return;
    }
    List<Annotation> invalidMentions = invalidMentionAnnotations;
    invalidMentionAnnotations = null;
    for (Annotation annotation : invalidMentions) {
        editable.removeSpan(annotation);
    }
}
Also used : Annotation(android.text.Annotation)

Example 18 with Annotation

use of android.text.Annotation in project Signal-Android by WhisperSystems.

the class MentionValidatorWatcher method onTextChanged.

@Override
public void onTextChanged(CharSequence sequence, int start, int before, int count) {
    if (count > 1 && mentionValidator != null && sequence instanceof Spanned) {
        Spanned span = (Spanned) sequence;
        List<Annotation> mentionAnnotations = MentionAnnotation.getMentionAnnotations(span, start, start + count);
        if (mentionAnnotations.size() > 0) {
            invalidMentionAnnotations = mentionValidator.getInvalidMentionAnnotations(mentionAnnotations);
        }
    }
}
Also used : Spanned(android.text.Spanned) Annotation(android.text.Annotation)

Example 19 with Annotation

use of android.text.Annotation in project android-aosp-mms by slvn.

the class RecipientsEditor method getFieldAt.

private static String getFieldAt(String field, Spanned sp, int start, int end, Context context) {
    Annotation[] a = sp.getSpans(start, end, Annotation.class);
    String fieldValue = getAnnotation(a, field);
    if (TextUtils.isEmpty(fieldValue)) {
        fieldValue = TextUtils.substring(sp, start, end);
    }
    return fieldValue;
}
Also used : SpannableString(android.text.SpannableString) Annotation(android.text.Annotation)

Example 20 with Annotation

use of android.text.Annotation in project Signal-Android by signalapp.

the class EmojiTextView method ellipsizeAnyTextForMaxLength.

private void ellipsizeAnyTextForMaxLength() {
    if (maxLength > 0 && getText().length() > maxLength + 1) {
        SpannableStringBuilder newContent = new SpannableStringBuilder();
        CharSequence shortenedText = getText().subSequence(0, maxLength);
        if (shortenedText instanceof Spanned) {
            Spanned spanned = (Spanned) shortenedText;
            List<Annotation> mentionAnnotations = MentionAnnotation.getMentionAnnotations(spanned, maxLength - 1, maxLength);
            if (!mentionAnnotations.isEmpty()) {
                shortenedText = shortenedText.subSequence(0, spanned.getSpanStart(mentionAnnotations.get(0)));
            }
        }
        newContent.append(shortenedText).append(ELLIPSIS).append(Util.emptyIfNull(overflowText));
        EmojiParser.CandidateList newCandidates = isInEditMode() ? null : EmojiProvider.getCandidates(newContent);
        if (useSystemEmoji || newCandidates == null || newCandidates.size() == 0) {
            super.setText(newContent, BufferType.SPANNABLE);
        } else {
            CharSequence emojified = EmojiProvider.emojify(newCandidates, newContent, this, isJumbomoji || forceJumboEmoji);
            super.setText(emojified, BufferType.SPANNABLE);
        }
    }
}
Also used : EmojiParser(org.thoughtcrime.securesms.components.emoji.parsing.EmojiParser) Spanned(android.text.Spanned) SpannableStringBuilder(android.text.SpannableStringBuilder) Annotation(android.text.Annotation) MentionAnnotation(org.thoughtcrime.securesms.components.mention.MentionAnnotation)

Aggregations

Annotation (android.text.Annotation)25 SpannableString (android.text.SpannableString)15 SpannableStringBuilder (android.text.SpannableStringBuilder)7 Spanned (android.text.Spanned)6 MentionAnnotation (org.thoughtcrime.securesms.components.mention.MentionAnnotation)6 TextPaint (android.text.TextPaint)5 ActivityNotFoundException (android.content.ActivityNotFoundException)3 Context (android.content.Context)3 Intent (android.content.Intent)3 URLSpan (android.text.style.URLSpan)3 View (android.view.View)3 ValueAnimator (android.animation.ValueAnimator)2 SuppressLint (android.annotation.SuppressLint)2 Color (android.graphics.Color)2 PorterDuff (android.graphics.PorterDuff)2 Rect (android.graphics.Rect)2 Typeface (android.graphics.Typeface)2 Uri (android.net.Uri)2 Spannable (android.text.Spannable)2 BackgroundColorSpan (android.text.style.BackgroundColorSpan)2