/[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 27 - (show annotations) (download)
Mon Apr 9 21:27:36 2012 UTC (12 years ago) by zoff99
File size: 137060 byte(s)
lots of new stuff, tranlsations, bug fixes ...
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 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.FileNotFoundException;
44 import java.io.FileOutputStream;
45 import java.io.IOException;
46 import java.io.InputStream;
47 import java.io.ObjectInputStream;
48 import java.io.ObjectOutputStream;
49 import java.io.OutputStream;
50 import java.io.Serializable;
51 import java.net.URLDecoder;
52 import java.nio.channels.FileChannel;
53 import java.util.ArrayList;
54 import java.util.HashSet;
55 import java.util.List;
56 import java.util.Locale;
57 import java.util.Set;
58
59 import android.app.Activity;
60 import android.app.AlertDialog;
61 import android.app.Dialog;
62 import android.app.ProgressDialog;
63 import android.content.Context;
64 import android.content.DialogInterface;
65 import android.content.DialogInterface.OnCancelListener;
66 import android.content.Intent;
67 import android.content.SharedPreferences;
68 import android.content.pm.PackageInfo;
69 import android.content.pm.PackageManager.NameNotFoundException;
70 import android.content.res.Configuration;
71 import android.content.res.Resources;
72 import android.graphics.Bitmap;
73 import android.graphics.BitmapFactory;
74 import android.graphics.Typeface;
75 import android.hardware.Sensor;
76 import android.hardware.SensorEvent;
77 import android.hardware.SensorEventListener;
78 import android.hardware.SensorManager;
79 import android.location.Address;
80 import android.location.Geocoder;
81 import android.location.GpsStatus;
82 import android.location.LocationManager;
83 import android.media.AudioManager;
84 import android.net.Uri;
85 import android.os.Bundle;
86 import android.os.Debug;
87 import android.os.Environment;
88 import android.os.Handler;
89 import android.os.Message;
90 import android.os.PowerManager;
91 import android.preference.PreferenceManager;
92 import android.text.SpannableString;
93 import android.text.method.LinkMovementMethod;
94 import android.text.util.Linkify;
95 import android.util.DisplayMetrics;
96 import android.util.Log;
97 import android.util.TypedValue;
98 import android.view.Display;
99 import android.view.Gravity;
100 import android.view.Menu;
101 import android.view.MenuItem;
102 import android.view.View;
103 import android.view.Window;
104 import android.view.WindowManager;
105 import android.view.inputmethod.InputMethodManager;
106 import android.widget.RelativeLayout;
107 import android.widget.TextView;
108 import android.widget.Toast;
109
110 import com.casadelgato.widgets.NumberPicker;
111 import com.zoffcc.applications.zanavi.NavitMapDownloader.ProgressThread;
112
113 public class Navit extends Activity implements Handler.Callback, SensorEventListener
114 {
115 public static final String VERSION_TEXT_LONG_INC_REV = "1401";
116 public static String NavitAppVersion = "0";
117 public static String NavitAppVersion_prev = "-1";
118 public static String NavitAppVersion_string = "0";
119 private Boolean xmlconfig_unpack_file = true;
120 private Boolean write_new_version_file = true;
121 final static int Navit_Status_COMPLETE_NEW_INSTALL = 1;
122 final static int Navit_Status_UPGRADED_TO_NEW_VERSION = 2;
123 final static int Navit_Status_NORMAL_STARTUP = 0;
124 Boolean Navit_DonateVersion_Installed = false;
125 static Boolean Navit_Largemap_DonateVersion_Installed = false;
126 private int startup_status = Navit_Status_NORMAL_STARTUP;
127 final static int Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL = 8;
128 static Boolean unsupported = false;
129 static Boolean Navit_maps_loaded = false;
130 final static int Navit_MAX_RECENT_DESTINATIONS = 50;
131
132 // for future use ...
133 // public static String NavitDataDirectory = "/sdcard/";
134 public static String NavitDataDirectory_Maps = "/sdcard/zanavi/maps/";
135
136 public static int GlobalScaleLevel = 0;
137
138 public class CopyFiles
139 {
140 public void copyFiles(File sourceLocation, File targetLocation) throws IOException
141 {
142 if (sourceLocation.isDirectory())
143 {
144 if (!targetLocation.exists())
145 {
146 targetLocation.mkdir();
147 }
148 File[] files = sourceLocation.listFiles();
149 for (File file : files)
150 {
151 InputStream in = new FileInputStream(file);
152 OutputStream out = new FileOutputStream(targetLocation + "/" + file.getName());
153
154 // Copy the bits from input stream to output stream
155 byte[] buf = new byte[1024];
156 int len;
157 while ((len = in.read(buf)) > 0)
158 {
159 out.write(buf, 0, len);
160 }
161 in.close();
162 out.close();
163 }
164 }
165 }
166 }
167
168 private static void copyFile(File sourceFile, File destFile) throws IOException
169 {
170 if (!sourceFile.exists())
171 {
172 return;
173 }
174 if (!destFile.exists())
175 {
176 destFile.createNewFile();
177 }
178 FileChannel source = null;
179 FileChannel destination = null;
180 source = new FileInputStream(sourceFile).getChannel();
181 destination = new FileOutputStream(destFile).getChannel();
182 if (destination != null && source != null)
183 {
184 destination.transferFrom(source, 0, source.size());
185 }
186 if (source != null)
187 {
188 source.close();
189 }
190 if (destination != null)
191 {
192 destination.close();
193 }
194
195 }
196
197 public static final class Navit_Address_Result_Struct
198 {
199 String result_type; // TWN,STR,SHN
200 String item_id; // H<ddddd>L<ddddd> -> item.id_hi item.id_lo
201 float lat;
202 float lon;
203 String addr;
204 }
205
206 public static final class Navit_Point_on_Map implements Serializable
207 {
208 /**
209 * struct for a point on the map
210 */
211 private static final long serialVersionUID = 6899215049749155051L;
212 String point_name = "";
213 String addon = null;
214 float lat = 0.0f;
215 float lon = 0.0f;
216 }
217
218 static ArrayList<Navit_Point_on_Map> map_points;
219
220 public static Set<String> Navit_Address_Result_double_index = new HashSet<String>();
221
222 public NavitAndroidOverlay NavitAOverlay2;
223 public static NavitAndroidOverlay NavitAOverlay2_s;
224
225 public static final class Navit_OSD_compass
226 {
227 Boolean angle_north_valid = false;
228 float angle_north = 0.0f;
229 Boolean angle_target_valid = false;
230 float angle_target = 0.0f;
231 Boolean direct_distance_to_target_valid = false;
232 String direct_distance_to_target = "";
233 }
234
235 public static final class Navit_OSD_route_001
236 {
237 Boolean driving_distance_to_target_valid = false;
238 String driving_distance_to_target = "";
239 Boolean arriving_time_valid = false;
240 String arriving_time = "";
241 }
242
243 public static final class Navit_OSD_route_nextturn
244 {
245 Boolean nextturn_image_filename_valid = false;
246 String nextturn_image_filename = "";
247 Boolean nextturn_image_valid = false;
248 Bitmap nextturn_image = null;
249 Boolean nextturn_distance_valid = false;
250 String nextturn_distance = "";
251 }
252
253 public static final class Navit_OSD_scale
254 {
255 Boolean scale_valid = false;
256 String scale_text = "";
257 int base = 0;
258 int var = 0;
259 }
260
261 public static Navit_OSD_compass OSD_compass = new Navit_OSD_compass();
262 public static Navit_OSD_route_001 OSD_route_001 = new Navit_OSD_route_001();
263 public static Navit_OSD_route_nextturn OSD_nextturn = new Navit_OSD_route_nextturn();
264 public static Navit_OSD_scale OSD_scale = new Navit_OSD_scale();
265
266 SimGPS Simulate = null;
267 WatchMem watchmem = null;
268
269 public static int sats = 0;
270 public static int satsInFix = 0;
271
272 // public static Vibrator vibrator = null;
273
274 public Handler handler;
275 private PowerManager.WakeLock wl;
276 private NavitActivityResult ActivityResults[];
277 public static InputMethodManager mgr = null;
278 public static DisplayMetrics metrics = null;
279 public static Boolean show_soft_keyboard = false;
280 public static Boolean show_soft_keyboard_now_showing = false;
281 public static long last_pressed_menu_key = 0L;
282 public static long time_pressed_menu_key = 0L;
283 private static Intent startup_intent = null;
284 private static long startup_intent_timestamp = 0L;
285 public static String my_display_density = "mdpi";
286 private boolean searchBoxShown = false;
287 public static final int MAPDOWNLOAD_PRI_DIALOG = 1;
288 public static final int MAPDOWNLOAD_SEC_DIALOG = 2;
289 public static final int SEARCHRESULTS_WAIT_DIALOG = 3;
290 public static final int SEARCHRESULTS_WAIT_DIALOG_OFFLINE = 4;
291 public static final int ADDRESS_RESULTS_DIALOG_MAX = 10;
292 public ProgressDialog mapdownloader_dialog_pri = null;
293 public ProgressDialog mapdownloader_dialog_sec = null;
294 public ProgressDialog search_results_wait = null;
295 public ProgressDialog search_results_wait_offline = null;
296 public static Handler Navit_progress_h = null;
297 public static NavitMapDownloader mapdownloader_pri = null;
298 public static NavitMapDownloader mapdownloader_sec = null;
299 public static final int NavitDownloaderPriSelectMap_id = 967;
300 public static final int NavitDownloaderSecSelectMap_id = 968;
301 public static final int NavitDeleteSecSelectMap_id = 969;
302 public static final int NavitRecentDest_id = 970;
303 public static final int NavitGeoCoordEnter_id = 971;
304 public static int download_map_id = 0;
305 ProgressThread progressThread_pri = null;
306 ProgressThread progressThread_sec = null;
307 public static int search_results_towns = 0;
308 public static int search_results_streets = 0;
309 public static int search_results_streets_hn = 0;
310 public static Boolean NavitStartupAlreadySearching = false;
311 SearchResultsThread searchresultsThread = null;
312 SearchResultsThread searchresultsThread_offline = null;
313 SearchResultsThreadSpinnerThread spinner_thread = null;
314 SearchResultsThreadSpinnerThread spinner_thread_offline = null;
315 public static Boolean NavitAddressSearchSpinnerActive = false;
316 public static final int MAP_NUM_PRIMARY = 11;
317 public static final int NavitAddressSearch_id_offline = 70;
318 public static final int NavitAddressSearch_id_online = 73;
319 public static final int NavitAddressResultList_id = 71;
320 public static final int NavitAddressSearchCountry_id = 74;
321 public static final int NavitMapPreview_id = 75;
322 public static final int NavitAddressSearch_id_gmaps = 76;
323 public static int NavitSearchresultBarIndex = -1;
324 public static String NavitSearchresultBar_title = "";
325 public static String NavitSearchresultBar_text = "";
326 public static List<Navit_Address_Result_Struct> NavitAddressResultList_foundItems = new ArrayList<Navit_Address_Result_Struct>();
327 public static Boolean DemoVehicle = false;
328
329 static Typeface NavitStreetnameFont = null;
330
331 public SensorManager sensorManager = null;
332 //private static SensorManager sensorManager_ = null;
333
334 public static Context getBaseContext_ = null;
335 public static GpsStatus gps_st = null;
336
337 public static Bitmap follow_on = null;
338 public static Bitmap follow_off = null;
339 public static Bitmap follow_current = null;
340 public static Bitmap zoomin = null;
341 public static Bitmap zoomout = null;
342 public static Bitmap bigmap_bitmap = null;
343 public static Bitmap oneway_arrow = null;
344
345 public static String Navit_last_address_search_string = "";
346 public static Boolean Navit_last_address_full_file_search = false;
347 public static String Navit_last_address_search_country_iso2_string = "";
348 public static int Navit_last_address_search_country_flags = 3;
349 public static int Navit_last_address_search_country_id = 0;
350 public static Boolean Navit_last_address_partial_match = false;
351 public static Geocoder Navit_Geocoder = null;
352 public static String UserAgentString = null;
353 public static Boolean first_ever_startup = false;
354
355 public static Boolean Navit_Announcer = true;
356
357 public static final int MAP_NUM_SECONDARY = 12;
358 static String MAP_FILENAME_PATH = "/sdcard/zanavi/maps/";
359 static String MAPMD5_FILENAME_PATH = "/sdcard/zanavi/md5/";
360 static String CFG_FILENAME_PATH = "/sdcard/zanavi/";
361 static final String NAVIT_DATA_DIR = "/data/data/com.zoffcc.applications.zanavi";
362 static final String NAVIT_DATA_SHARE_DIR = NAVIT_DATA_DIR + "/share";
363 static final String FIRST_STARTUP_FILE = NAVIT_DATA_SHARE_DIR + "/has_run_once.txt";
364 static final String VERSION_FILE = NAVIT_DATA_SHARE_DIR + "/version.txt";
365 static final String Navit_DEST_FILENAME = "destinations.dat";
366
367 static Resources res_ = null;
368
369 public static String get_text(String in)
370 {
371 return NavitTextTranslations.get_text(in);
372 }
373
374 private boolean extractRes(String resname, String result)
375 {
376 int slash = -1;
377 boolean needs_update = false;
378 File resultfile;
379 Resources res = getResources();
380 Log.e("Navit", "Res Name " + resname);
381 Log.e("Navit", "result " + result);
382 int id = res.getIdentifier(resname, "raw", "com.zoffcc.applications.zanavi");
383 Log.e("Navit", "Res ID " + id);
384
385 if (id == 0)
386 {
387 return false;
388 }
389
390 while ((slash = result.indexOf("/", slash + 1)) != -1)
391 {
392 if (slash != 0)
393 {
394 Log.e("Navit", "Checking " + result.substring(0, slash));
395 resultfile = new File(result.substring(0, slash));
396 if (!resultfile.exists())
397 {
398 Log.e("Navit", "Creating dir");
399 if (!resultfile.mkdir()) return false;
400 needs_update = true;
401 }
402 }
403 }
404
405 resultfile = new File(result);
406
407 if (!resultfile.exists())
408 {
409 needs_update = true;
410 }
411
412 if (!needs_update)
413 {
414 try
415 {
416 InputStream resourcestream = res.openRawResource(id);
417 FileInputStream resultfilestream = new FileInputStream(resultfile);
418 byte[] resourcebuf = new byte[1024];
419 byte[] resultbuf = new byte[1024];
420 int i = 0;
421 while ((i = resourcestream.read(resourcebuf)) != -1)
422 {
423 if (resultfilestream.read(resultbuf) != i)
424 {
425 Log.e("Navit", "Result is too short");
426 needs_update = true;
427 break;
428 }
429 for (int j = 0; j < i; j++)
430 {
431 if (resourcebuf[j] != resultbuf[j])
432 {
433 Log.e("Navit", "Result is different");
434 needs_update = true;
435 break;
436 }
437 }
438 if (needs_update) break;
439 }
440 if (!needs_update && resultfilestream.read(resultbuf) != -1)
441 {
442 Log.e("Navit", "Result is too long");
443 needs_update = true;
444 }
445
446 }
447 catch (Exception e)
448 {
449 Log.e("Navit", "Exception " + e.getMessage());
450 return false;
451 }
452 }
453
454 if (needs_update)
455 {
456 Log.e("Navit", "Extracting resource");
457 try
458 {
459 InputStream resourcestream = res.openRawResource(id);
460 FileOutputStream resultfilestream = new FileOutputStream(resultfile);
461 byte[] buf = new byte[1024];
462 int i = 0;
463 while ((i = resourcestream.read(buf)) != -1)
464 {
465 resultfilestream.write(buf, 0, i);
466 }
467 }
468 catch (Exception e)
469 {
470 Log.e("Navit", "Exception " + e.getMessage());
471 return false;
472 }
473 }
474 return true;
475 }
476
477 /** Called when the activity is first created. */
478 @Override
479 public void onCreate(Bundle savedInstanceState)
480 {
481 super.onCreate(savedInstanceState);
482
483 getBaseContext_ = getBaseContext();
484
485 res_ = getResources();
486
487 NavitStreetnameFont = Typeface.createFromAsset(getBaseContext().getAssets(), "Soutane Regular.ttf");
488
489 Navit_maps_loaded = false;
490
491 // only take arguments here, onResume gets called all the time (e.g. when screenblanks, etc.)
492 Navit.startup_intent = this.getIntent();
493 // hack! remeber timstamp, and only allow 4 secs. later in onResume to set target!
494 Navit.startup_intent_timestamp = System.currentTimeMillis();
495 Log.e("Navit", "**1**A " + startup_intent.getAction());
496 Log.e("Navit", "**1**D " + startup_intent.getDataString());
497
498 startup_status = Navit_Status_NORMAL_STARTUP;
499
500 // init translated text
501 NavitTextTranslations.init();
502
503 // set the new locale here -----------------------------------
504 getPrefs_loc();
505 activatePrefs_loc();
506 // set the new locale here -----------------------------------
507
508 // set map cache size here -----------------------------------
509 getPrefs_mapcache();
510 activatePrefs_mapcache();
511 // set map cache size here -----------------------------------
512
513 // get map data dir and set it -----------------------------
514 getPrefs_mapdir();
515 activatePrefs_mapdir(true);
516 // get map data dir and set it -----------------------------
517
518 // get the local language -------------
519 Locale locale = java.util.Locale.getDefault();
520 String lang = locale.getLanguage();
521 String langu = lang;
522 String langc = lang;
523 Log.e("Navit", "lang=" + lang);
524 int pos = langu.indexOf('_');
525 if (pos != -1)
526 {
527 langc = langu.substring(0, pos);
528 langu = langc + langu.substring(pos).toUpperCase(locale);
529 Log.e("Navit", "substring lang " + langu.substring(pos).toUpperCase(locale));
530 // set lang. for translation
531 NavitTextTranslations.main_language = langc;
532 NavitTextTranslations.sub_language = langu.substring(pos).toUpperCase(locale);
533 }
534 else
535 {
536 String country = locale.getCountry();
537 Log.e("Navit", "Country1 " + country);
538 Log.e("Navit", "Country2 " + country.toUpperCase(locale));
539 langu = langc + "_" + country.toUpperCase(locale);
540 // set lang. for translation
541 NavitTextTranslations.main_language = langc;
542 NavitTextTranslations.sub_language = country.toUpperCase(locale);
543 }
544 Log.e("Navit", "Language " + lang);
545 // get the local language -------------
546
547 // make sure the new path for config files exist
548 File navit_cfg_dir = new File(CFG_FILENAME_PATH);
549 navit_cfg_dir.mkdirs();
550
551 // make sure the new path for the navitmap.bin file(s) exist!!
552 File navit_maps_dir = new File(MAP_FILENAME_PATH);
553 navit_maps_dir.mkdirs();
554
555 // make sure the new path for the navitmap.bin file(s) exist!!
556 File navit_mapsmd5_dir = new File(MAPMD5_FILENAME_PATH);
557 navit_mapsmd5_dir.mkdirs();
558
559 // make sure the share dir exists, otherwise the infobox will not show
560 File navit_data_share_dir = new File(NAVIT_DATA_SHARE_DIR);
561 navit_data_share_dir.mkdirs();
562
563 // try to create cat. file if it does not exist
564 File navit_maps_catalogue = new File(CFG_FILENAME_PATH + NavitMapDownloader.CAT_FILE);
565 if (!navit_maps_catalogue.exists())
566 {
567 FileOutputStream fos_temp;
568 try
569 {
570 fos_temp = new FileOutputStream(navit_maps_catalogue);
571 fos_temp.write((NavitMapDownloader.MAP_CAT_HEADER + "\n").getBytes()); // just write header to the file
572 fos_temp.flush();
573 fos_temp.close();
574 }
575 catch (Exception e)
576 {
577 e.printStackTrace();
578 }
579 }
580
581 // ---------- downloader threads ----------------
582 NavitMapDownloader.MULTI_NUM_THREADS = 1;
583 PackageInfo pkgInfo;
584 Navit_DonateVersion_Installed = false;
585 try
586 {
587 // is the donate version installed?
588 pkgInfo = getPackageManager().getPackageInfo("com.zoffcc.applications.zanavi_donate", 0);
589 String sharedUserId = pkgInfo.sharedUserId;
590 System.out.println("str nd=" + sharedUserId);
591 if (sharedUserId.equals("com.zoffcc.applications.zanavi"))
592 {
593 System.out.println("##bonus 001##");
594 Navit_DonateVersion_Installed = true;
595 NavitMapDownloader.MULTI_NUM_THREADS = 3;
596 }
597 }
598 catch (NameNotFoundException e)
599 {
600 e.printStackTrace();
601 }
602 catch (Exception e)
603 {
604 e.printStackTrace();
605 }
606
607 try
608 {
609 // is the "large map" donate version installed?
610 pkgInfo = getPackageManager().getPackageInfo("com.zoffcc.applications.zanavi_largemap_donate", 0);
611 String sharedUserId = pkgInfo.sharedUserId;
612 System.out.println("str lm=" + sharedUserId);
613 if (sharedUserId.equals("com.zoffcc.applications.zanavi"))
614 {
615 System.out.println("##bonus 002##");
616 Navit_DonateVersion_Installed = true;
617 Navit_Largemap_DonateVersion_Installed = true;
618 NavitMapDownloader.MULTI_NUM_THREADS = 3;
619 }
620 }
621 catch (NameNotFoundException e)
622 {
623 e.printStackTrace();
624 }
625 catch (Exception e)
626 {
627 e.printStackTrace();
628 }
629 // update map list
630 NavitMapDownloader.init_maps_without_donate_largemaps();
631 // ---------- downloader threads ----------------
632
633 Navit.follow_on = BitmapFactory.decodeResource(getResources(), R.drawable.follow);
634 Navit.follow_off = BitmapFactory.decodeResource(getResources(), R.drawable.follow_off);
635 Navit.follow_current = Navit.follow_on;
636
637 Navit.zoomin = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_in_32_32);
638 Navit.zoomout = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_out_32_32);
639
640 Navit.oneway_arrow = BitmapFactory.decodeResource(getResources(), R.drawable.oneway);
641
642 // *******************
643 // *******************
644 // *******************
645 // *******************
646 // check/init the catalogue file for downloaded maps
647 NavitMapDownloader.init_cat_file();
648 // *******************
649 // *******************
650 // *******************
651 // *******************
652
653 xmlconfig_unpack_file = false;
654 write_new_version_file = false;
655 try
656 {
657 NavitAppVersion = "" + this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
658 NavitAppVersion_string = "" + this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
659 }
660 catch (NameNotFoundException e)
661 {
662 e.printStackTrace();
663 NavitAppVersion = "1";
664 NavitAppVersion_string = "1";
665 }
666 catch (Exception e)
667 {
668 e.printStackTrace();
669 NavitAppVersion = "2";
670 NavitAppVersion_string = "2";
671 }
672
673 try
674 {
675 File navit_version = new File(VERSION_FILE);
676 if (!navit_version.exists())
677 {
678 System.out.println("version file does not exist");
679 NavitAppVersion_prev = "-1";
680 write_new_version_file = true;
681 }
682 else
683 {
684 // files exists, read in the prev. verison number
685 System.out.println("version file is here");
686 FileInputStream fos_temp;
687 byte[] buffer = new byte[101];
688 fos_temp = new FileInputStream(navit_version);
689 int len = fos_temp.read(buffer, 0, 100);
690 if (len != -1)
691 {
692 // use only len bytes to make the string (the rest is garbage!!)
693 NavitAppVersion_prev = new String(buffer).substring(0, len);
694 }
695 else
696 {
697 NavitAppVersion_prev = "-1";
698 write_new_version_file = true;
699 }
700 fos_temp.close();
701 }
702
703 }
704 catch (Exception e)
705 {
706 NavitAppVersion_prev = "-1";
707 write_new_version_file = true;
708 e.printStackTrace();
709 }
710
711 System.out.println("vprev:" + NavitAppVersion_prev + " vcur:" + NavitAppVersion);
712
713 if (NavitAppVersion_prev.compareTo(NavitAppVersion) != 0)
714 {
715 // different version
716 System.out.println("different version!!");
717 write_new_version_file = true;
718 xmlconfig_unpack_file = true;
719
720 //if ((NavitAppVersion_prev.compareTo("-1") != 0) && (NavitAppVersion.compareTo("-1") != 0))
721 //{
722 // user has upgraded to a new version of ZANavi
723 startup_status = Navit_Status_UPGRADED_TO_NEW_VERSION;
724 //}
725 }
726 else
727 {
728 // same version
729 System.out.println("same version");
730 xmlconfig_unpack_file = false;
731 }
732
733 // write new version file
734 if (write_new_version_file)
735 {
736 try
737 {
738 System.out.println("write version file");
739 FileOutputStream fos_temp;
740 File navit_version = new File(VERSION_FILE);
741 navit_version.delete();
742 fos_temp = new FileOutputStream(navit_version);
743 fos_temp.write(NavitAppVersion.getBytes());
744 fos_temp.flush();
745 fos_temp.close();
746 }
747 catch (Exception e)
748 {
749 e.printStackTrace();
750 }
751 }
752
753 // Sample useragent strings:
754 //
755 // Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0a1) Gecko/20110616 Firefox/7.0a1 SeaMonkey/2.4a1
756 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; GT-I9100 Build/GINGERBREAD)
757 // Dalvik/1.2.0 (Linux; U; Android 2.2.1; GT-S5830 Build/FROYO)
758 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; HTC Desire S Build/GRI40)
759 // Dalvik/1.2.0 (Linux; U; Android 2.2.2; MB525 Build/3.4.2-179)
760 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; HTC Wildfire S A510e Build/GRI40)
761 // Wget/1.10.2
762 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; sdk Build/GRI34)
763 // Dalvik/1.2.0 (Linux; U; Android 2.2.2; MB525 Build/3.4.2-164)
764 // Dalvik/1.2.0 (Linux; U; Android 2.2; GT-I9000 Build/FROYO)
765 // Dalvik/1.2.0 (Linux; U; Android 2.2.1; GT-S5570L Build/FROYO)
766 // Dalvik/1.2.0 (Linux; U; Android 2.2.1; GT-I9000 Build/FROYO)
767 // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
768 String ANDROID = android.os.Build.VERSION.SDK; //The current development codename, or the string "REL" if this is a release build.
769 //String BOARD = android.os.Build.BOARD; //The name of the underlying board, like "goldfish".
770 //String BOOTLOADER = android.os.Build.BOOTLOADER; // The system bootloader version number.
771 String BRAND = android.os.Build.BRAND; //The brand (e.g., carrier) the software is customized for, if any.
772 //String CPU_ABI = android.os.Build.CPU_ABI; //The name of the instruction set (CPU type + ABI convention) of native code.
773 //String CPU_ABI2 = android.os.Build.CPU_ABI2; // The name of the second instruction set (CPU type + ABI convention) of native code.
774 String DEVICE = android.os.Build.DEVICE; // The name of the industrial design.
775 String DISPLAY = android.os.Build.DISPLAY; //A build ID string meant for displaying to the user
776 //String FINGERPRINT = android.os.Build.FINGERPRINT; //A string that uniquely identifies this build.
777 //String HARDWARE = android.os.Build.HARDWARE; //The name of the hardware (from the kernel command line or /proc).
778 //String HOST = android.os.Build.HOST;
779 //String ID = android.os.Build.ID; //Either a changelist number, or a label like "M4-rc20".
780 String MANUFACTURER = android.os.Build.MANUFACTURER; //The manufacturer of the product/hardware.
781 //String MODEL = android.os.Build.MODEL; //The end-user-visible name for the end product.
782 //String PRODUCT = android.os.Build.PRODUCT; //The name of the overall product.
783 //String RADIO = android.os.Build.RADIO; //The radio firmware version number.
784 //String TAGS = android.os.Build.TAGS; //Comma-separated tags describing the build, like "unsigned,debug".
785 //String TYPE = android.os.Build.TYPE; //The type of build, like "user" or "eng".
786 //String USER = android.os.Build.USER;
787
788 String android_version = "Android " + ANDROID;
789 String android_device = MANUFACTURER + " " + BRAND + " " + DEVICE;
790
791 // debug
792 // debug
793 // android_device = "telechips telechips m801";
794 // debug
795 // debug
796
797 String android_rom_name = DISPLAY;
798 if (Navit_DonateVersion_Installed == false)
799 {
800 UserAgentString = "Mozilla/5.0 (Linux; U; " + "Z" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
801 }
802 else
803 {
804 if (Navit_Largemap_DonateVersion_Installed == false)
805 {
806 UserAgentString = "Mozilla/5.0 (Linux; U; " + "donateZ" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
807 }
808 else
809 {
810 UserAgentString = "Mozilla/5.0 (Linux; U; " + "LMdonateLMZ" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
811 }
812 }
813 // System.out.println("UA=" + UserAgentString);
814
815 unsupported = false;
816 try
817 {
818 if (android_device.toLowerCase().contains("telechips"))
819 {
820 if (android_device.toLowerCase().contains("m801"))
821 {
822 // if the donate version is already installed, dont disable the app
823 if (Navit_DonateVersion_Installed == false)
824 {
825 if (Navit_Largemap_DonateVersion_Installed == false)
826 {
827 // activate [Weltbild] Cat Nova again (19.12.2011)
828 // ** // unsupported = true;
829 }
830 }
831 }
832 }
833 }
834 catch (Exception e)
835 {
836 e.printStackTrace();
837 }
838
839 try
840 {
841 // this hangs the emulator, if emulator < 2.3 (only works in emulator >= 2.3)!!
842 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
843 }
844 catch (Exception e3)
845 {
846 e3.printStackTrace();
847 }
848
849 // try
850 // {
851 // vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
852 // }
853 // catch (Exception e)
854 // {
855 // e.printStackTrace();
856 // }
857 //sensorManager_ = sensorManager;
858
859 /*
860 * show info box for first time users
861 */
862 AlertDialog.Builder infobox = new AlertDialog.Builder(this);
863 //. english text: Welcome to ZANavi
864 infobox.setTitle(Navit.get_text("__INFO_BOX_TITLE__")); //TRANS
865 infobox.setCancelable(false);
866 final TextView message = new TextView(this);
867 message.setFadingEdgeLength(20);
868 message.setVerticalFadingEdgeEnabled(true);
869 message.setPadding(10, 5, 10, 5);
870 message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
871 message.setGravity(Gravity.LEFT);
872 // message.setScrollBarStyle(TextView.SCROLLBARS_INSIDE_OVERLAY);
873 // message.setVerticalScrollBarEnabled(true);
874 RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
875 rlp.leftMargin = 7;
876 rlp.rightMargin = 7;
877
878 Navit.Navit_Geocoder = null;
879 try
880 {
881 // for online search
882 Navit.Navit_Geocoder = new Geocoder(this);
883 }
884 catch (Exception e)
885 {
886 e.printStackTrace();
887 }
888
889 //TRANS
890 infobox.setPositiveButton(Navit.get_text("Ok"), new DialogInterface.OnClickListener()
891 {
892 public void onClick(DialogInterface arg0, int arg1)
893 {
894 Log.e("Navit", "Ok, user saw the infobox");
895 }
896 });
897
898 //TRANS
899 infobox.setNeutralButton(Navit.get_text("More info"), new DialogInterface.OnClickListener()
900 {
901 public void onClick(DialogInterface arg0, int arg1)
902 {
903 Log.e("Navit", "user wants more info, show the website");
904 // URL to ZANavi Manual (in english language)
905 String url = "http://zanavi.cc/index.php/Manual";
906 Intent i = new Intent(Intent.ACTION_VIEW);
907 i.setData(Uri.parse(url));
908 startActivity(i);
909 }
910 });
911
912 File navit_first_startup = new File(FIRST_STARTUP_FILE);
913 // if file does NOT exist, show the info box
914 if (!navit_first_startup.exists())
915 {
916 // set first-ever-startup flag
917 first_ever_startup = true;
918 startup_status = Navit_Status_COMPLETE_NEW_INSTALL;
919 FileOutputStream fos_temp;
920 try
921 {
922 fos_temp = new FileOutputStream(navit_first_startup);
923 fos_temp.write((int) 65); // just write an "A" to the file, but it really doesnt matter
924 fos_temp.flush();
925 fos_temp.close();
926
927 message.setLayoutParams(rlp);
928 //. TRANSLATORS: multiline info text for first startup of application (see en_US for english text)
929 final SpannableString s = new SpannableString(" " + Navit.get_text("__INFO_BOX_TEXT__")); //TRANS
930 Linkify.addLinks(s, Linkify.WEB_URLS);
931 message.setText(s);
932 message.setMovementMethod(LinkMovementMethod.getInstance());
933 infobox.setView(message);
934
935 infobox.show();
936 }
937 catch (Exception e)
938 {
939 e.printStackTrace();
940 }
941 }
942 /*
943 * show info box for first time users
944 */
945
946 // show info box for upgrade
947 if (startup_status == Navit_Status_UPGRADED_TO_NEW_VERSION)
948 {
949 try
950 {
951 message.setLayoutParams(rlp);
952 // upgrade message
953 String upgrade_summary = "\n\n********\n";
954 // upgrade message
955 final SpannableString s = new SpannableString("\n" + "ZANavi " + NavitAppVersion_string + "\n\n" + "upgraded" + upgrade_summary);
956 Linkify.addLinks(s, Linkify.WEB_URLS);
957 message.setText(s);
958 message.setMovementMethod(LinkMovementMethod.getInstance());
959 infobox.setView(message);
960
961 infobox.show();
962 }
963 catch (Exception e)
964 {
965 e.printStackTrace();
966 }
967 }
968 // show info box for upgrade
969
970 // make handler statically available for use in "msg_to_msg_handler"
971 Navit_progress_h = this.progress_handler;
972
973 Display display_ = getWindowManager().getDefaultDisplay();
974 int width_ = display_.getWidth();
975 int height_ = display_.getHeight();
976 metrics = new DisplayMetrics();
977 display_.getMetrics(Navit.metrics);
978 Log.e("Navit", "Navit -> pixels x=" + width_ + " pixels y=" + height_);
979 Log.e("Navit", "Navit -> dpi=" + Navit.metrics.densityDpi);
980 Log.e("Navit", "Navit -> density=" + Navit.metrics.density);
981 Log.e("Navit", "Navit -> scaledDensity=" + Navit.metrics.scaledDensity);
982
983 System.gc();
984 System.gc();
985 Navit.bigmap_bitmap = BitmapFactory.decodeResource(getResources(), R.raw.bigmap_colors_zanavi2);
986 // Navit.bigmap_bitmap.setDensity(120); // set our dpi!!
987
988 ActivityResults = new NavitActivityResult[16];
989 setVolumeControlStream(AudioManager.STREAM_MUSIC);
990 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
991 // wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen");
992 wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen");
993
994 Log.e("Navit", "trying to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language);
995 if (!extractRes(NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language, NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language + "/LC_MESSAGES/navit.mo"))
996 {
997 Log.e("Navit", "Failed to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language);
998 }
999
1000 Log.e("Navit", "trying to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language.toLowerCase());
1001 if (!extractRes(NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language.toLowerCase(), NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language + "/LC_MESSAGES/navit.mo"))
1002 {
1003 Log.e("Navit", "Failed to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language.toLowerCase());
1004 }
1005
1006 Log.e("Navit", "trying to extract language resource " + NavitTextTranslations.main_language);
1007 if (!extractRes(NavitTextTranslations.main_language, NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "/LC_MESSAGES/navit.mo"))
1008 {
1009 Log.e("Navit", "Failed to extract language resource " + NavitTextTranslations.main_language);
1010 }
1011
1012 // DEBUG - check if language file is on SDCARD -
1013 try
1014 {
1015 File debug_mo_src = new File("/sdcard/zanavi/debug/navit.mo");
1016 File debug_mo_dest = new File(NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "/LC_MESSAGES/navit.mo");
1017 //* File navit_debug_dir = new File("/sdcard/zanavi/debug/");
1018 //* navit_debug_dir.mkdirs();
1019 copyFile(debug_mo_src, debug_mo_dest);
1020 }
1021 catch (Exception e)
1022 {
1023 e.printStackTrace();
1024 }
1025 // DEBUG - check if language file is on SDCARD -
1026
1027 File navit_config_xml_file = new File(NAVIT_DATA_DIR + "/share/navit.xml");
1028 if (!navit_config_xml_file.exists())
1029 {
1030 xmlconfig_unpack_file = true;
1031 Log.e("Navit", "navit.xml does not exist, unpacking in any case");
1032 }
1033
1034 my_display_density = "mdpi";
1035 // ldpi display (120 dpi)
1036
1037 if (Navit.metrics.densityDpi <= 120)
1038 {
1039 my_display_density = "ldpi";
1040 if (xmlconfig_unpack_file)
1041 {
1042 if (!extractRes("navitldpi", NAVIT_DATA_DIR + "/share/navit.xml"))
1043 {
1044 Log.e("Navit", "Failed to extract navit.xml for ldpi device(s)");
1045 }
1046 }
1047 }
1048 // mdpi display (160 dpi)
1049 else if ((Navit.metrics.densityDpi > 120) && (Navit.metrics.densityDpi <= 160))
1050 {
1051 my_display_density = "mdpi";
1052 if (xmlconfig_unpack_file)
1053 {
1054 if (!extractRes("navitmdpi", NAVIT_DATA_DIR + "/share/navit.xml"))
1055 {
1056 Log.e("Navit", "Failed to extract navit.xml for mdpi device(s)");
1057 }
1058 }
1059 }
1060 // hdpi display (240 dpi)
1061 else if ((Navit.metrics.densityDpi > 160) && (Navit.metrics.densityDpi < 320))
1062 //else if (Navit.metrics.densityDpi == 240)
1063 {
1064 my_display_density = "hdpi";
1065 if (xmlconfig_unpack_file)
1066 {
1067 if (!extractRes("navithdpi", NAVIT_DATA_DIR + "/share/navit.xml"))
1068 {
1069 Log.e("Navit", "Failed to extract navit.xml for hdpi device(s)");
1070 }
1071 }
1072 }
1073 // xhdpi display (320 dpi)
1074 else if (Navit.metrics.densityDpi >= 320)
1075 {
1076 Log.e("Navit", "found xhdpi device, this is not fully supported!!");
1077 Log.e("Navit", "using hdpi values");
1078 my_display_density = "hdpi";
1079 if (xmlconfig_unpack_file)
1080 {
1081 if (!extractRes("navithdpi", NAVIT_DATA_DIR + "/share/navit.xml"))
1082 {
1083 Log.e("Navit", "Failed to extract navit.xml for xhdpi device(s)");
1084 }
1085 }
1086 }
1087 else
1088 {
1089 /* default, meaning we just dont know what display this is */
1090 if (xmlconfig_unpack_file)
1091 {
1092 if (!extractRes("navitmdpi", NAVIT_DATA_DIR + "/share/navit.xml"))
1093 {
1094 Log.e("Navit", "Failed to extract navit.xml (default version)");
1095 }
1096 }
1097 }
1098 // Debug.startMethodTracing("calc");
1099
1100 // if (unsupported)
1101 // {
1102 // class CustomListener implements View.OnClickListener
1103 // {
1104 // private final Dialog dialog;
1105 //
1106 // public CustomListener(Dialog dialog)
1107 // {
1108 // this.dialog = dialog;
1109 // }
1110 //
1111 // @Override
1112 // public void onClick(View v)
1113 // {
1114 //
1115 // // Do whatever you want here
1116 //
1117 // // If tou want to close the dialog, uncomment the line below
1118 // //dialog.dismiss();
1119 // }
1120 // }
1121 //
1122 // AlertDialog.Builder dialog = new AlertDialog.Builder(this);
1123 // dialog.setTitle(Navit.get_text("WeltBild Tablet")); //TRANS
1124 // dialog.setCancelable(false);
1125 // dialog.setMessage("Your device is not supported!");
1126 // dialog.show();
1127 // //Button theButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
1128 // //theButton.setOnClickListener(new CustomListener(dialog));
1129 // }
1130
1131 // --> dont use!! NavitMain(this, langu, android.os.Build.VERSION.SDK_INT);
1132 Log.e("Navit", "android.os.Build.VERSION.SDK_INT=" + Integer.valueOf(android.os.Build.VERSION.SDK));
1133 NavitMain(this, langu, Integer.valueOf(android.os.Build.VERSION.SDK), my_display_density);
1134 // CAUTION: don't use android.os.Build.VERSION.SDK_INT if <uses-sdk android:minSdkVersion="3" />
1135 // You will get exception on all devices with Android 1.5 and lower
1136 // because Build.VERSION.SDK_INT is since SDK 4 (Donut 1.6)
1137
1138 // (see: http://developer.android.com/guide/appendix/api-levels.html)
1139 // Platform Version API Level
1140 // =============================================
1141 // Android 4.0.3 15
1142 // Android 4.0, 4.0.1, 4.0.2 14
1143 // Android 3.2 13
1144 // Android 3.1 12
1145 // Android 3.0 11
1146 // Android 2.3.3 10
1147 // Android 2.3.1 9
1148 // Android 2.2 8
1149 // Android 2.1 7
1150 // Android 2.0.1 6
1151 // Android 2.0 5
1152 // Android 1.6 4
1153 // Android 1.5 3
1154 // Android 1.1 2
1155 // Android 1.0 1
1156
1157 NavitActivity(3);
1158
1159 Navit.mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
1160
1161 getPrefs();
1162 activatePrefs();
1163
1164 // unpack some localized Strings
1165 // a test now, later we will unpack all needed strings for java, here at this point!!
1166 //String x = NavitGraphics.getLocalizedString("Austria");
1167 //Log.e("Navit", "x=" + x);
1168 Navit.show_mem_used();
1169
1170 /*
1171 * GpsStatus.Listener listener = new GpsStatus.Listener()
1172 * {
1173 * public void onGpsStatusChanged(int event)
1174 * {
1175 * //System.out.println("xxxxx");
1176 * if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS)
1177 * {
1178 * }
1179 * }
1180 * };
1181 */
1182 }
1183
1184 // private void setOnKeyListener(OnKeyListener onKeyListener)
1185 // {
1186 //
1187 // }
1188
1189 public static void show_mem_used() // wrapper
1190 {
1191 try
1192 {
1193 Message msg = Navit_progress_h.obtainMessage();
1194 Bundle b = new Bundle();
1195 msg.what = 14;
1196 msg.setData(b);
1197 Navit_progress_h.sendMessage(msg);
1198 }
1199 catch (Exception e)
1200 {
1201 e.printStackTrace();
1202 }
1203 }
1204
1205 public static void show_mem_used_real()
1206 {
1207 try
1208 {
1209 int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
1210 String usedMegsString = String.format("Memory Used: %d MB", usedMegs);
1211 // System.out.println("" + usedMegsString);
1212 Navit.set_debug_messages2(usedMegsString);
1213 }
1214 catch (Exception e)
1215 {
1216 e.printStackTrace();
1217 }
1218 }
1219
1220 public static void set_debug_messages(String texta, String textb, String textc)
1221 {
1222 try
1223 {
1224 NavitGraphics.debug_line_1 = texta;
1225 NavitGraphics.debug_line_2 = textb;
1226 NavitGraphics.debug_line_3 = textc;
1227 NavitGraphics.NavitMsgTv_.setMaxLines(3);
1228 NavitGraphics.NavitMsgTv_.setLines(3);
1229 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3);
1230 NavitGraphics.NavitMsgTv_.invalidate();
1231 }
1232 catch (Exception e)
1233 {
1234 e.printStackTrace();
1235 }
1236 }
1237
1238 public static void set_debug_messages1(String text)
1239 {
1240 try
1241 {
1242 NavitGraphics.debug_line_1 = text;
1243 NavitGraphics.NavitMsgTv_.setMaxLines(3);
1244 NavitGraphics.NavitMsgTv_.setLines(3);
1245 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3);
1246 NavitGraphics.NavitMsgTv_.invalidate();
1247 }
1248 catch (Exception e)
1249 {
1250 e.printStackTrace();
1251 }
1252 }
1253
1254 public static void set_debug_messages2(String text)
1255 {
1256 try
1257 {
1258 NavitGraphics.debug_line_2 = text;
1259 NavitGraphics.NavitMsgTv_.setMaxLines(3);
1260 NavitGraphics.NavitMsgTv_.setLines(3);
1261 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3);
1262 NavitGraphics.NavitMsgTv_.invalidate();
1263 }
1264 catch (Exception e)
1265 {
1266 e.printStackTrace();
1267 }
1268 }
1269
1270 public static void set_debug_messages3(String text)
1271 {
1272 try
1273 {
1274 NavitGraphics.debug_line_3 = text;
1275 NavitGraphics.NavitMsgTv_.setMaxLines(3);
1276 NavitGraphics.NavitMsgTv_.setLines(3);
1277 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3);
1278 NavitGraphics.NavitMsgTv_.invalidate();
1279 }
1280 catch (Exception e)
1281 {
1282 e.printStackTrace();
1283 }
1284 }
1285
1286 public static void set_debug_messages3_wrapper(String text)
1287 {
1288 try
1289 {
1290 Message msg = Navit_progress_h.obtainMessage();
1291 Bundle b = new Bundle();
1292 msg.what = 15;
1293 b.putString("text", text);
1294 msg.setData(b);
1295 Navit_progress_h.sendMessage(msg);
1296 }
1297 catch (Exception e)
1298 {
1299 e.printStackTrace();
1300 }
1301 }
1302
1303 @Override
1304 public void onStart()
1305 {
1306 Navit.show_mem_used();
1307
1308 System.gc();
1309 super.onStart();
1310 Log.e("Navit", "OnStart");
1311 NavitActivity(2);
1312
1313 getPrefs();
1314 activatePrefs();
1315 // activate gps AFTER 3g-location
1316 NavitVehicle.turn_on_precise_provider();
1317
1318 Navit.show_mem_used();
1319
1320 // restore points
1321 read_map_points();
1322 }
1323
1324 @Override
1325 public void onRestart()
1326 {
1327 super.onRestart();
1328 Log.e("Navit", "OnRestart");
1329 NavitActivity(0);
1330 }
1331
1332 @Override
1333 public void onResume()
1334 {
1335 // System.gc();
1336 super.onResume();
1337
1338 Log.e("Navit", "OnResume");
1339 //InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
1340 NavitActivity(1);
1341
1342 //Intent caller = this.getIntent();
1343 //System.out.println("A=" + caller.getAction() + " D=" + caller.getDataString());
1344 //System.out.println("C=" + caller.getComponent().flattenToString());
1345
1346 if (unsupported)
1347 {
1348 class CustomListener implements View.OnClickListener
1349 {
1350 private final Dialog dialog;
1351
1352 public CustomListener(Dialog dialog)
1353 {
1354 this.dialog = dialog;
1355 }
1356
1357 @Override
1358 public void onClick(View v)
1359 {
1360
1361 // Do whatever you want here
1362
1363 // If tou want to close the dialog, uncomment the line below
1364 //dialog.dismiss();
1365 }
1366 }
1367
1368 AlertDialog.Builder dialog = new AlertDialog.Builder(this);
1369 dialog.setTitle("WeltBild Tablet");
1370 dialog.setCancelable(false);
1371 dialog.setMessage("Your device is not supported!");
1372 dialog.show();
1373 //Button theButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
1374 //theButton.setOnClickListener(new CustomListener(dialog));
1375 }
1376
1377 if (Navit_maps_loaded == false)
1378 {
1379 Navit_maps_loaded = true;
1380 // activate all maps
1381 Log.e("Navit", "**** LOAD ALL MAPS **** start");
1382 Message msg3 = new Message();
1383 Bundle b3 = new Bundle();
1384 b3.putInt("Callback", 20);
1385 msg3.setData(b3);
1386 N_NavitGraphics.callback_handler.sendMessage(msg3);
1387 Log.e("Navit", "**** LOAD ALL MAPS **** end");
1388 }
1389
1390 String intent_data = null;
1391 if (startup_intent != null)
1392 {
1393 if (System.currentTimeMillis() <= Navit.startup_intent_timestamp + 4000L)
1394 {
1395 Log.e("Navit", "**2**A " + startup_intent.getAction());
1396 Log.e("Navit", "**2**D " + startup_intent.getDataString());
1397 intent_data = startup_intent.getDataString();
1398 }
1399 else
1400 {
1401 Log.e("Navit", "timestamp for navigate_to expired! not using data");
1402 }
1403 }
1404
1405 if ((intent_data != null) && (intent_data.substring(0, 18).equals("google.navigation:")))
1406 {
1407 // better use regex later, but for now to test this feature its ok :-)
1408 // better use regex later, but for now to test this feature its ok :-)
1409
1410 // d: google.navigation:q=blabla-strasse # (this happens when you are offline, or from contacts)
1411 // b: google.navigation:q=48.25676,16.643
1412 // a: google.navigation:ll=48.25676,16.643&q=blabla-strasse
1413 // e: google.navigation:ll=48.25676,16.643&title=blabla-strasse
1414 // sample: -> google.navigation:ll=48.026096,16.023993&title=N%C3%B6stach+43%2C+2571+N%C3%B6stach&entry=w
1415 // -> google.navigation:ll=48.014413,16.005579&title=Hainfelder+Stra%C3%9Fe+44%2C+2571%2C+Austria&entry=w
1416 // f: google.navigation:ll=48.25676,16.643&...
1417 // c: google.navigation:ll=48.25676,16.643
1418
1419 String lat;
1420 String lon;
1421 String q;
1422
1423 String temp1 = null;
1424 String temp2 = null;
1425 String temp3 = null;
1426 boolean parsable = false;
1427 boolean unparsable_info_box = true;
1428 try
1429 {
1430 intent_data = java.net.URLDecoder.decode(intent_data, "UTF-8");
1431 }
1432 catch (Exception e1)
1433 {
1434 e1.printStackTrace();
1435 }
1436
1437 // DEBUG
1438 // DEBUG
1439 // DEBUG
1440 // intent_data = "google.navigation:q=Wien Burggasse 27";
1441 // intent_data = "google.navigation:q=48.25676,16.643";
1442 // intent_data = "google.navigation:ll=48.25676,16.643&q=blabla-strasse";
1443 // intent_data = "google.navigation:ll=48.25676,16.643";
1444 // DEBUG
1445 // DEBUG
1446 // DEBUG
1447
1448 try
1449 {
1450 Log.e("Navit", "found DEBUG 1: " + intent_data.substring(0, 20));
1451 Log.e("Navit", "found DEBUG 2: " + intent_data.substring(20, 22));
1452 Log.e("Navit", "found DEBUG 3: " + intent_data.substring(20, 21));
1453 Log.e("Navit", "found DEBUG 4: " + intent_data.split("&").length);
1454 Log.e("Navit", "found DEBUG 4.1: yy" + intent_data.split("&")[1].substring(0, 1).toLowerCase() + "yy");
1455 Log.e("Navit", "found DEBUG 5: xx" + intent_data.split("&")[1] + "xx");
1456 }
1457 catch (Exception e)
1458 {
1459 e.printStackTrace();
1460 }
1461
1462 if (!Navit.NavitStartupAlreadySearching)
1463 {
1464 if (intent_data.length() > 19)
1465 {
1466 // if d: then start target search
1467 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]"))))
1468 {
1469 Log.e("Navit", "target found (d): " + intent_data.split("q=", -1)[1]);
1470 Navit.NavitStartupAlreadySearching = true;
1471 start_targetsearch_from_intent(intent_data.split("q=", -1)[1]);
1472 // dont use this here, already starting search, so set to "false"
1473 parsable = false;
1474 unparsable_info_box = false;
1475 }
1476 // if b: then remodel the input string to look like a:
1477 else if (intent_data.substring(0, 20).equals("google.navigation:q="))
1478 {
1479 intent_data = "ll=" + intent_data.split("q=", -1)[1] + "&q=Target";
1480 Log.e("Navit", "target found (b): " + intent_data);
1481 parsable = true;
1482 }
1483 // if e: then remodel the input string to look like a:
1484 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")))
1485 {
1486 int idx = intent_data.indexOf("&");
1487 intent_data = intent_data.substring(0, idx) + "&q=Target";
1488 Log.e("Navit", "target found (e): " + intent_data);
1489 parsable = true;
1490 }
1491 // if f: then remodel the input string to look like a:
1492 else if ((intent_data.substring(0, 21).equals("google.navigation:ll=")) && (intent_data.split("&").length > 1))
1493 {
1494 int idx = intent_data.indexOf("&");
1495 intent_data = intent_data.substring(0, idx) + "&q=Target";
1496 Log.e("Navit", "target found (f): " + intent_data);
1497 parsable = true;
1498 }
1499 // already looks like a: just set flag
1500 else if ((intent_data.substring(0, 21).equals("google.navigation:ll=")) && (intent_data.split("&q=").length > 1))
1501 {
1502 // dummy, just set the flag
1503 Log.e("Navit", "target found (a): " + intent_data);
1504 Log.e("Navit", "target found (a): " + intent_data.split("&q=").length);
1505 parsable = true;
1506 }
1507 // if c: then remodel the input string to look like a:
1508 else if ((intent_data.substring(0, 21).equals("google.navigation:ll=")) && (intent_data.split("&q=").length < 2))
1509 {
1510 intent_data = intent_data + "&q=Target";
1511 Log.e("Navit", "target found (c): " + intent_data);
1512 parsable = true;
1513 }
1514 }
1515 }
1516 else
1517 {
1518 Log.e("Navit", "already started search from startup intent");
1519 parsable = false;
1520 unparsable_info_box = false;
1521 }
1522
1523 if (parsable)
1524 {
1525 // now string should be in form --> a:
1526 // now split the parts off
1527 temp1 = intent_data.split("&q=", -1)[0];
1528 try
1529 {
1530 temp3 = temp1.split("ll=", -1)[1];
1531 temp2 = intent_data.split("&q=", -1)[1];
1532 }
1533 catch (Exception e)
1534 {
1535 // java.lang.ArrayIndexOutOfBoundsException most likely
1536 // so let's assume we dont have '&q=xxxx'
1537 temp3 = temp1;
1538 }
1539
1540 if (temp2 == null)
1541 {
1542 // use some default name
1543 temp2 = "Target";
1544 }
1545
1546 lat = temp3.split(",", -1)[0];
1547 lon = temp3.split(",", -1)[1];
1548 q = temp2;
1549 // is the "search name" url-encoded? i think so, lets url-decode it here
1550 q = URLDecoder.decode(q);
1551 // System.out.println();
1552
1553 Navit.remember_destination(q, lat, lon);
1554 Navit.destination_set();
1555
1556 Message msg = new Message();
1557 Bundle b = new Bundle();
1558 b.putInt("Callback", 3);
1559 b.putString("lat", lat);
1560 b.putString("lon", lon);
1561 b.putString("q", q);
1562 msg.setData(b);
1563 N_NavitGraphics.callback_handler.sendMessage(msg);
1564
1565 // zoom_to_route();
1566 try
1567 {
1568 Thread.sleep(400);
1569 }
1570 catch (InterruptedException e)
1571 {
1572 }
1573
1574 try
1575 {
1576 show_geo_on_screen(Float.parseFloat(lat), Float.parseFloat(lon));
1577 }
1578 catch (Exception e2)
1579 {
1580 e2.printStackTrace();
1581 }
1582
1583 try
1584 {
1585 Navit.follow_button_on();
1586 }
1587 catch (Exception e2)
1588 {
1589 e2.printStackTrace();
1590 }
1591 }
1592 else
1593 {
1594 if (unparsable_info_box && !searchBoxShown)
1595 {
1596 try
1597 {
1598 searchBoxShown = true;
1599 String searchString = intent_data.split("q=")[1];
1600 searchString = searchString.split("&")[0];
1601 searchString = URLDecoder.decode(searchString); // decode the URL: e.g. %20 -> space
1602 Log.e("Navit", "Search String :" + searchString);
1603 executeSearch(searchString);
1604 }
1605 catch (Exception e)
1606 {
1607 // safety net
1608 try
1609 {
1610 Log.e("Navit", "problem with startup search 7 str=" + intent_data);
1611 }
1612 catch (Exception e2)
1613 {
1614 e2.printStackTrace();
1615 }
1616 }
1617 }
1618 }
1619 }
1620 else if ((intent_data != null) && (intent_data.substring(0, 10).equals("geo:0,0?q=")))
1621 {
1622 // g: geo:0,0?q=wien%20burggasse
1623
1624 boolean parsable = false;
1625 boolean unparsable_info_box = true;
1626 try
1627 {
1628 intent_data = java.net.URLDecoder.decode(intent_data, "UTF-8");
1629 }
1630 catch (Exception e1)
1631 {
1632 e1.printStackTrace();
1633 }
1634
1635 if (!Navit.NavitStartupAlreadySearching)
1636 {
1637 if (intent_data.length() > 10)
1638 {
1639 // if g: then start target search
1640 Log.e("Navit", "target found (g): " + intent_data.split("q=", -1)[1]);
1641 Navit.NavitStartupAlreadySearching = true;
1642 start_targetsearch_from_intent(intent_data.split("q=", -1)[1]);
1643 // dont use this here, already starting search, so set to "false"
1644 parsable = false;
1645 unparsable_info_box = false;
1646 }
1647 }
1648 else
1649 {
1650 Log.e("Navit", "already started search from startup intent");
1651 parsable = false;
1652 unparsable_info_box = false;
1653 }
1654
1655 if (unparsable_info_box && !searchBoxShown)
1656 {
1657 try
1658 {
1659 searchBoxShown = true;
1660 String searchString = intent_data.split("q=")[1];
1661 searchString = searchString.split("&")[0];
1662 searchString = URLDecoder.decode(searchString); // decode the URL: e.g. %20 -> space
1663 Log.e("Navit", "Search String :" + searchString);
1664 executeSearch(searchString);
1665 }
1666 catch (Exception e)
1667 {
1668 // safety net
1669 try
1670 {
1671 Log.e("Navit", "problem with startup search 88 str=" + intent_data);
1672 }
1673 catch (Exception e2)
1674 {
1675 e2.printStackTrace();
1676 }
1677 }
1678 }
1679
1680 }
1681
1682 getPrefs();
1683 activatePrefs();
1684 // activate gps AFTER 3g-location
1685 NavitVehicle.turn_on_precise_provider();
1686 NavitVehicle.set_last_known_pos_fast_provider();
1687
1688 try
1689 {
1690 //Simulate = new SimGPS(NavitVehicle.vehicle_handler_);
1691 //Simulate.start();
1692 }
1693 catch (Exception e)
1694 {
1695 e.printStackTrace();
1696 }
1697
1698 try
1699 {
1700 watchmem = new WatchMem();
1701 watchmem.start();
1702 }
1703 catch (Exception e)
1704 {
1705 e.printStackTrace();
1706 }
1707 }
1708
1709 @Override
1710 public void onPause()
1711 {
1712 try
1713 {
1714 setPrefs_zoomlevel();
1715 }
1716 catch (Exception e)
1717 {
1718 e.printStackTrace();
1719 }
1720
1721 try
1722 {
1723 watchmem.stop_me();
1724 }
1725 catch (Exception e)
1726 {
1727 e.printStackTrace();
1728 }
1729
1730 try
1731 {
1732 //watchmem.join();
1733 }
1734 catch (Exception e)
1735 {
1736 e.printStackTrace();
1737 }
1738
1739 try
1740 {
1741 //Simulate.stop_me();
1742 }
1743 catch (Exception e)
1744 {
1745 e.printStackTrace();
1746 }
1747
1748 try
1749 {
1750 //Simulate.join();
1751 }
1752 catch (Exception e)
1753 {
1754 e.printStackTrace();
1755 }
1756
1757 Navit.show_mem_used();
1758
1759 super.onPause();
1760
1761 turn_off_compass();
1762
1763 Log.e("Navit", "OnPause");
1764 NavitActivity(-1);
1765
1766 Navit.show_mem_used();
1767 }
1768
1769 @Override
1770 public void onStop()
1771 {
1772 super.onStop();
1773 Log.e("Navit", "OnStop");
1774
1775 NavitVehicle.turn_off_all_providers();
1776
1777 NavitActivity(-2);
1778 System.gc();
1779 Navit.show_mem_used();
1780
1781 // save points
1782 write_map_points();
1783 }
1784
1785 @Override
1786 public void onDestroy()
1787 {
1788 super.onDestroy();
1789 Log.e("Navit", "OnDestroy");
1790 NavitActivity(-3);
1791 System.gc();
1792 Navit.show_mem_used();
1793 }
1794
1795 public void setActivityResult(int requestCode, NavitActivityResult ActivityResult)
1796 {
1797 Log.e("Navit", "setActivityResult " + requestCode);
1798 ActivityResults[requestCode] = ActivityResult;
1799 }
1800
1801 @Override
1802 public boolean onCreateOptionsMenu(Menu menu)
1803 {
1804 super.onCreateOptionsMenu(menu);
1805 //Log.e("Navit","onCreateOptionsMenu");
1806 return true;
1807 }
1808
1809 @Override
1810 public boolean onPrepareOptionsMenu(Menu menu)
1811 {
1812 super.onPrepareOptionsMenu(menu);
1813 //Log.e("Navit","onPrepareOptionsMenu");
1814 // this gets called every time the menu is opened!!
1815 // change menu items here!
1816 menu.clear();
1817
1818 // group-id,item-id,sort order number
1819 // menu.add(1, 1, 100, get_text("zoom in")); //leave out
1820 // menu.add(1, 2, 200, get_text("zoom out")); //leave out
1821
1822 menu.add(1, 6, 300, get_text("address search (online)")); //TRANS
1823 menu.add(1, 7, 310, get_text("address search (offline)")); //TRANS
1824 if (NavitGraphics.CallbackDestinationValid2() > 0)
1825 {
1826 menu.add(1, 9, 450, get_text("Stop Navigation")); //TRANS
1827 menu.add(1, 11, 455, get_text("Zoom to Route")); //TRANS
1828 //. TRANSLATORS: it means: "show current target in google maps"
1829 //. TRANSLATORS: please keep this text short, to fit in the android menu!
1830 menu.add(1, 15, 457, get_text("Target in gmaps")); //TRANS
1831 }
1832 //. TRANSLATORS: text to translate is: exit ZANavi
1833 menu.add(1, 99, 480, get_text("exit navit")); //TRANS
1834 menu.add(1, 5, 485, get_text("toggle POI")); //TRANS
1835 menu.add(1, 10, 490, get_text("Settings")); //TRANS
1836
1837 if (Navit_Announcer == true)
1838 {
1839 menu.add(1, 12, 496, get_text("Announcer Off")); //TRANS
1840 }
1841 else
1842 {
1843 menu.add(1, 13, 495, get_text("Announcer On")); //TRANS
1844 }
1845
1846 menu.add(1, 14, 498, get_text("Recent destinations")); //TRANS
1847 menu.add(1, 3, 500, get_text("download maps")); //TRANS
1848 menu.add(1, 8, 505, get_text("delete maps")); //TRANS
1849
1850 if (PREF_enable_debug_functions)
1851 {
1852 menu.add(1, 88, 9001, "--");
1853 menu.add(1, 601, 9001, get_text("Demo Vehicle")); //TRANS
1854 menu.add(1, 602, 9002, get_text("Speech Texts")); //TRANS
1855 menu.add(1, 603, 9003, get_text("Nav. Commands")); //TRANS
1856 }
1857
1858 menu.add(1, 88, 11000, "--");
1859 menu.add(1, 16, 11001, get_text("online Help")); //TRANS
1860
1861 // menu.add(1, 88, 800, "--");
1862 return true;
1863 }
1864
1865 // define graphics here
1866 public static NavitGraphics N_NavitGraphics = null;
1867
1868 // callback id gets set here when called from NavitGraphics
1869 public static void setKeypressCallback(int kp_cb_id, NavitGraphics ng)
1870 {
1871 //Log.e("Navit", "setKeypressCallback -> id1=" + kp_cb_id);
1872 //Log.e("Navit", "setKeypressCallback -> ng=" + String.valueOf(ng));
1873 //N_KeypressCallbackID = kp_cb_id;
1874 N_NavitGraphics = ng;
1875 }
1876
1877 public static void setMotionCallback(int mo_cb_id, NavitGraphics ng)
1878 {
1879 //Log.e("Navit", "setKeypressCallback -> id2=" + mo_cb_id);
1880 //Log.e("Navit", "setKeypressCallback -> ng=" + String.valueOf(ng));
1881 //N_MotionCallbackID = mo_cb_id;
1882 N_NavitGraphics = ng;
1883 }
1884
1885 //public native void KeypressCallback(int id, String s);
1886
1887 public void start_targetsearch_from_intent(String target_address)
1888 {
1889 Navit_last_address_partial_match = false;
1890 Navit_last_address_search_string = target_address;
1891
1892 // ----------- CONFIG ---------
1893 // ----------- CONFIG ---------
1894 // ----------- CONFIG ---------
1895 Boolean use_online_searchmode_here = false;
1896 Boolean hide_duplicates_searchmode_here = false;
1897 // ----------- CONFIG ---------
1898 // ----------- CONFIG ---------
1899 // ----------- CONFIG ---------
1900
1901 int dialog_num_;
1902
1903 if (use_online_searchmode_here)
1904 {
1905 dialog_num_ = Navit.SEARCHRESULTS_WAIT_DIALOG;
1906 }
1907 else
1908 {
1909 dialog_num_ = Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE;
1910 }
1911
1912 // clear results
1913 Navit.NavitAddressResultList_foundItems.clear();
1914 Navit.Navit_Address_Result_double_index.clear();
1915 Navit.NavitSearchresultBarIndex = -1;
1916 Navit.NavitSearchresultBar_title = "";
1917 Navit.NavitSearchresultBar_text = "";
1918
1919 if (Navit_last_address_search_string.equals(""))
1920 {
1921 // empty search string entered
1922 Toast.makeText(getApplicationContext(), Navit.get_text("No address found"), Toast.LENGTH_LONG).show(); //TRANS
1923 }
1924 else
1925 {
1926 // show dialog
1927 try
1928 {
1929 Log.e("Navit", "call-11: (0)num " + dialog_num_);
1930 }
1931 catch (Exception e)
1932 {
1933 e.printStackTrace();
1934 }
1935
1936 if (hide_duplicates_searchmode_here)
1937 {
1938 // hide duplicates when searching
1939 // hide duplicates when searching
1940 Message msg22 = new Message();
1941 Bundle b22 = new Bundle();
1942 b22.putInt("Callback", 45);
1943 msg22.setData(b22);
1944 N_NavitGraphics.callback_handler.sendMessage(msg22);
1945 // hide duplicates when searching
1946 // hide duplicates when searching
1947 }
1948
1949 Message msg = progress_handler.obtainMessage();
1950 Bundle b = new Bundle();
1951 msg.what = 11;
1952 b.putInt("dialog_num", dialog_num_);
1953 msg.setData(b);
1954 progress_handler.sendMessage(msg);
1955 }
1956 }
1957
1958 @Override
1959 public boolean onOptionsItemSelected(MenuItem item)
1960 {
1961 // Handle item selection
1962 switch (item.getItemId())
1963 {
1964 case 1:
1965 // zoom in
1966 Message msg = new Message();
1967 Bundle b = new Bundle();
1968 b.putInt("Callback", 1);
1969 msg.setData(b);
1970 N_NavitGraphics.callback_handler.sendMessage(msg);
1971 // if we zoom, hide the bubble
1972 if (N_NavitGraphics.NavitAOverlay != null)
1973 {
1974 N_NavitGraphics.NavitAOverlay.hide_bubble();
1975 }
1976 Log.e("Navit", "onOptionsItemSelected -> zoom in");
1977 break;
1978 case 2:
1979 // zoom out
1980 msg = new Message();
1981 b = new Bundle();
1982 b.putInt("Callback", 2);
1983 msg.setData(b);
1984 N_NavitGraphics.callback_handler.sendMessage(msg);
1985 // if we zoom, hide the bubble
1986 if (N_NavitGraphics.NavitAOverlay != null)
1987 {
1988 N_NavitGraphics.NavitAOverlay.hide_bubble();
1989 }
1990 Log.e("Navit", "onOptionsItemSelected -> zoom out");
1991 break;
1992 case 3:
1993 // map download menu
1994 Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class);
1995 this.startActivityForResult(map_download_list_activity, Navit.NavitDownloaderPriSelectMap_id);
1996 break;
1997 case 5:
1998 // GeoCoordEnterDialog
1999 // DEBUG - // Intent it001 = new Intent(this, GeoCoordEnterDialog.class);
2000 // DEBUG - // this.startActivityForResult(it001, Navit.NavitGeoCoordEnter_id);
2001
2002 // toggle the normal POI layers (to avoid double POIs)
2003 msg = new Message();
2004 b = new Bundle();
2005 b.putInt("Callback", 5);
2006 b.putString("cmd", "toggle_layer(\"POI Symbols\");");
2007 msg.setData(b);
2008 N_NavitGraphics.callback_handler.sendMessage(msg);
2009 // toggle full POI icons on/off
2010 msg = new Message();
2011 b = new Bundle();
2012 b.putInt("Callback", 5);
2013 b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");");
2014 msg.setData(b);
2015 N_NavitGraphics.callback_handler.sendMessage(msg);
2016 break;
2017 case 6:
2018 // ok startup address search activity (online google maps search)
2019 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
2020 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
2021 search_intent.putExtra("address_string", Navit_last_address_search_string);
2022 search_intent.putExtra("type", "online");
2023 String pm_temp = "0";
2024 if (Navit_last_address_partial_match)
2025 {
2026 pm_temp = "1";
2027 }
2028 search_intent.putExtra("partial_match", pm_temp);
2029 this.startActivityForResult(search_intent, NavitAddressSearch_id_online);
2030 break;
2031 case 7:
2032 // ok startup address search activity (offline binfile search)
2033 Intent search_intent2 = new Intent(this, NavitAddressSearchActivity.class);
2034 search_intent2.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
2035 search_intent2.putExtra("address_string", Navit_last_address_search_string);
2036 search_intent2.putExtra("type", "offline");
2037 search_intent2.putExtra("search_country_id", Navit_last_address_search_country_id);
2038
2039 String pm_temp2 = "0";
2040 if (Navit_last_address_partial_match)
2041 {
2042 pm_temp2 = "1";
2043 }
2044
2045 search_intent2.putExtra("partial_match", pm_temp2);
2046 this.startActivityForResult(search_intent2, NavitAddressSearch_id_offline);
2047 break;
2048 case 8:
2049 // map delete menu
2050 Intent map_delete_list_activity2 = new Intent(this, NavitDeleteSelectMapActivity.class);
2051 this.startActivityForResult(map_delete_list_activity2, Navit.NavitDeleteSecSelectMap_id);
2052 break;
2053 case 9:
2054 // stop navigation (this menu should only appear when navigation is actually on!)
2055 Message msg2 = new Message();
2056 Bundle b2 = new Bundle();
2057 b2.putInt("Callback", 7);
2058 msg2.setData(b2);
2059 N_NavitGraphics.callback_handler.sendMessage(msg2);
2060 break;
2061 case 10:
2062 // open settings menu
2063 Intent settingsActivity = new Intent(getBaseContext(), NavitPreferences.class);
2064 startActivity(settingsActivity);
2065 break;
2066 case 11:
2067 //zoom_to_route
2068 zoom_to_route();
2069 break;
2070 case 12:
2071 // announcer off
2072 Navit_Announcer = false;
2073 msg = new Message();
2074 b = new Bundle();
2075 b.putInt("Callback", 34);
2076 msg.setData(b);
2077 N_NavitGraphics.callback_handler.sendMessage(msg);
2078 break;
2079 case 13:
2080 // announcer on
2081 Navit_Announcer = true;
2082 msg = new Message();
2083 b = new Bundle();
2084 b.putInt("Callback", 35);
2085 msg.setData(b);
2086 N_NavitGraphics.callback_handler.sendMessage(msg);
2087 break;
2088 case 14:
2089 // show recent destination list
2090 Intent i2 = new Intent(this, NavitRecentDestinationActivity.class);
2091 this.startActivityForResult(i2, Navit.NavitRecentDest_id);
2092 break;
2093 case 15:
2094 // show current target on googlemaps
2095 String current_target_string = NavitGraphics.CallbackGeoCalc(4, 1, 1);
2096 // Log.e("Navit", "got target 1: "+current_target_string);
2097 if (current_target_string.equals("x:x"))
2098 {
2099 Log.e("Navit", "no target set!");
2100 }
2101 else
2102 {
2103 try
2104 {
2105 String tmp[] = current_target_string.split(":", 2);
2106 googlemaps_show(tmp[0], tmp[1], "ZANavi Target");
2107 }
2108 catch (Exception e)
2109 {
2110 e.printStackTrace();
2111 Log.e("Navit", "problem with target!");
2112 }
2113 }
2114 break;
2115 case 16:
2116 // show online manual
2117 Log.e("Navit", "user wants online help, show the website lang=" + NavitTextTranslations.main_language.toLowerCase());
2118 // URL to ZANavi Manual (in english language)
2119 String url = "http://zanavi.cc/index.php/Manual";
2120 if (NavitTextTranslations.main_language.toLowerCase().equals("de"))
2121 {
2122 // show german manual
2123 url = "http://zanavi.cc/index.php/Manual/de";
2124 }
2125
2126 Intent i = new Intent(Intent.ACTION_VIEW);
2127 i.setData(Uri.parse(url));
2128 startActivity(i);
2129 break;
2130 case 88:
2131 // dummy entry, just to make "breaks" in the menu
2132 break;
2133 case 601:
2134 // DEBUG: activate demo vehicle and set position to position 20px-x, 20px-y on screen
2135
2136 Navit.DemoVehicle = true;
2137
2138 msg = new Message();
2139 b = new Bundle();
2140 b.putInt("Callback", 52);
2141 msg.setData(b);
2142 N_NavitGraphics.callback_handler.sendMessage(msg);
2143
2144 msg = new Message();
2145 b = new Bundle();
2146 b.putInt("Callback", 51);
2147 b.putInt("x", 20);
2148 b.putInt("y", 20);
2149 msg.setData(b);
2150 N_NavitGraphics.callback_handler.sendMessage(msg);
2151
2152 break;
2153 case 602:
2154 // DEBUG: toggle textview with spoken and translated string (to help with translation)
2155 try
2156 {
2157 if (NavitGraphics.NavitMsgTv2_.getVisibility() == View.VISIBLE)
2158 {
2159 NavitGraphics.NavitMsgTv2_.setVisibility(View.GONE);
2160 NavitGraphics.NavitMsgTv2_.setEnabled(false);
2161 }
2162 else
2163 {
2164 NavitGraphics.NavitMsgTv2_.setVisibility(View.VISIBLE);
2165 NavitGraphics.NavitMsgTv2_.setEnabled(true);
2166 }
2167 }
2168 catch (Exception e)
2169 {
2170 e.printStackTrace();
2171 }
2172 break;
2173 case 603:
2174 // DEBUG: show all possible navigation commands (also translated)
2175 NavitGraphics.generate_all_speech_commands();
2176 break;
2177 case 99:
2178 // exit
2179 this.onStop();
2180 this.exit();
2181 //msg = new Message();
2182 //b = new Bundle();
2183 //b.putInt("Callback", 5);
2184 //b.putString("cmd", "quit();");
2185 //msg.setData(b);
2186 //N_NavitGraphics.callback_handler.sendMessage(msg);
2187 break;
2188 }
2189 return true;
2190 }
2191
2192 private class PickerListener implements NumberPicker.ValueChangeListener
2193 {
2194 @Override
2195 public void onNumberPickerValueChange(NumberPicker picker, int value)
2196 {
2197 //if (picker.getId() == R.id.SpinRate)
2198 //{
2199 // mBeatsPerMin = value;
2200 //}
2201 return;
2202 }
2203 }
2204
2205 protected void onActivityResult(int requestCode, int resultCode, Intent data)
2206 {
2207 Log.e("Navit", "onActivityResult");
2208 switch (requestCode)
2209 {
2210 case Navit.NavitDeleteSecSelectMap_id:
2211 try
2212 {
2213 if (resultCode == Activity.RESULT_OK)
2214 {
2215 // remove all sdcard maps
2216 Message msg = new Message();
2217 Bundle b = new Bundle();
2218 b.putInt("Callback", 19);
2219 msg.setData(b);
2220 N_NavitGraphics.callback_handler.sendMessage(msg);
2221
2222 Log.d("Navit", "delete map id=" + Integer.parseInt(data.getStringExtra("selected_id")));
2223 String map_full_line = NavitMapDownloader.OSM_MAP_NAME_ondisk_ORIG_LIST[Integer.parseInt(data.getStringExtra("selected_id"))];
2224 Log.d("Navit", "delete map full line=" + map_full_line);
2225
2226 String del_map_name = MAP_FILENAME_PATH + map_full_line.split(":", 2)[0];
2227 System.out.println("del map file :" + del_map_name);
2228 // remove from cat file
2229 NavitMapDownloader.remove_from_cat_file(map_full_line);
2230 // remove from disk
2231 File del_map_name_file = new File(del_map_name);
2232 del_map_name_file.delete();
2233 for (int jkl = 1; jkl < 51; jkl++)
2234 {
2235 File del_map_name_fileSplit = new File(del_map_name + "." + String.valueOf(jkl));
2236 del_map_name_fileSplit.delete();
2237 }
2238 // remove also any MD5 files for this map that may be on disk
2239 try
2240 {
2241 String tmp = map_full_line.split(":", 2)[1];
2242 if (!tmp.equals(NavitMapDownloader.MAP_URL_NAME_UNKNOWN))
2243 {
2244 tmp = tmp.replace("*", "");
2245 tmp = tmp.replace("/", "");
2246 tmp = tmp.replace("\\", "");
2247 tmp = tmp.replace(" ", "");
2248 tmp = tmp.replace(">", "");
2249 tmp = tmp.replace("<", "");
2250 System.out.println("removing md5 file:" + Navit.MAPMD5_FILENAME_PATH + tmp + ".md5");
2251 File md5_final_filename = new File(Navit.MAPMD5_FILENAME_PATH + tmp + ".md5");
2252 md5_final_filename.delete();
2253 }
2254 }
2255 catch (Exception e)
2256 {
2257 e.printStackTrace();
2258 }
2259
2260 // remove map, and zoom out
2261 // ***** onStop();
2262 // ***** onCreate(getIntent().getExtras());
2263
2264 // add all sdcard maps
2265 msg = new Message();
2266 b = new Bundle();
2267 b.putInt("Callback", 20);
2268 msg.setData(b);
2269 N_NavitGraphics.callback_handler.sendMessage(msg);
2270
2271 zoom_out_full();
2272 }
2273 }
2274 catch (Exception e)
2275 {
2276 Log.d("Navit", "error on onActivityResult 3");
2277 e.printStackTrace();
2278 }
2279 break;
2280 case Navit.NavitDownloaderPriSelectMap_id:
2281 try
2282 {
2283 if (resultCode == Activity.RESULT_OK)
2284 {
2285 try
2286 {
2287 Log.d("Navit", "PRI id=" + Integer.parseInt(data.getStringExtra("selected_id")));
2288 // set map id to download
2289 Navit.download_map_id = NavitMapDownloader.OSM_MAP_NAME_ORIG_ID_LIST[Integer.parseInt(data.getStringExtra("selected_id"))];
2290 // show the map download progressbar, and download the map
2291 if (Navit.download_map_id > -1)
2292 {
2293 showDialog(Navit.MAPDOWNLOAD_PRI_DIALOG);
2294 }
2295 }
2296 catch (NumberFormatException e)
2297 {
2298 Log.d("Navit", "NumberFormatException selected_id");
2299 }
2300 }
2301 else
2302 {
2303 // user pressed back key
2304 }
2305 }
2306 catch (Exception e)
2307 {
2308 Log.d("Navit", "error on onActivityResult");
2309 e.printStackTrace();
2310 }
2311 break;
2312 case Navit.NavitDownloaderSecSelectMap_id:
2313 try
2314 {
2315 if (resultCode == Activity.RESULT_OK)
2316 {
2317 try
2318 {
2319 Log.d("Navit", "SEC id=" + Integer.parseInt(data.getStringExtra("selected_id")));
2320 // set map id to download
2321 Navit.download_map_id = NavitMapDownloader.OSM_MAP_NAME_ORIG_ID_LIST[Integer.parseInt(data.getStringExtra("selected_id"))];
2322 // show the map download progressbar, and download the map
2323 if (Navit.download_map_id > -1)
2324 {
2325 showDialog(Navit.MAPDOWNLOAD_SEC_DIALOG);
2326 }
2327 }
2328 catch (NumberFormatException e)
2329 {
2330 Log.d("Navit", "NumberFormatException selected_id");
2331 }
2332 }
2333 else
2334 {
2335 // user pressed back key
2336 }
2337 }
2338 catch (Exception e)
2339 {
2340 Log.d("Navit", "error on onActivityResult");
2341 e.printStackTrace();
2342 }
2343 break;
2344 case NavitAddressSearch_id_online:
2345 case NavitAddressSearch_id_offline:
2346 try
2347 {
2348 if (resultCode == Activity.RESULT_OK)
2349 {
2350 try
2351 {
2352 String addr = data.getStringExtra("address_string");
2353 Boolean partial_match = false;
2354 try
2355 {
2356 // only from offline mask!
2357 partial_match = data.getStringExtra("partial_match").equals("1");
2358 }
2359 catch (Exception e)
2360 {
2361 }
2362
2363 Message msg2 = new Message();
2364 Bundle b2 = new Bundle();
2365 b2.putInt("Callback", 44);
2366 msg2.setData(b2);
2367 N_NavitGraphics.callback_handler.sendMessage(msg2);
2368
2369 if (requestCode == NavitAddressSearch_id_offline)
2370 {
2371 try
2372 {
2373 Boolean hide_dup = data.getStringExtra("hide_dup").equals("1");
2374 if (hide_dup)
2375 {
2376 Message msg = new Message();
2377 Bundle b = new Bundle();
2378 b.putInt("Callback", 45);
2379 msg.setData(b);
2380 N_NavitGraphics.callback_handler.sendMessage(msg);
2381 }
2382 }
2383 catch (Exception e)
2384 {
2385 }
2386 }
2387
2388 Navit_last_address_partial_match = partial_match;
2389 Navit_last_address_search_string = addr;
2390
2391 try
2392 {
2393 // only from offline mask!
2394 Navit_last_address_full_file_search = data.getStringExtra("full_file_search").equals("1");
2395 }
2396 catch (Exception e)
2397 {
2398 Navit_last_address_full_file_search = false;
2399 }
2400
2401 try
2402 {
2403 // only from offline mask!
2404 Navit_last_address_search_country_iso2_string = data.getStringExtra("address_country_iso2");
2405 Navit_last_address_search_country_flags = data.getIntExtra("address_country_flags", 3);
2406 // System.out.println("Navit_last_address_search_country_flags=" + Navit_last_address_search_country_flags);
2407 Navit_last_address_search_country_id = data.getIntExtra("search_country_id", 1); // default=*ALL*
2408 PREF_search_country = Navit_last_address_search_country_id;
2409 setPrefs_search_country();
2410 }
2411 catch (Exception e)
2412 {
2413
2414 }
2415
2416 // clear results
2417 Navit.NavitAddressResultList_foundItems.clear();
2418 Navit.Navit_Address_Result_double_index.clear();
2419 Navit.NavitSearchresultBarIndex = -1;
2420 Navit.NavitSearchresultBar_title = "";
2421 Navit.NavitSearchresultBar_text = "";
2422 Navit.search_results_towns = 0;
2423 Navit.search_results_streets = 0;
2424 Navit.search_results_streets_hn = 0;
2425
2426 if (addr.equals(""))
2427 {
2428 // empty search string entered
2429 Toast.makeText(getApplicationContext(), Navit.get_text("No search string entered"), Toast.LENGTH_LONG).show(); //TRANS
2430 }
2431 else
2432 {
2433 if (requestCode == NavitAddressSearch_id_online)
2434 {
2435 // online googlemaps search
2436 try
2437 {
2438 Log.e("Navit", "call-11: (1)num " + Navit.SEARCHRESULTS_WAIT_DIALOG);
2439 }
2440 catch (Exception e)
2441 {
2442 e.printStackTrace();
2443 }
2444
2445 System.out.println("online googlemaps search");
2446 Message msg = progress_handler.obtainMessage();
2447 Bundle b = new Bundle();
2448 msg.what = 11;
2449 b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG);
2450 msg.setData(b);
2451 progress_handler.sendMessage(msg);
2452 }
2453 else if (requestCode == NavitAddressSearch_id_offline)
2454 {
2455 // offline binfile search
2456 try
2457 {
2458 Log.e("Navit", "call-11: (2)num " + Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
2459 }
2460 catch (Exception e)
2461 {
2462 e.printStackTrace();
2463 }
2464
2465 // show dialog, and start search for the results
2466 // make it indirect, to give our activity a chance to startup
2467 // (remember we come straight from another activity and ours is still paused!)
2468 Message msg = progress_handler.obtainMessage();
2469 Bundle b = new Bundle();
2470 msg.what = 11;
2471 b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
2472 msg.setData(b);
2473 progress_handler.sendMessage(msg);
2474 }
2475 }
2476 }
2477 catch (NumberFormatException e)
2478 {
2479 Log.d("Navit", "NumberFormatException selected_id");
2480 }
2481 }
2482 else
2483 {
2484 // user pressed back key
2485 }
2486 }
2487 catch (Exception e)
2488 {
2489 Log.d("Navit", "error on onActivityResult");
2490 e.printStackTrace();
2491 }
2492 break;
2493 case Navit.NavitAddressResultList_id:
2494 try
2495 {
2496 if (resultCode == Activity.RESULT_OK)
2497 {
2498 try
2499 {
2500 if (data.getStringExtra("what").equals("view"))
2501 {
2502 // get the coords for the destination
2503 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
2504
2505 // set nice zoomlevel before we show destination
2506 int zoom_want = Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL;
2507 //
2508 Message msg = new Message();
2509 Bundle b = new Bundle();
2510 b.putInt("Callback", 33);
2511 b.putString("s", Integer.toString(zoom_want));
2512 msg.setData(b);
2513 try
2514 {
2515 N_NavitGraphics.callback_handler.sendMessage(msg);
2516 Navit.GlobalScaleLevel = zoom_want;
2517 }
2518 catch (Exception e)
2519 {
2520 e.printStackTrace();
2521 }
2522 if (PREF_save_zoomlevel)
2523 {
2524 setPrefs_zoomlevel();
2525 }
2526 // set nice zoomlevel before we show destination
2527
2528 try
2529 {
2530 Navit.follow_button_off();
2531 }
2532 catch (Exception e2)
2533 {
2534 e2.printStackTrace();
2535 }
2536
2537 show_geo_on_screen(Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
2538 }
2539 else
2540 {
2541 Log.d("Navit", "adress result list id=" + Integer.parseInt(data.getStringExtra("selected_id")));
2542 // get the coords for the destination
2543 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
2544
2545 // ok now set target
2546 try
2547 {
2548 Navit.remember_destination(Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
2549 // save points
2550 write_map_points();
2551 }
2552 catch (Exception e)
2553 {
2554 e.printStackTrace();
2555 }
2556
2557 if (NavitGraphics.navit_route_status == 0)
2558 {
2559 Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS
2560 Navit.destination_set();
2561
2562 Message msg = new Message();
2563 Bundle b = new Bundle();
2564 b.putInt("Callback", 3);
2565 b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lat));
2566 b.putString("lon", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lon));
2567 b.putString("q", Navit.NavitAddressResultList_foundItems.get(destination_id).addr);
2568 msg.setData(b);
2569 N_NavitGraphics.callback_handler.sendMessage(msg);
2570 }
2571 else
2572 {
2573 Toast.makeText(getApplicationContext(), Navit.get_text("new Waypoint") + "\n" + Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS
2574 Message msg = new Message();
2575 Bundle b = new Bundle();
2576 b.putInt("Callback", 48);
2577 b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lat));
2578 b.putString("lon", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lon));
2579 b.putString("q", Navit.NavitAddressResultList_foundItems.get(destination_id).addr);
2580 msg.setData(b);
2581 N_NavitGraphics.callback_handler.sendMessage(msg);
2582 }
2583
2584 // zoom_to_route();
2585 try
2586 {
2587 Thread.sleep(400);
2588 }
2589 catch (InterruptedException e)
2590 {
2591 }
2592
2593 try
2594 {
2595 Navit.follow_button_on();
2596 }
2597 catch (Exception e2)
2598 {
2599 e2.printStackTrace();
2600 }
2601
2602 show_geo_on_screen(Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
2603 }
2604 }
2605 catch (NumberFormatException e)
2606 {
2607 Log.d("Navit", "NumberFormatException selected_id");
2608 }
2609 catch (Exception e)
2610 {
2611
2612 }
2613 }
2614 else
2615 {
2616 // user pressed back key
2617 }
2618 }
2619 catch (Exception e)
2620 {
2621 Log.d("Navit", "error on onActivityResult");
2622 e.printStackTrace();
2623 }
2624 break;
2625 case NavitAddressSearch_id_gmaps:
2626 try
2627 {
2628 if (resultCode == Activity.RESULT_OK)
2629 {
2630
2631 }
2632 }
2633 catch (Exception e)
2634 {
2635 e.printStackTrace();
2636 }
2637 break;
2638 case NavitGeoCoordEnter_id:
2639 try
2640 {
2641 if (resultCode == Activity.RESULT_OK)
2642 {
2643 // lat lon enter activitiy result
2644 }
2645 }
2646 catch (Exception e)
2647 {
2648 e.printStackTrace();
2649 }
2650 break;
2651 case NavitRecentDest_id:
2652 try
2653 {
2654 if (resultCode == Activity.RESULT_OK)
2655 {
2656 Log.d("Navit", "recent dest id=" + Integer.parseInt(data.getStringExtra("selected_id")));
2657 // get the coords for the destination
2658 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
2659
2660 // ok now set target
2661 String dest_name = Navit.map_points.get(destination_id).point_name;
2662 float lat = Navit.map_points.get(destination_id).lat;
2663 float lon = Navit.map_points.get(destination_id).lon;
2664
2665 if (NavitGraphics.navit_route_status == 0)
2666 {
2667 Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + dest_name, Toast.LENGTH_LONG).show(); //TRANS
2668 Navit.destination_set();
2669
2670 Message msg = new Message();
2671 Bundle b = new Bundle();
2672 b.putInt("Callback", 3);
2673 b.putString("lat", String.valueOf(lat));
2674 b.putString("lon", String.valueOf(lon));
2675 b.putString("q", dest_name);
2676 msg.setData(b);
2677 N_NavitGraphics.callback_handler.sendMessage(msg);
2678 }
2679 else
2680 {
2681 Toast.makeText(getApplicationContext(), Navit.get_text("new Waypoint") + "\n" + dest_name, Toast.LENGTH_LONG).show(); //TRANS
2682 Message msg = new Message();
2683 Bundle b = new Bundle();
2684 b.putInt("Callback", 48);
2685 b.putString("lat", String.valueOf(lat));
2686 b.putString("lon", String.valueOf(lon));
2687 b.putString("q", dest_name);
2688 msg.setData(b);
2689 N_NavitGraphics.callback_handler.sendMessage(msg);
2690 }
2691
2692 // zoom_to_route();
2693 try
2694 {
2695 Thread.sleep(400);
2696 }
2697 catch (InterruptedException e)
2698 {
2699 }
2700
2701 try
2702 {
2703 Navit.follow_button_on();
2704 }
2705 catch (Exception e2)
2706 {
2707 e2.printStackTrace();
2708 }
2709
2710 show_geo_on_screen(lat, lon);
2711
2712 }
2713 }
2714 catch (Exception e)
2715 {
2716 e.printStackTrace();
2717 }
2718 break;
2719 default:
2720 Log.e("Navit", "onActivityResult " + requestCode + " " + resultCode);
2721 try
2722 {
2723 ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data);
2724 }
2725 catch (Exception e)
2726 {
2727 e.printStackTrace();
2728 }
2729 break;
2730 }
2731 Log.e("Navit", "onActivityResult finished");
2732 }
2733
2734 public class WatchMem extends Thread
2735 {
2736 private Boolean running;
2737
2738 WatchMem()
2739 {
2740 this.running = true;
2741 }
2742
2743 public void run()
2744 {
2745 System.out.println("WatchMem -- started --");
2746 while (this.running)
2747 {
2748 Navit.show_mem_used();
2749
2750 try
2751 {
2752 Thread.sleep(5000); // 5 secs.
2753 }
2754 catch (InterruptedException e)
2755 {
2756 }
2757 }
2758 System.out.println("WatchMem -- stopped --");
2759 }
2760
2761 public void stop_me()
2762 {
2763 this.running = false;
2764 }
2765 }
2766
2767 public class SimGPS extends Thread
2768 {
2769 private Boolean running;
2770 private Handler h;
2771
2772 SimGPS(Handler h_)
2773 {
2774 System.out.println("SimGPS -- inited --");
2775 this.h = h_;
2776 this.running = true;
2777 }
2778
2779 public void run()
2780 {
2781 System.out.println("SimGPS -- started --");
2782 while (this.running)
2783 {
2784 float rnd_heading = (float) (Math.random() * 360d);
2785 float lat = 48.216023f;
2786 float lng = 16.391664f;
2787 //Location l = new Location("Network");
2788 //l.setLatitude(lat);
2789 //l.setLongitude(lng);
2790 //l.setBearing(rnd_heading);
2791 // NavitVehicle.set_mock_location__fast(l);
2792 // NavitVehicle.update_compass_heading(rnd_heading);
2793 if (this.h != null)
2794 {
2795 Message msg = this.h.obtainMessage();
2796 Bundle b = new Bundle();
2797 msg.what = 1;
2798 b.putFloat("b", rnd_heading);
2799 b.putFloat("lat", lat);
2800 b.putFloat("lng", lng);
2801 msg.setData(b);
2802 this.h.sendMessage(msg);
2803 }
2804 try
2805 {
2806 Thread.sleep(800);
2807 }
2808 catch (InterruptedException e)
2809 {
2810 }
2811 }
2812 System.out.println("SimGPS -- stopped --");
2813 }
2814
2815 public void stop_me()
2816 {
2817 this.running = false;
2818 }
2819 }
2820
2821 public class SearchResultsThreadSpinnerThread extends Thread
2822 {
2823 int dialog_num;
2824 int spinner_current_value;
2825 private Boolean running;
2826 Handler mHandler;
2827
2828 SearchResultsThreadSpinnerThread(Handler h, int dialog_num)
2829 {
2830 this.dialog_num = dialog_num;
2831 this.mHandler = h;
2832 this.spinner_current_value = 0;
2833
2834 this.running = true;
2835 Log.e("Navit", "SearchResultsThreadSpinnerThread created");
2836 }
2837
2838 public void run()
2839 {
2840 Log.e("Navit", "SearchResultsThreadSpinnerThread started");
2841 while (this.running)
2842 {
2843 if (Navit.NavitAddressSearchSpinnerActive == false)
2844 {
2845 this.running = false;
2846 }
2847 else
2848 {
2849 Message msg = mHandler.obtainMessage();
2850 Bundle b = new Bundle();
2851 msg.what = 10;
2852 b.putInt("dialog_num", this.dialog_num);
2853 b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
2854 b.putInt("cur", this.spinner_current_value % (Navit.ADDRESS_RESULTS_DIALOG_MAX + 1));
2855 if ((Navit.NavitSearchresultBar_title.equals("")) && (Navit.NavitSearchresultBar_text.equals("")))
2856 {
2857 b.putString("title", Navit.get_text("getting search results")); //TRANS
2858 b.putString("text", Navit.get_text("searching ...")); //TRANS
2859 }
2860 else
2861 {
2862 b.putString("title", Navit.NavitSearchresultBar_title);
2863 b.putString("text", Navit.NavitSearchresultBar_text);
2864 }
2865 msg.setData(b);
2866 mHandler.sendMessage(msg);
2867 try
2868 {
2869 Thread.sleep(700);
2870 }
2871 catch (InterruptedException e)
2872 {
2873 // e.printStackTrace();
2874 }
2875 this.spinner_current_value++;
2876 }
2877 }
2878 Log.e("Navit", "SearchResultsThreadSpinnerThread ended");
2879 }
2880 }
2881
2882 public class SearchResultsThread extends Thread
2883 {
2884 private Boolean running;
2885 Handler mHandler;
2886 int my_dialog_num;
2887
2888 SearchResultsThread(Handler h, int dialog_num)
2889 {
2890 this.running = true;
2891 this.mHandler = h;
2892 this.my_dialog_num = dialog_num;
2893 Log.e("Navit", "SearchResultsThread created");
2894 }
2895
2896 public void stop_me()
2897 {
2898 this.running = false;
2899 }
2900
2901 public void run()
2902 {
2903 Log.e("Navit", "SearchResultsThread started");
2904
2905 // initialize the dialog with sane values
2906 Message msg = mHandler.obtainMessage();
2907 Bundle b = new Bundle();
2908 msg.what = 10;
2909 b.putInt("dialog_num", this.my_dialog_num);
2910 b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
2911 b.putInt("cur", 0);
2912 b.putString("title", Navit.get_text("getting search results")); //TRANS
2913 b.putString("text", Navit.get_text("searching ...")); //TRANS
2914 msg.setData(b);
2915 mHandler.sendMessage(msg);
2916
2917 int partial_match_i = 0;
2918 if (Navit_last_address_partial_match)
2919 {
2920 partial_match_i = 1;
2921 }
2922
2923 if (this.my_dialog_num == Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE)
2924 {
2925 // start the search, this could take a long time!!
2926 Log.e("Navit", "SearchResultsThread run1");
2927 // need lowercase to find stuff !!
2928 Navit_last_address_search_string = filter_bad_chars(Navit_last_address_search_string).toLowerCase();
2929 if (Navit_last_address_full_file_search)
2930 {
2931 // flags (18) -> order level to search at
2932 // ================
2933 // 0#0 0 -> search full world
2934 // lat#lon radius -> search only this area, around lat,lon
2935 // ================
2936 N_NavitGraphics.SearchResultList(3, partial_match_i, Navit_last_address_search_string, 18, Navit_last_address_search_country_iso2_string, "0#0", 0);
2937 }
2938 else
2939 {
2940 // flags --> 3: search all countries
2941 // 2: search <iso2 string> country
2942 // 1: search default country (what you have set as language in prefs)
2943 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);
2944 }
2945 Log.e("Navit", "SearchResultsThread run2");
2946 }
2947 else if (this.my_dialog_num == Navit.SEARCHRESULTS_WAIT_DIALOG)
2948 {
2949 // online googlemaps search
2950 // google search
2951 Log.e("Navit", "SearchResultsThread run1 -> online googlemaps search");
2952 String addressInput = filter_bad_chars(Navit_last_address_search_string);
2953 try
2954 {
2955 List<Address> foundAdresses = Navit.Navit_Geocoder.getFromLocationName(addressInput, 30); //Search addresses
2956 System.out.println("found " + foundAdresses.size() + " results");
2957 // System.out.println("addr=" + foundAdresses.get(0).getLatitude() + " " + foundAdresses.get(0).getLongitude() + "" + foundAdresses.get(0).getAddressLine(0));
2958
2959 Navit.NavitAddressSearchSpinnerActive = false;
2960
2961 for (int results_step = 0; results_step < foundAdresses.size(); results_step++)
2962 {
2963 Navit.Navit_Address_Result_Struct tmp_addr = new Navit_Address_Result_Struct();
2964 tmp_addr.result_type = "STR";
2965 tmp_addr.item_id = "0";
2966 tmp_addr.lat = (float) foundAdresses.get(results_step).getLatitude();
2967 tmp_addr.lon = (float) foundAdresses.get(results_step).getLongitude();
2968 tmp_addr.addr = "";
2969
2970 String c_code = foundAdresses.get(results_step).getCountryCode();
2971 if (c_code != null)
2972 {
2973 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getCountryCode() + ",";
2974 }
2975
2976 String p_code = foundAdresses.get(results_step).getPostalCode();
2977 if (p_code != null)
2978 {
2979 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getPostalCode() + " ";
2980 }
2981
2982 if (foundAdresses.get(results_step).getMaxAddressLineIndex() > -1)
2983 {
2984 for (int addr_line = 0; addr_line < foundAdresses.get(results_step).getMaxAddressLineIndex(); addr_line++)
2985 {
2986 if (addr_line > 0) tmp_addr.addr = tmp_addr.addr + " ";
2987 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getAddressLine(addr_line);
2988 }
2989 }
2990
2991 Navit.NavitAddressResultList_foundItems.add(tmp_addr);
2992
2993 if (tmp_addr.result_type.equals("TWN"))
2994 {
2995 Navit.search_results_towns++;
2996 }
2997 else if (tmp_addr.result_type.equals("STR"))
2998 {
2999 Navit.search_results_streets++;
3000 }
3001 else if (tmp_addr.result_type.equals("SHN"))
3002 {
3003 Navit.search_results_streets_hn++;
3004 }
3005
3006 // make the dialog move its bar ...
3007 Bundle b2 = new Bundle();
3008 b2.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG);
3009 b2.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
3010 b2.putInt("cur", Navit.NavitAddressResultList_foundItems.size() % (Navit.ADDRESS_RESULTS_DIALOG_MAX + 1));
3011 b2.putString("title", Navit.get_text("loading search results")); //TRANS
3012 b2.putString("text", Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn);
3013 Navit.msg_to_msg_handler(b2, 10);
3014 }
3015 }
3016 catch (Exception e)
3017 {
3018 e.printStackTrace();
3019 System.out.println("seems googlemaps API is not working, try offline search");
3020 }
3021 }
3022
3023 Navit.NavitAddressSearchSpinnerActive = false;
3024
3025 if (Navit.NavitAddressResultList_foundItems.size() > 0)
3026 {
3027 open_search_result_list();
3028 }
3029 else
3030 {
3031 // not results found, show toast
3032 msg = mHandler.obtainMessage();
3033 b = new Bundle();
3034 msg.what = 3;
3035 b.putString("text", Navit.get_text("No Results found!")); //TRANS
3036 msg.setData(b);
3037 mHandler.sendMessage(msg);
3038 }
3039
3040 // ok, remove dialog
3041 msg = mHandler.obtainMessage();
3042 b = new Bundle();
3043 msg.what = 99;
3044 b.putInt("dialog_num", this.my_dialog_num);
3045 msg.setData(b);
3046 mHandler.sendMessage(msg);
3047
3048 // reset the startup-search flag
3049 Navit.NavitStartupAlreadySearching = false;
3050
3051 Log.e("Navit", "SearchResultsThread ended");
3052 }
3053 }
3054
3055 public static String filter_bad_chars(String in)
3056 {
3057 String out = in;
3058 out = out.replaceAll("\\n", " "); // newline -> space
3059 out = out.replaceAll("\\r", " "); // return -> space
3060 out = out.replaceAll("\\t", " "); // tab -> space
3061 return out;
3062 }
3063
3064 public static void msg_to_msg_handler(Bundle b, int id)
3065 {
3066 Message msg = Navit_progress_h.obtainMessage();
3067 msg.what = id;
3068 msg.setData(b);
3069 Navit_progress_h.sendMessage(msg);
3070 }
3071
3072 public void open_search_result_list()
3073 {
3074 // open result list
3075 Intent address_result_list_activity = new Intent(this, NavitAddressResultListActivity.class);
3076 this.startActivityForResult(address_result_list_activity, Navit.NavitAddressResultList_id);
3077 }
3078
3079 public Handler progress_handler = new Handler()
3080 {
3081 public void handleMessage(Message msg)
3082 {
3083 switch (msg.what)
3084 {
3085 case 0:
3086 // dismiss dialog, remove dialog
3087 try
3088 {
3089 Log.e("Navit", "0: dismiss dialog num " + msg.getData().getInt("dialog_num"));
3090 }
3091 catch (Exception e)
3092 {
3093 e.printStackTrace();
3094 }
3095 dismissDialog(msg.getData().getInt("dialog_num"));
3096 removeDialog(msg.getData().getInt("dialog_num"));
3097
3098 // exit_code=0 -> OK, map was downloaded fine
3099 if (msg.getData().getInt("exit_code") == 0)
3100 {
3101 // try to use the new downloaded map (works fine now!)
3102 //Log.d("Navit", "instance count=" + Navit.getInstanceCount()); // where did this go to?
3103
3104 // **** onStop();
3105 // **** onCreate(getIntent().getExtras());
3106
3107 // reload sdcard maps
3108 Message msg2 = new Message();
3109 Bundle b2 = new Bundle();
3110 b2.putInt("Callback", 18);
3111 msg2.setData(b2);
3112 N_NavitGraphics.callback_handler.sendMessage(msg2);
3113
3114 zoom_out_full();
3115
3116 /*
3117 * Intent intent = getIntent();
3118 * System.out.println("ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ**********************");
3119 * startActivity(intent);
3120 * System.out.println("FFFFFFFFFFFFFFFFFFF**********************");
3121 * Log.d("Navit", "instance count=" + Navit.getInstanceCount());
3122 * onStop();
3123 * System.out.println("HHHHHHHHHHHHHHHHHHH**********************");
3124 */
3125
3126 //Message msg2 = new Message();
3127 //Bundle b2 = new Bundle();
3128 //b2.putInt("Callback", 6);
3129 //msg2.setData(b2);
3130 //N_NavitGraphics.callback_handler.sendMessage(msg2);
3131 }
3132 break;
3133 case 1:
3134 // change progressbar values
3135 int what_dialog = msg.getData().getInt("dialog_num");
3136 if (what_dialog == MAPDOWNLOAD_PRI_DIALOG)
3137 {
3138 mapdownloader_dialog_pri.setMax(msg.getData().getInt("max"));
3139 mapdownloader_dialog_pri.setProgress(msg.getData().getInt("cur"));
3140 mapdownloader_dialog_pri.setTitle(msg.getData().getString("title"));
3141 mapdownloader_dialog_pri.setMessage(msg.getData().getString("text"));
3142 }
3143 else if (what_dialog == MAPDOWNLOAD_SEC_DIALOG)
3144 {
3145 mapdownloader_dialog_sec.setMax(msg.getData().getInt("max"));
3146 mapdownloader_dialog_sec.setProgress(msg.getData().getInt("cur"));
3147 mapdownloader_dialog_sec.setTitle(msg.getData().getString("title"));
3148 mapdownloader_dialog_sec.setMessage(msg.getData().getString("text"));
3149 }
3150 break;
3151 case 2:
3152 Toast.makeText(getApplicationContext(), msg.getData().getString("text"), Toast.LENGTH_SHORT).show();
3153 break;
3154 case 3:
3155 Toast.makeText(getApplicationContext(), msg.getData().getString("text"), Toast.LENGTH_LONG).show();
3156 break;
3157 case 10:
3158 // change values - generic
3159 int what_dialog_generic = msg.getData().getInt("dialog_num");
3160 if (what_dialog_generic == SEARCHRESULTS_WAIT_DIALOG)
3161 {
3162 search_results_wait.setMax(msg.getData().getInt("max"));
3163 search_results_wait.setProgress(msg.getData().getInt("cur"));
3164 search_results_wait.setTitle(msg.getData().getString("title"));
3165 search_results_wait.setMessage(msg.getData().getString("text"));
3166 }
3167 else if (what_dialog_generic == SEARCHRESULTS_WAIT_DIALOG_OFFLINE)
3168 {
3169 search_results_wait_offline.setMax(msg.getData().getInt("max"));
3170 search_results_wait_offline.setProgress(msg.getData().getInt("cur"));
3171 search_results_wait_offline.setTitle(msg.getData().getString("title"));
3172 search_results_wait_offline.setMessage(msg.getData().getString("text"));
3173 }
3174 break;
3175 case 11:
3176 // show dialog - generic
3177 try
3178 {
3179 // just in case, remove the dialog if it should be shown already!
3180 dismissDialog(msg.getData().getInt("dialog_num"));
3181 removeDialog(msg.getData().getInt("dialog_num"));
3182 }
3183 catch (Exception e)
3184 {
3185 // System.out.println("Ex D1: " + e.toString());
3186 }
3187 showDialog(msg.getData().getInt("dialog_num"));
3188 break;
3189 case 12:
3190 // turn on compass
3191 turn_on_compass();
3192 break;
3193 case 13:
3194 // turn off compass
3195 turn_off_compass();
3196 break;
3197 case 14:
3198 // set used mem in textview
3199 show_mem_used_real();
3200 break;
3201 case 15:
3202 // set debug text line 3
3203 Navit.set_debug_messages3(msg.getData().getString("text"));
3204 break;
3205 case 16:
3206 // refresh NavitAndriodOverlay
3207 try
3208 {
3209 //Log.e("NavitGraphics", "xx 1");
3210 NavitGraphics.NavitAOverlay_s.invalidate();
3211 //Log.e("NavitGraphics", "xx 2");
3212 }
3213 catch (Exception e)
3214 {
3215 e.printStackTrace();
3216 }
3217 break;
3218 case 99:
3219 // dismiss dialog, remove dialog - generic
3220 try
3221 {
3222 Log.e("Navit", "99: dismiss dialog num " + msg.getData().getInt("dialog_num"));
3223 }
3224 catch (Exception e)
3225 {
3226 e.printStackTrace();
3227 }
3228 try
3229 {
3230 dismissDialog(msg.getData().getInt("dialog_num"));
3231 }
3232 catch (Exception e)
3233 {
3234 e.printStackTrace();
3235 }
3236 try
3237 {
3238 removeDialog(msg.getData().getInt("dialog_num"));
3239 }
3240 catch (Exception e)
3241 {
3242 e.printStackTrace();
3243 }
3244 break;
3245 }
3246 }
3247 };
3248
3249 protected Dialog onCreateDialog(int id)
3250 {
3251 switch (id)
3252 {
3253 case Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE:
3254 search_results_wait_offline = new ProgressDialog(this);
3255 search_results_wait_offline.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
3256 search_results_wait_offline.setTitle("--");
3257 search_results_wait_offline.setMessage("--");
3258 search_results_wait_offline.setCancelable(true); // allow to stop search
3259 search_results_wait_offline.setProgress(0);
3260 search_results_wait_offline.setMax(10);
3261
3262 search_results_wait_offline.setOnCancelListener(new OnCancelListener()
3263 {
3264 public void onCancel(DialogInterface dialog)
3265 {
3266 Message msg = new Message();
3267 Bundle b = new Bundle();
3268 b.putInt("Callback", 46);
3269 msg.setData(b);
3270 try
3271 {
3272 N_NavitGraphics.callback_handler.sendMessage(msg);
3273 }
3274 catch (Exception e)
3275 {
3276 }
3277 Log.e("Navit", "onCancel: search_results_wait offline");
3278 }
3279 });
3280
3281 /*
3282 * search_results_wait.setButton("stop", new DialogInterface.OnClickListener()
3283 * {
3284 * public void onClick(DialogInterface dialog, int which)
3285 * {
3286 * // Use either finish() or return() to either close the activity or just the dialog
3287 * return;
3288 * }
3289 * });
3290 */
3291
3292 DialogInterface.OnDismissListener mOnDismissListener4 = new DialogInterface.OnDismissListener()
3293 {
3294 public void onDismiss(DialogInterface dialog)
3295 {
3296 Log.e("Navit", "onDismiss: search_results_wait offline");
3297 dialog.dismiss();
3298 dialog.cancel();
3299 searchresultsThread_offline.stop_me();
3300 }
3301 };
3302 search_results_wait_offline.setOnDismissListener(mOnDismissListener4);
3303 searchresultsThread_offline = new SearchResultsThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
3304 searchresultsThread_offline.start();
3305
3306 NavitAddressSearchSpinnerActive = true;
3307 spinner_thread_offline = new SearchResultsThreadSpinnerThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
3308 spinner_thread_offline.start();
3309
3310 return search_results_wait_offline;
3311 case Navit.SEARCHRESULTS_WAIT_DIALOG:
3312 search_results_wait = new ProgressDialog(this);
3313 search_results_wait.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
3314 search_results_wait.setTitle("--");
3315 search_results_wait.setMessage("--");
3316 search_results_wait.setCancelable(false);
3317 search_results_wait.setProgress(0);
3318 search_results_wait.setMax(10);
3319
3320 DialogInterface.OnDismissListener mOnDismissListener3 = new DialogInterface.OnDismissListener()
3321 {
3322 public void onDismiss(DialogInterface dialog)
3323 {
3324 Log.e("Navit", "onDismiss: search_results_wait");
3325 dialog.dismiss();
3326 dialog.cancel();
3327 searchresultsThread.stop_me();
3328 }
3329 };
3330 search_results_wait.setOnDismissListener(mOnDismissListener3);
3331 searchresultsThread = new SearchResultsThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG);
3332 searchresultsThread.start();
3333
3334 NavitAddressSearchSpinnerActive = true;
3335 spinner_thread = new SearchResultsThreadSpinnerThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG);
3336 spinner_thread.start();
3337
3338 return search_results_wait;
3339 case Navit.MAPDOWNLOAD_PRI_DIALOG:
3340 mapdownloader_dialog_pri = new ProgressDialog(this);
3341 mapdownloader_dialog_pri.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
3342 mapdownloader_dialog_pri.setTitle("--");
3343 mapdownloader_dialog_pri.setMessage("--");
3344 mapdownloader_dialog_pri.setCancelable(true);
3345 mapdownloader_dialog_pri.setProgress(0);
3346 mapdownloader_dialog_pri.setMax(200);
3347 DialogInterface.OnDismissListener mOnDismissListener1 = new DialogInterface.OnDismissListener()
3348 {
3349 public void onDismiss(DialogInterface dialog)
3350 {
3351 Log.e("Navit", "onDismiss: mapdownloader_dialog pri");
3352 dialog.dismiss();
3353 dialog.cancel();
3354 progressThread_pri.stop_thread();
3355 }
3356 };
3357 mapdownloader_dialog_pri.setOnDismissListener(mOnDismissListener1);
3358 mapdownloader_pri = new NavitMapDownloader(this);
3359 progressThread_pri = mapdownloader_pri.new ProgressThread(progress_handler, NavitMapDownloader.z_OSM_MAPS[Navit.download_map_id], MAP_NUM_PRIMARY);
3360 progressThread_pri.start();
3361 // show license for OSM maps
3362 //. TRANSLATORS: please only translate the first word "Map data" and leave the other words in english
3363 Toast.makeText(getApplicationContext(), Navit.get_text("Map data (c) OpenStreetMap contributors, CC-BY-SA"), Toast.LENGTH_LONG).show(); //TRANS
3364 return mapdownloader_dialog_pri;
3365 case Navit.MAPDOWNLOAD_SEC_DIALOG:
3366 mapdownloader_dialog_sec = new ProgressDialog(this);
3367 mapdownloader_dialog_sec.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
3368 mapdownloader_dialog_sec.setTitle("--");
3369 mapdownloader_dialog_sec.setMessage("--");
3370 mapdownloader_dialog_sec.setCancelable(true);
3371 mapdownloader_dialog_sec.setProgress(0);
3372 mapdownloader_dialog_sec.setMax(200);
3373 DialogInterface.OnDismissListener mOnDismissListener2 = new DialogInterface.OnDismissListener()
3374 {
3375 public void onDismiss(DialogInterface dialog)
3376 {
3377 Log.e("Navit", "onDismiss: mapdownloader_dialog sec");
3378 dialog.dismiss();
3379 dialog.cancel();
3380 progressThread_sec.stop_thread();
3381 }
3382 };
3383 mapdownloader_dialog_sec.setOnDismissListener(mOnDismissListener2);
3384 mapdownloader_sec = new NavitMapDownloader(this);
3385 progressThread_sec = mapdownloader_sec.new ProgressThread(progress_handler, NavitMapDownloader.z_OSM_MAPS[Navit.download_map_id], MAP_NUM_SECONDARY);
3386 progressThread_sec.start();
3387 // show license for OSM maps
3388 //. TRANSLATORS: please only translate the first word "Map data" and leave the other words in english
3389 Toast.makeText(getApplicationContext(), Navit.get_text("Map data (c) OpenStreetMap contributors, CC-BY-SA"), Toast.LENGTH_LONG).show(); //TRANS
3390 return mapdownloader_dialog_sec;
3391 }
3392 // should never get here!!
3393 return null;
3394 }
3395
3396 public void disableSuspend()
3397 {
3398 wl.acquire();
3399 wl.release();
3400 }
3401
3402 public void exit()
3403 {
3404 NavitVehicle.turn_off_all_providers();
3405 try
3406 {
3407 NavitSpeech.stop_me();
3408 }
3409 catch (Exception s)
3410 {
3411 s.printStackTrace();
3412 }
3413 try
3414 {
3415 NavitSpeech2.stop_me();
3416 }
3417 catch (Exception s)
3418 {
3419 s.printStackTrace();
3420 }
3421 //Intent resultIntent = new Intent();
3422 //resultIntent.putExtra("exitcode", String.valueOf(exitcode));
3423 //setResult(Activity.RESULT_OK, resultIntent);
3424 Log.e("Navit", "1***************** exit called ****************");
3425 Log.e("Navit", "2***************** exit called ****************");
3426 Log.e("Navit", "3***************** exit called ****************");
3427 Log.e("Navit", "4***************** exit called ****************");
3428 Log.e("Navit", "5***************** exit called ****************");
3429 Log.e("Navit", "6***************** exit called ****************");
3430 Log.e("Navit", "7***************** exit called ****************");
3431 Log.e("Navit", "8***************** exit called ****************");
3432 System.gc();
3433 NavitActivity(-4);
3434 finish();
3435 }
3436
3437 public boolean handleMessage(Message m)
3438 {
3439 //Log.e("Navit", "Handler received message");
3440 return true;
3441 }
3442
3443 //public static void set_zanavi_revision_in_settings()
3444 //{
3445 // // can it be that this is never used anymore??
3446 //
3447 // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
3448 // SharedPreferences.Editor editor = prefs.edit();
3449 // // editor.commit();
3450 //}
3451
3452 public static void follow_button_on()
3453 {
3454 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
3455 SharedPreferences.Editor editor = prefs.edit();
3456 Navit.follow_current = Navit.follow_on;
3457 PREF_follow_gps = true;
3458 editor.putBoolean("follow_gps", PREF_follow_gps);
3459 editor.commit();
3460 getPrefs();
3461 activatePrefs(1);
3462 NavitVehicle.set_last_known_pos_fast_provider();
3463 }
3464
3465 public static void follow_button_off()
3466 {
3467 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
3468 SharedPreferences.Editor editor = prefs.edit();
3469 Navit.follow_current = Navit.follow_off;
3470 PREF_follow_gps = false;
3471 editor.putBoolean("follow_gps", PREF_follow_gps);
3472 editor.commit();
3473 getPrefs();
3474 activatePrefs(1);
3475 }
3476
3477 public static void toggle_follow_button()
3478 {
3479 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
3480 SharedPreferences.Editor editor = prefs.edit();
3481 if (PREF_follow_gps)
3482 {
3483 Navit.follow_current = Navit.follow_off;
3484 PREF_follow_gps = false;
3485 }
3486 else
3487 {
3488 Navit.follow_current = Navit.follow_on;
3489 PREF_follow_gps = true;
3490 }
3491 editor.putBoolean("follow_gps", PREF_follow_gps);
3492 editor.commit();
3493 //if (!PREF_follow_gps)
3494 //{
3495 // // no compass turning without follow mode!
3496 // PREF_use_compass_heading_base = false;
3497 //}
3498 //if (!PREF_use_compass_heading_base)
3499 //{
3500 // // child is always "false" when parent is "false" !!
3501 // PREF_use_compass_heading_always = false;
3502 //}
3503 getPrefs();
3504 activatePrefs(1);
3505 NavitVehicle.set_last_known_pos_fast_provider();
3506 }
3507
3508 static boolean PREF_use_fast_provider;
3509 static boolean PREF_follow_gps;
3510 static boolean PREF_use_compass_heading_base;
3511 static boolean PREF_use_compass_heading_always;
3512 static boolean PREF_allow_gui_internal;
3513 static boolean PREF_show_vehicle_in_center;
3514 static boolean PREF_use_imperial;
3515 static boolean PREF_use_compass_heading_fast;
3516 static boolean PREF_use_anti_aliasing;
3517 static boolean PREF_gui_oneway_arrows;
3518 static boolean PREF_show_debug_messages;
3519 static boolean PREF_show_3d_map;
3520 static boolean PREF_use_lock_on_roads;
3521 static boolean PREF_use_route_highways;
3522 static boolean PREF_save_zoomlevel;
3523 static boolean PREF_show_sat_status;
3524 static boolean PREF_use_agps;
3525 static boolean PREF_enable_debug_functions;
3526 static boolean PREF_speak_street_names;
3527 static int PREF_search_country = 1; // default=*ALL*
3528 static int PREF_zoomlevel_num = 2 * 2 * 2 * 2 * 2;
3529 static boolean PREF_use_custom_font = false;
3530 static int PREF_map_font_size = 2; // 1 -> small, 2 -> normal, 3 -> large, 4-> extra large, 4-> mega large
3531 static int PREF_cancel_map_drawing_timeout = 1; // 0 -> short, 1-> normal, 2-> long, 3-> almost unlimited
3532 static boolean PREF_draw_polyline_circles = true; // true -> yes (default) false -> no
3533 static int PREF_mapcache = 10 * 1024; // in kbytes
3534 static String PREF_navit_lang;
3535 static int PREF_drawatorder = 1;
3536 static String PREF_streetsearch_r = "1"; // street search radius factor (multiplier)
3537
3538 public static void setPrefs_search_country()
3539 {
3540 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
3541 SharedPreferences.Editor editor = prefs.edit();
3542 editor.putInt("search_country_id", PREF_search_country);
3543 editor.commit();
3544 }
3545
3546 public static void setPrefs_zoomlevel()
3547 {
3548 //System.out.println("1 save zoom level: " + Navit.GlobalScaleLevel);
3549 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
3550 SharedPreferences.Editor editor = prefs.edit();
3551 editor.putInt("zoomlevel_num", Navit.GlobalScaleLevel);
3552 editor.commit();
3553 //System.out.println("2 save zoom level: " + Navit.GlobalScaleLevel);
3554 }
3555
3556 private static void getPrefs()
3557 {
3558 // Get the xml/preferences.xml preferences
3559 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
3560 PREF_use_fast_provider = prefs.getBoolean("use_fast_provider", false);
3561 PREF_allow_gui_internal = prefs.getBoolean("allow_gui_internal", false);
3562 PREF_follow_gps = prefs.getBoolean("follow_gps", true);
3563 PREF_use_compass_heading_base = prefs.getBoolean("use_compass_heading_base", false);
3564 PREF_use_compass_heading_always = prefs.getBoolean("use_compass_heading_always", false);
3565 PREF_use_compass_heading_fast = prefs.getBoolean("use_compass_heading_fast", false);
3566 PREF_use_anti_aliasing = prefs.getBoolean("use_anti_aliasing", true);
3567 PREF_gui_oneway_arrows = prefs.getBoolean("gui_oneway_arrows", false);
3568 PREF_show_debug_messages = prefs.getBoolean("show_debug_messages", false);
3569 PREF_show_3d_map = prefs.getBoolean("show_3d_map", false);
3570 PREF_use_lock_on_roads = prefs.getBoolean("use_lock_on_roads", true);
3571 PREF_use_route_highways = prefs.getBoolean("use_route_highways", true);
3572 PREF_save_zoomlevel = prefs.getBoolean("save_zoomlevel", true);
3573 PREF_search_country = prefs.getInt("search_country_id", 1); // default=*ALL*
3574 PREF_zoomlevel_num = prefs.getInt("zoomlevel_num", 2 * 2 * 2 * 2 * 2);
3575 PREF_show_sat_status = prefs.getBoolean("show_sat_status", false);
3576 PREF_use_agps = prefs.getBoolean("use_agps", false);
3577 PREF_enable_debug_functions = prefs.getBoolean("enable_debug_functions", false);
3578 PREF_speak_street_names = prefs.getBoolean("speak_street_names", true);
3579 PREF_use_custom_font = prefs.getBoolean("use_custom_font", false);
3580 PREF_draw_polyline_circles = prefs.getBoolean("draw_polyline_circles", true);
3581 PREF_streetsearch_r = prefs.getString("streetsearch_r", "1");
3582
3583 try
3584 {
3585 PREF_drawatorder = Integer.parseInt(prefs.getString("drawatorder", "0"));
3586 }
3587 catch (Exception e)
3588 {
3589 PREF_drawatorder = 0;
3590 }
3591
3592 try
3593 {
3594 PREF_cancel_map_drawing_timeout = Integer.parseInt(prefs.getString("cancel_map_drawing_timeout", "1"));
3595 }
3596 catch (Exception e)
3597 {
3598 PREF_cancel_map_drawing_timeout = 1;
3599 }
3600
3601 try
3602 {
3603 PREF_map_font_size = Integer.parseInt(prefs.getString("map_font_size", "2"));
3604 }
3605 catch (Exception e)
3606 {
3607 PREF_map_font_size = 2;
3608 }
3609
3610 Navit_last_address_search_country_id = PREF_search_country;
3611 Navit_last_address_search_country_iso2_string = NavitAddressSearchCountrySelectActivity.CountryList_Human[PREF_search_country][0];
3612
3613 if (!PREF_follow_gps)
3614 {
3615 // no compass turning without follow mode!
3616 PREF_use_compass_heading_base = false;
3617 }
3618
3619 if (!PREF_use_compass_heading_base)
3620 {
3621 // child is always "false" when parent is "false" !!
3622 PREF_use_compass_heading_always = false;
3623 }
3624 PREF_show_vehicle_in_center = prefs.getBoolean("show_vehicle_in_center", false);
3625 PREF_use_imperial = prefs.getBoolean("use_imperial", false);
3626
3627 // System.out.println("get settings");
3628 // System.out.println("PREF_search_country=" + PREF_search_country);
3629 // System.out.println("PREF_follow_gps=" + PREF_follow_gps);
3630 // System.out.println("PREF_use_fast_provider=" + PREF_use_fast_provider);
3631 // System.out.println("PREF_allow_gui_internal=" + PREF_allow_gui_internal);
3632 // System.out.println("PREF_use_compass_heading_base=" + PREF_use_compass_heading_base);
3633 // System.out.println("PREF_use_compass_heading_always=" + PREF_use_compass_heading_always);
3634 // System.out.println("PREF_show_vehicle_in_center=" + PREF_show_vehicle_in_center);
3635 // System.out.println("PREF_use_imperial=" + PREF_use_imperial);
3636 }
3637
3638 private static void activatePrefs()
3639 {
3640 activatePrefs(1);
3641 if (PREF_save_zoomlevel)
3642 {
3643 // only if really started, but NOT if returning from our own child activities!!
3644
3645 //System.out.println("3 restore zoom level: " + Navit.GlobalScaleLevel);
3646 //System.out.println("4 restore zoom level: " + PREF_zoomlevel_num);
3647
3648 Message msg = new Message();
3649 Bundle b = new Bundle();
3650 b.putInt("Callback", 33);
3651 b.putString("s", Integer.toString(PREF_zoomlevel_num));
3652 msg.setData(b);
3653 try
3654 {
3655 N_NavitGraphics.callback_handler.sendMessage(msg);
3656 Navit.GlobalScaleLevel = PREF_zoomlevel_num;
3657 //System.out.println("5 restore zoom level: " + PREF_zoomlevel_num);
3658 }
3659 catch (Exception e)
3660 {
3661 }
3662 }
3663 else
3664 {
3665 PREF_zoomlevel_num = Navit.GlobalScaleLevel;
3666 }
3667 }
3668
3669 private static void activatePrefs(int dummy)
3670 {
3671 // call some functions to activate the new settings
3672 if (PREF_follow_gps)
3673 {
3674 Navit.follow_current = Navit.follow_on;
3675 }
3676 else
3677 {
3678 Navit.follow_current = Navit.follow_off;
3679 }
3680
3681 if (PREF_use_fast_provider)
3682 {
3683 NavitVehicle.turn_on_fast_provider();
3684 }
3685 else
3686 {
3687 NavitVehicle.turn_off_fast_provider();
3688 }
3689
3690 if (PREF_show_sat_status)
3691 {
3692 NavitVehicle.turn_on_sat_status();
3693 }
3694 else
3695 {
3696 // status always on !
3697 //
3698 // NavitVehicle.turn_off_sat_status();
3699 NavitVehicle.turn_on_sat_status();
3700 }
3701
3702 if (PREF_allow_gui_internal)
3703 {
3704 Message msg = new Message();
3705 Bundle b = new Bundle();
3706 b.putInt("Callback", 10);
3707 msg.setData(b);
3708 try
3709 {
3710 N_NavitGraphics.callback_handler.sendMessage(msg);
3711 }
3712 catch (Exception e)
3713 {
3714 }
3715 }
3716 else
3717 {
3718 Message msg = new Message();
3719 Bundle b = new Bundle();
3720 b.putInt("Callback", 9);
3721 msg.setData(b);
3722 try
3723 {
3724 N_NavitGraphics.callback_handler.sendMessage(msg);
3725 }
3726 catch (Exception e)
3727 {
3728 }
3729 }
3730
3731 if (PREF_use_compass_heading_base)
3732 {
3733 // turn on compass
3734 msg_to_msg_handler(new Bundle(), 12);
3735 Message msg = new Message();
3736 Bundle b = new Bundle();
3737 b.putInt("Callback", 11);
3738 msg.setData(b);
3739 try
3740 {
3741 N_NavitGraphics.callback_handler.sendMessage(msg);
3742 }
3743 catch (Exception e)
3744 {
3745 }
3746 }
3747 else
3748 {
3749 // turn off compass
3750 msg_to_msg_handler(new Bundle(), 13);
3751 Message msg = new Message();
3752 Bundle b = new Bundle();
3753 b.putInt("Callback", 12);
3754 msg.setData(b);
3755 try
3756 {
3757 N_NavitGraphics.callback_handler.sendMessage(msg);
3758 }
3759 catch (Exception e)
3760 {
3761 }
3762 }
3763
3764 if (PREF_show_vehicle_in_center)
3765 {
3766 Message msg = new Message();
3767 Bundle b = new Bundle();
3768 b.putInt("Callback", 14);
3769 msg.setData(b);
3770 try
3771 {
3772 N_NavitGraphics.callback_handler.sendMessage(msg);
3773 }
3774 catch (Exception e)
3775 {
3776 }
3777 }
3778 else
3779 {
3780 Message msg = new Message();
3781 Bundle b = new Bundle();
3782 b.putInt("Callback", 13);
3783 msg.setData(b);
3784 try
3785 {
3786 N_NavitGraphics.callback_handler.sendMessage(msg);
3787 }
3788 catch (Exception e)
3789 {
3790 }
3791 }
3792
3793 if (PREF_use_imperial)
3794 {
3795 Message msg = new Message();
3796 Bundle b = new Bundle();
3797 b.putInt("Callback", 16);
3798 msg.setData(b);
3799 try
3800 {
3801 N_NavitGraphics.callback_handler.sendMessage(msg);
3802 }
3803 catch (Exception e)
3804 {
3805 }
3806 }
3807 else
3808 {
3809 Message msg = new Message();
3810 Bundle b = new Bundle();
3811 b.putInt("Callback", 15);
3812 msg.setData(b);
3813 try
3814 {
3815 N_NavitGraphics.callback_handler.sendMessage(msg);
3816 }
3817 catch (Exception e)
3818 {
3819 }
3820 }
3821
3822 if (PREF_show_debug_messages)
3823 {
3824 Message msg = new Message();
3825 Bundle b = new Bundle();
3826 b.putInt("Callback", 24);
3827 msg.setData(b);
3828 try
3829 {
3830 N_NavitGraphics.callback_handler.sendMessage(msg);
3831 }
3832 catch (Exception e)
3833 {
3834 }
3835 }
3836 else
3837 {
3838 Message msg = new Message();
3839 Bundle b = new Bundle();
3840 b.putInt("Callback", 25);
3841 msg.setData(b);
3842 try
3843 {
3844 N_NavitGraphics.callback_handler.sendMessage(msg);
3845 }
3846 catch (Exception e)
3847 {
3848 }
3849 }
3850
3851 if (PREF_show_3d_map)
3852 {
3853 Message msg = new Message();
3854 Bundle b = new Bundle();
3855 b.putInt("Callback", 31);
3856 msg.setData(b);
3857 try
3858 {
3859 N_NavitGraphics.callback_handler.sendMessage(msg);
3860 }
3861 catch (Exception e)
3862 {
3863 }
3864 }
3865 else
3866 {
3867 Message msg = new Message();
3868 Bundle b = new Bundle();
3869 b.putInt("Callback", 30);
3870 msg.setData(b);
3871 try
3872 {
3873 N_NavitGraphics.callback_handler.sendMessage(msg);
3874 }
3875 catch (Exception e)
3876 {
3877 }
3878 }
3879
3880 if (PREF_use_lock_on_roads)
3881 {
3882 Message msg = new Message();
3883 Bundle b = new Bundle();
3884 b.putInt("Callback", 36);
3885 msg.setData(b);
3886 try
3887 {
3888 N_NavitGraphics.callback_handler.sendMessage(msg);
3889 }
3890 catch (Exception e)
3891 {
3892 }
3893 }
3894 else
3895 {
3896 Message msg = new Message();
3897 Bundle b = new Bundle();
3898 b.putInt("Callback", 37);
3899 msg.setData(b);
3900 try
3901 {
3902 N_NavitGraphics.callback_handler.sendMessage(msg);
3903 }
3904 catch (Exception e)
3905 {
3906 }
3907 }
3908
3909 // if (PREF_draw_polyline_circles)
3910 // {
3911 // Message msg = new Message();
3912 // Bundle b = new Bundle();
3913 // b.putString("s", "0");
3914 // b.putInt("Callback", 56);
3915 // msg.setData(b);
3916 // try
3917 // {
3918 // N_NavitGraphics.callback_handler.sendMessage(msg);
3919 // }
3920 // catch (Exception e)
3921 // {
3922 // }
3923 // }
3924 // else
3925 // {
3926 // Message msg = new Message();
3927 // Bundle b = new Bundle();
3928 // b.putString("s", "1");
3929 // b.putInt("Callback", 56);
3930 // msg.setData(b);
3931 // try
3932 // {
3933 // N_NavitGraphics.callback_handler.sendMessage(msg);
3934 // }
3935 // catch (Exception e)
3936 // {
3937 // }
3938 // }
3939
3940 if (PREF_use_route_highways)
3941 {
3942 Message msg = new Message();
3943 Bundle b = new Bundle();
3944 b.putInt("Callback", 42);
3945 msg.setData(b);
3946 try
3947 {
3948 N_NavitGraphics.callback_handler.sendMessage(msg);
3949 }
3950 catch (Exception e)
3951 {
3952 }
3953 }
3954 else
3955 {
3956 Message msg = new Message();
3957 Bundle b = new Bundle();
3958 b.putInt("Callback", 43);
3959 msg.setData(b);
3960 try
3961 {
3962 N_NavitGraphics.callback_handler.sendMessage(msg);
3963 }
3964 catch (Exception e)
3965 {
3966 }
3967 }
3968
3969 Message msg7 = new Message();
3970 Bundle b7 = new Bundle();
3971 b7.putInt("Callback", 57);
3972 b7.putString("s", "" + PREF_drawatorder);
3973 msg7.setData(b7);
3974 try
3975 {
3976 N_NavitGraphics.callback_handler.sendMessage(msg7);
3977 }
3978 catch (Exception e)
3979 {
3980 }
3981
3982 msg7 = new Message();
3983 b7 = new Bundle();
3984 b7.putInt("Callback", 58);
3985 b7.putString("s", PREF_streetsearch_r);
3986 msg7.setData(b7);
3987 try
3988 {
3989 N_NavitGraphics.callback_handler.sendMessage(msg7);
3990 }
3991 catch (Exception e)
3992 {
3993 }
3994
3995 if (PREF_speak_street_names)
3996 {
3997 Message msg = new Message();
3998 Bundle b = new Bundle();
3999 b.putInt("Callback", 54);
4000 msg.setData(b);
4001 try
4002 {
4003 N_NavitGraphics.callback_handler.sendMessage(msg);
4004 }
4005 catch (Exception e)
4006 {
4007 }
4008 }
4009 else
4010 {
4011 Message msg = new Message();
4012 Bundle b = new Bundle();
4013 b.putInt("Callback", 53);
4014 msg.setData(b);
4015 try
4016 {
4017 N_NavitGraphics.callback_handler.sendMessage(msg);
4018 }
4019 catch (Exception e)
4020 {
4021 }
4022 }
4023
4024 try
4025 {
4026 NavitGraphics.OverlayDrawThread_cancel_drawing_timeout = NavitGraphics.OverlayDrawThread_cancel_drawing_timeout__options[PREF_cancel_map_drawing_timeout];
4027 NavitGraphics.OverlayDrawThread_cancel_thread_sleep_time = NavitGraphics.OverlayDrawThread_cancel_thread_sleep_time__options[PREF_cancel_map_drawing_timeout];
4028 NavitGraphics.OverlayDrawThread_cancel_thread_timeout = NavitGraphics.OverlayDrawThread_cancel_thread_timeout__options[PREF_cancel_map_drawing_timeout];
4029 }
4030 catch (Exception e)
4031 {
4032
4033 }
4034
4035 // set vars for mapdir change (only really takes effect after restart!)
4036 getPrefs_mapdir();
4037 }
4038
4039 private static void getPrefs_mapdir()
4040 {
4041 // Get the xml/preferences.xml preferences
4042 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
4043 String default_sdcard_dir = Environment.getExternalStorageDirectory().getAbsolutePath();
4044 Log.e("Navit", "old sdcard dir=" + NavitDataDirectory_Maps);
4045 Log.e("Navit", "default sdcard dir=" + default_sdcard_dir);
4046 NavitDataDirectory_Maps = prefs.getString("map_directory", default_sdcard_dir + "/zanavi/maps/");
4047 // ** DEBUG ** NavitDataDirectory_Maps = prefs.getString("navit_mapsdir", "/sdcard" + "/zanavi/maps/");
4048 Log.e("Navit", "new sdcard dir=" + NavitDataDirectory_Maps);
4049 }
4050
4051 static String sanity_check_maps_dir(String check_dir)
4052 {
4053 String ret = check_dir;
4054 ret = ret.replaceAll("\\n", ""); // newline -> ""
4055 ret = ret.replaceAll("\\r", ""); // return -> ""
4056 ret = ret.replaceAll("\\t", ""); // tab -> ""
4057 ret = ret.replaceAll(" ", ""); // space -> ""
4058 ret = ret.replaceAll("\"", ""); // \" -> ""
4059 ret = ret.replaceAll("'", ""); // \' -> ""
4060 ret = ret.replaceAll("\\\\", ""); // "\" -> ""
4061 if (!ret.endsWith("/"))
4062 {
4063 ret = ret + "/";
4064 }
4065 System.out.println("sanity check:" + ret);
4066 return ret;
4067 }
4068
4069 private static void activatePrefs_mapdir(Boolean at_startup)
4070 {
4071 // activate the new directory
4072 NavitDataDirectory_Maps = sanity_check_maps_dir(NavitDataDirectory_Maps);
4073 MAP_FILENAME_PATH = NavitDataDirectory_Maps;
4074 MAPMD5_FILENAME_PATH = NavitDataDirectory_Maps + "/../md5/";
4075 CFG_FILENAME_PATH = NavitDataDirectory_Maps + "/../";
4076
4077 System.out.println("xxxxxxxx************XXXXXXXXXXX");
4078 System.out.println("xxxxxxxx************XXXXXXXXXXX");
4079 System.out.println("xxxxxxxx************XXXXXXXXXXX");
4080 System.out.println("xxxxxxxx************XXXXXXXXXXX");
4081 System.out.println("xxxxxxxx************XXXXXXXXXXX");
4082 System.out.println("xxxxxxxx************XXXXXXXXXXX");
4083 System.out.println("xxxxxxxx************XXXXXXXXXXX");
4084 System.out.println("xxxxxxxx************XXXXXXXXXXX");
4085 System.out.println("xxxxxxxx************XXXXXXXXXXX");
4086
4087 Handler h_temp = null;
4088 h_temp = NavitGraphics.callback_handler_s;
4089 System.out.println("handler 1=" + h_temp.toString());
4090
4091 Message msg1 = new Message();
4092 Bundle b1 = new Bundle();
4093 b1.putInt("Callback", 47);
4094 b1.putString("s", MAP_FILENAME_PATH);
4095 msg1.setData(b1);
4096 h_temp.sendMessage(msg1);
4097
4098 if (!at_startup)
4099 {
4100 Message msg2 = new Message();
4101 Bundle b2 = new Bundle();
4102 b2.putInt("Callback", 18);
4103 msg2.setData(b2);
4104 h_temp.sendMessage(msg2);
4105 }
4106 }
4107
4108 private static void getPrefs_loc()
4109 {
4110 // Get the xml/preferences.xml preferences
4111 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
4112 PREF_navit_lang = prefs.getString("navit_lang", "*DEFAULT*");
4113 System.out.println("**** ***** **** pref lang=" + PREF_navit_lang);
4114 }
4115
4116 private static void activatePrefs_loc()
4117 {
4118 // creating locale
4119 if (!PREF_navit_lang.equals("*DEFAULT*"))
4120 {
4121 Locale locale2 = null;
4122 if (PREF_navit_lang.contains("_"))
4123 {
4124 String _lang = PREF_navit_lang.split("_", 2)[0];
4125 String _country = PREF_navit_lang.split("_", 2)[1];
4126 System.out.println("l=" + _lang + " c=" + _country);
4127 locale2 = new Locale(_lang, _country);
4128 }
4129 else
4130 {
4131 locale2 = new Locale(PREF_navit_lang);
4132 }
4133 Locale.setDefault(locale2);
4134 Configuration config2 = new Configuration();
4135 config2.locale = locale2;
4136 // updating locale
4137 getBaseContext_.getResources().updateConfiguration(config2, null);
4138 }
4139 }
4140
4141 private static void getPrefs_mapcache()
4142 {
4143 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
4144 try
4145 {
4146 PREF_mapcache = Integer.parseInt(prefs.getString("mapcache", "" + (10 * 1024)));
4147 }
4148 catch (Exception e)
4149 {
4150 e.printStackTrace();
4151 PREF_mapcache = 10 * 1024;
4152 }
4153 System.out.println("**** ***** **** pref mapcache=" + PREF_mapcache);
4154 }
4155
4156 private static void activatePrefs_mapcache()
4157 {
4158 Handler h_temp2 = null;
4159 h_temp2 = NavitGraphics.callback_handler_s;
4160 Message msg7 = new Message();
4161 Bundle b7 = new Bundle();
4162 b7.putInt("Callback", 55);
4163 b7.putString("s", String.valueOf(PREF_mapcache * 1024));
4164 msg7.setData(b7);
4165 h_temp2.sendMessage(msg7);
4166 }
4167
4168 public native void NavitMain(Navit x, String lang, int version, String display_density_string);
4169
4170 public native void NavitActivity(int activity);
4171
4172 /*
4173 * this is used to load the 'navit' native library on
4174 * application startup. The library has already been unpacked at
4175 * installation time by the package manager.
4176 */
4177 static
4178 {
4179 System.loadLibrary("navit");
4180 }
4181
4182 /*
4183 * Show a search activity with the string "search" filled in
4184 */
4185 private void executeSearch(String search)
4186 {
4187 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
4188 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
4189 search_intent.putExtra("address_string", search);
4190 search_intent.putExtra("type", "offline");
4191 search_intent.putExtra("search_country_id", Navit_last_address_search_country_id);
4192 String pm_temp = "0";
4193 if (Navit_last_address_partial_match)
4194 {
4195 pm_temp = "1";
4196 }
4197 search_intent.putExtra("partial_match", pm_temp);
4198 this.startActivityForResult(search_intent, NavitAddressSearch_id_offline);
4199 }
4200
4201 /*
4202 * open google maps at a given coordinate
4203 */
4204 private void googlemaps_show(String lat, String lon, String name)
4205 {
4206 // geo:latitude,longitude
4207 String url = null;
4208 Intent gmaps_intent = new Intent(Intent.ACTION_VIEW);
4209
4210 //url = "geo:" + lat + "," + lon + "?z=" + "16";
4211 //url = "geo:0,0?q=" + lat + "," + lon + " (" + name + ")";
4212 url = "geo:0,0?z=16&q=" + lat + "," + lon + " (" + name + ")";
4213
4214 gmaps_intent.setData(Uri.parse(url));
4215 this.startActivityForResult(gmaps_intent, NavitAddressSearch_id_gmaps);
4216 }
4217
4218 public void zoom_out_full()
4219 {
4220 System.out.println("");
4221 System.out.println("*** Zoom out FULL ***");
4222 System.out.println("");
4223 Message msg = new Message();
4224 Bundle b = new Bundle();
4225 b.putInt("Callback", 8);
4226 msg.setData(b);
4227 N_NavitGraphics.callback_handler.sendMessage(msg);
4228 }
4229
4230 public void show_geo_on_screen(float lat, float lng)
4231 {
4232 // -> let follow mode stay as it now is ### Navit.follow_button_off();
4233
4234 // this function sets screen center to "lat, lon", and just returns a dummy string!
4235 String nix = NavitGraphics.CallbackGeoCalc(3, lat, lng);
4236 }
4237
4238 public void zoom_to_route()
4239 {
4240 //System.out.println("");
4241 //System.out.println("*** Zoom to ROUTE ***");
4242 //System.out.println("");
4243 Message msg = new Message();
4244 Bundle b = new Bundle();
4245 b.putInt("Callback", 17);
4246 msg.setData(b);
4247 N_NavitGraphics.callback_handler.sendMessage(msg);
4248 }
4249
4250 public void turn_on_compass()
4251 {
4252 try
4253 {
4254 if (!PREF_use_compass_heading_fast)
4255 {
4256 // Slower
4257 sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
4258 }
4259 else
4260 {
4261 // FAST
4262 sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_UI);
4263 }
4264 }
4265 catch (Exception e)
4266 {
4267 e.printStackTrace();
4268 }
4269 }
4270
4271 public void turn_off_compass()
4272 {
4273 try
4274 {
4275 sensorManager.unregisterListener(this);
4276 }
4277 catch (Exception e)
4278 {
4279 e.printStackTrace();
4280 }
4281 }
4282
4283 public void onSensorChanged(SensorEvent event)
4284 {
4285 if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
4286 {
4287 // System.out.println("Sensor.TYPE_MAGNETIC_FIELD");
4288 return;
4289 }
4290
4291 if (event.sensor.getType() == Sensor.TYPE_ORIENTATION)
4292 {
4293 // System.out.println("Sensor.TYPE_ORIENTATION");
4294
4295 // compass
4296 float myAzimuth = event.values[0];
4297 // double myPitch = event.values[1];
4298 // double myRoll = event.values[2];
4299
4300 //String out = String.format("Azimuth: %.2f", myAzimuth);
4301 //System.out.println("compass: " + out);
4302 NavitVehicle.update_compass_heading(myAzimuth);
4303 }
4304 }
4305
4306 public void onAccuracyChanged(Sensor sensor, int accuracy)
4307 {
4308 // compass
4309 }
4310
4311 public void hide_status_bar()
4312 {
4313 // Hide the Status Bar
4314 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
4315 }
4316
4317 public void show_status_bar()
4318 {
4319 // Hide the Status Bar
4320 // ??? getWindow().setFlags(0, 0);
4321 }
4322
4323 public void hide_title_bar()
4324 {
4325 // Hide the Title Bar - this works ONLY before setcontent in onCreate!!
4326 requestWindowFeature(Window.FEATURE_NO_TITLE);
4327 }
4328
4329 public void show_title_bar()
4330 {
4331 // Hide the Title Bar - this works ONLY before setcontent in onCreate!!
4332 // ?? requestWindowFeature(Window.);
4333 }
4334
4335 public static Boolean downloadGPSXtra(Context context)
4336 {
4337 Boolean ret = false;
4338 Boolean ret2 = false;
4339 try
4340 {
4341 LocationManager locationmanager2 = (LocationManager) context.getSystemService("location");
4342 Bundle bundle = new Bundle();
4343 //ret2 = locationmanager2.sendExtraCommand("gps", "delete_aiding_data", null);
4344 //ret = ret2;
4345 // System.out.println("ret0=" + ret);
4346 ret2 = locationmanager2.sendExtraCommand("gps", "force_xtra_injection", bundle);
4347 ret = ret2;
4348 System.out.println("ret1=" + ret2);
4349 ret2 = locationmanager2.sendExtraCommand("gps", "force_time_injection", bundle);
4350 ret = ret || ret2;
4351 System.out.println("ret2=" + ret2);
4352 }
4353 catch (Exception e)
4354 {
4355 System.out.println("*XX*");
4356 e.printStackTrace();
4357 }
4358 return ret;
4359 }
4360
4361 static void add_map_point(Navit_Point_on_Map element)
4362 {
4363 if (element == null)
4364 {
4365 return;
4366 }
4367 if (map_points == null)
4368 {
4369 map_points = new ArrayList<Navit_Point_on_Map>();
4370 }
4371 if (map_points.size() > Navit_MAX_RECENT_DESTINATIONS)
4372 {
4373 try
4374 {
4375 map_points.remove(0);
4376 }
4377 catch (Exception e)
4378 {
4379
4380 }
4381 }
4382
4383 if (!check_dup_destination(element))
4384 {
4385 // if not duplicate, then add
4386 map_points.add(element);
4387 }
4388 }
4389
4390 void read_map_points()
4391 {
4392 deserialize_map_points();
4393 }
4394
4395 static void write_map_points()
4396 {
4397 if (map_points != null)
4398 {
4399 serialize_map_points();
4400 }
4401 }
4402
4403 private static void serialize_map_points()
4404 {
4405 FileOutputStream fos;
4406 try
4407 {
4408 fos = new FileOutputStream(CFG_FILENAME_PATH + Navit_DEST_FILENAME);
4409 // openFileOutput(CFG_FILENAME_PATH + Navit_DEST_FILENAME, Context.MODE_PRIVATE);
4410 ObjectOutputStream oos = new ObjectOutputStream(fos);
4411 oos.writeObject(map_points);
4412 oos.close();
4413 }
4414 catch (FileNotFoundException e)
4415 {
4416 e.printStackTrace();
4417 }
4418 catch (IOException e)
4419 {
4420 e.printStackTrace();
4421 }
4422 catch (Exception e)
4423 {
4424 e.printStackTrace();
4425 }
4426 }
4427
4428 @SuppressWarnings("unchecked")
4429 private void deserialize_map_points()
4430 {
4431 try
4432 {
4433 FileInputStream fis = new FileInputStream(CFG_FILENAME_PATH + Navit_DEST_FILENAME);
4434 // openFileInput(CFG_FILENAME_PATH + Navit_DEST_FILENAME);
4435 ObjectInputStream ois = new ObjectInputStream(fis);
4436 map_points = (ArrayList<Navit_Point_on_Map>) ois.readObject();
4437 }
4438 catch (FileNotFoundException e)
4439 {
4440 e.printStackTrace();
4441 map_points = new ArrayList<Navit_Point_on_Map>();
4442 }
4443 catch (IOException e)
4444 {
4445 e.printStackTrace();
4446 map_points = new ArrayList<Navit_Point_on_Map>();
4447 }
4448 catch (ClassNotFoundException e)
4449 {
4450 e.printStackTrace();
4451 map_points = new ArrayList<Navit_Point_on_Map>();
4452 }
4453 catch (Exception e)
4454 {
4455 e.printStackTrace();
4456 map_points = new ArrayList<Navit_Point_on_Map>();
4457 }
4458
4459 // for (int j = 0; j < map_points.size(); j++)
4460 // {
4461 // System.out.println("####******************" + j + ":" + map_points.get(j).point_name);
4462 // }
4463 }
4464
4465 static void remember_destination_xy(String name, int x, int y)
4466 {
4467 // i=1 -> pixel a,b (x,y) -> geo string "lat(float):lng(float)"
4468 // i=2 -> geo a,b (lat,lng) -> pixel string "x(int):y(int)"
4469 String lat_lon = NavitGraphics.CallbackGeoCalc(1, x, y);
4470 try
4471 {
4472 String tmp[] = lat_lon.split(":", 2);
4473 //System.out.println("tmp=" + lat_lon);
4474 float lat = Float.parseFloat(tmp[0]);
4475 float lon = Float.parseFloat(tmp[1]);
4476 //System.out.println("ret=" + lat_lon + " lat=" + lat + " lon=" + lon);
4477 remember_destination(name, lat, lon);
4478 }
4479 catch (Exception e)
4480 {
4481 e.printStackTrace();
4482 }
4483 }
4484
4485 static void remember_destination(String name, String lat, String lon)
4486 {
4487 try
4488 {
4489 //System.out.println("22 **## " + name + " " + lat + " " + lon + " ##**");
4490 remember_destination(name, Float.parseFloat(lat), Float.parseFloat(lon));
4491 }
4492 catch (Exception e)
4493 {
4494 e.printStackTrace();
4495 }
4496 }
4497
4498 static void remember_destination(String name, float lat, float lon)
4499 {
4500 //System.out.println("11 **## " + name + " " + lat + " " + lon + " ##**");
4501 Navit_Point_on_Map t = new Navit_Point_on_Map();
4502 t.point_name = name;
4503 t.lat = lat;
4504 t.lon = lon;
4505 add_map_point(t);
4506 }
4507
4508 static void destination_set()
4509 {
4510 // status = "destination set"
4511 NavitGraphics.navit_route_status = 1;
4512 }
4513
4514 static Boolean check_dup_destination(Navit_Point_on_Map element)
4515 {
4516 Boolean ret = false;
4517 Navit_Point_on_Map t;
4518 for (int i = 0; i < map_points.size(); i++)
4519 {
4520 t = map_points.get(i);
4521 if ((t.point_name.equals(element.point_name)) && (t.lat == element.lat) && (t.lon == element.lon))
4522 {
4523 return true;
4524 }
4525 }
4526 return ret;
4527 }
4528
4529 }

   
Visit the ZANavi Wiki