Simplify layer structure make poi/favorites layers all the time present
This commit is contained in:
parent
9da74014a4
commit
9a036239c7
10 changed files with 75 additions and 89 deletions
|
@ -747,9 +747,6 @@ public class OsmandSettings {
|
|||
|
||||
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final OsmandPreference<Boolean> SHOW_POI_OVER_MAP = new BooleanPreference("show_poi_over_map", false).makeGlobal();
|
||||
|
||||
public final OsmandPreference<Boolean> SHOW_POI_LABEL = new BooleanPreference("show_poi_label", false).makeGlobal();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
|
@ -925,7 +922,7 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<Boolean> DEBUG_RENDERING_INFO = new BooleanPreference("debug_rendering", false).makeGlobal();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final OsmandPreference<Boolean> SHOW_FAVORITES = new BooleanPreference("show_favorites", false).makeGlobal();
|
||||
public final OsmandPreference<Boolean> SHOW_FAVORITES = new BooleanPreference("show_favorites", false).makeGlobal().cache();
|
||||
|
||||
public final CommonPreference<Boolean> SHOW_ZOOM_BUTTONS_NAVIGATION = new BooleanPreference("show_zoom_buttons_navigation", false).makeProfile().cache();
|
||||
{
|
||||
|
@ -1672,15 +1669,8 @@ public class OsmandSettings {
|
|||
return settingsAPI.edit(globalPreferences).putString(LAST_SEARCHED_INTERSECTED_STREET, street).commit();
|
||||
}
|
||||
|
||||
public static final String SELECTED_POI_FILTER_FOR_MAP = "selected_poi_filter_for_map"; //$NON-NLS-1$
|
||||
|
||||
public boolean setPoiFilterForMap(String filterId) {
|
||||
return settingsAPI.edit(globalPreferences).putString(SELECTED_POI_FILTER_FOR_MAP, filterId).commit();
|
||||
}
|
||||
|
||||
public String getPoiFilterForMap(){
|
||||
return settingsAPI.getString(globalPreferences,SELECTED_POI_FILTER_FOR_MAP, null);
|
||||
}
|
||||
public final OsmandPreference<String> SELECTED_POI_FILTER_FOR_MAP = new StringPreference("selected_poi_filter_for_map", null).makeGlobal().cache();
|
||||
|
||||
public static final String VOICE_PROVIDER_NOT_USE = "VOICE_PROVIDER_NOT_USE";
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
|
|
|
@ -369,9 +369,6 @@ public class MapActivity extends AccessibleActivity {
|
|||
settings.APPLICATION_MODE.addListener(applicationModeListener);
|
||||
updateApplicationModeSettings();
|
||||
|
||||
String filterId = settings.getPoiFilterForMap();
|
||||
PoiLegacyFilter poiFilter = app.getPoiFilters().getFilterById(filterId);
|
||||
mapLayers.getPoiMapLayer().setFilter(poiFilter);
|
||||
|
||||
// if destination point was changed try to recalculate route
|
||||
TargetPointsHelper targets = app.getTargetPointsHelper();
|
||||
|
|
|
@ -124,8 +124,10 @@ public class MapActivityLayers {
|
|||
// 2. osm bugs layer
|
||||
// 3. poi layer
|
||||
poiMapLayer = new POIMapLayer(activity);
|
||||
mapView.addLayer(poiMapLayer, 3);
|
||||
// 4. favorites layer
|
||||
favoritesLayer = new FavoritesLayer();
|
||||
mapView.addLayer(favoritesLayer, 4);
|
||||
// 5. transport layer
|
||||
transportStopsLayer = new TransportStopsLayer();
|
||||
// 5.5 transport info layer
|
||||
|
@ -173,22 +175,6 @@ public class MapActivityLayers {
|
|||
mapView.removeLayer(transportStopsLayer);
|
||||
}
|
||||
}
|
||||
|
||||
if(mapView.getLayers().contains(poiMapLayer) != settings.SHOW_POI_OVER_MAP.get()){
|
||||
if(settings.SHOW_POI_OVER_MAP.get()){
|
||||
mapView.addLayer(poiMapLayer, 3);
|
||||
} else {
|
||||
mapView.removeLayer(poiMapLayer);
|
||||
}
|
||||
}
|
||||
|
||||
if(mapView.getLayers().contains(favoritesLayer) != settings.SHOW_FAVORITES.get()){
|
||||
if(settings.SHOW_FAVORITES.get()){
|
||||
mapView.addLayer(favoritesLayer, 4);
|
||||
} else {
|
||||
mapView.removeLayer(favoritesLayer);
|
||||
}
|
||||
}
|
||||
OsmandPlugin.refreshLayers(mapView, activity);
|
||||
}
|
||||
|
||||
|
@ -283,12 +269,11 @@ public class MapActivityLayers {
|
|||
activity.getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.POI_TAB_INDEX);
|
||||
activity.startActivity(search);
|
||||
} else {
|
||||
getApplication().getSettings().setPoiFilterForMap(filterId);
|
||||
pf = poiFilters.getFilterById(filterId);
|
||||
if (pf != null) {
|
||||
pf.setFilterByName(pf.getSavedFilterByName());
|
||||
}
|
||||
poiMapLayer.setFilter(pf);
|
||||
getApplication().getSettings().SELECTED_POI_FILTER_FOR_MAP.set(filterId);
|
||||
mapView.refreshMap();
|
||||
if(selected != null && selected.length > 0) {
|
||||
selected[0] = pf;
|
||||
|
|
|
@ -162,8 +162,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
|||
public boolean onMenuItemClick(MenuItem item) {
|
||||
OsmandSettings settings = app.getSettings();
|
||||
filter.setFilterByName(searchFilter.getText().toString().trim());
|
||||
settings.setPoiFilterForMap(filter.getFilterId());
|
||||
settings.SHOW_POI_OVER_MAP.set(true);
|
||||
settings.SELECTED_POI_FILTER_FOR_MAP.set(filter.getFilterId());
|
||||
if (location != null) {
|
||||
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15);
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class ConfigureMapMenu {
|
|||
|
||||
@Override
|
||||
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
|
||||
if(itemId == R.string.layer_poi && cm.getSelection(pos) == 1) {
|
||||
if(itemId == R.string.layer_poi) {
|
||||
selectPOILayer(ma.getMyApplication().getSettings());
|
||||
return false;
|
||||
} else if(itemId == R.string.layer_gpx_layer && cm.getSelection(pos) == 1) {
|
||||
|
@ -107,13 +107,10 @@ public class ConfigureMapMenu {
|
|||
public boolean onContextMenuClick(final ArrayAdapter<?> adapter, int itemId, final int pos, boolean isChecked) {
|
||||
final OsmandSettings settings = ma.getMyApplication().getSettings();
|
||||
if (itemId == R.string.layer_poi) {
|
||||
settings.setPoiFilterForMap(null);
|
||||
ma.getMapLayers().getPoiMapLayer().setFilter(null);
|
||||
settings.SHOW_POI_OVER_MAP.set(isChecked);
|
||||
settings.SELECTED_POI_FILTER_FOR_MAP.set(null);
|
||||
if (isChecked) {
|
||||
selectPOILayer(settings);
|
||||
}
|
||||
|
||||
} else if (itemId == R.string.layer_amenity_label) {
|
||||
settings.SHOW_POI_LABEL.set(isChecked);
|
||||
} else if (itemId == R.string.shared_string_favorites) {
|
||||
|
@ -140,15 +137,12 @@ public class ConfigureMapMenu {
|
|||
}
|
||||
|
||||
protected void selectPOILayer(final OsmandSettings settings) {
|
||||
final PoiLegacyFilter[] selected = new PoiLegacyFilter[1];
|
||||
final PoiLegacyFilter[] selected = new PoiLegacyFilter[1];
|
||||
AlertDialog dlg = ma.getMapLayers().selectPOIFilterLayer(ma.getMapView(), selected);
|
||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if(selected[0] == null) {
|
||||
settings.SHOW_POI_OVER_MAP.set(selected[0] != null);
|
||||
}
|
||||
ma.getDashboard().refreshContent(true);
|
||||
}
|
||||
});
|
||||
|
@ -161,7 +155,7 @@ public class ConfigureMapMenu {
|
|||
LayerMenuListener l = new LayerMenuListener(activity, adapter);
|
||||
adapter.item(R.string.shared_string_show).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
|
||||
// String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
|
||||
adapter.item(R.string.layer_poi).selected(settings.SHOW_POI_OVER_MAP.get() ? 1 : 0)
|
||||
adapter.item(R.string.layer_poi).selected(settings.SELECTED_POI_FILTER_FOR_MAP.get() != null ? 1 : 0)
|
||||
.iconColor(R.drawable.ic_action_info_dark).listen(l).reg();
|
||||
adapter.item(R.string.layer_amenity_label).selected(settings.SHOW_POI_LABEL.get() ? 1 : 0)
|
||||
.iconColor(R.drawable.ic_action_text_dark).listen(l).reg();
|
||||
|
|
|
@ -238,7 +238,7 @@ public class WaypointDialogHelper {
|
|||
private void selectPoi(final int[] running, final ArrayAdapter<Object> listAdapter, final int type,
|
||||
final boolean enable, Activity ctx) {
|
||||
if (ctx instanceof MapActivity &&
|
||||
!PoiLegacyFilter.CUSTOM_FILTER_ID.equals(app.getSettings().getPoiFilterForMap())) {
|
||||
!PoiLegacyFilter.CUSTOM_FILTER_ID.equals(app.getSettings().SELECTED_POI_FILTER_FOR_MAP.get())) {
|
||||
MapActivity map = (MapActivity) ctx;
|
||||
final PoiLegacyFilter[] selected = new PoiLegacyFilter[1];
|
||||
AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView(), selected);
|
||||
|
|
|
@ -592,7 +592,7 @@ public class WaypointHelper {
|
|||
|
||||
///
|
||||
public PoiLegacyFilter getPoiFilter() {
|
||||
return app.getPoiFilters().getFilterById(app.getSettings().getPoiFilterForMap());
|
||||
return app.getPoiFilters().getFilterById(app.getSettings().SELECTED_POI_FILTER_FOR_MAP.get());
|
||||
}
|
||||
public boolean showPOI() {
|
||||
return app.getSettings().SHOW_NEARBY_POI.get();
|
||||
|
|
|
@ -531,14 +531,14 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
|
|||
R.string.menu_mute_on, R.string.menu_mute_off,
|
||||
R.string.where_am_i, R.string.context_menu_item_share_location);
|
||||
//poi
|
||||
if (osmandSettings.SHOW_POI_OVER_MAP.get()) {
|
||||
if (osmandSettings.SELECTED_POI_FILTER_FOR_MAP.get()!= null) {
|
||||
adapter.item(R.string.sherpafy_disable_poi).iconColor(
|
||||
R.drawable.ic_action_gremove_dark)
|
||||
.listen(new OnContextMenuClick() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
app.getSettings().SHOW_POI_OVER_MAP.set(false);
|
||||
mapActivity.getMapLayers().updateLayers(mapActivity.getMapView());
|
||||
app.getSettings().SELECTED_POI_FILTER_FOR_MAP.set(null);
|
||||
mapActivity.refreshMap();
|
||||
return true;
|
||||
}
|
||||
}).reg();
|
||||
|
@ -548,8 +548,6 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
|
|||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||
mapActivity.getMapLayers().selectPOIFilterLayer(mapActivity.getMapView(), null);
|
||||
app.getSettings().SHOW_POI_OVER_MAP.set(true);
|
||||
mapActivity.getMapLayers().updateLayers(mapActivity.getMapView());
|
||||
return true;
|
||||
}
|
||||
}).reg();
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.plus.ContextMenuAdapter;
|
|||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.FavoritesTreeFragment;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
|
@ -39,6 +40,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
private FavouritesDbHelper favorites;
|
||||
protected List<LocationPoint> cache = new ArrayList<LocationPoint>();
|
||||
private MapTextLayer textLayer;
|
||||
|
||||
private OsmandSettings settings;
|
||||
// private Bitmap d;
|
||||
|
||||
|
||||
|
@ -61,7 +64,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
paint.setAntiAlias(true);
|
||||
paint.setFilterBitmap(true);
|
||||
paint.setDither(true);
|
||||
|
||||
settings = view.getApplication().getSettings();
|
||||
favorites = view.getApplication().getFavorites();
|
||||
textLayer = view.getLayerByClass(MapTextLayer.class);
|
||||
// favoriteIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.poi_favourite);
|
||||
|
@ -93,17 +96,20 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
cache.clear();
|
||||
if (tileBox.getZoom() >= startZoom) {
|
||||
// request to load
|
||||
final QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||
for (LocationPoint o : getPoints()) {
|
||||
drawPoint(canvas, tileBox, latLonBounds, o);
|
||||
if (this.settings.SHOW_FAVORITES.get()) {
|
||||
if (tileBox.getZoom() >= startZoom) {
|
||||
// request to load
|
||||
final QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||
for (LocationPoint o : getPoints()) {
|
||||
drawPoint(canvas, tileBox, latLonBounds, o);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if(textLayer.isVisible()) {
|
||||
textLayer.putData(this, cache);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -17,14 +17,18 @@ import net.osmand.osm.PoiType;
|
|||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.poi.PoiLegacyFilter;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
|
||||
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Intent;
|
||||
|
@ -59,10 +63,16 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
|||
// Work with cache (for map copied from AmenityIndexRepositoryOdb)
|
||||
private MapLayerData<List<Amenity>> data;
|
||||
|
||||
private OsmandSettings settings;
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
|
||||
public POIMapLayer(final MapActivity activity) {
|
||||
routingHelper = activity.getRoutingHelper();
|
||||
routingHelper.addListener(this);
|
||||
settings = activity.getMyApplication().getSettings();
|
||||
app = activity.getMyApplication();
|
||||
data = new OsmandMapLayer.MapLayerData<List<Amenity>>() {
|
||||
{
|
||||
ZOOM_THRESHOLD = 0;
|
||||
|
@ -101,10 +111,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
|||
};
|
||||
}
|
||||
|
||||
public void setFilter(PoiLegacyFilter filter) {
|
||||
this.filter = filter;
|
||||
data.clearCache();
|
||||
}
|
||||
|
||||
public void getAmenityFromPoint(RotatedTileBox tb, PointF point, List<? super Amenity> am) {
|
||||
List<Amenity> objects = data.getResults();
|
||||
|
@ -193,39 +199,50 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
|||
|
||||
@Override
|
||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
if(!Algorithms.objectEquals(this.settings.SELECTED_POI_FILTER_FOR_MAP.get(),
|
||||
filter == null ? null : filter.getFilterId())) {
|
||||
if(this.settings.SELECTED_POI_FILTER_FOR_MAP.get() == null) {
|
||||
this.filter = null;
|
||||
} else {
|
||||
PoiFiltersHelper pfh = app.getPoiFilters();
|
||||
this.filter = pfh.getFilterById(this.settings.SELECTED_POI_FILTER_FOR_MAP.get());
|
||||
}
|
||||
data.clearCache();
|
||||
}
|
||||
List<Amenity> objects = Collections.emptyList();
|
||||
if (tileBox.getZoom() >= startZoom) {
|
||||
data.queryNewData(tileBox);
|
||||
objects = data.getResults();
|
||||
if (objects != null) {
|
||||
int r = getRadiusPoi(tileBox);
|
||||
for (Amenity o : objects) {
|
||||
int x = (int) tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation()
|
||||
.getLongitude());
|
||||
int y = (int) tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation()
|
||||
.getLongitude());
|
||||
canvas.drawCircle(x, y, r, pointAltUI);
|
||||
canvas.drawCircle(x, y, r, point);
|
||||
String id = null;
|
||||
PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
|
||||
if (st != null) {
|
||||
if (RenderingIcons.containsIcon(st.getIconKeyName())) {
|
||||
id = st.getIconKeyName();
|
||||
} else if (RenderingIcons.containsIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
|
||||
id = st.getOsmTag() + "_" + st.getOsmValue();
|
||||
if (filter != null) {
|
||||
if (tileBox.getZoom() >= startZoom) {
|
||||
data.queryNewData(tileBox);
|
||||
objects = data.getResults();
|
||||
if (objects != null) {
|
||||
int r = getRadiusPoi(tileBox);
|
||||
for (Amenity o : objects) {
|
||||
int x = (int) tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation()
|
||||
.getLongitude());
|
||||
int y = (int) tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation()
|
||||
.getLongitude());
|
||||
canvas.drawCircle(x, y, r, pointAltUI);
|
||||
canvas.drawCircle(x, y, r, point);
|
||||
String id = null;
|
||||
PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
|
||||
if (st != null) {
|
||||
if (RenderingIcons.containsIcon(st.getIconKeyName())) {
|
||||
id = st.getIconKeyName();
|
||||
} else if (RenderingIcons.containsIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
|
||||
id = st.getOsmTag() + "_" + st.getOsmValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (id != null) {
|
||||
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id);
|
||||
if (bmp != null) {
|
||||
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon);
|
||||
if (id != null) {
|
||||
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id);
|
||||
if (bmp != null) {
|
||||
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mapTextLayer.putData(this, objects);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue