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

   
Visit the ZANavi Wiki