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

   
Visit the ZANavi Wiki