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
50 Boolean is_continent = false;
\r
51 int continent_id = 0;
\r
54 public osm_map_values(String mapname, String lon_1, String lat_1, String lon_2, String lat_2,
\r
55 long bytes_est, Boolean is_con, int con_id)
\r
57 this.is_continent = is_con;
\r
58 this.continent_id = con_id;
\r
59 this.map_name = mapname;
\r
64 this.est_size_bytes = bytes_est;
\r
65 this.est_size_bytes_human_string = " ca. "
\r
66 + (int) ((float) (this.est_size_bytes) / 1024f / 1024f) + "MB";
\r
67 this.text_for_select_list = this.map_name + " " + this.est_size_bytes_human_string;
\r
72 // define the maps here
\r
75 static final osm_map_values Whole_Planet = new osm_map_values(
\r
77 "-180", "-90", "180",
\r
80 static final osm_map_values Africa = new osm_map_values(
\r
85 static final osm_map_values Angola = new osm_map_values(
\r
90 static final osm_map_values Burundi = new osm_map_values(
\r
95 static final osm_map_values Democratic_Republic_of_the_Congo = new osm_map_values(
\r
96 "Democratic Republic of the Congo",
\r
99 65026791L, false, 1);
\r
100 static final osm_map_values Kenya = new osm_map_values(
\r
105 static final osm_map_values Lesotho = new osm_map_values(
\r
108 "-28.4", 54791041L,
\r
110 static final osm_map_values Madagascar = new osm_map_values(
\r
111 "Madagascar", "43.0",
\r
113 "-11.8", 56801099L,
\r
115 static final osm_map_values Nambia_Botswana = new osm_map_values(
\r
119 61807049L, false, 1);
\r
120 static final osm_map_values Reunion = new osm_map_values(
\r
123 "-20.9", 58537419L,
\r
125 static final osm_map_values Rwanda = new osm_map_values(
\r
130 static final osm_map_values South_Africa = new osm_map_values(
\r
134 73545245L, false, 1);
\r
135 static final osm_map_values Uganda = new osm_map_values(
\r
140 static final osm_map_values Asia = new osm_map_values(
\r
143 "82.4", 797725952L,
\r
145 static final osm_map_values China = new osm_map_values(
\r
148 "54.5", 259945160L,
\r
150 static final osm_map_values Cyprus = new osm_map_values(
\r
155 static final osm_map_values India_Nepal = new osm_map_values(
\r
159 82819344L, false, 2);
\r
160 static final osm_map_values Indonesia = new osm_map_values(
\r
161 "Indonesia", "93.7",
\r
165 static final osm_map_values Iran = new osm_map_values(
\r
170 static final osm_map_values Iraq = new osm_map_values(
\r
175 static final osm_map_values Israel = new osm_map_values(
\r
180 static final osm_map_values Japan_Korea_Taiwan = new osm_map_values(
\r
181 "Japan+Korea+Taiwan",
\r
184 305538751L, false, 2);
\r
185 static final osm_map_values Malasia_Singapore = new osm_map_values(
\r
186 "Malasia+Singapore",
\r
189 58849792L, false, 2);
\r
190 static final osm_map_values Mongolia = new osm_map_values(
\r
191 "Mongolia", "87.5",
\r
195 static final osm_map_values Thailand = new osm_map_values(
\r
196 "Thailand", "97.5",
\r
200 static final osm_map_values Turkey = new osm_map_values(
\r
205 static final osm_map_values UAE_Other = new osm_map_values(
\r
206 "UAE+Other", "51.5",
\r
210 static final osm_map_values Australia = new osm_map_values(
\r
211 "Australia", "110.5",
\r
213 "-9.2", 128502185L,
\r
215 static final osm_map_values Tasmania = new osm_map_values(
\r
216 "Tasmania", "144.0",
\r
218 "-24.8", 103573989L,
\r
220 static final osm_map_values Victoria_New_South_Wales = new osm_map_values(
\r
221 "Victoria+New South Wales",
\r
224 99307594L, false, 3);
\r
225 static final osm_map_values New_Zealand = new osm_map_values(
\r
229 64757454L, false, 3);
\r
230 static final osm_map_values Europe = new osm_map_values(
\r
231 "Europe", "-12.97",
\r
233 "72.10", 2753910015L,
\r
235 static final osm_map_values Western_Europe = new osm_map_values(
\r
239 2832986851L, false, 4);
\r
240 static final osm_map_values Austria = new osm_map_values(
\r
243 "49.1", 222359992L,
\r
245 static final osm_map_values BeNeLux = new osm_map_values(
\r
248 "54.52", 533865194L,
\r
250 static final osm_map_values Faroe_Islands = new osm_map_values(
\r
254 54526101L, false, 4);
\r
255 static final osm_map_values France = new osm_map_values(
\r
258 "51.68", 1112047845L,
\r
260 static final osm_map_values Germany = new osm_map_values(
\r
263 "55.64", 944716238L,
\r
265 static final osm_map_values Bavaria = new osm_map_values(
\r
268 "49.7", 131799419L,
\r
270 static final osm_map_values Saxonia = new osm_map_values(
\r
273 "51.7", 112073909L,
\r
275 static final osm_map_values Germany_Austria_Switzerland = new osm_map_values(
\r
276 "Germany+Austria+Switzerland",
\r
279 1385785353L, false, 4);
\r
280 static final osm_map_values Iceland = new osm_map_values(
\r
281 "Iceland", "-25.3",
\r
285 static final osm_map_values Ireland = new osm_map_values(
\r
286 "Ireland", "-11.17",
\r
290 static final osm_map_values Italy = new osm_map_values(
\r
293 "47.19", 291401314L,
\r
295 static final osm_map_values Spain_Portugal = new osm_map_values(
\r
299 292407746L, false, 4);
\r
300 static final osm_map_values Mallorca = new osm_map_values(
\r
305 static final osm_map_values Galicia = new osm_map_values(
\r
306 "Galicia", "-10.0",
\r
310 static final osm_map_values Scandinavia = new osm_map_values(
\r
311 "Scandinavia", "4.0",
\r
313 "71.5", 299021928L,
\r
315 static final osm_map_values Finland = new osm_map_values(
\r
318 "70.3", 128871467L,
\r
320 static final osm_map_values Denmark = new osm_map_values(
\r
323 "57.88", 120025875L,
\r
325 static final osm_map_values Switzerland = new osm_map_values(
\r
329 162616817L, false, 4);
\r
330 static final osm_map_values UK = new osm_map_values("UK",
\r
333 245161510L, false, 4);
\r
334 static final osm_map_values Bulgaria = new osm_map_values(
\r
335 "Bulgaria", "24.7",
\r
339 static final osm_map_values Czech_Republic = new osm_map_values(
\r
343 234138824L, false, 4);
\r
344 static final osm_map_values Croatia = new osm_map_values(
\r
349 static final osm_map_values Estonia = new osm_map_values(
\r
354 static final osm_map_values Greece = new osm_map_values(
\r
359 static final osm_map_values Crete = new osm_map_values(
\r
364 static final osm_map_values Hungary = new osm_map_values(
\r
365 "Hungary", "16.08",
\r
367 "48.39", 109831319L,
\r
369 static final osm_map_values Latvia = new osm_map_values(
\r
374 static final osm_map_values Lithuania = new osm_map_values(
\r
375 "Lithuania", "20.9",
\r
379 static final osm_map_values Poland = new osm_map_values(
\r
382 "55.0", 266136768L,
\r
384 static final osm_map_values Romania = new osm_map_values(
\r
387 "48.4", 134525863L,
\r
389 static final osm_map_values North_America = new osm_map_values(
\r
393 2477309662L, true, 5);
\r
394 static final osm_map_values Alaska = new osm_map_values(
\r
395 "Alaska", "-179.5",
\r
399 static final osm_map_values Canada = new osm_map_values(
\r
400 "Canada", "-141.3",
\r
402 "70.2", 937813467L,
\r
404 static final osm_map_values Hawaii = new osm_map_values(
\r
405 "Hawaii", "-161.07",
\r
406 "18.49", "-154.45",
\r
407 "22.85", 57311788L,
\r
409 static final osm_map_values USA__except_Alaska_and_Hawaii_ = new osm_map_values(
\r
410 "USA (except Alaska and Hawaii)",
\r
413 2216912004L, false, 5);
\r
414 static final osm_map_values Nevada = new osm_map_values(
\r
415 "Nevada", "-120.2",
\r
417 "42.1", 136754975L,
\r
419 static final osm_map_values Oregon = new osm_map_values(
\r
420 "Oregon", "-124.8",
\r
422 "46.3", 101627308L,
\r
424 static final osm_map_values Washington_State = new osm_map_values(
\r
425 "Washington State",
\r
428 98178877L, false, 0);
\r
429 static final osm_map_values South_Middle_America = new osm_map_values(
\r
430 "South+Middle America",
\r
433 159615197L, true, 6);
\r
434 static final osm_map_values Argentina = new osm_map_values(
\r
435 "Argentina", "-73.9",
\r
437 "-21.0", 87516152L,
\r
439 static final osm_map_values Argentina_Chile = new osm_map_values(
\r
443 91976696L, false, 0);
\r
444 static final osm_map_values Bolivia = new osm_map_values(
\r
445 "Bolivia", "-70.5",
\r
449 static final osm_map_values Brazil = new osm_map_values(
\r
454 static final osm_map_values Cuba = new osm_map_values(
\r
459 static final osm_map_values Colombia = new osm_map_values(
\r
460 "Colombia", "-79.1",
\r
464 static final osm_map_values Ecuador = new osm_map_values(
\r
465 "Ecuador", "-82.6",
\r
469 static final osm_map_values Guyana_Suriname_Guyane_Francaise = new osm_map_values(
\r
470 "Guyana+Suriname+Guyane Francaise",
\r
473 57040689L, false, 0);
\r
474 static final osm_map_values Haiti_Republica_Dominicana = new osm_map_values(
\r
475 "Haiti+Republica Dominicana",
\r
478 63528584L, false, 0);
\r
479 static final osm_map_values Jamaica = new osm_map_values(
\r
480 "Jamaica", "-78.6",
\r
484 static final osm_map_values Mexico = new osm_map_values(
\r
485 "Mexico", "-117.6",
\r
487 "32.8", 251108617L,
\r
489 static final osm_map_values Paraguay = new osm_map_values(
\r
490 "Paraguay", "-63.8",
\r
492 "-18.8", 57188715L,
\r
494 static final osm_map_values Peru = new osm_map_values(
\r
499 static final osm_map_values Uruguay = new osm_map_values(
\r
500 "Uruguay", "-59.2",
\r
502 "-29.7", 63542225L,
\r
504 static final osm_map_values Venezuela = new osm_map_values(
\r
505 "Venezuela", "-73.6",
\r
510 static final osm_map_values[] OSM_MAPS = new osm_map_values[]{
\r
511 Whole_Planet, Africa, Angola, Burundi, Democratic_Republic_of_the_Congo, Kenya, Lesotho,
\r
512 Madagascar, Nambia_Botswana, Reunion, Rwanda, South_Africa, Uganda, Asia, China, Cyprus,
\r
513 India_Nepal, Indonesia, Iran, Iraq, Israel, Japan_Korea_Taiwan, Malasia_Singapore,
\r
514 Mongolia, Nambia_Botswana, Thailand, Turkey, UAE_Other, Australia, Tasmania,
\r
515 Victoria_New_South_Wales, New_Zealand, Europe, Western_Europe, Austria, BeNeLux,
\r
516 Faroe_Islands, France, Germany, Bavaria, Saxonia, Germany_Austria_Switzerland, Iceland,
\r
517 Ireland, Italy, Spain_Portugal, Mallorca, Galicia, Scandinavia, Finland, Denmark,
\r
518 Switzerland, UK, Bulgaria, Czech_Republic, Croatia, Estonia, Greece, Crete, Hungary,
\r
519 Latvia, Lithuania, Poland, Romania, North_America, Alaska, Canada, Hawaii,
\r
520 USA__except_Alaska_and_Hawaii_, Nevada, Oregon, Washington_State, South_Middle_America,
\r
521 Argentina, Argentina_Chile, Bolivia, Brazil, Cuba, Colombia, Ecuador,
\r
522 Guyana_Suriname_Guyane_Francaise, Haiti_Republica_Dominicana, Jamaica, Mexico, Paraguay,
\r
523 Peru, Uruguay, Venezuela };
\r
524 //public static String[] OSM_MAP_NAME_LIST = null;
\r
526 public static String[] OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE = null;
\r
528 public static int[] OSM_MAP_NAME_ORIG_ID_LIST = null;
\r
530 private static Boolean already_inited = false;
\r
532 public Boolean stop_me = false;
\r
533 static final int SOCKET_CONNECT_TIMEOUT = 6000;
\r
534 static final int SOCKET_READ_TIMEOUT = 6000;
\r
535 static final int MAP_WRITE_FILE_BUFFER = 1024 * 64;
\r
536 static final int MAP_WRITE_MEM_BUFFER = 1024 * 64;
\r
537 static final int MAP_READ_FILE_BUFFER = 1024 * 64;
\r
538 static final int UPDATE_PROGRESS_EVERY_CYCLE = 8;
\r
540 static final String DOWNLOAD_FILENAME = "navitmap.tmp";
\r
541 static final String MAP_FILENAME_PRI = "navitmap.bin";
\r
542 static final String MAP_FILENAME_SEC = "navitmap_002.bin";
\r
543 static final String MAP_FILENAME_PATH = Navit.MAP_FILENAME_PATH;
\r
545 static final int MAX_MAP_COUNT = 200;
\r
547 public class ProgressThread extends Thread
\r
550 osm_map_values map_values;
\r
554 ProgressThread(Handler h, osm_map_values map_values, int map_num2)
\r
557 this.map_values = map_values;
\r
558 this.map_num = map_num2;
\r
559 if (this.map_num == Navit.MAP_NUM_PRIMARY)
\r
561 this.my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
\r
563 else if (this.map_num == Navit.MAP_NUM_SECONDARY)
\r
565 this.my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
\r
572 int exit_code = download_osm_map(mHandler, map_values, this.map_num);
\r
574 // ok, remove dialog
\r
575 Message msg = mHandler.obtainMessage();
\r
576 Bundle b = new Bundle();
\r
578 b.putInt("dialog_num", this.my_dialog_num);
\r
579 b.putInt("exit_code", exit_code);
\r
581 mHandler.sendMessage(msg);
\r
584 public void stop_thread()
\r
587 Log.d("NavitMapDownloader", "stop_me -> true");
\r
591 public Navit navit_jmain = null;
\r
593 public NavitMapDownloader(Navit main)
\r
595 this.navit_jmain = main;
\r
598 public static void init()
\r
600 // need only init once
\r
601 if (already_inited) { return; }
\r
603 //String[] temp_m = new String[MAX_MAP_COUNT];
\r
604 String[] temp_ml = new String[MAX_MAP_COUNT];
\r
605 int[] temp_i = new int[MAX_MAP_COUNT];
\r
606 Boolean[] already_added = new Boolean[OSM_MAPS.length];
\r
607 int cur_continent = -1;
\r
609 Log.v("NavitMapDownloader", "init maps");
\r
610 for (int i = 0; i < OSM_MAPS.length; i++)
\r
612 already_added[i] = false;
\r
614 for (int i = 0; i < OSM_MAPS.length; i++)
\r
616 //Log.v("NavitMapDownloader", "i=" + i);
\r
617 // look for continents only
\r
618 if (OSM_MAPS[i].is_continent)
\r
622 // add a break into list
\r
623 //temp_m[count] = "*break*";
\r
624 temp_ml[count] = "======";
\r
625 temp_i[count] = -1;
\r
629 cur_continent = OSM_MAPS[i].continent_id;
\r
630 //Log.v("NavitMapDownloader", "found cont=" + cur_continent);
\r
632 //temp_m[count] = OSM_MAPS[i].map_name;
\r
633 temp_ml[count] = OSM_MAPS[i].text_for_select_list;
\r
636 already_added[i] = true;
\r
637 for (int j = 0; j < OSM_MAPS.length; j++)
\r
639 // if (already_added[j] == null)
\r
640 if (!already_added[j])
\r
642 // look for maps in that continent
\r
643 if ((OSM_MAPS[j].continent_id == cur_continent) && (!OSM_MAPS[j].is_continent))
\r
645 //Log.v("NavitMapDownloader", "found map=" + j + " c=" + cur_continent);
\r
647 //temp_m[count] = OSM_MAPS[j].map_name;
\r
648 temp_ml[count] = " * " + OSM_MAPS[j].text_for_select_list;
\r
651 already_added[j] = true;
\r
657 // add the rest of the list (dont have a continent)
\r
658 cur_continent = 9999; // unknown
\r
660 for (int i = 0; i < OSM_MAPS.length; i++)
\r
662 if (!already_added[i])
\r
667 // add a break into list
\r
668 //temp_m[count] = "*break*";
\r
669 temp_ml[count] = "======";
\r
670 temp_i[count] = -1;
\r
674 //Log.v("NavitMapDownloader", "found map(loose)=" + i + " c=" + cur_continent);
\r
676 //temp_m[count] = OSM_MAPS[i].map_name;
\r
677 temp_ml[count] = " # " + OSM_MAPS[i].text_for_select_list;
\r
680 already_added[i] = true;
\r
684 Log.e("NavitMapDownloader", "count=" + count);
\r
685 Log.e("NavitMapDownloader", "size1 " + OSM_MAPS.length);
\r
686 //Log.e("NavitMapDownloader", "size2 " + temp_m.length);
\r
687 Log.e("NavitMapDownloader", "size3 " + temp_ml.length);
\r
689 //OSM_MAP_NAME_LIST = new String[count];
\r
690 OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE = new String[count];
\r
691 OSM_MAP_NAME_ORIG_ID_LIST = new int[count];
\r
693 for (int i = 0; i < count; i++)
\r
695 //OSM_MAP_NAME_LIST[i] = temp_m[i];
\r
696 OSM_MAP_NAME_ORIG_ID_LIST[i] = temp_i[i];
\r
697 OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE[i] = temp_ml[i];
\r
700 already_inited = true;
\r
703 public int download_osm_map(Handler handler, osm_map_values map_values, int map_num3)
\r
707 //Log.v("NavitMapDownloader", "map_num3=" + map_num3);
\r
708 int my_dialog_num = 0;
\r
709 if (map_num3 == Navit.MAP_NUM_PRIMARY)
\r
711 my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
\r
712 //Log.v("NavitMapDownloader", "PRI");
\r
714 else if (map_num3 == Navit.MAP_NUM_SECONDARY)
\r
716 my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
\r
717 //Log.v("NavitMapDownloader", "SEC");
\r
719 //Log.v("NavitMapDownloader", "map_num3=" + map_num3);
\r
721 Message msg = handler.obtainMessage();
\r
722 Bundle b = new Bundle();
\r
724 b.putInt("max", 20); // use a dummy number here
\r
725 b.putInt("cur", 0);
\r
726 b.putInt("dialog_num", my_dialog_num);
\r
727 b.putString("title", "Mapdownload"); //TRANS
\r
728 b.putString("text", "downloading: " + map_values.map_name); //TRANS
\r
730 handler.sendMessage(msg);
\r
733 // little pause here
\r
736 catch (InterruptedException e1)
\r
741 String PATH = MAP_FILENAME_PATH;
\r
742 String fileName = DOWNLOAD_FILENAME;
\r
743 String final_fileName = "xxx";
\r
744 //Log.v("NavitMapDownloader", "map_num3=" + map_num3);
\r
745 if (map_num3 == Navit.MAP_NUM_SECONDARY)
\r
747 final_fileName = MAP_FILENAME_SEC;
\r
749 else if (map_num3 == Navit.MAP_NUM_PRIMARY)
\r
751 final_fileName = MAP_FILENAME_PRI;
\r
753 // output path for output filename
\r
754 // String PATH = Environment.getExternalStorageDirectory() + "/download/";
\r
758 URL url = new URL("http://maps.navit-project.org/api/map/?bbox=" + map_values.lon1 + ","
\r
759 + map_values.lat1 + "," + map_values.lon2 + "," + map_values.lat2);
\r
760 HttpURLConnection c = (HttpURLConnection) url.openConnection();
\r
761 c.setRequestMethod("GET");
\r
762 c.setDoOutput(true);
\r
763 c.setReadTimeout(SOCKET_READ_TIMEOUT);
\r
764 c.setConnectTimeout(SOCKET_CONNECT_TIMEOUT);
\r
765 long real_size_bytes = c.getContentLength();
\r
768 Log.d("NavitMapDownloader", "real size in bytes: " + real_size_bytes);
\r
769 if (real_size_bytes > 20)
\r
771 // change the estimated filesize to reported filesize
\r
772 map_values.est_size_bytes = real_size_bytes;
\r
774 Log.d("NavitMapDownloader", "size in bytes: " + map_values.est_size_bytes);
\r
776 File file = new File(PATH);
\r
777 File outputFile = new File(file, fileName);
\r
778 File final_outputFile = new File(file, final_fileName);
\r
779 // tests have shown that deleting the file first is sometimes faster -> so we delete it (who knows)
\r
780 outputFile.delete();
\r
781 // seems this command overwrites the output file anyway
\r
782 FileOutputStream fos = new FileOutputStream(outputFile);
\r
783 BufferedOutputStream buf = new BufferedOutputStream(fos, MAP_WRITE_FILE_BUFFER); // buffer
\r
785 InputStream is = c.getInputStream();
\r
786 BufferedInputStream bif = new BufferedInputStream(is, MAP_READ_FILE_BUFFER); // buffer
\r
788 byte[] buffer = new byte[MAP_WRITE_MEM_BUFFER]; // buffer
\r
790 int already_read = 0;
\r
791 int alt = UPDATE_PROGRESS_EVERY_CYCLE; // show progress about every xx cylces
\r
793 String kbytes_per_second = "";
\r
794 long start_timestamp = System.currentTimeMillis();
\r
795 NumberFormat formatter = new DecimalFormat("00000.0");
\r
796 String eta_string = "";
\r
797 float per_second_overall = 0f;
\r
798 long bytes_remaining = 0;
\r
799 int eta_seconds = 0;
\r
800 while ((len1 = bif.read(buffer)) != -1)
\r
804 // ok we need to be stopped! close all files and end
\r
813 already_read = already_read + len1;
\r
819 msg = handler.obtainMessage();
\r
822 b.putInt("max", (int) (map_values.est_size_bytes / 1024));
\r
823 b.putInt("cur", (int) (already_read / 1024));
\r
824 b.putInt("dialog_num", my_dialog_num);
\r
825 b.putString("title", "Map download"); //TRANS
\r
826 per_second_overall = (float) already_read
\r
827 / (float) ((System.currentTimeMillis() - start_timestamp) / 1000);
\r
828 kbytes_per_second = formatter.format((per_second_overall / 1024f));
\r
829 bytes_remaining = map_values.est_size_bytes - already_read;
\r
830 eta_seconds = (int) ((float) bytes_remaining / (float) per_second_overall);
\r
831 if (eta_seconds > 60)
\r
833 eta_string = (int) (eta_seconds / 60f) + " m";
\r
837 eta_string = eta_seconds + " s";
\r
839 b.putString("text", "downloading: " + map_values.map_name + "\n" + " "
\r
840 + (int) (already_read / 1024f / 1024f) + "Mb / "
\r
841 + (int) (map_values.est_size_bytes / 1024f / 1024f) + "Mb" + "\n" + " "
\r
842 + kbytes_per_second + "kb/s" + " ETA: " + eta_string); //TRANS
\r
844 handler.sendMessage(msg);
\r
846 buf.write(buffer, 0, len1);
\r
858 // delete an already final filename, first
\r
859 final_outputFile.delete();
\r
860 // rename file to final name
\r
861 outputFile.renameTo(final_outputFile);
\r
863 catch (IOException e)
\r
865 msg = handler.obtainMessage();
\r
868 b.putInt("dialog_num", my_dialog_num);
\r
869 b.putString("text", "Error downloading map!"); //TRANS
\r
871 handler.sendMessage(msg);
\r
873 Log.d("NavitMapDownloader", "Error: " + e);
\r
876 catch (Exception e)
\r
878 msg = handler.obtainMessage();
\r
881 b.putInt("dialog_num", my_dialog_num);
\r
882 b.putString("text", "Error downloading map!"); //TRANS
\r
884 handler.sendMessage(msg);
\r
886 Log.d("NavitMapDownloader", "gerneral Error: " + e);
\r
890 msg = handler.obtainMessage();
\r
893 b.putInt("max", (int) (map_values.est_size_bytes / 1024));
\r
894 b.putInt("cur", (int) (map_values.est_size_bytes / 1024));
\r
895 b.putInt("dialog_num", my_dialog_num);
\r
896 b.putString("title", "Mapdownload"); //TRANS
\r
897 b.putString("text", map_values.map_name + " ready"); //TRANS
\r
899 handler.sendMessage(msg);
\r
902 Log.d("NavitMapDownloader", "success");
\r