Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
51aea91e3b
3 changed files with 134 additions and 53 deletions
|
@ -47,6 +47,7 @@ import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
|
||||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
|
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||||
import net.osmand.plus.views.GPXLayer;
|
import net.osmand.plus.views.GPXLayer;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
import net.osmand.plus.views.RouteLayer;
|
import net.osmand.plus.views.RouteLayer;
|
||||||
|
@ -472,6 +473,13 @@ public class ConfigureMapMenu {
|
||||||
|
|
||||||
OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
|
OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
|
||||||
app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
|
app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
|
||||||
|
boolean srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
|
||||||
|
if (srtmDisabled) {
|
||||||
|
SRTMPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
|
||||||
|
if (srtmPlugin != null) {
|
||||||
|
srtmPlugin.registerLayerContextMenuActions(activity.getMapView(), adapter, activity);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshMapComplete(final MapActivity activity) {
|
public static void refreshMapComplete(final MapActivity activity) {
|
||||||
|
|
|
@ -6,15 +6,19 @@ import android.widget.ArrayAdapter;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.plus.ContextMenuItem;
|
import net.osmand.plus.ContextMenuItem;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.activities.SettingsActivity;
|
||||||
|
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||||
import net.osmand.plus.views.GPXLayer;
|
import net.osmand.plus.views.GPXLayer;
|
||||||
import net.osmand.plus.views.RouteLayer;
|
import net.osmand.plus.views.RouteLayer;
|
||||||
import net.osmand.render.RenderingRuleProperty;
|
import net.osmand.render.RenderingRuleProperty;
|
||||||
|
|
||||||
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_ATTR;
|
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_ATTR;
|
||||||
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_DISABLED_VALUE;
|
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_DISABLED_VALUE;
|
||||||
|
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_SCHEME_ATTR;
|
||||||
|
|
||||||
public class ContourLinesMenu {
|
public class ContourLinesMenu {
|
||||||
private static final String TAG = "ContourLinesMenu";
|
private static final String TAG = "ContourLinesMenu";
|
||||||
|
@ -30,13 +34,15 @@ public class ContourLinesMenu {
|
||||||
final MapActivity mapActivity) {
|
final MapActivity mapActivity) {
|
||||||
final OsmandApplication app = mapActivity.getMyApplication();
|
final OsmandApplication app = mapActivity.getMyApplication();
|
||||||
final OsmandSettings settings = app.getSettings();
|
final OsmandSettings settings = app.getSettings();
|
||||||
|
final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
|
||||||
|
|
||||||
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
|
final RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
|
||||||
if (contourLinesProp == null) {
|
final RenderingRuleProperty colorSchemeProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_SCHEME_ATTR);
|
||||||
|
if (plugin == null || contourLinesProp == null || colorSchemeProp == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final OsmandSettings.CommonPreference<String> pref =
|
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
|
||||||
mapActivity.getMyApplication().getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
|
final OsmandSettings.CommonPreference<String> colorPref = settings.getCustomRenderProperty(colorSchemeProp.getAttrName());
|
||||||
|
|
||||||
final boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
|
final boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
|
||||||
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
|
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
|
||||||
|
@ -46,35 +52,95 @@ public class ContourLinesMenu {
|
||||||
@Override
|
@Override
|
||||||
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter,
|
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter,
|
||||||
View view, int itemId, int pos) {
|
View view, int itemId, int pos) {
|
||||||
|
/*
|
||||||
if (itemId == showZoomLevelStringId) {
|
if (itemId == showZoomLevelStringId) {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
// todo select zoom level
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return super.onRowItemClick(adapter, view, itemId, pos);
|
return super.onRowItemClick(adapter, view, itemId, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter,
|
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter,
|
||||||
final int itemId, final int pos, final boolean isChecked) {
|
final int itemId, final int pos, final boolean isChecked) {
|
||||||
/*
|
|
||||||
if (itemId == toggleActionStringId) {
|
if (itemId == toggleActionStringId) {
|
||||||
app.runInUIThread(new Runnable() {
|
app.runInUIThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
|
plugin.toggleContourLines(mapActivity, isChecked, new Runnable() {
|
||||||
ConfigureMapMenu.refreshMapComplete(mapActivity);
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mapActivity.getDashboard().refreshContent(true);
|
||||||
|
refreshMapComplete(mapActivity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (itemId == showZoomLevelStringId) {
|
||||||
|
plugin.selectPropertyValue(mapActivity, contourLinesProp, pref, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ContextMenuItem item = adapter.getItem(pos);
|
||||||
|
if (item != null) {
|
||||||
|
item.setDescription(plugin.getPrefDescription(app, contourLinesProp, pref));
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
refreshMapComplete(mapActivity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (itemId == colorSchemeStringId) {
|
} else if (itemId == colorSchemeStringId) {
|
||||||
hidePolygonsPref.set(!isChecked);
|
plugin.selectPropertyValue(mapActivity, colorSchemeProp, colorPref, new Runnable() {
|
||||||
refreshMapComplete(mapActivity);
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ContextMenuItem item = adapter.getItem(pos);
|
||||||
|
if (item != null) {
|
||||||
|
item.setDescription(plugin.getPrefDescription(app, colorSchemeProp, colorPref));
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
refreshMapComplete(mapActivity);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
boolean light = settings.isLightContent();
|
||||||
|
int toggleIconColorId;
|
||||||
|
int toggleIconId;
|
||||||
|
if (selected) {
|
||||||
|
toggleIconId = R.drawable.ic_action_view;
|
||||||
|
toggleIconColorId = light ?
|
||||||
|
R.color.color_dialog_buttons_light : R.color.color_dialog_buttons_dark;
|
||||||
|
} else {
|
||||||
|
toggleIconId = R.drawable.ic_action_hide;
|
||||||
|
toggleIconColorId = light ? R.color.icon_color : 0;
|
||||||
|
}
|
||||||
|
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
|
.setTitleId(toggleActionStringId, mapActivity)
|
||||||
|
.setIcon(toggleIconId)
|
||||||
|
.setColor(toggleIconColorId)
|
||||||
|
.hideDivider(true)
|
||||||
|
.setListener(l)
|
||||||
|
.setSelected(selected).createItem());
|
||||||
|
if (selected) {
|
||||||
|
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
|
.setTitleId(showZoomLevelStringId, mapActivity)
|
||||||
|
.setLayout(R.layout.list_item_single_line_descrition_narrow)
|
||||||
|
.setIcon(R.drawable.ic_action_map_magnifier)
|
||||||
|
.hideDivider(true)
|
||||||
|
.setDescription(plugin.getPrefDescription(app, contourLinesProp, pref))
|
||||||
|
.setListener(l).createItem());
|
||||||
|
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
|
.setTitleId(colorSchemeStringId, mapActivity)
|
||||||
|
.setLayout(R.layout.list_item_single_line_descrition_narrow)
|
||||||
|
.setIcon(R.drawable.ic_action_appearance)
|
||||||
|
.hideDivider(true)
|
||||||
|
.setDescription(plugin.getPrefDescription(app, colorSchemeProp, colorPref))
|
||||||
|
.setListener(l).createItem());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshMapComplete(final MapActivity activity) {
|
public static void refreshMapComplete(final MapActivity activity) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.osmand.plus.srtmplugin;
|
package net.osmand.plus.srtmplugin;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -132,10 +133,31 @@ public class SRTMPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
|
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter,
|
||||||
|
final int itemId,
|
||||||
|
final int position,
|
||||||
|
final boolean isChecked) {
|
||||||
if (itemId == R.string.srtm_plugin_name) {
|
if (itemId == R.string.srtm_plugin_name) {
|
||||||
toggleContourLines(mapActivity, adapter, itemId, position, isChecked);
|
toggleContourLines(mapActivity, isChecked, new Runnable() {
|
||||||
adapter.notifyDataSetChanged();
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ContextMenuItem item = adapter.getItem(position);
|
||||||
|
if (item != null) {
|
||||||
|
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
|
||||||
|
if (contourLinesProp != null) {
|
||||||
|
OsmandSettings settings = app.getSettings();
|
||||||
|
final OsmandSettings.CommonPreference<String> pref =
|
||||||
|
settings.getCustomRenderProperty(contourLinesProp.getAttrName());
|
||||||
|
boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
|
||||||
|
item.setDescription(app.getString(R.string.display_zoom_level,
|
||||||
|
getPrefDescription(app, contourLinesProp, pref)));
|
||||||
|
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||||
|
item.setSelected(selected);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (itemId == R.string.layer_hillshade) {
|
} else if (itemId == R.string.layer_hillshade) {
|
||||||
HILLSHADE.set(!HILLSHADE.get());
|
HILLSHADE.set(!HILLSHADE.get());
|
||||||
adapter.getItem(position).setColorRes(HILLSHADE.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
adapter.getItem(position).setColorRes(HILLSHADE.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||||
|
@ -146,21 +168,17 @@ public class SRTMPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//app.getSettings().CONTOUR_LINES_ZOOM.set(null);
|
|
||||||
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
|
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
|
||||||
if (contourLinesProp != null) {
|
if (contourLinesProp != null) {
|
||||||
final OsmandSettings.CommonPreference<String> pref =
|
final OsmandSettings.CommonPreference<String> pref =
|
||||||
app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
|
app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
|
||||||
String descr;
|
|
||||||
boolean contourLinesSelected;
|
boolean contourLinesSelected;
|
||||||
if (!Algorithms.isEmpty(pref.get())) {
|
if (!Algorithms.isEmpty(pref.get())) {
|
||||||
descr = SettingsActivity.getStringPropertyValue(mapActivity, pref.get());
|
|
||||||
contourLinesSelected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
|
contourLinesSelected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
|
||||||
} else {
|
} else {
|
||||||
descr = SettingsActivity.getStringPropertyValue(
|
|
||||||
mapActivity, contourLinesProp.getDefaultValueDescription());
|
|
||||||
contourLinesSelected = !contourLinesProp.getDefaultValueDescription().equals(CONTOUR_LINES_DISABLED_VALUE);
|
contourLinesSelected = !contourLinesProp.getDefaultValueDescription().equals(CONTOUR_LINES_DISABLED_VALUE);
|
||||||
}
|
}
|
||||||
|
String descr = getPrefDescription(app, contourLinesProp, pref);
|
||||||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
.setTitleId(R.string.srtm_plugin_name, mapActivity)
|
.setTitleId(R.string.srtm_plugin_name, mapActivity)
|
||||||
.setSelected(contourLinesSelected)
|
.setSelected(contourLinesSelected)
|
||||||
|
@ -180,9 +198,9 @@ public class SRTMPlugin extends OsmandPlugin {
|
||||||
.createItem());
|
.createItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleContourLines(final MapActivity activity,
|
public void toggleContourLines(final MapActivity activity,
|
||||||
final ArrayAdapter<ContextMenuItem> adapter, final int itemId,
|
final boolean isChecked,
|
||||||
final int pos, final boolean isChecked) {
|
final Runnable callback) {
|
||||||
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
|
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
|
||||||
if (contourLinesProp != null) {
|
if (contourLinesProp != null) {
|
||||||
OsmandSettings settings = app.getSettings();
|
OsmandSettings settings = app.getSettings();
|
||||||
|
@ -192,35 +210,35 @@ public class SRTMPlugin extends OsmandPlugin {
|
||||||
if (!isChecked) {
|
if (!isChecked) {
|
||||||
zoomSetting.set(pref.get());
|
zoomSetting.set(pref.get());
|
||||||
pref.set(CONTOUR_LINES_DISABLED_VALUE);
|
pref.set(CONTOUR_LINES_DISABLED_VALUE);
|
||||||
ContextMenuItem item = adapter.getItem(pos);
|
if (callback != null) {
|
||||||
if (item != null) {
|
callback.run();
|
||||||
item.setDescription(app.getString(R.string.display_zoom_level,
|
|
||||||
SettingsActivity.getStringPropertyValue(app, pref.get())));
|
|
||||||
item.setColorRes(ContextMenuItem.INVALID_ID);
|
|
||||||
}
|
}
|
||||||
} else if (!Algorithms.isEmpty(zoomSetting.get())) {
|
} else if (zoomSetting.get() != null && !zoomSetting.get().equals(CONTOUR_LINES_DISABLED_VALUE)) {
|
||||||
pref.set(zoomSetting.get());
|
pref.set(zoomSetting.get());
|
||||||
ContextMenuItem item = adapter.getItem(pos);
|
if (callback != null) {
|
||||||
if (item != null) {
|
callback.run();
|
||||||
item.setDescription(app.getString(R.string.display_zoom_level,
|
|
||||||
SettingsActivity.getStringPropertyValue(app, pref.get())));
|
|
||||||
item.setColorRes(R.color.osmand_orange);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
selectZoomLevel(activity, adapter, contourLinesProp, pref, pos);
|
selectPropertyValue(activity, contourLinesProp, pref, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectZoomLevel(final MapActivity activity,
|
public String getPrefDescription(final Context ctx, final RenderingRuleProperty p, final OsmandSettings.CommonPreference<String> pref) {
|
||||||
final ArrayAdapter<ContextMenuItem> adapter,
|
if (!Algorithms.isEmpty(pref.get())) {
|
||||||
final RenderingRuleProperty p,
|
return SettingsActivity.getStringPropertyValue(ctx, pref.get());
|
||||||
final OsmandSettings.CommonPreference<String> pref,
|
} else {
|
||||||
final int pos) {
|
return SettingsActivity.getStringPropertyValue(ctx, p.getDefaultValueDescription());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectPropertyValue(final MapActivity activity,
|
||||||
|
final RenderingRuleProperty p,
|
||||||
|
final OsmandSettings.CommonPreference<String> pref,
|
||||||
|
final Runnable callback) {
|
||||||
final String propertyDescr = SettingsActivity.getStringPropertyDescription(activity,
|
final String propertyDescr = SettingsActivity.getStringPropertyDescription(activity,
|
||||||
p.getAttrName(), p.getName());
|
p.getAttrName(), p.getName());
|
||||||
AlertDialog.Builder b = new AlertDialog.Builder(activity);
|
AlertDialog.Builder b = new AlertDialog.Builder(activity);
|
||||||
// test old descr as title
|
|
||||||
b.setTitle(propertyDescr);
|
b.setTitle(propertyDescr);
|
||||||
|
|
||||||
List<String> possibleValuesList = new ArrayList<>(Arrays.asList(p.getPossibleValues()));
|
List<String> possibleValuesList = new ArrayList<>(Arrays.asList(p.getPossibleValues()));
|
||||||
|
@ -259,20 +277,9 @@ public class SRTMPlugin extends OsmandPlugin {
|
||||||
b.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
b.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
ContextMenuItem item = adapter.getItem(pos);
|
if (callback != null) {
|
||||||
if (item != null) {
|
callback.run();
|
||||||
String description = activity.getString(R.string.display_zoom_level,
|
|
||||||
SettingsActivity.getStringPropertyValue(activity, pref.get()));
|
|
||||||
item.setDescription(description);
|
|
||||||
if (pref.get().equals(CONTOUR_LINES_DISABLED_VALUE)) {
|
|
||||||
item.setSelected(false);
|
|
||||||
item.setColorRes(ContextMenuItem.INVALID_ID);
|
|
||||||
} else {
|
|
||||||
item.setSelected(true);
|
|
||||||
item.setColorRes(R.color.osmand_orange);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
b.show();
|
b.show();
|
||||||
|
|
Loading…
Reference in a new issue