Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

Photo Prints: a drawn halo for the shadow, the same under every print

Shivam Singh0f321870245d
diff --git a/addons/photo-screensaver/app/src/main/java/io/github/shivamsingh262/photoprints/PrintShadow.java b/addons/photo-screensaver/app/src/main/java/io/github/shivamsingh262/photoprints/PrintShadow.java
new file mode 100644
index 000000000..e95dbbff1
--- /dev/null
+++ b/addons/photo-screensaver/app/src/main/java/io/github/shivamsingh262/photoprints/PrintShadow.java
@@ -0,0 +1,60 @@
+package io.github.shivamsingh262.photoprints;
+
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+
+/**
+ * The shadow under a print, drawn here rather than by elevation: Android's own shadow comes from a light at the top
+ * of the screen, so each print's leaned a different way and showed as a grey band down one side. This one is the
+ * same under every print and tilts with it. It sits behind the photo, inset by the print's clear margin.
+ */
+final class PrintShadow extends Drawable {
+
+ private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ private final RectF card = new RectF();
+ private final float inset, radius;
+
+ /**
+ * @param inset the clear margin around the photo, px
+ * @param radius the photo's corner radius, px
+ * @param blur how soft the shadow is, px
+ * @param dy how far it falls below the photo, px
+ * @param color the shadow's colour, alpha included
+ */
+ PrintShadow(float inset, float radius, float blur, float dy, int color) {
+ this.inset = inset;
+ this.radius = radius;
+ paint.setColor(0xFF101014);
+ paint.setShadowLayer(blur, 0f, dy, color);
+ }
+
+ @Override
+ protected void onBoundsChange(Rect bounds) {
+ card.set(bounds.left + inset, bounds.top + inset, bounds.right - inset, bounds.bottom - inset);
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ canvas.drawRoundRect(card, radius, radius, paint);
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ paint.setAlpha(alpha);
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter colorFilter) {
+ paint.setColorFilter(colorFilter);
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.TRANSLUCENT;
+ }
+}
diff --git a/addons/photo-screensaver/app/src/main/java/io/github/shivamsingh262/photoprints/Prints.java b/addons/photo-screensaver/app/src/main/java/io/github/shivamsingh262/photoprints/Prints.java
index 3cb791fd3..008476953 100644
--- a/addons/photo-screensaver/app/src/main/java/io/github/shivamsingh262/photoprints/Prints.java
+++ b/addons/photo-screensaver/app/src/main/java/io/github/shivamsingh262/photoprints/Prints.java
@@ -92,6 +92,7 @@ final class Prints {
cards[i] = inflater.inflate(R.layout.print, stage, false);
// Drawn into a layer with a clear margin, the tilted print is filtered as one image: smooth edges.
cards[i].setLayerType(View.LAYER_TYPE_HARDWARE, null);
+ cards[i].setBackground(shadow(context, density));
cards[i].findViewById(R.id.printCard).setClipToOutline(true); // the photo takes the rounded corners
photoViews[i] = cards[i].findViewById(R.id.printPhoto);
dateViews[i] = cards[i].findViewById(R.id.printDate);
@@ -265,6 +266,12 @@ final class Prints {
clock.bringToFront();
}
+ /** A soft halo all round each print, a little deeper below, the same under every print. */
+ private static PrintShadow shadow(Context context, float density) {
+ float inset = context.getResources().getDimensionPixelSize(R.dimen.print_shadow_room);
+ return new PrintShadow(inset, 16 * density, 22 * density, 4 * density, 0x73000000);
+ }
+
private void nudgeClock() {
float d = density * NUDGE_DP;
clock.animate().translationX((random.nextFloat() * 2 - 1) * d)
diff --git a/addons/photo-screensaver/app/src/main/res/layout/print.xml b/addons/photo-screensaver/app/src/main/res/layout/print.xml
index c094478cc..cc6e16964 100644
--- a/addons/photo-screensaver/app/src/main/res/layout/print.xml
+++ b/addons/photo-screensaver/app/src/main/res/layout/print.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- One print: the whole photo with rounded corners and a soft shadow, its month and year in white over a fade
- along its foot. Prints sizes the photo to its own shape, so nothing is cropped.
+<!-- One print: the whole photo with rounded corners, its month and year in white over a fade along its foot, and a
+ soft halo for a shadow (PrintShadow, the outer frame's background). Prints sizes the photo to its own shape, so
+ nothing is cropped.
The outer frame is a clear margin the photo and its shadow are drawn into as one hardware layer: tilted, the
layer is filtered as a whole, so the edges come out smooth instead of stair-stepped. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
@@ -14,8 +15,7 @@
android:id="@+id/printCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:background="@drawable/print_card"
- android:elevation="12dp">
+ android:background="@drawable/print_card">
<ImageView
android:id="@+id/printPhoto"