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

The following examples show how to use org.telegram.tgnet.TLRPC#TL_photoSize . 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: StickersAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkStickerFilesExistAndDownload() {
    if (stickers == null) {
        return false;
    }
    stickersToLoad.clear();
    int size = Math.min(6, stickers.size());
    for (int a = 0; a < size; a++) {
        StickerResult result = stickers.get(a);
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(result.sticker.thumbs, 90);
        if (thumb instanceof TLRPC.TL_photoSize) {
            File f = FileLoader.getPathToAttach(thumb, "webp", true);
            if (!f.exists()) {
                stickersToLoad.add(FileLoader.getAttachFileName(thumb, "webp"));
                FileLoader.getInstance(currentAccount).loadFile(ImageLocation.getForDocument(thumb, result.sticker), result.parent, "webp", 1, 1);
            }
        }
    }
    return stickersToLoad.isEmpty();
}
 
Example 2
Source File: SharedAudioCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setMessageObject(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    currentMessageObject = messageObject;
    TLRPC.Document document = messageObject.getDocument();

    TLRPC.PhotoSize thumb = document != null ? FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 240) : 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);
        }
    }
    updateButtonState(false, false);
    requestLayout();
}
 
Example 3
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 4
Source File: StickersAdapter.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkStickerFilesExistAndDownload() {
    if (stickers == null) {
        return false;
    }
    stickersToLoad.clear();
    int size = Math.min(6, stickers.size());
    for (int a = 0; a < size; a++) {
        StickerResult result = stickers.get(a);
        TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(result.sticker.thumbs, 90);
        if (thumb instanceof TLRPC.TL_photoSize) {
            File f = FileLoader.getPathToAttach(thumb, "webp", true);
            if (!f.exists()) {
                stickersToLoad.add(FileLoader.getAttachFileName(thumb, "webp"));
                FileLoader.getInstance(currentAccount).loadFile(ImageLocation.getForDocument(thumb, result.sticker), result.parent, "webp", 1, 1);
            }
        }
    }
    return stickersToLoad.isEmpty();
}
 
Example 5
Source File: SharedAudioCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setMessageObject(MessageObject messageObject, boolean divider) {
    needDivider = divider;
    currentMessageObject = messageObject;
    TLRPC.Document document = messageObject.getDocument();

    TLRPC.PhotoSize thumb = document != null ? FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 240) : 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);
        }
    }
    updateButtonState(false, false);
    requestLayout();
}
 
Example 6
Source File: AudioPlayerCell.java    From Telegram 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 7
Source File: ImageLoader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway) throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    TLRPC.TL_fileLocation location = new TLRPC.TL_fileLocation();
    location.volume_id = Integer.MIN_VALUE;
    location.dc_id = Integer.MIN_VALUE;
    location.local_id = SharedConfig.getLastLocalId();
    TLRPC.PhotoSize size = new TLRPC.TL_photoSize();
    size.location = location;
    size.w = scaledBitmap.getWidth();
    size.h = scaledBitmap.getHeight();
    if (size.w <= 100 && size.h <= 100) {
        size.type = "s";
    } else if (size.w <= 320 && size.h <= 320) {
        size.type = "m";
    } else if (size.w <= 800 && size.h <= 800) {
        size.type = "x";
    } else if (size.w <= 1280 && size.h <= 1280) {
        size.type = "y";
    } else {
        size.type = "w";
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    final File cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream2);
        size.bytes = stream2.toByteArray();
        size.size = size.bytes.length;
        stream2.close();
    } else {
        size.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return size;
}
 
Example 8
Source File: ImageLoader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway) throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    TLRPC.TL_fileLocation location = new TLRPC.TL_fileLocation();
    location.volume_id = Integer.MIN_VALUE;
    location.dc_id = Integer.MIN_VALUE;
    location.local_id = SharedConfig.getLastLocalId();
    TLRPC.PhotoSize size = new TLRPC.TL_photoSize();
    size.location = location;
    size.w = scaledBitmap.getWidth();
    size.h = scaledBitmap.getHeight();
    if (size.w <= 100 && size.h <= 100) {
        size.type = "s";
    } else if (size.w <= 320 && size.h <= 320) {
        size.type = "m";
    } else if (size.w <= 800 && size.h <= 800) {
        size.type = "x";
    } else if (size.w <= 1280 && size.h <= 1280) {
        size.type = "y";
    } else {
        size.type = "w";
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    final File cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream2);
        size.bytes = stream2.toByteArray();
        size.size = size.bytes.length;
        stream2.close();
    } else {
        size.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return size;
}
 
Example 9
Source File: ImageLoader.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private static TLRPC.PhotoSize scaleAndSaveImageInternal(TLRPC.PhotoSize photoSize, Bitmap bitmap, Bitmap.CompressFormat compressFormat, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway, boolean forceCacheDir) throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    boolean check = photoSize != null;
    TLRPC.TL_fileLocationToBeDeprecated location;
    if (photoSize == null || !(photoSize.location instanceof TLRPC.TL_fileLocationToBeDeprecated)) {
        location = new TLRPC.TL_fileLocationToBeDeprecated();
        location.volume_id = Integer.MIN_VALUE;
        location.dc_id = Integer.MIN_VALUE;
        location.local_id = SharedConfig.getLastLocalId();
        location.file_reference = new byte[0];

        photoSize = new TLRPC.TL_photoSize();
        photoSize.location = location;
        photoSize.w = scaledBitmap.getWidth();
        photoSize.h = scaledBitmap.getHeight();
        if (photoSize.w <= 100 && photoSize.h <= 100) {
            photoSize.type = "s";
        } else if (photoSize.w <= 320 && photoSize.h <= 320) {
            photoSize.type = "m";
        } else if (photoSize.w <= 800 && photoSize.h <= 800) {
            photoSize.type = "x";
        } else if (photoSize.w <= 1280 && photoSize.h <= 1280) {
            photoSize.type = "y";
        } else {
            photoSize.type = "w";
        }
    } else {
        location = (TLRPC.TL_fileLocationToBeDeprecated) photoSize.location;
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    File fileDir;
    if (forceCacheDir) {
        fileDir = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
    } else {
        fileDir = location.volume_id != Integer.MIN_VALUE ? FileLoader.getDirectory(FileLoader.MEDIA_DIR_IMAGE) : FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
    }
    final File cacheFile = new File(fileDir, fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(compressFormat, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(compressFormat, quality, stream2);
        photoSize.bytes = stream2.toByteArray();
        photoSize.size = photoSize.bytes.length;
        stream2.close();
    } else {
        photoSize.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return photoSize;
}
 
Example 10
Source File: StickerMasksAlert.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void updateStickerTabs() {
    if (stickersTab == null) {
        return;
    }

    if (stickersButton != null) {
        if (currentType == MediaDataController.TYPE_IMAGE) {
            stickersButton.setSelected(true);
            masksButton.setSelected(false);
        } else {
            stickersButton.setSelected(false);
            masksButton.setSelected(true);
        }
    }

    recentTabBum = -2;
    favTabBum = -2;

    stickersTabOffset = 0;
    int lastPosition = stickersTab.getCurrentPosition();
    stickersTab.beginUpdate(false);

    if (currentType == MediaDataController.TYPE_IMAGE && !favouriteStickers.isEmpty()) {
        favTabBum = stickersTabOffset;
        stickersTabOffset++;
        stickersTab.addIconTab(1, stickerIcons[1]).setContentDescription(LocaleController.getString("FavoriteStickers", R.string.FavoriteStickers));
    }

    if (!recentStickers[currentType].isEmpty()) {
        recentTabBum = stickersTabOffset;
        stickersTabOffset++;
        stickersTab.addIconTab(0, stickerIcons[0]).setContentDescription(LocaleController.getString("RecentStickers", R.string.RecentStickers));
    }

    stickerSets[currentType].clear();
    ArrayList<TLRPC.TL_messages_stickerSet> packs = MediaDataController.getInstance(currentAccount).getStickerSets(currentType);
    for (int a = 0; a < packs.size(); a++) {
        TLRPC.TL_messages_stickerSet pack = packs.get(a);
        if (pack.set.archived || pack.documents == null || pack.documents.isEmpty()) {
            continue;
        }
        stickerSets[currentType].add(pack);
    }
    for (int a = 0; a < stickerSets[currentType].size(); a++) {
        TLRPC.TL_messages_stickerSet stickerSet = stickerSets[currentType].get(a);
        TLObject thumb;
        TLRPC.Document document = stickerSet.documents.get(0);
        if (stickerSet.set.thumb instanceof TLRPC.TL_photoSize) {
            thumb = stickerSet.set.thumb;
        } else {
            thumb = document;
        }
        stickersTab.addStickerTab(thumb, document, stickerSet).setContentDescription(stickerSet.set.title + ", " + LocaleController.getString("AccDescrStickerSet", R.string.AccDescrStickerSet));
    }
    stickersTab.commitUpdate();
    stickersTab.updateTabStyles();
    if (lastPosition != 0) {
        stickersTab.onPageScrolled(lastPosition, lastPosition);
    }
    checkPanels();
}
 
Example 11
Source File: ImageLoader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private static TLRPC.PhotoSize scaleAndSaveImageInternal(TLRPC.PhotoSize photoSize, Bitmap bitmap, Bitmap.CompressFormat compressFormat, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway, boolean forceCacheDir) throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    boolean check = photoSize != null;
    TLRPC.TL_fileLocationToBeDeprecated location;
    if (photoSize == null || !(photoSize.location instanceof TLRPC.TL_fileLocationToBeDeprecated)) {
        location = new TLRPC.TL_fileLocationToBeDeprecated();
        location.volume_id = Integer.MIN_VALUE;
        location.dc_id = Integer.MIN_VALUE;
        location.local_id = SharedConfig.getLastLocalId();
        location.file_reference = new byte[0];

        photoSize = new TLRPC.TL_photoSize();
        photoSize.location = location;
        photoSize.w = scaledBitmap.getWidth();
        photoSize.h = scaledBitmap.getHeight();
        if (photoSize.w <= 100 && photoSize.h <= 100) {
            photoSize.type = "s";
        } else if (photoSize.w <= 320 && photoSize.h <= 320) {
            photoSize.type = "m";
        } else if (photoSize.w <= 800 && photoSize.h <= 800) {
            photoSize.type = "x";
        } else if (photoSize.w <= 1280 && photoSize.h <= 1280) {
            photoSize.type = "y";
        } else {
            photoSize.type = "w";
        }
    } else {
        location = (TLRPC.TL_fileLocationToBeDeprecated) photoSize.location;
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    File fileDir;
    if (forceCacheDir) {
        fileDir = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
    } else {
        fileDir = location.volume_id != Integer.MIN_VALUE ? FileLoader.getDirectory(FileLoader.MEDIA_DIR_IMAGE) : FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
    }
    final File cacheFile = new File(fileDir, fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(compressFormat, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(compressFormat, quality, stream2);
        photoSize.bytes = stream2.toByteArray();
        photoSize.size = photoSize.bytes.length;
        stream2.close();
    } else {
        photoSize.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return photoSize;
}
 
Example 12
Source File: StickerMasksAlert.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void updateStickerTabs() {
    if (stickersTab == null) {
        return;
    }

    if (stickersButton != null) {
        if (currentType == MediaDataController.TYPE_IMAGE) {
            stickersButton.setSelected(true);
            masksButton.setSelected(false);
        } else {
            stickersButton.setSelected(false);
            masksButton.setSelected(true);
        }
    }

    recentTabBum = -2;
    favTabBum = -2;

    stickersTabOffset = 0;
    int lastPosition = stickersTab.getCurrentPosition();
    stickersTab.beginUpdate(false);

    if (currentType == MediaDataController.TYPE_IMAGE && !favouriteStickers.isEmpty()) {
        favTabBum = stickersTabOffset;
        stickersTabOffset++;
        stickersTab.addIconTab(1, stickerIcons[1]).setContentDescription(LocaleController.getString("FavoriteStickers", R.string.FavoriteStickers));
    }

    if (!recentStickers[currentType].isEmpty()) {
        recentTabBum = stickersTabOffset;
        stickersTabOffset++;
        stickersTab.addIconTab(0, stickerIcons[0]).setContentDescription(LocaleController.getString("RecentStickers", R.string.RecentStickers));
    }

    stickerSets[currentType].clear();
    ArrayList<TLRPC.TL_messages_stickerSet> packs = MediaDataController.getInstance(currentAccount).getStickerSets(currentType);
    for (int a = 0; a < packs.size(); a++) {
        TLRPC.TL_messages_stickerSet pack = packs.get(a);
        if (pack.set.archived || pack.documents == null || pack.documents.isEmpty()) {
            continue;
        }
        stickerSets[currentType].add(pack);
    }
    for (int a = 0; a < stickerSets[currentType].size(); a++) {
        TLRPC.TL_messages_stickerSet stickerSet = stickerSets[currentType].get(a);
        TLObject thumb;
        TLRPC.Document document = stickerSet.documents.get(0);
        if (stickerSet.set.thumb instanceof TLRPC.TL_photoSize) {
            thumb = stickerSet.set.thumb;
        } else {
            thumb = document;
        }
        stickersTab.addStickerTab(thumb, document, stickerSet).setContentDescription(stickerSet.set.title + ", " + LocaleController.getString("AccDescrStickerSet", R.string.AccDescrStickerSet));
    }
    stickersTab.commitUpdate();
    stickersTab.updateTabStyles();
    if (lastPosition != 0) {
        stickersTab.onPageScrolled(lastPosition, lastPosition);
    }
    checkPanels();
}