Search in sources :

Example 16 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class MenuController method getMenuController.

public static MenuController getMenuController(MapActivity mapActivity, LatLon latLon, PointDescription pointDescription, Object object, MenuType menuType) {
    MenuController menuController = null;
    if (object != null) {
        if (object instanceof Amenity) {
            menuController = new AmenityMenuController(mapActivity, pointDescription, (Amenity) object);
        } else if (object instanceof FavouritePoint) {
            menuController = new FavouritePointMenuController(mapActivity, pointDescription, (FavouritePoint) object);
        } else if (object instanceof SearchHistoryHelper.HistoryEntry) {
            menuController = new HistoryMenuController(mapActivity, pointDescription, (SearchHistoryHelper.HistoryEntry) object);
        } else if (object instanceof TargetPoint) {
            menuController = new TargetPointMenuController(mapActivity, pointDescription, (TargetPoint) object);
        } else if (object instanceof Recording) {
            menuController = new AudioVideoNoteMenuController(mapActivity, pointDescription, (Recording) object);
        } else if (object instanceof OsmPoint) {
            menuController = new EditPOIMenuController(mapActivity, pointDescription, (OsmPoint) object);
        } else if (object instanceof WptPt) {
            menuController = new WptPtMenuController(mapActivity, pointDescription, (WptPt) object);
        } else if (object instanceof DownloadMapObject) {
            menuController = new MapDataMenuController(mapActivity, pointDescription, (DownloadMapObject) object);
        } else if (object instanceof OpenStreetNote) {
            menuController = new OsmBugMenuController(mapActivity, pointDescription, (OpenStreetNote) object);
        } else if (object instanceof GpxDisplayItem) {
            menuController = new GpxItemMenuController(mapActivity, pointDescription, (GpxDisplayItem) object);
        } else if (object instanceof MapMarker) {
            menuController = new MapMarkerMenuController(mapActivity, pointDescription, (MapMarker) object);
        } else if (object instanceof TransportStopRoute) {
            menuController = new TransportRouteController(mapActivity, pointDescription, (TransportStopRoute) object);
        } else if (object instanceof TransportStop) {
            menuController = new TransportStopController(mapActivity, pointDescription, (TransportStop) object);
        } else if (object instanceof AMapPoint) {
            menuController = new AMapPointMenuController(mapActivity, pointDescription, (AMapPoint) object);
        } else if (object instanceof LatLon) {
            if (pointDescription.isParking()) {
                menuController = new ParkingPositionMenuController(mapActivity, pointDescription);
            } else if (pointDescription.isMyLocation()) {
                menuController = new MyLocationMenuController(mapActivity, pointDescription);
            }
        } else if (object instanceof RouteDataObject) {
            menuController = new ImpassibleRoadsMenuController(mapActivity, pointDescription, (RouteDataObject) object);
        } else if (object instanceof RenderedObject) {
            menuController = new RenderedObjectMenuController(mapActivity, pointDescription, (RenderedObject) object);
        } else if (object instanceof MapillaryImage) {
            menuController = new MapillaryMenuController(mapActivity, pointDescription, (MapillaryImage) object);
        }
    }
    if (menuController == null) {
        menuController = new PointDescriptionMenuController(mapActivity, pointDescription);
    }
    menuController.menuType = menuType;
    menuController.setLatLon(latLon);
    menuController.onCreated();
    return menuController;
}
Also used : TargetPointMenuController(net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController) WptPt(net.osmand.plus.GPXUtilities.WptPt) HistoryMenuController(net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController) TransportStopController(net.osmand.plus.mapcontextmenu.controllers.TransportStopController) FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) MapillaryImage(net.osmand.plus.mapillary.MapillaryImage) ParkingPositionMenuController(net.osmand.plus.parkingpoint.ParkingPositionMenuController) GpxDisplayItem(net.osmand.plus.GpxSelectionHelper.GpxDisplayItem) GpxItemMenuController(net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) RenderedObjectMenuController(net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController) ImpassibleRoadsMenuController(net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController) EditPOIMenuController(net.osmand.plus.osmedit.EditPOIMenuController) TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) MapMarkerMenuController(net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController) PointDescriptionMenuController(net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController) AMapPointMenuController(net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController) TransportStop(net.osmand.data.TransportStop) Amenity(net.osmand.data.Amenity) FavouritePointMenuController(net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController) AudioVideoNoteMenuController(net.osmand.plus.audionotes.AudioVideoNoteMenuController) OsmBugMenuController(net.osmand.plus.osmedit.OsmBugMenuController) OsmPoint(net.osmand.plus.osmedit.OsmPoint) TransportRouteController(net.osmand.plus.mapcontextmenu.controllers.TransportRouteController) AMapPoint(net.osmand.aidl.maplayer.point.AMapPoint) AmenityMenuController(net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController) DownloadMapObject(net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject) MyLocationMenuController(net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController) RenderedObjectMenuController(net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController) PointDescriptionMenuController(net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController) MapMarkerMenuController(net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController) AMapPointMenuController(net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController) OsmBugMenuController(net.osmand.plus.osmedit.OsmBugMenuController) WptPtMenuController(net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController) MapillaryMenuController(net.osmand.plus.mapillary.MapillaryMenuController) GpxItemMenuController(net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController) HistoryMenuController(net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController) ParkingPositionMenuController(net.osmand.plus.parkingpoint.ParkingPositionMenuController) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) TargetPointMenuController(net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController) AudioVideoNoteMenuController(net.osmand.plus.audionotes.AudioVideoNoteMenuController) AmenityMenuController(net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController) ImpassibleRoadsMenuController(net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController) EditPOIMenuController(net.osmand.plus.osmedit.EditPOIMenuController) FavouritePointMenuController(net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController) MyLocationMenuController(net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController) LatLon(net.osmand.data.LatLon) RenderedObject(net.osmand.NativeLibrary.RenderedObject) OpenStreetNote(net.osmand.plus.osmedit.OsmBugsLayer.OpenStreetNote) RouteDataObject(net.osmand.binary.RouteDataObject) Recording(net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording) WptPtMenuController(net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController) MapillaryMenuController(net.osmand.plus.mapillary.MapillaryMenuController)

Example 17 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class MapPoiTypes method parseAmenity.

public Amenity parseAmenity(String tag, String val, boolean relation, Map<String, String> otherTags) {
    initPoiTypesByTag();
    PoiType pt = poiTypesByTag.get(tag + "/" + val);
    if (pt == null) {
        pt = poiTypesByTag.get(tag);
    }
    if (pt == null || pt.isAdditional()) {
        return null;
    }
    if (!Algorithms.isEmpty(pt.getOsmTag2())) {
        if (!Algorithms.objectEquals(otherTags.get(pt.getOsmTag2()), pt.getOsmValue2())) {
            return null;
        }
    }
    if (pt.getCategory() == getOtherMapCategory()) {
        return null;
    }
    String nameValue = otherTags.get("name");
    if (pt.getNameTag() != null) {
        nameValue = otherTags.get(pt.getNameTag());
    }
    boolean hasName = !Algorithms.isEmpty(nameValue);
    if (!hasName && pt.isNameOnly()) {
        return null;
    }
    if (relation && !pt.isRelation()) {
        return null;
    }
    Amenity a = new Amenity();
    a.setType(pt.getCategory());
    a.setSubType(pt.getKeyName());
    if (pt.getNameTag() != null) {
        a.setName(nameValue);
    }
    // additional info
    Iterator<Entry<String, String>> it = otherTags.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, String> e = it.next();
        String otag = e.getKey();
        if (!otag.equals(tag) && !otag.equals("name")) {
            PoiType pat = poiTypesByTag.get(otag + "/" + e.getValue());
            if (pat == null) {
                for (String splValue : e.getValue().split(";")) {
                    PoiType ps = poiTypesByTag.get(otag + "/" + splValue.trim());
                    if (ps != null) {
                        a.setAdditionalInfo(ps.getKeyName(), splValue.trim());
                    }
                }
                pat = poiTypesByTag.get(otag);
            }
            if (pat != null && pat.isAdditional()) {
                a.setAdditionalInfo(pat.getKeyName(), e.getValue());
            }
        }
    }
    return a;
}
Also used : Amenity(net.osmand.data.Amenity) Entry(java.util.Map.Entry)

Example 18 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class MapMarkersGroupsFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final MapActivity mapActivity = (MapActivity) getActivity();
    final boolean night = !mapActivity.getMyApplication().getSettings().isLightContent();
    mainView = inflater.inflate(R.layout.fragment_map_markers_groups, container, false);
    Fragment selectionMarkersGroupFragment = getChildFragmentManager().findFragmentByTag(SelectionMarkersGroupBottomSheetDialogFragment.TAG);
    if (selectionMarkersGroupFragment != null) {
        ((SelectionMarkersGroupBottomSheetDialogFragment) selectionMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener());
    }
    Fragment historyMarkerMenuFragment = getChildFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
    if (historyMarkerMenuFragment != null) {
        ((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
    }
    final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
        }
    });
    backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light));
    backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    backgroundPaint.setAntiAlias(true);
    iconPaint.setAntiAlias(true);
    iconPaint.setFilterBitmap(true);
    iconPaint.setDither(true);
    textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size));
    textPaint.setFakeBoldText(true);
    textPaint.setAntiAlias(true);
    final String delStr = getString(R.string.shared_string_delete).toUpperCase();
    final String moveToHistoryStr = getString(R.string.move_to_history).toUpperCase();
    final Rect bounds = new Rect();
    textPaint.getTextBounds(delStr, 0, delStr.length(), bounds);
    final int delStrWidth = bounds.width();
    final int textHeight = bounds.height();
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

        private float marginSides = getResources().getDimension(R.dimen.list_content_padding);

        private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark);

        private Bitmap historyBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_history);

        private boolean iconHidden;

        @Override
        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            boolean markerViewHolder = viewHolder instanceof MapMarkerItemViewHolder;
            int pos = viewHolder.getAdapterPosition();
            if (markerViewHolder && pos != -1) {
                MapMarker marker = (MapMarker) adapter.getItem(pos);
                if (marker.history) {
                    return ItemTouchHelper.LEFT;
                } else {
                    return ItemTouchHelper.RIGHT;
                }
            } else {
                return 0;
            }
        }

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
            if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
                if (!iconHidden && isCurrentlyActive) {
                    ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
                    compassUpdateAllowed = false;
                    iconHidden = true;
                }
                View itemView = viewHolder.itemView;
                int colorIcon;
                int colorText;
                if (Math.abs(dX) > itemView.getWidth() / 2) {
                    colorIcon = R.color.map_widget_blue;
                    colorText = R.color.map_widget_blue;
                } else {
                    colorIcon = night ? 0 : R.color.icon_color;
                    colorText = R.color.dashboard_subheader_text_light;
                }
                if (colorIcon != 0) {
                    iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), colorIcon), PorterDuff.Mode.SRC_IN));
                }
                textPaint.setColor(ContextCompat.getColor(getActivity(), colorText));
                float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
                if (dX > 0) {
                    c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
                    float iconMarginTop = ((float) itemView.getHeight() - (float) historyBitmap.getHeight()) / 2;
                    c.drawBitmap(historyBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
                    c.drawText(moveToHistoryStr, itemView.getLeft() + 2 * marginSides + historyBitmap.getWidth(), itemView.getTop() + textMarginTop + textHeight, textPaint);
                } else {
                    c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
                    float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2;
                    c.drawBitmap(deleteBitmap, itemView.getRight() - deleteBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint);
                    c.drawText(delStr, itemView.getRight() - deleteBitmap.getWidth() - 2 * marginSides - delStrWidth, itemView.getTop() + textMarginTop + textHeight, textPaint);
                }
            }
            super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }

        @Override
        public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            if (viewHolder instanceof MapMarkerItemViewHolder) {
                ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE);
                iconHidden = false;
                compassUpdateAllowed = true;
            }
            super.clearView(recyclerView, viewHolder);
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, final int direction) {
            final int pos = viewHolder.getAdapterPosition();
            Object item = adapter.getItem(pos);
            if (item instanceof MapMarker) {
                final MapMarker marker = (MapMarker) item;
                int snackbarStringRes;
                if (direction == ItemTouchHelper.RIGHT) {
                    mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory((MapMarker) item);
                    snackbarStringRes = R.string.marker_moved_to_history;
                } else {
                    mapActivity.getMyApplication().getMapMarkersHelper().removeMarker((MapMarker) item);
                    snackbarStringRes = R.string.item_removed;
                }
                updateAdapter();
                snackbar = Snackbar.make(viewHolder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (direction == ItemTouchHelper.RIGHT) {
                            mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
                        } else {
                            mapActivity.getMyApplication().getMapMarkersHelper().addMarker(marker);
                        }
                        updateAdapter();
                    }
                });
                AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
                snackbar.show();
            }
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    adapter = new MapMarkersGroupsAdapter(mapActivity);
    adapter.setListener(new MapMarkersGroupsAdapter.MapMarkersGroupsAdapterListener() {

        @Override
        public void onItemClick(View view) {
            int pos = recyclerView.getChildAdapterPosition(view);
            if (pos == RecyclerView.NO_POSITION) {
                return;
            }
            Object item = adapter.getItem(pos);
            if (item instanceof MapMarker) {
                MapMarker marker = (MapMarker) item;
                OsmandApplication app = mapActivity.getMyApplication();
                if (!marker.history) {
                    if (app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) {
                        app.getMapMarkersHelper().moveMarkerToTop(marker);
                        updateAdapter();
                    } else {
                        FavouritePoint fav = marker.favouritePoint == null ? app.getFavorites().getVisibleFavByLatLon(marker.point) : marker.favouritePoint;
                        if (fav != null) {
                            showMap(marker.point, fav.getPointDescription(), fav);
                            return;
                        }
                        WptPt pt = marker.wptPt == null ? app.getSelectedGpxHelper().getVisibleWayPointByLatLon(marker.point) : marker.wptPt;
                        if (pt != null) {
                            showMap(marker.point, pt.getPointDescription(mapActivity), pt);
                            return;
                        }
                        Amenity mapObj = mapActivity.getMapLayers().getMapMarkersLayer().getMapObjectByMarker(marker);
                        PointDescription desc = mapObj == null ? marker.getPointDescription(mapActivity) : mapActivity.getMapLayers().getPoiMapLayer().getObjectName(mapObj);
                        showMap(marker.point, desc, mapObj == null ? marker : mapObj);
                    }
                } else {
                    showHistoryMenuFragment(pos, marker);
                }
            }
        }

        private void showMap(LatLon latLon, PointDescription desc, Object objToShow) {
            mapActivity.getMyApplication().getSettings().setMapLocationToShow(latLon.getLatitude(), latLon.getLongitude(), 15, desc, true, objToShow);
            MapActivity.launchMapActivityMoveToTop(mapActivity);
            ((DialogFragment) getParentFragment()).dismiss();
        }

        private void showHistoryMenuFragment(int pos, MapMarker marker) {
            HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment();
            fragment.setUsedOnMap(false);
            Bundle arguments = new Bundle();
            arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos);
            arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity));
            arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex);
            arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate);
            fragment.setArguments(arguments);
            fragment.setListener(createHistoryMarkerMenuListener());
            fragment.show(getChildFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG);
        }
    });
    adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onChanged() {
            changeFabVisibilityIfNeeded();
        }

        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            changeFabVisibilityIfNeeded();
        }

        @Override
        public void onItemRangeRemoved(int positionStart, int itemCount) {
            changeFabVisibilityIfNeeded();
        }
    });
    final View emptyView = mainView.findViewById(R.id.empty_view);
    mainView.findViewById(R.id.import_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openAddGroupMenu();
        }
    });
    ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
    if (Build.VERSION.SDK_INT >= 18) {
        emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_group_night : R.drawable.ic_empty_state_marker_group_day);
    } else {
        emptyImageView.setVisibility(View.INVISIBLE);
    }
    recyclerView.setEmptyView(emptyView);
    recyclerView.setAdapter(adapter);
    mainView.findViewById(R.id.add_group_fab).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openAddGroupMenu();
        }
    });
    if (groupIdToOpen != null) {
        int groupHeaderPosition = adapter.getGroupHeaderPosition(groupIdToOpen);
        if (groupHeaderPosition != -1) {
            ((EmptyStateRecyclerView) mainView.findViewById(R.id.list)).scrollToPosition(groupHeaderPosition);
        }
    }
    return mainView;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) MapMarkerItemViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DialogFragment(android.support.v4.app.DialogFragment) DashLocationFragment(net.osmand.plus.dashboard.DashLocationFragment) Fragment(android.support.v4.app.Fragment) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Bitmap(android.graphics.Bitmap) MapMarkerItemViewHolder(net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity) Amenity(net.osmand.data.Amenity) Rect(android.graphics.Rect) Bundle(android.os.Bundle) Canvas(android.graphics.Canvas) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) FavouritePoint(net.osmand.data.FavouritePoint) Paint(android.graphics.Paint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) MapMarkersGroupsAdapter(net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter) Nullable(android.support.annotation.Nullable)

Example 19 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class MapMarkersActiveFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final MapActivity mapActivity = (MapActivity) getActivity();
    final View mainView = inflater.inflate(R.layout.fragment_map_markers_active, container, false);
    final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    adapter = new MapMarkersActiveAdapter(mapActivity);
    final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(mapActivity, adapter));
    touchHelper.attachToRecyclerView(recyclerView);
    adapter.setAdapterListener(new MapMarkersActiveAdapterListener() {

        private int fromPosition;

        private int toPosition;

        @Override
        public void onItemClick(View view) {
            int pos = recyclerView.getChildAdapterPosition(view);
            if (pos == RecyclerView.NO_POSITION) {
                return;
            }
            MapMarker marker = adapter.getItem(pos);
            OsmandApplication app = mapActivity.getMyApplication();
            if (app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) {
                app.getMapMarkersHelper().moveMarkerToTop(marker);
                updateAdapter();
            } else {
                FavouritePoint fav = marker.favouritePoint == null ? app.getFavorites().getVisibleFavByLatLon(marker.point) : marker.favouritePoint;
                if (fav != null) {
                    showMap(marker.point, fav.getPointDescription(), fav);
                    return;
                }
                WptPt pt = marker.wptPt == null ? app.getSelectedGpxHelper().getVisibleWayPointByLatLon(marker.point) : marker.wptPt;
                if (pt != null) {
                    showMap(marker.point, pt.getPointDescription(mapActivity), pt);
                    return;
                }
                Amenity mapObj = mapActivity.getMapLayers().getMapMarkersLayer().getMapObjectByMarker(marker);
                PointDescription desc = mapObj == null ? marker.getPointDescription(mapActivity) : mapActivity.getMapLayers().getPoiMapLayer().getObjectName(mapObj);
                showMap(marker.point, desc, mapObj == null ? marker : mapObj);
            }
        }

        private void showMap(LatLon latLon, PointDescription desc, Object objToShow) {
            mapActivity.getMyApplication().getSettings().setMapLocationToShow(latLon.getLatitude(), latLon.getLongitude(), 15, desc, true, objToShow);
            MapActivity.launchMapActivityMoveToTop(mapActivity);
            ((DialogFragment) getParentFragment()).dismiss();
        }

        @Override
        public void onDragStarted(RecyclerView.ViewHolder holder) {
            compassUpdateAllowed = false;
            fromPosition = holder.getAdapterPosition();
            touchHelper.startDrag(holder);
        }

        @Override
        public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) {
            compassUpdateAllowed = true;
            toPosition = holder.getAdapterPosition();
            if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
                hideSnackbar();
                mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded();
                adapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onSwipeStarted() {
            compassUpdateAllowed = false;
        }
    });
    final View emptyView = mainView.findViewById(R.id.empty_view);
    ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
    if (Build.VERSION.SDK_INT >= 18) {
        emptyImageView.setImageResource(mapActivity.getMyApplication().getSettings().isLightContent() ? R.drawable.ic_empty_state_marker_list_day : R.drawable.ic_empty_state_marker_list_night);
    } else {
        emptyImageView.setVisibility(View.INVISIBLE);
    }
    recyclerView.setEmptyView(emptyView);
    recyclerView.setAdapter(adapter);
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
        }
    });
    return mainView;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) Amenity(net.osmand.data.Amenity) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) MapMarkersActiveAdapterListener(net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) FavouritePoint(net.osmand.data.FavouritePoint) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) LatLon(net.osmand.data.LatLon) MapMarkersItemTouchHelperCallback(net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback) PointDescription(net.osmand.data.PointDescription) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) MapMarkersActiveAdapter(net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(android.support.annotation.Nullable)

Example 20 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class PoiUIFilter method getNameFilterInternal.

private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter, final boolean allTime, final boolean open, final List<PoiType> poiAdditionals) {
    final CollatorStringMatcher sm = nmFilter.length() > 0 ? new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
    return new AmenityNameFilter() {

        @Override
        public boolean accept(Amenity a) {
            if (sm != null) {
                String lower = OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get());
                if (!sm.matches(lower)) {
                    return false;
                }
            }
            if (poiAdditionals != null) {
                Map<PoiType, PoiType> textPoiAdditionalsMap = new HashMap<>();
                Map<String, List<PoiType>> poiAdditionalCategoriesMap = new HashMap<>();
                for (PoiType pt : poiAdditionals) {
                    String category = pt.getPoiAdditionalCategory();
                    List<PoiType> types = poiAdditionalCategoriesMap.get(category);
                    if (types == null) {
                        types = new ArrayList<>();
                        poiAdditionalCategoriesMap.put(category, types);
                    }
                    types.add(pt);
                    String osmTag = pt.getOsmTag();
                    if (osmTag.length() < pt.getKeyName().length()) {
                        PoiType textPoiType = poiTypes.getTextPoiAdditionalByKey(osmTag);
                        if (textPoiType != null) {
                            textPoiAdditionalsMap.put(pt, textPoiType);
                        }
                    }
                }
                for (List<PoiType> types : poiAdditionalCategoriesMap.values()) {
                    boolean acceptedAnyInCategory = false;
                    for (PoiType p : types) {
                        String inf = a.getAdditionalInfo(p.getKeyName());
                        if (inf != null) {
                            acceptedAnyInCategory = true;
                            break;
                        } else {
                            PoiType textPoiType = textPoiAdditionalsMap.get(p);
                            if (textPoiType != null) {
                                inf = a.getAdditionalInfo(textPoiType.getKeyName());
                                if (!Algorithms.isEmpty(inf)) {
                                    String[] items = inf.split(";");
                                    String val = p.getOsmValue().trim().toLowerCase();
                                    for (String item : items) {
                                        if (item.trim().toLowerCase().equals(val)) {
                                            acceptedAnyInCategory = true;
                                            break;
                                        }
                                    }
                                    if (acceptedAnyInCategory) {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (!acceptedAnyInCategory) {
                        return false;
                    }
                }
            }
            if (allTime) {
                if (!"24/7".equalsIgnoreCase(a.getOpeningHours()) && !"Mo-Su 00:00-24:00".equalsIgnoreCase(a.getOpeningHours())) {
                    return false;
                }
            }
            if (open) {
                OpeningHours rs = OpeningHoursParser.parseOpenedHours(a.getOpeningHours());
                if (rs != null) {
                    Calendar inst = Calendar.getInstance();
                    inst.setTimeInMillis(System.currentTimeMillis());
                    boolean work = rs.isOpenedForTime(inst);
                    if (!work) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
            return true;
        }
    };
}
Also used : Amenity(net.osmand.data.Amenity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Calendar(java.util.Calendar) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) OpeningHours(net.osmand.util.OpeningHoursParser.OpeningHours) CollatorStringMatcher(net.osmand.CollatorStringMatcher) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Amenity (net.osmand.data.Amenity)53 LatLon (net.osmand.data.LatLon)17 ArrayList (java.util.ArrayList)11 PoiCategory (net.osmand.osm.PoiCategory)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)8 PoiType (net.osmand.osm.PoiType)8 PointDescription (net.osmand.data.PointDescription)7 Paint (android.graphics.Paint)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 FavouritePoint (net.osmand.data.FavouritePoint)6 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)5 File (java.io.File)5 Map (java.util.Map)5 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 QuadRect (net.osmand.data.QuadRect)5 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 LinearLayout (android.widget.LinearLayout)4