implement zip/unzip files for downloading
git-svn-id: https://osmand.googlecode.com/svn/trunk@309 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
e94b2b8350
commit
e16371d336
8 changed files with 153 additions and 70 deletions
|
@ -19,7 +19,10 @@ public class ToDoConstants {
|
||||||
// 60. Audio guidance for routing !
|
// 60. Audio guidance for routing !
|
||||||
// 68. Implement service to app work with screen offline
|
// 68. Implement service to app work with screen offline
|
||||||
// (introduce special settings how often update location to monitoring & audio guidance)
|
// (introduce special settings how often update location to monitoring & audio guidance)
|
||||||
|
// 69. Multitouch zoom
|
||||||
|
// Improvement : Show stops in the transport route on the map
|
||||||
|
|
||||||
|
// Not clear if it is really needed
|
||||||
// 43. Enable poi filter by name
|
// 43. Enable poi filter by name
|
||||||
// 58. Upload/Download zip-index from site & unzip them on phone
|
// 58. Upload/Download zip-index from site & unzip them on phone
|
||||||
// 45. Get clear <Use internet> settings. Move that setting on top settings screen.
|
// 45. Get clear <Use internet> settings. Move that setting on top settings screen.
|
||||||
|
@ -27,6 +30,7 @@ public class ToDoConstants {
|
||||||
// (would you like to use internet for that operation - if using internet is not checked).
|
// (would you like to use internet for that operation - if using internet is not checked).
|
||||||
// Internet using now for : edit POI osm, show osm bugs layer, download tiles.
|
// Internet using now for : edit POI osm, show osm bugs layer, download tiles.
|
||||||
|
|
||||||
|
// Unscheduled (complex)
|
||||||
// 66. Transport routing (show next stop, total distance, show stop get out) (?).
|
// 66. Transport routing (show next stop, total distance, show stop get out) (?).
|
||||||
// 64. Traffic information (?)
|
// 64. Traffic information (?)
|
||||||
// 65. Intermediate points - for better control routing, to avoid traffic jam ...(?)
|
// 65. Intermediate points - for better control routing, to avoid traffic jam ...(?)
|
||||||
|
@ -34,15 +38,14 @@ public class ToDoConstants {
|
||||||
// 63. Support simple offline routing(require new index file) (?)
|
// 63. Support simple offline routing(require new index file) (?)
|
||||||
|
|
||||||
|
|
||||||
// FIXME BUGS Android
|
// BUGS Android
|
||||||
// 1. Improvement : Show stops in the transport route
|
|
||||||
// 2. Pinch zoom !!!
|
|
||||||
|
|
||||||
// TODO swing
|
// TODO swing
|
||||||
// 9. Fix issues with big files (such as netherlands) - save memory (!) - very slow due to transport index !
|
// 9. Fix issues with big files (such as netherlands) - save memory (!) - very slow due to transport index !
|
||||||
// Current result : for big file (1 - task 60-80% time, 90% memory)
|
// Current result : for big file (1 - task 60-80% time, 90% memory) (?)
|
||||||
// 1. Download tiles without using dir tiles (?)
|
// 1. Download tiles without using dir tiles (?)
|
||||||
// 10. Improve address indexing (use relations).
|
// 10. Improve address indexing (use relations). (?)
|
||||||
// use relation "a6" (to accumulate streets!), "a3" to read all cities & define boundaries for city (& define that street in city).
|
// use relation "a6" (to accumulate streets!), "a3" to read all cities & define boundaries for city (& define that street in city).
|
||||||
|
|
||||||
// BUGS Swing
|
// BUGS Swing
|
||||||
|
|
|
@ -22,8 +22,11 @@ public class DownloaderIndexFromGoogleCode {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws URISyntaxException, IOException {
|
public static void main(String[] args) throws URISyntaxException, IOException {
|
||||||
Map<String, String> indexFiles = DownloaderIndexFromGoogleCode.getIndexFiles(new String[] { IndexConstants.ADDRESS_INDEX_EXT,
|
Map<String, String> indexFiles = DownloaderIndexFromGoogleCode.getIndexFiles(
|
||||||
IndexConstants.POI_INDEX_EXT, IndexConstants.TRANSPORT_INDEX_EXT }, new String[] {
|
new String[] { IndexConstants.ADDRESS_INDEX_EXT, IndexConstants.POI_INDEX_EXT, IndexConstants.TRANSPORT_INDEX_EXT,
|
||||||
|
IndexConstants.ADDRESS_INDEX_EXT_ZIP, IndexConstants.POI_INDEX_EXT_ZIP, IndexConstants.TRANSPORT_INDEX_EXT_ZIP,},
|
||||||
|
new String[] { IndexConstants.ADDRESS_TABLE_VERSION + "", IndexConstants.POI_TABLE_VERSION + "", //$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
IndexConstants.TRANSPORT_TABLE_VERSION + "" , //$NON-NLS-1$
|
||||||
IndexConstants.ADDRESS_TABLE_VERSION + "", IndexConstants.POI_TABLE_VERSION + "", //$NON-NLS-1$//$NON-NLS-2$
|
IndexConstants.ADDRESS_TABLE_VERSION + "", IndexConstants.POI_TABLE_VERSION + "", //$NON-NLS-1$//$NON-NLS-2$
|
||||||
IndexConstants.TRANSPORT_TABLE_VERSION + "" }); //$NON-NLS-1$
|
IndexConstants.TRANSPORT_TABLE_VERSION + "" }); //$NON-NLS-1$
|
||||||
System.out.println(indexFiles);
|
System.out.println(indexFiles);
|
||||||
|
@ -31,7 +34,7 @@ public class DownloaderIndexFromGoogleCode {
|
||||||
|
|
||||||
private static StringBuilder getContent() {
|
private static StringBuilder getContent() {
|
||||||
try {
|
try {
|
||||||
URL url = new URL("http://code.google.com/p/osmand/downloads/list?num=500&start=0"); //$NON-NLS-1$
|
URL url = new URL("http://code.google.com/p/osmand/downloads/list?num=1500&start=0"); //$NON-NLS-1$
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.osmand.data.index;
|
package com.osmand.data.index;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -12,6 +13,8 @@ import java.util.Date;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
@ -61,20 +64,19 @@ public class IndexBatchCreator {
|
||||||
// us states
|
// us states
|
||||||
// TODO address
|
// TODO address
|
||||||
protected static final String[] usStates = new String[] {
|
protected static final String[] usStates = new String[] {
|
||||||
"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut",
|
// "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut",
|
||||||
"Delaware", "District_of_Columbia", "Florida", "Georgia", "Guantanamo_Bay", "Hawaii",
|
// "Delaware", "District_of_Columbia", "Florida", "Georgia", "Guantanamo_Bay", "Hawaii",
|
||||||
"Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
|
// "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
|
||||||
"Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
|
// "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
|
||||||
"Montana", "Nebraska", "Nevada", "New_Hampshire", "New_Jersey", "New_Mexico",
|
// "Montana", "Nebraska", "Nevada", "New_Hampshire", "New_Jersey", "New_Mexico",
|
||||||
"New_York", "North_Carolina", "North_Dakota", "Ohio", "Oklahoma", "Oregon",
|
// "New_York", "North_Carolina", "North_Dakota", "Ohio", "Oklahoma", "Oregon",
|
||||||
"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee",
|
// "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee",
|
||||||
"Texas", "Utah", "Vermont", "Virginia", "Washington", "West_Virginia", "Wisconsin", "Wyoming",
|
// "Texas", "Utah", "Vermont", "Virginia", "Washington", "West_Virginia", "Wisconsin", "Wyoming",
|
||||||
};
|
};
|
||||||
// TODO address
|
|
||||||
protected static final String[] canadaStates = new String[] {
|
protected static final String[] canadaStates = new String[] {
|
||||||
"Alberta","British_Columbia","Manitoba","New_Brunswick","Newfoundland",
|
// "Alberta","British_Columbia","Manitoba","New_Brunswick","Newfoundland",
|
||||||
"Nova_Scotia","Nunavut", "Nw_Territories","Ontario","Pr_Edwrd_Island",
|
// "Nova_Scotia","Nunavut", "Nw_Territories","Ontario","Pr_Edwrd_Island",
|
||||||
"Quebec","Saskatchewan","Yukon",
|
// "Quebec","Saskatchewan","Yukon",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -266,24 +268,51 @@ public class IndexBatchCreator {
|
||||||
MessageFormat format = new MessageFormat("{0,date,dd.MM.yyyy} : {1, number,##.#} MB", Locale.US);
|
MessageFormat format = new MessageFormat("{0,date,dd.MM.yyyy} : {1, number,##.#} MB", Locale.US);
|
||||||
String summary;
|
String summary;
|
||||||
double mbLengh = (double)f.length() / MB;
|
double mbLengh = (double)f.length() / MB;
|
||||||
|
String regionName;
|
||||||
String descriptionFile = "{"+format.format(new Object[]{new Date(f.lastModified()), mbLengh})+"}";
|
if(f.getName().endsWith(IndexConstants.POI_INDEX_EXT) || f.getName().endsWith(IndexConstants.POI_INDEX_EXT_ZIP)){
|
||||||
if(f.getName().endsWith(IndexConstants.POI_INDEX_EXT)){
|
regionName = f.getName().substring(0, f.getName().length() - IndexConstants.POI_INDEX_EXT.length() - 2);
|
||||||
String regionName = f.getName().substring(0, f.getName().length() - IndexConstants.POI_INDEX_EXT.length() - 2);
|
summary = "POI index for " ;
|
||||||
summary = "POI index for " + regionName + " " + descriptionFile;
|
} else if(f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT) || f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT_ZIP)){
|
||||||
} else if(f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)){
|
regionName = f.getName().substring(0, f.getName().length() - IndexConstants.ADDRESS_INDEX_EXT.length() - 2);
|
||||||
String regionName = f.getName().substring(0, f.getName().length() - IndexConstants.ADDRESS_INDEX_EXT.length() - 2);
|
summary = "Adress index for " ;
|
||||||
summary = "Adress index for " + regionName + " " + descriptionFile;
|
} else if(f.getName().endsWith(IndexConstants.TRANSPORT_INDEX_EXT) || f.getName().endsWith(IndexConstants.TRANSPORT_INDEX_EXT_ZIP)){
|
||||||
} else if(f.getName().endsWith(IndexConstants.TRANSPORT_INDEX_EXT)){
|
regionName = f.getName().substring(0, f.getName().length() - IndexConstants.TRANSPORT_INDEX_EXT.length() - 2);
|
||||||
String regionName = f.getName().substring(0, f.getName().length() - IndexConstants.TRANSPORT_INDEX_EXT.length() - 2);
|
summary = "Transport index for ";
|
||||||
summary = "Transport index for " + regionName + " " + descriptionFile;
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(mbLengh > 5 && f.getName().endsWith(".odb")){
|
||||||
|
String zipFileName = f.getName().subSequence(0, f.getName().length() - 4)+".zip";
|
||||||
|
File zFile = new File(f.getParentFile(), zipFileName);
|
||||||
|
log.info("Zipping file " + f.getName());
|
||||||
|
try {
|
||||||
|
ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zFile));
|
||||||
|
zout.setLevel(9);
|
||||||
|
zout.putNextEntry(new ZipEntry(f.getName()));
|
||||||
|
FileInputStream is = new FileInputStream(f);
|
||||||
|
byte[] BUFFER = new byte[8192];
|
||||||
|
int read = 0;
|
||||||
|
while((read = is.read(BUFFER)) != -1){
|
||||||
|
zout.write(BUFFER, 0, read);
|
||||||
|
}
|
||||||
|
zout.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Exception while zipping file");
|
||||||
|
}
|
||||||
|
if(f.delete()){
|
||||||
|
log.info("Source odb file was deleted");
|
||||||
|
}
|
||||||
|
f = zFile;
|
||||||
|
|
||||||
|
}
|
||||||
|
mbLengh = (double)f.length() / MB;
|
||||||
if(mbLengh > 100){
|
if(mbLengh > 100){
|
||||||
System.err.println("ERROR : file " + f.getName() + " exceeded 90 mb!!! Could not be uploaded.");
|
System.err.println("ERROR : file " + f.getName() + " exceeded 100 mb!!! Could not be uploaded.");
|
||||||
return; // restriction for google code
|
return; // restriction for google code
|
||||||
}
|
}
|
||||||
|
String descriptionFile = "{"+format.format(new Object[]{new Date(f.lastModified()), mbLengh})+"}";
|
||||||
|
summary += regionName + " " + descriptionFile;
|
||||||
|
|
||||||
alreadyUploadedFiles.add(f.getName());
|
alreadyUploadedFiles.add(f.getName());
|
||||||
GoogleCodeUploadIndex uploader = new GoogleCodeUploadIndex();
|
GoogleCodeUploadIndex uploader = new GoogleCodeUploadIndex();
|
||||||
uploader.setFileName(f.getAbsolutePath());
|
uploader.setFileName(f.getAbsolutePath());
|
||||||
|
|
|
@ -16,6 +16,10 @@ public class IndexConstants {
|
||||||
public static final String ADDRESS_INDEX_EXT = ".addr.odb"; //$NON-NLS-1$
|
public static final String ADDRESS_INDEX_EXT = ".addr.odb"; //$NON-NLS-1$
|
||||||
public static final String TRANSPORT_INDEX_EXT = ".trans.odb"; //$NON-NLS-1$
|
public static final String TRANSPORT_INDEX_EXT = ".trans.odb"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
public static final String POI_INDEX_EXT_ZIP = ".poi.zip"; //$NON-NLS-1$
|
||||||
|
public static final String ADDRESS_INDEX_EXT_ZIP = ".addr.zip"; //$NON-NLS-1$
|
||||||
|
public static final String TRANSPORT_INDEX_EXT_ZIP = ".trans.zip"; //$NON-NLS-1$
|
||||||
|
|
||||||
public interface IndexColumn {
|
public interface IndexColumn {
|
||||||
public boolean isIndex();
|
public boolean isIndex();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.osmand" android:versionName="0.2.1" android:versionCode="4">
|
package="com.osmand" android:versionName="0.2.2" android:versionCode="5">
|
||||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||||
android:debuggable="true" android:name=".activities.OsmandApplication" android:description="@string/app_description">
|
android:debuggable="true" android:name=".activities.OsmandApplication" android:description="@string/app_description">
|
||||||
<activity android:name=".activities.MainMenuActivity"
|
<activity android:name=".activities.MainMenuActivity"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<string name="unzipping_file">Файл распаковывается</string>
|
||||||
<string name="route_tr">Поверните направо и двигайтесь</string>
|
<string name="route_tr">Поверните направо и двигайтесь</string>
|
||||||
<string name="route_tshr">Поверните резко направо и двигайтесь</string>
|
<string name="route_tshr">Поверните резко направо и двигайтесь</string>
|
||||||
<string name="route_tslr">Поверните направо и двигайтесь</string>
|
<string name="route_tslr">Поверните направо и двигайтесь</string>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<string name="unzipping_file">File is unzipping</string>
|
||||||
<string name="route_tr">Turn right and go</string>
|
<string name="route_tr">Turn right and go</string>
|
||||||
<string name="route_tshr">Turn sharply right and go</string>
|
<string name="route_tshr">Turn sharply right and go</string>
|
||||||
<string name="route_tslr">Turn slightly right and go</string>
|
<string name="route_tslr">Turn slightly right and go</string>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.osmand.activities;
|
package com.osmand.activities;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -13,6 +14,8 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
@ -74,10 +77,14 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
protected Map<String, String> downloadIndex(){
|
protected Map<String, String> downloadIndex(){
|
||||||
try {
|
try {
|
||||||
log.debug("Start loading list of index files"); //$NON-NLS-1$
|
log.debug("Start loading list of index files"); //$NON-NLS-1$
|
||||||
Map<String, String> indexFiles = DownloaderIndexFromGoogleCode.getIndexFiles(new String[] { IndexConstants.ADDRESS_INDEX_EXT,
|
Map<String, String> indexFiles = DownloaderIndexFromGoogleCode.getIndexFiles(new String[] {
|
||||||
IndexConstants.POI_INDEX_EXT, IndexConstants.TRANSPORT_INDEX_EXT, }, new String[] {
|
IndexConstants.ADDRESS_INDEX_EXT, IndexConstants.POI_INDEX_EXT, IndexConstants.TRANSPORT_INDEX_EXT,
|
||||||
|
IndexConstants.ADDRESS_INDEX_EXT_ZIP, IndexConstants.POI_INDEX_EXT_ZIP, IndexConstants.TRANSPORT_INDEX_EXT_ZIP, },
|
||||||
|
new String[] {
|
||||||
IndexConstants.ADDRESS_TABLE_VERSION + "", IndexConstants.POI_TABLE_VERSION + "",//$NON-NLS-1$//$NON-NLS-2$
|
IndexConstants.ADDRESS_TABLE_VERSION + "", IndexConstants.POI_TABLE_VERSION + "",//$NON-NLS-1$//$NON-NLS-2$
|
||||||
IndexConstants.TRANSPORT_TABLE_VERSION + "",}); //$NON-NLS-1$
|
IndexConstants.TRANSPORT_TABLE_VERSION + "", //$NON-NLS-1$
|
||||||
|
IndexConstants.ADDRESS_TABLE_VERSION + "", IndexConstants.POI_TABLE_VERSION + "",//$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
IndexConstants.TRANSPORT_TABLE_VERSION + ""}); //$NON-NLS-1$
|
||||||
if (indexFiles != null && !indexFiles.isEmpty()) {
|
if (indexFiles != null && !indexFiles.isEmpty()) {
|
||||||
return indexFiles;
|
return indexFiles;
|
||||||
} else {
|
} else {
|
||||||
|
@ -129,18 +136,27 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
if(key.endsWith(IndexConstants.ADDRESS_INDEX_EXT)){
|
if(key.endsWith(IndexConstants.ADDRESS_INDEX_EXT)){
|
||||||
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.ADDRESS_PATH);
|
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.ADDRESS_PATH);
|
||||||
regionName += IndexConstants.ADDRESS_INDEX_EXT;
|
regionName += IndexConstants.ADDRESS_INDEX_EXT;
|
||||||
|
} else if(key.endsWith(IndexConstants.ADDRESS_INDEX_EXT_ZIP)){
|
||||||
|
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.ADDRESS_PATH);
|
||||||
|
regionName += IndexConstants.ADDRESS_INDEX_EXT_ZIP;
|
||||||
} else if(key.endsWith(IndexConstants.POI_INDEX_EXT)){
|
} else if(key.endsWith(IndexConstants.POI_INDEX_EXT)){
|
||||||
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.POI_PATH);
|
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.POI_PATH);
|
||||||
regionName += IndexConstants.POI_INDEX_EXT;
|
regionName += IndexConstants.POI_INDEX_EXT;
|
||||||
|
} else if(key.endsWith(IndexConstants.POI_INDEX_EXT_ZIP)){
|
||||||
|
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.POI_PATH);
|
||||||
|
regionName += IndexConstants.POI_INDEX_EXT_ZIP;
|
||||||
} else if(key.endsWith(IndexConstants.TRANSPORT_INDEX_EXT)){
|
} else if(key.endsWith(IndexConstants.TRANSPORT_INDEX_EXT)){
|
||||||
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.TRANSPORT_PATH);
|
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.TRANSPORT_PATH);
|
||||||
regionName += IndexConstants.TRANSPORT_INDEX_EXT;
|
regionName += IndexConstants.TRANSPORT_INDEX_EXT;
|
||||||
|
} else if(key.endsWith(IndexConstants.TRANSPORT_INDEX_EXT_ZIP)){
|
||||||
|
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.TRANSPORT_PATH);
|
||||||
|
regionName += IndexConstants.TRANSPORT_INDEX_EXT_ZIP;
|
||||||
}
|
}
|
||||||
if(parent != null){
|
if(parent != null){
|
||||||
parent.mkdirs();
|
parent.mkdirs();
|
||||||
}
|
}
|
||||||
if(parent == null || !parent.exists()){
|
if(parent == null || !parent.exists()){
|
||||||
Toast.makeText(DownloadIndexActivity.this, getString(R.string.download_sd_dir_not_accessible), Toast.LENGTH_LONG);
|
Toast.makeText(DownloadIndexActivity.this, getString(R.string.download_sd_dir_not_accessible), Toast.LENGTH_LONG).show();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
File file = new File(parent, regionName);
|
File file = new File(parent, regionName);
|
||||||
|
@ -158,7 +174,6 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
FileOutputStream out = new FileOutputStream(file);
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
try {
|
|
||||||
URL url = DownloaderIndexFromGoogleCode.getInputStreamToLoadIndex(key);
|
URL url = DownloaderIndexFromGoogleCode.getInputStreamToLoadIndex(key);
|
||||||
URLConnection conn = url.openConnection();
|
URLConnection conn = url.openConnection();
|
||||||
InputStream is = conn.getInputStream();
|
InputStream is = conn.getInputStream();
|
||||||
|
@ -169,22 +184,46 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
out.write(buffer, 0, read);
|
out.write(buffer, 0, read);
|
||||||
impl.progress(read);
|
impl.progress(read);
|
||||||
}
|
}
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
File toIndex = file;
|
||||||
|
if(file.getName().endsWith(".zip")){ //$NON-NLS-1$
|
||||||
|
impl.startTask(getString(R.string.unzipping_file), -1);
|
||||||
|
toIndex = new File(file.getParentFile(), file.getName().substring(0, file.getName().length() - 3) + "odb"); //$NON-NLS-1$
|
||||||
|
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(file));
|
||||||
|
ZipEntry entry = null;
|
||||||
|
boolean found = false;
|
||||||
|
while(!found) {
|
||||||
|
if(entry != null){
|
||||||
|
zipIn.closeEntry();
|
||||||
|
}
|
||||||
|
entry = zipIn.getNextEntry();
|
||||||
|
found = entry == null || entry.getName().endsWith(".odb"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
if(entry != null){
|
||||||
|
out = new FileOutputStream(toIndex);
|
||||||
|
while((read = zipIn.read(buffer)) != -1){
|
||||||
|
out.write(buffer, 0, read);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
zipIn.close();
|
||||||
|
file.delete(); // zip is no needed more
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<String> warnings = new ArrayList<String>();
|
ArrayList<String> warnings = new ArrayList<String>();
|
||||||
if(file.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)){
|
if(toIndex.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)){
|
||||||
ResourceManager.getResourceManager().indexingAddress(impl, warnings, file);
|
ResourceManager.getResourceManager().indexingAddress(impl, warnings, toIndex);
|
||||||
} else if(file.getName().endsWith(IndexConstants.POI_INDEX_EXT)){
|
} else if(toIndex.getName().endsWith(IndexConstants.POI_INDEX_EXT)){
|
||||||
ResourceManager.getResourceManager().indexingPoi(impl, warnings, file);
|
ResourceManager.getResourceManager().indexingPoi(impl, warnings, toIndex);
|
||||||
} else if(file.getName().endsWith(IndexConstants.TRANSPORT_INDEX_EXT)){
|
} else if(toIndex.getName().endsWith(IndexConstants.TRANSPORT_INDEX_EXT)){
|
||||||
ResourceManager.getResourceManager().indexingTransport(impl, warnings, file);
|
ResourceManager.getResourceManager().indexingTransport(impl, warnings, toIndex);
|
||||||
}
|
}
|
||||||
if(warnings.isEmpty()){
|
if(warnings.isEmpty()){
|
||||||
showWarning(getString(R.string.download_index_success));
|
showWarning(getString(R.string.download_index_success));
|
||||||
} else {
|
} else {
|
||||||
showWarning(warnings.get(0));
|
showWarning(warnings.get(0));
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Exception ocurred", e); //$NON-NLS-1$
|
log.error("Exception ocurred", e); //$NON-NLS-1$
|
||||||
showWarning(getString(R.string.error_io_error));
|
showWarning(getString(R.string.error_io_error));
|
||||||
|
@ -227,15 +266,18 @@ public class DownloadIndexActivity extends ListActivity {
|
||||||
Entry<String, String> e = getItem(position);
|
Entry<String, String> e = getItem(position);
|
||||||
int l = e.getKey().lastIndexOf('_');
|
int l = e.getKey().lastIndexOf('_');
|
||||||
String s = ""; //$NON-NLS-1$
|
String s = ""; //$NON-NLS-1$
|
||||||
if(e.getKey().endsWith(IndexConstants.POI_INDEX_EXT)){
|
if(e.getKey().endsWith(IndexConstants.POI_INDEX_EXT) || e.getKey().endsWith(IndexConstants.POI_INDEX_EXT_ZIP)){
|
||||||
s = getString(R.string.poi);
|
s = getString(R.string.poi);
|
||||||
} else if(e.getKey().endsWith(IndexConstants.ADDRESS_INDEX_EXT)){
|
} else if(e.getKey().endsWith(IndexConstants.ADDRESS_INDEX_EXT) || e.getKey().endsWith(IndexConstants.ADDRESS_INDEX_EXT_ZIP)){
|
||||||
s = getString(R.string.address);
|
s = getString(R.string.address);
|
||||||
} else if(e.getKey().endsWith(IndexConstants.TRANSPORT_INDEX_EXT)){
|
} else if(e.getKey().endsWith(IndexConstants.TRANSPORT_INDEX_EXT) || e.getKey().endsWith(IndexConstants.TRANSPORT_INDEX_EXT_ZIP)){
|
||||||
s = getString(R.string.transport);
|
s = getString(R.string.transport);
|
||||||
}
|
}
|
||||||
|
String name = e.getKey().substring(0, l).replace('_', ' ');
|
||||||
item.setText(s + "\n " + e.getKey().substring(0, l).replace('_', ' ')); //$NON-NLS-1$
|
if(e.getKey().endsWith(".zip")){ //$NON-NLS-1$
|
||||||
|
name += " (zip)"; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
item.setText(s + "\n " + name); //$NON-NLS-1$
|
||||||
description.setText(e.getValue().replace(':', '\n'));
|
description.setText(e.getValue().replace(':', '\n'));
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue