Move functions to get Android dimen to ThemeHelper

This commit is contained in:
Stypox 2022-07-07 11:59:00 +02:00
parent 1cf746f721
commit 9c51fc3ade
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
2 changed files with 24 additions and 20 deletions

View file

@ -244,6 +244,22 @@ public final class ThemeHelper {
return AppCompatResources.getDrawable(context, typedValue.resourceId);
}
/**
* Gets a runtime dimen from the {@code android} package. Should be used for dimens for which
* normal accessing with {@code R.dimen.} is not available.
*
* @param context context
* @param name dimen resource name (e.g. navigation_bar_height)
* @return the obtained dimension, in pixels, or 0 if the resource could not be resolved
*/
public static int getAndroidDimenPx(@NonNull final Context context, final String name) {
final int resId = context.getResources().getIdentifier(name, "dimen", "android");
if (resId <= 0) {
return 0;
}
return context.getResources().getDimensionPixelSize(resId);
}
private static String getSelectedThemeKey(final Context context) {
final String themeKey = context.getString(R.string.theme_key);
final String defaultTheme = context.getResources().getString(R.string.default_theme_value);