Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-04-05 09:50:39 +02:00
commit 51aea91e3b
3 changed files with 134 additions and 53 deletions

View file

@ -47,6 +47,7 @@ import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.GPXLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.RouteLayer;
@ -472,6 +473,13 @@ public class ConfigureMapMenu {
OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
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) {

View file

@ -6,15 +6,19 @@ import android.widget.ArrayAdapter;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
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.RouteLayer;
import net.osmand.render.RenderingRuleProperty;
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_SCHEME_ATTR;
public class ContourLinesMenu {
private static final String TAG = "ContourLinesMenu";
@ -30,13 +34,15 @@ public class ContourLinesMenu {
final MapActivity mapActivity) {
final OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp == null) {
final RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
final RenderingRuleProperty colorSchemeProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_SCHEME_ATTR);
if (plugin == null || contourLinesProp == null || colorSchemeProp == null) {
return;
}
final OsmandSettings.CommonPreference<String> pref =
mapActivity.getMyApplication().getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
final OsmandSettings.CommonPreference<String> colorPref = settings.getCustomRenderProperty(colorSchemeProp.getAttrName());
final boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
@ -46,35 +52,95 @@ public class ContourLinesMenu {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter,
View view, int itemId, int pos) {
/*
if (itemId == showZoomLevelStringId) {
if (selected) {
// todo select zoom level
}
return false;
}
*/
return super.onRowItemClick(adapter, view, itemId, pos);
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter,
final int itemId, final int pos, final boolean isChecked) {
/*
if (itemId == toggleActionStringId) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
ConfigureMapMenu.refreshMapComplete(mapActivity);
plugin.toggleContourLines(mapActivity, isChecked, new Runnable() {
@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) {
hidePolygonsPref.set(!isChecked);
refreshMapComplete(mapActivity);
plugin.selectPropertyValue(mapActivity, colorSchemeProp, colorPref, new Runnable() {
@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;
}
};
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) {

View file

@ -1,6 +1,7 @@
package net.osmand.plus.srtmplugin;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.View;
@ -132,10 +133,31 @@ public class SRTMPlugin extends OsmandPlugin {
}
@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) {
toggleContourLines(mapActivity, adapter, itemId, position, isChecked);
adapter.notifyDataSetChanged();
toggleContourLines(mapActivity, isChecked, new Runnable() {
@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) {
HILLSHADE.set(!HILLSHADE.get());
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);
if (contourLinesProp != null) {
final OsmandSettings.CommonPreference<String> pref =
app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
String descr;
boolean contourLinesSelected;
if (!Algorithms.isEmpty(pref.get())) {
descr = SettingsActivity.getStringPropertyValue(mapActivity, pref.get());
contourLinesSelected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
} else {
descr = SettingsActivity.getStringPropertyValue(
mapActivity, contourLinesProp.getDefaultValueDescription());
contourLinesSelected = !contourLinesProp.getDefaultValueDescription().equals(CONTOUR_LINES_DISABLED_VALUE);
}
String descr = getPrefDescription(app, contourLinesProp, pref);
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.srtm_plugin_name, mapActivity)
.setSelected(contourLinesSelected)
@ -180,9 +198,9 @@ public class SRTMPlugin extends OsmandPlugin {
.createItem());
}
private void toggleContourLines(final MapActivity activity,
final ArrayAdapter<ContextMenuItem> adapter, final int itemId,
final int pos, final boolean isChecked) {
public void toggleContourLines(final MapActivity activity,
final boolean isChecked,
final Runnable callback) {
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
OsmandSettings settings = app.getSettings();
@ -192,35 +210,35 @@ public class SRTMPlugin extends OsmandPlugin {
if (!isChecked) {
zoomSetting.set(pref.get());
pref.set(CONTOUR_LINES_DISABLED_VALUE);
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setDescription(app.getString(R.string.display_zoom_level,
SettingsActivity.getStringPropertyValue(app, pref.get())));
item.setColorRes(ContextMenuItem.INVALID_ID);
if (callback != null) {
callback.run();
}
} else if (!Algorithms.isEmpty(zoomSetting.get())) {
} else if (zoomSetting.get() != null && !zoomSetting.get().equals(CONTOUR_LINES_DISABLED_VALUE)) {
pref.set(zoomSetting.get());
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setDescription(app.getString(R.string.display_zoom_level,
SettingsActivity.getStringPropertyValue(app, pref.get())));
item.setColorRes(R.color.osmand_orange);
if (callback != null) {
callback.run();
}
} else {
selectZoomLevel(activity, adapter, contourLinesProp, pref, pos);
selectPropertyValue(activity, contourLinesProp, pref, callback);
}
}
}
private void selectZoomLevel(final MapActivity activity,
final ArrayAdapter<ContextMenuItem> adapter,
final RenderingRuleProperty p,
final OsmandSettings.CommonPreference<String> pref,
final int pos) {
public String getPrefDescription(final Context ctx, final RenderingRuleProperty p, final OsmandSettings.CommonPreference<String> pref) {
if (!Algorithms.isEmpty(pref.get())) {
return SettingsActivity.getStringPropertyValue(ctx, pref.get());
} else {
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,
p.getAttrName(), p.getName());
AlertDialog.Builder b = new AlertDialog.Builder(activity);
// test old descr as title
b.setTitle(propertyDescr);
List<String> possibleValuesList = new ArrayList<>(Arrays.asList(p.getPossibleValues()));
@ -259,20 +277,9 @@ public class SRTMPlugin extends OsmandPlugin {
b.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
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);
}
if (callback != null) {
callback.run();
}
adapter.notifyDataSetChanged();
}
});
b.show();