Add:Android:more translation of strings, some fixes, catch xhdpi density
[profile/ivi/navit.git] / navit / navit / android / src / org / navitproject / navit / NavitMapDownloader.java
1 /**\r
2  * Navit, a modular navigation system.\r
3  * Copyright (C) 2005-2008 Navit Team\r
4  *\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
8  *\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
13  *\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
18  */\r
19 \r
20 package org.navitproject.navit;\r
21 \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
32 \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
37 \r
38 public class NavitMapDownloader\r
39 {\r
40         public static class osm_map_values\r
41         {\r
42                 String  lon1;\r
43                 String  lat1;\r
44                 String  lon2;\r
45                 String  lat2;\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
52 \r
53 \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
56                 {\r
57                         this.is_continent = is_con;\r
58                         this.continent_id = con_id;\r
59                         this.map_name = mapname;\r
60                         this.lon1 = lon_1;\r
61                         this.lat1 = lat_1;\r
62                         this.lon2 = lon_2;\r
63                         this.lat2 = lat_2;\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
68                 }\r
69         }\r
70 \r
71         //\r
72         // define the maps here\r
73         //\r
74 \r
75         static final osm_map_values     Whole_Planet                                                                    = new osm_map_values(\r
76                                                                                                                                                                                                                 "Whole Planet",\r
77                                                                                                                                                                                                                 "-180", "-90", "180",\r
78                                                                                                                                                                                                                 "90", 5985878379L,\r
79                                                                                                                                                                                                                 true, 0);\r
80         static final osm_map_values     Africa                                                                                  = new osm_map_values(\r
81                                                                                                                                                                                                                 "Africa", "-20.8",\r
82                                                                                                                                                                                                                 "-35.2", "52.5",\r
83                                                                                                                                                                                                                 "37.4", 180836389L,\r
84                                                                                                                                                                                                                 true, 1);\r
85         static final osm_map_values     Angola                                                                                  = new osm_map_values(\r
86                                                                                                                                                                                                                 "Angola", "11.4",\r
87                                                                                                                                                                                                                 "-18.1", "24.2",\r
88                                                                                                                                                                                                                 "-5.3", 56041641L,\r
89                                                                                                                                                                                                                 false, 1);\r
90         static final osm_map_values     Burundi                                                                                 = new osm_map_values(\r
91                                                                                                                                                                                                                 "Burundi", "28.9",\r
92                                                                                                                                                                                                                 "-4.5", "30.9",\r
93                                                                                                                                                                                                                 "-2.2", 56512924L,\r
94                                                                                                                                                                                                                 false, 1);\r
95         static final osm_map_values     Democratic_Republic_of_the_Congo                        = new osm_map_values(\r
96                                                                                                                                                                                                                 "Democratic Republic of the Congo",\r
97                                                                                                                                                                                                                 "11.7", "-13.6",\r
98                                                                                                                                                                                                                 "31.5", "5.7",\r
99                                                                                                                                                                                                                 65026791L, false, 1);\r
100         static final osm_map_values     Kenya                                                                                           = new osm_map_values(\r
101                                                                                                                                                                                                                 "Kenya", "33.8",\r
102                                                                                                                                                                                                                 "-5.2", "42.4",\r
103                                                                                                                                                                                                                 "4.9", 58545273L,\r
104                                                                                                                                                                                                                 false, 1);\r
105         static final osm_map_values     Lesotho                                                                                 = new osm_map_values(\r
106                                                                                                                                                                                                                 "Lesotho", "26.9",\r
107                                                                                                                                                                                                                 "-30.7", "29.6",\r
108                                                                                                                                                                                                                 "-28.4", 54791041L,\r
109                                                                                                                                                                                                                 false, 1);\r
110         static final osm_map_values     Madagascar                                                                              = new osm_map_values(\r
111                                                                                                                                                                                                                 "Madagascar", "43.0",\r
112                                                                                                                                                                                                                 "-25.8", "50.8",\r
113                                                                                                                                                                                                                 "-11.8", 56801099L,\r
114                                                                                                                                                                                                                 false, 1);\r
115         static final osm_map_values     Nambia_Botswana                                                         = new osm_map_values(\r
116                                                                                                                                                                                                                 "Nambia+Botswana",\r
117                                                                                                                                                                                                                 "11.4", "-29.1",\r
118                                                                                                                                                                                                                 "29.5", "-16.9",\r
119                                                                                                                                                                                                                 61807049L, false, 1);\r
120         static final osm_map_values     Reunion                                                                                 = new osm_map_values(\r
121                                                                                                                                                                                                                 "Reunion", "55.2",\r
122                                                                                                                                                                                                                 "-21.4", "55.9",\r
123                                                                                                                                                                                                                 "-20.9", 58537419L,\r
124                                                                                                                                                                                                                 false, 1);\r
125         static final osm_map_values     Rwanda                                                                                  = new osm_map_values(\r
126                                                                                                                                                                                                                 "Rwanda", "28.8",\r
127                                                                                                                                                                                                                 "-2.9", "30.9",\r
128                                                                                                                                                                                                                 "-1.0", 56313710L,\r
129                                                                                                                                                                                                                 false, 1);\r
130         static final osm_map_values     South_Africa                                                                    = new osm_map_values(\r
131                                                                                                                                                                                                                 "South Africa",\r
132                                                                                                                                                                                                                 "15.6", "-35.2",\r
133                                                                                                                                                                                                                 "33.3", "-21.9",\r
134                                                                                                                                                                                                                 73545245L, false, 1);\r
135         static final osm_map_values     Uganda                                                                                  = new osm_map_values(\r
136                                                                                                                                                                                                                 "Uganda", "29.3",\r
137                                                                                                                                                                                                                 "-1.6", "35.1",\r
138                                                                                                                                                                                                                 "4.3", 57376589L,\r
139                                                                                                                                                                                                                 false, 1);\r
140         static final osm_map_values     Asia                                                                                            = new osm_map_values(\r
141                                                                                                                                                                                                                 "Asia", "23.8",\r
142                                                                                                                                                                                                                 "0.1", "195.0",\r
143                                                                                                                                                                                                                 "82.4", 797725952L,\r
144                                                                                                                                                                                                                 true, 2);\r
145         static final osm_map_values     China                                                                                           = new osm_map_values(\r
146                                                                                                                                                                                                                 "China", "67.3",\r
147                                                                                                                                                                                                                 "5.3", "135.0",\r
148                                                                                                                                                                                                                 "54.5", 259945160L,\r
149                                                                                                                                                                                                                 false, 2);\r
150         static final osm_map_values     Cyprus                                                                                  = new osm_map_values(\r
151                                                                                                                                                                                                                 "Cyprus", "32.0",\r
152                                                                                                                                                                                                                 "34.5", "34.9",\r
153                                                                                                                                                                                                                 "35.8", 58585278L,\r
154                                                                                                                                                                                                                 false, 2);\r
155         static final osm_map_values     India_Nepal                                                                             = new osm_map_values(\r
156                                                                                                                                                                                                                 "India+Nepal",\r
157                                                                                                                                                                                                                 "67.9", "5.5",\r
158                                                                                                                                                                                                                 "89.6", "36.0",\r
159                                                                                                                                                                                                                 82819344L, false, 2);\r
160         static final osm_map_values     Indonesia                                                                               = new osm_map_values(\r
161                                                                                                                                                                                                                 "Indonesia", "93.7",\r
162                                                                                                                                                                                                                 "-17.3", "155.5",\r
163                                                                                                                                                                                                                 "7.6", 74648081L,\r
164                                                                                                                                                                                                                 false, 2);\r
165         static final osm_map_values     Iran                                                                                            = new osm_map_values(\r
166                                                                                                                                                                                                                 "Iran", "43.5",\r
167                                                                                                                                                                                                                 "24.4", "63.6",\r
168                                                                                                                                                                                                                 "40.4", 69561312L,\r
169                                                                                                                                                                                                                 false, 2);\r
170         static final osm_map_values     Iraq                                                                                            = new osm_map_values(\r
171                                                                                                                                                                                                                 "Iraq", "38.7",\r
172                                                                                                                                                                                                                 "28.5", "49.2",\r
173                                                                                                                                                                                                                 "37.4", 59146383L,\r
174                                                                                                                                                                                                                 false, 2);\r
175         static final osm_map_values     Israel                                                                                  = new osm_map_values(\r
176                                                                                                                                                                                                                 "Israel", "33.99",\r
177                                                                                                                                                                                                                 "29.8", "35.95",\r
178                                                                                                                                                                                                                 "33.4", 65065351L,\r
179                                                                                                                                                                                                                 false, 2);\r
180         static final osm_map_values     Japan_Korea_Taiwan                                                      = new osm_map_values(\r
181                                                                                                                                                                                                                 "Japan+Korea+Taiwan",\r
182                                                                                                                                                                                                                 "117.6", "20.5",\r
183                                                                                                                                                                                                                 "151.3", "47.1",\r
184                                                                                                                                                                                                                 305538751L, false, 2);\r
185         static final osm_map_values     Malasia_Singapore                                                               = new osm_map_values(\r
186                                                                                                                                                                                                                 "Malasia+Singapore",\r
187                                                                                                                                                                                                                 "94.3", "-5.9",\r
188                                                                                                                                                                                                                 "108.6", "6.8",\r
189                                                                                                                                                                                                                 58849792L, false, 2);\r
190         static final osm_map_values     Mongolia                                                                                        = new osm_map_values(\r
191                                                                                                                                                                                                                 "Mongolia", "87.5",\r
192                                                                                                                                                                                                                 "41.4", "120.3",\r
193                                                                                                                                                                                                                 "52.7", 60871187L,\r
194                                                                                                                                                                                                                 false, 2);\r
195         static final osm_map_values     Thailand                                                                                        = new osm_map_values(\r
196                                                                                                                                                                                                                 "Thailand", "97.5",\r
197                                                                                                                                                                                                                 "5.7", "105.2",\r
198                                                                                                                                                                                                                 "19.7", 62422864L,\r
199                                                                                                                                                                                                                 false, 2);\r
200         static final osm_map_values     Turkey                                                                                  = new osm_map_values(\r
201                                                                                                                                                                                                                 "Turkey", "25.1",\r
202                                                                                                                                                                                                                 "35.8", "46.4",\r
203                                                                                                                                                                                                                 "42.8", 81758047L,\r
204                                                                                                                                                                                                                 false, 2);\r
205         static final osm_map_values     UAE_Other                                                                               = new osm_map_values(\r
206                                                                                                                                                                                                                 "UAE+Other", "51.5",\r
207                                                                                                                                                                                                                 "22.6", "56.7",\r
208                                                                                                                                                                                                                 "26.5", 57419510L,\r
209                                                                                                                                                                                                                 false, 2);\r
210         static final osm_map_values     Australia2                                                                              = new osm_map_values(\r
211                                                                                                                                                                                                                 "Australia", "110.5",\r
212                                                                                                                                                                                                                 "-44.2", "154.9",\r
213                                                                                                                                                                                                                 "-9.2", 128502185L,\r
214                                                                                                                                                                                                                 true, 3);\r
215         static final osm_map_values     Australia                                                                               = new osm_map_values(\r
216                                                                                                                                                                                                                 "Australia", "110.5",\r
217                                                                                                                                                                                                                 "-44.2", "154.9",\r
218                                                                                                                                                                                                                 "-9.2", 128502185L,\r
219                                                                                                                                                                                                                 false, 3);\r
220         static final osm_map_values     Tasmania                                                                                        = new osm_map_values(\r
221                                                                                                                                                                                                                 "Tasmania", "144.0",\r
222                                                                                                                                                                                                                 "-45.1", "155.3",\r
223                                                                                                                                                                                                                 "-24.8", 103573989L,\r
224                                                                                                                                                                                                                 false, 3);\r
225         static final osm_map_values     Victoria_New_South_Wales                                        = new osm_map_values(\r
226                                                                                                                                                                                                                 "Victoria+New South Wales",\r
227                                                                                                                                                                                                                 "140.7", "-39.4",\r
228                                                                                                                                                                                                                 "153.7", "-26.9",\r
229                                                                                                                                                                                                                 99307594L, false, 3);\r
230         static final osm_map_values     New_Zealand                                                                             = new osm_map_values(\r
231                                                                                                                                                                                                                 "New Zealand",\r
232                                                                                                                                                                                                                 "165.2", "-47.6",\r
233                                                                                                                                                                                                                 "179.1", "-33.7",\r
234                                                                                                                                                                                                                 64757454L, false, 3);\r
235         static final osm_map_values     Europe                                                                                  = new osm_map_values(\r
236                                                                                                                                                                                                                 "Europe", "-12.97",\r
237                                                                                                                                                                                                                 "33.59", "34.15",\r
238                                                                                                                                                                                                                 "72.10", 2753910015L,\r
239                                                                                                                                                                                                                 true, 4);\r
240         static final osm_map_values     Western_Europe                                                                  = new osm_map_values(\r
241                                                                                                                                                                                                                 "Western Europe",\r
242                                                                                                                                                                                                                 "-17.6", "34.5",\r
243                                                                                                                                                                                                                 "42.9", "70.9",\r
244                                                                                                                                                                                                                 2832986851L, false, 4);\r
245         static final osm_map_values     Austria                                                                                 = new osm_map_values(\r
246                                                                                                                                                                                                                 "Austria", "9.4",\r
247                                                                                                                                                                                                                 "46.32", "17.21",\r
248                                                                                                                                                                                                                 "49.1", 222359992L,\r
249                                                                                                                                                                                                                 false, 4);\r
250         static final osm_map_values     BeNeLux                                                                                 = new osm_map_values(\r
251                                                                                                                                                                                                                 "BeNeLux", "2.08",\r
252                                                                                                                                                                                                                 "48.87", "7.78",\r
253                                                                                                                                                                                                                 "54.52", 533865194L,\r
254                                                                                                                                                                                                                 false, 4);\r
255         static final osm_map_values     Faroe_Islands                                                                   = new osm_map_values(\r
256                                                                                                                                                                                                                 "Faroe Islands",\r
257                                                                                                                                                                                                                 "-7.8", "61.3",\r
258                                                                                                                                                                                                                 "-6.1", "62.5",\r
259                                                                                                                                                                                                                 54526101L, false, 4);\r
260         static final osm_map_values     France                                                                                  = new osm_map_values(\r
261                                                                                                                                                                                                                 "France", "-5.45",\r
262                                                                                                                                                                                                                 "42.00", "8.44",\r
263                                                                                                                                                                                                                 "51.68", 1112047845L,\r
264                                                                                                                                                                                                                 false, 4);\r
265         static final osm_map_values     Germany                                                                                 = new osm_map_values(\r
266                                                                                                                                                                                                                 "Germany", "5.18",\r
267                                                                                                                                                                                                                 "46.84", "15.47",\r
268                                                                                                                                                                                                                 "55.64", 944716238L,\r
269                                                                                                                                                                                                                 false, 4);\r
270         static final osm_map_values     Bavaria                                                                                 = new osm_map_values(\r
271                                                                                                                                                                                                                 "Bavaria", "10.3",\r
272                                                                                                                                                                                                                 "47.8", "13.6",\r
273                                                                                                                                                                                                                 "49.7", 131799419L,\r
274                                                                                                                                                                                                                 false, 4);\r
275         static final osm_map_values     Saxonia                                                                                 = new osm_map_values(\r
276                                                                                                                                                                                                                 "Saxonia", "11.8",\r
277                                                                                                                                                                                                                 "50.1", "15.0",\r
278                                                                                                                                                                                                                 "51.7", 112073909L,\r
279                                                                                                                                                                                                                 false, 4);\r
280         static final osm_map_values     Germany_Austria_Switzerland                             = new osm_map_values(\r
281                                                                                                                                                                                                                 "Germany+Austria+Switzerland",\r
282                                                                                                                                                                                                                 "3.4", "44.5",\r
283                                                                                                                                                                                                                 "18.6", "55.1",\r
284                                                                                                                                                                                                                 1385785353L, false, 4);\r
285         static final osm_map_values     Iceland                                                                                 = new osm_map_values(\r
286                                                                                                                                                                                                                 "Iceland", "-25.3",\r
287                                                                                                                                                                                                                 "62.8", "-11.4",\r
288                                                                                                                                                                                                                 "67.5", 57281405L,\r
289                                                                                                                                                                                                                 false, 4);\r
290         static final osm_map_values     Ireland                                                                                 = new osm_map_values(\r
291                                                                                                                                                                                                                 "Ireland", "-11.17",\r
292                                                                                                                                                                                                                 "51.25", "-5.23",\r
293                                                                                                                                                                                                                 "55.9", 70186936L,\r
294                                                                                                                                                                                                                 false, 4);\r
295         static final osm_map_values     Italy                                                                                           = new osm_map_values(\r
296                                                                                                                                                                                                                 "Italy", "6.52",\r
297                                                                                                                                                                                                                 "36.38", "18.96",\r
298                                                                                                                                                                                                                 "47.19", 291401314L,\r
299                                                                                                                                                                                                                 false, 4);\r
300         static final osm_map_values     Spain_Portugal                                                                  = new osm_map_values(\r
301                                                                                                                                                                                                                 "Spain+Portugal",\r
302                                                                                                                                                                                                                 "-11.04", "34.87",\r
303                                                                                                                                                                                                                 "4.62", "44.41",\r
304                                                                                                                                                                                                                 292407746L, false, 4);\r
305         static final osm_map_values     Mallorca                                                                                        = new osm_map_values(\r
306                                                                                                                                                                                                                 "Mallorca", "2.2",\r
307                                                                                                                                                                                                                 "38.8", "4.7",\r
308                                                                                                                                                                                                                 "40.2", 59700600L,\r
309                                                                                                                                                                                                                 false, 4);\r
310         static final osm_map_values     Galicia                                                                                 = new osm_map_values(\r
311                                                                                                                                                                                                                 "Galicia", "-10.0",\r
312                                                                                                                                                                                                                 "41.7", "-6.3",\r
313                                                                                                                                                                                                                 "44.1", 64605237L,\r
314                                                                                                                                                                                                                 false, 4);\r
315         static final osm_map_values     Scandinavia                                                                             = new osm_map_values(\r
316                                                                                                                                                                                                                 "Scandinavia", "4.0",\r
317                                                                                                                                                                                                                 "54.4", "32.1",\r
318                                                                                                                                                                                                                 "71.5", 299021928L,\r
319                                                                                                                                                                                                                 false, 4);\r
320         static final osm_map_values     Finland                                                                                 = new osm_map_values(\r
321                                                                                                                                                                                                                 "Finland", "18.6",\r
322                                                                                                                                                                                                                 "59.2", "32.3",\r
323                                                                                                                                                                                                                 "70.3", 128871467L,\r
324                                                                                                                                                                                                                 false, 4);\r
325         static final osm_map_values     Denmark                                                                                 = new osm_map_values(\r
326                                                                                                                                                                                                                 "Denmark", "7.49",\r
327                                                                                                                                                                                                                 "54.33", "13.05",\r
328                                                                                                                                                                                                                 "57.88", 120025875L,\r
329                                                                                                                                                                                                                 false, 4);\r
330         static final osm_map_values     Switzerland                                                                             = new osm_map_values(\r
331                                                                                                                                                                                                                 "Switzerland",\r
332                                                                                                                                                                                                                 "5.79", "45.74",\r
333                                                                                                                                                                                                                 "10.59", "47.84",\r
334                                                                                                                                                                                                                 162616817L, false, 4);\r
335         static final osm_map_values     UK                                                                                                      = new osm_map_values("UK",\r
336                                                                                                                                                                                                                 "-9.7", "49.6",\r
337                                                                                                                                                                                                                 "2.2", "61.2",\r
338                                                                                                                                                                                                                 245161510L, false, 4);\r
339         static final osm_map_values     Bulgaria                                                                                        = new osm_map_values(\r
340                                                                                                                                                                                                                 "Bulgaria", "24.7",\r
341                                                                                                                                                                                                                 "42.1", "24.8",\r
342                                                                                                                                                                                                                 "42.1", 56607427L,\r
343                                                                                                                                                                                                                 false, 4);\r
344         static final osm_map_values     Czech_Republic                                                                  = new osm_map_values(\r
345                                                                                                                                                                                                                 "Czech Republic",\r
346                                                                                                                                                                                                                 "11.91", "48.48",\r
347                                                                                                                                                                                                                 "19.02", "51.17",\r
348                                                                                                                                                                                                                 234138824L, false, 4);\r
349         static final osm_map_values     Croatia                                                                                 = new osm_map_values(\r
350                                                                                                                                                                                                                 "Croatia", "13.4",\r
351                                                                                                                                                                                                                 "42.1", "19.4",\r
352                                                                                                                                                                                                                 "46.9", 99183280L,\r
353                                                                                                                                                                                                                 false, 4);\r
354         static final osm_map_values     Estonia                                                                                 = new osm_map_values(\r
355                                                                                                                                                                                                                 "Estonia", "21.5",\r
356                                                                                                                                                                                                                 "57.5", "28.2",\r
357                                                                                                                                                                                                                 "59.6", 79276178L,\r
358                                                                                                                                                                                                                 false, 4);\r
359         static final osm_map_values     Greece                                                                                  = new osm_map_values(\r
360                                                                                                                                                                                                                 "Greece", "28.9",\r
361                                                                                                                                                                                                                 "37.8", "29.0",\r
362                                                                                                                                                                                                                 "37.8", 55486527L,\r
363                                                                                                                                                                                                                 false, 4);\r
364         static final osm_map_values     Crete                                                                                           = new osm_map_values(\r
365                                                                                                                                                                                                                 "Crete", "23.3",\r
366                                                                                                                                                                                                                 "34.5", "26.8",\r
367                                                                                                                                                                                                                 "36.0", 57032630L,\r
368                                                                                                                                                                                                                 false, 4);\r
369         static final osm_map_values     Hungary                                                                                 = new osm_map_values(\r
370                                                                                                                                                                                                                 "Hungary", "16.08",\r
371                                                                                                                                                                                                                 "45.57", "23.03",\r
372                                                                                                                                                                                                                 "48.39", 109831319L,\r
373                                                                                                                                                                                                                 false, 4);\r
374         static final osm_map_values     Latvia                                                                                  = new osm_map_values(\r
375                                                                                                                                                                                                                 "Latvia", "20.7",\r
376                                                                                                                                                                                                                 "55.6", "28.3",\r
377                                                                                                                                                                                                                 "58.1", 71490706L,\r
378                                                                                                                                                                                                                 false, 4);\r
379         static final osm_map_values     Lithuania                                                                               = new osm_map_values(\r
380                                                                                                                                                                                                                 "Lithuania", "20.9",\r
381                                                                                                                                                                                                                 "53.8", "26.9",\r
382                                                                                                                                                                                                                 "56.5", 67992457L,\r
383                                                                                                                                                                                                                 false, 4);\r
384         static final osm_map_values     Poland                                                                                  = new osm_map_values(\r
385                                                                                                                                                                                                                 "Poland", "13.6",\r
386                                                                                                                                                                                                                 "48.8", "24.5",\r
387                                                                                                                                                                                                                 "55.0", 266136768L,\r
388                                                                                                                                                                                                                 false, 4);\r
389         static final osm_map_values     Romania                                                                                 = new osm_map_values(\r
390                                                                                                                                                                                                                 "Romania", "20.3",\r
391                                                                                                                                                                                                                 "43.5", "29.9",\r
392                                                                                                                                                                                                                 "48.4", 134525863L,\r
393                                                                                                                                                                                                                 false, 4);\r
394         static final osm_map_values     North_America                                                                   = new osm_map_values(\r
395                                                                                                                                                                                                                 "North America",\r
396                                                                                                                                                                                                                 "-178.1", "6.5",\r
397                                                                                                                                                                                                                 "-10.4", "84.0",\r
398                                                                                                                                                                                                                 2477309662L, true, 5);\r
399         static final osm_map_values     Alaska                                                                                  = new osm_map_values(\r
400                                                                                                                                                                                                                 "Alaska", "-179.5",\r
401                                                                                                                                                                                                                 "49.5", "-129",\r
402                                                                                                                                                                                                                 "71.6", 72320027L,\r
403                                                                                                                                                                                                                 false, 5);\r
404         static final osm_map_values     Canada                                                                                  = new osm_map_values(\r
405                                                                                                                                                                                                                 "Canada", "-141.3",\r
406                                                                                                                                                                                                                 "41.5", "-52.2",\r
407                                                                                                                                                                                                                 "70.2", 937813467L,\r
408                                                                                                                                                                                                                 false, 5);\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
413                                                                                                                                                                                                                 false, 5);\r
414         static final osm_map_values     USA__except_Alaska_and_Hawaii_                  = new osm_map_values(\r
415                                                                                                                                                                                                                 "USA (except Alaska and Hawaii)",\r
416                                                                                                                                                                                                                 "-125.4", "24.3",\r
417                                                                                                                                                                                                                 "-66.5", "49.3",\r
418                                                                                                                                                                                                                 2216912004L, false, 5);\r
419         static final osm_map_values     Nevada                                                                                  = new osm_map_values(\r
420                                                                                                                                                                                                                 "Nevada", "-120.2",\r
421                                                                                                                                                                                                                 "35.0", "-113.8",\r
422                                                                                                                                                                                                                 "42.1", 136754975L,\r
423                                                                                                                                                                                                                 false, 5);\r
424         static final osm_map_values     Oregon                                                                                  = new osm_map_values(\r
425                                                                                                                                                                                                                 "Oregon", "-124.8",\r
426                                                                                                                                                                                                                 "41.8", "-116.3",\r
427                                                                                                                                                                                                                 "46.3", 101627308L,\r
428                                                                                                                                                                                                                 false, 5);\r
429         static final osm_map_values     Washington_State                                                                = new osm_map_values(\r
430                                                                                                                                                                                                                 "Washington State",\r
431                                                                                                                                                                                                                 "-125.0", "45.5",\r
432                                                                                                                                                                                                                 "-116.9", "49.0",\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
436                                                                                                                                                                                                                 "-83.5", "-56.3",\r
437                                                                                                                                                                                                                 "-30.8", "13.7",\r
438                                                                                                                                                                                                                 159615197L, true, 6);\r
439         static final osm_map_values     Argentina                                                                               = new osm_map_values(\r
440                                                                                                                                                                                                                 "Argentina", "-73.9",\r
441                                                                                                                                                                                                                 "-57.3", "-51.6",\r
442                                                                                                                                                                                                                 "-21.0", 87516152L,\r
443                                                                                                                                                                                                                 false, 6);\r
444         static final osm_map_values     Argentina_Chile                                                         = new osm_map_values(\r
445                                                                                                                                                                                                                 "Argentina+Chile",\r
446                                                                                                                                                                                                                 "-77.2", "-56.3",\r
447                                                                                                                                                                                                                 "-52.7", "-16.1",\r
448                                                                                                                                                                                                                 91976696L, false, 6);\r
449         static final osm_map_values     Bolivia                                                                                 = new osm_map_values(\r
450                                                                                                                                                                                                                 "Bolivia", "-70.5",\r
451                                                                                                                                                                                                                 "-23.1", "-57.3",\r
452                                                                                                                                                                                                                 "-9.3", 58242168L,\r
453                                                                                                                                                                                                                 false, 6);\r
454         static final osm_map_values     Brazil                                                                                  = new osm_map_values(\r
455                                                                                                                                                                                                                 "Brazil", "-71.4",\r
456                                                                                                                                                                                                                 "-34.7", "-32.8",\r
457                                                                                                                                                                                                                 "5.4", 105527899L,\r
458                                                                                                                                                                                                                 false, 6);\r
459         static final osm_map_values     Cuba                                                                                            = new osm_map_values(\r
460                                                                                                                                                                                                                 "Cuba", "-85.3",\r
461                                                                                                                                                                                                                 "19.6", "-74.0",\r
462                                                                                                                                                                                                                 "23.6", 56608942L,\r
463                                                                                                                                                                                                                 false, 6);\r
464         static final osm_map_values     Colombia                                                                                        = new osm_map_values(\r
465                                                                                                                                                                                                                 "Colombia", "-79.1",\r
466                                                                                                                                                                                                                 "-4.0", "-66.7",\r
467                                                                                                                                                                                                                 "12.6", 78658454L,\r
468                                                                                                                                                                                                                 false, 6);\r
469         static final osm_map_values     Ecuador                                                                                 = new osm_map_values(\r
470                                                                                                                                                                                                                 "Ecuador", "-82.6",\r
471                                                                                                                                                                                                                 "-5.4", "-74.4",\r
472                                                                                                                                                                                                                 "2.3", 61501914L,\r
473                                                                                                                                                                                                                 false, 6);\r
474         static final osm_map_values     Guyana_Suriname_Guyane_Francaise                        = new osm_map_values(\r
475                                                                                                                                                                                                                 "Guyana+Suriname+Guyane Francaise",\r
476                                                                                                                                                                                                                 "-62.0", "1.0",\r
477                                                                                                                                                                                                                 "-51.2", "8.9",\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
481                                                                                                                                                                                                                 "-74.8", "17.3",\r
482                                                                                                                                                                                                                 "-68.2", "20.1",\r
483                                                                                                                                                                                                                 63528584L, false, 6);\r
484         static final osm_map_values     Jamaica                                                                                 = new osm_map_values(\r
485                                                                                                                                                                                                                 "Jamaica", "-78.6",\r
486                                                                                                                                                                                                                 "17.4", "-75.9",\r
487                                                                                                                                                                                                                 "18.9", 53958307L,\r
488                                                                                                                                                                                                                 false, 6);\r
489         static final osm_map_values     Mexico                                                                                  = new osm_map_values(\r
490                                                                                                                                                                                                                 "Mexico", "-117.6",\r
491                                                                                                                                                                                                                 "14.1", "-86.4",\r
492                                                                                                                                                                                                                 "32.8", 251108617L,\r
493                                                                                                                                                                                                                 false, 6);\r
494         static final osm_map_values     Paraguay                                                                                        = new osm_map_values(\r
495                                                                                                                                                                                                                 "Paraguay", "-63.8",\r
496                                                                                                                                                                                                                 "-28.1", "-53.6",\r
497                                                                                                                                                                                                                 "-18.8", 57188715L,\r
498                                                                                                                                                                                                                 false, 6);\r
499         static final osm_map_values     Peru                                                                                            = new osm_map_values(\r
500                                                                                                                                                                                                                 "Peru", "-82.4",\r
501                                                                                                                                                                                                                 "-18.1", "-67.5",\r
502                                                                                                                                                                                                                 "0.4", 65421441L,\r
503                                                                                                                                                                                                                 false, 6);\r
504         static final osm_map_values     Uruguay                                                                                 = new osm_map_values(\r
505                                                                                                                                                                                                                 "Uruguay", "-59.2",\r
506                                                                                                                                                                                                                 "-36.5", "-51.7",\r
507                                                                                                                                                                                                                 "-29.7", 63542225L,\r
508                                                                                                                                                                                                                 false, 6);\r
509         static final osm_map_values     Venezuela                                                                               = new osm_map_values(\r
510                                                                                                                                                                                                                 "Venezuela", "-73.6",\r
511                                                                                                                                                                                                                 "0.4", "-59.7",\r
512                                                                                                                                                                                                                 "12.8", 64838882L,\r
513                                                                                                                                                                                                                 false, 6);\r
514 \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
529 \r
530         public static String[]                  OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE    = null;\r
531 \r
532         public static int[]                             OSM_MAP_NAME_ORIG_ID_LIST                                       = null;\r
533 \r
534         private static Boolean                  already_inited                                                                  = false;\r
535 \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
543 \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
548 \r
549         static final int                                        MAX_MAP_COUNT                                                                   = 200;\r
550 \r
551         public class ProgressThread extends Thread\r
552         {\r
553                 Handler                 mHandler;\r
554                 osm_map_values  map_values;\r
555                 int                             map_num;\r
556                 int                             my_dialog_num;\r
557 \r
558                 ProgressThread(Handler h, osm_map_values map_values, int map_num2)\r
559                 {\r
560                         this.mHandler = h;\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
564                         {\r
565                                 this.my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;\r
566                         }\r
567                         else if (this.map_num == Navit.MAP_NUM_SECONDARY)\r
568                         {\r
569                                 this.my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;\r
570                         }\r
571                 }\r
572 \r
573                 public void run()\r
574                 {\r
575                         stop_me = false;\r
576                         int exit_code = download_osm_map(mHandler, map_values, this.map_num);\r
577 \r
578                         // ok, remove dialog\r
579                         Message msg = mHandler.obtainMessage();\r
580                         Bundle b = new Bundle();\r
581                         msg.what = 0;\r
582                         b.putInt("dialog_num", this.my_dialog_num);\r
583                         b.putInt("exit_code", exit_code);\r
584                         msg.setData(b);\r
585                         mHandler.sendMessage(msg);\r
586                 }\r
587 \r
588                 public void stop_thread()\r
589                 {\r
590                         stop_me = true;\r
591                         Log.d("NavitMapDownloader", "stop_me -> true");\r
592                 }\r
593         }\r
594 \r
595         public Navit    navit_jmain     = null;\r
596 \r
597         public NavitMapDownloader(Navit main)\r
598         {\r
599                 this.navit_jmain = main;\r
600         }\r
601 \r
602         public static void init()\r
603         {\r
604                 // need only init once\r
605                 if (already_inited) { return; }\r
606 \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
612                 int count = 0;\r
613                 Log.v("NavitMapDownloader", "init maps");\r
614                 for (int i = 0; i < OSM_MAPS.length; i++)\r
615                 {\r
616                         already_added[i] = false;\r
617                 }\r
618                 for (int i = 0; i < OSM_MAPS.length; i++)\r
619                 {\r
620                         //Log.v("NavitMapDownloader", "i=" + i);\r
621                         // look for continents only\r
622                         if (OSM_MAPS[i].is_continent)\r
623                         {\r
624                                 if (count > 0)\r
625                                 {\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
630                                         count++;\r
631                                 }\r
632 \r
633                                 cur_continent = OSM_MAPS[i].continent_id;\r
634                                 //Log.v("NavitMapDownloader", "found cont=" + cur_continent);\r
635                                 // add this cont.\r
636                                 //temp_m[count] = OSM_MAPS[i].map_name;\r
637                                 temp_ml[count] = OSM_MAPS[i].text_for_select_list;\r
638                                 temp_i[count] = i;\r
639                                 count++;\r
640                                 already_added[i] = true;\r
641                                 for (int j = 0; j < OSM_MAPS.length; j++)\r
642                                 {\r
643                                         // if (already_added[j] == null)\r
644                                         if (!already_added[j])\r
645                                         {\r
646                                                 // look for maps in that continent\r
647                                                 if ((OSM_MAPS[j].continent_id == cur_continent) && (!OSM_MAPS[j].is_continent))\r
648                                                 {\r
649                                                         //Log.v("NavitMapDownloader", "found map=" + j + " c=" + cur_continent);\r
650                                                         // add this map.\r
651                                                         //temp_m[count] = OSM_MAPS[j].map_name;\r
652                                                         temp_ml[count] = " * " + OSM_MAPS[j].text_for_select_list;\r
653                                                         temp_i[count] = j;\r
654                                                         count++;\r
655                                                         already_added[j] = true;\r
656                                                 }\r
657                                         }\r
658                                 }\r
659                         }\r
660                 }\r
661                 // add the rest of the list (dont have a continent)\r
662                 cur_continent = 9999; // unknown\r
663                 int found = 0;\r
664                 for (int i = 0; i < OSM_MAPS.length; i++)\r
665                 {\r
666                         if (!already_added[i])\r
667                         {\r
668                                 if (found == 0)\r
669                                 {\r
670                                         found = 1;\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
675                                         count++;\r
676                                 }\r
677 \r
678                                 //Log.v("NavitMapDownloader", "found map(loose)=" + i + " c=" + cur_continent);\r
679                                 // add this map.\r
680                                 //temp_m[count] = OSM_MAPS[i].map_name;\r
681                                 temp_ml[count] = " # " + OSM_MAPS[i].text_for_select_list;\r
682                                 temp_i[count] = i;\r
683                                 count++;\r
684                                 already_added[i] = true;\r
685                         }\r
686                 }\r
687 \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
692 \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
696 \r
697                 for (int i = 0; i < count; i++)\r
698                 {\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
702                 }\r
703 \r
704                 already_inited = true;\r
705         }\r
706 \r
707         public int download_osm_map(Handler handler, osm_map_values map_values, int map_num3)\r
708         {\r
709                 int exit_code = 1;\r
710 \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
714                 {\r
715                         my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;\r
716                         //Log.v("NavitMapDownloader", "PRI");\r
717                 }\r
718                 else if (map_num3 == Navit.MAP_NUM_SECONDARY)\r
719                 {\r
720                         my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;\r
721                         //Log.v("NavitMapDownloader", "SEC");\r
722                 }\r
723                 //Log.v("NavitMapDownloader", "map_num3=" + map_num3);\r
724 \r
725                 Message msg = handler.obtainMessage();\r
726                 Bundle b = new Bundle();\r
727                 msg.what = 1;\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
733                 msg.setData(b);\r
734                 handler.sendMessage(msg);\r
735                 try\r
736                 {\r
737                         // little pause here\r
738                         Thread.sleep(10);\r
739                 }\r
740                 catch (InterruptedException e1)\r
741                 {\r
742                 }\r
743 \r
744                 // output filename\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
750                 {\r
751                         final_fileName = MAP_FILENAME_SEC;\r
752                 }\r
753                 else if (map_num3 == Navit.MAP_NUM_PRIMARY)\r
754                 {\r
755                         final_fileName = MAP_FILENAME_PRI;\r
756                 }\r
757                 // output path for output filename\r
758                 // String PATH = Environment.getExternalStorageDirectory() + "/download/";\r
759 \r
760                 try\r
761                 {\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
770                         c.connect();\r
771 \r
772                         Log.d("NavitMapDownloader", "real size in bytes: " + real_size_bytes);\r
773                         if (real_size_bytes > 20)\r
774                         {\r
775                                 // change the estimated filesize to reported filesize\r
776                                 map_values.est_size_bytes = real_size_bytes;\r
777                         }\r
778                         Log.d("NavitMapDownloader", "size in bytes: " + map_values.est_size_bytes);\r
779 \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
788 \r
789                         InputStream is = c.getInputStream();\r
790                         BufferedInputStream bif = new BufferedInputStream(is, MAP_READ_FILE_BUFFER); // buffer\r
791 \r
792                         byte[] buffer = new byte[MAP_WRITE_MEM_BUFFER]; // buffer\r
793                         int len1 = 0;\r
794                         int already_read = 0;\r
795                         int alt = UPDATE_PROGRESS_EVERY_CYCLE; // show progress about every xx cylces\r
796                         int alt_cur = 0;\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
805                         {\r
806                                 if (stop_me)\r
807                                 {\r
808                                         // ok we need to be stopped! close all files and end\r
809                                         buf.flush();\r
810                                         buf.close();\r
811                                         fos.close();\r
812                                         bif.close();\r
813                                         is.close();\r
814                                         c.disconnect();\r
815                                         return 2;\r
816                                 }\r
817                                 already_read = already_read + len1;\r
818                                 alt_cur++;\r
819                                 if (alt_cur > alt)\r
820                                 {\r
821                                         alt_cur = 0;\r
822 \r
823                                         msg = handler.obtainMessage();\r
824                                         b = new Bundle();\r
825                                         msg.what = 1;\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
836                                         {\r
837                                                 eta_string = (int) (eta_seconds / 60f) + " m";\r
838                                         }\r
839                                         else\r
840                                         {\r
841                                                 eta_string = eta_seconds + " s";\r
842                                         }\r
843                                         b\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
849                                         msg.setData(b);\r
850                                         handler.sendMessage(msg);\r
851                                 }\r
852                                 buf.write(buffer, 0, len1);\r
853                         }\r
854                         buf.flush();\r
855 \r
856                         buf.close();\r
857                         fos.close();\r
858 \r
859                         bif.close();\r
860                         is.close();\r
861 \r
862                         c.disconnect();\r
863 \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
868                 }\r
869                 catch (IOException e)\r
870                 {\r
871                         msg = handler.obtainMessage();\r
872                         b = new Bundle();\r
873                         msg.what = 2;\r
874                         b.putInt("dialog_num", my_dialog_num);\r
875                         b.putString("text", Navit.get_text("Error downloading map!")); //TRANS\r
876                         msg.setData(b);\r
877                         handler.sendMessage(msg);\r
878 \r
879                         Log.d("NavitMapDownloader", "Error: " + e);\r
880                         exit_code = 3;\r
881                 }\r
882                 catch (Exception e)\r
883                 {\r
884                         msg = handler.obtainMessage();\r
885                         b = new Bundle();\r
886                         msg.what = 2;\r
887                         b.putInt("dialog_num", my_dialog_num);\r
888                         b.putString("text", Navit.get_text("Error downloading map!")); //TRANS\r
889                         msg.setData(b);\r
890                         handler.sendMessage(msg);\r
891 \r
892                         Log.d("NavitMapDownloader", "gerneral Error: " + e);\r
893                         exit_code = 4;\r
894                 }\r
895 \r
896                 msg = handler.obtainMessage();\r
897                 b = new Bundle();\r
898                 msg.what = 1;\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
904                 msg.setData(b);\r
905                 handler.sendMessage(msg);\r
906 \r
907 \r
908                 Log.d("NavitMapDownloader", "success");\r
909                 exit_code = 0;\r
910                 return exit_code;\r
911         }\r
912 }\r