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 Australia2 = new osm_map_values(
\r
211 "Australia", "110.5",
\r
213 "-9.2", 128502185L,
\r
215 static final osm_map_values Australia = new osm_map_values(
\r
216 "Australia", "110.5",
\r
218 "-9.2", 128502185L,
\r
220 static final osm_map_values Tasmania = new osm_map_values(
\r
221 "Tasmania", "144.0",
\r
223 "-24.8", 103573989L,
\r
225 static final osm_map_values Victoria_New_South_Wales = new osm_map_values(
\r
226 "Victoria+New South Wales",
\r
229 99307594L, false, 3);
\r
230 static final osm_map_values New_Zealand = new osm_map_values(
\r
234 64757454L, false, 3);
\r
235 static final osm_map_values Europe = new osm_map_values(
\r
236 "Europe", "-12.97",
\r
238 "72.10", 2753910015L,
\r
240 static final osm_map_values Western_Europe = new osm_map_values(
\r
244 2832986851L, false, 4);
\r
245 static final osm_map_values Austria = new osm_map_values(
\r
248 "49.1", 222359992L,
\r
250 static final osm_map_values BeNeLux = new osm_map_values(
\r
253 "54.52", 533865194L,
\r
255 static final osm_map_values Faroe_Islands = new osm_map_values(
\r
259 54526101L, false, 4);
\r
260 static final osm_map_values France = new osm_map_values(
\r
263 "51.68", 1112047845L,
\r
265 static final osm_map_values Germany = new osm_map_values(
\r
268 "55.64", 944716238L,
\r
270 static final osm_map_values Bavaria = new osm_map_values(
\r
273 "49.7", 131799419L,
\r
275 static final osm_map_values Saxonia = new osm_map_values(
\r
278 "51.7", 112073909L,
\r
280 static final osm_map_values Germany_Austria_Switzerland = new osm_map_values(
\r
281 "Germany+Austria+Switzerland",
\r
284 1385785353L, false, 4);
\r
285 static final osm_map_values Iceland = new osm_map_values(
\r
286 "Iceland", "-25.3",
\r
290 static final osm_map_values Ireland = new osm_map_values(
\r
291 "Ireland", "-11.17",
\r
295 static final osm_map_values Italy = new osm_map_values(
\r
298 "47.19", 291401314L,
\r
300 static final osm_map_values Spain_Portugal = new osm_map_values(
\r
304 292407746L, false, 4);
\r
305 static final osm_map_values Mallorca = new osm_map_values(
\r
310 static final osm_map_values Galicia = new osm_map_values(
\r
311 "Galicia", "-10.0",
\r
315 static final osm_map_values Scandinavia = new osm_map_values(
\r
316 "Scandinavia", "4.0",
\r
318 "71.5", 299021928L,
\r
320 static final osm_map_values Finland = new osm_map_values(
\r
323 "70.3", 128871467L,
\r
325 static final osm_map_values Denmark = new osm_map_values(
\r
328 "57.88", 120025875L,
\r
330 static final osm_map_values Switzerland = new osm_map_values(
\r
334 162616817L, false, 4);
\r
335 static final osm_map_values UK = new osm_map_values("UK",
\r
338 245161510L, false, 4);
\r
339 static final osm_map_values Bulgaria = new osm_map_values(
\r
340 "Bulgaria", "24.7",
\r
344 static final osm_map_values Czech_Republic = new osm_map_values(
\r
348 234138824L, false, 4);
\r
349 static final osm_map_values Croatia = new osm_map_values(
\r
354 static final osm_map_values Estonia = new osm_map_values(
\r
359 static final osm_map_values Greece = new osm_map_values(
\r
364 static final osm_map_values Crete = new osm_map_values(
\r
369 static final osm_map_values Hungary = new osm_map_values(
\r
370 "Hungary", "16.08",
\r
372 "48.39", 109831319L,
\r
374 static final osm_map_values Latvia = new osm_map_values(
\r
379 static final osm_map_values Lithuania = new osm_map_values(
\r
380 "Lithuania", "20.9",
\r
384 static final osm_map_values Poland = new osm_map_values(
\r
387 "55.0", 266136768L,
\r
389 static final osm_map_values Romania = new osm_map_values(
\r
392 "48.4", 134525863L,
\r
394 static final osm_map_values North_America = new osm_map_values(
\r
398 2477309662L, true, 5);
\r
399 static final osm_map_values Alaska = new osm_map_values(
\r
400 "Alaska", "-179.5",
\r
404 static final osm_map_values Canada = new osm_map_values(
\r
405 "Canada", "-141.3",
\r
407 "70.2", 937813467L,
\r
409 static final osm_map_values Hawaii = new osm_map_values(
\r
410 "Hawaii", "-161.07",
\r
411 "18.49", "-154.45",
\r
412 "22.85", 57311788L,
\r
414 static final osm_map_values USA__except_Alaska_and_Hawaii_ = new osm_map_values(
\r
415 "USA (except Alaska and Hawaii)",
\r
418 2216912004L, false, 5);
\r
419 static final osm_map_values Nevada = new osm_map_values(
\r
420 "Nevada", "-120.2",
\r
422 "42.1", 136754975L,
\r
424 static final osm_map_values Oregon = new osm_map_values(
\r
425 "Oregon", "-124.8",
\r
427 "46.3", 101627308L,
\r
429 static final osm_map_values Washington_State = new osm_map_values(
\r
430 "Washington State",
\r
433 98178877L, false, 5);
\r
434 static final osm_map_values South_Middle_America = new osm_map_values(
\r
435 "South+Middle America",
\r
438 159615197L, true, 6);
\r
439 static final osm_map_values Argentina = new osm_map_values(
\r
440 "Argentina", "-73.9",
\r
442 "-21.0", 87516152L,
\r
444 static final osm_map_values Argentina_Chile = new osm_map_values(
\r
448 91976696L, false, 6);
\r
449 static final osm_map_values Bolivia = new osm_map_values(
\r
450 "Bolivia", "-70.5",
\r
454 static final osm_map_values Brazil = new osm_map_values(
\r
459 static final osm_map_values Cuba = new osm_map_values(
\r
464 static final osm_map_values Colombia = new osm_map_values(
\r
465 "Colombia", "-79.1",
\r
469 static final osm_map_values Ecuador = new osm_map_values(
\r
470 "Ecuador", "-82.6",
\r
474 static final osm_map_values Guyana_Suriname_Guyane_Francaise = new osm_map_values(
\r
475 "Guyana+Suriname+Guyane Francaise",
\r
478 57040689L, false, 6);
\r
479 static final osm_map_values Haiti_Republica_Dominicana = new osm_map_values(
\r
480 "Haiti+Republica Dominicana",
\r
483 63528584L, false, 6);
\r
484 static final osm_map_values Jamaica = new osm_map_values(
\r
485 "Jamaica", "-78.6",
\r
489 static final osm_map_values Mexico = new osm_map_values(
\r
490 "Mexico", "-117.6",
\r
492 "32.8", 251108617L,
\r
494 static final osm_map_values Paraguay = new osm_map_values(
\r
495 "Paraguay", "-63.8",
\r
497 "-18.8", 57188715L,
\r
499 static final osm_map_values Peru = new osm_map_values(
\r
504 static final osm_map_values Uruguay = new osm_map_values(
\r
505 "Uruguay", "-59.2",
\r
507 "-29.7", 63542225L,
\r
509 static final osm_map_values Venezuela = new osm_map_values(
\r
510 "Venezuela", "-73.6",
\r
515 static final osm_map_values[] OSM_MAPS = new osm_map_values[]{
\r
516 Whole_Planet, Africa, Angola, Burundi, Democratic_Republic_of_the_Congo, Kenya, Lesotho,
\r
517 Madagascar, Nambia_Botswana, Reunion, Rwanda, South_Africa, Uganda, Asia, China, Cyprus,
\r
518 India_Nepal, Indonesia, Iran, Iraq, Israel, Japan_Korea_Taiwan, Malasia_Singapore,
\r
519 Mongolia, Nambia_Botswana, Thailand, Turkey, UAE_Other, Australia2, Australia, Tasmania,
\r
520 Victoria_New_South_Wales, New_Zealand, Europe, Western_Europe, Austria, BeNeLux,
\r
521 Faroe_Islands, France, Germany, Bavaria, Saxonia, Germany_Austria_Switzerland, Iceland,
\r
522 Ireland, Italy, Spain_Portugal, Mallorca, Galicia, Scandinavia, Finland, Denmark,
\r
523 Switzerland, UK, Bulgaria, Czech_Republic, Croatia, Estonia, Greece, Crete, Hungary,
\r
524 Latvia, Lithuania, Poland, Romania, North_America, Alaska, Canada, Hawaii,
\r
525 USA__except_Alaska_and_Hawaii_, Nevada, Oregon, Washington_State, South_Middle_America,
\r
526 Argentina, Argentina_Chile, Bolivia, Brazil, Cuba, Colombia, Ecuador,
\r
527 Guyana_Suriname_Guyane_Francaise, Haiti_Republica_Dominicana, Jamaica, Mexico, Paraguay,
\r
528 Peru, Uruguay, Venezuela };
\r
530 public static String[] OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE = null;
\r
532 public static int[] OSM_MAP_NAME_ORIG_ID_LIST = null;
\r
534 private static Boolean already_inited = false;
\r
536 public Boolean stop_me = false;
\r
537 static final int SOCKET_CONNECT_TIMEOUT = 25000; // 25 secs.
\r
538 static final int SOCKET_READ_TIMEOUT = 15000; // 15 secs.
\r
539 static final int MAP_WRITE_FILE_BUFFER = 1024 * 64;
\r
540 static final int MAP_WRITE_MEM_BUFFER = 1024 * 64;
\r
541 static final int MAP_READ_FILE_BUFFER = 1024 * 64;
\r
542 static final int UPDATE_PROGRESS_EVERY_CYCLE = 8;
\r
544 static final String DOWNLOAD_FILENAME = "navitmap.tmp";
\r
545 static final String MAP_FILENAME_PRI = "navitmap.bin";
\r
546 static final String MAP_FILENAME_SEC = "navitmap_002.bin";
\r
547 static final String MAP_FILENAME_PATH = Navit.MAP_FILENAME_PATH;
\r
549 static final int MAX_MAP_COUNT = 200;
\r
551 public class ProgressThread extends Thread
\r
554 osm_map_values map_values;
\r
558 ProgressThread(Handler h, osm_map_values map_values, int map_num2)
\r
561 this.map_values = map_values;
\r
562 this.map_num = map_num2;
\r
563 if (this.map_num == Navit.MAP_NUM_PRIMARY)
\r
565 this.my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
\r
567 else if (this.map_num == Navit.MAP_NUM_SECONDARY)
\r
569 this.my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
\r
576 int exit_code = download_osm_map(mHandler, map_values, this.map_num);
\r
578 // ok, remove dialog
\r
579 Message msg = mHandler.obtainMessage();
\r
580 Bundle b = new Bundle();
\r
582 b.putInt("dialog_num", this.my_dialog_num);
\r
583 b.putInt("exit_code", exit_code);
\r
585 mHandler.sendMessage(msg);
\r
588 public void stop_thread()
\r
591 Log.d("NavitMapDownloader", "stop_me -> true");
\r
595 public Navit navit_jmain = null;
\r
597 public NavitMapDownloader(Navit main)
\r
599 this.navit_jmain = main;
\r
602 public static void init()
\r
604 // need only init once
\r
605 if (already_inited) { return; }
\r
607 //String[] temp_m = new String[MAX_MAP_COUNT];
\r
608 String[] temp_ml = new String[MAX_MAP_COUNT];
\r
609 int[] temp_i = new int[MAX_MAP_COUNT];
\r
610 Boolean[] already_added = new Boolean[OSM_MAPS.length];
\r
611 int cur_continent = -1;
\r
613 Log.v("NavitMapDownloader", "init maps");
\r
614 for (int i = 0; i < OSM_MAPS.length; i++)
\r
616 already_added[i] = false;
\r
618 for (int i = 0; i < OSM_MAPS.length; i++)
\r
620 //Log.v("NavitMapDownloader", "i=" + i);
\r
621 // look for continents only
\r
622 if (OSM_MAPS[i].is_continent)
\r
626 // add a break into list
\r
627 //temp_m[count] = "*break*";
\r
628 temp_ml[count] = "======";
\r
629 temp_i[count] = -1;
\r
633 cur_continent = OSM_MAPS[i].continent_id;
\r
634 //Log.v("NavitMapDownloader", "found cont=" + cur_continent);
\r
636 //temp_m[count] = OSM_MAPS[i].map_name;
\r
637 temp_ml[count] = OSM_MAPS[i].text_for_select_list;
\r
640 already_added[i] = true;
\r
641 for (int j = 0; j < OSM_MAPS.length; j++)
\r
643 // if (already_added[j] == null)
\r
644 if (!already_added[j])
\r
646 // look for maps in that continent
\r
647 if ((OSM_MAPS[j].continent_id == cur_continent) && (!OSM_MAPS[j].is_continent))
\r
649 //Log.v("NavitMapDownloader", "found map=" + j + " c=" + cur_continent);
\r
651 //temp_m[count] = OSM_MAPS[j].map_name;
\r
652 temp_ml[count] = " * " + OSM_MAPS[j].text_for_select_list;
\r
655 already_added[j] = true;
\r
661 // add the rest of the list (dont have a continent)
\r
662 cur_continent = 9999; // unknown
\r
664 for (int i = 0; i < OSM_MAPS.length; i++)
\r
666 if (!already_added[i])
\r
671 // add a break into list
\r
672 //temp_m[count] = "*break*";
\r
673 temp_ml[count] = "======";
\r
674 temp_i[count] = -1;
\r
678 //Log.v("NavitMapDownloader", "found map(loose)=" + i + " c=" + cur_continent);
\r
680 //temp_m[count] = OSM_MAPS[i].map_name;
\r
681 temp_ml[count] = " # " + OSM_MAPS[i].text_for_select_list;
\r
684 already_added[i] = true;
\r
688 Log.e("NavitMapDownloader", "count=" + count);
\r
689 Log.e("NavitMapDownloader", "size1 " + OSM_MAPS.length);
\r
690 //Log.e("NavitMapDownloader", "size2 " + temp_m.length);
\r
691 Log.e("NavitMapDownloader", "size3 " + temp_ml.length);
\r
693 //OSM_MAP_NAME_LIST = new String[count];
\r
694 OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE = new String[count];
\r
695 OSM_MAP_NAME_ORIG_ID_LIST = new int[count];
\r
697 for (int i = 0; i < count; i++)
\r
699 //OSM_MAP_NAME_LIST[i] = temp_m[i];
\r
700 OSM_MAP_NAME_ORIG_ID_LIST[i] = temp_i[i];
\r
701 OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE[i] = temp_ml[i];
\r
704 already_inited = true;
\r
707 public int download_osm_map(Handler handler, osm_map_values map_values, int map_num3)
\r
711 //Log.v("NavitMapDownloader", "map_num3=" + map_num3);
\r
712 int my_dialog_num = 0;
\r
713 if (map_num3 == Navit.MAP_NUM_PRIMARY)
\r
715 my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
\r
716 //Log.v("NavitMapDownloader", "PRI");
\r
718 else if (map_num3 == Navit.MAP_NUM_SECONDARY)
\r
720 my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
\r
721 //Log.v("NavitMapDownloader", "SEC");
\r
723 //Log.v("NavitMapDownloader", "map_num3=" + map_num3);
\r
725 Message msg = handler.obtainMessage();
\r
726 Bundle b = new Bundle();
\r
728 b.putInt("max", 20); // use a dummy number here
\r
729 b.putInt("cur", 0);
\r
730 b.putInt("dialog_num", my_dialog_num);
\r
731 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
\r
732 b.putString("text", Navit.get_text("downloading") + ": " + map_values.map_name); //TRANS
\r
734 handler.sendMessage(msg);
\r
737 // little pause here
\r
740 catch (InterruptedException e1)
\r
745 String PATH = MAP_FILENAME_PATH;
\r
746 String fileName = DOWNLOAD_FILENAME;
\r
747 String final_fileName = "xxx";
\r
748 //Log.v("NavitMapDownloader", "map_num3=" + map_num3);
\r
749 if (map_num3 == Navit.MAP_NUM_SECONDARY)
\r
751 final_fileName = MAP_FILENAME_SEC;
\r
753 else if (map_num3 == Navit.MAP_NUM_PRIMARY)
\r
755 final_fileName = MAP_FILENAME_PRI;
\r
757 // output path for output filename
\r
758 // String PATH = Environment.getExternalStorageDirectory() + "/download/";
\r
762 URL url = new URL("http://maps.navit-project.org/api/map/?bbox=" + map_values.lon1 + ","
\r
763 + map_values.lat1 + "," + map_values.lon2 + "," + map_values.lat2);
\r
764 HttpURLConnection c = (HttpURLConnection) url.openConnection();
\r
765 c.setRequestMethod("GET");
\r
766 c.setDoOutput(true);
\r
767 c.setReadTimeout(SOCKET_READ_TIMEOUT);
\r
768 c.setConnectTimeout(SOCKET_CONNECT_TIMEOUT);
\r
769 long real_size_bytes = c.getContentLength();
\r
772 Log.d("NavitMapDownloader", "real size in bytes: " + real_size_bytes);
\r
773 if (real_size_bytes > 20)
\r
775 // change the estimated filesize to reported filesize
\r
776 map_values.est_size_bytes = real_size_bytes;
\r
778 Log.d("NavitMapDownloader", "size in bytes: " + map_values.est_size_bytes);
\r
780 File file = new File(PATH);
\r
781 File outputFile = new File(file, fileName);
\r
782 File final_outputFile = new File(file, final_fileName);
\r
783 // tests have shown that deleting the file first is sometimes faster -> so we delete it (who knows)
\r
784 outputFile.delete();
\r
785 // seems this command overwrites the output file anyway
\r
786 FileOutputStream fos = new FileOutputStream(outputFile);
\r
787 BufferedOutputStream buf = new BufferedOutputStream(fos, MAP_WRITE_FILE_BUFFER); // buffer
\r
789 InputStream is = c.getInputStream();
\r
790 BufferedInputStream bif = new BufferedInputStream(is, MAP_READ_FILE_BUFFER); // buffer
\r
792 byte[] buffer = new byte[MAP_WRITE_MEM_BUFFER]; // buffer
\r
794 int already_read = 0;
\r
795 int alt = UPDATE_PROGRESS_EVERY_CYCLE; // show progress about every xx cylces
\r
797 String kbytes_per_second = "";
\r
798 long start_timestamp = System.currentTimeMillis();
\r
799 NumberFormat formatter = new DecimalFormat("00000.0");
\r
800 String eta_string = "";
\r
801 float per_second_overall = 0f;
\r
802 long bytes_remaining = 0;
\r
803 int eta_seconds = 0;
\r
804 while ((len1 = bif.read(buffer)) != -1)
\r
808 // ok we need to be stopped! close all files and end
\r
817 already_read = already_read + len1;
\r
823 msg = handler.obtainMessage();
\r
826 b.putInt("max", (int) (map_values.est_size_bytes / 1024));
\r
827 b.putInt("cur", (int) (already_read / 1024));
\r
828 b.putInt("dialog_num", my_dialog_num);
\r
829 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
\r
830 per_second_overall = (float) already_read
\r
831 / (float) ((System.currentTimeMillis() - start_timestamp) / 1000);
\r
832 kbytes_per_second = formatter.format((per_second_overall / 1024f));
\r
833 bytes_remaining = map_values.est_size_bytes - already_read;
\r
834 eta_seconds = (int) ((float) bytes_remaining / (float) per_second_overall);
\r
835 if (eta_seconds > 60)
\r
837 eta_string = (int) (eta_seconds / 60f) + " m";
\r
841 eta_string = eta_seconds + " s";
\r
844 .putString("text", Navit.get_text("downloading") + ": " + map_values.map_name
\r
845 + "\n" + " " + (int) (already_read / 1024f / 1024f) + "Mb / "
\r
846 + (int) (map_values.est_size_bytes / 1024f / 1024f) + "Mb" + "\n" + " "
\r
847 + kbytes_per_second + "kb/s" + " " + Navit.get_text("ETA") + ": "
\r
848 + eta_string); //TRANS
\r
850 handler.sendMessage(msg);
\r
852 buf.write(buffer, 0, len1);
\r
864 // delete an already final filename, first
\r
865 final_outputFile.delete();
\r
866 // rename file to final name
\r
867 outputFile.renameTo(final_outputFile);
\r
869 catch (IOException e)
\r
871 msg = handler.obtainMessage();
\r
874 b.putInt("dialog_num", my_dialog_num);
\r
875 b.putString("text", Navit.get_text("Error downloading map!")); //TRANS
\r
877 handler.sendMessage(msg);
\r
879 Log.d("NavitMapDownloader", "Error: " + e);
\r
882 catch (Exception e)
\r
884 msg = handler.obtainMessage();
\r
887 b.putInt("dialog_num", my_dialog_num);
\r
888 b.putString("text", Navit.get_text("Error downloading map!")); //TRANS
\r
890 handler.sendMessage(msg);
\r
892 Log.d("NavitMapDownloader", "gerneral Error: " + e);
\r
896 msg = handler.obtainMessage();
\r
899 b.putInt("max", (int) (map_values.est_size_bytes / 1024));
\r
900 b.putInt("cur", (int) (map_values.est_size_bytes / 1024));
\r
901 b.putInt("dialog_num", my_dialog_num);
\r
902 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
\r
903 b.putString("text", map_values.map_name + " "+Navit.get_text("ready")); //TRANS
\r
905 handler.sendMessage(msg);
\r
908 Log.d("NavitMapDownloader", "success");
\r