Search in sources :

Example 1 with URLSpanReplacement

use of org.telegram.ui.Components.URLSpanReplacement in project Telegram-FOSS by Telegram-FOSS-Team.

the class MediaDataController method addStyleToText.

public static void addStyleToText(TextStyleSpan span, int start, int end, Spannable editable, boolean allowIntersection) {
    try {
        CharacterStyle[] spans = editable.getSpans(start, end, CharacterStyle.class);
        if (spans != null && spans.length > 0) {
            for (int a = 0; a < spans.length; a++) {
                CharacterStyle oldSpan = spans[a];
                TextStyleSpan.TextStyleRun textStyleRun;
                TextStyleSpan.TextStyleRun newStyleRun = span != null ? span.getTextStyleRun() : new TextStyleSpan.TextStyleRun();
                if (oldSpan instanceof TextStyleSpan) {
                    TextStyleSpan textStyleSpan = (TextStyleSpan) oldSpan;
                    textStyleRun = textStyleSpan.getTextStyleRun();
                } else if (oldSpan instanceof URLSpanReplacement) {
                    URLSpanReplacement urlSpanReplacement = (URLSpanReplacement) oldSpan;
                    textStyleRun = urlSpanReplacement.getTextStyleRun();
                    if (textStyleRun == null) {
                        textStyleRun = new TextStyleSpan.TextStyleRun();
                    }
                } else {
                    continue;
                }
                if (textStyleRun == null) {
                    continue;
                }
                int spanStart = editable.getSpanStart(oldSpan);
                int spanEnd = editable.getSpanEnd(oldSpan);
                editable.removeSpan(oldSpan);
                if (spanStart > start && end > spanEnd) {
                    editable.setSpan(createNewSpan(oldSpan, textStyleRun, newStyleRun, allowIntersection), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    if (span != null) {
                        editable.setSpan(new TextStyleSpan(new TextStyleSpan.TextStyleRun(newStyleRun)), spanEnd, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    end = spanStart;
                } else {
                    int startTemp = start;
                    if (spanStart <= start) {
                        if (spanStart != start) {
                            editable.setSpan(createNewSpan(oldSpan, textStyleRun, null, allowIntersection), spanStart, start, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        }
                        if (spanEnd > start) {
                            if (span != null) {
                                editable.setSpan(createNewSpan(oldSpan, textStyleRun, newStyleRun, allowIntersection), start, Math.min(spanEnd, end), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            }
                            start = spanEnd;
                        }
                    }
                    if (spanEnd >= end) {
                        if (spanEnd != end) {
                            editable.setSpan(createNewSpan(oldSpan, textStyleRun, null, allowIntersection), end, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        }
                        if (end > spanStart && spanEnd <= startTemp) {
                            if (span != null) {
                                editable.setSpan(createNewSpan(oldSpan, textStyleRun, newStyleRun, allowIntersection), spanStart, Math.min(spanEnd, end), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            }
                            end = spanStart;
                        }
                    }
                }
            }
        }
        if (span != null && start < end && start < editable.length()) {
            editable.setSpan(span, start, Math.min(editable.length(), end), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
Also used : TextStyleSpan(org.telegram.ui.Components.TextStyleSpan) CharacterStyle(android.text.style.CharacterStyle) Paint(android.graphics.Paint) SQLiteException(org.telegram.SQLite.SQLiteException) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement)

Example 2 with URLSpanReplacement

use of org.telegram.ui.Components.URLSpanReplacement in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessageObject method addEntitiesToText.

public static boolean addEntitiesToText(CharSequence text, ArrayList<TLRPC.MessageEntity> entities, boolean out, boolean usernames, boolean photoViewer, boolean useManualParse) {
    if (!(text instanceof Spannable)) {
        return false;
    }
    Spannable spannable = (Spannable) text;
    URLSpan[] spans = spannable.getSpans(0, text.length(), URLSpan.class);
    boolean hasUrls = spans != null && spans.length > 0;
    if (entities.isEmpty()) {
        return hasUrls;
    }
    byte t;
    if (photoViewer) {
        t = 2;
    } else if (out) {
        t = 1;
    } else {
        t = 0;
    }
    ArrayList<TextStyleSpan.TextStyleRun> runs = new ArrayList<>();
    ArrayList<TLRPC.MessageEntity> entitiesCopy = new ArrayList<>(entities);
    Collections.sort(entitiesCopy, (o1, o2) -> {
        if (o1.offset > o2.offset) {
            return 1;
        } else if (o1.offset < o2.offset) {
            return -1;
        }
        return 0;
    });
    for (int a = 0, N = entitiesCopy.size(); a < N; a++) {
        TLRPC.MessageEntity entity = entitiesCopy.get(a);
        if (entity.length <= 0 || entity.offset < 0 || entity.offset >= text.length()) {
            continue;
        } else if (entity.offset + entity.length > text.length()) {
            entity.length = text.length() - entity.offset;
        }
        if (!useManualParse || entity instanceof TLRPC.TL_messageEntityBold || entity instanceof TLRPC.TL_messageEntityItalic || entity instanceof TLRPC.TL_messageEntityStrike || entity instanceof TLRPC.TL_messageEntityUnderline || entity instanceof TLRPC.TL_messageEntityBlockquote || entity instanceof TLRPC.TL_messageEntityCode || entity instanceof TLRPC.TL_messageEntityPre || entity instanceof TLRPC.TL_messageEntityMentionName || entity instanceof TLRPC.TL_inputMessageEntityMentionName || entity instanceof TLRPC.TL_messageEntityTextUrl || entity instanceof TLRPC.TL_messageEntitySpoiler) {
            if (spans != null && spans.length > 0) {
                for (int b = 0; b < spans.length; b++) {
                    if (spans[b] == null) {
                        continue;
                    }
                    int start = spannable.getSpanStart(spans[b]);
                    int end = spannable.getSpanEnd(spans[b]);
                    if (entity.offset <= start && entity.offset + entity.length >= start || entity.offset <= end && entity.offset + entity.length >= end) {
                        spannable.removeSpan(spans[b]);
                        spans[b] = null;
                    }
                }
            }
        }
        TextStyleSpan.TextStyleRun newRun = new TextStyleSpan.TextStyleRun();
        newRun.start = entity.offset;
        newRun.end = newRun.start + entity.length;
        TLRPC.MessageEntity urlEntity = null;
        if (entity instanceof TLRPC.TL_messageEntitySpoiler) {
            newRun.flags = TextStyleSpan.FLAG_STYLE_SPOILER;
        } else if (entity instanceof TLRPC.TL_messageEntityStrike) {
            newRun.flags = TextStyleSpan.FLAG_STYLE_STRIKE;
        } else if (entity instanceof TLRPC.TL_messageEntityUnderline) {
            newRun.flags = TextStyleSpan.FLAG_STYLE_UNDERLINE;
        } else if (entity instanceof TLRPC.TL_messageEntityBlockquote) {
            newRun.flags = TextStyleSpan.FLAG_STYLE_QUOTE;
        } else if (entity instanceof TLRPC.TL_messageEntityBold) {
            newRun.flags = TextStyleSpan.FLAG_STYLE_BOLD;
        } else if (entity instanceof TLRPC.TL_messageEntityItalic) {
            newRun.flags = TextStyleSpan.FLAG_STYLE_ITALIC;
        } else if (entity instanceof TLRPC.TL_messageEntityCode || entity instanceof TLRPC.TL_messageEntityPre) {
            newRun.flags = TextStyleSpan.FLAG_STYLE_MONO;
        } else if (entity instanceof TLRPC.TL_messageEntityMentionName) {
            if (!usernames) {
                continue;
            }
            newRun.flags = TextStyleSpan.FLAG_STYLE_MENTION;
            newRun.urlEntity = entity;
        } else if (entity instanceof TLRPC.TL_inputMessageEntityMentionName) {
            if (!usernames) {
                continue;
            }
            newRun.flags = TextStyleSpan.FLAG_STYLE_MENTION;
            newRun.urlEntity = entity;
        } else {
            if (useManualParse && !(entity instanceof TLRPC.TL_messageEntityTextUrl)) {
                continue;
            }
            if ((entity instanceof TLRPC.TL_messageEntityUrl || entity instanceof TLRPC.TL_messageEntityTextUrl) && Browser.isPassportUrl(entity.url)) {
                continue;
            }
            if (entity instanceof TLRPC.TL_messageEntityMention && !usernames) {
                continue;
            }
            newRun.flags = TextStyleSpan.FLAG_STYLE_URL;
            newRun.urlEntity = entity;
        }
        for (int b = 0, N2 = runs.size(); b < N2; b++) {
            TextStyleSpan.TextStyleRun run = runs.get(b);
            if (newRun.start > run.start) {
                if (newRun.start >= run.end) {
                    continue;
                }
                if (newRun.end < run.end) {
                    TextStyleSpan.TextStyleRun r = new TextStyleSpan.TextStyleRun(newRun);
                    r.merge(run);
                    b++;
                    N2++;
                    runs.add(b, r);
                    r = new TextStyleSpan.TextStyleRun(run);
                    r.start = newRun.end;
                    b++;
                    N2++;
                    runs.add(b, r);
                } else {
                    TextStyleSpan.TextStyleRun r = new TextStyleSpan.TextStyleRun(newRun);
                    r.merge(run);
                    r.end = run.end;
                    b++;
                    N2++;
                    runs.add(b, r);
                }
                int temp = newRun.start;
                newRun.start = run.end;
                run.end = temp;
            } else {
                if (run.start >= newRun.end) {
                    continue;
                }
                int temp = run.start;
                if (newRun.end == run.end) {
                    run.merge(newRun);
                } else if (newRun.end < run.end) {
                    TextStyleSpan.TextStyleRun r = new TextStyleSpan.TextStyleRun(run);
                    r.merge(newRun);
                    r.end = newRun.end;
                    b++;
                    N2++;
                    runs.add(b, r);
                    run.start = newRun.end;
                } else {
                    TextStyleSpan.TextStyleRun r = new TextStyleSpan.TextStyleRun(newRun);
                    r.start = run.end;
                    b++;
                    N2++;
                    runs.add(b, r);
                    run.merge(newRun);
                }
                newRun.end = temp;
            }
        }
        if (newRun.start < newRun.end) {
            runs.add(newRun);
        }
    }
    int count = runs.size();
    for (int a = 0; a < count; a++) {
        TextStyleSpan.TextStyleRun run = runs.get(a);
        boolean setRun = false;
        String url = run.urlEntity != null ? TextUtils.substring(text, run.urlEntity.offset, run.urlEntity.offset + run.urlEntity.length) : null;
        if (run.urlEntity instanceof TLRPC.TL_messageEntityBotCommand) {
            spannable.setSpan(new URLSpanBotCommand(url, t, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (run.urlEntity instanceof TLRPC.TL_messageEntityHashtag || run.urlEntity instanceof TLRPC.TL_messageEntityMention || run.urlEntity instanceof TLRPC.TL_messageEntityCashtag) {
            spannable.setSpan(new URLSpanNoUnderline(url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (run.urlEntity instanceof TLRPC.TL_messageEntityEmail) {
            spannable.setSpan(new URLSpanReplacement("mailto:" + url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (run.urlEntity instanceof TLRPC.TL_messageEntityUrl) {
            hasUrls = true;
            String lowerCase = url.toLowerCase();
            if (!lowerCase.contains("://")) {
                spannable.setSpan(new URLSpanBrowser("http://" + url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                spannable.setSpan(new URLSpanBrowser(url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } else if (run.urlEntity instanceof TLRPC.TL_messageEntityBankCard) {
            hasUrls = true;
            spannable.setSpan(new URLSpanNoUnderline("card:" + url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (run.urlEntity instanceof TLRPC.TL_messageEntityPhone) {
            hasUrls = true;
            String tel = PhoneFormat.stripExceptNumbers(url);
            if (url.startsWith("+")) {
                tel = "+" + tel;
            }
            spannable.setSpan(new URLSpanBrowser("tel:" + tel, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (run.urlEntity instanceof TLRPC.TL_messageEntityTextUrl) {
            spannable.setSpan(new URLSpanReplacement(run.urlEntity.url, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (run.urlEntity instanceof TLRPC.TL_messageEntityMentionName) {
            spannable.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_messageEntityMentionName) run.urlEntity).user_id, t, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (run.urlEntity instanceof TLRPC.TL_inputMessageEntityMentionName) {
            spannable.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_inputMessageEntityMentionName) run.urlEntity).user_id.user_id, t, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if ((run.flags & TextStyleSpan.FLAG_STYLE_MONO) != 0) {
            spannable.setSpan(new URLSpanMono(spannable, run.start, run.end, t, run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            setRun = true;
            spannable.setSpan(new TextStyleSpan(run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (!setRun && (run.flags & TextStyleSpan.FLAG_STYLE_SPOILER) != 0) {
            spannable.setSpan(new TextStyleSpan(run), run.start, run.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return hasUrls;
}
Also used : URLSpanMono(org.telegram.ui.Components.URLSpanMono) ArrayList(java.util.ArrayList) URLSpanBotCommand(org.telegram.ui.Components.URLSpanBotCommand) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) TLRPC(org.telegram.tgnet.TLRPC) TextStyleSpan(org.telegram.ui.Components.TextStyleSpan) URLSpanNoUnderline(org.telegram.ui.Components.URLSpanNoUnderline) URLSpanBrowser(org.telegram.ui.Components.URLSpanBrowser) TextPaint(android.text.TextPaint) URLSpanUserMention(org.telegram.ui.Components.URLSpanUserMention) Spannable(android.text.Spannable) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement)

Example 3 with URLSpanReplacement

use of org.telegram.ui.Components.URLSpanReplacement in project Telegram-FOSS by Telegram-FOSS-Team.

the class IdenticonActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    fragmentView = new FrameLayout(context);
    FrameLayout parentFrameLayout = (FrameLayout) fragmentView;
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    fragmentView.setOnTouchListener((v, event) -> true);
    linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setWeightSum(100);
    parentFrameLayout.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    FrameLayout frameLayout = new FrameLayout(context);
    frameLayout.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20));
    linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));
    ImageView identiconView = new ImageView(context);
    identiconView.setScaleType(ImageView.ScaleType.FIT_XY);
    frameLayout.addView(identiconView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    container = new FrameLayout(context) {

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            if (codeTextView != null) {
                int x = codeTextView.getLeft() + codeTextView.getMeasuredWidth() / 2 - emojiTextView.getMeasuredWidth() / 2;
                int y = (codeTextView.getMeasuredHeight() - emojiTextView.getMeasuredHeight()) / 2 + linearLayout1.getTop() - AndroidUtilities.dp(16);
                emojiTextView.layout(x, y, x + emojiTextView.getMeasuredWidth(), y + emojiTextView.getMeasuredHeight());
            }
        }
    };
    container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    linearLayout.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));
    linearLayout1 = new LinearLayout(context);
    linearLayout1.setOrientation(LinearLayout.VERTICAL);
    linearLayout1.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
    container.addView(linearLayout1, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
    codeTextView = new TextView(context);
    codeTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
    codeTextView.setGravity(Gravity.CENTER);
    codeTextView.setTypeface(Typeface.MONOSPACE);
    codeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    /*codeTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                emojiSelected = !emojiSelected;
                updateEmojiButton(true);
                showHint(false);
            }
        });*/
    linearLayout1.addView(codeTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
    textView = new TextView(context);
    textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
    textView.setLinkTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLinksClickable(true);
    textView.setClickable(true);
    textView.setGravity(Gravity.CENTER);
    textView.setMovementMethod(new LinkMovementMethodMy());
    linearLayout1.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
    emojiTextView = new TextView(context);
    emojiTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
    emojiTextView.setGravity(Gravity.CENTER);
    emojiTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 32);
    container.addView(emojiTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
    TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(chat_id);
    if (encryptedChat != null) {
        IdenticonDrawable drawable = new IdenticonDrawable();
        identiconView.setImageDrawable(drawable);
        drawable.setEncryptedChat(encryptedChat);
        TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id);
        SpannableStringBuilder hash = new SpannableStringBuilder();
        StringBuilder emojis = new StringBuilder();
        if (encryptedChat.key_hash.length > 16) {
            String hex = Utilities.bytesToHex(encryptedChat.key_hash);
            for (int a = 0; a < 32; a++) {
                if (a != 0) {
                    if (a % 8 == 0) {
                        hash.append('\n');
                    } else if (a % 4 == 0) {
                        hash.append(' ');
                    }
                }
                hash.append(hex.substring(a * 2, a * 2 + 2));
                hash.append(' ');
            }
            hash.append("\n");
            for (int a = 0; a < 5; a++) {
                int num = ((encryptedChat.key_hash[16 + a * 4] & 0x7f) << 24) | ((encryptedChat.key_hash[16 + a * 4 + 1] & 0xff) << 16) | ((encryptedChat.key_hash[16 + a * 4 + 2] & 0xff) << 8) | (encryptedChat.key_hash[16 + a * 4 + 3] & 0xff);
                if (a != 0) {
                    emojis.append(" ");
                }
                emojis.append(EmojiData.emojiSecret[num % EmojiData.emojiSecret.length]);
            }
            emojiText = emojis.toString();
        }
        codeTextView.setText(hash.toString());
        hash.clear();
        hash.append(AndroidUtilities.replaceTags(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name)));
        final String url = "telegram.org";
        int index = hash.toString().indexOf(url);
        if (index != -1) {
            hash.setSpan(new URLSpanReplacement(LocaleController.getString("EncryptionKeyLink", R.string.EncryptionKeyLink)), index, index + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        textView.setText(hash);
    }
    updateEmojiButton(false);
    return fragmentView;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) IdenticonDrawable(org.telegram.ui.Components.IdenticonDrawable) TLRPC(org.telegram.tgnet.TLRPC) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearLayout(android.widget.LinearLayout) SpannableStringBuilder(android.text.SpannableStringBuilder) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement)

Example 4 with URLSpanReplacement

use of org.telegram.ui.Components.URLSpanReplacement in project Telegram-FOSS by Telegram-FOSS-Team.

the class MediaDataController method getEntities.

public ArrayList<TLRPC.MessageEntity> getEntities(CharSequence[] message, boolean allowStrike) {
    if (message == null || message[0] == null) {
        return null;
    }
    ArrayList<TLRPC.MessageEntity> entities = null;
    int index;
    int start = -1;
    int lastIndex = 0;
    boolean isPre = false;
    final String mono = "`";
    final String pre = "```";
    while ((index = TextUtils.indexOf(message[0], !isPre ? mono : pre, lastIndex)) != -1) {
        if (start == -1) {
            isPre = message[0].length() - index > 2 && message[0].charAt(index + 1) == '`' && message[0].charAt(index + 2) == '`';
            start = index;
            lastIndex = index + (isPre ? 3 : 1);
        } else {
            if (entities == null) {
                entities = new ArrayList<>();
            }
            for (int a = index + (isPre ? 3 : 1); a < message[0].length(); a++) {
                if (message[0].charAt(a) == '`') {
                    index++;
                } else {
                    break;
                }
            }
            lastIndex = index + (isPre ? 3 : 1);
            if (isPre) {
                int firstChar = start > 0 ? message[0].charAt(start - 1) : 0;
                boolean replacedFirst = firstChar == ' ' || firstChar == '\n';
                CharSequence startMessage = substring(message[0], 0, start - (replacedFirst ? 1 : 0));
                CharSequence content = substring(message[0], start + 3, index);
                firstChar = index + 3 < message[0].length() ? message[0].charAt(index + 3) : 0;
                CharSequence endMessage = substring(message[0], index + 3 + (firstChar == ' ' || firstChar == '\n' ? 1 : 0), message[0].length());
                if (startMessage.length() != 0) {
                    startMessage = AndroidUtilities.concat(startMessage, "\n");
                } else {
                    replacedFirst = true;
                }
                if (endMessage.length() != 0) {
                    endMessage = AndroidUtilities.concat("\n", endMessage);
                }
                if (!TextUtils.isEmpty(content)) {
                    message[0] = AndroidUtilities.concat(startMessage, content, endMessage);
                    TLRPC.TL_messageEntityPre entity = new TLRPC.TL_messageEntityPre();
                    entity.offset = start + (replacedFirst ? 0 : 1);
                    entity.length = index - start - 3 + (replacedFirst ? 0 : 1);
                    entity.language = "";
                    entities.add(entity);
                    lastIndex -= 6;
                }
            } else {
                if (start + 1 != index) {
                    message[0] = AndroidUtilities.concat(substring(message[0], 0, start), substring(message[0], start + 1, index), substring(message[0], index + 1, message[0].length()));
                    TLRPC.TL_messageEntityCode entity = new TLRPC.TL_messageEntityCode();
                    entity.offset = start;
                    entity.length = index - start - 1;
                    entities.add(entity);
                    lastIndex -= 2;
                }
            }
            start = -1;
            isPre = false;
        }
    }
    if (start != -1 && isPre) {
        message[0] = AndroidUtilities.concat(substring(message[0], 0, start), substring(message[0], start + 2, message[0].length()));
        if (entities == null) {
            entities = new ArrayList<>();
        }
        TLRPC.TL_messageEntityCode entity = new TLRPC.TL_messageEntityCode();
        entity.offset = start;
        entity.length = 1;
        entities.add(entity);
    }
    if (message[0] instanceof Spanned) {
        Spanned spannable = (Spanned) message[0];
        TextStyleSpan[] spans = spannable.getSpans(0, message[0].length(), TextStyleSpan.class);
        if (spans != null && spans.length > 0) {
            for (int a = 0; a < spans.length; a++) {
                TextStyleSpan span = spans[a];
                int spanStart = spannable.getSpanStart(span);
                int spanEnd = spannable.getSpanEnd(span);
                if (checkInclusion(spanStart, entities, false) || checkInclusion(spanEnd, entities, true) || checkIntersection(spanStart, spanEnd, entities)) {
                    continue;
                }
                if (entities == null) {
                    entities = new ArrayList<>();
                }
                addStyle(span.getStyleFlags(), spanStart, spanEnd, entities);
            }
        }
        URLSpanUserMention[] spansMentions = spannable.getSpans(0, message[0].length(), URLSpanUserMention.class);
        if (spansMentions != null && spansMentions.length > 0) {
            if (entities == null) {
                entities = new ArrayList<>();
            }
            for (int b = 0; b < spansMentions.length; b++) {
                TLRPC.TL_inputMessageEntityMentionName entity = new TLRPC.TL_inputMessageEntityMentionName();
                entity.user_id = getMessagesController().getInputUser(Utilities.parseLong(spansMentions[b].getURL()));
                if (entity.user_id != null) {
                    entity.offset = spannable.getSpanStart(spansMentions[b]);
                    entity.length = Math.min(spannable.getSpanEnd(spansMentions[b]), message[0].length()) - entity.offset;
                    if (message[0].charAt(entity.offset + entity.length - 1) == ' ') {
                        entity.length--;
                    }
                    entities.add(entity);
                }
            }
        }
        URLSpanReplacement[] spansUrlReplacement = spannable.getSpans(0, message[0].length(), URLSpanReplacement.class);
        if (spansUrlReplacement != null && spansUrlReplacement.length > 0) {
            if (entities == null) {
                entities = new ArrayList<>();
            }
            for (int b = 0; b < spansUrlReplacement.length; b++) {
                TLRPC.TL_messageEntityTextUrl entity = new TLRPC.TL_messageEntityTextUrl();
                entity.offset = spannable.getSpanStart(spansUrlReplacement[b]);
                entity.length = Math.min(spannable.getSpanEnd(spansUrlReplacement[b]), message[0].length()) - entity.offset;
                entity.url = spansUrlReplacement[b].getURL();
                entities.add(entity);
                TextStyleSpan.TextStyleRun style = spansUrlReplacement[b].getTextStyleRun();
                if (style != null) {
                    addStyle(style.flags, entity.offset, entity.offset + entity.length, entities);
                }
            }
        }
    }
    CharSequence cs = message[0];
    if (entities == null)
        entities = new ArrayList<>();
    cs = parsePattern(cs, BOLD_PATTERN, entities, obj -> new TLRPC.TL_messageEntityBold());
    cs = parsePattern(cs, ITALIC_PATTERN, entities, obj -> new TLRPC.TL_messageEntityItalic());
    cs = parsePattern(cs, SPOILER_PATTERN, entities, obj -> new TLRPC.TL_messageEntitySpoiler());
    if (allowStrike) {
        cs = parsePattern(cs, STRIKE_PATTERN, entities, obj -> new TLRPC.TL_messageEntityStrike());
    }
    message[0] = cs;
    return entities;
}
Also used : SparseLongArray(org.telegram.messenger.support.SparseLongArray) Spannable(android.text.Spannable) URLSpanUserMention(org.telegram.ui.Components.URLSpanUserMention) Drawable(android.graphics.drawable.Drawable) Bulletin(org.telegram.ui.Components.Bulletin) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) Map(java.util.Map) Shader(android.graphics.Shader) Canvas(android.graphics.Canvas) RectF(android.graphics.RectF) BitmapShader(android.graphics.BitmapShader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) UUID(java.util.UUID) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) SparseArray(android.util.SparseArray) CountDownLatch(java.util.concurrent.CountDownLatch) TextStyleSpan(org.telegram.ui.Components.TextStyleSpan) List(java.util.List) LaunchActivity(org.telegram.ui.LaunchActivity) Paint(android.graphics.Paint) Pattern(java.util.regex.Pattern) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) Context(android.content.Context) Path(android.graphics.Path) SpannedString(android.text.SpannedString) Spanned(android.text.Spanned) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) Build(android.os.Build) SQLiteException(org.telegram.SQLite.SQLiteException) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) SerializedData(org.telegram.tgnet.SerializedData) LongSparseArray(androidx.collection.LongSparseArray) SQLiteDatabase(org.telegram.SQLite.SQLiteDatabase) TextUtils(android.text.TextUtils) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement) ShortcutManager(android.content.pm.ShortcutManager) File(java.io.File) Color(android.graphics.Color) PorterDuffXfermode(android.graphics.PorterDuffXfermode) SharedPreferences(android.content.SharedPreferences) IconCompat(androidx.core.graphics.drawable.IconCompat) Bitmap(android.graphics.Bitmap) CharacterStyle(android.text.style.CharacterStyle) StickersArchiveAlert(org.telegram.ui.Components.StickersArchiveAlert) Comparator(java.util.Comparator) Activity(android.app.Activity) Collections(java.util.Collections) StickerSetBulletinLayout(org.telegram.ui.Components.StickerSetBulletinLayout) ArrayList(java.util.ArrayList) SpannedString(android.text.SpannedString) TLRPC(org.telegram.tgnet.TLRPC) TextStyleSpan(org.telegram.ui.Components.TextStyleSpan) Spanned(android.text.Spanned) Paint(android.graphics.Paint) URLSpanUserMention(org.telegram.ui.Components.URLSpanUserMention) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement)

Example 5 with URLSpanReplacement

use of org.telegram.ui.Components.URLSpanReplacement in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method didPressMessageUrl.

private void didPressMessageUrl(CharacterStyle url, boolean longPress, MessageObject messageObject, ChatMessageCell cell) {
    if (url == null || getParentActivity() == null) {
        return;
    }
    boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || (messageObject != null && messageObject.messageOwner != null && messageObject.messageOwner.noforwards);
    if (url instanceof URLSpanMono) {
        if (!noforwards) {
            ((URLSpanMono) url).copyToClipboard();
            getUndoView().showWithAction(0, UndoView.ACTION_TEXT_COPIED, null);
        }
    } else if (url instanceof URLSpanUserMention) {
        TLRPC.User user = getMessagesController().getUser(Utilities.parseLong(((URLSpanUserMention) url).getURL()));
        if (user != null) {
            MessagesController.openChatOrProfileWith(user, null, ChatActivity.this, 0, false);
        }
    } else if (url instanceof URLSpanNoUnderline) {
        String str = ((URLSpanNoUnderline) url).getURL();
        if (messageObject != null && str.startsWith("/")) {
            if (URLSpanBotCommand.enabled) {
                chatActivityEnterView.setCommand(messageObject, str, longPress, currentChat != null && currentChat.megagroup);
                if (!longPress && chatActivityEnterView.getFieldText() == null) {
                    hideFieldPanel(false);
                }
            }
        } else if (messageObject != null && str.startsWith("video") && !longPress) {
            int seekTime = Utilities.parseInt(str);
            TLRPC.WebPage webPage;
            if (messageObject.isYouTubeVideo()) {
                webPage = messageObject.messageOwner.media.webpage;
            } else if (messageObject.replyMessageObject != null && messageObject.replyMessageObject.isYouTubeVideo()) {
                webPage = messageObject.replyMessageObject.messageOwner.media.webpage;
                messageObject = messageObject.replyMessageObject;
            } else {
                webPage = null;
            }
            if (webPage != null) {
                EmbedBottomSheet.show(getParentActivity(), messageObject, photoViewerProvider, webPage.site_name, webPage.title, webPage.url, webPage.embed_url, webPage.embed_width, webPage.embed_height, seekTime, isKeyboardVisible());
            } else {
                if (!messageObject.isVideo() && messageObject.replyMessageObject != null) {
                    MessageObject obj = messagesDict[messageObject.replyMessageObject.getDialogId() == dialog_id ? 0 : 1].get(messageObject.replyMessageObject.getId());
                    cell = null;
                    if (obj == null) {
                        messageObject = messageObject.replyMessageObject;
                    } else {
                        messageObject = obj;
                    }
                }
                messageObject.forceSeekTo = seekTime / (float) messageObject.getDuration();
                openPhotoViewerForMessage(cell, messageObject);
            }
        } else if (messageObject != null && str.startsWith("audio")) {
            int seekTime = Utilities.parseInt(str);
            if (!messageObject.isMusic() && messageObject.replyMessageObject != null) {
                messageObject = messagesDict[messageObject.replyMessageObject.getDialogId() == dialog_id ? 0 : 1].get(messageObject.replyMessageObject.getId());
            }
            float progress = seekTime / (float) messageObject.getDuration();
            MediaController mediaController = getMediaController();
            if (mediaController.isPlayingMessage(messageObject)) {
                messageObject.audioProgress = progress;
                mediaController.seekToProgress(messageObject, progress);
                if (mediaController.isMessagePaused()) {
                    mediaController.playMessage(messageObject);
                }
            } else {
                messageObject.forceSeekTo = seekTime / (float) messageObject.getDuration();
                mediaController.playMessage(messageObject);
            }
        } else if (str.startsWith("card:")) {
            String number = str.substring(5);
            final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(getParentActivity(), 3, themeDelegate) };
            TLRPC.TL_payments_getBankCardData req = new TLRPC.TL_payments_getBankCardData();
            req.number = number;
            int requestId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                try {
                    progressDialog[0].dismiss();
                } catch (Throwable ignore) {
                }
                progressDialog[0] = null;
                if (response instanceof TLRPC.TL_payments_bankCardData) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    TLRPC.TL_payments_bankCardData data = (TLRPC.TL_payments_bankCardData) response;
                    BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
                    ArrayList<CharSequence> arrayList = new ArrayList<>();
                    for (int a = 0, N = data.open_urls.size(); a < N; a++) {
                        arrayList.add(data.open_urls.get(a).name);
                    }
                    arrayList.add(LocaleController.getString("CopyCardNumber", R.string.CopyCardNumber));
                    builder.setTitle(data.title);
                    builder.setItems(arrayList.toArray(new CharSequence[0]), (dialog, which) -> {
                        if (which < data.open_urls.size()) {
                            Browser.openUrl(getParentActivity(), data.open_urls.get(which).url, inlineReturn == 0, false);
                        } else {
                            AndroidUtilities.addToClipboard(number);
                            Toast.makeText(ApplicationLoader.applicationContext, LocaleController.getString("CardNumberCopied", R.string.CardNumberCopied), Toast.LENGTH_SHORT).show();
                        }
                    });
                    showDialog(builder.create());
                }
            }), null, null, 0, getMessagesController().webFileDatacenterId, ConnectionsManager.ConnectionTypeGeneric, true);
            AndroidUtilities.runOnUIThread(() -> {
                if (progressDialog[0] == null) {
                    return;
                }
                progressDialog[0].setOnCancelListener(dialog -> getConnectionsManager().cancelRequest(requestId, true));
                showDialog(progressDialog[0]);
            }, 500);
        } else {
            if (longPress) {
                BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
                int timestamp = -1;
                if (str.startsWith("video?")) {
                    timestamp = Utilities.parseInt(str);
                }
                if (timestamp >= 0) {
                    builder.setTitle(AndroidUtilities.formatDuration(timestamp, false));
                } else {
                    builder.setTitle(str);
                }
                final int finalTimestamp = timestamp;
                ChatMessageCell finalCell = cell;
                MessageObject finalMessageObject = messageObject;
                builder.setItems(noforwards ? new CharSequence[] { LocaleController.getString("Open", R.string.Open) } : new CharSequence[] { LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy) }, (dialog, which) -> {
                    if (which == 0) {
                        if (str.startsWith("video?")) {
                            didPressMessageUrl(url, false, finalMessageObject, finalCell);
                        } else {
                            openClickableLink(str);
                        }
                    } else if (which == 1) {
                        if (str.startsWith("video?") && finalMessageObject != null && !finalMessageObject.scheduled) {
                            MessageObject messageObject1 = finalMessageObject;
                            boolean isMedia = finalMessageObject.isVideo() || finalMessageObject.isRoundVideo() || finalMessageObject.isVoice() || finalMessageObject.isMusic();
                            if (!isMedia && finalMessageObject.replyMessageObject != null) {
                                messageObject1 = finalMessageObject.replyMessageObject;
                            }
                            long dialogId = messageObject1.getDialogId();
                            int messageId = messageObject1.getId();
                            String link = null;
                            if (messageObject1.messageOwner.fwd_from != null) {
                                if (messageObject1.messageOwner.fwd_from.saved_from_peer != null) {
                                    dialogId = MessageObject.getPeerId(messageObject1.messageOwner.fwd_from.saved_from_peer);
                                    messageId = messageObject1.messageOwner.fwd_from.saved_from_msg_id;
                                } else if (messageObject1.messageOwner.fwd_from.from_id != null) {
                                    dialogId = MessageObject.getPeerId(messageObject1.messageOwner.fwd_from.from_id);
                                    messageId = messageObject1.messageOwner.fwd_from.channel_post;
                                }
                            }
                            if (DialogObject.isChatDialog(dialogId)) {
                                TLRPC.Chat currentChat = MessagesController.getInstance(currentAccount).getChat(-dialogId);
                                if (currentChat != null && currentChat.username != null) {
                                    link = "https://t.me/" + currentChat.username + "/" + messageId + "?t=" + finalTimestamp;
                                }
                            } else {
                                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(dialogId);
                                if (user != null && user.username != null) {
                                    link = "https://t.me/" + user.username + "/" + messageId + "?t=" + finalTimestamp;
                                }
                            }
                            if (link == null) {
                                return;
                            }
                            AndroidUtilities.addToClipboard(link);
                        } else {
                            AndroidUtilities.addToClipboard(str);
                        }
                        if (str.startsWith("@")) {
                            undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null);
                        } else if (str.startsWith("#") || str.startsWith("$")) {
                            undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null);
                        } else {
                            undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
                        }
                    }
                });
                showDialog(builder.create());
            } else {
                openClickableLink(str);
            }
        }
    } else {
        final String urlFinal = ((URLSpan) url).getURL();
        if (longPress) {
            BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
            builder.setTitle(urlFinal);
            builder.setItems(noforwards ? new CharSequence[] { LocaleController.getString("Open", R.string.Open) } : new CharSequence[] { LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy) }, (dialog, which) -> {
                if (which == 0) {
                    processExternalUrl(1, urlFinal, false);
                } else if (which == 1) {
                    String url1 = urlFinal;
                    boolean tel = false;
                    boolean mail = false;
                    if (url1.startsWith("mailto:")) {
                        url1 = url1.substring(7);
                        mail = true;
                    } else if (url1.startsWith("tel:")) {
                        url1 = url1.substring(4);
                        tel = true;
                    }
                    AndroidUtilities.addToClipboard(url1);
                    if (mail) {
                        undoView.showWithAction(0, UndoView.ACTION_EMAIL_COPIED, null);
                    } else if (tel) {
                        undoView.showWithAction(0, UndoView.ACTION_PHONE_COPIED, null);
                    } else {
                        undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
                    }
                }
            });
            showDialog(builder.create());
        } else {
            boolean forceAlert = url instanceof URLSpanReplacement;
            if (url instanceof URLSpanReplacement && (urlFinal == null || !urlFinal.startsWith("mailto:")) || AndroidUtilities.shouldShowUrlInAlert(urlFinal)) {
                if (openLinkInternally(urlFinal, messageObject != null ? messageObject.getId() : 0)) {
                    return;
                }
                forceAlert = true;
            } else {
                if (messageObject != null && messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageObject.messageOwner.media.webpage != null && messageObject.messageOwner.media.webpage.cached_page != null) {
                    String lowerUrl = urlFinal.toLowerCase();
                    String lowerUrl2 = messageObject.messageOwner.media.webpage.url.toLowerCase();
                    if ((lowerUrl.contains("telegram.org/blog") || Browser.isTelegraphUrl(lowerUrl, false) || lowerUrl.contains("t.me/iv")) && (lowerUrl.contains(lowerUrl2) || lowerUrl2.contains(lowerUrl))) {
                        ArticleViewer.getInstance().setParentActivity(getParentActivity(), ChatActivity.this);
                        ArticleViewer.getInstance().open(messageObject);
                        return;
                    }
                }
                if (openLinkInternally(urlFinal, messageObject != null ? messageObject.getId() : 0)) {
                    return;
                }
            }
            if (Browser.urlMustNotHaveConfirmation(urlFinal)) {
                forceAlert = false;
            }
            processExternalUrl(2, urlFinal, forceAlert);
        }
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ViewHelper(org.telegram.ui.Components.ViewHelper) Bundle(android.os.Bundle) BotHelpCell(org.telegram.ui.Cells.BotHelpCell) AdjustPanLayoutHelper(org.telegram.ui.ActionBar.AdjustPanLayoutHelper) StickersAlert(org.telegram.ui.Components.StickersAlert) RecyclerAnimationScrollHelper(org.telegram.ui.Components.RecyclerAnimationScrollHelper) URLSpanUserMention(org.telegram.ui.Components.URLSpanUserMention) Property(android.util.Property) HorizontalScrollView(android.widget.HorizontalScrollView) ChatThemeController(org.telegram.messenger.ChatThemeController) MediaStore(android.provider.MediaStore) Map(java.util.Map) Shader(android.graphics.Shader) ContextCompat(androidx.core.content.ContextCompat) NotificationCenter(org.telegram.messenger.NotificationCenter) PinnedLineView(org.telegram.ui.Components.PinnedLineView) CountDownLatch(java.util.concurrent.CountDownLatch) Layout(android.text.Layout) EmojiData(org.telegram.messenger.EmojiData) ForwardingMessagesParams(org.telegram.messenger.ForwardingMessagesParams) BotCommandsMenuView(org.telegram.ui.Components.BotCommandsMenuView) Paint(android.graphics.Paint) Path(android.graphics.Path) ReactedHeaderView(org.telegram.ui.Components.ReactedHeaderView) PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) SystemClock(android.os.SystemClock) ChatBlurredFrameLayout(org.telegram.ui.Components.ChatBlurredFrameLayout) SpannableStringBuilder(android.text.SpannableStringBuilder) Calendar(java.util.Calendar) Toast(android.widget.Toast) PhoneFormat(org.telegram.PhoneFormat.PhoneFormat) Menu(android.view.Menu) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) JoinGroupAlert(org.telegram.ui.Components.JoinGroupAlert) AspectRatioFrameLayout(com.google.android.exoplayer2.ui.AspectRatioFrameLayout) LongSparseIntArray(org.telegram.messenger.support.LongSparseIntArray) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) URLSpan(android.text.style.URLSpan) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) ChatActivityMemberRequestsDelegate(org.telegram.ui.Delegates.ChatActivityMemberRequestsDelegate) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) EditText(android.widget.EditText) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) URLDecoder(java.net.URLDecoder) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) Animator(android.animation.Animator) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) ChatAttachAlertDocumentLayout(org.telegram.ui.Components.ChatAttachAlertDocumentLayout) DatePickerDialog(android.app.DatePickerDialog) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) RecyclerView(androidx.recyclerview.widget.RecyclerView) StickersAdapter(org.telegram.ui.Adapters.StickersAdapter) RectF(android.graphics.RectF) ReportAlert(org.telegram.ui.Components.ReportAlert) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ChatActionCell(org.telegram.ui.Cells.ChatActionCell) ChatThemeBottomSheet(org.telegram.ui.Components.ChatThemeBottomSheet) PorterDuff(android.graphics.PorterDuff) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) ShareAlert(org.telegram.ui.Components.ShareAlert) BluredView(org.telegram.ui.Components.BluredView) UserConfig(org.telegram.messenger.UserConfig) TextStyleSpan(org.telegram.ui.Components.TextStyleSpan) EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes) InstantCameraView(org.telegram.ui.Components.InstantCameraView) PhonebookShareAlert(org.telegram.ui.Components.PhonebookShareAlert) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) ImportingAlert(org.telegram.ui.Components.ImportingAlert) Spanned(android.text.Spanned) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) SparseIntArray(android.util.SparseIntArray) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocaleController(org.telegram.messenger.LocaleController) ChatActivityEnterTopView(org.telegram.ui.Components.ChatActivityEnterTopView) ExtendedGridLayoutManager(org.telegram.ui.Components.ExtendedGridLayoutManager) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearSmoothScrollerCustom(androidx.recyclerview.widget.LinearSmoothScrollerCustom) TLObject(org.telegram.tgnet.TLObject) Size(org.telegram.ui.Components.Size) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) ChatAvatarContainer(org.telegram.ui.Components.ChatAvatarContainer) PollVotesAlert(org.telegram.ui.Components.PollVotesAlert) EmbedBottomSheet(org.telegram.ui.Components.EmbedBottomSheet) DialogObject(org.telegram.messenger.DialogObject) BackupImageView(org.telegram.ui.Components.BackupImageView) LayoutHelper(org.telegram.ui.Components.LayoutHelper) TextureView(android.view.TextureView) Color(android.graphics.Color) Bitmap(android.graphics.Bitmap) CharacterStyle(android.text.style.CharacterStyle) ViewTreeObserver(android.view.ViewTreeObserver) Vibrator(android.os.Vibrator) Comparator(java.util.Comparator) Activity(android.app.Activity) ImageReceiver(org.telegram.messenger.ImageReceiver) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Arrays(java.util.Arrays) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) Bulletin(org.telegram.ui.Components.Bulletin) RadialProgressView(org.telegram.ui.Components.RadialProgressView) Manifest(android.Manifest) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) Matcher(java.util.regex.Matcher) ChatGreetingsView(org.telegram.ui.Components.ChatGreetingsView) Canvas(android.graphics.Canvas) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Emoji(org.telegram.messenger.Emoji) MessagesSearchAdapter(org.telegram.ui.Adapters.MessagesSearchAdapter) ColorMatrix(android.graphics.ColorMatrix) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TargetApi(android.annotation.TargetApi) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) BackButtonMenu(org.telegram.ui.Components.BackButtonMenu) ChatListItemAnimator(androidx.recyclerview.widget.ChatListItemAnimator) MentionsAdapter(org.telegram.ui.Adapters.MentionsAdapter) UndoView(org.telegram.ui.Components.UndoView) AnimationProperties(org.telegram.ui.Components.AnimationProperties) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) CounterView(org.telegram.ui.Components.CounterView) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TrendingStickersAlert(org.telegram.ui.Components.TrendingStickersAlert) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) TextPaint(android.text.TextPaint) BotSwitchCell(org.telegram.ui.Cells.BotSwitchCell) HintView(org.telegram.ui.Components.HintView) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) URLSpanBotCommand(org.telegram.ui.Components.URLSpanBotCommand) ReactionsLayoutInBubble(org.telegram.ui.Components.Reactions.ReactionsLayoutInBubble) ExifInterface(androidx.exifinterface.media.ExifInterface) FileLoader(org.telegram.messenger.FileLoader) ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) ClearHistoryAlert(org.telegram.ui.Components.ClearHistoryAlert) Space(android.widget.Space) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) BitmapFactory(android.graphics.BitmapFactory) GigagroupConvertAlert(org.telegram.ui.Components.GigagroupConvertAlert) URLSpanMono(org.telegram.ui.Components.URLSpanMono) URLSpanNoUnderline(org.telegram.ui.Components.URLSpanNoUnderline) AlertsCreator(org.telegram.ui.Components.AlertsCreator) BlurBehindDrawable(org.telegram.ui.Components.BlurBehindDrawable) ArrayList(java.util.ArrayList) SharedMediaLayout(org.telegram.ui.Components.SharedMediaLayout) FragmentContextView(org.telegram.ui.Components.FragmentContextView) TLRPC(org.telegram.tgnet.TLRPC) EditTextCaption(org.telegram.ui.Components.EditTextCaption) BuildConfig(org.telegram.messenger.BuildConfig) DialogCell(org.telegram.ui.Cells.DialogCell) SpannableString(android.text.SpannableString) BufferedWriter(java.io.BufferedWriter) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) ChatUnreadCell(org.telegram.ui.Cells.ChatUnreadCell) ChatLoadingCell(org.telegram.ui.Cells.ChatLoadingCell) ClippingImageView(org.telegram.ui.Components.ClippingImageView) File(java.io.File) ReactionsEffectOverlay(org.telegram.ui.Components.Reactions.ReactionsEffectOverlay) Gravity(android.view.Gravity) PorterDuffXfermode(android.graphics.PorterDuffXfermode) TypedValue(android.util.TypedValue) Configuration(android.content.res.Configuration) StickerCell(org.telegram.ui.Cells.StickerCell) ReactionsContainerLayout(org.telegram.ui.Components.ReactionsContainerLayout) ColorUtils(androidx.core.graphics.ColorUtils) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) VoIPHelper(org.telegram.ui.Components.voip.VoIPHelper) EmojiView(org.telegram.ui.Components.EmojiView) ValueAnimator(android.animation.ValueAnimator) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) ChatScrimPopupContainerLayout(org.telegram.ui.Components.ChatScrimPopupContainerLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Spannable(android.text.Spannable) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) ChecksHintView(org.telegram.ui.Components.ChecksHintView) MediaController(org.telegram.messenger.MediaController) ThemeEditorView(org.telegram.ui.Components.ThemeEditorView) View(android.view.View) Matrix(android.graphics.Matrix) SearchCounterView(org.telegram.ui.Components.SearchCounterView) ForwardingPreviewView(org.telegram.ui.Components.ForwardingPreviewView) BitmapShader(android.graphics.BitmapShader) Utilities(org.telegram.messenger.Utilities) HideViewAfterAnimation(org.telegram.ui.Components.HideViewAfterAnimation) ObjectAnimator(android.animation.ObjectAnimator) GridLayoutManagerFixed(androidx.recyclerview.widget.GridLayoutManagerFixed) ImageLocation(org.telegram.messenger.ImageLocation) MentionCell(org.telegram.ui.Cells.MentionCell) ReactionTabHolderView(org.telegram.ui.Components.ReactionTabHolderView) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) SparseArray(android.util.SparseArray) List(java.util.List) TextView(android.widget.TextView) MotionBackgroundDrawable(org.telegram.ui.Components.MotionBackgroundDrawable) SecretChatHelper(org.telegram.messenger.SecretChatHelper) FileProvider(androidx.core.content.FileProvider) Pattern(java.util.regex.Pattern) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Typeface(android.graphics.Typeface) Context(android.content.Context) StaticLayout(android.text.StaticLayout) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) TextSelectionHelper(org.telegram.ui.Cells.TextSelectionHelper) ReactedUsersListView(org.telegram.ui.Components.ReactedUsersListView) KeyEvent(android.view.KeyEvent) VoIPService(org.telegram.messenger.voip.VoIPService) Theme(org.telegram.ui.ActionBar.Theme) PagerAdapter(androidx.viewpager.widget.PagerAdapter) ViewOutlineProvider(android.view.ViewOutlineProvider) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Intent(android.content.Intent) HashMap(java.util.HashMap) ActionBarLayout(org.telegram.ui.ActionBar.ActionBarLayout) TranslateAlert(org.telegram.ui.Components.TranslateAlert) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MotionEvent(android.view.MotionEvent) AnimatorSet(android.animation.AnimatorSet) MediaDataController(org.telegram.messenger.MediaDataController) DialogInterface(android.content.DialogInterface) Browser(org.telegram.messenger.browser.Browser) FireworksOverlay(org.telegram.ui.Components.FireworksOverlay) LongSparseArray(androidx.collection.LongSparseArray) FileWriter(java.io.FileWriter) FileLog(org.telegram.messenger.FileLog) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement) MessagesController(org.telegram.messenger.MessagesController) NumberTextView(org.telegram.ui.Components.NumberTextView) ChatAttachAlert(org.telegram.ui.Components.ChatAttachAlert) InviteMembersBottomSheet(org.telegram.ui.Components.InviteMembersBottomSheet) Collections(java.util.Collections) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) InputStream(java.io.InputStream) MediaController(org.telegram.messenger.MediaController) URLSpanMono(org.telegram.ui.Components.URLSpanMono) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) TLRPC(org.telegram.tgnet.TLRPC) URLSpanNoUnderline(org.telegram.ui.Components.URLSpanNoUnderline) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) URLSpanUserMention(org.telegram.ui.Components.URLSpanUserMention) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) ChatThemeBottomSheet(org.telegram.ui.Components.ChatThemeBottomSheet) EmbedBottomSheet(org.telegram.ui.Components.EmbedBottomSheet) InviteMembersBottomSheet(org.telegram.ui.Components.InviteMembersBottomSheet) MessageObject(org.telegram.messenger.MessageObject) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement)

Aggregations

URLSpanReplacement (org.telegram.ui.Components.URLSpanReplacement)7 TLRPC (org.telegram.tgnet.TLRPC)6 TextStyleSpan (org.telegram.ui.Components.TextStyleSpan)6 Paint (android.graphics.Paint)5 SpannableStringBuilder (android.text.SpannableStringBuilder)5 URLSpanUserMention (org.telegram.ui.Components.URLSpanUserMention)5 Spannable (android.text.Spannable)4 TextPaint (android.text.TextPaint)4 CharacterStyle (android.text.style.CharacterStyle)4 ArrayList (java.util.ArrayList)4 SuppressLint (android.annotation.SuppressLint)3 Activity (android.app.Activity)3 Context (android.content.Context)3 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 Bitmap (android.graphics.Bitmap)3 BitmapFactory (android.graphics.BitmapFactory)3 BitmapShader (android.graphics.BitmapShader)3 Canvas (android.graphics.Canvas)3 Color (android.graphics.Color)3