Extract finding night mode to method
This commit is contained in:
parent
812ca26679
commit
d33ec08b18
1 changed files with 13 additions and 19 deletions
|
@ -47,12 +47,7 @@ public class AppModeDialog {
|
||||||
public static View prepareAppModeView(Activity a, final List<ApplicationMode> values , final Set<ApplicationMode> selected,
|
public static View prepareAppModeView(Activity a, final List<ApplicationMode> values , final Set<ApplicationMode> selected,
|
||||||
ViewGroup parent, final boolean singleSelection, boolean drawer, boolean useMapTheme, final View.OnClickListener onClickListener) {
|
ViewGroup parent, final boolean singleSelection, boolean drawer, boolean useMapTheme, final View.OnClickListener onClickListener) {
|
||||||
View ll = a.getLayoutInflater().inflate(R.layout.mode_toggles, parent);
|
View ll = a.getLayoutInflater().inflate(R.layout.mode_toggles, parent);
|
||||||
boolean nightMode;
|
boolean nightMode = isNightMode(((OsmandApplication) a.getApplication()), useMapTheme);
|
||||||
if (useMapTheme) {
|
|
||||||
nightMode = ((OsmandApplication) a.getApplication()).getDaynightHelper().isNightModeForMapControls();
|
|
||||||
} else {
|
|
||||||
nightMode = !((OsmandApplication) a.getApplication()).getSettings().isLightContent();
|
|
||||||
}
|
|
||||||
ll.setBackgroundColor(ContextCompat.getColor(a, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light));
|
ll.setBackgroundColor(ContextCompat.getColor(a, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light));
|
||||||
final View[] buttons = new View[values.size()];
|
final View[] buttons = new View[values.size()];
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
@ -75,12 +70,7 @@ public class AppModeDialog {
|
||||||
final ApplicationMode mode = visible.get(i);
|
final ApplicationMode mode = visible.get(i);
|
||||||
final boolean checked = selected.contains(mode);
|
final boolean checked = selected.contains(mode);
|
||||||
ImageView iv = (ImageView) tb.findViewById(R.id.app_mode_icon);
|
ImageView iv = (ImageView) tb.findViewById(R.id.app_mode_icon);
|
||||||
boolean nightMode;
|
boolean nightMode = isNightMode(ctx, useMapTheme);
|
||||||
if (useMapTheme) {
|
|
||||||
nightMode = ctx.getDaynightHelper().isNightModeForMapControls();
|
|
||||||
} else {
|
|
||||||
nightMode = !ctx.getSettings().isLightContent();
|
|
||||||
}
|
|
||||||
if (checked) {
|
if (checked) {
|
||||||
iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), nightMode ? R.color.route_info_checked_mode_icon_color_dark : R.color.route_info_checked_mode_icon_color_light));
|
iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), nightMode ? R.color.route_info_checked_mode_icon_color_dark : R.color.route_info_checked_mode_icon_color_light));
|
||||||
iv.setContentDescription(String.format("%s %s", mode.toHumanString(ctx), ctx.getString(R.string.item_checked)));
|
iv.setContentDescription(String.format("%s %s", mode.toHumanString(ctx), ctx.getString(R.string.item_checked)));
|
||||||
|
@ -129,13 +119,7 @@ public class AppModeDialog {
|
||||||
int metricsY = (int) ctx.getResources().getDimension(R.dimen.route_info_modes_height);
|
int metricsY = (int) ctx.getResources().getDimension(R.dimen.route_info_modes_height);
|
||||||
View tb = layoutInflater.inflate(R.layout.mode_view, null);
|
View tb = layoutInflater.inflate(R.layout.mode_view, null);
|
||||||
ImageView iv = (ImageView) tb.findViewById(R.id.app_mode_icon);
|
ImageView iv = (ImageView) tb.findViewById(R.id.app_mode_icon);
|
||||||
boolean nightMode;
|
iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), isNightMode(ctx, useMapTheme) ? R.color.route_info_checked_mode_icon_color_dark : R.color.route_info_checked_mode_icon_color_light));
|
||||||
if (useMapTheme) {
|
|
||||||
nightMode = ctx.getDaynightHelper().isNightModeForMapControls();
|
|
||||||
} else {
|
|
||||||
nightMode = !ctx.getSettings().isLightContent();
|
|
||||||
}
|
|
||||||
iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), nightMode ? R.color.route_info_checked_mode_icon_color_dark : R.color.route_info_checked_mode_icon_color_light));
|
|
||||||
iv.setContentDescription(mode.toHumanString(ctx));
|
iv.setContentDescription(mode.toHumanString(ctx));
|
||||||
// tb.setCompoundDrawablesWithIntrinsicBounds(null, ctx.getIconsCache().getIcon(mode.getIconId(), R.color.app_mode_icon_color), null, null);
|
// tb.setCompoundDrawablesWithIntrinsicBounds(null, ctx.getIconsCache().getIcon(mode.getIconId(), R.color.app_mode_icon_color), null, null);
|
||||||
LayoutParams lp = new LinearLayout.LayoutParams(metricsX, metricsY);
|
LayoutParams lp = new LinearLayout.LayoutParams(metricsX, metricsY);
|
||||||
|
@ -143,4 +127,14 @@ public class AppModeDialog {
|
||||||
layout.addView(tb, lp);
|
layout.addView(tb, lp);
|
||||||
return tb;
|
return tb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isNightMode(OsmandApplication ctx, boolean useMapTheme) {
|
||||||
|
boolean nightMode;
|
||||||
|
if (useMapTheme) {
|
||||||
|
nightMode = ctx.getDaynightHelper().isNightModeForMapControls();
|
||||||
|
} else {
|
||||||
|
nightMode = !ctx.getSettings().isLightContent();
|
||||||
|
}
|
||||||
|
return nightMode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue