forked from upstream-mirrors/OpenTracks
Removed Parcelable from all data classes as it not needed anymore.
This commit is contained in:
@@ -8,4 +8,5 @@ Bugfix:
|
||||
|
||||
Developer:
|
||||
- Fixed (some) test cases
|
||||
- Removed unused parcelable functionality
|
||||
- Major cleanup and reformatting
|
||||
-64
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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<Track> CREATOR = new Parcelable.Creator<Track>() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -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<Waypoint> CREATOR = new Parcelable.Creator<Waypoint>() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -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<WaypointCreationRequest> {
|
||||
|
||||
@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];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<TrackFileFormat> CREATOR = new Creator<TrackFileFormat>() {
|
||||
@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";
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* 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<TripStatistics> {
|
||||
|
||||
@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];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user