Add srtm files to download
This commit is contained in:
parent
d080cb056c
commit
8c3b611d0e
20 changed files with 392 additions and 333 deletions
|
@ -10,7 +10,7 @@ public class IndexConstants {
|
|||
public final static int VOICE_VERSION = 0; //supported download versions
|
||||
public final static int TTSVOICE_VERSION = 1; //supported download versions
|
||||
|
||||
public static final String POI_INDEX_DIR = "POI/"; //$NON-NLS-1$
|
||||
public static final String SRTM_INDEX_DIR = "srtm/"; //$NON-NLS-1$
|
||||
public static final String VOICE_INDEX_DIR = "voice/"; //$NON-NLS-1$
|
||||
public static final String RENDERERS_DIR = "rendering/"; //$NON-NLS-1$
|
||||
|
||||
|
@ -33,5 +33,6 @@ public class IndexConstants {
|
|||
public final static String POI_TABLE = "poi"; //$NON-NLS-1$
|
||||
|
||||
public static final String INDEX_DOWNLOAD_DOMAIN = "download.osmand.net";
|
||||
public static final String BACKUP_INDEX_DIR= "backup/";
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.map;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
import gnu.trove.list.array.TLongArrayList;
|
||||
import gnu.trove.set.hash.TLongHashSet;
|
||||
|
||||
|
@ -12,13 +13,12 @@ import net.osmand.osm.MapUtils;
|
|||
|
||||
public class RegionCountry {
|
||||
public String continentName;
|
||||
public TLongArrayList tiles = new TLongArrayList();
|
||||
public TIntArrayList tiles = new TIntArrayList();
|
||||
public int left, right, top, bottom;
|
||||
public String name;
|
||||
public RegionCountry parent;
|
||||
|
||||
private List<RegionCountry> regions = new ArrayList<RegionCountry>();
|
||||
private final static int SHIFT = 5;
|
||||
|
||||
public void add(int xdeg, int ydeg) {
|
||||
if (tiles.size() == 0) {
|
||||
|
@ -29,15 +29,20 @@ public class RegionCountry {
|
|||
right = Math.max(xdeg, right);
|
||||
bottom = Math.min(ydeg, bottom);
|
||||
top = Math.max(ydeg, top);
|
||||
tiles.add((xdeg << SHIFT) + ydeg);
|
||||
tiles.add(xdeg);
|
||||
tiles.add(ydeg);
|
||||
}
|
||||
|
||||
public int getTileSize() {
|
||||
return tiles.size()/2;
|
||||
}
|
||||
|
||||
public int getLon(int i) {
|
||||
return (int) (tiles.get(i) >> SHIFT);
|
||||
return tiles.get(i*2);
|
||||
}
|
||||
|
||||
public int getLat(int i) {
|
||||
return (int) (tiles.get(i) - ((tiles.get(i) >> SHIFT) << SHIFT));
|
||||
return tiles.get(i*2 + 1);
|
||||
}
|
||||
|
||||
public void addSubregion(RegionCountry c) {
|
||||
|
@ -49,7 +54,7 @@ public class RegionCountry {
|
|||
return regions;
|
||||
}
|
||||
|
||||
public TLongHashSet calculateTileSet(TLongHashSet t, int z) {
|
||||
/*public TLongHashSet calculateTileSet(TLongHashSet t, int z) {
|
||||
for (int j = 0; j < tiles.size(); j++) {
|
||||
int kx = (int) MapUtils.getTileNumberX(z, getLon(j));
|
||||
int ex = (int) MapUtils.getTileNumberX(z, getLon(j) + 0.9999f);
|
||||
|
@ -63,7 +68,7 @@ public class RegionCountry {
|
|||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}*/
|
||||
|
||||
public static RegionCountry construct(OsmAndRegion reg) {
|
||||
RegionCountry rc = new RegionCountry();
|
||||
|
@ -71,8 +76,12 @@ public class RegionCountry {
|
|||
rc.continentName = reg.getContinentName();
|
||||
}
|
||||
rc.name = reg.getName();
|
||||
int px = 0;
|
||||
int py = 0;
|
||||
for (int i = 0; i < reg.getDegXCount(); i++) {
|
||||
rc.add(reg.getDegX(i), reg.getDegY(i));
|
||||
px = reg.getDegX(i) + px;
|
||||
py = reg.getDegY(i) + py;
|
||||
rc.add(px, py);
|
||||
}
|
||||
for (int i = 0; i < reg.getSubregionsCount(); i++) {
|
||||
rc.addSubregion(construct(reg.getSubregions(i)));
|
||||
|
@ -85,7 +94,7 @@ public class RegionCountry {
|
|||
// System.out.println(r.name + " " + r.tiles.size() + " ?= " + r.calculateTileSet(new TLongHashSet(), 8).size());
|
||||
int px = 0;
|
||||
int py = 0;
|
||||
for (int i = 0; i < this.tiles.size(); i++) {
|
||||
for (int i = 0; i < this.getTileSize(); i++) {
|
||||
reg.addDegX(this.getLon(i) - px);
|
||||
reg.addDegY(this.getLat(i) - py);
|
||||
px = this.getLon(i);
|
||||
|
|
|
@ -112,6 +112,9 @@ public class RegionsRegistryConverter {
|
|||
InputStream in = RegionsRegistryConverter.class.getResourceAsStream(RegionRegistry.fileName);
|
||||
OsmAndRegionInfo regInfo = OsmAndRegionInfo.newBuilder().mergeFrom(in).build();
|
||||
t += System.currentTimeMillis();
|
||||
for(int j = 0; j < regInfo.getRegionInfo().getRegionsCount(); j++) {
|
||||
RegionCountry.construct(regInfo.getRegionInfo().getRegions(j));
|
||||
}
|
||||
System.out.println("Read countries " + regInfo.getRegionInfo().getRegionsCount() + " " + countries.size() );
|
||||
System.out.println("Timing " + t);
|
||||
|
||||
|
|
Binary file not shown.
|
@ -16,9 +16,7 @@ public interface ClientContext {
|
|||
|
||||
public File getAppDir();
|
||||
|
||||
public File getVoiceDir();
|
||||
|
||||
public File getBackupDir();
|
||||
public File getAppDir(String extend);
|
||||
|
||||
public void showToastMessage(int msgId);
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package net.osmand.plus.download;
|
|||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class DownloadEntry {
|
||||
public File fileToSave;
|
||||
public File fileToUnzip;
|
||||
|
@ -11,13 +10,14 @@ public class DownloadEntry {
|
|||
public Long dateModified;
|
||||
public double sizeMB;
|
||||
public String baseName;
|
||||
public String urlToDownload;
|
||||
public int parts;
|
||||
public File existingBackupFile;
|
||||
public DownloadEntry attachedEntry;
|
||||
public boolean isAsset;
|
||||
public DownloadActivityType type;
|
||||
|
||||
public List<String> srtmFilesToDownload;
|
||||
public DownloadEntry attachedEntry;
|
||||
|
||||
public DownloadEntry() {
|
||||
// default
|
||||
|
|
|
@ -39,7 +39,7 @@ public class DownloadFileHelper {
|
|||
public void showWarning(String warning);
|
||||
}
|
||||
|
||||
protected void downloadFile(String fileName, FileOutputStream out, URL url, String part, String indexOfAllFiles,
|
||||
private void downloadFileInternal(String fileName, FileOutputStream out, URL url, String part, String indexOfAllFiles,
|
||||
IProgress progress, boolean forceWifi) throws IOException, InterruptedException {
|
||||
InputStream is = null;
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
|
@ -47,6 +47,7 @@ public class DownloadFileHelper {
|
|||
int length = 0;
|
||||
int fileread = 0;
|
||||
int triesDownload = TRIES_TO_DOWNLOAD;
|
||||
boolean notFound = false;
|
||||
boolean first = true;
|
||||
try {
|
||||
while (triesDownload > 0) {
|
||||
|
@ -68,6 +69,10 @@ public class DownloadFileHelper {
|
|||
conn.setConnectTimeout(30000);
|
||||
log.info(conn.getResponseMessage() + " " + conn.getResponseCode()); //$NON-NLS-1$
|
||||
boolean wifiConnectionBroken = forceWifi && !isWifiConnected();
|
||||
if(conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND){
|
||||
notFound = true;
|
||||
break;
|
||||
}
|
||||
if ((conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL &&
|
||||
conn.getResponseCode() != HttpURLConnection.HTTP_OK ) || wifiConnectionBroken) {
|
||||
conn.disconnect();
|
||||
|
@ -75,10 +80,6 @@ public class DownloadFileHelper {
|
|||
continue;
|
||||
}
|
||||
is = conn.getInputStream();
|
||||
// long skipped = 0;
|
||||
// while (skipped < fileread) {
|
||||
// skipped += is.skip(fileread - skipped);
|
||||
// }
|
||||
if (first) {
|
||||
length = conn.getContentLength();
|
||||
String taskName = ctx.getString(R.string.downloading_file) + indexOfAllFiles +" " + fileName;
|
||||
|
@ -111,7 +112,9 @@ public class DownloadFileHelper {
|
|||
is.close();
|
||||
}
|
||||
}
|
||||
if(length != fileread || length == 0){
|
||||
if(notFound) {
|
||||
throw new IOException("File not found " + fileName); //$NON-NLS-1$
|
||||
} else if(length != fileread || length == 0){
|
||||
throw new IOException("File was not fully read"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
@ -121,53 +124,31 @@ public class DownloadFileHelper {
|
|||
return ctx.isWifiConnected();
|
||||
}
|
||||
|
||||
public boolean downloadFile(final String fileName, DownloadEntry de, IProgress progress,
|
||||
public boolean downloadFile(DownloadEntry de, IProgress progress,
|
||||
List<File> toReIndex, String indexOfAllFiles,
|
||||
DownloadFileShowWarning showWarningCallback, boolean forceWifi) throws InterruptedException {
|
||||
try {
|
||||
String urlSuffix = "&" + ctx.getVersionAsURLParam();
|
||||
if(de.type == DownloadActivityType.SRTM_FILE) {
|
||||
String urlPrefix = "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download_srtm?event=2&file=";
|
||||
List<String> list = de.srtmFilesToDownload;
|
||||
if(list != null) {
|
||||
int i = 1;
|
||||
for(String fname : list) {
|
||||
URL url = new URL(urlPrefix + fname + urlSuffix); //$NON-NLS-1$
|
||||
FileOutputStream out = new FileOutputStream(new File(de.fileToSave, fname));
|
||||
try {
|
||||
downloadFile(fname, out, url, null, " [" + i + "/" + list.size() + "]", progress, forceWifi);
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream(de.fileToSave);
|
||||
try {
|
||||
log.info("Download " + de.urlToDownload);
|
||||
if (de.parts == 1) {
|
||||
URL url = new URL(de.urlToDownload); //$NON-NLS-1$
|
||||
downloadFileInternal(de.baseName, out, url, null, indexOfAllFiles, progress, forceWifi);
|
||||
} else {
|
||||
for (int i = 1; i <= de.parts; i++) {
|
||||
URL url = new URL(de.urlToDownload); //$NON-NLS-1$
|
||||
downloadFileInternal(de.baseName, out, url, " [" + i + "/" + de.parts + "]", indexOfAllFiles, progress, forceWifi);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FileOutputStream out = new FileOutputStream(de.fileToSave);
|
||||
try {
|
||||
String urlPrefix = "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&file=";
|
||||
|
||||
if (de.type == DownloadActivityType.ROADS_FILE) {
|
||||
urlSuffix += "&road=yes";
|
||||
}
|
||||
if (de.parts == 1) {
|
||||
URL url = new URL(urlPrefix + fileName + urlSuffix); //$NON-NLS-1$
|
||||
downloadFile(fileName, out, url, null, indexOfAllFiles, progress, forceWifi);
|
||||
} else {
|
||||
for (int i = 1; i <= de.parts; i++) {
|
||||
URL url = new URL(urlPrefix + fileName + "-" + i + urlSuffix); //$NON-NLS-1$
|
||||
downloadFile(fileName, out, url, " [" + i + "/" + de.parts + "]", indexOfAllFiles, progress, forceWifi);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
unzipFile(de, progress, toReIndex);
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
unzipFile(de, progress, toReIndex);
|
||||
showWarningCallback.showWarning(ctx.getString(R.string.download_index_success));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
log.error("Exception ocurred", e); //$NON-NLS-1$
|
||||
showWarningCallback.showWarning(ctx.getString(R.string.error_io_error));
|
||||
showWarningCallback.showWarning(ctx.getString(R.string.error_io_error) + " : " + e.getMessage());
|
||||
// Possibly file is corrupted
|
||||
de.fileToSave.delete();
|
||||
return false;
|
||||
|
|
|
@ -1,20 +1,26 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import static net.osmand.data.IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
import static net.osmand.data.IndexConstants.BINARY_MAP_INDEX_EXT_ZIP;
|
||||
import static net.osmand.data.IndexConstants.TTSVOICE_INDEX_EXT_ZIP;
|
||||
import static net.osmand.data.IndexConstants.VOICE_INDEX_EXT_ZIP;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.data.IndexConstants;
|
||||
import net.osmand.plus.ClientContext;
|
||||
import net.osmand.plus.R;
|
||||
import static net.osmand.data.IndexConstants.*;
|
||||
|
||||
public class IndexItem {
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
public class IndexItem implements Comparable<IndexItem> {
|
||||
private static final Log log = LogUtil.getLog(IndexItem.class);
|
||||
|
||||
String description;
|
||||
|
@ -56,7 +62,7 @@ public class IndexItem {
|
|||
return s;
|
||||
}
|
||||
|
||||
public String getVisibleName() {
|
||||
public String getVisibleName(ClientContext ctx) {
|
||||
return getBasename().replace('_', ' ');
|
||||
}
|
||||
|
||||
|
@ -101,7 +107,7 @@ public class IndexItem {
|
|||
return date;
|
||||
}
|
||||
|
||||
public String getSizeDescription() {
|
||||
public String getSizeDescription(ClientContext ctx) {
|
||||
return size + " MB";
|
||||
}
|
||||
|
||||
|
@ -109,7 +115,8 @@ public class IndexItem {
|
|||
return size;
|
||||
}
|
||||
|
||||
public DownloadEntry createDownloadEntry(ClientContext ctx, DownloadActivityType type) {
|
||||
public List<DownloadEntry> createDownloadEntry(ClientContext ctx, DownloadActivityType type,
|
||||
List<DownloadEntry> downloadEntries) {
|
||||
String fileName = this.fileName;
|
||||
File parent = null;
|
||||
String toSavePostfix = null;
|
||||
|
@ -130,13 +137,13 @@ public class IndexItem {
|
|||
toSavePostfix = IndexConstants.EXTRA_ZIP_EXT;
|
||||
toCheckPostfix = IndexConstants.EXTRA_EXT;
|
||||
} else if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
|
||||
parent = ctx.getVoiceDir();
|
||||
parent = ctx.getAppDir(IndexConstants.VOICE_INDEX_DIR);
|
||||
toSavePostfix = VOICE_INDEX_EXT_ZIP;
|
||||
toCheckPostfix = ""; //$NON-NLS-1$
|
||||
unzipDir = true;
|
||||
preventMediaIndexing = true;
|
||||
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
|
||||
parent = ctx.getVoiceDir();
|
||||
parent = ctx.getAppDir(IndexConstants.VOICE_INDEX_DIR);
|
||||
toSavePostfix = TTSVOICE_INDEX_EXT_ZIP;
|
||||
toCheckPostfix = ""; //$NON-NLS-1$
|
||||
unzipDir = true;
|
||||
|
@ -160,11 +167,16 @@ public class IndexItem {
|
|||
final DownloadEntry entry;
|
||||
if (parent == null || !parent.exists()) {
|
||||
ctx.showToastMessage(R.string.sd_dir_not_accessible);
|
||||
entry = null;
|
||||
} else {
|
||||
entry = new DownloadEntry();
|
||||
entry.type = type;
|
||||
entry.baseName = getBasename();
|
||||
String url = "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&";
|
||||
url += ctx.getVersionAsURLParam() + "&";
|
||||
if (type == DownloadActivityType.ROADS_FILE) {
|
||||
url += "road=yes&";
|
||||
}
|
||||
entry.urlToDownload = url + "file=" + fileName;
|
||||
entry.fileToSave = new File(parent, entry.baseName + toSavePostfix);
|
||||
entry.unzip = unzipDir;
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
|
||||
|
@ -184,32 +196,49 @@ public class IndexItem {
|
|||
entry.parts = Integer.parseInt(parts);
|
||||
}
|
||||
entry.fileToUnzip = new File(parent, entry.baseName + toCheckPostfix);
|
||||
File backup = new File(ctx.getBackupDir(), entry.fileToUnzip.getName());
|
||||
File backup = new File(ctx.getAppDir(IndexConstants.BACKUP_INDEX_DIR), entry.fileToUnzip.getName());
|
||||
if (backup.exists()) {
|
||||
entry.existingBackupFile = backup;
|
||||
}
|
||||
if (attachedItem != null) {
|
||||
ArrayList<DownloadEntry> sz = new ArrayList<DownloadEntry>();
|
||||
attachedItem.createDownloadEntry(ctx, type, sz);
|
||||
if(sz.size() > 0) {
|
||||
entry.attachedEntry = sz.get(0);
|
||||
}
|
||||
}
|
||||
downloadEntries.add(entry);
|
||||
}
|
||||
if (attachedItem != null) {
|
||||
entry.attachedEntry = attachedItem.createDownloadEntry(ctx, type);
|
||||
return downloadEntries;
|
||||
}
|
||||
|
||||
public String getTargetFileName(){
|
||||
String e = getFileName();
|
||||
|
||||
if (e.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) || e.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
|
||||
int l = e.lastIndexOf('_');
|
||||
if(l == -1) {
|
||||
l = e.length();
|
||||
}
|
||||
String s = e.substring(0, l);
|
||||
if (getType() == DownloadActivityType.ROADS_FILE) {
|
||||
s = "-roads" + s;
|
||||
}
|
||||
s += IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
return s;
|
||||
} else if(e.endsWith(IndexConstants.EXTRA_ZIP_EXT)){
|
||||
return e.substring(0, e.length() - IndexConstants.EXTRA_ZIP_EXT.length()) + IndexConstants.EXTRA_EXT;
|
||||
}
|
||||
return entry;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
public String convertServerFileNameToLocal() {
|
||||
String e = getFileName();
|
||||
int l = e.lastIndexOf('_');
|
||||
String s;
|
||||
if (e.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) || e.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
|
||||
s = IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
} else {
|
||||
s = ""; //$NON-NLS-1$
|
||||
@Override
|
||||
public int compareTo(IndexItem another) {
|
||||
if(another == null) {
|
||||
return -1;
|
||||
}
|
||||
if (getType() == DownloadActivityType.ROADS_FILE) {
|
||||
s = "-roads" + s;
|
||||
}
|
||||
if(l == -1) {
|
||||
l = e.length();
|
||||
}
|
||||
return e.substring(0, l) + s;
|
||||
return getFileName().compareTo(another.getFileName());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,14 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import java.io.File;
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.data.IndexConstants;
|
||||
import net.osmand.map.RegionCountry;
|
||||
import net.osmand.plus.ClientContext;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -9,17 +16,46 @@ import net.osmand.plus.R;
|
|||
public class SrtmIndexItem extends IndexItem {
|
||||
|
||||
private RegionCountry item;
|
||||
public SrtmIndexItem(RegionCountry item) {
|
||||
super(fileName(item), "Elevation lines", "", item.tiles.size()+"", null);
|
||||
private List<String> tilesToDownload = new ArrayList<String>();
|
||||
public SrtmIndexItem(RegionCountry item, Map<String, String> existingFileNames) {
|
||||
super(fileName(item), "Elevation lines", "", item.getTileSize()+"", null);
|
||||
this.item = item;
|
||||
type = DownloadActivityType.SRTM_FILE;
|
||||
updateExistingTiles(existingFileNames);
|
||||
}
|
||||
|
||||
public void updateExistingTiles(Map<String, String> existingFileNames) {
|
||||
for(int i = 0; i<item.getTileSize() ; i++) {
|
||||
int lat = item.getLat(i);
|
||||
int lon = item.getLon(i);
|
||||
String fname = getFileName(lat, lon);
|
||||
if(!existingFileNames.containsKey(fname + IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||
tilesToDownload.add(fname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileName(int lat, int lon) {
|
||||
String fn = lat >= 0 ? "N" : "S";
|
||||
if(Math.abs(lat) < 10) {
|
||||
fn += "0";
|
||||
}
|
||||
fn += Math.abs(lat);
|
||||
fn += lon >= 0 ? "e" : "w";
|
||||
if(Math.abs(lon) < 10) {
|
||||
fn += "00";
|
||||
} else if(Math.abs(lon) < 100) {
|
||||
fn += "0";
|
||||
}
|
||||
fn += Math.abs(lon);
|
||||
return fn;
|
||||
}
|
||||
|
||||
private static String fileName(RegionCountry r) {
|
||||
if(r.parent == null) {
|
||||
return r.continentName + " " + r.name;
|
||||
return (r.continentName + " " + r.name).trim();
|
||||
} else {
|
||||
return r.parent.continentName + " " + r.parent.name + " " + r.name;
|
||||
return (r.parent.continentName + " " + r.parent.name + " " + r.name).trim();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,27 +65,40 @@ public class SrtmIndexItem extends IndexItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DownloadEntry createDownloadEntry(ClientContext ctx, DownloadActivityType type) {
|
||||
File parent = ctx.getAppDir();
|
||||
final DownloadEntry entry;
|
||||
public List<DownloadEntry> createDownloadEntry(ClientContext ctx, DownloadActivityType type,
|
||||
List<DownloadEntry> downloadEntries) {
|
||||
File parent = ctx.getAppDir(IndexConstants.SRTM_INDEX_DIR);
|
||||
parent.mkdirs();
|
||||
List<DownloadEntry> toDownload = new ArrayList<DownloadEntry>();
|
||||
if (parent == null || !parent.exists()) {
|
||||
ctx.showToastMessage(R.string.sd_dir_not_accessible);
|
||||
entry = null;
|
||||
} else {
|
||||
entry = new DownloadEntry();
|
||||
entry.type = type;
|
||||
entry.baseName = getBasename();
|
||||
// entry.fileToSave = new File(parent, entry.baseName + toSavePostfix);
|
||||
// entry.unzip = unzipDir;
|
||||
entry.dateModified = System.currentTimeMillis();
|
||||
entry.parts = Integer.parseInt(size);
|
||||
// entry.fileToUnzip = new File(parent, entry.baseName + toCheckPostfix);
|
||||
for (String fileToDownload : tilesToDownload) {
|
||||
DownloadEntry entry = new DownloadEntry();
|
||||
entry.type = type;
|
||||
entry.baseName = fileToDownload;
|
||||
String url = "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN;
|
||||
//FIXME
|
||||
// url += "/download?event=2&";
|
||||
// url += ctx.getVersionAsURLParam() + "&";
|
||||
String fullName = fileToDownload + "_" + IndexConstants.BINARY_MAP_VERSION + IndexConstants.BINARY_MAP_INDEX_EXT_ZIP;
|
||||
entry.urlToDownload = url +"/srtm/" + fullName;
|
||||
// url + "file=" + fileName;
|
||||
entry.fileToSave = new File(parent, fullName);
|
||||
entry.unzip = false;
|
||||
entry.dateModified = System.currentTimeMillis();
|
||||
entry.sizeMB = 20;
|
||||
entry.parts = 1;
|
||||
entry.fileToUnzip = new File(parent, entry.baseName + IndexConstants.BINARY_MAP_INDEX_EXT);
|
||||
downloadEntries.add(entry);
|
||||
toDownload.size();
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
return downloadEntries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertServerFileNameToLocal() {
|
||||
public String getTargetFileName() {
|
||||
return fileName+".nonexistent";
|
||||
}
|
||||
|
||||
|
@ -59,16 +108,21 @@ public class SrtmIndexItem extends IndexItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getSizeDescription() {
|
||||
return size + " parts";
|
||||
public String getSizeDescription(ClientContext ctx) {
|
||||
return (item.getTileSize()-tilesToDownload.size()) + "/" + item.getTileSize() + " " + ctx.getString(R.string.index_srtm_parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVisibleName() {
|
||||
public String getVisibleDescription(ClientContext ctx) {
|
||||
return ctx.getString(R.string.index_srtm_ele);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVisibleName(ClientContext ctx) {
|
||||
if(item.parent == null) {
|
||||
return item.name + "\n";
|
||||
return item.name;
|
||||
} else {
|
||||
return item.parent.name +"\n"+item.name;
|
||||
return item.parent.name +" "+item.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
1. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="index_srtm_parts">parts</string>
|
||||
<string name="index_srtm_ele">Elevation lines</string>
|
||||
<string name="srtm_plugin_description">SRTM plugin (TODO description)</string>
|
||||
<string name="srtm_plugin_name">SRTM plugin</string>
|
||||
<string name="download_select_map_types">Other maps</string>
|
||||
|
|
|
@ -45,16 +45,12 @@ public class AndroidClientContext implements ClientContext {
|
|||
public File getAppDir() {
|
||||
return app.getSettings().extendOsmandPath(ResourceManager.APP_DIR);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public File getVoiceDir() {
|
||||
return app.getSettings().extendOsmandPath(ResourceManager.VOICE_PATH);
|
||||
public File getAppDir(String extend) {
|
||||
return app.getSettings().extendOsmandPath(ResourceManager.APP_DIR + extend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getBackupDir() {
|
||||
return app.getSettings().extendOsmandPath(ResourceManager.BACKUP_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showToastMessage(int msgId) {
|
||||
|
|
|
@ -66,11 +66,11 @@ public abstract class OsmandPlugin {
|
|||
installedPlugins.add(new OsmandBackgroundServicePlugin(app));
|
||||
installedPlugins.add(new OsmandExtraSettings(app));
|
||||
installedPlugins.add(new AccessibilityPlugin(app));
|
||||
installedPlugins.add(new OsmEditingPlugin(app));
|
||||
installedPlugins.add(new OsmandDevelopmentPlugin(app));
|
||||
installedPlugins.add(new SRTMPlugin(app));
|
||||
installParkingPlugin(app);
|
||||
installOsmodroidPlugin(app);
|
||||
installedPlugins.add(new OsmEditingPlugin(app));
|
||||
installedPlugins.add(new OsmandDevelopmentPlugin(app));
|
||||
|
||||
Set<String> enabledPlugins = settings.getEnabledPlugins();
|
||||
for (OsmandPlugin plugin : installedPlugins) {
|
||||
|
|
|
@ -69,12 +69,12 @@ public class ResourceManager {
|
|||
|
||||
public static final String APP_DIR = "osmand/"; //$NON-NLS-1$
|
||||
public static final String ROUTING_XML = APP_DIR + "routing.xml";
|
||||
public static final String POI_PATH = APP_DIR + IndexConstants.POI_INDEX_DIR;
|
||||
public static final String SRTM_PATH = APP_DIR + IndexConstants.SRTM_INDEX_DIR;
|
||||
public static final String VOICE_PATH = APP_DIR + IndexConstants.VOICE_INDEX_DIR;
|
||||
public static final String GPX_PATH = APP_DIR + "tracks";
|
||||
public static final String MAPS_PATH = APP_DIR;
|
||||
public static final String INDEXES_CACHE = APP_DIR + "ind.cache";
|
||||
public static final String BACKUP_PATH = APP_DIR + "backup/";
|
||||
public static final String BACKUP_PATH = APP_DIR + IndexConstants.BACKUP_INDEX_DIR;
|
||||
public static final String TILES_PATH = APP_DIR+"tiles/"; //$NON-NLS-1$
|
||||
public static final String TEMP_SOURCE_TO_LOAD = "temp"; //$NON-NLS-1$
|
||||
public static final String VECTOR_MAP = "#vector_map"; //$NON-NLS-1$
|
||||
|
@ -535,106 +535,112 @@ public class ResourceManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<File> collectFiles(File dir, String ext, List<File> files) {
|
||||
if(dir.exists() && dir.canRead()) {
|
||||
File[] lf = dir.listFiles();
|
||||
if(lf == null) {
|
||||
lf = new File[0];
|
||||
}
|
||||
for (File f : lf) {
|
||||
if (f.getName().endsWith(ext)) {
|
||||
files.add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
public List<String> indexingMaps(final IProgress progress) {
|
||||
File file = context.getSettings().extendOsmandPath(MAPS_PATH);
|
||||
file.mkdirs();
|
||||
long val = System.currentTimeMillis();
|
||||
ArrayList<File> files = new ArrayList<File>();
|
||||
collectFiles(context.getSettings().extendOsmandPath(MAPS_PATH), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
collectFiles(context.getSettings().extendOsmandPath(SRTM_PATH), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
renderer.clearAllResources();
|
||||
CachedOsmandIndexes cachedOsmandIndexes = new CachedOsmandIndexes();
|
||||
File indCache = context.getSettings().extendOsmandPath(INDEXES_CACHE);
|
||||
if(indCache.exists()) {
|
||||
if (indCache.exists()) {
|
||||
try {
|
||||
cachedOsmandIndexes.readFromFile(indCache, CachedOsmandIndexes.VERSION);
|
||||
NativeOsmandLibrary nativeLib = NativeOsmandLibrary.getLoadedLibrary();
|
||||
if(nativeLib != null) {
|
||||
if (nativeLib != null) {
|
||||
nativeLib.initCacheMapFile(indCache.getAbsolutePath());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if (file.exists() && file.canRead() ) {
|
||||
long val = System.currentTimeMillis();
|
||||
File[] lf = file.listFiles();
|
||||
if(lf == null) {
|
||||
lf = new File[0];
|
||||
}
|
||||
for (File f : lf) {
|
||||
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||
progress.startTask(context.getString(R.string.indexing_map) + " " + f.getName(), -1); //$NON-NLS-1$
|
||||
try {
|
||||
BinaryMapIndexReader index = null;
|
||||
try {
|
||||
index = cachedOsmandIndexes.getReader(f);
|
||||
if (index.getVersion() != IndexConstants.BINARY_MAP_VERSION) {
|
||||
index = null;
|
||||
}
|
||||
if (index != null) {
|
||||
renderer.initializeNewResource(progress, f, index);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error(String.format("File %s could not be read", f.getName()), e);
|
||||
}
|
||||
if (index == null || (Version.isFreeVersion(context) && f.getName().contains("_wiki"))) {
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
} else {
|
||||
if(index.isBasemap()) {
|
||||
basemapFileNames.add(f.getName());
|
||||
}
|
||||
long dateCreated = index.getDateCreated();
|
||||
if(dateCreated == 0) {
|
||||
dateCreated = f.lastModified();
|
||||
}
|
||||
indexFileNames.put(f.getName(), MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(dateCreated))); //$NON-NLS-1$
|
||||
for(String rName : index.getRegionNames()) {
|
||||
// skip duplicate names (don't make collision between getName() and name in the map)
|
||||
// it can be dangerous to use one file to different indexes if it is multithreaded
|
||||
RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(index, rName);
|
||||
addressMap.put(rName, rarb);
|
||||
}
|
||||
if (index.hasTransportData()) {
|
||||
try {
|
||||
RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$
|
||||
transportRepositories.add(new TransportIndexRepositoryBinary(new BinaryMapIndexReader(raf, index)));
|
||||
} catch (IOException e) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
if(index.containsRouteData()) {
|
||||
try {
|
||||
RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$
|
||||
routingMapFiles.put(f.getAbsolutePath(), new BinaryMapIndexReader(raf, index));
|
||||
} catch (IOException e) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
if(index.containsPoiData()) {
|
||||
try {
|
||||
RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$
|
||||
amenityRepositories.add(new AmenityIndexRepositoryBinary(new BinaryMapIndexReader(raf, index)));
|
||||
} catch (IOException e) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLiteException e) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
} catch (OutOfMemoryError oome) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), oome); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_big_for_memory), f.getName()));
|
||||
for (File f : files) {
|
||||
progress.startTask(context.getString(R.string.indexing_map) + " " + f.getName(), -1); //$NON-NLS-1$
|
||||
try {
|
||||
BinaryMapIndexReader index = null;
|
||||
try {
|
||||
index = cachedOsmandIndexes.getReader(f);
|
||||
if (index.getVersion() != IndexConstants.BINARY_MAP_VERSION) {
|
||||
index = null;
|
||||
}
|
||||
} else if(f.getName().endsWith(".map.odb")){ //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.old_map_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
if (index != null) {
|
||||
renderer.initializeNewResource(progress, f, index);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error(String.format("File %s could not be read", f.getName()), e);
|
||||
}
|
||||
if (index == null || (Version.isFreeVersion(context) && f.getName().contains("_wiki"))) {
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
} else {
|
||||
if (index.isBasemap()) {
|
||||
basemapFileNames.add(f.getName());
|
||||
}
|
||||
long dateCreated = index.getDateCreated();
|
||||
if (dateCreated == 0) {
|
||||
dateCreated = f.lastModified();
|
||||
}
|
||||
indexFileNames.put(f.getName(), MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(dateCreated))); //$NON-NLS-1$
|
||||
for (String rName : index.getRegionNames()) {
|
||||
// skip duplicate names (don't make collision between getName() and name in the map)
|
||||
// it can be dangerous to use one file to different indexes if it is multithreaded
|
||||
RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(index, rName);
|
||||
addressMap.put(rName, rarb);
|
||||
}
|
||||
if (index.hasTransportData()) {
|
||||
try {
|
||||
RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$
|
||||
transportRepositories.add(new TransportIndexRepositoryBinary(new BinaryMapIndexReader(raf, index)));
|
||||
} catch (IOException e) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
if (index.containsRouteData()) {
|
||||
try {
|
||||
RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$
|
||||
routingMapFiles.put(f.getAbsolutePath(), new BinaryMapIndexReader(raf, index));
|
||||
} catch (IOException e) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
if (index.containsPoiData()) {
|
||||
try {
|
||||
RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$
|
||||
amenityRepositories.add(new AmenityIndexRepositoryBinary(new BinaryMapIndexReader(raf, index)));
|
||||
} catch (IOException e) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLiteException e) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
} catch (OutOfMemoryError oome) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), oome); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_big_for_memory), f.getName()));
|
||||
}
|
||||
log.debug("All map files initialized " + (System.currentTimeMillis() - val) + " ms");
|
||||
}
|
||||
if(!indCache.exists() || indCache.canWrite()){
|
||||
log.debug("All map files initialized " + (System.currentTimeMillis() - val) + " ms");
|
||||
if (files.size() > 0 && (!indCache.exists() || indCache.canWrite())) {
|
||||
try {
|
||||
cachedOsmandIndexes.writeToFile(indCache);
|
||||
} catch (Exception e) {
|
||||
|
@ -646,22 +652,11 @@ public class ResourceManager {
|
|||
|
||||
// POI INDEX //
|
||||
private List<String> indexingPoi(final IProgress progress) {
|
||||
File file = context.getSettings().extendOsmandPath(POI_PATH);
|
||||
file.mkdirs();
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
if (file.exists() && file.canRead()) {
|
||||
File[] listFiles = file.listFiles();
|
||||
if (listFiles != null) {
|
||||
for (File f : listFiles) {
|
||||
indexingPoi(progress, warnings, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
File updatablePoiDbFile = context.getSettings().extendOsmandPath(MINE_POI_DB);
|
||||
if(updatablePoiDbFile.exists() && updatablePoiDbFile.canRead()){
|
||||
tryToOpenUpdatablePoiDb(updatablePoiDbFile);
|
||||
}
|
||||
return warnings;
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
public AmenityIndexRepositoryOdb getUpdatablePoiDb() {
|
||||
|
@ -692,19 +687,6 @@ public class ResourceManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
// POI not supported any more
|
||||
public void indexingPoi(final IProgress progress, List<String> warnings, File f) {
|
||||
if (f.getName().endsWith(IndexConstants.POI_INDEX_EXT)) {
|
||||
progress.startTask(context.getString(R.string.indexing_poi) + " " + f.getName(), -1); //$NON-NLS-1$
|
||||
try {
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
} catch (SQLiteException e) {
|
||||
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
|
||||
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
|
||||
public List<Amenity> searchAmenities(PoiFilter filter,
|
||||
|
|
|
@ -16,7 +16,9 @@ import java.io.IOException;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
@ -92,7 +94,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
|
||||
private ProgressDialog progressFileDlg = null;
|
||||
|
||||
private TreeMap<String, DownloadEntry> entriesToDownload = new TreeMap<String, DownloadEntry>();
|
||||
private TreeMap<IndexItem, List<DownloadEntry>> entriesToDownload = new TreeMap<IndexItem, List<DownloadEntry>>();
|
||||
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
|
||||
|
||||
private int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
|
||||
|
@ -122,7 +124,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
downloadFilesCheckFreeVersion();
|
||||
downloadFilesCheckFreeVersion(flattenDownloadEntries());
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -171,6 +173,15 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
|
||||
|
||||
public void updateLoadedFiles() {
|
||||
if (type == DownloadActivityType.SRTM_FILE) {
|
||||
List<IndexItem> srtms = downloadListIndexThread.getCachedIndexFiles();
|
||||
for (IndexItem i : srtms) {
|
||||
if (i instanceof SrtmIndexItem) {
|
||||
((SrtmIndexItem) i).updateExistingTiles(getMyApplication().getResourceManager().getIndexFileNames());
|
||||
}
|
||||
}
|
||||
((DownloadIndexAdapter) getExpandableListAdapter()).notifyDataSetInvalidated();
|
||||
}
|
||||
if(getExpandableListAdapter() != null) {
|
||||
((DownloadIndexAdapter)getExpandableListAdapter()).updateLoadedFiles();
|
||||
}
|
||||
|
@ -199,7 +210,17 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
return type;
|
||||
}
|
||||
|
||||
public TreeMap<String, DownloadEntry> getEntriesToDownload() {
|
||||
public List<DownloadEntry> flattenDownloadEntries() {
|
||||
List<DownloadEntry> res = new ArrayList<DownloadEntry>();
|
||||
for(List<DownloadEntry> ens : entriesToDownload.values()) {
|
||||
if(ens != null) {
|
||||
res.addAll(ens);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public TreeMap<IndexItem, List<DownloadEntry>> getEntriesToDownload() {
|
||||
return entriesToDownload;
|
||||
}
|
||||
|
||||
|
@ -218,7 +239,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
IndexItem es = listAdapter.getChild(j, i);
|
||||
if (!entriesToDownload.containsKey(es.getFileName())) {
|
||||
selected++;
|
||||
entriesToDownload.put(es.getFileName(), es.createDownloadEntry(getClientContext(), type));
|
||||
entriesToDownload.put(es, es.createDownloadEntry(getClientContext(), type, new ArrayList<DownloadEntry>(1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,10 +249,10 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else if (item.getItemId() == FILTER_EXISTING_REGIONS) {
|
||||
final Set<String> listAlreadyDownloaded = listAlreadyDownloadedWithAlternatives();
|
||||
final Map<String, String> listAlreadyDownloaded = listAlreadyDownloadedWithAlternatives();
|
||||
final List<IndexItem> filtered = new ArrayList<IndexItem>();
|
||||
for (IndexItem fileItem : listAdapter.getIndexFiles()) {
|
||||
if (listAlreadyDownloaded.contains(fileItem.convertServerFileNameToLocal())) {
|
||||
if (listAlreadyDownloaded.containsKey(fileItem.getTargetFileName())) {
|
||||
filtered.add(fileItem);
|
||||
}
|
||||
}
|
||||
|
@ -295,14 +316,15 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
public List<IndexItem> getFilteredByType() {
|
||||
final List<IndexItem> filtered = new ArrayList<IndexItem>();
|
||||
if(type == DownloadActivityType.SRTM_FILE){
|
||||
Map<String, String> indexFileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
||||
List<RegionCountry> countries = RegionRegistry.getRegionRegistry().getCountries();
|
||||
for(RegionCountry rc : countries){
|
||||
if(rc.tiles.size() > 50){
|
||||
for(RegionCountry ch : rc.getSubRegions()) {
|
||||
filtered.add(new SrtmIndexItem(ch));
|
||||
filtered.add(new SrtmIndexItem(ch, indexFileNames));
|
||||
}
|
||||
} else {
|
||||
filtered.add(new SrtmIndexItem(rc));
|
||||
filtered.add(new SrtmIndexItem(rc, indexFileNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +397,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
switch (id) {
|
||||
case DIALOG_PROGRESS_FILE:
|
||||
DownloadIndexesAsyncTask task = new DownloadIndexesAsyncTask(new ProgressDialogImplementation(progressFileDlg,true));
|
||||
String[] indexes = entriesToDownload.keySet().toArray(new String[0]);
|
||||
IndexItem[] indexes = entriesToDownload.keySet().toArray(new IndexItem[0]);
|
||||
task.execute(indexes);
|
||||
break;
|
||||
case DIALOG_PROGRESS_LIST:
|
||||
|
@ -418,12 +440,11 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
final IndexItem e = (IndexItem) ((DownloadIndexAdapter)getListAdapter()).getChild(groupPosition, childPosition);
|
||||
String key = e.getFileName();
|
||||
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
|
||||
|
||||
if(ch.isChecked()){
|
||||
ch.setChecked(!ch.isChecked());
|
||||
entriesToDownload.remove(key);
|
||||
entriesToDownload.remove(e);
|
||||
if(entriesToDownload.isEmpty()){
|
||||
int x = getListView().getScrollX();
|
||||
int y = getListView().getScrollY();
|
||||
|
@ -433,11 +454,11 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
return true;
|
||||
}
|
||||
|
||||
final DownloadEntry entry = e.createDownloadEntry(getClientContext(), type);
|
||||
if (entry != null) {
|
||||
List<DownloadEntry> download = e.createDownloadEntry(getClientContext(), type, new ArrayList<DownloadEntry>());
|
||||
if (download.size() > 0) {
|
||||
// if(!fileToUnzip.exists()){
|
||||
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
|
||||
entriesToDownload.put(e.getFileName(), entry);
|
||||
entriesToDownload.put(e, download);
|
||||
int x = getListView().getScrollX();
|
||||
int y = getListView().getScrollY();
|
||||
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||
|
@ -448,29 +469,26 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
}
|
||||
|
||||
|
||||
private Set<String> listAlreadyDownloadedWithAlternatives() {
|
||||
Set<String> files = new TreeSet<String>();
|
||||
File externalStorageDirectory = settings.getExternalStorageDirectory();
|
||||
// files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.POI_PATH),POI_INDEX_EXT,POI_INDEX_EXT_ZIP,POI_TABLE_VERSION));
|
||||
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.APP_DIR),BINARY_MAP_INDEX_EXT,BINARY_MAP_INDEX_EXT_ZIP,BINARY_MAP_VERSION));
|
||||
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.APP_DIR),EXTRA_EXT, EXTRA_ZIP_EXT,0));
|
||||
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.BACKUP_PATH),BINARY_MAP_INDEX_EXT,BINARY_MAP_INDEX_EXT_ZIP,BINARY_MAP_VERSION));
|
||||
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.VOICE_PATH),"",VOICE_INDEX_EXT_ZIP, VOICE_VERSION));
|
||||
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.VOICE_PATH),"",TTSVOICE_INDEX_EXT_ZIP, TTSVOICE_VERSION));
|
||||
private Map<String, String> listAlreadyDownloadedWithAlternatives() {
|
||||
Map<String, String> files = new TreeMap<String, String>();
|
||||
listWithAlternatives(settings.extendOsmandPath(ResourceManager.BACKUP_PATH),BINARY_MAP_INDEX_EXT, files);
|
||||
listWithAlternatives(settings.extendOsmandPath(ResourceManager.APP_DIR),BINARY_MAP_INDEX_EXT, files);
|
||||
listWithAlternatives(settings.extendOsmandPath(ResourceManager.APP_DIR),EXTRA_EXT, files);
|
||||
listWithAlternatives(settings.extendOsmandPath(ResourceManager.VOICE_PATH),"", files);
|
||||
listWithAlternatives(settings.extendOsmandPath(ResourceManager.VOICE_PATH),"", files);
|
||||
return files;
|
||||
}
|
||||
|
||||
private Collection<? extends String> listWithAlternatives(File file, final String ext, final String downloadExt, final int version) {
|
||||
final List<String> files = new ArrayList<String>();
|
||||
public static Map<String, String> listWithAlternatives(File file, final String ext,
|
||||
final Map<String, String> files) {
|
||||
if (file.isDirectory()) {
|
||||
file.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String filename) {
|
||||
if (filename.endsWith(ext)) {
|
||||
files.add(filename);
|
||||
if (downloadExt != null) {
|
||||
files.add(filename.substring(0, filename.length() - ext.length()) + downloadExt);
|
||||
}
|
||||
String date = MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(new File(dir, filename).lastModified()));
|
||||
files.put(filename, date);
|
||||
// files.put(filename.substring(0, filename.length() - ext.length()) + downloadExt, date);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -482,14 +500,16 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
return files;
|
||||
}
|
||||
|
||||
protected void downloadFilesCheckFreeVersion() {
|
||||
if (Version.isFreeVersion(this)) {
|
||||
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get() + entriesToDownload.size();
|
||||
protected void downloadFilesCheckFreeVersion(List<DownloadEntry> list) {
|
||||
if (Version.isFreeVersion(this) ) {
|
||||
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||
boolean wiki = false;
|
||||
for (DownloadEntry es : entriesToDownload.values()) {
|
||||
for (DownloadEntry es : list) {
|
||||
if (es.baseName != null && es.baseName.contains("_wiki")) {
|
||||
wiki = true;
|
||||
break;
|
||||
} else if (es.type != DownloadActivityType.SRTM_FILE) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
|
||||
|
@ -499,16 +519,16 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
msg.setPositiveButton(R.string.default_buttons_ok, null);
|
||||
msg.show();
|
||||
} else {
|
||||
downloadFilesPreCheckSpace();
|
||||
downloadFilesPreCheckSpace( list);
|
||||
}
|
||||
} else {
|
||||
downloadFilesPreCheckSpace();
|
||||
downloadFilesPreCheckSpace( list);
|
||||
}
|
||||
}
|
||||
|
||||
protected void downloadFilesPreCheckSpace() {
|
||||
protected void downloadFilesPreCheckSpace(List<DownloadEntry> list) {
|
||||
double sz = 0;
|
||||
for(DownloadEntry es : entriesToDownload.values()){
|
||||
for(DownloadEntry es : list){
|
||||
sz += es.sizeMB;
|
||||
}
|
||||
// get availabile space
|
||||
|
@ -518,15 +538,15 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||
asz = (((long) fs.getAvailableBlocks()) * fs.getBlockSize()) / (1 << 20);
|
||||
}
|
||||
if(asz != -1 && asz < sz ){
|
||||
if(asz != -1 && asz < sz * 2 ){
|
||||
AccessibleToast.makeText(this, getString(R.string.download_files_not_enough_space, sz, asz), Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
if (asz > 0 && sz/asz > 0.8) {
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), entriesToDownload.size(), sz,
|
||||
if (asz > 0 && sz/asz > 0.4) {
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), list.size(), sz,
|
||||
asz));
|
||||
} else {
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question), entriesToDownload.size(), sz));
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question), list.size(), sz));
|
||||
}
|
||||
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -552,7 +572,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
downloadListIndexThread.setUiActivity(null);
|
||||
}
|
||||
|
||||
public class DownloadIndexesAsyncTask extends AsyncTask<String, Object, String> implements DownloadFileShowWarning {
|
||||
public class DownloadIndexesAsyncTask extends AsyncTask<IndexItem, Object, String> implements DownloadFileShowWarning {
|
||||
|
||||
private IProgress progress;
|
||||
private OsmandPreference<Integer> downloads;
|
||||
|
@ -611,23 +631,25 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... filesToDownload) {
|
||||
protected String doInBackground(IndexItem... filesToDownload) {
|
||||
try {
|
||||
List<File> filesToReindex = new ArrayList<File>();
|
||||
boolean forceWifi = DownloadIndexActivity.this.downloadFileHelper.isWifiConnected();
|
||||
for (int i = 0; i < filesToDownload.length; i++) {
|
||||
String filename = filesToDownload[i];
|
||||
DownloadEntry entry = DownloadIndexActivity.this.entriesToDownload.get(filename);
|
||||
if (entry != null) {
|
||||
IndexItem filename = filesToDownload[i];
|
||||
List<DownloadEntry> list = DownloadIndexActivity.this.entriesToDownload.get(filename);
|
||||
if (list != null) {
|
||||
String indexOfAllFiles = filesToDownload.length <= 1 ? "" : (" [" + (i + 1) + "/" + filesToDownload.length + "]");
|
||||
boolean result = downloadFile(entry, filename, filesToReindex, indexOfAllFiles, forceWifi);
|
||||
if (result) {
|
||||
DownloadIndexActivity.this.entriesToDownload.remove(filename);
|
||||
downloads.set(downloads.get() + 1);
|
||||
if (entry.existingBackupFile != null) {
|
||||
Algoritms.removeAllFiles(entry.existingBackupFile);
|
||||
for (DownloadEntry entry : list) {
|
||||
boolean result = downloadFile(entry, filesToReindex, indexOfAllFiles, forceWifi);
|
||||
if (result) {
|
||||
DownloadIndexActivity.this.entriesToDownload.remove(filename);
|
||||
downloads.set(downloads.get() + 1);
|
||||
if (entry.existingBackupFile != null) {
|
||||
Algoritms.removeAllFiles(entry.existingBackupFile);
|
||||
}
|
||||
publishProgress(entry);
|
||||
}
|
||||
publishProgress(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -664,7 +686,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
|
||||
}
|
||||
|
||||
public boolean downloadFile(DownloadEntry de, String filename, List<File> filesToReindex, String indexOfAllFiles, boolean forceWifi)
|
||||
public boolean downloadFile(DownloadEntry de, List<File> filesToReindex, String indexOfAllFiles, boolean forceWifi)
|
||||
throws InterruptedException {
|
||||
boolean res = false;
|
||||
if (de.isAsset) {
|
||||
|
@ -676,10 +698,10 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
log.error("Copy exception", e);
|
||||
}
|
||||
} else {
|
||||
res = downloadFileHelper.downloadFile(filename, de, progress, filesToReindex, indexOfAllFiles, this, forceWifi);
|
||||
res = downloadFileHelper.downloadFile(de, progress, filesToReindex, indexOfAllFiles, this, forceWifi);
|
||||
}
|
||||
if (res && de.attachedEntry != null) {
|
||||
return downloadFile(de.attachedEntry, filename, filesToReindex, indexOfAllFiles, forceWifi);
|
||||
return downloadFile(de.attachedEntry, filesToReindex, indexOfAllFiles, forceWifi);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
|
|||
import net.osmand.plus.voice.MediaCommandPlayerImpl;
|
||||
import net.osmand.plus.voice.TTSCommandPlayerImpl;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Build;
|
||||
|
||||
public class LocalIndexHelper {
|
||||
|
@ -69,9 +68,6 @@ public class LocalIndexHelper {
|
|||
File f = new File(info.getPathToData());
|
||||
if(info.getType() == LocalIndexType.MAP_DATA){
|
||||
updateObfFileInformation(info, f);
|
||||
} else if(info.getType() == LocalIndexType.POI_DATA){
|
||||
checkPoiFileVersion(info, f);
|
||||
info.setDescription(getInstalledDate(f));
|
||||
} else if(info.getType() == LocalIndexType.GPX_DATA){
|
||||
updateGpxInfo(info, f);
|
||||
} else if(info.getType() == LocalIndexType.VOICE_DATA){
|
||||
|
@ -214,8 +210,6 @@ public class LocalIndexHelper {
|
|||
loadObfData(settings.extendOsmandPath(ResourceManager.BACKUP_PATH), result, true, loadTask, loadedMaps);
|
||||
loadTilesData(settings.extendOsmandPath(ResourceManager.TILES_PATH), result, false, loadTask);
|
||||
loadTilesData(settings.extendOsmandPath(ResourceManager.BACKUP_PATH), result, false, loadTask);
|
||||
loadPoiData(settings.extendOsmandPath(ResourceManager.POI_PATH), result, false, loadTask);
|
||||
loadPoiData(settings.extendOsmandPath(ResourceManager.BACKUP_PATH), result, true, loadTask);
|
||||
loadVoiceData(settings.extendOsmandPath(ResourceManager.VOICE_PATH), result, false, loadTask);
|
||||
loadVoiceData(settings.extendOsmandPath(ResourceManager.BACKUP_PATH), result, true, loadTask);
|
||||
loadGPXData(settings.extendOsmandPath(ResourceManager.GPX_PATH), result, false, loadTask);
|
||||
|
@ -312,34 +306,7 @@ public class LocalIndexHelper {
|
|||
return listFiles;
|
||||
}
|
||||
|
||||
private void loadPoiData(File mapPath, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
|
||||
if (mapPath.canRead()) {
|
||||
for (File poiFile : listFilesSorted(mapPath)) {
|
||||
if (poiFile.isFile() && poiFile.getName().endsWith(IndexConstants.POI_INDEX_EXT)) {
|
||||
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.POI_DATA, poiFile, backup);
|
||||
if (!backup) {
|
||||
checkPoiFileVersion(info, poiFile);
|
||||
}
|
||||
result.add(info);
|
||||
loadTask.loadFile(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void checkPoiFileVersion(LocalIndexInfo info, File poiFile) {
|
||||
try {
|
||||
SQLiteDatabase db = SQLiteDatabase.openDatabase(poiFile.getPath(), null, SQLiteDatabase.OPEN_READONLY);
|
||||
int version = db.getVersion();
|
||||
info.setNotSupported(version != IndexConstants.POI_TABLE_VERSION);
|
||||
db.close();
|
||||
} catch(RuntimeException e){
|
||||
info.setCorrupted(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private MessageFormat format = new MessageFormat("\t {0}, {1} NE \n\t {2}, {3} NE", Locale.US);
|
||||
|
||||
|
@ -414,7 +381,6 @@ public class LocalIndexHelper {
|
|||
public enum LocalIndexType {
|
||||
MAP_DATA(R.string.local_indexes_cat_map),
|
||||
TILES_DATA(R.string.local_indexes_cat_tile),
|
||||
POI_DATA(R.string.local_indexes_cat_poi),
|
||||
VOICE_DATA(R.string.local_indexes_cat_voice),
|
||||
TTS_VOICE_DATA(R.string.local_indexes_cat_tts),
|
||||
GPX_DATA(R.string.local_indexes_cat_gpx);
|
||||
|
|
|
@ -187,7 +187,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
descriptionLoader = new LoadLocalIndexDescriptionTask();
|
||||
descriptionLoader.execute(info);
|
||||
}
|
||||
if(info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.POI_DATA){
|
||||
if(info.getType() == LocalIndexType.MAP_DATA){
|
||||
if(!info.isBackupedData()){
|
||||
menu.add(R.string.local_index_mi_backup);
|
||||
}
|
||||
|
@ -331,8 +331,6 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
parent = settings.extendOsmandPath(ResourceManager.GPX_PATH);
|
||||
} else if(i.getType() == LocalIndexType.MAP_DATA){
|
||||
parent = settings.extendOsmandPath(ResourceManager.MAPS_PATH);
|
||||
} else if(i.getType() == LocalIndexType.POI_DATA){
|
||||
parent = settings.extendOsmandPath(ResourceManager.POI_PATH);
|
||||
} else if(i.getType() == LocalIndexType.TILES_DATA){
|
||||
parent = settings.extendOsmandPath(ResourceManager.TILES_PATH);
|
||||
} else if(i.getType() == LocalIndexType.VOICE_DATA){
|
||||
|
@ -750,7 +748,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
openSelectionMode(R.string.local_index_mi_delete);
|
||||
} else if(item.getItemId() == R.string.local_index_mi_backup){
|
||||
listAdapter.filterCategories(false);
|
||||
listAdapter.filterCategories(LocalIndexType.MAP_DATA, LocalIndexType.POI_DATA);
|
||||
listAdapter.filterCategories(LocalIndexType.MAP_DATA);
|
||||
openSelectionMode(R.string.local_index_mi_backup);
|
||||
} else if(item.getItemId() == R.string.local_index_mi_restore){
|
||||
listAdapter.filterCategories(true);
|
||||
|
|
|
@ -135,7 +135,7 @@ public class SearchActivity extends TabActivity {
|
|||
|
||||
TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);
|
||||
tabs.setBackgroundResource(R.drawable.tab_icon_background);
|
||||
TabHost host = getTabHost();
|
||||
TabHost host = getTabHost();
|
||||
host.addTab(host.newTabSpec(SEARCH_POI).setIndicator(getTabIndicator(R.drawable.tab_search_poi_icon, R.string.poi)).
|
||||
setContent(new Intent(this, SearchPoiFilterActivity.class))); //$NON-NLS-1$
|
||||
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import static net.osmand.data.IndexConstants.EXTRA_EXT;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.osmand.plus.ClientContext;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.ResourceManager;
|
||||
import net.osmand.plus.activities.DownloadIndexActivity;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import android.graphics.Color;
|
||||
|
@ -42,8 +47,13 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
|||
}
|
||||
|
||||
public void updateLoadedFiles() {
|
||||
OsmandSettings settings = getMyApplication().getSettings();
|
||||
indexActivatedFileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
||||
DownloadIndexActivity.listWithAlternatives(settings.extendOsmandPath(ResourceManager.APP_DIR),
|
||||
EXTRA_EXT, indexActivatedFileNames);
|
||||
indexFileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
||||
DownloadIndexActivity.listWithAlternatives(settings.extendOsmandPath(ResourceManager.APP_DIR),
|
||||
EXTRA_EXT, indexFileNames);
|
||||
getMyApplication().getResourceManager().getBackupIndexes(indexFileNames);
|
||||
}
|
||||
|
||||
|
@ -75,6 +85,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
|||
return indexFiles;
|
||||
}
|
||||
|
||||
|
||||
public void setIndexFiles(List<IndexItem> indexFiles) {
|
||||
this.indexFiles.clear();
|
||||
for (IndexItem i : indexFiles) {
|
||||
|
@ -109,11 +120,12 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
|||
vars[i] = vars[i].trim().toLowerCase();
|
||||
}
|
||||
List<IndexItem> filter = new ArrayList<IndexItem>();
|
||||
ClientContext c = downloadActivity.getClientContext();
|
||||
for (IndexItem item : indexFiles) {
|
||||
boolean add = true;
|
||||
for (String var : vars) {
|
||||
if (var.length() > 0) {
|
||||
if (!item.getVisibleName().toLowerCase().contains(var)
|
||||
if (!item.getVisibleName(c).toLowerCase().contains(var)
|
||||
/*&& !item.getDescription().toLowerCase().contains(var)*/) {
|
||||
add = false;
|
||||
}
|
||||
|
@ -209,13 +221,14 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
|||
TextView item = (TextView) row.findViewById(R.id.download_item);
|
||||
TextView description = (TextView) row.findViewById(R.id.download_descr);
|
||||
IndexItem e = (IndexItem) getChild(groupPosition, childPosition);
|
||||
String eName = e.getVisibleDescription(downloadActivity.getClientContext()) + "\n" + e.getVisibleName();
|
||||
ClientContext clctx = downloadActivity.getClientContext();
|
||||
String eName = e.getVisibleDescription(clctx) + "\n" + e.getVisibleName(clctx);
|
||||
item.setText(eName.trim()); //$NON-NLS-1$
|
||||
String d = e.getDate() + "\n" + e.getSizeDescription();
|
||||
String d = e.getDate() + "\n" + e.getSizeDescription(clctx);
|
||||
description.setText(d.trim());
|
||||
|
||||
CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item);
|
||||
ch.setChecked(downloadActivity.getEntriesToDownload().containsKey(e.getFileName()));
|
||||
ch.setChecked(downloadActivity.getEntriesToDownload().containsKey(e));
|
||||
ch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -226,7 +239,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
|||
});
|
||||
|
||||
if (indexFileNames != null) {
|
||||
String sfName = e.convertServerFileNameToLocal();
|
||||
String sfName = e.getTargetFileName();
|
||||
if (!indexFileNames.containsKey(sfName)) {
|
||||
item.setTextColor(downloadActivity.getResources().getColor(R.color.index_unknown));
|
||||
item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.access.AccessibleToast;
|
||||
|
@ -50,9 +51,11 @@ public class DownloadIndexListThread extends Thread {
|
|||
public void run() {
|
||||
if (indexFiles != null) {
|
||||
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
|
||||
if (!basemapExists && indexFiles.getBasemap() != null) {
|
||||
uiActivity.getEntriesToDownload().put(indexFiles.getBasemap().getFileName(), indexFiles.getBasemap()
|
||||
.createDownloadEntry(uiActivity.getClientContext(), uiActivity.getType()));
|
||||
IndexItem basemap = indexFiles.getBasemap();
|
||||
if (!basemapExists && basemap != null) {
|
||||
List<DownloadEntry> downloadEntry = basemap
|
||||
.createDownloadEntry(uiActivity.getClientContext(), uiActivity.getType(), new ArrayList<DownloadEntry>());
|
||||
uiActivity.getEntriesToDownload().put(basemap, downloadEntry);
|
||||
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download, Toast.LENGTH_LONG).show();
|
||||
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.Version;
|
||||
|
@ -174,8 +175,9 @@ public class DownloadOsmandIndexesHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DownloadEntry createDownloadEntry(ClientContext ctx, DownloadActivityType type) {
|
||||
return new DownloadEntry(assetName, destFile, dateModified);
|
||||
public List<DownloadEntry> createDownloadEntry(ClientContext ctx, DownloadActivityType type, List<DownloadEntry> res) {
|
||||
res.add(new DownloadEntry(assetName, destFile, dateModified));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue