From a34a091cdb99158882a8455633b1d865e1a3ced7 Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Tue, 30 Sep 2025 23:27:11 +0200 Subject: [PATCH] Fix crash on missing header colors An off-by-one error caused invalid colour info to sometimes be generated if no header colour was set. Under normal conditions, a header colour should always be set, but due to some bugs in the past in some cases they may not be set. Sadly this does change the card colours for cards which are not properly initialized. But that's better than a crash at least. --- app/src/main/java/protect/card_locker/LetterBitmap.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/src/main/java/protect/card_locker/LetterBitmap.java b/app/src/main/java/protect/card_locker/LetterBitmap.java index 3964ca0b0..73ae8d79e 100644 --- a/app/src/main/java/protect/card_locker/LetterBitmap.java +++ b/app/src/main/java/protect/card_locker/LetterBitmap.java @@ -22,11 +22,6 @@ import androidx.core.graphics.PaintCompat; * is shown instead. */ class LetterBitmap { - - /** - * The number of available tile colors - */ - private static final int NUM_OF_TILE_COLORS = 8; /** * The letter bitmap */ @@ -121,7 +116,7 @@ class LetterBitmap { private static int pickColor(String key, TypedArray colors) { // String.hashCode() is not supposed to change across java versions, so // this should guarantee the same key always maps to the same color - final int color = Math.abs(key.hashCode()) % NUM_OF_TILE_COLORS; + final int color = Math.abs(key.hashCode()) % colors.length(); return colors.getColor(color, Color.BLACK); }