Java Code Examples for org.telegram.messenger.MessageObject#addLinks()

The following examples show how to use org.telegram.messenger.MessageObject#addLinks() . 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: AboutLinkCell.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setTextAndIcon(String text, int resId, boolean parseLinks) {
    if (TextUtils.isEmpty(text) || text != null && oldText != null && text.equals(oldText)) {
        return;
    }
    oldText = text;
    stringBuilder = new SpannableStringBuilder(oldText);
    if (parseLinks) {
        MessageObject.addLinks(false, stringBuilder, false);
    }
    Emoji.replaceEmoji(stringBuilder, Theme.profile_aboutTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
    requestLayout();
    if (resId == 0) {
        imageView.setImageDrawable(null);
    } else {
        imageView.setImageResource(resId);
    }
}
 
Example 2
Source File: AboutLinkCell.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setTextAndIcon(String text, int resId, boolean parseLinks) {
    if (TextUtils.isEmpty(text) || text != null && oldText != null && text.equals(oldText)) {
        return;
    }
    oldText = text;
    stringBuilder = new SpannableStringBuilder(oldText);
    if (parseLinks) {
        MessageObject.addLinks(false, stringBuilder, false);
    }
    Emoji.replaceEmoji(stringBuilder, Theme.profile_aboutTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
    requestLayout();
    if (resId == 0) {
        imageView.setImageDrawable(null);
    } else {
        imageView.setImageResource(resId);
    }
}
 
Example 3
Source File: AboutLinkCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setTextAndValue(String text, String value, boolean parseLinks) {
    if (TextUtils.isEmpty(text) || text != null && text.equals(oldText)) {
        return;
    }
    oldText = text;
    stringBuilder = new SpannableStringBuilder(oldText);
    if (parseLinks) {
        MessageObject.addLinks(false, stringBuilder, false, false);
    }
    Emoji.replaceEmoji(stringBuilder, Theme.profile_aboutTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
    if (TextUtils.isEmpty(value)) {
        valueTextView.setVisibility(GONE);
    } else {
        valueTextView.setText(value);
        valueTextView.setVisibility(VISIBLE);
    }
    requestLayout();
}
 
Example 4
Source File: AboutLinkCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setTextAndValue(String text, String value, boolean parseLinks) {
    if (TextUtils.isEmpty(text) || text != null && text.equals(oldText)) {
        return;
    }
    oldText = text;
    stringBuilder = new SpannableStringBuilder(oldText);
    if (parseLinks) {
        MessageObject.addLinks(false, stringBuilder, false, false);
    }
    Emoji.replaceEmoji(stringBuilder, Theme.profile_aboutTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
    if (TextUtils.isEmpty(value)) {
        valueTextView.setVisibility(GONE);
    } else {
        valueTextView.setText(value);
        valueTextView.setVisibility(VISIBLE);
    }
    requestLayout();
}
 
Example 5
Source File: BotHelpCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setText(String text) {
    if (text == null || text.length() == 0) {
        setVisibility(GONE);
        return;
    }
    if (text != null && oldText != null && text.equals(oldText)) {
        return;
    }
    oldText = text;
    setVisibility(VISIBLE);
    int maxWidth;
    if (AndroidUtilities.isTablet()) {
        maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
    } else {
        maxWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
    }
    String lines[] = text.split("\n");
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
    String help = LocaleController.getString("BotInfoTitle", R.string.BotInfoTitle);
    stringBuilder.append(help);
    stringBuilder.append("\n\n");
    for (int a = 0; a < lines.length; a++) {
        stringBuilder.append(lines[a].trim());
        if (a != lines.length - 1) {
            stringBuilder.append("\n");
        }
    }
    MessageObject.addLinks(false, stringBuilder);
    stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), 0, help.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    Emoji.replaceEmoji(stringBuilder, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
    try {
        textLayout = new StaticLayout(stringBuilder, Theme.chat_msgTextPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        width = 0;
        height = textLayout.getHeight() + AndroidUtilities.dp(4 + 18);
        int count = textLayout.getLineCount();
        for (int a = 0; a < count; a++) {
            width = (int) Math.ceil(Math.max(width, textLayout.getLineWidth(a) + textLayout.getLineLeft(a)));
        }
        if (width > maxWidth) {
            width = maxWidth;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    width += AndroidUtilities.dp(4 + 18);
}
 
Example 6
Source File: BotHelpCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setText(String text) {
    if (text == null || text.length() == 0) {
        setVisibility(GONE);
        return;
    }
    if (text != null && oldText != null && text.equals(oldText)) {
        return;
    }
    oldText = text;
    setVisibility(VISIBLE);
    int maxWidth;
    if (AndroidUtilities.isTablet()) {
        maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
    } else {
        maxWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
    }
    String lines[] = text.split("\n");
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
    String help = LocaleController.getString("BotInfoTitle", R.string.BotInfoTitle);
    stringBuilder.append(help);
    stringBuilder.append("\n\n");
    for (int a = 0; a < lines.length; a++) {
        stringBuilder.append(lines[a].trim());
        if (a != lines.length - 1) {
            stringBuilder.append("\n");
        }
    }
    MessageObject.addLinks(false, stringBuilder);
    stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), 0, help.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    Emoji.replaceEmoji(stringBuilder, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
    try {
        textLayout = new StaticLayout(stringBuilder, Theme.chat_msgTextPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        width = 0;
        height = textLayout.getHeight() + AndroidUtilities.dp(4 + 18);
        int count = textLayout.getLineCount();
        for (int a = 0; a < count; a++) {
            width = (int) Math.ceil(Math.max(width, textLayout.getLineWidth(a) + textLayout.getLineLeft(a)));
        }
        if (width > maxWidth) {
            width = maxWidth;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    width += AndroidUtilities.dp(4 + 18);
}
 
Example 7
Source File: BotHelpCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void setText(String text) {
    if (text == null || text.length() == 0) {
        setVisibility(GONE);
        return;
    }
    if (text != null && text.equals(oldText)) {
        return;
    }
    oldText = text;
    setVisibility(VISIBLE);
    int maxWidth;
    if (AndroidUtilities.isTablet()) {
        maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
    } else {
        maxWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
    }
    String[] lines = text.split("\n");
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
    String help = LocaleController.getString("BotInfoTitle", R.string.BotInfoTitle);
    stringBuilder.append(help);
    stringBuilder.append("\n\n");
    for (int a = 0; a < lines.length; a++) {
        stringBuilder.append(lines[a].trim());
        if (a != lines.length - 1) {
            stringBuilder.append("\n");
        }
    }
    MessageObject.addLinks(false, stringBuilder);
    stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), 0, help.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    Emoji.replaceEmoji(stringBuilder, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
    try {
        textLayout = new StaticLayout(stringBuilder, Theme.chat_msgTextPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        width = 0;
        height = textLayout.getHeight() + AndroidUtilities.dp(4 + 18);
        int count = textLayout.getLineCount();
        for (int a = 0; a < count; a++) {
            width = (int) Math.ceil(Math.max(width, textLayout.getLineWidth(a) + textLayout.getLineLeft(a)));
        }
        if (width > maxWidth) {
            width = maxWidth;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    width += AndroidUtilities.dp(4 + 18);
}
 
Example 8
Source File: BotHelpCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void setText(String text) {
    if (text == null || text.length() == 0) {
        setVisibility(GONE);
        return;
    }
    if (text != null && text.equals(oldText)) {
        return;
    }
    oldText = text;
    setVisibility(VISIBLE);
    int maxWidth;
    if (AndroidUtilities.isTablet()) {
        maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
    } else {
        maxWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
    }
    String[] lines = text.split("\n");
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
    String help = LocaleController.getString("BotInfoTitle", R.string.BotInfoTitle);
    stringBuilder.append(help);
    stringBuilder.append("\n\n");
    for (int a = 0; a < lines.length; a++) {
        stringBuilder.append(lines[a].trim());
        if (a != lines.length - 1) {
            stringBuilder.append("\n");
        }
    }
    MessageObject.addLinks(false, stringBuilder);
    stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), 0, help.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    Emoji.replaceEmoji(stringBuilder, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
    try {
        textLayout = new StaticLayout(stringBuilder, Theme.chat_msgTextPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        width = 0;
        height = textLayout.getHeight() + AndroidUtilities.dp(4 + 18);
        int count = textLayout.getLineCount();
        for (int a = 0; a < count; a++) {
            width = (int) Math.ceil(Math.max(width, textLayout.getLineWidth(a) + textLayout.getLineLeft(a)));
        }
        if (width > maxWidth) {
            width = maxWidth;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    width += AndroidUtilities.dp(4 + 18);
}