Signal-Android/src/org/thoughtcrime/securesms/util/ThemeUtil.java
2018-07-17 09:53:52 -07:00

37 lines
1.1 KiB
Java

package org.thoughtcrime.securesms.util;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.util.TypedValue;
import org.thoughtcrime.securesms.R;
public class ThemeUtil {
public static boolean isDarkTheme(@NonNull Context context) {
return getAttribute(context, R.attr.theme_type, "light").equals("dark");
}
public static int getThemedColor(@NonNull Context context, @AttrRes int attr) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
if (theme.resolveAttribute(attr, typedValue, true)) {
return typedValue.data;
}
return Color.RED;
}
private static String getAttribute(Context context, int attribute, String defaultValue) {
TypedValue outValue = new TypedValue();
if (context.getTheme().resolveAttribute(attribute, outValue, true)) {
return outValue.coerceToString().toString();
} else {
return defaultValue;
}
}
}