Search in sources :

Example 16 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class CoordinateInputDialogFragment method addMapMarker.

private void addMapMarker(LatLon latLon, String name) {
    PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name);
    int colorIndex = mapMarkers.size() > 0 ? mapMarkers.get(mapMarkers.size() - 1).colorIndex : -1;
    if (colorIndex == -1) {
        colorIndex = 0;
    } else {
        colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
    }
    MapMarker mapMarker = new MapMarker(latLon, pointDescription, colorIndex, false, 0);
    mapMarker.history = false;
    mapMarker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
    mapMarkers.add(mapMarker);
    adapter.notifyDataSetChanged();
    clearInputs();
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) PointDescription(net.osmand.data.PointDescription)

Example 17 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class MapRouteInfoMenu method addMarkersToSpinner.

private void addMarkersToSpinner(List<RouteSpinnerRow> actions) {
    MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
    List<MapMarker> markers = markersHelper.getMapMarkers();
    if (markers.size() > 0) {
        MapMarker m = markers.get(0);
        actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_1_ID, MapMarkerDialogHelper.getMapMarkerIcon(mapActivity.getMyApplication(), m.colorIndex), m.getName(mapActivity)));
    }
    if (markers.size() > 1) {
        MapMarker m = markers.get(1);
        actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_2_ID, MapMarkerDialogHelper.getMapMarkerIcon(mapActivity.getMyApplication(), m.colorIndex), m.getName(mapActivity)));
    }
    /*
		if (markers.size() > 2) {
			MapMarker m = markers.get(2);
			actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_3_ID,
					MapMarkerDialogHelper.getMapMarkerIcon(mapActivity.getMyApplication(), m.colorIndex),
					m.getOnlyName()));
		}
		*/
    if (markers.size() > 2) {
        actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_MORE_ID, 0, mapActivity.getString(R.string.map_markers_other)));
    }
}
Also used : MapMarkersHelper(net.osmand.plus.MapMarkersHelper) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker)

Example 18 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class MapRouteInfoMenu method selectMapMarker.

public void selectMapMarker(final int index, final boolean target, final boolean intermediate) {
    if (index != -1) {
        MapMarker m = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers().get(index);
        LatLon point = new LatLon(m.getLatitude(), m.getLongitude());
        if (intermediate) {
            getTargets().navigateToPoint(point, true, getTargets().getIntermediatePoints().size(), m.getPointDescription(mapActivity));
        } else if (target) {
            getTargets().navigateToPoint(point, true, -1, m.getPointDescription(mapActivity));
        } else {
            getTargets().setStartPoint(point, true, m.getPointDescription(mapActivity));
        }
        updateFromIcon();
    } else {
        MapMarkerSelectionFragment selectionFragment = MapMarkerSelectionFragment.newInstance(target, intermediate);
        selectionFragment.show(mapActivity.getSupportFragmentManager(), MapMarkerSelectionFragment.TAG);
    }
}
Also used : LatLon(net.osmand.data.LatLon) MapMarkerSelectionFragment(net.osmand.plus.mapmarkers.MapMarkerSelectionFragment) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker)

Example 19 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class PlanRouteFragment method createOptionsFragmentListener.

private PlanRouteOptionsFragmentListener createOptionsFragmentListener() {
    return new PlanRouteOptionsFragmentListener() {

        private MapActivity mapActivity = getMapActivity();

        @Override
        public void selectOnClick() {
            selectAllOnClick();
        }

        @Override
        public void navigateOnClick() {
            if (mapActivity != null) {
                boolean hasTargets = false;
                TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
                List<MapMarker> markers = markersHelper.getSelectedMarkers();
                if (markers.size() > 0) {
                    int i = 0;
                    if (markersHelper.isStartFromMyLocation()) {
                        targetPointsHelper.clearStartPoint(false);
                    } else {
                        MapMarker m = markers.get(i++);
                        targetPointsHelper.setStartPoint(new LatLon(m.getLatitude(), m.getLongitude()), false, m.getPointDescription(mapActivity));
                    }
                    List<TargetPoint> targetPoints = new ArrayList<>();
                    for (int k = i; k < markers.size(); k++) {
                        MapMarker m = markers.get(k);
                        TargetPoint t = new TargetPoint(new LatLon(m.getLatitude(), m.getLongitude()), m.getPointDescription(mapActivity));
                        targetPoints.add(t);
                    }
                    if (mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get()) {
                        TargetPoint end = targetPointsHelper.getPointToStart();
                        if (end == null) {
                            Location loc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
                            if (loc != null) {
                                end = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, getString(R.string.shared_string_my_location)));
                            }
                        }
                        if (end != null) {
                            targetPoints.add(end);
                        }
                    }
                    RoutingHelper routingHelper = mapActivity.getRoutingHelper();
                    boolean updateRoute = routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode();
                    targetPointsHelper.reorderAllTargetPoints(targetPoints, updateRoute);
                    hasTargets = true;
                } else {
                    targetPointsHelper.clearStartPoint(false);
                    targetPointsHelper.clearPointToNavigate(false);
                }
                planRouteContext.setNavigationFromMarkers(true);
                dismiss();
                mapActivity.getMapLayers().getMapControlsLayer().doRoute(hasTargets);
            }
        }

        @Override
        public void makeRoundTripOnClick() {
            roundTripOnClick();
        }

        @Override
        public void doorToDoorOnClick() {
            if (mapActivity != null) {
                OsmandApplication app = mapActivity.getMyApplication();
                Location myLoc = app.getLocationProvider().getLastStaleKnownLocation();
                boolean startFromLocation = app.getMapMarkersHelper().isStartFromMyLocation() && myLoc != null;
                if (selectedCount > (startFromLocation ? 0 : 1)) {
                    sortSelectedMarkersDoorToDoor(mapActivity, startFromLocation, myLoc);
                }
            }
        }

        @Override
        public void reverseOrderOnClick() {
            if (mapActivity != null) {
                markersHelper.reverseActiveMarkersOrder();
                adapter.reloadData();
                adapter.notifyDataSetChanged();
                planRouteContext.recreateSnapTrkSegment(false);
            }
        }
    };
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PlanRouteOptionsFragmentListener(net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener) PointDescription(net.osmand.data.PointDescription) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location)

Example 20 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker in project Osmand by osmandapp.

the class PlanRouteFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final MapActivity mapActivity = getMapActivity();
    markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
    planRouteContext = markersHelper.getPlanRouteContext();
    planRouteContext.setListener(new MarkersPlanRouteContext.PlanRouteProgressListener() {

        @Override
        public void showProgressBar() {
            PlanRouteFragment.this.showProgressBar();
        }

        @Override
        public void updateProgress(int progress) {
            ((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setProgress(progress);
        }

        @Override
        public void hideProgressBar(boolean canceled) {
            mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
            planRouteContext.setProgressBarVisible(false);
            if (!canceled && portrait && planRouteContext.isMarkersListOpened()) {
                Snackbar.make(mainView, getString(R.string.route_is_calculated) + ":", Snackbar.LENGTH_LONG).setAction(R.string.show_map, new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        showHideMarkersList();
                    }
                }).show();
            }
        }

        @Override
        public void refresh() {
            adapter.notifyDataSetChanged();
            mapActivity.refreshMap();
        }

        @Override
        public void updateText() {
            PlanRouteFragment.this.updateText();
        }

        @Override
        public void showMarkersRouteOnMap(boolean adjustMap) {
            PlanRouteFragment.this.showMarkersRouteOnMap(adjustMap);
        }
    });
    // Handling screen rotation
    FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
    Fragment snapToRoadFragment = fragmentManager.findFragmentByTag(SnapToRoadBottomSheetDialogFragment.TAG);
    if (snapToRoadFragment != null) {
        ((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener());
    }
    Fragment optionsFragment = fragmentManager.findFragmentByTag(PlanRouteOptionsBottomSheetDialogFragment.TAG);
    if (optionsFragment != null) {
        ((PlanRouteOptionsBottomSheetDialogFragment) optionsFragment).setListener(createOptionsFragmentListener());
    }
    toolbarHeight = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
    nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final int backgroundColor = ContextCompat.getColor(mapActivity, nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
    portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
    fullScreen = portrait && planRouteContext.isMarkersListOpened();
    int layoutRes = fullScreen ? R.layout.fragment_plan_route_full_screen : R.layout.fragment_plan_route_half_screen;
    View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), layoutRes, null);
    mainView = fullScreen ? view : view.findViewById(R.id.main_view);
    enterPlanRouteMode();
    View markersListContainer = mainView.findViewById(R.id.markers_list_container);
    if (markersListContainer != null) {
        markersListContainer.setBackgroundColor(backgroundColor);
    }
    if (portrait) {
        mainView.findViewById(R.id.toolbar_divider).setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
        Drawable arrow = getContentIcon(fullScreen ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up);
        ((ImageView) mainView.findViewById(R.id.up_down_icon)).setImageDrawable(arrow);
        mainView.findViewById(R.id.up_down_row).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                showHideMarkersList();
            }
        });
        mainView.findViewById(R.id.select_all_button).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                selectAllOnClick();
                updateSelectButton();
            }
        });
        toolbarController = new PlanRouteToolbarController();
        toolbarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
        toolbarController.setTitle(getString(R.string.plan_route));
        toolbarController.setOnBackButtonClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (quit(false)) {
                    MapMarkersDialogFragment.showInstance(mapActivity);
                }
            }
        });
        toolbarController.setSaveViewTextId(R.string.shared_string_options);
        toolbarController.setOnSaveViewClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                optionsOnClick();
            }
        });
        mapActivity.showTopToolbar(toolbarController);
        if (fullScreen) {
            mapActivity.findViewById(R.id.bottom_controls_container).setVisibility(View.GONE);
            mainView.findViewById(R.id.plan_route_toolbar).setVisibility(View.VISIBLE);
            mainView.findViewById(R.id.toolbar_divider).setVisibility(View.VISIBLE);
        } else {
            final int screenH = AndroidUtils.getScreenHeight(mapActivity);
            final int statusBarH = AndroidUtils.getStatusBarHeight(mapActivity);
            final int navBarH = AndroidUtils.getNavBarHeight(mapActivity);
            final int availableHeight = (screenH - statusBarH - navBarH) / 2;
            mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    int upDownRowH = mainView.findViewById(R.id.up_down_row).getHeight();
                    closedListContainerHeight = availableHeight - upDownRowH;
                    View listContainer = mainView.findViewById(R.id.markers_list_container);
                    listContainer.getLayoutParams().height = closedListContainerHeight;
                    listContainer.requestLayout();
                    ViewTreeObserver obs = mainView.getViewTreeObserver();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        obs.removeOnGlobalLayoutListener(this);
                    } else {
                        obs.removeGlobalOnLayoutListener(this);
                    }
                }
            });
        }
    }
    Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.plan_route_toolbar);
    toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (quit(false)) {
                MapMarkersDialogFragment.showInstance(mapActivity);
            }
        }
    });
    mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            optionsOnClick();
        }
    });
    markersRv = mainView.findViewById(R.id.markers_recycler_view);
    adapter = new MapMarkersListAdapter(mapActivity);
    adapter.setHasStableIds(true);
    adapter.setSnappedToRoadPoints(planRouteContext.getSnappedToRoadPoints());
    final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter));
    touchHelper.attachToRecyclerView(markersRv);
    adapter.setAdapterListener(new MapMarkersListAdapter.MapMarkersListAdapterListener() {

        private int fromPosition;

        private int toPosition;

        @Override
        public void onDisableRoundTripClick() {
            roundTripOnClick();
        }

        @Override
        public void onCheckBoxClick(View view) {
            int pos = markersRv.getChildAdapterPosition(view);
            if (pos == RecyclerView.NO_POSITION) {
                return;
            }
            Object item = adapter.getItem(pos);
            if (item instanceof Location) {
                markersHelper.setStartFromMyLocation(!mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get());
            } else if (item instanceof MapMarker) {
                MapMarker marker = (MapMarker) item;
                selectedCount = marker.selected ? selectedCount - 1 : selectedCount + 1;
                marker.selected = !marker.selected;
                markersHelper.updateMapMarker(marker, false);
            }
            adapter.reloadData();
            adapter.notifyDataSetChanged();
            updateSelectButton();
            planRouteContext.recreateSnapTrkSegment(false);
        }

        @Override
        public void onItemClick(View v) {
            int pos = markersRv.getChildAdapterPosition(v);
            if (pos == RecyclerView.NO_POSITION) {
                return;
            }
            Object item = adapter.getItem(pos);
            if (item instanceof Location) {
                Location loc = (Location) item;
                moveMapToPosition(loc.getLatitude(), loc.getLongitude());
            } else if (item instanceof MapMarker) {
                MapMarker marker = (MapMarker) item;
                moveMapToPosition(marker.getLatitude(), marker.getLongitude());
            }
        }

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

        @Override
        public void onDragEnded(RecyclerView.ViewHolder holder) {
            toPosition = holder.getAdapterPosition();
            if (toPosition >= 0 && fromPosition >= 0) {
                mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded();
                mapActivity.refreshMap();
                adapter.reloadData();
                try {
                    adapter.notifyDataSetChanged();
                } catch (Exception e) {
                // to avoid crash because of:
                // java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
                }
                planRouteContext.recreateSnapTrkSegment(false);
            }
        }
    });
    markersRv.setPadding(0, (int) mapActivity.getResources().getDimension(R.dimen.map_markers_recycler_view_padding_top), 0, (int) mapActivity.getResources().getDimension(R.dimen.map_markers_recycler_view_padding_bottom));
    markersRv.setClipToPadding(false);
    markersRv.setLayoutManager(new LinearLayoutManager(getContext()));
    markersRv.setAdapter(adapter);
    if (planRouteContext.isProgressBarVisible()) {
        showProgressBar();
    }
    return view;
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Fragment(android.support.v4.app.Fragment) SnapToRoadBottomSheetDialogFragment(net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment) BaseOsmAndFragment(net.osmand.plus.base.BaseOsmAndFragment) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MapMarkersItemTouchHelperCallback(net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) MapActivity(net.osmand.plus.activities.MapActivity) SnapToRoadBottomSheetDialogFragment(net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment) Toolbar(android.support.v7.widget.Toolbar) Drawable(android.graphics.drawable.Drawable) MapMarkersListAdapter(net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RecyclerView(android.support.v7.widget.RecyclerView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) FragmentManager(android.support.v4.app.FragmentManager) ContextThemeWrapper(android.view.ContextThemeWrapper) RecyclerView(android.support.v7.widget.RecyclerView) Location(net.osmand.Location) Nullable(android.support.annotation.Nullable)

Aggregations

MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)38 LatLon (net.osmand.data.LatLon)20 View (android.view.View)13 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)11 RecyclerView (android.support.v7.widget.RecyclerView)10 OsmandApplication (net.osmand.plus.OsmandApplication)10 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)9 ImageView (android.widget.ImageView)8 Location (net.osmand.Location)8 PointDescription (net.osmand.data.PointDescription)8 Paint (android.graphics.Paint)7 Nullable (android.support.annotation.Nullable)6 MapActivity (net.osmand.plus.activities.MapActivity)6 ArrayList (java.util.ArrayList)5 Amenity (net.osmand.data.Amenity)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)4 FavouritePoint (net.osmand.data.FavouritePoint)4 QuadPoint (net.osmand.data.QuadPoint)4 Bitmap (android.graphics.Bitmap)3