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; package net.osmand.data;
import net.osmand.FloatMath;
import java.io.Serializable; import java.io.Serializable;
public class LatLon implements Serializable { public class LatLon implements Serializable {
@ -32,10 +34,17 @@ public class LatLon implements Serializable {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
LatLon other = (LatLon) obj; 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)) if (Double.doubleToLongBits(latitude) != Double.doubleToLongBits(other.latitude))
return false; return false;
if (Double.doubleToLongBits(longitude) != Double.doubleToLongBits(other.longitude)) if (Double.doubleToLongBits(longitude) != Double.doubleToLongBits(other.longitude))
return false; return false;
*/
return true; return true;
} }

View file

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

View file

@ -39,6 +39,8 @@
android:layout_marginLeft="12dp" android:layout_marginLeft="12dp"
android:layout_marginRight="12dp" android:layout_marginRight="12dp"
android:text="@string/search_address_building" android:text="@string/search_address_building"
android:maxLines="3"
android:ellipsize="end"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size_large"/> 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_TARGET = "destination";
public static final String POINT_TYPE_OSM_BUG = "bug"; 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_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, ""); 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.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -137,6 +136,31 @@ public class GPXUtilities {
return true; 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 { 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) { 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.lat = lat;
pt.lon = lon; pt.lon = lon;
pt.time = time; pt.time = time;
@ -617,6 +643,10 @@ public class GPXUtilities {
if (color != 0) { if (color != 0) {
pt.setColor(color); pt.setColor(color);
} }
if (index != -1) {
points.set(index, pt);
}
} }
public boolean deleteWptPt(WptPt pt) { public boolean deleteWptPt(WptPt pt) {

View file

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

View file

@ -9,6 +9,8 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.WptPt; 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.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint; 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.AudioVideoNoteMenuController;
import net.osmand.plus.mapcontextmenu.controllers.EditPOIMenuController; import net.osmand.plus.mapcontextmenu.controllers.EditPOIMenuController;
import net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController; 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.HistoryMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController; import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController; 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); menuController = new MapDataMenuController(app, mapActivity, pointDescription, (BinaryMapDataObject) object);
} else if (object instanceof OpenStreetNote) { } else if (object instanceof OpenStreetNote) {
menuController = new OsmBugMenuController(app, mapActivity, pointDescription, (OpenStreetNote) object); 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) { } else if (object instanceof LatLon) {
if (pointDescription.isParking()) { if (pointDescription.isParking()) {
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription); 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); 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; saved = true;
} }

View file

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

View file

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