Clean up and refactoring

This commit is contained in:
cepprice 2021-03-01 12:28:55 +05:00
parent 5b590cf3ec
commit 4b93539c25
26 changed files with 106 additions and 142 deletions

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<net.osmand.plus.widgets.FlowLayout
android:id="@+id/color_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp" />
</LinearLayout>

View file

@ -26,7 +26,7 @@
<Preference <Preference
android:key="color_items" android:key="color_items"
android:layout="@layout/preference_color_select" android:layout="@layout/preference_colors_card"
android:title="@string/select_color" android:title="@string/select_color"
android:selectable="false"/> android:selectable="false"/>

View file

@ -133,7 +133,7 @@ public class ConnectedApp implements Comparable<ConnectedApp> {
CompoundButton btn = view.findViewById(R.id.toggle_item); CompoundButton btn = view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) { if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked()); btn.setChecked(!btn.isChecked());
menuAdapter.getItem(position).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); menuAdapter.getItem(position).setColor(app, btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
return false; return false;
} }
@ -146,7 +146,7 @@ public class ConnectedApp implements Comparable<ConnectedApp> {
if (layersPref.set(isChecked)) { if (layersPref.set(isChecked)) {
ContextMenuItem item = adapter.getItem(position); ContextMenuItem item = adapter.getItem(position);
if (item != null) { if (item != null) {
item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(app, isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setSelected(isChecked); item.setSelected(isChecked);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
@ -162,7 +162,7 @@ public class ConnectedApp implements Comparable<ConnectedApp> {
.setListener(listener) .setListener(listener)
.setSelected(layersEnabled) .setSelected(layersEnabled)
.setIcon(R.drawable.ic_extension_dark) .setIcon(R.drawable.ic_extension_dark)
.setColor(layersEnabled ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, layersEnabled ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.createItem()); .createItem());
} }

View file

@ -277,14 +277,7 @@ public class ContextMenuAdapter {
} }
if (layoutId == R.layout.main_menu_drawer_btn_switch_profile || if (layoutId == R.layout.main_menu_drawer_btn_switch_profile ||
layoutId == R.layout.main_menu_drawer_btn_configure_profile) { layoutId == R.layout.main_menu_drawer_btn_configure_profile) {
int colorNoAlpha; int colorNoAlpha = item.getColor();
if (item.getColor() != null) {
colorNoAlpha = item.getColor();
} else {
int colorResId = item.getColorRes();
colorNoAlpha = ContextCompat.getColor(app, colorResId);
}
TextView title = convertView.findViewById(R.id.title); TextView title = convertView.findViewById(R.id.title);
title.setText(item.getTitle()); title.setText(item.getTitle());
@ -310,16 +303,8 @@ public class ContextMenuAdapter {
return convertView; return convertView;
} }
if (layoutId == R.layout.profile_list_item) { if (layoutId == R.layout.profile_list_item) {
int tag = item.getTag(); int tag = item.getTag();
int colorNoAlpha = item.getColor();
int colorNoAlpha;
if (item.getColor() != null) {
colorNoAlpha = item.getColor();
} else {
int colorResId = item.getColorRes();
colorNoAlpha = ContextCompat.getColor(app, colorResId);
}
TextView title = convertView.findViewById(R.id.title); TextView title = convertView.findViewById(R.id.title);
TextView desc = convertView.findViewById(R.id.description); TextView desc = convertView.findViewById(R.id.description);
ImageView icon = convertView.findViewById(R.id.icon); ImageView icon = convertView.findViewById(R.id.icon);
@ -428,20 +413,18 @@ public class ContextMenuAdapter {
} }
} else { } else {
if (item.getIcon() != ContextMenuItem.INVALID_ID) { if (item.getIcon() != ContextMenuItem.INVALID_ID) {
int colorRes = item.getColorRes(); Integer color = item.getColor();
Drawable drawable; Drawable drawable;
if (profileDependent) { if (color == null) {
int colorRes = lightTheme ? R.color.icon_color_default_light : R.color.icon_color_default_dark;
colorRes = item.shouldSkipPainting() ? 0 : colorRes;
drawable = mIconsCache.getIcon(item.getIcon(), colorRes);
} else if (profileDependent) {
drawable = mIconsCache.getPaintedIcon(item.getIcon(), currentModeColor); drawable = mIconsCache.getPaintedIcon(item.getIcon(), currentModeColor);
} else { } else {
if (colorRes == ContextMenuItem.INVALID_ID) { drawable = mIconsCache.getPaintedIcon(item.getIcon(), color);
if (!item.shouldSkipPainting()) {
colorRes = lightTheme ? R.color.icon_color_default_light : R.color.icon_color_default_dark;
} else {
colorRes = 0;
}
}
drawable = mIconsCache.getIcon(item.getIcon(), colorRes);
} }
((AppCompatImageView) convertView.findViewById(R.id.icon)).setImageDrawable(drawable); ((AppCompatImageView) convertView.findViewById(R.id.icon)).setImageDrawable(drawable);
convertView.findViewById(R.id.icon).setVisibility(View.VISIBLE); convertView.findViewById(R.id.icon).setVisibility(View.VISIBLE);
} else if (convertView.findViewById(R.id.icon) != null) { } else if (convertView.findViewById(R.id.icon) != null) {

View file

@ -19,8 +19,6 @@ public class ContextMenuItem {
private String title; private String title;
@DrawableRes @DrawableRes
private int mIcon; private int mIcon;
@ColorRes
private int colorRes;
@ColorInt @ColorInt
private Integer color; private Integer color;
@DrawableRes @DrawableRes
@ -50,7 +48,6 @@ public class ContextMenuItem {
private ContextMenuItem(@StringRes int titleId, private ContextMenuItem(@StringRes int titleId,
String title, String title,
@DrawableRes int icon, @DrawableRes int icon,
@ColorRes int colorRes,
@ColorInt Integer color, @ColorInt Integer color,
@DrawableRes int secondaryIcon, @DrawableRes int secondaryIcon,
Boolean selected, Boolean selected,
@ -75,7 +72,6 @@ public class ContextMenuItem {
this.titleId = titleId; this.titleId = titleId;
this.title = title; this.title = title;
this.mIcon = icon; this.mIcon = icon;
this.colorRes = colorRes;
this.color = color; this.color = color;
this.secondaryIcon = secondaryIcon; this.secondaryIcon = secondaryIcon;
this.selected = selected; this.selected = selected;
@ -113,28 +109,17 @@ public class ContextMenuItem {
return mIcon; return mIcon;
} }
@ColorRes
public int getColorRes() {
return colorRes;
}
@ColorInt @ColorInt
Integer getColor() { public Integer getColor() {
return color; return color;
} }
@ColorRes
public int getThemedColorRes(Context context) {
if (skipPaintingWithoutColor || getColorRes() != INVALID_ID) {
return getColorRes();
} else {
return UiUtilities.getDefaultColorRes(context);
}
}
@ColorInt @ColorInt
public int getThemedColor(Context context) { public int getThemedColor(Context context) {
return ContextCompat.getColor(context, getThemedColorRes(context)); if (skipPaintingWithoutColor || color != null) {
return color;
}
return ContextCompat.getColor(context, UiUtilities.getDefaultColorRes(context));
} }
@DrawableRes @DrawableRes
@ -221,8 +206,10 @@ public class ContextMenuItem {
this.secondaryIcon = secondaryIcon; this.secondaryIcon = secondaryIcon;
} }
public void setColorRes(int colorRes) { public void setColor(Context context, @ColorRes int colorRes) {
this.colorRes = colorRes; if (colorRes != INVALID_ID) {
this.color = ContextCompat.getColor(context, colorRes);
}
} }
public void setSelected(boolean selected) { public void setSelected(boolean selected) {
@ -277,8 +264,6 @@ public class ContextMenuItem {
private String mTitle; private String mTitle;
@DrawableRes @DrawableRes
private int mIcon = INVALID_ID; private int mIcon = INVALID_ID;
@ColorRes
private int mColorRes = INVALID_ID;
@ColorInt @ColorInt
private Integer mColor = null; private Integer mColor = null;
@DrawableRes @DrawableRes
@ -318,13 +303,15 @@ public class ContextMenuItem {
return this; return this;
} }
public ItemBuilder setColor(@ColorRes int colorRes) { public ItemBuilder setColor(@ColorInt Integer color) {
mColorRes = colorRes; mColor = color;
return this; return this;
} }
public ItemBuilder setColorInt(@ColorInt int color) { public ItemBuilder setColor(Context context, @ColorRes int colorRes) {
mColor = color; if (colorRes != INVALID_ID) {
mColor = ContextCompat.getColor(context, colorRes);
}
return this; return this;
} }
@ -438,7 +425,7 @@ public class ContextMenuItem {
} }
public ContextMenuItem createItem() { public ContextMenuItem createItem() {
ContextMenuItem item = new ContextMenuItem(mTitleId, mTitle, mIcon, mColorRes, mColor, mSecondaryIcon, ContextMenuItem item = new ContextMenuItem(mTitleId, mTitle, mIcon, mColor, mSecondaryIcon,
mSelected, mProgress, mLayout, mLoading, mIsCategory, mIsClickable, mSkipPaintingWithoutColor, mSelected, mProgress, mLayout, mLoading, mIsCategory, mIsClickable, mSkipPaintingWithoutColor,
mOrder, mDescription, mOnUpdateCallback, mItemClickListener, mIntegerListener, mProgressListener, mOrder, mDescription, mOnUpdateCallback, mItemClickListener, mIntegerListener, mProgressListener,
mItemDeleteAction, mHideDivider, mHideCompoundButton, mMinHeight, mTag, mId); mItemDeleteAction, mHideDivider, mHideCompoundButton, mMinHeight, mTag, mId);

View file

@ -749,7 +749,7 @@ public class MapActivityActions implements DialogProvider {
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item) optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item)
.setIcon(appMode.getIconRes()) .setIcon(appMode.getIconRes())
.setColorInt(appMode.getProfileColor(nightMode)) .setColor(appMode.getProfileColor(nightMode))
.setTag(tag) .setTag(tag)
.setTitle(appMode.toHumanString()) .setTitle(appMode.toHumanString())
.setDescription(modeDescription) .setDescription(modeDescription)
@ -766,7 +766,7 @@ public class MapActivityActions implements DialogProvider {
int activeColorPrimaryResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; int activeColorPrimaryResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item) optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item)
.setColor(activeColorPrimaryResId) .setColor(app, activeColorPrimaryResId)
.setTag(PROFILES_CONTROL_BUTTON_TAG) .setTag(PROFILES_CONTROL_BUTTON_TAG)
.setTitle(getString(R.string.shared_string_manage)) .setTitle(getString(R.string.shared_string_manage))
.setListener(new ItemClickListener() { .setListener(new ItemClickListener() {
@ -1059,7 +1059,7 @@ public class MapActivityActions implements DialogProvider {
.setId(DRAWER_SWITCH_PROFILE_ID) .setId(DRAWER_SWITCH_PROFILE_ID)
.setIcon(currentMode.getIconRes()) .setIcon(currentMode.getIconRes())
.setSecondaryIcon(icArrowResId) .setSecondaryIcon(icArrowResId)
.setColorInt(currentMode.getProfileColor(nightMode)) .setColor(currentMode.getProfileColor(nightMode))
.setTitle(currentMode.toHumanString()) .setTitle(currentMode.toHumanString())
.setDescription(modeDescription) .setDescription(modeDescription)
.setListener(new ItemClickListener() { .setListener(new ItemClickListener() {
@ -1073,7 +1073,7 @@ public class MapActivityActions implements DialogProvider {
.createItem()); .createItem());
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_configure_profile) optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_configure_profile)
.setId(DRAWER_CONFIGURE_PROFILE_ID) .setId(DRAWER_CONFIGURE_PROFILE_ID)
.setColorInt(currentMode.getProfileColor(nightMode)) .setColor(currentMode.getProfileColor(nightMode))
.setTitle(getString(R.string.configure_profile)) .setTitle(getString(R.string.configure_profile))
.setListener(new ItemClickListener() { .setListener(new ItemClickListener() {
@Override @Override

View file

@ -432,7 +432,7 @@ public class MapActivityLayers {
} else { } else {
builder.setIcon(R.drawable.mx_user_defined); builder.setIcon(R.drawable.mx_user_defined);
} }
builder.setColor(ContextMenuItem.INVALID_ID); builder.setColor(activity, ContextMenuItem.INVALID_ID);
builder.setSkipPaintingWithoutColor(true); builder.setSkipPaintingWithoutColor(true);
adapter.addItem(builder.createItem()); adapter.addItem(builder.createItem());
} }

View file

@ -678,7 +678,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
if (itemId == R.string.layer_recordings) { if (itemId == R.string.layer_recordings) {
SHOW_RECORDINGS.set(!SHOW_RECORDINGS.get()); SHOW_RECORDINGS.set(!SHOW_RECORDINGS.get());
adapter.getItem(pos).setColorRes(SHOW_RECORDINGS.get() ? adapter.getItem(pos).setColor(app, SHOW_RECORDINGS.get() ?
R.color.osmand_orange : ContextMenuItem.INVALID_ID); R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
updateLayers(mapView, mapActivity); updateLayers(mapView, mapActivity);
@ -690,7 +690,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
.setId(RECORDING_LAYER) .setId(RECORDING_LAYER)
.setSelected(SHOW_RECORDINGS.get()) .setSelected(SHOW_RECORDINGS.get())
.setIcon(R.drawable.ic_action_micro_dark) .setIcon(R.drawable.ic_action_micro_dark)
.setColor(SHOW_RECORDINGS.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(mapActivity, SHOW_RECORDINGS.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setItemDeleteAction(makeDeleteAction(SHOW_RECORDINGS)) .setItemDeleteAction(makeDeleteAction(SHOW_RECORDINGS))
.setListener(listener).createItem()); .setListener(listener).createItem());
} }

View file

@ -184,7 +184,7 @@ public class ConfigureMapMenu {
.setId(FAVORITES_ID) .setId(FAVORITES_ID)
.setTitleId(R.string.shared_string_favorites, activity) .setTitleId(R.string.shared_string_favorites, activity)
.setSelected(settings.SHOW_FAVORITES.get()) .setSelected(settings.SHOW_FAVORITES.get())
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_favorite) .setIcon(R.drawable.ic_action_favorite)
.setItemDeleteAction(makeDeleteAction(settings.SHOW_FAVORITES)) .setItemDeleteAction(makeDeleteAction(settings.SHOW_FAVORITES))
.setListener(l) .setListener(l)
@ -196,7 +196,7 @@ public class ConfigureMapMenu {
.setTitleId(R.string.layer_poi, activity) .setTitleId(R.string.layer_poi, activity)
.setSelected(selected) .setSelected(selected)
.setDescription(app.getPoiFilters().getSelectedPoiFiltersName(wiki)) .setDescription(app.getPoiFilters().getSelectedPoiFiltersName(wiki))
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_info_dark) .setIcon(R.drawable.ic_action_info_dark)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(l).createItem()); .setListener(l).createItem());
@ -205,7 +205,7 @@ public class ConfigureMapMenu {
.setId(POI_OVERLAY_LABELS_ID) .setId(POI_OVERLAY_LABELS_ID)
.setTitleId(R.string.layer_amenity_label, activity) .setTitleId(R.string.layer_amenity_label, activity)
.setSelected(settings.SHOW_POI_LABEL.get()) .setSelected(settings.SHOW_POI_LABEL.get())
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_text_dark) .setIcon(R.drawable.ic_action_text_dark)
.setItemDeleteAction(makeDeleteAction(settings.SHOW_POI_LABEL)) .setItemDeleteAction(makeDeleteAction(settings.SHOW_POI_LABEL))
.setListener(l).createItem()); .setListener(l).createItem());
@ -217,7 +217,7 @@ public class ConfigureMapMenu {
.setIcon(R.drawable.ic_action_transport_bus) .setIcon(R.drawable.ic_action_transport_bus)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setSelected(selected) .setSelected(selected)
.setColor(selected ? selectedProfileColor : ContextMenuItem.INVALID_ID) .setColor(selected ? selectedProfileColor : null)
.setListener(l).createItem()); .setListener(l).createItem());
selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles(); selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
@ -226,7 +226,7 @@ public class ConfigureMapMenu {
.setTitleId(R.string.layer_gpx_layer, activity) .setTitleId(R.string.layer_gpx_layer, activity)
.setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles()) .setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles())
.setDescription(app.getSelectedGpxHelper().getGpxDescription()) .setDescription(app.getSelectedGpxHelper().getGpxDescription())
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_polygom_dark) .setIcon(R.drawable.ic_action_polygom_dark)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(l).createItem()); .setListener(l).createItem());
@ -236,7 +236,7 @@ public class ConfigureMapMenu {
.setId(MAP_MARKERS_ID) .setId(MAP_MARKERS_ID)
.setTitleId(R.string.map_markers, activity) .setTitleId(R.string.map_markers, activity)
.setSelected(selected) .setSelected(selected)
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_flag) .setIcon(R.drawable.ic_action_flag)
.setItemDeleteAction(makeDeleteAction(settings.SHOW_MAP_MARKERS)) .setItemDeleteAction(makeDeleteAction(settings.SHOW_MAP_MARKERS))
.setListener(l).createItem()); .setListener(l).createItem());
@ -704,7 +704,6 @@ public class ConfigureMapMenu {
for (int i = 0; i < prefs.size(); i++) { for (int i = 0; i < prefs.size(); i++) {
prefs.get(i).set(false); prefs.get(i).set(false);
} }
adapter.getItem(pos).setColorRes(ContextMenuItem.INVALID_ID);
a.notifyDataSetInvalidated(); a.notifyDataSetInvalidated();
activity.refreshMapComplete(); activity.refreshMapComplete();
activity.getMapLayers().updateLayers(activity.getMapView()); activity.getMapLayers().updateLayers(activity.getMapView());
@ -738,7 +737,7 @@ public class ConfigureMapMenu {
} }
} }
} }
builder.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); builder.setColor(activity, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
if (useDescription) { if (useDescription) {
final String descr = getDescription(prefs, includedPrefs); final String descr = getDescription(prefs, includedPrefs);
builder.setDescription(descr); builder.setDescription(descr);
@ -839,7 +838,7 @@ public class ConfigureMapMenu {
selected |= prefs.get(i).get(); selected |= prefs.get(i).get();
} }
adapter.getItem(pos).setSelected(selected); adapter.getItem(pos).setSelected(selected);
adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); adapter.getItem(pos).setColor(activity, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
a.notifyDataSetInvalidated(); a.notifyDataSetInvalidated();
} }
}); });
@ -874,7 +873,7 @@ public class ConfigureMapMenu {
} else { } else {
adapter.getItem(pos).setSelected(selected); adapter.getItem(pos).setSelected(selected);
} }
adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); adapter.getItem(pos).setColor(activity, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
} }
a.notifyDataSetInvalidated(); a.notifyDataSetInvalidated();
activity.refreshMapComplete(); activity.refreshMapComplete();

View file

@ -217,7 +217,7 @@ public class DetailsBottomSheet extends BasePreferenceBottomSheet {
} }
if (adapter != null) { if (adapter != null) {
adapter.getItem(position).setSelected(checked); adapter.getItem(position).setSelected(checked);
adapter.getItem(position).setColorRes(checked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); adapter.getItem(position).setColor(app, checked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.getItem(position).setDescription(getString( adapter.getItem(position).setDescription(getString(
R.string.ltr_or_rtl_combine_via_slash, R.string.ltr_or_rtl_combine_via_slash,
String.valueOf(selected), String.valueOf(selected),

View file

@ -77,7 +77,7 @@ final class MapLayerMenuListener extends OnRowItemClick {
public boolean processResult(Boolean result) { public boolean processResult(Boolean result) {
if (item != null) { if (item != null) {
item.setSelected(result); item.setSelected(result);
item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(mapActivity, result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
return true; return true;
@ -86,7 +86,7 @@ final class MapLayerMenuListener extends OnRowItemClick {
boolean selected = TransportLinesMenu.isShowLines(mapActivity.getMyApplication()); boolean selected = TransportLinesMenu.isShowLines(mapActivity.getMyApplication());
if (!selected && item != null) { if (!selected && item != null) {
item.setSelected(true); item.setSelected(true);
item.setColorRes(R.color.osmand_orange); item.setColor(mapActivity, R.color.osmand_orange);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
return false; return false;
@ -94,7 +94,7 @@ final class MapLayerMenuListener extends OnRowItemClick {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item); CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) { if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked()); btn.setChecked(!btn.isChecked());
menuAdapter.getItem(pos).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); menuAdapter.getItem(pos).setColor(mapActivity, btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
return false; return false;
} else { } else {
@ -110,7 +110,7 @@ final class MapLayerMenuListener extends OnRowItemClick {
final PoiFiltersHelper poiFiltersHelper = mapActivity.getMyApplication().getPoiFilters(); final PoiFiltersHelper poiFiltersHelper = mapActivity.getMyApplication().getPoiFilters();
final ContextMenuItem item = menuAdapter.getItem(pos); final ContextMenuItem item = menuAdapter.getItem(pos);
if (item.getSelected() != null) { if (item.getSelected() != null) {
item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(mapActivity, isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
} }
if (itemId == R.string.layer_poi) { if (itemId == R.string.layer_poi) {
PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter(); PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter();
@ -139,7 +139,7 @@ final class MapLayerMenuListener extends OnRowItemClick {
@Override @Override
public boolean processResult(Boolean result) { public boolean processResult(Boolean result) {
item.setSelected(result); item.setSelected(result);
item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(mapActivity, result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
return true; return true;
} }
@ -171,7 +171,7 @@ final class MapLayerMenuListener extends OnRowItemClick {
boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles(); boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
item.setSelected(selected); item.setSelected(selected);
item.setDescription(app.getSelectedGpxHelper().getGpxDescription()); item.setDescription(app.getSelectedGpxHelper().getGpxDescription());
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(mapActivity, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
}); });
@ -189,7 +189,7 @@ final class MapLayerMenuListener extends OnRowItemClick {
boolean selected = pf.isShowingAnyPoi(wiki); boolean selected = pf.isShowingAnyPoi(wiki);
item.setSelected(selected); item.setSelected(selected);
item.setDescription(pf.getSelectedPoiFiltersName(wiki)); item.setDescription(pf.getSelectedPoiFiltersName(wiki));
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(mapActivity, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
}; };

View file

@ -516,13 +516,13 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
.setTitleId(R.string.shared_string_refresh, getContext()) .setTitleId(R.string.shared_string_refresh, getContext())
.setIcon(R.drawable.ic_action_refresh_dark) .setIcon(R.drawable.ic_action_refresh_dark)
.setListener(listener) .setListener(listener)
.setColor(iconColorResId) .setColor(getContext(), iconColorResId)
.createItem()); .createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.shared_string_delete, getContext()) .setTitleId(R.string.shared_string_delete, getContext())
.setIcon(R.drawable.ic_action_delete_dark) .setIcon(R.drawable.ic_action_delete_dark)
.setListener(listener) .setListener(listener)
.setColor(iconColorResId) .setColor(getContext(), iconColorResId)
.createItem()); .createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.local_index_mi_backup, getContext()) .setTitleId(R.string.local_index_mi_backup, getContext())
@ -554,7 +554,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
} }
if (contextMenuItem.getIcon() != -1) { if (contextMenuItem.getIcon() != -1) {
Drawable icMenuItem = getMyApplication().getUIUtilities().getIcon(contextMenuItem.getIcon(), contextMenuItem.getColorRes()); Drawable icMenuItem = getMyApplication().getUIUtilities().getPaintedIcon(contextMenuItem.getIcon(), contextMenuItem.getColor());
item.setIcon(icMenuItem); item.setIcon(icMenuItem);
} }

View file

@ -185,7 +185,7 @@ public class MapillaryPlugin extends OsmandPlugin {
ContextMenuItem item = adapter.getItem(pos); ContextMenuItem item = adapter.getItem(pos);
if (item != null) { if (item != null) {
item.setSelected(settings.SHOW_MAPILLARY.get()); item.setSelected(settings.SHOW_MAPILLARY.get());
item.setColorRes(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(app, settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
} }
@ -201,7 +201,7 @@ public class MapillaryPlugin extends OsmandPlugin {
.setTitleId(R.string.street_level_imagery, mapActivity) .setTitleId(R.string.street_level_imagery, mapActivity)
.setDescription("Mapillary") .setDescription("Mapillary")
.setSelected(settings.SHOW_MAPILLARY.get()) .setSelected(settings.SHOW_MAPILLARY.get())
.setColor(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_mapillary) .setIcon(R.drawable.ic_action_mapillary)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setItemDeleteAction(makeDeleteAction(settings.SHOW_MAPILLARY)) .setItemDeleteAction(makeDeleteAction(settings.SHOW_MAPILLARY))

View file

@ -324,7 +324,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
.setTitleId(R.string.layer_osm_bugs, mapActivity) .setTitleId(R.string.layer_osm_bugs, mapActivity)
.setSelected(settings.SHOW_OSM_BUGS.get()) .setSelected(settings.SHOW_OSM_BUGS.get())
.setIcon(R.drawable.ic_action_osm_note) .setIcon(R.drawable.ic_action_osm_note)
.setColor(settings.SHOW_OSM_BUGS.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, settings.SHOW_OSM_BUGS.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(new ContextMenuAdapter.OnRowItemClick() { .setListener(new ContextMenuAdapter.OnRowItemClick() {
@ -343,7 +343,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
if (itemId == R.string.layer_osm_bugs) { if (itemId == R.string.layer_osm_bugs) {
OsmandPreference<Boolean> showOsmBugs = settings.SHOW_OSM_BUGS; OsmandPreference<Boolean> showOsmBugs = settings.SHOW_OSM_BUGS;
showOsmBugs.set(isChecked); showOsmBugs.set(isChecked);
adapter.getItem(pos).setColorRes(showOsmBugs.get() ? adapter.getItem(pos).setColor(app, showOsmBugs.get() ?
R.color.osmand_orange : ContextMenuItem.INVALID_ID); R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
updateLayers(mapActivity.getMapView(), mapActivity); updateLayers(mapActivity.getMapView(), mapActivity);
@ -359,14 +359,14 @@ public class OsmEditingPlugin extends OsmandPlugin {
.setTitleId(R.string.layer_osm_edits, mapActivity) .setTitleId(R.string.layer_osm_edits, mapActivity)
.setSelected(settings.SHOW_OSM_EDITS.get()) .setSelected(settings.SHOW_OSM_EDITS.get())
.setIcon(R.drawable.ic_action_openstreetmap_logo) .setIcon(R.drawable.ic_action_openstreetmap_logo)
.setColor(settings.SHOW_OSM_EDITS.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, settings.SHOW_OSM_EDITS.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setListener(new ContextMenuAdapter.OnRowItemClick() { .setListener(new ContextMenuAdapter.OnRowItemClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
if (itemId == R.string.layer_osm_edits) { if (itemId == R.string.layer_osm_edits) {
OsmandPreference<Boolean> showOsmEdits = settings.SHOW_OSM_EDITS; OsmandPreference<Boolean> showOsmEdits = settings.SHOW_OSM_EDITS;
showOsmEdits.set(isChecked); showOsmEdits.set(isChecked);
adapter.getItem(pos).setColorRes(showOsmEdits.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); adapter.getItem(pos).setColor(app, showOsmEdits.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
updateLayers(mapActivity.getMapView(), mapActivity); updateLayers(mapActivity.getMapView(), mapActivity);
} }
@ -404,7 +404,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
final AvailableGPXFragment f = ((AvailableGPXFragment) fragment); final AvailableGPXFragment f = ((AvailableGPXFragment) fragment);
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, activity) optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, activity)
.setIcon(R.drawable.ic_action_export) .setIcon(R.drawable.ic_action_export)
.setColor(R.color.color_white) .setColor(app, R.color.color_white)
.setListener(new ItemClickListener() { .setListener(new ItemClickListener() {
@Override @Override

View file

@ -110,7 +110,7 @@ public class OsmNotesMenu {
.setTitleId(osmNotesStringId, mapActivity) .setTitleId(osmNotesStringId, mapActivity)
.setDescription(mapActivity.getString(R.string.switch_osm_notes_visibility_desc)) .setDescription(mapActivity.getString(R.string.switch_osm_notes_visibility_desc))
.setIcon(R.drawable.ic_action_osm_note) .setIcon(R.drawable.ic_action_osm_note)
.setColor(toggleIconColorId) .setColor(app, toggleIconColorId)
.setListener(l) .setListener(l)
.setSelected(showOsmBugs) .setSelected(showOsmBugs)
.createItem()); .createItem());

View file

@ -353,7 +353,6 @@ public class ShowHidePoiAction extends QuickAction {
builder.setIcon(R.drawable.mx_user_defined); builder.setIcon(R.drawable.mx_user_defined);
} }
builder.setColor(ContextMenuItem.INVALID_ID);
builder.setSkipPaintingWithoutColor(true); builder.setSkipPaintingWithoutColor(true);
adapter.addItem(builder.createItem()); adapter.addItem(builder.createItem());
} }

View file

@ -13,7 +13,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@ -323,7 +322,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
: mapActivity.getString(R.string.shared_string_none); : mapActivity.getString(R.string.shared_string_none);
item.setDescription(overlayMapDescr); item.setDescription(overlayMapDescr);
item.setSelected(hasOverlayDescription); item.setSelected(hasOverlayDescription);
item.setColorRes(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(app, hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
} }
@ -348,7 +347,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
item.setDescription(underlayMapDescr); item.setDescription(underlayMapDescr);
item.setSelected(hasUnderlayDescription); item.setSelected(hasUnderlayDescription);
item.setColorRes(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(app, hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
@ -381,7 +380,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
.setId(OVERLAY_MAP) .setId(OVERLAY_MAP)
.setDescription(overlayMapDescr) .setDescription(overlayMapDescr)
.setSelected(hasOverlayDescription) .setSelected(hasOverlayDescription)
.setColor(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_layer_top) .setIcon(R.drawable.ic_layer_top)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(listener) .setListener(listener)
@ -397,7 +396,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
.setId(UNDERLAY_MAP) .setId(UNDERLAY_MAP)
.setDescription(underlayMapDescr) .setDescription(underlayMapDescr)
.setSelected(hasUnderlayDescription) .setSelected(hasUnderlayDescription)
.setColor(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_layer_bottom) .setIcon(R.drawable.ic_layer_bottom)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(listener) .setListener(listener)

View file

@ -65,8 +65,6 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
private List<BottomSheetItemWithCompoundButton> compoundButtons = new ArrayList<>(); private List<BottomSheetItemWithCompoundButton> compoundButtons = new ArrayList<>();
private boolean hideImpassableRoads; private boolean hideImpassableRoads;
@ColorRes
private int compoundButtonColorId = INVALID_ID;
@ColorInt @ColorInt
private Integer compoundButtonColor = null; private Integer compoundButtonColor = null;
private ApplicationMode appMode; private ApplicationMode appMode;
@ -239,7 +237,6 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
final BottomSheetItemWithCompoundButton[] item = new BottomSheetItemWithCompoundButton[1]; final BottomSheetItemWithCompoundButton[] item = new BottomSheetItemWithCompoundButton[1];
item[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() item[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setCompoundButtonColorId(compoundButtonColorId)
.setCompoundButtonColor(compoundButtonColor) .setCompoundButtonColor(compoundButtonColor)
.setChecked(selected) .setChecked(selected)
.setTitle(parameterName) .setTitle(parameterName)
@ -258,10 +255,6 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
} }
} }
public void setCompoundButtonColorId(@ColorRes int compoundButtonColorId) {
this.compoundButtonColorId = compoundButtonColorId;
}
public void setCompoundButtonColor(@ColorInt int compoundButtonColor) { public void setCompoundButtonColor(@ColorInt int compoundButtonColor) {
this.compoundButtonColor = compoundButtonColor; this.compoundButtonColor = compoundButtonColor;
} }

View file

@ -500,11 +500,11 @@ public class ApplicationMode {
public Integer getCustomIconColor() { public Integer getCustomIconColor() {
String customColor = app.getSettings().CUSTOM_ICON_COLOR.getModeValue(this); String customColor = app.getSettings().CUSTOM_ICON_COLOR.getModeValue(this);
return customColor == null ? null : Integer.valueOf(customColor); return customColor == null ? null : Algorithms.parseColor(customColor);
} }
public void setCustomIconColor(Integer customIconColor) { public void setCustomIconColor(Integer customIconColor) {
String valueToSave = customIconColor == null ? null : String.valueOf(customIconColor); String valueToSave = customIconColor == null ? null : Algorithms.colorToString(customIconColor);
app.getSettings().CUSTOM_ICON_COLOR.setModeValue(this, valueToSave); app.getSettings().CUSTOM_ICON_COLOR.setModeValue(this, valueToSave);
} }
@ -605,7 +605,6 @@ public class ApplicationMode {
mode.setRoutingProfile(builder.routingProfile); mode.setRoutingProfile(builder.routingProfile);
mode.setRouteService(builder.routeService); mode.setRouteService(builder.routeService);
mode.setIconColor(builder.iconColor); mode.setIconColor(builder.iconColor);
mode.setCustomIconColors(builder.customIconColors);
mode.setCustomIconColor(builder.customIconColor); mode.setCustomIconColor(builder.customIconColor);
mode.setLocationIcon(builder.locationIcon); mode.setLocationIcon(builder.locationIcon);
mode.setNavigationIcon(builder.navigationIcon); mode.setNavigationIcon(builder.navigationIcon);
@ -726,7 +725,6 @@ public class ApplicationMode {
private String routingProfile; private String routingProfile;
private String iconResName; private String iconResName;
private ProfileIconColors iconColor; private ProfileIconColors iconColor;
private List<String> customIconColors;
private Integer customIconColor; private Integer customIconColor;
private LocationIcon locationIcon; private LocationIcon locationIcon;
private NavigationIcon navigationIcon; private NavigationIcon navigationIcon;
@ -751,7 +749,6 @@ public class ApplicationMode {
applicationMode.setRouteService(routeService); applicationMode.setRouteService(routeService);
applicationMode.setRoutingProfile(routingProfile); applicationMode.setRoutingProfile(routingProfile);
applicationMode.setIconResName(iconResName); applicationMode.setIconResName(iconResName);
applicationMode.setCustomIconColors(customIconColors);
applicationMode.setCustomIconColor(customIconColor); applicationMode.setCustomIconColor(customIconColor);
applicationMode.setIconColor(iconColor); applicationMode.setIconColor(iconColor);
applicationMode.setLocationIcon(locationIcon); applicationMode.setLocationIcon(locationIcon);
@ -801,11 +798,6 @@ public class ApplicationMode {
return this; return this;
} }
public ApplicationModeBuilder setCustomIconColors(List<String> customIconColors) {
this.customIconColors = customIconColors;
return this;
}
public ApplicationModeBuilder setCustomIconColor(Integer customIconColor) { public ApplicationModeBuilder setCustomIconColor(Integer customIconColor) {
this.customIconColor = customIconColor; this.customIconColor = customIconColor;
return this; return this;

View file

@ -682,7 +682,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
protected int getActiveProfileColor() { protected int getActiveProfileColor() {
return isProfileDependent() ? return isProfileDependent() ?
getSelectedAppMode().getProfileColor(isNightMode()) : getSelectedAppMode().getProfileColor(isNightMode()) :
ContextCompat.getColor(app, R.color.icon_color_active_light); ContextCompat.getColor(app, nightMode ? R.color.icon_color_active_dark : R.color.icon_color_active_light);
} }
@ColorRes @ColorRes
@ -826,7 +826,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
Drawable icon = AndroidUtils.createEnabledStateListDrawable(disabled, enabled); Drawable icon = AndroidUtils.createEnabledStateListDrawable(disabled, enabled);
if (Build.VERSION.SDK_INT < 21) { if (Build.VERSION.SDK_INT < 21) {
int defaultColor = ContextCompat.getColor(app, R.color.icon_color_default_light); int defaultColor = ContextCompat.getColor(app, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light);
ColorStateList colorStateList = AndroidUtils.createEnabledColorIntStateList(defaultColor, getActiveProfileColor()); ColorStateList colorStateList = AndroidUtils.createEnabledColorIntStateList(defaultColor, getActiveProfileColor());
icon = DrawableCompat.wrap(icon); icon = DrawableCompat.wrap(icon);
DrawableCompat.setTintList(icon, colorStateList); DrawableCompat.setTintList(icon, colorStateList);

View file

@ -38,12 +38,13 @@ import net.osmand.plus.profiles.SelectProfileBottomSheet;
import net.osmand.plus.profiles.SelectProfileBottomSheet.DialogMode; import net.osmand.plus.profiles.SelectProfileBottomSheet.DialogMode;
import net.osmand.plus.profiles.SelectProfileBottomSheet.OnSelectProfileCallback; import net.osmand.plus.profiles.SelectProfileBottomSheet.OnSelectProfileCallback;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem; import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
import net.osmand.plus.settings.backend.backup.SettingsHelper; import net.osmand.plus.settings.backend.backup.SettingsHelper;
import net.osmand.plus.track.ColorsCard; import net.osmand.plus.track.ColorsCard;
import net.osmand.plus.track.CustomColorBottomSheet; import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener;
import net.osmand.plus.widgets.FlowLayout; import net.osmand.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -74,7 +75,7 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID
import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILES_LIST_UPDATED_ARG; import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILES_LIST_UPDATED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_ARG; import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_ARG;
public class ProfileAppearanceFragment extends BaseSettingsFragment implements OnSelectProfileCallback, BaseCard.CardListener, CustomColorBottomSheet.ColorPickerListener { public class ProfileAppearanceFragment extends BaseSettingsFragment implements OnSelectProfileCallback, CardListener, ColorPickerListener {
private static final Log LOG = PlatformUtil.getLog(ProfileAppearanceFragment.class); private static final Log LOG = PlatformUtil.getLog(ProfileAppearanceFragment.class);
@ -475,7 +476,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
if (mapActivity == null) { if (mapActivity == null) {
return; return;
} }
ViewGroup parentView = (ViewGroup) holder.itemView; FlowLayout colorsCardContainer = (FlowLayout) holder.findViewById(R.id.color_items);
colorsCardContainer.removeAllViews();
int selectedColor = changedProfile.getActualColor(); int selectedColor = changedProfile.getActualColor();
List<Integer> colors = new ArrayList<>(); List<Integer> colors = new ArrayList<>();
for (ProfileIconColors color : ProfileIconColors.values()) { for (ProfileIconColors color : ProfileIconColors.values()) {
@ -483,8 +486,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
} }
colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors, app.getSettings().CUSTOM_ICON_COLORS, getSelectedAppMode()); colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors, app.getSettings().CUSTOM_ICON_COLORS, getSelectedAppMode());
colorsCard.setListener(this); colorsCard.setListener(this);
parentView.removeAllViews(); colorsCardContainer.addView(colorsCard.build(app));
parentView.addView(colorsCard.build(app));
updateColorName(); updateColorName();
} }

View file

@ -184,7 +184,7 @@ public class ContourLinesMenu {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(toggleActionStringId, mapActivity) .setTitleId(toggleActionStringId, mapActivity)
.setIcon(toggleIconId) .setIcon(toggleIconId)
.setColor(toggleIconColorId) .setColor(app, toggleIconColorId)
.setListener(l) .setListener(l)
.setSelected(selected).createItem()); .setSelected(selected).createItem());
if (selected) { if (selected) {
@ -225,7 +225,7 @@ public class ContourLinesMenu {
.setTitleId(R.string.srtm_plugin_name, mapActivity) .setTitleId(R.string.srtm_plugin_name, mapActivity)
.setLayout(R.layout.list_item_icon_and_right_btn) .setLayout(R.layout.list_item_icon_and_right_btn)
.setIcon(R.drawable.ic_plugin_srtm) .setIcon(R.drawable.ic_plugin_srtm)
.setColor(R.color.osmand_orange) .setColor(app, R.color.osmand_orange)
.setDescription(app.getString(R.string.shared_string_plugin)) .setDescription(app.getString(R.string.shared_string_plugin))
.setListener(l).createItem()); .setListener(l).createItem());
} else { } else {

View file

@ -10,7 +10,6 @@ import android.widget.ArrayAdapter;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -303,7 +302,7 @@ public class SRTMPlugin extends OsmandPlugin {
if (item != null) { if (item != null) {
item.setDescription(app.getString(R.string.display_zoom_level, item.setDescription(app.getString(R.string.display_zoom_level,
getPrefDescription(app, contourLinesProp, pref))); getPrefDescription(app, contourLinesProp, pref)));
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setSelected(selected); item.setSelected(selected);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
@ -322,7 +321,7 @@ public class SRTMPlugin extends OsmandPlugin {
} }
ContextMenuItem item = adapter.getItem(position); ContextMenuItem item = adapter.getItem(position);
if (item != null) { if (item != null) {
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setSelected(selected); item.setSelected(selected);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
@ -346,7 +345,7 @@ public class SRTMPlugin extends OsmandPlugin {
.setSelected(contourLinesSelected) .setSelected(contourLinesSelected)
.setIcon(R.drawable.ic_plugin_srtm) .setIcon(R.drawable.ic_plugin_srtm)
.setDescription(app.getString(R.string.display_zoom_level, descr)) .setDescription(app.getString(R.string.display_zoom_level, descr))
.setColor(contourLinesSelected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, contourLinesSelected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setItemDeleteAction(makeDeleteAction(settings.CONTOUR_LINES_ZOOM)) .setItemDeleteAction(makeDeleteAction(settings.CONTOUR_LINES_ZOOM))
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(listener).createItem()); .setListener(listener).createItem());
@ -360,7 +359,7 @@ public class SRTMPlugin extends OsmandPlugin {
? R.string.shared_string_hillshade ? R.string.shared_string_hillshade
: R.string.download_slope_maps)) : R.string.download_slope_maps))
.setSelected(terrainEnabled) .setSelected(terrainEnabled)
.setColor(terrainEnabled ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, terrainEnabled ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_hillshade_dark) .setIcon(R.drawable.ic_action_hillshade_dark)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setItemDeleteAction(makeDeleteAction(settings.TERRAIN, settings.TERRAIN_MODE)) .setItemDeleteAction(makeDeleteAction(settings.TERRAIN, settings.TERRAIN_MODE))

View file

@ -9,7 +9,6 @@ import android.widget.LinearLayout;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.core.content.ContextCompat;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
@ -461,7 +460,7 @@ public class MapWidgetRegistry {
.setTitleId(R.string.configure_screen_quick_action, mapActivity) .setTitleId(R.string.configure_screen_quick_action, mapActivity)
.setIcon(R.drawable.ic_quick_action) .setIcon(R.drawable.ic_quick_action)
.setSelected(selected) .setSelected(selected)
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setSecondaryIcon( R.drawable.ic_action_additional_option) .setSecondaryIcon( R.drawable.ic_action_additional_option)
.setListener(new ContextMenuAdapter.OnRowItemClick() { .setListener(new ContextMenuAdapter.OnRowItemClick() {
@Override @Override
@ -497,7 +496,7 @@ public class MapWidgetRegistry {
} }
ContextMenuItem item = adapter.getItem(position); ContextMenuItem item = adapter.getItem(position);
item.setSelected(visible); item.setSelected(visible);
item.setColorRes(visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(app, visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
@ -519,7 +518,7 @@ public class MapWidgetRegistry {
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder() ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder()
.setIcon(r.getDrawableMenu()) .setIcon(r.getDrawableMenu())
.setSelected(selected) .setSelected(selected)
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setSecondaryIcon(r.widget != null ? R.drawable.ic_action_additional_option : ContextMenuItem.INVALID_ID) .setSecondaryIcon(r.widget != null ? R.drawable.ic_action_additional_option : ContextMenuItem.INVALID_ID)
.setDescription(r.visibleCollapsed(mode) ? desc : null) .setDescription(r.visibleCollapsed(mode) ? desc : null)
.setListener(new ContextMenuAdapter.OnRowItemClick() { .setListener(new ContextMenuAdapter.OnRowItemClick() {
@ -638,7 +637,7 @@ public class MapWidgetRegistry {
} }
ContextMenuItem item = adapter.getItem(position); ContextMenuItem item = adapter.getItem(position);
item.setSelected(visible); item.setSelected(visible);
item.setColorRes(visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColor(app, visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setDescription(visible && collapsed ? desc : null); item.setDescription(visible && collapsed ? desc : null);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }

View file

@ -141,7 +141,7 @@ public class WikipediaPlugin extends OsmandPlugin {
ContextMenuItem item = adapter.getItem(pos); ContextMenuItem item = adapter.getItem(pos);
if (item != null) { if (item != null) {
item.setSelected(selected); item.setSelected(selected);
item.setColorRes(selected ? item.setColor(app, selected ?
R.color.osmand_orange : ContextMenuItem.INVALID_ID); R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setDescription(selected ? getLanguagesSummary() : null); item.setDescription(selected ? getLanguagesSummary() : null);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
@ -160,7 +160,7 @@ public class WikipediaPlugin extends OsmandPlugin {
.setTitleId(R.string.shared_string_wikipedia, mapActivity) .setTitleId(R.string.shared_string_wikipedia, mapActivity)
.setDescription(selected ? getLanguagesSummary() : null) .setDescription(selected ? getLanguagesSummary() : null)
.setSelected(selected) .setSelected(selected)
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setColor(app, selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_plugin_wikipedia) .setIcon(R.drawable.ic_plugin_wikipedia)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(listener).createItem()); .setListener(listener).createItem());

View file

@ -74,7 +74,7 @@ public class WikipediaPoiMenu {
.setTitleId(toggleActionStringId, mapActivity) .setTitleId(toggleActionStringId, mapActivity)
.setDescription(summary) .setDescription(summary)
.setIcon(toggleIconId) .setIcon(toggleIconId)
.setColor(toggleIconColorId) .setColor(app, toggleIconColorId)
.setListener(l) .setListener(l)
.setSelected(enabled).createItem()); .setSelected(enabled).createItem());