Save transport settings Fix #2908
This commit is contained in:
parent
6dcee1c58b
commit
3b41b6ce8b
5 changed files with 155 additions and 81 deletions
|
@ -14,7 +14,6 @@ import android.os.Environment;
|
|||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.ValueHolder;
|
||||
|
@ -516,6 +515,59 @@ public class OsmandSettings {
|
|||
return settingsAPI.edit(prefs).putString(getId(), (val != null) ? val.trim() : val).commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ListStringPreference extends StringPreference {
|
||||
|
||||
private String delimiter;
|
||||
|
||||
private ListStringPreference(String id, String defaultValue, String delimiter) {
|
||||
super(id, defaultValue);
|
||||
this.delimiter = delimiter;
|
||||
}
|
||||
|
||||
public boolean addValue(String res) {
|
||||
String vl = get();
|
||||
if (vl == null || vl.isEmpty()) {
|
||||
vl = res + delimiter;
|
||||
} else {
|
||||
vl = vl + res + delimiter;
|
||||
}
|
||||
set(vl);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearAll() {
|
||||
set("");
|
||||
}
|
||||
|
||||
public boolean containsValue(String res) {
|
||||
String vl = get();
|
||||
String r = res + delimiter;
|
||||
return vl.startsWith(r) || vl.indexOf(delimiter + r) >= 0;
|
||||
}
|
||||
|
||||
public boolean removeValue(String res) {
|
||||
String vl = get();
|
||||
String r = res + delimiter;
|
||||
if(vl != null) {
|
||||
if(vl.startsWith(r)) {
|
||||
vl = vl.substring(r.length());
|
||||
set(vl);
|
||||
return true;
|
||||
} else {
|
||||
int it = vl.indexOf(delimiter + r);
|
||||
if(it >= 0) {
|
||||
vl = vl.substring(0, it + delimiter.length()) + vl.substring(it + delimiter.length() + r.length());
|
||||
}
|
||||
set(vl);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class EnumIntPreference<E extends Enum<E>> extends CommonPreference<E> {
|
||||
|
@ -2608,6 +2660,9 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<Boolean> FOLLOW_THE_ROUTE = new BooleanPreference("follow_to_route", false).makeGlobal();
|
||||
public final OsmandPreference<String> FOLLOW_THE_GPX_ROUTE = new StringPreference("follow_gpx", null).makeGlobal();
|
||||
|
||||
public final ListStringPreference TRANSPORT_DEFAULT_SETTINGS =
|
||||
(ListStringPreference) new ListStringPreference("transport_default_settings", "transportStops", ",").makeProfile();
|
||||
|
||||
public final OsmandPreference<Boolean> SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME =
|
||||
new BooleanPreference("show_arrival_time", true).makeGlobal();
|
||||
|
||||
|
|
|
@ -419,7 +419,7 @@ public class MapActivityLayers {
|
|||
adapter.addItem(builder.createItem());
|
||||
}
|
||||
|
||||
public void selectMapLayer(final OsmandMapTileView mapView) {
|
||||
public void selectMapLayer(final OsmandMapTileView mapView, final ContextMenuItem it) {
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
|
||||
Toast.makeText(activity, R.string.map_online_plugin_is_not_installed, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
|
@ -477,6 +477,9 @@ public class MapActivityLayers {
|
|||
case layerOsmVector:
|
||||
settings.MAP_ONLINE_DATA.set(false);
|
||||
updateMapSource(mapView, null);
|
||||
if(it != null) {
|
||||
it.setDescription(null);
|
||||
}
|
||||
break;
|
||||
case layerEditInstall:
|
||||
OsmandRasterMapsPlugin.defineNewEditLayer(activity, new ResultMatcher<TileSourceTemplate>() {
|
||||
|
@ -485,6 +488,9 @@ public class MapActivityLayers {
|
|||
public boolean publish(TileSourceTemplate object) {
|
||||
settings.MAP_TILE_SOURCES.set(object.getName());
|
||||
settings.MAP_ONLINE_DATA.set(true);
|
||||
if(it != null) {
|
||||
it.setDescription(object.getName());
|
||||
}
|
||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||
return true;
|
||||
}
|
||||
|
@ -507,9 +513,12 @@ public class MapActivityLayers {
|
|||
if (count == 1) {
|
||||
settings.MAP_TILE_SOURCES.set(template.getName());
|
||||
settings.MAP_ONLINE_DATA.set(true);
|
||||
if(it != null) {
|
||||
it.setDescription(template.getName());
|
||||
}
|
||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||
} else {
|
||||
selectMapLayer(mapView);
|
||||
selectMapLayer(mapView, it);
|
||||
}
|
||||
} else {
|
||||
count++;
|
||||
|
@ -527,6 +536,9 @@ public class MapActivityLayers {
|
|||
default:
|
||||
settings.MAP_TILE_SOURCES.set(layerKey);
|
||||
settings.MAP_ONLINE_DATA.set(true);
|
||||
if(it != null) {
|
||||
it.setDescription(layerKey);
|
||||
}
|
||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||
import net.osmand.plus.OsmandSettings.ListStringPreference;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivityLayers;
|
||||
|
@ -136,7 +137,6 @@ public class ConfigureMapMenu {
|
|||
final ContextMenuItem item = cm.getItem(pos);
|
||||
if (item.getSelected() != null) {
|
||||
item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
if (itemId == R.string.layer_poi) {
|
||||
poiFiltersHelper.clearSelectedPoiFilters();
|
||||
|
@ -163,9 +163,11 @@ public class ConfigureMapMenu {
|
|||
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandRasterMapsPlugin.ID);
|
||||
ma.startActivity(intent);
|
||||
} else {
|
||||
ma.getMapLayers().selectMapLayer(ma.getMapView());
|
||||
ContextMenuItem it = adapter.getItem(pos);
|
||||
ma.getMapLayers().selectMapLayer(ma.getMapView(), it);
|
||||
}
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
ma.getMapLayers().updateLayers(ma.getMapView());
|
||||
ma.getMapView().refreshMap();
|
||||
return false;
|
||||
|
@ -238,7 +240,7 @@ public class ConfigureMapMenu {
|
|||
.setSecondaryIcon(R.drawable.ic_action_additional_option)
|
||||
.setListener(l).createItem());
|
||||
ContextMenuItem item = createProperties(customRules, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark,
|
||||
"transport", adapter, activity, false);
|
||||
"transport", settings.TRANSPORT_DEFAULT_SETTINGS, adapter, activity, false);
|
||||
if(item != null) {
|
||||
adapter.addItem(item);
|
||||
}
|
||||
|
@ -261,6 +263,7 @@ public class ConfigureMapMenu {
|
|||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
.setTitleId(R.string.layer_map, activity)
|
||||
.setIcon(R.drawable.ic_world_globe_dark)
|
||||
.setDescription(settings.MAP_ONLINE_DATA.get() ? settings.MAP_TILE_SOURCES.get() : null)
|
||||
.setListener(l).createItem());
|
||||
|
||||
OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
|
||||
|
@ -498,22 +501,22 @@ public class ConfigureMapMenu {
|
|||
|
||||
ContextMenuItem props;
|
||||
props = createProperties(customRules, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark,
|
||||
"transport", adapter, activity, true);
|
||||
"transport", null, adapter, activity, true);
|
||||
if(props != null) {
|
||||
adapter.addItem(props);
|
||||
}
|
||||
props = createProperties(customRules, R.string.rendering_category_details, R.drawable.ic_action_layers_dark,
|
||||
"details", adapter, activity, true);
|
||||
"details", null, adapter, activity, true);
|
||||
if(props != null) {
|
||||
adapter.addItem(props);
|
||||
}
|
||||
props = createProperties(customRules, R.string.rendering_category_hide, R.drawable.ic_action_hide, "hide",
|
||||
adapter, activity, true);
|
||||
props = createProperties(customRules, R.string.rendering_category_hide, R.drawable.ic_action_hide,
|
||||
"hide", null, adapter, activity, true);
|
||||
if(props != null) {
|
||||
adapter.addItem(props);
|
||||
}
|
||||
props = createProperties(customRules, R.string.rendering_category_routes, R.drawable.ic_action_map_routes,
|
||||
"routes", adapter, activity, true);
|
||||
"routes", null, adapter, activity, true);
|
||||
if(props != null) {
|
||||
adapter.addItem(props);
|
||||
}
|
||||
|
@ -570,7 +573,7 @@ public class ConfigureMapMenu {
|
|||
private ContextMenuItem createProperties(List<RenderingRuleProperty> customRules,
|
||||
@StringRes final int strId,
|
||||
@DrawableRes final int icon,
|
||||
String category,
|
||||
String category, final ListStringPreference defaultSettings,
|
||||
final ContextMenuAdapter adapter, final MapActivity activity, final boolean useDescription) {
|
||||
final List<RenderingRuleProperty> ps = new ArrayList<>();
|
||||
final List<OsmandSettings.CommonPreference<Boolean>> prefs = new ArrayList<>();
|
||||
|
@ -592,6 +595,14 @@ public class ConfigureMapMenu {
|
|||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a, int itemId, int pos,
|
||||
boolean isChecked) {
|
||||
if (!isChecked && !useDescription) {
|
||||
if (defaultSettings != null) {
|
||||
defaultSettings.set("");
|
||||
for (int i = 0; i < prefs.size(); i++) {
|
||||
if (prefs.get(i).get()) {
|
||||
defaultSettings.addValue(prefs.get(i).getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < prefs.size(); i++) {
|
||||
prefs.get(i).set(false);
|
||||
}
|
||||
|
@ -601,7 +612,7 @@ public class ConfigureMapMenu {
|
|||
activity.getMapLayers().updateLayers(activity.getMapView());
|
||||
} else {
|
||||
showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs,
|
||||
useDescription);
|
||||
useDescription, defaultSettings, true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -626,7 +637,7 @@ public class ConfigureMapMenu {
|
|||
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> a, View view, int itemId,
|
||||
int pos) {
|
||||
showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs,
|
||||
useDescription);
|
||||
useDescription, defaultSettings, false);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
@ -659,16 +670,14 @@ public class ConfigureMapMenu {
|
|||
}
|
||||
|
||||
protected void showPreferencesDialog(final ContextMenuAdapter adapter, final ArrayAdapter<?> a, final int pos, final MapActivity activity,
|
||||
String category, List<RenderingRuleProperty> ps, final List<CommonPreference<Boolean>> prefs, final boolean useDescription) {
|
||||
String category, List<RenderingRuleProperty> ps, final List<CommonPreference<Boolean>> prefs,
|
||||
final boolean useDescription, ListStringPreference defaultSettings, boolean useDefault) {
|
||||
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
|
||||
boolean[] checkedItems = new boolean[prefs.size()];
|
||||
for (int i = 0; i < prefs.size(); i++) {
|
||||
checkedItems[i] = prefs.get(i).get();
|
||||
}
|
||||
|
||||
final boolean[] tempPrefs = new boolean[prefs.size()];
|
||||
for (int i = 0; i < prefs.size(); i++) {
|
||||
tempPrefs[i] = prefs.get(i).get();
|
||||
tempPrefs[i] = checkedItems[i] = defaultSettings != null && useDefault ?
|
||||
defaultSettings.containsValue(prefs.get(i).getId()) : prefs.get(i).get();
|
||||
}
|
||||
final String[] vals = new String[ps.size()];
|
||||
for (int i = 0; i < ps.size(); i++) {
|
||||
|
@ -692,8 +701,7 @@ public class ConfigureMapMenu {
|
|||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
boolean selected = false;
|
||||
for (int i = 0; i < prefs.size(); i++) {
|
||||
prefs.get(i).set(tempPrefs[i]);
|
||||
selected |= tempPrefs[i];
|
||||
selected |= prefs.get(i).get();
|
||||
}
|
||||
adapter.getItem(pos).setSelected(selected);
|
||||
adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||
|
@ -713,8 +721,8 @@ public class ConfigureMapMenu {
|
|||
adapter.getItem(pos).setDescription(getDescription(prefs));
|
||||
} else{
|
||||
adapter.getItem(pos).setSelected(selected);
|
||||
adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||
}
|
||||
adapter.getItem(pos).setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
|
||||
}
|
||||
a.notifyDataSetInvalidated();
|
||||
refreshMapComplete(activity);
|
||||
|
|
|
@ -122,9 +122,9 @@ public class DiscountHelper {
|
|||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((start == null) ? 0 : start.hashCode());
|
||||
result = prime * result + ((end == null) ? 0 : end.hashCode());
|
||||
// result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
// result = prime * result + ((end == null) ? 0 : end.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.view.WindowManager;
|
|||
|
||||
public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
|
||||
private static final int startZoom = 12;
|
||||
private static final int startZoomRoute = 10;
|
||||
|
||||
private OsmandMapTileView view;
|
||||
|
||||
|
@ -105,34 +106,32 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
};
|
||||
}
|
||||
|
||||
public void getFromPoint(RotatedTileBox tb,PointF point, List<? super TransportStop> res) {
|
||||
if (data.getResults() != null) {
|
||||
List<TransportStop> objects = route != null ? route.getForwardStops() : data.getResults();
|
||||
int ex = (int) point.x;
|
||||
int ey = (int) point.y;
|
||||
final int rp = getRadiusPoi(tb);
|
||||
int radius = rp * 3 / 2;
|
||||
try {
|
||||
TreeSet<String> ms = new TreeSet<>();
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
TransportStop n = objects.get(i);
|
||||
if (n.getLocation() == null){
|
||||
public void getFromPoint(RotatedTileBox tb, PointF point, List<? super TransportStop> res,
|
||||
List<TransportStop> objects) {
|
||||
int ex = (int) point.x;
|
||||
int ey = (int) point.y;
|
||||
final int rp = getRadiusPoi(tb);
|
||||
int radius = rp * 3 / 2;
|
||||
try {
|
||||
TreeSet<String> ms = new TreeSet<>();
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
TransportStop n = objects.get(i);
|
||||
if (n.getLocation() == null) {
|
||||
continue;
|
||||
}
|
||||
int x = (int) tb.getPixXFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
|
||||
int y = (int) tb.getPixYFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
|
||||
if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) {
|
||||
if (!ms.add(n.getName())) {
|
||||
// only unique names
|
||||
continue;
|
||||
}
|
||||
int x = (int) tb.getPixXFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
|
||||
int y = (int) tb.getPixYFromLatLon(n.getLocation().getLatitude(), n.getLocation().getLongitude());
|
||||
if (Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius) {
|
||||
if(!ms.add(n.getName())) {
|
||||
// only unique names
|
||||
continue;
|
||||
}
|
||||
radius = rp;
|
||||
res.add(n);
|
||||
}
|
||||
radius = rp;
|
||||
res.add(n);
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// that's really rare case, but is much efficient than introduce synchronized block
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// that's really rare case, but is much efficient than introduce synchronized block
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +148,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
public int getRadiusPoi(RotatedTileBox tb){
|
||||
final double zoom = tb.getZoom();
|
||||
int r;
|
||||
if(zoom < startZoom){
|
||||
if(zoom < startZoomRoute){
|
||||
r = 0;
|
||||
} else if(zoom <= 15){
|
||||
r = 8;
|
||||
|
@ -162,14 +161,14 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
}
|
||||
return (int) (r * tb.getDensity());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb,
|
||||
DrawSettings settings) {
|
||||
if (tb.getZoom() >= startZoom) {
|
||||
data.queryNewData(tb);
|
||||
if(route != null) {
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tb,DrawSettings settings) {
|
||||
List<TransportStop> objects = null;
|
||||
if (tb.getZoom() >= startZoomRoute) {
|
||||
if (route != null) {
|
||||
objects = route.getForwardStops();
|
||||
attrs.updatePaints(view, settings, tb);
|
||||
try {
|
||||
path.reset();
|
||||
|
@ -193,35 +192,33 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (tb.getZoom() >= startZoom && objects == null) {
|
||||
data.queryNewData(tb);
|
||||
objects = data.getResults();
|
||||
}
|
||||
if (objects != null) {
|
||||
float iconSize = stopBus.getWidth() * 3 / 2.5f;
|
||||
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tb);
|
||||
List<TransportStop> fullObjects = new ArrayList<>();
|
||||
List<TransportStop> objects = data.getResults() ;
|
||||
if(route != null) {
|
||||
objects = route.getForwardStops();
|
||||
}
|
||||
if (objects != null) {
|
||||
for (TransportStop o : objects) {
|
||||
float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
|
||||
float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
|
||||
for (TransportStop o : objects) {
|
||||
float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
|
||||
float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
|
||||
|
||||
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
|
||||
canvas.drawBitmap(stopSmall, x - stopSmall.getWidth() / 2, y - stopSmall.getHeight() / 2,
|
||||
paintIcon);
|
||||
} else {
|
||||
fullObjects.add(o);
|
||||
}
|
||||
}
|
||||
for (TransportStop o : fullObjects) {
|
||||
float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
|
||||
float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
|
||||
Bitmap b = stopBus;
|
||||
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
|
||||
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
|
||||
canvas.drawBitmap(stopSmall, x - stopSmall.getWidth() / 2, y - stopSmall.getHeight() / 2, paintIcon);
|
||||
} else {
|
||||
fullObjects.add(o);
|
||||
}
|
||||
}
|
||||
|
||||
for (TransportStop o : fullObjects) {
|
||||
float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
|
||||
float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
|
||||
Bitmap b = stopBus;
|
||||
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -268,9 +265,11 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
|
|||
|
||||
@Override
|
||||
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
|
||||
if (tileBox.getZoom() >= startZoom) {
|
||||
getFromPoint(tileBox, point, res);
|
||||
}
|
||||
if(tileBox.getZoom() >= startZoomRoute && route != null) {
|
||||
getFromPoint(tileBox, point, res, route.getForwardStops());
|
||||
} else if (tileBox.getZoom() >= startZoom && data.getResults() != null) {
|
||||
getFromPoint(tileBox, point, res, data.getResults());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue