Search in sources :

Example 11 with MessageObject

use of org.telegram.messenger.MessageObject 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 12 with MessageObject

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

the class ImageUpdater method openPhotoForEdit.

public void openPhotoForEdit(String path, String thumb, int orientation, boolean isVideo) {
    final ArrayList<Object> arrayList = new ArrayList<>();
    MediaController.PhotoEntry photoEntry = new MediaController.PhotoEntry(0, 0, 0, path, orientation, false, 0, 0, 0);
    photoEntry.isVideo = isVideo;
    photoEntry.thumbPath = thumb;
    arrayList.add(photoEntry);
    PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
    PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, PhotoViewer.SELECT_TYPE_AVATAR, false, new PhotoViewer.EmptyPhotoViewerProvider() {

        @Override
        public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
            String path = null;
            MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) arrayList.get(0);
            if (photoEntry.imagePath != null) {
                path = photoEntry.imagePath;
            } else if (photoEntry.path != null) {
                path = photoEntry.path;
            }
            MessageObject avatarObject = null;
            Bitmap bitmap;
            if (photoEntry.isVideo || photoEntry.editedInfo != null) {
                TLRPC.TL_message message = new TLRPC.TL_message();
                message.id = 0;
                message.message = "";
                message.media = new TLRPC.TL_messageMediaEmpty();
                message.action = new TLRPC.TL_messageActionEmpty();
                message.dialog_id = 0;
                avatarObject = new MessageObject(UserConfig.selectedAccount, message, false, false);
                avatarObject.messageOwner.attachPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_avatar.mp4").getAbsolutePath();
                avatarObject.videoEditedInfo = photoEntry.editedInfo;
                bitmap = ImageLoader.loadBitmap(photoEntry.thumbPath, null, 800, 800, true);
            } else {
                bitmap = ImageLoader.loadBitmap(path, null, 800, 800, true);
            }
            processBitmap(bitmap, avatarObject);
        }

        @Override
        public boolean allowCaption() {
            return false;
        }

        @Override
        public boolean canScrollAway() {
            return false;
        }
    }, null);
}
Also used : MediaController(org.telegram.messenger.MediaController) ArrayList(java.util.ArrayList) PhotoViewer(org.telegram.ui.PhotoViewer) TLRPC(org.telegram.tgnet.TLRPC) Bitmap(android.graphics.Bitmap) MessageObject(org.telegram.messenger.MessageObject) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MessageObject(org.telegram.messenger.MessageObject) File(java.io.File)

Example 13 with MessageObject

use of org.telegram.messenger.MessageObject 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)

Example 14 with MessageObject

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

the class ChatMessageCell method checkVideoPlayback.

public void checkVideoPlayback(boolean allowStart, Bitmap thumb) {
    if (currentMessageObject.isVideo()) {
        if (MediaController.getInstance().isPlayingMessage(currentMessageObject)) {
            photoImage.setAllowStartAnimation(false);
            photoImage.stopAnimation();
        } else {
            photoImage.setAllowStartAnimation(true);
            photoImage.startAnimation();
        }
    } else {
        if (allowStart) {
            MessageObject playingMessage = MediaController.getInstance().getPlayingMessageObject();
            allowStart = playingMessage == null || !playingMessage.isRoundVideo();
        }
        photoImage.setAllowStartAnimation(allowStart);
        if (thumb != null) {
            photoImage.startCrossfadeFromStaticThumb(thumb);
        }
        if (allowStart) {
            photoImage.startAnimation();
        } else {
            photoImage.stopAnimation();
        }
    }
}
Also used : MessageObject(org.telegram.messenger.MessageObject)

Example 15 with MessageObject

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

the class ContextLinkCell method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    if (checkBox != null) {
        if (checkBox.isChecked() || !linkImageView.hasBitmapImage() || linkImageView.getCurrentAlpha() != 1.0f || PhotoViewer.isShowingImage((MessageObject) parentObject)) {
            canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
        }
    }
    if (titleLayout != null) {
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY);
        titleLayout.draw(canvas);
        canvas.restore();
    }
    if (descriptionLayout != null) {
        Theme.chat_contextResult_descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY);
        descriptionLayout.draw(canvas);
        canvas.restore();
    }
    if (linkLayout != null) {
        Theme.chat_contextResult_descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY);
        linkLayout.draw(canvas);
        canvas.restore();
    }
    if (!mediaWebpage) {
        if (drawLinkImageView && !PhotoViewer.isShowingImage(inlineResult)) {
            letterDrawable.setAlpha((int) (255 * (1.0f - linkImageView.getCurrentAlpha())));
        } else {
            letterDrawable.setAlpha(255);
        }
        if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
            radialProgress.setProgressColor(Theme.getColor(buttonPressed ? Theme.key_chat_inAudioSelectedProgress : Theme.key_chat_inAudioProgress));
            radialProgress.draw(canvas);
        } else if (inlineResult != null && inlineResult.type.equals("file")) {
            int w = Theme.chat_inlineResultFile.getIntrinsicWidth();
            int h = Theme.chat_inlineResultFile.getIntrinsicHeight();
            int x = (int) (linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2);
            int y = (int) (linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2);
            canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint);
            Theme.chat_inlineResultFile.setBounds(x, y, x + w, y + h);
            Theme.chat_inlineResultFile.draw(canvas);
        } else if (inlineResult != null && (inlineResult.type.equals("audio") || inlineResult.type.equals("voice"))) {
            int w = Theme.chat_inlineResultAudio.getIntrinsicWidth();
            int h = Theme.chat_inlineResultAudio.getIntrinsicHeight();
            int x = (int) (linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2);
            int y = (int) (linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2);
            canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint);
            Theme.chat_inlineResultAudio.setBounds(x, y, x + w, y + h);
            Theme.chat_inlineResultAudio.draw(canvas);
        } else if (inlineResult != null && (inlineResult.type.equals("venue") || inlineResult.type.equals("geo"))) {
            int w = Theme.chat_inlineResultLocation.getIntrinsicWidth();
            int h = Theme.chat_inlineResultLocation.getIntrinsicHeight();
            int x = (int) (linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2);
            int y = (int) (linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2);
            canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint);
            Theme.chat_inlineResultLocation.setBounds(x, y, x + w, y + h);
            Theme.chat_inlineResultLocation.draw(canvas);
        } else {
            letterDrawable.draw(canvas);
        }
    } else {
        if (inlineResult != null && (inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaGeo || inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) {
            int w = Theme.chat_inlineResultLocation.getIntrinsicWidth();
            int h = Theme.chat_inlineResultLocation.getIntrinsicHeight();
            int x = (int) (linkImageView.getImageX() + (linkImageView.getImageWidth() - w) / 2);
            int y = (int) (linkImageView.getImageY() + (linkImageView.getImageHeight() - h) / 2);
            canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + linkImageView.getImageWidth(), linkImageView.getImageY() + linkImageView.getImageHeight(), LetterDrawable.paint);
            Theme.chat_inlineResultLocation.setBounds(x, y, x + w, y + h);
            Theme.chat_inlineResultLocation.draw(canvas);
        }
    }
    if (drawLinkImageView) {
        if (inlineResult != null) {
            linkImageView.setVisible(!PhotoViewer.isShowingImage(inlineResult), false);
        }
        canvas.save();
        if (scaled && scale != 0.8f || !scaled && scale != 1.0f) {
            long newTime = System.currentTimeMillis();
            long dt = (newTime - lastUpdateTime);
            lastUpdateTime = newTime;
            if (scaled && scale != 0.8f) {
                scale -= dt / 400.0f;
                if (scale < 0.8f) {
                    scale = 0.8f;
                }
            } else {
                scale += dt / 400.0f;
                if (scale > 1.0f) {
                    scale = 1.0f;
                }
            }
            invalidate();
        }
        canvas.scale(scale * imageScale, scale * imageScale, getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        linkImageView.draw(canvas);
        canvas.restore();
    }
    if (mediaWebpage && (documentAttachType == DOCUMENT_ATTACH_TYPE_PHOTO || documentAttachType == DOCUMENT_ATTACH_TYPE_GIF)) {
        radialProgress.draw(canvas);
    }
    if (needDivider && !mediaWebpage) {
        if (LocaleController.isRTL) {
            canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, Theme.dividerPaint);
        } else {
            canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, Theme.dividerPaint);
        }
    }
    if (needShadow) {
        Theme.chat_contextResult_shadowUnderSwitchDrawable.setBounds(0, 0, getMeasuredWidth(), AndroidUtilities.dp(3));
        Theme.chat_contextResult_shadowUnderSwitchDrawable.draw(canvas);
    }
}
Also used : MessageObject(org.telegram.messenger.MessageObject) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) TLRPC(org.telegram.tgnet.TLRPC)

Aggregations

MessageObject (org.telegram.messenger.MessageObject)156 Paint (android.graphics.Paint)107 TLRPC (org.telegram.tgnet.TLRPC)88 SuppressLint (android.annotation.SuppressLint)87 TextPaint (android.text.TextPaint)80 View (android.view.View)59 ArrayList (java.util.ArrayList)59 TextView (android.widget.TextView)53 TextSelectionHint (org.telegram.ui.Components.TextSelectionHint)52 RecyclerView (androidx.recyclerview.widget.RecyclerView)50 ImageView (android.widget.ImageView)48 RecyclerListView (org.telegram.ui.Components.RecyclerListView)46 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)39 UndoView (org.telegram.ui.Components.UndoView)36 TextureView (android.view.TextureView)34 File (java.io.File)33 ChatObject (org.telegram.messenger.ChatObject)32 DialogObject (org.telegram.messenger.DialogObject)30 MediaController (org.telegram.messenger.MediaController)30 TLObject (org.telegram.tgnet.TLObject)30