Color preference: fix crash on Android < N
Change-Id: Id14a76c1933028a97c1da43dbcce61bd92547d65
This commit is contained in:
parent
6bca1bf18b
commit
69d90fc8dd
|
@ -21,6 +21,7 @@ import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
@ -121,12 +122,17 @@ public class ColorMatrixListPreferenceDialogFragment extends PreferenceDialogFra
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDarkTheme() {
|
private boolean isDarkTheme() {
|
||||||
TypedValue tv = new TypedValue();
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
getContext().getTheme().resolveAttribute(android.R.attr.colorBackground, tv, true);
|
TypedValue tv = new TypedValue();
|
||||||
int bgColor = tv.data;
|
getContext().getTheme().resolveAttribute(android.R.attr.colorBackground, tv, true);
|
||||||
getContext().getTheme().resolveAttribute(android.R.attr.colorForeground, tv, true);
|
int bgColor = tv.data;
|
||||||
int fgColor = tv.data;
|
getContext().getTheme().resolveAttribute(android.R.attr.colorForeground, tv, true);
|
||||||
return Color.luminance(fgColor) > Color.luminance(bgColor);
|
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() {
|
private int getAccentColor() {
|
||||||
|
|
Loading…
Reference in New Issue