Java Code Examples for org.telegram.messenger.Emoji#replaceEmoji()

The following examples show how to use org.telegram.messenger.Emoji#replaceEmoji() . 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: ChatActivityEnterView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void replaceWithText(int start, int len, CharSequence text, boolean parseEmoji)
{
    try
    {
        SpannableStringBuilder builder = new SpannableStringBuilder(messageEditText.getText());
        builder.replace(start, start + len, text);
        if (parseEmoji)
        {
            Emoji.replaceEmoji(builder, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
        }
        messageEditText.setText(builder);
        messageEditText.setSelection(start + text.length());
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
}
 
Example 3
Source File: PhotoViewerCaptionEnterView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void replaceWithText(int start, int len, CharSequence text, boolean parseEmoji) {
    try {
        SpannableStringBuilder builder = new SpannableStringBuilder(messageEditText.getText());
        builder.replace(start, start + len, text);
        if (parseEmoji) {
            Emoji.replaceEmoji(builder, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
        }
        messageEditText.setText(builder);
        if (start + text.length() <= messageEditText.length()) {
            messageEditText.setSelection(start + text.length());
        } else {
            messageEditText.setSelection(messageEditText.length());
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 4
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 5
Source File: ChatActivityEnterView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void replaceWithText(int start, int len, CharSequence text, boolean parseEmoji)
{
    try
    {
        SpannableStringBuilder builder = new SpannableStringBuilder(messageEditText.getText());
        builder.replace(start, start + len, text);
        if (parseEmoji)
        {
            Emoji.replaceEmoji(builder, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
        }
        messageEditText.setText(builder);
        messageEditText.setSelection(start + text.length());
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
}
 
Example 6
Source File: PhotoViewerCaptionEnterView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void replaceWithText(int start, int len, CharSequence text, boolean parseEmoji) {
    try {
        SpannableStringBuilder builder = new SpannableStringBuilder(messageEditText.getText());
        builder.replace(start, start + len, text);
        if (parseEmoji) {
            Emoji.replaceEmoji(builder, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
        }
        messageEditText.setText(builder);
        if (start + text.length() <= messageEditText.length()) {
            messageEditText.setSelection(start + text.length());
        } else {
            messageEditText.setSelection(messageEditText.length());
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 7
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 8
Source File: PhotoViewerCaptionEnterView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void replaceWithText(int start, int len, CharSequence text, boolean parseEmoji) {
    try {
        SpannableStringBuilder builder = new SpannableStringBuilder(messageEditText.getText());
        builder.replace(start, start + len, text);
        if (parseEmoji) {
            Emoji.replaceEmoji(builder, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
        }
        messageEditText.setText(builder);
        if (start + text.length() <= messageEditText.length()) {
            messageEditText.setSelection(start + text.length());
        } else {
            messageEditText.setSelection(messageEditText.length());
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 9
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 10
Source File: PhotoViewerCaptionEnterView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void replaceWithText(int start, int len, CharSequence text, boolean parseEmoji) {
    try {
        SpannableStringBuilder builder = new SpannableStringBuilder(messageEditText.getText());
        builder.replace(start, start + len, text);
        if (parseEmoji) {
            Emoji.replaceEmoji(builder, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
        }
        messageEditText.setText(builder);
        if (start + text.length() <= messageEditText.length()) {
            messageEditText.setSelection(start + text.length());
        } else {
            messageEditText.setSelection(messageEditText.length());
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 11
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 12
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 13
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 14
Source File: DialogCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private CharSequence formatArchivedDialogNames() {
    ArrayList<TLRPC.Dialog> dialogs = MessagesController.getInstance(currentAccount).getDialogs(currentDialogFolderId);
    currentDialogFolderDialogsCount = dialogs.size();
    SpannableStringBuilder builder = new SpannableStringBuilder();
    for (int a = 0, N = dialogs.size(); a < N; a++) {
        TLRPC.Dialog dialog = dialogs.get(a);
        TLRPC.User currentUser = null;
        TLRPC.Chat currentChat = null;
        if (DialogObject.isSecretDialogId(dialog.id)) {
            TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat((int) (dialog.id >> 32));
            if (encryptedChat != null) {
                currentUser = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id);
            }
        } else {
            int lowerId = (int) dialog.id;
            if (lowerId > 0) {
                currentUser = MessagesController.getInstance(currentAccount).getUser(lowerId);
            } else {
                currentChat = MessagesController.getInstance(currentAccount).getChat(-lowerId);
            }
        }
        String title;
        if (currentChat != null) {
            title = currentChat.title.replace('\n', ' ');
        } else if (currentUser != null) {
            if (UserObject.isDeleted(currentUser)) {
                title = LocaleController.getString("HiddenName", R.string.HiddenName);
            } else {
                title = ContactsController.formatName(currentUser.first_name, currentUser.last_name).replace('\n', ' ');
            }
        } else {
            continue;
        }
        if (builder.length() > 0) {
            builder.append(", ");
        }
        int boldStart = builder.length();
        int boldEnd = boldStart + title.length();
        builder.append(title);
        if (dialog.unread_count > 0) {
            builder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, Theme.getColor(Theme.key_chats_nameArchived)), boldStart, boldEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (builder.length() > 150) {
            break;
        }
    }
    return Emoji.replaceEmoji(builder, Theme.dialogs_messagePaint[paintIndex].getFontMetricsInt(), AndroidUtilities.dp(17), false);
}
 
Example 15
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);
}
 
Example 16
Source File: DialogCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private CharSequence formatArchivedDialogNames() {
    ArrayList<TLRPC.Dialog> dialogs = MessagesController.getInstance(currentAccount).getDialogs(currentDialogFolderId);
    currentDialogFolderDialogsCount = dialogs.size();
    SpannableStringBuilder builder = new SpannableStringBuilder();
    for (int a = 0, N = dialogs.size(); a < N; a++) {
        TLRPC.Dialog dialog = dialogs.get(a);
        TLRPC.User currentUser = null;
        TLRPC.Chat currentChat = null;
        if (DialogObject.isSecretDialogId(dialog.id)) {
            TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat((int) (dialog.id >> 32));
            if (encryptedChat != null) {
                currentUser = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id);
            }
        } else {
            int lowerId = (int) dialog.id;
            if (lowerId > 0) {
                currentUser = MessagesController.getInstance(currentAccount).getUser(lowerId);
            } else {
                currentChat = MessagesController.getInstance(currentAccount).getChat(-lowerId);
            }
        }
        String title;
        if (currentChat != null) {
            title = currentChat.title.replace('\n', ' ');
        } else if (currentUser != null) {
            if (UserObject.isDeleted(currentUser)) {
                title = LocaleController.getString("HiddenName", R.string.HiddenName);
            } else {
                title = ContactsController.formatName(currentUser.first_name, currentUser.last_name).replace('\n', ' ');
            }
        } else {
            continue;
        }
        if (builder.length() > 0) {
            builder.append(", ");
        }
        int boldStart = builder.length();
        int boldEnd = boldStart + title.length();
        builder.append(title);
        if (dialog.unread_count > 0) {
            builder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, Theme.getColor(Theme.key_chats_nameArchived)), boldStart, boldEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (builder.length() > 150) {
            break;
        }
    }
    return Emoji.replaceEmoji(builder, Theme.dialogs_messagePaint[paintIndex].getFontMetricsInt(), AndroidUtilities.dp(17), false);
}