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 VOICE_VERSION = 0; //supported download versions
|
||||||
public final static int TTSVOICE_VERSION = 1; //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 VOICE_INDEX_DIR = "voice/"; //$NON-NLS-1$
|
||||||
public static final String RENDERERS_DIR = "rendering/"; //$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 final static String POI_TABLE = "poi"; //$NON-NLS-1$
|
||||||
|
|
||||||
public static final String INDEX_DOWNLOAD_DOMAIN = "download.osmand.net";
|
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;
|
package net.osmand.map;
|
||||||
|
|
||||||
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
import gnu.trove.list.array.TLongArrayList;
|
import gnu.trove.list.array.TLongArrayList;
|
||||||
import gnu.trove.set.hash.TLongHashSet;
|
import gnu.trove.set.hash.TLongHashSet;
|
||||||
|
|
||||||
|
@ -12,13 +13,12 @@ import net.osmand.osm.MapUtils;
|
||||||
|
|
||||||
public class RegionCountry {
|
public class RegionCountry {
|
||||||
public String continentName;
|
public String continentName;
|
||||||
public TLongArrayList tiles = new TLongArrayList();
|
public TIntArrayList tiles = new TIntArrayList();
|
||||||
public int left, right, top, bottom;
|
public int left, right, top, bottom;
|
||||||
public String name;
|
public String name;
|
||||||
public RegionCountry parent;
|
public RegionCountry parent;
|
||||||
|
|
||||||
private List<RegionCountry> regions = new ArrayList<RegionCountry>();
|
private List<RegionCountry> regions = new ArrayList<RegionCountry>();
|
||||||
private final static int SHIFT = 5;
|
|
||||||
|
|
||||||
public void add(int xdeg, int ydeg) {
|
public void add(int xdeg, int ydeg) {
|
||||||
if (tiles.size() == 0) {
|
if (tiles.size() == 0) {
|
||||||
|
@ -29,15 +29,20 @@ public class RegionCountry {
|
||||||
right = Math.max(xdeg, right);
|
right = Math.max(xdeg, right);
|
||||||
bottom = Math.min(ydeg, bottom);
|
bottom = Math.min(ydeg, bottom);
|
||||||
top = Math.max(ydeg, top);
|
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) {
|
public int getLon(int i) {
|
||||||
return (int) (tiles.get(i) >> SHIFT);
|
return tiles.get(i*2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLat(int i) {
|
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) {
|
public void addSubregion(RegionCountry c) {
|
||||||
|
@ -49,7 +54,7 @@ public class RegionCountry {
|
||||||
return regions;
|
return regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TLongHashSet calculateTileSet(TLongHashSet t, int z) {
|
/*public TLongHashSet calculateTileSet(TLongHashSet t, int z) {
|
||||||
for (int j = 0; j < tiles.size(); j++) {
|
for (int j = 0; j < tiles.size(); j++) {
|
||||||
int kx = (int) MapUtils.getTileNumberX(z, getLon(j));
|
int kx = (int) MapUtils.getTileNumberX(z, getLon(j));
|
||||||
int ex = (int) MapUtils.getTileNumberX(z, getLon(j) + 0.9999f);
|
int ex = (int) MapUtils.getTileNumberX(z, getLon(j) + 0.9999f);
|
||||||
|
@ -63,7 +68,7 @@ public class RegionCountry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public static RegionCountry construct(OsmAndRegion reg) {
|
public static RegionCountry construct(OsmAndRegion reg) {
|
||||||
RegionCountry rc = new RegionCountry();
|
RegionCountry rc = new RegionCountry();
|
||||||
|
@ -71,8 +76,12 @@ public class RegionCountry {
|
||||||
rc.continentName = reg.getContinentName();
|
rc.continentName = reg.getContinentName();
|
||||||
}
|
}
|
||||||
rc.name = reg.getName();
|
rc.name = reg.getName();
|
||||||
|
int px = 0;
|
||||||
|
int py = 0;
|
||||||
for (int i = 0; i < reg.getDegXCount(); i++) {
|
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++) {
|
for (int i = 0; i < reg.getSubregionsCount(); i++) {
|
||||||
rc.addSubregion(construct(reg.getSubregions(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());
|
// System.out.println(r.name + " " + r.tiles.size() + " ?= " + r.calculateTileSet(new TLongHashSet(), 8).size());
|
||||||
int px = 0;
|
int px = 0;
|
||||||
int py = 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.addDegX(this.getLon(i) - px);
|
||||||
reg.addDegY(this.getLat(i) - py);
|
reg.addDegY(this.getLat(i) - py);
|
||||||
px = this.getLon(i);
|
px = this.getLon(i);
|
||||||
|
|
|
@ -112,6 +112,9 @@ public class RegionsRegistryConverter {
|
||||||
InputStream in = RegionsRegistryConverter.class.getResourceAsStream(RegionRegistry.fileName);
|
InputStream in = RegionsRegistryConverter.class.getResourceAsStream(RegionRegistry.fileName);
|
||||||
OsmAndRegionInfo regInfo = OsmAndRegionInfo.newBuilder().mergeFrom(in).build();
|
OsmAndRegionInfo regInfo = OsmAndRegionInfo.newBuilder().mergeFrom(in).build();
|
||||||
t += System.currentTimeMillis();
|
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("Read countries " + regInfo.getRegionInfo().getRegionsCount() + " " + countries.size() );
|
||||||
System.out.println("Timing " + t);
|
System.out.println("Timing " + t);
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -16,9 +16,7 @@ public interface ClientContext {
|
||||||
|
|
||||||
public File getAppDir();
|
public File getAppDir();
|
||||||
|
|
||||||
public File getVoiceDir();
|
public File getAppDir(String extend);
|
||||||
|
|
||||||
public File getBackupDir();
|
|
||||||
|
|
||||||
public void showToastMessage(int msgId);
|
public void showToastMessage(int msgId);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package net.osmand.plus.download;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class DownloadEntry {
|
public class DownloadEntry {
|
||||||
public File fileToSave;
|
public File fileToSave;
|
||||||
public File fileToUnzip;
|
public File fileToUnzip;
|
||||||
|
@ -11,13 +10,14 @@ public class DownloadEntry {
|
||||||
public Long dateModified;
|
public Long dateModified;
|
||||||
public double sizeMB;
|
public double sizeMB;
|
||||||
public String baseName;
|
public String baseName;
|
||||||
|
public String urlToDownload;
|
||||||
public int parts;
|
public int parts;
|
||||||
public File existingBackupFile;
|
public File existingBackupFile;
|
||||||
public DownloadEntry attachedEntry;
|
|
||||||
public boolean isAsset;
|
public boolean isAsset;
|
||||||
public DownloadActivityType type;
|
public DownloadActivityType type;
|
||||||
|
|
||||||
public List<String> srtmFilesToDownload;
|
public List<String> srtmFilesToDownload;
|
||||||
|
public DownloadEntry attachedEntry;
|
||||||
|
|
||||||
public DownloadEntry() {
|
public DownloadEntry() {
|
||||||
// default
|
// default
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class DownloadFileHelper {
|
||||||
public void showWarning(String warning);
|
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 {
|
IProgress progress, boolean forceWifi) throws IOException, InterruptedException {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
byte[] buffer = new byte[BUFFER_SIZE];
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
|
@ -47,6 +47,7 @@ public class DownloadFileHelper {
|
||||||
int length = 0;
|
int length = 0;
|
||||||
int fileread = 0;
|
int fileread = 0;
|
||||||
int triesDownload = TRIES_TO_DOWNLOAD;
|
int triesDownload = TRIES_TO_DOWNLOAD;
|
||||||
|
boolean notFound = false;
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
try {
|
try {
|
||||||
while (triesDownload > 0) {
|
while (triesDownload > 0) {
|
||||||
|
@ -68,6 +69,10 @@ public class DownloadFileHelper {
|
||||||
conn.setConnectTimeout(30000);
|
conn.setConnectTimeout(30000);
|
||||||
log.info(conn.getResponseMessage() + " " + conn.getResponseCode()); //$NON-NLS-1$
|
log.info(conn.getResponseMessage() + " " + conn.getResponseCode()); //$NON-NLS-1$
|
||||||
boolean wifiConnectionBroken = forceWifi && !isWifiConnected();
|
boolean wifiConnectionBroken = forceWifi && !isWifiConnected();
|
||||||
|
if(conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND){
|
||||||
|
notFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if ((conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL &&
|
if ((conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL &&
|
||||||
conn.getResponseCode() != HttpURLConnection.HTTP_OK ) || wifiConnectionBroken) {
|
conn.getResponseCode() != HttpURLConnection.HTTP_OK ) || wifiConnectionBroken) {
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
|
@ -75,10 +80,6 @@ public class DownloadFileHelper {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
is = conn.getInputStream();
|
is = conn.getInputStream();
|
||||||
// long skipped = 0;
|
|
||||||
// while (skipped < fileread) {
|
|
||||||
// skipped += is.skip(fileread - skipped);
|
|
||||||
// }
|
|
||||||
if (first) {
|
if (first) {
|
||||||
length = conn.getContentLength();
|
length = conn.getContentLength();
|
||||||
String taskName = ctx.getString(R.string.downloading_file) + indexOfAllFiles +" " + fileName;
|
String taskName = ctx.getString(R.string.downloading_file) + indexOfAllFiles +" " + fileName;
|
||||||
|
@ -111,7 +112,9 @@ public class DownloadFileHelper {
|
||||||
is.close();
|
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$
|
throw new IOException("File was not fully read"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,53 +124,31 @@ public class DownloadFileHelper {
|
||||||
return ctx.isWifiConnected();
|
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,
|
List<File> toReIndex, String indexOfAllFiles,
|
||||||
DownloadFileShowWarning showWarningCallback, boolean forceWifi) throws InterruptedException {
|
DownloadFileShowWarning showWarningCallback, boolean forceWifi) throws InterruptedException {
|
||||||
try {
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
FileOutputStream out = new FileOutputStream(de.fileToSave);
|
FileOutputStream out = new FileOutputStream(de.fileToSave);
|
||||||
try {
|
try {
|
||||||
String urlPrefix = "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&file=";
|
log.info("Download " + de.urlToDownload);
|
||||||
|
|
||||||
if (de.type == DownloadActivityType.ROADS_FILE) {
|
|
||||||
urlSuffix += "&road=yes";
|
|
||||||
}
|
|
||||||
if (de.parts == 1) {
|
if (de.parts == 1) {
|
||||||
URL url = new URL(urlPrefix + fileName + urlSuffix); //$NON-NLS-1$
|
URL url = new URL(de.urlToDownload); //$NON-NLS-1$
|
||||||
downloadFile(fileName, out, url, null, indexOfAllFiles, progress, forceWifi);
|
downloadFileInternal(de.baseName, out, url, null, indexOfAllFiles, progress, forceWifi);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 1; i <= de.parts; i++) {
|
for (int i = 1; i <= de.parts; i++) {
|
||||||
URL url = new URL(urlPrefix + fileName + "-" + i + urlSuffix); //$NON-NLS-1$
|
URL url = new URL(de.urlToDownload); //$NON-NLS-1$
|
||||||
downloadFile(fileName, out, url, " [" + i + "/" + de.parts + "]", indexOfAllFiles, progress, forceWifi);
|
downloadFileInternal(de.baseName, out, url, " [" + i + "/" + de.parts + "]", indexOfAllFiles, progress, forceWifi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
unzipFile(de, progress, toReIndex);
|
unzipFile(de, progress, toReIndex);
|
||||||
}
|
|
||||||
showWarningCallback.showWarning(ctx.getString(R.string.download_index_success));
|
showWarningCallback.showWarning(ctx.getString(R.string.download_index_success));
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Exception ocurred", e); //$NON-NLS-1$
|
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
|
// Possibly file is corrupted
|
||||||
de.fileToSave.delete();
|
de.fileToSave.delete();
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,20 +1,26 @@
|
||||||
package net.osmand.plus.download;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
|
|
||||||
import net.osmand.LogUtil;
|
import net.osmand.LogUtil;
|
||||||
import net.osmand.data.IndexConstants;
|
import net.osmand.data.IndexConstants;
|
||||||
import net.osmand.plus.ClientContext;
|
import net.osmand.plus.ClientContext;
|
||||||
import net.osmand.plus.R;
|
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);
|
private static final Log log = LogUtil.getLog(IndexItem.class);
|
||||||
|
|
||||||
String description;
|
String description;
|
||||||
|
@ -56,7 +62,7 @@ public class IndexItem {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVisibleName() {
|
public String getVisibleName(ClientContext ctx) {
|
||||||
return getBasename().replace('_', ' ');
|
return getBasename().replace('_', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +107,7 @@ public class IndexItem {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSizeDescription() {
|
public String getSizeDescription(ClientContext ctx) {
|
||||||
return size + " MB";
|
return size + " MB";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +115,8 @@ public class IndexItem {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadEntry createDownloadEntry(ClientContext ctx, DownloadActivityType type) {
|
public List<DownloadEntry> createDownloadEntry(ClientContext ctx, DownloadActivityType type,
|
||||||
|
List<DownloadEntry> downloadEntries) {
|
||||||
String fileName = this.fileName;
|
String fileName = this.fileName;
|
||||||
File parent = null;
|
File parent = null;
|
||||||
String toSavePostfix = null;
|
String toSavePostfix = null;
|
||||||
|
@ -130,13 +137,13 @@ public class IndexItem {
|
||||||
toSavePostfix = IndexConstants.EXTRA_ZIP_EXT;
|
toSavePostfix = IndexConstants.EXTRA_ZIP_EXT;
|
||||||
toCheckPostfix = IndexConstants.EXTRA_EXT;
|
toCheckPostfix = IndexConstants.EXTRA_EXT;
|
||||||
} else if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
|
} else if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
|
||||||
parent = ctx.getVoiceDir();
|
parent = ctx.getAppDir(IndexConstants.VOICE_INDEX_DIR);
|
||||||
toSavePostfix = VOICE_INDEX_EXT_ZIP;
|
toSavePostfix = VOICE_INDEX_EXT_ZIP;
|
||||||
toCheckPostfix = ""; //$NON-NLS-1$
|
toCheckPostfix = ""; //$NON-NLS-1$
|
||||||
unzipDir = true;
|
unzipDir = true;
|
||||||
preventMediaIndexing = true;
|
preventMediaIndexing = true;
|
||||||
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
|
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
|
||||||
parent = ctx.getVoiceDir();
|
parent = ctx.getAppDir(IndexConstants.VOICE_INDEX_DIR);
|
||||||
toSavePostfix = TTSVOICE_INDEX_EXT_ZIP;
|
toSavePostfix = TTSVOICE_INDEX_EXT_ZIP;
|
||||||
toCheckPostfix = ""; //$NON-NLS-1$
|
toCheckPostfix = ""; //$NON-NLS-1$
|
||||||
unzipDir = true;
|
unzipDir = true;
|
||||||
|
@ -160,11 +167,16 @@ public class IndexItem {
|
||||||
final DownloadEntry entry;
|
final DownloadEntry entry;
|
||||||
if (parent == null || !parent.exists()) {
|
if (parent == null || !parent.exists()) {
|
||||||
ctx.showToastMessage(R.string.sd_dir_not_accessible);
|
ctx.showToastMessage(R.string.sd_dir_not_accessible);
|
||||||
entry = null;
|
|
||||||
} else {
|
} else {
|
||||||
entry = new DownloadEntry();
|
entry = new DownloadEntry();
|
||||||
entry.type = type;
|
entry.type = type;
|
||||||
entry.baseName = getBasename();
|
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.fileToSave = new File(parent, entry.baseName + toSavePostfix);
|
||||||
entry.unzip = unzipDir;
|
entry.unzip = unzipDir;
|
||||||
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
|
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
|
||||||
|
@ -184,32 +196,49 @@ public class IndexItem {
|
||||||
entry.parts = Integer.parseInt(parts);
|
entry.parts = Integer.parseInt(parts);
|
||||||
}
|
}
|
||||||
entry.fileToUnzip = new File(parent, entry.baseName + toCheckPostfix);
|
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()) {
|
if (backup.exists()) {
|
||||||
entry.existingBackupFile = backup;
|
entry.existingBackupFile = backup;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (attachedItem != null) {
|
if (attachedItem != null) {
|
||||||
entry.attachedEntry = attachedItem.createDownloadEntry(ctx, type);
|
ArrayList<DownloadEntry> sz = new ArrayList<DownloadEntry>();
|
||||||
|
attachedItem.createDownloadEntry(ctx, type, sz);
|
||||||
|
if(sz.size() > 0) {
|
||||||
|
entry.attachedEntry = sz.get(0);
|
||||||
}
|
}
|
||||||
return entry;
|
}
|
||||||
|
downloadEntries.add(entry);
|
||||||
|
}
|
||||||
|
return downloadEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String convertServerFileNameToLocal() {
|
public String getTargetFileName(){
|
||||||
String e = getFileName();
|
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)) {
|
if (e.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) || e.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
|
||||||
s = IndexConstants.BINARY_MAP_INDEX_EXT;
|
int l = e.lastIndexOf('_');
|
||||||
} else {
|
|
||||||
s = ""; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
if (getType() == DownloadActivityType.ROADS_FILE) {
|
|
||||||
s = "-roads" + s;
|
|
||||||
}
|
|
||||||
if(l == -1) {
|
if(l == -1) {
|
||||||
l = e.length();
|
l = e.length();
|
||||||
}
|
}
|
||||||
return e.substring(0, l) + s;
|
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 e;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(IndexItem another) {
|
||||||
|
if(another == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return getFileName().compareTo(another.getFileName());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,7 +1,14 @@
|
||||||
package net.osmand.plus.download;
|
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.map.RegionCountry;
|
||||||
import net.osmand.plus.ClientContext;
|
import net.osmand.plus.ClientContext;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -9,17 +16,46 @@ import net.osmand.plus.R;
|
||||||
public class SrtmIndexItem extends IndexItem {
|
public class SrtmIndexItem extends IndexItem {
|
||||||
|
|
||||||
private RegionCountry item;
|
private RegionCountry item;
|
||||||
public SrtmIndexItem(RegionCountry item) {
|
private List<String> tilesToDownload = new ArrayList<String>();
|
||||||
super(fileName(item), "Elevation lines", "", item.tiles.size()+"", null);
|
public SrtmIndexItem(RegionCountry item, Map<String, String> existingFileNames) {
|
||||||
|
super(fileName(item), "Elevation lines", "", item.getTileSize()+"", null);
|
||||||
this.item = item;
|
this.item = item;
|
||||||
type = DownloadActivityType.SRTM_FILE;
|
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) {
|
private static String fileName(RegionCountry r) {
|
||||||
if(r.parent == null) {
|
if(r.parent == null) {
|
||||||
return r.continentName + " " + r.name;
|
return (r.continentName + " " + r.name).trim();
|
||||||
} else {
|
} 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
|
@Override
|
||||||
public DownloadEntry createDownloadEntry(ClientContext ctx, DownloadActivityType type) {
|
public List<DownloadEntry> createDownloadEntry(ClientContext ctx, DownloadActivityType type,
|
||||||
File parent = ctx.getAppDir();
|
List<DownloadEntry> downloadEntries) {
|
||||||
final DownloadEntry entry;
|
File parent = ctx.getAppDir(IndexConstants.SRTM_INDEX_DIR);
|
||||||
|
parent.mkdirs();
|
||||||
|
List<DownloadEntry> toDownload = new ArrayList<DownloadEntry>();
|
||||||
if (parent == null || !parent.exists()) {
|
if (parent == null || !parent.exists()) {
|
||||||
ctx.showToastMessage(R.string.sd_dir_not_accessible);
|
ctx.showToastMessage(R.string.sd_dir_not_accessible);
|
||||||
entry = null;
|
|
||||||
} else {
|
} else {
|
||||||
entry = new DownloadEntry();
|
for (String fileToDownload : tilesToDownload) {
|
||||||
|
DownloadEntry entry = new DownloadEntry();
|
||||||
entry.type = type;
|
entry.type = type;
|
||||||
entry.baseName = getBasename();
|
entry.baseName = fileToDownload;
|
||||||
// entry.fileToSave = new File(parent, entry.baseName + toSavePostfix);
|
String url = "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN;
|
||||||
// entry.unzip = unzipDir;
|
//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.dateModified = System.currentTimeMillis();
|
||||||
entry.parts = Integer.parseInt(size);
|
entry.sizeMB = 20;
|
||||||
// entry.fileToUnzip = new File(parent, entry.baseName + toCheckPostfix);
|
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
|
@Override
|
||||||
public String convertServerFileNameToLocal() {
|
public String getTargetFileName() {
|
||||||
return fileName+".nonexistent";
|
return fileName+".nonexistent";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,16 +108,21 @@ public class SrtmIndexItem extends IndexItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSizeDescription() {
|
public String getSizeDescription(ClientContext ctx) {
|
||||||
return size + " parts";
|
return (item.getTileSize()-tilesToDownload.size()) + "/" + item.getTileSize() + " " + ctx.getString(R.string.index_srtm_parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if(item.parent == null) {
|
||||||
return item.name + "\n";
|
return item.name;
|
||||||
} else {
|
} 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).
|
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
|
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_description">SRTM plugin (TODO description)</string>
|
||||||
<string name="srtm_plugin_name">SRTM plugin</string>
|
<string name="srtm_plugin_name">SRTM plugin</string>
|
||||||
<string name="download_select_map_types">Other maps</string>
|
<string name="download_select_map_types">Other maps</string>
|
||||||
|
|
|
@ -47,14 +47,10 @@ public class AndroidClientContext implements ClientContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getVoiceDir() {
|
public File getAppDir(String extend) {
|
||||||
return app.getSettings().extendOsmandPath(ResourceManager.VOICE_PATH);
|
return app.getSettings().extendOsmandPath(ResourceManager.APP_DIR + extend);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public File getBackupDir() {
|
|
||||||
return app.getSettings().extendOsmandPath(ResourceManager.BACKUP_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showToastMessage(int msgId) {
|
public void showToastMessage(int msgId) {
|
||||||
|
|
|
@ -66,11 +66,11 @@ public abstract class OsmandPlugin {
|
||||||
installedPlugins.add(new OsmandBackgroundServicePlugin(app));
|
installedPlugins.add(new OsmandBackgroundServicePlugin(app));
|
||||||
installedPlugins.add(new OsmandExtraSettings(app));
|
installedPlugins.add(new OsmandExtraSettings(app));
|
||||||
installedPlugins.add(new AccessibilityPlugin(app));
|
installedPlugins.add(new AccessibilityPlugin(app));
|
||||||
installedPlugins.add(new OsmEditingPlugin(app));
|
|
||||||
installedPlugins.add(new OsmandDevelopmentPlugin(app));
|
|
||||||
installedPlugins.add(new SRTMPlugin(app));
|
installedPlugins.add(new SRTMPlugin(app));
|
||||||
installParkingPlugin(app);
|
installParkingPlugin(app);
|
||||||
installOsmodroidPlugin(app);
|
installOsmodroidPlugin(app);
|
||||||
|
installedPlugins.add(new OsmEditingPlugin(app));
|
||||||
|
installedPlugins.add(new OsmandDevelopmentPlugin(app));
|
||||||
|
|
||||||
Set<String> enabledPlugins = settings.getEnabledPlugins();
|
Set<String> enabledPlugins = settings.getEnabledPlugins();
|
||||||
for (OsmandPlugin plugin : installedPlugins) {
|
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 APP_DIR = "osmand/"; //$NON-NLS-1$
|
||||||
public static final String ROUTING_XML = APP_DIR + "routing.xml";
|
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 VOICE_PATH = APP_DIR + IndexConstants.VOICE_INDEX_DIR;
|
||||||
public static final String GPX_PATH = APP_DIR + "tracks";
|
public static final String GPX_PATH = APP_DIR + "tracks";
|
||||||
public static final String MAPS_PATH = APP_DIR;
|
public static final String MAPS_PATH = APP_DIR;
|
||||||
public static final String INDEXES_CACHE = APP_DIR + "ind.cache";
|
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 TILES_PATH = APP_DIR+"tiles/"; //$NON-NLS-1$
|
||||||
public static final String TEMP_SOURCE_TO_LOAD = "temp"; //$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$
|
public static final String VECTOR_MAP = "#vector_map"; //$NON-NLS-1$
|
||||||
|
@ -536,9 +536,26 @@ 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) {
|
public List<String> indexingMaps(final IProgress progress) {
|
||||||
File file = context.getSettings().extendOsmandPath(MAPS_PATH);
|
long val = System.currentTimeMillis();
|
||||||
file.mkdirs();
|
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>();
|
List<String> warnings = new ArrayList<String>();
|
||||||
renderer.clearAllResources();
|
renderer.clearAllResources();
|
||||||
CachedOsmandIndexes cachedOsmandIndexes = new CachedOsmandIndexes();
|
CachedOsmandIndexes cachedOsmandIndexes = new CachedOsmandIndexes();
|
||||||
|
@ -554,14 +571,7 @@ public class ResourceManager {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.exists() && file.canRead() ) {
|
for (File f : files) {
|
||||||
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$
|
progress.startTask(context.getString(R.string.indexing_map) + " " + f.getName(), -1); //$NON-NLS-1$
|
||||||
try {
|
try {
|
||||||
BinaryMapIndexReader index = null;
|
BinaryMapIndexReader index = null;
|
||||||
|
@ -628,13 +638,9 @@ public class ResourceManager {
|
||||||
log.error("Exception reading " + f.getAbsolutePath(), oome); //$NON-NLS-1$
|
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()));
|
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_big_for_memory), f.getName()));
|
||||||
}
|
}
|
||||||
} 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$
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
log.debug("All map files initialized " + (System.currentTimeMillis() - val) + " ms");
|
log.debug("All map files initialized " + (System.currentTimeMillis() - val) + " ms");
|
||||||
}
|
if (files.size() > 0 && (!indCache.exists() || indCache.canWrite())) {
|
||||||
if(!indCache.exists() || indCache.canWrite()){
|
|
||||||
try {
|
try {
|
||||||
cachedOsmandIndexes.writeToFile(indCache);
|
cachedOsmandIndexes.writeToFile(indCache);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -646,22 +652,11 @@ public class ResourceManager {
|
||||||
|
|
||||||
// POI INDEX //
|
// POI INDEX //
|
||||||
private List<String> indexingPoi(final IProgress progress) {
|
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);
|
File updatablePoiDbFile = context.getSettings().extendOsmandPath(MINE_POI_DB);
|
||||||
if(updatablePoiDbFile.exists() && updatablePoiDbFile.canRead()){
|
if(updatablePoiDbFile.exists() && updatablePoiDbFile.canRead()){
|
||||||
tryToOpenUpdatablePoiDb(updatablePoiDbFile);
|
tryToOpenUpdatablePoiDb(updatablePoiDbFile);
|
||||||
}
|
}
|
||||||
return warnings;
|
return new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AmenityIndexRepositoryOdb getUpdatablePoiDb() {
|
public AmenityIndexRepositoryOdb getUpdatablePoiDb() {
|
||||||
|
@ -692,19 +687,6 @@ public class ResourceManager {
|
||||||
return false;
|
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 ////////////////////////////////////////////////
|
////////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
|
||||||
public List<Amenity> searchAmenities(PoiFilter filter,
|
public List<Amenity> searchAmenities(PoiFilter filter,
|
||||||
|
|
|
@ -16,7 +16,9 @@ import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
@ -92,7 +94,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
|
|
||||||
private ProgressDialog progressFileDlg = null;
|
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 DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
|
||||||
|
|
||||||
private int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
|
private int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
|
||||||
|
@ -122,7 +124,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
downloadFilesCheckFreeVersion();
|
downloadFilesCheckFreeVersion(flattenDownloadEntries());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -171,6 +173,15 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
|
|
||||||
|
|
||||||
public void updateLoadedFiles() {
|
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) {
|
if(getExpandableListAdapter() != null) {
|
||||||
((DownloadIndexAdapter)getExpandableListAdapter()).updateLoadedFiles();
|
((DownloadIndexAdapter)getExpandableListAdapter()).updateLoadedFiles();
|
||||||
}
|
}
|
||||||
|
@ -199,7 +210,17 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
return type;
|
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;
|
return entriesToDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +239,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
IndexItem es = listAdapter.getChild(j, i);
|
IndexItem es = listAdapter.getChild(j, i);
|
||||||
if (!entriesToDownload.containsKey(es.getFileName())) {
|
if (!entriesToDownload.containsKey(es.getFileName())) {
|
||||||
selected++;
|
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);
|
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
} else if (item.getItemId() == FILTER_EXISTING_REGIONS) {
|
} 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>();
|
final List<IndexItem> filtered = new ArrayList<IndexItem>();
|
||||||
for (IndexItem fileItem : listAdapter.getIndexFiles()) {
|
for (IndexItem fileItem : listAdapter.getIndexFiles()) {
|
||||||
if (listAlreadyDownloaded.contains(fileItem.convertServerFileNameToLocal())) {
|
if (listAlreadyDownloaded.containsKey(fileItem.getTargetFileName())) {
|
||||||
filtered.add(fileItem);
|
filtered.add(fileItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,14 +316,15 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
public List<IndexItem> getFilteredByType() {
|
public List<IndexItem> getFilteredByType() {
|
||||||
final List<IndexItem> filtered = new ArrayList<IndexItem>();
|
final List<IndexItem> filtered = new ArrayList<IndexItem>();
|
||||||
if(type == DownloadActivityType.SRTM_FILE){
|
if(type == DownloadActivityType.SRTM_FILE){
|
||||||
|
Map<String, String> indexFileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
||||||
List<RegionCountry> countries = RegionRegistry.getRegionRegistry().getCountries();
|
List<RegionCountry> countries = RegionRegistry.getRegionRegistry().getCountries();
|
||||||
for(RegionCountry rc : countries){
|
for(RegionCountry rc : countries){
|
||||||
if(rc.tiles.size() > 50){
|
if(rc.tiles.size() > 50){
|
||||||
for(RegionCountry ch : rc.getSubRegions()) {
|
for(RegionCountry ch : rc.getSubRegions()) {
|
||||||
filtered.add(new SrtmIndexItem(ch));
|
filtered.add(new SrtmIndexItem(ch, indexFileNames));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filtered.add(new SrtmIndexItem(rc));
|
filtered.add(new SrtmIndexItem(rc, indexFileNames));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,7 +397,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case DIALOG_PROGRESS_FILE:
|
case DIALOG_PROGRESS_FILE:
|
||||||
DownloadIndexesAsyncTask task = new DownloadIndexesAsyncTask(new ProgressDialogImplementation(progressFileDlg,true));
|
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);
|
task.execute(indexes);
|
||||||
break;
|
break;
|
||||||
case DIALOG_PROGRESS_LIST:
|
case DIALOG_PROGRESS_LIST:
|
||||||
|
@ -418,12 +440,11 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
@Override
|
@Override
|
||||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||||
final IndexItem e = (IndexItem) ((DownloadIndexAdapter)getListAdapter()).getChild(groupPosition, childPosition);
|
final IndexItem e = (IndexItem) ((DownloadIndexAdapter)getListAdapter()).getChild(groupPosition, childPosition);
|
||||||
String key = e.getFileName();
|
|
||||||
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
|
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
|
||||||
|
|
||||||
if(ch.isChecked()){
|
if(ch.isChecked()){
|
||||||
ch.setChecked(!ch.isChecked());
|
ch.setChecked(!ch.isChecked());
|
||||||
entriesToDownload.remove(key);
|
entriesToDownload.remove(e);
|
||||||
if(entriesToDownload.isEmpty()){
|
if(entriesToDownload.isEmpty()){
|
||||||
int x = getListView().getScrollX();
|
int x = getListView().getScrollX();
|
||||||
int y = getListView().getScrollY();
|
int y = getListView().getScrollY();
|
||||||
|
@ -433,11 +454,11 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final DownloadEntry entry = e.createDownloadEntry(getClientContext(), type);
|
List<DownloadEntry> download = e.createDownloadEntry(getClientContext(), type, new ArrayList<DownloadEntry>());
|
||||||
if (entry != null) {
|
if (download.size() > 0) {
|
||||||
// if(!fileToUnzip.exists()){
|
// if(!fileToUnzip.exists()){
|
||||||
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
|
// 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 x = getListView().getScrollX();
|
||||||
int y = getListView().getScrollY();
|
int y = getListView().getScrollY();
|
||||||
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||||
|
@ -448,29 +469,26 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Set<String> listAlreadyDownloadedWithAlternatives() {
|
private Map<String, String> listAlreadyDownloadedWithAlternatives() {
|
||||||
Set<String> files = new TreeSet<String>();
|
Map<String, String> files = new TreeMap<String, String>();
|
||||||
File externalStorageDirectory = settings.getExternalStorageDirectory();
|
listWithAlternatives(settings.extendOsmandPath(ResourceManager.BACKUP_PATH),BINARY_MAP_INDEX_EXT, files);
|
||||||
// files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.POI_PATH),POI_INDEX_EXT,POI_INDEX_EXT_ZIP,POI_TABLE_VERSION));
|
listWithAlternatives(settings.extendOsmandPath(ResourceManager.APP_DIR),BINARY_MAP_INDEX_EXT, files);
|
||||||
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.APP_DIR),BINARY_MAP_INDEX_EXT,BINARY_MAP_INDEX_EXT_ZIP,BINARY_MAP_VERSION));
|
listWithAlternatives(settings.extendOsmandPath(ResourceManager.APP_DIR),EXTRA_EXT, files);
|
||||||
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.APP_DIR),EXTRA_EXT, EXTRA_ZIP_EXT,0));
|
listWithAlternatives(settings.extendOsmandPath(ResourceManager.VOICE_PATH),"", files);
|
||||||
files.addAll(listWithAlternatives(new File(externalStorageDirectory, ResourceManager.BACKUP_PATH),BINARY_MAP_INDEX_EXT,BINARY_MAP_INDEX_EXT_ZIP,BINARY_MAP_VERSION));
|
listWithAlternatives(settings.extendOsmandPath(ResourceManager.VOICE_PATH),"", files);
|
||||||
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));
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<? extends String> listWithAlternatives(File file, final String ext, final String downloadExt, final int version) {
|
public static Map<String, String> listWithAlternatives(File file, final String ext,
|
||||||
final List<String> files = new ArrayList<String>();
|
final Map<String, String> files) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
file.list(new FilenameFilter() {
|
file.list(new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File dir, String filename) {
|
public boolean accept(File dir, String filename) {
|
||||||
if (filename.endsWith(ext)) {
|
if (filename.endsWith(ext)) {
|
||||||
files.add(filename);
|
String date = MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(new File(dir, filename).lastModified()));
|
||||||
if (downloadExt != null) {
|
files.put(filename, date);
|
||||||
files.add(filename.substring(0, filename.length() - ext.length()) + downloadExt);
|
// files.put(filename.substring(0, filename.length() - ext.length()) + downloadExt, date);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -482,14 +500,16 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void downloadFilesCheckFreeVersion() {
|
protected void downloadFilesCheckFreeVersion(List<DownloadEntry> list) {
|
||||||
if (Version.isFreeVersion(this) ) {
|
if (Version.isFreeVersion(this) ) {
|
||||||
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get() + entriesToDownload.size();
|
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||||
boolean wiki = false;
|
boolean wiki = false;
|
||||||
for (DownloadEntry es : entriesToDownload.values()) {
|
for (DownloadEntry es : list) {
|
||||||
if (es.baseName != null && es.baseName.contains("_wiki")) {
|
if (es.baseName != null && es.baseName.contains("_wiki")) {
|
||||||
wiki = true;
|
wiki = true;
|
||||||
break;
|
break;
|
||||||
|
} else if (es.type != DownloadActivityType.SRTM_FILE) {
|
||||||
|
total++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
|
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.setPositiveButton(R.string.default_buttons_ok, null);
|
||||||
msg.show();
|
msg.show();
|
||||||
} else {
|
} else {
|
||||||
downloadFilesPreCheckSpace();
|
downloadFilesPreCheckSpace( list);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
downloadFilesPreCheckSpace();
|
downloadFilesPreCheckSpace( list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void downloadFilesPreCheckSpace() {
|
protected void downloadFilesPreCheckSpace(List<DownloadEntry> list) {
|
||||||
double sz = 0;
|
double sz = 0;
|
||||||
for(DownloadEntry es : entriesToDownload.values()){
|
for(DownloadEntry es : list){
|
||||||
sz += es.sizeMB;
|
sz += es.sizeMB;
|
||||||
}
|
}
|
||||||
// get availabile space
|
// get availabile space
|
||||||
|
@ -518,15 +538,15 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||||
asz = (((long) fs.getAvailableBlocks()) * fs.getBlockSize()) / (1 << 20);
|
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();
|
AccessibleToast.makeText(this, getString(R.string.download_files_not_enough_space, sz, asz), Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
Builder builder = new AlertDialog.Builder(this);
|
Builder builder = new AlertDialog.Builder(this);
|
||||||
if (asz > 0 && sz/asz > 0.8) {
|
if (asz > 0 && sz/asz > 0.4) {
|
||||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), entriesToDownload.size(), sz,
|
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), list.size(), sz,
|
||||||
asz));
|
asz));
|
||||||
} else {
|
} 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() {
|
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -552,7 +572,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
downloadListIndexThread.setUiActivity(null);
|
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 IProgress progress;
|
||||||
private OsmandPreference<Integer> downloads;
|
private OsmandPreference<Integer> downloads;
|
||||||
|
@ -611,16 +631,17 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(String... filesToDownload) {
|
protected String doInBackground(IndexItem... filesToDownload) {
|
||||||
try {
|
try {
|
||||||
List<File> filesToReindex = new ArrayList<File>();
|
List<File> filesToReindex = new ArrayList<File>();
|
||||||
boolean forceWifi = DownloadIndexActivity.this.downloadFileHelper.isWifiConnected();
|
boolean forceWifi = DownloadIndexActivity.this.downloadFileHelper.isWifiConnected();
|
||||||
for (int i = 0; i < filesToDownload.length; i++) {
|
for (int i = 0; i < filesToDownload.length; i++) {
|
||||||
String filename = filesToDownload[i];
|
IndexItem filename = filesToDownload[i];
|
||||||
DownloadEntry entry = DownloadIndexActivity.this.entriesToDownload.get(filename);
|
List<DownloadEntry> list = DownloadIndexActivity.this.entriesToDownload.get(filename);
|
||||||
if (entry != null) {
|
if (list != null) {
|
||||||
String indexOfAllFiles = filesToDownload.length <= 1 ? "" : (" [" + (i + 1) + "/" + filesToDownload.length + "]");
|
String indexOfAllFiles = filesToDownload.length <= 1 ? "" : (" [" + (i + 1) + "/" + filesToDownload.length + "]");
|
||||||
boolean result = downloadFile(entry, filename, filesToReindex, indexOfAllFiles, forceWifi);
|
for (DownloadEntry entry : list) {
|
||||||
|
boolean result = downloadFile(entry, filesToReindex, indexOfAllFiles, forceWifi);
|
||||||
if (result) {
|
if (result) {
|
||||||
DownloadIndexActivity.this.entriesToDownload.remove(filename);
|
DownloadIndexActivity.this.entriesToDownload.remove(filename);
|
||||||
downloads.set(downloads.get() + 1);
|
downloads.set(downloads.get() + 1);
|
||||||
|
@ -631,6 +652,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
boolean vectorMapsToReindex = false;
|
boolean vectorMapsToReindex = false;
|
||||||
for (File f : filesToReindex) {
|
for (File f : filesToReindex) {
|
||||||
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||||
|
@ -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 {
|
throws InterruptedException {
|
||||||
boolean res = false;
|
boolean res = false;
|
||||||
if (de.isAsset) {
|
if (de.isAsset) {
|
||||||
|
@ -676,10 +698,10 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
||||||
log.error("Copy exception", e);
|
log.error("Copy exception", e);
|
||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
if (res && de.attachedEntry != null) {
|
||||||
return downloadFile(de.attachedEntry, filename, filesToReindex, indexOfAllFiles, forceWifi);
|
return downloadFile(de.attachedEntry, filesToReindex, indexOfAllFiles, forceWifi);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
|
||||||
import net.osmand.plus.voice.MediaCommandPlayerImpl;
|
import net.osmand.plus.voice.MediaCommandPlayerImpl;
|
||||||
import net.osmand.plus.voice.TTSCommandPlayerImpl;
|
import net.osmand.plus.voice.TTSCommandPlayerImpl;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
public class LocalIndexHelper {
|
public class LocalIndexHelper {
|
||||||
|
@ -69,9 +68,6 @@ public class LocalIndexHelper {
|
||||||
File f = new File(info.getPathToData());
|
File f = new File(info.getPathToData());
|
||||||
if(info.getType() == LocalIndexType.MAP_DATA){
|
if(info.getType() == LocalIndexType.MAP_DATA){
|
||||||
updateObfFileInformation(info, f);
|
updateObfFileInformation(info, f);
|
||||||
} else if(info.getType() == LocalIndexType.POI_DATA){
|
|
||||||
checkPoiFileVersion(info, f);
|
|
||||||
info.setDescription(getInstalledDate(f));
|
|
||||||
} else if(info.getType() == LocalIndexType.GPX_DATA){
|
} else if(info.getType() == LocalIndexType.GPX_DATA){
|
||||||
updateGpxInfo(info, f);
|
updateGpxInfo(info, f);
|
||||||
} else if(info.getType() == LocalIndexType.VOICE_DATA){
|
} else if(info.getType() == LocalIndexType.VOICE_DATA){
|
||||||
|
@ -214,8 +210,6 @@ public class LocalIndexHelper {
|
||||||
loadObfData(settings.extendOsmandPath(ResourceManager.BACKUP_PATH), result, true, loadTask, loadedMaps);
|
loadObfData(settings.extendOsmandPath(ResourceManager.BACKUP_PATH), result, true, loadTask, loadedMaps);
|
||||||
loadTilesData(settings.extendOsmandPath(ResourceManager.TILES_PATH), result, false, loadTask);
|
loadTilesData(settings.extendOsmandPath(ResourceManager.TILES_PATH), result, false, loadTask);
|
||||||
loadTilesData(settings.extendOsmandPath(ResourceManager.BACKUP_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.VOICE_PATH), result, false, loadTask);
|
||||||
loadVoiceData(settings.extendOsmandPath(ResourceManager.BACKUP_PATH), result, true, loadTask);
|
loadVoiceData(settings.extendOsmandPath(ResourceManager.BACKUP_PATH), result, true, loadTask);
|
||||||
loadGPXData(settings.extendOsmandPath(ResourceManager.GPX_PATH), result, false, loadTask);
|
loadGPXData(settings.extendOsmandPath(ResourceManager.GPX_PATH), result, false, loadTask);
|
||||||
|
@ -312,35 +306,8 @@ public class LocalIndexHelper {
|
||||||
return listFiles;
|
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);
|
private MessageFormat format = new MessageFormat("\t {0}, {1} NE \n\t {2}, {3} NE", Locale.US);
|
||||||
|
|
||||||
private String formatLatLonBox(int left, int right, int top, int bottom) {
|
private String formatLatLonBox(int left, int right, int top, int bottom) {
|
||||||
|
@ -414,7 +381,6 @@ public class LocalIndexHelper {
|
||||||
public enum LocalIndexType {
|
public enum LocalIndexType {
|
||||||
MAP_DATA(R.string.local_indexes_cat_map),
|
MAP_DATA(R.string.local_indexes_cat_map),
|
||||||
TILES_DATA(R.string.local_indexes_cat_tile),
|
TILES_DATA(R.string.local_indexes_cat_tile),
|
||||||
POI_DATA(R.string.local_indexes_cat_poi),
|
|
||||||
VOICE_DATA(R.string.local_indexes_cat_voice),
|
VOICE_DATA(R.string.local_indexes_cat_voice),
|
||||||
TTS_VOICE_DATA(R.string.local_indexes_cat_tts),
|
TTS_VOICE_DATA(R.string.local_indexes_cat_tts),
|
||||||
GPX_DATA(R.string.local_indexes_cat_gpx);
|
GPX_DATA(R.string.local_indexes_cat_gpx);
|
||||||
|
|
|
@ -187,7 +187,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
descriptionLoader = new LoadLocalIndexDescriptionTask();
|
descriptionLoader = new LoadLocalIndexDescriptionTask();
|
||||||
descriptionLoader.execute(info);
|
descriptionLoader.execute(info);
|
||||||
}
|
}
|
||||||
if(info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.POI_DATA){
|
if(info.getType() == LocalIndexType.MAP_DATA){
|
||||||
if(!info.isBackupedData()){
|
if(!info.isBackupedData()){
|
||||||
menu.add(R.string.local_index_mi_backup);
|
menu.add(R.string.local_index_mi_backup);
|
||||||
}
|
}
|
||||||
|
@ -331,8 +331,6 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
parent = settings.extendOsmandPath(ResourceManager.GPX_PATH);
|
parent = settings.extendOsmandPath(ResourceManager.GPX_PATH);
|
||||||
} else if(i.getType() == LocalIndexType.MAP_DATA){
|
} else if(i.getType() == LocalIndexType.MAP_DATA){
|
||||||
parent = settings.extendOsmandPath(ResourceManager.MAPS_PATH);
|
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){
|
} else if(i.getType() == LocalIndexType.TILES_DATA){
|
||||||
parent = settings.extendOsmandPath(ResourceManager.TILES_PATH);
|
parent = settings.extendOsmandPath(ResourceManager.TILES_PATH);
|
||||||
} else if(i.getType() == LocalIndexType.VOICE_DATA){
|
} else if(i.getType() == LocalIndexType.VOICE_DATA){
|
||||||
|
@ -750,7 +748,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
openSelectionMode(R.string.local_index_mi_delete);
|
openSelectionMode(R.string.local_index_mi_delete);
|
||||||
} else if(item.getItemId() == R.string.local_index_mi_backup){
|
} else if(item.getItemId() == R.string.local_index_mi_backup){
|
||||||
listAdapter.filterCategories(false);
|
listAdapter.filterCategories(false);
|
||||||
listAdapter.filterCategories(LocalIndexType.MAP_DATA, LocalIndexType.POI_DATA);
|
listAdapter.filterCategories(LocalIndexType.MAP_DATA);
|
||||||
openSelectionMode(R.string.local_index_mi_backup);
|
openSelectionMode(R.string.local_index_mi_backup);
|
||||||
} else if(item.getItemId() == R.string.local_index_mi_restore){
|
} else if(item.getItemId() == R.string.local_index_mi_restore){
|
||||||
listAdapter.filterCategories(true);
|
listAdapter.filterCategories(true);
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
package net.osmand.plus.download;
|
package net.osmand.plus.download;
|
||||||
|
|
||||||
|
import static net.osmand.data.IndexConstants.EXTRA_EXT;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.osmand.plus.ClientContext;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.ResourceManager;
|
||||||
import net.osmand.plus.activities.DownloadIndexActivity;
|
import net.osmand.plus.activities.DownloadIndexActivity;
|
||||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
@ -42,8 +47,13 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLoadedFiles() {
|
public void updateLoadedFiles() {
|
||||||
|
OsmandSettings settings = getMyApplication().getSettings();
|
||||||
indexActivatedFileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
indexActivatedFileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
||||||
|
DownloadIndexActivity.listWithAlternatives(settings.extendOsmandPath(ResourceManager.APP_DIR),
|
||||||
|
EXTRA_EXT, indexActivatedFileNames);
|
||||||
indexFileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
indexFileNames = getMyApplication().getResourceManager().getIndexFileNames();
|
||||||
|
DownloadIndexActivity.listWithAlternatives(settings.extendOsmandPath(ResourceManager.APP_DIR),
|
||||||
|
EXTRA_EXT, indexFileNames);
|
||||||
getMyApplication().getResourceManager().getBackupIndexes(indexFileNames);
|
getMyApplication().getResourceManager().getBackupIndexes(indexFileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +85,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
||||||
return indexFiles;
|
return indexFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setIndexFiles(List<IndexItem> indexFiles) {
|
public void setIndexFiles(List<IndexItem> indexFiles) {
|
||||||
this.indexFiles.clear();
|
this.indexFiles.clear();
|
||||||
for (IndexItem i : indexFiles) {
|
for (IndexItem i : indexFiles) {
|
||||||
|
@ -109,11 +120,12 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
||||||
vars[i] = vars[i].trim().toLowerCase();
|
vars[i] = vars[i].trim().toLowerCase();
|
||||||
}
|
}
|
||||||
List<IndexItem> filter = new ArrayList<IndexItem>();
|
List<IndexItem> filter = new ArrayList<IndexItem>();
|
||||||
|
ClientContext c = downloadActivity.getClientContext();
|
||||||
for (IndexItem item : indexFiles) {
|
for (IndexItem item : indexFiles) {
|
||||||
boolean add = true;
|
boolean add = true;
|
||||||
for (String var : vars) {
|
for (String var : vars) {
|
||||||
if (var.length() > 0) {
|
if (var.length() > 0) {
|
||||||
if (!item.getVisibleName().toLowerCase().contains(var)
|
if (!item.getVisibleName(c).toLowerCase().contains(var)
|
||||||
/*&& !item.getDescription().toLowerCase().contains(var)*/) {
|
/*&& !item.getDescription().toLowerCase().contains(var)*/) {
|
||||||
add = false;
|
add = false;
|
||||||
}
|
}
|
||||||
|
@ -209,13 +221,14 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
||||||
TextView item = (TextView) row.findViewById(R.id.download_item);
|
TextView item = (TextView) row.findViewById(R.id.download_item);
|
||||||
TextView description = (TextView) row.findViewById(R.id.download_descr);
|
TextView description = (TextView) row.findViewById(R.id.download_descr);
|
||||||
IndexItem e = (IndexItem) getChild(groupPosition, childPosition);
|
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$
|
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());
|
description.setText(d.trim());
|
||||||
|
|
||||||
CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item);
|
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() {
|
ch.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -226,7 +239,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
|
||||||
});
|
});
|
||||||
|
|
||||||
if (indexFileNames != null) {
|
if (indexFileNames != null) {
|
||||||
String sfName = e.convertServerFileNameToLocal();
|
String sfName = e.getTargetFileName();
|
||||||
if (!indexFileNames.containsKey(sfName)) {
|
if (!indexFileNames.containsKey(sfName)) {
|
||||||
item.setTextColor(downloadActivity.getResources().getColor(R.color.index_unknown));
|
item.setTextColor(downloadActivity.getResources().getColor(R.color.index_unknown));
|
||||||
item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
|
item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.osmand.plus.download;
|
package net.osmand.plus.download;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
|
@ -50,9 +51,11 @@ public class DownloadIndexListThread extends Thread {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (indexFiles != null) {
|
if (indexFiles != null) {
|
||||||
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
|
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
|
||||||
if (!basemapExists && indexFiles.getBasemap() != null) {
|
IndexItem basemap = indexFiles.getBasemap();
|
||||||
uiActivity.getEntriesToDownload().put(indexFiles.getBasemap().getFileName(), indexFiles.getBasemap()
|
if (!basemapExists && basemap != null) {
|
||||||
.createDownloadEntry(uiActivity.getClientContext(), uiActivity.getType()));
|
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();
|
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download, Toast.LENGTH_LONG).show();
|
||||||
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.osmand.LogUtil;
|
import net.osmand.LogUtil;
|
||||||
import net.osmand.Version;
|
import net.osmand.Version;
|
||||||
|
@ -174,8 +175,9 @@ public class DownloadOsmandIndexesHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DownloadEntry createDownloadEntry(ClientContext ctx, DownloadActivityType type) {
|
public List<DownloadEntry> createDownloadEntry(ClientContext ctx, DownloadActivityType type, List<DownloadEntry> res) {
|
||||||
return new DownloadEntry(assetName, destFile, dateModified);
|
res.add(new DownloadEntry(assetName, destFile, dateModified));
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue