use of net.osmand.ResultMatcher in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method selectMapOverlayLayer.
public void selectMapOverlayLayer(@NonNull final OsmandMapTileView mapView, @NonNull final CommonPreference<String> mapPref, @NonNull final CommonPreference<String> exMapPref, boolean force, @NonNull final MapActivity activity, @Nullable final OnMapSelectedCallback callback) {
final MapActivityLayers layers = activity.getMapLayers();
if (!force && exMapPref.get() != null) {
mapPref.set(exMapPref.get());
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, mapPref, layers);
return;
}
final OsmandSettings settings = app.getSettings();
Map<String, String> entriesMap = settings.getTileSourceEntries();
final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final String[] items = new String[entriesMap.size() + 1];
int i = 0;
for (String it : entriesMap.values()) {
items[i++] = it;
}
items[i] = app.getString(R.string.install_more);
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == items.length - 1) {
installMapLayers(activity, new ResultMatcher<TileSourceTemplate>() {
TileSourceTemplate template = null;
int count = 0;
@Override
public boolean publish(TileSourceTemplate object) {
if (object == null) {
if (count == 1) {
mapPref.set(template.getName());
exMapPref.set(template.getName());
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, mapPref, layers);
} else {
selectMapOverlayLayer(mapView, mapPref, exMapPref, false, activity, null);
}
} else {
count++;
template = object;
}
return false;
}
@Override
public boolean isCancelled() {
return false;
}
});
} else {
mapPref.set(keys.get(which));
exMapPref.set(keys.get(which));
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, mapPref, layers);
}
dialog.dismiss();
}
}).setNegativeButton(R.string.shared_string_cancel, null).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (callback != null) {
callback.onMapSelected(true);
}
}
});
builder.show();
}
use of net.osmand.ResultMatcher in project Osmand by osmandapp.
the class RegionAddressRepositoryBinary method fillWithCities.
private List<City> fillWithCities(String name, final ResultMatcher<City> resultMatcher, final List<Integer> typeFilter) throws IOException {
List<City> result = new ArrayList<City>();
ResultMatcher<MapObject> matcher = new ResultMatcher<MapObject>() {
List<City> cache = new ArrayList<City>();
@Override
public boolean publish(MapObject o) {
City c = (City) o;
City.CityType type = c.getType();
if (type != null && type.ordinal() >= City.CityType.VILLAGE.ordinal()) {
if (c.getLocation() != null) {
City ct = getClosestCity(c.getLocation(), cache);
c.setClosestCity(ct);
}
}
return resultMatcher.publish(c);
}
@Override
public boolean isCancelled() {
return resultMatcher.isCancelled();
}
};
List<MapObject> foundCities = searchMapObjectsByName(name, matcher, typeFilter);
for (MapObject o : foundCities) {
result.add((City) o);
if (resultMatcher.isCancelled()) {
return result;
}
}
return result;
}
use of net.osmand.ResultMatcher in project Osmand by osmandapp.
the class SearchCityByNameActivity method filterLoop.
@Override
protected boolean filterLoop(String query, Collection<City> list) {
final boolean[] result = { false };
redefineSearchVillagesMode(query);
if (!initializeTaskIsFinished() || !isVillagesSearchEnabled()) {
result[0] = super.filterLoop(query, list);
if (!result[0] && !isVillagesSearchEnabled()) {
setVillagesSearchEnabled(true);
}
}
if (!result[0]) {
ResultMatcher<City> resultMatcher = new ResultMatcher<City>() {
@Override
public boolean isCancelled() {
return namesFilter.isCancelled;
}
@Override
public boolean publish(City object) {
result[0] = true;
Message msg = uiHandler.obtainMessage(MESSAGE_ADD_ENTITY, object);
msg.sendToTarget();
return true;
}
};
region.fillWithSuggestedCities(query, resultMatcher, isVillagesSearchEnabled(), locationToSearch);
}
return result[0];
}
use of net.osmand.ResultMatcher in project Osmand by osmandapp.
the class SearchStreetByNameActivity method filterLoop.
@Override
protected boolean filterLoop(String query, Collection<Street> list) {
final boolean[] result = { false };
if (searchWithCity == -1) {
filter(query, list);
} else if (searchWithCity == 0) {
for (Street obj : list) {
if (namesFilter.isCancelled) {
break;
}
if (filterObject(obj, query)) {
result[0] = true;
Message msg = uiHandler.obtainMessage(MESSAGE_ADD_ENTITY, obj);
msg.sendToTarget();
}
}
} else {
searchWithCity = 0;
final List res = region.searchMapObjectsByName(query, new ResultMatcher<MapObject>() {
@Override
public boolean publish(MapObject object) {
if (object instanceof Street) {
if (city == null || MapUtils.getDistance(city.getLocation(), object.getLocation()) < 100 * 1000) {
result[0] = true;
Message msg = uiHandler.obtainMessage(MESSAGE_ADD_ENTITY, object);
msg.sendToTarget();
return true;
}
}
return false;
}
@Override
public boolean isCancelled() {
return namesFilter.isCancelled;
}
});
runOnUiThread(new Runnable() {
@Override
public void run() {
finishInitializing(res);
}
});
}
return result[0];
}
use of net.osmand.ResultMatcher in project Osmand by osmandapp.
the class TransportStopsLayer method initLayer.
@SuppressWarnings("deprecation")
@Override
public void initLayer(final OsmandMapTileView view) {
backgroundIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bg);
backgroundIconHalfWidth = backgroundIcon.getWidth() / 2;
backgroundIconHalfHeight = backgroundIcon.getWidth() / 2;
this.view = view;
DisplayMetrics dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
paintIcon = new Paint();
paintWhiteIcon = new Paint();
paintWhiteIcon.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(mapActivity, R.color.primary_text_dark), PorterDuff.Mode.SRC_IN));
path = new Path();
stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus);
stopSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_small);
attrs = new RenderingLineAttributes("transport_route");
attrs.defaultWidth = (int) (6 * view.getDensity());
data = new OsmandMapLayer.MapLayerData<List<TransportStop>>() {
{
ZOOM_THRESHOLD = 0;
}
@Override
public boolean isInterrupted() {
return super.isInterrupted();
}
@Override
public void layerOnPostExecute() {
view.refreshMap();
}
@Override
protected List<TransportStop> calculateResult(RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds();
if (latLonBounds == null) {
return new ArrayList<>();
}
List<TransportStop> res = view.getApplication().getResourceManager().searchTransportSync(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, new ResultMatcher<TransportStop>() {
@Override
public boolean publish(TransportStop object) {
return true;
}
@Override
public boolean isCancelled() {
return isInterrupted();
}
});
Collections.sort(res, new Comparator<TransportStop>() {
@Override
public int compare(TransportStop lhs, TransportStop rhs) {
return lhs.getId() < rhs.getId() ? -1 : (lhs.getId().longValue() == rhs.getId().longValue() ? 0 : 1);
}
});
return res;
}
};
}
Aggregations