Add osmodroid plugin (todo description)

This commit is contained in:
Victor Shcherb 2012-12-03 22:51:59 +01:00
parent 0ccdd89b96
commit d0b5ea3240
25 changed files with 11544 additions and 414 deletions

View file

@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="icons"/>
<classpathentry kind="src" path="src-tests"/>
<classpathentry excluding="com/OsMoDroid/" kind="src" path="gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/bzip2-20090327.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>

View file

@ -20,4 +20,11 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
<linkedResources>
<link>
<name>gen</name>
<type>2</type>
<locationURI>OSMAND_TRUNK/OsmAnd/gen</locationURI>
</link>
</linkedResources>
</projectDescription>

File diff suppressed because one or more lines are too long

View file

@ -32,4 +32,6 @@ public class IndexConstants {
public final static String POI_TABLE = "poi"; //$NON-NLS-1$
public static final String INDEX_DOWNLOAD_DOMAIN = "download.osmand.net";
}

View file

@ -0,0 +1,26 @@
package net.osmand.plus;
import java.io.File;
public interface ClientContext {
public String getFullVersion();
public boolean isWifiConnected();
public String getVersionAsURLParam();
public String getString(int resId);
public File getAppDir();
public File getVoiceDir();
public File getBackupDir();
public void showToastMessage(int msgId);
}

View file

@ -0,0 +1,5 @@
package net.osmand.plus.download;
public enum DownloadActivityType {
NORMAL_FILE, ROADS_FILE, SRTM_FILE
}

View file

@ -0,0 +1,33 @@
package net.osmand.plus.download;
import java.io.File;
import java.util.List;
public class DownloadEntry {
public File fileToSave;
public File fileToUnzip;
public boolean unzip;
public Long dateModified;
public double sizeMB;
public String baseName;
public int parts;
public File existingBackupFile;
public DownloadEntry attachedEntry;
public boolean isAsset;
public DownloadActivityType type;
public List<String> srtmFilesToDownload;
public DownloadEntry() {
// default
}
public DownloadEntry(String assetName, String fileName, long dateModified) {
this.dateModified = dateModified;
fileToUnzip = new File(fileName);
fileToSave = new File(assetName);
isAsset = true;
}
}

View file

@ -0,0 +1,336 @@
package net.osmand.plus.download;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.osmand.IProgress;
import net.osmand.LogUtil;
import net.osmand.data.IndexConstants;
import net.osmand.plus.ClientContext;
import net.osmand.plus.R;
import org.apache.commons.logging.Log;
public class DownloadFileHelper {
private final static Log log = LogUtil.getLog(DownloadFileHelper.class);
private static final int BUFFER_SIZE = 32256;
protected final int TRIES_TO_DOWNLOAD = 15;
protected final long TIMEOUT_BETWEEN_DOWNLOADS = 8000;
private final ClientContext ctx;
private boolean interruptDownloading = false;
public DownloadFileHelper(ClientContext ctx){
this.ctx = ctx;
}
public interface DownloadFileShowWarning {
public void showWarning(String warning);
}
protected void downloadFile(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];
int read = 0;
int length = 0;
int fileread = 0;
int triesDownload = TRIES_TO_DOWNLOAD;
boolean first = true;
try {
while (triesDownload > 0) {
try {
if (!first) {
log.info("Reconnecting"); //$NON-NLS-1$
try {
Thread.sleep(TIMEOUT_BETWEEN_DOWNLOADS);
} catch (InterruptedException e) {
}
}
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", ctx.getFullVersion()); //$NON-NLS-1$
conn.setReadTimeout(30000);
if (fileread > 0) {
String range = "bytes="+fileread + "-" + (length -1); //$NON-NLS-1$ //$NON-NLS-2$
conn.setRequestProperty("Range", range); //$NON-NLS-1$
}
conn.setConnectTimeout(30000);
log.info(conn.getResponseMessage() + " " + conn.getResponseCode()); //$NON-NLS-1$
boolean wifiConnectionBroken = forceWifi && !isWifiConnected();
if ((conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL &&
conn.getResponseCode() != HttpURLConnection.HTTP_OK ) || wifiConnectionBroken) {
conn.disconnect();
triesDownload--;
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;
if(part != null){
taskName += part;
}
progress.startTask(taskName, length / 1024); //$NON-NLS-1$
}
first = false;
while ((read = is.read(buffer)) != -1) {
if(interruptDownloading){
throw new InterruptedException();
}
out.write(buffer, 0, read);
fileread += read;
progress.remaining((length - fileread) / 1024);
}
if(length <= fileread){
triesDownload = 0;
}
} catch (IOException e) {
log.error("IOException", e); //$NON-NLS-1$
triesDownload--;
}
}
} finally {
if (is != null) {
is.close();
}
}
if(length != fileread || length == 0){
throw new IOException("File was not fully read"); //$NON-NLS-1$
}
}
public boolean isWifiConnected(){
return ctx.isWifiConnected();
}
public boolean downloadFile(final String fileName, 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();
}
}
}
} 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);
}
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));
// Possibly file is corrupted
de.fileToSave.delete();
return false;
} catch (InterruptedException e) {
// Possibly file is corrupted
de.fileToSave.delete();
throw e;
}
}
private void unzipFile(DownloadEntry de, IProgress progress, List<File> toReIndex)
throws FileNotFoundException, IOException {
if (de.fileToSave.getName().endsWith(".zip")) { //$NON-NLS-1$
if (de.unzip) {
de.fileToUnzip.mkdirs();
}
CountingInputStream fin = new CountingInputStream(new FileInputStream(de.fileToSave));
ZipInputStream zipIn = new ZipInputStream(fin);
ZipEntry entry = null;
boolean first = true;
int len = (int) de.fileToSave.length();
progress.startTask(ctx.getString(R.string.unzipping_file), len / 1024);
while ((entry = zipIn.getNextEntry()) != null) {
if (entry.isDirectory() || entry.getName().endsWith(IndexConstants.GEN_LOG_EXT)) {
continue;
}
File fs;
if (!de.unzip) {
if (first) {
fs = de.fileToUnzip;
first = false;
} else {
String name = entry.getName();
// small simplification
int ind = name.lastIndexOf('_');
if (ind > 0) {
// cut version
int i = name.indexOf('.', ind);
if (i > 0) {
name = name.substring(0, ind) + name.substring(i, name.length());
}
}
fs = new File(de.fileToUnzip.getParent(), name);
}
} else {
fs = new File(de.fileToUnzip, entry.getName());
}
FileOutputStream out = new FileOutputStream(fs);
int read;
byte[] buffer = new byte[BUFFER_SIZE];
int remaining = len;
while ((read = zipIn.read(buffer)) != -1) {
out.write(buffer, 0, read);
remaining -= fin.lastReadCount();
progress.remaining(remaining / 1024);
}
out.close();
if (de.dateModified != null) {
fs.setLastModified(de.dateModified);
}
toReIndex.add(fs);
}
zipIn.close();
de.fileToSave.delete(); // zip is no needed more
}
}
public void setInterruptDownloading(boolean interruptDownloading) {
this.interruptDownloading = interruptDownloading;
}
public boolean isInterruptDownloading() {
return interruptDownloading;
}
private static class CountingInputStream extends InputStream {
private final InputStream delegate;
private int count;
public CountingInputStream(InputStream delegate) {
this.delegate = delegate;
}
public int lastReadCount() {
int last = count;
count = 0;
return last;
}
@Override
public int available() throws IOException {
return delegate.available();
}
@Override
public void close() throws IOException {
delegate.close();
}
@Override
public boolean equals(Object o) {
return delegate.equals(o);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
@Override
public void mark(int readlimit) {
delegate.mark(readlimit);
}
@Override
public boolean markSupported() {
return delegate.markSupported();
}
@Override
public int read() throws IOException {
int read = delegate.read();
if (read > 0) {
this.count++;;
}
return read;
}
@Override
public int read(byte[] buffer, int offset, int length)
throws IOException {
int read = delegate.read(buffer, offset, length);
if (read > 0) {
this.count += read;
}
return read;
}
@Override
public int read(byte[] buffer) throws IOException {
int read = delegate.read(buffer);
if (read > 0) {
this.count += read;
}
return read;
}
@Override
public void reset() throws IOException {
delegate.reset();
}
@Override
public long skip(long byteCount) throws IOException {
return delegate.skip(byteCount);
}
@Override
public String toString() {
return delegate.toString();
}
}
}

View file

@ -0,0 +1,92 @@
package net.osmand.plus.download;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import net.osmand.data.IndexConstants;
public class IndexFileList implements Serializable {
private static final long serialVersionUID = 1L;
private boolean downloadedFromInternet = false;
IndexItem basemap;
ArrayList<IndexItem> indexFiles = new ArrayList<IndexItem>();
private String mapversion;
private Comparator<IndexItem> comparator = new Comparator<IndexItem>(){
@Override
public int compare(IndexItem o1, IndexItem o2) {
String object1 = o1.getFileName();
String object2 = o2.getFileName();
if(object1.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
return object1.compareTo(object2);
} else {
return -1;
}
} else if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
return 1;
}
return object1.compareTo(object2);
}
};
public void setDownloadedFromInternet(boolean downloadedFromInternet) {
this.downloadedFromInternet = downloadedFromInternet;
}
public boolean isDownloadedFromInternet() {
return downloadedFromInternet;
}
public void setMapVersion(String mapversion) {
this.mapversion = mapversion;
}
public void add(IndexItem indexItem) {
if (indexItem.isAccepted()) {
indexFiles.add(indexItem);
}
if(indexItem.getFileName().toLowerCase().startsWith("world_basemap")) {
basemap = indexItem;
}
}
public void sort(){
Collections.sort(indexFiles, comparator);
}
public boolean isAcceptable() {
return (indexFiles != null && !indexFiles.isEmpty()) || (mapversion != null);
}
public List<IndexItem> getIndexFiles() {
return indexFiles;
}
public IndexItem getBasemap() {
return basemap;
}
public boolean isIncreasedMapVersion() {
try {
int mapVersionInList = Integer.parseInt(mapversion);
return IndexConstants.BINARY_MAP_VERSION < mapVersionInList;
} catch (NumberFormatException e) {
//ignore this...
}
return false;
}
public IndexItem getIndexFilesByName(String key) {
for(IndexItem i : indexFiles) {
if(i.getFileName().equals(key)) {
return i;
}
}
return null;
}
}

View file

@ -0,0 +1,208 @@
package net.osmand.plus.download;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.logging.Log;
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 {
private static final Log log = LogUtil.getLog(IndexItem.class);
String description;
String date;
String parts;
String fileName;
String size;
IndexItem attachedItem;
DownloadActivityType type;
public IndexItem(String fileName, String description, String date, String size, String parts) {
this.fileName = fileName;
this.description = description;
this.date = date;
this.size = size;
this.parts = parts;
this.type = DownloadActivityType.NORMAL_FILE;
}
public DownloadActivityType getType() {
return type;
}
public void setType(DownloadActivityType type) {
this.type = type;
}
public String getVisibleDescription(ClientContext ctx, DownloadActivityType type) {
String s = ""; //$NON-NLS-1$
if (type == DownloadActivityType.ROADS_FILE) {
return ctx.getString(R.string.download_roads_only_item);
}
if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) || fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
} else if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
s = ctx.getString(R.string.voice);
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
s = ctx.getString(R.string.ttsvoice);
}
return s;
}
public String getVisibleName() {
return getBasename().replace('_', ' ');
}
public String getBasename() {
if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length());
}
int ls = fileName.lastIndexOf('_');
if (ls >= 0) {
return fileName.substring(0, ls);
}
return fileName;
}
public boolean isAccepted() {
// POI index download is not supported any longer
if (fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT, IndexConstants.BINARY_MAP_VERSION)) //
|| fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)) //
|| fileName.endsWith(addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION))
|| fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)
// || fileName.endsWith(addVersionToExt(IndexConstants.TTSVOICE_INDEX_EXT_ZIP, IndexConstants.TTSVOICE_VERSION)) drop support for
// downloading tts files from inet
) {
return true;
}
return false;
}
protected static String addVersionToExt(String ext, int version) {
return "_" + version + ext;
}
public String getFileName() {
return fileName;
}
public String getDescription() {
return description;
}
public String getDate() {
return date;
}
public String getSize() {
return size;
}
public DownloadEntry createDownloadEntry(ClientContext ctx, DownloadActivityType type) {
String fileName = this.fileName;
File parent = null;
String toSavePostfix = null;
String toCheckPostfix = null;
boolean unzipDir = false;
boolean preventMediaIndexing = false;
if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
parent = ctx.getAppDir();
toSavePostfix = BINARY_MAP_INDEX_EXT;
toCheckPostfix = BINARY_MAP_INDEX_EXT;
} else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
parent = ctx.getAppDir();
toSavePostfix = BINARY_MAP_INDEX_EXT_ZIP;
toCheckPostfix = BINARY_MAP_INDEX_EXT;
} else if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
parent = ctx.getAppDir();
// unzipDir = true;
toSavePostfix = IndexConstants.EXTRA_ZIP_EXT;
toCheckPostfix = IndexConstants.EXTRA_EXT;
} else if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
parent = ctx.getVoiceDir();
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();
toSavePostfix = TTSVOICE_INDEX_EXT_ZIP;
toCheckPostfix = ""; //$NON-NLS-1$
unzipDir = true;
}
if (type == DownloadActivityType.ROADS_FILE) {
toSavePostfix = "-roads" + toSavePostfix;
toCheckPostfix = "-roads" + toCheckPostfix;
}
if (parent != null) {
parent.mkdirs();
// ".nomedia" indicates there are no pictures and no music to list in this dir for the Gallery and Music apps
if (preventMediaIndexing) {
try {
new File(parent, ".nomedia").createNewFile();//$NON-NLS-1$
} catch (IOException e) {
// swallow io exception
log.error("IOException", e);
}
}
}
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();
entry.fileToSave = new File(parent, entry.baseName + toSavePostfix);
entry.unzip = unzipDir;
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
try {
Date d = format.parse(date);
entry.dateModified = d.getTime();
} catch (ParseException e1) {
log.error("ParseException", e1);
}
try {
entry.sizeMB = Double.parseDouble(size);
} catch (NumberFormatException e1) {
log.error("ParseException", e1);
}
entry.parts = 1;
if (parts != null) {
entry.parts = Integer.parseInt(parts);
}
entry.fileToUnzip = new File(parent, entry.baseName + toCheckPostfix);
File backup = new File(ctx.getBackupDir(), entry.fileToUnzip.getName());
if (backup.exists()) {
entry.existingBackupFile = backup;
}
}
if (attachedItem != null) {
entry.attachedEntry = attachedItem.createDownloadEntry(ctx, type);
}
return entry;
}
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$
}
if (getType() == DownloadActivityType.ROADS_FILE) {
s = "-roads" + s;
}
return e.substring(0, l) + s;
}
}

View file

@ -0,0 +1,89 @@
package net.osmand.plus.download;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import net.osmand.plus.ClientContext;
import net.osmand.plus.R;
public class IndexItemCategory implements Comparable<IndexItemCategory> {
public final String name;
public final List<IndexItem> items = new ArrayList<IndexItem>();
private final int order;
public IndexItemCategory(String name, int order) {
this.name = name;
this.order = order;
}
@Override
public int compareTo(IndexItemCategory another) {
return order < another.order ? -1 : 1;
}
public static List<IndexItemCategory> categorizeIndexItems(ClientContext ctx, Collection<IndexItem> indexItems) {
final Map<String, IndexItemCategory> cats = new TreeMap<String, IndexItemCategory>();
for (IndexItem i : indexItems) {
int nameId = R.string.index_name_other;
int order = 0;
String lc = i.getFileName().toLowerCase();
if (lc.endsWith(".voice.zip")) {
nameId = R.string.index_name_voice;
order = 1;
} else if (lc.contains(".ttsvoice.zip")) {
nameId = R.string.index_name_tts_voice;
order = 2;
} else if (lc.startsWith("us")) {
nameId = R.string.index_name_us;
order = 31;
} else if (lc.contains("_northamerica_")) {
nameId = R.string.index_name_north_america;
order = 30;
} else if (lc.contains("_centralamerica_") || lc.contains("central-america")) {
nameId = R.string.index_name_central_america;
order = 40;
} else if (lc.contains("_southamerica_") || lc.contains("south-america")) {
nameId = R.string.index_name_south_america;
order = 45;
} else if (lc.startsWith("france_")) {
nameId = R.string.index_name_france;
order = 17;
} else if (lc.startsWith("germany_")) {
nameId = R.string.index_name_germany;
order = 16;
} else if (lc.contains("_europe_")) {
nameId = R.string.index_name_europe;
order = 15;
} else if (lc.startsWith("russia_")) {
nameId = R.string.index_name_russia;
order = 18;
} else if (lc.contains("africa")) {
nameId = R.string.index_name_africa;
order = 80;
} else if (lc.contains("_asia_")) {
nameId = R.string.index_name_asia;
order = 50;
} else if (lc.contains("_oceania_") || lc.contains("australia")) {
nameId = R.string.index_name_oceania;
order = 70;
} else if (lc.contains("_wiki_")) {
nameId = R.string.index_name_wiki;
order = 10;
}
String name = ctx.getString(nameId);
if (!cats.containsKey(name)) {
cats.put(name, new IndexItemCategory(name, order));
}
cats.get(name).items.add(i);
}
ArrayList<IndexItemCategory> r = new ArrayList<IndexItemCategory>(cats.values());
Collections.sort(r);
return r;
}
}

View file

@ -0,0 +1,60 @@
package net.osmand.plus.download;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.osmand.LogUtil;
import net.osmand.plus.ClientContext;
import net.osmand.plus.R;
import org.apache.commons.logging.Log;
public class SrtmIndexItem extends IndexItem {
private static final Log log = LogUtil.getLog(SrtmIndexItem.class);
public SrtmIndexItem(String fileName, String description, String date, String size) {
super(fileName, description, date, size, null);
type = DownloadActivityType.SRTM_FILE;
}
@Override
public boolean isAccepted() {
return true;
}
@Override
public DownloadEntry createDownloadEntry(ClientContext ctx, DownloadActivityType type) {
File parent = ctx.getAppDir();
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();
// entry.fileToSave = new File(parent, entry.baseName + toSavePostfix);
// entry.unzip = unzipDir;
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
try {
Date d = format.parse(date);
entry.dateModified = d.getTime();
} catch (ParseException e1) {
log.error("ParseException", e1);
}
try {
entry.sizeMB = Double.parseDouble(size);
} catch (NumberFormatException e1) {
log.error("ParseException", e1);
}
entry.parts = 1;
if (parts != null) {
entry.parts = Integer.parseInt(parts);
}
// entry.fileToUnzip = new File(parent, entry.baseName + toCheckPostfix);
}
return entry;
}
}

View file

@ -1,80 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=error
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6

3
OsmAnd/lint.xml Normal file
View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>

View file

@ -1119,8 +1119,8 @@
<string name="rendering_attr_roadColors_description">Выберите цветовую схему дорог:</string>
<string name="rendering_attr_roadColors_name">Цветовая схема дорог</string>
<string name="route_descr_current_location">Текущая позиция</string>
<string name="route_descr_from_to">Из %1$s\nДо %2$s</string>
<string name="route_descr_from_to_via">Из : %1$s\nЧерез : %2$s\nДо : %3$s</string>
<string name="route_descr_from_to">Из %1$s\nДо %2$s</string>
<string name="route_descr_from_to_via">Из : %1$s\nЧерез : %2$s\nДо : %3$s</string>
<string name="route_descr_lat_lon">Ш %1$.3f Д %2$.3f</string>
<string name="incomplete_locale">незавершенное</string>
</resources>

View file

@ -11,6 +11,9 @@
-->
<string name="rendering_attr_noAdminboundaries_name">Hide boundaries</string>
<string name="rendering_attr_noAdminboundaries_description">Suppress display of regional boundaries (admin levels 5-9)</string>
<string name="osmodroid_plugin_old_ver_not_supported">OsMoDroid plugin has an old version and needs to be updated.</string>
<string name="osmodroid_plugin_description">OsMoDroid plugin (TODO description)</string>
<string name="osmodroid_plugin_name">OsMoDroid plugin</string>
<string name="tip_altitude_offset">Altitude Display - Offset Correction</string>
<string name="tip_altitude_offset_t">\tMost GPS devices report altitude measurements in the ellipsoid-based WGS84 reference system, from which a conversion to locally used systems requires a position-dependent correction.
\n\tA better approximation to these local systems is the EGM96 reference. OsmAnd now also supports the automatic display of altitudes in the EGM96 system.

View file

@ -0,0 +1,6 @@
package com.OsMoDroid;
interface IRemoteOsMoDroidService {
int getVersion();
}

View file

@ -0,0 +1,64 @@
package net.osmand.plus;
import java.io.File;
import net.osmand.Version;
import net.osmand.access.AccessibleToast;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;
public class AndroidClientContext implements ClientContext {
private final OsmandApplication app;
public AndroidClientContext(OsmandApplication app) {
this.app = app;
}
@Override
public String getFullVersion() {
return Version.getFullVersion(app);
}
@Override
public String getVersionAsURLParam() {
return Version.getVersionAsURLParam(app);
}
@Override
public boolean isWifiConnected() {
ConnectivityManager mgr = (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = mgr.getActiveNetworkInfo();
return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;
}
@Override
public String getString(int resId) {
return app.getString(resId);
}
@Override
public File getAppDir() {
return app.getSettings().extendOsmandPath(ResourceManager.APP_DIR);
}
@Override
public File getVoiceDir() {
return app.getSettings().extendOsmandPath(ResourceManager.VOICE_PATH);
}
@Override
public File getBackupDir() {
return app.getSettings().extendOsmandPath(ResourceManager.BACKUP_PATH);
}
@Override
public void showToastMessage(int msgId) {
AccessibleToast.makeText(app, msgId, Toast.LENGTH_LONG).show();
}
}

View file

@ -43,7 +43,6 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Handler;
@ -80,7 +79,7 @@ public class OsmandApplication extends Application {
private boolean applicationInitializing = false;
private Locale prefferedLocale = null;
private AndroidClientContext clientContext;
@Override
public void onCreate() {
@ -91,7 +90,8 @@ public class OsmandApplication extends Application {
routingHelper = new RoutingHelper(this, player);
manager = new ResourceManager(this);
daynightHelper = new DayNightHelper(this);
bidforfix = new BidForFixHelper("osmand.net", getString(R.string.default_buttons_support), getString(R.string.default_buttons_cancel));
bidforfix = new BidForFixHelper("osmand.net", getString(R.string.default_buttons_support),
getString(R.string.default_buttons_cancel));
savingTrackHelper = new SavingTrackHelper(this);
liveMonitoringHelper = new LiveMonitoringHelper(this);
uiHandler = new Handler();
@ -126,6 +126,7 @@ public class OsmandApplication extends Application {
/**
* Creates instance of OsmandSettings
*
* @return Reference to instance of OsmandSettings
*/
protected OsmandSettings createOsmandSettingsInstance() {
@ -134,6 +135,7 @@ public class OsmandApplication extends Application {
/**
* Application settings
*
* @return Reference to instance of OsmandSettings
*/
public OsmandSettings getSettings() {
@ -151,7 +153,6 @@ public class OsmandApplication extends Application {
return liveMonitoringHelper;
}
public PoiFiltersHelper getPoiFilters() {
if (poiFilters == null) {
poiFilters = new PoiFiltersHelper(this);
@ -207,8 +208,6 @@ public class OsmandApplication extends Application {
manager.onLowMemory();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (prefferedLocale != null && !newConfig.locale.getLanguage().equals(prefferedLocale.getLanguage())) {
@ -240,8 +239,7 @@ public class OsmandApplication extends Application {
/**
* @param activity
* that supports onCreateDialog({@link #PROGRESS_DIALOG}) and
* returns @param progressdialog
* that supports onCreateDialog({@link #PROGRESS_DIALOG}) and returns @param progressdialog
* @param progressDialog
* - it should be exactly the same as onCreateDialog
* @return
@ -255,7 +253,8 @@ public class OsmandApplication extends Application {
SpecialPhrases.setLanguage(this, osmandSettings);
} catch (IOException e) {
LOG.error("I/O exception", e);
Toast error = Toast.makeText(this, "Error while reading the special phrases. Restart OsmAnd if possible", Toast.LENGTH_LONG);
Toast error = Toast.makeText(this, "Error while reading the special phrases. Restart OsmAnd if possible",
Toast.LENGTH_LONG);
error.show();
}
@ -296,17 +295,12 @@ public class OsmandApplication extends Application {
Builder builder = new AlertDialog.Builder(uiContext);
builder.setCancelable(true);
builder.setNegativeButton(R.string.default_buttons_cancel, null);
builder.setPositiveButton(R.string.default_buttons_ok,
new DialogInterface.OnClickListener() {
builder.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
Intent intent = new Intent(uiContext,
SettingsActivity.class);
intent.putExtra(
SettingsActivity.INTENT_KEY_SETTINGS_SCREEN,
SettingsActivity.SCREEN_NAVIGATION_SETTINGS);
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(uiContext, SettingsActivity.class);
intent.putExtra(SettingsActivity.INTENT_KEY_SETTINGS_SCREEN, SettingsActivity.SCREEN_NAVIGATION_SETTINGS);
uiContext.startActivity(intent);
}
});
@ -324,8 +318,7 @@ public class OsmandApplication extends Application {
}
private void initVoiceDataInDifferentThread(final Activity uiContext, final String voiceProvider, final Runnable run) {
final ProgressDialog dlg = ProgressDialog.show(uiContext,
getString(R.string.loading_data),
final ProgressDialog dlg = ProgressDialog.show(uiContext, getString(R.string.loading_data),
getString(R.string.voice_data_initializing));
new Thread(new Runnable() {
@Override
@ -360,7 +353,6 @@ public class OsmandApplication extends Application {
return bidforfix;
}
public synchronized void closeApplication(final Activity activity) {
if (getNavigationService() != null) {
Builder bld = new AlertDialog.Builder(activity);
@ -583,4 +575,11 @@ public class OsmandApplication extends Application {
return ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)).isEnabled();
}
public ClientContext getClientContext() {
if (clientContext == null) {
clientContext = new AndroidClientContext(this);
}
return clientContext;
}
}

View file

@ -14,6 +14,7 @@ import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.extrasettings.OsmandExtraSettings;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmodroid.OsMoDroidPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.views.OsmandMapTileView;
@ -23,6 +24,7 @@ import org.apache.commons.logging.Log;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.preference.PreferenceScreen;
@ -35,6 +37,8 @@ public abstract class OsmandPlugin {
private static final String PARKING_PLUGIN_COMPONENT = "net.osmand.parkingPlugin"; //$NON-NLS-1$
private static final String PARKING_PLUGIN_ACTIVITY = "net.osmand.parkingPlugin.ParkingPluginActivity"; //$NON-NLS-1$
private static final String OSMODROID_PLUGIN_COMPONENT = "net.osmand.parkingPlugin"; //$NON-NLS-1$
public abstract String getId();
@ -64,8 +68,8 @@ public abstract class OsmandPlugin {
installedPlugins.add(new AccessibilityPlugin(app));
installedPlugins.add(new OsmEditingPlugin(app));
installedPlugins.add(new OsmandDevelopmentPlugin(app));
// installedPlugins.add(parkingPlugin);
installParkingPlugin(app);
installOsmodroidPlugin(app);
Set<String> enabledPlugins = settings.getEnabledPlugins();
for (OsmandPlugin plugin : installedPlugins) {
@ -228,4 +232,19 @@ public abstract class OsmandPlugin {
app.getSettings().enablePlugin(parkingPlugin.getId(), false);
}
}
private static void installOsmodroidPlugin(OsmandApplication app) {
Intent parkingIntent = new Intent();
boolean installed = false;
try{
installed = app.getPackageManager().getPackageInfo(OSMODROID_PLUGIN_COMPONENT, 0) != null;
} catch ( NameNotFoundException e){
}
if(installed) {
installedPlugins.add(new OsMoDroidPlugin(app));
app.getSettings().enablePlugin(OsMoDroidPlugin.ID, true);
} else {
app.getSettings().enablePlugin(OsMoDroidPlugin.ID, false);
}
}
}

View file

@ -1,6 +1,14 @@
package net.osmand.plus.activities;
import static net.osmand.data.IndexConstants.*;
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.BINARY_MAP_VERSION;
import static net.osmand.data.IndexConstants.EXTRA_EXT;
import static net.osmand.data.IndexConstants.EXTRA_ZIP_EXT;
import static net.osmand.data.IndexConstants.TTSVOICE_INDEX_EXT_ZIP;
import static net.osmand.data.IndexConstants.TTSVOICE_VERSION;
import static net.osmand.data.IndexConstants.VOICE_INDEX_EXT_ZIP;
import static net.osmand.data.IndexConstants.VOICE_VERSION;
import java.io.File;
import java.io.FilenameFilter;
@ -19,19 +27,21 @@ import net.osmand.LogUtil;
import net.osmand.Version;
import net.osmand.access.AccessibleToast;
import net.osmand.data.IndexConstants;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadEntry;
import net.osmand.plus.download.DownloadFileHelper;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.download.DownloadIndexAdapter;
import net.osmand.plus.download.DownloadIndexListThread;
import net.osmand.plus.download.DownloadOsmandIndexesHelper.IndexItem;
import net.osmand.plus.download.DownloadTracker;
import net.osmand.plus.download.IndexItem;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
@ -88,14 +98,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
private DownloadFileHelper downloadFileHelper = null;
private OsmandSettings settings;
public enum DownloadActivityType {
NORMAL_FILE,
ROADS_FILE,
SRTM_FILE
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -110,7 +112,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
downloadFileHelper = new DownloadFileHelper(this);
downloadFileHelper = new DownloadFileHelper(getClientContext());
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
@Override
@ -212,7 +214,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
IndexItem es = listAdapter.getChild(j, i);
if (!entriesToDownload.containsKey(es.getFileName())) {
selected++;
entriesToDownload.put(es.getFileName(), es.createDownloadEntry(DownloadIndexActivity.this, type));
entriesToDownload.put(es.getFileName(), es.createDownloadEntry(getClientContext(), type));
}
}
}
@ -391,7 +393,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
return true;
}
final DownloadEntry entry = e.createDownloadEntry(DownloadIndexActivity.this, type);
final DownloadEntry entry = e.createDownloadEntry(getClientContext(), type);
if (entry != null) {
// if(!fileToUnzip.exists()){
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
@ -642,4 +644,8 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
return res;
}
}
public ClientContext getClientContext() {
return getMyApplication().getClientContext();
}
}

View file

@ -5,13 +5,10 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.osmand.data.IndexConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.DownloadIndexActivity.DownloadActivityType;
import net.osmand.plus.download.DownloadOsmandIndexesHelper.IndexItem;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
@ -36,7 +33,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
public DownloadIndexAdapter(DownloadIndexActivity downloadActivity, List<IndexItem> indexFiles) {
this.downloadActivity = downloadActivity;
this.indexFiles = new ArrayList<IndexItem>(indexFiles);
List<IndexItemCategory> cats = IndexItemCategory.categorizeIndexItems(downloadActivity, indexFiles);
List<IndexItemCategory> cats = IndexItemCategory.categorizeIndexItems(downloadActivity.getClientContext(), indexFiles);
synchronized (this) {
list.clear();
list.addAll(cats);
@ -83,7 +80,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
for (IndexItem i : indexFiles) {
this.indexFiles.add(i);
}
List<IndexItemCategory> cats = IndexItemCategory.categorizeIndexItems(downloadActivity, indexFiles);
List<IndexItemCategory> cats = IndexItemCategory.categorizeIndexItems(downloadActivity.getClientContext(), indexFiles);
synchronized (this) {
list.clear();
list.addAll(cats);
@ -140,7 +137,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
list.clear();
Collection<IndexItem> items = (Collection<IndexItem>) results.values;
if (items != null && !items.isEmpty()) {
list.addAll(IndexItemCategory.categorizeIndexItems(downloadActivity, items));
list.addAll(IndexItemCategory.categorizeIndexItems(downloadActivity.getClientContext(), items));
} else {
list.add(new IndexItemCategory(downloadActivity.getResources().getString(R.string.select_index_file_to_download), 1));
}
@ -212,7 +209,7 @@ 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);
item.setText((e.getVisibleDescription(downloadActivity, downloadActivity.getType()) + "\n" + e.getVisibleName()).trim()); //$NON-NLS-1$
item.setText((e.getVisibleDescription(downloadActivity.getClientContext(), downloadActivity.getType()) + "\n" + e.getVisibleName()).trim()); //$NON-NLS-1$
description.setText(e.getDate() + "\n" + e.getSize() + " MB");
CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item);

View file

@ -1,14 +1,11 @@
package net.osmand.plus.download;
import java.util.List;
import java.util.Map;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.DownloadIndexActivity.DownloadActivityType;
import net.osmand.plus.download.DownloadOsmandIndexesHelper.IndexItem;
import android.content.Context;
import android.view.View;
import android.widget.Toast;
@ -45,10 +42,10 @@ public class DownloadIndexListThread extends Thread {
@Override
public void run() {
if (indexFiles != null) {
boolean basemapExists = ((OsmandApplication) uiActivity.getApplication()).getResourceManager().containsBasemap();
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
if (!basemapExists && indexFiles.getBasemap() != null) {
uiActivity.getEntriesToDownload().put(indexFiles.getBasemap().getFileName(), indexFiles.getBasemap()
.createDownloadEntry(ctx, uiActivity.getType()));
.createDownloadEntry(uiActivity.getClientContext(), uiActivity.getType()));
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download, Toast.LENGTH_LONG).show();
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
}

View file

@ -1,26 +1,18 @@
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.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.osmand.LogUtil;
import net.osmand.Version;
import net.osmand.access.AccessibleToast;
import net.osmand.data.IndexConstants;
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.DownloadActivityType;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
@ -32,11 +24,10 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.widget.Toast;
public class DownloadOsmandIndexesHelper {
private final static Log log = LogUtil.getLog(DownloadOsmandIndexesHelper.class);
public static final String INDEX_DOWNLOAD_DOMAIN = "download.osmand.net";
public static IndexFileList getIndexesList(Context ctx) {
PackageManager pm =ctx.getPackageManager();
@ -119,8 +110,9 @@ public class DownloadOsmandIndexesHelper {
IndexFileList result = new IndexFileList();
log.debug("Start loading list of index files"); //$NON-NLS-1$
try {
log.info("http://"+INDEX_DOWNLOAD_DOMAIN+"/get_indexes?" + versionAsUrl);
URL url = new URL("http://"+INDEX_DOWNLOAD_DOMAIN+"/get_indexes?" + versionAsUrl ); //$NON-NLS-1$
String strUrl = "http://"+IndexConstants.INDEX_DOWNLOAD_DOMAIN+"/get_indexes?" + versionAsUrl; //$NON-NLS-1$
log.info(strUrl);
URL url = new URL(strUrl );
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setInput(url.openStream(), "UTF-8"); //$NON-NLS-1$
int next;
@ -182,251 +174,10 @@ public class DownloadOsmandIndexesHelper {
}
@Override
public DownloadEntry createDownloadEntry(Context ctx, DownloadActivityType type) {
public DownloadEntry createDownloadEntry(ClientContext ctx, DownloadActivityType type) {
return new DownloadEntry(assetName, destFile, dateModified);
}
}
public static class IndexItem {
String description;
String date;
String parts;
String fileName;
String size;
IndexItem attachedItem;
DownloadActivityType type;
public IndexItem(String fileName, String description, String date, String size, String parts) {
this.fileName = fileName;
this.description = description;
this.date = date;
this.size = size;
this.parts = parts;
this.type = DownloadActivityType.NORMAL_FILE;
}
public DownloadActivityType getType() {
return type;
}
public void setType(DownloadActivityType type) {
this.type = type;
}
public String getVisibleDescription(Context ctx, DownloadActivityType type){
String s = ""; //$NON-NLS-1$
if(type == DownloadActivityType.ROADS_FILE){
return ctx.getString(R.string.download_roads_only_item);
}
if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)
|| fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
} else if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
s = ctx.getString(R.string.voice);
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
s = ctx.getString(R.string.ttsvoice);
}
return s;
}
public String getVisibleName(){
return getBasename().replace('_', ' ');
}
private String getBasename(){
if(fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length());
}
int ls = fileName.lastIndexOf('_');
if(ls >= 0) {
return fileName.substring(0, ls);
}
return fileName;
}
public boolean isAccepted(){
// POI index download is not supported any longer
if (fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT,IndexConstants.BINARY_MAP_VERSION)) //
|| fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP,IndexConstants.BINARY_MAP_VERSION)) //
|| fileName.endsWith(addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION))
|| fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)
//|| fileName.endsWith(addVersionToExt(IndexConstants.TTSVOICE_INDEX_EXT_ZIP, IndexConstants.TTSVOICE_VERSION)) drop support for downloading tts files from inet
) {
return true;
}
return false;
}
protected static String addVersionToExt(String ext, int version) {
return "_" + version + ext;
}
public String getFileName() {
return fileName;
}
public String getDescription() {
return description;
}
public String getDate() {
return date;
}
public String getSize() {
return size;
}
public DownloadEntry createDownloadEntry(Context ctx, DownloadActivityType type) {
String fileName = this.fileName;
File parent = null;
String toSavePostfix = null;
String toCheckPostfix = null;
boolean unzipDir = false;
boolean preventMediaIndexing = false;
OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
if(fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)){
parent = settings.extendOsmandPath(ResourceManager.APP_DIR);
toSavePostfix = BINARY_MAP_INDEX_EXT;
toCheckPostfix = BINARY_MAP_INDEX_EXT;
} else if(fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)){
parent = settings.extendOsmandPath(ResourceManager.APP_DIR);
toSavePostfix = BINARY_MAP_INDEX_EXT_ZIP;
toCheckPostfix = BINARY_MAP_INDEX_EXT;
} else if(fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)){
parent = settings.extendOsmandPath(ResourceManager.APP_DIR);
//unzipDir = true;
toSavePostfix = IndexConstants.EXTRA_ZIP_EXT;
toCheckPostfix = IndexConstants.EXTRA_EXT;
} else if(fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)){
parent = settings.extendOsmandPath(ResourceManager.VOICE_PATH);
toSavePostfix = VOICE_INDEX_EXT_ZIP;
toCheckPostfix = ""; //$NON-NLS-1$
unzipDir = true;
preventMediaIndexing = true;
} else if(fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)){
parent = settings.extendOsmandPath(ResourceManager.VOICE_PATH);
toSavePostfix = TTSVOICE_INDEX_EXT_ZIP;
toCheckPostfix = ""; //$NON-NLS-1$
unzipDir = true;
}
if(type == DownloadActivityType.ROADS_FILE) {
toSavePostfix = "-roads" + toSavePostfix;
toCheckPostfix = "-roads" + toCheckPostfix;
}
if(parent != null) {
parent.mkdirs();
// ".nomedia" indicates there are no pictures and no music to list in this dir for the Gallery and Music apps
if( preventMediaIndexing ) {
try {
new File(parent, ".nomedia").createNewFile();//$NON-NLS-1$
} catch (IOException e) {
// swallow io exception
log.error("IOException" ,e);
}
}
}
final DownloadEntry entry;
if(parent == null || !parent.exists()){
AccessibleToast.makeText(ctx, ctx.getString(R.string.sd_dir_not_accessible), Toast.LENGTH_LONG).show();
entry = null;
} else {
entry = new DownloadEntry();
entry.isRoadMap = type == DownloadActivityType.ROADS_FILE;
entry.baseName = getBasename();
entry.fileToSave = new File(parent, entry.baseName + toSavePostfix);
entry.unzip = unzipDir;
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
try {
Date d = format.parse(date);
entry.dateModified = d.getTime();
} catch (ParseException e1) {
log.error("ParseException" ,e1);
}
try {
entry.sizeMB = Double.parseDouble(size);
} catch (NumberFormatException e1) {
log.error("ParseException" ,e1);
}
entry.parts = 1;
if (parts != null) {
entry.parts = Integer.parseInt(parts);
}
entry.fileToUnzip = new File(parent, entry.baseName + toCheckPostfix);
File backup = settings.extendOsmandPath(ResourceManager.BACKUP_PATH + entry.fileToUnzip.getName());
if (backup.exists()) {
entry.existingBackupFile = backup;
}
}
if(attachedItem != null) {
entry.attachedEntry = attachedItem.createDownloadEntry(ctx, type);
}
return entry;
}
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$
}
if(getType() == DownloadActivityType.ROADS_FILE ) {
s = "-roads"+s;
}
return e.substring(0, l) + s;
}
}
/*public static class SrtmIndexItem extends IndexItem {
public SrtmIndexItem(String fileName, String description, String date, String size) {
super(fileName, description, date, size, null);
type = DownloadActivityType.SRTM_FILE;
}
@Override
public boolean isAccepted() {
return true;
}
public DownloadEntry createDownloadEntry(Context ctx, DownloadActivityType type) {
OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
File parent = settings.extendOsmandPath(ResourceManager.APP_DIR);
final DownloadEntry entry;
if(parent == null || !parent.exists()){
AccessibleToast.makeText(ctx, ctx.getString(R.string.sd_dir_not_accessible), Toast.LENGTH_LONG).show();
entry = null;
} else {
entry = new DownloadEntry();
entry.isRoadMap = type == DownloadActivityType.ROADS_FILE;
entry.baseName = getBasename();
entry.fileToSave = new File(parent, entry.baseName + toSavePostfix);
entry.unzip = unzipDir;
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
try {
Date d = format.parse(date);
entry.dateModified = d.getTime();
} catch (ParseException e1) {
log.error("ParseException" ,e1);
}
try {
entry.sizeMB = Double.parseDouble(size);
} catch (NumberFormatException e1) {
log.error("ParseException" ,e1);
}
entry.parts = 1;
if (parts != null) {
entry.parts = Integer.parseInt(parts);
}
entry.fileToUnzip = new File(parent, entry.baseName + toCheckPostfix);
File backup = settings.extendOsmandPath(ResourceManager.BACKUP_PATH + entry.fileToUnzip.getName());
if (backup.exists()) {
entry.existingBackupFile = backup;
}
return entry;
}
}
}*/
}

View file

@ -0,0 +1,94 @@
package net.osmand.plus.osmodroid;
import org.apache.commons.logging.Log;
import net.osmand.LogUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import com.OsMoDroid.IRemoteOsMoDroidService;
public class OsMoDroidPlugin extends OsmandPlugin {
public static final String ID = "osmand.osmodroid";
private static final Log log = LogUtil.getLog(OsMoDroidPlugin.class);
private OsmandApplication app;
IRemoteOsMoDroidService mIRemoteService;
private ServiceConnection mConnection;
private int OSMODROID_SUPPORTED_VERSION_MIN = 0;
@Override
public String getId() {
return ID;
}
public OsMoDroidPlugin(OsmandApplication app) {
this.app = app;
}
@Override
public String getDescription() {
return app.getString(R.string.osmodroid_plugin_description);
}
@Override
public String getName() {
return app.getString(R.string.osmodroid_plugin_name);
}
@Override
public boolean init(final OsmandApplication app) {
mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mIRemoteService = IRemoteOsMoDroidService.Stub.asInterface(service);
try {
System.out.println(mIRemoteService.getVersion());
if(mIRemoteService.getVersion() < OSMODROID_SUPPORTED_VERSION_MIN) {
app.getClientContext().showToastMessage(R.string.osmodroid_plugin_old_ver_not_supported);
shutdown(app);
} else {
app.getClientContext().showToastMessage(R.string.osmodroid_plugin_description);
}
} catch (RemoteException e) {
log.error(e.getMessage(), e);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
mIRemoteService = null;
}
};
Intent serviceIntent = (new Intent("OsMoDroid.remote"));
app.bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
return true;
}
@Override
public void registerLayers(MapActivity activity) {
}
@Override
public void disable(OsmandApplication app) {
shutdown(app);
}
private void shutdown(OsmandApplication app) {
if (mIRemoteService != null) {
app.unbindService(mConnection);
mIRemoteService = null;
}
}
}