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);
}
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();
}
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);
}
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();
}
}
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);
}
Aggregations