Search in sources :

Example 6 with Annotation

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

the class MentionRendererDelegate method draw.

public void draw(@NonNull Canvas canvas, @NonNull Spanned text, @NonNull Layout layout) {
    Annotation[] annotations = text.getSpans(0, text.length(), Annotation.class);
    for (Annotation annotation : annotations) {
        if (MentionAnnotation.isMentionAnnotation(annotation)) {
            int spanStart = text.getSpanStart(annotation);
            int spanEnd = text.getSpanEnd(annotation);
            int startLine = layout.getLineForOffset(spanStart);
            int endLine = layout.getLineForOffset(spanEnd);
            int startOffset = (int) (layout.getPrimaryHorizontal(spanStart) + -1 * layout.getParagraphDirection(startLine) * horizontalPadding);
            int endOffset = (int) (layout.getPrimaryHorizontal(spanEnd) + layout.getParagraphDirection(endLine) * horizontalPadding);
            MentionRenderer renderer = (startLine == endLine) ? single : multi;
            renderer.draw(canvas, layout, startLine, endLine, startOffset, endOffset);
        }
    }
}
Also used : Annotation(android.text.Annotation)

Example 7 with Annotation

use of android.text.Annotation in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AnnotationSpan method linkify.

public static CharSequence linkify(CharSequence rawText, LinkInfo... linkInfos) {
    SpannableString msg = new SpannableString(rawText);
    Annotation[] spans = msg.getSpans(0, msg.length(), Annotation.class);
    SpannableStringBuilder builder = new SpannableStringBuilder(msg);
    for (Annotation annotation : spans) {
        final String key = annotation.getValue();
        int start = msg.getSpanStart(annotation);
        int end = msg.getSpanEnd(annotation);
        AnnotationSpan link = null;
        for (LinkInfo linkInfo : linkInfos) {
            if (linkInfo.mAnnotation.equals(key)) {
                link = new AnnotationSpan(linkInfo.mListener);
                break;
            }
        }
        if (link != null) {
            builder.setSpan(link, start, end, msg.getSpanFlags(link));
        }
    }
    return builder;
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) Annotation(android.text.Annotation) SpannableStringBuilder(android.text.SpannableStringBuilder) TextPaint(android.text.TextPaint)

Example 8 with Annotation

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

the class ComposeText method changeSelectionForPartialMentions.

private boolean changeSelectionForPartialMentions(@NonNull Spanned spanned, int selectionStart, int selectionEnd) {
    Annotation[] annotations = spanned.getSpans(0, spanned.length(), Annotation.class);
    for (Annotation annotation : annotations) {
        if (MentionAnnotation.isMentionAnnotation(annotation)) {
            int spanStart = spanned.getSpanStart(annotation);
            int spanEnd = spanned.getSpanEnd(annotation);
            boolean startInMention = selectionStart > spanStart && selectionStart < spanEnd;
            boolean endInMention = selectionEnd > spanStart && selectionEnd < spanEnd;
            if (startInMention || endInMention) {
                if (selectionStart == selectionEnd) {
                    setSelection(spanEnd, spanEnd);
                } else {
                    int newStart = startInMention ? spanStart : selectionStart;
                    int newEnd = endInMention ? spanEnd : selectionEnd;
                    setSelection(newStart, newEnd);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Annotation(android.text.Annotation) MentionAnnotation(org.thoughtcrime.securesms.components.mention.MentionAnnotation)

Example 9 with Annotation

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

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 10 with Annotation

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

the class ConversationItem method linkifyMessageBody.

private void linkifyMessageBody(@NonNull Spannable messageBody, boolean shouldLinkifyAllLinks) {
    int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
    boolean hasLinks = LinkifyCompat.addLinks(messageBody, shouldLinkifyAllLinks ? linkPattern : 0);
    if (hasLinks) {
        Stream.of(messageBody.getSpans(0, messageBody.length(), URLSpan.class)).filterNot(url -> LinkPreviewUtil.isLegalUrl(url.getURL())).forEach(messageBody::removeSpan);
        URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
        for (URLSpan urlSpan : urlSpans) {
            int start = messageBody.getSpanStart(urlSpan);
            int end = messageBody.getSpanEnd(urlSpan);
            URLSpan span = new InterceptableLongClickCopyLinkSpan(urlSpan.getURL(), urlClickListener);
            messageBody.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    if (conversationMessage.hasStyleLinks()) {
        for (PlaceholderURLSpan placeholder : messageBody.getSpans(0, messageBody.length(), PlaceholderURLSpan.class)) {
            int start = messageBody.getSpanStart(placeholder);
            int end = messageBody.getSpanEnd(placeholder);
            URLSpan span = new InterceptableLongClickCopyLinkSpan(placeholder.getValue(), urlClickListener, ContextCompat.getColor(getContext(), R.color.signal_accent_primary), false);
            messageBody.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    List<Annotation> mentionAnnotations = MentionAnnotation.getMentionAnnotations(messageBody);
    for (Annotation annotation : mentionAnnotations) {
        messageBody.setSpan(new MentionClickableSpan(RecipientId.from(annotation.getValue())), messageBody.getSpanStart(annotation), messageBody.getSpanEnd(annotation), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
Also used : LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) SlideClickListener(org.thoughtcrime.securesms.mms.SlideClickListener) NonNull(androidx.annotation.NonNull) LongClickMovementMethod(org.thoughtcrime.securesms.util.LongClickMovementMethod) Uri(android.net.Uri) StringUtil(org.thoughtcrime.securesms.util.StringUtil) TouchDelegate(android.view.TouchDelegate) ColorInt(androidx.annotation.ColorInt) LinkPreviewUtil(org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) TextSlide(org.thoughtcrime.securesms.mms.TextSlide) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) BindableConversationItem(org.thoughtcrime.securesms.BindableConversationItem) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) LinkPreviewView(org.thoughtcrime.securesms.components.LinkPreviewView) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ContextCompat(androidx.core.content.ContextCompat) PlaceholderURLSpan(org.thoughtcrime.securesms.util.PlaceholderURLSpan) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) MediaPreviewActivity(org.thoughtcrime.securesms.MediaPreviewActivity) MmsDownloadJob(org.thoughtcrime.securesms.jobs.MmsDownloadJob) MessageRecordUtil(org.thoughtcrime.securesms.util.MessageRecordUtil) Nullable(androidx.annotation.Nullable) TextPaint(android.text.TextPaint) AlertView(org.thoughtcrime.securesms.components.AlertView) LinkifyCompat(androidx.core.text.util.LinkifyCompat) ViewOnceMessageView(org.thoughtcrime.securesms.revealable.ViewOnceMessageView) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) PlaybackSpeedToggleTextView(org.thoughtcrime.securesms.components.PlaybackSpeedToggleTextView) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) Toast(android.widget.Toast) Annotation(android.text.Annotation) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) MultiselectCollection(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectCollection) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) URLSpan(android.text.style.URLSpan) Contact(org.thoughtcrime.securesms.contactshare.Contact) SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) NullableStub(org.thoughtcrime.securesms.util.views.NullableStub) Optional(org.whispersystems.libsignal.util.guava.Optional) ThemeUtil(org.thoughtcrime.securesms.util.ThemeUtil) TypedValue(android.util.TypedValue) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob) DocumentView(org.thoughtcrime.securesms.components.DocumentView) ProjectionList(org.thoughtcrime.securesms.util.ProjectionList) ValueAnimator(android.animation.ValueAnimator) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Rect(android.graphics.Rect) UrlClickHandler(org.thoughtcrime.securesms.util.UrlClickHandler) DimenRes(androidx.annotation.DimenRes) ConversationItemThumbnail(org.thoughtcrime.securesms.components.ConversationItemThumbnail) AttachmentDownloadJob(org.thoughtcrime.securesms.jobs.AttachmentDownloadJob) Spannable(android.text.Spannable) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) ClickableSpan(android.text.style.ClickableSpan) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) R(org.thoughtcrime.securesms.R) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) AttributeSet(android.util.AttributeSet) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SlidesClickedListener(org.thoughtcrime.securesms.mms.SlidesClickedListener) QuoteView(org.thoughtcrime.securesms.components.QuoteView) MediaItem(com.google.android.exoplayer2.MediaItem) Outliner(org.thoughtcrime.securesms.components.Outliner) RecipientForeverObserver(org.thoughtcrime.securesms.recipients.RecipientForeverObserver) PorterDuff(android.graphics.PorterDuff) SharedContactView(org.thoughtcrime.securesms.components.SharedContactView) ViewGroup(android.view.ViewGroup) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) Slide(org.thoughtcrime.securesms.mms.Slide) MentionAnnotation(org.thoughtcrime.securesms.components.mention.MentionAnnotation) SearchUtil(org.thoughtcrime.securesms.util.SearchUtil) ActivityNotFoundException(android.content.ActivityNotFoundException) DateUtils(org.thoughtcrime.securesms.util.DateUtils) RelativeLayout(android.widget.RelativeLayout) GlideRequests(org.thoughtcrime.securesms.mms.GlideRequests) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) ReactionsConversationView(org.thoughtcrime.securesms.reactions.ReactionsConversationView) GiphyMp4PlaybackPolicy(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackPolicy) Projection(org.thoughtcrime.securesms.util.Projection) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) Typeface(android.graphics.Typeface) Context(android.content.Context) Spanned(android.text.Spanned) AlertDialog(androidx.appcompat.app.AlertDialog) InterceptableLongClickCopyLinkSpan(org.thoughtcrime.securesms.util.InterceptableLongClickCopyLinkSpan) BorderlessImageView(org.thoughtcrime.securesms.components.BorderlessImageView) MultiselectPart(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectPart) GiphyMp4PlaybackPolicyEnforcer(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackPolicyEnforcer) Intent(android.content.Intent) VibrateUtil(org.thoughtcrime.securesms.util.VibrateUtil) Linkify(android.text.util.Linkify) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) HashSet(java.util.HashSet) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob) SuppressLint(android.annotation.SuppressLint) LifecycleOwner(androidx.lifecycle.LifecycleOwner) MotionEvent(android.view.MotionEvent) Colorizer(org.thoughtcrime.securesms.conversation.colors.Colorizer) AudioView(org.thoughtcrime.securesms.components.AudioView) Stub(org.thoughtcrime.securesms.util.views.Stub) BackgroundColorSpan(android.text.style.BackgroundColorSpan) Quote(org.thoughtcrime.securesms.database.model.Quote) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) CharacterStyle(android.text.style.CharacterStyle) ConversationItemFooter(org.thoughtcrime.securesms.components.ConversationItemFooter) Collections(java.util.Collections) InterceptableLongClickCopyLinkSpan(org.thoughtcrime.securesms.util.InterceptableLongClickCopyLinkSpan) PlaceholderURLSpan(org.thoughtcrime.securesms.util.PlaceholderURLSpan) URLSpan(android.text.style.URLSpan) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) PlaceholderURLSpan(org.thoughtcrime.securesms.util.PlaceholderURLSpan) 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