From 06f3ae09c61464f6111c61c8584cf8ad9948f8dd Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 15 Feb 2018 14:50:39 +0200 Subject: [PATCH] Add CorrdinateInputFormats --- OsmAnd/res/values/strings.xml | 5 + .../mapmarkers/CoordinateInputFormats.java | 103 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 7661a3e5a4..05f81738fb 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,11 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + DD°MM′SS″ + DD.DDDDDD° + DD.DDDDD° + DD°MM.MMMM′ + DD°MM.MMM′ E W S diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java new file mode 100644 index 0000000000..7a8968cf7e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputFormats.java @@ -0,0 +1,103 @@ +package net.osmand.plus.mapmarkers; + +import android.content.Context; +import android.support.annotation.IntDef; + +import net.osmand.plus.R; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class CoordinateInputFormats { + + public static final int DD_MM_MMM = 0; + public static final int DD_MM_MMMM = 1; + public static final int DD_DDDDD = 2; + public static final int DD_DDDDDD = 3; + public static final int DD_MM_SS = 4; + + @Retention(RetentionPolicy.SOURCE) + @IntDef({DD_MM_MMM, DD_MM_MMMM, DD_DDDDD, DD_DDDDDD, DD_MM_SS}) + @interface CoordinateInputFormatDef { + } + + public static String formatToHumanString(Context ctx, @CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + return ctx.getString(R.string.dd_mm_mmm_format); + case DD_MM_MMMM: + return ctx.getString(R.string.dd_mm_mmmm_format); + case DD_DDDDD: + return ctx.getString(R.string.dd_ddddd_format); + case DD_DDDDDD: + return ctx.getString(R.string.dd_dddddd_format); + case DD_MM_SS: + return ctx.getString(R.string.dd_mm_ss_format); + default: + return "Unknown format"; + } + } + + public static boolean containsThirdPart(@CoordinateInputFormatDef int format) { + return format == DD_MM_MMM || format == DD_MM_MMMM || format == DD_MM_SS; + } + + public static int getSecondPartSymbolsCount(@CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + case DD_MM_MMMM: + case DD_MM_SS: + return 2; + case DD_DDDDD: + return 5; + case DD_DDDDDD: + return 6; + default: + return 0; + } + } + + public static int getThirdPartSymbolsCount(@CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + return 3; + case DD_MM_MMMM: + return 4; + case DD_MM_SS: + return 2; + case DD_DDDDD: + case DD_DDDDDD: + default: + return 0; + } + } + + public static String getFirstSeparator(@CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + case DD_MM_MMMM: + case DD_MM_SS: + return "°"; + case DD_DDDDD: + case DD_DDDDDD: + return "."; + default: + return ""; + } + } + + public static String getSecondSeparator(@CoordinateInputFormatDef int format) { + switch (format) { + case DD_MM_MMM: + case DD_MM_MMMM: + return "."; + case DD_DDDDD: + case DD_DDDDDD: + return "°"; + case DD_MM_SS: + return "′"; + default: + return ""; + } + } +}