Search in sources :

Example 6 with MapMarkersHelper

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

the class MapMarkersDialogFragment method createOptionsFragmentListener.

private MarkerOptionsFragmentListener createOptionsFragmentListener() {
    return new MarkerOptionsFragmentListener() {

        final MapActivity mapActivity = getMapActivity();

        @Override
        public void sortByOnClick() {
            if (mapActivity != null) {
                OrderByBottomSheetDialogFragment fragment = new OrderByBottomSheetDialogFragment();
                fragment.setUsedOnMap(false);
                fragment.setListener(createOrderByFragmentListener());
                fragment.show(getChildFragmentManager(), OrderByBottomSheetDialogFragment.TAG);
            }
        }

        @Override
        public void showDirectionOnClick() {
            if (mapActivity != null) {
                DirectionIndicationDialogFragment fragment = new DirectionIndicationDialogFragment();
                fragment.setListener(createShowDirectionFragmentListener());
                fragment.show(getChildFragmentManager(), DirectionIndicationDialogFragment.TAG);
            }
        }

        @Override
        public void coordinateInputOnClick() {
            if (mapActivity != null) {
                CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment();
                fragment.setRetainInstance(true);
                fragment.setListener(createOnMapMarkersSavedListener());
                fragment.show(getChildFragmentManager(), CoordinateInputDialogFragment.TAG);
            }
        }

        @Override
        public void buildRouteOnClick() {
            if (mapActivity != null) {
                if (mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers().isEmpty()) {
                    Toast.makeText(mapActivity, getString(R.string.plan_route_no_markers_toast), Toast.LENGTH_SHORT).show();
                } else {
                    PlanRouteFragment.showInstance(mapActivity);
                    MapMarkersDialogFragment.this.dismiss();
                }
            }
        }

        @Override
        public void saveAsNewTrackOnClick() {
            if (mapActivity != null) {
                if (mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers().isEmpty()) {
                    Toast.makeText(mapActivity, getString(R.string.plan_route_no_markers_toast), Toast.LENGTH_SHORT).show();
                } else {
                    SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment();
                    fragment.setListener(createSaveAsTrackFragmentListener());
                    fragment.show(getChildFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG);
                }
            }
        }

        @Override
        public void moveAllToHistoryOnClick() {
            if (mapActivity != null) {
                final MapMarkersHelper helper = mapActivity.getMyApplication().getMapMarkersHelper();
                final List<MapMarkersHelper.MapMarker> markers = new ArrayList<>(helper.getMapMarkers());
                helper.moveAllActiveMarkersToHistory();
                if (viewPager.getCurrentItem() == ACTIVE_MARKERS_POSITION) {
                    activeFragment.updateAdapter();
                } else {
                    groupsFragment.updateAdapter();
                }
                snackbar = Snackbar.make(viewPager, R.string.all_markers_moved_to_history, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        helper.restoreMarkersFromHistory(markers);
                        if (viewPager.getCurrentItem() == ACTIVE_MARKERS_POSITION) {
                            activeFragment.updateAdapter();
                        } else {
                            groupsFragment.updateAdapter();
                        }
                    }
                });
                AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
                snackbar.show();
            }
        }

        @Override
        public void dismiss() {
            restoreSelectedNavItem();
        }
    };
}
Also used : MarkerOptionsFragmentListener(net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) ArrayList(java.util.ArrayList) View(android.view.View) BottomNavigationView(android.support.design.widget.BottomNavigationView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 7 with MapMarkersHelper

use of net.osmand.plus.MapMarkersHelper 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 8 with MapMarkersHelper

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

the class MapMarkersGroupsAdapter method createDisplayGroups.

private void createDisplayGroups() {
    items = new ArrayList<>();
    MapMarkersHelper helper = app.getMapMarkersHelper();
    helper.updateGroups();
    List<MapMarkersGroup> groups = new ArrayList<>(helper.getMapMarkersGroups());
    groups.addAll(helper.getGroupsForDisplayedGpx());
    for (int i = 0; i < groups.size(); i++) {
        MapMarkersGroup group = groups.get(i);
        if (!group.isVisible()) {
            continue;
        }
        String markerGroupName = group.getName();
        if (markerGroupName == null) {
            int previousDateHeader = -1;
            int monthsDisplayed = 0;
            Calendar currentDateCalendar = Calendar.getInstance();
            currentDateCalendar.setTimeInMillis(System.currentTimeMillis());
            int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR);
            int currentMonth = currentDateCalendar.get(Calendar.MONTH);
            int currentYear = currentDateCalendar.get(Calendar.YEAR);
            Calendar markerCalendar = Calendar.getInstance();
            List<MapMarker> groupMarkers = group.getActiveMarkers();
            for (int j = 0; j < groupMarkers.size(); j++) {
                MapMarker marker = groupMarkers.get(j);
                markerCalendar.setTimeInMillis(marker.creationDate);
                int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR);
                int markerMonth = markerCalendar.get(Calendar.MONTH);
                int markerYear = markerCalendar.get(Calendar.YEAR);
                if (markerYear == currentYear) {
                    if (markerDay == currentDay && previousDateHeader != TODAY_HEADER) {
                        items.add(TODAY_HEADER);
                        previousDateHeader = TODAY_HEADER;
                    } else if (markerDay == currentDay - 1 && previousDateHeader != YESTERDAY_HEADER) {
                        items.add(YESTERDAY_HEADER);
                        previousDateHeader = YESTERDAY_HEADER;
                    } else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousDateHeader != LAST_SEVEN_DAYS_HEADER) {
                        items.add(LAST_SEVEN_DAYS_HEADER);
                        previousDateHeader = LAST_SEVEN_DAYS_HEADER;
                    } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousDateHeader != markerMonth) {
                        items.add(markerMonth);
                        previousDateHeader = markerMonth;
                        monthsDisplayed += 1;
                    } else if (currentMonth - markerMonth >= 4 && previousDateHeader != THIS_YEAR_HEADER) {
                        items.add(THIS_YEAR_HEADER);
                        previousDateHeader = THIS_YEAR_HEADER;
                    }
                } else if (previousDateHeader != markerYear) {
                    items.add(markerYear);
                    previousDateHeader = markerYear;
                }
                items.add(marker);
            }
        } else {
            GroupHeader header = group.getGroupHeader();
            items.add(header);
            populateAdapterWithGroupMarkers(group, getItemCount());
        }
    }
}
Also used : MapMarkersHelper(net.osmand.plus.MapMarkersHelper) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) Calendar(java.util.Calendar) GroupHeader(net.osmand.plus.MapMarkersHelper.GroupHeader) ArrayList(java.util.ArrayList) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup)

Example 9 with MapMarkersHelper

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

the class TrackPointFragment method syncGpx.

private void syncGpx(GPXFile gpxFile) {
    File gpx = new File(gpxFile.path);
    if (gpx.exists()) {
        MapMarkersHelper helper = app.getMapMarkersHelper();
        helper.runSynchronization(helper.getOrCreateGroup(gpx));
    }
}
Also used : MapMarkersHelper(net.osmand.plus.MapMarkersHelper) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File)

Example 10 with MapMarkersHelper

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

the class TrackPointFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    getTrackActivity().getClearToolbar(false);
    MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark, R.drawable.ic_action_search_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    searchView = new SearchView(getActivity());
    FavoritesActivity.updateSearchView(getActivity(), searchView);
    MenuItemCompat.setActionView(mi, searchView);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            adapter.getFilter().filter(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            adapter.getFilter().filter(newText);
            return true;
        }
    });
    MenuItemCompat.setOnActionExpandListener(mi, new MenuItemCompat.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            adapter.setFilterResults(null);
            adapter.synchronizeGroups(filterGroups());
            adapter.notifyDataSetChanged();
            // Needed to hide intermediate progress bar after closing action mode
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    hideProgressBar();
                }
            }, 100);
            return true;
        }
    });
    if (!MenuItemCompat.isActionViewExpanded(mi)) {
        final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
        final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(getGpxDataItem().getFile());
        final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
        createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
        createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag_dark, R.drawable.ic_action_flag_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
        createMenuItem(menu, SELECT_FAVORITES_ID, R.string.shared_string_add_to_favorites, R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
        createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
    }
    this.optionsMenu = menu;
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) SearchView(android.support.v7.widget.SearchView) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) Handler(android.os.Handler) MenuItem(android.view.MenuItem) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup)

Aggregations

MapMarkersHelper (net.osmand.plus.MapMarkersHelper)21 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)10 LatLon (net.osmand.data.LatLon)9 MapMarkersGroup (net.osmand.plus.MapMarkersHelper.MapMarkersGroup)7 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)6 View (android.view.View)5 PointDescription (net.osmand.data.PointDescription)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Paint (android.graphics.Paint)3 ImageView (android.widget.ImageView)3 Location (net.osmand.Location)3 FavouritePoint (net.osmand.data.FavouritePoint)3 QuadPoint (net.osmand.data.QuadPoint)3 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)3 DialogInterface (android.content.DialogInterface)2 Bundle (android.os.Bundle)2 AlertDialog (android.support.v7.app.AlertDialog)2 SearchView (android.support.v7.widget.SearchView)2 TextView (android.widget.TextView)2