Search in sources :

Example 1 with AudioVisualizerDrawable

use of org.telegram.ui.Components.AudioVisualizerDrawable in project Telegram-FOSS by Telegram-FOSS-Team.

the class Theme method unrefAudioVisualizeDrawable.

public static void unrefAudioVisualizeDrawable(MessageObject messageObject) {
    if (chat_msgAudioVisualizeDrawable == null) {
        return;
    }
    if (chat_msgAudioVisualizeDrawable.getParentView() == null || messageObject == null) {
        chat_msgAudioVisualizeDrawable.setParentView(null);
    } else {
        if (animatedOutVisualizerDrawables == null) {
            animatedOutVisualizerDrawables = new HashMap<>();
        }
        animatedOutVisualizerDrawables.put(messageObject, chat_msgAudioVisualizeDrawable);
        chat_msgAudioVisualizeDrawable.setWaveform(false, true, null);
        AndroidUtilities.runOnUIThread(() -> {
            AudioVisualizerDrawable drawable = animatedOutVisualizerDrawables.remove(messageObject);
            if (drawable != null) {
                drawable.setParentView(null);
            }
        }, 200);
        chat_msgAudioVisualizeDrawable = null;
    }
}
Also used : AudioVisualizerDrawable(org.telegram.ui.Components.AudioVisualizerDrawable)

Example 2 with AudioVisualizerDrawable

use of org.telegram.ui.Components.AudioVisualizerDrawable in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatMessageCell method drawContent.

private void drawContent(Canvas canvas) {
    boolean newPart = needNewVisiblePart && currentMessageObject.type == 0, hasSpoilers = hasSpoilers();
    if (newPart || hasSpoilers) {
        getLocalVisibleRect(scrollRect);
        if (hasSpoilers) {
            updateSpoilersVisiblePart(scrollRect.top, scrollRect.bottom);
        }
        if (newPart) {
            setVisiblePart(scrollRect.top, scrollRect.bottom - scrollRect.top, parentHeight, parentViewTopOffset, viewTop, parentWidth, backgroundHeight);
            needNewVisiblePart = false;
        }
    }
    float buttonX = this.buttonX;
    float buttonY = this.buttonY;
    if (transitionParams.animateButton) {
        buttonX = transitionParams.animateFromButtonX * (1f - transitionParams.animateChangeProgress) + this.buttonX * (transitionParams.animateChangeProgress);
        buttonY = (transitionParams.animateFromButtonY * (1f - transitionParams.animateChangeProgress) + this.buttonY * (transitionParams.animateChangeProgress));
        radialProgress.setProgressRect((int) buttonX, (int) buttonY, (int) buttonX + AndroidUtilities.dp(44), (int) buttonY + AndroidUtilities.dp(44));
    }
    if (transitionParams.animateBackgroundBoundsInner && documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO) {
        int backgroundWidth = (int) (this.backgroundWidth - transitionParams.deltaLeft + transitionParams.deltaRight);
        seekBarWaveform.setSize(backgroundWidth - AndroidUtilities.dp(92 + (hasLinkPreview ? 10 : 0)), AndroidUtilities.dp(30));
        seekBar.setSize(backgroundWidth - AndroidUtilities.dp(72 + (hasLinkPreview ? 10 : 0)), AndroidUtilities.dp(30));
    }
    forceNotDrawTime = currentMessagesGroup != null;
    photoImage.setPressed((isHighlightedAnimated || isHighlighted) && currentPosition != null ? 2 : 0);
    photoImage.setVisible(!PhotoViewer.isShowingImage(currentMessageObject) && !SecretMediaViewer.getInstance().isShowingImage(currentMessageObject), false);
    if (!photoImage.getVisible()) {
        mediaWasInvisible = true;
        timeWasInvisible = true;
        if (animatingNoSound == 1) {
            animatingNoSoundProgress = 0.0f;
            animatingNoSound = 0;
        } else if (animatingNoSound == 2) {
            animatingNoSoundProgress = 1.0f;
            animatingNoSound = 0;
        }
    } else if (groupPhotoInvisible) {
        timeWasInvisible = true;
    } else if (mediaWasInvisible || timeWasInvisible) {
        if (mediaWasInvisible) {
            controlsAlpha = 0.0f;
            mediaWasInvisible = false;
        }
        if (timeWasInvisible) {
            timeAlpha = 0.0f;
            timeWasInvisible = false;
        }
        lastControlsAlphaChangeTime = System.currentTimeMillis();
        totalChangeTime = 0;
    }
    radialProgress.setProgressColor(getThemedColor(Theme.key_chat_mediaProgress));
    videoRadialProgress.setProgressColor(getThemedColor(Theme.key_chat_mediaProgress));
    imageDrawn = false;
    radialProgress.setCircleCrossfadeColor(null, 0.0f, 1.0f);
    if (currentMessageObject.type == 0) {
        if (currentMessageObject.isOutOwner()) {
            textX = getCurrentBackgroundLeft() + AndroidUtilities.dp(11) + getExtraTextX();
        } else {
            textX = getCurrentBackgroundLeft() + AndroidUtilities.dp(!mediaBackground && drawPinnedBottom ? 11 : 17) + getExtraTextX();
        }
        if (hasGamePreview) {
            textX += AndroidUtilities.dp(11);
            textY = AndroidUtilities.dp(14) + namesOffset;
            if (siteNameLayout != null) {
                textY += siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
            }
        } else if (hasInvoicePreview) {
            textY = AndroidUtilities.dp(14) + namesOffset;
            if (siteNameLayout != null) {
                textY += siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
            }
        } else {
            textY = AndroidUtilities.dp(10) + namesOffset;
        }
        unmovedTextX = textX;
        if (currentMessageObject.textXOffset != 0 && replyNameLayout != null) {
            int diff = backgroundWidth - AndroidUtilities.dp(31) - currentMessageObject.textWidth;
            if (!hasNewLineForTime) {
                diff -= timeWidth + AndroidUtilities.dp(4 + (currentMessageObject.isOutOwner() ? 20 : 0));
            }
            if (diff > 0) {
                textX += diff - getExtraTimeX();
            }
        }
        if (!enterTransitionInPorgress && currentMessageObject != null && !currentMessageObject.preview) {
            if (transitionParams.animateChangeProgress != 1.0f && transitionParams.animateMessageText) {
                canvas.save();
                if (currentBackgroundDrawable != null) {
                    Rect r = currentBackgroundDrawable.getBounds();
                    if (currentMessageObject.isOutOwner() && !mediaBackground && !pinnedBottom) {
                        canvas.clipRect(r.left + AndroidUtilities.dp(4), r.top + AndroidUtilities.dp(4), r.right - AndroidUtilities.dp(10), r.bottom - AndroidUtilities.dp(4));
                    } else {
                        canvas.clipRect(r.left + AndroidUtilities.dp(4), r.top + AndroidUtilities.dp(4), r.right - AndroidUtilities.dp(4), r.bottom - AndroidUtilities.dp(4));
                    }
                }
                drawMessageText(canvas, transitionParams.animateOutTextBlocks, false, (1.0f - transitionParams.animateChangeProgress), false);
                drawMessageText(canvas, currentMessageObject.textLayoutBlocks, true, transitionParams.animateChangeProgress, false);
                canvas.restore();
            } else {
                drawMessageText(canvas, currentMessageObject.textLayoutBlocks, true, 1.0f, false);
            }
        }
        if (!(enterTransitionInPorgress && !currentMessageObject.isVoice())) {
            drawLinkPreview(canvas, 1f);
        }
        drawTime = true;
    } else if (drawPhotoImage) {
        if (isRoundVideo && MediaController.getInstance().isPlayingMessage(currentMessageObject) && MediaController.getInstance().isVideoDrawingReady() && canvas.isHardwareAccelerated()) {
            imageDrawn = true;
            drawTime = true;
        } else {
            if (currentMessageObject.type == MessageObject.TYPE_ROUND_VIDEO && Theme.chat_roundVideoShadow != null) {
                float x = photoImage.getImageX() - AndroidUtilities.dp(3);
                float y = photoImage.getImageY() - AndroidUtilities.dp(2);
                Theme.chat_roundVideoShadow.setAlpha(255);
                Theme.chat_roundVideoShadow.setBounds((int) x, (int) y, (int) (x + photoImage.getImageWidth() + AndroidUtilities.dp(6)), (int) (y + photoImage.getImageHeight() + AndroidUtilities.dp(6)));
                Theme.chat_roundVideoShadow.draw(canvas);
                if (!photoImage.hasBitmapImage() || photoImage.getCurrentAlpha() != 1) {
                    Theme.chat_docBackPaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outBubble : Theme.key_chat_inBubble));
                    canvas.drawCircle(photoImage.getCenterX(), photoImage.getCenterY(), photoImage.getImageWidth() / 2, Theme.chat_docBackPaint);
                }
            } else if (currentMessageObject.type == MessageObject.TYPE_GEO) {
                rect.set(photoImage.getImageX(), photoImage.getImageY(), photoImage.getImageX2(), photoImage.getImageY2());
                Theme.chat_docBackPaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outLocationBackground : Theme.key_chat_inLocationBackground));
                int[] rad = photoImage.getRoundRadius();
                rectPath.reset();
                for (int a = 0; a < rad.length; a++) {
                    radii[a * 2] = radii[a * 2 + 1] = rad[a];
                }
                rectPath.addRoundRect(rect, radii, Path.Direction.CW);
                rectPath.close();
                canvas.drawPath(rectPath, Theme.chat_docBackPaint);
                Drawable iconDrawable = Theme.chat_locationDrawable[currentMessageObject.isOutOwner() ? 1 : 0];
                setDrawableBounds(iconDrawable, rect.centerX() - iconDrawable.getIntrinsicWidth() / 2, rect.centerY() - iconDrawable.getIntrinsicHeight() / 2);
                iconDrawable.draw(canvas);
            }
            drawMediaCheckBox = mediaCheckBox != null && (checkBoxVisible || mediaCheckBox.getProgress() != 0 || checkBoxAnimationInProgress) && currentMessagesGroup != null;
            if (drawMediaCheckBox && (mediaCheckBox.isChecked() || mediaCheckBox.getProgress() != 0 || checkBoxAnimationInProgress) && (!textIsSelectionMode())) {
                if (!currentMessagesGroup.isDocuments) {
                    Theme.chat_replyLinePaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outBubbleSelected : Theme.key_chat_inBubbleSelected));
                    rect.set(photoImage.getImageX(), photoImage.getImageY(), photoImage.getImageX2(), photoImage.getImageY2());
                    int[] rad = photoImage.getRoundRadius();
                    rectPath.reset();
                    for (int a = 0; a < rad.length; a++) {
                        radii[a * 2] = radii[a * 2 + 1] = rad[a];
                    }
                    rectPath.addRoundRect(rect, radii, Path.Direction.CW);
                    rectPath.close();
                    canvas.drawPath(rectPath, Theme.chat_replyLinePaint);
                }
                photoImage.setSideClip(AndroidUtilities.dp(14) * mediaCheckBox.getProgress());
                if (checkBoxAnimationInProgress) {
                    mediaCheckBox.setBackgroundAlpha(checkBoxAnimationProgress);
                } else {
                    mediaCheckBox.setBackgroundAlpha(checkBoxVisible ? 1.0f : mediaCheckBox.getProgress());
                }
            } else {
                photoImage.setSideClip(0);
            }
            if (delegate == null || delegate.getPinchToZoomHelper() == null || !delegate.getPinchToZoomHelper().isInOverlayModeFor(this)) {
                imageDrawn = photoImage.draw(canvas);
            }
            boolean drawTimeOld = drawTime;
            drawTime = photoImage.getVisible();
            if (currentPosition != null && drawTimeOld != drawTime) {
                ViewGroup viewGroup = (ViewGroup) getParent();
                if (viewGroup != null) {
                    if (!currentPosition.last) {
                        int count = viewGroup.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = viewGroup.getChildAt(a);
                            if (child == this || !(child instanceof ChatMessageCell)) {
                                continue;
                            }
                            ChatMessageCell cell = (ChatMessageCell) child;
                            if (cell.getCurrentMessagesGroup() == currentMessagesGroup) {
                                MessageObject.GroupedMessagePosition position = cell.getCurrentPosition();
                                if (position.last && position.maxY == currentPosition.maxY && cell.timeX - AndroidUtilities.dp(4) + cell.getLeft() < getRight()) {
                                    cell.groupPhotoInvisible = !drawTime;
                                    cell.invalidate();
                                    viewGroup.invalidate();
                                }
                            }
                        }
                    } else {
                        viewGroup.invalidate();
                    }
                }
            }
        }
    } else {
        if (documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC || documentAttachType == DOCUMENT_ATTACH_TYPE_DOCUMENT) {
            drawMediaCheckBox = mediaCheckBox != null && (checkBoxVisible || mediaCheckBox.getProgress() != 0 || checkBoxAnimationInProgress) && currentMessagesGroup != null;
            if (drawMediaCheckBox) {
                radialProgress.setCircleCrossfadeColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outTimeText : Theme.key_chat_inTimeText, checkBoxAnimationProgress, 1.0f - mediaCheckBox.getProgress());
            }
            if (drawMediaCheckBox && !textIsSelectionMode() && (mediaCheckBox.isChecked() || mediaCheckBox.getProgress() != 0 || checkBoxAnimationInProgress)) {
                if (checkBoxAnimationInProgress) {
                    mediaCheckBox.setBackgroundAlpha(checkBoxAnimationProgress);
                    if (radialProgress.getMiniIcon() == MediaActionDrawable.ICON_NONE) {
                        radialProgress.setMiniIconScale(checkBoxAnimationProgress);
                    }
                } else {
                    mediaCheckBox.setBackgroundAlpha(checkBoxVisible ? 1.0f : mediaCheckBox.getProgress());
                }
            } else if (mediaCheckBox != null) {
                mediaCheckBox.setBackgroundAlpha(1.0f);
            }
        }
    }
    if (documentAttachType == DOCUMENT_ATTACH_TYPE_GIF) {
        if (photoImage.getVisible() && !hasGamePreview && !currentMessageObject.needDrawBluredPreview()) {
            int oldAlpha = ((BitmapDrawable) Theme.chat_msgMediaMenuDrawable).getPaint().getAlpha();
            Theme.chat_msgMediaMenuDrawable.setAlpha((int) (oldAlpha * controlsAlpha));
            setDrawableBounds(Theme.chat_msgMediaMenuDrawable, otherX = (int) (photoImage.getImageX() + photoImage.getImageWidth() - AndroidUtilities.dp(14)), otherY = (int) (photoImage.getImageY() + AndroidUtilities.dp(8.1f)));
            Theme.chat_msgMediaMenuDrawable.draw(canvas);
            Theme.chat_msgMediaMenuDrawable.setAlpha(oldAlpha);
        }
    } else if (documentAttachType == DOCUMENT_ATTACH_TYPE_ROUND) {
        if (durationLayout != null) {
            boolean playing = MediaController.getInstance().isPlayingMessage(currentMessageObject);
            if (playing || roundProgressAlpha != 0) {
                if (playing) {
                    roundProgressAlpha = 1f;
                } else {
                    roundProgressAlpha -= 16 / 150f;
                    if (roundProgressAlpha < 0) {
                        roundProgressAlpha = 0;
                    } else {
                        invalidate();
                    }
                }
                drawRoundProgress(canvas);
            }
        }
    } else if (documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
        if (currentMessageObject.isOutOwner()) {
            Theme.chat_audioTitlePaint.setColor(getThemedColor(Theme.key_chat_outAudioTitleText));
            Theme.chat_audioPerformerPaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_outAudioPerformerSelectedText : Theme.key_chat_outAudioPerformerText));
            Theme.chat_audioTimePaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_outAudioDurationSelectedText : Theme.key_chat_outAudioDurationText));
            radialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() || buttonPressed != 0 ? Theme.key_chat_outAudioSelectedProgress : Theme.key_chat_outAudioProgress));
        } else {
            Theme.chat_audioTitlePaint.setColor(getThemedColor(Theme.key_chat_inAudioTitleText));
            Theme.chat_audioPerformerPaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_inAudioPerformerSelectedText : Theme.key_chat_inAudioPerformerText));
            Theme.chat_audioTimePaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_inAudioDurationSelectedText : Theme.key_chat_inAudioDurationText));
            radialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() || buttonPressed != 0 ? Theme.key_chat_inAudioSelectedProgress : Theme.key_chat_inAudioProgress));
        }
        radialProgress.setBackgroundDrawable(isDrawSelectionBackground() ? currentBackgroundSelectedDrawable : currentBackgroundDrawable);
        radialProgress.draw(canvas);
        canvas.save();
        canvas.translate(timeAudioX + songX, AndroidUtilities.dp(13) + namesOffset + mediaOffsetY);
        songLayout.draw(canvas);
        canvas.restore();
        boolean showSeekbar = MediaController.getInstance().isPlayingMessage(currentMessageObject);
        if (showSeekbar && toSeekBarProgress != 1f) {
            toSeekBarProgress += 16f / 100f;
            if (toSeekBarProgress > 1f) {
                toSeekBarProgress = 1f;
            }
            invalidate();
        } else if (!showSeekbar && toSeekBarProgress != 0) {
            toSeekBarProgress -= 16f / 100f;
            if (toSeekBarProgress < 0) {
                toSeekBarProgress = 0;
            }
            invalidate();
        }
        if (toSeekBarProgress > 0) {
            if (toSeekBarProgress != 1f) {
                canvas.saveLayerAlpha(seekBarX, seekBarY, seekBarX + seekBar.getWidth() + AndroidUtilities.dp(24), seekBarY + AndroidUtilities.dp(24), (int) (255 * (toSeekBarProgress)), Canvas.ALL_SAVE_FLAG);
            } else {
                canvas.save();
            }
            canvas.translate(seekBarX, seekBarY);
            seekBar.draw(canvas);
            canvas.restore();
        }
        if (toSeekBarProgress < 1f) {
            float x = timeAudioX + performerX;
            float y = AndroidUtilities.dp(35) + namesOffset + mediaOffsetY;
            if (toSeekBarProgress != 0) {
                canvas.saveLayerAlpha(x, y, x + performerLayout.getWidth(), y + performerLayout.getHeight(), (int) (255 * (1f - toSeekBarProgress)), Canvas.ALL_SAVE_FLAG);
            } else {
                canvas.save();
            }
            if (toSeekBarProgress != 0) {
                float s = 0.7f + 0.3f * (1f - toSeekBarProgress);
                canvas.scale(s, s, x, y + performerLayout.getHeight() / 2f);
            }
            canvas.translate(x, y);
            performerLayout.draw(canvas);
            canvas.restore();
        }
        canvas.save();
        canvas.translate(timeAudioX, AndroidUtilities.dp(57) + namesOffset + mediaOffsetY);
        durationLayout.draw(canvas);
        canvas.restore();
        if (shouldDrawMenuDrawable()) {
            Drawable menuDrawable;
            if (currentMessageObject.isOutOwner()) {
                menuDrawable = getThemedDrawable(isDrawSelectionBackground() ? Theme.key_drawable_msgOutMenuSelected : Theme.key_drawable_msgOutMenu);
            } else {
                menuDrawable = isDrawSelectionBackground() ? Theme.chat_msgInMenuSelectedDrawable : Theme.chat_msgInMenuDrawable;
            }
            setDrawableBounds(menuDrawable, otherX = (int) buttonX + backgroundWidth - AndroidUtilities.dp(currentMessageObject.type == 0 ? 58 : 48), otherY = (int) buttonY - AndroidUtilities.dp(2));
            if (transitionParams.animateChangeProgress != 1f && transitionParams.animateShouldDrawMenuDrawable) {
                menuDrawable.setAlpha((int) (255 * transitionParams.animateChangeProgress));
            }
            menuDrawable.draw(canvas);
            if (transitionParams.animateChangeProgress != 1f && transitionParams.animateShouldDrawMenuDrawable) {
                menuDrawable.setAlpha(255);
            }
        }
    } else if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO) {
        if (currentMessageObject.isOutOwner()) {
            Theme.chat_audioTimePaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_outAudioDurationSelectedText : Theme.key_chat_outAudioDurationText));
            radialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() || buttonPressed != 0 ? Theme.key_chat_outAudioSelectedProgress : Theme.key_chat_outAudioProgress));
        } else {
            Theme.chat_audioTimePaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_inAudioDurationSelectedText : Theme.key_chat_inAudioDurationText));
            radialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() || buttonPressed != 0 ? Theme.key_chat_inAudioSelectedProgress : Theme.key_chat_inAudioProgress));
        }
        AudioVisualizerDrawable audioVisualizerDrawable;
        if (MediaController.getInstance().isPlayingMessage(currentMessageObject)) {
            audioVisualizerDrawable = Theme.getCurrentAudiVisualizerDrawable();
        } else {
            audioVisualizerDrawable = Theme.getAnimatedOutAudioVisualizerDrawable(currentMessageObject);
        }
        if (audioVisualizerDrawable != null) {
            audioVisualizerDrawable.setParentView(this);
            audioVisualizerDrawable.draw(canvas, buttonX + AndroidUtilities.dp(22), buttonY + AndroidUtilities.dp(22), currentMessageObject.isOutOwner(), resourcesProvider);
        }
        if (!enterTransitionInPorgress) {
            radialProgress.setBackgroundDrawable(isDrawSelectionBackground() ? currentBackgroundSelectedDrawable : currentBackgroundDrawable);
            radialProgress.draw(canvas);
        }
        int seekBarX = this.seekBarX;
        int timeAudioX = this.timeAudioX;
        if (transitionParams.animateButton) {
            int offset = this.buttonX - (int) (transitionParams.animateFromButtonX * (1f - transitionParams.animateChangeProgress) + this.buttonX * (transitionParams.animateChangeProgress));
            seekBarX -= offset;
            timeAudioX -= offset;
        }
        canvas.save();
        if (useSeekBarWaweform) {
            canvas.translate(seekBarX + AndroidUtilities.dp(13), seekBarY);
            seekBarWaveform.draw(canvas, this);
        } else {
            canvas.translate(seekBarX, seekBarY);
            seekBar.draw(canvas);
        }
        canvas.restore();
        canvas.save();
        canvas.translate(timeAudioX, AndroidUtilities.dp(44) + namesOffset + mediaOffsetY);
        durationLayout.draw(canvas);
        canvas.restore();
        if (currentMessageObject.type != 0 && currentMessageObject.isContentUnread()) {
            Theme.chat_docBackPaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outVoiceSeekbarFill : Theme.key_chat_inVoiceSeekbarFill));
            canvas.drawCircle(timeAudioX + timeWidthAudio + AndroidUtilities.dp(6), AndroidUtilities.dp(51) + namesOffset + mediaOffsetY, AndroidUtilities.dp(3), Theme.chat_docBackPaint);
        }
    }
    if (captionLayout != null) {
        updateCaptionLayout();
    }
    updateReactionLayoutPosition();
    if (!currentMessageObject.preview && (currentPosition == null || (currentMessagesGroup != null && currentMessagesGroup.isDocuments && (currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) == 0)) && !transitionParams.animateBackgroundBoundsInner && !(enterTransitionInPorgress && currentMessageObject.isVoice())) {
        drawCaptionLayout(canvas, false, 1f);
    }
    if (hasOldCaptionPreview) {
        int linkX;
        if (currentMessageObject.type == MessageObject.TYPE_PHOTO || documentAttachType == DOCUMENT_ATTACH_TYPE_VIDEO || currentMessageObject.type == 8) {
            linkX = (int) (photoImage.getImageX() + AndroidUtilities.dp(5));
        } else {
            linkX = backgroundDrawableLeft + AndroidUtilities.dp(currentMessageObject.isOutOwner() ? 11 : 17);
        }
        int startY = totalHeight - AndroidUtilities.dp(drawPinnedTop ? 9 : 10) - linkPreviewHeight - AndroidUtilities.dp(8);
        int linkPreviewY = startY;
        Theme.chat_replyLinePaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outPreviewLine : Theme.key_chat_inPreviewLine));
        canvas.drawRect(linkX, linkPreviewY - AndroidUtilities.dp(3), linkX + AndroidUtilities.dp(2), linkPreviewY + linkPreviewHeight, Theme.chat_replyLinePaint);
        if (siteNameLayout != null) {
            Theme.chat_replyNamePaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outSiteNameText : Theme.key_chat_inSiteNameText));
            canvas.save();
            int x;
            if (siteNameRtl) {
                x = backgroundWidth - siteNameWidth - AndroidUtilities.dp(32);
            } else {
                x = (hasInvoicePreview ? 0 : AndroidUtilities.dp(10));
            }
            canvas.translate(linkX + x, linkPreviewY - AndroidUtilities.dp(3));
            siteNameLayout.draw(canvas);
            canvas.restore();
            linkPreviewY += siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
        }
        if (currentMessageObject.isOutOwner()) {
            Theme.chat_replyTextPaint.setColor(getThemedColor(Theme.key_chat_messageTextOut));
        } else {
            Theme.chat_replyTextPaint.setColor(getThemedColor(Theme.key_chat_messageTextIn));
        }
        if (descriptionLayout != null) {
            if (linkPreviewY != startY) {
                linkPreviewY += AndroidUtilities.dp(2);
            }
            descriptionY = linkPreviewY - AndroidUtilities.dp(3);
            canvas.save();
            canvas.translate(linkX + AndroidUtilities.dp(10) + descriptionX, descriptionY);
            descriptionLayout.draw(canvas);
            canvas.restore();
        }
        drawTime = true;
    }
    if (documentAttachType == DOCUMENT_ATTACH_TYPE_DOCUMENT) {
        Drawable menuDrawable;
        if (currentMessageObject.isOutOwner()) {
            Theme.chat_docNamePaint.setColor(getThemedColor(Theme.key_chat_outFileNameText));
            Theme.chat_infoPaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_outFileInfoSelectedText : Theme.key_chat_outFileInfoText));
            Theme.chat_docBackPaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_outFileBackgroundSelected : Theme.key_chat_outFileBackground));
            menuDrawable = getThemedDrawable(isDrawSelectionBackground() ? Theme.key_drawable_msgOutMenuSelected : Theme.key_drawable_msgOutMenu);
        } else {
            Theme.chat_docNamePaint.setColor(getThemedColor(Theme.key_chat_inFileNameText));
            Theme.chat_infoPaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_inFileInfoSelectedText : Theme.key_chat_inFileInfoText));
            Theme.chat_docBackPaint.setColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_inFileBackgroundSelected : Theme.key_chat_inFileBackground));
            menuDrawable = isDrawSelectionBackground() ? Theme.chat_msgInMenuSelectedDrawable : Theme.chat_msgInMenuDrawable;
        }
        float x;
        int titleY;
        int subtitleY;
        if (drawPhotoImage) {
            if (currentMessageObject.type == 0) {
                setDrawableBounds(menuDrawable, otherX = (int) (photoImage.getImageX() + backgroundWidth - AndroidUtilities.dp(56)), otherY = (int) (photoImage.getImageY() + AndroidUtilities.dp(4)));
            } else {
                setDrawableBounds(menuDrawable, otherX = (int) (photoImage.getImageX() + backgroundWidth - AndroidUtilities.dp(40)), otherY = (int) (photoImage.getImageY() + AndroidUtilities.dp(4)));
            }
            x = (int) (photoImage.getImageX() + photoImage.getImageWidth() + AndroidUtilities.dp(10));
            titleY = (int) (photoImage.getImageY() + AndroidUtilities.dp(8));
            subtitleY = (int) (photoImage.getImageY() + (docTitleLayout != null ? docTitleLayout.getLineBottom(docTitleLayout.getLineCount() - 1) + AndroidUtilities.dp(13) : AndroidUtilities.dp(8)));
            if (!imageDrawn) {
                if (currentMessageObject.isOutOwner()) {
                    radialProgress.setColors(Theme.key_chat_outLoader, Theme.key_chat_outLoaderSelected, Theme.key_chat_outMediaIcon, Theme.key_chat_outMediaIconSelected);
                    radialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_outFileProgressSelected : Theme.key_chat_outFileProgress));
                    videoRadialProgress.setColors(Theme.key_chat_outLoader, Theme.key_chat_outLoaderSelected, Theme.key_chat_outMediaIcon, Theme.key_chat_outMediaIconSelected);
                    videoRadialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_outFileProgressSelected : Theme.key_chat_outFileProgress));
                } else {
                    radialProgress.setColors(Theme.key_chat_inLoader, Theme.key_chat_inLoaderSelected, Theme.key_chat_inMediaIcon, Theme.key_chat_inMediaIconSelected);
                    radialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_inFileProgressSelected : Theme.key_chat_inFileProgress));
                    videoRadialProgress.setColors(Theme.key_chat_inLoader, Theme.key_chat_inLoaderSelected, Theme.key_chat_inMediaIcon, Theme.key_chat_inMediaIconSelected);
                    videoRadialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() ? Theme.key_chat_inFileProgressSelected : Theme.key_chat_inFileProgress));
                }
                rect.set(photoImage.getImageX(), photoImage.getImageY(), photoImage.getImageX() + photoImage.getImageWidth(), photoImage.getImageY() + photoImage.getImageHeight());
                int[] rad = photoImage.getRoundRadius();
                rectPath.reset();
                for (int a = 0; a < rad.length; a++) {
                    radii[a * 2] = rad[a];
                    radii[a * 2 + 1] = rad[a];
                }
                rectPath.addRoundRect(rect, radii, Path.Direction.CW);
                rectPath.close();
                canvas.drawPath(rectPath, Theme.chat_docBackPaint);
            } else {
                radialProgress.setColors(Theme.key_chat_mediaLoaderPhoto, Theme.key_chat_mediaLoaderPhotoSelected, Theme.key_chat_mediaLoaderPhotoIcon, Theme.key_chat_mediaLoaderPhotoIconSelected);
                radialProgress.setProgressColor(getThemedColor(Theme.key_chat_mediaProgress));
                videoRadialProgress.setColors(Theme.key_chat_mediaLoaderPhoto, Theme.key_chat_mediaLoaderPhotoSelected, Theme.key_chat_mediaLoaderPhotoIcon, Theme.key_chat_mediaLoaderPhotoIconSelected);
                videoRadialProgress.setProgressColor(getThemedColor(Theme.key_chat_mediaProgress));
                if (buttonState == -1 && radialProgress.getIcon() != MediaActionDrawable.ICON_NONE) {
                    radialProgress.setIcon(MediaActionDrawable.ICON_NONE, true, true);
                }
            }
        } else {
            setDrawableBounds(menuDrawable, otherX = (int) buttonX + backgroundWidth - AndroidUtilities.dp(currentMessageObject.type == 0 ? 58 : 48), otherY = (int) buttonY - AndroidUtilities.dp(2));
            x = buttonX + AndroidUtilities.dp(53);
            titleY = (int) buttonY + AndroidUtilities.dp(4);
            subtitleY = (int) buttonY + AndroidUtilities.dp(27);
            if (docTitleLayout != null && docTitleLayout.getLineCount() > 1) {
                subtitleY += (docTitleLayout.getLineCount() - 1) * AndroidUtilities.dp(16) + AndroidUtilities.dp(2);
            }
            if (currentMessageObject.isOutOwner()) {
                radialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() || buttonPressed != 0 ? Theme.key_chat_outAudioSelectedProgress : Theme.key_chat_outAudioProgress));
                videoRadialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() || videoButtonPressed != 0 ? Theme.key_chat_outAudioSelectedProgress : Theme.key_chat_outAudioProgress));
            } else {
                radialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() || buttonPressed != 0 ? Theme.key_chat_inAudioSelectedProgress : Theme.key_chat_inAudioProgress));
                videoRadialProgress.setProgressColor(getThemedColor(isDrawSelectionBackground() || videoButtonPressed != 0 ? Theme.key_chat_inAudioSelectedProgress : Theme.key_chat_inAudioProgress));
            }
        }
        if (shouldDrawMenuDrawable()) {
            if (transitionParams.animateChangeProgress != 1f && transitionParams.animateShouldDrawMenuDrawable) {
                menuDrawable.setAlpha((int) (255 * transitionParams.animateChangeProgress));
            }
            menuDrawable.draw(canvas);
            if (transitionParams.animateChangeProgress != 1f && transitionParams.animateShouldDrawMenuDrawable) {
                menuDrawable.setAlpha(255);
            }
        }
        try {
            if (docTitleLayout != null) {
                canvas.save();
                canvas.translate(x + docTitleOffsetX, titleY);
                docTitleLayout.draw(canvas);
                canvas.restore();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
        try {
            if (infoLayout != null) {
                canvas.save();
                canvas.translate(x, subtitleY);
                if (buttonState == 1 && loadingProgressLayout != null) {
                    loadingProgressLayout.draw(canvas);
                } else {
                    infoLayout.draw(canvas);
                }
                canvas.restore();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
    if (currentMessageObject.type == MessageObject.TYPE_GEO && !(currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) && currentMapProvider == 2 && photoImage.hasNotThumb()) {
        int w = (int) (Theme.chat_redLocationIcon.getIntrinsicWidth() * 0.8f);
        int h = (int) (Theme.chat_redLocationIcon.getIntrinsicHeight() * 0.8f);
        int x = (int) (photoImage.getImageX() + (photoImage.getImageWidth() - w) / 2);
        int y = (int) (photoImage.getImageY() + (photoImage.getImageHeight() / 2 - h));
        Theme.chat_redLocationIcon.setAlpha((int) (255 * photoImage.getCurrentAlpha()));
        Theme.chat_redLocationIcon.setBounds(x, y, x + w, y + h);
        Theme.chat_redLocationIcon.draw(canvas);
    }
    transitionParams.recordDrawingState();
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) MediaActionDrawable(org.telegram.ui.Components.MediaActionDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) SlotsDrawable(org.telegram.ui.Components.SlotsDrawable) BackgroundGradientDrawable(org.telegram.ui.Components.BackgroundGradientDrawable) VideoForwardDrawable(org.telegram.ui.Components.VideoForwardDrawable) RoundVideoPlayingDrawable(org.telegram.ui.Components.RoundVideoPlayingDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) MotionBackgroundDrawable(org.telegram.ui.Components.MotionBackgroundDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) AudioVisualizerDrawable(org.telegram.ui.Components.AudioVisualizerDrawable) MsgClockDrawable(org.telegram.ui.Components.MsgClockDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) View(android.view.View) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(org.telegram.ui.Components.Point) TLRPC(org.telegram.tgnet.TLRPC) AudioVisualizerDrawable(org.telegram.ui.Components.AudioVisualizerDrawable)

Aggregations

AudioVisualizerDrawable (org.telegram.ui.Components.AudioVisualizerDrawable)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 Rect (android.graphics.Rect)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 RippleDrawable (android.graphics.drawable.RippleDrawable)1 TextPaint (android.text.TextPaint)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TLRPC (org.telegram.tgnet.TLRPC)1 AnimatedFileDrawable (org.telegram.ui.Components.AnimatedFileDrawable)1 AvatarDrawable (org.telegram.ui.Components.AvatarDrawable)1 BackgroundGradientDrawable (org.telegram.ui.Components.BackgroundGradientDrawable)1 MediaActionDrawable (org.telegram.ui.Components.MediaActionDrawable)1 MessageBackgroundDrawable (org.telegram.ui.Components.MessageBackgroundDrawable)1 MotionBackgroundDrawable (org.telegram.ui.Components.MotionBackgroundDrawable)1 MsgClockDrawable (org.telegram.ui.Components.MsgClockDrawable)1 Point (org.telegram.ui.Components.Point)1 RLottieDrawable (org.telegram.ui.Components.RLottieDrawable)1