Single choice/multi choice dialog implemented.
This commit is contained in:
parent
7cbdaa6161
commit
642975818f
3 changed files with 146 additions and 85 deletions
|
@ -2,6 +2,7 @@ package net.osmand.plus.activities;
|
|||
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
|
@ -24,6 +25,7 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SQLiteTileSource;
|
||||
import net.osmand.plus.activities.search.SearchActivity;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
|
@ -100,7 +102,7 @@ public class MapActivityLayers {
|
|||
|
||||
public void createLayers(final OsmandMapTileView mapView) {
|
||||
|
||||
OsmandApplication app = (OsmandApplication) getApplication();
|
||||
OsmandApplication app = getApplication();
|
||||
RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
// first create to make accessible
|
||||
mapTextLayer = new MapTextLayer();
|
||||
|
@ -234,8 +236,7 @@ public class MapActivityLayers {
|
|||
g.path = getString(R.string.show_current_gpx_title);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!g.showCurrentTrack || locToShow == null) {
|
||||
} else {
|
||||
locToShow = g.findPointToShow();
|
||||
}
|
||||
}
|
||||
|
@ -258,22 +259,21 @@ public class MapActivityLayers {
|
|||
}
|
||||
|
||||
|
||||
public void showPoiFilterDialog(final OsmandMapTileView mapView, final ConfirmListener listener) {
|
||||
public void showMultichoicePoiFilterDialog(final OsmandMapTileView mapView, final ConfirmListener listener) {
|
||||
OsmandApplication app = getApplication();
|
||||
final PoiFiltersHelper poiFilters = app.getPoiFilters();
|
||||
final ContextMenuAdapter adapter = new ContextMenuAdapter();
|
||||
final List<PoiUIFilter> list = new ArrayList<>();
|
||||
list.add(poiFilters.getCustomPOIFilter());
|
||||
for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
|
||||
addFilterToList(adapter, list, f);
|
||||
addFilterToList(adapter, list, f, true);
|
||||
}
|
||||
for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) {
|
||||
addFilterToList(adapter, list, f);
|
||||
addFilterToList(adapter, list, f, true);
|
||||
}
|
||||
|
||||
final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(activity, app.getSettings().isLightContent());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(activity,
|
||||
app.getSettings().isLightContent());
|
||||
final ListView listView = new ListView(activity);
|
||||
listView.setDivider(null);
|
||||
listView.setClickable(true);
|
||||
|
@ -287,8 +287,8 @@ public class MapActivityLayers {
|
|||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
builder.setView(listView);
|
||||
builder.setTitle(R.string.show_poi_over_map)
|
||||
builder.setView(listView)
|
||||
.setTitle(R.string.show_poi_over_map)
|
||||
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
@ -298,26 +298,82 @@ public class MapActivityLayers {
|
|||
})
|
||||
.setNegativeButton(R.string.shared_string_cancel, null)
|
||||
// TODO go to single choice dialog
|
||||
.setNeutralButton("", null);
|
||||
.setNeutralButton("Single choice", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
showSingleChoicePoiFilterDialog(mapView, listener);
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void addFilterToList(final ContextMenuAdapter adapter, final List<PoiUIFilter> list, final PoiUIFilter f) {
|
||||
list.add(f);
|
||||
ContextMenuItem.ItemBuilder builder = new ContextMenuItem.ItemBuilder();
|
||||
builder.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||
public void showSingleChoicePoiFilterDialog(final OsmandMapTileView mapView, final ConfirmListener listener) {
|
||||
OsmandApplication app = getApplication();
|
||||
final PoiFiltersHelper poiFilters = app.getPoiFilters();
|
||||
final ContextMenuAdapter adapter = new ContextMenuAdapter();
|
||||
final List<PoiUIFilter> list = new ArrayList<>();
|
||||
list.add(poiFilters.getCustomPOIFilter());
|
||||
for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
|
||||
addFilterToList(adapter, list, f, false);
|
||||
}
|
||||
for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) {
|
||||
addFilterToList(adapter, list, f, false);
|
||||
}
|
||||
|
||||
final ArrayAdapter<ContextMenuItem> listAdapter =
|
||||
adapter.createListAdapter(activity, app.getSettings().isLightContent());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
getApplication().getPoiFilters().addSelectedPoiFilter(f);
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
PoiUIFilter pf = list.get(which + 1);
|
||||
String filterId = pf.getFilterId();
|
||||
if (filterId.equals(PoiUIFilter.CUSTOM_FILTER_ID)) {
|
||||
Intent search = new Intent(activity, SearchActivity.class);
|
||||
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
activity.getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.POI_TAB_INDEX);
|
||||
activity.startActivity(search);
|
||||
} else {
|
||||
getApplication().getPoiFilters().removeSelectedPoiFilter(f);
|
||||
getApplication().getPoiFilters().clearSelectedPoiFilters();
|
||||
getApplication().getPoiFilters().addSelectedPoiFilter(pf);
|
||||
mapView.refreshMap();
|
||||
listener.confirm();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
builder.setTitle(R.string.show_poi_over_map);
|
||||
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
builder.setNeutralButton("Multichoice", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
showMultichoicePoiFilterDialog(mapView, listener);
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void addFilterToList(final ContextMenuAdapter adapter,
|
||||
final List<PoiUIFilter> list,
|
||||
final PoiUIFilter f,
|
||||
boolean multichoice) {
|
||||
list.add(f);
|
||||
ContextMenuItem.ItemBuilder builder = new ContextMenuItem.ItemBuilder();
|
||||
if (multichoice) {
|
||||
builder.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
getApplication().getPoiFilters().addSelectedPoiFilter(f);
|
||||
} else {
|
||||
getApplication().getPoiFilters().removeSelectedPoiFilter(f);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
builder.setSelected(getApplication().getPoiFilters().isPoiFilterSelected(f));
|
||||
}
|
||||
builder.setTitle(f.getName());
|
||||
builder.setSelected(getApplication().getPoiFilters().isPoiFilterSelected(f));
|
||||
if (RenderingIcons.containsBigIcon(f.getIconId())) {
|
||||
builder.setIcon(RenderingIcons.getBigIconResourceId(f.getIconId()));
|
||||
} else {
|
||||
|
@ -335,7 +391,7 @@ public class MapActivityLayers {
|
|||
}
|
||||
final OsmandSettings settings = getApplication().getSettings();
|
||||
|
||||
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<String, String>();
|
||||
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>();
|
||||
|
||||
|
||||
final String layerOsmVector = "LAYER_OSM_VECTOR";
|
||||
|
@ -347,7 +403,7 @@ public class MapActivityLayers {
|
|||
entriesMap.put(layerInstallMore, getString(R.string.install_more));
|
||||
entriesMap.put(layerEditInstall, getString(R.string.maps_define_edit));
|
||||
|
||||
final List<Entry<String, String>> entriesMapList = new ArrayList<Entry<String, String>>(entriesMap.entrySet());
|
||||
final List<Entry<String, String>> entriesMapList = new ArrayList<>(entriesMap.entrySet());
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
|
||||
|
@ -382,57 +438,62 @@ public class MapActivityLayers {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String layerKey = entriesMapList.get(which).getKey();
|
||||
if (layerKey.equals(layerOsmVector)) {
|
||||
settings.MAP_ONLINE_DATA.set(false);
|
||||
updateMapSource(mapView, null);
|
||||
} else if (layerKey.equals(layerEditInstall)) {
|
||||
OsmandRasterMapsPlugin.defineNewEditLayer(activity, new ResultMatcher<TileSourceTemplate>() {
|
||||
switch (layerKey) {
|
||||
case layerOsmVector:
|
||||
settings.MAP_ONLINE_DATA.set(false);
|
||||
updateMapSource(mapView, null);
|
||||
break;
|
||||
case layerEditInstall:
|
||||
OsmandRasterMapsPlugin.defineNewEditLayer(activity, new ResultMatcher<TileSourceTemplate>() {
|
||||
|
||||
@Override
|
||||
public boolean publish(TileSourceTemplate object) {
|
||||
settings.MAP_TILE_SOURCES.set(object.getName());
|
||||
settings.MAP_ONLINE_DATA.set(true);
|
||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
} else if (layerKey.equals(layerInstallMore)) {
|
||||
OsmandRasterMapsPlugin.installMapLayers(activity, new ResultMatcher<TileSourceTemplate>() {
|
||||
TileSourceTemplate template = null;
|
||||
int count = 0;
|
||||
|
||||
@Override
|
||||
public boolean publish(TileSourceTemplate object) {
|
||||
if (object == null) {
|
||||
if (count == 1) {
|
||||
settings.MAP_TILE_SOURCES.set(template.getName());
|
||||
settings.MAP_ONLINE_DATA.set(true);
|
||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||
} else {
|
||||
selectMapLayer(mapView);
|
||||
}
|
||||
} else {
|
||||
count++;
|
||||
template = object;
|
||||
@Override
|
||||
public boolean publish(TileSourceTemplate object) {
|
||||
settings.MAP_TILE_SOURCES.set(object.getName());
|
||||
settings.MAP_ONLINE_DATA.set(true);
|
||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
settings.MAP_TILE_SOURCES.set(layerKey);
|
||||
settings.MAP_ONLINE_DATA.set(true);
|
||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
break;
|
||||
case layerInstallMore:
|
||||
OsmandRasterMapsPlugin.installMapLayers(activity, new ResultMatcher<TileSourceTemplate>() {
|
||||
TileSourceTemplate template = null;
|
||||
int count = 0;
|
||||
|
||||
@Override
|
||||
public boolean publish(TileSourceTemplate object) {
|
||||
if (object == null) {
|
||||
if (count == 1) {
|
||||
settings.MAP_TILE_SOURCES.set(template.getName());
|
||||
settings.MAP_ONLINE_DATA.set(true);
|
||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||
} else {
|
||||
selectMapLayer(mapView);
|
||||
}
|
||||
} else {
|
||||
count++;
|
||||
template = object;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
settings.MAP_TILE_SOURCES.set(layerKey);
|
||||
settings.MAP_ONLINE_DATA.set(true);
|
||||
updateMapSource(mapView, settings.MAP_TILE_SOURCES);
|
||||
break;
|
||||
}
|
||||
|
||||
dialog.dismiss();
|
||||
|
|
|
@ -103,7 +103,7 @@ public class ConfigureMapMenu {
|
|||
@Override
|
||||
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
|
||||
if (itemId == R.string.layer_poi) {
|
||||
selectPOILayer(adapter, adapter.getItem(pos));
|
||||
showPoiFilterDialog(adapter, adapter.getItem(pos));
|
||||
return false;
|
||||
} else if (itemId == R.string.layer_gpx_layer && cm.getItem(pos).getSelected()) {
|
||||
showGpxSelectionDialog(adapter, adapter.getItem(pos));
|
||||
|
@ -134,7 +134,7 @@ public class ConfigureMapMenu {
|
|||
if (itemId == R.string.layer_poi) {
|
||||
pfh.clearSelectedPoiFilters();
|
||||
if (isChecked) {
|
||||
selectPOILayer(adapter, adapter.getItem(pos));
|
||||
showPoiFilterDialog(adapter, adapter.getItem(pos));
|
||||
} else {
|
||||
adapter.getItem(pos).setDescription(pfh.getSelectedPoiFiltersName());
|
||||
}
|
||||
|
@ -183,9 +183,9 @@ public class ConfigureMapMenu {
|
|||
});
|
||||
}
|
||||
|
||||
protected void selectPOILayer(final ArrayAdapter<ContextMenuItem> adapter,
|
||||
final ContextMenuItem item) {
|
||||
ma.getMapLayers().showPoiFilterDialog(ma.getMapView(),
|
||||
protected void showPoiFilterDialog(final ArrayAdapter<ContextMenuItem> adapter,
|
||||
final ContextMenuItem item) {
|
||||
ma.getMapLayers().showSingleChoicePoiFilterDialog(ma.getMapView(),
|
||||
new MapActivityLayers.ConfirmListener() {
|
||||
@Override
|
||||
public void confirm() {
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.graphics.drawable.ShapeDrawable;
|
|||
import android.graphics.drawable.shapes.Shape;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -224,11 +225,11 @@ public class WaypointDialogHelper {
|
|||
int color;
|
||||
int pointColor;
|
||||
if (nightMode) {
|
||||
color = ctx.getResources().getColor(R.color.dashboard_divider_dark);
|
||||
pointColor = ctx.getResources().getColor(R.color.dashboard_divider_dark);
|
||||
color = ContextCompat.getColor(ctx, R.color.dashboard_divider_dark);
|
||||
pointColor = ContextCompat.getColor(ctx, R.color.dashboard_divider_dark);
|
||||
} else {
|
||||
color = ctx.getResources().getColor(R.color.dashboard_divider_light);
|
||||
pointColor = ctx.getResources().getColor(R.color.ctx_menu_info_divider_light);
|
||||
color = ContextCompat.getColor(ctx, R.color.dashboard_divider_light);
|
||||
pointColor = ContextCompat.getColor(ctx, R.color.ctx_menu_info_divider_light);
|
||||
}
|
||||
|
||||
Shape fullDividerShape = new ListDividerShape(color, 0);
|
||||
|
@ -616,7 +617,7 @@ public class WaypointDialogHelper {
|
|||
running[0] = position;
|
||||
thisAdapter.notifyDataSetInvalidated();
|
||||
MapActivity map = (MapActivity) ctx;
|
||||
map.getMapLayers().showPoiFilterDialog(map.getMapView(),
|
||||
map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(),
|
||||
new MapActivityLayers.ConfirmListener() {
|
||||
@Override
|
||||
public void confirm() {
|
||||
|
@ -690,7 +691,7 @@ public class WaypointDialogHelper {
|
|||
if (ctx instanceof MapActivity &&
|
||||
!app.getPoiFilters().isPoiFilterSelected(PoiUIFilter.CUSTOM_FILTER_ID)) {
|
||||
MapActivity map = (MapActivity) ctx;
|
||||
map.getMapLayers().showPoiFilterDialog(map.getMapView(),
|
||||
map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(),
|
||||
new MapActivityLayers.ConfirmListener() {
|
||||
@Override
|
||||
public void confirm() {
|
||||
|
@ -834,9 +835,8 @@ public class WaypointDialogHelper {
|
|||
boolean rc = waypointHelper.isRouteCalculated();
|
||||
for (int i = 0; i < WaypointHelper.MAX; i++) {
|
||||
List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i);
|
||||
if (!rc && i != WaypointHelper.WAYPOINTS && i != WaypointHelper.TARGETS) {
|
||||
// skip
|
||||
} else if (waypointHelper.isTypeVisible(i)) {
|
||||
if ((rc || i == WaypointHelper.WAYPOINTS || i == WaypointHelper.TARGETS)
|
||||
&& waypointHelper.isTypeVisible(i)) {
|
||||
if (points.size() > 0) {
|
||||
points.add(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue