first commit

This commit is contained in:
Elijah Kuntz 2026-10-17 22:38:45 -07:00
commit f5f1c0928f
39 changed files with 4478 additions and 0 deletions

View file

@ -0,0 +1,188 @@
package tv.luma.launcher;
import android.content.Context;
import android.graphics.*;
import android.view.*;
import android.view.animation.DecelerateInterpolator;
import android.widget.*;
/** Real focusable view: native D-pad navigation and accessibility labels. */
final class AppTile extends LinearLayout {
private final ArtView art;
private final TextView label;
private boolean motion = true;
private String labelMode = "always";
interface Focus {
void changed(boolean hasFocus);
}
AppTile(Context c, String name, int width, boolean compact) {
super(c);
setOrientation(VERTICAL);
setGravity(Gravity.CENTER_HORIZONTAL);
setFocusable(true);
setClickable(true);
setClipChildren(false);
setClipToPadding(false);
setContentDescription(name);
setPadding(Ui.dp(c, 5), Ui.dp(c, 7), Ui.dp(c, 5), Ui.dp(c, 7));
art = new ArtView(c, name);
int height = Math.round((width - 10) * 9f / 16f);
addView(art, new LinearLayout.LayoutParams(Ui.dp(c, width - 10), Ui.dp(c, height)));
label = Ui.text(c, name, compact ? 11 : 12, Ui.MUTED);
label.setSingleLine(true);
label.setEllipsize(android.text.TextUtils.TruncateAt.END);
label.setGravity(Gravity.CENTER);
label.setPadding(0, Ui.dp(c, 9), 0, 0);
addView(label, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, Ui.dp(c, 28)));
setOnFocusChangeListener(
(v, f) -> {
animate().cancel();
animate()
.scaleX(f ? 1.065f : 1f)
.scaleY(f ? 1.065f : 1f)
.translationZ(f ? Ui.dp(c, 8) : 0)
.setDuration(motion ? 160 : 0)
.setInterpolator(new DecelerateInterpolator())
.start();
label.setTextColor(f ? Ui.WHITE : Ui.MUTED);
updateLabel();
art.focus = f;
art.animate().translationZ(Ui.dp(c, f ? 8 : 1)).setDuration(motion ? 160 : 0).start();
art.invalidate();
if (focus != null) focus.changed(f);
});
}
private Focus focus;
void onFocused(Focus f) {
focus = f;
}
void setMotion(boolean enabled) {
motion = enabled;
}
void setLabelMode(String mode) {
labelMode = mode;
updateLabel();
}
private void updateLabel() {
label.setVisibility(
labelMode.equals("never")
? View.GONE
: labelMode.equals("focused") && !hasFocus() ? View.INVISIBLE : View.VISIBLE);
}
void setAccent(int color) {
if (android.os.Build.VERSION.SDK_INT >= 28) {
art.setOutlineAmbientShadowColor(color);
art.setOutlineSpotShadowColor(color);
}
}
void stopAnimations() {
animate().cancel();
art.animate().cancel();
}
void bitmap(Bitmap b) {
art.bitmap = b;
art.invalidate();
}
void progress(float value) {
art.progress = value;
art.invalidate();
}
private static final class ArtView extends View {
final Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
final RectF rect = new RectF();
final Path clip = new Path();
Bitmap bitmap;
boolean focus;
String fallback;
float progress;
ArtView(Context c, String s) {
super(c);
fallback = s;
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
setElevation(Ui.dp(c, 2));
setOutlineProvider(
new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(
2,
2,
Math.max(3, view.getWidth() - 2),
Math.max(3, view.getHeight() - 2),
Ui.dp(c, 12));
}
});
}
protected void onSizeChanged(int w, int h, int ow, int oh) {
rect.set(
Ui.dp(getContext(), 2),
Ui.dp(getContext(), 2),
w - Ui.dp(getContext(), 2),
h - Ui.dp(getContext(), 2));
clip.reset();
clip.addRoundRect(rect, Ui.dp(getContext(), 12), Ui.dp(getContext(), 12), Path.Direction.CW);
}
protected void onDraw(Canvas c) {
c.save();
c.clipPath(clip);
p.setColor(0xFF1B263B);
c.drawRect(rect, p);
if (bitmap != null) {
float scale =
Math.max(rect.width() / bitmap.getWidth(), rect.height() / bitmap.getHeight());
float w = bitmap.getWidth() * scale, h = bitmap.getHeight() * scale;
c.drawBitmap(
bitmap,
null,
new RectF(
rect.centerX() - w / 2,
rect.centerY() - h / 2,
rect.centerX() + w / 2,
rect.centerY() + h / 2),
p);
} else {
p.setColor(Ui.WHITE);
p.setTextSize(Ui.dp(getContext(), 17));
p.setTypeface(Typeface.create("sans-serif-medium", 0));
p.setTextAlign(Paint.Align.CENTER);
c.drawText(
fallback.length() > 15 ? fallback.substring(0, 14) + "…" : fallback,
rect.centerX(),
rect.centerY() + Ui.dp(getContext(), 5),
p);
}
if (progress > 0) {
p.setColor(0xA0080D18);
c.drawRect(rect.left, rect.bottom - Ui.dp(getContext(), 4), rect.right, rect.bottom, p);
p.setColor(Ui.GOLD);
c.drawRect(
rect.left,
rect.bottom - Ui.dp(getContext(), 4),
rect.left + rect.width() * progress,
rect.bottom,
p);
}
c.restore();
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(Ui.dp(getContext(), focus ? 1.5f : 1));
p.setColor(focus ? 0xDBF4E8D8 : 0x26FFFFFF);
c.drawRoundRect(rect, Ui.dp(getContext(), 12), Ui.dp(getContext(), 12), p);
p.setStyle(Paint.Style.FILL);
}
}
}