diff --git a/metadata/en-US/changelogs/next_release.txt b/metadata/en-US/changelogs/next_release.txt index fcdcd91b9..b8e4c7255 100644 --- a/metadata/en-US/changelogs/next_release.txt +++ b/metadata/en-US/changelogs/next_release.txt @@ -8,4 +8,5 @@ Bugfix: Developer: - Fixed (some) test cases +- Removed unused parcelable functionality - Major cleanup and reformatting \ No newline at end of file diff --git a/src/androidTest/java/de/dennisguse/opentracks/content/WaypointCreationRequestTest.java b/src/androidTest/java/de/dennisguse/opentracks/content/WaypointCreationRequestTest.java deleted file mode 100644 index 2fc4acdeb..000000000 --- a/src/androidTest/java/de/dennisguse/opentracks/content/WaypointCreationRequestTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package de.dennisguse.opentracks.content; - -import android.os.Parcel; - -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; - -import de.dennisguse.opentracks.content.Waypoint.WaypointType; - -/** - * Tests for the {@link WaypointCreationRequest} class. - * - * @author Sandor Dornbush - */ -@RunWith(AndroidJUnit4.class) -public class WaypointCreationRequestTest { - - @Test - public void testTypeParceling() { - WaypointCreationRequest original = WaypointCreationRequest.DEFAULT_WAYPOINT; - Parcel p = Parcel.obtain(); - original.writeToParcel(p, 0); - p.setDataPosition(0); - WaypointCreationRequest copy = WaypointCreationRequest.CREATOR.createFromParcel(p); - Assert.assertEquals(original.getType(), copy.getType()); - Assert.assertFalse(copy.isTrackStatistics()); - Assert.assertNull(copy.getName()); - Assert.assertNull(copy.getDescription()); - Assert.assertNull(copy.getIconUrl()); - } - - @Test - public void testAllAttributesParceling() { - WaypointCreationRequest original = new WaypointCreationRequest(WaypointType.WAYPOINT, false, "name", "category", "description", "img.png", null); - Parcel p = Parcel.obtain(); - original.writeToParcel(p, 0); - p.setDataPosition(0); - WaypointCreationRequest copy = WaypointCreationRequest.CREATOR.createFromParcel(p); - Assert.assertEquals(original.getType(), copy.getType()); - Assert.assertFalse(copy.isTrackStatistics()); - Assert.assertEquals("name", copy.getName()); - Assert.assertEquals("category", copy.getCategory()); - Assert.assertEquals("description", copy.getDescription()); - Assert.assertEquals("img.png", copy.getIconUrl()); - } -} diff --git a/src/main/java/de/dennisguse/opentracks/content/Track.java b/src/main/java/de/dennisguse/opentracks/content/Track.java index 51614a37b..75d77f2af 100644 --- a/src/main/java/de/dennisguse/opentracks/content/Track.java +++ b/src/main/java/de/dennisguse/opentracks/content/Track.java @@ -17,8 +17,6 @@ package de.dennisguse.opentracks.content; import android.location.Location; -import android.os.Parcel; -import android.os.Parcelable; import java.util.ArrayList; import java.util.List; @@ -31,19 +29,7 @@ import de.dennisguse.opentracks.stats.TripStatistics; * @author Leif Hendrik Wilden * @author Rodrigo Damazio */ -public class Track implements Parcelable { - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public Track createFromParcel(Parcel in) { - return new Track(in); - } - - @Override - public Track[] newArray(int size) { - return new Track[size]; - } - }; +public class Track { private long id = -1L; private String name = ""; @@ -66,47 +52,6 @@ public class Track implements Parcelable { public Track() { } - private Track(Parcel in) { - id = in.readLong(); - name = in.readString(); - description = in.readString(); - category = in.readString(); - startId = in.readLong(); - stopId = in.readLong(); - numberOfPoints = in.readInt(); - icon = in.readString(); - - ClassLoader classLoader = getClass().getClassLoader(); - tripStatistics = in.readParcelable(classLoader); - - for (int i = 0; i < numberOfPoints; ++i) { - Location location = in.readParcelable(classLoader); - locations.add(location); - } - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(id); - dest.writeString(name); - dest.writeString(description); - dest.writeString(category); - dest.writeLong(startId); - dest.writeLong(stopId); - dest.writeInt(numberOfPoints); - dest.writeString(icon); - - dest.writeParcelable(tripStatistics, 0); - for (int i = 0; i < numberOfPoints; ++i) { - dest.writeParcelable(locations.get(i), 0); - } - } - public long getId() { return id; } diff --git a/src/main/java/de/dennisguse/opentracks/content/Waypoint.java b/src/main/java/de/dennisguse/opentracks/content/Waypoint.java index 4aa9cc1d2..d2324cd92 100644 --- a/src/main/java/de/dennisguse/opentracks/content/Waypoint.java +++ b/src/main/java/de/dennisguse/opentracks/content/Waypoint.java @@ -18,8 +18,6 @@ package de.dennisguse.opentracks.content; import android.location.Location; import android.net.Uri; -import android.os.Parcel; -import android.os.Parcelable; import de.dennisguse.opentracks.stats.TripStatistics; @@ -29,19 +27,7 @@ import de.dennisguse.opentracks.stats.TripStatistics; * @author Leif Hendrik Wilden * @author Rodrigo Damazio */ -public final class Waypoint implements Parcelable { - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public Waypoint createFromParcel(Parcel in) { - return new Waypoint(in); - } - - @Override - public Waypoint[] newArray(int size) { - return new Waypoint[size]; - } - }; +public final class Waypoint { private long id = -1L; private String name = ""; @@ -77,60 +63,6 @@ public final class Waypoint implements Parcelable { this.photoUrl = photoUrl; } - private Waypoint(Parcel source) { - id = source.readLong(); - name = source.readString(); - description = source.readString(); - category = source.readString(); - icon = source.readString(); - trackId = source.readLong(); - type = WaypointType.values()[source.readInt()]; - length = source.readDouble(); - duration = source.readLong(); - startId = source.readLong(); - stopId = source.readLong(); - - ClassLoader classLoader = getClass().getClassLoader(); - byte hasLocation = source.readByte(); - if (hasLocation > 0) { - location = source.readParcelable(classLoader); - } - byte hasStats = source.readByte(); - if (hasStats > 0) { - tripStatistics = source.readParcelable(classLoader); - } - photoUrl = source.readString(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(id); - dest.writeString(name); - dest.writeString(description); - dest.writeString(category); - dest.writeString(icon); - dest.writeLong(trackId); - dest.writeInt(type.ordinal()); - dest.writeDouble(length); - dest.writeLong(duration); - dest.writeLong(startId); - dest.writeLong(stopId); - dest.writeByte(location == null ? (byte) 0 : (byte) 1); - if (location != null) { - dest.writeParcelable(location, 0); - } - dest.writeByte(tripStatistics == null ? (byte) 0 : (byte) 1); - if (tripStatistics != null) { - dest.writeParcelable(tripStatistics, 0); - } - dest.writeString(photoUrl); - } - public long getId() { return id; } diff --git a/src/main/java/de/dennisguse/opentracks/content/WaypointCreationRequest.java b/src/main/java/de/dennisguse/opentracks/content/WaypointCreationRequest.java index d5584009f..5743c99cc 100644 --- a/src/main/java/de/dennisguse/opentracks/content/WaypointCreationRequest.java +++ b/src/main/java/de/dennisguse/opentracks/content/WaypointCreationRequest.java @@ -15,9 +15,6 @@ */ package de.dennisguse.opentracks.content; -import android.os.Parcel; -import android.os.Parcelable; - import de.dennisguse.opentracks.content.Waypoint.WaypointType; /** @@ -25,7 +22,7 @@ import de.dennisguse.opentracks.content.Waypoint.WaypointType; * * @author Sandor Dornbush */ -public class WaypointCreationRequest implements Parcelable { +public class WaypointCreationRequest { public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(WaypointType.WAYPOINT, false); @@ -33,8 +30,6 @@ public class WaypointCreationRequest implements Parcelable { public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(WaypointType.STATISTICS, true); - public static final Creator CREATOR = new Creator(); - private WaypointType type; // true if this marker contains the track statistics @@ -60,22 +55,6 @@ public class WaypointCreationRequest implements Parcelable { this.photoUrl = photoUrl; } - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int arg1) { - parcel.writeInt(type.ordinal()); - parcel.writeByte((byte) (isTrackStatistics ? 1 : 0)); - parcel.writeString(name); - parcel.writeString(category); - parcel.writeString(description); - parcel.writeString(iconUrl); - parcel.writeString(photoUrl); - } - public WaypointType getType() { return type; } @@ -103,23 +82,4 @@ public class WaypointCreationRequest implements Parcelable { public String getPhotoUrl() { return photoUrl; } - - public static class Creator implements Parcelable.Creator { - - @Override - public WaypointCreationRequest createFromParcel(Parcel source) { - return new WaypointCreationRequest( - WaypointType.values()[source.readInt()], - source.readByte() == 1, - source.readString(), - source.readString(), - source.readString(), - source.readString(), - source.readString()); - } - - public WaypointCreationRequest[] newArray(int size) { - return new WaypointCreationRequest[size]; - } - } } \ No newline at end of file diff --git a/src/main/java/de/dennisguse/opentracks/io/file/TrackFileFormat.java b/src/main/java/de/dennisguse/opentracks/io/file/TrackFileFormat.java index 11d6f34f0..b46b9d90b 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/TrackFileFormat.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/TrackFileFormat.java @@ -1,8 +1,6 @@ package de.dennisguse.opentracks.io.file; import android.content.Context; -import android.os.Parcel; -import android.os.Parcelable; import java.util.Locale; @@ -20,7 +18,7 @@ import de.dennisguse.opentracks.io.file.exporter.TrackWriter; /** * Definition of all possible track formats. */ -public enum TrackFileFormat implements Parcelable { +public enum TrackFileFormat { KML_ONLY_TRACK { @Override @@ -121,29 +119,6 @@ public enum TrackFileFormat implements Parcelable { } }; - @Deprecated - public static final Creator CREATOR = new Creator() { - @Override - public TrackFileFormat createFromParcel(final Parcel source) { - return TrackFileFormat.values()[source.readInt()]; - } - - @Override - public TrackFileFormat[] newArray(final int size) { - return new TrackFileFormat[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(final Parcel dest, final int flags) { - dest.writeInt(ordinal()); - } - private static final String MIME_KMZ = "application/vnd.google-earth.kmz"; private static final String MIME_KML = "application/vnd.google-earth.kml+xml"; diff --git a/src/main/java/de/dennisguse/opentracks/stats/TripStatistics.java b/src/main/java/de/dennisguse/opentracks/stats/TripStatistics.java index 3f25bbeaf..98e806080 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/TripStatistics.java +++ b/src/main/java/de/dennisguse/opentracks/stats/TripStatistics.java @@ -16,25 +16,15 @@ package de.dennisguse.opentracks.stats; -import android.os.Parcel; -import android.os.Parcelable; - import androidx.annotation.NonNull; /** - * Statistical data about a trip. The data in this class should be filled out by - * TripStatisticsBuilder. - *

- * TODO: hashCode and equals + * Statistical data about a trip. + * The data in this class should be filled out by TripStatisticsBuilder. * * @author Rodrigo Damazio */ -public class TripStatistics implements Parcelable { - - /** - * Creator of {@link TripStatistics} from parcels. - */ - public static final Creator CREATOR = new Creator(); +public class TripStatistics { // The min and max latitude seen in this trip. private final ExtremityMonitor latitudeExtremities = new ExtremityMonitor(); @@ -60,9 +50,6 @@ public class TripStatistics implements Parcelable { // The total elevation gained (meters). private double totalElevationGain; - /** - * Default constructor. - */ public TripStatistics() { } @@ -86,8 +73,8 @@ public class TripStatistics implements Parcelable { } /** - * Combines these statistics with those from another object. This assumes that - * the time periods covered by each do not intersect. + * Combines these statistics with those from another object. + * This assumes that the time periods covered by each do not intersect. * * @param other another statistics data object */ @@ -478,71 +465,4 @@ public class TripStatistics implements Parcelable { + "; Elevation Gain: " + getTotalElevationGain() + "; Min Grade: " + getMinGrade() + "; Max Grade: " + getMaxGrade() + "}"; } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(startTime); - dest.writeLong(stopTime); - dest.writeDouble(totalDistance); - dest.writeLong(totalTime); - dest.writeLong(movingTime); - dest.writeDouble(latitudeExtremities.getMin()); - dest.writeDouble(latitudeExtremities.getMax()); - dest.writeDouble(longitudeExtremities.getMin()); - dest.writeDouble(longitudeExtremities.getMax()); - dest.writeDouble(maxSpeed); - dest.writeDouble(elevationExtremities.getMin()); - dest.writeDouble(elevationExtremities.getMax()); - dest.writeDouble(totalElevationGain); - dest.writeDouble(gradeExtremities.getMin()); - dest.writeDouble(gradeExtremities.getMax()); - } - - /** - * Creator of statistics data from parcels. - */ - public static class Creator implements Parcelable.Creator { - - @Override - public TripStatistics createFromParcel(Parcel source) { - TripStatistics data = new TripStatistics(); - - data.startTime = source.readLong(); - data.stopTime = source.readLong(); - data.totalDistance = source.readDouble(); - data.totalTime = source.readLong(); - data.movingTime = source.readLong(); - - double minLat = source.readDouble(); - double maxLat = source.readDouble(); - data.latitudeExtremities.set(minLat, maxLat); - - double minLong = source.readDouble(); - double maxLong = source.readDouble(); - data.longitudeExtremities.set(minLong, maxLong); - - data.maxSpeed = source.readDouble(); - - double minElev = source.readDouble(); - double maxElev = source.readDouble(); - data.elevationExtremities.set(minElev, maxElev); - data.totalElevationGain = source.readDouble(); - - double minGrade = source.readDouble(); - double maxGrade = source.readDouble(); - data.gradeExtremities.set(minGrade, maxGrade); - - return data; - } - - @Override - public TripStatistics[] newArray(int size) { - return new TripStatistics[size]; - } - } } \ No newline at end of file