From 810f5f82528894d54751064e37c1b0be231287ba Mon Sep 17 00:00:00 2001 From: vshcherb Date: Wed, 25 Sep 2013 20:09:35 +0200 Subject: [PATCH] Implement new SRTM download type --- .../src/net/osmand/IndexConstants.java | 1 + OsmAnd/AndroidManifest.xml | 6 -- .../activities/DownloadIndexActivity.java | 64 ++++++------------- .../plus/download/DownloadActivityType.java | 6 +- .../plus/download/DownloadIndexAdapter.java | 3 +- .../plus/download/DownloadIndexesThread.java | 5 +- .../download/DownloadOsmandIndexesHelper.java | 2 + .../net/osmand/plus/download/IndexItem.java | 28 +++++++- 8 files changed, 57 insertions(+), 58 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/IndexConstants.java b/OsmAnd-java/src/net/osmand/IndexConstants.java index d78dc3bf76..eb6c45b48e 100644 --- a/OsmAnd-java/src/net/osmand/IndexConstants.java +++ b/OsmAnd-java/src/net/osmand/IndexConstants.java @@ -13,6 +13,7 @@ public class IndexConstants { public static final String POI_INDEX_EXT = ".poi.odb"; //$NON-NLS-1$ public static final String BINARY_MAP_INDEX_EXT = ".obf"; //$NON-NLS-1$ public static final String BINARY_SRTM_MAP_INDEX_EXT = ".srtm.obf"; //$NON-NLS-1$ + public static final String BINARY_SRTM_MAP_INDEX_EXT_ZIP = ".srtm.obf.zip"; //$NON-NLS-1$ public static final String GEN_LOG_EXT = ".gen.log"; //$NON-NLS-1$ diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index ac617dfb6f..2818a1daf6 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -85,13 +85,11 @@ - - @@ -101,11 +99,7 @@ - - - - diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index 618b47850e..7d380e5a26 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -1,34 +1,6 @@ package net.osmand.plus.activities; -import java.io.File; -import java.io.FilenameFilter; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import net.osmand.AndroidUtils; -import net.osmand.IndexConstants; -import net.osmand.access.AccessibleToast; -import net.osmand.plus.ClientContext; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; -import net.osmand.plus.Version; -import net.osmand.plus.base.BasicProgressAsyncTask; -import net.osmand.plus.base.SuggestExternalDirectoryDialog; -import net.osmand.plus.download.DownloadActivityType; -import net.osmand.plus.download.DownloadEntry; -import net.osmand.plus.download.DownloadIndexAdapter; -import net.osmand.plus.download.DownloadIndexesThread; -import net.osmand.plus.download.IndexItem; -import net.osmand.plus.download.IndexItemCategory; -import net.osmand.plus.srtmplugin.SRTMPlugin; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.ActivityNotFoundException; @@ -42,22 +14,25 @@ import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.ExpandableListAdapter; -import android.widget.ExpandableListView; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - +import android.widget.*; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.OnNavigationListener; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.SubMenu; +import net.osmand.AndroidUtils; +import net.osmand.IndexConstants; +import net.osmand.access.AccessibleToast; +import net.osmand.plus.*; +import net.osmand.plus.base.BasicProgressAsyncTask; +import net.osmand.plus.base.SuggestExternalDirectoryDialog; +import net.osmand.plus.download.*; +import net.osmand.plus.srtmplugin.SRTMPlugin; + +import java.io.File; +import java.io.FilenameFilter; +import java.text.MessageFormat; +import java.util.*; public class DownloadIndexActivity extends OsmandExpandableListActivity { @@ -338,7 +313,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { boolean excessLimit = left < 0; if (left < 0) left = 0; - if (getType() != DownloadActivityType.HILLSHADE_FILE || getType() != DownloadActivityType.SRTM_FILE) { + if (DownloadActivityType.isCountedInDownloads(getType())) { text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")"; } } @@ -368,7 +343,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { items[i] = getString(R.string.download_regular_maps); } else if (t[i] == DownloadActivityType.ROADS_FILE) { items[i] = getString(R.string.download_roads_only_maps); - } else if (t[i] == DownloadActivityType.SRTM_FILE) { + } else if (t[i] == DownloadActivityType.SRTM_FILE || t[i] == DownloadActivityType.SRTM_COUNTRY_FILE) { items[i] = getString(R.string.download_srtm_maps); } else if (t[i] == DownloadActivityType.HILLSHADE_FILE) { items[i] = getString(R.string.download_hillshade_maps); @@ -383,8 +358,9 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { items = new DownloadActivityType[]{ DownloadActivityType.NORMAL_FILE, DownloadActivityType.ROADS_FILE, - DownloadActivityType.SRTM_FILE, - DownloadActivityType.HILLSHADE_FILE}; + //DownloadActivityType.SRTM_FILE, + DownloadActivityType.HILLSHADE_FILE, + DownloadActivityType.SRTM_COUNTRY_FILE}; } else { items = new DownloadActivityType[]{ DownloadActivityType.NORMAL_FILE, @@ -495,7 +471,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { if (es.getBasename() != null && es.getBasename().contains("_wiki")) { wiki = true; break; - } else if (es.getType() != DownloadActivityType.SRTM_FILE) { + } else if (DownloadActivityType.isCountedInDownloads(es.getType())) { total++; } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index af145dcc09..73f178c750 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -1,5 +1,9 @@ package net.osmand.plus.download; public enum DownloadActivityType { - NORMAL_FILE, ROADS_FILE, SRTM_FILE, HILLSHADE_FILE + NORMAL_FILE, ROADS_FILE, SRTM_FILE, HILLSHADE_FILE, SRTM_COUNTRY_FILE; + + public static boolean isCountedInDownloads(DownloadActivityType tp) { + return tp != SRTM_FILE && tp != HILLSHADE_FILE && tp != SRTM_COUNTRY_FILE; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java index c8c8ccab4b..3e6ac9ba7f 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java @@ -255,7 +255,8 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem item.setTextColor(defaultColor); item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); } else { - if(e.getType() == DownloadActivityType.SRTM_FILE || e.getType() == DownloadActivityType.HILLSHADE_FILE){ + if(e.getType() == DownloadActivityType.SRTM_FILE || e.getType() == DownloadActivityType.HILLSHADE_FILE + || e.getType() == DownloadActivityType.SRTM_COUNTRY_FILE){ item.setTextColor(okColor); // GREEN item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); } else if (e.getDate() != null) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 318468ae8c..d32a815d21 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -228,7 +228,7 @@ public class DownloadIndexesThread { boolean result = downloadFile(entry, filesToReindex, forceWifi); success = result || success; if (result) { - if (entry.type != DownloadActivityType.SRTM_FILE && entry.type != DownloadActivityType.HILLSHADE_FILE) { + if (DownloadActivityType.isCountedInDownloads(entry.type)) { downloads.set(downloads.get() + 1); } if (entry.existingBackupFile != null) { @@ -263,8 +263,7 @@ public class DownloadIndexesThread { private boolean exceedsFreelimit(DownloadEntry entry) { return Version.isFreeVersion(app) && - entry.type != DownloadActivityType.SRTM_FILE && entry.type != DownloadActivityType.HILLSHADE_FILE - && downloads.get() >= DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS; + DownloadActivityType.isCountedInDownloads(entry.type) && downloads.get() >= DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS; } private String reindexFiles(List filesToReindex) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index e0cf37d1a9..68e2d877ae 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -125,6 +125,8 @@ public class DownloadOsmandIndexesHelper { return DownloadActivityType.NORMAL_FILE; } else if("road_region".equals(tagName) ) { return DownloadActivityType.ROADS_FILE; + } else if("srtmcountry".equals(tagName) ) { + return DownloadActivityType.SRTM_COUNTRY_FILE; } else if("hillshade".equals(tagName) ) { return DownloadActivityType.HILLSHADE_FILE; } diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java index 93513329a9..5722d51e29 100644 --- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java @@ -1,6 +1,7 @@ package net.osmand.plus.download; import static net.osmand.IndexConstants.BINARY_MAP_INDEX_EXT; +import static net.osmand.IndexConstants.BINARY_SRTM_MAP_INDEX_EXT; import java.io.File; import java.io.IOException; @@ -53,7 +54,7 @@ public class IndexItem implements Comparable { public String getVisibleDescription(ClientContext ctx) { String s = ""; //$NON-NLS-1$ - if (type == DownloadActivityType.SRTM_FILE) { + if (type == DownloadActivityType.SRTM_FILE || type == DownloadActivityType.SRTM_COUNTRY_FILE) { return ctx.getString(R.string.download_srtm_maps); } else if (type == DownloadActivityType.ROADS_FILE) { return ctx.getString(R.string.download_roads_only_item); @@ -79,6 +80,14 @@ public class IndexItem implements Comparable { if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) { return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length()); } + if (fileName.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP)) { + String simple = fileName.substring(0, fileName.length() - IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP.length()); + int ls = simple.lastIndexOf('_'); + if (ls >= 0) { + return simple.substring(0, ls); + } + return simple; + } if (fileName.endsWith(IndexConstants.SQLITE_EXT)) { return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()).replace('_', ' '); } @@ -93,6 +102,7 @@ public class IndexItem implements Comparable { // POI index download is not supported any longer if (fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT, IndexConstants.BINARY_MAP_VERSION)) // || fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)) // + || fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)) // || fileName.endsWith(addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION)) || fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT) || fileName.endsWith(IndexConstants.SQLITE_EXT) @@ -136,7 +146,11 @@ public class IndexItem implements Comparable { boolean unzipDir = false; boolean zipStream = false; boolean preventMediaIndexing = false; - if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { + if (fileName.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP)) { + parent = ctx.getAppPath(IndexConstants.SRTM_INDEX_DIR); + extension = BINARY_SRTM_MAP_INDEX_EXT; + zipStream = true; + } else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { parent = ctx.getAppPath(IndexConstants.MAPS_PATH); extension = BINARY_MAP_INDEX_EXT; } else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) { @@ -165,6 +179,8 @@ public class IndexItem implements Comparable { } if (type == DownloadActivityType.ROADS_FILE) { extension = "-roads" + extension; + } else if (type == DownloadActivityType.SRTM_COUNTRY_FILE) { +// extension = "-srtm" + extension; } if (parent != null) { parent.mkdirs(); @@ -190,6 +206,9 @@ public class IndexItem implements Comparable { if (type == DownloadActivityType.ROADS_FILE) { url += "road=yes&"; } + if (type == DownloadActivityType.SRTM_COUNTRY_FILE) { + url += "srtmcountry=yes&"; + } if (type == DownloadActivityType.HILLSHADE_FILE) { url += "hillshade=yes&"; } @@ -239,7 +258,10 @@ public class IndexItem implements Comparable { String s = e.substring(0, l); if (getType() == DownloadActivityType.ROADS_FILE) { s += "-roads" ; - } + } + if (getType() == DownloadActivityType.SRTM_COUNTRY_FILE) { + return s + IndexConstants.BINARY_SRTM_MAP_INDEX_EXT; + } s += IndexConstants.BINARY_MAP_INDEX_EXT; return s; } else if(e.endsWith(IndexConstants.SQLITE_EXT)){