This commit is contained in:
Chumva 2019-10-29 13:08:47 +02:00
parent 5558bacc16
commit 7f4f4f0dc7
8 changed files with 229 additions and 25 deletions

View file

@ -11,6 +11,14 @@
Thx - Hardy
-->
<string name="quick_action_contour_lines_descr">Tapping this action button shows or hides contour lines on the map</string>
<string name="quick_action_contour_lines_show">Show contour lines</string>
<string name="quick_action_contour_lines_hide">Hide contour lines</string>
<string name="quick_action_show_hide_contour_lines">Show/Hide contour lines</string>
<string name="quick_action_hillshade_descr">Tapping this action button shows or hides hillshade on the map</string>
<string name="quick_action_hillshade_show">Show hillshade</string>
<string name="quick_action_hillshade_hide">Hide hillshade</string>
<string name="quick_action_show_hide_hillshade">Show/Hide hillshade</string>
<string name="apply_preference_to_all_profiles">You can apply this change to all profiles or only to selected.</string>
<string name="shared_preference">Shared</string>
<string name="routing_attr_driving_style_prefer_unpaved_name">Prefer unpaved roads</string>

View file

@ -182,6 +182,7 @@ public abstract class OsmandPlugin {
LOG.error("Plugin initialization failed " + plugin.getId(), e);
}
} else if (plugin.isActive()) {
plugin.disable(app);
plugin.setActive(false);
}
}

View file

@ -1851,6 +1851,8 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> MAP_ONLINE_DATA = new BooleanPreference("map_online_data", false).makeProfile();
public final CommonPreference<Boolean> HILLSHADE = new BooleanPreference("hillshade_layer", true).makeProfile();
public final CommonPreference<String> CONTOUR_LINES_ZOOM = new StringPreference("contour_lines_zoom", null).makeGlobal().cache();
// this value string is synchronized with settings_pref.xml preference name

View file

@ -17,8 +17,11 @@ import net.osmand.plus.parkingpoint.ParkingAction;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.quickaction.actions.AddOSMBugAction;
import net.osmand.plus.quickaction.actions.AddPOIAction;
import net.osmand.plus.quickaction.actions.ContourLinesAction;
import net.osmand.plus.quickaction.actions.DayNightModeAction;
import net.osmand.plus.quickaction.actions.FavoriteAction;
import net.osmand.plus.quickaction.actions.GPXAction;
import net.osmand.plus.quickaction.actions.HillshadeAction;
import net.osmand.plus.quickaction.actions.MapOverlayAction;
import net.osmand.plus.quickaction.actions.MapSourceAction;
import net.osmand.plus.quickaction.actions.MapStyleAction;
@ -36,8 +39,8 @@ import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
import net.osmand.plus.quickaction.actions.ShowHideOSMBugAction;
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
import net.osmand.plus.quickaction.actions.DayNightModeAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.lang.reflect.Type;
import java.util.ArrayList;
@ -121,6 +124,11 @@ public class QuickActionFactory {
quickActions.add(new MapUnderlayAction());
}
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
quickActions.add(new ContourLinesAction());
quickActions.add(new HillshadeAction());
}
quickActions.add(new DayNightModeAction());
@ -246,6 +254,12 @@ public class QuickActionFactory {
case ShowHideGpxTracksAction.TYPE:
return new ShowHideGpxTracksAction();
case ContourLinesAction.TYPE:
return new ContourLinesAction();
case HillshadeAction.TYPE:
return new HillshadeAction();
default:
return new QuickAction();
}
@ -333,6 +347,12 @@ public class QuickActionFactory {
case ShowHideGpxTracksAction.TYPE:
return new ShowHideGpxTracksAction(quickAction);
case ContourLinesAction.TYPE:
return new ContourLinesAction(quickAction);
case HillshadeAction.TYPE:
return new HillshadeAction(quickAction);
default:
return quickAction;
}
@ -420,6 +440,12 @@ public class QuickActionFactory {
case ShowHideGpxTracksAction.TYPE:
return R.drawable.ic_gpx_track;
case ContourLinesAction.TYPE:
return R.drawable.ic_plugin_srtm;
case HillshadeAction.TYPE:
return R.drawable.ic_action_hillshade_dark;
default:
return R.drawable.ic_action_plus;
}
@ -507,6 +533,12 @@ public class QuickActionFactory {
case ShowHideGpxTracksAction.TYPE:
return R.string.quick_action_show_hide_gpx_tracks;
case ContourLinesAction.TYPE:
return R.string.quick_action_show_hide_contour_lines;
case HillshadeAction.TYPE:
return R.string.quick_action_show_hide_hillshade;
default:
return R.string.quick_action_new_action;
}
@ -534,6 +566,8 @@ public class QuickActionFactory {
case NavResumePauseAction.TYPE:
case DayNightModeAction.TYPE:
case ShowHideGpxTracksAction.TYPE:
case ContourLinesAction.TYPE:
case HillshadeAction.TYPE:
return false;
default:

View file

@ -17,9 +17,12 @@ import net.osmand.plus.parkingpoint.ParkingAction;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.quickaction.actions.AddOSMBugAction;
import net.osmand.plus.quickaction.actions.AddPOIAction;
import net.osmand.plus.quickaction.actions.ContourLinesAction;
import net.osmand.plus.quickaction.actions.HillshadeAction;
import net.osmand.plus.quickaction.actions.MapSourceAction;
import net.osmand.plus.quickaction.actions.MapStyleAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.lang.reflect.Type;
import java.util.ArrayList;
@ -111,6 +114,14 @@ public class QuickActionRegistry {
skip = true;
}
}
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null) {
if (action.type == ContourLinesAction.TYPE) {
skip = true;
}
if (action.type == HillshadeAction.TYPE) {
skip = true;
}
}
if (!skip) {
filteredActions.add(action);
}

View file

@ -0,0 +1,77 @@
package net.osmand.plus.quickaction.actions;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
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.quickaction.QuickAction;
import net.osmand.plus.srtmplugin.SRTMPlugin;
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;
public class ContourLinesAction extends QuickAction {
public static final int TYPE = 29;
public ContourLinesAction() {
super(TYPE);
}
public ContourLinesAction(QuickAction quickAction) {
super(quickAction);
}
@Override
public void execute(final MapActivity activity) {
final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
if (plugin != null) {
boolean enabled = SRTMPlugin.isContourLinesLayerEnabled(activity.getMyApplication());
plugin.toggleContourLines(activity, !enabled, new Runnable() {
@Override
public void run() {
OsmandApplication app = activity.getMyApplication();
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
final OsmandSettings.CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
if (selected && !plugin.isActive() && !plugin.needsInstallation()) {
OsmandPlugin.enablePlugin(activity, app, plugin, true);
}
SRTMPlugin.refreshMapComplete(activity);
}
}
});
}
}
@Override
public void drawUI(ViewGroup parent, MapActivity activity) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.quick_action_with_text, parent, false);
((TextView) view.findViewById(R.id.text))
.setText(R.string.quick_action_contour_lines_descr);
parent.addView(view);
}
@Override
public int getIconRes(Context context) {
return R.drawable.ic_plugin_srtm;
}
@Override
public String getActionText(OsmandApplication app) {
return SRTMPlugin.isContourLinesLayerEnabled(app) ? app.getString(R.string.quick_action_contour_lines_hide)
: app.getString(R.string.quick_action_contour_lines_show);
}
}

View file

@ -0,0 +1,64 @@
package net.osmand.plus.quickaction.actions;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.srtmplugin.SRTMPlugin;
public class HillshadeAction extends QuickAction {
public static final int TYPE = 30;
public HillshadeAction() {
super(TYPE);
}
public HillshadeAction(QuickAction quickAction) {
super(quickAction);
}
@Override
public void execute(final MapActivity activity) {
final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
if (plugin != null) {
plugin.toggleHillshade(activity, !plugin.isHillShadeLayerEnabled(), new Runnable() {
@Override
public void run() {
if (plugin.isHillShadeLayerEnabled() && !plugin.isActive() && !plugin.needsInstallation()) {
OsmandPlugin.enablePlugin(activity, activity.getMyApplication(), plugin, true);
}
plugin.updateLayers(activity.getMapView(), activity);
SRTMPlugin.refreshMapComplete(activity);
}
});
}
}
@Override
public void drawUI(ViewGroup parent, MapActivity activity) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.quick_action_with_text, parent, false);
((TextView) view.findViewById(R.id.text))
.setText(R.string.quick_action_hillshade_descr);
parent.addView(view);
}
@Override
public int getIconRes(Context context) {
return R.drawable.ic_action_hillshade_dark;
}
@Override
public String getActionText(OsmandApplication application) {
return application.getSettings().HILLSHADE.get() ? application.getString(R.string.quick_action_hillshade_hide)
: application.getString(R.string.quick_action_hillshade_show);
}
}

View file

@ -44,10 +44,11 @@ public class SRTMPlugin extends OsmandPlugin {
public static final String CONTOUR_DENSITY_ATTR = "contourDensity";
private OsmandApplication app;
private OsmandSettings settings;
private boolean paid;
private HillshadeLayer hillshadeLayer;
private CommonPreference<Boolean> HILLSHADE;
@Override
public String getId() {
return paid ? ID : FREE_ID;
@ -55,7 +56,7 @@ public class SRTMPlugin extends OsmandPlugin {
public SRTMPlugin(OsmandApplication app) {
this.app = app;
HILLSHADE = app.getSettings().registerBooleanPreference("hillshade_layer", true);
settings = app.getSettings();
}
@Override
@ -106,19 +107,34 @@ public class SRTMPlugin extends OsmandPlugin {
if (hillshadeLayer != null) {
activity.getMapView().removeLayer(hillshadeLayer);
}
if (HILLSHADE.get()) {
if (settings.HILLSHADE.get()) {
hillshadeLayer = new HillshadeLayer(activity, this);
activity.getMapView().addLayer(hillshadeLayer, 0.6f);
}
}
public boolean isHillShadeLayerEnabled() {
return HILLSHADE.get();
return settings.HILLSHADE.get();
}
public static boolean isContourLinesLayerEnabled(OsmandApplication app) {
boolean contourLinesEnabled = false;
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
final OsmandSettings.CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
if (!Algorithms.isEmpty(pref.get())) {
contourLinesEnabled = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
} else {
contourLinesEnabled = !contourLinesProp.getDefaultValueDescription().equals(CONTOUR_LINES_DISABLED_VALUE);
}
}
return contourLinesEnabled;
}
@Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
if (HILLSHADE.get() && isActive()) {
if (settings.HILLSHADE.get() && isActive()) {
if (hillshadeLayer == null) {
registerLayers(activity);
}
@ -160,9 +176,7 @@ public class SRTMPlugin extends OsmandPlugin {
public void run() {
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
OsmandSettings settings = app.getSettings();
final OsmandSettings.CommonPreference<String> pref =
settings.getCustomRenderProperty(contourLinesProp.getAttrName());
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
@ -187,7 +201,7 @@ public class SRTMPlugin extends OsmandPlugin {
toggleHillshade(mapActivity, isChecked, new Runnable() {
@Override
public void run() {
boolean selected = HILLSHADE.get();
boolean selected = settings.HILLSHADE.get();
SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
if (selected && plugin != null && !plugin.isActive() && !plugin.needsInstallation()) {
OsmandPlugin.enablePlugin(mapActivity, mapActivity.getMyApplication(), plugin, true);
@ -210,14 +224,8 @@ public class SRTMPlugin extends OsmandPlugin {
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
final OsmandSettings.CommonPreference<String> pref =
app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
boolean contourLinesSelected;
if (!Algorithms.isEmpty(pref.get())) {
contourLinesSelected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
} else {
contourLinesSelected = !contourLinesProp.getDefaultValueDescription().equals(CONTOUR_LINES_DISABLED_VALUE);
}
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
boolean contourLinesSelected = isContourLinesLayerEnabled(app);
String descr = getPrefDescription(app, contourLinesProp, pref);
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(CONTOUR_LINES)
@ -230,11 +238,12 @@ public class SRTMPlugin extends OsmandPlugin {
.setPosition(12)
.setListener(listener).createItem());
}
boolean hillshadeEnabled = settings.HILLSHADE.get();
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(HILLSHADE_LAYER)
.setTitleId(R.string.layer_hillshade, mapActivity)
.setSelected(HILLSHADE.get())
.setColor(HILLSHADE.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setSelected(hillshadeEnabled)
.setColor(hillshadeEnabled ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_hillshade_dark)
.setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(listener)
@ -247,9 +256,7 @@ public class SRTMPlugin extends OsmandPlugin {
final Runnable callback) {
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
OsmandSettings settings = app.getSettings();
final OsmandSettings.CommonPreference<String> pref =
settings.getCustomRenderProperty(contourLinesProp.getAttrName());
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
CommonPreference<String> zoomSetting = settings.CONTOUR_LINES_ZOOM;
if (!isChecked) {
zoomSetting.set(pref.get());
@ -271,7 +278,7 @@ public class SRTMPlugin extends OsmandPlugin {
public void toggleHillshade(final MapActivity activity,
final boolean isChecked,
final Runnable callback) {
HILLSHADE.set(isChecked);
settings.HILLSHADE.set(isChecked);
if (callback != null) {
callback.run();
}