Java Code Examples for org.telegram.tgnet.TLRPC#DocumentAttribute

The following examples show how to use org.telegram.tgnet.TLRPC#DocumentAttribute . 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: FileLoader.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static String getDocumentFileName(TLRPC.Document document) {
    String fileName = null;
    if (document != null) {
        if (document.file_name != null) {
            fileName = document.file_name;
        } else {
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(a);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeFilename) {
                    fileName = documentAttribute.file_name;
                }
            }
        }
    }
    fileName = fixFileName(fileName);
    return fileName != null ? fileName : "";
}
 
Example 2
Source File: FileLoader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static String getDocumentFileName(TLRPC.Document document)
{
    String fileName = null;
    if (document != null)
    {
        if (document.file_name != null)
        {
            fileName = document.file_name;
        }
        else
        {
            for (int a = 0; a < document.attributes.size(); a++)
            {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(a);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeFilename)
                {
                    fileName = documentAttribute.file_name;
                }
            }
        }
    }
    fileName = fixFileName(fileName);
    return fileName != null ? fileName : "";
}
 
Example 3
Source File: StickerCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info){
    super.onInitializeAccessibilityNodeInfo(info);
    if (sticker == null)
        return;
    String emoji = null;
    for (int a = 0; a < sticker.attributes.size(); a++) {
        TLRPC.DocumentAttribute attribute = sticker.attributes.get(a);
        if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
            emoji = attribute.alt != null && attribute.alt.length() > 0 ? attribute.alt : null;
        }
    }
    if (emoji != null)
        info.setText(emoji + " " + LocaleController.getString("AttachSticker", R.string.AttachSticker));
    else
        info.setText(LocaleController.getString("AttachSticker", R.string.AttachSticker));
    info.setEnabled(true);
}
 
Example 4
Source File: PhotoPaintView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private StickerPosition calculateStickerPosition(TLRPC.Document document) {
TLRPC.TL_maskCoords maskCoords = null;

for (int a = 0; a < document.attributes.size(); a++) {
    TLRPC.DocumentAttribute attribute = document.attributes.get(a);
    if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
        maskCoords = attribute.mask_coords;
        break;
    }
}

StickerPosition defaultPosition = new StickerPosition(centerPositionForEntity(), 0.75f, 0.0f);
/*
if (maskCoords == null || faces == null || faces.size() == 0) {
    return defaultPosition;
} else {
    int anchor = maskCoords.n;

    PhotoFace face = getRandomFaceWithVacantAnchor(anchor, document.id, maskCoords);
    if (face == null) {*/
        return defaultPosition;
    }
 
Example 5
Source File: StickersAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void addStickersToResult(ArrayList<TLRPC.Document> documents, Object parent) {
    if (documents == null || documents.isEmpty()) {
        return;
    }
    for (int a = 0, size = documents.size(); a < size; a++) {
        TLRPC.Document document = documents.get(a);
        String key = document.dc_id + "_" + document.id;
        if (stickersMap != null && stickersMap.containsKey(key)) {
            continue;
        }
        if (stickers == null) {
            stickers = new ArrayList<>();
            stickersMap = new HashMap<>();
        }
        for (int b = 0, size2 = document.attributes.size(); b < size2; b++) {
            TLRPC.DocumentAttribute attribute = document.attributes.get(b);
            if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
                parent = attribute.stickerset;
                break;
            }
        }
        stickers.add(new StickerResult(document, parent));
        stickersMap.put(key, document);
    }
}
 
Example 6
Source File: StickerEmojiCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    String descr = LocaleController.getString("AttachSticker", R.string.AttachSticker);
    for (int a = 0; a < sticker.attributes.size(); a++) {
        TLRPC.DocumentAttribute attribute = sticker.attributes.get(a);
        if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
            if (attribute.alt != null && attribute.alt.length() > 0) {
                emojiTextView.setText(Emoji.replaceEmoji(attribute.alt, emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                descr = attribute.alt + " " + descr;
            }
            break;
        }
    }
    info.setContentDescription(descr);
    info.setEnabled(true);
}
 
Example 7
Source File: StickerCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info){
    super.onInitializeAccessibilityNodeInfo(info);
    if (sticker == null)
        return;
    String emoji = null;
    for (int a = 0; a < sticker.attributes.size(); a++) {
        TLRPC.DocumentAttribute attribute = sticker.attributes.get(a);
        if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
            emoji = attribute.alt != null && attribute.alt.length() > 0 ? attribute.alt : null;
        }
    }
    if (emoji != null)
        info.setText(emoji + " " + LocaleController.getString("AttachSticker", R.string.AttachSticker));
    else
        info.setText(LocaleController.getString("AttachSticker", R.string.AttachSticker));
    info.setEnabled(true);
}
 
Example 8
Source File: FileLoader.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static String getDocumentFileName(TLRPC.Document document) {
    String fileName = null;
    if (document != null) {
        if (document.file_name != null) {
            fileName = document.file_name;
        } else {
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(a);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeFilename) {
                    fileName = documentAttribute.file_name;
                }
            }
        }
    }
    fileName = fixFileName(fileName);
    return fileName != null ? fileName : "";
}
 
Example 9
Source File: StickerView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public StickerView(Context context, Point position, float angle, float scale, Size baseSize, TLRPC.Document sticker, Object parentObject) {
    super(context, position);
    setRotation(angle);
    setScale(scale);

    this.sticker = sticker;
    this.baseSize = baseSize;
    this.parentObject = parentObject;

    for (int a = 0; a < sticker.attributes.size(); a++) {
        TLRPC.DocumentAttribute attribute = sticker.attributes.get(a);
        if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
            if (attribute.mask_coords != null) {
                anchor = attribute.mask_coords.n;
            }
            break;
        }
    }

    containerView = new FrameLayoutDrawer(context);
    addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    centerImage.setAspectFit(true);
    centerImage.setInvalidateAll(true);
    centerImage.setParentView(containerView);
    TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(sticker.thumbs, 90);
    centerImage.setImage(ImageLocation.getForDocument(sticker), null, ImageLocation.getForDocument(thumb, sticker), null, "webp", parentObject, 1);

    updatePosition();
}
 
Example 10
Source File: StickerView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public StickerView(Context context, Point position, float angle, float scale, Size baseSize, TLRPC.Document sticker) {
    super(context, position);
    setRotation(angle);
    setScale(scale);

    this.sticker = sticker;
    this.baseSize = baseSize;

    for (int a = 0; a < sticker.attributes.size(); a++) {
        TLRPC.DocumentAttribute attribute = sticker.attributes.get(a);
        if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
            if (attribute.mask_coords != null)
                anchor = attribute.mask_coords.n;
            break;
        }
    }

    containerView = new FrameLayoutDrawer(context);
    addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    centerImage.setAspectFit(true);
    centerImage.setInvalidateAll(true);
    centerImage.setParentView(containerView);
    centerImage.setImage(sticker, null, sticker.thumb.location, null, "webp", 1);

    updatePosition();
}
 
Example 11
Source File: PopupAudioView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void updateProgress() {
    if (currentMessageObject == null) {
        return;
    }

    if (!seekBar.isDragging()) {
        seekBar.setProgress(currentMessageObject.audioProgress);
    }

    int duration = 0;
    if (!MediaController.getInstance().isPlayingMessage(currentMessageObject)) {
        for (int a = 0; a < currentMessageObject.getDocument().attributes.size(); a++) {
            TLRPC.DocumentAttribute attribute = currentMessageObject.getDocument().attributes.get(a);
            if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                duration = attribute.duration;
                break;
            }
        }
    } else {
        duration = currentMessageObject.audioProgressSec;
    }
    String timeString = AndroidUtilities.formatLongDuration(duration);
    if (lastTimeString == null || lastTimeString != null && !lastTimeString.equals(timeString)) {
        timeWidth = (int)Math.ceil(timePaint.measureText(timeString));
        timeLayout = new StaticLayout(timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    }
    invalidate();
}
 
Example 12
Source File: StickersAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean isValidSticker(TLRPC.Document document, String emoji) {
    for (int b = 0, size2 = document.attributes.size(); b < size2; b++) {
        TLRPC.DocumentAttribute attribute = document.attributes.get(b);
        if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
            if (attribute.alt != null && attribute.alt.contains(emoji)) {
                return true;
            }
            break;
        }
    }
    return false;
}
 
Example 13
Source File: StickerEmojiCell.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void setSticker(TLRPC.Document document, boolean showEmoji) {
    if (document != null) {
        sticker = document;
        if (document.thumb != null) {
            imageView.setImage(document.thumb.location, null, "webp", null);
        }

        if (showEmoji) {
            boolean set = false;
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = document.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
                    if (attribute.alt != null && attribute.alt.length() > 0) {
                        emojiTextView.setText(Emoji.replaceEmoji(attribute.alt, emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                        set = true;
                    }
                    break;
                }
            }
            if (!set) {
                emojiTextView.setText(Emoji.replaceEmoji(DataQuery.getInstance(currentAccount).getEmojiForSticker(sticker.id), emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
            }
            emojiTextView.setVisibility(VISIBLE);
        } else {
            emojiTextView.setVisibility(INVISIBLE);
        }
    }
}
 
Example 14
Source File: PopupAudioView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void updateProgress() {
    if (currentMessageObject == null) {
        return;
    }

    if (!seekBar.isDragging()) {
        seekBar.setProgress(currentMessageObject.audioProgress);
    }

    int duration = 0;
    if (!MediaController.getInstance().isPlayingMessage(currentMessageObject)) {
        for (int a = 0; a < currentMessageObject.getDocument().attributes.size(); a++) {
            TLRPC.DocumentAttribute attribute = currentMessageObject.getDocument().attributes.get(a);
            if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                duration = attribute.duration;
                break;
            }
        }
    } else {
        duration = currentMessageObject.audioProgressSec;
    }
    String timeString = String.format("%02d:%02d", duration / 60, duration % 60);
    if (lastTimeString == null || lastTimeString != null && !lastTimeString.equals(timeString)) {
        timeWidth = (int)Math.ceil(timePaint.measureText(timeString));
        timeLayout = new StaticLayout(timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    }
    invalidate();
}
 
Example 15
Source File: StickerView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public StickerView(Context context, Point position, float angle, float scale, Size baseSize, TLRPC.Document sticker) {
    super(context, position);
    setRotation(angle);
    setScale(scale);

    this.sticker = sticker;
    this.baseSize = baseSize;

    for (int a = 0; a < sticker.attributes.size(); a++) {
        TLRPC.DocumentAttribute attribute = sticker.attributes.get(a);
        if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
            if (attribute.mask_coords != null)
                anchor = attribute.mask_coords.n;
            break;
        }
    }

    containerView = new FrameLayoutDrawer(context);
    addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    centerImage.setAspectFit(true);
    centerImage.setInvalidateAll(true);
    centerImage.setParentView(containerView);
    centerImage.setImage(sticker, null, sticker.thumb.location, null, "webp", 1);

    updatePosition();
}
 
Example 16
Source File: SharedDocumentCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void setDocument(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    message = messageObject;
    loaded = false;
    loading = false;

    TLRPC.Document document = messageObject.getDocument();
    if (messageObject != null && document != null) {
        int idx;
        String name = null;
        if (messageObject.isMusic()) {
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = document.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                    if (attribute.performer != null && attribute.performer.length() != 0 || attribute.title != null && attribute.title.length() != 0) {
                        name = messageObject.getMusicAuthor() + " - " + messageObject.getMusicTitle();
                    }
                }
            }
        }
        String fileName = FileLoader.getDocumentFileName(document);
        if (name == null) {
            name = fileName;
        }
        nameTextView.setText(name);
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        placeholderImageView.setImageResource(AndroidUtilities.getThumbForNameOrMime(fileName, document.mime_type, false));
        extTextView.setText((idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toLowerCase());

        TLRPC.PhotoSize bigthumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 40);
        if (thumb == bigthumb) {
            bigthumb = null;
        }
        if (thumb instanceof TLRPC.TL_photoSizeEmpty || thumb == null) {
            thumbImageView.setVisibility(INVISIBLE);
            thumbImageView.setImageBitmap(null);
            extTextView.setAlpha(1.0f);
            placeholderImageView.setAlpha(1.0f);
        } else {
            thumbImageView.getImageReceiver().setNeedsQualityThumb(bigthumb == null);
            thumbImageView.getImageReceiver().setShouldGenerateQualityThumb(bigthumb == null);

            thumbImageView.setVisibility(VISIBLE);
            thumbImageView.setImage(ImageLocation.getForDocument(bigthumb, document), "40_40", ImageLocation.getForDocument(thumb, document), "40_40_b", null, 0, 1, messageObject);
        }
        long date = (long) messageObject.messageOwner.date * 1000;
        dateTextView.setText(String.format("%s, %s", AndroidUtilities.formatFileSize(document.size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)))));
    } else {
        nameTextView.setText("");
        extTextView.setText("");
        dateTextView.setText("");
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        extTextView.setAlpha(1.0f);
        placeholderImageView.setAlpha(1.0f);
        thumbImageView.setVisibility(INVISIBLE);
        thumbImageView.setImageBitmap(null);
    }

    setWillNotDraw(!needDivider);
    progressView.setProgress(0, false);
    updateFileExistIcon();
}
 
Example 17
Source File: SharedPhotoVideoCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setItem(int a, int index, MessageObject messageObject) {
    messageObjects[a] = messageObject;
    indeces[a] = index;

    if (messageObject != null) {
        photoVideoViews[a].setVisibility(VISIBLE);

        PhotoVideoView photoVideoView = photoVideoViews[a];
        photoVideoView.imageView.getImageReceiver().setParentMessageObject(messageObject);
        photoVideoView.imageView.getImageReceiver().setVisible(!PhotoViewer.isShowingImage(messageObject), false);
        if (messageObject.isVideo()) {
            photoVideoView.videoInfoContainer.setVisibility(VISIBLE);
            int duration = 0;
            for (int b = 0; b < messageObject.getDocument().attributes.size(); b++) {
                TLRPC.DocumentAttribute attribute = messageObject.getDocument().attributes.get(b);
                if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
                    duration = attribute.duration;
                    break;
                }
            }
            int minutes = duration / 60;
            int seconds = duration - minutes * 60;
            photoVideoView.videoTextView.setText(String.format("%d:%02d", minutes, seconds));
            if (messageObject.getDocument().thumb != null) {
                TLRPC.FileLocation location = messageObject.getDocument().thumb.location;
                photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, location, "b", null, 0);
            } else {
                photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
            }
        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
            photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
            TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
            photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, photoSize.location, "b", null, 0);
        } else {
            photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
            photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
        }
    } else {
        photoVideoViews[a].clearAnimation();
        photoVideoViews[a].setVisibility(INVISIBLE);
        messageObjects[a] = null;
    }
}
 
Example 18
Source File: SharedDocumentCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setDocument(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    message = messageObject;
    loaded = false;
    loading = false;

    if (messageObject != null && messageObject.getDocument() != null) {
        int idx;
        String name = null;
        if (messageObject.isMusic()) {
            TLRPC.Document document;
            if (messageObject.type == 0) {
                document = messageObject.messageOwner.media.webpage.document;
            } else {
                document = messageObject.messageOwner.media.document;
            }
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = document.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                    if (attribute.performer != null && attribute.performer.length() != 0 || attribute.title != null && attribute.title.length() != 0) {
                        name = messageObject.getMusicAuthor() + " - " + messageObject.getMusicTitle();
                    }
                }
            }
        }
        String fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
        if (name == null) {
            name = fileName;
        }
        nameTextView.setText(name);
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        placeholderImageView.setImageResource(getThumbForNameOrMime(fileName, messageObject.getDocument().mime_type));
        extTextView.setText((idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toLowerCase());
        if (messageObject.getDocument().thumb instanceof TLRPC.TL_photoSizeEmpty || messageObject.getDocument().thumb == null) {
            thumbImageView.setVisibility(INVISIBLE);
            thumbImageView.setImageBitmap(null);
        } else {
            thumbImageView.setVisibility(VISIBLE);
            thumbImageView.setImage(messageObject.getDocument().thumb.location, "40_40", (Drawable) null);
        }
        long date = (long) messageObject.messageOwner.date * 1000;
        dateTextView.setText(String.format("%s, %s", AndroidUtilities.formatFileSize(messageObject.getDocument().size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)))));
    } else {
        nameTextView.setText("");
        extTextView.setText("");
        dateTextView.setText("");
        placeholderImageView.setVisibility(VISIBLE);
        extTextView.setVisibility(VISIBLE);
        thumbImageView.setVisibility(INVISIBLE);
        thumbImageView.setImageBitmap(null);
    }

    setWillNotDraw(!needDivider);
    progressView.setProgress(0, false);
    updateFileExistIcon();
}
 
Example 19
Source File: StickerEmojiCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void setSticker(TLRPC.Document document, Object parent, String emoji, boolean showEmoji) {
    if (document != null) {
        sticker = document;
        parentObject = parent;
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90);
        if (MessageObject.canAutoplayAnimatedSticker(document)) {
            if (thumb != null) {
                imageView.setImage(ImageLocation.getForDocument(document), "80_80", ImageLocation.getForDocument(thumb, document), null, 0, parentObject);
            } else {
                imageView.setImage(ImageLocation.getForDocument(document), "80_80", null, null, parentObject);
            }
        } else {
            if (thumb != null) {
                imageView.setImage(ImageLocation.getForDocument(thumb, document), null, "webp", null, parentObject);
            } else {
                imageView.setImage(ImageLocation.getForDocument(document), null, "webp", null, parentObject);
            }
        }

        if (emoji != null) {
            emojiTextView.setText(Emoji.replaceEmoji(emoji, emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
            emojiTextView.setVisibility(VISIBLE);
        } else if (showEmoji) {
            boolean set = false;
            for (int a = 0; a < document.attributes.size(); a++) {
                TLRPC.DocumentAttribute attribute = document.attributes.get(a);
                if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
                    if (attribute.alt != null && attribute.alt.length() > 0) {
                        emojiTextView.setText(Emoji.replaceEmoji(attribute.alt, emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                        set = true;
                    }
                    break;
                }
            }
            if (!set) {
                emojiTextView.setText(Emoji.replaceEmoji(MediaDataController.getInstance(currentAccount).getEmojiForSticker(sticker.id), emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
            }
            emojiTextView.setVisibility(VISIBLE);
        } else {
            emojiTextView.setVisibility(INVISIBLE);
        }
    }
}
 
Example 20
Source File: SharedPhotoVideoCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setItem(int a, int index, MessageObject messageObject) {
    messageObjects[a] = messageObject;
    indeces[a] = index;

    if (messageObject != null) {
        photoVideoViews[a].setVisibility(VISIBLE);

        PhotoVideoView photoVideoView = photoVideoViews[a];
        photoVideoView.imageView.getImageReceiver().setParentMessageObject(messageObject);
        photoVideoView.imageView.getImageReceiver().setVisible(!PhotoViewer.isShowingImage(messageObject), false);
        if (messageObject.isVideo()) {
            photoVideoView.videoInfoContainer.setVisibility(VISIBLE);
            int duration = 0;
            for (int b = 0; b < messageObject.getDocument().attributes.size(); b++) {
                TLRPC.DocumentAttribute attribute = messageObject.getDocument().attributes.get(b);
                if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
                    duration = attribute.duration;
                    break;
                }
            }
            int minutes = duration / 60;
            int seconds = duration - minutes * 60;
            photoVideoView.videoTextView.setText(String.format("%d:%02d", minutes, seconds));
            if (messageObject.getDocument().thumb != null) {
                TLRPC.FileLocation location = messageObject.getDocument().thumb.location;
                photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, location, "b", null, 0);
            } else {
                photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
            }
        } else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
            photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
            TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
            photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, photoSize.location, "b", null, 0);
        } else {
            photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
            photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
        }
    } else {
        photoVideoViews[a].clearAnimation();
        photoVideoViews[a].setVisibility(INVISIBLE);
        messageObjects[a] = null;
    }
}