Merge pull request #7160 from osmandapp/coord_formatter

Add foldable location menu to POI menu
This commit is contained in:
vshcherb 2019-07-05 14:56:06 +02:00 committed by GitHub
commit e646774c0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 62 deletions

View file

@ -156,26 +156,7 @@ public class PointDescription {
public static String getLocationName(Context ctx, double lat, double lon, boolean sh) {
OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
int f = st.COORDINATES_FORMAT.get();
if (f == PointDescription.UTM_FORMAT) {
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " "
+ ((long) pnt.northing);
} else if (f == PointDescription.OLC_FORMAT) {
try {
return getLocationOlcName(lat, lon);
} catch (RuntimeException e) {
e.printStackTrace();
return "0, 0";
}
} else {
try {
return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, LocationConvert.convert(lat, f),
LocationConvert.convert(lon, f));
} catch (RuntimeException e) {
e.printStackTrace();
return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, 0, 0);
}
}
return OsmAndFormatter.getFormattedCoordinates(lat, lon, f);
}
public static Map<Integer, String> getLocationData(MapActivity ctx, double lat, double lon, boolean sh) {
@ -187,14 +168,14 @@ public class PointDescription {
String latLonMin;
String latLonSec;
String utm = OsmAndFormatter.formatLocationCoordinates(lat, lon, OsmAndFormatter.FORMAT_UTM);
String olc = OsmAndFormatter.formatLocationCoordinates(lat, lon, OsmAndFormatter.FORMAT_OLC);
String utm = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.UTM_FORMAT);
String olc = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.OLC_FORMAT);
try {
latLonString = OsmAndFormatter.formatLocationCoordinates(lat, lon, OsmAndFormatter.FORMAT_DEGREES_SHORT);
latLonDeg = OsmAndFormatter.formatLocationCoordinates(lat, lon, OsmAndFormatter.FORMAT_DEGREES);
latLonMin = OsmAndFormatter.formatLocationCoordinates(lat, lon, OsmAndFormatter.FORMAT_MINUTES);
latLonSec = OsmAndFormatter.formatLocationCoordinates(lat, lon, OsmAndFormatter.FORMAT_SECONDS);
latLonString = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.FORMAT_DEGREES_SHORT);
latLonDeg = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.FORMAT_DEGREES);
latLonMin = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.FORMAT_MINUTES);
latLonSec = OsmAndFormatter.getFormattedCoordinates(lat, lon, OsmAndFormatter.FORMAT_SECONDS);
} catch (RuntimeException e) {
latLonString = "0, 0";
latLonDeg = "0°, 0°";
@ -206,8 +187,8 @@ public class PointDescription {
results.put(OsmAndFormatter.FORMAT_DEGREES, latLonDeg);
results.put(OsmAndFormatter.FORMAT_MINUTES, latLonMin);
results.put(OsmAndFormatter.FORMAT_SECONDS, latLonSec);
results.put(OsmAndFormatter.FORMAT_UTM, utm);
results.put(OsmAndFormatter.FORMAT_OLC, olc);
results.put(OsmAndFormatter.UTM_FORMAT, utm);
results.put(OsmAndFormatter.OLC_FORMAT, olc);
int zoom = 17;
if (ctx.getMapView() != null) {
@ -235,25 +216,8 @@ public class PointDescription {
public static String getLocationNamePlain(Context ctx, double lat, double lon) {
OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
int f = st.COORDINATES_FORMAT.get();
if (f == PointDescription.UTM_FORMAT) {
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " "
+ ((long) pnt.northing);
} else if (f == PointDescription.OLC_FORMAT) {
try {
return getLocationOlcName(lat, lon);
} catch (RuntimeException e) {
e.printStackTrace();
return "0, 0";
}
} else {
try {
return LocationConvert.convert(lat, f) + ", " + LocationConvert.convert(lon, f);
} catch (RuntimeException e) {
e.printStackTrace();
return "0, 0";
}
}
return OsmAndFormatter.getFormattedCoordinates(lat, lon, f);
}
public static String getLocationOlcName(double lat, double lon) {

View file

@ -8,6 +8,7 @@ import android.text.format.DateUtils;
import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.UTMPoint;
import java.text.DecimalFormatSymbols;
import net.osmand.LocationConvert;
import net.osmand.data.Amenity;
import net.osmand.data.City.CityType;
import net.osmand.osm.AbstractPoiType;
@ -17,7 +18,6 @@ import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandSettings.AngularConstants;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.OsmandSettings.SpeedConstants;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format;
import net.osmand.util.Algorithms;
import java.text.DateFormatSymbols;
@ -40,12 +40,12 @@ public class OsmAndFormatter {
private static final SimpleDateFormat SIMPLE_TIME_OF_DAY_FORMAT = new SimpleDateFormat("HH:mm", Locale.getDefault());
private static final String[] localDaysStr = getLettersStringArray(DateFormatSymbols.getInstance().getShortWeekdays(), 3);
public static final int FORMAT_DEGREES_SHORT = 100;
public static final int FORMAT_DEGREES = 101;
public static final int FORMAT_MINUTES = 102;
public static final int FORMAT_SECONDS = 103;
public static final int FORMAT_UTM = 104;
public static final int FORMAT_OLC = 105;
public static final int FORMAT_DEGREES_SHORT = 6;
public static final int FORMAT_DEGREES = LocationConvert.FORMAT_DEGREES;
public static final int FORMAT_MINUTES = LocationConvert.FORMAT_MINUTES;
public static final int FORMAT_SECONDS = LocationConvert.FORMAT_SECONDS;
public static final int UTM_FORMAT = LocationConvert.UTM_FORMAT;
public static final int OLC_FORMAT = LocationConvert.OLC_FORMAT;
private static final char DELIMITER_DEGREES = '°';
private static final char DELIMITER_MINUTES = '';
private static final char DELIMITER_SECONDS = '″';
@ -429,7 +429,7 @@ public class OsmAndFormatter {
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
}
public static String formatLocationCoordinates(double lat, double lon, int outputFormat) {
public static String getFormattedCoordinates(double lat, double lon, int outputFormat) {
StringBuilder result = new StringBuilder();
if (outputFormat == FORMAT_DEGREES_SHORT) {
result.append(formatCoordinate(lat, outputFormat)).append(" ").append(formatCoordinate(lon, outputFormat));
@ -439,14 +439,14 @@ public class OsmAndFormatter {
.append(lat > 0 ? NORTH : SOUTH).append(", ")
.append(formatCoordinate(lon, outputFormat)).append(" ")
.append(lon > 0 ? EAST : WEST);
} else if (outputFormat == FORMAT_UTM) {
} else if (outputFormat == UTM_FORMAT) {
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
result
.append(pnt.zone_number)
.append(pnt.zone_letter).append(" ")
.append((long) pnt.easting).append(" ")
.append((long) pnt.northing);
} else if (outputFormat == FORMAT_OLC) {
} else if (outputFormat == OLC_FORMAT) {
String r;
try {
r = getLocationOlcName(lat, lon);

View file

@ -674,9 +674,9 @@ public class MenuBuilder {
LinearLayout llv = buildCollapsableContentView(mapActivity, true, true);
for (final Map.Entry<Integer, String> line : locationData.entrySet()) {
final TextViewEx button = buildButtonInCollapsableView(mapActivity, false, false);
if (line.getKey() == OsmAndFormatter.FORMAT_UTM || line.getKey() == OsmAndFormatter.FORMAT_OLC) {
if (line.getKey() == OsmAndFormatter.UTM_FORMAT || line.getKey() == OsmAndFormatter.OLC_FORMAT) {
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(line.getKey() == OsmAndFormatter.FORMAT_UTM ? "UTM: " : "OLC: ");
ssb.append(line.getKey() == OsmAndFormatter.UTM_FORMAT ? "UTM: " : "OLC: ");
ssb.setSpan(new ForegroundColorSpan(app.getResources().getColor(R.color.text_color_secondary_light)), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(line.getValue());
button.setText(ssb);

View file

@ -72,8 +72,11 @@ public class EditPOIMenuBuilder extends MenuBuilder {
}
}
buildRow(view, R.drawable.ic_action_get_my_location, null, PointDescription.getLocationName(app,
osmPoint.getLatitude(), osmPoint.getLongitude(), true)
.replaceAll("\n", " "), 0, false, null, false, 0, false, null, false);
Map<Integer, String> locationData = PointDescription.getLocationData(mapActivity, osmPoint.getLatitude(), osmPoint.getLongitude(), true);
String title = locationData.get(PointDescription.LOCATION_LIST_HEADER);
locationData.remove(PointDescription.LOCATION_LIST_HEADER);
CollapsableView cv = getLocationCollapsableView(locationData);
buildRow(view, R.drawable.ic_action_get_my_location, null, title, 0, true, cv,
true, 1, false, null, false);
}
}