pR fixes 3

This commit is contained in:
madwasp79 2019-02-20 17:17:32 +02:00
parent 4bdbc170c9
commit a3d66bedd7
6 changed files with 37 additions and 36 deletions

View file

@ -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:

View file

@ -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<Token> tokens = tokenizer.tokenize(text);

View file

@ -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'

View file

@ -524,5 +524,4 @@ public class AndroidUtils {
}
return result;
}
}

View file

@ -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<BinaryMapDataObject> 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<BinaryMapDataObject>();
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;
}

View file

@ -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;