diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapAddressReaderAdapter.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapAddressReaderAdapter.java index b99bd972e1..2060c8c23a 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapAddressReaderAdapter.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapAddressReaderAdapter.java @@ -152,7 +152,7 @@ public class BinaryMapAddressReaderAdapter { switch (tag) { case 0: if (region.enName == null || region.enName.length() == 0) { - region.enName = region.name == null ? "" : TransliterationHelper.getInstance().transliterate(region.name); + region.enName = region.name == null ? "" : TransliterationHelper.transliterate(region.name); } return; case OsmandOdb.OsmAndAddressIndex.NAME_FIELD_NUMBER: diff --git a/OsmAnd-java/src/main/java/net/osmand/util/TransliterationHelper.java b/OsmAnd-java/src/main/java/net/osmand/util/TransliterationHelper.java index 274b254c6e..5ab8c050a4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/TransliterationHelper.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/TransliterationHelper.java @@ -1,10 +1,12 @@ package net.osmand.util; -import com.atilika.kuromoji.ipadic.Token; -import com.atilika.kuromoji.ipadic.Tokenizer; + import java.util.HashMap; import java.util.List; import java.util.Map; + +import com.atilika.kuromoji.ipadic.Token; +import com.atilika.kuromoji.ipadic.Tokenizer; import net.osmand.PlatformUtil; import net.sf.junidecode.Junidecode; import org.apache.commons.logging.Log; @@ -17,7 +19,7 @@ public class TransliterationHelper { public final static String DEFAULT = "default"; public final static String JAPAN = "Japan"; - private static String country = DEFAULT; + private static String countryName = DEFAULT; private static Tokenizer tokenizer; @@ -26,41 +28,26 @@ public class TransliterationHelper { private TransliterationHelper() { } - static { - try { - instance = new TransliterationHelper(); - } catch (Exception e) { - LOG.debug(e.getMessage(), e); - } - } - - public static TransliterationHelper getInstance() { - return instance; - } - - public static void setCountry(String countryName) { - if (!countryName.equals(country)) { + public static void setCountryName(String countryName) { + if (!countryName.equals(TransliterationHelper.countryName)) { switch (countryName) { case "Japan": { - country = JAPAN; + TransliterationHelper.countryName = JAPAN; break; } default: - country = DEFAULT; + TransliterationHelper.countryName = DEFAULT; break; } } } - public static String getCountry() { - return country; + public static String getCountryName() { + return countryName; } public static String transliterate(String text) { - if (tokenizer == null) { - tokenizer = new Tokenizer(); - } - switch (country) { + switch (countryName) { case DEFAULT: return Junidecode.unidecode(text); case JAPAN: @@ -71,6 +58,10 @@ public class TransliterationHelper { private static String japanese2Romaji(String text) { + if (tokenizer == null) { + tokenizer = new Tokenizer(); + } + boolean capitalizeWords = true; List tokens = tokenizer.tokenize(text); diff --git a/OsmAnd/build.gradle b/OsmAnd/build.gradle index 8695bd75c6..62873093a7 100644 --- a/OsmAnd/build.gradle +++ b/OsmAnd/build.gradle @@ -66,6 +66,12 @@ android { warningsAsErrors false } + packagingOptions { + exclude '/META-INF/CONTRIBUTORS.md' + exclude '/META-INF/LICENSE.md' + exclude '/META-INF/NOTICE.md' + } + // This is from OsmAndCore_android.aar - for some reason it's not inherited aaptOptions { // Don't compress any embedded resources @@ -391,7 +397,7 @@ dependencies { implementation 'com.moparisthebest:junidecode:0.1.1' implementation 'org.immutables:gson:2.5.0' implementation 'com.vividsolutions:jts-core:1.14.0' - + implementation 'com.atilika.kuromoji:kuromoji-ipadic:0.9.0' implementation 'com.squareup.picasso:picasso:2.71828' // JS core implementation group: 'org.mozilla', name: 'rhino', version: '1.7.9' diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index e423db4294..9f6593f8d3 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -524,5 +524,4 @@ public class AndroidUtils { } return result; } - } diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 4917dd9608..26ae65f013 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -1,7 +1,7 @@ package net.osmand.plus.render; -import static net.osmand.util.TransliterationHelper.setCountry; +import static net.osmand.util.TransliterationHelper.setCountryName; import gnu.trove.iterator.TIntObjectIterator; import gnu.trove.list.TLongList; @@ -303,14 +303,12 @@ public class MapRenderRepositories { if(library == null) { return; } + String countryInView = ""; boolean useLive = context.getSettings().USE_OSM_LIVE_FOR_ROUTING.get(); for (String mapName : files.keySet()) { BinaryMapIndexReader fr = files.get(mapName); if (fr != null && (fr.containsMapData(leftX, topY, rightX, bottomY, zoom) || fr.containsRouteData(leftX, topY, rightX, bottomY, zoom))) { - if (!Algorithms.isEmpty(fr.getCountryName())) { - TransliterationHelper.setCountry(fr.getCountryName()); - } if (!nativeFiles.contains(mapName)) { long time = System.currentTimeMillis(); nativeFiles.add(mapName); @@ -319,8 +317,13 @@ public class MapRenderRepositories { } log.debug("Native resource " + mapName + " initialized " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ } + if (fr.getCountryName().equals("Japan")) { + countryInView = fr.getCountryName(); + } } } + setCountryName(countryInView); + } private void readRouteDataAsMapObjects(SearchRequest sr, BinaryMapIndexReader c, @@ -536,6 +539,7 @@ public class MapRenderRepositories { } MapIndex mi = null; searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, searchFilter); + String countryInView = ""; for (BinaryMapIndexReader c : files.values()) { boolean basemap = c.isBasemap(); searchRequest.clearSearchResults(); @@ -546,13 +550,15 @@ public class MapRenderRepositories { res = new ArrayList(); log.debug("Search failed " + c.getRegionNames(), e); //$NON-NLS-1$ } - if (res.size() > 0) { - TransliterationHelper.setCountry(c.getCountryName()); + if(res.size() > 0) { if(basemap) { renderedState |= 1; } else { renderedState |= 2; } + if (c.getCountryName().equals("Japan")) { + countryInView = c.getCountryName(); + } } for (BinaryMapDataObject r : res) { if (checkForDuplicateObjectIds && !basemap) { @@ -592,6 +598,7 @@ public class MapRenderRepositories { land[0] = true; } } + setCountryName(countryInView); return mi; } diff --git a/OsmAnd/src/net/osmand/plus/render/TextRenderer.java b/OsmAnd/src/net/osmand/plus/render/TextRenderer.java index 2d2397f5ef..429db5200b 100644 --- a/OsmAnd/src/net/osmand/plus/render/TextRenderer.java +++ b/OsmAnd/src/net/osmand/plus/render/TextRenderer.java @@ -35,8 +35,6 @@ import org.apache.commons.logging.Log; public class TextRenderer { - public final static Log LOG = PlatformUtil.getLog(TextRenderer.class); - private Paint paintText; private final Context context; private Paint paintIcon;