/[zanavi_public1]/navit/navit/android/src/com/zoffcc/applications/zanavi/Navit.java
ZANavi

Contents of /navit/navit/android/src/com/zoffcc/applications/zanavi/Navit.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File size: 99892 byte(s)
import files
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 package com.zoffcc.applications.zanavi;
40
41 import java.io.File;
42 import java.io.FileInputStream;
43 import java.io.FileOutputStream;
44 import java.io.InputStream;
45 import java.net.URLDecoder;
46 import java.util.ArrayList;
47 import java.util.HashSet;
48 import java.util.List;
49 import java.util.Locale;
50 import java.util.Set;
51
52 import android.app.Activity;
53 import android.app.AlertDialog;
54 import android.app.Dialog;
55 import android.app.ProgressDialog;
56 import android.content.Context;
57 import android.content.DialogInterface;
58 import android.content.Intent;
59 import android.content.SharedPreferences;
60 import android.content.pm.PackageManager.NameNotFoundException;
61 import android.content.res.Configuration;
62 import android.content.res.Resources;
63 import android.graphics.Bitmap;
64 import android.graphics.BitmapFactory;
65 import android.hardware.Sensor;
66 import android.hardware.SensorEvent;
67 import android.hardware.SensorEventListener;
68 import android.hardware.SensorManager;
69 import android.location.Address;
70 import android.location.Geocoder;
71 import android.location.GpsStatus;
72 import android.location.LocationManager;
73 import android.media.AudioManager;
74 import android.net.Uri;
75 import android.os.Bundle;
76 import android.os.Debug;
77 import android.os.Handler;
78 import android.os.Message;
79 import android.os.PowerManager;
80 import android.preference.PreferenceManager;
81 import android.text.SpannableString;
82 import android.text.method.LinkMovementMethod;
83 import android.text.util.Linkify;
84 import android.util.DisplayMetrics;
85 import android.util.Log;
86 import android.view.Display;
87 import android.view.Menu;
88 import android.view.MenuItem;
89 import android.view.Window;
90 import android.view.WindowManager;
91 import android.view.inputmethod.InputMethodManager;
92 import android.widget.RelativeLayout;
93 import android.widget.TextView;
94 import android.widget.Toast;
95
96 import com.zoffcc.applications.zanavi.NavitMapDownloader.ProgressThread;
97
98 public class Navit extends Activity implements Handler.Callback, SensorEventListener
99 {
100 public static final String VERSION_TEXT_LONG_INC_REV = "v1.0.0-795";
101 public static String NavitAppVersion = "0";
102 public static String NavitAppVersion_prev = "-1";
103 public static String NavitAppVersion_string = "0";
104 private Boolean xmlconfig_unpack_file = true;
105 private Boolean write_new_version_file = true;
106
107 // for future use ...
108 public static String NavitDataDirectory = "/sdcard/";
109
110 public static int GlobalScaleLevel = 0;
111
112 public static final class Navit_Address_Result_Struct
113 {
114 String result_type; // TWN,STR,SHN
115 String item_id; // H<ddddd>L<ddddd> -> item.id_hi item.id_lo
116 float lat;
117 float lon;
118 String addr;
119 }
120
121 public static Set<String> Navit_Address_Result_double_index = new HashSet<String>();
122
123 public NavitAndroidOverlay NavitAOverlay2;
124 public static NavitAndroidOverlay NavitAOverlay2_s;
125
126 public static final class Navit_OSD_compass
127 {
128 Boolean angle_north_valid = false;
129 float angle_north = 0.0f;
130 Boolean angle_target_valid = false;
131 float angle_target = 0.0f;
132 Boolean direct_distance_to_target_valid = false;
133 String direct_distance_to_target = "";
134 }
135
136 public static final class Navit_OSD_route_001
137 {
138 Boolean driving_distance_to_target_valid = false;
139 String driving_distance_to_target = "";
140 Boolean arriving_time_valid = false;
141 String arriving_time = "";
142 }
143
144 public static final class Navit_OSD_route_nextturn
145 {
146 Boolean nextturn_image_filename_valid = false;
147 String nextturn_image_filename = "";
148 Boolean nextturn_image_valid = false;
149 Bitmap nextturn_image = null;
150 Boolean nextturn_distance_valid = false;
151 String nextturn_distance = "";
152 }
153
154 public static final class Navit_OSD_scale
155 {
156 Boolean scale_valid = false;
157 String scale_text = "";
158 int base = 0;
159 int var = 0;
160 }
161
162 public static Navit_OSD_compass OSD_compass = new Navit_OSD_compass();
163 public static Navit_OSD_route_001 OSD_route_001 = new Navit_OSD_route_001();
164 public static Navit_OSD_route_nextturn OSD_nextturn = new Navit_OSD_route_nextturn();
165 public static Navit_OSD_scale OSD_scale = new Navit_OSD_scale();
166
167 SimGPS Simulate = null;
168 WatchMem watchmem = null;
169
170 public static int sats = 0;
171 public static int satsInFix = 0;
172
173 // public static Vibrator vibrator = null;
174
175 public Handler handler;
176 private PowerManager.WakeLock wl;
177 private NavitActivityResult ActivityResults[];
178 public static InputMethodManager mgr = null;
179 public static DisplayMetrics metrics = null;
180 public static Boolean show_soft_keyboard = false;
181 public static Boolean show_soft_keyboard_now_showing = false;
182 public static long last_pressed_menu_key = 0L;
183 public static long time_pressed_menu_key = 0L;
184 private static Intent startup_intent = null;
185 private static long startup_intent_timestamp = 0L;
186 public static String my_display_density = "mdpi";
187 private boolean searchBoxShown = false;
188 public static final int MAPDOWNLOAD_PRI_DIALOG = 1;
189 public static final int MAPDOWNLOAD_SEC_DIALOG = 2;
190 public static final int SEARCHRESULTS_WAIT_DIALOG = 3;
191 public static final int SEARCHRESULTS_WAIT_DIALOG_OFFLINE = 4;
192 public static final int ADDRESS_RESULTS_DIALOG_MAX = 10;
193 public ProgressDialog mapdownloader_dialog_pri = null;
194 public ProgressDialog mapdownloader_dialog_sec = null;
195 public ProgressDialog search_results_wait = null;
196 public ProgressDialog search_results_wait_offline = null;
197 public static Handler Navit_progress_h = null;
198 public static NavitMapDownloader mapdownloader_pri = null;
199 public static NavitMapDownloader mapdownloader_sec = null;
200 public static final int NavitDownloaderPriSelectMap_id = 967;
201 public static final int NavitDownloaderSecSelectMap_id = 968;
202 public static final int NavitDeleteSecSelectMap_id = 969;
203 public static int download_map_id = 0;
204 ProgressThread progressThread_pri = null;
205 ProgressThread progressThread_sec = null;
206 public static int search_results_towns = 0;
207 public static int search_results_streets = 0;
208 public static int search_results_streets_hn = 0;
209 SearchResultsThread searchresultsThread = null;
210 SearchResultsThread searchresultsThread_offline = null;
211 SearchResultsThreadSpinnerThread spinner_thread = null;
212 SearchResultsThreadSpinnerThread spinner_thread_offline = null;
213 public static Boolean NavitAddressSearchSpinnerActive = false;
214 public static final int MAP_NUM_PRIMARY = 11;
215 public static final int NavitAddressSearch_id_offline = 70;
216 public static final int NavitAddressSearch_id_online = 73;
217 public static final int NavitAddressResultList_id = 71;
218 public static final int NavitAddressSearchCountry_id = 74;
219 public static final int NavitMapPreview_id = 75;
220 public static final int NavitAddressSearch_id_gmaps = 76;
221 public static List<Navit_Address_Result_Struct> NavitAddressResultList_foundItems = new ArrayList<Navit_Address_Result_Struct>();
222
223 public SensorManager sensorManager = null;
224 //private static SensorManager sensorManager_ = null;
225
226 public static Context getBaseContext_ = null;
227 public static GpsStatus gps_st = null;
228
229 public static Bitmap follow_on = null;
230 public static Bitmap follow_off = null;
231 public static Bitmap follow_current = null;
232 public static Bitmap zoomin = null;
233 public static Bitmap zoomout = null;
234 public static Bitmap bigmap_bitmap = null;
235 public static Bitmap onway_arrow = null;
236
237 public static String Navit_last_address_search_string = "";
238 public static Boolean Navit_last_address_full_file_search = false;
239 public static String Navit_last_address_search_country_iso2_string = "";
240 public static int Navit_last_address_search_country_flags = 3;
241 public static int Navit_last_address_search_country_id = 0;
242 public static Boolean Navit_last_address_partial_match = false;
243 public static Geocoder Navit_Geocoder = null;
244 public static String UserAgentString = null;
245 public static Boolean first_ever_startup = false;
246
247 public static Boolean Navit_Announcer = true;
248
249 public static final int MAP_NUM_SECONDARY = 12;
250 static final String MAP_FILENAME_PATH = "/sdcard/zanavi/maps/";
251 static final String MAPMD5_FILENAME_PATH = "/sdcard/zanavi/md5/";
252 static final String CFG_FILENAME_PATH = "/sdcard/zanavi/";
253 static final String NAVIT_DATA_DIR = "/data/data/com.zoffcc.applications.zanavi";
254 static final String NAVIT_DATA_SHARE_DIR = NAVIT_DATA_DIR + "/share";
255 static final String FIRST_STARTUP_FILE = NAVIT_DATA_SHARE_DIR + "/has_run_once.txt";
256 static final String VERSION_FILE = NAVIT_DATA_SHARE_DIR + "/version.txt";
257
258 static Resources res_ = null;
259
260 public static String get_text(String in)
261 {
262 return NavitTextTranslations.get_text(in);
263 }
264
265 private boolean extractRes(String resname, String result)
266 {
267 int slash = -1;
268 boolean needs_update = false;
269 File resultfile;
270 Resources res = getResources();
271 Log.e("Navit", "Res Name " + resname);
272 Log.e("Navit", "result " + result);
273 int id = res.getIdentifier(resname, "raw", "com.zoffcc.applications.zanavi");
274 Log.e("Navit", "Res ID " + id);
275 if (id == 0) return false;
276 while ((slash = result.indexOf("/", slash + 1)) != -1)
277 {
278 if (slash != 0)
279 {
280 Log.e("Navit", "Checking " + result.substring(0, slash));
281 resultfile = new File(result.substring(0, slash));
282 if (!resultfile.exists())
283 {
284 Log.e("Navit", "Creating dir");
285 if (!resultfile.mkdir()) return false;
286 needs_update = true;
287 }
288 }
289 }
290 resultfile = new File(result);
291 if (!resultfile.exists()) needs_update = true;
292 if (!needs_update)
293 {
294 try
295 {
296 InputStream resourcestream = res.openRawResource(id);
297 FileInputStream resultfilestream = new FileInputStream(resultfile);
298 byte[] resourcebuf = new byte[1024];
299 byte[] resultbuf = new byte[1024];
300 int i = 0;
301 while ((i = resourcestream.read(resourcebuf)) != -1)
302 {
303 if (resultfilestream.read(resultbuf) != i)
304 {
305 Log.e("Navit", "Result is too short");
306 needs_update = true;
307 break;
308 }
309 for (int j = 0; j < i; j++)
310 {
311 if (resourcebuf[j] != resultbuf[j])
312 {
313 Log.e("Navit", "Result is different");
314 needs_update = true;
315 break;
316 }
317 }
318 if (needs_update) break;
319 }
320 if (!needs_update && resultfilestream.read(resultbuf) != -1)
321 {
322 Log.e("Navit", "Result is too long");
323 needs_update = true;
324 }
325
326 }
327 catch (Exception e)
328 {
329 Log.e("Navit", "Exception " + e.getMessage());
330 return false;
331 }
332 }
333 if (needs_update)
334 {
335 Log.e("Navit", "Extracting resource");
336
337 try
338 {
339 InputStream resourcestream = res.openRawResource(id);
340 FileOutputStream resultfilestream = new FileOutputStream(resultfile);
341 byte[] buf = new byte[1024];
342 int i = 0;
343 while ((i = resourcestream.read(buf)) != -1)
344 {
345 resultfilestream.write(buf, 0, i);
346 }
347 }
348 catch (Exception e)
349 {
350 Log.e("Navit", "Exception " + e.getMessage());
351 return false;
352 }
353 }
354 return true;
355 }
356
357 /** Called when the activity is first created. */
358 @Override
359 public void onCreate(Bundle savedInstanceState)
360 {
361 super.onCreate(savedInstanceState);
362
363 getBaseContext_ = getBaseContext();
364
365 res_ = getResources();
366
367 // only take arguments here, onResume gets called all the time (e.g. when screenblanks, etc.)
368 Navit.startup_intent = this.getIntent();
369 // hack! remeber timstamp, and only allow 4 secs. later in onResume to set target!
370 Navit.startup_intent_timestamp = System.currentTimeMillis();
371 Log.e("Navit", "**1**A " + startup_intent.getAction());
372 Log.e("Navit", "**1**D " + startup_intent.getDataString());
373
374 // init translated text
375 NavitTextTranslations.init();
376
377 // set the new locale here -----------------------------------
378 getPrefs_loc();
379 activatePrefs_loc();
380 // set the new locale here -----------------------------------
381
382 // get the local language -------------
383 Locale locale = java.util.Locale.getDefault();
384 String lang = locale.getLanguage();
385 String langu = lang;
386 String langc = lang;
387 Log.e("Navit", "lang=" + lang);
388 int pos = langu.indexOf('_');
389 if (pos != -1)
390 {
391 langc = langu.substring(0, pos);
392 langu = langc + langu.substring(pos).toUpperCase(locale);
393 Log.e("Navit", "substring lang " + langu.substring(pos).toUpperCase(locale));
394 // set lang. for translation
395 NavitTextTranslations.main_language = langc;
396 NavitTextTranslations.sub_language = langu.substring(pos).toUpperCase(locale);
397 }
398 else
399 {
400 String country = locale.getCountry();
401 Log.e("Navit", "Country1 " + country);
402 Log.e("Navit", "Country2 " + country.toUpperCase(locale));
403 langu = langc + "_" + country.toUpperCase(locale);
404 // set lang. for translation
405 NavitTextTranslations.main_language = langc;
406 NavitTextTranslations.sub_language = country.toUpperCase(locale);
407 }
408 Log.e("Navit", "Language " + lang);
409 // get the local language -------------
410
411 // make sure the new path for config files exist
412 File navit_cfg_dir = new File(CFG_FILENAME_PATH);
413 navit_cfg_dir.mkdirs();
414
415 // make sure the new path for the navitmap.bin file(s) exist!!
416 File navit_maps_dir = new File(MAP_FILENAME_PATH);
417 navit_maps_dir.mkdirs();
418
419 // make sure the new path for the navitmap.bin file(s) exist!!
420 File navit_mapsmd5_dir = new File(MAPMD5_FILENAME_PATH);
421 navit_mapsmd5_dir.mkdirs();
422
423 // make sure the share dir exists, otherwise the infobox will not show
424 File navit_data_share_dir = new File(NAVIT_DATA_SHARE_DIR);
425 navit_data_share_dir.mkdirs();
426
427 // try to create cat. file if it does not exist
428 File navit_maps_catalogue = new File(CFG_FILENAME_PATH + NavitMapDownloader.CAT_FILE);
429 if (!navit_maps_catalogue.exists())
430 {
431 // only on complete new start (cat file doesnt yet exist)
432 // when user puts old files in dir later on, its users problem
433 // because we dont want to overwrite new/good map files in new mapdir
434 File old_map1 = new File(CFG_FILENAME_PATH + "navitmap.bin");
435 File old_map2 = new File(CFG_FILENAME_PATH + "navitmap_002.bin");
436 if (old_map1.exists())
437 {
438 // move it to new dir
439 old_map1.renameTo(new File(MAP_FILENAME_PATH + "/navitmap_001.bin"));
440 }
441 if (old_map2.exists())
442 {
443 // move it to new dir
444 old_map2.renameTo(new File(MAP_FILENAME_PATH + "/navitmap_002.bin"));
445 }
446
447 FileOutputStream fos_temp;
448 try
449 {
450 fos_temp = new FileOutputStream(navit_maps_catalogue);
451 fos_temp.write((NavitMapDownloader.MAP_CAT_HEADER + "\n").getBytes()); // just write header to the file
452 fos_temp.flush();
453 fos_temp.close();
454 }
455 catch (Exception e)
456 {
457 e.printStackTrace();
458 }
459 }
460
461 NavitMapDownloader.MULTI_NUM_THREADS = 1;
462 // try to create cat. file if it does not exist
463 File navit_secret_file = new File(CFG_FILENAME_PATH + "z.txt");
464 if (navit_secret_file.exists())
465 {
466 NavitMapDownloader.MULTI_NUM_THREADS = 6;
467 }
468
469 Navit.follow_on = BitmapFactory.decodeResource(getResources(), R.drawable.follow);
470 Navit.follow_off = BitmapFactory.decodeResource(getResources(), R.drawable.follow_off);
471 Navit.follow_current = Navit.follow_on;
472
473 Navit.zoomin = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_in_32_32);
474 Navit.zoomout = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_out_32_32);
475
476 Navit.onway_arrow = BitmapFactory.decodeResource(getResources(), R.drawable.oneway);
477
478 // *******************
479 // *******************
480 // *******************
481 // *******************
482 // check/init the catalogue file for downloaded maps
483 NavitMapDownloader.init_cat_file();
484 // *******************
485 // *******************
486 // *******************
487 // *******************
488
489 xmlconfig_unpack_file = false;
490 write_new_version_file = false;
491 try
492 {
493 NavitAppVersion = "" + this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
494 NavitAppVersion_string = "" + this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
495 }
496 catch (NameNotFoundException e)
497 {
498 e.printStackTrace();
499 NavitAppVersion = "1";
500 NavitAppVersion_string = "1";
501 }
502 catch (Exception e)
503 {
504 e.printStackTrace();
505 NavitAppVersion = "2";
506 NavitAppVersion_string = "2";
507 }
508
509 try
510 {
511 File navit_version = new File(VERSION_FILE);
512 if (!navit_version.exists())
513 {
514 System.out.println("version file does not exist");
515 NavitAppVersion_prev = "-1";
516 write_new_version_file = true;
517 }
518 else
519 {
520 // files exists, read in the prev. verison number
521 System.out.println("version file is here");
522 FileInputStream fos_temp;
523 byte[] buffer = new byte[101];
524 fos_temp = new FileInputStream(navit_version);
525 int len = fos_temp.read(buffer, 0, 100);
526 if (len != -1)
527 {
528 // use only len bytes to make the string (the rest is garbage!!)
529 NavitAppVersion_prev = new String(buffer).substring(0, len);
530 }
531 else
532 {
533 NavitAppVersion_prev = "-1";
534 write_new_version_file = true;
535 }
536 fos_temp.close();
537 }
538
539 }
540 catch (Exception e)
541 {
542 NavitAppVersion_prev = "-1";
543 write_new_version_file = true;
544 e.printStackTrace();
545 }
546
547 System.out.println("vprev:" + NavitAppVersion_prev + " vcur:" + NavitAppVersion);
548
549 if (NavitAppVersion_prev.compareTo(NavitAppVersion) != 0)
550 {
551 // different version
552 System.out.println("different version!!");
553 write_new_version_file = true;
554 xmlconfig_unpack_file = true;
555 }
556 else
557 {
558 // same version
559 System.out.println("same version");
560 xmlconfig_unpack_file = false;
561 }
562
563 // write new version file
564 if (write_new_version_file)
565 {
566 try
567 {
568 System.out.println("write version file");
569 FileOutputStream fos_temp;
570 File navit_version = new File(VERSION_FILE);
571 navit_version.delete();
572 fos_temp = new FileOutputStream(navit_version);
573 fos_temp.write(NavitAppVersion.getBytes());
574 fos_temp.flush();
575 fos_temp.close();
576 }
577 catch (Exception e)
578 {
579 e.printStackTrace();
580 }
581 }
582
583 // Sample useragent strings:
584 //
585 // Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0a1) Gecko/20110616 Firefox/7.0a1 SeaMonkey/2.4a1
586 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; GT-I9100 Build/GINGERBREAD)
587 // Dalvik/1.2.0 (Linux; U; Android 2.2.1; GT-S5830 Build/FROYO)
588 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; HTC Desire S Build/GRI40)
589 // Dalvik/1.2.0 (Linux; U; Android 2.2.2; MB525 Build/3.4.2-179)
590 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; HTC Wildfire S A510e Build/GRI40)
591 // Wget/1.10.2
592 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; sdk Build/GRI34)
593 // Dalvik/1.2.0 (Linux; U; Android 2.2.2; MB525 Build/3.4.2-164)
594 // Dalvik/1.2.0 (Linux; U; Android 2.2; GT-I9000 Build/FROYO)
595 // Dalvik/1.2.0 (Linux; U; Android 2.2.1; GT-S5570L Build/FROYO)
596 // Dalvik/1.2.0 (Linux; U; Android 2.2.1; GT-I9000 Build/FROYO)
597 // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
598 String ANDROID = android.os.Build.VERSION.SDK; //The current development codename, or the string "REL" if this is a release build.
599 //String BOARD = android.os.Build.BOARD; //The name of the underlying board, like "goldfish".
600 //String BOOTLOADER = android.os.Build.BOOTLOADER; // The system bootloader version number.
601 String BRAND = android.os.Build.BRAND; //The brand (e.g., carrier) the software is customized for, if any.
602 //String CPU_ABI = android.os.Build.CPU_ABI; //The name of the instruction set (CPU type + ABI convention) of native code.
603 //String CPU_ABI2 = android.os.Build.CPU_ABI2; // The name of the second instruction set (CPU type + ABI convention) of native code.
604 String DEVICE = android.os.Build.DEVICE; // The name of the industrial design.
605 String DISPLAY = android.os.Build.DISPLAY; //A build ID string meant for displaying to the user
606 //String FINGERPRINT = android.os.Build.FINGERPRINT; //A string that uniquely identifies this build.
607 //String HARDWARE = android.os.Build.HARDWARE; //The name of the hardware (from the kernel command line or /proc).
608 //String HOST = android.os.Build.HOST;
609 //String ID = android.os.Build.ID; //Either a changelist number, or a label like "M4-rc20".
610 String MANUFACTURER = android.os.Build.MANUFACTURER; //The manufacturer of the product/hardware.
611 //String MODEL = android.os.Build.MODEL; //The end-user-visible name for the end product.
612 //String PRODUCT = android.os.Build.PRODUCT; //The name of the overall product.
613 //String RADIO = android.os.Build.RADIO; //The radio firmware version number.
614 //String TAGS = android.os.Build.TAGS; //Comma-separated tags describing the build, like "unsigned,debug".
615 //String TYPE = android.os.Build.TYPE; //The type of build, like "user" or "eng".
616 //String USER = android.os.Build.USER;
617
618 String android_version = "Android " + ANDROID;
619 String android_device = MANUFACTURER + " " + BRAND + " " + DEVICE;
620 String android_rom_name = DISPLAY;
621 UserAgentString = "Mozilla/5.0 (Linux; U; " + "Z" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
622 System.out.println("UA=" + UserAgentString);
623
624 try
625 {
626 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
627 }
628 catch (Exception e)
629 {
630 e.printStackTrace();
631 }
632
633 // try
634 // {
635 // vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
636 // }
637 // catch (Exception e)
638 // {
639 // e.printStackTrace();
640 // }
641 //sensorManager_ = sensorManager;
642
643 /*
644 * show info box for first time users
645 */
646 AlertDialog.Builder infobox = new AlertDialog.Builder(this);
647 infobox.setTitle(Navit.get_text("__INFO_BOX_TITLE__")); //TRANS
648 infobox.setCancelable(false);
649 final TextView message = new TextView(this);
650 message.setFadingEdgeLength(20);
651 message.setVerticalFadingEdgeEnabled(true);
652 message.setPadding(10, 5, 10, 5);
653 //message.setVerticalScrollBarEnabled(true);
654 RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
655 // margins seem not to work, hmm strange
656 // so add a " " at start of every line. well whadda you gonna do ...
657 //rlp.leftMargin = 8; -> we use "m" string
658
659 message.setLayoutParams(rlp);
660 final SpannableString s = new SpannableString(" " + Navit.get_text("__INFO_BOX_TEXT__")); //TRANS
661 Linkify.addLinks(s, Linkify.WEB_URLS);
662 message.setText(s);
663 message.setMovementMethod(LinkMovementMethod.getInstance());
664 infobox.setView(message);
665
666 // for online search
667 Navit.Navit_Geocoder = new Geocoder(this);
668
669 //TRANS
670 infobox.setPositiveButton(Navit.get_text("Ok"), new DialogInterface.OnClickListener()
671 {
672 public void onClick(DialogInterface arg0, int arg1)
673 {
674 Log.e("Navit", "Ok, user saw the infobox");
675 }
676 });
677
678 //TRANS
679 infobox.setNeutralButton(Navit.get_text("More info"), new DialogInterface.OnClickListener()
680 {
681 public void onClick(DialogInterface arg0, int arg1)
682 {
683 Log.e("Navit", "user wants more info, show the website");
684 // URL to ZANavi Manual (in english language)
685 String url = "http://zanavi.cc/index.php/Manual";
686 Intent i = new Intent(Intent.ACTION_VIEW);
687 i.setData(Uri.parse(url));
688 startActivity(i);
689 }
690 });
691
692 File navit_first_startup = new File(FIRST_STARTUP_FILE);
693 // if file does NOT exist, show the info box
694 if (!navit_first_startup.exists())
695 {
696 // set first-ever-startup flag
697 first_ever_startup = true;
698 FileOutputStream fos_temp;
699 try
700 {
701 fos_temp = new FileOutputStream(navit_first_startup);
702 fos_temp.write((int) 65); // just write an "A" to the file, but really doesnt matter
703 fos_temp.flush();
704 fos_temp.close();
705 infobox.show();
706 }
707 catch (Exception e)
708 {
709 e.printStackTrace();
710 }
711 }
712 /*
713 * show info box for first time users
714 */
715
716 // make handler statically available for use in "msg_to_msg_handler"
717 Navit_progress_h = this.progress_handler;
718
719 Display display_ = getWindowManager().getDefaultDisplay();
720 int width_ = display_.getWidth();
721 int height_ = display_.getHeight();
722 metrics = new DisplayMetrics();
723 display_.getMetrics(Navit.metrics);
724 Log.e("Navit", "Navit -> pixels x=" + width_ + " pixels y=" + height_);
725 Log.e("Navit", "Navit -> dpi=" + Navit.metrics.densityDpi);
726 Log.e("Navit", "Navit -> density=" + Navit.metrics.density);
727 Log.e("Navit", "Navit -> scaledDensity=" + Navit.metrics.scaledDensity);
728
729 System.gc();
730 System.gc();
731 Navit.bigmap_bitmap = BitmapFactory.decodeResource(getResources(), R.raw.bigmap_colors_zanavi2);
732 // Navit.bigmap_bitmap.setDensity(120); // set our dpi!!
733
734 ActivityResults = new NavitActivityResult[16];
735 setVolumeControlStream(AudioManager.STREAM_MUSIC);
736 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
737 // wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen");
738 wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen");
739
740 Log.e("Navit", "trying to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language);
741 if (!extractRes(NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language, NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language + "/LC_MESSAGES/navit.mo"))
742 {
743 Log.e("Navit", "Failed to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language);
744 }
745
746 Log.e("Navit", "trying to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language.toLowerCase());
747 if (!extractRes(NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language.toLowerCase(), NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language + "/LC_MESSAGES/navit.mo"))
748 {
749 Log.e("Navit", "Failed to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language.toLowerCase());
750 }
751
752 Log.e("Navit", "trying to extract language resource " + NavitTextTranslations.main_language);
753 if (!extractRes(NavitTextTranslations.main_language, NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "/LC_MESSAGES/navit.mo"))
754 {
755 Log.e("Navit", "Failed to extract language resource " + NavitTextTranslations.main_language);
756 }
757
758 File navit_config_xml_file = new File(NAVIT_DATA_DIR + "/share/navit.xml");
759 if (!navit_config_xml_file.exists())
760 {
761 xmlconfig_unpack_file = true;
762 Log.e("Navit", "navit.xml does not exist, unpacking in any case");
763 }
764
765 my_display_density = "mdpi";
766 // ldpi display (120 dpi)
767 if (Navit.metrics.densityDpi <= 120)
768 {
769 my_display_density = "ldpi";
770 if (xmlconfig_unpack_file)
771 {
772 if (!extractRes("navitldpi", NAVIT_DATA_DIR + "/share/navit.xml"))
773 {
774 Log.e("Navit", "Failed to extract navit.xml for ldpi device(s)");
775 }
776 }
777 }
778 // mdpi display (160 dpi)
779 else if ((Navit.metrics.densityDpi > 120) && (Navit.metrics.densityDpi <= 160))
780 {
781 my_display_density = "mdpi";
782 if (xmlconfig_unpack_file)
783 {
784 if (!extractRes("navitmdpi", NAVIT_DATA_DIR + "/share/navit.xml"))
785 {
786 Log.e("Navit", "Failed to extract navit.xml for mdpi device(s)");
787 }
788 }
789 }
790 // hdpi display (240 dpi)
791 else if ((Navit.metrics.densityDpi > 160) && (Navit.metrics.densityDpi < 320))
792 //else if (Navit.metrics.densityDpi == 240)
793 {
794 my_display_density = "hdpi";
795 if (xmlconfig_unpack_file)
796 {
797 if (!extractRes("navithdpi", NAVIT_DATA_DIR + "/share/navit.xml"))
798 {
799 Log.e("Navit", "Failed to extract navit.xml for hdpi device(s)");
800 }
801 }
802 }
803 // xhdpi display (320 dpi)
804 else if (Navit.metrics.densityDpi >= 320)
805 {
806 Log.e("Navit", "found xhdpi device, this is not fully supported!!");
807 Log.e("Navit", "using hdpi values");
808 my_display_density = "hdpi";
809 if (xmlconfig_unpack_file)
810 {
811 if (!extractRes("navithdpi", NAVIT_DATA_DIR + "/share/navit.xml"))
812 {
813 Log.e("Navit", "Failed to extract navit.xml for xhdpi device(s)");
814 }
815 }
816 }
817 else
818 {
819 /* default, meaning we just dont know what display this is */
820 if (xmlconfig_unpack_file)
821 {
822 if (!extractRes("navitmdpi", NAVIT_DATA_DIR + "/share/navit.xml"))
823 {
824 Log.e("Navit", "Failed to extract navit.xml (default version)");
825 }
826 }
827 }
828 // Debug.startMethodTracing("calc");
829
830 // --> dont use!! NavitMain(this, langu, android.os.Build.VERSION.SDK_INT);
831 Log.e("Navit", "android.os.Build.VERSION.SDK_INT=" + Integer.valueOf(android.os.Build.VERSION.SDK));
832 NavitMain(this, langu, Integer.valueOf(android.os.Build.VERSION.SDK), my_display_density);
833 // CAUTION: don't use android.os.Build.VERSION.SDK_INT if <uses-sdk android:minSdkVersion="3" />
834 // You will get exception on all devices with Android 1.5 and lower
835 // because Build.VERSION.SDK_INT is since SDK 4 (Donut 1.6)
836
837 // Platform Version API Level
838 // Android 3.1 12
839 // Android 3.0 11
840 // Android 2.3.3 10
841 // Android 2.3.1 9
842 // Android 2.2 8
843 // Android 2.1 7
844 // Android 2.0.1 6
845 // Android 2.0 5
846 // Android 1.6 4
847 // Android 1.5 3
848 // Android 1.1 2
849 // Android 1.0 1
850
851 NavitActivity(3);
852
853 Navit.mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
854
855 getPrefs();
856 activatePrefs();
857
858 // unpack some localized Strings
859 // a test now, later we will unpack all needed strings for java, here at this point!!
860 //String x = NavitGraphics.getLocalizedString("Austria");
861 //Log.e("Navit", "x=" + x);
862 Navit.show_mem_used();
863
864 GpsStatus.Listener listener = new GpsStatus.Listener()
865 {
866 public void onGpsStatusChanged(int event)
867 {
868 System.out.println("xxxxx");
869 if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS)
870 {
871 }
872 }
873 };
874 }
875
876 public static void show_mem_used() // wrapper
877 {
878 try
879 {
880 Message msg = Navit_progress_h.obtainMessage();
881 Bundle b = new Bundle();
882 msg.what = 14;
883 msg.setData(b);
884 Navit_progress_h.sendMessage(msg);
885 }
886 catch (Exception e)
887 {
888 e.printStackTrace();
889 }
890 }
891
892 public static void show_mem_used_real()
893 {
894 try
895 {
896 int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
897 String usedMegsString = String.format("Memory Used: %d MB", usedMegs);
898 // System.out.println("" + usedMegsString);
899 Navit.set_debug_messages2(usedMegsString);
900 }
901 catch (Exception e)
902 {
903 e.printStackTrace();
904 }
905 }
906
907 public static void set_debug_messages(String texta, String textb, String textc)
908 {
909 try
910 {
911 NavitGraphics.debug_line_1 = texta;
912 NavitGraphics.debug_line_2 = textb;
913 NavitGraphics.debug_line_3 = textc;
914 NavitGraphics.NavitMsgTv_.setMaxLines(3);
915 NavitGraphics.NavitMsgTv_.setLines(3);
916 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3);
917 NavitGraphics.NavitMsgTv_.invalidate();
918 }
919 catch (Exception e)
920 {
921 e.printStackTrace();
922 }
923 }
924
925 public static void set_debug_messages1(String text)
926 {
927 try
928 {
929 NavitGraphics.debug_line_1 = text;
930 NavitGraphics.NavitMsgTv_.setMaxLines(3);
931 NavitGraphics.NavitMsgTv_.setLines(3);
932 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3);
933 NavitGraphics.NavitMsgTv_.invalidate();
934 }
935 catch (Exception e)
936 {
937 e.printStackTrace();
938 }
939 }
940
941 public static void set_debug_messages2(String text)
942 {
943 try
944 {
945 NavitGraphics.debug_line_2 = text;
946 NavitGraphics.NavitMsgTv_.setMaxLines(3);
947 NavitGraphics.NavitMsgTv_.setLines(3);
948 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3);
949 NavitGraphics.NavitMsgTv_.invalidate();
950 }
951 catch (Exception e)
952 {
953 e.printStackTrace();
954 }
955 }
956
957 public static void set_debug_messages3(String text)
958 {
959 try
960 {
961 NavitGraphics.debug_line_3 = text;
962 NavitGraphics.NavitMsgTv_.setMaxLines(3);
963 NavitGraphics.NavitMsgTv_.setLines(3);
964 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3);
965 NavitGraphics.NavitMsgTv_.invalidate();
966 }
967 catch (Exception e)
968 {
969 e.printStackTrace();
970 }
971 }
972
973 public static void set_debug_messages3_wrapper(String text)
974 {
975 try
976 {
977 Message msg = Navit_progress_h.obtainMessage();
978 Bundle b = new Bundle();
979 msg.what = 15;
980 b.putString("text", text);
981 msg.setData(b);
982 Navit_progress_h.sendMessage(msg);
983 }
984 catch (Exception e)
985 {
986 e.printStackTrace();
987 }
988 }
989
990 @Override
991 public void onStart()
992 {
993 Navit.show_mem_used();
994
995 System.gc();
996 super.onStart();
997 Log.e("Navit", "OnStart");
998 NavitActivity(2);
999
1000 getPrefs();
1001 activatePrefs();
1002 // activate gps AFTER 3g-location
1003 NavitVehicle.turn_on_precise_provider();
1004
1005 Navit.show_mem_used();
1006 }
1007
1008 @Override
1009 public void onRestart()
1010 {
1011 super.onRestart();
1012 Log.e("Navit", "OnRestart");
1013 NavitActivity(0);
1014 }
1015
1016 @Override
1017 public void onResume()
1018 {
1019 // System.gc();
1020 super.onResume();
1021
1022 Log.e("Navit", "OnResume");
1023 //InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
1024 NavitActivity(1);
1025
1026 //Intent caller = this.getIntent();
1027 //System.out.println("A=" + caller.getAction() + " D=" + caller.getDataString());
1028 //System.out.println("C=" + caller.getComponent().flattenToString());
1029
1030 String intent_data = null;
1031 if (startup_intent != null)
1032 {
1033 if (System.currentTimeMillis() <= Navit.startup_intent_timestamp + 4000L)
1034 {
1035 Log.e("Navit", "**2**A " + startup_intent.getAction());
1036 Log.e("Navit", "**2**D " + startup_intent.getDataString());
1037 intent_data = startup_intent.getDataString();
1038 }
1039 else
1040 {
1041 Log.e("Navit", "timestamp for navigate_to expired! not using data");
1042 }
1043 }
1044
1045 if ((intent_data != null) && (intent_data.substring(0, 18).equals("google.navigation:")))
1046 {
1047 // better use regex later, but for now to test this feature its ok :-)
1048 // better use regex later, but for now to test this feature its ok :-)
1049
1050 // d: google.navigation:q=blabla-strasse # (this happens when you are offline, or from contacts)
1051 // b: google.navigation:q=48.25676,16.643
1052 // a: google.navigation:ll=48.25676,16.643&q=blabla-strasse
1053 // e: google.navigation:ll=48.25676,16.643&title=blabla-strasse
1054 // f: google.navigation:ll=48.25676,16.643&...
1055 // c: google.navigation:ll=48.25676,16.643
1056
1057 String lat;
1058 String lon;
1059 String q;
1060
1061 String temp1 = null;
1062 String temp2 = null;
1063 String temp3 = null;
1064 boolean parsable = false;
1065 boolean unparsable_info_box = true;
1066
1067 // DEBUG
1068 // DEBUG
1069 // DEBUG
1070 // intent_data = "google.navigation:q=Wien Burggasse 27";
1071 // intent_data = "google.navigation:q=48.25676,16.643";
1072 // intent_data = "google.navigation:ll=48.25676,16.643&q=blabla-strasse";
1073 // intent_data = "google.navigation:ll=48.25676,16.643";
1074 // DEBUG
1075 // DEBUG
1076 // DEBUG
1077
1078 try
1079 {
1080 Log.e("Navit", "found DEBUG 1: " + intent_data.substring(0, 20));
1081 Log.e("Navit", "found DEBUG 2: " + intent_data.substring(20, 22));
1082 Log.e("Navit", "found DEBUG 3: " + intent_data.substring(20, 21));
1083 Log.e("Navit", "found DEBUG 4: " + intent_data.split("&").length);
1084 Log.e("Navit", "found DEBUG 4.1: yy" + intent_data.split("&")[1].substring(0, 1).toLowerCase() + "yy");
1085 Log.e("Navit", "found DEBUG 5: xx" + intent_data.split("&")[1] + "xx");
1086 }
1087 catch (Exception e)
1088 {
1089 e.printStackTrace();
1090 }
1091
1092 if (intent_data.length() > 19)
1093 {
1094 // if d: then start target search
1095 if ((intent_data.substring(0, 20).equals("google.navigation:q=")) && ((!intent_data.substring(20, 21).equals('+')) && (!intent_data.substring(20, 21).equals('-')) && (!intent_data.substring(20, 22).matches("[0-9][0-9]"))))
1096 {
1097 Log.e("Navit", "target found (d): " + intent_data.split("q=", -1)[1]);
1098 start_targetsearch_from_intent(intent_data.split("q=", -1)[1]);
1099 // dont use this here, already starting search, so set to "false"
1100 parsable = false;
1101 unparsable_info_box = false;
1102 }
1103 // if b: then remodel the input string to look like a:
1104 else if (intent_data.substring(0, 20).equals("google.navigation:q="))
1105 {
1106 intent_data = "ll=" + intent_data.split("q=", -1)[1] + "&q=Target";
1107 Log.e("Navit", "target found (b): " + intent_data);
1108 parsable = true;
1109 }
1110 // if e: then remodel the input string to look like a:
1111 else if ((intent_data.substring(0, 21).equals("google.navigation:ll=")) && (intent_data.split("&").length > 1) && (intent_data.split("&")[1].substring(0, 1).toLowerCase().equals("f")))
1112 {
1113 int idx = intent_data.indexOf("&");
1114 intent_data = intent_data.substring(0, idx) + "&q=Target";
1115 Log.e("Navit", "target found (e): " + intent_data);
1116 parsable = true;
1117 }
1118 // if f: then remodel the input string to look like a:
1119 else if ((intent_data.substring(0, 21).equals("google.navigation:ll=")) && (intent_data.split("&").length > 1))
1120 {
1121 int idx = intent_data.indexOf("&");
1122 intent_data = intent_data.substring(0, idx) + "&q=Target";
1123 Log.e("Navit", "target found (f): " + intent_data);
1124 parsable = true;
1125 }
1126 // already looks like a: just set flag
1127 else if ((intent_data.substring(0, 21).equals("google.navigation:ll=")) && (intent_data.split("&q=").length > 1))
1128 {
1129 // dummy, just set the flag
1130 Log.e("Navit", "target found (a): " + intent_data);
1131 Log.e("Navit", "target found (a): " + intent_data.split("&q=").length);
1132 parsable = true;
1133 }
1134 // if c: then remodel the input string to look like a:
1135 else if ((intent_data.substring(0, 21).equals("google.navigation:ll=")) && (intent_data.split("&q=").length < 2))
1136 {
1137 intent_data = intent_data + "&q=Target";
1138 Log.e("Navit", "target found (c): " + intent_data);
1139 parsable = true;
1140 }
1141 }
1142
1143 if (parsable)
1144 {
1145 // now string should be in form --> a:
1146 // now split the parts off
1147 temp1 = intent_data.split("&q=", -1)[0];
1148 try
1149 {
1150 temp3 = temp1.split("ll=", -1)[1];
1151 temp2 = intent_data.split("&q=", -1)[1];
1152 }
1153 catch (Exception e)
1154 {
1155 // java.lang.ArrayIndexOutOfBoundsException most likely
1156 // so let's assume we dont have '&q=xxxx'
1157 temp3 = temp1;
1158 }
1159
1160 if (temp2 == null)
1161 {
1162 // use some default name
1163 temp2 = "Target";
1164 }
1165
1166 lat = temp3.split(",", -1)[0];
1167 lon = temp3.split(",", -1)[1];
1168 q = temp2;
1169
1170 System.out.println();
1171
1172 Message msg = new Message();
1173 Bundle b = new Bundle();
1174 b.putInt("Callback", 3);
1175 b.putString("lat", lat);
1176 b.putString("lon", lon);
1177 b.putString("q", q);
1178 msg.setData(b);
1179 N_NavitGraphics.callback_handler.sendMessage(msg);
1180
1181 // zoom_to_route();
1182 try
1183 {
1184 Thread.sleep(400);
1185 }
1186 catch (InterruptedException e)
1187 {
1188 }
1189
1190 try
1191 {
1192 show_geo_on_screen(Float.parseFloat(lat), Float.parseFloat(lon));
1193 }
1194 catch (Exception e2)
1195 {
1196 e2.printStackTrace();
1197 }
1198
1199 try
1200 {
1201 Navit.follow_button_on();
1202 }
1203 catch (Exception e2)
1204 {
1205 e2.printStackTrace();
1206 }
1207 }
1208 else
1209 {
1210 if (unparsable_info_box && !searchBoxShown)
1211 {
1212
1213 searchBoxShown = true;
1214 String searchString = intent_data.split("q=")[1];
1215 searchString = searchString.split("&")[0];
1216 searchString = URLDecoder.decode(searchString); // decode the URL: e.g. %20 -> space
1217 Log.e("Navit", "Search String :" + searchString);
1218 executeSearch(searchString);
1219
1220 }
1221 }
1222 }
1223
1224 getPrefs();
1225 activatePrefs();
1226 // activate gps AFTER 3g-location
1227 NavitVehicle.turn_on_precise_provider();
1228 NavitVehicle.set_last_known_pos_fast_provider();
1229
1230 try
1231 {
1232 //Simulate = new SimGPS(NavitVehicle.vehicle_handler_);
1233 //Simulate.start();
1234 }
1235 catch (Exception e)
1236 {
1237 e.printStackTrace();
1238 }
1239
1240 try
1241 {
1242 watchmem = new WatchMem();
1243 watchmem.start();
1244 }
1245 catch (Exception e)
1246 {
1247 e.printStackTrace();
1248 }
1249 }
1250
1251 @Override
1252 public void onPause()
1253 {
1254 try
1255 {
1256 setPrefs_zoomlevel();
1257 }
1258 catch (Exception e)
1259 {
1260 e.printStackTrace();
1261 }
1262
1263 try
1264 {
1265 watchmem.stop_me();
1266 }
1267 catch (Exception e)
1268 {
1269 e.printStackTrace();
1270 }
1271
1272 try
1273 {
1274 //watchmem.join();
1275 }
1276 catch (Exception e)
1277 {
1278 e.printStackTrace();
1279 }
1280
1281 try
1282 {
1283 //Simulate.stop_me();
1284 }
1285 catch (Exception e)
1286 {
1287 e.printStackTrace();
1288 }
1289
1290 try
1291 {
1292 //Simulate.join();
1293 }
1294 catch (Exception e)
1295 {
1296 e.printStackTrace();
1297 }
1298
1299 Navit.show_mem_used();
1300
1301 super.onPause();
1302
1303 turn_off_compass();
1304
1305 Log.e("Navit", "OnPause");
1306 NavitActivity(-1);
1307
1308 Navit.show_mem_used();
1309 }
1310
1311 @Override
1312 public void onStop()
1313 {
1314 super.onStop();
1315 Log.e("Navit", "OnStop");
1316
1317 NavitVehicle.turn_off_all_providers();
1318
1319 NavitActivity(-2);
1320 System.gc();
1321 Navit.show_mem_used();
1322 }
1323
1324 @Override
1325 public void onDestroy()
1326 {
1327 super.onDestroy();
1328 Log.e("Navit", "OnDestroy");
1329 NavitActivity(-3);
1330 System.gc();
1331 Navit.show_mem_used();
1332 }
1333
1334 public void setActivityResult(int requestCode, NavitActivityResult ActivityResult)
1335 {
1336 Log.e("Navit", "setActivityResult " + requestCode);
1337 ActivityResults[requestCode] = ActivityResult;
1338 }
1339
1340 @Override
1341 public boolean onCreateOptionsMenu(Menu menu)
1342 {
1343 super.onCreateOptionsMenu(menu);
1344 //Log.e("Navit","onCreateOptionsMenu");
1345 return true;
1346 }
1347
1348 @Override
1349 public boolean onPrepareOptionsMenu(Menu menu)
1350 {
1351 super.onPrepareOptionsMenu(menu);
1352 //Log.e("Navit","onPrepareOptionsMenu");
1353 // this gets called every time the menu is opened!!
1354 // change menu items here!
1355 menu.clear();
1356
1357 // group-id,item-id,sort order number
1358 // menu.add(1, 1, 100, get_text("zoom in")); //leave out
1359 // menu.add(1, 2, 200, get_text("zoom out")); //leave out
1360
1361 menu.add(1, 6, 300, get_text("address search (online)")); //TRANS
1362 menu.add(1, 7, 310, get_text("address search (offline)")); //TRANS
1363 if (NavitGraphics.CallbackDestinationValid2() > 0)
1364 {
1365 menu.add(1, 9, 450, get_text("Stop Navigation")); //TRANS
1366 menu.add(1, 11, 455, get_text("Zoom to Route")); //TRANS
1367 }
1368 menu.add(1, 99, 480, get_text("exit navit")); //TRANS
1369 menu.add(1, 5, 485, get_text("toggle POI")); //TRANS
1370 menu.add(1, 10, 490, get_text("Settings")); //TRANS
1371
1372 if (Navit_Announcer == true)
1373 {
1374 menu.add(1, 12, 496, get_text("Announcer Off")); //TRANS
1375 }
1376 else
1377 {
1378 menu.add(1, 13, 495, get_text("Announcer On")); //TRANS
1379 }
1380
1381 menu.add(1, 3, 500, get_text("download maps")); //TRANS
1382 menu.add(1, 8, 505, get_text("delete maps")); //TRANS
1383
1384 // menu.add(1, 88, 800, "--");
1385 return true;
1386 }
1387
1388 // define graphics here
1389 public static NavitGraphics N_NavitGraphics = null;
1390
1391 // callback id gets set here when called from NavitGraphics
1392 public static void setKeypressCallback(int kp_cb_id, NavitGraphics ng)
1393 {
1394 //Log.e("Navit", "setKeypressCallback -> id1=" + kp_cb_id);
1395 //Log.e("Navit", "setKeypressCallback -> ng=" + String.valueOf(ng));
1396 //N_KeypressCallbackID = kp_cb_id;
1397 N_NavitGraphics = ng;
1398 }
1399
1400 public static void setMotionCallback(int mo_cb_id, NavitGraphics ng)
1401 {
1402 //Log.e("Navit", "setKeypressCallback -> id2=" + mo_cb_id);
1403 //Log.e("Navit", "setKeypressCallback -> ng=" + String.valueOf(ng));
1404 //N_MotionCallbackID = mo_cb_id;
1405 N_NavitGraphics = ng;
1406 }
1407
1408 //public native void KeypressCallback(int id, String s);
1409
1410 public void start_targetsearch_from_intent(String target_address)
1411 {
1412 Navit_last_address_partial_match = false;
1413 Navit_last_address_search_string = target_address;
1414
1415 // clear results
1416 Navit.NavitAddressResultList_foundItems.clear();
1417 Navit.Navit_Address_Result_double_index.clear();
1418
1419 if (Navit_last_address_search_string.equals(""))
1420 {
1421 // empty search string entered
1422 Toast.makeText(getApplicationContext(), Navit.get_text("No address found"), Toast.LENGTH_LONG).show(); //TRANS
1423 }
1424 else
1425 {
1426 // show dialog
1427 Message msg = progress_handler.obtainMessage();
1428 Bundle b = new Bundle();
1429 msg.what = 11;
1430 b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG);
1431 msg.setData(b);
1432 progress_handler.sendMessage(msg);
1433 }
1434 }
1435
1436 @Override
1437 public boolean onOptionsItemSelected(MenuItem item)
1438 {
1439 // Handle item selection
1440 switch (item.getItemId())
1441 {
1442 case 1:
1443 // zoom in
1444 Message msg = new Message();
1445 Bundle b = new Bundle();
1446 b.putInt("Callback", 1);
1447 msg.setData(b);
1448 N_NavitGraphics.callback_handler.sendMessage(msg);
1449 // if we zoom, hide the bubble
1450 if (N_NavitGraphics.NavitAOverlay != null)
1451 {
1452 N_NavitGraphics.NavitAOverlay.hide_bubble();
1453 }
1454 Log.e("Navit", "onOptionsItemSelected -> zoom in");
1455 break;
1456 case 2:
1457 // zoom out
1458 msg = new Message();
1459 b = new Bundle();
1460 b.putInt("Callback", 2);
1461 msg.setData(b);
1462 N_NavitGraphics.callback_handler.sendMessage(msg);
1463 // if we zoom, hide the bubble
1464 if (N_NavitGraphics.NavitAOverlay != null)
1465 {
1466 N_NavitGraphics.NavitAOverlay.hide_bubble();
1467 }
1468 Log.e("Navit", "onOptionsItemSelected -> zoom out");
1469 break;
1470 case 3:
1471 // map download menu
1472 Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class);
1473 this.startActivityForResult(map_download_list_activity, Navit.NavitDownloaderPriSelectMap_id);
1474 break;
1475 case 5:
1476 // toggle the normal POI layers (to avoid double POIs)
1477 msg = new Message();
1478 b = new Bundle();
1479 b.putInt("Callback", 5);
1480 b.putString("cmd", "toggle_layer(\"POI Symbols\");");
1481 msg.setData(b);
1482 N_NavitGraphics.callback_handler.sendMessage(msg);
1483 // toggle full POI icons on/off
1484 msg = new Message();
1485 b = new Bundle();
1486 b.putInt("Callback", 5);
1487 b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");");
1488 msg.setData(b);
1489 N_NavitGraphics.callback_handler.sendMessage(msg);
1490
1491 // TEST TEST // googlemaps_show("48.28696", "16.48816", "XXyy ö2432ä ä3");
1492
1493 break;
1494 case 6:
1495 // ok startup address search activity (online google maps search)
1496 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
1497 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
1498 search_intent.putExtra("address_string", Navit_last_address_search_string);
1499 search_intent.putExtra("type", "online");
1500 String pm_temp = "0";
1501 if (Navit_last_address_partial_match)
1502 {
1503 pm_temp = "1";
1504 }
1505 search_intent.putExtra("partial_match", pm_temp);
1506 this.startActivityForResult(search_intent, NavitAddressSearch_id_online);
1507 break;
1508 case 7:
1509 // ok startup address search activity (offline binfile search)
1510 Intent search_intent2 = new Intent(this, NavitAddressSearchActivity.class);
1511 search_intent2.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
1512 search_intent2.putExtra("address_string", Navit_last_address_search_string);
1513 search_intent2.putExtra("type", "offline");
1514 search_intent2.putExtra("search_country_id", Navit_last_address_search_country_id);
1515
1516 String pm_temp2 = "0";
1517 if (Navit_last_address_partial_match)
1518 {
1519 pm_temp2 = "1";
1520 }
1521 search_intent2.putExtra("partial_match", pm_temp2);
1522 this.startActivityForResult(search_intent2, NavitAddressSearch_id_offline);
1523 break;
1524 case 8:
1525 // map delete menu
1526 Intent map_delete_list_activity2 = new Intent(this, NavitDeleteSelectMapActivity.class);
1527 this.startActivityForResult(map_delete_list_activity2, Navit.NavitDeleteSecSelectMap_id);
1528 break;
1529 case 9:
1530 // stop navigation (this menu should only appear when navigation is actually on!)
1531 Message msg2 = new Message();
1532 Bundle b2 = new Bundle();
1533 b2.putInt("Callback", 7);
1534 msg2.setData(b2);
1535 N_NavitGraphics.callback_handler.sendMessage(msg2);
1536 break;
1537 case 10:
1538 // open settings menu
1539 Intent settingsActivity = new Intent(getBaseContext(), NavitPreferences.class);
1540 startActivity(settingsActivity);
1541 break;
1542 case 11:
1543 //zoom_to_route
1544 zoom_to_route();
1545 break;
1546 case 12:
1547 // announcer off
1548 Navit_Announcer = false;
1549 msg = new Message();
1550 b = new Bundle();
1551 b.putInt("Callback", 34);
1552 msg.setData(b);
1553 N_NavitGraphics.callback_handler.sendMessage(msg);
1554 break;
1555 case 13:
1556 // announcer on
1557 Navit_Announcer = true;
1558 msg = new Message();
1559 b = new Bundle();
1560 b.putInt("Callback", 35);
1561 msg.setData(b);
1562 N_NavitGraphics.callback_handler.sendMessage(msg);
1563 break;
1564 case 88:
1565 // dummy entry, just to make "breaks" in the menu
1566 break;
1567 case 99:
1568 // exit
1569 this.onStop();
1570 this.exit();
1571 //msg = new Message();
1572 //b = new Bundle();
1573 //b.putInt("Callback", 5);
1574 //b.putString("cmd", "quit();");
1575 //msg.setData(b);
1576 //N_NavitGraphics.callback_handler.sendMessage(msg);
1577 break;
1578 }
1579 return true;
1580 }
1581
1582 protected void onActivityResult(int requestCode, int resultCode, Intent data)
1583 {
1584 Log.e("Navit", "onActivityResult");
1585 switch (requestCode)
1586 {
1587 case Navit.NavitDeleteSecSelectMap_id:
1588 try
1589 {
1590 if (resultCode == Activity.RESULT_OK)
1591 {
1592 // remove all sdcard maps
1593 Message msg = new Message();
1594 Bundle b = new Bundle();
1595 b.putInt("Callback", 19);
1596 msg.setData(b);
1597 N_NavitGraphics.callback_handler.sendMessage(msg);
1598
1599 Log.d("Navit", "delete map id=" + Integer.parseInt(data.getStringExtra("selected_id")));
1600 String map_full_line = NavitMapDownloader.OSM_MAP_NAME_ondisk_ORIG_LIST[Integer.parseInt(data.getStringExtra("selected_id"))];
1601 Log.d("Navit", "delete map full line=" + map_full_line);
1602
1603 String del_map_name = MAP_FILENAME_PATH + map_full_line.split(":", 2)[0];
1604 System.out.println("del map file :" + del_map_name);
1605 // remove from cat file
1606 NavitMapDownloader.remove_from_cat_file(map_full_line);
1607 // remove from disk
1608 File del_map_name_file = new File(del_map_name);
1609 del_map_name_file.delete();
1610 // remove also any MD5 files for this map that may be on disk
1611 try
1612 {
1613 String tmp = map_full_line.split(":", 2)[1];
1614 if (!tmp.equals(NavitMapDownloader.MAP_URL_NAME_UNKNOWN))
1615 {
1616 tmp = tmp.replace("*", "");
1617 tmp = tmp.replace("/", "");
1618 tmp = tmp.replace("\\", "");
1619 tmp = tmp.replace(" ", "");
1620 tmp = tmp.replace(">", "");
1621 tmp = tmp.replace("<", "");
1622 System.out.println("removing md5 file:" + Navit.MAPMD5_FILENAME_PATH + tmp + ".md5");
1623 File md5_final_filename = new File(Navit.MAPMD5_FILENAME_PATH + tmp + ".md5");
1624 md5_final_filename.delete();
1625 }
1626 }
1627 catch (Exception e)
1628 {
1629 e.printStackTrace();
1630 }
1631
1632 // remove map, and zoom out
1633 // ***** onStop();
1634 // ***** onCreate(getIntent().getExtras());
1635
1636 // add all sdcard maps
1637 msg = new Message();
1638 b = new Bundle();
1639 b.putInt("Callback", 20);
1640 msg.setData(b);
1641 N_NavitGraphics.callback_handler.sendMessage(msg);
1642
1643 zoom_out_full();
1644 }
1645 }
1646 catch (Exception e)
1647 {
1648 Log.d("Navit", "error on onActivityResult 3");
1649 e.printStackTrace();
1650 }
1651 break;
1652 case Navit.NavitDownloaderPriSelectMap_id:
1653 try
1654 {
1655 if (resultCode == Activity.RESULT_OK)
1656 {
1657 try
1658 {
1659 Log.d("Navit", "PRI id=" + Integer.parseInt(data.getStringExtra("selected_id")));
1660 // set map id to download
1661 Navit.download_map_id = NavitMapDownloader.OSM_MAP_NAME_ORIG_ID_LIST[Integer.parseInt(data.getStringExtra("selected_id"))];
1662 // show the map download progressbar, and download the map
1663 if (Navit.download_map_id > -1)
1664 {
1665 showDialog(Navit.MAPDOWNLOAD_PRI_DIALOG);
1666 }
1667 }
1668 catch (NumberFormatException e)
1669 {
1670 Log.d("Navit", "NumberFormatException selected_id");
1671 }
1672 }
1673 else
1674 {
1675 // user pressed back key
1676 }
1677 }
1678 catch (Exception e)
1679 {
1680 Log.d("Navit", "error on onActivityResult");
1681 e.printStackTrace();
1682 }
1683 break;
1684 case Navit.NavitDownloaderSecSelectMap_id:
1685 try
1686 {
1687 if (resultCode == Activity.RESULT_OK)
1688 {
1689 try
1690 {
1691 Log.d("Navit", "SEC id=" + Integer.parseInt(data.getStringExtra("selected_id")));
1692 // set map id to download
1693 Navit.download_map_id = NavitMapDownloader.OSM_MAP_NAME_ORIG_ID_LIST[Integer.parseInt(data.getStringExtra("selected_id"))];
1694 // show the map download progressbar, and download the map
1695 if (Navit.download_map_id > -1)
1696 {
1697 showDialog(Navit.MAPDOWNLOAD_SEC_DIALOG);
1698 }
1699 }
1700 catch (NumberFormatException e)
1701 {
1702 Log.d("Navit", "NumberFormatException selected_id");
1703 }
1704 }
1705 else
1706 {
1707 // user pressed back key
1708 }
1709 }
1710 catch (Exception e)
1711 {
1712 Log.d("Navit", "error on onActivityResult");
1713 e.printStackTrace();
1714 }
1715 break;
1716 case NavitAddressSearch_id_online:
1717 case NavitAddressSearch_id_offline:
1718 try
1719 {
1720 if (resultCode == Activity.RESULT_OK)
1721 {
1722 try
1723 {
1724 String addr = data.getStringExtra("address_string");
1725 Boolean partial_match = false;
1726 try
1727 {
1728 // only from offline mask!
1729 partial_match = data.getStringExtra("partial_match").equals("1");
1730 }
1731 catch (Exception e)
1732 {
1733 }
1734
1735 Navit_last_address_partial_match = partial_match;
1736 Navit_last_address_search_string = addr;
1737
1738 try
1739 {
1740 // only from offline mask!
1741 Navit_last_address_full_file_search = data.getStringExtra("full_file_search").equals("1");
1742 }
1743 catch (Exception e)
1744 {
1745 Navit_last_address_full_file_search = false;
1746 }
1747
1748 try
1749 {
1750 // only from offline mask!
1751 Navit_last_address_search_country_iso2_string = data.getStringExtra("address_country_iso2");
1752 Navit_last_address_search_country_flags = data.getIntExtra("address_country_flags", 3);
1753 // System.out.println("Navit_last_address_search_country_flags=" + Navit_last_address_search_country_flags);
1754 Navit_last_address_search_country_id = data.getIntExtra("search_country_id", 1); // default=*ALL*
1755 PREF_search_country = Navit_last_address_search_country_id;
1756 setPrefs_search_country();
1757 }
1758 catch (Exception e)
1759 {
1760
1761 }
1762
1763 // clear results
1764 Navit.NavitAddressResultList_foundItems.clear();
1765 Navit.Navit_Address_Result_double_index.clear();
1766 Navit.search_results_towns = 0;
1767 Navit.search_results_streets = 0;
1768 Navit.search_results_streets_hn = 0;
1769
1770 if (addr.equals(""))
1771 {
1772 // empty search string entered
1773 Toast.makeText(getApplicationContext(), Navit.get_text("No search string entered"), Toast.LENGTH_LONG).show(); //TRANS
1774 }
1775 else
1776 {
1777 if (requestCode == NavitAddressSearch_id_online)
1778 {
1779 // online googlemaps search
1780 System.out.println("online googlemaps search");
1781 Message msg = progress_handler.obtainMessage();
1782 Bundle b = new Bundle();
1783 msg.what = 11;
1784 b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG);
1785 msg.setData(b);
1786 progress_handler.sendMessage(msg);
1787 }
1788 else if (requestCode == NavitAddressSearch_id_offline)
1789 {
1790 // offline binfile search
1791
1792 // show dialog, and start search for the results
1793 // make it indirect, to give our activity a chance to startup
1794 // (remember we come straight from another activity and ours is still paused!)
1795 Message msg = progress_handler.obtainMessage();
1796 Bundle b = new Bundle();
1797 msg.what = 11;
1798 b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
1799 msg.setData(b);
1800 progress_handler.sendMessage(msg);
1801 }
1802 }
1803 }
1804 catch (NumberFormatException e)
1805 {
1806 Log.d("Navit", "NumberFormatException selected_id");
1807 }
1808 }
1809 else
1810 {
1811 // user pressed back key
1812 }
1813 }
1814 catch (Exception e)
1815 {
1816 Log.d("Navit", "error on onActivityResult");
1817 e.printStackTrace();
1818 }
1819 break;
1820 case Navit.NavitAddressResultList_id:
1821 try
1822 {
1823 if (resultCode == Activity.RESULT_OK)
1824 {
1825 try
1826 {
1827 Log.d("Navit", "adress result list id=" + Integer.parseInt(data.getStringExtra("selected_id")));
1828 // get the coords for the destination
1829 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
1830
1831 // ok now set target
1832 Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS
1833
1834 Message msg = new Message();
1835 Bundle b = new Bundle();
1836 b.putInt("Callback", 3);
1837 b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lat));
1838 b.putString("lon", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lon));
1839 b.putString("q", Navit.NavitAddressResultList_foundItems.get(destination_id).addr);
1840 msg.setData(b);
1841 N_NavitGraphics.callback_handler.sendMessage(msg);
1842
1843 // zoom_to_route();
1844 try
1845 {
1846 Thread.sleep(400);
1847 }
1848 catch (InterruptedException e)
1849 {
1850 }
1851
1852 try
1853 {
1854 Navit.follow_button_on();
1855 }
1856 catch (Exception e2)
1857 {
1858 e2.printStackTrace();
1859 }
1860
1861 show_geo_on_screen(Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
1862 }
1863 catch (NumberFormatException e)
1864 {
1865 Log.d("Navit", "NumberFormatException selected_id");
1866 }
1867 }
1868 else
1869 {
1870 // user pressed back key
1871 }
1872 }
1873 catch (Exception e)
1874 {
1875 Log.d("Navit", "error on onActivityResult");
1876 e.printStackTrace();
1877 }
1878 break;
1879 case NavitAddressSearch_id_gmaps:
1880 try
1881 {
1882 if (resultCode == Activity.RESULT_OK)
1883 {
1884
1885 }
1886 }
1887 catch (Exception e)
1888 {
1889 e.printStackTrace();
1890 }
1891 break;
1892 default:
1893 Log.e("Navit", "onActivityResult " + requestCode + " " + resultCode);
1894 ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data);
1895 break;
1896 }
1897 Log.e("Navit", "onActivityResult finished");
1898 }
1899
1900 public class WatchMem extends Thread
1901 {
1902 private Boolean running;
1903
1904 WatchMem()
1905 {
1906 this.running = true;
1907 }
1908
1909 public void run()
1910 {
1911 System.out.println("WatchMem -- started --");
1912 while (this.running)
1913 {
1914 Navit.show_mem_used();
1915
1916 try
1917 {
1918 Thread.sleep(5000); // 5 secs.
1919 }
1920 catch (InterruptedException e)
1921 {
1922 }
1923 }
1924 System.out.println("WatchMem -- stopped --");
1925 }
1926
1927 public void stop_me()
1928 {
1929 this.running = false;
1930 }
1931 }
1932
1933 public class SimGPS extends Thread
1934 {
1935 private Boolean running;
1936 private Handler h;
1937
1938 SimGPS(Handler h_)
1939 {
1940 System.out.println("SimGPS -- inited --");
1941 this.h = h_;
1942 this.running = true;
1943 }
1944
1945 public void run()
1946 {
1947 System.out.println("SimGPS -- started --");
1948 while (this.running)
1949 {
1950 float rnd_heading = (float) (Math.random() * 360d);
1951 float lat = 48.216023f;
1952 float lng = 16.391664f;
1953 //Location l = new Location("Network");
1954 //l.setLatitude(lat);
1955 //l.setLongitude(lng);
1956 //l.setBearing(rnd_heading);
1957 // NavitVehicle.set_mock_location__fast(l);
1958 // NavitVehicle.update_compass_heading(rnd_heading);
1959 if (this.h != null)
1960 {
1961 Message msg = this.h.obtainMessage();
1962 Bundle b = new Bundle();
1963 msg.what = 1;
1964 b.putFloat("b", rnd_heading);
1965 b.putFloat("lat", lat);
1966 b.putFloat("lng", lng);
1967 msg.setData(b);
1968 this.h.sendMessage(msg);
1969 }
1970 try
1971 {
1972 Thread.sleep(800);
1973 }
1974 catch (InterruptedException e)
1975 {
1976 }
1977 }
1978 System.out.println("SimGPS -- stopped --");
1979 }
1980
1981 public void stop_me()
1982 {
1983 this.running = false;
1984 }
1985 }
1986
1987 public class SearchResultsThreadSpinnerThread extends Thread
1988 {
1989 int dialog_num;
1990 int spinner_current_value;
1991 private Boolean running;
1992 Handler mHandler;
1993
1994 SearchResultsThreadSpinnerThread(Handler h, int dialog_num)
1995 {
1996 this.dialog_num = dialog_num;
1997 this.mHandler = h;
1998 this.spinner_current_value = 0;
1999 this.running = true;
2000 Log.e("Navit", "SearchResultsThreadSpinnerThread created");
2001 }
2002
2003 public void run()
2004 {
2005 Log.e("Navit", "SearchResultsThreadSpinnerThread started");
2006 while (this.running)
2007 {
2008 if (Navit.NavitAddressSearchSpinnerActive == false)
2009 {
2010 this.running = false;
2011 }
2012 else
2013 {
2014 Message msg = mHandler.obtainMessage();
2015 Bundle b = new Bundle();
2016 msg.what = 10;
2017 b.putInt("dialog_num", this.dialog_num);
2018 b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
2019 b.putInt("cur", this.spinner_current_value % (Navit.ADDRESS_RESULTS_DIALOG_MAX + 1));
2020 b.putString("title", Navit.get_text("getting search results")); //TRANS
2021 b.putString("text", Navit.get_text("searching ...")); //TRANS
2022 msg.setData(b);
2023 mHandler.sendMessage(msg);
2024 try
2025 {
2026 Thread.sleep(700);
2027 }
2028 catch (InterruptedException e)
2029 {
2030 // e.printStackTrace();
2031 }
2032 this.spinner_current_value++;
2033 }
2034 }
2035 Log.e("Navit", "SearchResultsThreadSpinnerThread ended");
2036 }
2037 }
2038
2039 public class SearchResultsThread extends Thread
2040 {
2041 private Boolean running;
2042 Handler mHandler;
2043 int my_dialog_num;
2044
2045 SearchResultsThread(Handler h, int dialog_num)
2046 {
2047 this.running = true;
2048 this.mHandler = h;
2049 this.my_dialog_num = dialog_num;
2050 Log.e("Navit", "SearchResultsThread created");
2051 }
2052
2053 public void stop_me()
2054 {
2055 this.running = false;
2056 }
2057
2058 public void run()
2059 {
2060 Log.e("Navit", "SearchResultsThread started");
2061
2062 // initialize the dialog with sane values
2063 Message msg = mHandler.obtainMessage();
2064 Bundle b = new Bundle();
2065 msg.what = 10;
2066 b.putInt("dialog_num", this.my_dialog_num);
2067 b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
2068 b.putInt("cur", 0);
2069 b.putString("title", Navit.get_text("getting search results")); //TRANS
2070 b.putString("text", Navit.get_text("searching ...")); //TRANS
2071 msg.setData(b);
2072 mHandler.sendMessage(msg);
2073
2074 int partial_match_i = 0;
2075 if (Navit_last_address_partial_match)
2076 {
2077 partial_match_i = 1;
2078 }
2079
2080 if (this.my_dialog_num == Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE)
2081 {
2082 // start the search, this could take a long time!!
2083 Log.e("Navit", "SearchResultsThread run1");
2084 // need lowercase to find stuff !!
2085 Navit_last_address_search_string = filter_bad_chars(Navit_last_address_search_string).toLowerCase();
2086 if (Navit_last_address_full_file_search)
2087 {
2088 // flags -> order level to search at
2089 // ================
2090 // 0#0 0 -> search full world
2091 // lat#lon radius -> search only this area, around lat,lon
2092 // ================
2093 N_NavitGraphics.SearchResultList(3, partial_match_i, Navit_last_address_search_string, 18, Navit_last_address_search_country_iso2_string, "0#0", 0);
2094 }
2095 else
2096 {
2097 // flags --> 3: search all countries
2098 // 2: search <iso2 string> country
2099 // 1: search default country (what you have set as language in prefs)
2100 N_NavitGraphics.SearchResultList(2, partial_match_i, Navit_last_address_search_string, Navit_last_address_search_country_flags, Navit_last_address_search_country_iso2_string, "0#0", 0);
2101 }
2102 Log.e("Navit", "SearchResultsThread run2");
2103 }
2104 else if (this.my_dialog_num == Navit.SEARCHRESULTS_WAIT_DIALOG)
2105 {
2106 // online googlemaps search
2107 // google search
2108 Log.e("Navit", "SearchResultsThread run1 -> online googlemaps search");
2109 String addressInput = filter_bad_chars(Navit_last_address_search_string);
2110 try
2111 {
2112 List<Address> foundAdresses = Navit.Navit_Geocoder.getFromLocationName(addressInput, 30); //Search addresses
2113 System.out.println("found " + foundAdresses.size() + " results");
2114 // System.out.println("addr=" + foundAdresses.get(0).getLatitude() + " " + foundAdresses.get(0).getLongitude() + "" + foundAdresses.get(0).getAddressLine(0));
2115
2116 Navit.NavitAddressSearchSpinnerActive = false;
2117
2118 for (int results_step = 0; results_step < foundAdresses.size(); results_step++)
2119 {
2120 Navit.Navit_Address_Result_Struct tmp_addr = new Navit_Address_Result_Struct();
2121 tmp_addr.result_type = "STR";
2122 tmp_addr.item_id = "0";
2123 tmp_addr.lat = (float) foundAdresses.get(results_step).getLatitude();
2124 tmp_addr.lon = (float) foundAdresses.get(results_step).getLongitude();
2125 tmp_addr.addr = "";
2126
2127 String c_code = foundAdresses.get(results_step).getCountryCode();
2128 if (c_code != null)
2129 {
2130 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getCountryCode() + ",";
2131 }
2132
2133 String p_code = foundAdresses.get(results_step).getPostalCode();
2134 if (p_code != null)
2135 {
2136 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getPostalCode() + " ";
2137 }
2138
2139 if (foundAdresses.get(results_step).getMaxAddressLineIndex() > -1)
2140 {
2141 for (int addr_line = 0; addr_line < foundAdresses.get(results_step).getMaxAddressLineIndex(); addr_line++)
2142 {
2143 if (addr_line > 0) tmp_addr.addr = tmp_addr.addr + " ";
2144 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getAddressLine(addr_line);
2145 }
2146 }
2147
2148 Navit.NavitAddressResultList_foundItems.add(tmp_addr);
2149
2150 if (tmp_addr.result_type.equals("TWN"))
2151 {
2152 Navit.search_results_towns++;
2153 }
2154 else if (tmp_addr.result_type.equals("STR"))
2155 {
2156 Navit.search_results_streets++;
2157 }
2158 else if (tmp_addr.result_type.equals("SHN"))
2159 {
2160 Navit.search_results_streets_hn++;
2161 }
2162
2163 // make the dialog move its bar ...
2164 Bundle b2 = new Bundle();
2165 b2.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG);
2166 b2.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
2167 b2.putInt("cur", Navit.NavitAddressResultList_foundItems.size() % (Navit.ADDRESS_RESULTS_DIALOG_MAX + 1));
2168 b2.putString("title", Navit.get_text("loading search results")); //TRANS
2169 b2.putString("text", Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn);
2170 Navit.msg_to_msg_handler(b2, 10);
2171 }
2172 }
2173 catch (Exception e)
2174 {
2175 System.out.println("seems googlemaps API is not working, try offline search");
2176 }
2177 }
2178
2179 Navit.NavitAddressSearchSpinnerActive = false;
2180
2181 if (Navit.NavitAddressResultList_foundItems.size() > 0)
2182 {
2183 open_search_result_list();
2184 }
2185 else
2186 {
2187 // not results found, show toast
2188 msg = mHandler.obtainMessage();
2189 b = new Bundle();
2190 msg.what = 3;
2191 b.putString("text", Navit.get_text("No Results found!")); //TRANS
2192 msg.setData(b);
2193 mHandler.sendMessage(msg);
2194 }
2195
2196 // ok, remove dialog
2197 msg = mHandler.obtainMessage();
2198 b = new Bundle();
2199 msg.what = 99;
2200 b.putInt("dialog_num", this.my_dialog_num);
2201 msg.setData(b);
2202 mHandler.sendMessage(msg);
2203
2204 Log.e("Navit", "SearchResultsThread ended");
2205 }
2206 }
2207
2208 public static String filter_bad_chars(String in)
2209 {
2210 String out = in;
2211 out = out.replaceAll("\\n", " "); // newline -> space
2212 out = out.replaceAll("\\r", " "); // return -> space
2213 out = out.replaceAll("\\t", " "); // tab -> space
2214 return out;
2215 }
2216
2217 public static void msg_to_msg_handler(Bundle b, int id)
2218 {
2219 Message msg = Navit_progress_h.obtainMessage();
2220 msg.what = id;
2221 msg.setData(b);
2222 Navit_progress_h.sendMessage(msg);
2223 }
2224
2225 public void open_search_result_list()
2226 {
2227 // open result list
2228 Intent address_result_list_activity = new Intent(this, NavitAddressResultListActivity.class);
2229 this.startActivityForResult(address_result_list_activity, Navit.NavitAddressResultList_id);
2230 }
2231
2232 public Handler progress_handler = new Handler()
2233 {
2234 public void handleMessage(Message msg)
2235 {
2236 switch (msg.what)
2237 {
2238 case 0:
2239 // dismiss dialog, remove dialog
2240 dismissDialog(msg.getData().getInt("dialog_num"));
2241 removeDialog(msg.getData().getInt("dialog_num"));
2242
2243 // exit_code=0 -> OK, map was downloaded fine
2244 if (msg.getData().getInt("exit_code") == 0)
2245 {
2246 // try to use the new downloaded map (works fine now!)
2247 //Log.d("Navit", "instance count=" + Navit.getInstanceCount()); // where did this go to?
2248
2249 // **** onStop();
2250 // **** onCreate(getIntent().getExtras());
2251
2252 // reload sdcard maps
2253 Message msg2 = new Message();
2254 Bundle b2 = new Bundle();
2255 b2.putInt("Callback", 18);
2256 msg2.setData(b2);
2257 N_NavitGraphics.callback_handler.sendMessage(msg2);
2258
2259 zoom_out_full();
2260
2261 /*
2262 * Intent intent = getIntent();
2263 * System.out.println("ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ**********************");
2264 * startActivity(intent);
2265 * System.out.println("FFFFFFFFFFFFFFFFFFF**********************");
2266 * Log.d("Navit", "instance count=" + Navit.getInstanceCount());
2267 * onStop();
2268 * System.out.println("HHHHHHHHHHHHHHHHHHH**********************");
2269 */
2270
2271 //Message msg2 = new Message();
2272 //Bundle b2 = new Bundle();
2273 //b2.putInt("Callback", 6);
2274 //msg2.setData(b2);
2275 //N_NavitGraphics.callback_handler.sendMessage(msg2);
2276 }
2277 break;
2278 case 1:
2279 // change progressbar values
2280 int what_dialog = msg.getData().getInt("dialog_num");
2281 if (what_dialog == MAPDOWNLOAD_PRI_DIALOG)
2282 {
2283 mapdownloader_dialog_pri.setMax(msg.getData().getInt("max"));
2284 mapdownloader_dialog_pri.setProgress(msg.getData().getInt("cur"));
2285 mapdownloader_dialog_pri.setTitle(msg.getData().getString("title"));
2286 mapdownloader_dialog_pri.setMessage(msg.getData().getString("text"));
2287 }
2288 else if (what_dialog == MAPDOWNLOAD_SEC_DIALOG)
2289 {
2290 mapdownloader_dialog_sec.setMax(msg.getData().getInt("max"));
2291 mapdownloader_dialog_sec.setProgress(msg.getData().getInt("cur"));
2292 mapdownloader_dialog_sec.setTitle(msg.getData().getString("title"));
2293 mapdownloader_dialog_sec.setMessage(msg.getData().getString("text"));
2294 }
2295 break;
2296 case 2:
2297 Toast.makeText(getApplicationContext(), msg.getData().getString("text"), Toast.LENGTH_SHORT).show();
2298 break;
2299 case 3:
2300 Toast.makeText(getApplicationContext(), msg.getData().getString("text"), Toast.LENGTH_LONG).show();
2301 break;
2302 case 10:
2303 // change values - generic
2304 int what_dialog_generic = msg.getData().getInt("dialog_num");
2305 if (what_dialog_generic == SEARCHRESULTS_WAIT_DIALOG)
2306 {
2307 search_results_wait.setMax(msg.getData().getInt("max"));
2308 search_results_wait.setProgress(msg.getData().getInt("cur"));
2309 search_results_wait.setTitle(msg.getData().getString("title"));
2310 search_results_wait.setMessage(msg.getData().getString("text"));
2311 }
2312 else if (what_dialog_generic == SEARCHRESULTS_WAIT_DIALOG_OFFLINE)
2313 {
2314 search_results_wait_offline.setMax(msg.getData().getInt("max"));
2315 search_results_wait_offline.setProgress(msg.getData().getInt("cur"));
2316 search_results_wait_offline.setTitle(msg.getData().getString("title"));
2317 search_results_wait_offline.setMessage(msg.getData().getString("text"));
2318 }
2319 break;
2320 case 11:
2321 // show dialog - generic
2322 try
2323 {
2324 // just in case, remove the dialog if it should be shown already!
2325 dismissDialog(msg.getData().getInt("dialog_num"));
2326 removeDialog(msg.getData().getInt("dialog_num"));
2327 }
2328 catch (Exception e)
2329 {
2330 // System.out.println("Ex D1: " + e.toString());
2331 }
2332 showDialog(msg.getData().getInt("dialog_num"));
2333 break;
2334 case 12:
2335 // turn on compass
2336 turn_on_compass();
2337 break;
2338 case 13:
2339 // turn off compass
2340 turn_off_compass();
2341 break;
2342 case 14:
2343 // set used mem in textview
2344 show_mem_used_real();
2345 break;
2346 case 15:
2347 // set debug text line 3
2348 Navit.set_debug_messages3(msg.getData().getString("text"));
2349 break;
2350 case 16:
2351 // refresh NavitAndriodOverlay
2352 try
2353 {
2354 //Log.e("NavitGraphics", "xx 1");
2355 NavitGraphics.NavitAOverlay_s.invalidate();
2356 //Log.e("NavitGraphics", "xx 2");
2357 }
2358 catch (Exception e)
2359 {
2360 e.printStackTrace();
2361 }
2362 break;
2363 case 99:
2364 // dismiss dialog, remove dialog - generic
2365 dismissDialog(msg.getData().getInt("dialog_num"));
2366 removeDialog(msg.getData().getInt("dialog_num"));
2367 break;
2368 }
2369 }
2370 };
2371
2372 protected Dialog onCreateDialog(int id)
2373 {
2374 switch (id)
2375 {
2376 case Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE:
2377 search_results_wait_offline = new ProgressDialog(this);
2378 search_results_wait_offline.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
2379 search_results_wait_offline.setTitle("--");
2380 search_results_wait_offline.setMessage("--");
2381 search_results_wait_offline.setCancelable(false);
2382 search_results_wait_offline.setProgress(0);
2383 search_results_wait_offline.setMax(10);
2384 DialogInterface.OnDismissListener mOnDismissListener4 = new DialogInterface.OnDismissListener()
2385 {
2386 public void onDismiss(DialogInterface dialog)
2387 {
2388 Log.e("Navit", "onDismiss: search_results_wait offline");
2389 dialog.dismiss();
2390 dialog.cancel();
2391 searchresultsThread_offline.stop_me();
2392 }
2393 };
2394 search_results_wait_offline.setOnDismissListener(mOnDismissListener4);
2395 searchresultsThread_offline = new SearchResultsThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
2396 searchresultsThread_offline.start();
2397
2398 NavitAddressSearchSpinnerActive = true;
2399 spinner_thread_offline = new SearchResultsThreadSpinnerThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
2400 spinner_thread_offline.start();
2401
2402 return search_results_wait_offline;
2403 case Navit.SEARCHRESULTS_WAIT_DIALOG:
2404 search_results_wait = new ProgressDialog(this);
2405 search_results_wait.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
2406 search_results_wait.setTitle("--");
2407 search_results_wait.setMessage("--");
2408 search_results_wait.setCancelable(false);
2409 search_results_wait.setProgress(0);
2410 search_results_wait.setMax(10);
2411 DialogInterface.OnDismissListener mOnDismissListener3 = new DialogInterface.OnDismissListener()
2412 {
2413 public void onDismiss(DialogInterface dialog)
2414 {
2415 Log.e("Navit", "onDismiss: search_results_wait");
2416 dialog.dismiss();
2417 dialog.cancel();
2418 searchresultsThread.stop_me();
2419 }
2420 };
2421 search_results_wait.setOnDismissListener(mOnDismissListener3);
2422 searchresultsThread = new SearchResultsThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG);
2423 searchresultsThread.start();
2424
2425 NavitAddressSearchSpinnerActive = true;
2426 spinner_thread = new SearchResultsThreadSpinnerThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG);
2427 spinner_thread.start();
2428
2429 return search_results_wait;
2430 case Navit.MAPDOWNLOAD_PRI_DIALOG:
2431 mapdownloader_dialog_pri = new ProgressDialog(this);
2432 mapdownloader_dialog_pri.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
2433 mapdownloader_dialog_pri.setTitle("--");
2434 mapdownloader_dialog_pri.setMessage("--");
2435 mapdownloader_dialog_pri.setCancelable(true);
2436 mapdownloader_dialog_pri.setProgress(0);
2437 mapdownloader_dialog_pri.setMax(200);
2438 DialogInterface.OnDismissListener mOnDismissListener1 = new DialogInterface.OnDismissListener()
2439 {
2440 public void onDismiss(DialogInterface dialog)
2441 {
2442 Log.e("Navit", "onDismiss: mapdownloader_dialog pri");
2443 dialog.dismiss();
2444 dialog.cancel();
2445 progressThread_pri.stop_thread();
2446 }
2447 };
2448 mapdownloader_dialog_pri.setOnDismissListener(mOnDismissListener1);
2449 mapdownloader_pri = new NavitMapDownloader(this);
2450 progressThread_pri = mapdownloader_pri.new ProgressThread(progress_handler, NavitMapDownloader.z_OSM_MAPS[Navit.download_map_id], MAP_NUM_PRIMARY);
2451 progressThread_pri.start();
2452 // show license for OSM maps
2453 Toast.makeText(getApplicationContext(), Navit.get_text("Map data (c) OpenStreetMap contributors, CC-BY-SA"), Toast.LENGTH_LONG).show(); //TRANS
2454 return mapdownloader_dialog_pri;
2455 case Navit.MAPDOWNLOAD_SEC_DIALOG:
2456 mapdownloader_dialog_sec = new ProgressDialog(this);
2457 mapdownloader_dialog_sec.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
2458 mapdownloader_dialog_sec.setTitle("--");
2459 mapdownloader_dialog_sec.setMessage("--");
2460 mapdownloader_dialog_sec.setCancelable(true);
2461 mapdownloader_dialog_sec.setProgress(0);
2462 mapdownloader_dialog_sec.setMax(200);
2463 DialogInterface.OnDismissListener mOnDismissListener2 = new DialogInterface.OnDismissListener()
2464 {
2465 public void onDismiss(DialogInterface dialog)
2466 {
2467 Log.e("Navit", "onDismiss: mapdownloader_dialog sec");
2468 dialog.dismiss();
2469 dialog.cancel();
2470 progressThread_sec.stop_thread();
2471 }
2472 };
2473 mapdownloader_dialog_sec.setOnDismissListener(mOnDismissListener2);
2474 mapdownloader_sec = new NavitMapDownloader(this);
2475 progressThread_sec = mapdownloader_sec.new ProgressThread(progress_handler, NavitMapDownloader.z_OSM_MAPS[Navit.download_map_id], MAP_NUM_SECONDARY);
2476 progressThread_sec.start();
2477 // show license for OSM maps
2478 Toast.makeText(getApplicationContext(), Navit.get_text("Map data (c) OpenStreetMap contributors, CC-BY-SA"), Toast.LENGTH_LONG).show(); //TRANS
2479 return mapdownloader_dialog_sec;
2480 }
2481 // should never get here!!
2482 return null;
2483 }
2484
2485 public void disableSuspend()
2486 {
2487 wl.acquire();
2488 wl.release();
2489 }
2490
2491 public void exit()
2492 {
2493 NavitVehicle.turn_off_all_providers();
2494 try
2495 {
2496 NavitSpeech.stop_me();
2497 }
2498 catch (Exception s)
2499 {
2500 s.printStackTrace();
2501 }
2502 try
2503 {
2504 NavitSpeech2.stop_me();
2505 }
2506 catch (Exception s)
2507 {
2508 s.printStackTrace();
2509 }
2510 //Intent resultIntent = new Intent();
2511 //resultIntent.putExtra("exitcode", String.valueOf(exitcode));
2512 //setResult(Activity.RESULT_OK, resultIntent);
2513 Log.e("Navit", "1***************** exit called ****************");
2514 Log.e("Navit", "2***************** exit called ****************");
2515 Log.e("Navit", "3***************** exit called ****************");
2516 Log.e("Navit", "4***************** exit called ****************");
2517 Log.e("Navit", "5***************** exit called ****************");
2518 Log.e("Navit", "6***************** exit called ****************");
2519 Log.e("Navit", "7***************** exit called ****************");
2520 Log.e("Navit", "8***************** exit called ****************");
2521 // NavitActivity(-3);
2522 System.gc();
2523 finish();
2524 }
2525
2526 public boolean handleMessage(Message m)
2527 {
2528 //Log.e("Navit", "Handler received message");
2529 return true;
2530 }
2531
2532 //public static void set_zanavi_revision_in_settings()
2533 //{
2534 // // can it be that this is never used anymore??
2535 //
2536 // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
2537 // SharedPreferences.Editor editor = prefs.edit();
2538 // // editor.commit();
2539 //}
2540
2541 public static void follow_button_on()
2542 {
2543 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
2544 SharedPreferences.Editor editor = prefs.edit();
2545 Navit.follow_current = Navit.follow_on;
2546 PREF_follow_gps = true;
2547 editor.putBoolean("follow_gps", PREF_follow_gps);
2548 editor.commit();
2549 getPrefs();
2550 activatePrefs(1);
2551 NavitVehicle.set_last_known_pos_fast_provider();
2552 }
2553
2554 public static void follow_button_off()
2555 {
2556 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
2557 SharedPreferences.Editor editor = prefs.edit();
2558 Navit.follow_current = Navit.follow_off;
2559 PREF_follow_gps = false;
2560 editor.putBoolean("follow_gps", PREF_follow_gps);
2561 editor.commit();
2562 getPrefs();
2563 activatePrefs(1);
2564 }
2565
2566 public static void toggle_follow_button()
2567 {
2568 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
2569 SharedPreferences.Editor editor = prefs.edit();
2570 if (PREF_follow_gps)
2571 {
2572 Navit.follow_current = Navit.follow_off;
2573 PREF_follow_gps = false;
2574 }
2575 else
2576 {
2577 Navit.follow_current = Navit.follow_on;
2578 PREF_follow_gps = true;
2579 }
2580 editor.putBoolean("follow_gps", PREF_follow_gps);
2581 editor.commit();
2582 //if (!PREF_follow_gps)
2583 //{
2584 // // no compass turning without follow mode!
2585 // PREF_use_compass_heading_base = false;
2586 //}
2587 //if (!PREF_use_compass_heading_base)
2588 //{
2589 // // child is always "false" when parent is "false" !!
2590 // PREF_use_compass_heading_always = false;
2591 //}
2592 getPrefs();
2593 activatePrefs(1);
2594 NavitVehicle.set_last_known_pos_fast_provider();
2595 }
2596
2597 static boolean PREF_use_fast_provider;
2598 static boolean PREF_follow_gps;
2599 static boolean PREF_use_compass_heading_base;
2600 static boolean PREF_use_compass_heading_always;
2601 static boolean PREF_allow_gui_internal;
2602 static boolean PREF_show_vehicle_in_center;
2603 static boolean PREF_use_imperial;
2604 static boolean PREF_use_compass_heading_fast;
2605 static boolean PREF_use_anti_aliasing;
2606 static boolean PREF_gui_oneway_arrows;
2607 static boolean PREF_show_debug_messages;
2608 static boolean PREF_show_3d_map;
2609 static boolean PREF_use_lock_on_roads;
2610 static boolean PREF_use_route_highways;
2611 static boolean PREF_save_zoomlevel;
2612 static boolean PREF_show_sat_status;
2613 static boolean PREF_use_agps;
2614 static int PREF_search_country = 1; // default=*ALL*
2615 static int PREF_zoomlevel_num = 2 * 2 * 2 * 2 * 2;
2616
2617 public static void setPrefs_search_country()
2618 {
2619 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
2620 SharedPreferences.Editor editor = prefs.edit();
2621 editor.putInt("search_country_id", PREF_search_country);
2622 editor.commit();
2623 }
2624
2625 public static void setPrefs_zoomlevel()
2626 {
2627 //System.out.println("1 save zoom level: " + Navit.GlobalScaleLevel);
2628 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
2629 SharedPreferences.Editor editor = prefs.edit();
2630 editor.putInt("zoomlevel_num", Navit.GlobalScaleLevel);
2631 editor.commit();
2632 //System.out.println("2 save zoom level: " + Navit.GlobalScaleLevel);
2633 }
2634
2635 private static void getPrefs()
2636 {
2637 // Get the xml/preferences.xml preferences
2638 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
2639 PREF_use_fast_provider = prefs.getBoolean("use_fast_provider", false);
2640 PREF_allow_gui_internal = prefs.getBoolean("allow_gui_internal", false);
2641 PREF_follow_gps = prefs.getBoolean("follow_gps", true);
2642 PREF_use_compass_heading_base = prefs.getBoolean("use_compass_heading_base", false);
2643 PREF_use_compass_heading_always = prefs.getBoolean("use_compass_heading_always", false);
2644 PREF_use_compass_heading_fast = prefs.getBoolean("use_compass_heading_fast", false);
2645 PREF_use_anti_aliasing = prefs.getBoolean("use_anti_aliasing", true);
2646 PREF_gui_oneway_arrows = prefs.getBoolean("gui_oneway_arrows", false);
2647 PREF_show_debug_messages = prefs.getBoolean("show_debug_messages", false);
2648 PREF_show_3d_map = prefs.getBoolean("show_3d_map", false);
2649 PREF_use_lock_on_roads = prefs.getBoolean("use_lock_on_roads", true);
2650 PREF_use_route_highways = prefs.getBoolean("use_route_highways", true);
2651 PREF_save_zoomlevel = prefs.getBoolean("save_zoomlevel", true);
2652 PREF_search_country = prefs.getInt("search_country_id", 1); // default=*ALL*
2653 PREF_zoomlevel_num = prefs.getInt("zoomlevel_num", 2 * 2 * 2 * 2 * 2);
2654 PREF_show_sat_status = prefs.getBoolean("show_sat_status", false);
2655 PREF_use_agps = prefs.getBoolean("use_agps", false);
2656
2657 Navit_last_address_search_country_id = PREF_search_country;
2658 Navit_last_address_search_country_iso2_string = NavitAddressSearchCountrySelectActivity.CountryList_Human[PREF_search_country][0];
2659
2660 if (!PREF_follow_gps)
2661 {
2662 // no compass turning without follow mode!
2663 PREF_use_compass_heading_base = false;
2664 }
2665
2666 if (!PREF_use_compass_heading_base)
2667 {
2668 // child is always "false" when parent is "false" !!
2669 PREF_use_compass_heading_always = false;
2670 }
2671 PREF_show_vehicle_in_center = prefs.getBoolean("show_vehicle_in_center", false);
2672 PREF_use_imperial = prefs.getBoolean("use_imperial", false);
2673
2674 // System.out.println("get settings");
2675 // System.out.println("PREF_search_country=" + PREF_search_country);
2676 // System.out.println("PREF_follow_gps=" + PREF_follow_gps);
2677 // System.out.println("PREF_use_fast_provider=" + PREF_use_fast_provider);
2678 // System.out.println("PREF_allow_gui_internal=" + PREF_allow_gui_internal);
2679 // System.out.println("PREF_use_compass_heading_base=" + PREF_use_compass_heading_base);
2680 // System.out.println("PREF_use_compass_heading_always=" + PREF_use_compass_heading_always);
2681 // System.out.println("PREF_show_vehicle_in_center=" + PREF_show_vehicle_in_center);
2682 // System.out.println("PREF_use_imperial=" + PREF_use_imperial);
2683 }
2684
2685 private static void activatePrefs()
2686 {
2687 activatePrefs(1);
2688 if (PREF_save_zoomlevel)
2689 {
2690 // only if really started, but NOT if returning from our own child activities!!
2691
2692 //System.out.println("3 restore zoom level: " + Navit.GlobalScaleLevel);
2693 //System.out.println("4 restore zoom level: " + PREF_zoomlevel_num);
2694
2695 Message msg = new Message();
2696 Bundle b = new Bundle();
2697 b.putInt("Callback", 33);
2698 b.putString("s", Integer.toString(PREF_zoomlevel_num));
2699 msg.setData(b);
2700 try
2701 {
2702 N_NavitGraphics.callback_handler.sendMessage(msg);
2703 Navit.GlobalScaleLevel = PREF_zoomlevel_num;
2704 // System.out.println("5 restore zoom level: " + PREF_zoomlevel_num);
2705 }
2706 catch (Exception e)
2707 {
2708 }
2709 }
2710 else
2711 {
2712 PREF_zoomlevel_num = Navit.GlobalScaleLevel;
2713 }
2714 }
2715
2716 private static void activatePrefs(int dummy)
2717 {
2718 // call some functions to activate the new settings
2719 if (PREF_follow_gps)
2720 {
2721 Navit.follow_current = Navit.follow_on;
2722 }
2723 else
2724 {
2725 Navit.follow_current = Navit.follow_off;
2726 }
2727
2728 if (PREF_use_fast_provider)
2729 {
2730 NavitVehicle.turn_on_fast_provider();
2731 }
2732 else
2733 {
2734 NavitVehicle.turn_off_fast_provider();
2735 }
2736
2737 if (PREF_show_sat_status)
2738 {
2739 NavitVehicle.turn_on_sat_status();
2740 }
2741 else
2742 {
2743 NavitVehicle.turn_off_sat_status();
2744 }
2745
2746 if (PREF_allow_gui_internal)
2747 {
2748 Message msg = new Message();
2749 Bundle b = new Bundle();
2750 b.putInt("Callback", 10);
2751 msg.setData(b);
2752 try
2753 {
2754 N_NavitGraphics.callback_handler.sendMessage(msg);
2755 }
2756 catch (Exception e)
2757 {
2758 }
2759 }
2760 else
2761 {
2762 Message msg = new Message();
2763 Bundle b = new Bundle();
2764 b.putInt("Callback", 9);
2765 msg.setData(b);
2766 try
2767 {
2768 N_NavitGraphics.callback_handler.sendMessage(msg);
2769 }
2770 catch (Exception e)
2771 {
2772 }
2773 }
2774
2775 if (PREF_use_compass_heading_base)
2776 {
2777 // turn on compass
2778 msg_to_msg_handler(new Bundle(), 12);
2779 Message msg = new Message();
2780 Bundle b = new Bundle();
2781 b.putInt("Callback", 11);
2782 msg.setData(b);
2783 try
2784 {
2785 N_NavitGraphics.callback_handler.sendMessage(msg);
2786 }
2787 catch (Exception e)
2788 {
2789 }
2790 }
2791 else
2792 {
2793 // turn off compass
2794 msg_to_msg_handler(new Bundle(), 13);
2795 Message msg = new Message();
2796 Bundle b = new Bundle();
2797 b.putInt("Callback", 12);
2798 msg.setData(b);
2799 try
2800 {
2801 N_NavitGraphics.callback_handler.sendMessage(msg);
2802 }
2803 catch (Exception e)
2804 {
2805 }
2806 }
2807
2808 if (PREF_show_vehicle_in_center)
2809 {
2810 Message msg = new Message();
2811 Bundle b = new Bundle();
2812 b.putInt("Callback", 14);
2813 msg.setData(b);
2814 try
2815 {
2816 N_NavitGraphics.callback_handler.sendMessage(msg);
2817 }
2818 catch (Exception e)
2819 {
2820 }
2821 }
2822 else
2823 {
2824 Message msg = new Message();
2825 Bundle b = new Bundle();
2826 b.putInt("Callback", 13);
2827 msg.setData(b);
2828 try
2829 {
2830 N_NavitGraphics.callback_handler.sendMessage(msg);
2831 }
2832 catch (Exception e)
2833 {
2834 }
2835 }
2836
2837 if (PREF_use_imperial)
2838 {
2839 Message msg = new Message();
2840 Bundle b = new Bundle();
2841 b.putInt("Callback", 16);
2842 msg.setData(b);
2843 try
2844 {
2845 N_NavitGraphics.callback_handler.sendMessage(msg);
2846 }
2847 catch (Exception e)
2848 {
2849 }
2850 }
2851 else
2852 {
2853 Message msg = new Message();
2854 Bundle b = new Bundle();
2855 b.putInt("Callback", 15);
2856 msg.setData(b);
2857 try
2858 {
2859 N_NavitGraphics.callback_handler.sendMessage(msg);
2860 }
2861 catch (Exception e)
2862 {
2863 }
2864 }
2865
2866 if (PREF_show_debug_messages)
2867 {
2868 Message msg = new Message();
2869 Bundle b = new Bundle();
2870 b.putInt("Callback", 24);
2871 msg.setData(b);
2872 try
2873 {
2874 N_NavitGraphics.callback_handler.sendMessage(msg);
2875 }
2876 catch (Exception e)
2877 {
2878 }
2879 }
2880 else
2881 {
2882 Message msg = new Message();
2883 Bundle b = new Bundle();
2884 b.putInt("Callback", 25);
2885 msg.setData(b);
2886 try
2887 {
2888 N_NavitGraphics.callback_handler.sendMessage(msg);
2889 }
2890 catch (Exception e)
2891 {
2892 }
2893 }
2894
2895 if (PREF_show_3d_map)
2896 {
2897 Message msg = new Message();
2898 Bundle b = new Bundle();
2899 b.putInt("Callback", 31);
2900 msg.setData(b);
2901 try
2902 {
2903 N_NavitGraphics.callback_handler.sendMessage(msg);
2904 }
2905 catch (Exception e)
2906 {
2907 }
2908 }
2909 else
2910 {
2911 Message msg = new Message();
2912 Bundle b = new Bundle();
2913 b.putInt("Callback", 30);
2914 msg.setData(b);
2915 try
2916 {
2917 N_NavitGraphics.callback_handler.sendMessage(msg);
2918 }
2919 catch (Exception e)
2920 {
2921 }
2922 }
2923
2924 if (PREF_use_lock_on_roads)
2925 {
2926 Message msg = new Message();
2927 Bundle b = new Bundle();
2928 b.putInt("Callback", 36);
2929 msg.setData(b);
2930 try
2931 {
2932 N_NavitGraphics.callback_handler.sendMessage(msg);
2933 }
2934 catch (Exception e)
2935 {
2936 }
2937 }
2938 else
2939 {
2940 Message msg = new Message();
2941 Bundle b = new Bundle();
2942 b.putInt("Callback", 37);
2943 msg.setData(b);
2944 try
2945 {
2946 N_NavitGraphics.callback_handler.sendMessage(msg);
2947 }
2948 catch (Exception e)
2949 {
2950 }
2951 }
2952
2953 if (PREF_use_route_highways)
2954 {
2955 Message msg = new Message();
2956 Bundle b = new Bundle();
2957 b.putInt("Callback", 42);
2958 msg.setData(b);
2959 try
2960 {
2961 N_NavitGraphics.callback_handler.sendMessage(msg);
2962 }
2963 catch (Exception e)
2964 {
2965 }
2966 }
2967 else
2968 {
2969 Message msg = new Message();
2970 Bundle b = new Bundle();
2971 b.putInt("Callback", 43);
2972 msg.setData(b);
2973 try
2974 {
2975 N_NavitGraphics.callback_handler.sendMessage(msg);
2976 }
2977 catch (Exception e)
2978 {
2979 }
2980 }
2981 }
2982
2983 static String PREF_navit_lang;
2984
2985 private static void getPrefs_loc()
2986 {
2987 // Get the xml/preferences.xml preferences
2988 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
2989 PREF_navit_lang = prefs.getString("navit_lang", "*DEFAULT*");
2990 System.out.println("**** ***** **** pref lang=" + PREF_navit_lang);
2991 }
2992
2993 private static void activatePrefs_loc()
2994 {
2995 // creating locale
2996 if (!PREF_navit_lang.equals("*DEFAULT*"))
2997 {
2998 Locale locale2 = null;
2999 if (PREF_navit_lang.contains("_"))
3000 {
3001 String _lang = PREF_navit_lang.split("_", 2)[0];
3002 String _country = PREF_navit_lang.split("_", 2)[1];
3003 System.out.println("l=" + _lang + " c=" + _country);
3004 locale2 = new Locale(_lang, _country);
3005 }
3006 else
3007 {
3008 locale2 = new Locale(PREF_navit_lang);
3009 }
3010 Locale.setDefault(locale2);
3011 Configuration config2 = new Configuration();
3012 config2.locale = locale2;
3013 // updating locale
3014 getBaseContext_.getResources().updateConfiguration(config2, null);
3015 }
3016 }
3017
3018 public native void NavitMain(Navit x, String lang, int version, String display_density_string);
3019
3020 public native void NavitActivity(int activity);
3021
3022 /*
3023 * this is used to load the 'navit' native library on
3024 * application startup. The library has already been unpacked at
3025 * installation time by the package manager.
3026 */
3027 static
3028 {
3029 System.loadLibrary("navit");
3030 }
3031
3032 /*
3033 * Show a search activity with the string "search" filled in
3034 */
3035 private void executeSearch(String search)
3036 {
3037 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
3038 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
3039 search_intent.putExtra("address_string", search);
3040 search_intent.putExtra("type", "offline");
3041 search_intent.putExtra("search_country_id", Navit_last_address_search_country_id);
3042 String pm_temp = "0";
3043 if (Navit_last_address_partial_match)
3044 {
3045 pm_temp = "1";
3046 }
3047 search_intent.putExtra("partial_match", pm_temp);
3048 this.startActivityForResult(search_intent, NavitAddressSearch_id_offline);
3049 }
3050
3051 /*
3052 * open google maps at a given coordinate, to make bookmarks
3053 */
3054 private void googlemaps_show(String lat, String lon, String name)
3055 {
3056 // geo:latitude,longitude
3057 String url = "geo:" + lat + "," + lon + "?z=" + "16";
3058 Intent gmaps_intent = new Intent(Intent.ACTION_VIEW);
3059 gmaps_intent.setData(Uri.parse(url));
3060 this.startActivityForResult(gmaps_intent, NavitAddressSearch_id_gmaps);
3061 }
3062
3063 public void zoom_out_full()
3064 {
3065 System.out.println("");
3066 System.out.println("*** Zoom out FULL ***");
3067 System.out.println("");
3068 Message msg = new Message();
3069 Bundle b = new Bundle();
3070 b.putInt("Callback", 8);
3071 msg.setData(b);
3072 N_NavitGraphics.callback_handler.sendMessage(msg);
3073 }
3074
3075 public void show_geo_on_screen(float lat, float lng)
3076 {
3077 // -> let follow mode stay turned on ### Navit.follow_button_off();
3078 String nix = NavitGraphics.CallbackGeoCalc(3, lat, lng);
3079 }
3080
3081 public void zoom_to_route()
3082 {
3083 System.out.println("");
3084 System.out.println("*** Zoom to ROUTE ***");
3085 System.out.println("");
3086 Message msg = new Message();
3087 Bundle b = new Bundle();
3088 b.putInt("Callback", 17);
3089 msg.setData(b);
3090 N_NavitGraphics.callback_handler.sendMessage(msg);
3091 }
3092
3093 public void turn_on_compass()
3094 {
3095 try
3096 {
3097 if (!PREF_use_compass_heading_fast)
3098 {
3099 // Slower
3100 sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
3101 }
3102 else
3103 {
3104 // FAST
3105 sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_UI);
3106 }
3107 }
3108 catch (Exception e)
3109 {
3110 e.printStackTrace();
3111 }
3112 }
3113
3114 public void turn_off_compass()
3115 {
3116 try
3117 {
3118 sensorManager.unregisterListener(this);
3119 }
3120 catch (Exception e)
3121 {
3122 e.printStackTrace();
3123 }
3124 }
3125
3126 public void onSensorChanged(SensorEvent event)
3127 {
3128 if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
3129 {
3130 // System.out.println("Sensor.TYPE_MAGNETIC_FIELD");
3131 return;
3132 }
3133
3134 if (event.sensor.getType() == Sensor.TYPE_ORIENTATION)
3135 {
3136 // System.out.println("Sensor.TYPE_ORIENTATION");
3137
3138 // compass
3139 float myAzimuth = event.values[0];
3140 // double myPitch = event.values[1];
3141 // double myRoll = event.values[2];
3142
3143 //String out = String.format("Azimuth: %.2f", myAzimuth);
3144 //System.out.println("compass: " + out);
3145 NavitVehicle.update_compass_heading(myAzimuth);
3146 }
3147 }
3148
3149 public void onAccuracyChanged(Sensor sensor, int accuracy)
3150 {
3151 // compass
3152 }
3153
3154 public void hide_status_bar()
3155 {
3156 // Hide the Status Bar
3157 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
3158 }
3159
3160 public void show_status_bar()
3161 {
3162 // Hide the Status Bar
3163 // ??? getWindow().setFlags(0, 0);
3164 }
3165
3166 public void hide_title_bar()
3167 {
3168 // Hide the Title Bar - this works ONLY before setcontent in onCreate!!
3169 requestWindowFeature(Window.FEATURE_NO_TITLE);
3170 }
3171
3172 public void show_title_bar()
3173 {
3174 // Hide the Title Bar - this works ONLY before setcontent in onCreate!!
3175 // ?? requestWindowFeature(Window.);
3176 }
3177
3178 public static Boolean downloadGPSXtra(Context context)
3179 {
3180 Boolean ret = false;
3181 Boolean ret2 = false;
3182 try
3183 {
3184 LocationManager locationmanager2 = (LocationManager) context.getSystemService("location");
3185 Bundle bundle = new Bundle();
3186 //ret2 = locationmanager2.sendExtraCommand("gps", "delete_aiding_data", null);
3187 //ret = ret2;
3188 // System.out.println("ret0=" + ret);
3189 ret2 = locationmanager2.sendExtraCommand("gps", "force_xtra_injection", bundle);
3190 ret = ret2;
3191 System.out.println("ret1=" + ret2);
3192 ret2 = locationmanager2.sendExtraCommand("gps", "force_time_injection", bundle);
3193 ret = ret || ret2;
3194 System.out.println("ret2=" + ret2);
3195 }
3196 catch (Exception e)
3197 {
3198 System.out.println("*XX*");
3199 e.printStackTrace();
3200 }
3201 return ret;
3202 }
3203 }

   
Visit the ZANavi Wiki