\Merge branch 'master' of ssh://github.com/osmandapp/Osmand into Fix_7140

This commit is contained in:
Chumva 2019-07-03 09:55:44 +03:00
commit c4a7d9ef07
7 changed files with 184 additions and 43 deletions

View file

@ -360,7 +360,7 @@
android:layout_marginEnd="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:text="@string/setup_profile"
android:text="@string/edit_profile_setup_title"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>
@ -372,7 +372,7 @@
android:layout_marginEnd="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:text="@string/setup_profile_descr"
android:text="@string/edit_profile_setup_subtitle"
android:textColor="@color/description_font_and_bottom_sheet_icons"/>
<LinearLayout
@ -404,14 +404,14 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/configure_map"
android:text="@string/edit_profile_configure_map"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/configure_map_for_profile_descr"
android:text="@string/edit_profile_setup_map_subtitle"
android:textColor="@color/description_font_and_bottom_sheet_icons"/>
</LinearLayout>
</LinearLayout>
@ -452,14 +452,14 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map_widget_config"
android:text="@string/edit_profile_configure_screen_title"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/configure_screen_for_profile_descr"
android:text="@string/edit_profile_screen_options_subtitle"
android:textColor="@color/description_font_and_bottom_sheet_icons"/>
</LinearLayout>
@ -502,14 +502,14 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/routing_settings_2"
android:text="@string/edit_profile_nav_settings_title"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/configure_navigation_settings_for_profile_descr"
android:text="@string/edit_profile_nav_settings_subtitle"
android:textColor="@color/description_font_and_bottom_sheet_icons"/>
</LinearLayout>

View file

@ -11,6 +11,14 @@
Thx - Hardy
-->
<string name="edit_profile_setup_title">Setup Profile</string>
<string name="edit_profile_setup_subtitle">Profile keeps its own settings</string>
<string name="edit_profile_configure_map">Configure map</string>
<string name="edit_profile_setup_map_subtitle">Select default map options for profile</string>
<string name="edit_profile_configure_screen_title">Configure screen</string>
<string name="edit_profile_screen_options_subtitle">Select default screen options for profile</string>
<string name="edit_profile_nav_settings_title">Navigation settings</string>
<string name="edit_profile_nav_settings_subtitle">Select default navigation settings for profile</string>
<string name="routing_attr_max_num_changes_description">Specify max number of changes</string>
<string name="routing_attr_max_num_changes_name">Number of changes</string>
<string name="configure_navigation_settings_for_profile_descr">Select default navigation settings for profile</string>
@ -3246,4 +3254,5 @@
<string name="routing_attr_freeride_policy_name">Off-piste</string>
<string name="routing_attr_freeride_policy_description">Freerides and offpiste are unofficial routes and passages. Typically ungroomed, unmainted by the officials and not checked in the evening. Enter at own risk.</string>
</resources>

View file

@ -11,6 +11,7 @@ import com.jwetherell.openmap.common.UTMPoint;
import java.util.LinkedHashMap;
import java.util.Map;
import net.osmand.LocationConvert;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
@ -52,6 +53,8 @@ public class PointDescription {
public static final String POINT_TYPE_MAPILLARY_IMAGE = "mapillary_image";
public static final String POINT_TYPE_POI_TYPE = "poi_type";
public static final String POINT_TYPE_CUSTOM_POI_FILTER = "custom_poi_filter";
public static final int LOCATION_URL = 200;
public static final int LOCATION_LIST_HEADER = 201;
public static final PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, "");
@ -175,41 +178,57 @@ public class PointDescription {
}
}
public static Map<String, String> getLocationData(MapActivity ctx, double lat, double lon, boolean sh) {
public static Map<Integer, String> getLocationData(MapActivity ctx, double lat, double lon, boolean sh) {
OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
Map<String, String> results = new LinkedHashMap<>();
int f = settings.COORDINATES_FORMAT.get();
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
results.put(PointDescription.formatToHumanString(ctx, UTM_FORMAT), pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " "+ ((long) pnt.northing));
Map<Integer, String> results = new LinkedHashMap<>();
String latLonString ;
String latLonDeg;
String latLonMin;
String latLonSec;
String utm = OsmAndFormatter.formatLocationCoordinates(lat, lon, OsmAndFormatter.FORMAT_UTM);
String olc = OsmAndFormatter.formatLocationCoordinates(lat, lon, OsmAndFormatter.FORMAT_OLC);
try {
results.put(PointDescription.formatToHumanString(ctx, OLC_FORMAT), getLocationOlcName(lat, lon));
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);
} catch (RuntimeException e) {
results.put(PointDescription.formatToHumanString(ctx, OLC_FORMAT), "0, 0");
latLonString = "0, 0";
latLonDeg = "0°, 0°";
latLonMin = "0° 0, 0° 0";
latLonSec = "0° 0 0″, 0° 0 0″";
}
if (f == PointDescription.UTM_FORMAT || f == PointDescription.OLC_FORMAT) {
f = PointDescription.FORMAT_DEGREES;
}
try {
results.put(PointDescription.formatToHumanString(ctx, f),
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();
results.put(PointDescription.formatToHumanString(ctx, f),
ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, 0, 0));
}
results.put(OsmAndFormatter.FORMAT_DEGREES_SHORT, latLonString);
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);
int zoom = 17;
if (ctx.getMapView() != null) {
zoom = ctx.getMapView().getZoom();
}
final String httpUrl = "https://osmand.net/go?lat=" + (lat)
+ "&lon=" + (lon) + "&z=" + zoom;
results.put("URL", httpUrl);
final String httpUrl = "https://osmand.net/go?lat=" + (lat) + "&lon=" + (lon) + "&z=" + zoom;
results.put(LOCATION_URL, httpUrl);
int f = settings.COORDINATES_FORMAT.get();
if (f == PointDescription.UTM_FORMAT) {
results.put(LOCATION_LIST_HEADER, utm);
} else if (f == PointDescription.OLC_FORMAT) {
results.put(LOCATION_LIST_HEADER, olc);
} else if (f == PointDescription.FORMAT_DEGREES) {
results.put(LOCATION_LIST_HEADER, latLonDeg);
} else if (f == PointDescription.FORMAT_MINUTES) {
results.put(LOCATION_LIST_HEADER, latLonMin);
} else if (f == PointDescription.FORMAT_SECONDS) {
results.put(LOCATION_LIST_HEADER, latLonSec);
}
return results;
}

View file

@ -1,8 +1,13 @@
package net.osmand.plus;
import static net.osmand.data.PointDescription.getLocationOlcName;
import android.content.Context;
import android.text.format.DateUtils;
import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.UTMPoint;
import java.text.DecimalFormatSymbols;
import net.osmand.data.Amenity;
import net.osmand.data.City.CityType;
import net.osmand.osm.AbstractPoiType;
@ -12,6 +17,7 @@ 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;
@ -34,6 +40,21 @@ 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;
private static final char DELIMITER_DEGREES = '°';
private static final char DELIMITER_MINUTES = '';
private static final char DELIMITER_SECONDS = '″';
private static final char NORTH = 'N';
private static final char SOUTH = 'S';
private static final char WEST = 'W';
private static final char EAST = 'E';
{
fixed2.setMinimumFractionDigits(2);
fixed1.setMinimumFractionDigits(1);
@ -407,4 +428,83 @@ public class OsmAndFormatter {
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
}
public static String formatLocationCoordinates(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));
} else if (outputFormat == FORMAT_DEGREES || outputFormat == FORMAT_MINUTES || outputFormat == FORMAT_SECONDS) {
result
.append(formatCoordinate(lat, outputFormat)).append(" ")
.append(lat > 0 ? NORTH : SOUTH).append(", ")
.append(formatCoordinate(lon, outputFormat)).append(" ")
.append(lon > 0 ? EAST : WEST);
} else if (outputFormat == FORMAT_UTM) {
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) {
String r;
try {
r = getLocationOlcName(lat, lon);
} catch (RuntimeException e) {
r = "0, 0";
}
result.append(r);
}
return result.toString();
}
private static String formatCoordinate(double coordinate, int outputType) {
if (coordinate < -180.0 || coordinate > 180.0 || Double.isNaN(coordinate)) {
return "Error. Wrong coordinates data!";
}
if ((outputType != FORMAT_DEGREES) && (outputType != FORMAT_MINUTES) && (outputType
!= FORMAT_SECONDS) && (outputType != FORMAT_DEGREES_SHORT)) {
return "Unknown Output Format!";
}
DecimalFormat degDf = new DecimalFormat("##0.00000",new DecimalFormatSymbols(Locale.US));
DecimalFormat minDf = new DecimalFormat("00.0000",new DecimalFormatSymbols(Locale.US));
DecimalFormat secDf = new DecimalFormat("00.000",new DecimalFormatSymbols(Locale.US));
StringBuilder sb = new StringBuilder();
if (coordinate < 0) {
if (outputType == FORMAT_DEGREES_SHORT) {
sb.append('-');
}
coordinate = -coordinate;
}
if (outputType == FORMAT_DEGREES_SHORT) {
sb.append(degDf.format(coordinate));
} else if (outputType == FORMAT_DEGREES) {
sb.append(degDf.format(coordinate)).append(DELIMITER_DEGREES);
} else if (outputType == FORMAT_MINUTES) {
sb.append(minDf.format(formatCoordinate(coordinate, sb, DELIMITER_DEGREES)))
.append(DELIMITER_MINUTES);
} else {
sb.append(secDf.format(formatCoordinate(
formatCoordinate(coordinate, sb, DELIMITER_DEGREES), sb, DELIMITER_MINUTES)))
.append(DELIMITER_SECONDS);
}
return sb.toString();
}
private static double formatCoordinate(double coordinate, StringBuilder sb, char delimiter) {
int deg = (int) Math.floor(coordinate);
if (deg < 10) {
sb.append('0');
}
sb.append(deg);
sb.append(delimiter);
coordinate -= deg;
coordinate *= 60.0;
return coordinate;
}
}

View file

@ -17,9 +17,11 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.view.ContextThemeWrapper;
import android.text.ClipboardManager;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.util.Linkify;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
@ -677,11 +679,19 @@ public class MenuBuilder {
Toast.LENGTH_SHORT).show();
}
protected CollapsableView getLocationCollapsableView(Map<String, String> locationData) {
protected CollapsableView getLocationCollapsableView(Map<Integer, String> locationData) {
LinearLayout llv = buildCollapsableContentView(mapActivity, true, true);
for (final Map.Entry<String, String> line : locationData.entrySet()) {
for (final Map.Entry<Integer, String> line : locationData.entrySet()) {
final TextViewEx button = buildButtonInCollapsableView(mapActivity, false, false);
button.setText(line.getValue());
if (line.getKey() == OsmAndFormatter.FORMAT_UTM || line.getKey() == OsmAndFormatter.FORMAT_OLC) {
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(line.getKey() == OsmAndFormatter.FORMAT_UTM ? "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);
} else {
button.setText(line.getValue());
}
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

View file

@ -288,10 +288,11 @@ public abstract class MenuController extends BaseMenuController implements Colla
protected void addMyLocationToPlainItems(LatLon latlon) {
final MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
String f = PointDescription.formatToHumanString(mapActivity, mapActivity.getMyApplication().getSettings().COORDINATES_FORMAT.get());
Map<String, String> locationData = PointDescription.getLocationData(mapActivity, latlon.getLatitude(), latlon.getLongitude(), true);
Map<Integer, String> locationData = PointDescription.getLocationData(mapActivity, latlon.getLatitude(), latlon.getLongitude(), true);
String title = locationData.get(PointDescription.LOCATION_LIST_HEADER);
locationData.remove(PointDescription.LOCATION_LIST_HEADER);
CollapsableView cv = builder.getLocationCollapsableView(locationData);
addPlainMenuItem(R.drawable.ic_action_get_my_location, locationData.get(f).replace("\n", " "), true, false, true, cv, null);
addPlainMenuItem(R.drawable.ic_action_get_my_location, title, false, false, true, cv, null);
}
}

View file

@ -673,10 +673,12 @@ public class AmenityMenuBuilder extends MenuBuilder {
0, false, null, true, 0, true, null, false);
}
String f = PointDescription.formatToHumanString(mapActivity, app.getSettings().COORDINATES_FORMAT.get());
Map<String, String> locationData = PointDescription.getLocationData(mapActivity, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), true);
Map<Integer, String> locationData = PointDescription.getLocationData(mapActivity, amenity.getLocation().getLatitude(), amenity.getLocation().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, locationData.get(f).replace("\n", " "), 0, true, cv,
buildRow(view, R.drawable.ic_action_get_my_location, null, title, 0, true, cv,
true, 1, false, null, false);
}