Move GpxSplitType and GradientScaleType to android module

This commit is contained in:
Vitaliy 2020-07-14 11:49:44 +03:00
parent d88bf79930
commit 67d2166d0f
7 changed files with 122 additions and 77 deletions

View file

@ -1514,52 +1514,38 @@ public class GPXUtilities {
return new QuadRect(left, top, right, bottom);
}
public int getGradientScaleColor(GradientScaleType gradientScaleType, int defColor) {
public int getGradientScaleColor(String gradientScaleType, int defColor) {
String clrValue = null;
if (extensions != null) {
clrValue = extensions.get(gradientScaleType.getTypeName());
clrValue = extensions.get(gradientScaleType);
}
return parseColor(clrValue, defColor);
}
public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleColor) {
getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor));
public void setGradientScaleColor(String gradientScaleType, int gradientScaleColor) {
getExtensionsToWrite().put(gradientScaleType, Algorithms.colorToString(gradientScaleColor));
}
public GradientScaleType getGradientScaleType() {
public String getGradientScaleType() {
if (extensions != null) {
String gradientScaleTypeName = extensions.get("gradient_scale_type");
if (!Algorithms.isEmpty(gradientScaleTypeName)) {
try {
return GradientScaleType.valueOf(gradientScaleTypeName);
} catch (IllegalArgumentException e) {
log.error("Error reading gradientScaleType", e);
}
}
return extensions.get("gradient_scale_type");
}
return null;
}
public void setGradientScaleType(GradientScaleType gradientScaleType) {
getExtensionsToWrite().put("gradient_scale_type", gradientScaleType.name());
public void setGradientScaleType(String gradientScaleType) {
getExtensionsToWrite().put("gradient_scale_type", gradientScaleType);
}
public GpxSplitType getSplitType() {
public String getSplitType() {
if (extensions != null) {
String gradientScaleTypeName = extensions.get("split_type");
if (!Algorithms.isEmpty(gradientScaleTypeName)) {
try {
return GpxSplitType.valueOf(gradientScaleTypeName);
} catch (IllegalArgumentException e) {
log.error("Error reading GpxSplitType", e);
}
}
return extensions.get("split_type");
}
return null;
}
public void setSplitType(GpxSplitType gpxSplitType) {
getExtensionsToWrite().put("split_type", gpxSplitType.name());
public void setSplitType(String gpxSplitType) {
getExtensionsToWrite().put("split_type", gpxSplitType);
}
public double getSplitInterval() {
@ -1615,37 +1601,6 @@ public class GPXUtilities {
getExtensionsToWrite().put("show_start_finish", String.valueOf(showStartFinish));
}
public enum GradientScaleType {
SPEED("gradient_speed_color"),
ALTITUDE("gradient_altitude_color"),
SLOPE("gradient_slope_color");
private String typeName;
GradientScaleType(String typeName) {
this.typeName = typeName;
}
public String getTypeName() {
return typeName;
}
}
public enum GpxSplitType {
NO_SPLIT(-1),
DISTANCE(1),
TIME(2);
private int type;
GpxSplitType(int type) {
this.type = type;
}
public int getType() {
return type;
}
}
}
public static String asString(GPXFile file) {

View file

@ -4,11 +4,12 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.IndexConstants;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.track.GpxSplitType;
import net.osmand.plus.track.GradientScaleType;
import net.osmand.util.Algorithms;
import java.io.File;
@ -201,17 +202,34 @@ public class GPXDatabase {
public GpxDataItem(File file, @NonNull GPXFile gpxFile) {
this.file = file;
readGpxParams(gpxFile);
}
private void readGpxParams(GPXFile gpxFile) {
color = gpxFile.getColor(0);
width = gpxFile.getWidth(null);
showArrows = gpxFile.isShowArrows();
showStartFinish = gpxFile.isShowStartFinish();
gradientScaleType = gpxFile.getGradientScaleType();
gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED, 0);
gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0);
gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0);
if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) {
splitType = gpxFile.getSplitType().getType();
splitInterval = gpxFile.getSplitInterval();
gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED.getTypeName(), 0);
gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), 0);
gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), 0);
if (!Algorithms.isEmpty(gpxFile.getSplitType()) && gpxFile.getSplitInterval() != 0) {
for (GpxSplitType gpxSplitType : GpxSplitType.values()) {
if (gpxSplitType.name().equalsIgnoreCase(gpxFile.getSplitType())) {
splitType = gpxSplitType.getType();
splitInterval = gpxFile.getSplitInterval();
break;
}
}
}
if (!Algorithms.isEmpty(gpxFile.getGradientScaleType())) {
for (GradientScaleType scaleType : GradientScaleType.values()) {
if (scaleType.name().equalsIgnoreCase(gpxFile.getGradientScaleType())) {
gradientScaleType = scaleType;
break;
}
}
}
}

View file

@ -8,11 +8,11 @@ import androidx.annotation.Nullable;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GpxSplitType;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.plus.track.GpxSplitType;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.track.GradientScaleType;
import java.io.File;
import java.util.List;

View file

@ -11,8 +11,7 @@ import androidx.core.content.ContextCompat;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GpxSplitType;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.plus.track.GpxSplitType;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.GPXUtilities.Route;
import net.osmand.GPXUtilities.Track;
@ -29,6 +28,7 @@ import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants;
import net.osmand.plus.track.GradientScaleType;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -524,7 +524,7 @@ public class GpxSelectionHelper {
for (GradientScaleType scaleType : GradientScaleType.values()) {
if (obj.has(scaleType.getTypeName())) {
int clr = Algorithms.parseColor(obj.getString(scaleType.getTypeName()));
gpx.setGradientScaleColor(scaleType, clr);
gpx.setGradientScaleColor(scaleType.getTypeName(), clr);
}
}
if (obj.has(SHOW_ARROWS)) {
@ -534,7 +534,7 @@ public class GpxSelectionHelper {
if (obj.has(GRADIENT_SCALE_TYPE)) {
String gradientScaleTypeName = obj.optString(GRADIENT_SCALE_TYPE);
if (!Algorithms.isEmpty(gradientScaleTypeName)) {
gpx.setGradientScaleType(GradientScaleType.valueOf(gradientScaleTypeName));
gpx.setGradientScaleType(GradientScaleType.valueOf(gradientScaleTypeName).getTypeName());
}
}
if (obj.has(SHOW_START_FINISH)) {
@ -592,7 +592,7 @@ public class GpxSelectionHelper {
obj.put(SHOW_ARROWS, s.gpxFile.isShowArrows());
obj.put(SHOW_START_FINISH, s.gpxFile.isShowStartFinish());
for (GradientScaleType scaleType : GradientScaleType.values()) {
int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType, 0);
int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType.getTypeName(), 0);
if (gradientScaleColor != 0) {
obj.put(scaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor));
}
@ -650,16 +650,16 @@ public class GpxSelectionHelper {
gpx.setColor(dataItem.getColor());
}
if (dataItem.getGradientSpeedColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.SPEED, dataItem.getGradientSpeedColor());
gpx.setGradientScaleColor(GradientScaleType.SPEED.getTypeName(), dataItem.getGradientSpeedColor());
}
if (dataItem.getGradientAltitudeColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.ALTITUDE, dataItem.getGradientAltitudeColor());
gpx.setGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), dataItem.getGradientAltitudeColor());
}
if (dataItem.getGradientSlopeColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.SLOPE, dataItem.getGradientSlopeColor());
gpx.setGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), dataItem.getGradientSlopeColor());
}
if (dataItem.getGradientScaleType() != null) {
gpx.setGradientScaleType(dataItem.getGradientScaleType());
gpx.setGradientScaleType(dataItem.getGradientScaleType().getTypeName());
}
if (dataItem.getWidth() != null) {
gpx.setWidth(dataItem.getWidth());

View file

@ -39,7 +39,7 @@ import com.squareup.picasso.RequestCreator;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GpxSplitType;
import net.osmand.plus.track.GpxSplitType;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.PicassoUtils;
import net.osmand.data.LatLon;

View file

@ -0,0 +1,32 @@
package net.osmand.plus.track;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import net.osmand.plus.R;
public enum GpxSplitType {
NO_SPLIT(-1, R.string.shared_string_none),
DISTANCE(1, R.string.distance),
TIME(2, R.string.shared_string_time);
private int type;
@StringRes
private int resId;
GpxSplitType(int type, @StringRes int resId) {
this.type = type;
this.resId = resId;
}
public int getType() {
return type;
}
public String getHumanString(@NonNull Context ctx) {
return ctx.getString(resId);
}
}

View file

@ -0,0 +1,40 @@
package net.osmand.plus.track;
import android.content.Context;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import net.osmand.plus.R;
public enum GradientScaleType {
SPEED("gradient_speed_color", R.string.map_widget_speed, R.drawable.ic_action_speed),
ALTITUDE("gradient_altitude_color", R.string.altitude, R.drawable.ic_action_altitude_average),
SLOPE("gradient_slope_color", R.string.shared_string_slope, R.drawable.ic_action_altitude_ascent);
private String typeName;
@StringRes
private int resId;
@DrawableRes
private int iconId;
GradientScaleType(@NonNull String typeName, @StringRes int resId, @DrawableRes int iconId) {
this.typeName = typeName;
this.resId = resId;
this.iconId = iconId;
}
public String getTypeName() {
return typeName;
}
public int getIconId() {
return iconId;
}
public String getHumanString(@NonNull Context ctx) {
return ctx.getString(resId);
}
}