From b96abd5416709c0d50b840e30d44ec4925bfb2e6 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 5 Oct 2015 18:43:34 +0300 Subject: [PATCH 1/7] Fix issue with road only maps (sort names) --- .../src/net/osmand/binary/BinaryInspector.java | 17 ++++++++--------- .../binary/BinaryMapRouteReaderAdapter.java | 3 +++ .../src/net/osmand/binary/RouteDataObject.java | 6 ++++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index 4fad96be36..47e295b882 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -66,9 +66,9 @@ public class BinaryInspector { // test cases show info if(args.length == 1 && "test".equals(args[0])) { in.inspector(new String[]{ - "-vpoi", +// "-vpoi", // "-vmap", "-vmapobjects", // "-vmapcoordinates", -// "-vrouting", + "-vrouting", // "-vaddress", "-vcities",//"-vstreetgroups", // "-vstreets", "-vbuildings", "-vintersections", // "-zoom=15", @@ -535,16 +535,15 @@ public class BinaryInspector { b.setLength(0); b.append("Road "); b.append(obj.id); - for(int i = 0; i < obj.getTypes().length; i++) { + for (int i = 0; i < obj.getTypes().length; i++) { RouteTypeRule rr = obj.region.quickGetEncodingRule(obj.getTypes()[i]); b.append(" ").append(rr.getTag()).append("='").append(rr.getValue()).append("'"); } - if (obj.getNames() != null) { - TIntObjectIterator it = obj.getNames().iterator(); - while (it.hasNext()) { - it.advance(); - RouteTypeRule rr = obj.region.quickGetEncodingRule(it.key()); - b.append(" ").append(rr.getTag()).append("='").append(it.value()).append("'"); + int[] nameIds = obj.getNameIds(); + if (nameIds != null) { + for (int key : nameIds) { + RouteTypeRule rr = obj.region.quickGetEncodingRule(key); + b.append(" ").append(rr.getTag()).append("='").append(obj.getNames().get(key)).append("'"); } } println(b.toString()); diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java index 0adb877759..e17e884fda 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -451,11 +451,14 @@ public class BinaryMapRouteReaderAdapter { o.names = new TIntObjectHashMap(); int sizeL = codedIS.readRawVarint32(); int old = codedIS.pushLimit(sizeL); + TIntArrayList list = new TIntArrayList(); while (codedIS.getBytesUntilLimit() > 0) { int stag = codedIS.readRawVarint32(); int pId = codedIS.readRawVarint32(); o.names.put(stag, ((char)pId)+""); + list.add(stag); } + o.nameIds = list.toArray(); codedIS.popLimit(old); break; case RouteData.POINTS_FIELD_NUMBER: diff --git a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java index c5c6465b96..4542915cf9 100644 --- a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java @@ -26,6 +26,7 @@ public class RouteDataObject { public long id; public TIntObjectHashMap names; public final static float NONE_MAX_SPEED = 40f; + public int[] nameIds; public RouteDataObject(RouteRegion region) { this.region = region; @@ -33,6 +34,7 @@ public class RouteDataObject { public RouteDataObject(RouteRegion region, int[] nameIds, String[] nameValues) { this.region = region; + this.nameIds = nameIds; if (nameIds.length > 0) { names = new TIntObjectHashMap(); } @@ -86,6 +88,10 @@ public class RouteDataObject { return null; } + public int[] getNameIds() { + return nameIds; + } + public TIntObjectHashMap getNames() { return names; } From cab1fd815c5f596ed70984fac5dfbbe1509e4061 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 5 Oct 2015 19:16:34 +0300 Subject: [PATCH 2/7] Fix https://github.com/osmandapp/Osmand/issues/1770 #1770 --- OsmAnd-java/src/net/osmand/util/Algorithms.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index e6fa8347bd..adcc4e0411 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -220,6 +220,13 @@ public class Algorithms { if (colorString.charAt(0) == '#') { // Use a long to avoid rollovers on #ffXXXXXX long color = Long.parseLong(colorString.substring(1), 16); + if (colorString.length() == 4) { + colorString = "#" + + colorString.charAt(1) + colorString.charAt(1) + + colorString.charAt(2) + colorString.charAt(2) + + colorString.charAt(3) + colorString.charAt(3); + + } if (colorString.length() == 7) { // Set the alpha value color |= 0x00000000ff000000; From d8fa958c3707df49a76794435f7f7b014c00739f Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 5 Oct 2015 20:15:22 +0300 Subject: [PATCH 3/7] Downloads refactoring --- OsmAnd/src/net/osmand/plus/WorldRegion.java | 13 ++ .../plus/download/BaseDownloadActivity.java | 19 +++ .../plus/download/DownloadIndexesThread.java | 119 +++++++++++++- .../plus/download/items/ItemsListBuilder.java | 145 +++--------------- .../download/items/RegionDialogFragment.java | 39 ++--- .../download/items/RegionItemsFragment.java | 62 +++----- .../download/items/WorldItemsFragment.java | 21 ++- 7 files changed, 214 insertions(+), 204 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/WorldRegion.java b/OsmAnd/src/net/osmand/plus/WorldRegion.java index 6bea8a0bcd..fc78b63f54 100644 --- a/OsmAnd/src/net/osmand/plus/WorldRegion.java +++ b/OsmAnd/src/net/osmand/plus/WorldRegion.java @@ -282,4 +282,17 @@ public class WorldRegion implements Serializable { return s; } } + + public WorldRegion getRegionById(String regionId) { + if (regionId == null) { + return this; + } else { + for (WorldRegion region : flattenedSubregions) { + if (region.getRegionId().equals(regionId)) { + return region; + } + } + } + return null; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java index d7418160df..16c30103ec 100644 --- a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java @@ -19,6 +19,7 @@ import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.ActionBarProgressActivity; import net.osmand.plus.base.BasicProgressAsyncTask; +import net.osmand.plus.download.items.ItemsListBuilder; import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat; import java.lang.ref.WeakReference; @@ -122,6 +123,24 @@ public class BaseDownloadActivity extends ActionBarProgressActivity { } + public ItemsListBuilder getItemsBuilder() { + if (downloadListIndexThread.isDataPrepared()) { + return new ItemsListBuilder(getMyApplication(), null, downloadListIndexThread.getResourcesByRegions(), + downloadListIndexThread.getVoiceRecItems(), downloadListIndexThread.getVoiceTTSItems()); + } else { + return null; + } + } + + public ItemsListBuilder getItemsBuilder(String regionId) { + if (downloadListIndexThread.isDataPrepared()) { + return new ItemsListBuilder(getMyApplication(), regionId, downloadListIndexThread.getResourcesByRegions(), + downloadListIndexThread.getVoiceRecItems(), downloadListIndexThread.getVoiceTTSItems()); + } else { + return null; + } + } + public boolean startDownload(IndexItem item) { if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) { downloadQueue.add(item); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 8233685c83..80de30d777 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -15,13 +15,17 @@ import android.os.StatFs; import android.view.View; import android.widget.Toast; +import net.osmand.Collator; import net.osmand.IndexConstants; +import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.access.AccessibleToast; +import net.osmand.map.OsmandRegions; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.Version; +import net.osmand.plus.WorldRegion; import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning; import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem; @@ -39,13 +43,17 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; @SuppressLint("NewApi") @@ -64,6 +72,12 @@ public class DownloadIndexesThread { private java.text.DateFormat dateFormat; private List itemsToUpdate = new ArrayList(); + private Map> resourcesByRegions = new HashMap<>(); + private List voiceRecItems = new LinkedList<>(); + private List voiceTTSItems = new LinkedList<>(); + + private boolean dataPrepared; + DatabaseHelper dbHelper; public DownloadIndexesThread(Context ctx) { @@ -141,6 +155,107 @@ public class DownloadIndexesThread { return itemsToUpdate; } + public boolean isDataPrepared() { + return dataPrepared; + } + + public Map> getResourcesByRegions() { + return resourcesByRegions; + } + + public List getVoiceRecItems() { + return voiceRecItems; + } + + public List getVoiceTTSItems() { + return voiceTTSItems; + } + + private boolean prepareData(List resources) { + List resourcesInRepository; + if (resources != null) { + resourcesInRepository = resources; + } else { + resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles(); + } + if (resourcesInRepository == null) { + return false; + } + + resourcesByRegions.clear(); + voiceRecItems.clear(); + voiceTTSItems.clear(); + + List mergedRegions = app.getWorldRegion().getFlattenedSubregions(); + mergedRegions.add(app.getWorldRegion()); + boolean voiceFilesProcessed = false; + for (WorldRegion region : mergedRegions) { + String downloadsIdPrefix = region.getDownloadsIdPrefix(); + + Map regionResources = new HashMap<>(); + + Set typesSet = new TreeSet<>(new Comparator() { + @Override + public int compare(DownloadActivityType dat1, DownloadActivityType dat2) { + return dat1.getTag().compareTo(dat2.getTag()); + } + }); + + for (IndexItem resource : resourcesInRepository) { + + if (!voiceFilesProcessed) { + if (resource.getSimplifiedFileName().endsWith(".voice.zip")) { + voiceRecItems.add(resource); + continue; + } else if (resource.getSimplifiedFileName().contains(".ttsvoice.zip")) { + voiceTTSItems.add(resource); + continue; + } + } + + if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) { + continue; + } + + typesSet.add(resource.getType()); + regionResources.put(resource.getSimplifiedFileName(), resource); + } + + voiceFilesProcessed = true; + + if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) { + if (region.getSuperregion().getResourceTypes() == null) { + region.getSuperregion().setResourceTypes(typesSet); + } else { + region.getSuperregion().getResourceTypes().addAll(typesSet); + } + } + + region.setResourceTypes(typesSet); + resourcesByRegions.put(region, regionResources); + } + + final Collator collator = OsmAndCollator.primaryCollator(); + final OsmandRegions osmandRegions = app.getRegions(); + + Collections.sort(voiceRecItems, new Comparator() { + @Override + public int compare(IndexItem lhs, IndexItem rhs) { + return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions), + rhs.getVisibleName(app.getApplicationContext(), osmandRegions)); + } + }); + + Collections.sort(voiceTTSItems, new Comparator() { + @Override + public int compare(IndexItem lhs, IndexItem rhs) { + return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions), + rhs.getVisibleName(app.getApplicationContext(), osmandRegions)); + } + }); + + return true; + } public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask implements DownloadFileShowWarning { @@ -408,13 +523,14 @@ public class DownloadIndexesThread { currentRunningTask.add(this); super.onPreExecute(); this.message = ctx.getString(R.string.downloading_list_indexes); + dataPrepared = false; } @Override protected IndexFileList doInBackground(Void... params) { IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx); if (indexFileList != null) { - ItemsListBuilder.prepareData(app, indexFileList.getIndexFiles()); + prepareData(indexFileList.getIndexFiles()); } return indexFileList; } @@ -422,6 +538,7 @@ public class DownloadIndexesThread { protected void onPostExecute(IndexFileList result) { indexFiles = result; if (indexFiles != null && uiActivity != null) { + dataPrepared = resourcesByRegions.size() > 0; prepareFilesToUpdate(); boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap(); IndexItem basemap = indexFiles.getBasemap(); diff --git a/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java b/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java index 8ec8a5650c..b99478d549 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java +++ b/OsmAnd/src/net/osmand/plus/download/items/ItemsListBuilder.java @@ -2,15 +2,12 @@ package net.osmand.plus.download.items; import android.content.Context; -import net.osmand.Collator; -import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.map.OsmandRegions; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.WorldRegion; -import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.IndexItem; import net.osmand.plus.srtmplugin.SRTMPlugin; @@ -18,20 +15,19 @@ import net.osmand.util.Algorithms; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; public class ItemsListBuilder { public static final String WORLD_BASEMAP_KEY = "world_basemap.obf.zip"; public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap.obf.zip"; + private Map> resourcesByRegions; + private List voiceRecItems; + private List voiceTTSItems; + public class ResourceItem { private String resourceId; @@ -101,15 +97,6 @@ public class ItemsListBuilder { private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(ItemsListBuilder.class); - private static Map> resourcesByRegions = - new HashMap<>(); - private static List searchableWorldwideRegionItems = new LinkedList<>(); - - private static List voiceRecItems = new LinkedList<>(); - private static List voiceTTSItems = new LinkedList<>(); - - private static final Lock lock = new ReentrantLock(); - private List regionMapItems; private List allResourceItems; private List allSubregionItems; @@ -138,18 +125,18 @@ public class ItemsListBuilder { return list; } - public static String getVoicePromtName(Context context, VoicePromptsType type) { + public String getVoicePromtName(VoicePromptsType type) { switch (type) { case RECORDED: - return context.getResources().getString(R.string.index_name_voice); + return app.getResources().getString(R.string.index_name_voice); case TTS: - return context.getResources().getString(R.string.index_name_tts_voice); + return app.getResources().getString(R.string.index_name_tts_voice); default: return null; } } - public static List getVoicePromptsItems(VoicePromptsType type) { + public List getVoicePromptsItems(VoicePromptsType type) { switch (type) { case RECORDED: return voiceRecItems; @@ -160,7 +147,7 @@ public class ItemsListBuilder { } } - public static boolean isVoicePromptsItemsEmpty(VoicePromptsType type) { + public boolean isVoicePromptsItemsEmpty(VoicePromptsType type) { switch (type) { case RECORDED: return voiceRecItems.isEmpty(); @@ -171,28 +158,22 @@ public class ItemsListBuilder { } } - public ItemsListBuilder(OsmandApplication app) { + public ItemsListBuilder(OsmandApplication app, String regionId, Map> resourcesByRegions, + List voiceRecItems, List voiceTTSItems) { this.app = app; - regionMapItems = new LinkedList<>(); - allResourceItems = new LinkedList(); - allSubregionItems = new LinkedList<>(); - } + this.resourcesByRegions = resourcesByRegions; + this.voiceRecItems = voiceRecItems; + this.voiceTTSItems = voiceTTSItems; - public ItemsListBuilder(OsmandApplication app, WorldRegion region) { - this(app); - this.region = region; + regionMapItems = new LinkedList<>(); + allResourceItems = new LinkedList<>(); + allSubregionItems = new LinkedList<>(); + + region = app.getWorldRegion().getRegionById(regionId); } public boolean build() { - if (lock.tryLock()) { - try { - return obtainDataAndItems(); - } finally { - lock.unlock(); - } - } else { - return false; - } + return obtainDataAndItems(); } private boolean obtainDataAndItems() { @@ -206,92 +187,6 @@ public class ItemsListBuilder { return true; } - public static boolean prepareData(final OsmandApplication app, List resources) { - lock.lock(); - try { - List resourcesInRepository; - if (resources != null) { - resourcesInRepository = resources; - } else { - resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles(); - } - if (resourcesInRepository == null) { - return false; - } - - resourcesByRegions.clear(); - searchableWorldwideRegionItems.clear(); - voiceRecItems.clear(); - voiceTTSItems.clear(); - - List mergedRegions = app.getWorldRegion().getFlattenedSubregions(); - mergedRegions.add(app.getWorldRegion()); - boolean voiceFilesProcessed = false; - for (WorldRegion region : mergedRegions) { - searchableWorldwideRegionItems.add(region); - - String downloadsIdPrefix = region.getDownloadsIdPrefix(); - - Map regionResources = new HashMap<>(); - - Set typesSet = new TreeSet<>(new Comparator() { - @Override - public int compare(DownloadActivityType dat1, DownloadActivityType dat2) { - return dat1.getTag().compareTo(dat2.getTag()); - } - }); - - for (IndexItem resource : resourcesInRepository) { - - if (!voiceFilesProcessed) { - if (resource.getSimplifiedFileName().endsWith(".voice.zip")) { - voiceRecItems.add(resource); - continue; - } else if (resource.getSimplifiedFileName().contains(".ttsvoice.zip")) { - voiceTTSItems.add(resource); - continue; - } - } - - if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) { - continue; - } - - typesSet.add(resource.getType()); - regionResources.put(resource.getSimplifiedFileName(), resource); - } - - voiceFilesProcessed = true; - - if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) { - if (region.getSuperregion().getResourceTypes() == null) { - region.getSuperregion().setResourceTypes(typesSet); - } else { - region.getSuperregion().getResourceTypes().addAll(typesSet); - } - } - - region.setResourceTypes(typesSet); - resourcesByRegions.put(region, regionResources); - } - - final Collator collator = OsmAndCollator.primaryCollator(); - final OsmandRegions osmandRegions = app.getRegions(); - Collections.sort(voiceRecItems, new Comparator() { - @Override - public int compare(IndexItem lhs, IndexItem rhs) { - return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions), - rhs.getVisibleName(app.getApplicationContext(), osmandRegions)); - } - }); - - return true; - - } finally { - lock.unlock(); - } - } - private void collectSubregionsDataAndItems() { srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null; hasSrtm = false; diff --git a/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java index 99808eaba8..60d9e43c5b 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/RegionDialogFragment.java @@ -21,8 +21,8 @@ import org.apache.commons.logging.Log; public class RegionDialogFragment extends DialogFragment { private static final Log LOG = PlatformUtil.getLog(RegionDialogFragment.class); public static final String TAG = "RegionDialogFragment"; - private static final String REGION_DLG_KEY = "world_region_dialog_key"; - private WorldRegion region; + private static final String REGION_ID_DLG_KEY = "world_region_dialog_key"; + private String regionId; private DownloadsUiHelper.MapDownloadListener mProgressListener; @Override @@ -39,22 +39,13 @@ public class RegionDialogFragment extends DialogFragment { Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false); - WorldRegion region = null; if (savedInstanceState != null) { - Object regionObj = savedInstanceState.getSerializable(REGION_DLG_KEY); - if (regionObj != null) { - region = (WorldRegion)regionObj; - } + regionId = savedInstanceState.getString(REGION_ID_DLG_KEY); } - if (region == null) { - Object regionObj = getArguments().getSerializable(REGION_DLG_KEY); - if (regionObj != null) { - region = (WorldRegion)regionObj; - } + if (regionId == null) { + regionId = getArguments().getString(REGION_ID_DLG_KEY); } - this.region = region; - Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha)); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @@ -64,13 +55,16 @@ public class RegionDialogFragment extends DialogFragment { } }); - if (this.region != null) { + if (regionId != null) { Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer); if (fragment == null) { getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer, - RegionItemsFragment.createInstance(region)).commit(); + RegionItemsFragment.createInstance(regionId)).commit(); + } + WorldRegion region = getMyApplication().getWorldRegion().getRegionById(regionId); + if (region != null) { + toolbar.setTitle(region.getName()); } - toolbar.setTitle(this.region.getName()); } DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication(), getResources()); @@ -95,7 +89,6 @@ public class RegionDialogFragment extends DialogFragment { @Override public void onResume() { super.onResume(); - LOG.debug(region.getName() + " onResume()"); getMyActivity().setOnProgressUpdateListener(mProgressListener); } @@ -107,7 +100,7 @@ public class RegionDialogFragment extends DialogFragment { @Override public void onSaveInstanceState(Bundle outState) { - outState.putSerializable(REGION_DLG_KEY, region); + outState.putString(REGION_ID_DLG_KEY, regionId); super.onSaveInstanceState(outState); } @@ -119,13 +112,13 @@ public class RegionDialogFragment extends DialogFragment { return (DownloadActivity) getActivity(); } - public void onRegionSelected(WorldRegion region) { - DownloadsUiHelper.showDialog(getActivity(), createInstance(region)); + public void onRegionSelected(String regionId) { + DownloadsUiHelper.showDialog(getActivity(), createInstance(regionId)); } - public static RegionDialogFragment createInstance(WorldRegion region) { + public static RegionDialogFragment createInstance(String regionId) { Bundle bundle = new Bundle(); - bundle.putSerializable(REGION_DLG_KEY, region); + bundle.putString(REGION_ID_DLG_KEY, regionId); RegionDialogFragment fragment = new RegionDialogFragment(); fragment.setArguments(bundle); return fragment; diff --git a/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java index e71cbbaa8f..b6ac20a9c0 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java @@ -7,7 +7,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ExpandableListView; -import android.widget.LinearLayout; import android.widget.TextView; import net.osmand.PlatformUtil; @@ -21,7 +20,6 @@ import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin; -import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -38,13 +36,12 @@ public class RegionItemsFragment extends OsmandExpandableListFragment { private static final Log LOG = PlatformUtil.getLog(RegionItemsFragment.class); private static final MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US); - private ItemsListBuilder builder; private RegionsItemsAdapter listAdapter; private int regionMapsGroupPos = -1; private int additionalMapsGroupPos = -1; - private static final String REGION_KEY = "world_region_key"; - private WorldRegion region; + private static final String REGION_ID_KEY = "world_region_id_key"; + private String regionId; @Override public void onCreate(Bundle savedInstanceState) { @@ -56,33 +53,25 @@ public class RegionItemsFragment extends OsmandExpandableListFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.download_items_fragment, container, false); - WorldRegion region = null; if (savedInstanceState != null) { - Object regionObj = savedInstanceState.getSerializable(REGION_KEY); - if (regionObj != null) { - region = (WorldRegion) regionObj; - } + regionId = savedInstanceState.getString(REGION_ID_KEY); } - if (region == null) { - Object regionObj = getArguments().getSerializable(REGION_KEY); - if (regionObj != null) { - region = (WorldRegion) regionObj; - } + if (regionId == null) { + regionId = getArguments().getString(REGION_ID_KEY); } - this.region = region; - - builder = new ItemsListBuilder(getMyApplication(), this.region); - ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list); listAdapter = new RegionsItemsAdapter(getActivity()); listView.setAdapter(listAdapter); setListView(listView); - if (builder.build()) { - fillRegionItemsAdapter(); - listAdapter.notifyDataSetChanged(); - expandAllGroups(); + if (regionId != null) { + ItemsListBuilder builder = getDownloadActivity().getItemsBuilder(regionId); + if (builder != null && builder.build()) { + fillRegionItemsAdapter(builder); + listAdapter.notifyDataSetChanged(); + expandAllGroups(); + } } return view; @@ -90,7 +79,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment { @Override public void onSaveInstanceState(Bundle outState) { - outState.putSerializable(REGION_KEY, region); + outState.putString(REGION_ID_KEY, regionId); super.onSaveInstanceState(outState); } @@ -100,7 +89,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment { if (obj instanceof WorldRegion) { WorldRegion region = (WorldRegion) obj; ((RegionDialogFragment) getParentFragment()) - .onRegionSelected(region); + .onRegionSelected(region.getRegionId()); return true; } else { return false; @@ -117,17 +106,12 @@ public class RegionItemsFragment extends OsmandExpandableListFragment { return (OsmandApplication) getActivity().getApplication(); } - private void fillRegionItemsAdapter() { + private void fillRegionItemsAdapter(ItemsListBuilder builder) { if (listAdapter != null) { listAdapter.clear(); int nextAvailableGroupPos = 0; if (builder.getRegionMapItems().size() > 0) { - String sectionTitle; - if (builder.getAllResourceItems().size() > 0) { - sectionTitle = "Region maps"; - } else { - sectionTitle = ""; - } + String sectionTitle = "Region maps"; regionMapsGroupPos = nextAvailableGroupPos++; listAdapter.add(sectionTitle, builder.getRegionMapItems()); } @@ -136,7 +120,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment { if (builder.getRegionMapItems().size() > 0) { sectionTitle = "Additional maps"; } else { - sectionTitle = ""; + sectionTitle = "Regions"; } additionalMapsGroupPos = nextAvailableGroupPos; listAdapter.add(sectionTitle, builder.getAllResourceItems()); @@ -148,9 +132,9 @@ public class RegionItemsFragment extends OsmandExpandableListFragment { return (DownloadActivity) getActivity(); } - public static RegionItemsFragment createInstance(WorldRegion region) { + public static RegionItemsFragment createInstance(String regionId) { Bundle bundle = new Bundle(); - bundle.putSerializable(REGION_KEY, region); + bundle.putString(REGION_ID_KEY, regionId); RegionItemsFragment fragment = new RegionItemsFragment(); fragment.setArguments(bundle); return fragment; @@ -254,14 +238,6 @@ public class RegionItemsFragment extends OsmandExpandableListFragment { public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { View v = convertView; String section = getGroup(groupPosition); - /* - if (section.length() == 0) { - LinearLayout emptyLL = new LinearLayout(parent.getContext()); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0); - emptyLL.setLayoutParams(params); - return emptyLL; - } - */ if (v == null) { LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); diff --git a/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java index f59b93f7be..a9f20a4fd3 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/WorldItemsFragment.java @@ -23,7 +23,6 @@ import net.osmand.plus.WorldRegion; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.download.DownloadActivity; -import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.newimplementation.DownloadsUiHelper; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin; @@ -42,7 +41,6 @@ public class WorldItemsFragment extends OsmandExpandableListFragment { public static final int RELOAD_ID = 0; - private ItemsListBuilder builder; private WorldItemsAdapter listAdapter; private int worldRegionsIndex = -1; @@ -62,8 +60,6 @@ public class WorldItemsFragment extends OsmandExpandableListFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.download_index_fragment, container, false); - builder = new ItemsListBuilder(getMyApplication(), getMyApplication().getWorldRegion()); - ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list); listAdapter = new WorldItemsAdapter(getActivity()); listView.setAdapter(listAdapter); @@ -97,7 +93,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment { return (OsmandApplication) getActivity().getApplication(); } - private void fillWorldItemsAdapter() { + private void fillWorldItemsAdapter(ItemsListBuilder builder) { if (listAdapter != null) { listAdapter.clear(); if (builder.getRegionMapItems().size() > 0) { @@ -109,12 +105,12 @@ public class WorldItemsFragment extends OsmandExpandableListFragment { int unusedSubIndex = 0; List voicePromptsItems = new LinkedList<>(); - if (!ItemsListBuilder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.RECORDED)) { - voicePromptsItems.add(ItemsListBuilder.getVoicePromtName(getMyApplication(), ItemsListBuilder.VoicePromptsType.RECORDED)); + if (!builder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.RECORDED)) { + voicePromptsItems.add(builder.getVoicePromtName(ItemsListBuilder.VoicePromptsType.RECORDED)); voicePromptsItemsRecordedSubIndex = unusedSubIndex++; } - if (!ItemsListBuilder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.TTS)) { - voicePromptsItems.add(ItemsListBuilder.getVoicePromtName(getMyApplication(), ItemsListBuilder.VoicePromptsType.TTS)); + if (!builder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.TTS)) { + voicePromptsItems.add(builder.getVoicePromtName(ItemsListBuilder.VoicePromptsType.TTS)); voicePromptsItemsTTSSubIndex = unusedSubIndex; } if (!voicePromptsItems.isEmpty()) { @@ -130,7 +126,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { if (groupPosition == worldRegionsIndex) { WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition); - DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region)); + DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId())); return true; } else if (groupPosition == voicePromptsIndex) { // @@ -160,8 +156,9 @@ public class WorldItemsFragment extends OsmandExpandableListFragment { } public void onCategorizationFinished() { - if (builder.build()) { - fillWorldItemsAdapter(); + ItemsListBuilder builder = getDownloadActivity().getItemsBuilder(); + if (builder != null && builder.build()) { + fillWorldItemsAdapter(builder); listAdapter.notifyDataSetChanged(); expandAllGroups(); } From af747fbbec0132a07378e010034ceffd73ce2e7f Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 5 Oct 2015 22:21:27 +0300 Subject: [PATCH 4/7] Fix https://github.com/osmandapp/Osmand/issues/1770 #1770 --- OsmAnd-java/src/net/osmand/util/Algorithms.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index adcc4e0411..09a3ed4f87 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -219,14 +219,14 @@ public class Algorithms { public static int parseColor(String colorString) { if (colorString.charAt(0) == '#') { // Use a long to avoid rollovers on #ffXXXXXX - long color = Long.parseLong(colorString.substring(1), 16); - if (colorString.length() == 4) { + if (colorString.length() == 4) { colorString = "#" + colorString.charAt(1) + colorString.charAt(1) + colorString.charAt(2) + colorString.charAt(2) + colorString.charAt(3) + colorString.charAt(3); } + long color = Long.parseLong(colorString.substring(1), 16); if (colorString.length() == 7) { // Set the alpha value color |= 0x00000000ff000000; From d5b483cacc7a3647b69ac10490090ebf33dfc772 Mon Sep 17 00:00:00 2001 From: Matej U Date: Mon, 5 Oct 2015 20:59:59 +0200 Subject: [PATCH 5/7] Translated using Weblate (Slovenian) Currently translated at 100.0% (1750 of 1750 strings) --- OsmAnd/res/values-sl/strings.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/values-sl/strings.xml b/OsmAnd/res/values-sl/strings.xml index a4f90d6815..b9cc4268c9 100644 --- a/OsmAnd/res/values-sl/strings.xml +++ b/OsmAnd/res/values-sl/strings.xml @@ -2012,4 +2012,8 @@ min/km m/s - + Prejemanje datotek: %1$d + Pokaži pasico brezplačne različice + Izris izohips je onemogočen + Četudi imate plačljivo različico, še vedno lahko prikažete pasico brezplačne različice. + From 2a34ac8f5e203456a10cd3a168ff92c64f3911c7 Mon Sep 17 00:00:00 2001 From: xmd5a Date: Mon, 5 Oct 2015 23:05:08 +0300 Subject: [PATCH 6/7] Update license, phrases --- LICENSE | 8 ++++- OsmAnd/res/values-ru/phrases.xml | 55 ++++++++++++++++++++++++++++++++ OsmAnd/res/values/phrases.xml | 54 +++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index bb7daaffb6..70adfe40b0 100644 --- a/LICENSE +++ b/LICENSE @@ -136,4 +136,10 @@ - Praha: «Prag Metro Logo» (wikinight2) - Eigenes Werk (own work), created with inkscape, based on PDF http://www.zdanice.cz/clanky/letak_Haje_.pdf. Licensed under Public Domain via Commons from site - https://commons.wikimedia.org/wiki/File:Prag_Metro_Logo.svg#/media/File:Prag_Metro_Logo.svg - Tehran: "Tehran Metro Logo" by Tehran Urban and Suburban Railway Organization - http://metro.tehran.ir/. Licensed under Public Domain via Wikipedia - https://en.wikipedia.org/wiki/File:Tehran_Metro_Logo.svg#/media/File:Tehran_Metro_Logo.svg - Athens: "Logo of the Athens Metro Operating Company (AMEL)" by Marianian - Own work, based on personal observations of publicity and signage.. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Logo_of_the_Athens_Metro_Operating_Company_(AMEL).svg#/media/File:Logo_of_the_Athens_Metro_Operating_Company_(AMEL).svg - - Nagoya: "Nagoya Municipal Subway Logo" by ASDFGHJ - 名古屋市交通局. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Nagoya_Municipal_Subway_Logo.svg#/media/File:Nagoya_Municipal_Subway_Logo.svg \ No newline at end of file + - Nagoya: "Nagoya Municipal Subway Logo" by ASDFGHJ - 名古屋市交通局. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Nagoya_Municipal_Subway_Logo.svg#/media/File:Nagoya_Municipal_Subway_Logo.svg + - Catania: "Logo metropolitana di Catania" by Friedrichstrasse - Own work. Licensed under CC BY-SA 3.0 via Commons - https://commons.wikimedia.org/wiki/File:Logo_metropolitana_di_Catania.svg#/media/File:Logo_metropolitana_di_Catania.svg + - Manila: "Lrtalogo" by Cda stitch - Own work. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Lrtalogo.svg#/media/File:Lrtalogo.svg + - Rio de Janeiro: "Metrorioicon" by Metrô Rio - http://www.metrorio.com.br/. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Metrorioicon.png#/media/File:Metrorioicon.png + - Montreal: "Montreal Metro" by STM - http://www.stm.info/en-bref/pictometro.htm. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Montreal_Metro.svg#/media/File:Montreal_Metro.svg + - Toronto: "TTC" by Source. Licensed under Fair use via Wikipedia - https://en.wikipedia.org/wiki/File:TTC.svg#/media/File:TTC.svg + - Bangkok: "MRT (Bangkok) logo" by Bangkok_Metro_logo.png: Paul_012.Original uploader was Paul 012 at en.wikipediaderivative work: Nevetsjc (talk)Revision traced from http://si0.twimg.com/profile_images/975897559/logo.jpg - Bangkok_Metro_logo.png. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:MRT_(Bangkok)_logo.svg#/media/File:MRT_(Bangkok)_logo.svg \ No newline at end of file diff --git a/OsmAnd/res/values-ru/phrases.xml b/OsmAnd/res/values-ru/phrases.xml index c281f99577..a010ff1881 100644 --- a/OsmAnd/res/values-ru/phrases.xml +++ b/OsmAnd/res/values-ru/phrases.xml @@ -1545,4 +1545,59 @@ Надпись + Исторический карьер + + Заполнители бетона + Сурьма + Асбест + Барит + Базальт + Бокситы + Берил + Висмут + Зерновые культуры + Хромиты, хромовая руда + Глина + Уголь + Медь + Алмазы + Строительный камень + Доломит + Природный газ + Золото + Графит + Гравий + Гипс + Железная руда + Свинец + Бурый уголь + Известняк + Мрамор + Ртуть + Слюда + Минеральное масло + Никель + Нефть/масло + Опал + Торф + Платина + Радий + Рубин + Рутил + Соль + Песок + Песчаник + Кремнезём, кварц + Серебро + Сланец;железная руда;медь + Сланец + Камень (ресурс) + Олово + Вулканический туф + Уран + Ванадий + Вода (ресурс) + Цинк + Циркон + \ No newline at end of file diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index e3caa0492e..cf934bbf7d 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -1695,5 +1695,59 @@ Obelisk Inscription + Historic quarry + + Aggregate + Antimony + Asbestos + Barite + Basalt + Bauxite + Beryl + Bismuth + Cereal + Chromite + Clay + Coal + Copper + Diamond + Dimension stone + Dolomite + Gas + Gold + Graphite + Gravel + Gypsum + Iron ore + Lead + Lignite + Limestone + Marble + Mercury + Mica + Mineral oil + Nickel + Oil + Opal + Peat + Platinum + Radium + Ruby + Rutile + Salt + Sand + Sandstone + Silica + Silver + Slate;iron ore;copper + Slate + Stone + Tin + Tuff + Uranium + Vanadium + Water + Zinc + Zircon From 8e62996964f0550d7542835402b88bd08db1eb2e Mon Sep 17 00:00:00 2001 From: Viktar Palstsiuk Date: Mon, 5 Oct 2015 21:51:55 +0200 Subject: [PATCH 7/7] Translated using Weblate (Belarusian) Currently translated at 75.1% (1192 of 1586 strings) --- OsmAnd/res/values-be/phrases.xml | 118 +++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/OsmAnd/res/values-be/phrases.xml b/OsmAnd/res/values-be/phrases.xml index ffadaf0458..06e2ee5a64 100644 --- a/OsmAnd/res/values-be/phrases.xml +++ b/OsmAnd/res/values-be/phrases.xml @@ -1233,4 +1233,122 @@ Пальмавы алей Апельсін Банан + Няма шкленьня + Абаграваньне + Без абаграваньня + Правоз ровараў дазволены + Правоз ровараў забаронены + Правоз ровараў дазволены толькі летам + Толькі ўваход + Толькі выхад + Уваход і выхад + Доступ летам: толькі ўваход + Доступ летам: толькі выхад + Доступ летам: уваход і выхад + + Колькасьць зорак: 1 (турысцкі клас) + Колькасьць зорак: 1S (палепшаны турысцкі клас) + Колькасьць зорак: 2 (стандартны кляс) + Колькасьць зорак: 2S (палепшаны стандартны кляс) + Колькасьць зорак: 3 (камфортны кляс) + Колькасьць зорак: 3S (палепшаны камфортны кляс) + Колькасьць зорак: 4 (першы кляс) + Колькасьць зорак: 4S (палепшаны першы кляс) + Колькасьць зорак: 5 (катэгорыя люкс) + Колькасьць зорак: 5S (катэгорыя люкс +) + Колькасьць зорак: 6 + Колькасьць зорак: 7 + Колькасць нумароў + + Love-гатэль + + На вынас: не + Толькі на вынас + + З дастаўкай + Без дастаўкі + Толькі з дастаўкай + + Месцы на адкрытым паветры + Няма месцаў на адкрытым паветры + Месцы на адкрытым паветры: тэраса + Месцы на адкрытым паветры: тратуар + Месцы на адкрытым паветры: пешаходная зона + Месцы на адкрытым паветры: сад + Месцы на адкрытым паветры: паціа + + Кактэйлі + + Ужываны тавар + Ужываны тавар адсутнічае + Толькі ўжываны тавар + + Запчасткі + Дылер + Рамонт + Рамонт не ажыцьцяўляецца + Рамонт электратранспарту + Рамонт матацыклаў + Самаабслугоўваньне + Самаабслугоўваньне: няма + Аўтаматызацыя + Без аўтаматызацыі + Поўны комплекс паслуг + Безкантактная + Кантактная + Без аўтамыйні + + Заправачная станцыя для паветранага транспарту + Грамадзкая лазьня + + Для мужчын + Не для мужчын + Для жанчын + Не для жанчын + Унутры памяшканьня + Знадворку + З прыбіральняй + Без прыбіральні + Доступ у прыбіральню для інвалідных вазкоў: так + Доступ у прыбіральню для інвалідных вазкоў: не + Доступ у прыбіральню: толькі для наведвальнікаў + Доступ у прыбіральню: з дазволу ўладальніка + Доступ у прыбіральню: агульны + + Максімальны час стаянкі + + Парковачныя талоны + Цыгарэты + Пакеты для экскрыментаў жывёл + Квіткі на грамадзкі транспарт + Продаж напояў + Саладосьці + Атрыманьне і адпраўленьне пасылак + Прэзэрватывы + Маркі + Веласіпедныя камэры + Харчаваньне + Напоі і закускі + Паліва + Атрыманьне пасылак + Дошка + Статуя + Камень + Стэла + Бюст + Сіняя шыльда + Крыж + Абеліск + + Надпіс + +Міндаль + Лясны арэх + Какос + Хурма + Вішня + Грэцкі арэх + Сліва + Пладовы сад + Фінікі