Add:Android:use and download 2 maps
[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 \r
51                 public osm_map_values(String mapname, String lon_1, String lat_1, String lon_2, String lat_2,\r
52                                 long bytes_est)\r
53                 {\r
54                         this.map_name = mapname;\r
55                         this.lon1 = lon_1;\r
56                         this.lat1 = lat_1;\r
57                         this.lon2 = lon_2;\r
58                         this.lat2 = lat_2;\r
59                         this.est_size_bytes = bytes_est;\r
60                         this.est_size_bytes_human_string = " ca. "\r
61                                         + (int) ((float) (this.est_size_bytes) / 1024f / 1024f) + "MB";\r
62                         this.text_for_select_list = this.map_name + " " + this.est_size_bytes_human_string;\r
63                 }\r
64         }\r
65 \r
66         /*\r
67          * coords for predefined maps:\r
68          * \r
69          * <a onclick='predefined(5.18,46.84,15.47,55.64)'>Germany</a>\r
70          * <a onclick='predefined(2.08,48.87,7.78,54.52)'>BeNeLux</a>\r
71          * <a onclick='predefined(9.4,46.32,17.21,49.1)'>Austria</a> 209 MBytes = 219152384 Bytes\r
72          */\r
73         //\r
74         // define the maps here\r
75         //                                                          name     , lon1 , lat1   , lon2   , lat2, est. size in bytes\r
76         /*\r
77          * public static osm_map_values austria = new osm_map_values("Austria",\r
78          * "9.4", "46.32", "17.21",\r
79          * "49.1", 222000000);\r
80          * public static osm_map_values benelux = new osm_map_values("BeNeLux",\r
81          * "2.08", "48.87", "7.78",\r
82          * "54.52", 530000000);\r
83          * public static osm_map_values germany = new osm_map_values("Germany",\r
84          * "5.18", "46.84", "15.47",\r
85          * "55.64", 943000000);\r
86          */\r
87 \r
88 \r
89         public static osm_map_values            Whole_Planet                                                                    = new osm_map_values(\r
90                                                                                                                                                                                                                         "Whole Planet",\r
91                                                                                                                                                                                                                         "-180", "-90",\r
92                                                                                                                                                                                                                         "180", "90",\r
93                                                                                                                                                                                                                         5985878379L);\r
94         public static osm_map_values            Africa                                                                                  = new osm_map_values(\r
95                                                                                                                                                                                                                         "Africa", "-20.8",\r
96                                                                                                                                                                                                                         "-35.2", "52.5",\r
97                                                                                                                                                                                                                         "37.4", 180836389L);\r
98         public static osm_map_values            Angola                                                                                  = new osm_map_values(\r
99                                                                                                                                                                                                                         "Angola", "11.4",\r
100                                                                                                                                                                                                                         "-18.1", "24.2",\r
101                                                                                                                                                                                                                         "-5.3", 56041641L);\r
102         public static osm_map_values            Burundi                                                                                 = new osm_map_values(\r
103                                                                                                                                                                                                                         "Burundi", "28.9",\r
104                                                                                                                                                                                                                         "-4.5", "30.9",\r
105                                                                                                                                                                                                                         "-2.2", 56512924L);\r
106         public static osm_map_values            Democratic_Republic_of_the_Congo                        = new osm_map_values(\r
107                                                                                                                                                                                                                         "Democratic Republic of the Congo",\r
108                                                                                                                                                                                                                         "11.7", "-13.6",\r
109                                                                                                                                                                                                                         "31.5", "5.7",\r
110                                                                                                                                                                                                                         65026791L);\r
111         public static osm_map_values            Kenya                                                                                           = new osm_map_values(\r
112                                                                                                                                                                                                                         "Kenya", "33.8",\r
113                                                                                                                                                                                                                         "-5.2", "42.4",\r
114                                                                                                                                                                                                                         "4.9", 58545273L);\r
115         public static osm_map_values            Lesotho                                                                                 = new osm_map_values(\r
116                                                                                                                                                                                                                         "Lesotho", "26.9",\r
117                                                                                                                                                                                                                         "-30.7", "29.6",\r
118                                                                                                                                                                                                                         "-28.4", 54791041L);\r
119         public static osm_map_values            Madagascar                                                                              = new osm_map_values(\r
120                                                                                                                                                                                                                         "Madagascar",\r
121                                                                                                                                                                                                                         "43.0", "-25.8",\r
122                                                                                                                                                                                                                         "50.8", "-11.8",\r
123                                                                                                                                                                                                                         56801099L);\r
124         public static osm_map_values            Nambia_Botswana                                                         = new osm_map_values(\r
125                                                                                                                                                                                                                         "Nambia+Botswana",\r
126                                                                                                                                                                                                                         "11.4", "-29.1",\r
127                                                                                                                                                                                                                         "29.5", "-16.9",\r
128                                                                                                                                                                                                                         61807049L);\r
129         public static osm_map_values            Reunion                                                                                 = new osm_map_values(\r
130                                                                                                                                                                                                                         "Reunion", "55.2",\r
131                                                                                                                                                                                                                         "-21.4", "55.9",\r
132                                                                                                                                                                                                                         "-20.9", 58537419L);\r
133         public static osm_map_values            Rwanda                                                                                  = new osm_map_values(\r
134                                                                                                                                                                                                                         "Rwanda", "28.8",\r
135                                                                                                                                                                                                                         "-2.9", "30.9",\r
136                                                                                                                                                                                                                         "-1.0", 56313710L);\r
137         public static osm_map_values            South_Africa                                                                    = new osm_map_values(\r
138                                                                                                                                                                                                                         "South Africa",\r
139                                                                                                                                                                                                                         "15.6", "-35.2",\r
140                                                                                                                                                                                                                         "33.3", "-21.9",\r
141                                                                                                                                                                                                                         73545245L);\r
142         public static osm_map_values            Uganda                                                                                  = new osm_map_values(\r
143                                                                                                                                                                                                                         "Uganda", "29.3",\r
144                                                                                                                                                                                                                         "-1.6", "35.1",\r
145                                                                                                                                                                                                                         "4.3", 57376589L);\r
146         public static osm_map_values            Asia                                                                                            = new osm_map_values(\r
147                                                                                                                                                                                                                         "Asia", "23.8",\r
148                                                                                                                                                                                                                         "0.1", "195.0",\r
149                                                                                                                                                                                                                         "82.4", 797725952L);\r
150         public static osm_map_values            China                                                                                           = new osm_map_values(\r
151                                                                                                                                                                                                                         "China", "67.3",\r
152                                                                                                                                                                                                                         "5.3", "135.0",\r
153                                                                                                                                                                                                                         "54.5", 259945160L);\r
154         public static osm_map_values            Cyprus                                                                                  = new osm_map_values(\r
155                                                                                                                                                                                                                         "Cyprus", "32.0",\r
156                                                                                                                                                                                                                         "34.5", "34.9",\r
157                                                                                                                                                                                                                         "35.8", 58585278L);\r
158         public static osm_map_values            India_Nepal                                                                             = new osm_map_values(\r
159                                                                                                                                                                                                                         "India+Nepal",\r
160                                                                                                                                                                                                                         "67.9", "5.5",\r
161                                                                                                                                                                                                                         "89.6", "36.0",\r
162                                                                                                                                                                                                                         82819344L);\r
163         public static osm_map_values            Indonesia                                                                               = new osm_map_values(\r
164                                                                                                                                                                                                                         "Indonesia",\r
165                                                                                                                                                                                                                         "93.7", "-17.3",\r
166                                                                                                                                                                                                                         "155.5", "7.6",\r
167                                                                                                                                                                                                                         74648081L);\r
168         public static osm_map_values            Iran                                                                                            = new osm_map_values(\r
169                                                                                                                                                                                                                         "Iran", "43.5",\r
170                                                                                                                                                                                                                         "24.4", "63.6",\r
171                                                                                                                                                                                                                         "40.4", 69561312L);\r
172         public static osm_map_values            Iraq                                                                                            = new osm_map_values(\r
173                                                                                                                                                                                                                         "Iraq", "38.7",\r
174                                                                                                                                                                                                                         "28.5", "49.2",\r
175                                                                                                                                                                                                                         "37.4", 59146383L);\r
176         public static osm_map_values            Israel                                                                                  = new osm_map_values(\r
177                                                                                                                                                                                                                         "Israel", "33.99",\r
178                                                                                                                                                                                                                         "29.8", "35.95",\r
179                                                                                                                                                                                                                         "33.4", 65065351L);\r
180         public static osm_map_values            Japan_Korea_Taiwan                                                      = new osm_map_values(\r
181                                                                                                                                                                                                                         "Japan+Korea+Taiwan",\r
182                                                                                                                                                                                                                         "117.6", "20.5",\r
183                                                                                                                                                                                                                         "151.3", "47.1",\r
184                                                                                                                                                                                                                         305538751L);\r
185         public static 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);\r
190         public static osm_map_values            Mongolia                                                                                        = new osm_map_values(\r
191                                                                                                                                                                                                                         "Mongolia",\r
192                                                                                                                                                                                                                         "87.5", "41.4",\r
193                                                                                                                                                                                                                         "120.3", "52.7",\r
194                                                                                                                                                                                                                         60871187L);\r
195         public static osm_map_values            Thailand                                                                                        = new osm_map_values(\r
196                                                                                                                                                                                                                         "Thailand",\r
197                                                                                                                                                                                                                         "97.5", "5.7",\r
198                                                                                                                                                                                                                         "105.2", "19.7",\r
199                                                                                                                                                                                                                         62422864L);\r
200         public static 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         public static osm_map_values            UAE_Other                                                                               = new osm_map_values(\r
205                                                                                                                                                                                                                         "UAE+Other",\r
206                                                                                                                                                                                                                         "51.5", "22.6",\r
207                                                                                                                                                                                                                         "56.7", "26.5",\r
208                                                                                                                                                                                                                         57419510L);\r
209         public static osm_map_values            Australia                                                                               = new osm_map_values(\r
210                                                                                                                                                                                                                         "Australia",\r
211                                                                                                                                                                                                                         "110.5", "-44.2",\r
212                                                                                                                                                                                                                         "154.9", "-9.2",\r
213                                                                                                                                                                                                                         128502185L);\r
214         public static osm_map_values            Tasmania                                                                                        = new osm_map_values(\r
215                                                                                                                                                                                                                         "Tasmania",\r
216                                                                                                                                                                                                                         "144.0", "-45.1",\r
217                                                                                                                                                                                                                         "155.3", "-24.8",\r
218                                                                                                                                                                                                                         103573989L);\r
219         public static osm_map_values            Victoria_New_South_Wales                                        = new osm_map_values(\r
220                                                                                                                                                                                                                         "Victoria+New South Wales",\r
221                                                                                                                                                                                                                         "140.7", "-39.4",\r
222                                                                                                                                                                                                                         "153.7", "-26.9",\r
223                                                                                                                                                                                                                         99307594L);\r
224         public static osm_map_values            New_Zealand                                                                             = new osm_map_values(\r
225                                                                                                                                                                                                                         "New Zealand",\r
226                                                                                                                                                                                                                         "165.2", "-47.6",\r
227                                                                                                                                                                                                                         "179.1", "-33.7",\r
228                                                                                                                                                                                                                         64757454L);\r
229         public static osm_map_values            Europe                                                                                  = new osm_map_values(\r
230                                                                                                                                                                                                                         "Europe",\r
231                                                                                                                                                                                                                         "-12.97", "33.59",\r
232                                                                                                                                                                                                                         "34.15", "72.10",\r
233                                                                                                                                                                                                                         2753910015L);\r
234         public static osm_map_values            Western_Europe                                                                  = new osm_map_values(\r
235                                                                                                                                                                                                                         "Western Europe",\r
236                                                                                                                                                                                                                         "-17.6", "34.5",\r
237                                                                                                                                                                                                                         "42.9", "70.9",\r
238                                                                                                                                                                                                                         2832986851L);\r
239         public static osm_map_values            Austria                                                                                 = new osm_map_values(\r
240                                                                                                                                                                                                                         "Austria", "9.4",\r
241                                                                                                                                                                                                                         "46.32", "17.21",\r
242                                                                                                                                                                                                                         "49.1", 222359992L);\r
243         public static osm_map_values            BeNeLux                                                                                 = new osm_map_values(\r
244                                                                                                                                                                                                                         "BeNeLux", "2.08",\r
245                                                                                                                                                                                                                         "48.87", "7.78",\r
246                                                                                                                                                                                                                         "54.52",\r
247                                                                                                                                                                                                                         533865194L);\r
248         public static osm_map_values            Faroe_Islands                                                                   = new osm_map_values(\r
249                                                                                                                                                                                                                         "Faroe Islands",\r
250                                                                                                                                                                                                                         "-7.8", "61.3",\r
251                                                                                                                                                                                                                         "-6.1", "62.5",\r
252                                                                                                                                                                                                                         54526101L);\r
253         public static osm_map_values            France                                                                                  = new osm_map_values(\r
254                                                                                                                                                                                                                         "France", "-5.45",\r
255                                                                                                                                                                                                                         "42.00", "8.44",\r
256                                                                                                                                                                                                                         "51.68",\r
257                                                                                                                                                                                                                         1112047845L);\r
258         public static osm_map_values            Germany                                                                                 = new osm_map_values(\r
259                                                                                                                                                                                                                         "Germany", "5.18",\r
260                                                                                                                                                                                                                         "46.84", "15.47",\r
261                                                                                                                                                                                                                         "55.64",\r
262                                                                                                                                                                                                                         944716238L);\r
263         public static osm_map_values            Bavaria                                                                                 = new osm_map_values(\r
264                                                                                                                                                                                                                         "Bavaria", "10.3",\r
265                                                                                                                                                                                                                         "47.8", "13.6",\r
266                                                                                                                                                                                                                         "49.7", 131799419L);\r
267         public static osm_map_values            Saxonia                                                                                 = new osm_map_values(\r
268                                                                                                                                                                                                                         "Saxonia", "11.8",\r
269                                                                                                                                                                                                                         "50.1", "15.0",\r
270                                                                                                                                                                                                                         "51.7", 112073909L);\r
271         public static osm_map_values            Germany_Austria_Switzerland                             = new osm_map_values(\r
272                                                                                                                                                                                                                         "Germany+Austria+Switzerland",\r
273                                                                                                                                                                                                                         "3.4", "44.5",\r
274                                                                                                                                                                                                                         "18.6", "55.1",\r
275                                                                                                                                                                                                                         1385785353L);\r
276         public static osm_map_values            Iceland                                                                                 = new osm_map_values(\r
277                                                                                                                                                                                                                         "Iceland",\r
278                                                                                                                                                                                                                         "-25.3", "62.8",\r
279                                                                                                                                                                                                                         "-11.4", "67.5",\r
280                                                                                                                                                                                                                         57281405L);\r
281         public static osm_map_values            Ireland                                                                                 = new osm_map_values(\r
282                                                                                                                                                                                                                         "Ireland",\r
283                                                                                                                                                                                                                         "-11.17", "51.25",\r
284                                                                                                                                                                                                                         "-5.23", "55.9",\r
285                                                                                                                                                                                                                         70186936L);\r
286         public static osm_map_values            Italy                                                                                           = new osm_map_values(\r
287                                                                                                                                                                                                                         "Italy", "6.52",\r
288                                                                                                                                                                                                                         "36.38", "18.96",\r
289                                                                                                                                                                                                                         "47.19",\r
290                                                                                                                                                                                                                         291401314L);\r
291         public static osm_map_values            Spain_Portugal                                                                  = new osm_map_values(\r
292                                                                                                                                                                                                                         "Spain+Portugal",\r
293                                                                                                                                                                                                                         "-11.04", "34.87",\r
294                                                                                                                                                                                                                         "4.62", "44.41",\r
295                                                                                                                                                                                                                         292407746L);\r
296         public static osm_map_values            Mallorca                                                                                        = new osm_map_values(\r
297                                                                                                                                                                                                                         "Mallorca", "2.2",\r
298                                                                                                                                                                                                                         "38.8", "4.7",\r
299                                                                                                                                                                                                                         "40.2", 59700600L);\r
300         public static osm_map_values            Galicia                                                                                 = new osm_map_values(\r
301                                                                                                                                                                                                                         "Galicia",\r
302                                                                                                                                                                                                                         "-10.0", "41.7",\r
303                                                                                                                                                                                                                         "-6.3", "44.1",\r
304                                                                                                                                                                                                                         64605237L);\r
305         public static osm_map_values            Scandinavia                                                                             = new osm_map_values(\r
306                                                                                                                                                                                                                         "Scandinavia",\r
307                                                                                                                                                                                                                         "4.0", "54.4",\r
308                                                                                                                                                                                                                         "32.1", "71.5",\r
309                                                                                                                                                                                                                         299021928L);\r
310         public static osm_map_values            Finland                                                                                 = new osm_map_values(\r
311                                                                                                                                                                                                                         "Finland", "18.6",\r
312                                                                                                                                                                                                                         "59.2", "32.3",\r
313                                                                                                                                                                                                                         "70.3", 128871467L);\r
314         public static osm_map_values            Denmark                                                                                 = new osm_map_values(\r
315                                                                                                                                                                                                                         "Denmark", "7.49",\r
316                                                                                                                                                                                                                         "54.33", "13.05",\r
317                                                                                                                                                                                                                         "57.88",\r
318                                                                                                                                                                                                                         120025875L);\r
319         public static osm_map_values            Switzerland                                                                             = new osm_map_values(\r
320                                                                                                                                                                                                                         "Switzerland",\r
321                                                                                                                                                                                                                         "5.79", "45.74",\r
322                                                                                                                                                                                                                         "10.59", "47.84",\r
323                                                                                                                                                                                                                         162616817L);\r
324         public static osm_map_values            UK                                                                                                      = new osm_map_values(\r
325                                                                                                                                                                                                                         "UK", "-9.7",\r
326                                                                                                                                                                                                                         "49.6", "2.2",\r
327                                                                                                                                                                                                                         "61.2", 245161510L);\r
328         public static osm_map_values            Bulgaria                                                                                        = new osm_map_values(\r
329                                                                                                                                                                                                                         "Bulgaria",\r
330                                                                                                                                                                                                                         "24.7", "42.1",\r
331                                                                                                                                                                                                                         "24.8", "42.1",\r
332                                                                                                                                                                                                                         56607427L);\r
333         public static osm_map_values            Czech_Republic                                                                  = new osm_map_values(\r
334                                                                                                                                                                                                                         "Czech Republic",\r
335                                                                                                                                                                                                                         "11.91", "48.48",\r
336                                                                                                                                                                                                                         "19.02", "51.17",\r
337                                                                                                                                                                                                                         234138824L);\r
338         public static osm_map_values            Croatia                                                                                 = new osm_map_values(\r
339                                                                                                                                                                                                                         "Croatia", "13.4",\r
340                                                                                                                                                                                                                         "42.1", "19.4",\r
341                                                                                                                                                                                                                         "46.9", 99183280L);\r
342         public static osm_map_values            Estonia                                                                                 = new osm_map_values(\r
343                                                                                                                                                                                                                         "Estonia", "21.5",\r
344                                                                                                                                                                                                                         "57.5", "28.2",\r
345                                                                                                                                                                                                                         "59.6", 79276178L);\r
346         public static osm_map_values            Greece                                                                                  = new osm_map_values(\r
347                                                                                                                                                                                                                         "Greece", "28.9",\r
348                                                                                                                                                                                                                         "37.8", "29.0",\r
349                                                                                                                                                                                                                         "37.8", 55486527L);\r
350         public static osm_map_values            Crete                                                                                           = new osm_map_values(\r
351                                                                                                                                                                                                                         "Crete", "23.3",\r
352                                                                                                                                                                                                                         "34.5", "26.8",\r
353                                                                                                                                                                                                                         "36.0", 57032630L);\r
354         public static osm_map_values            Hungary                                                                                 = new osm_map_values(\r
355                                                                                                                                                                                                                         "Hungary",\r
356                                                                                                                                                                                                                         "16.08", "45.57",\r
357                                                                                                                                                                                                                         "23.03", "48.39",\r
358                                                                                                                                                                                                                         109831319L);\r
359         public static osm_map_values            Latvia                                                                                  = new osm_map_values(\r
360                                                                                                                                                                                                                         "Latvia", "20.7",\r
361                                                                                                                                                                                                                         "55.6", "28.3",\r
362                                                                                                                                                                                                                         "58.1", 71490706L);\r
363         public static osm_map_values            Lithuania                                                                               = new osm_map_values(\r
364                                                                                                                                                                                                                         "Lithuania",\r
365                                                                                                                                                                                                                         "20.9", "53.8",\r
366                                                                                                                                                                                                                         "26.9", "56.5",\r
367                                                                                                                                                                                                                         67992457L);\r
368         public static osm_map_values            Poland                                                                                  = new osm_map_values(\r
369                                                                                                                                                                                                                         "Poland", "13.6",\r
370                                                                                                                                                                                                                         "48.8", "24.5",\r
371                                                                                                                                                                                                                         "55.0", 266136768L);\r
372         public static osm_map_values            Romania                                                                                 = new osm_map_values(\r
373                                                                                                                                                                                                                         "Romania", "20.3",\r
374                                                                                                                                                                                                                         "43.5", "29.9",\r
375                                                                                                                                                                                                                         "48.4", 134525863L);\r
376         public static osm_map_values            North_America                                                                   = new osm_map_values(\r
377                                                                                                                                                                                                                         "North America",\r
378                                                                                                                                                                                                                         "-178.1", "6.5",\r
379                                                                                                                                                                                                                         "-10.4", "84.0",\r
380                                                                                                                                                                                                                         2477309662L);\r
381         public static osm_map_values            Alaska                                                                                  = new osm_map_values(\r
382                                                                                                                                                                                                                         "Alaska",\r
383                                                                                                                                                                                                                         "-179.5", "49.5",\r
384                                                                                                                                                                                                                         "-129", "71.6",\r
385                                                                                                                                                                                                                         72320027L);\r
386         public static osm_map_values            Canada                                                                                  = new osm_map_values(\r
387                                                                                                                                                                                                                         "Canada",\r
388                                                                                                                                                                                                                         "-141.3", "41.5",\r
389                                                                                                                                                                                                                         "-52.2", "70.2",\r
390                                                                                                                                                                                                                         937813467L);\r
391         public static osm_map_values            Hawaii                                                                                  = new osm_map_values(\r
392                                                                                                                                                                                                                         "Hawaii",\r
393                                                                                                                                                                                                                         "-161.07",\r
394                                                                                                                                                                                                                         "18.49",\r
395                                                                                                                                                                                                                         "-154.45",\r
396                                                                                                                                                                                                                         "22.85", 57311788L);\r
397         public static osm_map_values            USA__except_Alaska_and_Hawaii_                  = new osm_map_values(\r
398                                                                                                                                                                                                                         "USA (except Alaska and Hawaii)",\r
399                                                                                                                                                                                                                         "-125.4", "24.3",\r
400                                                                                                                                                                                                                         "-66.5", "49.3",\r
401                                                                                                                                                                                                                         2216912004L);\r
402         public static osm_map_values            Nevada                                                                                  = new osm_map_values(\r
403                                                                                                                                                                                                                         "Nevada",\r
404                                                                                                                                                                                                                         "-120.2", "35.0",\r
405                                                                                                                                                                                                                         "-113.8", "42.1",\r
406                                                                                                                                                                                                                         136754975L);\r
407         public static osm_map_values            Oregon                                                                                  = new osm_map_values(\r
408                                                                                                                                                                                                                         "Oregon",\r
409                                                                                                                                                                                                                         "-124.8", "41.8",\r
410                                                                                                                                                                                                                         "-116.3", "46.3",\r
411                                                                                                                                                                                                                         101627308L);\r
412         public static osm_map_values            Washington_State                                                                = new osm_map_values(\r
413                                                                                                                                                                                                                         "Washington State",\r
414                                                                                                                                                                                                                         "-125.0", "45.5",\r
415                                                                                                                                                                                                                         "-116.9", "49.0",\r
416                                                                                                                                                                                                                         98178877L);\r
417         public static osm_map_values            South_Middle_America                                                    = new osm_map_values(\r
418                                                                                                                                                                                                                         "South+Middle America",\r
419                                                                                                                                                                                                                         "-83.5", "-56.3",\r
420                                                                                                                                                                                                                         "-30.8", "13.7",\r
421                                                                                                                                                                                                                         159615197L);\r
422         public static osm_map_values            Argentina                                                                               = new osm_map_values(\r
423                                                                                                                                                                                                                         "Argentina",\r
424                                                                                                                                                                                                                         "-73.9", "-57.3",\r
425                                                                                                                                                                                                                         "-51.6", "-21.0",\r
426                                                                                                                                                                                                                         87516152L);\r
427         public static osm_map_values            Argentina_Chile                                                         = new osm_map_values(\r
428                                                                                                                                                                                                                         "Argentina+Chile",\r
429                                                                                                                                                                                                                         "-77.2", "-56.3",\r
430                                                                                                                                                                                                                         "-52.7", "-16.1",\r
431                                                                                                                                                                                                                         91976696L);\r
432         public static osm_map_values            Bolivia                                                                                 = new osm_map_values(\r
433                                                                                                                                                                                                                         "Bolivia",\r
434                                                                                                                                                                                                                         "-70.5", "-23.1",\r
435                                                                                                                                                                                                                         "-57.3", "-9.3",\r
436                                                                                                                                                                                                                         58242168L);\r
437         public static osm_map_values            Brazil                                                                                  = new osm_map_values(\r
438                                                                                                                                                                                                                         "Brazil", "-71.4",\r
439                                                                                                                                                                                                                         "-34.7", "-32.8",\r
440                                                                                                                                                                                                                         "5.4", 105527899L);\r
441         public static osm_map_values            Cuba                                                                                            = new osm_map_values(\r
442                                                                                                                                                                                                                         "Cuba", "-85.3",\r
443                                                                                                                                                                                                                         "19.6", "-74.0",\r
444                                                                                                                                                                                                                         "23.6", 56608942L);\r
445         public static osm_map_values            Colombia                                                                                        = new osm_map_values(\r
446                                                                                                                                                                                                                         "Colombia",\r
447                                                                                                                                                                                                                         "-79.1", "-4.0",\r
448                                                                                                                                                                                                                         "-66.7", "12.6",\r
449                                                                                                                                                                                                                         78658454L);\r
450         public static osm_map_values            Ecuador                                                                                 = new osm_map_values(\r
451                                                                                                                                                                                                                         "Ecuador",\r
452                                                                                                                                                                                                                         "-82.6", "-5.4",\r
453                                                                                                                                                                                                                         "-74.4", "2.3",\r
454                                                                                                                                                                                                                         61501914L);\r
455         public static osm_map_values            Guyana_Suriname_Guyane_Francaise                        = new osm_map_values(\r
456                                                                                                                                                                                                                         "Guyana+Suriname+Guyane Francaise",\r
457                                                                                                                                                                                                                         "-62.0", "1.0",\r
458                                                                                                                                                                                                                         "-51.2", "8.9",\r
459                                                                                                                                                                                                                         57040689L);\r
460         public static osm_map_values            Haiti_Republica_Dominicana                                      = new osm_map_values(\r
461                                                                                                                                                                                                                         "Haiti+Republica Dominicana",\r
462                                                                                                                                                                                                                         "-74.8", "17.3",\r
463                                                                                                                                                                                                                         "-68.2", "20.1",\r
464                                                                                                                                                                                                                         63528584L);\r
465         public static osm_map_values            Jamaica                                                                                 = new osm_map_values(\r
466                                                                                                                                                                                                                         "Jamaica",\r
467                                                                                                                                                                                                                         "-78.6", "17.4",\r
468                                                                                                                                                                                                                         "-75.9", "18.9",\r
469                                                                                                                                                                                                                         53958307L);\r
470         public static osm_map_values            Mexico                                                                                  = new osm_map_values(\r
471                                                                                                                                                                                                                         "Mexico",\r
472                                                                                                                                                                                                                         "-117.6", "14.1",\r
473                                                                                                                                                                                                                         "-86.4", "32.8",\r
474                                                                                                                                                                                                                         251108617L);\r
475         public static osm_map_values            Paraguay                                                                                        = new osm_map_values(\r
476                                                                                                                                                                                                                         "Paraguay",\r
477                                                                                                                                                                                                                         "-63.8", "-28.1",\r
478                                                                                                                                                                                                                         "-53.6", "-18.8",\r
479                                                                                                                                                                                                                         57188715L);\r
480         public static osm_map_values            Peru                                                                                            = new osm_map_values(\r
481                                                                                                                                                                                                                         "Peru", "-82.4",\r
482                                                                                                                                                                                                                         "-18.1", "-67.5",\r
483                                                                                                                                                                                                                         "0.4", 65421441L);\r
484         public static osm_map_values            Uruguay                                                                                 = new osm_map_values(\r
485                                                                                                                                                                                                                         "Uruguay",\r
486                                                                                                                                                                                                                         "-59.2", "-36.5",\r
487                                                                                                                                                                                                                         "-51.7", "-29.7",\r
488                                                                                                                                                                                                                         63542225L);\r
489         public static osm_map_values            Venezuela                                                                               = new osm_map_values(\r
490                                                                                                                                                                                                                         "Venezuela",\r
491                                                                                                                                                                                                                         "-73.6", "0.4",\r
492                                                                                                                                                                                                                         "-59.7", "12.8",\r
493                                                                                                                                                                                                                         64838882L);\r
494 \r
495         public static osm_map_values[]  OSM_MAPS                                                                                        = new osm_map_values[]{\r
496                         Whole_Planet, Africa, Angola, Burundi, Democratic_Republic_of_the_Congo, Kenya, Lesotho,\r
497                         Madagascar, Nambia_Botswana, Reunion, Rwanda, South_Africa, Uganda, Asia, China, Cyprus,\r
498                         India_Nepal, Indonesia, Iran, Iraq, Israel, Japan_Korea_Taiwan, Malasia_Singapore,\r
499                         Mongolia, Nambia_Botswana, Thailand, Turkey, UAE_Other, Australia, Tasmania,\r
500                         Victoria_New_South_Wales, New_Zealand, Europe, Western_Europe, Austria, BeNeLux,\r
501                         Faroe_Islands, France, Germany, Bavaria, Saxonia, Germany_Austria_Switzerland, Iceland,\r
502                         Ireland, Italy, Spain_Portugal, Mallorca, Galicia, Scandinavia, Finland, Denmark,\r
503                         Switzerland, UK, Bulgaria, Czech_Republic, Croatia, Estonia, Greece, Crete, Hungary,\r
504                         Latvia, Lithuania, Poland, Romania, North_America, Alaska, Canada, Hawaii,\r
505                         USA__except_Alaska_and_Hawaii_, Nevada, Oregon, Washington_State, South_Middle_America,\r
506                         Argentina, Argentina_Chile, Bolivia, Brazil, Cuba, Colombia, Ecuador,\r
507                         Guyana_Suriname_Guyane_Francaise, Haiti_Republica_Dominicana, Jamaica, Mexico, Paraguay,\r
508                         Peru, Uruguay, Venezuela                                                                                                                };\r
509         public static String[]                          OSM_MAP_NAME_LIST                                                               = new String[]{\r
510                         Whole_Planet.map_name, Africa.map_name, Angola.map_name, Burundi.map_name,\r
511                         Democratic_Republic_of_the_Congo.map_name, Kenya.map_name, Lesotho.map_name,\r
512                         Madagascar.map_name, Nambia_Botswana.map_name, Reunion.map_name, Rwanda.map_name,\r
513                         South_Africa.map_name, Uganda.map_name, Asia.map_name, China.map_name, Cyprus.map_name,\r
514                         India_Nepal.map_name, Indonesia.map_name, Iran.map_name, Iraq.map_name, Israel.map_name,\r
515                         Japan_Korea_Taiwan.map_name, Malasia_Singapore.map_name, Mongolia.map_name,\r
516                         Nambia_Botswana.map_name, Thailand.map_name, Turkey.map_name, UAE_Other.map_name,\r
517                         Australia.map_name, Tasmania.map_name, Victoria_New_South_Wales.map_name,\r
518                         New_Zealand.map_name, Europe.map_name, Western_Europe.map_name, Austria.map_name,\r
519                         BeNeLux.map_name, Faroe_Islands.map_name, France.map_name, Germany.map_name,\r
520                         Bavaria.map_name, Saxonia.map_name, Germany_Austria_Switzerland.map_name,\r
521                         Iceland.map_name, Ireland.map_name, Italy.map_name, Spain_Portugal.map_name,\r
522                         Mallorca.map_name, Galicia.map_name, Scandinavia.map_name, Finland.map_name,\r
523                         Denmark.map_name, Switzerland.map_name, UK.map_name, Bulgaria.map_name,\r
524                         Czech_Republic.map_name, Croatia.map_name, Estonia.map_name, Greece.map_name,\r
525                         Crete.map_name, Hungary.map_name, Latvia.map_name, Lithuania.map_name, Poland.map_name,\r
526                         Romania.map_name, North_America.map_name, Alaska.map_name, Canada.map_name,\r
527                         Hawaii.map_name, USA__except_Alaska_and_Hawaii_.map_name, Nevada.map_name,\r
528                         Oregon.map_name, Washington_State.map_name, South_Middle_America.map_name,\r
529                         Argentina.map_name, Argentina_Chile.map_name, Bolivia.map_name, Brazil.map_name,\r
530                         Cuba.map_name, Colombia.map_name, Ecuador.map_name,\r
531                         Guyana_Suriname_Guyane_Francaise.map_name, Haiti_Republica_Dominicana.map_name,\r
532                         Jamaica.map_name, Mexico.map_name, Paraguay.map_name, Peru.map_name, Uruguay.map_name,\r
533                         Venezuela.map_name                                                                                                                              };\r
534 \r
535         public static String[]                          OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE    = new String[]{\r
536                         Whole_Planet.text_for_select_list, Africa.text_for_select_list,\r
537                         Angola.text_for_select_list, Burundi.text_for_select_list,\r
538                         Democratic_Republic_of_the_Congo.text_for_select_list, Kenya.text_for_select_list,\r
539                         Lesotho.text_for_select_list, Madagascar.text_for_select_list,\r
540                         Nambia_Botswana.text_for_select_list, Reunion.text_for_select_list,\r
541                         Rwanda.text_for_select_list, South_Africa.text_for_select_list,\r
542                         Uganda.text_for_select_list, Asia.text_for_select_list, China.text_for_select_list,\r
543                         Cyprus.text_for_select_list, India_Nepal.text_for_select_list,\r
544                         Indonesia.text_for_select_list, Iran.text_for_select_list, Iraq.text_for_select_list,\r
545                         Israel.text_for_select_list, Japan_Korea_Taiwan.text_for_select_list,\r
546                         Malasia_Singapore.text_for_select_list, Mongolia.text_for_select_list,\r
547                         Nambia_Botswana.text_for_select_list, Thailand.text_for_select_list,\r
548                         Turkey.text_for_select_list, UAE_Other.text_for_select_list,\r
549                         Australia.text_for_select_list, Tasmania.text_for_select_list,\r
550                         Victoria_New_South_Wales.text_for_select_list, New_Zealand.text_for_select_list,\r
551                         Europe.text_for_select_list, Western_Europe.text_for_select_list,\r
552                         Austria.text_for_select_list, BeNeLux.text_for_select_list,\r
553                         Faroe_Islands.text_for_select_list, France.text_for_select_list,\r
554                         Germany.text_for_select_list, Bavaria.text_for_select_list, Saxonia.text_for_select_list,\r
555                         Germany_Austria_Switzerland.text_for_select_list, Iceland.text_for_select_list,\r
556                         Ireland.text_for_select_list, Italy.text_for_select_list,\r
557                         Spain_Portugal.text_for_select_list, Mallorca.text_for_select_list,\r
558                         Galicia.text_for_select_list, Scandinavia.text_for_select_list,\r
559                         Finland.text_for_select_list, Denmark.text_for_select_list,\r
560                         Switzerland.text_for_select_list, UK.text_for_select_list, Bulgaria.text_for_select_list,\r
561                         Czech_Republic.text_for_select_list, Croatia.text_for_select_list,\r
562                         Estonia.text_for_select_list, Greece.text_for_select_list, Crete.text_for_select_list,\r
563                         Hungary.text_for_select_list, Latvia.text_for_select_list, Lithuania.text_for_select_list,\r
564                         Poland.text_for_select_list, Romania.text_for_select_list,\r
565                         North_America.text_for_select_list, Alaska.text_for_select_list,\r
566                         Canada.text_for_select_list, Hawaii.text_for_select_list,\r
567                         USA__except_Alaska_and_Hawaii_.text_for_select_list, Nevada.text_for_select_list,\r
568                         Oregon.text_for_select_list, Washington_State.text_for_select_list,\r
569                         South_Middle_America.text_for_select_list, Argentina.text_for_select_list,\r
570                         Argentina_Chile.text_for_select_list, Bolivia.text_for_select_list,\r
571                         Brazil.text_for_select_list, Cuba.text_for_select_list, Colombia.text_for_select_list,\r
572                         Ecuador.text_for_select_list, Guyana_Suriname_Guyane_Francaise.text_for_select_list,\r
573                         Haiti_Republica_Dominicana.text_for_select_list, Jamaica.text_for_select_list,\r
574                         Mexico.text_for_select_list, Paraguay.text_for_select_list, Peru.text_for_select_list,\r
575                         Uruguay.text_for_select_list, Venezuela.text_for_select_list            };\r
576 \r
577         public Boolean                                                  stop_me                                                                                 = false;\r
578         static final int                                                SOCKET_CONNECT_TIMEOUT                                          = 6000;\r
579         static final int                                                SOCKET_READ_TIMEOUT                                                     = 6000;\r
580         static final int                                                MAP_WRITE_FILE_BUFFER                                           = 1024 * 64;\r
581         static final int                                                MAP_WRITE_MEM_BUFFER                                                    = 1024 * 64;\r
582         static final int                                                MAP_READ_FILE_BUFFER                                                    = 1024 * 64;\r
583         static final int                                                UPDATE_PROGRESS_EVERY_CYCLE                             = 8;\r
584 \r
585         static final String                                     DOWNLOAD_FILENAME                                                               = "navitmap.tmp";\r
586         static final String                                     MAP_FILENAME_PRI                                                                = "navitmap.bin";\r
587         static final String                                     MAP_FILENAME_SEC                                                                = "navitmap_002.bin";\r
588         static final String                                     MAP_FILENAME_PATH                                                               = "/sdcard/";\r
589 \r
590 \r
591         public class ProgressThread extends Thread\r
592         {\r
593                 Handler                 mHandler;\r
594                 osm_map_values  map_values;\r
595                 int                             map_num;\r
596                 int                             my_dialog_num;\r
597 \r
598                 ProgressThread(Handler h, osm_map_values map_values, int map_num)\r
599                 {\r
600                         this.mHandler = h;\r
601                         this.map_values = map_values;\r
602                         this.map_num = map_num;\r
603                         if (this.map_num == Navit.MAP_NUM_PRIMARY)\r
604                         {\r
605                                 this.my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;\r
606                         }\r
607                         else if (this.map_num == Navit.MAP_NUM_SECONDARY)\r
608                         {\r
609                                 this.my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;\r
610                         }\r
611                 }\r
612 \r
613                 public void run()\r
614                 {\r
615                         stop_me = false;\r
616                         int exit_code = download_osm_map(mHandler, map_values, this.map_num);\r
617 \r
618                         // ok, remove dialog\r
619                         Message msg = mHandler.obtainMessage();\r
620                         Bundle b = new Bundle();\r
621                         msg.what = 0;\r
622                         b.putInt("dialog_num", this.my_dialog_num);\r
623                         b.putInt("exit_code", exit_code);\r
624                         msg.setData(b);\r
625                         mHandler.sendMessage(msg);\r
626                 }\r
627 \r
628                 public void stop_thread()\r
629                 {\r
630                         stop_me = true;\r
631                         Log.d("NavitMapDownloader", "stop_me -> true");\r
632                 }\r
633         }\r
634 \r
635         public Navit    navit_jmain     = null;\r
636 \r
637         public NavitMapDownloader(Navit main)\r
638         {\r
639                 this.navit_jmain = main;\r
640         }\r
641 \r
642         public int download_osm_map(Handler handler, osm_map_values map_values, int map_num)\r
643         {\r
644                 int exit_code = 1;\r
645 \r
646                 int my_dialog_num = 0;\r
647                 if (map_num == Navit.MAP_NUM_PRIMARY)\r
648                 {\r
649                         my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;\r
650                 }\r
651                 else if (map_num == Navit.MAP_NUM_SECONDARY)\r
652                 {\r
653                         my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;\r
654                 }\r
655 \r
656                 Message msg = handler.obtainMessage();\r
657                 Bundle b = new Bundle();\r
658                 msg.what = 1;\r
659                 b.putInt("max", 20); // use a dummy number here\r
660                 b.putInt("cur", 0);\r
661                 b.putInt("dialog_num", my_dialog_num);\r
662                 b.putString("title", "Mapdownload");\r
663                 b.putString("text", "downloading: " + map_values.map_name);\r
664                 msg.setData(b);\r
665                 handler.sendMessage(msg);\r
666                 try\r
667                 {\r
668                         // little pause here\r
669                         Thread.sleep(10);\r
670                 }\r
671                 catch (InterruptedException e1)\r
672                 {\r
673                 }\r
674 \r
675                 // output filename\r
676                 String fileName = DOWNLOAD_FILENAME;\r
677                 String final_fileName = MAP_FILENAME_PRI;\r
678                 if (map_num == Navit.MAP_NUM_SECONDARY)\r
679                 {\r
680                         final_fileName = this.MAP_FILENAME_SEC;\r
681                 }\r
682                 // output path for output filename\r
683                 // String PATH = Environment.getExternalStorageDirectory() + "/download/";\r
684                 String PATH = MAP_FILENAME_PATH;\r
685                 Log.v("log_tag", "mapfilename tmp: " + PATH + fileName);\r
686 \r
687                 try\r
688                 {\r
689                         URL url = new URL("http://maps.navit-project.org/api/map/?bbox=" + map_values.lon1 + ","\r
690                                         + map_values.lat1 + "," + map_values.lon2 + "," + map_values.lat2);\r
691                         HttpURLConnection c = (HttpURLConnection) url.openConnection();\r
692                         c.setRequestMethod("GET");\r
693                         c.setDoOutput(true);\r
694                         c.setReadTimeout(SOCKET_READ_TIMEOUT);\r
695                         c.setConnectTimeout(SOCKET_CONNECT_TIMEOUT);\r
696                         long real_size_bytes = c.getContentLength();\r
697                         c.connect();\r
698 \r
699                         Log.d("NavitMapDownloader", "real size in bytes: " + real_size_bytes);\r
700                         if (real_size_bytes > 20)\r
701                         {\r
702                                 // change the estimated filesize to reported filesize\r
703                                 map_values.est_size_bytes = real_size_bytes;\r
704                         }\r
705                         Log.d("NavitMapDownloader", "size in bytes: " + map_values.est_size_bytes);\r
706 \r
707                         File file = new File(PATH);\r
708                         File outputFile = new File(file, fileName);\r
709                         File final_outputFile = new File(file, final_fileName);\r
710                         // tests have shown that deleting the file first is sometimes faster -> so we delete it (who knows)\r
711                         outputFile.delete();\r
712                         // seems this command overwrites the output file anyway\r
713                         FileOutputStream fos = new FileOutputStream(outputFile);\r
714                         BufferedOutputStream buf = new BufferedOutputStream(fos, MAP_WRITE_FILE_BUFFER); // buffer\r
715 \r
716                         InputStream is = c.getInputStream();\r
717                         BufferedInputStream bif = new BufferedInputStream(is, MAP_READ_FILE_BUFFER); // buffer\r
718 \r
719                         byte[] buffer = new byte[MAP_WRITE_MEM_BUFFER]; // buffer\r
720                         int len1 = 0;\r
721                         int already_read = 0;\r
722                         int alt = UPDATE_PROGRESS_EVERY_CYCLE; // show progress about every xx cylces\r
723                         int alt_cur = 0;\r
724                         String kbytes_per_second = "";\r
725                         long start_timestamp = System.currentTimeMillis();\r
726                         NumberFormat formatter = new DecimalFormat("00000.0");\r
727                         String eta_string = "";\r
728                         float per_second_overall = 0f;\r
729                         long bytes_remaining = 0;\r
730                         int eta_seconds = 0;\r
731                         while ((len1 = bif.read(buffer)) != -1)\r
732                         {\r
733                                 if (stop_me)\r
734                                 {\r
735                                         // ok we need to be stopped! close all files and end\r
736                                         buf.flush();\r
737                                         buf.close();\r
738                                         fos.close();\r
739                                         bif.close();\r
740                                         is.close();\r
741                                         c.disconnect();\r
742                                         return 2;\r
743                                 }\r
744                                 already_read = already_read + len1;\r
745                                 alt_cur++;\r
746                                 if (alt_cur > alt)\r
747                                 {\r
748                                         alt_cur = 0;\r
749 \r
750                                         msg = handler.obtainMessage();\r
751                                         b = new Bundle();\r
752                                         msg.what = 1;\r
753                                         b.putInt("max", (int) (map_values.est_size_bytes / 1024));\r
754                                         b.putInt("cur", (int) (already_read / 1024));\r
755                                         b.putInt("dialog_num", my_dialog_num);\r
756                                         b.putString("title", "Map download");\r
757                                         per_second_overall = (float) already_read\r
758                                                         / (float) ((System.currentTimeMillis() - start_timestamp) / 1000);\r
759                                         kbytes_per_second = formatter.format((per_second_overall / 1024f));\r
760                                         bytes_remaining = map_values.est_size_bytes - already_read;\r
761                                         eta_seconds = (int) ((float) bytes_remaining / (float) per_second_overall);\r
762                                         if (eta_seconds > 60)\r
763                                         {\r
764                                                 eta_string = (int) (eta_seconds / 60f) + " m";\r
765                                         }\r
766                                         else\r
767                                         {\r
768                                                 eta_string = eta_seconds + " s";\r
769                                         }\r
770                                         b.putString("text", "downloading: " + map_values.map_name + "\n" + " "\r
771                                                         + (int) (already_read / 1024f / 1024f) + "Mb / "\r
772                                                         + (int) (map_values.est_size_bytes / 1024f / 1024f) + "Mb" + "\n" + " "\r
773                                                         + kbytes_per_second + "kb/s" + " ETA: " + eta_string);\r
774                                         msg.setData(b);\r
775                                         handler.sendMessage(msg);\r
776                                         //                                      try\r
777                                         //                                      {\r
778                                         //                                              // little pause here\r
779                                         //                                              Thread.sleep(20);\r
780                                         //                                      }\r
781                                         //                                      catch (InterruptedException e1)\r
782                                         //                                      {\r
783                                         //                                      }\r
784                                 }\r
785                                 buf.write(buffer, 0, len1);\r
786                         }\r
787                         buf.flush();\r
788 \r
789                         buf.close();\r
790                         fos.close();\r
791 \r
792                         bif.close();\r
793                         is.close();\r
794 \r
795                         c.disconnect();\r
796 \r
797                         // delete an already final filename, first\r
798                         final_outputFile.delete();\r
799                         // rename file to final name\r
800                         outputFile.renameTo(final_outputFile);\r
801                 }\r
802                 catch (IOException e)\r
803                 {\r
804                         msg = handler.obtainMessage();\r
805                         b = new Bundle();\r
806                         msg.what = 2;\r
807                         b.putInt("dialog_num", my_dialog_num);\r
808                         b.putString("text", "Error downloading map!");\r
809                         msg.setData(b);\r
810                         handler.sendMessage(msg);\r
811 \r
812                         Log.d("NavitMapDownloader", "Error: " + e);\r
813                         exit_code = 3;\r
814                 }\r
815                 catch (Exception e)\r
816                 {\r
817                         msg = handler.obtainMessage();\r
818                         b = new Bundle();\r
819                         msg.what = 2;\r
820                         b.putInt("dialog_num", my_dialog_num);\r
821                         b.putString("text", "Error downloading map!");\r
822                         msg.setData(b);\r
823                         handler.sendMessage(msg);\r
824 \r
825                         Log.d("NavitMapDownloader", "gerneral Error: " + e);\r
826                         exit_code = 4;\r
827                 }\r
828 \r
829                 msg = handler.obtainMessage();\r
830                 b = new Bundle();\r
831                 msg.what = 1;\r
832                 b.putInt("max", (int) (map_values.est_size_bytes / 1024));\r
833                 b.putInt("cur", (int) (map_values.est_size_bytes / 1024));\r
834                 b.putInt("dialog_num", my_dialog_num);\r
835                 b.putString("title", "Mapdownload");\r
836                 b.putString("text", map_values.map_name + " ready");\r
837                 msg.setData(b);\r
838                 handler.sendMessage(msg);\r
839 \r
840 \r
841                 Log.d("NavitMapDownloader", "success");\r
842                 exit_code = 0;\r
843                 return exit_code;\r
844         }\r
845 }\r