Files
LihonT-Store/src/lihonstore/app/ArtView.java
cheb0chik e8277bb7e8 LihonT Store 0.1
A catalog app for the LihonT mod: avatar frames and chat bubbles made by members. Browse, add with the plus button, author profiles,
publishing with a check before anything is shown. Signs in through the TikTok that carries the mod, which hands over only the public
account data to an app signed with the same key.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 15:40:01 +03:00

101 lines
3.9 KiB
Java

package lihonstore.app;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.view.View;
/**
* How an item looks on a card: a frame is drawn round a plain avatar the way the mod draws it (the picture is OVERLAY times as wide as
* the avatar), a chat picture is drawn as the background of a small message.
*/
final class ArtView extends View implements Images.Ready {
private final Theme theme;
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
private final RectF box = new RectF();
private final Path clip = new Path();
private String id;
private boolean frame;
private Bitmap bitmap;
ArtView(Context context, Theme theme) {
super(context);
this.theme = theme;
}
void show(String id, boolean frame) {
this.id = id;
this.frame = frame;
bitmap = id == null ? null : Images.get(id, this);
invalidate();
}
@Override public void done(Bitmap ready) {
bitmap = ready;
invalidate();
}
@Override protected void onDraw(Canvas canvas) {
float w = getWidth();
float h = getHeight();
box.set(0, 0, w, h);
paint.setColor(theme.surfaceHigh);
canvas.drawRoundRect(box, theme.dp(16), theme.dp(16), paint);
if (frame) drawFrame(canvas, w, h); else drawBubble(canvas, w, h);
}
private void drawFrame(Canvas canvas, float w, float h) {
float side = Math.min(w, h) * 0.92f;
float cx = w / 2f;
float cy = h / 2f;
float disc = side / Cut.OVERLAY / 2f;
paint.setColor(theme.accentSoft);
canvas.drawCircle(cx, cy, disc, paint);
paint.setColor(theme.onAccentSoft);
canvas.drawCircle(cx, cy - disc * 0.18f, disc * 0.3f, paint);
RectF body = new RectF(cx - disc * 0.55f, cy + disc * 0.25f, cx + disc * 0.55f, cy + disc * 1.2f);
canvas.save();
clip.reset();
clip.addCircle(cx, cy, disc, Path.Direction.CW);
canvas.clipPath(clip);
canvas.drawOval(body, paint);
canvas.restore();
if (bitmap != null) {
box.set(cx - side / 2f, cy - side / 2f, cx + side / 2f, cy + side / 2f);
canvas.drawBitmap(bitmap, null, box, paint);
}
}
private void drawBubble(Canvas canvas, float w, float h) {
float bw = w * 0.82f;
float bh = Math.min(h * 0.5f, bw * 0.5f);
box.set((w - bw) / 2f, (h - bh) / 2f, (w + bw) / 2f, (h + bh) / 2f);
float radius = theme.dp(18);
if (bitmap == null) {
paint.setColor(theme.accentSoft);
canvas.drawRoundRect(box, radius, radius, paint);
return;
}
canvas.save();
clip.reset();
clip.addRoundRect(box, radius, radius, Path.Direction.CW);
canvas.clipPath(clip);
float scale = Math.max(box.width() / bitmap.getWidth(), box.height() / bitmap.getHeight());
float sw = box.width() / scale;
float sh = box.height() / scale;
android.graphics.Rect source = new android.graphics.Rect(Math.round((bitmap.getWidth() - sw) / 2f), Math.round((bitmap.getHeight() - sh) / 2f),
Math.round((bitmap.getWidth() + sw) / 2f), Math.round((bitmap.getHeight() + sh) / 2f));
canvas.drawBitmap(bitmap, source, box, paint);
canvas.restore();
int middle = bitmap.getPixel(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
float light = (0.299f * ((middle >> 16) & 0xFF) + 0.587f * ((middle >> 8) & 0xFF) + 0.114f * (middle & 0xFF)) / 255f;
paint.setColor(light < 0.55f ? 0xFFFFFFFF : 0xFF111111);
paint.setTextSize(theme.dp(15));
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText("Привет!", box.centerX(), box.centerY() + theme.dp(5), paint);
}
}