kopia lustrzana https://github.com/ge0rg/aprsdroid
Refactored code for formatting DMS coordinate strings for easier testability
rodzic
3bb004857e
commit
1bc23f775e
|
@ -71,12 +71,19 @@ object AprsPacket {
|
|||
""
|
||||
}
|
||||
|
||||
val DirectionsLatitude = "NS";
|
||||
val DirectionsLongitude = "WE";
|
||||
def formatDMS(coordinate : Float, nesw : String) = {
|
||||
val dms = Location.convert(coordinate, Location.FORMAT_SECONDS).split(":")
|
||||
val nesw_idx = (coordinate < 0).compare(false)
|
||||
"%2s° %2s' %s\" %s".format(dms(0), dms(1), dms(2), nesw(nesw_idx))
|
||||
}
|
||||
|
||||
def formatCoordinates(latitude : Float, longitude : Float) = {
|
||||
(AprsPacket.formatDMS(latitude, DirectionsLatitude),
|
||||
AprsPacket.formatDMS(longitude, DirectionsLongitude))
|
||||
}
|
||||
|
||||
def parseQrg(comment : String) : String = {
|
||||
comment match {
|
||||
case QRG_RE(qrg) => qrg
|
||||
|
|
|
@ -174,8 +174,7 @@ trait MapMenuHelper extends UIHelper with OnClickListener {
|
|||
|
||||
def updateCoordinateInfo(lat : Float, lon : Float): Unit = {
|
||||
resultIntent.putExtra("lat", lat).putExtra("lon", lon)
|
||||
val lat_s = AprsPacket.formatDMS(lat, "NS")
|
||||
val lon_s = AprsPacket.formatDMS(lon, "WE")
|
||||
val (lat_s, lon_s) = AprsPacket.formatCoordinates(lat, lon)
|
||||
infoText.setText(lat_s + "\n" + lon_s)
|
||||
accept.setEnabled(true);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue