use of net.osmand.plus.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackPointFragment method selectFavoritesImpl.
private void selectFavoritesImpl() {
if (getSelectedItemsCount() > 0) {
AlertDialog.Builder b = new AlertDialog.Builder(getTrackActivity());
final EditText editText = new EditText(getTrackActivity());
String name = getSelectedItems().iterator().next().group.getName();
if (name.indexOf('\n') > 0) {
name = name.substring(0, name.indexOf('\n'));
}
editText.setText(name);
int leftMargin = AndroidUtils.dpToPx(getContext(), 16f);
int topMargin = AndroidUtils.dpToPx(getContext(), 8f);
editText.setPadding(leftMargin, topMargin, leftMargin, topMargin);
b.setTitle(R.string.save_as_favorites_points);
b.setView(editText);
b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (actionMode != null) {
actionMode.finish();
}
FavouritesDbHelper fdb = app.getFavorites();
for (GpxDisplayItem i : getSelectedItems()) {
if (i.locationStart != null) {
FavouritePoint fp = new FavouritePoint(i.locationStart.lat, i.locationStart.lon, i.name, editText.getText().toString());
if (!Algorithms.isEmpty(i.description)) {
fp.setDescription(i.description);
}
fdb.addFavourite(fp, false);
}
}
fdb.saveCurrentPointsIntoFile();
MapActivity.launchMapActivityMoveToTop(getActivity());
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.show();
}
}
use of net.osmand.plus.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class TrackPointFragment method onChildClick.
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (selectionMode) {
CheckBox ch = (CheckBox) v.findViewById(R.id.toggle_item);
GpxDisplayItem item = adapter.getChild(groupPosition, childPosition);
ch.setChecked(!ch.isChecked());
if (ch.isChecked()) {
Set<GpxDisplayItem> set = selectedItems.get(item.group.getType());
if (set != null) {
set.add(item);
} else {
set = new LinkedHashSet<>();
set.add(item);
selectedItems.put(item.group.getType(), set);
}
} else {
Set<GpxDisplayItem> set = selectedItems.get(item.group.getType());
if (set != null) {
set.remove(item);
}
}
updateSelectionMode(actionMode);
} else {
final GpxDisplayItem item = adapter.getChild(groupPosition, childPosition);
if (item != null) {
if (item.group.getGpx() != null) {
app.getSelectedGpxHelper().setGpxFileToDisplay(item.group.getGpx());
}
final OsmandSettings settings = app.getSettings();
LatLon location = new LatLon(item.locationStart.lat, item.locationStart.lon);
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, item.name), false, item.locationStart);
MapActivity.launchMapActivityMoveToTop(getActivity());
}
}
return true;
}
use of net.osmand.plus.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class MapActivity method readLocationToShow.
public void readLocationToShow() {
if (!getDashboard().isVisible()) {
mapLayers.getMapControlsLayer().showMapControlsIfHidden();
}
LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude());
LatLon latLonToShow = settings.getAndClearMapLocationToShow();
PointDescription mapLabelToShow = settings.getAndClearMapLabelToShow(latLonToShow);
Object toShow = settings.getAndClearObjectToShow();
boolean editToShow = settings.getAndClearEditObjectToShow();
int status = settings.isRouteToPointNavigateAndClear();
String searchRequestToShow = settings.getAndClearSearchRequestToShow();
if (status != 0) {
// always enable and follow and let calculate it (i.e.GPS is not accessible in a garage)
Location loc = new Location("map");
loc.setLatitude(mapView.getLatitude());
loc.setLongitude(mapView.getLongitude());
getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true);
if (dashboardOnMap.isVisible()) {
dashboardOnMap.hideDashboard();
}
}
if (searchRequestToShow != null) {
showQuickSearch(searchRequestToShow);
}
if (latLonToShow != null) {
if (dashboardOnMap.isVisible()) {
dashboardOnMap.hideDashboard();
}
// remember if map should come back to isMapLinkedToLocation=true
mapViewTrackingUtilities.setMapLinkedToLocation(false);
if (mapLabelToShow != null && !mapLabelToShow.contextMenuDisabled()) {
mapContextMenu.setMapCenter(latLonToShow);
mapContextMenu.setMapPosition(mapView.getMapPosition());
mapContextMenu.setCenterMarker(true);
RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
LatLon prevCenter = tb.getCenterLatLon();
double border = 0.8;
int tbw = (int) (tb.getPixWidth() * border);
int tbh = (int) (tb.getPixHeight() * border);
tb.setPixelDimensions(tbw, tbh);
tb.setLatLonCenter(latLonToShow.getLatitude(), latLonToShow.getLongitude());
tb.setZoom(ZOOM_LABEL_DISPLAY);
while (!tb.containsLatLon(prevCenter.getLatitude(), prevCenter.getLongitude()) && tb.getZoom() > MIN_ZOOM_LABEL_DISPLAY) {
tb.setZoom(tb.getZoom() - 1);
}
// mapContextMenu.setMapZoom(settings.getMapZoomToShow());
mapContextMenu.setMapZoom(tb.getZoom());
if (toShow instanceof GpxDisplayItem) {
TrackDetailsMenu trackDetailsMenu = mapLayers.getMapControlsLayer().getTrackDetailsMenu();
trackDetailsMenu.setGpxItem((GpxDisplayItem) toShow);
trackDetailsMenu.show();
} else if (MapRouteInfoMenu.isVisible()) {
mapContextMenu.showMinimized(latLonToShow, mapLabelToShow, toShow);
mapLayers.getMapControlsLayer().getMapRouteInfoMenu().updateMenu();
MapRouteInfoMenu.showLocationOnMap(this, latLonToShow.getLatitude(), latLonToShow.getLongitude());
} else if (toShow instanceof QuadRect) {
QuadRect qr = (QuadRect) toShow;
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
} else if (toShow instanceof NewGpxPoint) {
NewGpxPoint newGpxPoint = (NewGpxPoint) toShow;
QuadRect qr = newGpxPoint.getRect();
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint);
} else if (toShow instanceof NewGpxData) {
NewGpxData newGpxData = (NewGpxData) toShow;
QuadRect qr = newGpxData.getRect();
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
MeasurementEditingContext editingContext = new MeasurementEditingContext();
editingContext.setNewGpxData(newGpxData);
MeasurementToolFragment.showInstance(getSupportFragmentManager(), editingContext);
} else {
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
}
if (editToShow) {
mapContextMenu.openEditor();
}
} else if (!latLonToShow.equals(cur)) {
mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), latLonToShow.getLongitude(), settings.getMapZoomToShow(), true);
}
}
}
use of net.osmand.plus.GpxSelectionHelper.GpxDisplayItem in project Osmand by osmandapp.
the class GPXLayer method drawSplitItems.
private void drawSplitItems(Canvas canvas, RotatedTileBox tileBox, List<GpxDisplayItem> items, DrawSettings settings) {
final QuadRect latLonBounds = tileBox.getLatLonBounds();
int r = (int) (12 * tileBox.getDensity());
paintTextIcon.setTextSize(r);
int dr = r * 3 / 2;
int px = -1;
int py = -1;
for (int k = 0; k < items.size(); k++) {
GpxDisplayItem i = items.get(k);
WptPt o = i.locationEnd;
if (o != null && o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top && o.lon >= latLonBounds.left && o.lon <= latLonBounds.right) {
int x = (int) tileBox.getPixXFromLatLon(o.lat, o.lon);
int y = (int) tileBox.getPixYFromLatLon(o.lat, o.lon);
if (px != -1 || py != -1) {
if (Math.abs(x - px) <= dr && Math.abs(y - py) <= dr) {
continue;
}
}
px = x;
py = y;
String nm = i.splitName;
if (nm != null) {
int ind = nm.indexOf(' ');
if (ind > 0) {
nm = nm.substring(0, ind);
}
Rect bounds = new Rect();
paintTextIcon.getTextBounds(nm, 0, nm.length(), bounds);
int nmWidth = bounds.width();
int nmHeight = bounds.height();
RectF rect = new RectF(x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), y + nmHeight / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), x + nmWidth / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), y - nmHeight / 2 - 2 * (float) Math.ceil(tileBox.getDensity()));
canvas.drawRoundRect(rect, 0, 0, paintInnerRect);
canvas.drawRoundRect(rect, 0, 0, paintOuterRect);
// canvas.drawRect(rect, paintInnerRect);
// canvas.drawRect(rect, paintOuterRect);
canvas.drawText(nm, x, y + nmHeight / 2, paintTextIcon);
}
}
}
}
Aggregations