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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 30 Revision 31
51import java.io.Serializable; 51import java.io.Serializable;
52import java.net.URLDecoder; 52import java.net.URLDecoder;
53import java.nio.channels.FileChannel; 53import java.nio.channels.FileChannel;
54import java.util.ArrayList; 54import java.util.ArrayList;
55import java.util.Calendar; 55import java.util.Calendar;
56import java.util.Collections;
56import java.util.Date; 57import java.util.Date;
57import java.util.HashSet; 58import java.util.HashSet;
58import java.util.List; 59import java.util.List;
59import java.util.Locale; 60import java.util.Locale;
60import java.util.Random; 61import java.util.Random;
126 127
127import de.oberoner.gpx2navit_txt.MainFrame; 128import de.oberoner.gpx2navit_txt.MainFrame;
128 129
129public class Navit extends Activity implements Handler.Callback, SensorEventListener 130public class Navit extends Activity implements Handler.Callback, SensorEventListener
130{ 131{
131 public static final String VERSION_TEXT_LONG_INC_REV = "179"; 132 public static final String VERSION_TEXT_LONG_INC_REV = "762";
132 public static String NavitAppVersion = "0"; 133 public static String NavitAppVersion = "0";
133 public static String NavitAppVersion_prev = "-1"; 134 public static String NavitAppVersion_prev = "-1";
134 public static String NavitAppVersion_string = "0"; 135 public static String NavitAppVersion_string = "0";
135 public final Boolean NAVIT_IS_EMULATOR = false; // when running on emulator set to true!! 136 public final Boolean NAVIT_IS_EMULATOR = false; // when running on emulator set to true!!
136 137
156 public double moon_evelation_cache = -1; 157 public double moon_evelation_cache = -1;
157 Boolean sun_moon__must_calc_new = true; 158 Boolean sun_moon__must_calc_new = true;
158 SunriseSunsetCalculator sun_moon__calc = null; 159 SunriseSunsetCalculator sun_moon__calc = null;
159 Calendar sun_moon__cx = null; 160 Calendar sun_moon__cx = null;
160 SolarPosition.SunCoordinates sun_moon__sc = null; 161 SolarPosition.SunCoordinates sun_moon__sc = null;
162 public static boolean calc_sun_enabled = true;
161 // -------- SUN / MOON ---------- 163 // -------- SUN / MOON ----------
162 164
163 public static CWorkerThread cwthr = null; 165 public static CWorkerThread cwthr = null;
164 public static NavitGraphics NG__map_main = null; 166 public static NavitGraphics NG__map_main = null;
165 public static NavitGraphics NG__vehicle = null; 167 public static NavitGraphics NG__vehicle = null;
166 public static NavitVehicle NV = null; 168 public static NavitVehicle NV = null;
167 public static NavitSpeech2 NSp = null; 169 public static NavitSpeech2 NSp = null;
168 170
171 public static boolean use_index_search = false;
172
169 static AlertDialog.Builder generic_alert_box = null; 173 static AlertDialog.Builder generic_alert_box = null;
170 174
171 private Boolean xmlconfig_unpack_file = true; 175 private Boolean xmlconfig_unpack_file = true;
172 private Boolean write_new_version_file = true; 176 private Boolean write_new_version_file = true;
173 final static int Navit_Status_COMPLETE_NEW_INSTALL = 1; 177 final static int Navit_Status_COMPLETE_NEW_INSTALL = 1;
174 final static int Navit_Status_UPGRADED_TO_NEW_VERSION = 2; 178 final static int Navit_Status_UPGRADED_TO_NEW_VERSION = 2;
175 final static int Navit_Status_NORMAL_STARTUP = 0; 179 final static int Navit_Status_NORMAL_STARTUP = 0;
176 Boolean Navit_DonateVersion_Installed = false; 180 static Boolean Navit_DonateVersion_Installed = false;
177 static Boolean Navit_Largemap_DonateVersion_Installed = false; 181 static Boolean Navit_Largemap_DonateVersion_Installed = false;
178 private int startup_status = Navit_Status_NORMAL_STARTUP; 182 private int startup_status = Navit_Status_NORMAL_STARTUP;
179 final static int Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL = 8; 183 final static int Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL = 8;
180 static Boolean unsupported = false; 184 static Boolean unsupported = false;
181 static Boolean Navit_maps_loaded = false; 185 static Boolean Navit_maps_loaded = false;
245 destination.close(); 249 destination.close();
246 } 250 }
247 251
248 } 252 }
249 253
250 public static final class Navit_Address_Result_Struct 254 public static final class Navit_Address_Result_Struct implements Comparable<Navit_Address_Result_Struct>
251 { 255 {
252 String result_type; // TWN,STR,SHN 256 String result_type; // TWN,STR,SHN
253 String item_id; // H<ddddd>L<ddddd> -> item.id_hi item.id_lo 257 String item_id; // H<ddddd>L<ddddd> -> item.id_hi item.id_lo
254 float lat; 258 float lat;
255 float lon; 259 float lon;
256 String addr; 260 String addr;
261
262 // function to sort address result list
263 public int compareTo(Navit_Address_Result_Struct comp)
264 {
265 return this.addr.toLowerCase().compareTo(comp.addr.toLowerCase());
266 }
257 } 267 }
258 268
259 public static final class Navit_Point_on_Map implements Serializable 269 public static final class Navit_Point_on_Map implements Serializable
260 { 270 {
261 /** 271 /**
361 ProgressThread progressThread_pri = null; 371 ProgressThread progressThread_pri = null;
362 ProgressThread progressThread_sec = null; 372 ProgressThread progressThread_sec = null;
363 public static int search_results_towns = 0; 373 public static int search_results_towns = 0;
364 public static int search_results_streets = 0; 374 public static int search_results_streets = 0;
365 public static int search_results_streets_hn = 0; 375 public static int search_results_streets_hn = 0;
376 public static Boolean search_hide_duplicates = false;
366 public static Boolean NavitStartupAlreadySearching = false; 377 public static Boolean NavitStartupAlreadySearching = false;
367 SearchResultsThread searchresultsThread = null; 378 SearchResultsThread searchresultsThread = null;
368 SearchResultsThread searchresultsThread_offline = null; 379 SearchResultsThread searchresultsThread_offline = null;
369 SearchResultsThreadSpinnerThread spinner_thread = null; 380 SearchResultsThreadSpinnerThread spinner_thread = null;
370 SearchResultsThreadSpinnerThread spinner_thread_offline = null; 381 SearchResultsThreadSpinnerThread spinner_thread_offline = null;
378 public static final int NavitAddressSearch_id_gmaps = 76; 389 public static final int NavitAddressSearch_id_gmaps = 76;
379 public static int NavitSearchresultBarIndex = -1; 390 public static int NavitSearchresultBarIndex = -1;
380 public static String NavitSearchresultBar_title = ""; 391 public static String NavitSearchresultBar_title = "";
381 public static String NavitSearchresultBar_text = ""; 392 public static String NavitSearchresultBar_text = "";
382 public static List<Navit_Address_Result_Struct> NavitAddressResultList_foundItems = new ArrayList<Navit_Address_Result_Struct>(); 393 public static List<Navit_Address_Result_Struct> NavitAddressResultList_foundItems = new ArrayList<Navit_Address_Result_Struct>();
394
383 public static Boolean DemoVehicle = false; 395 public static Boolean DemoVehicle = false;
384 396
385 static Typeface NavitStreetnameFont = null; 397 static Typeface NavitStreetnameFont = null;
386 398
387 public SensorManager sensorManager = null; 399 public SensorManager sensorManager = null;
400 public static Bitmap nav_arrow_stopped = null; 412 public static Bitmap nav_arrow_stopped = null;
401 public static Bitmap nav_arrow_moving = null; 413 public static Bitmap nav_arrow_moving = null;
402 public static Bitmap nav_arrow_moving_shadow = null; 414 public static Bitmap nav_arrow_moving_shadow = null;
403 415
404 public static String Navit_last_address_search_string = ""; 416 public static String Navit_last_address_search_string = "";
417 public static String Navit_last_address_hn_string = "";
405 public static Boolean Navit_last_address_full_file_search = false; 418 public static Boolean Navit_last_address_full_file_search = false;
406 public static String Navit_last_address_search_country_iso2_string = ""; 419 public static String Navit_last_address_search_country_iso2_string = "";
407 public static int Navit_last_address_search_country_flags = 3; 420 public static int Navit_last_address_search_country_flags = 3;
408 public static int Navit_last_address_search_country_id = 0; 421 public static int Navit_last_address_search_country_id = 0;
409 public static Boolean Navit_last_address_partial_match = false; 422 public static Boolean Navit_last_address_partial_match = false;
453 static int PREF_mapcache = 10 * 1024; // in kbytes 466 static int PREF_mapcache = 10 * 1024; // in kbytes
454 static String PREF_navit_lang; 467 static String PREF_navit_lang;
455 static int PREF_drawatorder = 1; 468 static int PREF_drawatorder = 1;
456 static String PREF_streetsearch_r = "1"; // street search radius factor (multiplier) 469 static String PREF_streetsearch_r = "1"; // street search radius factor (multiplier)
457 static String PREF_route_style = "1"; // 1 -> under green 2 -> on top blue 470 static String PREF_route_style = "1"; // 1 -> under green 2 -> on top blue
471 static String PREF_trafficlights_delay = "0"; // 0 -> dont calc traffic lights delay
458 static Boolean PREF_item_dump = false; 472 static boolean PREF_item_dump = false;
459 static Boolean PREF_use_smooth_drawing = true; 473 static boolean PREF_use_smooth_drawing = true;
474 static boolean PREF_show_route_rects = false;
475 static int PREF_more_map_detail = 0; // 0 -> *normal* , higher values show more detail (and use a lot more CPU!!)
476 static boolean PREF_show_multipolygons = true;
477 static boolean PREF_use_index_search = true;
460 478
461 static Resources res_ = null; 479 static Resources res_ = null;
462 480
463 public static String get_text(String in) 481 public static String get_text(String in)
464 { 482 {
1155 } 1173 }
1156 catch (Exception e) 1174 catch (Exception e)
1157 { 1175 {
1158 e.printStackTrace(); 1176 e.printStackTrace();
1159 } 1177 }
1178
1160 } 1179 }
1161 // show info box for upgrade 1180 // show info box for upgrade
1162 1181
1163 // make handler statically available for use in "msg_to_msg_handler" 1182 // make handler statically available for use in "msg_to_msg_handler"
1164 Navit_progress_h = this.progress_handler; 1183 Navit_progress_h = this.progress_handler;
1171 Log.e("Navit", "Navit -> pixels x=" + width_ + " pixels y=" + height_); 1190 Log.e("Navit", "Navit -> pixels x=" + width_ + " pixels y=" + height_);
1172 Log.e("Navit", "Navit -> dpi=" + Navit.metrics.densityDpi); 1191 Log.e("Navit", "Navit -> dpi=" + Navit.metrics.densityDpi);
1173 Log.e("Navit", "Navit -> density=" + Navit.metrics.density); 1192 Log.e("Navit", "Navit -> density=" + Navit.metrics.density);
1174 Log.e("Navit", "Navit -> scaledDensity=" + Navit.metrics.scaledDensity); 1193 Log.e("Navit", "Navit -> scaledDensity=" + Navit.metrics.scaledDensity);
1175 1194
1176 //System.gc(); 1195 try
1177 System.gc(); 1196 {
1178 Navit.bigmap_bitmap = BitmapFactory.decodeResource(getResources(), R.raw.bigmap_colors_zanavi2); 1197 Navit.bigmap_bitmap = BitmapFactory.decodeResource(getResources(), R.raw.bigmap_colors_zanavi2);
1198 }
1199 catch (Exception e)
1200 {
1201 // when not enough memory is available, then disable large world overview map!
1202 System.gc();
1203 Navit.bigmap_bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
1204 }
1179 // Navit.bigmap_bitmap.setDensity(120); // set our dpi!! 1205 // ------no----- // Navit.bigmap_bitmap.setDensity(120); // set our dpi!!
1180 1206
1181 try 1207 try
1182 { 1208 {
1183 ActivityResults = new NavitActivityResult[16]; 1209 ActivityResults = new NavitActivityResult[16];
1184 setVolumeControlStream(AudioManager.STREAM_MUSIC); 1210 setVolumeControlStream(AudioManager.STREAM_MUSIC);
1453 1479
1454 public static void show_mem_used_real() 1480 public static void show_mem_used_real()
1455 { 1481 {
1456 try 1482 try
1457 { 1483 {
1458 int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
1459
1460 if (PREF_show_debug_messages) 1484 if (PREF_show_debug_messages)
1461 { 1485 {
1486 int usedMegs;
1487 //System.gc();
1488 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
1489 //Debug.MemoryInfo meminfo = new Debug.MemoryInfo();
1490 //Debug.getMemoryInfo(meminfo);
1491
1462 if (usedMegs_old != usedMegs) 1492 if (usedMegs_old != usedMegs)
1463 { 1493 {
1464 String usedMegsString = String.format("Memory Used: %d MB", usedMegs); 1494 String usedMegsString = String.format("Memory Used: %d MB", usedMegs);
1465 // System.out.println("" + usedMegsString); 1495 //System.out.println("" + meminfo.dalvikPrivateDirty + " " + meminfo.dalvikPss + " " + meminfo.dalvikSharedDirty + " nP:" + meminfo.nativePrivateDirty + " nPss:" + meminfo.nativePss + " nSh:" + meminfo.nativeSharedDirty + " o1:" + meminfo.otherPrivateDirty + " o2:" + meminfo.otherPss + " o3:" + meminfo.otherSharedDirty);
1466 Navit.set_debug_messages2(usedMegsString); 1496 Navit.set_debug_messages2(usedMegsString);
1467 } 1497 }
1468 }
1469
1470 usedMegs_old = usedMegs; 1498 usedMegs_old = usedMegs;
1499 }
1471 } 1500 }
1472 catch (Exception e) 1501 catch (Exception e)
1473 { 1502 {
1474 e.printStackTrace(); 1503 e.printStackTrace();
1475 } 1504 }
1947 try 1976 try
1948 { 1977 {
1949 Navit.follow_button_on(); 1978 Navit.follow_button_on();
1950 } 1979 }
1951 catch (Exception e2) 1980 catch (Exception e2)
1981
1952 { 1982 {
1953 e2.printStackTrace(); 1983 e2.printStackTrace();
1954 } 1984 }
1955 } 1985 }
1956 else 1986 else
2412 2442
2413 public void start_targetsearch_from_intent(String target_address) 2443 public void start_targetsearch_from_intent(String target_address)
2414 { 2444 {
2415 Navit_last_address_partial_match = false; 2445 Navit_last_address_partial_match = false;
2416 Navit_last_address_search_string = target_address; 2446 Navit_last_address_search_string = target_address;
2447 Navit_last_address_hn_string = "";
2417 2448
2418 // ----------- CONFIG --------- 2449 // ----------- CONFIG ---------
2419 // ----------- CONFIG --------- 2450 // ----------- CONFIG ---------
2420 // ----------- CONFIG --------- 2451 // ----------- CONFIG ---------
2421 Boolean use_online_searchmode_here = false; 2452 Boolean use_online_searchmode_here = true;
2422 Boolean hide_duplicates_searchmode_here = false; 2453 Boolean hide_duplicates_searchmode_here = false;
2423 // ----------- CONFIG --------- 2454 // ----------- CONFIG ---------
2424 // ----------- CONFIG --------- 2455 // ----------- CONFIG ---------
2425 // ----------- CONFIG --------- 2456 // ----------- CONFIG ---------
2426 2457
2427 int dialog_num_; 2458 int dialog_num_;
2428 2459
2429 if (use_online_searchmode_here) 2460 if (use_online_searchmode_here)
2430 { 2461 {
2431 dialog_num_ = Navit.SEARCHRESULTS_WAIT_DIALOG; 2462 dialog_num_ = Navit.SEARCHRESULTS_WAIT_DIALOG;
2463 Navit.use_index_search = false;
2432 } 2464 }
2433 else 2465 else
2434 { 2466 {
2435 dialog_num_ = Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE; 2467 dialog_num_ = Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE;
2468 Navit.use_index_search = Navit.allow_use_index_search();
2436 } 2469 }
2437 2470
2438 // clear results 2471 // clear results
2439 Navit.NavitAddressResultList_foundItems.clear(); 2472 Navit.NavitAddressResultList_foundItems.clear();
2440 Navit.Navit_Address_Result_double_index.clear(); 2473 Navit.Navit_Address_Result_double_index.clear();
2441 Navit.NavitSearchresultBarIndex = -1; 2474 Navit.NavitSearchresultBarIndex = -1;
2442 Navit.NavitSearchresultBar_title = ""; 2475 Navit.NavitSearchresultBar_title = "";
2443 Navit.NavitSearchresultBar_text = ""; 2476 Navit.NavitSearchresultBar_text = "";
2477 search_hide_duplicates = false;
2444 2478
2445 if (Navit_last_address_search_string.equals("")) 2479 if (Navit_last_address_search_string.equals(""))
2446 { 2480 {
2447 // empty search string entered 2481 // empty search string entered
2448 Toast.makeText(getApplicationContext(), Navit.get_text("No address found"), Toast.LENGTH_LONG).show(); //TRANS 2482 Toast.makeText(getApplicationContext(), Navit.get_text("No address found"), Toast.LENGTH_LONG).show(); //TRANS
2459 e.printStackTrace(); 2493 e.printStackTrace();
2460 } 2494 }
2461 2495
2462 if (hide_duplicates_searchmode_here) 2496 if (hide_duplicates_searchmode_here)
2463 { 2497 {
2498 search_hide_duplicates = true;
2464 // hide duplicates when searching 2499 // hide duplicates when searching
2465 // hide duplicates when searching 2500 // hide duplicates when searching
2466 Message msg22 = new Message(); 2501 Message msg22 = new Message();
2467 Bundle b22 = new Bundle(); 2502 Bundle b22 = new Bundle();
2468 b22.putInt("Callback", 45); 2503 b22.putInt("Callback", 45);
2536 msg.setData(b); 2571 msg.setData(b);
2537 N_NavitGraphics.callback_handler.sendMessage(msg); 2572 N_NavitGraphics.callback_handler.sendMessage(msg);
2538 break; 2573 break;
2539 case 6: 2574 case 6:
2540 // ok startup address search activity (online google maps search) 2575 // ok startup address search activity (online google maps search)
2576 Navit.use_index_search = false;
2541 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class); 2577 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
2542 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS 2578 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
2543 search_intent.putExtra("address_string", Navit_last_address_search_string); 2579 search_intent.putExtra("address_string", Navit_last_address_search_string);
2580 //search_intent.putExtra("hn_string", Navit_last_address_hn_string);
2544 search_intent.putExtra("type", "online"); 2581 search_intent.putExtra("type", "online");
2545 String pm_temp = "0"; 2582 String pm_temp = "0";
2546 if (Navit_last_address_partial_match) 2583 if (Navit_last_address_partial_match)
2547 { 2584 {
2548 pm_temp = "1"; 2585 pm_temp = "1";
2550 search_intent.putExtra("partial_match", pm_temp); 2587 search_intent.putExtra("partial_match", pm_temp);
2551 this.startActivityForResult(search_intent, NavitAddressSearch_id_online); 2588 this.startActivityForResult(search_intent, NavitAddressSearch_id_online);
2552 break; 2589 break;
2553 case 7: 2590 case 7:
2554 // ok startup address search activity (offline binfile search) 2591 // ok startup address search activity (offline binfile search)
2592 Navit.use_index_search = Navit.allow_use_index_search();
2555 Intent search_intent2 = new Intent(this, NavitAddressSearchActivity.class); 2593 Intent search_intent2 = new Intent(this, NavitAddressSearchActivity.class);
2556 search_intent2.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS 2594 search_intent2.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
2557 search_intent2.putExtra("address_string", Navit_last_address_search_string); 2595 search_intent2.putExtra("address_string", Navit_last_address_search_string);
2596 search_intent2.putExtra("hn_string", Navit_last_address_hn_string);
2558 search_intent2.putExtra("type", "offline"); 2597 search_intent2.putExtra("type", "offline");
2559 search_intent2.putExtra("search_country_id", Navit_last_address_search_country_id); 2598 search_intent2.putExtra("search_country_id", Navit_last_address_search_country_id);
2560 2599
2561 String pm_temp2 = "0"; 2600 String pm_temp2 = "0";
2562 if (Navit_last_address_partial_match) 2601 if (Navit_last_address_partial_match)
2814 N_NavitGraphics.callback_handler.sendMessage(msg); 2853 N_NavitGraphics.callback_handler.sendMessage(msg);
2815 2854
2816 msg = new Message(); 2855 msg = new Message();
2817 b = new Bundle(); 2856 b = new Bundle();
2818 b.putInt("Callback", 51); 2857 b.putInt("Callback", 51);
2819 b.putInt("x", Navit.NG__map_main.view.getWidth()); 2858 b.putInt("x", (int) (Navit.NG__map_main.view.getWidth() / 2));
2820 b.putInt("y", Navit.NG__map_main.view.getHeight()); 2859 b.putInt("y", (int) (Navit.NG__map_main.view.getHeight() / 2));
2821 msg.setData(b); 2860 msg.setData(b);
2822 N_NavitGraphics.callback_handler.sendMessage(msg); 2861 N_NavitGraphics.callback_handler.sendMessage(msg);
2823 2862
2824 break; 2863 break;
2825 case 602: 2864 case 602:
2859 N_NavitGraphics.callback_handler.sendMessage(msg); 2898 N_NavitGraphics.callback_handler.sendMessage(msg);
2860 2899
2861 msg = new Message(); 2900 msg = new Message();
2862 b = new Bundle(); 2901 b = new Bundle();
2863 b.putInt("Callback", 51); 2902 b.putInt("Callback", 51);
2864 b.putInt("x", Navit.NG__map_main.view.getWidth()); 2903 b.putInt("x", (int) (Navit.NG__map_main.view.getWidth() / 2));
2904
2865 b.putInt("y", Navit.NG__map_main.view.getHeight()); 2905 b.putInt("y", (int) (Navit.NG__map_main.view.getHeight() / 2));
2866 msg.setData(b); 2906 msg.setData(b);
2867 N_NavitGraphics.callback_handler.sendMessage(msg); 2907 N_NavitGraphics.callback_handler.sendMessage(msg);
2868 2908
2869 break; 2909 break;
2870 case 605: 2910 case 605:
2959 for (int jkl = 1; jkl < 51; jkl++) 2999 for (int jkl = 1; jkl < 51; jkl++)
2960 { 3000 {
2961 File del_map_name_fileSplit = new File(del_map_name + "." + String.valueOf(jkl)); 3001 File del_map_name_fileSplit = new File(del_map_name + "." + String.valueOf(jkl));
2962 del_map_name_fileSplit.delete(); 3002 del_map_name_fileSplit.delete();
2963 } 3003 }
3004 // also remove index file
3005 File del_map_name_file_idx = new File(del_map_name + ".idx");
3006 del_map_name_file_idx.delete();
2964 // remove also any MD5 files for this map that may be on disk 3007 // remove also any MD5 files for this map that may be on disk
2965 try 3008 try
2966 { 3009 {
2967 String tmp = map_full_line.split(":", 2)[1]; 3010 String tmp = map_full_line.split(":", 2)[1];
2968 if (!tmp.equals(NavitMapDownloader.MAP_URL_NAME_UNKNOWN)) 3011 if (!tmp.equals(NavitMapDownloader.MAP_URL_NAME_UNKNOWN))
3074 if (resultCode == Activity.RESULT_OK) 3117 if (resultCode == Activity.RESULT_OK)
3075 { 3118 {
3076 try 3119 try
3077 { 3120 {
3078 String addr = data.getStringExtra("address_string"); 3121 String addr = data.getStringExtra("address_string");
3122 String hn = "";
3123 try
3124 {
3125 // only from offline mask!
3126 hn = data.getStringExtra("hn_string");
3127 }
3128 catch (Exception e)
3129 {
3130 hn = "";
3131 }
3132
3079 Boolean partial_match = false; 3133 Boolean partial_match = false;
3080 try 3134 try
3081 { 3135 {
3082 // only from offline mask! 3136 // only from offline mask!
3083 partial_match = data.getStringExtra("partial_match").equals("1"); 3137 partial_match = data.getStringExtra("partial_match").equals("1");
3092 msg2.setData(b2); 3146 msg2.setData(b2);
3093 N_NavitGraphics.callback_handler.sendMessage(msg2); 3147 N_NavitGraphics.callback_handler.sendMessage(msg2);
3094 3148
3095 if (requestCode == NavitAddressSearch_id_offline) 3149 if (requestCode == NavitAddressSearch_id_offline)
3096 { 3150 {
3151 search_hide_duplicates = false;
3097 try 3152 try
3098 { 3153 {
3099 Boolean hide_dup = data.getStringExtra("hide_dup").equals("1"); 3154 Boolean hide_dup = data.getStringExtra("hide_dup").equals("1");
3100 if (hide_dup) 3155 if (hide_dup)
3101 { 3156 {
3157 search_hide_duplicates = true;
3102 Message msg = new Message(); 3158 Message msg = new Message();
3103 Bundle b = new Bundle(); 3159 Bundle b = new Bundle();
3104 b.putInt("Callback", 45); 3160 b.putInt("Callback", 45);
3105 msg.setData(b); 3161 msg.setData(b);
3106 N_NavitGraphics.callback_handler.sendMessage(msg); 3162 N_NavitGraphics.callback_handler.sendMessage(msg);
3107 } 3163 }
3108 } 3164 }
3109 catch (Exception e) 3165 catch (Exception e)
3110 { 3166 {
3111 } 3167 }
3168 Navit.use_index_search = Navit.allow_use_index_search();
3169 }
3170 else
3171 {
3172 Navit.use_index_search = false;
3112 } 3173 }
3113 3174
3114 Navit_last_address_partial_match = partial_match; 3175 Navit_last_address_partial_match = partial_match;
3115 Navit_last_address_search_string = addr; 3176 Navit_last_address_search_string = addr;
3177 Navit_last_address_hn_string = hn;
3116 3178
3117 try 3179 try
3118 { 3180 {
3119 // only from offline mask! 3181 // only from offline mask!
3120 Navit_last_address_full_file_search = data.getStringExtra("full_file_search").equals("1"); 3182 Navit_last_address_full_file_search = data.getStringExtra("full_file_search").equals("1");
3259 catch (Exception e2) 3321 catch (Exception e2)
3260 { 3322 {
3261 e2.printStackTrace(); 3323 e2.printStackTrace();
3262 } 3324 }
3263 3325
3326 if (Navit.use_index_search)
3327 {
3328 show_geo_on_screen((float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(destination_id).lat), (float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(destination_id).lon));
3329 }
3330 else
3331 {
3264 show_geo_on_screen(Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon); 3332 show_geo_on_screen(Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
3333 }
3265 } 3334 }
3266 else 3335 else
3267 { 3336 {
3268 Log.d("Navit", "adress result list id=" + Integer.parseInt(data.getStringExtra("selected_id"))); 3337 Log.d("Navit", "adress result list id=" + Integer.parseInt(data.getStringExtra("selected_id")));
3269 // get the coords for the destination 3338 // get the coords for the destination
3270 int destination_id = Integer.parseInt(data.getStringExtra("selected_id")); 3339 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
3271 3340
3341 // (float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(destination_id).lat), (float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(destination_id).lon)
3342 // (float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(destination_id).lat)
3343
3272 // ok now set target 3344 // ok now set target
3273 try 3345 try
3274 { 3346 {
3347 if (Navit.use_index_search)
3348 {
3349 Navit.remember_destination(Navit.NavitAddressResultList_foundItems.get(destination_id).addr, (float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(destination_id).lat), (float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(destination_id).lon));
3350 }
3351 else
3352 {
3275 Navit.remember_destination(Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon); 3353 Navit.remember_destination(Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
3354 }
3276 // save points 3355 // save points
3277 write_map_points(); 3356 write_map_points();
3278 } 3357 }
3279 catch (Exception e) 3358 catch (Exception e)
3280 { 3359 {
3281 e.printStackTrace(); 3360 e.printStackTrace();
3282 } 3361 }
3283 3362
3363 // DEBUG: clear route rectangle list
3364 NavitGraphics.route_rects.clear();
3365
3284 if (NavitGraphics.navit_route_status == 0) 3366 if (NavitGraphics.navit_route_status == 0)
3285 { 3367 {
3286 Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS 3368 Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS
3287 Navit.destination_set(); 3369 Navit.destination_set();
3288 3370
3289 Message msg = new Message(); 3371 Message msg = new Message();
3290 Bundle b = new Bundle(); 3372 Bundle b = new Bundle();
3291 b.putInt("Callback", 3); 3373 b.putInt("Callback", 3);
3374 if (Navit.use_index_search)
3375 {
3376 b.putString("lat", String.valueOf((float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(destination_id).lat)));
3377 b.putString("lon", String.valueOf((float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(destination_id).lon)));
3378 }
3379 else
3380 {
3292 b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lat)); 3381 b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lat));
3293 b.putString("lon", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lon)); 3382 b.putString("lon", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lon));
3383 }
3294 b.putString("q", Navit.NavitAddressResultList_foundItems.get(destination_id).addr); 3384 b.putString("q", Navit.NavitAddressResultList_foundItems.get(destination_id).addr);
3295 msg.setData(b); 3385 msg.setData(b);
3296 N_NavitGraphics.callback_handler.sendMessage(msg); 3386 N_NavitGraphics.callback_handler.sendMessage(msg);
3297 } 3387 }
3298 else 3388 else
3299 { 3389 {
3300 Toast.makeText(getApplicationContext(), Navit.get_text("new Waypoint") + "\n" + Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS 3390 Toast.makeText(getApplicationContext(), Navit.get_text("new Waypoint") + "\n" + Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS
3301 Message msg = new Message(); 3391 Message msg = new Message();
3302 Bundle b = new Bundle(); 3392 Bundle b = new Bundle();
3303 b.putInt("Callback", 48); 3393 b.putInt("Callback", 48);
3394 if (Navit.use_index_search)
3395 {
3396 b.putString("lat", String.valueOf((float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(destination_id).lat)));
3397 b.putString("lon", String.valueOf((float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(destination_id).lon)));
3398 }
3399 else
3400 {
3304 b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lat)); 3401 b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lat));
3305 b.putString("lon", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lon)); 3402 b.putString("lon", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lon));
3403 }
3306 b.putString("q", Navit.NavitAddressResultList_foundItems.get(destination_id).addr); 3404 b.putString("q", Navit.NavitAddressResultList_foundItems.get(destination_id).addr);
3307 msg.setData(b); 3405 msg.setData(b);
3308 N_NavitGraphics.callback_handler.sendMessage(msg); 3406 N_NavitGraphics.callback_handler.sendMessage(msg);
3309 } 3407 }
3310 3408
3324 catch (Exception e2) 3422 catch (Exception e2)
3325 { 3423 {
3326 e2.printStackTrace(); 3424 e2.printStackTrace();
3327 } 3425 }
3328 3426
3427 if (Navit.use_index_search)
3428 {
3429 show_geo_on_screen((float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(destination_id).lat), (float) Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(destination_id).lon));
3430 }
3431 else
3432 {
3329 show_geo_on_screen(Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon); 3433 show_geo_on_screen(Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
3434 }
3330 } 3435 }
3331 } 3436 }
3332 catch (NumberFormatException e) 3437 catch (NumberFormatException e)
3333 { 3438 {
3334 Log.d("Navit", "NumberFormatException selected_id"); 3439 Log.d("Navit", "NumberFormatException selected_id");
3436 catch (Exception e) 3541 catch (Exception e)
3437 { 3542 {
3438 e.printStackTrace(); 3543 e.printStackTrace();
3439 } 3544 }
3440 3545
3546 // DEBUG: clear route rectangle list
3547 NavitGraphics.route_rects.clear();
3548
3441 if (NavitGraphics.navit_route_status == 0) 3549 if (NavitGraphics.navit_route_status == 0)
3442 { 3550 {
3443 Navit.destination_set(); 3551 Navit.destination_set();
3444 3552
3445 Message msg = new Message(); 3553 Message msg = new Message();
3510 3618
3511 // ok now set target 3619 // ok now set target
3512 String dest_name = Navit.map_points.get(destination_id).point_name; 3620 String dest_name = Navit.map_points.get(destination_id).point_name;
3513 float lat = Navit.map_points.get(destination_id).lat; 3621 float lat = Navit.map_points.get(destination_id).lat;
3514 float lon = Navit.map_points.get(destination_id).lon; 3622 float lon = Navit.map_points.get(destination_id).lon;
3623
3624 // DEBUG: clear route rectangle list
3625 NavitGraphics.route_rects.clear();
3515 3626
3516 if (NavitGraphics.navit_route_status == 0) 3627 if (NavitGraphics.navit_route_status == 0)
3517 { 3628 {
3518 Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + dest_name, Toast.LENGTH_LONG).show(); //TRANS 3629 Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + dest_name, Toast.LENGTH_LONG).show(); //TRANS
3519 Navit.destination_set(); 3630 Navit.destination_set();
3631 3742
3632 Navit x; 3743 Navit x;
3633 String lang; 3744 String lang;
3634 int version; 3745 int version;
3635 String display_density_string; 3746 String display_density_string;
3747 int timeout_loop_counter = 0;
3636 3748
3637 private final LinkedBlockingQueue<CMC_object> queue = new LinkedBlockingQueue<CMC_object>(); 3749 private final LinkedBlockingQueue<CMC_object> queue = new LinkedBlockingQueue<CMC_object>();
3638 private final LinkedBlockingQueue<Integer> queue2 = new LinkedBlockingQueue<Integer>(); 3750 private final LinkedBlockingQueue<Integer> queue2 = new LinkedBlockingQueue<Integer>();
3639 private final LinkedBlockingQueue<MCB_object> queue3 = new LinkedBlockingQueue<MCB_object>(); 3751 private final LinkedBlockingQueue<MCB_object> queue3 = new LinkedBlockingQueue<MCB_object>();
3640 private final LinkedBlockingQueue<TCB_object> queue4 = new LinkedBlockingQueue<TCB_object>(); 3752 private final LinkedBlockingQueue<TCB_object> queue4 = new LinkedBlockingQueue<TCB_object>();
3662 tcbo.del = del; 3774 tcbo.del = del;
3663 tcbo.id = id; 3775 tcbo.id = id;
3664 tcbo.nt = nt; 3776 tcbo.nt = nt;
3665 queue4.offer(tcbo); 3777 queue4.offer(tcbo);
3666 this.interrupt(); 3778 this.interrupt();
3779 //timeout_loop_counter++;
3780
3781 //if (timeout_loop_counter > 100)
3782 //{
3783 // timeout_loop_counter = 0;
3784 // // run GC at every 100th loop
3785 // // System.gc();
3786 //}
3667 } 3787 }
3668 3788
3669 public void CallbackMessageChannel(int i, String s) 3789 public void CallbackMessageChannel(int i, String s)
3670 { 3790 {
3671 CMC_object cmco = new CMC_object(); 3791 CMC_object cmco = new CMC_object();
3686 this.interrupt(); 3806 this.interrupt();
3687 } 3807 }
3688 3808
3689 public void NavitActivity2(int i) 3809 public void NavitActivity2(int i)
3690 { 3810 {
3691 queue2.offer(new Integer(i)); 3811 queue2.offer(Integer.valueOf(i));
3692 this.interrupt(); 3812 this.interrupt();
3693 } 3813 }
3694 3814
3695 public void CallbackGeoCalc2(int type, int a, float b, float c) 3815 public void CallbackGeoCalc2(int type, int a, float b, float c)
3696 { 3816 {
3799 // 3919 //
3800 // 3920 //
3801 // SUN ---------------- 3921 // SUN ----------------
3802 // 3922 //
3803 // 3923 //
3924 try
3925 {
3804 this.calc_sun_stats(); 3926 this.calc_sun_stats();
3927 }
3928 catch (Exception e)
3929 {
3930 // on some systems BigInteger seems to crash, or maybe some values are out of range
3931 // until the bug is found, night modus is deactivated
3932 calc_sun_enabled = false;
3933 is_twilight = false;
3934 is_night = false;
3935 }
3805 //System.out.println("sunrise: " + sunrise_cache); 3936 //System.out.println("sunrise: " + sunrise_cache);
3806 //System.out.println("sunset: " + sunset_cache); 3937 //System.out.println("sunset: " + sunset_cache);
3807 //System.out.println("azimuth: " + roundTwoDecimals(azmiuth_cache)); 3938 //System.out.println("azimuth: " + roundTwoDecimals(azmiuth_cache));
3808 //System.out.println("elevation: " + elevation); 3939 //System.out.println("elevation: " + elevation);
3809 // 3940 //
3816 public void run() 3947 public void run()
3817 { 3948 {
3818 //System.out.println("CWorkerThread -- started --"); 3949 //System.out.println("CWorkerThread -- started --");
3819 while (this.running) 3950 while (this.running)
3820 { 3951 {
3952 if (queue4.size() == 0)
3953 {
3821 try 3954 try
3822 { 3955 {
3823 Thread.sleep(20000); // 20 secs. 3956 Thread.sleep(20000); // 20 secs.
3824 } 3957 }
3825 catch (InterruptedException e) 3958 catch (InterruptedException e)
3826 { 3959 {
3960 }
3827 } 3961 }
3828 3962
3829 if (this.startmain) 3963 if (this.startmain)
3830 { 3964 {
3831 //System.out.println("CWorkerThread:startup_calls:JTHREAD ID=" + this.getId()); 3965 //System.out.println("CWorkerThread:startup_calls:JTHREAD ID=" + this.getId());
3834 this.startmain = false; 3968 this.startmain = false;
3835 System.out.println("CWorkerThread -- NavitMain --"); 3969 System.out.println("CWorkerThread -- NavitMain --");
3836 NavitMain(x, lang, version, display_density_string); 3970 NavitMain(x, lang, version, display_density_string);
3837 System.out.println("CWorkerThread -- NavitActivity(3) --"); 3971 System.out.println("CWorkerThread -- NavitActivity(3) --");
3838 NavitActivity(3); 3972 NavitActivity(3);
3973
3974 // -- set map detail level (after app startup) --
3975 // -- set map detail level (after app startup) --
3976 // -- set map detail level (after app startup) --
3977 try
3978 {
3979 getPrefs_more_map_detail();
3980 if (PREF_more_map_detail > 0)
3981 {
3982 Message msg2 = new Message();
3983 Bundle b2 = new Bundle();
3984 b2.putInt("Callback", 78);
3985 b2.putString("s", "" + PREF_more_map_detail);
3986 msg2.setData(b2);
3987 N_NavitGraphics.callback_handler.sendMessage(msg2);
3988 }
3989 }
3990 catch (Exception e)
3991 {
3992 // e.printStackTrace();
3993 }
3994 // -- set map detail level (after app startup) --
3995 // -- set map detail level (after app startup) --
3996 // -- set map detail level (after app startup) --
3839 3997
3840 Global_Init_Finished = 1; 3998 Global_Init_Finished = 1;
3841 //x.runOnUiThread(new Runnable() 3999 //x.runOnUiThread(new Runnable()
3842 //{ 4000 //{
3843 // public void run() 4001 // public void run()
3912 { 4070 {
3913 } 4071 }
3914 4072
3915 } 4073 }
3916 4074
3917 while (queue4.size() > 0) 4075 int count_timeout_callbacks = 0;
4076 while (count_timeout_callbacks < 100 && queue4.size() > 0)
3918 { 4077 {
4078 count_timeout_callbacks++;
3919 try 4079 try
3920 { 4080 {
3921 // blocking call 4081 // blocking call
3922 // l5 = queue4.take(); 4082 // l5 = queue4.take();
3923 // non-blocking call 4083 // non-blocking call
4257 { 4417 {
4258 // start the search, this could take a long time!! 4418 // start the search, this could take a long time!!
4259 Log.e("Navit", "SearchResultsThread run1"); 4419 Log.e("Navit", "SearchResultsThread run1");
4260 // need lowercase to find stuff !! 4420 // need lowercase to find stuff !!
4261 Navit_last_address_search_string = filter_bad_chars(Navit_last_address_search_string).toLowerCase(); 4421 Navit_last_address_search_string = filter_bad_chars(Navit_last_address_search_string).toLowerCase();
4422 if ((Navit_last_address_hn_string != null) && (Navit_last_address_hn_string.equals("")))
4423 {
4424 Navit_last_address_hn_string = filter_bad_chars(Navit_last_address_hn_string).toLowerCase();
4425 }
4426
4262 if (Navit_last_address_full_file_search) 4427 if (Navit_last_address_full_file_search)
4263 { 4428 {
4264 // flags (18) -> order level to search at 4429 // flags (18) -> order level to search at
4265 // ================ 4430 // ================
4266 // 0#0 0 -> search full world 4431 // 0#0 0 -> search full world
4267 // lat#lon radius -> search only this area, around lat,lon 4432 // lat#lon radius -> search only this area, around lat,lon
4268 // ================ 4433 // ================
4269 N_NavitGraphics.SearchResultList(3, partial_match_i, Navit_last_address_search_string, 18, Navit_last_address_search_country_iso2_string, "0#0", 0); 4434 N_NavitGraphics.SearchResultList(3, partial_match_i, Navit_last_address_search_string, "", "", 18, Navit_last_address_search_country_iso2_string, "0#0", 0);
4270 } 4435 }
4271 else 4436 else
4272 { 4437 {
4438 if (Navit.use_index_search)
4439 {
4440 // new method with index search
4441 // -----------------
4442 //Navit_last_address_search_string
4443 String street_ = "";
4444 String town_ = "";
4445 String hn_ = Navit_last_address_hn_string;
4446
4447 int last_space = Navit_last_address_search_string.lastIndexOf(" ");
4448 if (last_space != -1)
4449 {
4450 street_ = Navit_last_address_search_string.substring(0, last_space);
4451 town_ = Navit_last_address_search_string.substring(last_space);
4452 }
4453 else
4454 {
4455 street_ = Navit_last_address_search_string;
4456 town_ = "";
4457 }
4458 N_NavitGraphics.SearchResultList(2, partial_match_i, street_, town_, hn_, Navit_last_address_search_country_flags, Navit_last_address_search_country_iso2_string, "0#0", 0);
4459
4460 // sort result list
4461 Collections.sort(Navit.NavitAddressResultList_foundItems);
4462 }
4463 else
4464 {
4465 // old method search
4466 // -----------------
4273 // flags --> 3: search all countries 4467 // flags --> 3: search all countries
4274 // 2: search <iso2 string> country 4468 // 2: search <iso2 string> country
4275 // 1: search default country (what you have set as language in prefs) 4469 // 1: search default country (what you have set as language in prefs)
4276 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); 4470 N_NavitGraphics.SearchResultList(29, partial_match_i, Navit_last_address_search_string, "", "", Navit_last_address_search_country_flags, Navit_last_address_search_country_iso2_string, "0#0", 0);
4471
4472 // sort result list
4473 Collections.sort(Navit.NavitAddressResultList_foundItems);
4474 }
4277 } 4475 }
4278 Log.e("Navit", "SearchResultsThread run2"); 4476 Log.e("Navit", "SearchResultsThread run2");
4279 } 4477 }
4280 else if (this.my_dialog_num == Navit.SEARCHRESULTS_WAIT_DIALOG) 4478 else if (this.my_dialog_num == Navit.SEARCHRESULTS_WAIT_DIALOG)
4281 { 4479 {
4389 { 4587 {
4390 String out = in; 4588 String out = in;
4391 out = out.replaceAll("\\n", " "); // newline -> space 4589 out = out.replaceAll("\\n", " "); // newline -> space
4392 out = out.replaceAll("\\r", " "); // return -> space 4590 out = out.replaceAll("\\r", " "); // return -> space
4393 out = out.replaceAll("\\t", " "); // tab -> space 4591 out = out.replaceAll("\\t", " "); // tab -> space
4592 out = out.trim();
4394 return out; 4593 return out;
4395 } 4594 }
4396 4595
4397 public static void msg_to_msg_handler(Bundle b, int id) 4596 public static void msg_to_msg_handler(Bundle b, int id)
4398 { 4597 {
4719 case Navit.MAPDOWNLOAD_SEC_DIALOG: 4918 case Navit.MAPDOWNLOAD_SEC_DIALOG:
4720 mapdownloader_dialog_sec = new ProgressDialog(this); 4919 mapdownloader_dialog_sec = new ProgressDialog(this);
4721 mapdownloader_dialog_sec.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 4920 mapdownloader_dialog_sec.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
4722 mapdownloader_dialog_sec.setTitle("--"); 4921 mapdownloader_dialog_sec.setTitle("--");
4723 mapdownloader_dialog_sec.setMessage("--"); 4922 mapdownloader_dialog_sec.setMessage("--");
4923
4724 mapdownloader_dialog_sec.setCancelable(true); 4924 mapdownloader_dialog_sec.setCancelable(true);
4725 mapdownloader_dialog_sec.setProgress(0); 4925 mapdownloader_dialog_sec.setProgress(0);
4726 mapdownloader_dialog_sec.setMax(200); 4926 mapdownloader_dialog_sec.setMax(200);
4727 DialogInterface.OnDismissListener mOnDismissListener2 = new DialogInterface.OnDismissListener() 4927 DialogInterface.OnDismissListener mOnDismissListener2 = new DialogInterface.OnDismissListener()
4728 { 4928 {
4830 { 5030 {
4831 N_NavitGraphics.callback_handler.sendMessage(msg); 5031 N_NavitGraphics.callback_handler.sendMessage(msg);
4832 } 5032 }
4833 catch (Exception e) 5033 catch (Exception e)
4834 { 5034 {
5035 e.printStackTrace();
4835 } 5036 }
4836 // hold all map drawing ----------- 5037 // hold all map drawing -----------
4837 5038
4838 getPrefs(); 5039 getPrefs();
4839 activatePrefs(1); 5040 activatePrefs(1);
4847 { 5048 {
4848 N_NavitGraphics.callback_handler.sendMessage(msg); 5049 N_NavitGraphics.callback_handler.sendMessage(msg);
4849 } 5050 }
4850 catch (Exception e) 5051 catch (Exception e)
4851 { 5052 {
5053 e.printStackTrace();
4852 } 5054 }
4853 // follow mode ON ----------- 5055 // follow mode ON -----------
4854 5056
4855 // allow all map drawing ----------- 5057 // allow all map drawing -----------
4856 msg = new Message(); 5058 msg = new Message();
4897 } 5099 }
4898 5100
4899 public static void toggle_follow_button() 5101 public static void toggle_follow_button()
4900 { 5102 {
4901 // the "red needle" OSD calls this function only!! 5103 // the "red needle" OSD calls this function only!!
5104 //Log.e("NavitVehicle", "toggle_follow_button");
4902 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_); 5105 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
4903 SharedPreferences.Editor editor = prefs.edit(); 5106 SharedPreferences.Editor editor = prefs.edit();
4904 if (PREF_follow_gps) 5107 if (PREF_follow_gps)
4905 { 5108 {
4906 Navit.follow_current = Navit.follow_off; 5109 Navit.follow_current = Navit.follow_off;
4915 { 5118 {
4916 N_NavitGraphics.callback_handler.sendMessage(msg); 5119 N_NavitGraphics.callback_handler.sendMessage(msg);
4917 } 5120 }
4918 catch (Exception e) 5121 catch (Exception e)
4919 { 5122 {
5123 e.printStackTrace();
4920 } 5124 }
4921 // follow mode OFF ----------- 5125 // follow mode OFF -----------
4922 } 5126 }
4923 else 5127 else
4924 { 5128 {
4934 { 5138 {
4935 N_NavitGraphics.callback_handler.sendMessage(msg); 5139 N_NavitGraphics.callback_handler.sendMessage(msg);
4936 } 5140 }
4937 catch (Exception e) 5141 catch (Exception e)
4938 { 5142 {
5143 e.printStackTrace();
4939 } 5144 }
4940 // follow mode ON ----------- 5145 // follow mode ON -----------
4941 } 5146 }
4942 editor.putBoolean("follow_gps", PREF_follow_gps); 5147 editor.putBoolean("follow_gps", PREF_follow_gps);
4943 editor.commit(); 5148 editor.commit();
4961 { 5166 {
4962 N_NavitGraphics.callback_handler.sendMessage(msg); 5167 N_NavitGraphics.callback_handler.sendMessage(msg);
4963 } 5168 }
4964 catch (Exception e) 5169 catch (Exception e)
4965 { 5170 {
5171 e.printStackTrace();
4966 } 5172 }
4967 // hold all map drawing ----------- 5173 // hold all map drawing -----------
4968 5174
4969 getPrefs(); 5175 getPrefs();
4970 activatePrefs(1); 5176 activatePrefs(1);
5000 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_); 5206 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
5001 SharedPreferences.Editor editor = prefs.edit(); 5207 SharedPreferences.Editor editor = prefs.edit();
5002 editor.putInt("zoomlevel_num", Navit.GlobalScaleLevel); 5208 editor.putInt("zoomlevel_num", Navit.GlobalScaleLevel);
5003 editor.commit(); 5209 editor.commit();
5004 System.out.println("2 save zoom level: " + Navit.GlobalScaleLevel); 5210 System.out.println("2 save zoom level: " + Navit.GlobalScaleLevel);
5211 }
5212
5213 private static void getPrefs_more_map_detail()
5214 {
5215 int ret = 0;
5216 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
5217 try
5218 {
5219 PREF_more_map_detail = Integer.parseInt(prefs.getString("more_map_detail", "0"));
5220 }
5221 catch (Exception e)
5222 {
5223 PREF_more_map_detail = 0;
5224 }
5005 } 5225 }
5006 5226
5007 private static void getPrefs() 5227 private static void getPrefs()
5008 { 5228 {
5009 // Get the xml/preferences.xml preferences 5229 // Get the xml/preferences.xml preferences
5035 PREF_use_custom_font = prefs.getBoolean("use_custom_font", true); 5255 PREF_use_custom_font = prefs.getBoolean("use_custom_font", true);
5036 PREF_draw_polyline_circles = prefs.getBoolean("draw_polyline_circles", true); 5256 PREF_draw_polyline_circles = prefs.getBoolean("draw_polyline_circles", true);
5037 PREF_streetsearch_r = prefs.getString("streetsearch_r", "2"); 5257 PREF_streetsearch_r = prefs.getString("streetsearch_r", "2");
5038 PREF_route_style = prefs.getString("route_style", "2"); 5258 PREF_route_style = prefs.getString("route_style", "2");
5039 PREF_item_dump = prefs.getBoolean("item_dump", false); 5259 PREF_item_dump = prefs.getBoolean("item_dump", false);
5260 PREF_show_route_rects = prefs.getBoolean("show_route_rects", false);
5261 PREF_trafficlights_delay = prefs.getString("trafficlights_delay", "0");
5262
5263 PREF_show_multipolygons = prefs.getBoolean("show_multipolygons", true);
5264 PREF_use_index_search = prefs.getBoolean("use_index_search", true);
5040 5265
5041 try 5266 try
5042 { 5267 {
5043 PREF_drawatorder = Integer.parseInt(prefs.getString("drawatorder", "0")); 5268 PREF_drawatorder = Integer.parseInt(prefs.getString("drawatorder", "0"));
5044 } 5269 }
5534 catch (Exception e) 5759 catch (Exception e)
5535 { 5760 {
5536 } 5761 }
5537 // route variant 5762 // route variant
5538 5763
5764 // show route rectanlges -----
5765 if (PREF_show_route_rects)
5766 {
5767 msg67 = new Message();
5768 b67 = new Bundle();
5769 b67.putInt("Callback", 76);
5770 msg67.setData(b67);
5771 try
5772 {
5773 N_NavitGraphics.callback_handler.sendMessage(msg67);
5774 }
5775 catch (Exception e)
5776 {
5777 }
5778 }
5779 else
5780 {
5781 msg67 = new Message();
5782 b67 = new Bundle();
5783 b67.putInt("Callback", 77);
5784 msg67.setData(b67);
5785 try
5786 {
5787 N_NavitGraphics.callback_handler.sendMessage(msg67);
5788 }
5789 catch (Exception e)
5790 {
5791 }
5792 }
5793 // show route rectanlges -----
5794
5795 // show route multipolygons -----
5796 if (PREF_show_multipolygons)
5797 {
5798 msg67 = new Message();
5799 b67 = new Bundle();
5800 b67.putInt("Callback", 66);
5801 msg67.setData(b67);
5802 try
5803 {
5804 N_NavitGraphics.callback_handler.sendMessage(msg67);
5805 }
5806 catch (Exception e)
5807 {
5808 }
5809 }
5810 else
5811 {
5812 msg67 = new Message();
5813 b67 = new Bundle();
5814 b67.putInt("Callback", 67);
5815 msg67.setData(b67);
5816 try
5817 {
5818 N_NavitGraphics.callback_handler.sendMessage(msg67);
5819 }
5820 catch (Exception e)
5821 {
5822 }
5823 }
5824 // show route multipolygons -----
5825
5826 // traffic lights delay ----
5827 msg67 = new Message();
5828 b67 = new Bundle();
5829 b67.putInt("Callback", 79);
5830 System.out.println("traffic lights delay:" + PREF_trafficlights_delay);
5831 // (PREF_trafficlights_delay / 10) seconds delay for each traffic light
5832 b67.putString("s", PREF_trafficlights_delay); // (delay in 1/10 of a second)
5833 msg67.setData(b67);
5834 try
5835 {
5836 N_NavitGraphics.callback_handler.sendMessage(msg67);
5837 }
5838 catch (Exception e)
5839 {
5840 }
5841 // traffic lights delay ----
5842
5539 // set vars for mapdir change (only really takes effect after restart!) 5843 // set vars for mapdir change (only really takes effect after restart!)
5540 getPrefs_mapdir(); 5844 getPrefs_mapdir();
5541 } 5845 }
5542 5846
5543 private static void getPrefs_mapdir() 5847 private static void getPrefs_mapdir()
5576 NavitDataDirectory_Maps = sanity_check_maps_dir(NavitDataDirectory_Maps); 5880 NavitDataDirectory_Maps = sanity_check_maps_dir(NavitDataDirectory_Maps);
5577 MAP_FILENAME_PATH = NavitDataDirectory_Maps; 5881 MAP_FILENAME_PATH = NavitDataDirectory_Maps;
5578 MAPMD5_FILENAME_PATH = NavitDataDirectory_Maps + "/../md5/"; 5882 MAPMD5_FILENAME_PATH = NavitDataDirectory_Maps + "/../md5/";
5579 CFG_FILENAME_PATH = NavitDataDirectory_Maps + "/../"; 5883 CFG_FILENAME_PATH = NavitDataDirectory_Maps + "/../";
5580 5884
5581 System.out.println("xxxxxxxx************XXXXXXXXXXX"); 5885 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
5582 System.out.println("xxxxxxxx************XXXXXXXXXXX"); 5886 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
5583 System.out.println("xxxxxxxx************XXXXXXXXXXX"); 5887 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
5584 System.out.println("xxxxxxxx************XXXXXXXXXXX"); 5888 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
5585 System.out.println("xxxxxxxx************XXXXXXXXXXX"); 5889 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
5586 System.out.println("xxxxxxxx************XXXXXXXXXXX"); 5890 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
5587 System.out.println("xxxxxxxx************XXXXXXXXXXX"); 5891 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
5588 System.out.println("xxxxxxxx************XXXXXXXXXXX"); 5892 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
5589 System.out.println("xxxxxxxx************XXXXXXXXXXX"); 5893 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
5590 5894
5591 Handler h_temp = null; 5895 Handler h_temp = null;
5592 h_temp = NavitGraphics.callback_handler_s; 5896 h_temp = NavitGraphics.callback_handler_s;
5593 System.out.println("handler 1=" + h_temp.toString()); 5897 //System.out.println("handler 1=" + h_temp.toString());
5594 5898
5595 Message msg1 = new Message(); 5899 Message msg1 = new Message();
5596 Bundle b1 = new Bundle(); 5900 Bundle b1 = new Bundle();
5597 b1.putInt("Callback", 47); 5901 b1.putInt("Callback", 47);
5598 b1.putString("s", MAP_FILENAME_PATH); 5902 b1.putString("s", MAP_FILENAME_PATH);
5685 5989
5686 /* 5990 /*
5687 * Show a search activity with the string "search" filled in 5991 * Show a search activity with the string "search" filled in
5688 */ 5992 */
5689 private void executeSearch(String search) 5993 private void executeSearch(String search)
5690
5691 { 5994 {
5995 Navit.use_index_search = Navit.allow_use_index_search();
5692 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class); 5996 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
5693 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS 5997 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
5694 search_intent.putExtra("address_string", search); 5998 search_intent.putExtra("address_string", search);
5695 search_intent.putExtra("type", "offline"); 5999 search_intent.putExtra("type", "offline");
5696 search_intent.putExtra("search_country_id", Navit_last_address_search_country_id); 6000 search_intent.putExtra("search_country_id", Navit_last_address_search_country_id);
6095 6399
6096 public String roundTwoDecimals(double d) 6400 public String roundTwoDecimals(double d)
6097 { 6401 {
6098 return String.format("%.2f", d); 6402 return String.format("%.2f", d);
6099 } 6403 }
6404
6405 public static int transform_from_geo_lat(double lat)
6406 {
6407 /* slower */
6408 // int ret = log(tan(M_PI_4 + lat * M_PI / 360)) * 6371000.0;
6409 /* slower */
6410
6411 /* fast */
6412 int ret = (int) (Math.log(Math.tan((Math.PI / 4f) + lat * 0.008726646259971647884618)) * 6371000.0f); // already calced (M_PI/360)
6413 /* fast */
6414
6415 return ret;
6416 }
6417
6418 public static int transform_from_geo_lon(double lon)
6419 {
6420 /* slower */
6421 // int ret = lon * 6371000.0 * M_PI / 180;
6422 /* slower */
6423
6424 /* fast */
6425 int ret = (int) (lon * 111194.9266445587373); // already calced (6371000.0*M_PI/180)
6426 /* fast */
6427
6428 return ret;
6429 }
6430
6431 public static double transform_to_geo_lat(float lat) // y
6432 {
6433 return (Math.atan(Math.exp(lat / 6371000.0)) / Math.PI * 360 - 90);
6434 }
6435
6436 public static double transform_to_geo_lon(float lon) // x
6437 {
6438 // g->lng=c->x/6371000.0/M_PI*180;
6439 return (lon * 0.00000899322); // simpler
6440 }
6441
6442 public static boolean allow_use_index_search()
6443 {
6444 if ((!Navit_DonateVersion_Installed) && (!Navit_Largemap_DonateVersion_Installed))
6445 {
6446 // no donate version installed
6447 Log.e("Navit", "no donate version installed");
6448 return false;
6449 }
6450
6451 if (!PREF_use_index_search)
6452 {
6453 // user does not want to use index search (it was disabled via preferences)
6454 return false;
6455 }
6456
6457 // MAP_FILENAME_PATH
6458 File folder = new File(MAP_FILENAME_PATH);
6459 File[] listOfFiles = folder.listFiles();
6460
6461 for (File file : listOfFiles)
6462 {
6463 if (file.isFile())
6464 {
6465 System.out.println(file.getName());
6466 if (file.getName().endsWith(".bin.idx"))
6467 {
6468 return true;
6469 }
6470 }
6471 }
6472 return false;
6473 }
6100} 6474}

Legend:
Removed from v.30  
changed lines
  Added in v.31

   
Visit the ZANavi Wiki