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

The following examples show how to use org.telegram.tgnet.TLRPC#Document . 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: AnimatedFileDrawable.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public AnimatedFileDrawable(File file, boolean createDecoder, long streamSize, TLRPC.Document document, Object parentObject, int account, boolean preview) {
    path = file;
    streamFileSize = streamSize;
    currentAccount = account;
    getPaint().setFlags(Paint.FILTER_BITMAP_FLAG);
    if (streamSize != 0 && document != null) {
        stream = new AnimatedFileDrawableStream(document, parentObject, account, preview);
    }
    if (createDecoder) {
        nativePtr = createDecoder(file.getAbsolutePath(), metaData, currentAccount, streamFileSize, stream, preview);
        if (nativePtr != 0 && (metaData[0] > 3840 || metaData[1] > 3840)) {
            destroyDecoder(nativePtr);
            nativePtr = 0;
        }
        decoderCreated = true;
    }
}
 
Example 2
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 3
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 4
Source File: FileLoader.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static String getDocumentExtension(TLRPC.Document document) {
    String fileName = getDocumentFileName(document);
    int idx = fileName.lastIndexOf('.');
    String ext = null;
    if (idx != -1) {
        ext = fileName.substring(idx + 1);
    }
    if (ext == null || ext.length() == 0) {
        ext = document.mime_type;
    }
    if (ext == null) {
        ext = "";
    }
    ext = ext.toUpperCase();
    return ext;
}
 
Example 5
Source File: StickersAdapter.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void addStickersToResult(ArrayList<TLRPC.Document> documents) {
    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<>();
        }
        stickers.add(document);
        stickersMap.put(key, document);
    }
}
 
Example 6
Source File: TrendingStickersLayout.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch (holder.getItemViewType()) {
        case 0:
            TLRPC.Document sticker = (TLRPC.Document) cache.get(position);
            ((StickerEmojiCell) holder.itemView).setSticker(sticker, positionsToSets.get(position), false);
            break;
        case 1:
            ((EmptyCell) holder.itemView).setHeight(AndroidUtilities.dp(82));
            break;
        case 2:
        case 5:
            bindStickerSetCell(holder.itemView, position, false);
            break;
        case 4:
            ((GraySectionCell) holder.itemView).setText(LocaleController.getString("OtherStickers", R.string.OtherStickers));
            break;
    }
}
 
Example 7
Source File: AudioPlayerCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setMessageObject(MessageObject messageObject) {
    currentMessageObject = messageObject;
    TLRPC.Document document = messageObject.getDocument();
    TLRPC.PhotoSize thumb = document != null ? FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90) : null;
    if (thumb instanceof TLRPC.TL_photoSize) {
        radialProgress.setImageOverlay(thumb, document, messageObject);
    } else {
        String artworkUrl = messageObject.getArtworkUrl(true);
        if (!TextUtils.isEmpty(artworkUrl)) {
            radialProgress.setImageOverlay(artworkUrl);
        } else {
            radialProgress.setImageOverlay(null, null, null);
        }
    }
    requestLayout();
    updateButtonState(false, false);
}
 
Example 8
Source File: ImageLocation.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static ImageLocation getForDocument(TLRPC.PhotoSize photoSize, TLRPC.Document document) {
    if (photoSize instanceof TLRPC.TL_photoStrippedSize) {
        ImageLocation imageLocation = new ImageLocation();
        imageLocation.photoSize = photoSize;
        return imageLocation;
    } else if (photoSize == null || document == null) {
        return null;
    }
    return getForPhoto(photoSize.location, photoSize.size, null, document, null, false, document.dc_id, null, photoSize.type);
}
 
Example 9
Source File: FileLoader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setLoadingVideo(TLRPC.Document document, boolean player, boolean schedule) {
    if (document == null) {
        return;
    }
    if (schedule) {
        AndroidUtilities.runOnUIThread(() -> setLoadingVideoInternal(document, player));
    } else {
        setLoadingVideoInternal(document, player);
    }
}
 
Example 10
Source File: ContextLinkCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setGif(TLRPC.Document document, Object parent, int date, boolean divider) {
    needDivider = divider;
    needShadow = false;
    currentDate = date;
    inlineResult = null;
    parentObject = parent;
    documentAttach = document;
    photoAttach = null;
    mediaWebpage = true;
    isForceGif = true;
    setAttachType();
    documentAttachType = DOCUMENT_ATTACH_TYPE_GIF;
    requestLayout();
    updateButtonState(false, false);
}
 
Example 11
Source File: StickerMasksView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void notifyDataSetChanged() {
    int width = getMeasuredWidth();
    if (width == 0) {
        width = AndroidUtilities.displaySize.x;
    }
    stickersPerRow = width / AndroidUtilities.dp(72);
    stickersLayoutManager.setSpanCount(stickersPerRow);
    rowStartPack.clear();
    packStartRow.clear();
    cache.clear();
    totalItems = 0;
    ArrayList<TLRPC.TL_messages_stickerSet> packs = stickerSets[currentType];
    for (int a = -1; a < packs.size(); a++) {
        ArrayList<TLRPC.Document> documents;
        TLRPC.TL_messages_stickerSet pack = null;
        int startRow = totalItems / stickersPerRow;
        if (a == -1) {
            documents = recentStickers[currentType];
        } else {
            pack = packs.get(a);
            documents = pack.documents;
            packStartRow.put(pack, startRow);
        }
        if (documents.isEmpty()) {
            continue;
        }
        int count = (int) Math.ceil(documents.size() / (float) stickersPerRow);
        for (int b = 0; b < documents.size(); b++) {
            cache.put(b + totalItems, documents.get(b));
        }
        totalItems += count * stickersPerRow;
        for (int b = 0; b < count; b++) {
            rowStartPack.put(startRow + b, pack);
        }
    }
    super.notifyDataSetChanged();
}
 
Example 12
Source File: FileLoader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void loadFile(TLRPC.Document document, Object parentObject, int priority, int cacheType) {
    if (document == null) {
        return;
    }
    if (cacheType == 0 && document.key != null) {
        cacheType = 1;
    }
    loadFile(document, null, null, null, null, parentObject, null, 0, priority, cacheType);
}
 
Example 13
Source File: FileLoader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
protected FileLoadOperation loadStreamFile(final FileLoadOperationStream stream, final TLRPC.Document document, final Object parentObject, final int offset, final boolean priority) {
    final CountDownLatch semaphore = new CountDownLatch(1);
    final FileLoadOperation[] result = new FileLoadOperation[1];
    fileLoaderQueue.postRunnable(() -> {
        result[0] = loadFileInternal(document, null, null, null, null, parentObject, null, 0, 1, stream, offset, priority,  0);
        semaphore.countDown();
    });
    try {
        semaphore.await();
    } catch (Exception e) {
        FileLog.e(e);
    }
    return result[0];
}
 
Example 14
Source File: StickersAlert.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getItemViewType(int position) {
    if (stickerSetCovereds != null) {
        Object object = cache.get(position);
        if (object != null) {
            if (object instanceof TLRPC.Document) {
                return 0;
            } else {
                return 2;
            }
        }
        return 1;
    }
    return 0;
}
 
Example 15
Source File: StickersAdapter.java    From Telegram-FOSS 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 16
Source File: FileLoader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void cancelLoadFile(final TLRPC.Document document, final SecureDocument secureDocument, final WebFile webDocument, final TLRPC.FileLocation location, final String locationExt)
{
    if (location == null && document == null && webDocument == null && secureDocument == null)
    {
        return;
    }
    final String fileName;
    if (location != null)
    {
        fileName = getAttachFileName(location, locationExt);
    }
    else if (document != null)
    {
        fileName = getAttachFileName(document);
    }
    else if (secureDocument != null)
    {
        fileName = getAttachFileName(secureDocument);
    }
    else if (webDocument != null)
    {
        fileName = getAttachFileName(webDocument);
    }
    else
    {
        fileName = null;
    }
    if (fileName == null)
    {
        return;
    }
    loadOperationPathsUI.remove(fileName);
    fileLoaderQueue.postRunnable(new Runnable()
    {
        @Override
        public void run()
        {
            FileLoadOperation operation = loadOperationPaths.remove(fileName);
            if (operation != null)
            {
                int datacenterId = operation.getDatacenterId();
                if (MessageObject.isVoiceDocument(document) || MessageObject.isVoiceWebDocument(webDocument))
                {
                    LinkedList<FileLoadOperation> audioLoadOperationQueue = getAudioLoadOperationQueue(datacenterId);
                    if (!audioLoadOperationQueue.remove(operation))
                    {
                        currentAudioLoadOperationsCount.put(datacenterId, currentAudioLoadOperationsCount.get(datacenterId) - 1);
                    }
                }
                else if (secureDocument != null || location != null || MessageObject.isImageWebDocument(webDocument))
                {
                    LinkedList<FileLoadOperation> photoLoadOperationQueue = getPhotoLoadOperationQueue(datacenterId);
                    if (!photoLoadOperationQueue.remove(operation))
                    {
                        currentPhotoLoadOperationsCount.put(datacenterId, currentPhotoLoadOperationsCount.get(datacenterId) - 1);
                    }
                }
                else
                {
                    LinkedList<FileLoadOperation> loadOperationQueue = getLoadOperationQueue(datacenterId);
                    if (!loadOperationQueue.remove(operation))
                    {
                        currentLoadOperationsCount.put(datacenterId, currentLoadOperationsCount.get(datacenterId) - 1);
                    }
                    activeFileLoadOperation.remove(operation);
                }
                operation.cancel();
            }
        }
    });
}
 
Example 17
Source File: StickerView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public StickerView(Context context, Point position, Size baseSize, TLRPC.Document sticker) {
    this(context, position, 0.0f, 1.0f, baseSize, sticker);
}
 
Example 18
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 19
Source File: ImageReceiver.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public TLRPC.Document getQulityThumbDocument() {
    return qulityThumbDocument;
}
 
Example 20
Source File: StickersAlert.java    From TelePlus-Android with GNU General Public License v2.0 1 votes vote down vote up
void onStickerSelected(TLRPC.Document sticker);