RTL issue - Applying correct text direction (ltr or rtl)

https://github.com/osmandapp/OsmAnd/issues/11212
This commit is contained in:
androiddevkotlin 2021-03-25 23:56:08 +02:00
parent ce475077fe
commit eeaf45ea98

View file

@ -3,6 +3,8 @@ package net.osmand.plus;
import android.content.Context; import android.content.Context;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import androidx.core.text.TextUtilsCompat;
import androidx.core.view.ViewCompat;
import com.jwetherell.openmap.common.LatLonPoint; import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.MGRSPoint; import com.jwetherell.openmap.common.MGRSPoint;
import com.jwetherell.openmap.common.UTMPoint; import com.jwetherell.openmap.common.UTMPoint;
@ -225,10 +227,10 @@ public class OsmAndFormatter {
} }
public static String getFormattedAzimuth(float bearing, AngularConstants angularConstant) { public static String getFormattedAzimuth(float bearing, AngularConstants angularConstant) {
while(bearing < -180.0) { while (bearing < -180.0) {
bearing += 360; bearing += 360;
} }
while(bearing > 360.0) { while (bearing > 360.0) {
bearing -= 360; bearing -= 360;
} }
switch (angularConstant) { switch (angularConstant) {
@ -380,18 +382,18 @@ public class OsmAndFormatter {
public static String toPublicString(CityType t, Context ctx) { public static String toPublicString(CityType t, Context ctx) {
switch (t) { switch (t) {
case CITY: case CITY:
return ctx.getString(R.string.city_type_city); return ctx.getString(R.string.city_type_city);
case HAMLET: case HAMLET:
return ctx.getString(R.string.city_type_hamlet); return ctx.getString(R.string.city_type_hamlet);
case TOWN: case TOWN:
return ctx.getString(R.string.city_type_town); return ctx.getString(R.string.city_type_town);
case VILLAGE: case VILLAGE:
return ctx.getString(R.string.city_type_village); return ctx.getString(R.string.city_type_village);
case SUBURB: case SUBURB:
return ctx.getString(R.string.city_type_suburb); return ctx.getString(R.string.city_type_suburb);
default: default:
break; break;
} }
return ""; return "";
} }
@ -402,7 +404,7 @@ public class OsmAndFormatter {
String typeName = amenity.getSubType(); String typeName = amenity.getSubType();
if (pt != null) { if (pt != null) {
typeName = pt.getTranslation(); typeName = pt.getTranslation();
} else if(typeName != null){ } else if (typeName != null) {
typeName = Algorithms.capitalizeFirstLetterAndLowercase(typeName.replace('_', ' ')); typeName = Algorithms.capitalizeFirstLetterAndLowercase(typeName.replace('_', ' '));
} }
String localName = amenity.getName(locale, transliterate); String localName = amenity.getName(locale, transliterate);
@ -506,18 +508,27 @@ public class OsmAndFormatter {
if (outputFormat == FORMAT_DEGREES_SHORT) { if (outputFormat == FORMAT_DEGREES_SHORT) {
result.append(formatCoordinate(lat, outputFormat)).append(" ").append(formatCoordinate(lon, outputFormat)); result.append(formatCoordinate(lat, outputFormat)).append(" ").append(formatCoordinate(lon, outputFormat));
} else if (outputFormat == FORMAT_DEGREES || outputFormat == FORMAT_MINUTES || outputFormat == FORMAT_SECONDS) { } else if (outputFormat == FORMAT_DEGREES || outputFormat == FORMAT_MINUTES || outputFormat == FORMAT_SECONDS) {
result boolean isLeftToRight = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_LTR;
.append(formatCoordinate(lat, outputFormat)).append(" ") if (isLeftToRight) {
.append(lat > 0 ? NORTH : SOUTH).append(", ") result
.append(formatCoordinate(lon, outputFormat)).append(" ") .append(formatCoordinate(lat, outputFormat)).append(" ")
.append(lon > 0 ? EAST : WEST); .append(lat > 0 ? NORTH : SOUTH).append(", ")
} else if (outputFormat == UTM_FORMAT) { .append(formatCoordinate(lon, outputFormat)).append(" ")
.append(lon > 0 ? EAST : WEST);
} else {
result
.append(formatCoordinate(lat, outputFormat)).append(" ")
.append(lon > 0 ? EAST : WEST).append(" ")
.append(formatCoordinate(lon, outputFormat)).append(", ")
.append(lat > 0 ? NORTH : SOUTH);
}
} else if (outputFormat == UTM_FORMAT) {
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon)); UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
result result
.append(pnt.zone_number) .append(pnt.zone_number)
.append(pnt.zone_letter).append(" ") .append(pnt.zone_letter).append(" ")
.append((long) pnt.easting).append(" ") .append((long) pnt.easting).append(" ")
.append((long) pnt.northing); .append((long) pnt.northing);
} else if (outputFormat == OLC_FORMAT) { } else if (outputFormat == OLC_FORMAT) {
String r; String r;
try { try {
@ -543,7 +554,7 @@ public class OsmAndFormatter {
return "Error. Wrong coordinates data!"; return "Error. Wrong coordinates data!";
} }
if ((outputType != FORMAT_DEGREES) && (outputType != FORMAT_MINUTES) && (outputType if ((outputType != FORMAT_DEGREES) && (outputType != FORMAT_MINUTES) && (outputType
!= FORMAT_SECONDS) && (outputType != FORMAT_DEGREES_SHORT)) { != FORMAT_SECONDS) && (outputType != FORMAT_DEGREES_SHORT)) {
return "Unknown Output Format!"; return "Unknown Output Format!";
} }
@ -566,11 +577,11 @@ public class OsmAndFormatter {
sb.append(degDf.format(coordinate)).append(DELIMITER_DEGREES); sb.append(degDf.format(coordinate)).append(DELIMITER_DEGREES);
} else if (outputType == FORMAT_MINUTES) { } else if (outputType == FORMAT_MINUTES) {
sb.append(minDf.format(formatCoordinate(coordinate, sb, DELIMITER_DEGREES))) sb.append(minDf.format(formatCoordinate(coordinate, sb, DELIMITER_DEGREES)))
.append(DELIMITER_MINUTES); .append(DELIMITER_MINUTES);
} else { } else {
sb.append(secDf.format(formatCoordinate( sb.append(secDf.format(formatCoordinate(
formatCoordinate(coordinate, sb, DELIMITER_DEGREES), sb, DELIMITER_MINUTES))) formatCoordinate(coordinate, sb, DELIMITER_DEGREES), sb, DELIMITER_MINUTES)))
.append(DELIMITER_SECONDS); .append(DELIMITER_SECONDS);
} }
return sb.toString(); return sb.toString();
} }