From 69a6210b4ad89c7c06c4cd5f4ce93917c5c21d46 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 25 Oct 2015 17:08:20 +0100 Subject: [PATCH 1/6] Update --- .../src/net/osmand/map/OsmandRegions.java | 169 ++++++++---------- 1 file changed, 72 insertions(+), 97 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index 9ed6c79ba6..b1f4e8227a 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -77,6 +77,13 @@ public class OsmandRegions { Integer metricType = null; Integer leftHandDrivingType = null; Integer roadSignsType = null; + + public String get(Integer tp, BinaryMapDataObject object) { + if(tp == null) { + return null; + } + return object.getNameByType(tp); + } } @@ -95,32 +102,20 @@ public class OsmandRegions { final String lc = downloadName.toLowerCase(); if (downloadNamesToFullNames.containsKey(lc)) { String fullName = downloadNamesToFullNames.get(lc); - if (includingParent) { - if (fullNamesToLocaleNames.containsKey(fullName)) { - return fullNamesToLocaleNames.get(fullName); - } - } else { - if (fullNamesNoParentToLocaleNames.containsKey(fullName)) { - return fullNamesNoParentToLocaleNames.get(fullName); - } - } + return getLocaleNameByFullName(fullName, includingParent); } return downloadName.replace('_', ' '); } public String getLocaleNameByFullName(String fullName, boolean includingParent) { - if (includingParent) { - if (fullNamesToLocaleNames.containsKey(fullName)) { - return fullNamesToLocaleNames.get(fullName); - } else { - return fullName.replace('_', ' '); - } + RegionData rd = fullNamesToRegionData.get(fullName); + if(rd == null) { + return fullName.replace('_', ' '); + } + if (includingParent && rd.parent != null) { + return rd.parent.getLocaleName() + " " + rd.getLocaleName(); } else { - if (fullNamesNoParentToLocaleNames.containsKey(fullName)) { - return fullNamesNoParentToLocaleNames.get(fullName); - } else { - return fullName.replace('_', ' '); - } + return rd.getLocaleName(); } } @@ -138,48 +133,12 @@ public class OsmandRegions { return null; } - public String getLocaleName(BinaryMapDataObject object) { - String locName = ""; - if(locName == null || locName.length() == 0){ - if(nameLocaleType != null) { - locName = object.getNameByType(nameLocaleType); - } - } - if(locName == null || locName.length() == 0){ - if(nameEnType != null) { - locName = object.getNameByType(nameEnType); - } - } - if(locName == null || locName.length() == 0){ - if(nameType != null) { - locName = object.getNameByType(nameType); - } - } - return locName; - } - - public String getParentFullName(BinaryMapDataObject o) { - if(parentFullName == null) { - return null; - } - return o.getNameByType(parentFullName); - } - - - public String getFullName(BinaryMapDataObject o) { - if(fullNameType == null) { - return null; - } - return o.getNameByType(fullNameType); - } public boolean isInitialized(){ return reader != null; } - - public boolean contain(BinaryMapDataObject bo, int tx, int ty) { int t = 0; for (int i = 1; i < bo.getPointsLength(); i++) { @@ -365,54 +324,27 @@ public class OsmandRegions { return false; } } - String parentFullName = getParentFullName(object); - String fullName = getFullName(object); - if(!Algorithms.isEmpty(parentFullName)) { - fullNamesToParentFullNames.put(fullName, parentFullName); - parentRelations.put(fullName, parentFullName); + RegionData rd = new RegionData(); + rd.downloadsId = mapIndexFields.get(mapIndexFields.downloadNameType, object); + rd.regionFullName = mapIndexFields.get(mapIndexFields.fullNameType, object); + rd.regionParentFullName = mapIndexFields.get(mapIndexFields.parentFullName, object); + if(!Algorithms.isEmpty(rd.regionParentFullName)) { + parentRelations.put(rd.regionFullName, rd.regionParentFullName); } - String locName = getLocaleName(object); - if(!Algorithms.isEmpty(locName)){ - fullNamesToLocaleNames.put(fullName, locName); - fullNamesNoParentToLocaleNames.put(fullName, locName); - } + rd.regionName = mapIndexFields.get(mapIndexFields.nameType, object); + rd.regionNameLocale = mapIndexFields.get(mapIndexFields.nameLocaleType, object); + rd.regionNameEn = mapIndexFields.get(mapIndexFields.nameEnType, object); + rd.regionLang = mapIndexFields.get(mapIndexFields.langType, object); + rd.regionLeftHandDriving = mapIndexFields.get(mapIndexFields.leftHandDrivingType, object); + rd.regionMetric = mapIndexFields.get(mapIndexFields.metricType, object); + rd.regionRoadSigns = mapIndexFields.get(mapIndexFields.roadSignsType, object); - String lang = getLang(object); - if(!Algorithms.isEmpty(lang)){ - fullNamesToLangs.put(fullName, lang); - } - String metric = getMetric(object); - if(!Algorithms.isEmpty(metric)){ - fullNamesToMetrics.put(fullName, metric); - } - String leftHandDriving = getLeftHandDriving(object); - if(!Algorithms.isEmpty(leftHandDriving)){ - fullNamesToLeftHandDrivings.put(fullName, leftHandDriving); - } String roadSigns = getRoadSigns(object); if(!Algorithms.isEmpty(roadSigns)){ fullNamesToRoadSigns.put(fullName, roadSigns); } - MapIndex mi = object.getMapIndex(); - TIntObjectIterator it = object.getObjectNames().iterator(); - StringBuilder ind = new StringBuilder(); - while(it.hasNext()) { - it.advance(); - TagValuePair tp = mi.decodeType(it.key()); - if (tp.tag.equals("key_name") && Algorithms.isEmpty(locName)) { - String str = Algorithms.capitalizeFirstLetterAndLowercase(it.value().replace('_', '-')); - fullNamesToLocaleNames.put(fullName, str); - fullNamesNoParentToLocaleNames.put(fullName, str); - } - if(tp.tag.startsWith("name") || tp.tag.equals("key_name")) { - final String vl = it.value().toLowerCase(); -// if (!CollatorStringMatcher.ccontains(clt, ind.toString(), vl)) { - if(ind.indexOf(vl) == -1) { - ind.append(" ").append(vl); - } - } - } + rd.searchText = getSearchIndex(object); fullNamesToLowercaseIndex.put(fullName, ind.toString()); String downloadName = getDownloadName(object); if(downloadName != null) { @@ -426,6 +358,25 @@ public class OsmandRegions { } + private String getSearchIndex(BinaryMapDataObject object) { + MapIndex mi = object.getMapIndex(); + TIntObjectIterator it = object.getObjectNames().iterator(); + StringBuilder ind = new StringBuilder(); + while(it.hasNext()) { + it.advance(); + TagValuePair tp = mi.decodeType(it.key()); + if(tp.tag.startsWith("name") || tp.tag.equals("key_name")) { + final String vl = it.value().toLowerCase(); +// if (!CollatorStringMatcher.ccontains(clt, ind.toString(), vl)) { + if(ind.indexOf(vl) == -1) { + ind.append(" ").append(vl); + } + } + } + return ind.toString(); + } + + @Override public boolean isCancelled() { return false; @@ -458,6 +409,7 @@ public class OsmandRegions { } + private boolean isDownloadOfType(BinaryMapDataObject object, String type) { int[] addtypes = object.getAdditionalTypes(); for(int i = 0; i < addtypes.length; i++) { @@ -601,12 +553,35 @@ public class OsmandRegions { public static class RegionData { + // filled by osmand regions + protected RegionData parent = null; + protected String regionLeftHandDriving; + protected String regionLang; + protected String regionMetric; + protected String regionRoadSigns; + protected String regionFullName; + protected String regionParentFullName; + protected String regionName; + protected String regionNameEn; + protected String regionNameLocale; + + /// String regionId; private String downloadsId; private String name; private String searchText; private LatLon center; + public String getLocaleName() { + if(!Algorithms.isEmpty(regionNameLocale)) { + return regionNameLocale; + } + if(!Algorithms.isEmpty(regionNameEn)) { + return regionNameEn; + } + return regionName; + } + public LatLon getCenter() { return center; } From 6c445aed91cbb5d5c1cf9f8f5170a2f860d14a7d Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 25 Oct 2015 17:24:40 +0100 Subject: [PATCH 2/6] clean structure --- .../src/net/osmand/map/OsmandRegions.java | 211 ++++++++---------- 1 file changed, 90 insertions(+), 121 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index b1f4e8227a..a166aaa8c1 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -46,27 +46,16 @@ public class OsmandRegions { public static final String FIELD_ROAD_SIGNS = "road_signs"; private BinaryMapIndexReader reader; + private String locale = "en"; Map fullNamesToRegionData = new HashMap(); - Map> countriesByDownloadName = new HashMap>(); Map downloadNamesToFullNames = new HashMap(); -// Map fullNamesToLocaleNames = new HashMap(); -// Map fullNamesNoParentToLocaleNames = new HashMap(); -// Map fullMapNamesToDownloadNames = new HashMap(); -// Map fullNamesToLowercaseIndex = new HashMap(); -// Map fullNamesToParentFullNames = new HashMap(); -// Map fullNamesToDownloadNames = new HashMap(); -// Map fullNamesToLangs = new HashMap(); -// Map fullNamesToMetrics = new HashMap(); -// Map fullNamesToLeftHandDrivings = new HashMap(); -// Map fullNamesToRoadSigns = new HashMap(); + Map> countriesByDownloadName = new HashMap>(); QuadTree quadTree = null ; - String locale = "en"; MapIndexFields mapIndexFields = new MapIndexFields(); private class MapIndexFields { - MapIndex mapIndex; Integer parentFullName = null; Integer fullNameType = null; Integer downloadNameType = null; @@ -90,7 +79,7 @@ public class OsmandRegions { public void prepareFile(String fileName) throws IOException { reader = new BinaryMapIndexReader(new RandomAccessFile(fileName, "r"), new File(fileName)); - initLocaleNames(); + initRegionData(); } public boolean containsCountry(String name){ @@ -119,21 +108,6 @@ public class OsmandRegions { } } - public String getDownloadNameIndexLowercase(String downloadName) { - if(downloadName == null) { - return null; - } - final String lc = downloadName.toLowerCase(); - if (downloadNamesToFullNames.containsKey(lc)) { - String fullName = downloadNamesToFullNames.get(lc); - if (fullNamesToLowercaseIndex.containsKey(fullName)) { - return fullNamesToLowercaseIndex.get(fullName); - } - } - return null; - } - - public boolean isInitialized(){ return reader != null; @@ -297,19 +271,12 @@ public class OsmandRegions { this.locale = locale; } - public String getMapDownloadType(String fullname) { - return fullMapNamesToDownloadNames.get(fullname); + + public RegionData getRegionData(String fullname) { + return fullNamesToRegionData.get(fullname); } - public String getDownloadName(String fullname) { - return fullNamesToDownloadNames.get(fullname); - } - - public String getParentFullName(String fullname) { - return fullNamesToParentFullNames.get(fullname); - } - - public void initLocaleNames() throws IOException { + public void initRegionData() throws IOException { // final Collator clt = OsmAndCollator.primaryCollator(); final Map parentRelations = new LinkedHashMap(); final ResultMatcher resultMatcher = new ResultMatcher() { @@ -324,59 +291,15 @@ public class OsmandRegions { return false; } } - RegionData rd = new RegionData(); - rd.downloadsId = mapIndexFields.get(mapIndexFields.downloadNameType, object); - rd.regionFullName = mapIndexFields.get(mapIndexFields.fullNameType, object); - rd.regionParentFullName = mapIndexFields.get(mapIndexFields.parentFullName, object); - if(!Algorithms.isEmpty(rd.regionParentFullName)) { - parentRelations.put(rd.regionFullName, rd.regionParentFullName); - } - rd.regionName = mapIndexFields.get(mapIndexFields.nameType, object); - rd.regionNameLocale = mapIndexFields.get(mapIndexFields.nameLocaleType, object); - rd.regionNameEn = mapIndexFields.get(mapIndexFields.nameEnType, object); - rd.regionLang = mapIndexFields.get(mapIndexFields.langType, object); - rd.regionLeftHandDriving = mapIndexFields.get(mapIndexFields.leftHandDrivingType, object); - rd.regionMetric = mapIndexFields.get(mapIndexFields.metricType, object); - rd.regionRoadSigns = mapIndexFields.get(mapIndexFields.roadSignsType, object); - - String roadSigns = getRoadSigns(object); - if(!Algorithms.isEmpty(roadSigns)){ - fullNamesToRoadSigns.put(fullName, roadSigns); - } - - rd.searchText = getSearchIndex(object); - fullNamesToLowercaseIndex.put(fullName, ind.toString()); - String downloadName = getDownloadName(object); - if(downloadName != null) { - fullNamesToDownloadNames.put(fullName, downloadName); - downloadNamesToFullNames.put(downloadName, fullName); - if(isDownloadOfType(object, MAP_TYPE)) { - fullMapNamesToDownloadNames.put(fullName, downloadName); - } + RegionData rd = initRegionData(parentRelations, object); + if(rd == null) { + return false; } + downloadNamesToFullNames.put(rd.regionDownloadName, rd.regionFullName); + fullNamesToRegionData.put(rd.regionFullName, rd); return false; } - - private String getSearchIndex(BinaryMapDataObject object) { - MapIndex mi = object.getMapIndex(); - TIntObjectIterator it = object.getObjectNames().iterator(); - StringBuilder ind = new StringBuilder(); - while(it.hasNext()) { - it.advance(); - TagValuePair tp = mi.decodeType(it.key()); - if(tp.tag.startsWith("name") || tp.tag.equals("key_name")) { - final String vl = it.value().toLowerCase(); -// if (!CollatorStringMatcher.ccontains(clt, ind.toString(), vl)) { - if(ind.indexOf(vl) == -1) { - ind.append(" ").append(vl); - } - } - } - return ind.toString(); - } - - @Override public boolean isCancelled() { return false; @@ -387,29 +310,72 @@ public class OsmandRegions { for(Map.Entry e : parentRelations.entrySet()) { String fullName = e.getKey(); String parentFullName = e.getValue(); - String parentParentFulName = parentRelations.get(parentFullName); - if(!Algorithms.isEmpty(parentFullName) && - !Algorithms.isEmpty(parentParentFulName)) { - if(parentParentFulName.contains("russia") || parentParentFulName.contains("japan")) { - parentFullName = parentParentFulName; - } - String locPrefix = fullNamesToLocaleNames.get(parentFullName); - String locName = fullNamesToLocaleNames.get(fullName); - if(locPrefix == null || locName == null) { - throw new IllegalStateException("There is no prefix registered for " + fullName + " (" + parentFullName + ") "); - } - fullNamesToLocaleNames.put(fullName, locPrefix + " " + locName); - fullNamesNoParentToLocaleNames.put(fullName, locName); - // don't add parent to index -// String index = fullNamesToLowercaseIndex.get(fullName); -// String prindex = fullNamesToLowercaseIndex.get(parentFullName); -// fullNamesToLowercaseIndex.put(fullName, index + " " + prindex); + // String parentParentFulName = parentRelations.get(parentFullName); // could be used for japan/russia + RegionData rd = fullNamesToRegionData.get(fullName); + if(rd != null) { + rd.parent = fullNamesToRegionData.get(parentFullName); } } } + private RegionData initRegionData(final Map parentRelations, BinaryMapDataObject object) { + RegionData rd = new RegionData(); + rd.regionDownloadName = mapIndexFields.get(mapIndexFields.downloadNameType, object); + rd.regionFullName = mapIndexFields.get(mapIndexFields.fullNameType, object); + if(Algorithms.isEmpty(rd.regionDownloadName) || Algorithms.isEmpty(rd.regionFullName)) { + return null; + } + double cx = 0; + double cy = 0; + for(int i = 0; i 0) { + cx /= object.getPointsLength(); + cy /= object.getPointsLength(); + rd.regionCenter = new LatLon(MapUtils.get31LatitudeY((int) cy), MapUtils.get31LongitudeX((int) cx)); + } + + rd.regionParentFullName = mapIndexFields.get(mapIndexFields.parentFullName, object); + if(!Algorithms.isEmpty(rd.regionParentFullName)) { + parentRelations.put(rd.regionFullName, rd.regionParentFullName); + } + rd.regionName = mapIndexFields.get(mapIndexFields.nameType, object); + rd.regionNameLocale = mapIndexFields.get(mapIndexFields.nameLocaleType, object); + rd.regionNameEn = mapIndexFields.get(mapIndexFields.nameEnType, object); + rd.regionLang = mapIndexFields.get(mapIndexFields.langType, object); + rd.regionLeftHandDriving = mapIndexFields.get(mapIndexFields.leftHandDrivingType, object); + rd.regionMetric = mapIndexFields.get(mapIndexFields.metricType, object); + rd.regionRoadSigns = mapIndexFields.get(mapIndexFields.roadSignsType, object); + rd.regionSearchText = getSearchIndex(object); + rd.regionMapDownload = isDownloadOfType(object, MAP_TYPE); + return rd; + } + + private String getSearchIndex(BinaryMapDataObject object) { + MapIndex mi = object.getMapIndex(); + TIntObjectIterator it = object.getObjectNames().iterator(); + StringBuilder ind = new StringBuilder(); + while(it.hasNext()) { + it.advance(); + TagValuePair tp = mi.decodeType(it.key()); + if(tp.tag.startsWith("name") || tp.tag.equals("key_name")) { + final String vl = it.value().toLowerCase(); +// if (!CollatorStringMatcher.ccontains(clt, ind.toString(), vl)) { + if(ind.indexOf(vl) == -1) { + ind.append(" ").append(vl); + } + } + } + return ind.toString(); + } + + + + private boolean isDownloadOfType(BinaryMapDataObject object, String type) { int[] addtypes = object.getAdditionalTypes(); for(int i = 0; i < addtypes.length; i++) { @@ -433,10 +399,7 @@ public class OsmandRegions { return false; } initTypes(object); - String nm = object.getNameByType(downloadNameType); -// if(nm != null) { -// System.out.println((c++) +" " + nm); -// } + String nm = mapIndexFields.get(mapIndexFields.downloadNameType, object); if (!countriesByDownloadName.containsKey(nm)) { LinkedList ls = new LinkedList(); countriesByDownloadName.put(nm, ls); @@ -492,7 +455,7 @@ public class OsmandRegions { private void initTypes(BinaryMapDataObject object) { if (mapIndexFields == null) { mapIndexFields = new MapIndexFields(); - mapIndexFields.mapIndex = object.getMapIndex(); + // mapIndexFields.mapIndex = object.getMapIndex(); mapIndexFields.downloadNameType = object.getMapIndex().getRule(FIELD_DOWNLOAD_NAME, null); mapIndexFields.nameType = object.getMapIndex().getRule(FIELD_NAME, null); mapIndexFields.nameEnType = object.getMapIndex().getRule(FIELD_NAME_EN, null); @@ -515,7 +478,7 @@ public class OsmandRegions { Set found = new TreeSet(); for (BinaryMapDataObject b : cs) { - String nm = b.getNameByType(or.nameEnType); + String nm = b.getNameByType(or.mapIndexFields.nameEnType); if(nm == null) { nm = b.getName(); } @@ -553,8 +516,8 @@ public class OsmandRegions { public static class RegionData { - // filled by osmand regions protected RegionData parent = null; + // filled by osmand regions protected String regionLeftHandDriving; protected String regionLang; protected String regionMetric; @@ -564,13 +527,11 @@ public class OsmandRegions { protected String regionName; protected String regionNameEn; protected String regionNameLocale; + protected String regionSearchText; + protected String regionDownloadName; + protected boolean regionMapDownload; + protected LatLon regionCenter; - /// - String regionId; - private String downloadsId; - private String name; - private String searchText; - private LatLon center; public String getLocaleName() { if(!Algorithms.isEmpty(regionNameLocale)) { @@ -583,13 +544,21 @@ public class OsmandRegions { } public LatLon getCenter() { - return center; + return regionCenter; } public String getSearchText() { - return searchText; + return regionSearchText; } + + + ///TODO investigate do we need it ??? + String regionId; + private String downloadsId; + private String name; + + public String getName() { return name; } From aec0b252c3627caa30f6f48676c40c9a0d1d9200 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 25 Oct 2015 17:33:12 +0100 Subject: [PATCH 3/6] clean structure --- .../src/net/osmand/map/OsmandRegions.java | 48 ++++++++++++++++++- OsmAnd/src/net/osmand/plus/WorldRegion.java | 4 +- .../plus/download/DownloadActivity.java | 10 ++-- .../download/ui/SearchDialogFragment.java | 4 +- .../plus/views/DownloadedRegionsLayer.java | 9 ++-- 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index a166aaa8c1..974e4df1d7 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -275,6 +275,18 @@ public class OsmandRegions { public RegionData getRegionData(String fullname) { return fullNamesToRegionData.get(fullname); } + + public String getDownloadName(BinaryMapDataObject o) { + return mapIndexFields.get(mapIndexFields.downloadNameType, o); + } + + public String getFullName(BinaryMapDataObject o) { + return mapIndexFields.get(mapIndexFields.fullNameType, o); + } + + public List getAllRegionData() { + return new ArrayList(fullNamesToRegionData.values()); + } public void initRegionData() throws IOException { // final Collator clt = OsmAndCollator.primaryCollator(); @@ -533,6 +545,10 @@ public class OsmandRegions { protected LatLon regionCenter; + public boolean isRegionMapDownload() { + return regionMapDownload; + } + public String getLocaleName() { if(!Algorithms.isEmpty(regionNameLocale)) { return regionNameLocale; @@ -543,14 +559,33 @@ public class OsmandRegions { return regionName; } - public LatLon getCenter() { + public String getRegionDownloadName() { + return regionDownloadName; + } + + public String getRegionLeftHandDriving() { + return regionLeftHandDriving; + } + + public String getRegionMetric() { + return regionMetric; + } + + public String getRegionRoadSigns() { + return regionRoadSigns; + } + + public LatLon getRegionCenter() { return regionCenter; } - public String getSearchText() { + public String getRegionSearchText() { return regionSearchText; } + public String getRegionLang() { + return regionLang; + } ///TODO investigate do we need it ??? @@ -570,5 +605,14 @@ public class OsmandRegions { public String getDownloadsId() { return downloadsId; } + + } + + + + + + + } diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java index bc6d0a531e..49f8881cd3 100644 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ b/OsmAnd/src/net/osmand/plus/WorldRegion.java @@ -12,6 +12,7 @@ import java.util.Map.Entry; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.map.OsmandRegions; +import net.osmand.map.OsmandRegions.RegionData; import net.osmand.util.Algorithms; import android.content.res.Resources; @@ -117,8 +118,7 @@ public class WorldRegion { } public void loadWorldRegions(OsmandApplication app) { - OsmandRegions osmandRegions = app.getRegions(); - Map loadedItems = osmandRegions.getFullNamesToLowercaseCopy(); + List loadedItems = osmandRegions.getAllRegionData(); if (loadedItems.size() == 0) { return; } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index d33b198f86..f33077069d 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -20,6 +20,7 @@ import android.widget.Toast; import net.osmand.IProgress; import net.osmand.PlatformUtil; import net.osmand.access.AccessibleToast; +import net.osmand.map.OsmandRegions.RegionData; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.DrivingRegion; @@ -500,9 +501,10 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl // TODO test set correctly (4 tests): when you download first Australia, Japan, Luxembourgh, US getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false); DrivingRegion drg = null; - boolean americanSigns = "american".equals(reg.getRoadSigns(getMyApplication().getRegions())); - boolean leftHand = "yes".equals(reg.getLeftHandDriving(getMyApplication().getRegions())); - MetricsConstants mc = "miles".equals(reg.getMetric(getMyApplication().getRegions())) ? + RegionData rd = reg.getRegionData(); + boolean americanSigns = "american".equals(rd.getRegionRoadSigns()); + boolean leftHand = "yes".equals(rd.getRegionLeftHandDriving()); + MetricsConstants mc = "miles".equals(rd.getRegionMetric()) ? MetricsConstants.MILES_AND_FOOTS : MetricsConstants.KILOMETERS_AND_METERS; for (DrivingRegion r : DrivingRegion.values()) { if(r.americanSigns == americanSigns && r.leftHandDriving == leftHand && @@ -514,7 +516,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl if (drg != null) { getMyApplication().getSettings().DRIVING_REGION.set(drg); } - String lng = reg.getLang(getMyApplication().getRegions()); + String lng = rd.getRegionLang(); if (lng != null) { String setTts = null; for (String s : OsmandSettings.TTS_AVAILABLE_VOICES) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java index 39426e08c9..426aa95167 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java @@ -330,8 +330,8 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven private void processGroup(DownloadResourceGroup group, List filter, List> conds) { String name = null; - if (group.getRegion() != null && group.getRegion().getSearchText() != null) { - name = group.getRegion().getSearchText().toLowerCase(); + if (group.getRegion() != null && group.getRegion().getRegionData().getRegionSearchText() != null) { + name = group.getRegion().getRegionData().getRegionSearchText().toLowerCase(); } if (name == null) { name = group.getName(ctx).toLowerCase(); diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index 9c7397a3de..37595f0388 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -12,6 +12,7 @@ import net.osmand.binary.BinaryMapDataObject; import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; import net.osmand.map.OsmandRegions; +import net.osmand.map.OsmandRegions.RegionData; import net.osmand.plus.R; import net.osmand.plus.resources.ResourceManager; import net.osmand.util.Algorithms; @@ -248,10 +249,10 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { continue; } String fullName = osmandRegions.getFullName(o); - String downloadName = osmandRegions.getMapDownloadType(fullName); - if (!Algorithms.isEmpty(downloadName)) { - String name = osmandRegions.getLocaleName(downloadName, true); // Algorithms.capitalizeFirstLetterAndLowercase(o.getName()); - if (checkIfObjectDownloaded(downloadName)) { + RegionData rd = osmandRegions.getRegionData(fullName); + if (rd != null && rd.isRegionMapDownload()) { + String name = rd.getLocaleName(); + if (checkIfObjectDownloaded(rd.getRegionDownloadName())) { return null; } if (!set.add(name)) { From cd6675b64f42b6e93e19cfb16b8e2ff3c0638c5e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 25 Oct 2015 21:25:08 +0100 Subject: [PATCH 4/6] Update --- .../src/net/osmand/map/OsmandRegions.java | 311 ++++++++++-------- .../src/net/osmand/map/WorldRegion.java | 152 +++++++++ .../src/net/osmand/plus/AppInitializer.java | 38 ++- .../net/osmand/plus/OsmandApplication.java | 4 - OsmAnd/src/net/osmand/plus/WorldRegion.java | 264 --------------- .../plus/download/DownloadActivity.java | 81 +++-- .../plus/download/DownloadResourceGroup.java | 9 +- .../plus/download/DownloadResources.java | 14 +- .../download/ui/SearchDialogFragment.java | 47 ++- .../plus/views/DownloadedRegionsLayer.java | 6 +- 10 files changed, 425 insertions(+), 501 deletions(-) create mode 100644 OsmAnd-java/src/net/osmand/map/WorldRegion.java delete mode 100644 OsmAnd/src/net/osmand/plus/WorldRegion.java diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index 974e4df1d7..8f578f1107 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -9,6 +9,8 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -19,6 +21,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; +import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapIndexReader; @@ -47,13 +50,18 @@ public class OsmandRegions { private BinaryMapIndexReader reader; private String locale = "en"; - - Map fullNamesToRegionData = new HashMap(); + private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandRegions.class); + + WorldRegion worldRegion = new WorldRegion(WorldRegion.WORLD, WorldRegion.WORLD); + Map fullNamesToRegionData = new HashMap(); Map downloadNamesToFullNames = new HashMap(); Map> countriesByDownloadName = new HashMap>(); + - QuadTree quadTree = null ; - MapIndexFields mapIndexFields = new MapIndexFields(); + + QuadTree quadTree ; + MapIndexFields mapIndexFields ; + RegionTranslation translator; private class MapIndexFields { Integer parentFullName = null; @@ -74,12 +82,65 @@ public class OsmandRegions { return object.getNameByType(tp); } } + + + public void setTranslator(RegionTranslation translator) { + this.translator = translator; + } public void prepareFile(String fileName) throws IOException { reader = new BinaryMapIndexReader(new RandomAccessFile(fileName, "r"), new File(fileName)); - initRegionData(); +// final Collator clt = OsmAndCollator.primaryCollator(); + final Map parentRelations = new LinkedHashMap(); + final ResultMatcher resultMatcher = new ResultMatcher() { + + @Override + public boolean publish(BinaryMapDataObject object) { + initTypes(object); + int[] types = object.getTypes(); + for(int i = 0; i < types.length; i++ ) { + TagValuePair tp = object.getMapIndex().decodeType(types[i]); + if("boundary".equals(tp.value)) { + return false; + } + } + WorldRegion rd = initRegionData(parentRelations, object); + if(rd == null) { + return false; + } + if(rd.regionDownloadName != null) { + downloadNamesToFullNames.put(rd.regionDownloadName, rd.regionFullName); + } + fullNamesToRegionData.put(rd.regionFullName, rd); + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + }; + iterateOverAllObjects(resultMatcher); + // post process download names + for(Map.Entry e : parentRelations.entrySet()) { + String fullName = e.getKey(); + String parentFullName = e.getValue(); + // String parentParentFulName = parentRelations.get(parentFullName); // could be used for japan/russia + WorldRegion rd = fullNamesToRegionData.get(fullName); + WorldRegion parent = fullNamesToRegionData.get(parentFullName); + if(parent != null && rd != null) { + parent.addSubregion(rd); + } + if(rd != null) { + rd.superregion = parent; + } + if(parent != null) { + parent.subregions.add(rd); + } + } + structureWorldRegions(new ArrayList(fullNamesToRegionData.values())); } public boolean containsCountry(String name){ @@ -97,16 +158,20 @@ public class OsmandRegions { } public String getLocaleNameByFullName(String fullName, boolean includingParent) { - RegionData rd = fullNamesToRegionData.get(fullName); + WorldRegion rd = fullNamesToRegionData.get(fullName); if(rd == null) { return fullName.replace('_', ' '); } - if (includingParent && rd.parent != null) { - return rd.parent.getLocaleName() + " " + rd.getLocaleName(); + if (includingParent && rd.superregion != null) { + return rd.superregion.getLocaleName() + " " + rd.getLocaleName(); } else { return rd.getLocaleName(); } } + + public WorldRegion getWorldRegion() { + return worldRegion; + } public boolean isInitialized(){ @@ -128,7 +193,6 @@ public class OsmandRegions { } public boolean intersect(BinaryMapDataObject bo, int lx, int ty, int rx, int by) { - int t = 0; // 1. polygon in object if(contain(bo, lx, ty)) { return true; @@ -272,10 +336,14 @@ public class OsmandRegions { } - public RegionData getRegionData(String fullname) { + public WorldRegion getRegionData(String fullname) { return fullNamesToRegionData.get(fullname); } + public WorldRegion getRegionDataByDownloadName(String downloadName) { + return getRegionData(downloadNamesToFullNames.get(downloadName.toLowerCase())); + } + public String getDownloadName(BinaryMapDataObject o) { return mapIndexFields.get(mapIndexFields.downloadNameType, o); } @@ -284,66 +352,23 @@ public class OsmandRegions { return mapIndexFields.get(mapIndexFields.fullNameType, o); } - public List getAllRegionData() { - return new ArrayList(fullNamesToRegionData.values()); + public List getAllRegionData() { + return new ArrayList(fullNamesToRegionData.values()); } - public void initRegionData() throws IOException { -// final Collator clt = OsmAndCollator.primaryCollator(); - final Map parentRelations = new LinkedHashMap(); - final ResultMatcher resultMatcher = new ResultMatcher() { - - @Override - public boolean publish(BinaryMapDataObject object) { - initTypes(object); - int[] types = object.getTypes(); - for(int i = 0; i < types.length; i++ ) { - TagValuePair tp = object.getMapIndex().decodeType(types[i]); - if("boundary".equals(tp.value)) { - return false; - } - } - RegionData rd = initRegionData(parentRelations, object); - if(rd == null) { - return false; - } - downloadNamesToFullNames.put(rd.regionDownloadName, rd.regionFullName); - fullNamesToRegionData.put(rd.regionFullName, rd); - return false; - } - @Override - public boolean isCancelled() { - return false; - } - }; - iterateOverAllObjects(resultMatcher); - // post process download names - for(Map.Entry e : parentRelations.entrySet()) { - String fullName = e.getKey(); - String parentFullName = e.getValue(); - // String parentParentFulName = parentRelations.get(parentFullName); // could be used for japan/russia - RegionData rd = fullNamesToRegionData.get(fullName); - if(rd != null) { - rd.parent = fullNamesToRegionData.get(parentFullName); - } - } - - } - - - private RegionData initRegionData(final Map parentRelations, BinaryMapDataObject object) { - RegionData rd = new RegionData(); - rd.regionDownloadName = mapIndexFields.get(mapIndexFields.downloadNameType, object); - rd.regionFullName = mapIndexFields.get(mapIndexFields.fullNameType, object); - if(Algorithms.isEmpty(rd.regionDownloadName) || Algorithms.isEmpty(rd.regionFullName)) { + private WorldRegion initRegionData(final Map parentRelations, BinaryMapDataObject object) { + String regionDownloadName = mapIndexFields.get(mapIndexFields.downloadNameType, object); + String regionFullName = mapIndexFields.get(mapIndexFields.fullNameType, object); + if(Algorithms.isEmpty(regionFullName)) { return null; } + WorldRegion rd = new WorldRegion(regionFullName, regionDownloadName); double cx = 0; double cy = 0; - for(int i = 0; i 0) { cx /= object.getPointsLength(); @@ -509,6 +534,18 @@ public class OsmandRegions { public static void main(String[] args) throws IOException { OsmandRegions or = new OsmandRegions(); or.prepareFile("/Users/victorshcherb/osmand/repos/resources/countries-info/regions.ocbf"); + LinkedList lst = new LinkedList(); + lst.add(or.getWorldRegion()); +// int i =0; + while (!lst.isEmpty()) { + WorldRegion wd = lst.pollFirst(); + System.out.println((wd.superregion == null ? "" : wd.superregion.getLocaleName()) + " " + + wd.getLocaleName() + " " + wd.getRegionDownloadName()); +// if(i++ <=5) +// lst.addAll(wd.getSubregions()); + } + + or.cacheAllCountries(); // long t = System.currentTimeMillis(); // or.cacheAllCountries(); @@ -522,97 +559,83 @@ public class OsmandRegions { testCountry(or, 35.7521, 139.7887, "japan"); testCountry(or, 46.5145, 102.2580, "mongolia"); testCountry(or, 62.54, 43.36, "arkhangelsk oblast", "northwestern federal district"); - - } - - - public static class RegionData { - protected RegionData parent = null; - // filled by osmand regions - protected String regionLeftHandDriving; - protected String regionLang; - protected String regionMetric; - protected String regionRoadSigns; - protected String regionFullName; - protected String regionParentFullName; - protected String regionName; - protected String regionNameEn; - protected String regionNameLocale; - protected String regionSearchText; - protected String regionDownloadName; - protected boolean regionMapDownload; - protected LatLon regionCenter; + + + public interface RegionTranslation { - - public boolean isRegionMapDownload() { - return regionMapDownload; + public String getTranslation(String id); + } + + private void initWorldRegion(WorldRegion world, String id) { + WorldRegion rg = new WorldRegion(id); + rg.regionParentFullName = world.regionFullName; + if(translator != null) { + rg.regionName = translator.getTranslation(id); } - - public String getLocaleName() { - if(!Algorithms.isEmpty(regionNameLocale)) { - return regionNameLocale; - } - if(!Algorithms.isEmpty(regionNameEn)) { - return regionNameEn; - } - return regionName; - } - - public String getRegionDownloadName() { - return regionDownloadName; - } - - public String getRegionLeftHandDriving() { - return regionLeftHandDriving; - } - - public String getRegionMetric() { - return regionMetric; - } - - public String getRegionRoadSigns() { - return regionRoadSigns; - } - - public LatLon getRegionCenter() { - return regionCenter; - } - - public String getRegionSearchText() { - return regionSearchText; - } - - public String getRegionLang() { - return regionLang; - } - - - ///TODO investigate do we need it ??? - String regionId; - private String downloadsId; - private String name; - - - public String getName() { - return name; - } - - public String getRegionId() { - return regionId; - } - - public String getDownloadsId() { - return downloadsId; - } - + world.addSubregion(rg); } + public void structureWorldRegions(List loadedItems ) { + if (loadedItems.size() == 0) { + return; + } + WorldRegion world = new WorldRegion(WorldRegion.WORLD); + initWorldRegion(world, WorldRegion.AFRICA_REGION_ID); + initWorldRegion(world, WorldRegion.ASIA_REGION_ID); + initWorldRegion(world, WorldRegion.CENTRAL_AMERICA_REGION_ID); + initWorldRegion(world, WorldRegion.EUROPE_REGION_ID); + initWorldRegion(world, WorldRegion.NORTH_AMERICA_REGION_ID); + initWorldRegion(world, WorldRegion.RUSSIA_REGION_ID); + initWorldRegion(world, WorldRegion.SOUTH_AMERICA_REGION_ID); + Iterator it = loadedItems.iterator(); + while(it.hasNext()) { + WorldRegion region = it.next(); + if(region.superregion == null) { + boolean found = false; + for(WorldRegion worldSubregion : world.subregions) { + if(worldSubregion.getRegionId().equalsIgnoreCase(region.regionParentFullName)) { + worldSubregion.subregions.add(region); + found = true; + break; + } + } + if(found) { + it.remove(); + } + } else { + it.remove(); + } + } + Comparator nameComparator = new Comparator() { + @Override + public int compare(WorldRegion w1, WorldRegion w2) { + return w1.getLocaleName().compareTo(w2.getLocaleName()); + } + }; + sortSubregions(world, nameComparator); + this.worldRegion = world; + if (loadedItems.size() > 0) { + LOG.warn("Found orphaned regions: " + loadedItems.size()); + for (WorldRegion regionId : loadedItems) { + LOG.warn("FullName = " + regionId.regionFullName + + " parent=" + regionId.regionParentFullName); + } + } + } + private void sortSubregions(WorldRegion region, Comparator comparator) { + Collections.sort(region.subregions, comparator); + for (WorldRegion r : region.subregions) { + if (r.subregions.size() > 0) { + sortSubregions(r, comparator); + } + } + } } diff --git a/OsmAnd-java/src/net/osmand/map/WorldRegion.java b/OsmAnd-java/src/net/osmand/map/WorldRegion.java new file mode 100644 index 0000000000..fc0fe2ba96 --- /dev/null +++ b/OsmAnd-java/src/net/osmand/map/WorldRegion.java @@ -0,0 +1,152 @@ +package net.osmand.map; + +import java.util.LinkedList; +import java.util.List; + +import net.osmand.data.LatLon; +import net.osmand.util.Algorithms; + +public class WorldRegion { + + public static final String WORLD_BASEMAP = "world_basemap"; + public static final String AFRICA_REGION_ID = "africa"; + public static final String ASIA_REGION_ID = "asia"; + public static final String AUSTRALIA_AND_OCEANIA_REGION_ID = "australia-oceania"; + public static final String CENTRAL_AMERICA_REGION_ID = "centralamerica"; + public static final String EUROPE_REGION_ID = "europe"; + public static final String NORTH_AMERICA_REGION_ID = "northamerica"; + public static final String RUSSIA_REGION_ID = "russia"; + public static final String SOUTH_AMERICA_REGION_ID = "southamerica"; + protected static final String WORLD = "world"; + + // Hierarchy + protected WorldRegion superregion; + protected List subregions; + + // filled by osmand regions + protected String regionLeftHandDriving; + protected String regionLang; + protected String regionMetric; + protected String regionRoadSigns; + protected String regionFullName; + protected String regionParentFullName; + protected String regionName; + protected String regionNameEn; + protected String regionNameLocale; + protected String regionSearchText; + protected String regionDownloadName; + protected boolean regionMapDownload; + protected LatLon regionCenter; + + + public boolean isRegionMapDownload() { + return regionMapDownload; + } + + public String getLocaleName() { + if(!Algorithms.isEmpty(regionNameLocale)) { + return regionNameLocale; + } + if(!Algorithms.isEmpty(regionNameEn)) { + return regionNameEn; + } + if(!Algorithms.isEmpty(regionName)) { + return regionName; + } + + return capitalize(regionFullName.replace('_', ' ')); + } + + public String getRegionDownloadName() { + return regionDownloadName; + } + + public String getRegionDownloadNameLC() { + return regionDownloadName == null ? null : regionDownloadName.toLowerCase(); + } + + public String getRegionLeftHandDriving() { + return regionLeftHandDriving; + } + + public String getRegionMetric() { + return regionMetric; + } + + public String getRegionRoadSigns() { + return regionRoadSigns; + } + + public LatLon getRegionCenter() { + return regionCenter; + } + + public String getRegionSearchText() { + return regionSearchText; + } + + public String getRegionLang() { + return regionLang; + } + + + public WorldRegion getSuperregion() { + return superregion; + } + + public List getSubregions() { + return subregions; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + WorldRegion that = (WorldRegion) o; + + return !(regionFullName != null ? !regionFullName.toLowerCase().equals(that.regionFullName.toLowerCase()) : that.regionFullName != null); + } + + @Override + public int hashCode() { + return regionFullName != null ? regionFullName.hashCode() : 0; + } + + public WorldRegion(String regionFullName, String downloadName) { + this.regionFullName = regionFullName; + this.regionDownloadName = downloadName; + superregion = null; + subregions = new LinkedList(); + + } + public WorldRegion(String id) { + this(id, null); + } + + public String getRegionId() { + return regionFullName; + } + + private String capitalize(String s) { + String[] words = s.split(" "); + if (words[0].length() > 0) { + StringBuilder sb = new StringBuilder(); + sb.append(Algorithms.capitalizeFirstLetterAndLowercase(words[0])); + for (int i = 1; i < words.length; i++) { + sb.append(" "); + sb.append(Algorithms.capitalizeFirstLetterAndLowercase(words[i])); + } + return sb.toString(); + } else { + return s; + } + } + + public void addSubregion(WorldRegion rd) { + subregions.add(rd); + rd.superregion = this; + } + +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index b02b0e00af..c8ffbb8626 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -14,6 +14,8 @@ import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.access.AccessibleAlertBuilder; import net.osmand.map.OsmandRegions; +import net.osmand.map.OsmandRegions.RegionTranslation; +import net.osmand.map.WorldRegion; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.plus.activities.DayNightHelper; @@ -254,7 +256,7 @@ public class AppInitializer implements IProgress { new FileOutputStream(file)); } app.regions.prepareFile(file.getAbsolutePath()); - loadWorldRegions(); + } } catch (Exception e) { warnings.add(e.getMessage()); @@ -262,9 +264,6 @@ public class AppInitializer implements IProgress { } } - private void loadWorldRegions() { - app.worldRegion.loadWorldRegions(app); - } private void initPoiTypes() { if(app.getAppPath("poi_types.xml").exists()) { @@ -317,16 +316,41 @@ public class AppInitializer implements IProgress { app.selectedGpxHelper = startupInit(new GpxSelectionHelper(app, app.savingTrackHelper), GpxSelectionHelper.class); app.favorites = startupInit(new FavouritesDbHelper(app), FavouritesDbHelper.class); app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class); - app.worldRegion = startupInit(new WorldRegion(), WorldRegion.class); - app.worldRegion.initWorld(); app.regions = startupInit(new OsmandRegions(), OsmandRegions.class); - app.regions.setLocale(app.getLanguage()); + updateRegionVars(); app.poiFilters = startupInit(new PoiFiltersHelper(app), PoiFiltersHelper.class); app.rendererRegistry = startupInit(new RendererRegistry(app), RendererRegistry.class); app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class); } + private void updateRegionVars() { + app.regions.setTranslator(new RegionTranslation() { + + @Override + public String getTranslation(String id) { + if(WorldRegion.AFRICA_REGION_ID.equals(id)){ + return app.getString(R.string.index_name_africa); + } else if(WorldRegion.ASIA_REGION_ID.equals(id)){ + return app.getString(R.string.index_name_asia); + } else if(WorldRegion.CENTRAL_AMERICA_REGION_ID.equals(id)){ + return app.getString(R.string.index_name_central_america); + } else if(WorldRegion.EUROPE_REGION_ID.equals(id)){ + return app.getString(R.string.index_name_europe); + } else if(WorldRegion.RUSSIA_REGION_ID.equals(id)){ + return app.getString(R.string.index_name_russia); + } else if(WorldRegion.NORTH_AMERICA_REGION_ID.equals(id)){ + return app.getString(R.string.index_name_north_america); + } else if(WorldRegion.SOUTH_AMERICA_REGION_ID.equals(id)){ + return app.getString(R.string.index_name_south_america); + } + return null; + } + }); + app.regions.setLocale(app.getLanguage()); + } + + private T startupInit(T object, Class class1) { long t = System.currentTimeMillis(); diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index ab4ae0917b..ae0be4814a 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -98,7 +98,6 @@ public class OsmandApplication extends Application { AvoidSpecificRoads avoidSpecificRoads; BRouterServiceConnection bRouterServiceConnection; OsmandRegions regions; - WorldRegion worldRegion; RoutingConfiguration.Builder defaultRoutingConfig; @@ -659,9 +658,6 @@ public class OsmandApplication extends Application { public OsmandRegions getRegions() { return regions; } - public WorldRegion getWorldRegion() { - return worldRegion; - } public boolean accessibilityExtensions() { return (Build.VERSION.SDK_INT < 14) ? getSettings().ACCESSIBILITY_EXTENSIONS.get() : false; diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java deleted file mode 100644 index 49f8881cd3..0000000000 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ /dev/null @@ -1,264 +0,0 @@ -package net.osmand.plus; - -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import net.osmand.PlatformUtil; -import net.osmand.data.LatLon; -import net.osmand.map.OsmandRegions; -import net.osmand.map.OsmandRegions.RegionData; -import net.osmand.util.Algorithms; -import android.content.res.Resources; - -public class WorldRegion { - - public static final String AFRICA_REGION_ID = "africa"; - public static final String ASIA_REGION_ID = "asia"; - public static final String AUSTRALIA_AND_OCEANIA_REGION_ID = "australia-oceania"; - public static final String CENTRAL_AMERICA_REGION_ID = "centralamerica"; - public static final String EUROPE_REGION_ID = "europe"; - public static final String NORTH_AMERICA_REGION_ID = "northamerica"; - public static final String RUSSIA_REGION_ID = "russia"; - public static final String SOUTH_AMERICA_REGION_ID = "southamerica"; - public static final String WORLD = "world"; - - private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(WorldRegion.class); - - // Region data - private OsmandRegions.RegionData regionData; - - // Hierarchy - private WorldRegion superregion; - private List subregions; - private List flattenedSubregions; - - public OsmandRegions.RegionData getRegionData() { - return regionData; - } - - public String getName() { - return regionData.getName(); - } - - private String getRegionId() { - return regionData.getRegionId(); - } - - public WorldRegion getSuperregion() { - return superregion; - } - - public List getSubregions() { - return subregions; - } - - public List getFlattenedSubregions() { - return flattenedSubregions; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - WorldRegion that = (WorldRegion) o; - - return !(getName() != null ? !getName().toLowerCase().equals(that.getName().toLowerCase()) : that.getName() != null); - } - - @Override - public int hashCode() { - return getName() != null ? getName().hashCode() : 0; - } - - public WorldRegion() { - superregion = null; - subregions = new LinkedList<>(); - flattenedSubregions = new LinkedList<>(); - } - - public void initWorld() { - regionId = ""; - downloadsId = WORLD; - name = ""; - superregion = null; - } - - private WorldRegion init(String regionId, OsmandRegions osmandRegions, String name) { - this.regionId = regionId; - String downloadName = osmandRegions.getDownloadName(regionId); - if (downloadName != null) { - this.searchText = osmandRegions.getDownloadNameIndexLowercase(downloadName); - downloadsId = downloadName.toLowerCase(); - } else { - downloadsId = regionId.toLowerCase(); - } - if (name != null) { - this.name = name; - } else { - this.name = osmandRegions.getLocaleNameByFullName(regionId, false); - if (this.name == null) { - this.name = capitalize(regionId.replace('_', ' ')); - } - } - return this; - } - - - private void addSubregion(WorldRegion subregion, WorldRegion world) { - subregion.superregion = this; - subregions.add(subregion); - world.flattenedSubregions.add(subregion); - } - - public void loadWorldRegions(OsmandApplication app) { - List loadedItems = osmandRegions.getAllRegionData(); - if (loadedItems.size() == 0) { - return; - } - HashMap regionsLookupTable = new HashMap<>(loadedItems.size()); - // Create main regions - Resources res = app.getResources(); - - WorldRegion africaRegion = createRegionAs(AFRICA_REGION_ID, - loadedItems, osmandRegions, res.getString(R.string.index_name_africa)); - addSubregion(africaRegion, this); - regionsLookupTable.put(africaRegion.regionId, africaRegion); - - WorldRegion asiaRegion = createRegionAs(ASIA_REGION_ID, - loadedItems, osmandRegions, res.getString(R.string.index_name_asia)); - addSubregion(asiaRegion, this); - regionsLookupTable.put(asiaRegion.regionId, asiaRegion); - - WorldRegion australiaAndOceaniaRegion = createRegionAs(AUSTRALIA_AND_OCEANIA_REGION_ID, - loadedItems, osmandRegions, res.getString(R.string.index_name_oceania)); - addSubregion(australiaAndOceaniaRegion, this); - regionsLookupTable.put(australiaAndOceaniaRegion.regionId, australiaAndOceaniaRegion); - - WorldRegion centralAmericaRegion = createRegionAs(CENTRAL_AMERICA_REGION_ID, - loadedItems, osmandRegions, res.getString(R.string.index_name_central_america)); - addSubregion(centralAmericaRegion, this); - regionsLookupTable.put(centralAmericaRegion.getRegionId(), centralAmericaRegion); - - WorldRegion europeRegion = createRegionAs(EUROPE_REGION_ID, - loadedItems, osmandRegions, res.getString(R.string.index_name_europe)); - addSubregion(europeRegion, this); - regionsLookupTable.put(europeRegion.getRegionId(), europeRegion); - - WorldRegion northAmericaRegion = createRegionAs(NORTH_AMERICA_REGION_ID, - loadedItems, osmandRegions, res.getString(R.string.index_name_north_america)); - addSubregion(northAmericaRegion, this); - regionsLookupTable.put(northAmericaRegion.getRegionId(), northAmericaRegion); - - WorldRegion russiaRegion = createRegionAs(RUSSIA_REGION_ID, - loadedItems, osmandRegions, res.getString(R.string.index_name_russia)); - addSubregion(russiaRegion, this); - regionsLookupTable.put(russiaRegion.getRegionId(), russiaRegion); - - WorldRegion southAmericaRegion = createRegionAs(SOUTH_AMERICA_REGION_ID, - loadedItems, osmandRegions, res.getString(R.string.index_name_south_america)); - addSubregion(southAmericaRegion, this); - regionsLookupTable.put(southAmericaRegion.getRegionId(), southAmericaRegion); - - // Process all regions - for (; ; ) { - int processedRegions = 0; - Iterator> iterator = loadedItems.entrySet().iterator(); - while (iterator.hasNext()) { - String regionId = iterator.next().getKey(); - String parentRegionId = osmandRegions.getParentFullName(regionId); - if (parentRegionId == null) { - continue; - } - - // Try to find parent of this region - WorldRegion parentRegion = regionsLookupTable.get(parentRegionId); - if (parentRegion == null) { - continue; - } - - WorldRegion newRegion = new WorldRegion().init(regionId, osmandRegions, null); - parentRegion.addSubregion(newRegion, this); - regionsLookupTable.put(newRegion.getRegionId(), newRegion); - - // Remove - processedRegions++; - iterator.remove(); - } - - // If all remaining are orphans, that's all - if (processedRegions == 0) - break; - } - - Comparator nameComparator = new Comparator() { - @Override - public int compare(WorldRegion w1, WorldRegion w2) { - return w1.getName().compareTo(w2.getName()); - } - }; - sortSubregions(this, nameComparator); - - if (loadedItems.size() > 0) { - LOG.warn("Found orphaned regions: " + loadedItems.size()); - for (String regionId : loadedItems.keySet()) { - LOG.warn("FullName = " + regionId + " parent=" + osmandRegions.getParentFullName(regionId)); - } - } - } - - private void sortSubregions(WorldRegion region, Comparator comparator) { - Collections.sort(region.subregions, comparator); - for (WorldRegion r : region.subregions) { - if (r.subregions.size() > 0) { - sortSubregions(r, comparator); - } - } - } - - private static WorldRegion createRegionAs(String regionId, Map loadedItems, - OsmandRegions osmandRegions, String localizedName) { - WorldRegion worldRegion = new WorldRegion().init(regionId, osmandRegions, localizedName); - loadedItems.remove(regionId); - return worldRegion; - } - - - private String capitalize(String s) { - String[] words = s.split(" "); - if (words[0].length() > 0) { - StringBuilder sb = new StringBuilder(); - sb.append(Algorithms.capitalizeFirstLetterAndLowercase(words[0])); - for (int i = 1; i < words.length; i++) { - sb.append(" "); - sb.append(Algorithms.capitalizeFirstLetterAndLowercase(words[i])); - } - return sb.toString(); - } else { - return s; - } - } - - public WorldRegion getRegionById(String regionId) { - if (regionId.length() == 0) { - return this; - } else { - for (WorldRegion region : flattenedSubregions) { - if (region != null && region.getRegionId().equals(regionId)) { - return region; - } - } - } - return null; - } - - - - -} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index f33077069d..fc44ca24e5 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -1,5 +1,39 @@ package net.osmand.plus.download; +import java.io.File; +import java.lang.ref.WeakReference; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Set; + +import net.osmand.IProgress; +import net.osmand.PlatformUtil; +import net.osmand.access.AccessibleToast; +import net.osmand.map.WorldRegion; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.DrivingRegion; +import net.osmand.plus.OsmandSettings.MetricsConstants; +import net.osmand.plus.R; +import net.osmand.plus.Version; +import net.osmand.plus.activities.ActionBarProgressActivity; +import net.osmand.plus.activities.LocalIndexInfo; +import net.osmand.plus.activities.TabActivity; +import net.osmand.plus.base.BasicProgressAsyncTask; +import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; +import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType; +import net.osmand.plus.download.ui.ActiveDownloadsDialogFragment; +import net.osmand.plus.download.ui.DataStoragePlaceDialogFragment; +import net.osmand.plus.download.ui.DownloadResourceGroupFragment; +import net.osmand.plus.download.ui.LocalIndexesFragment; +import net.osmand.plus.download.ui.UpdatesIndexFragment; +import net.osmand.plus.views.controls.PagerSlidingTabStrip; + +import org.apache.commons.logging.Log; + import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.Uri; @@ -17,40 +51,6 @@ import android.view.View; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; -import net.osmand.IProgress; -import net.osmand.PlatformUtil; -import net.osmand.access.AccessibleToast; -import net.osmand.map.OsmandRegions.RegionData; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.DrivingRegion; -import net.osmand.plus.OsmandSettings.MetricsConstants; -import net.osmand.plus.R; -import net.osmand.plus.Version; -import net.osmand.plus.WorldRegion; -import net.osmand.plus.activities.ActionBarProgressActivity; -import net.osmand.plus.activities.LocalIndexInfo; -import net.osmand.plus.activities.TabActivity; -import net.osmand.plus.base.BasicProgressAsyncTask; -import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; -import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType; -import net.osmand.plus.download.ui.ActiveDownloadsDialogFragment; -import net.osmand.plus.download.ui.DataStoragePlaceDialogFragment; -import net.osmand.plus.download.ui.DownloadResourceGroupFragment; -import net.osmand.plus.download.ui.LocalIndexesFragment; -import net.osmand.plus.download.ui.UpdatesIndexFragment; -import net.osmand.plus.views.controls.PagerSlidingTabStrip; - -import org.apache.commons.logging.Log; - -import java.io.File; -import java.lang.ref.WeakReference; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Set; public class DownloadActivity extends ActionBarProgressActivity implements DownloadEvents { private static final Log LOG = PlatformUtil.getLog(DownloadActivity.class); @@ -212,7 +212,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl @UiThread public void downloadHasFinished() { visibleBanner.updateBannerInProgress(); - if(downloadItem != null && !WorldRegion.WORLD.equals(downloadItem.getDownloadsId())) { + if(downloadItem != null && !WorldRegion.WORLD_BASEMAP.equals(downloadItem.getRegionDownloadNameLC())) { boolean firstMap = getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.get(); if(firstMap) { initSettingsFirstMap(downloadItem); @@ -501,10 +501,9 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl // TODO test set correctly (4 tests): when you download first Australia, Japan, Luxembourgh, US getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false); DrivingRegion drg = null; - RegionData rd = reg.getRegionData(); - boolean americanSigns = "american".equals(rd.getRegionRoadSigns()); - boolean leftHand = "yes".equals(rd.getRegionLeftHandDriving()); - MetricsConstants mc = "miles".equals(rd.getRegionMetric()) ? + boolean americanSigns = "american".equals(reg.getRegionRoadSigns()); + boolean leftHand = "yes".equals(reg.getRegionLeftHandDriving()); + MetricsConstants mc = "miles".equals(reg.getRegionMetric()) ? MetricsConstants.MILES_AND_FOOTS : MetricsConstants.KILOMETERS_AND_METERS; for (DrivingRegion r : DrivingRegion.values()) { if(r.americanSigns == americanSigns && r.leftHandDriving == leftHand && @@ -516,7 +515,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl if (drg != null) { getMyApplication().getSettings().DRIVING_REGION.set(drg); } - String lng = rd.getRegionLang(); + String lng = reg.getRegionLang(); if (lng != null) { String setTts = null; for (String s : OsmandSettings.TTS_AVAILABLE_VOICES) { @@ -552,7 +551,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl List list = worldMaps.getIndividualResources(); if(list != null) { for(IndexItem ii : list) { - if(ii.getBasename().equalsIgnoreCase("world_basemap")) { + if(ii.getBasename().equalsIgnoreCase(WorldRegion.WORLD_BASEMAP)) { worldMap = ii; break; } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java index 91f359b6d5..b07e5f13f9 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java @@ -1,8 +1,5 @@ package net.osmand.plus.download; -import android.annotation.SuppressLint; -import android.content.Context; - import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -11,9 +8,11 @@ import java.util.List; import net.osmand.OsmAndCollator; import net.osmand.map.OsmandRegions; +import net.osmand.map.WorldRegion; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.WorldRegion; +import android.annotation.SuppressLint; +import android.content.Context; @SuppressLint("DefaultLocale") public class DownloadResourceGroup { @@ -316,7 +315,7 @@ public class DownloadResourceGroup { public String getName(Context ctx) { if (region != null) { - return region.getName(); + return region.getLocaleName(); } else if (type != null && type.resId != -1) { return ctx.getString(type.resId); } else { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 97c8fde1bc..07a61b165b 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -12,8 +12,9 @@ import java.util.List; import java.util.Map; import net.osmand.IndexConstants; +import net.osmand.map.OsmandRegions; +import net.osmand.map.WorldRegion; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.WorldRegion; import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem; public class DownloadResources extends DownloadResourceGroup { @@ -30,7 +31,7 @@ public class DownloadResources extends DownloadResourceGroup { public DownloadResources(OsmandApplication app) { super(null, DownloadResourceGroupType.WORLD, ""); - this.region = app.getWorldRegion(); + this.region = app.getRegions().getWorldRegion(); this.app = app; } @@ -209,12 +210,7 @@ public class DownloadResources extends DownloadResourceGroup { DownloadResourceGroup worldMaps = new DownloadResourceGroup(this, DownloadResourceGroupType.WORLD_MAPS); Map > groupByRegion = new LinkedHashMap>(); - - Map downloadIdForRegion = new LinkedHashMap(); - for(WorldRegion wg : region.getFlattenedSubregions()) { - downloadIdForRegion.put(wg.getDownloadsId(), wg); - } - + OsmandRegions regs = app.getRegions(); for (IndexItem ii : resources) { if (ii.getType() == DownloadActivityType.VOICE_FILE) { if (ii.getFileName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) { @@ -225,7 +221,7 @@ public class DownloadResources extends DownloadResourceGroup { continue; } String basename = ii.getBasename().toLowerCase(); - WorldRegion wg = downloadIdForRegion.get(basename); + WorldRegion wg = regs.getRegionDataByDownloadName(basename); if (wg != null) { if (!groupByRegion.containsKey(wg)) { groupByRegion.put(wg, new ArrayList()); diff --git a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java index 426aa95167..761a80b705 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/SearchDialogFragment.java @@ -1,5 +1,26 @@ package net.osmand.plus.download.ui; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; + +import net.osmand.Collator; +import net.osmand.OsmAndCollator; +import net.osmand.map.OsmandRegions; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.download.DownloadActivity.BannerAndDownloadFreeVersion; +import net.osmand.plus.download.DownloadActivityType; +import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; +import net.osmand.plus.download.DownloadResourceGroup; +import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType; +import net.osmand.plus.download.DownloadResources; +import net.osmand.plus.download.IndexItem; +import net.osmand.util.Algorithms; import android.content.res.TypedArray; import android.os.Bundle; import android.support.v4.app.DialogFragment; @@ -19,28 +40,6 @@ import android.widget.RelativeLayout; import android.widget.RelativeLayout.LayoutParams; import android.widget.SearchView; -import net.osmand.Collator; -import net.osmand.OsmAndCollator; -import net.osmand.map.OsmandRegions; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; -import net.osmand.plus.download.DownloadActivity; -import net.osmand.plus.download.DownloadActivity.BannerAndDownloadFreeVersion; -import net.osmand.plus.download.DownloadActivityType; -import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; -import net.osmand.plus.download.DownloadResourceGroup; -import net.osmand.plus.download.DownloadResourceGroup.DownloadResourceGroupType; -import net.osmand.plus.download.DownloadResources; -import net.osmand.plus.download.IndexItem; -import net.osmand.util.Algorithms; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; - public class SearchDialogFragment extends DialogFragment implements DownloadEvents, OnItemClickListener { public static final String TAG = "SearchDialogFragment"; @@ -330,8 +329,8 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven private void processGroup(DownloadResourceGroup group, List filter, List> conds) { String name = null; - if (group.getRegion() != null && group.getRegion().getRegionData().getRegionSearchText() != null) { - name = group.getRegion().getRegionData().getRegionSearchText().toLowerCase(); + if (group.getRegion() != null && group.getRegion().getRegionSearchText() != null) { + name = group.getRegion().getRegionSearchText().toLowerCase(); } if (name == null) { name = group.getName(ctx).toLowerCase(); diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index 37595f0388..5a18878844 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -12,7 +12,7 @@ import net.osmand.binary.BinaryMapDataObject; import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; import net.osmand.map.OsmandRegions; -import net.osmand.map.OsmandRegions.RegionData; +import net.osmand.map.WorldRegion; import net.osmand.plus.R; import net.osmand.plus.resources.ResourceManager; import net.osmand.util.Algorithms; @@ -249,8 +249,8 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { continue; } String fullName = osmandRegions.getFullName(o); - RegionData rd = osmandRegions.getRegionData(fullName); - if (rd != null && rd.isRegionMapDownload()) { + WorldRegion rd = osmandRegions.getRegionData(fullName); + if (rd != null && rd.isRegionMapDownload() && rd.getRegionDownloadName() != null) { String name = rd.getLocaleName(); if (checkIfObjectDownloaded(rd.getRegionDownloadName())) { return null; From 9d7236139b5022266398fbbdb274f67070c4432b Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 25 Oct 2015 22:18:45 +0100 Subject: [PATCH 5/6] Fix issues --- .../src/net/osmand/map/OsmandRegions.java | 35 ++++++++++++------- .../src/net/osmand/map/WorldRegion.java | 1 + .../src/net/osmand/plus/AppInitializer.java | 2 ++ .../plus/download/DownloadActivityType.java | 16 ++++----- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index 8f578f1107..464cd9fff5 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -52,7 +52,7 @@ public class OsmandRegions { private String locale = "en"; private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandRegions.class); - WorldRegion worldRegion = new WorldRegion(WorldRegion.WORLD, WorldRegion.WORLD); + WorldRegion worldRegion = new WorldRegion(WorldRegion.WORLD); Map fullNamesToRegionData = new HashMap(); Map downloadNamesToFullNames = new HashMap(); Map> countriesByDownloadName = new HashMap>(); @@ -133,12 +133,6 @@ public class OsmandRegions { if(parent != null && rd != null) { parent.addSubregion(rd); } - if(rd != null) { - rd.superregion = parent; - } - if(parent != null) { - parent.subregions.add(rd); - } } structureWorldRegions(new ArrayList(fullNamesToRegionData.values())); } @@ -162,8 +156,20 @@ public class OsmandRegions { if(rd == null) { return fullName.replace('_', ' '); } - if (includingParent && rd.superregion != null) { - return rd.superregion.getLocaleName() + " " + rd.getLocaleName(); + if (includingParent && rd.getSuperregion() != null && rd.getSuperregion().getSuperregion() != null) { + WorldRegion parentParent = rd.getSuperregion().getSuperregion(); + WorldRegion parent = rd.getSuperregion(); + if(parentParent.getRegionId().equals(WorldRegion.WORLD) && + !parent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) { + return rd.getLocaleName(); + } + if(parentParent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) { + return parentParent.getRegionId() + " " + rd.getLocaleName(); + } + if(parentParent.getRegionId().equals(WorldRegion.JAPAN_REGION_ID)) { + return parentParent.getRegionId() + " " + rd.getLocaleName(); + } + return parent.getLocaleName() + " " + rd.getLocaleName(); } else { return rd.getLocaleName(); } @@ -589,20 +595,25 @@ public class OsmandRegions { initWorldRegion(world, WorldRegion.NORTH_AMERICA_REGION_ID); initWorldRegion(world, WorldRegion.RUSSIA_REGION_ID); initWorldRegion(world, WorldRegion.SOUTH_AMERICA_REGION_ID); + initWorldRegion(world, WorldRegion.AUSTRALIA_AND_OCEANIA_REGION_ID); Iterator it = loadedItems.iterator(); while(it.hasNext()) { WorldRegion region = it.next(); if(region.superregion == null) { boolean found = false; for(WorldRegion worldSubregion : world.subregions) { - if(worldSubregion.getRegionId().equalsIgnoreCase(region.regionParentFullName)) { - worldSubregion.subregions.add(region); + if(worldSubregion.getRegionId().equalsIgnoreCase(region.regionFullName)) { + for(WorldRegion rg : region.subregions) { + worldSubregion.addSubregion(rg); + } found = true; break; - } + } } if(found) { it.remove(); + } else if(region.getRegionId().contains("basemap")) { + it.remove(); } } else { it.remove(); diff --git a/OsmAnd-java/src/net/osmand/map/WorldRegion.java b/OsmAnd-java/src/net/osmand/map/WorldRegion.java index fc0fe2ba96..980aa081c0 100644 --- a/OsmAnd-java/src/net/osmand/map/WorldRegion.java +++ b/OsmAnd-java/src/net/osmand/map/WorldRegion.java @@ -16,6 +16,7 @@ public class WorldRegion { public static final String EUROPE_REGION_ID = "europe"; public static final String NORTH_AMERICA_REGION_ID = "northamerica"; public static final String RUSSIA_REGION_ID = "russia"; + public static final String JAPAN_REGION_ID = "japan_asia"; public static final String SOUTH_AMERICA_REGION_ID = "southamerica"; protected static final String WORLD = "world"; diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index c8ffbb8626..14f008d95c 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -331,6 +331,8 @@ public class AppInitializer implements IProgress { public String getTranslation(String id) { if(WorldRegion.AFRICA_REGION_ID.equals(id)){ return app.getString(R.string.index_name_africa); + } else if(WorldRegion.AUSTRALIA_AND_OCEANIA_REGION_ID.equals(id)){ + return app.getString(R.string.index_name_oceania); } else if(WorldRegion.ASIA_REGION_ID.equals(id)){ return app.getString(R.string.index_name_asia); } else if(WorldRegion.CENTRAL_AMERICA_REGION_ID.equals(id)){ diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index b0f09d08e7..49733b4ed7 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -266,26 +266,26 @@ public class DownloadActivityType { } return getBasename(indexItem); } - final String bn = getBasename(indexItem); - if (bn.endsWith(FileNameTranslationHelper.WIKI_NAME)){ - return FileNameTranslationHelper.getWikiName(ctx,bn); + final String basename = getBasename(indexItem); + if (basename.endsWith(FileNameTranslationHelper.WIKI_NAME)){ + return FileNameTranslationHelper.getWikiName(ctx,basename); } // if (this == HILLSHADE_FILE){ // return FileNameTranslationHelper.getHillShadeName(ctx, osmandRegions, bn); // } - final String lc = bn.toLowerCase(); + final String lc = basename.toLowerCase(); String std = FileNameTranslationHelper.getStandardMapName(ctx, lc); if (std != null) { return std; } - if (bn.contains("addresses-nationwide")) { - final int ind = bn.indexOf("addresses-nationwide"); - String downloadName = bn.substring(0, ind - 1) + bn.substring(ind + "addresses-nationwide".length()); + if (basename.contains("addresses-nationwide")) { + final int ind = basename.indexOf("addresses-nationwide"); + String downloadName = basename.substring(0, ind - 1) + basename.substring(ind + "addresses-nationwide".length()); return osmandRegions.getLocaleName(downloadName, includingParent) + " "+ ctx.getString(R.string.index_item_nation_addresses); } - return osmandRegions.getLocaleName(bn, includingParent); + return osmandRegions.getLocaleName(basename, includingParent); } public String getTargetFileName(IndexItem item) { From e45f45afcda7fb302b1347b39fc42a5dea7c0090 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 25 Oct 2015 22:21:14 +0100 Subject: [PATCH 6/6] update regions --- OsmAnd-java/src/net/osmand/map/OsmandRegions.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java index 464cd9fff5..9619dc81a0 100644 --- a/OsmAnd-java/src/net/osmand/map/OsmandRegions.java +++ b/OsmAnd-java/src/net/osmand/map/OsmandRegions.java @@ -36,7 +36,7 @@ import net.osmand.util.MapUtils; public class OsmandRegions { - private static final String MAP_TYPE = "region_map"; + public static final String MAP_TYPE = "region_map"; public static final String FIELD_LEFT_HAND_DRIVING = "left_hand_driving"; public static final String FIELD_DOWNLOAD_NAME = "download_name"; @@ -419,7 +419,7 @@ public class OsmandRegions { - private boolean isDownloadOfType(BinaryMapDataObject object, String type) { + public boolean isDownloadOfType(BinaryMapDataObject object, String type) { int[] addtypes = object.getAdditionalTypes(); for(int i = 0; i < addtypes.length; i++) { TagValuePair tp = object.getMapIndex().decodeType(addtypes[i]);