Search in sources :

Example 1 with ImageReceiver

use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.

the class EmojiThemes method loadWallpaperThumb.

public void loadWallpaperThumb(int index, ResultCallback<Pair<Long, Bitmap>> callback) {
    final TLRPC.WallPaper wallpaper = getWallpaper(index);
    if (wallpaper == null) {
        if (callback != null) {
            callback.onComplete(null);
        }
        return;
    }
    long themeId = getTlTheme(index).id;
    Bitmap bitmap = ChatThemeController.getWallpaperThumbBitmap(themeId);
    File file = getWallpaperThumbFile(themeId);
    if (bitmap == null && file.exists() && file.length() > 0) {
        try {
            bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
    if (bitmap != null) {
        if (callback != null) {
            callback.onComplete(new Pair<>(themeId, bitmap));
        }
        return;
    }
    if (wallpaper.document == null) {
        if (callback != null) {
            callback.onComplete(new Pair<>(themeId, null));
        }
        return;
    }
    final TLRPC.PhotoSize thumbSize = FileLoader.getClosestPhotoSizeWithSize(wallpaper.document.thumbs, 120);
    ImageLocation imageLocation = ImageLocation.getForDocument(thumbSize, wallpaper.document);
    ImageReceiver imageReceiver = new ImageReceiver();
    imageReceiver.setImage(imageLocation, "120_80", null, null, null, 1);
    imageReceiver.setDelegate((receiver, set, thumb, memCache) -> {
        ImageReceiver.BitmapHolder holder = receiver.getBitmapSafe();
        if (!set || holder == null) {
            return;
        }
        Bitmap resultBitmap = holder.bitmap;
        if (resultBitmap == null && (holder.drawable instanceof BitmapDrawable)) {
            resultBitmap = ((BitmapDrawable) holder.drawable).getBitmap();
        }
        if (resultBitmap != null) {
            if (callback != null) {
                callback.onComplete(new Pair<>(themeId, resultBitmap));
            }
            final Bitmap saveBitmap = resultBitmap;
            Utilities.globalQueue.postRunnable(() -> {
                try (FileOutputStream outputStream = new FileOutputStream(file)) {
                    saveBitmap.compress(Bitmap.CompressFormat.PNG, 87, outputStream);
                } catch (Exception e) {
                    FileLog.e(e);
                }
            });
        } else {
            if (callback != null) {
                callback.onComplete(null);
            }
        }
    });
    ImageLoader.getInstance().loadImageForImageReceiver(imageReceiver);
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable) TLRPC(org.telegram.tgnet.TLRPC) ImageLocation(org.telegram.messenger.ImageLocation) ImageReceiver(org.telegram.messenger.ImageReceiver) Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 2 with ImageReceiver

use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChannelAdminLogActivity method updateTextureViewPosition.

private void updateTextureViewPosition() {
    boolean foundTextureViewMessage = false;
    int count = chatListView.getChildCount();
    for (int a = 0; a < count; a++) {
        View view = chatListView.getChildAt(a);
        if (view instanceof ChatMessageCell) {
            ChatMessageCell messageCell = (ChatMessageCell) view;
            MessageObject messageObject = messageCell.getMessageObject();
            if (roundVideoContainer != null && messageObject.isRoundVideo() && MediaController.getInstance().isPlayingMessage(messageObject)) {
                ImageReceiver imageReceiver = messageCell.getPhotoImage();
                roundVideoContainer.setTranslationX(imageReceiver.getImageX());
                roundVideoContainer.setTranslationY(fragmentView.getPaddingTop() + messageCell.getTop() + imageReceiver.getImageY());
                fragmentView.invalidate();
                roundVideoContainer.invalidate();
                foundTextureViewMessage = true;
                break;
            }
        }
    }
    if (roundVideoContainer != null) {
        MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
        if (!foundTextureViewMessage) {
            roundVideoContainer.setTranslationY(-AndroidUtilities.roundMessageSize - 100);
            fragmentView.invalidate();
            if (messageObject != null && messageObject.isRoundVideo()) {
                if (checkTextureViewPosition || PipRoundVideoView.getInstance() != null) {
                    MediaController.getInstance().setCurrentVideoVisible(false);
                }
            }
        } else {
            MediaController.getInstance().setCurrentVideoVisible(true);
        }
    }
}
Also used : ImageReceiver(org.telegram.messenger.ImageReceiver) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) UndoView(org.telegram.ui.Components.UndoView) PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextureView(android.view.TextureView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint)

Example 3 with ImageReceiver

use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.

the class EmojiView method startStopVisibleGifs.

private void startStopVisibleGifs(boolean start) {
    if (gifGridView == null) {
        return;
    }
    int count = gifGridView.getChildCount();
    for (int a = 0; a < count; a++) {
        View child = gifGridView.getChildAt(a);
        if (child instanceof ContextLinkCell) {
            ContextLinkCell cell = (ContextLinkCell) child;
            ImageReceiver imageReceiver = cell.getPhotoImage();
            if (start) {
                imageReceiver.setAllowStartAnimation(true);
                imageReceiver.startAnimation();
            } else {
                imageReceiver.setAllowStartAnimation(false);
                imageReceiver.stopAnimation();
            }
        }
    }
}
Also used : ImageReceiver(org.telegram.messenger.ImageReceiver) ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 4 with ImageReceiver

use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.

the class HintView method showForMessageCell.

public boolean showForMessageCell(ChatMessageCell cell, Object object, int x, int y, boolean animated) {
    if (currentType == TYPE_POLL_VOTE && y == shownY && messageCell == cell || currentType != TYPE_POLL_VOTE && (currentType == 0 && getTag() != null || messageCell == cell)) {
        return false;
    }
    if (hideRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(hideRunnable);
        hideRunnable = null;
    }
    int[] position = new int[2];
    cell.getLocationInWindow(position);
    int top = position[1];
    View p = (View) getParent();
    p.getLocationInWindow(position);
    top -= position[1];
    View parentView = (View) cell.getParent();
    int centerX;
    if (currentType == 0) {
        ImageReceiver imageReceiver = cell.getPhotoImage();
        top += imageReceiver.getImageY();
        int height = (int) imageReceiver.getImageHeight();
        int bottom = top + height;
        int parentHeight = parentView.getMeasuredHeight();
        if (top <= getMeasuredHeight() + AndroidUtilities.dp(10) || bottom > parentHeight + height / 4) {
            return false;
        }
        centerX = cell.getNoSoundIconCenterX();
    } else if (currentType == TYPE_POLL_VOTE) {
        Integer count = (Integer) object;
        centerX = x;
        top += y;
        shownY = y;
        if (count == -1) {
            textView.setText(LocaleController.getString("PollSelectOption", R.string.PollSelectOption));
        } else {
            if (cell.getMessageObject().isQuiz()) {
                if (count == 0) {
                    textView.setText(LocaleController.getString("NoVotesQuiz", R.string.NoVotesQuiz));
                } else {
                    textView.setText(LocaleController.formatPluralString("Answer", count));
                }
            } else {
                if (count == 0) {
                    textView.setText(LocaleController.getString("NoVotes", R.string.NoVotes));
                } else {
                    textView.setText(LocaleController.formatPluralString("Vote", count));
                }
            }
        }
        measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST));
    } else {
        MessageObject messageObject = cell.getMessageObject();
        if (overrideText == null) {
            textView.setText(LocaleController.getString("HidAccount", R.string.HidAccount));
        } else {
            textView.setText(overrideText);
        }
        measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST));
        TLRPC.User user = cell.getCurrentUser();
        if (user != null && user.id == 0) {
            top += (cell.getMeasuredHeight() - Math.max(0, cell.getBottom() - parentView.getMeasuredHeight()) - AndroidUtilities.dp(50));
        } else {
            top += AndroidUtilities.dp(22);
            if (!messageObject.isOutOwner() && cell.isDrawNameLayout()) {
                top += AndroidUtilities.dp(20);
            }
        }
        if (!isTopArrow && top <= getMeasuredHeight() + AndroidUtilities.dp(10)) {
            return false;
        }
        centerX = cell.getForwardNameCenterX();
    }
    int parentWidth = parentView.getMeasuredWidth();
    if (isTopArrow) {
        setTranslationY(extraTranslationY + (translationY = AndroidUtilities.dp(44)));
    } else {
        setTranslationY(extraTranslationY + (translationY = top - getMeasuredHeight()));
    }
    int iconX = cell.getLeft() + centerX;
    int left = AndroidUtilities.dp(19);
    if (currentType == TYPE_POLL_VOTE) {
        int offset = Math.max(0, centerX - getMeasuredWidth() / 2 - AndroidUtilities.dp(19.1f));
        setTranslationX(offset);
        left += offset;
    } else if (iconX > parentView.getMeasuredWidth() / 2) {
        int offset = parentWidth - getMeasuredWidth() - AndroidUtilities.dp(38);
        setTranslationX(offset);
        left += offset;
    } else {
        setTranslationX(0);
    }
    float arrowX = cell.getLeft() + centerX - left - arrowImageView.getMeasuredWidth() / 2;
    arrowImageView.setTranslationX(arrowX);
    if (iconX > parentView.getMeasuredWidth() / 2) {
        if (arrowX < AndroidUtilities.dp(10)) {
            float diff = arrowX - AndroidUtilities.dp(10);
            setTranslationX(getTranslationX() + diff);
            arrowImageView.setTranslationX(arrowX - diff);
        }
    } else {
        if (arrowX > getMeasuredWidth() - AndroidUtilities.dp(14 + 10)) {
            float diff = arrowX - getMeasuredWidth() + AndroidUtilities.dp(14 + 10);
            setTranslationX(diff);
            arrowImageView.setTranslationX(arrowX - diff);
        } else if (arrowX < AndroidUtilities.dp(10)) {
            float diff = arrowX - AndroidUtilities.dp(10);
            setTranslationX(getTranslationX() + diff);
            arrowImageView.setTranslationX(arrowX - diff);
        }
    }
    messageCell = cell;
    if (animatorSet != null) {
        animatorSet.cancel();
        animatorSet = null;
    }
    setTag(1);
    setVisibility(VISIBLE);
    if (animated) {
        animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(this, View.ALPHA, 0.0f, 1.0f));
        animatorSet.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                animatorSet = null;
                AndroidUtilities.runOnUIThread(hideRunnable = () -> hide(), currentType == 0 ? 10000 : 2000);
            }
        });
        animatorSet.setDuration(300);
        animatorSet.start();
    } else {
        setAlpha(1.0f);
    }
    return true;
}
Also used : ImageReceiver(org.telegram.messenger.ImageReceiver) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorSet(android.animation.AnimatorSet) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) MessageObject(org.telegram.messenger.MessageObject)

Example 5 with ImageReceiver

use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.

the class GroupedPhotosListView method fillImages.

private void fillImages(boolean move, int dx) {
    if (!move && !imagesToDraw.isEmpty()) {
        unusedReceivers.addAll(imagesToDraw);
        imagesToDraw.clear();
        moving = false;
        moveLineProgress = 1.0f;
        currentItemProgress = 1.0f;
        nextItemProgress = 0.0f;
    }
    invalidate();
    if (getMeasuredWidth() == 0 || currentPhotos.isEmpty()) {
        return;
    }
    int width = getMeasuredWidth();
    int startX = getMeasuredWidth() / 2 - itemWidth / 2;
    int addRightIndex;
    int addLeftIndex;
    if (move) {
        addRightIndex = Integer.MIN_VALUE;
        addLeftIndex = Integer.MAX_VALUE;
        int count = imagesToDraw.size();
        for (int a = 0; a < count; a++) {
            ImageReceiver receiver = imagesToDraw.get(a);
            int num = receiver.getParam();
            int x = startX + (num - currentImage) * (itemWidth + itemSpacing) + dx;
            if (x > width || x + itemWidth < 0) {
                unusedReceivers.add(receiver);
                imagesToDraw.remove(a);
                count--;
                a--;
            }
            addLeftIndex = Math.min(addLeftIndex, num - 1);
            addRightIndex = Math.max(addRightIndex, num + 1);
        }
    } else {
        addRightIndex = currentImage;
        addLeftIndex = currentImage - 1;
    }
    if (addRightIndex != Integer.MIN_VALUE) {
        int count = currentPhotos.size();
        for (int a = addRightIndex; a < count; a++) {
            int x = startX + (a - currentImage) * (itemWidth + itemSpacing) + dx;
            if (x < width) {
                ImageLocation location = currentPhotos.get(a);
                ImageReceiver receiver = getFreeReceiver();
                receiver.setImageCoords(x, itemY, itemWidth, itemHeight);
                Object parent;
                if (currentObjects.get(0) instanceof MessageObject) {
                    parent = currentObjects.get(a);
                } else if (currentObjects.get(0) instanceof TLRPC.PageBlock) {
                    parent = delegate.getParentObject();
                } else {
                    parent = "avatar_" + delegate.getAvatarsDialogId();
                }
                receiver.setImage(null, null, location, "80_80", 0, null, parent, 1);
                receiver.setParam(a);
            } else {
                break;
            }
        }
    }
    if (addLeftIndex != Integer.MAX_VALUE) {
        for (int a = addLeftIndex; a >= 0; a--) {
            int x = startX + (a - currentImage) * (itemWidth + itemSpacing) + dx + itemWidth;
            if (x > 0) {
                ImageLocation location = currentPhotos.get(a);
                ImageReceiver receiver = getFreeReceiver();
                receiver.setImageCoords(x, itemY, itemWidth, itemHeight);
                Object parent;
                if (currentObjects.get(0) instanceof MessageObject) {
                    parent = currentObjects.get(a);
                } else if (currentObjects.get(0) instanceof TLRPC.PageBlock) {
                    parent = delegate.getParentObject();
                } else {
                    parent = "avatar_" + delegate.getAvatarsDialogId();
                }
                receiver.setImage(null, null, location, "80_80", 0, null, parent, 1);
                receiver.setParam(a);
            } else {
                break;
            }
        }
    }
    if (showAnimator != null && !showAnimator.isStarted()) {
        showAnimator.start();
    }
}
Also used : ImageReceiver(org.telegram.messenger.ImageReceiver) MessageObject(org.telegram.messenger.MessageObject) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint) ImageLocation(org.telegram.messenger.ImageLocation) TLRPC(org.telegram.tgnet.TLRPC)

Aggregations

ImageReceiver (org.telegram.messenger.ImageReceiver)43 Paint (android.graphics.Paint)28 MessageObject (org.telegram.messenger.MessageObject)21 View (android.view.View)19 ImageView (android.widget.ImageView)18 TextView (android.widget.TextView)18 TLRPC (org.telegram.tgnet.TLRPC)18 SuppressLint (android.annotation.SuppressLint)17 TextPaint (android.text.TextPaint)17 RecyclerView (androidx.recyclerview.widget.RecyclerView)17 RecyclerListView (org.telegram.ui.Components.RecyclerListView)15 BackupImageView (org.telegram.ui.Components.BackupImageView)14 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)13 UndoView (org.telegram.ui.Components.UndoView)13 ImageLocation (org.telegram.messenger.ImageLocation)12 RadialProgressView (org.telegram.ui.Components.RadialProgressView)12 TextureView (android.view.TextureView)11 ChatMessageCell (org.telegram.ui.Cells.ChatMessageCell)11 FrameLayout (android.widget.FrameLayout)10 PipRoundVideoView (org.telegram.ui.Components.PipRoundVideoView)10