Merge branch 'master' of git@github.com:osmandapp/Osmand.git

This commit is contained in:
sonora 2011-08-27 17:50:20 +02:00
commit e43fb08a65
15 changed files with 548 additions and 395 deletions

View file

@ -815,17 +815,17 @@ public class IndexAddressCreator extends AbstractIndexPartCreator{
Statement stat = conn.createStatement();
stat.executeUpdate("create table city (id bigint primary key, latitude double, longitude double, " +
"name varchar(255), name_en varchar(255), city_type varchar(32))");
"name varchar(1024), name_en varchar(1024), city_type varchar(32))");
stat.executeUpdate("create index city_ind on city (id, city_type)");
stat.executeUpdate("create table street (id bigint primary key, latitude double, longitude double, " +
"name varchar(255), name_en varchar(255), city bigint)");
"name varchar(1024), name_en varchar(1024), city bigint)");
stat.executeUpdate("create index street_city on street (city)");
stat.executeUpdate("create index street_id on street (id)");
// create index on name ?
stat.executeUpdate("create table building (id bigint, latitude double, longitude double, " +
"name varchar(255), name_en varchar(255), street bigint, postcode varchar(255), primary key(street, id))");
"name varchar(1024), name_en varchar(1024), street bigint, postcode varchar(1024), primary key(street, id))");
stat.executeUpdate("create index building_postcode on building (postcode)");
stat.executeUpdate("create index building_street on building (street)");
stat.executeUpdate("create index building_id on building (id)");

View file

@ -339,8 +339,8 @@ public class IndexCreator {
public void generateIndexes(File readFile, IProgress progress, IOsmStorageFilter addFilter, MapZooms mapZooms,
MapRenderingTypes renderingTypes) throws IOException, SAXException, SQLException {
if(LevelDBAccess.load()){
dialect = DBDialect.NOSQL;
if(!LevelDBAccess.load() && dialect == DBDialect.NOSQL){
dialect = DBDialect.SQLITE;
}
if (renderingTypes == null) {

View file

@ -119,8 +119,8 @@ public class IndexPoiCreator extends AbstractIndexPartCreator {
// create database structure
Statement stat = poiConnection.createStatement();
stat.executeUpdate("create table " + IndexConstants.POI_TABLE + //$NON-NLS-1$
"(id bigint, x int, y int, name_en varchar(255), name varchar(255), " +
"type varchar(255), subtype varchar(255), opening_hours varchar(255), phone varchar(255), site varchar(255)," +
"(id bigint, x int, y int, name_en varchar(1024), name varchar(1024), " +
"type varchar(1024), subtype varchar(1024), opening_hours varchar(1024), phone varchar(1024), site varchar(1024)," +
"primary key(id, type, subtype))");
stat.executeUpdate("create index poi_loc on poi (x, y, type, subtype)");
stat.executeUpdate("create index poi_id on poi (id, type, subtype)");

View file

@ -141,15 +141,15 @@ public class IndexTransportCreator extends AbstractIndexPartCreator {
public void createDatabaseStructure(Connection conn, DBDialect dialect, String rtreeStopsFileName) throws SQLException, IOException{
Statement stat = conn.createStatement();
stat.executeUpdate("create table transport_route (id bigint primary key, type varchar(255), operator varchar(255)," +
"ref varchar(255), name varchar(255), name_en varchar(255), dist int)");
stat.executeUpdate("create table transport_route (id bigint primary key, type varchar(1024), operator varchar(1024)," +
"ref varchar(1024), name varchar(1024), name_en varchar(1024), dist int)");
stat.executeUpdate("create index transport_route_id on transport_route (id)");
stat.executeUpdate("create table transport_route_stop (stop bigint, route bigint, ord int, direction smallint, primary key (route, ord, direction))");
stat.executeUpdate("create index transport_route_stop_stop on transport_route_stop (stop)");
stat.executeUpdate("create index transport_route_stop_route on transport_route_stop (route)");
stat.executeUpdate("create table transport_stop (id bigint primary key, latitude double, longitude double, name varchar(255), name_en varchar(255))");
stat.executeUpdate("create table transport_stop (id bigint primary key, latitude double, longitude double, name varchar(1024), name_en varchar(1024))");
stat.executeUpdate("create index transport_stop_id on transport_stop (id)");
stat.executeUpdate("create index transport_stop_location on transport_stop (latitude, longitude)");

View file

@ -773,12 +773,12 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator {
private void createMapIndexStructure(Connection conn) throws SQLException{
Statement stat = conn.createStatement();
stat.executeUpdate("create table binary_map_objects (id bigint primary key, name varchar(255), " +
stat.executeUpdate("create table binary_map_objects (id bigint primary key, name varchar(1024), " +
"types binary, restrictions binary, nodes binary, highway int)");
stat.executeUpdate("create index binary_map_objects_ind on binary_map_objects (id)");
stat.executeUpdate("create table low_level_map_objects (id bigint primary key, start_node bigint, " +
"end_node bigint, name varchar(255), nodes binary, type bigint, level smallint)");
"end_node bigint, name varchar(1024), nodes binary, type bigint, level smallint)");
stat.executeUpdate("create index low_level_map_objects_ind on low_level_map_objects (id)");
stat.executeUpdate("create index low_level_map_objects_ind_st on low_level_map_objects (start_node, type)");
stat.executeUpdate("create index low_level_map_objects_ind_end on low_level_map_objects (end_node, type)");

View file

@ -210,9 +210,9 @@ public class OsmDbAccessor implements OsmDbAccessorContext {
String select;
int count = 0;
// stat.executeUpdate("create table tags (id "+longType+", type smallint, skeys varchar(255), value varchar(255))");
// stat.executeUpdate("create table tags (id "+longType+", type smallint, skeys varchar(1024), value varchar(1024))");
// stat.executeUpdate("create table ways (id "+longType+", node "+longType+", ord smallint)");
// stat.executeUpdate("create table relations (id "+longType+", member "+longType+", type smallint, role varchar(255), ord smallint)");
// stat.executeUpdate("create table relations (id "+longType+", member "+longType+", type smallint, role varchar(1024), ord smallint)");
if (type == EntityType.NODE) {
// filter out all nodes without tags
select = "select n.id, n.latitude, n.longitude, t.skeys, t.value from node n inner join tags t on n.id = t.id and t.type = 0 order by n.id"; //$NON-NLS-1$

View file

@ -76,10 +76,10 @@ public class OsmDbCreator implements IOsmStorageFilter {
stat.executeUpdate("create table ways (id bigint, node bigint, ord smallint, primary key (id, ord))"); //$NON-NLS-1$
stat.executeUpdate("create index IdWIndex ON ways (id)"); //$NON-NLS-1$
dialect.deleteTableIfExists("relations", stat);
stat.executeUpdate("create table relations (id bigint, member bigint, type smallint, role varchar(255), ord smallint, primary key (id, ord))"); //$NON-NLS-1$
stat.executeUpdate("create table relations (id bigint, member bigint, type smallint, role varchar(1024), ord smallint, primary key (id, ord))"); //$NON-NLS-1$
stat.executeUpdate("create index IdRIndex ON relations (id)"); //$NON-NLS-1$
dialect.deleteTableIfExists("tags", stat);
stat.executeUpdate("create table tags (id bigint, type smallint, skeys varchar(255), value varchar(255), primary key (id, type, skeys))"); //$NON-NLS-1$
stat.executeUpdate("create table tags (id bigint, type smallint, skeys varchar(1024), value varchar(1024), primary key (id, type, skeys))"); //$NON-NLS-1$
stat.executeUpdate("create index IdTIndex ON tags (id, type)"); //$NON-NLS-1$
stat.close();

View file

@ -47,7 +47,7 @@
<subtype id="36" point="true" tag="highway" value="stop" minzoom="15" />
<subtype id="37" point="true" tag="highway" value="give_way" minzoom="15" />
<subtype id="38" point="true" tag="highway" value="traffic_signals" minzoom="15" />
<subtype id="39" point="true" tag="highway" value="motorway_junction" minzoom="15" />
<subtype id="39" point="true" tag="highway" value="motorway_junction" minzoom="13" />
<subtype id="40" point="true" tag="highway" value="bus_stop" minzoom="15" />
<subtype id="41" point="true" tag="highway" value="platform" minzoom="15" />
<subtype id="42" point="true" tag="highway" value="turning_circle" minzoom="15" />

View file

@ -2,7 +2,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical" android:keepScreenOn="true">
android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/MainLayout">
<TextView android:id="@+id/Label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/select_index_file_to_download"></TextView>

View file

@ -0,0 +1,240 @@
package net.osmand.plus.activities;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.logging.Log;
import android.app.Activity;
import android.graphics.drawable.Drawable.Callback;
import android.os.AsyncTask;
import android.widget.Toast;
import net.osmand.IProgress;
import net.osmand.LogUtil;
import net.osmand.data.IndexConstants;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
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 Activity ctx;
private boolean interruptDownloading = false;
public DownloadFileHelper(Activity 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) 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.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$
if (conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL &&
conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
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); //$NON-NLS-1$
}
first = false;
while ((read = is.read(buffer)) != -1) {
if(interruptDownloading){
throw new InterruptedException();
}
out.write(buffer, 0, read);
progress.progress(read);
fileread += read;
}
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$
}
}
protected boolean downloadFile(final String fileName, final File fileToDownload, final File fileToUnZip, final boolean unzipToDir,
IProgress progress, Long dateModified, int parts, List<File> toReIndex, String indexOfAllFiles,
DownloadFileShowWarning showWarningCallback) throws InterruptedException {
FileOutputStream out = null;
try {
out = new FileOutputStream(fileToDownload);
try {
if(parts == 1){
URL url = new URL("http://download.osmand.net/download?file="+fileName); //$NON-NLS-1$
downloadFile(fileName, out, url, null, indexOfAllFiles, progress);
} else {
for(int i=1; i<=parts; i++){
URL url = new URL("http://download.osmand.net/download?file="+fileName+"-"+i); //$NON-NLS-1$
downloadFile(fileName, out, url, " ["+i+"/"+parts+"]", indexOfAllFiles, progress);
}
}
} finally {
out.close();
out = null;
}
File toIndex = fileToDownload;
if (fileToDownload.getName().endsWith(".zip")) { //$NON-NLS-1$
progress.startTask(ctx.getString(R.string.unzipping_file), -1);
if (!unzipToDir) {
toIndex = fileToUnZip;
} else {
fileToUnZip.mkdirs();
}
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(fileToDownload));
ZipEntry entry = null;
boolean first = true;
while ((entry = zipIn.getNextEntry()) != null) {
File fs;
if (!unzipToDir) {
if (first) {
fs = toIndex;
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(fileToUnZip.getParent(), name);
toIndex = fs;
}
} else {
fs = new File(fileToUnZip, entry.getName());
}
out = new FileOutputStream(fs);
int read;
byte[] buffer = new byte[BUFFER_SIZE];
while ((read = zipIn.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
out.close();
}
zipIn.close();
fileToDownload.delete(); // zip is no needed more
}
ArrayList<String> warnings = new ArrayList<String>();
ResourceManager manager = ((OsmandApplication) ctx.getApplicationContext()).getResourceManager();
if(dateModified != null){
toIndex.setLastModified(dateModified);
}
if (toIndex.getName().endsWith(IndexConstants.POI_INDEX_EXT)) {
// update poi index immediately
manager.indexingPoi(progress, warnings, toIndex);
}
if(dateModified != null){
toIndex.setLastModified(dateModified);
manager.updateIndexLastDateModified(toIndex);
}
toReIndex.add(toIndex);
if (warnings.isEmpty()) {
showWarningCallback.showWarning(ctx.getString(R.string.download_index_success));
} else {
showWarningCallback.showWarning(warnings.get(0));
}
return true;
} catch (IOException e) {
log.error("Exception ocurred", e); //$NON-NLS-1$
showWarningCallback.showWarning(ctx.getString(R.string.error_io_error));
if(out != null){
try {
out.close();
} catch (IOException e1) {
}
}
// Possibly file is corrupted
fileToDownload.delete();
return false;
} catch (InterruptedException e) {
// Possibly file is corrupted
fileToDownload.delete();
throw e;
}
}
public void setInterruptDownloading(boolean interruptDownloading) {
this.interruptDownloading = interruptDownloading;
}
public boolean isInterruptDownloading() {
return interruptDownloading;
}
}

View file

@ -12,13 +12,7 @@ import static net.osmand.data.IndexConstants.VOICE_VERSION;
import static net.osmand.data.IndexConstants.TTSVOICE_VERSION;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -33,11 +27,8 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Map.Entry;
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.DownloadOsmandIndexesHelper;
import net.osmand.plus.OsmandSettings;
@ -45,8 +36,8 @@ import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import net.osmand.plus.DownloadOsmandIndexesHelper.IndexItem;
import net.osmand.plus.activities.DownloadFileHelper.DownloadFileShowWarning;
import org.apache.commons.logging.Log;
import android.app.AlertDialog;
import android.app.ListActivity;
@ -55,6 +46,7 @@ import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@ -74,23 +66,48 @@ import android.widget.Toast;
public class DownloadIndexActivity extends ListActivity {
private final static Log log = LogUtil.getLog(DownloadIndexActivity.class);
private static final int RELOAD_ID = 0;
private static final int SELECT_ALL_ID = 1;
private static final int DESELECT_ALL_ID = 2;
private static final int FILTER_EXISTING_REGIONS = 3;
private static final int MB = 1 << 20;
public static final String FILTER_KEY = "filter";
private static DownloadIndexListThread downloadListIndexThread = new DownloadIndexListThread();
private ProgressDialog progressFileDlg = null;
private ProgressDialog progressListDlg = null;
private Map<String, String> indexFileNames = null;
private TreeMap<String, DownloadEntry> entriesToDownload = new TreeMap<String, DownloadEntry>();
private TextWatcher textWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
private TextWatcher textWatcher ;
private EditText filterText;
private DownloadFileHelper downloadFileHelper = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// recreation upon rotation is prevented in manifest file
setContentView(R.layout.download_index);
downloadFileHelper = new DownloadFileHelper(this);
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
downloadFilesConfirmation();
}
});
indexFileNames = ((OsmandApplication)getApplication()).getResourceManager().getIndexFileNames();
filterText = (EditText) findViewById(R.id.search_box);
textWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@ -104,26 +121,6 @@ public class DownloadIndexActivity extends ListActivity {
}
};
private EditText filterText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// recreation upon rotation is prevented in manifest file
setContentView(R.layout.download_index);
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
downloadFiles();
}
});
indexFileNames = ((OsmandApplication)getApplication()).getResourceManager().getIndexFileNames();
filterText = (EditText) findViewById(R.id.search_box);
filterText.addTextChangedListener(textWatcher);
final Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
@ -252,11 +249,6 @@ public class DownloadIndexActivity extends ListActivity {
private final static int MB = 1 << 20;
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
@ -420,7 +412,7 @@ public class DownloadIndexActivity extends ListActivity {
return entry;
}
protected void downloadFiles() {
protected void downloadFilesConfirmation() {
Builder builder = new AlertDialog.Builder(this);
double sz = 0;
for(DownloadEntry es : entriesToDownload.values()){
@ -430,40 +422,109 @@ public class DownloadIndexActivity extends ListActivity {
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DownloadIndexesAsyncTask task = new DownloadIndexesAsyncTask();
task.execute(entriesToDownload.keySet().toArray(new String[0]));
}
});
builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show();
}
@Override
protected void onDestroy() {
super.onDestroy();
if(isFinishing()){
downloadFileHelper.setInterruptDownloading(true);
}
if (textWatcher != null) {
EditText filterText = (EditText) findViewById(R.id.search_box);
filterText.removeTextChangedListener(textWatcher);
}
downloadListIndexThread.setUiActivity(null);
progressFileDlg = null;
}
private String convertServerFileNameToLocal(String name){
int l = name.lastIndexOf('_');
String s;
if(name.endsWith(IndexConstants.POI_INDEX_EXT) || name.endsWith(IndexConstants.POI_INDEX_EXT_ZIP)){
s = IndexConstants.POI_INDEX_EXT;
} else if(name.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) || name.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)){
s = IndexConstants.BINARY_MAP_INDEX_EXT;
} else {
s = ""; //$NON-NLS-1$
}
return name.substring(0, l) + s;
}
private class DownloadIndexesAsyncTask extends AsyncTask<String, Object, String> implements DownloadFileShowWarning {
private IProgress progress;
@Override
protected void onProgressUpdate(Object... values) {
for(Object o : values){
if(o instanceof DownloadEntry){
((DownloadIndexAdapter) getListAdapter()).notifyDataSetChanged();
findViewById(R.id.DownloadButton).setVisibility(
entriesToDownload.isEmpty() ? View.GONE : View.VISIBLE);
} else if(o instanceof String) {
Toast.makeText(DownloadIndexActivity.this, (String) o, Toast.LENGTH_LONG).show();
}
}
super.onProgressUpdate(values);
}
@Override
protected void onPreExecute() {
progressFileDlg = ProgressDialog.show(DownloadIndexActivity.this, getString(R.string.downloading),
getString(R.string.downloading_file), true, true);
interruptDownloading = false;
downloadFileHelper.setInterruptDownloading(false);
progressFileDlg.show();
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressFileDlg, true);
progress = new ProgressDialogImplementation(progressFileDlg, true);
progressFileDlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
interruptDownloading = true;
downloadFileHelper.setInterruptDownloading(true);
}
});
View mainView = findViewById(R.id.MainLayout);
if(mainView != null){
mainView.setKeepScreenOn(true);
}
}
impl.setRunnable("DownloadIndex", new Runnable() { //$NON-NLS-1$
@Override
public void run() {
protected void onPostExecute(String result) {
if(result != null){
Toast.makeText(DownloadIndexActivity.this, result, Toast.LENGTH_LONG).show();
}
View mainView = findViewById(R.id.MainLayout);
if(mainView != null){
mainView.setKeepScreenOn(false);
}
}
@Override
protected String doInBackground(String... filesToDownload) {
try {
List<File> filesToReindex = new ArrayList<File>();
ArrayList<String> filesToDownload = new ArrayList<String>(entriesToDownload.keySet());
for(int i=0;i<filesToDownload.size(); i++) {
String filename = filesToDownload.get(i);
for (int i = 0; i < filesToDownload.length; i++) {
String filename = filesToDownload[i];
DownloadEntry entry = entriesToDownload.get(filename);
if (entry != null) {
String indexOfAllFiles = filesToDownload.size() <= 1 ? "" : (" ["+(i+1)+"/"+filesToDownload.size()+"]");
if (downloadFile(filename, entry.fileToSave, entry.fileToUnzip, entry.unzip, impl, entry.dateModified,
entry.parts, filesToReindex, indexOfAllFiles)) {
String indexOfAllFiles = filesToDownload.length <= 1 ? "" : (" [" + (i + 1) + "/"
+ filesToDownload.length + "]");
boolean result = downloadFileHelper.downloadFile(filename,
entry.fileToSave, entry.fileToUnzip, entry.unzip, progress, entry.dateModified,
entry.parts, filesToReindex, indexOfAllFiles, this);
if (result) {
entriesToDownload.remove(filename);
runOnUiThread(new Runnable() {
@Override
public void run() {
((DownloadIndexAdapter) getListAdapter()).notifyDataSetChanged();
findViewById(R.id.DownloadButton).setVisibility(entriesToDownload.isEmpty() ? View.GONE : View.VISIBLE);
}
});
publishProgress(entry);
}
}
}
@ -477,14 +538,14 @@ public class DownloadIndexActivity extends ListActivity {
// reindex vector maps all at one time
if (vectorMapsToReindex) {
ResourceManager manager = ((OsmandApplication) getApplication()).getResourceManager();
List<String> warnings = manager.indexingMaps(impl);
List<String> warnings = manager.indexingMaps(progress);
if (warnings.isEmpty() && !OsmandSettings.getOsmandSettings(getApplicationContext()).MAP_VECTOR_DATA.get()) {
warnings.add(getString(R.string.binary_map_download_success));
// Is it proper way to switch every tome to vector data?
OsmandSettings.getOsmandSettings(getApplicationContext()).MAP_VECTOR_DATA.set(true);
}
if (!warnings.isEmpty()) {
showWarning(warnings.get(0));
return warnings.get(0);
}
}
} catch (InterruptedException e) {
@ -496,17 +557,15 @@ public class DownloadIndexActivity extends ListActivity {
progressFileDlg = null;
}
}
}
});
impl.run();
}
});
builder.setNegativeButton(R.string.default_buttons_no, null);
builder.show();
return null;
}
private static final int BUFFER_SIZE = 32256;
public static final String FILTER_KEY = "filter";
@Override
public void showWarning(String warning) {
publishProgress(warning);
}
}
private static class DownloadEntry {
public File fileToSave;
@ -518,232 +577,6 @@ public class DownloadIndexActivity extends ListActivity {
public int parts;
}
protected final int TRIES_TO_DOWNLOAD = 15;
protected final long TIMEOUT_BETWEEN_DOWNLOADS = 8000;
private boolean interruptDownloading = false;
protected void downloadFile(String fileName, FileOutputStream out, URL url, String part, String indexOfAllFiles,
IProgress progress) 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.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$
if (conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL &&
conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
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 = getString(R.string.downloading_file) + indexOfAllFiles +" " + fileName;
if(part != null){
taskName += part;
}
progress.startTask(taskName, length); //$NON-NLS-1$
}
first = false;
while ((read = is.read(buffer)) != -1) {
if(interruptDownloading){
throw new InterruptedException();
}
out.write(buffer, 0, read);
progress.progress(read);
fileread += read;
}
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$
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if(isFinishing()){
interruptDownloading = true;
}
if (textWatcher != null) {
EditText filterText = (EditText) findViewById(R.id.search_box);
filterText.removeTextChangedListener(textWatcher);
}
downloadListIndexThread.setUiActivity(null);
progressFileDlg = null;
}
protected boolean downloadFile(final String fileName, final File fileToDownload, final File fileToUnZip, final boolean unzipToDir,
IProgress progress, Long dateModified, int parts, List<File> toReIndex, String indexOfAllFiles) throws InterruptedException {
FileOutputStream out = null;
try {
out = new FileOutputStream(fileToDownload);
try {
if(parts == 1){
URL url = new URL("http://download.osmand.net/download?file="+fileName); //$NON-NLS-1$
downloadFile(fileName, out, url, null, indexOfAllFiles, progress);
} else {
for(int i=1; i<=parts; i++){
URL url = new URL("http://download.osmand.net/download?file="+fileName+"-"+i); //$NON-NLS-1$
downloadFile(fileName, out, url, " ["+i+"/"+parts+"]", indexOfAllFiles, progress);
}
}
} finally {
out.close();
out = null;
}
File toIndex = fileToDownload;
if (fileToDownload.getName().endsWith(".zip")) { //$NON-NLS-1$
progress.startTask(getString(R.string.unzipping_file), -1);
if (!unzipToDir) {
toIndex = fileToUnZip;
} else {
fileToUnZip.mkdirs();
}
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(fileToDownload));
ZipEntry entry = null;
boolean first = true;
while ((entry = zipIn.getNextEntry()) != null) {
File fs;
if (!unzipToDir) {
if (first) {
fs = toIndex;
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(fileToUnZip.getParent(), name);
toIndex = fs;
}
} else {
fs = new File(fileToUnZip, entry.getName());
}
out = new FileOutputStream(fs);
int read;
byte[] buffer = new byte[BUFFER_SIZE];
while ((read = zipIn.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
out.close();
}
zipIn.close();
fileToDownload.delete(); // zip is no needed more
}
ArrayList<String> warnings = new ArrayList<String>();
ResourceManager manager = ((OsmandApplication) getApplication()).getResourceManager();
if(dateModified != null){
toIndex.setLastModified(dateModified);
}
if (toIndex.getName().endsWith(IndexConstants.POI_INDEX_EXT)) {
// update poi index immediately
manager.indexingPoi(progress, warnings, toIndex);
}
if(dateModified != null){
toIndex.setLastModified(dateModified);
manager.updateIndexLastDateModified(toIndex);
}
toReIndex.add(toIndex);
if (warnings.isEmpty()) {
showWarning(getString(R.string.download_index_success));
} else {
showWarning(warnings.get(0));
}
return true;
} catch (IOException e) {
log.error("Exception ocurred", e); //$NON-NLS-1$
showWarning(getString(R.string.error_io_error));
if(out != null){
try {
out.close();
} catch (IOException e1) {
}
}
// Possibly file is corrupted
fileToDownload.delete();
return false;
} catch (InterruptedException e) {
// Possibly file is corrupted
fileToDownload.delete();
throw e;
}
}
public void showWarning(final String messages){
runOnUiThread(new Runnable(){
@Override
public void run() {
Toast.makeText(DownloadIndexActivity.this, messages, Toast.LENGTH_LONG).show();
}
});
}
private String convertServerFileNameToLocal(String name){
int l = name.lastIndexOf('_');
String s;
if(name.endsWith(IndexConstants.POI_INDEX_EXT) || name.endsWith(IndexConstants.POI_INDEX_EXT_ZIP)){
s = IndexConstants.POI_INDEX_EXT;
} else if(name.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) || name.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)){
s = IndexConstants.BINARY_MAP_INDEX_EXT;
} else {
s = ""; //$NON-NLS-1$
}
return name.substring(0, l) + s;
}
protected class DownloadIndexAdapter extends ArrayAdapter<IndexItem> implements Filterable {
private DownloadIndexFilter myFilter;

View file

@ -5,6 +5,7 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@ -61,6 +62,7 @@ public class LocalIndexHelper {
updateObfFileInformation(info, f);
info.setDescription(info.getDescription() + getInstalledDate(f));
} else if(info.getType() == LocalIndexType.POI_DATA){
checkPoiFileVersion(info, f);
info.setDescription(getInstalledDate(f));
} else if(info.getType() == LocalIndexType.GPX_DATA){
updateGpxInfo(info, f);
@ -210,7 +212,7 @@ public class LocalIndexHelper {
private void loadVoiceData(File voiceDir, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
if (voiceDir.canRead()) {
for (File voiceF : voiceDir.listFiles()) {
for (File voiceF : listFilesSorted(voiceDir)) {
if (voiceF.isDirectory()) {
LocalIndexInfo info = null;
if (MediaCommandPlayerImpl.isMyData(voiceF)) {
@ -231,7 +233,7 @@ public class LocalIndexHelper {
private void loadTilesData(File tilesPath, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
if (tilesPath.canRead()) {
for (File tileFile : tilesPath.listFiles()) {
for (File tileFile : listFilesSorted(tilesPath)) {
if (tileFile.isFile() && tileFile.getName().endsWith(SQLiteTileSource.EXT)) {
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.TILES_DATA, tileFile, backup);
result.add(info);
@ -253,7 +255,7 @@ public class LocalIndexHelper {
private void loadObfData(File mapPath, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask, Map<String, String> loadedMaps) {
if (mapPath.canRead()) {
for (File mapFile : mapPath.listFiles()) {
for (File mapFile : listFilesSorted(mapPath)) {
if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.MAP_DATA, mapFile, backup);
if(loadedMaps.containsKey(mapFile.getName()) && !backup){
@ -268,7 +270,7 @@ public class LocalIndexHelper {
private void loadGPXData(File mapPath, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
if (mapPath.canRead()) {
for (File gpxFile : mapPath.listFiles()) {
for (File gpxFile : listFilesSorted(mapPath)) {
if (gpxFile.isFile() && gpxFile.getName().endsWith(".gpx")) {
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.GPX_DATA, gpxFile, backup);
result.add(info);
@ -278,9 +280,15 @@ public class LocalIndexHelper {
}
}
private File[] listFilesSorted(File dir){
File[] listFiles = dir.listFiles();
Arrays.sort(listFiles);
return listFiles;
}
private void loadPoiData(File mapPath, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
if (mapPath.canRead()) {
for (File poiFile : mapPath.listFiles()) {
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) {

View file

@ -6,11 +6,11 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import net.osmand.Algoritms;
import net.osmand.FavouritePoint;
import net.osmand.IProgress;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
@ -35,7 +35,6 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.BaseExpandableListAdapter;
@ -44,12 +43,11 @@ import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
public class LocalIndexesActivity extends ExpandableListActivity {
private AsyncTask<Activity, LocalIndexInfo, List<LocalIndexInfo>> asyncLoader;
private LoadLocalIndexTask asyncLoader;
private LocalIndexesAdapter listAdapter;
private LoadLocalIndexDescriptionTask descriptionLoader;
private LocalIndexOperationTask operationTask;
@ -61,17 +59,23 @@ public class LocalIndexesActivity extends ExpandableListActivity {
protected static int BACKUP_OPERATION = 2;
protected static int RESTORE_OPERATION = 3;
@SuppressWarnings("unchecked")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.local_index);
LoadLocalIndexTask task = new LoadLocalIndexTask();
asyncLoader = task.execute(this);
descriptionLoader = new LoadLocalIndexDescriptionTask();
listAdapter = new LocalIndexesAdapter();
Object indexes = getLastNonConfigurationInstance();
asyncLoader = new LoadLocalIndexTask();
if(indexes instanceof List<?>){
asyncLoader.setResult((List<LocalIndexInfo>) indexes);
} else {
asyncLoader.execute(this);
}
findViewById(R.id.DownloadButton).setOnClickListener(new View.OnClickListener() {
@Override
@ -84,30 +88,33 @@ public class LocalIndexesActivity extends ExpandableListActivity {
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
long packedPos = ((ExpandableListContextMenuInfo)menuInfo).packedPosition;
final LocalIndexInfo point = (LocalIndexInfo) listAdapter.getChild(ExpandableListView.getPackedPositionGroup(packedPos),
ExpandableListView.getPackedPositionChild(packedPos));
if(point.getGpxFile() != null){
int group = ExpandableListView.getPackedPositionGroup(packedPos);
int child = ExpandableListView.getPackedPositionChild(packedPos);
if (child >= 0 && group >= 0) {
final LocalIndexInfo point = (LocalIndexInfo) listAdapter.getChild(group, child);
if (point != null && point.getGpxFile() != null) {
Location loc = point.getGpxFile().findFistLocation();
if (loc != null) {
OsmandSettings.getOsmandSettings(LocalIndexesActivity.this).setMapLocationToShow(loc.getLatitude(),loc.getLongitude());
OsmandSettings.getOsmandSettings(LocalIndexesActivity.this).setMapLocationToShow(loc.getLatitude(),
loc.getLongitude());
}
((OsmandApplication) getApplication()).setGpxFileToDisplay(point.getGpxFile());
MapActivity.launchMapActivityMoveToTop(LocalIndexesActivity.this);
}
}
}
});
setListAdapter(listAdapter);
}
public class LoadLocalIndexTask extends AsyncTask<Activity, LocalIndexInfo, List<LocalIndexInfo>> {
List<LocalIndexInfo> progress = new ArrayList<LocalIndexInfo>();
private List<LocalIndexInfo> result;
@Override
protected List<LocalIndexInfo> doInBackground(Activity... params) {
LocalIndexHelper helper = new LocalIndexHelper((OsmandApplication) getApplication());
progress.clear();
return helper.getAllLocalIndexData(this);
}
@ -128,11 +135,25 @@ public class LocalIndexesActivity extends ExpandableListActivity {
listAdapter.notifyDataSetChanged();
}
public void setResult(List<LocalIndexInfo> result) {
this.result = result;
for (LocalIndexInfo v : result) {
listAdapter.addLocalIndexInfo(v);
}
listAdapter.notifyDataSetChanged();
onPostExecute(result);
}
@Override
protected void onPostExecute(List<LocalIndexInfo> result) {
this.result = result;
findViewById(R.id.ProgressBar).setVisibility(View.GONE);
}
public List<LocalIndexInfo> getResult() {
return result;
}
}
public class LocalIndexOperationTask extends AsyncTask<LocalIndexInfo, LocalIndexInfo, String> {
@ -240,7 +261,11 @@ public class LocalIndexesActivity extends ExpandableListActivity {
protected void onPostExecute(String result) {
findViewById(R.id.ProgressBar).setVisibility(View.GONE);
Toast.makeText(LocalIndexesActivity.this, result, Toast.LENGTH_LONG).show();
listAdapter.clear();
asyncLoader = new LoadLocalIndexTask();
asyncLoader.execute(LocalIndexesActivity.this);
reloadIndexes();
}
}
@ -303,7 +328,13 @@ public class LocalIndexesActivity extends ExpandableListActivity {
descriptionLoader.cancel(true);
}
@Override
public Object onRetainNonConfigurationInstance() {
if(asyncLoader != null){
return asyncLoader.getResult();
}
return super.onRetainNonConfigurationInstance();
}
@Override
@ -341,6 +372,13 @@ public class LocalIndexesActivity extends ExpandableListActivity {
closeSelectionMode();
}
private void collapseAllGroups() {
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
getExpandableListView().collapseGroup(i);
}
}
private void openSelectionMode(final int actionResId){
final String actionButton = getString(actionResId);
if(listAdapter.getGroupCount() == 0){
@ -348,8 +386,7 @@ public class LocalIndexesActivity extends ExpandableListActivity {
Toast.makeText(LocalIndexesActivity.this, getString(R.string.local_index_no_items_to_do, actionButton.toLowerCase()), Toast.LENGTH_SHORT).show();
return;
}
collapseAllGroups();
selectionMode = true;
selectedItems.clear();
Button action = (Button) findViewById(R.id.ActionButton);
@ -403,6 +440,7 @@ public class LocalIndexesActivity extends ExpandableListActivity {
findViewById(R.id.CancelButton).setVisibility(View.GONE);
findViewById(R.id.ActionButton).setVisibility(View.GONE);
listAdapter.cancelFilter();
collapseAllGroups();
listAdapter.notifyDataSetChanged();
}
@ -472,7 +510,14 @@ public class LocalIndexesActivity extends ExpandableListActivity {
private MessageFormat formatMb;
public LocalIndexesAdapter() {
formatMb = new MessageFormat("{0, number,##.#} MB");
formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
}
public void clear() {
data.clear();
category.clear();
filterCategory = null;
notifyDataSetChanged();
}
public LocalIndexInfo findCategory(LocalIndexInfo val, boolean backuped){
@ -642,10 +687,32 @@ public class LocalIndexesActivity extends ExpandableListActivity {
}
StringBuilder t = new StringBuilder(group.getType().getHumanString(LocalIndexesActivity.this));
if (group.isBackupedData()) {
t.append("* ");
t.append(" - ").append(getString(R.string.local_indexes_cat_backup));
}
TextView nameView = ((TextView) v.findViewById(R.id.local_index_category_name));
t.append(" [").append(getChildrenCount(groupPosition)).append(" ").append(getString(R.string.local_index_items)).append("]");
t.append(" [").append(getChildrenCount(groupPosition));
if(getString(R.string.local_index_items).length() > 0){
t.append(" ").append(getString(R.string.local_index_items));
}
if(getString(R.string.local_index_items).length() > 0){
t.append(" ").append(getString(R.string.local_index_items));
}
List<LocalIndexInfo> list = data.get(group);
int size = 0;
for(int i=0; i<list.size(); i++){
int sz = list.get(i).getSize();
if(sz < 0){
size = 0;
break;
} else {
size += sz;
}
}
size = size / (1 << 10);
if(size > 0){
t.append(", ").append(size).append(" MB");
}
t.append("]");
nameView.setText(t.toString());
if (!group.isBackupedData()) {
nameView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);

View file

@ -35,6 +35,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Handler;
import android.text.format.DateFormat;
import android.util.Log;

View file

@ -6,7 +6,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@ -23,7 +22,6 @@ import net.osmand.osm.MapUtils;
import net.osmand.plus.R;
import net.osmand.plus.activities.RoutingHelper.RouteDirectionInfo;
import net.osmand.plus.activities.RoutingHelper.TurnType;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.router.BicycleRouter;
import net.osmand.router.BinaryRoutePlanner;
import net.osmand.router.CarRouter;
@ -180,6 +178,36 @@ public class RouteProvider {
try {
RouteCalculationResult res;
if(gpxRoute != null && !gpxRoute.isEmpty()){
res = calculateGpxRoute(start, end, gpxRoute);
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else if (type == RouteService.YOURS) {
res = findYOURSRoute(start, end, mode, fast);
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else if (type == RouteService.OSMAND) {
res = findVectorMapsRoute(start, end, mode, fast, (OsmandApplication)ctx.getApplicationContext());
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else {
res = findCloudMadeRoute(start, end, mode, ctx, fast);
// for test purpose
addMissingTurnsToRoute(res, start, end, mode, ctx);
}
if(log.isInfoEnabled() && res.locations != null){
log.info("Finding route contained " + res.locations.size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return res;
} catch (IOException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
} catch (ParserConfigurationException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
} catch (SAXException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
}
}
return new RouteCalculationResult(null);
}
private RouteCalculationResult calculateGpxRoute(Location start, LatLon end, List<Location> gpxRoute) {
RouteCalculationResult res;
// get the closest point to start and to end
float minDist = Integer.MAX_VALUE;
int startI = 0;
@ -209,31 +237,7 @@ public class RouteProvider {
}
}
res = new RouteCalculationResult(new ArrayList<Location>(gpxRoute.subList(startI, endI)), null, start, end, null);
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else if (type == RouteService.YOURS) {
res = findYOURSRoute(start, end, mode, fast);
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else if (type == RouteService.OSMAND) {
res = findVectorMapsRoute(start, end, mode, fast, (OsmandApplication)ctx.getApplicationContext());
addMissingTurnsToRoute(res, start, end, mode, ctx);
} else {
res = findCloudMadeRoute(start, end, mode, ctx, fast);
// for test purpose
addMissingTurnsToRoute(res, start, end, mode, ctx);
}
if(log.isInfoEnabled() && res.locations != null){
log.info("Finding route contained " + res.locations.size() + " points for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return res;
} catch (IOException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
} catch (ParserConfigurationException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
} catch (SAXException e) {
log.error("Failed to find route ", e); //$NON-NLS-1$
}
}
return new RouteCalculationResult(null);
}
protected String getString(Context ctx, int resId){
@ -579,7 +583,7 @@ public class RouteProvider {
URLConnection connection = url.openConnection();
DocumentBuilder dom = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = dom.parse(new InputSource(new InputStreamReader(connection.getInputStream())));
// TODO how to find that error occurred ? API gpx doesn't say nothing
// TODO how to find that error occurred ? Gpx API doesn't say anything
NodeList list = doc.getElementsByTagName("wpt"); //$NON-NLS-1$
for (int i = 0; i < list.getLength(); i++) {
Element item = (Element) list.item(i);