Context menu - wpt fixes

This commit is contained in:
Alexey Kulish 2015-11-15 19:02:25 +03:00
parent f61bcd9bb8
commit 4370d673ed
11 changed files with 138 additions and 28 deletions

View file

@ -1,5 +1,7 @@
package net.osmand.data;
import net.osmand.FloatMath;
import java.io.Serializable;
public class LatLon implements Serializable {
@ -32,10 +34,17 @@ public class LatLon implements Serializable {
if (getClass() != obj.getClass())
return false;
LatLon other = (LatLon) obj;
if (Float.floatToIntBits((float) latitude) != Float.floatToIntBits((float) other.latitude))
return false;
if (Float.floatToIntBits((float) longitude) != Float.floatToIntBits((float) other.longitude))
return false;
/*
if (Double.doubleToLongBits(latitude) != Double.doubleToLongBits(other.latitude))
return false;
if (Double.doubleToLongBits(longitude) != Double.doubleToLongBits(other.longitude))
return false;
*/
return true;
}

View file

@ -74,7 +74,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_address_building"
android:maxLines="8"
android:maxLines="6"
android:ellipsize="end"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size_large"/>

View file

@ -39,6 +39,8 @@
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:text="@string/search_address_building"
android:maxLines="3"
android:ellipsize="end"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size_large"/>

View file

@ -40,6 +40,7 @@ public class PointDescription {
public static final String POINT_TYPE_TARGET = "destination";
public static final String POINT_TYPE_OSM_BUG = "bug";
public static final String POINT_TYPE_WORLD_REGION = "world_region";
public static final String POINT_TYPE_GPX_ITEM = "gpx_item";
public static final PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, "");

View file

@ -6,7 +6,6 @@ import android.graphics.Color;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription;
import net.osmand.util.Algorithms;
@ -137,6 +136,31 @@ public class GPXUtilities {
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((category == null) ? 0 : category.hashCode());
result = prime * result + ((desc == null) ? 0 : desc.hashCode());
result = prime * result + ((lat == 0) ? 0 : Double.valueOf(lat).hashCode());
result = prime * result + ((lon == 0) ? 0 : Double.valueOf(lon).hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
WptPt other = (WptPt) obj;
return Algorithms.objectEquals(other.name, name)
&& Algorithms.objectEquals(other.category, category)
&& Algorithms.objectEquals(other.lat, lat)
&& Algorithms.objectEquals(other.lon, lon)
&& Algorithms.objectEquals(other.desc, desc);
}
}
public static class TrkSegment extends GPXExtensions {
@ -608,6 +632,8 @@ public class GPXUtilities {
}
public void updateWptPt(WptPt pt, double lat, double lon, long time, String description, String name, String category, int color) {
int index = points.indexOf(pt);
pt.lat = lat;
pt.lon = lon;
pt.time = time;
@ -617,6 +643,10 @@ public class GPXUtilities {
if (color != 0) {
pt.setColor(color);
}
if (index != -1) {
points.set(index, pt);
}
}
public boolean deleteWptPt(WptPt pt) {

View file

@ -1,8 +1,6 @@
package net.osmand.plus;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import android.graphics.Bitmap;
import net.osmand.IProgress;
import net.osmand.plus.GPXUtilities.GPXFile;
@ -11,7 +9,6 @@ import net.osmand.plus.GPXUtilities.Route;
import net.osmand.plus.GPXUtilities.Track;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.helpers.GpxUiHelper;
@ -21,7 +18,9 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.graphics.Bitmap;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class GpxSelectionHelper {
@ -55,11 +54,8 @@ public class GpxSelectionHelper {
public SelectedGpxFile getSelectedGPXFile(WptPt point) {
for (SelectedGpxFile g : selectedGPXFiles) {
List<WptPt> pts = g.getGpxFile().points;
for (WptPt n : pts) {
if (n == point) {
return g;
}
if (g.getGpxFile().points.contains(point)) {
return g;
}
}
return null;
@ -199,6 +195,7 @@ public class GpxSelectionHelper {
item.description = GpxUiHelper.getDescription(app, analysis, true);
item.analysis = analysis;
/*
String name = "";
// if(group.track.segments.size() > 1) {
// name += t++ + ". ";
@ -241,7 +238,8 @@ public class GpxSelectionHelper {
OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app));
}
}
item.name = name;
*/
item.name = group.getName();//.replace("\n", "");
item.locationStart = analysis.locationStart;
item.locationEnd = analysis.locationEnd;
list.add(item);

View file

@ -9,6 +9,8 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@ -19,6 +21,7 @@ import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController;
import net.osmand.plus.mapcontextmenu.controllers.AudioVideoNoteMenuController;
import net.osmand.plus.mapcontextmenu.controllers.EditPOIMenuController;
import net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController;
import net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController;
import net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController;
@ -93,6 +96,8 @@ public abstract class MenuController extends BaseMenuController {
menuController = new MapDataMenuController(app, mapActivity, pointDescription, (BinaryMapDataObject) object);
} else if (object instanceof OpenStreetNote) {
menuController = new OsmBugMenuController(app, mapActivity, pointDescription, (OpenStreetNote) object);
} else if (object instanceof GpxDisplayItem) {
menuController = new GpxItemMenuController(app, mapActivity, pointDescription, (GpxDisplayItem) object);
} else if (object instanceof LatLon) {
if (pointDescription.isParking()) {
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription);

View file

@ -0,0 +1,53 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import net.osmand.data.PointDescription;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
public class GpxItemMenuController extends MenuController {
private GpxDisplayItem item;
public GpxItemMenuController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, GpxDisplayItem item) {
super(new MenuBuilder(app), pointDescription, mapActivity);
this.item = item;
}
@Override
protected void setObject(Object object) {
if (object instanceof GpxDisplayItem) {
this.item = (GpxDisplayItem) object;
}
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
}
@Override
public String getTypeStr() {
return getPointDescription().getTypeName();
}
@Override
public String getCommonTypeStr() {
return getMapActivity().getString(R.string.gpx_selection_segment_title);
}
@Override
public boolean needStreetName() {
return false;
}
@Override
public Drawable getLeftIcon() {
return getIcon(R.drawable.ic_action_polygom_dark, R.color.osmand_orange);
}
}

View file

@ -104,6 +104,12 @@ public class WptPtEditorFragment extends PointEditorFragment {
menu.update(latLon, wpt.getPointDescription(getMapActivity()), wpt);
}
if (editor.isNew() && selectedGpxFile == null) {
selectedGpxHelper.setGpxFileToDisplay(savingTrackHelper.getCurrentGpx());
} else if (selectedGpxFile != null) {
selectedGpxHelper.setGpxFileToDisplay(selectedGpxFile.getGpxFile());
}
saved = true;
}

View file

@ -480,14 +480,26 @@ public class SelectedGPXFragment extends OsmAndListFragment {
GpxDisplayItem child = adapter.getItem(position);
if (child.group.getGpx() != null) {
app.getSelectedGpxHelper().setGpxFileToDisplay(child.group.getGpx());
}
final OsmandSettings settings = app.getSettings();
LatLon location = new LatLon(child.locationStart.lat, child.locationStart.lon);
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, Html.fromHtml(child.name).toString()),
false,
child.locationStart); //$NON-NLS-1$
if (child.group.getType() == GpxDisplayItemType.TRACK_POINTS) {
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_WPT, child.locationStart.name),
false,
child.locationStart);
} else {
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_GPX_ITEM, child.name),
false,
child);
}
MapActivity.launchMapActivityMoveToTop(getActivity());
/*
// if(child.group.getType() == GpxDisplayItemType.TRACK_POINTS ||

View file

@ -79,27 +79,21 @@ public class ContextMenuLayer extends OsmandMapLayer {
contextMarker.layout(0, 0, minw, minh);
}
public boolean isVisible() {
return menu.isActive();
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (menu.isActive()) {
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
if(menu.isActive()) {
LatLon latLon = menu.getLatLon();
int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight());
contextMarker.draw(canvas);
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
}
public void setSelectOnMap(CallbackWithObject<LatLon> selectOnMap) {
this.selectOnMap = selectOnMap;
}