Skip to content

Commit

Permalink
Show letters instead of sign in turn gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov committed Mar 18, 2024
1 parent 8972ac5 commit 027473d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/mobi/maptrek/MapTrek.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ private void initializeSettings() {
unit = Configuration.getAngleUnit();
StringFormatter.angleFactor = Double.parseDouble(resources.getStringArray(R.array.angle_factors)[unit]);
StringFormatter.angleAbbr = resources.getStringArray(R.array.angle_abbreviations)[unit];
StringFormatter.angleLeft = resources.getString(R.string.angle_left);
StringFormatter.angleRight = resources.getString(R.string.angle_right);
boolean precision = Configuration.getUnitPrecision();
StringFormatter.precisionFormat = precision ? "%.1f" : "%.0f";
StringFormatter.coordinateFormat = Configuration.getCoordinatesFormat();
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/mobi/maptrek/util/StringFormatter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Andrey Novikov
* Copyright 2024 Andrey Novikov
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
Expand Down Expand Up @@ -57,6 +57,8 @@ public class StringFormatter
public static String angleFormat = "%.0f";
public static double angleFactor = 1d;
public static String angleAbbr = "deg";
public static String angleLeft = "L";
public static String angleRight = "R";

//FIXME Should localize:
public static String secondAbbr = "sec";
Expand Down Expand Up @@ -166,6 +168,14 @@ public static String angleH(final double angle)
}
}

public static String angleT(final double angle)
{
String value = angleC(Math.abs(angle));
if ("0".equals(value))
return value;
return (angle < 0 ? angleLeft : angleRight) + value;
}

public static String angleC(final double angle)
{
return String.format(angleFormat, angle / angleFactor);
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/mobi/maptrek/view/Gauge.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ public void setValue(float value) {
break;
}
case Gauge.TYPE_TRACK:
case Gauge.TYPE_BEARING:
case Gauge.TYPE_TURN: {
case Gauge.TYPE_BEARING: {
indication = StringFormatter.angleC(value);
break;
}
case Gauge.TYPE_TURN: {
indication = StringFormatter.angleT(value);
break;
}
default:
indication = String.format(Locale.getDefault(), StringFormatter.precisionFormat, value);
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@
<string name="gauge_xtk">Cross track</string>
<string name="gauge_ete">ETE</string>
<string name="gauge_elevation">Elevation</string>
<string name="angle_left">L</string>
<string name="angle_right">R</string>
<string name="place_altitude" translatable="false">&#9014; %s</string>
<string name="place_proximity" translatable="false">~ %s</string>
<string name="placeStoreName">My places</string>
Expand Down

0 comments on commit 027473d

Please sign in to comment.