Search in sources :

Example 1 with ResultMatcher

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) TileSourceTemplate(net.osmand.map.TileSourceManager.TileSourceTemplate) MapActivityLayers(net.osmand.plus.activities.MapActivityLayers) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) ResultMatcher(net.osmand.ResultMatcher) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 2 with ResultMatcher

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;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) City(net.osmand.data.City) ResultMatcher(net.osmand.ResultMatcher) MapObject(net.osmand.data.MapObject)

Example 3 with ResultMatcher

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];
}
Also used : Message(android.os.Message) City(net.osmand.data.City) ResultMatcher(net.osmand.ResultMatcher)

Example 4 with ResultMatcher

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];
}
Also used : Message(android.os.Message) Street(net.osmand.data.Street) ArrayList(java.util.ArrayList) List(java.util.List) ResultMatcher(net.osmand.ResultMatcher) MapObject(net.osmand.data.MapObject)

Example 5 with ResultMatcher

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;
        }
    };
}
Also used : Path(android.graphics.Path) RotatedTileBox(net.osmand.data.RotatedTileBox) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) ResultMatcher(net.osmand.ResultMatcher) DisplayMetrics(android.util.DisplayMetrics) QuadRect(net.osmand.data.QuadRect) WindowManager(android.view.WindowManager) Comparator(java.util.Comparator) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TransportStop(net.osmand.data.TransportStop)

Aggregations

ResultMatcher (net.osmand.ResultMatcher)11 ArrayList (java.util.ArrayList)7 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 City (net.osmand.data.City)3 DialogInterface (android.content.DialogInterface)2 Message (android.os.Message)2 AlertDialog (android.support.v7.app.AlertDialog)2 LinkedHashMap (java.util.LinkedHashMap)2 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)2 TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)2 MapObject (net.osmand.data.MapObject)2 QuadRect (net.osmand.data.QuadRect)2 Street (net.osmand.data.Street)2 TileSourceTemplate (net.osmand.map.TileSourceManager.TileSourceTemplate)2 OsmandSettings (net.osmand.plus.OsmandSettings)2 Paint (android.graphics.Paint)1 Path (android.graphics.Path)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1