Skip to content

Commit

Permalink
fix #1957 open MarkerEditActivity to receive external marker (#1960)
Browse files Browse the repository at this point in the history
* fix #1957 add CreateMarkerActivity to receive external marker
  • Loading branch information
pstorch authored Jul 30, 2024
1 parent d8acf7d commit 389c4be
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public static TrackData createTestingTrack(Track.Id trackId) {
stats.setTotalDistance(Distance.of(0));
stats.setTotalTime(Duration.ofMillis(0));
List<Marker> markers = List.of(
new Marker("Marker 1", "Marker description 1", "Marker category 3", "", trackId, stats, trackPoints.get(1), null),
new Marker("Marker 2", "Marker description 2", "Marker category 3", "", trackId, stats, trackPoints.get(4), null),
new Marker("Marker 3", "Marker description 3", "Marker category 3", "", trackId, stats, trackPoints.get(5), null)
new Marker("Marker 1", "Marker description 1", "Marker category 3", "", trackId, trackPoints.get(1), null),
new Marker("Marker 2", "Marker description 2", "Marker category 3", "", trackId, trackPoints.get(4), null),
new Marker("Marker 3", "Marker description 3", "Marker category 3", "", trackId, trackPoints.get(5), null)
);

return new TrackData(track, trackPoints, markers);
Expand Down Expand Up @@ -152,7 +152,7 @@ public static Marker createMarkerWithPhoto(Context context, Track.Id trackId, Tr
stats.setTotalDistance(Distance.of(0));
stats.setTotalTime(Duration.ofMillis(0));

return new Marker("Marker name", "Marker description", "Marker category", "", trackId, stats, trackPoint, photoUrl);
return new Marker("Marker name", "Marker description", "Marker category", "", trackId, trackPoint, photoUrl);
}

public static List<TrackPoint> getTrackPoints(ContentProviderUtils contentProviderUtils, Track.Id trackId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void setUp() throws TimeoutException {
Distance sensorDistance = Distance.of(10); // recording distance interval

sendLocation(trackPointCreator, "2020-02-02T02:02:03Z", 3, 14, 10, 13, 15, 10, 1f);
service.insertMarker("Marker 1", "Marker 1 category", "Marker 1 desc", null);
contentProviderUtils.insertMarker(new Marker("Marker 1", "Marker 1 desc", "Marker 1 category", null, trackId, service.getLastStoredTrackPointWithLocation(), ""));

// A sensor-only TrackPoint
trackPointCreator.setClock("2020-02-02T02:02:04Z");
Expand All @@ -154,7 +154,7 @@ public void setUp() throws TimeoutException {
mockSensorData(trackPointCreator, 5f, Distance.of(2), 69f, 3f, 50f, null); // Distance will be added to next TrackPoint

sendLocation(trackPointCreator, "2020-02-02T02:02:17Z", 3, 14.001, 10, 13, 15, 10, 0f);
service.insertMarker("Marker 2", "Marker 2 category", "Marker 2 desc", null);
contentProviderUtils.insertMarker(new Marker("Marker 2", "Marker 2 desc", "Marker 2 category", null, trackId, service.getLastStoredTrackPointWithLocation(), ""));

trackPointCreator.setClock("2020-02-02T02:02:18Z");
trackPointCreator.getSensorManager().sensorDataSet = new SensorDataSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void kml22_with_statistics_marker() throws IOException {
assertEquals(ActivityType.UNKNOWN, importedTrack.getActivityType());

// 2. markers
assertEquals(0, contentProviderUtils.getMarkers(importTrackId).size());
assertEquals(1, contentProviderUtils.getMarkers(importTrackId).size());

// 3. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
Expand Down

This file was deleted.

12 changes: 11 additions & 1 deletion src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,24 @@ limitations under the License.
</activity>

<activity
android:name=".ui.markers.MarkerDetailActivity"
android:name=".publicapi.ShowMarkerActivity"
android:exported="true">
<intent-filter>
<action android:name="de.dennisguse.opentracks.MarkerDetails" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".publicapi.CreateMarkerActivity"
android:exported="true">
<intent-filter>
<action android:name="de.dennisguse.opentracks.CreateMarker" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity android:name=".ui.markers.MarkerDetailActivity" />
<activity android:name=".ui.markers.MarkerEditActivity" />
<activity android:name=".ui.markers.MarkerListActivity" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import de.dennisguse.opentracks.data.TrackDataHub;
import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.databinding.TrackRecordingBinding;
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
import de.dennisguse.opentracks.fragments.StatisticsRecordingFragment;
Expand Down Expand Up @@ -269,9 +270,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

if (item.getItemId() == R.id.track_detail_insert_marker) {
TrackPoint trackPoint = trackRecordingServiceConnection.getTrackRecordingService().getLastStoredTrackPointWithLocation();
if (trackPoint == null) {
return true;
}
Intent intent = IntentUtils
.newIntent(this, MarkerEditActivity.class)
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId);
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId)
.putExtra(MarkerEditActivity.EXTRA_LOCATION, trackPoint.getLocation());
startActivity(intent);
return true;
}
Expand Down
58 changes: 0 additions & 58 deletions src/main/java/de/dennisguse/opentracks/chart/ChartView.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,31 +152,6 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
return true;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent event) {
// Check if the y event is within markerHeight of the marker center
if (Math.abs(event.getY() - topBorder - spacer - markerHeight / 2f) < markerHeight) {
int minDistance = Integer.MAX_VALUE;
Marker nearestMarker = null;
synchronized (markers) {
for (Marker marker : markers) {
int distance = Math.abs(getX(getMarkerXValue(marker)) - (int) event.getX() - getScrollX());
if (distance < minDistance) {
minDistance = distance;
nearestMarker = marker;
}
}
}
if (nearestMarker != null && minDistance < markerWidth) {
Intent intent = IntentUtils.newIntent(getContext(), MarkerDetailActivity.class)
.putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, nearestMarker.getId());
getContext().startActivity(intent);
return true;
}
}

return false;
}
});

private final ScaleGestureDetector detectorZoom = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() {
Expand Down Expand Up @@ -589,7 +564,6 @@ protected void onDraw(Canvas canvas) {

clipToGraphArea(canvas);
drawDataSeries(canvas);
drawMarker(canvas);
drawGrid(canvas);

canvas.restore();
Expand Down Expand Up @@ -630,30 +604,6 @@ private void drawDataSeries(Canvas canvas) {
}
}

private void drawMarker(Canvas canvas) {
synchronized (markers) {
for (Marker marker : markers) {
double xValue = getMarkerXValue(marker);
double markerIconSizeInXaxisUnits = maxX*markerWidth/effectiveWidth / zoomLevel;
if (xValue > maxX + markerIconSizeInXaxisUnits * (1-MARKER_X_ANCHOR)) {
continue; // there is no chance that this marker will be visible
}
canvas.save();
float x = getX(getMarkerXValue(marker));
canvas.drawLine(x, topBorder + spacer + markerHeight / 2, x, topBorder + effectiveHeight, markerPaint);
// if marker is not near the end of the track then draw it normally
if (xValue < maxX - markerIconSizeInXaxisUnits*(1-MARKER_X_ANCHOR)) {
canvas.translate(x - (markerWidth * MARKER_X_ANCHOR), topBorder + spacer);
} else { // marker at the end needs to be drawn mirrored so that it is more visible
canvas.translate(x + (markerWidth * MARKER_X_ANCHOR), topBorder + spacer);
canvas.scale(-1, 1);
}
markerPin.draw(canvas);
canvas.restore();
}
}
}

/**
* Draws the grid.
*
Expand Down Expand Up @@ -1043,14 +993,6 @@ private int getY(ChartValueSeries chartValueSeries, double value) {
return topBorder + yAxisOffset + (int) ((1 - percentage) * rangeHeight);
}

private double getMarkerXValue(Marker marker) {
if (chartByDistance) {
return marker.getLength().toKM_Miles(unitSystem);
} else {
return marker.getDuration().toMillis();
}
}

/**
* Gets a paint's Rect for a string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ public Marker createMarker(Cursor cursor) {
int categoryIndex = cursor.getColumnIndexOrThrow(MarkerColumns.CATEGORY);
int iconIndex = cursor.getColumnIndexOrThrow(MarkerColumns.ICON);
int trackIdIndex = cursor.getColumnIndexOrThrow(MarkerColumns.TRACKID);
int lengthIndex = cursor.getColumnIndexOrThrow(MarkerColumns.LENGTH);
int durationIndex = cursor.getColumnIndexOrThrow(MarkerColumns.DURATION);
int longitudeIndex = cursor.getColumnIndexOrThrow(MarkerColumns.LONGITUDE);
int latitudeIndex = cursor.getColumnIndexOrThrow(MarkerColumns.LATITUDE);
int timeIndex = cursor.getColumnIndexOrThrow(MarkerColumns.TIME);
Expand Down Expand Up @@ -419,13 +417,6 @@ public Marker createMarker(Cursor cursor) {
if (!cursor.isNull(iconIndex)) {
marker.setIcon(cursor.getString(iconIndex));
}
if (!cursor.isNull(lengthIndex)) {
marker.setLength(Distance.of(cursor.getFloat(lengthIndex)));
}
if (!cursor.isNull(durationIndex)) {
marker.setDuration(Duration.ofMillis(cursor.getLong(durationIndex)));
}

if (!cursor.isNull(photoUrlIndex)) {
marker.setPhotoUrl(cursor.getString(photoUrlIndex));
}
Expand Down Expand Up @@ -542,9 +533,6 @@ ContentValues createContentValues(@NonNull Marker marker) {
values.put(MarkerColumns.CATEGORY, marker.getCategory());
values.put(MarkerColumns.ICON, marker.getIcon());
values.put(MarkerColumns.TRACKID, marker.getTrackId().id());
values.put(MarkerColumns.LENGTH, marker.getLength().toM());
values.put(MarkerColumns.DURATION, marker.getDuration().toMillis());

values.put(MarkerColumns.LONGITUDE, (int) (marker.getLongitude() * 1E6));
values.put(MarkerColumns.LATITUDE, (int) (marker.getLatitude() * 1E6));
values.put(MarkerColumns.TIME, marker.getTime().toEpochMilli());
Expand Down
Loading

0 comments on commit 389c4be

Please sign in to comment.