2 * Navit, a modular navigation system.
\r
3 * Copyright (C) 2005-2008 Navit Team
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * version 2 as published by the Free Software Foundation.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License
\r
15 * along with this program; if not, write to the
\r
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
\r
17 * Boston, MA 02110-1301, USA.
\r
20 package org.navitproject.navit;
\r
22 import java.io.BufferedInputStream;
\r
23 import java.io.BufferedOutputStream;
\r
24 import java.io.File;
\r
25 import java.io.FileOutputStream;
\r
26 import java.io.IOException;
\r
27 import java.io.InputStream;
\r
28 import java.net.HttpURLConnection;
\r
29 import java.net.URL;
\r
30 import java.text.DecimalFormat;
\r
31 import java.text.NumberFormat;
\r
33 import android.os.Bundle;
\r
34 import android.os.Handler;
\r
35 import android.os.Message;
\r
36 import android.util.Log;
\r
38 public class NavitMapDownloader
\r
40 public static class osm_map_values
\r
46 String map_name = "";
\r
47 long est_size_bytes = 0;
\r
48 String est_size_bytes_human_string = "";
\r
49 String text_for_select_list = "";
\r
51 public osm_map_values(String mapname, String lon_1, String lat_1, String lon_2, String lat_2,
\r
54 this.map_name = mapname;
\r
59 this.est_size_bytes = bytes_est;
\r
60 this.est_size_bytes_human_string = " ca. "
\r
61 + (int) ((float) (this.est_size_bytes) / 1024f / 1024f) + "MB";
\r
62 this.text_for_select_list = this.map_name + " " + this.est_size_bytes_human_string;
\r
67 * coords for predefined maps:
\r
69 * <a onclick='predefined(5.18,46.84,15.47,55.64)'>Germany</a>
\r
70 * <a onclick='predefined(2.08,48.87,7.78,54.52)'>BeNeLux</a>
\r
71 * <a onclick='predefined(9.4,46.32,17.21,49.1)'>Austria</a> 209 MBytes = 219152384 Bytes
\r
74 // define the maps here
\r
75 // name , lon1 , lat1 , lon2 , lat2, est. size in bytes
\r
77 * public static osm_map_values austria = new osm_map_values("Austria",
\r
78 * "9.4", "46.32", "17.21",
\r
79 * "49.1", 222000000);
\r
80 * public static osm_map_values benelux = new osm_map_values("BeNeLux",
\r
81 * "2.08", "48.87", "7.78",
\r
82 * "54.52", 530000000);
\r
83 * public static osm_map_values germany = new osm_map_values("Germany",
\r
84 * "5.18", "46.84", "15.47",
\r
85 * "55.64", 943000000);
\r
89 public static osm_map_values Whole_Planet = new osm_map_values(
\r
94 public static osm_map_values Africa = new osm_map_values(
\r
97 "37.4", 180836389L);
\r
98 public static osm_map_values Angola = new osm_map_values(
\r
101 "-5.3", 56041641L);
\r
102 public static osm_map_values Burundi = new osm_map_values(
\r
105 "-2.2", 56512924L);
\r
106 public static osm_map_values Democratic_Republic_of_the_Congo = new osm_map_values(
\r
107 "Democratic Republic of the Congo",
\r
111 public static osm_map_values Kenya = new osm_map_values(
\r
115 public static osm_map_values Lesotho = new osm_map_values(
\r
118 "-28.4", 54791041L);
\r
119 public static osm_map_values Madagascar = new osm_map_values(
\r
124 public static osm_map_values Nambia_Botswana = new osm_map_values(
\r
129 public static osm_map_values Reunion = new osm_map_values(
\r
132 "-20.9", 58537419L);
\r
133 public static osm_map_values Rwanda = new osm_map_values(
\r
136 "-1.0", 56313710L);
\r
137 public static osm_map_values South_Africa = new osm_map_values(
\r
142 public static osm_map_values Uganda = new osm_map_values(
\r
146 public static osm_map_values Asia = new osm_map_values(
\r
149 "82.4", 797725952L);
\r
150 public static osm_map_values China = new osm_map_values(
\r
153 "54.5", 259945160L);
\r
154 public static osm_map_values Cyprus = new osm_map_values(
\r
157 "35.8", 58585278L);
\r
158 public static osm_map_values India_Nepal = new osm_map_values(
\r
163 public static osm_map_values Indonesia = new osm_map_values(
\r
168 public static osm_map_values Iran = new osm_map_values(
\r
171 "40.4", 69561312L);
\r
172 public static osm_map_values Iraq = new osm_map_values(
\r
175 "37.4", 59146383L);
\r
176 public static osm_map_values Israel = new osm_map_values(
\r
179 "33.4", 65065351L);
\r
180 public static osm_map_values Japan_Korea_Taiwan = new osm_map_values(
\r
181 "Japan+Korea+Taiwan",
\r
185 public static osm_map_values Malasia_Singapore = new osm_map_values(
\r
186 "Malasia+Singapore",
\r
190 public static osm_map_values Mongolia = new osm_map_values(
\r
195 public static osm_map_values Thailand = new osm_map_values(
\r
200 public static osm_map_values Turkey = new osm_map_values(
\r
203 "42.8", 81758047L);
\r
204 public static osm_map_values UAE_Other = new osm_map_values(
\r
209 public static osm_map_values Australia = new osm_map_values(
\r
214 public static osm_map_values Tasmania = new osm_map_values(
\r
219 public static osm_map_values Victoria_New_South_Wales = new osm_map_values(
\r
220 "Victoria+New South Wales",
\r
224 public static osm_map_values New_Zealand = new osm_map_values(
\r
229 public static osm_map_values Europe = new osm_map_values(
\r
234 public static osm_map_values Western_Europe = new osm_map_values(
\r
239 public static osm_map_values Austria = new osm_map_values(
\r
242 "49.1", 222359992L);
\r
243 public static osm_map_values BeNeLux = new osm_map_values(
\r
248 public static osm_map_values Faroe_Islands = new osm_map_values(
\r
253 public static osm_map_values France = new osm_map_values(
\r
258 public static osm_map_values Germany = new osm_map_values(
\r
263 public static osm_map_values Bavaria = new osm_map_values(
\r
266 "49.7", 131799419L);
\r
267 public static osm_map_values Saxonia = new osm_map_values(
\r
270 "51.7", 112073909L);
\r
271 public static osm_map_values Germany_Austria_Switzerland = new osm_map_values(
\r
272 "Germany+Austria+Switzerland",
\r
276 public static osm_map_values Iceland = new osm_map_values(
\r
281 public static osm_map_values Ireland = new osm_map_values(
\r
286 public static osm_map_values Italy = new osm_map_values(
\r
291 public static osm_map_values Spain_Portugal = new osm_map_values(
\r
296 public static osm_map_values Mallorca = new osm_map_values(
\r
299 "40.2", 59700600L);
\r
300 public static osm_map_values Galicia = new osm_map_values(
\r
305 public static osm_map_values Scandinavia = new osm_map_values(
\r
310 public static osm_map_values Finland = new osm_map_values(
\r
313 "70.3", 128871467L);
\r
314 public static osm_map_values Denmark = new osm_map_values(
\r
319 public static osm_map_values Switzerland = new osm_map_values(
\r
324 public static osm_map_values UK = new osm_map_values(
\r
327 "61.2", 245161510L);
\r
328 public static osm_map_values Bulgaria = new osm_map_values(
\r
333 public static osm_map_values Czech_Republic = new osm_map_values(
\r
338 public static osm_map_values Croatia = new osm_map_values(
\r
341 "46.9", 99183280L);
\r
342 public static osm_map_values Estonia = new osm_map_values(
\r
345 "59.6", 79276178L);
\r
346 public static osm_map_values Greece = new osm_map_values(
\r
349 "37.8", 55486527L);
\r
350 public static osm_map_values Crete = new osm_map_values(
\r
353 "36.0", 57032630L);
\r
354 public static osm_map_values Hungary = new osm_map_values(
\r
359 public static osm_map_values Latvia = new osm_map_values(
\r
362 "58.1", 71490706L);
\r
363 public static osm_map_values Lithuania = new osm_map_values(
\r
368 public static osm_map_values Poland = new osm_map_values(
\r
371 "55.0", 266136768L);
\r
372 public static osm_map_values Romania = new osm_map_values(
\r
375 "48.4", 134525863L);
\r
376 public static osm_map_values North_America = new osm_map_values(
\r
381 public static osm_map_values Alaska = new osm_map_values(
\r
386 public static osm_map_values Canada = new osm_map_values(
\r
391 public static osm_map_values Hawaii = new osm_map_values(
\r
396 "22.85", 57311788L);
\r
397 public static osm_map_values USA__except_Alaska_and_Hawaii_ = new osm_map_values(
\r
398 "USA (except Alaska and Hawaii)",
\r
402 public static osm_map_values Nevada = new osm_map_values(
\r
407 public static osm_map_values Oregon = new osm_map_values(
\r
412 public static osm_map_values Washington_State = new osm_map_values(
\r
413 "Washington State",
\r
417 public static osm_map_values South_Middle_America = new osm_map_values(
\r
418 "South+Middle America",
\r
422 public static osm_map_values Argentina = new osm_map_values(
\r
427 public static osm_map_values Argentina_Chile = new osm_map_values(
\r
432 public static osm_map_values Bolivia = new osm_map_values(
\r
437 public static osm_map_values Brazil = new osm_map_values(
\r
440 "5.4", 105527899L);
\r
441 public static osm_map_values Cuba = new osm_map_values(
\r
444 "23.6", 56608942L);
\r
445 public static osm_map_values Colombia = new osm_map_values(
\r
450 public static osm_map_values Ecuador = new osm_map_values(
\r
455 public static osm_map_values Guyana_Suriname_Guyane_Francaise = new osm_map_values(
\r
456 "Guyana+Suriname+Guyane Francaise",
\r
460 public static osm_map_values Haiti_Republica_Dominicana = new osm_map_values(
\r
461 "Haiti+Republica Dominicana",
\r
465 public static osm_map_values Jamaica = new osm_map_values(
\r
470 public static osm_map_values Mexico = new osm_map_values(
\r
475 public static osm_map_values Paraguay = new osm_map_values(
\r
480 public static osm_map_values Peru = new osm_map_values(
\r
484 public static osm_map_values Uruguay = new osm_map_values(
\r
489 public static osm_map_values Venezuela = new osm_map_values(
\r
495 public static osm_map_values[] OSM_MAPS = new osm_map_values[]{
\r
496 Whole_Planet, Africa, Angola, Burundi, Democratic_Republic_of_the_Congo, Kenya, Lesotho,
\r
497 Madagascar, Nambia_Botswana, Reunion, Rwanda, South_Africa, Uganda, Asia, China, Cyprus,
\r
498 India_Nepal, Indonesia, Iran, Iraq, Israel, Japan_Korea_Taiwan, Malasia_Singapore,
\r
499 Mongolia, Nambia_Botswana, Thailand, Turkey, UAE_Other, Australia, Tasmania,
\r
500 Victoria_New_South_Wales, New_Zealand, Europe, Western_Europe, Austria, BeNeLux,
\r
501 Faroe_Islands, France, Germany, Bavaria, Saxonia, Germany_Austria_Switzerland, Iceland,
\r
502 Ireland, Italy, Spain_Portugal, Mallorca, Galicia, Scandinavia, Finland, Denmark,
\r
503 Switzerland, UK, Bulgaria, Czech_Republic, Croatia, Estonia, Greece, Crete, Hungary,
\r
504 Latvia, Lithuania, Poland, Romania, North_America, Alaska, Canada, Hawaii,
\r
505 USA__except_Alaska_and_Hawaii_, Nevada, Oregon, Washington_State, South_Middle_America,
\r
506 Argentina, Argentina_Chile, Bolivia, Brazil, Cuba, Colombia, Ecuador,
\r
507 Guyana_Suriname_Guyane_Francaise, Haiti_Republica_Dominicana, Jamaica, Mexico, Paraguay,
\r
508 Peru, Uruguay, Venezuela };
\r
509 public static String[] OSM_MAP_NAME_LIST = new String[]{
\r
510 Whole_Planet.map_name, Africa.map_name, Angola.map_name, Burundi.map_name,
\r
511 Democratic_Republic_of_the_Congo.map_name, Kenya.map_name, Lesotho.map_name,
\r
512 Madagascar.map_name, Nambia_Botswana.map_name, Reunion.map_name, Rwanda.map_name,
\r
513 South_Africa.map_name, Uganda.map_name, Asia.map_name, China.map_name, Cyprus.map_name,
\r
514 India_Nepal.map_name, Indonesia.map_name, Iran.map_name, Iraq.map_name, Israel.map_name,
\r
515 Japan_Korea_Taiwan.map_name, Malasia_Singapore.map_name, Mongolia.map_name,
\r
516 Nambia_Botswana.map_name, Thailand.map_name, Turkey.map_name, UAE_Other.map_name,
\r
517 Australia.map_name, Tasmania.map_name, Victoria_New_South_Wales.map_name,
\r
518 New_Zealand.map_name, Europe.map_name, Western_Europe.map_name, Austria.map_name,
\r
519 BeNeLux.map_name, Faroe_Islands.map_name, France.map_name, Germany.map_name,
\r
520 Bavaria.map_name, Saxonia.map_name, Germany_Austria_Switzerland.map_name,
\r
521 Iceland.map_name, Ireland.map_name, Italy.map_name, Spain_Portugal.map_name,
\r
522 Mallorca.map_name, Galicia.map_name, Scandinavia.map_name, Finland.map_name,
\r
523 Denmark.map_name, Switzerland.map_name, UK.map_name, Bulgaria.map_name,
\r
524 Czech_Republic.map_name, Croatia.map_name, Estonia.map_name, Greece.map_name,
\r
525 Crete.map_name, Hungary.map_name, Latvia.map_name, Lithuania.map_name, Poland.map_name,
\r
526 Romania.map_name, North_America.map_name, Alaska.map_name, Canada.map_name,
\r
527 Hawaii.map_name, USA__except_Alaska_and_Hawaii_.map_name, Nevada.map_name,
\r
528 Oregon.map_name, Washington_State.map_name, South_Middle_America.map_name,
\r
529 Argentina.map_name, Argentina_Chile.map_name, Bolivia.map_name, Brazil.map_name,
\r
530 Cuba.map_name, Colombia.map_name, Ecuador.map_name,
\r
531 Guyana_Suriname_Guyane_Francaise.map_name, Haiti_Republica_Dominicana.map_name,
\r
532 Jamaica.map_name, Mexico.map_name, Paraguay.map_name, Peru.map_name, Uruguay.map_name,
\r
533 Venezuela.map_name };
\r
535 public static String[] OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE = new String[]{
\r
536 Whole_Planet.text_for_select_list, Africa.text_for_select_list,
\r
537 Angola.text_for_select_list, Burundi.text_for_select_list,
\r
538 Democratic_Republic_of_the_Congo.text_for_select_list, Kenya.text_for_select_list,
\r
539 Lesotho.text_for_select_list, Madagascar.text_for_select_list,
\r
540 Nambia_Botswana.text_for_select_list, Reunion.text_for_select_list,
\r
541 Rwanda.text_for_select_list, South_Africa.text_for_select_list,
\r
542 Uganda.text_for_select_list, Asia.text_for_select_list, China.text_for_select_list,
\r
543 Cyprus.text_for_select_list, India_Nepal.text_for_select_list,
\r
544 Indonesia.text_for_select_list, Iran.text_for_select_list, Iraq.text_for_select_list,
\r
545 Israel.text_for_select_list, Japan_Korea_Taiwan.text_for_select_list,
\r
546 Malasia_Singapore.text_for_select_list, Mongolia.text_for_select_list,
\r
547 Nambia_Botswana.text_for_select_list, Thailand.text_for_select_list,
\r
548 Turkey.text_for_select_list, UAE_Other.text_for_select_list,
\r
549 Australia.text_for_select_list, Tasmania.text_for_select_list,
\r
550 Victoria_New_South_Wales.text_for_select_list, New_Zealand.text_for_select_list,
\r
551 Europe.text_for_select_list, Western_Europe.text_for_select_list,
\r
552 Austria.text_for_select_list, BeNeLux.text_for_select_list,
\r
553 Faroe_Islands.text_for_select_list, France.text_for_select_list,
\r
554 Germany.text_for_select_list, Bavaria.text_for_select_list, Saxonia.text_for_select_list,
\r
555 Germany_Austria_Switzerland.text_for_select_list, Iceland.text_for_select_list,
\r
556 Ireland.text_for_select_list, Italy.text_for_select_list,
\r
557 Spain_Portugal.text_for_select_list, Mallorca.text_for_select_list,
\r
558 Galicia.text_for_select_list, Scandinavia.text_for_select_list,
\r
559 Finland.text_for_select_list, Denmark.text_for_select_list,
\r
560 Switzerland.text_for_select_list, UK.text_for_select_list, Bulgaria.text_for_select_list,
\r
561 Czech_Republic.text_for_select_list, Croatia.text_for_select_list,
\r
562 Estonia.text_for_select_list, Greece.text_for_select_list, Crete.text_for_select_list,
\r
563 Hungary.text_for_select_list, Latvia.text_for_select_list, Lithuania.text_for_select_list,
\r
564 Poland.text_for_select_list, Romania.text_for_select_list,
\r
565 North_America.text_for_select_list, Alaska.text_for_select_list,
\r
566 Canada.text_for_select_list, Hawaii.text_for_select_list,
\r
567 USA__except_Alaska_and_Hawaii_.text_for_select_list, Nevada.text_for_select_list,
\r
568 Oregon.text_for_select_list, Washington_State.text_for_select_list,
\r
569 South_Middle_America.text_for_select_list, Argentina.text_for_select_list,
\r
570 Argentina_Chile.text_for_select_list, Bolivia.text_for_select_list,
\r
571 Brazil.text_for_select_list, Cuba.text_for_select_list, Colombia.text_for_select_list,
\r
572 Ecuador.text_for_select_list, Guyana_Suriname_Guyane_Francaise.text_for_select_list,
\r
573 Haiti_Republica_Dominicana.text_for_select_list, Jamaica.text_for_select_list,
\r
574 Mexico.text_for_select_list, Paraguay.text_for_select_list, Peru.text_for_select_list,
\r
575 Uruguay.text_for_select_list, Venezuela.text_for_select_list };
\r
577 public Boolean stop_me = false;
\r
578 static final int SOCKET_CONNECT_TIMEOUT = 6000;
\r
579 static final int SOCKET_READ_TIMEOUT = 6000;
\r
580 static final int MAP_WRITE_FILE_BUFFER = 1024 * 64;
\r
581 static final int MAP_WRITE_MEM_BUFFER = 1024 * 64;
\r
582 static final int MAP_READ_FILE_BUFFER = 1024 * 64;
\r
583 static final int UPDATE_PROGRESS_EVERY_CYCLE = 8;
\r
585 static final String DOWNLOAD_FILENAME = "navitmap.tmp";
\r
586 static final String MAP_FILENAME_PRI = "navitmap.bin";
\r
587 static final String MAP_FILENAME_SEC = "navitmap_002.bin";
\r
588 static final String MAP_FILENAME_PATH = "/sdcard/";
\r
591 public class ProgressThread extends Thread
\r
594 osm_map_values map_values;
\r
598 ProgressThread(Handler h, osm_map_values map_values, int map_num)
\r
601 this.map_values = map_values;
\r
602 this.map_num = map_num;
\r
603 if (this.map_num == Navit.MAP_NUM_PRIMARY)
\r
605 this.my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
\r
607 else if (this.map_num == Navit.MAP_NUM_SECONDARY)
\r
609 this.my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
\r
616 int exit_code = download_osm_map(mHandler, map_values, this.map_num);
\r
618 // ok, remove dialog
\r
619 Message msg = mHandler.obtainMessage();
\r
620 Bundle b = new Bundle();
\r
622 b.putInt("dialog_num", this.my_dialog_num);
\r
623 b.putInt("exit_code", exit_code);
\r
625 mHandler.sendMessage(msg);
\r
628 public void stop_thread()
\r
631 Log.d("NavitMapDownloader", "stop_me -> true");
\r
635 public Navit navit_jmain = null;
\r
637 public NavitMapDownloader(Navit main)
\r
639 this.navit_jmain = main;
\r
642 public int download_osm_map(Handler handler, osm_map_values map_values, int map_num)
\r
646 int my_dialog_num = 0;
\r
647 if (map_num == Navit.MAP_NUM_PRIMARY)
\r
649 my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
\r
651 else if (map_num == Navit.MAP_NUM_SECONDARY)
\r
653 my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
\r
656 Message msg = handler.obtainMessage();
\r
657 Bundle b = new Bundle();
\r
659 b.putInt("max", 20); // use a dummy number here
\r
660 b.putInt("cur", 0);
\r
661 b.putInt("dialog_num", my_dialog_num);
\r
662 b.putString("title", "Mapdownload");
\r
663 b.putString("text", "downloading: " + map_values.map_name);
\r
665 handler.sendMessage(msg);
\r
668 // little pause here
\r
671 catch (InterruptedException e1)
\r
676 String fileName = DOWNLOAD_FILENAME;
\r
677 String final_fileName = MAP_FILENAME_PRI;
\r
678 if (map_num == Navit.MAP_NUM_SECONDARY)
\r
680 final_fileName = this.MAP_FILENAME_SEC;
\r
682 // output path for output filename
\r
683 // String PATH = Environment.getExternalStorageDirectory() + "/download/";
\r
684 String PATH = MAP_FILENAME_PATH;
\r
685 Log.v("log_tag", "mapfilename tmp: " + PATH + fileName);
\r
689 URL url = new URL("http://maps.navit-project.org/api/map/?bbox=" + map_values.lon1 + ","
\r
690 + map_values.lat1 + "," + map_values.lon2 + "," + map_values.lat2);
\r
691 HttpURLConnection c = (HttpURLConnection) url.openConnection();
\r
692 c.setRequestMethod("GET");
\r
693 c.setDoOutput(true);
\r
694 c.setReadTimeout(SOCKET_READ_TIMEOUT);
\r
695 c.setConnectTimeout(SOCKET_CONNECT_TIMEOUT);
\r
696 long real_size_bytes = c.getContentLength();
\r
699 Log.d("NavitMapDownloader", "real size in bytes: " + real_size_bytes);
\r
700 if (real_size_bytes > 20)
\r
702 // change the estimated filesize to reported filesize
\r
703 map_values.est_size_bytes = real_size_bytes;
\r
705 Log.d("NavitMapDownloader", "size in bytes: " + map_values.est_size_bytes);
\r
707 File file = new File(PATH);
\r
708 File outputFile = new File(file, fileName);
\r
709 File final_outputFile = new File(file, final_fileName);
\r
710 // tests have shown that deleting the file first is sometimes faster -> so we delete it (who knows)
\r
711 outputFile.delete();
\r
712 // seems this command overwrites the output file anyway
\r
713 FileOutputStream fos = new FileOutputStream(outputFile);
\r
714 BufferedOutputStream buf = new BufferedOutputStream(fos, MAP_WRITE_FILE_BUFFER); // buffer
\r
716 InputStream is = c.getInputStream();
\r
717 BufferedInputStream bif = new BufferedInputStream(is, MAP_READ_FILE_BUFFER); // buffer
\r
719 byte[] buffer = new byte[MAP_WRITE_MEM_BUFFER]; // buffer
\r
721 int already_read = 0;
\r
722 int alt = UPDATE_PROGRESS_EVERY_CYCLE; // show progress about every xx cylces
\r
724 String kbytes_per_second = "";
\r
725 long start_timestamp = System.currentTimeMillis();
\r
726 NumberFormat formatter = new DecimalFormat("00000.0");
\r
727 String eta_string = "";
\r
728 float per_second_overall = 0f;
\r
729 long bytes_remaining = 0;
\r
730 int eta_seconds = 0;
\r
731 while ((len1 = bif.read(buffer)) != -1)
\r
735 // ok we need to be stopped! close all files and end
\r
744 already_read = already_read + len1;
\r
750 msg = handler.obtainMessage();
\r
753 b.putInt("max", (int) (map_values.est_size_bytes / 1024));
\r
754 b.putInt("cur", (int) (already_read / 1024));
\r
755 b.putInt("dialog_num", my_dialog_num);
\r
756 b.putString("title", "Map download");
\r
757 per_second_overall = (float) already_read
\r
758 / (float) ((System.currentTimeMillis() - start_timestamp) / 1000);
\r
759 kbytes_per_second = formatter.format((per_second_overall / 1024f));
\r
760 bytes_remaining = map_values.est_size_bytes - already_read;
\r
761 eta_seconds = (int) ((float) bytes_remaining / (float) per_second_overall);
\r
762 if (eta_seconds > 60)
\r
764 eta_string = (int) (eta_seconds / 60f) + " m";
\r
768 eta_string = eta_seconds + " s";
\r
770 b.putString("text", "downloading: " + map_values.map_name + "\n" + " "
\r
771 + (int) (already_read / 1024f / 1024f) + "Mb / "
\r
772 + (int) (map_values.est_size_bytes / 1024f / 1024f) + "Mb" + "\n" + " "
\r
773 + kbytes_per_second + "kb/s" + " ETA: " + eta_string);
\r
775 handler.sendMessage(msg);
\r
778 // // little pause here
\r
779 // Thread.sleep(20);
\r
781 // catch (InterruptedException e1)
\r
785 buf.write(buffer, 0, len1);
\r
797 // delete an already final filename, first
\r
798 final_outputFile.delete();
\r
799 // rename file to final name
\r
800 outputFile.renameTo(final_outputFile);
\r
802 catch (IOException e)
\r
804 msg = handler.obtainMessage();
\r
807 b.putInt("dialog_num", my_dialog_num);
\r
808 b.putString("text", "Error downloading map!");
\r
810 handler.sendMessage(msg);
\r
812 Log.d("NavitMapDownloader", "Error: " + e);
\r
815 catch (Exception e)
\r
817 msg = handler.obtainMessage();
\r
820 b.putInt("dialog_num", my_dialog_num);
\r
821 b.putString("text", "Error downloading map!");
\r
823 handler.sendMessage(msg);
\r
825 Log.d("NavitMapDownloader", "gerneral Error: " + e);
\r
829 msg = handler.obtainMessage();
\r
832 b.putInt("max", (int) (map_values.est_size_bytes / 1024));
\r
833 b.putInt("cur", (int) (map_values.est_size_bytes / 1024));
\r
834 b.putInt("dialog_num", my_dialog_num);
\r
835 b.putString("title", "Mapdownload");
\r
836 b.putString("text", map_values.map_name + " ready");
\r
838 handler.sendMessage(msg);
\r
841 Log.d("NavitMapDownloader", "success");
\r