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

   
Visit the ZANavi Wiki