Color preference: fix crash on Android < N

Change-Id: Id14a76c1933028a97c1da43dbcce61bd92547d65
This commit is contained in:
SpiritCroc 2021-11-12 12:05:21 +01:00
parent 6bca1bf18b
commit 69d90fc8dd
1 changed files with 12 additions and 6 deletions

View File

@ -21,6 +21,7 @@ import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
@ -121,12 +122,17 @@ public class ColorMatrixListPreferenceDialogFragment extends PreferenceDialogFra
}
private boolean isDarkTheme() {
TypedValue tv = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.colorBackground, tv, true);
int bgColor = tv.data;
getContext().getTheme().resolveAttribute(android.R.attr.colorForeground, tv, true);
int fgColor = tv.data;
return Color.luminance(fgColor) > Color.luminance(bgColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
TypedValue tv = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.colorBackground, tv, true);
int bgColor = tv.data;
getContext().getTheme().resolveAttribute(android.R.attr.colorForeground, tv, true);
int fgColor = tv.data;
return Color.luminance(fgColor) > Color.luminance(bgColor);
} else {
// We might want to implement a fallback here, but for now, let's just not care
return false;
}
}
private int getAccentColor() {