Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-05-03 14:10:45 +02:00
commit ac043b11e9
3 changed files with 166 additions and 124 deletions

View file

@ -2,10 +2,13 @@ package net.osmand.plus.activities;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
@ -24,6 +27,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
@ -100,7 +104,7 @@ public class MapActivityLayers {
public void createLayers(final OsmandMapTileView mapView) { public void createLayers(final OsmandMapTileView mapView) {
OsmandApplication app = (OsmandApplication) getApplication(); OsmandApplication app = getApplication();
RoutingHelper routingHelper = app.getRoutingHelper(); RoutingHelper routingHelper = app.getRoutingHelper();
// first create to make accessible // first create to make accessible
mapTextLayer = new MapTextLayer(); mapTextLayer = new MapTextLayer();
@ -234,8 +238,7 @@ public class MapActivityLayers {
g.path = getString(R.string.show_current_gpx_title); g.path = getString(R.string.show_current_gpx_title);
} }
break; break;
} } else {
if (!g.showCurrentTrack || locToShow == null) {
locToShow = g.findPointToShow(); locToShow = g.findPointToShow();
} }
} }
@ -258,22 +261,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 OsmandApplication app = getApplication();
final PoiFiltersHelper poiFilters = app.getPoiFilters(); final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter();
final List<PoiUIFilter> list = new ArrayList<>(); final List<PoiUIFilter> list = new ArrayList<>();
list.add(poiFilters.getCustomPOIFilter()); list.add(poiFilters.getCustomPOIFilter());
for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) { for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
addFilterToList(adapter, list, f); addFilterToList(adapter, list, f, true);
} }
for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) { 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); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(activity,
app.getSettings().isLightContent());
final ListView listView = new ListView(activity); final ListView listView = new ListView(activity);
listView.setDivider(null); listView.setDivider(null);
listView.setClickable(true); listView.setClickable(true);
@ -287,8 +289,8 @@ public class MapActivityLayers {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
}); });
builder.setView(listView); builder.setView(listView)
builder.setTitle(R.string.show_poi_over_map) .setTitle(R.string.show_poi_over_map)
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -298,26 +300,98 @@ public class MapActivityLayers {
}) })
.setNegativeButton(R.string.shared_string_cancel, null) .setNegativeButton(R.string.shared_string_cancel, null)
// TODO go to single choice dialog // TODO go to single choice dialog
.setNeutralButton("", null); .setNeutralButton(" ", new DialogInterface.OnClickListener() {
builder.show(); @Override
public void onClick(DialogInterface dialog, int which) {
showSingleChoicePoiFilterDialog(mapView, listener);
}
});
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_singleselect);
neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); }
});
alertDialog.show();
} }
private void addFilterToList(final ContextMenuAdapter adapter, final List<PoiUIFilter> list, final PoiUIFilter f) { public void showSingleChoicePoiFilterDialog(final OsmandMapTileView mapView, final ConfirmListener listener) {
list.add(f); final OsmandApplication app = getApplication();
ContextMenuItem.ItemBuilder builder = new ContextMenuItem.ItemBuilder(); final PoiFiltersHelper poiFilters = app.getPoiFilters();
builder.setListener(new ContextMenuAdapter.ItemClickListener() { 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 @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) { public void onClick(DialogInterface dialog, int which) {
if (isChecked) { PoiUIFilter pf = list.get(which + 1);
getApplication().getPoiFilters().addSelectedPoiFilter(f); 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 { } 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(" ", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showMultichoicePoiFilterDialog(mapView, listener);
} }
}); });
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_multiselect);
neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); }
});
alertDialog.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.setTitle(f.getName());
builder.setSelected(getApplication().getPoiFilters().isPoiFilterSelected(f));
if (RenderingIcons.containsBigIcon(f.getIconId())) { if (RenderingIcons.containsBigIcon(f.getIconId())) {
builder.setIcon(RenderingIcons.getBigIconResourceId(f.getIconId())); builder.setIcon(RenderingIcons.getBigIconResourceId(f.getIconId()));
} else { } else {
@ -335,7 +409,7 @@ public class MapActivityLayers {
} }
final OsmandSettings settings = getApplication().getSettings(); 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"; final String layerOsmVector = "LAYER_OSM_VECTOR";
@ -347,7 +421,7 @@ public class MapActivityLayers {
entriesMap.put(layerInstallMore, getString(R.string.install_more)); entriesMap.put(layerInstallMore, getString(R.string.install_more));
entriesMap.put(layerEditInstall, getString(R.string.maps_define_edit)); 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); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
@ -382,57 +456,62 @@ public class MapActivityLayers {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String layerKey = entriesMapList.get(which).getKey(); String layerKey = entriesMapList.get(which).getKey();
if (layerKey.equals(layerOsmVector)) { switch (layerKey) {
settings.MAP_ONLINE_DATA.set(false); case layerOsmVector:
updateMapSource(mapView, null); settings.MAP_ONLINE_DATA.set(false);
} else if (layerKey.equals(layerEditInstall)) { updateMapSource(mapView, null);
OsmandRasterMapsPlugin.defineNewEditLayer(activity, new ResultMatcher<TileSourceTemplate>() { break;
case layerEditInstall:
OsmandRasterMapsPlugin.defineNewEditLayer(activity, new ResultMatcher<TileSourceTemplate>() {
@Override @Override
public boolean publish(TileSourceTemplate object) { public boolean publish(TileSourceTemplate object) {
settings.MAP_TILE_SOURCES.set(object.getName()); settings.MAP_TILE_SOURCES.set(object.getName());
settings.MAP_ONLINE_DATA.set(true); settings.MAP_ONLINE_DATA.set(true);
updateMapSource(mapView, settings.MAP_TILE_SOURCES); updateMapSource(mapView, settings.MAP_TILE_SOURCES);
return true; 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;
} }
return false;
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return false; return false;
} }
});
} else { });
settings.MAP_TILE_SOURCES.set(layerKey); break;
settings.MAP_ONLINE_DATA.set(true); case layerInstallMore:
updateMapSource(mapView, settings.MAP_TILE_SOURCES); 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(); dialog.dismiss();

View file

@ -103,7 +103,7 @@ public class ConfigureMapMenu {
@Override @Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) { public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
if (itemId == R.string.layer_poi) { if (itemId == R.string.layer_poi) {
selectPOILayer(adapter, adapter.getItem(pos)); showPoiFilterDialog(adapter, adapter.getItem(pos));
return false; return false;
} else if (itemId == R.string.layer_gpx_layer && cm.getItem(pos).getSelected()) { } else if (itemId == R.string.layer_gpx_layer && cm.getItem(pos).getSelected()) {
showGpxSelectionDialog(adapter, adapter.getItem(pos)); showGpxSelectionDialog(adapter, adapter.getItem(pos));
@ -134,7 +134,7 @@ public class ConfigureMapMenu {
if (itemId == R.string.layer_poi) { if (itemId == R.string.layer_poi) {
pfh.clearSelectedPoiFilters(); pfh.clearSelectedPoiFilters();
if (isChecked) { if (isChecked) {
selectPOILayer(adapter, adapter.getItem(pos)); showPoiFilterDialog(adapter, adapter.getItem(pos));
} else { } else {
adapter.getItem(pos).setDescription(pfh.getSelectedPoiFiltersName()); adapter.getItem(pos).setDescription(pfh.getSelectedPoiFiltersName());
} }
@ -183,9 +183,9 @@ public class ConfigureMapMenu {
}); });
} }
protected void selectPOILayer(final ArrayAdapter<ContextMenuItem> adapter, protected void showPoiFilterDialog(final ArrayAdapter<ContextMenuItem> adapter,
final ContextMenuItem item) { final ContextMenuItem item) {
ma.getMapLayers().showPoiFilterDialog(ma.getMapView(), ma.getMapLayers().showSingleChoicePoiFilterDialog(ma.getMapView(),
new MapActivityLayers.ConfirmListener() { new MapActivityLayers.ConfirmListener() {
@Override @Override
public void confirm() { public void confirm() {

View file

@ -10,6 +10,7 @@ import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape; import android.graphics.drawable.shapes.Shape;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.view.MenuItem; import android.view.MenuItem;
@ -224,11 +225,11 @@ public class WaypointDialogHelper {
int color; int color;
int pointColor; int pointColor;
if (nightMode) { if (nightMode) {
color = ctx.getResources().getColor(R.color.dashboard_divider_dark); color = ContextCompat.getColor(ctx, R.color.dashboard_divider_dark);
pointColor = ctx.getResources().getColor(R.color.dashboard_divider_dark); pointColor = ContextCompat.getColor(ctx, R.color.dashboard_divider_dark);
} else { } else {
color = ctx.getResources().getColor(R.color.dashboard_divider_light); color = ContextCompat.getColor(ctx, R.color.dashboard_divider_light);
pointColor = ctx.getResources().getColor(R.color.ctx_menu_info_divider_light); pointColor = ContextCompat.getColor(ctx, R.color.ctx_menu_info_divider_light);
} }
Shape fullDividerShape = new ListDividerShape(color, 0); Shape fullDividerShape = new ListDividerShape(color, 0);
@ -616,7 +617,7 @@ public class WaypointDialogHelper {
running[0] = position; running[0] = position;
thisAdapter.notifyDataSetInvalidated(); thisAdapter.notifyDataSetInvalidated();
MapActivity map = (MapActivity) ctx; MapActivity map = (MapActivity) ctx;
map.getMapLayers().showPoiFilterDialog(map.getMapView(), map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(),
new MapActivityLayers.ConfirmListener() { new MapActivityLayers.ConfirmListener() {
@Override @Override
public void confirm() { public void confirm() {
@ -690,7 +691,7 @@ public class WaypointDialogHelper {
if (ctx instanceof MapActivity && if (ctx instanceof MapActivity &&
!app.getPoiFilters().isPoiFilterSelected(PoiUIFilter.CUSTOM_FILTER_ID)) { !app.getPoiFilters().isPoiFilterSelected(PoiUIFilter.CUSTOM_FILTER_ID)) {
MapActivity map = (MapActivity) ctx; MapActivity map = (MapActivity) ctx;
map.getMapLayers().showPoiFilterDialog(map.getMapView(), map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(),
new MapActivityLayers.ConfirmListener() { new MapActivityLayers.ConfirmListener() {
@Override @Override
public void confirm() { public void confirm() {
@ -834,9 +835,8 @@ public class WaypointDialogHelper {
boolean rc = waypointHelper.isRouteCalculated(); boolean rc = waypointHelper.isRouteCalculated();
for (int i = 0; i < WaypointHelper.MAX; i++) { for (int i = 0; i < WaypointHelper.MAX; i++) {
List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i); List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i);
if (!rc && i != WaypointHelper.WAYPOINTS && i != WaypointHelper.TARGETS) { if ((rc || i == WaypointHelper.WAYPOINTS || i == WaypointHelper.TARGETS)
// skip && waypointHelper.isTypeVisible(i)) {
} else if (waypointHelper.isTypeVisible(i)) {
if (points.size() > 0) { if (points.size() > 0) {
points.add(true); points.add(true);
} }
@ -889,43 +889,6 @@ public class WaypointDialogHelper {
app.getSettings().setMapLocationToShow(locationPoint.getLatitude(), locationPoint.getLongitude(), app.getSettings().setMapLocationToShow(locationPoint.getLatitude(), locationPoint.getLongitude(),
15, locationPoint.getPointDescription(a), false, locationPoint); 15, locationPoint.getPointDescription(a), false, locationPoint);
MapActivity.launchMapActivityMoveToTop(a); MapActivity.launchMapActivityMoveToTop(a);
/*
MapActivity ctx = (MapActivity) a;
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
int fZoom = ctx.getMapView().getZoom() < 15 ? 15 : ctx.getMapView().getZoom();
double flat = locationPoint.getLatitude();
double flon = locationPoint.getLongitude();
if (!center) {
RotatedTileBox cp = ctx.getMapView().getCurrentRotatedTileBox().copy();
cp.setCenterLocation(0.5f, 0.25f);
cp.setLatLonCenter(flat, flon);
flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2);
}
if (thread.isAnimating()) {
ctx.getMapView().setIntZoom(fZoom);
ctx.getMapView().setLatLon(flat, flon);
app.getAppCustomization().showLocationPoint(ctx, locationPoint);
} else {
final double dist = MapUtils.getDistance(ctx.getMapView().getLatitude(), ctx.getMapView().getLongitude(),
locationPoint.getLatitude(), locationPoint.getLongitude());
double t = 10;
if (dist < t) {
app.getAppCustomization().showLocationPoint(ctx, locationPoint);
} else {
thread.startMoving(flat, flon, fZoom, true);
}
if (ctx.getDashboard().isVisible()) {
ctx.getDashboard().hideDashboard();
ctx.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide();
ctx.getContextMenu().show(
new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude()),
locationPoint.getPointDescription(ctx),
locationPoint);
}
}
*/
} }
public static void sortAllTargets(final OsmandApplication app, final Activity activity, public static void sortAllTargets(final OsmandApplication app, final Activity activity,