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();
}
};
}
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)));
}
}
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());
}
}
}
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));
}
}
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;
}
Aggregations