Search in sources :

Example 1 with SpoilerEffect

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

the class SharedLinkCell method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean result = false;
    if (message != null && !linkLayout.isEmpty() && delegate != null && delegate.canPerformActions()) {
        if (event.getAction() == MotionEvent.ACTION_DOWN || (linkPreviewPressed || spoilerPressed != null) && event.getAction() == MotionEvent.ACTION_UP) {
            int x = (int) event.getX();
            int y = (int) event.getY();
            int offset = 0;
            boolean ok = false;
            for (int a = 0; a < linkLayout.size(); a++) {
                StaticLayout layout = linkLayout.get(a);
                if (layout.getLineCount() > 0) {
                    int height = layout.getLineBottom(layout.getLineCount() - 1);
                    int linkPosX = AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline);
                    if (x >= linkPosX + layout.getLineLeft(0) && x <= linkPosX + layout.getLineWidth(0) && y >= linkY + offset && y <= linkY + offset + height) {
                        ok = true;
                        if (event.getAction() == MotionEvent.ACTION_DOWN) {
                            resetPressedLink();
                            spoilerPressed = null;
                            if (linkSpoilers.get(a, null) != null) {
                                for (SpoilerEffect eff : linkSpoilers.get(a)) {
                                    if (eff.getBounds().contains(x - linkPosX, y - linkY - offset)) {
                                        spoilerPressed = eff;
                                        spoilerTypePressed = SPOILER_TYPE_LINK;
                                        break;
                                    }
                                }
                            }
                            if (spoilerPressed != null) {
                                result = true;
                            } else {
                                pressedLink = a;
                                linkPreviewPressed = true;
                                startCheckLongPress();
                                try {
                                    urlPath.setCurrentLayout(layout, 0, 0);
                                    layout.getSelectionPath(0, layout.getText().length(), urlPath);
                                } catch (Exception e) {
                                    FileLog.e(e);
                                }
                                result = true;
                            }
                        } else if (linkPreviewPressed) {
                            try {
                                TLRPC.WebPage webPage = pressedLink == 0 && message.messageOwner.media != null ? message.messageOwner.media.webpage : null;
                                if (webPage != null && webPage.embed_url != null && webPage.embed_url.length() != 0) {
                                    delegate.needOpenWebView(webPage, message);
                                } else {
                                    delegate.onLinkPress(links.get(pressedLink).toString(), false);
                                }
                            } catch (Exception e) {
                                FileLog.e(e);
                            }
                            resetPressedLink();
                            result = true;
                        } else if (spoilerPressed != null) {
                            startSpoilerRipples(x, y, offset);
                            result = true;
                        }
                        break;
                    }
                    offset += height;
                }
            }
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                int offX = AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline);
                if (descriptionLayout != null && x >= offX && x <= offX + descriptionLayout.getWidth() && y >= descriptionY && y <= descriptionY + descriptionLayout.getHeight()) {
                    for (SpoilerEffect eff : descriptionLayoutSpoilers) {
                        if (eff.getBounds().contains(x - offX, y - descriptionY)) {
                            spoilerPressed = eff;
                            spoilerTypePressed = SPOILER_TYPE_DESCRIPTION;
                            ok = true;
                            result = true;
                            break;
                        }
                    }
                }
                if (descriptionLayout2 != null && x >= offX && x <= offX + descriptionLayout2.getWidth() && y >= description2Y && y <= description2Y + descriptionLayout2.getHeight()) {
                    for (SpoilerEffect eff : descriptionLayout2Spoilers) {
                        if (eff.getBounds().contains(x - offX, y - description2Y)) {
                            spoilerPressed = eff;
                            spoilerTypePressed = SPOILER_TYPE_DESCRIPTION2;
                            ok = true;
                            result = true;
                            break;
                        }
                    }
                }
            } else if (event.getAction() == MotionEvent.ACTION_UP && spoilerPressed != null) {
                startSpoilerRipples(x, y, 0);
                ok = true;
                result = true;
            }
            if (!ok) {
                resetPressedLink();
            }
        } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
            resetPressedLink();
        }
    } else {
        resetPressedLink();
    }
    return result || super.onTouchEvent(event);
}
Also used : SpoilerEffect(org.telegram.ui.Components.spoilers.SpoilerEffect) StaticLayout(android.text.StaticLayout) SuppressLint(android.annotation.SuppressLint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 2 with SpoilerEffect

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

the class EditTextEffects method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    canvas.save();
    path.rewind();
    for (SpoilerEffect eff : spoilers) {
        Rect bounds = eff.getBounds();
        path.addRect(bounds.left, bounds.top, bounds.right, bounds.bottom, Path.Direction.CW);
    }
    canvas.clipPath(path, Region.Op.DIFFERENCE);
    super.onDraw(canvas);
    canvas.restore();
    canvas.save();
    canvas.clipPath(path);
    path.rewind();
    if (!spoilers.isEmpty())
        spoilers.get(0).getRipplePath(path);
    canvas.clipPath(path);
    canvas.translate(0, -getPaddingTop());
    super.onDraw(canvas);
    canvas.restore();
    rect.set(0, getScrollY(), getWidth(), getScrollY() + getHeight() - getPaddingBottom());
    canvas.save();
    canvas.clipRect(rect);
    for (SpoilerEffect eff : spoilers) {
        Rect b = eff.getBounds();
        if (rect.top <= b.bottom && rect.bottom >= b.top || b.top <= rect.bottom && b.bottom >= rect.top) {
            eff.setColor(getPaint().getColor());
            eff.draw(canvas);
        }
    }
    canvas.restore();
}
Also used : SpoilerEffect(org.telegram.ui.Components.spoilers.SpoilerEffect) Rect(android.graphics.Rect)

Example 3 with SpoilerEffect

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

the class SimpleTextView method clipOutSpoilers.

private void clipOutSpoilers(Canvas canvas) {
    path.rewind();
    for (SpoilerEffect eff : spoilers) {
        Rect b = eff.getBounds();
        path.addRect(b.left, b.top, b.right, b.bottom, Path.Direction.CW);
    }
    canvas.clipPath(path, Region.Op.DIFFERENCE);
}
Also used : SpoilerEffect(org.telegram.ui.Components.spoilers.SpoilerEffect) Rect(android.graphics.Rect)

Example 4 with SpoilerEffect

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

the class ChatActionCell method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    if (currentMessageObject != null && currentMessageObject.type == 11) {
        imageReceiver.draw(canvas);
    }
    if (textLayout == null) {
        return;
    }
    drawBackground(canvas, false);
    if (textPaint != null) {
        canvas.save();
        canvas.translate(textXLeft, textY);
        if (textLayout.getPaint() != textPaint) {
            buildLayout();
        }
        canvas.save();
        SpoilerEffect.clipOutCanvas(canvas, spoilers);
        textLayout.draw(canvas);
        canvas.restore();
        for (SpoilerEffect eff : spoilers) {
            eff.setColor(textLayout.getPaint().getColor());
            eff.draw(canvas);
        }
        canvas.restore();
    }
}
Also used : SpoilerEffect(org.telegram.ui.Components.spoilers.SpoilerEffect)

Example 5 with SpoilerEffect

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

the class EditTextEffects method onSpoilerClicked.

private void onSpoilerClicked(SpoilerEffect eff, float x, float y) {
    if (isSpoilersRevealed)
        return;
    lastRippleX = x;
    lastRippleY = y;
    postedSpoilerTimeout = false;
    removeCallbacks(spoilerTimeout);
    setSpoilersRevealed(true, false);
    eff.setOnRippleEndCallback(() -> post(() -> {
        invalidateSpoilers();
        checkSpoilerTimeout();
    }));
    float rad = (float) Math.sqrt(Math.pow(getWidth(), 2) + Math.pow(getHeight(), 2));
    for (SpoilerEffect ef : spoilers) ef.startRipple(x, y, rad);
}
Also used : SpoilerEffect(org.telegram.ui.Components.spoilers.SpoilerEffect)

Aggregations

SpoilerEffect (org.telegram.ui.Components.spoilers.SpoilerEffect)12 SuppressLint (android.annotation.SuppressLint)7 Paint (android.graphics.Paint)7 TextPaint (android.text.TextPaint)7 StaticLayout (android.text.StaticLayout)5 Rect (android.graphics.Rect)4 Layout (android.text.Layout)2 Spannable (android.text.Spannable)2 View (android.view.View)2 RecyclerListView (org.telegram.ui.Components.RecyclerListView)2 Canvas (android.graphics.Canvas)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 ArrayList (java.util.ArrayList)1 MessageObject (org.telegram.messenger.MessageObject)1 TLRPC (org.telegram.tgnet.TLRPC)1