Fixed highlight for buttons.

This commit is contained in:
GaidamakUA 2016-04-04 19:01:34 +03:00
parent 95d6ccd9fa
commit 5013c8d44d
5 changed files with 68 additions and 14 deletions

View file

@ -49,6 +49,7 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -581,11 +582,15 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override @Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) { public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
final int defaultColor = IconsCache.getDefaultColorRes(mapActivity);
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() { ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
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() ?
R.color.osmand_orange : defaultColor);
adapter.notifyDataSetChanged();
updateLayers(mapView, mapActivity); updateLayers(mapView, mapActivity);
} }
return true; return true;
@ -594,6 +599,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_recordings, app) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_recordings, app)
.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 : defaultColor)
.setPosition(12) .setPosition(12)
.setListener(listener).createItem()); .setListener(listener).createItem());
} }

View file

@ -4,11 +4,13 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener; import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent; import android.content.Intent;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
@ -19,6 +21,7 @@ import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -82,10 +85,12 @@ public class ConfigureMapMenu {
private final class LayerMenuListener extends OnRowItemClick { private final class LayerMenuListener extends OnRowItemClick {
private MapActivity ma; private MapActivity ma;
private ContextMenuAdapter cm; private ContextMenuAdapter cm;
@ColorRes final int defaultColor;
private LayerMenuListener(MapActivity ma, ContextMenuAdapter cm) { private LayerMenuListener(MapActivity ma, ContextMenuAdapter cm) {
this.ma = ma; this.ma = ma;
this.cm = cm; this.cm = cm;
defaultColor = IconsCache.getDefaultColorRes(ma);
} }
private List<String> getAlreadySelectedGpx() { private List<String> getAlreadySelectedGpx() {
@ -107,13 +112,26 @@ public class ConfigureMapMenu {
ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), ma.getMapView()); ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), ma.getMapView());
return false; return false;
} else { } else {
return super.onRowItemClick(adapter, view, itemId, pos); CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
cm.getItem(pos).setColorRes(btn.isChecked() ? R.color.osmand_orange : defaultColor);
adapter.notifyDataSetChanged();
return false;
} else {
return onContextMenuClick(adapter, itemId, pos, false);
}
} }
} }
@Override @Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked) { public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked) {
final OsmandSettings settings = ma.getMyApplication().getSettings(); final OsmandSettings settings = ma.getMyApplication().getSettings();
final ContextMenuItem item = cm.getItem(pos);
if (item.getSelected() != null) {
item.setColorRes(isChecked ? R.color.osmand_orange : defaultColor);
adapter.notifyDataSetChanged();
}
if (itemId == R.string.layer_poi) { if (itemId == R.string.layer_poi) {
settings.SELECTED_POI_FILTER_FOR_MAP.set(null); settings.SELECTED_POI_FILTER_FOR_MAP.set(null);
if (isChecked) { if (isChecked) {
@ -134,7 +152,8 @@ public class ConfigureMapMenu {
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
boolean areAnyGpxTracksVisible = boolean areAnyGpxTracksVisible =
ma.getMyApplication().getSelectedGpxHelper().isShowingAnyGpxFiles(); ma.getMyApplication().getSelectedGpxHelper().isShowingAnyGpxFiles();
cm.getItem(pos).setSelected(areAnyGpxTracksVisible); item.setSelected(areAnyGpxTracksVisible);
item.setColorRes(areAnyGpxTracksVisible ? R.color.osmand_orange : defaultColor);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
}); });
@ -169,6 +188,7 @@ public class ConfigureMapMenu {
} }
private void createLayersItems(ContextMenuAdapter adapter, MapActivity activity) { private void createLayersItems(ContextMenuAdapter adapter, MapActivity activity) {
@ColorRes final int defaultColor = IconsCache.getDefaultColorRes(activity);
OsmandApplication app = activity.getMyApplication(); OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
LayerMenuListener l = new LayerMenuListener(activity, adapter); LayerMenuListener l = new LayerMenuListener(activity, adapter);
@ -176,25 +196,33 @@ public class ConfigureMapMenu {
.setTitleId(R.string.shared_string_show, activity) .setTitleId(R.string.shared_string_show, activity)
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem()); .setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
// String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] "; // String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
adapter.addItem(new ContextMenuItem.ItemBuilder() boolean selected = settings.SHOW_FAVORITES.get();
.setTitleId(R.string.layer_poi, activity)
.setSelected(settings.SELECTED_POI_FILTER_FOR_MAP.get() != null)
.setIcon(R.drawable.ic_action_info_dark)
.setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(l).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_amenity_label, activity)
.setSelected(settings.SHOW_POI_LABEL.get())
.setIcon(R.drawable.ic_action_text_dark)
.setListener(l).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder() adapter.addItem(new ContextMenuItem.ItemBuilder()
.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 : defaultColor)
.setIcon(R.drawable.ic_action_fav_dark) .setIcon(R.drawable.ic_action_fav_dark)
.setListener(l).createItem()); .setListener(l).createItem());
selected = settings.SELECTED_POI_FILTER_FOR_MAP.get() != null;
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_poi, activity)
.setSelected(settings.SELECTED_POI_FILTER_FOR_MAP.get() != null)
.setColor(selected ? R.color.osmand_orange : defaultColor)
.setIcon(R.drawable.ic_action_info_dark)
.setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(l).createItem());
selected = settings.SHOW_POI_LABEL.get();
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_amenity_label, activity)
.setSelected(settings.SHOW_POI_LABEL.get())
.setColor(selected ? R.color.osmand_orange : defaultColor)
.setIcon(R.drawable.ic_action_text_dark)
.setListener(l).createItem());
selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
adapter.addItem(new ContextMenuItem.ItemBuilder() adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_gpx_layer, activity) .setTitleId(R.string.layer_gpx_layer, activity)
.setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles()) .setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles())
.setColor(selected ? R.color.osmand_orange : defaultColor)
.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());
@ -203,9 +231,11 @@ public class ConfigureMapMenu {
.setIcon(R.drawable.ic_world_globe_dark) .setIcon(R.drawable.ic_world_globe_dark)
.setListener(l).createItem()); .setListener(l).createItem());
if (TransportRouteHelper.getInstance().routeIsCalculated()) { if (TransportRouteHelper.getInstance().routeIsCalculated()) {
selected = true;
adapter.addItem(new ContextMenuItem.ItemBuilder() adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_transport_route, activity) .setTitleId(R.string.layer_transport_route, activity)
.setSelected(true) .setSelected(true)
.setColor(selected ? R.color.osmand_orange : defaultColor)
.setIcon(R.drawable.ic_action_bus_dark) .setIcon(R.drawable.ic_action_bus_dark)
.setListener(l).createItem()); .setListener(l).createItem());
} }

View file

@ -22,6 +22,7 @@ import net.osmand.osm.edit.Node;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -257,15 +258,21 @@ public class OsmEditingPlugin extends OsmandPlugin {
@Override @Override
public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) { public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
final int defaultColor = IconsCache.getDefaultColorRes(mapActivity);
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_osm_bugs, mapActivity) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_osm_bugs, mapActivity)
.setSelected(settings.SHOW_OSM_BUGS.get()) .setSelected(settings.SHOW_OSM_BUGS.get())
.setIcon(R.drawable.ic_action_bug_dark) .setIcon(R.drawable.ic_action_bug_dark)
.setColor(settings.SHOW_OSM_BUGS.get() ? R.color.osmand_orange : defaultColor)
.setListener(new ContextMenuAdapter.ItemClickListener() { .setListener(new ContextMenuAdapter.ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.layer_osm_bugs) { if (itemId == R.string.layer_osm_bugs) {
settings.SHOW_OSM_BUGS.set(isChecked); OsmandSettings.OsmandPreference<Boolean> showOsmBugs = settings.SHOW_OSM_BUGS;
showOsmBugs.set(isChecked);
adapter.getItem(pos).setColorRes(showOsmBugs.get() ?
R.color.osmand_orange : defaultColor);
adapter.notifyDataSetChanged();
updateLayers(mapActivity.getMapView(), mapActivity); updateLayers(mapActivity.getMapView(), mapActivity);
} }
return true; return true;

View file

@ -25,6 +25,7 @@ import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -235,6 +236,8 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, public void registerLayerContextMenuActions(final OsmandMapTileView mapView,
ContextMenuAdapter adapter, ContextMenuAdapter adapter,
final MapActivity mapActivity) { final MapActivity mapActivity) {
final int defaultColor = IconsCache.getDefaultColorRes(mapActivity);
final MapActivityLayers layers = mapActivity.getMapLayers(); final MapActivityLayers layers = mapActivity.getMapLayers();
ContextMenuAdapter.ItemClickListener listener = new ItemClickListener() { ContextMenuAdapter.ItemClickListener listener = new ItemClickListener() {
@Override @Override
@ -259,6 +262,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_overlay, mapActivity) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_overlay, mapActivity)
.setDescription(overlayMapDescr) .setDescription(overlayMapDescr)
.setSelected(hasOverlayDescription) .setSelected(hasOverlayDescription)
.setColor(hasOverlayDescription ? R.color.osmand_orange : defaultColor)
.setIcon(R.drawable.ic_layer_top_dark) .setIcon(R.drawable.ic_layer_top_dark)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(listener) .setListener(listener)
@ -270,6 +274,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_underlay, mapActivity) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_underlay, mapActivity)
.setDescription(underlayMapDescr) .setDescription(underlayMapDescr)
.setSelected(hasUnderlayDescription) .setSelected(hasUnderlayDescription)
.setColor(hasUnderlayDescription ? R.color.osmand_orange : defaultColor)
.setIcon(R.drawable.ic_layer_bottom_dark) .setIcon(R.drawable.ic_layer_bottom_dark)
.setSecondaryIcon(R.drawable.ic_action_additional_option) .setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(listener) .setListener(listener)

View file

@ -7,6 +7,7 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -105,11 +106,15 @@ public class SRTMPlugin extends OsmandPlugin {
@Override @Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) { public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
final int defaultColor = IconsCache.getDefaultColorRes(mapActivity);
ItemClickListener listener = new ItemClickListener() { ItemClickListener listener = new ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.layer_hillshade) { if (itemId == R.string.layer_hillshade) {
HILLSHADE.set(!HILLSHADE.get()); HILLSHADE.set(!HILLSHADE.get());
adapter.getItem(pos).setColorRes(HILLSHADE.get() ? R.color.osmand_orange
: defaultColor);
adapter.notifyDataSetChanged();
updateLayers(mapView, mapActivity); updateLayers(mapView, mapActivity);
} }
return true; return true;
@ -118,6 +123,7 @@ public class SRTMPlugin extends OsmandPlugin {
adapter.addItem(new ContextMenuItem.ItemBuilder() adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_hillshade, mapActivity) .setTitleId(R.string.layer_hillshade, mapActivity)
.setSelected(HILLSHADE.get()) .setSelected(HILLSHADE.get())
.setColor(HILLSHADE.get() ? R.color.osmand_orange : defaultColor)
.setIcon(R.drawable.ic_action_hillshade_dark) .setIcon(R.drawable.ic_action_hillshade_dark)
.setListener(listener) .setListener(listener)
.setPosition(13) .setPosition(13)