/[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 21 Revision 22
38 38
39package com.zoffcc.applications.zanavi; 39package com.zoffcc.applications.zanavi;
40 40
41import java.io.File; 41import java.io.File;
42import java.io.FileInputStream; 42import java.io.FileInputStream;
43import java.io.FileNotFoundException;
43import java.io.FileOutputStream; 44import java.io.FileOutputStream;
45import java.io.IOException;
44import java.io.InputStream; 46import java.io.InputStream;
47import java.io.ObjectInputStream;
48import java.io.ObjectOutputStream;
49import java.io.Serializable;
45import java.net.URLDecoder; 50import java.net.URLDecoder;
46import java.util.ArrayList; 51import java.util.ArrayList;
47import java.util.HashSet; 52import java.util.HashSet;
48import java.util.List; 53import java.util.List;
49import java.util.Locale; 54import java.util.Locale;
56import android.content.Context; 61import android.content.Context;
57import android.content.DialogInterface; 62import android.content.DialogInterface;
58import android.content.DialogInterface.OnCancelListener; 63import android.content.DialogInterface.OnCancelListener;
59import android.content.Intent; 64import android.content.Intent;
60import android.content.SharedPreferences; 65import android.content.SharedPreferences;
66import android.content.pm.PackageInfo;
61import android.content.pm.PackageManager.NameNotFoundException; 67import android.content.pm.PackageManager.NameNotFoundException;
62import android.content.res.Configuration; 68import android.content.res.Configuration;
63import android.content.res.Resources; 69import android.content.res.Resources;
64import android.graphics.Bitmap; 70import android.graphics.Bitmap;
65import android.graphics.BitmapFactory; 71import android.graphics.BitmapFactory;
87import android.util.TypedValue; 93import android.util.TypedValue;
88import android.view.Display; 94import android.view.Display;
89import android.view.Gravity; 95import android.view.Gravity;
90import android.view.Menu; 96import android.view.Menu;
91import android.view.MenuItem; 97import android.view.MenuItem;
98import android.view.View;
92import android.view.Window; 99import android.view.Window;
93import android.view.WindowManager; 100import android.view.WindowManager;
94import android.view.inputmethod.InputMethodManager; 101import android.view.inputmethod.InputMethodManager;
95import android.widget.RelativeLayout; 102import android.widget.RelativeLayout;
96import android.widget.TextView; 103import android.widget.TextView;
97import android.widget.Toast; 104import android.widget.Toast;
98 105
106import com.casadelgato.widgets.NumberPicker;
99import com.zoffcc.applications.zanavi.NavitMapDownloader.ProgressThread; 107import com.zoffcc.applications.zanavi.NavitMapDownloader.ProgressThread;
100 108
101public class Navit extends Activity implements Handler.Callback, SensorEventListener 109public class Navit extends Activity implements Handler.Callback, SensorEventListener
102{ 110{
103 public static final String VERSION_TEXT_LONG_INC_REV = "v1.0.0-930"; 111 public static final String VERSION_TEXT_LONG_INC_REV = "954";
104 public static String NavitAppVersion = "0"; 112 public static String NavitAppVersion = "0";
105 public static String NavitAppVersion_prev = "-1"; 113 public static String NavitAppVersion_prev = "-1";
106 public static String NavitAppVersion_string = "0"; 114 public static String NavitAppVersion_string = "0";
107 private Boolean xmlconfig_unpack_file = true; 115 private Boolean xmlconfig_unpack_file = true;
108 private Boolean write_new_version_file = true; 116 private Boolean write_new_version_file = true;
109 final static int Navit_Status_COMPLETE_NEW_INSTALL = 1; 117 final static int Navit_Status_COMPLETE_NEW_INSTALL = 1;
110 final static int Navit_Status_UPGRADED_TO_NEW_VERSION = 2; 118 final static int Navit_Status_UPGRADED_TO_NEW_VERSION = 2;
111 final static int Navit_Status_NORMAL_STARTUP = 0; 119 final static int Navit_Status_NORMAL_STARTUP = 0;
120 Boolean Navit_DonateVersion_Installed = false;
112 private int startup_status = Navit_Status_NORMAL_STARTUP; 121 private int startup_status = Navit_Status_NORMAL_STARTUP;
122 final static int Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL = 8;
123 static Boolean unsupported = false;
113 124
114 // for future use ... 125 // for future use ...
115 public static String NavitDataDirectory = "/sdcard/"; 126 public static String NavitDataDirectory = "/sdcard/";
116 127
117 public static int GlobalScaleLevel = 0; 128 public static int GlobalScaleLevel = 0;
122 String item_id; // H<ddddd>L<ddddd> -> item.id_hi item.id_lo 133 String item_id; // H<ddddd>L<ddddd> -> item.id_hi item.id_lo
123 float lat; 134 float lat;
124 float lon; 135 float lon;
125 String addr; 136 String addr;
126 } 137 }
138
139 public static final class Navit_Point_on_Map implements Serializable
140 {
141 /**
142 * struct for a point on the map
143 */
144 private static final long serialVersionUID = 6899215049749155051L;
145 String point_name = "";
146 String addon = null;
147 float lat = 0.0f;
148 float lon = 0.0f;
149 }
150
151 static ArrayList<Navit_Point_on_Map> map_points;
127 152
128 public static Set<String> Navit_Address_Result_double_index = new HashSet<String>(); 153 public static Set<String> Navit_Address_Result_double_index = new HashSet<String>();
129 154
130 public NavitAndroidOverlay NavitAOverlay2; 155 public NavitAndroidOverlay NavitAOverlay2;
131 public static NavitAndroidOverlay NavitAOverlay2_s; 156 public static NavitAndroidOverlay NavitAOverlay2_s;
205 public static NavitMapDownloader mapdownloader_pri = null; 230 public static NavitMapDownloader mapdownloader_pri = null;
206 public static NavitMapDownloader mapdownloader_sec = null; 231 public static NavitMapDownloader mapdownloader_sec = null;
207 public static final int NavitDownloaderPriSelectMap_id = 967; 232 public static final int NavitDownloaderPriSelectMap_id = 967;
208 public static final int NavitDownloaderSecSelectMap_id = 968; 233 public static final int NavitDownloaderSecSelectMap_id = 968;
209 public static final int NavitDeleteSecSelectMap_id = 969; 234 public static final int NavitDeleteSecSelectMap_id = 969;
235 public static final int NavitRecentDest_id = 970;
236 public static final int NavitGeoCoordEnter_id = 971;
210 public static int download_map_id = 0; 237 public static int download_map_id = 0;
211 ProgressThread progressThread_pri = null; 238 ProgressThread progressThread_pri = null;
212 ProgressThread progressThread_sec = null; 239 ProgressThread progressThread_sec = null;
213 public static int search_results_towns = 0; 240 public static int search_results_towns = 0;
214 public static int search_results_streets = 0; 241 public static int search_results_streets = 0;
240 public static Bitmap follow_off = null; 267 public static Bitmap follow_off = null;
241 public static Bitmap follow_current = null; 268 public static Bitmap follow_current = null;
242 public static Bitmap zoomin = null; 269 public static Bitmap zoomin = null;
243 public static Bitmap zoomout = null; 270 public static Bitmap zoomout = null;
244 public static Bitmap bigmap_bitmap = null; 271 public static Bitmap bigmap_bitmap = null;
245 public static Bitmap onway_arrow = null; 272 public static Bitmap oneway_arrow = null;
246 273
247 public static String Navit_last_address_search_string = ""; 274 public static String Navit_last_address_search_string = "";
248 public static Boolean Navit_last_address_full_file_search = false; 275 public static Boolean Navit_last_address_full_file_search = false;
249 public static String Navit_last_address_search_country_iso2_string = ""; 276 public static String Navit_last_address_search_country_iso2_string = "";
250 public static int Navit_last_address_search_country_flags = 3; 277 public static int Navit_last_address_search_country_flags = 3;
262 static final String CFG_FILENAME_PATH = "/sdcard/zanavi/"; 289 static final String CFG_FILENAME_PATH = "/sdcard/zanavi/";
263 static final String NAVIT_DATA_DIR = "/data/data/com.zoffcc.applications.zanavi"; 290 static final String NAVIT_DATA_DIR = "/data/data/com.zoffcc.applications.zanavi";
264 static final String NAVIT_DATA_SHARE_DIR = NAVIT_DATA_DIR + "/share"; 291 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"; 292 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"; 293 static final String VERSION_FILE = NAVIT_DATA_SHARE_DIR + "/version.txt";
294 static final String Navit_DEST_FILENAME = "destinations.dat";
267 295
268 static Resources res_ = null; 296 static Resources res_ = null;
269 297
270 public static String get_text(String in) 298 public static String get_text(String in)
271 { 299 {
468 { 496 {
469 e.printStackTrace(); 497 e.printStackTrace();
470 } 498 }
471 } 499 }
472 500
501 // downloader threads
473 NavitMapDownloader.MULTI_NUM_THREADS = 1; 502 NavitMapDownloader.MULTI_NUM_THREADS = 1;
474 // try to create cat. file if it does not exist 503 PackageInfo pkgInfo;
475 File navit_secret_file = new File(CFG_FILENAME_PATH + "z.txt"); 504 Navit_DonateVersion_Installed = false;
476 if (navit_secret_file.exists()) 505 try
506 {
507 // is the donate version installed?
508 pkgInfo = getPackageManager().getPackageInfo("com.zoffcc.applications.zanavi_donate", 0);
509 String sharedUserId = pkgInfo.sharedUserId;
510 System.out.println("str=" + sharedUserId);
511 if (sharedUserId.equals("com.zoffcc.applications.zanavi"))
477 { 512 {
513 System.out.println("##bonus 001##");
514 Navit_DonateVersion_Installed = true;
478 NavitMapDownloader.MULTI_NUM_THREADS = 6; 515 NavitMapDownloader.MULTI_NUM_THREADS = 4;
479 } 516 }
517 }
518 catch (NameNotFoundException e)
519 {
520 e.printStackTrace();
521 }
522 catch (Exception e)
523 {
524 e.printStackTrace();
525 }
526 // downloader threads
480 527
481 Navit.follow_on = BitmapFactory.decodeResource(getResources(), R.drawable.follow); 528 Navit.follow_on = BitmapFactory.decodeResource(getResources(), R.drawable.follow);
482 Navit.follow_off = BitmapFactory.decodeResource(getResources(), R.drawable.follow_off); 529 Navit.follow_off = BitmapFactory.decodeResource(getResources(), R.drawable.follow_off);
483 Navit.follow_current = Navit.follow_on; 530 Navit.follow_current = Navit.follow_on;
484 531
485 Navit.zoomin = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_in_32_32); 532 Navit.zoomin = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_in_32_32);
486 Navit.zoomout = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_out_32_32); 533 Navit.zoomout = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_out_32_32);
487 534
488 Navit.onway_arrow = BitmapFactory.decodeResource(getResources(), R.drawable.oneway); 535 Navit.oneway_arrow = BitmapFactory.decodeResource(getResources(), R.drawable.oneway);
489 536
490 // ******************* 537 // *******************
491 // ******************* 538 // *******************
492 // ******************* 539 // *******************
493 // ******************* 540 // *******************
633 //String TYPE = android.os.Build.TYPE; //The type of build, like "user" or "eng". 680 //String TYPE = android.os.Build.TYPE; //The type of build, like "user" or "eng".
634 //String USER = android.os.Build.USER; 681 //String USER = android.os.Build.USER;
635 682
636 String android_version = "Android " + ANDROID; 683 String android_version = "Android " + ANDROID;
637 String android_device = MANUFACTURER + " " + BRAND + " " + DEVICE; 684 String android_device = MANUFACTURER + " " + BRAND + " " + DEVICE;
685
686 // debug
687 // debug
688 // android_device = "telechips telechips m801";
689 // debug
690 // debug
691
638 String android_rom_name = DISPLAY; 692 String android_rom_name = DISPLAY;
693 if (Navit_DonateVersion_Installed == false)
694 {
639 UserAgentString = "Mozilla/5.0 (Linux; U; " + "Z" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")"; 695 UserAgentString = "Mozilla/5.0 (Linux; U; " + "Z" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
696 }
697 else
698 {
699 UserAgentString = "Mozilla/5.0 (Linux; U; " + "donateZ" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
700 }
640 System.out.println("UA=" + UserAgentString); 701 System.out.println("UA=" + UserAgentString);
702
703 unsupported = false;
704 try
705 {
706 if (android_device.toLowerCase().contains("telechips"))
707 {
708 if (android_device.toLowerCase().contains("m801"))
709 {
710 // if the donate version is already installed, dont disable the app
711 if (Navit_DonateVersion_Installed == false)
712 {
713 unsupported = true;
714 }
715 }
716 }
717 }
718 catch (Exception e)
719 {
720 e.printStackTrace();
721 }
641 722
642 try 723 try
643 { 724 {
644 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); 725 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
645 } 726 }
719 startup_status = Navit_Status_COMPLETE_NEW_INSTALL; 800 startup_status = Navit_Status_COMPLETE_NEW_INSTALL;
720 FileOutputStream fos_temp; 801 FileOutputStream fos_temp;
721 try 802 try
722 { 803 {
723 fos_temp = new FileOutputStream(navit_first_startup); 804 fos_temp = new FileOutputStream(navit_first_startup);
724 fos_temp.write((int) 65); // just write an "A" to the file, but really doesnt matter 805 fos_temp.write((int) 65); // just write an "A" to the file, but it really doesnt matter
725 fos_temp.flush(); 806 fos_temp.flush();
726 fos_temp.close(); 807 fos_temp.close();
727 808
728 message.setLayoutParams(rlp); 809 message.setLayoutParams(rlp);
729 final SpannableString s = new SpannableString(" " + Navit.get_text("__INFO_BOX_TEXT__")); //TRANS 810 final SpannableString s = new SpannableString(" " + Navit.get_text("__INFO_BOX_TEXT__")); //TRANS
875 Log.e("Navit", "Failed to extract navit.xml (default version)"); 956 Log.e("Navit", "Failed to extract navit.xml (default version)");
876 } 957 }
877 } 958 }
878 } 959 }
879 // Debug.startMethodTracing("calc"); 960 // Debug.startMethodTracing("calc");
961
962 // if (unsupported)
963 // {
964 // class CustomListener implements View.OnClickListener
965 // {
966 // private final Dialog dialog;
967 //
968 // public CustomListener(Dialog dialog)
969 // {
970 // this.dialog = dialog;
971 // }
972 //
973 // @Override
974 // public void onClick(View v)
975 // {
976 //
977 // // Do whatever you want here
978 //
979 // // If tou want to close the dialog, uncomment the line below
980 // //dialog.dismiss();
981 // }
982 // }
983 //
984 // AlertDialog.Builder dialog = new AlertDialog.Builder(this);
985 // dialog.setTitle(Navit.get_text("WeltBild Tablet")); //TRANS
986 // dialog.setCancelable(false);
987 // dialog.setMessage("Your device is not supported!");
988 // dialog.show();
989 // //Button theButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
990 // //theButton.setOnClickListener(new CustomListener(dialog));
991 // }
880 992
881 // --> dont use!! NavitMain(this, langu, android.os.Build.VERSION.SDK_INT); 993 // --> 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)); 994 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); 995 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" /> 996 // CAUTION: don't use android.os.Build.VERSION.SDK_INT if <uses-sdk android:minSdkVersion="3" />
910 // a test now, later we will unpack all needed strings for java, here at this point!! 1022 // a test now, later we will unpack all needed strings for java, here at this point!!
911 //String x = NavitGraphics.getLocalizedString("Austria"); 1023 //String x = NavitGraphics.getLocalizedString("Austria");
912 //Log.e("Navit", "x=" + x); 1024 //Log.e("Navit", "x=" + x);
913 Navit.show_mem_used(); 1025 Navit.show_mem_used();
914 1026
1027 /*
915 GpsStatus.Listener listener = new GpsStatus.Listener() 1028 * GpsStatus.Listener listener = new GpsStatus.Listener()
916 { 1029 * {
917 public void onGpsStatusChanged(int event) 1030 * public void onGpsStatusChanged(int event)
918 { 1031 * {
919 //System.out.println("xxxxx"); 1032 * //System.out.println("xxxxx");
920 if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) 1033 * if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS)
921 { 1034 * {
922 } 1035 * }
923 } 1036 * }
924 }; 1037 * };
1038 */
925 } 1039 }
1040
1041 // private void setOnKeyListener(OnKeyListener onKeyListener)
1042 // {
1043 //
1044 // }
926 1045
927 public static void show_mem_used() // wrapper 1046 public static void show_mem_used() // wrapper
928 { 1047 {
929 try 1048 try
930 { 1049 {
1052 activatePrefs(); 1171 activatePrefs();
1053 // activate gps AFTER 3g-location 1172 // activate gps AFTER 3g-location
1054 NavitVehicle.turn_on_precise_provider(); 1173 NavitVehicle.turn_on_precise_provider();
1055 1174
1056 Navit.show_mem_used(); 1175 Navit.show_mem_used();
1176
1177 // restore points
1178 read_map_points();
1057 } 1179 }
1058 1180
1059 @Override 1181 @Override
1060 public void onRestart() 1182 public void onRestart()
1061 { 1183 {
1075 NavitActivity(1); 1197 NavitActivity(1);
1076 1198
1077 //Intent caller = this.getIntent(); 1199 //Intent caller = this.getIntent();
1078 //System.out.println("A=" + caller.getAction() + " D=" + caller.getDataString()); 1200 //System.out.println("A=" + caller.getAction() + " D=" + caller.getDataString());
1079 //System.out.println("C=" + caller.getComponent().flattenToString()); 1201 //System.out.println("C=" + caller.getComponent().flattenToString());
1202
1203 if (unsupported)
1204 {
1205 class CustomListener implements View.OnClickListener
1206 {
1207 private final Dialog dialog;
1208
1209 public CustomListener(Dialog dialog)
1210 {
1211 this.dialog = dialog;
1212 }
1213
1214 @Override
1215 public void onClick(View v)
1216 {
1217
1218 // Do whatever you want here
1219
1220 // If tou want to close the dialog, uncomment the line below
1221 //dialog.dismiss();
1222 }
1223 }
1224
1225 AlertDialog.Builder dialog = new AlertDialog.Builder(this);
1226 dialog.setTitle(Navit.get_text("WeltBild Tablet")); //TRANS
1227 dialog.setCancelable(false);
1228 dialog.setMessage("Your device is not supported!");
1229 dialog.show();
1230 //Button theButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
1231 //theButton.setOnClickListener(new CustomListener(dialog));
1232 }
1080 1233
1081 String intent_data = null; 1234 String intent_data = null;
1082 if (startup_intent != null) 1235 if (startup_intent != null)
1083 { 1236 {
1084 if (System.currentTimeMillis() <= Navit.startup_intent_timestamp + 4000L) 1237 if (System.currentTimeMillis() <= Navit.startup_intent_timestamp + 4000L)
1216 1369
1217 lat = temp3.split(",", -1)[0]; 1370 lat = temp3.split(",", -1)[0];
1218 lon = temp3.split(",", -1)[1]; 1371 lon = temp3.split(",", -1)[1];
1219 q = temp2; 1372 q = temp2;
1220 1373
1221 System.out.println(); 1374 // System.out.println();
1375
1376 Navit.remember_destination(q, lat, lon);
1377 Navit.destination_set();
1222 1378
1223 Message msg = new Message(); 1379 Message msg = new Message();
1224 Bundle b = new Bundle(); 1380 Bundle b = new Bundle();
1225 b.putInt("Callback", 3); 1381 b.putInt("Callback", 3);
1226 b.putString("lat", lat); 1382 b.putString("lat", lat);
1368 NavitVehicle.turn_off_all_providers(); 1524 NavitVehicle.turn_off_all_providers();
1369 1525
1370 NavitActivity(-2); 1526 NavitActivity(-2);
1371 System.gc(); 1527 System.gc();
1372 Navit.show_mem_used(); 1528 Navit.show_mem_used();
1529
1530 // save points
1531 write_map_points();
1373 } 1532 }
1374 1533
1375 @Override 1534 @Override
1376 public void onDestroy() 1535 public void onDestroy()
1377 { 1536 {
1427 else 1586 else
1428 { 1587 {
1429 menu.add(1, 13, 495, get_text("Announcer On")); //TRANS 1588 menu.add(1, 13, 495, get_text("Announcer On")); //TRANS
1430 } 1589 }
1431 1590
1591 menu.add(1, 14, 498, get_text("Recent destinations")); //TRANS
1432 menu.add(1, 3, 500, get_text("download maps")); //TRANS 1592 menu.add(1, 3, 500, get_text("download maps")); //TRANS
1433 menu.add(1, 8, 505, get_text("delete maps")); //TRANS 1593 menu.add(1, 8, 505, get_text("delete maps")); //TRANS
1434 1594
1435 // menu.add(1, 88, 800, "--"); 1595 // menu.add(1, 88, 800, "--");
1436 return true; 1596 return true;
1525 // map download menu 1685 // map download menu
1526 Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class); 1686 Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class);
1527 this.startActivityForResult(map_download_list_activity, Navit.NavitDownloaderPriSelectMap_id); 1687 this.startActivityForResult(map_download_list_activity, Navit.NavitDownloaderPriSelectMap_id);
1528 break; 1688 break;
1529 case 5: 1689 case 5:
1690 // GeoCoordEnterDialog
1691 // DEBUG - // Intent it001 = new Intent(this, GeoCoordEnterDialog.class);
1692 // DEBUG - // this.startActivityForResult(it001, Navit.NavitGeoCoordEnter_id);
1693
1530 // toggle the normal POI layers (to avoid double POIs) 1694 // toggle the normal POI layers (to avoid double POIs)
1531 msg = new Message(); 1695 msg = new Message();
1532 b = new Bundle(); 1696 b = new Bundle();
1533 b.putInt("Callback", 5); 1697 b.putInt("Callback", 5);
1534 b.putString("cmd", "toggle_layer(\"POI Symbols\");"); 1698 b.putString("cmd", "toggle_layer(\"POI Symbols\");");
1540 b.putInt("Callback", 5); 1704 b.putInt("Callback", 5);
1541 b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");"); 1705 b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");");
1542 msg.setData(b); 1706 msg.setData(b);
1543 N_NavitGraphics.callback_handler.sendMessage(msg); 1707 N_NavitGraphics.callback_handler.sendMessage(msg);
1544 1708
1545 // TEST TEST // googlemaps_show("48.28696", "16.48816", "XXyy ö2432ä ä3"); 1709 // DEBUG - // googlemaps_show("48.28696", "16.48816", "XXyy ö2432ä ä3");
1546 1710
1547 break; 1711 break;
1548 case 6: 1712 case 6:
1549 // ok startup address search activity (online google maps search) 1713 // ok startup address search activity (online google maps search)
1550 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class); 1714 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
1613 b = new Bundle(); 1777 b = new Bundle();
1614 b.putInt("Callback", 35); 1778 b.putInt("Callback", 35);
1615 msg.setData(b); 1779 msg.setData(b);
1616 N_NavitGraphics.callback_handler.sendMessage(msg); 1780 N_NavitGraphics.callback_handler.sendMessage(msg);
1617 break; 1781 break;
1782 case 14:
1783 Intent i2 = new Intent(this, NavitRecentDestinationActivity.class);
1784 this.startActivityForResult(i2, Navit.NavitRecentDest_id);
1785 break;
1618 case 88: 1786 case 88:
1619 // dummy entry, just to make "breaks" in the menu 1787 // dummy entry, just to make "breaks" in the menu
1620 break; 1788 break;
1621 case 99: 1789 case 99:
1622 // exit 1790 // exit
1629 //msg.setData(b); 1797 //msg.setData(b);
1630 //N_NavitGraphics.callback_handler.sendMessage(msg); 1798 //N_NavitGraphics.callback_handler.sendMessage(msg);
1631 break; 1799 break;
1632 } 1800 }
1633 return true; 1801 return true;
1802 }
1803
1804 private class PickerListener implements NumberPicker.ValueChangeListener
1805 {
1806 @Override
1807 public void onNumberPickerValueChange(NumberPicker picker, int value)
1808 {
1809 //if (picker.getId() == R.id.SpinRate)
1810 //{
1811 // mBeatsPerMin = value;
1812 //}
1813 return;
1814 }
1634 } 1815 }
1635 1816
1636 protected void onActivityResult(int requestCode, int resultCode, Intent data) 1817 protected void onActivityResult(int requestCode, int resultCode, Intent data)
1637 { 1818 {
1638 Log.e("Navit", "onActivityResult"); 1819 Log.e("Navit", "onActivityResult");
1784 } 1965 }
1785 catch (Exception e) 1966 catch (Exception e)
1786 { 1967 {
1787 } 1968 }
1788 1969
1970 Message msg2 = new Message();
1971 Bundle b2 = new Bundle();
1972 b2.putInt("Callback", 44);
1973 msg2.setData(b2);
1974 N_NavitGraphics.callback_handler.sendMessage(msg2);
1975
1976 if (requestCode == NavitAddressSearch_id_offline)
1977 {
1978 try
1979 {
1980 Boolean hide_dup = data.getStringExtra("hide_dup").equals("1");
1981 if (hide_dup)
1982 {
1983 Message msg = new Message();
1984 Bundle b = new Bundle();
1985 b.putInt("Callback", 45);
1986 msg.setData(b);
1987 N_NavitGraphics.callback_handler.sendMessage(msg);
1988 }
1989 }
1990 catch (Exception e)
1991 {
1992 }
1993 }
1994
1789 Navit_last_address_partial_match = partial_match; 1995 Navit_last_address_partial_match = partial_match;
1790 Navit_last_address_search_string = addr; 1996 Navit_last_address_search_string = addr;
1791 1997
1792 try 1998 try
1793 { 1999 {
1884 if (data.getStringExtra("what").equals("view")) 2090 if (data.getStringExtra("what").equals("view"))
1885 { 2091 {
1886 // get the coords for the destination 2092 // get the coords for the destination
1887 int destination_id = Integer.parseInt(data.getStringExtra("selected_id")); 2093 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
1888 2094
2095 // set nice zoomlevel before we show destination
2096 int zoom_want = Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL;
2097 //
2098 Message msg = new Message();
2099 Bundle b = new Bundle();
2100 b.putInt("Callback", 33);
2101 b.putString("s", Integer.toString(zoom_want));
2102 msg.setData(b);
2103 try
2104 {
2105 N_NavitGraphics.callback_handler.sendMessage(msg);
2106 Navit.GlobalScaleLevel = zoom_want;
2107 }
2108 catch (Exception e)
2109 {
2110 e.printStackTrace();
2111 }
2112 if (PREF_save_zoomlevel)
2113 {
2114 setPrefs_zoomlevel();
2115 }
2116 // set nice zoomlevel before we show destination
2117
1889 try 2118 try
1890 { 2119 {
1891 Navit.follow_button_off(); 2120 Navit.follow_button_off();
1892 } 2121 }
1893 catch (Exception e2) 2122 catch (Exception e2)
1903 // get the coords for the destination 2132 // get the coords for the destination
1904 int destination_id = Integer.parseInt(data.getStringExtra("selected_id")); 2133 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
1905 2134
1906 // ok now set target 2135 // 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 2136 Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS
2137
2138 try
2139 {
2140 Navit.remember_destination(Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
2141 // save points
2142 write_map_points();
2143 }
2144 catch (Exception e)
2145 {
2146 e.printStackTrace();
2147 }
2148 Navit.destination_set();
1908 2149
1909 Message msg = new Message(); 2150 Message msg = new Message();
1910 Bundle b = new Bundle(); 2151 Bundle b = new Bundle();
1911 b.putInt("Callback", 3); 2152 b.putInt("Callback", 3);
1912 b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lat)); 2153 b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems.get(destination_id).lat));
1967 catch (Exception e) 2208 catch (Exception e)
1968 { 2209 {
1969 e.printStackTrace(); 2210 e.printStackTrace();
1970 } 2211 }
1971 break; 2212 break;
2213 case NavitGeoCoordEnter_id:
2214 try
2215 {
2216 if (resultCode == Activity.RESULT_OK)
2217 {
2218 // lat lon enter activitiy result
2219 }
2220 }
2221 catch (Exception e)
2222 {
2223 e.printStackTrace();
2224 }
2225 break;
2226 case NavitRecentDest_id:
2227 try
2228 {
2229 if (resultCode == Activity.RESULT_OK)
2230 {
2231 Log.d("Navit", "recent dest id=" + Integer.parseInt(data.getStringExtra("selected_id")));
2232 // get the coords for the destination
2233 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
2234
2235 // ok now set target
2236 String dest_name = Navit.map_points.get(destination_id).point_name;
2237 float lat = Navit.map_points.get(destination_id).lat;
2238 float lon = Navit.map_points.get(destination_id).lon;
2239 Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + dest_name, Toast.LENGTH_LONG).show(); //TRANS
2240
2241 Navit.destination_set();
2242
2243 Message msg = new Message();
2244 Bundle b = new Bundle();
2245 b.putInt("Callback", 3);
2246 b.putString("lat", String.valueOf(lat));
2247 b.putString("lon", String.valueOf(lon));
2248 b.putString("q", dest_name);
2249 msg.setData(b);
2250 N_NavitGraphics.callback_handler.sendMessage(msg);
2251
2252 // zoom_to_route();
2253 try
2254 {
2255 Thread.sleep(400);
2256 }
2257 catch (InterruptedException e)
2258 {
2259 }
2260
2261 try
2262 {
2263 Navit.follow_button_on();
2264 }
2265 catch (Exception e2)
2266 {
2267 e2.printStackTrace();
2268 }
2269
2270 show_geo_on_screen(lat, lon);
2271
2272 }
2273 }
2274 catch (Exception e)
2275 {
2276 e.printStackTrace();
2277 }
2278 break;
1972 default: 2279 default:
1973 Log.e("Navit", "onActivityResult " + requestCode + " " + resultCode); 2280 Log.e("Navit", "onActivityResult " + requestCode + " " + resultCode);
2281 try
2282 {
1974 ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data); 2283 ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data);
2284 }
2285 catch (Exception e)
2286 {
2287 e.printStackTrace();
2288 }
1975 break; 2289 break;
1976 } 2290 }
1977 Log.e("Navit", "onActivityResult finished"); 2291 Log.e("Navit", "onActivityResult finished");
1978 } 2292 }
1979 2293
2820 msg.setData(b); 3134 msg.setData(b);
2821 try 3135 try
2822 { 3136 {
2823 N_NavitGraphics.callback_handler.sendMessage(msg); 3137 N_NavitGraphics.callback_handler.sendMessage(msg);
2824 Navit.GlobalScaleLevel = PREF_zoomlevel_num; 3138 Navit.GlobalScaleLevel = PREF_zoomlevel_num;
2825 // System.out.println("5 restore zoom level: " + PREF_zoomlevel_num); 3139 //System.out.println("5 restore zoom level: " + PREF_zoomlevel_num);
2826 } 3140 }
2827 catch (Exception e) 3141 catch (Exception e)
2828 { 3142 {
2829 } 3143 }
2830 } 3144 }
3168 search_intent.putExtra("partial_match", pm_temp); 3482 search_intent.putExtra("partial_match", pm_temp);
3169 this.startActivityForResult(search_intent, NavitAddressSearch_id_offline); 3483 this.startActivityForResult(search_intent, NavitAddressSearch_id_offline);
3170 } 3484 }
3171 3485
3172 /* 3486 /*
3173 * open google maps at a given coordinate, to make bookmarks 3487 * open google maps at a given coordinate
3174 */ 3488 */
3175 private void googlemaps_show(String lat, String lon, String name) 3489 private void googlemaps_show(String lat, String lon, String name)
3176 { 3490 {
3177 // geo:latitude,longitude 3491 // geo:latitude,longitude
3178 String url = "geo:" + lat + "," + lon + "?z=" + "16"; 3492 String url = "geo:" + lat + "," + lon + "?z=" + "16";
3193 N_NavitGraphics.callback_handler.sendMessage(msg); 3507 N_NavitGraphics.callback_handler.sendMessage(msg);
3194 } 3508 }
3195 3509
3196 public void show_geo_on_screen(float lat, float lng) 3510 public void show_geo_on_screen(float lat, float lng)
3197 { 3511 {
3198 // -> let follow mode stay turned on ### Navit.follow_button_off(); 3512 // -> let follow mode stay as it now is ### Navit.follow_button_off();
3199 String nix = NavitGraphics.CallbackGeoCalc(3, lat, lng); 3513 String nix = NavitGraphics.CallbackGeoCalc(3, lat, lng);
3200 } 3514 }
3201 3515
3202 public void zoom_to_route() 3516 public void zoom_to_route()
3203 { 3517 {
3204 System.out.println(""); 3518 //System.out.println("");
3205 System.out.println("*** Zoom to ROUTE ***"); 3519 //System.out.println("*** Zoom to ROUTE ***");
3206 System.out.println(""); 3520 //System.out.println("");
3207 Message msg = new Message(); 3521 Message msg = new Message();
3208 Bundle b = new Bundle(); 3522 Bundle b = new Bundle();
3209 b.putInt("Callback", 17); 3523 b.putInt("Callback", 17);
3210 msg.setData(b); 3524 msg.setData(b);
3211 N_NavitGraphics.callback_handler.sendMessage(msg); 3525 N_NavitGraphics.callback_handler.sendMessage(msg);
3319 System.out.println("*XX*"); 3633 System.out.println("*XX*");
3320 e.printStackTrace(); 3634 e.printStackTrace();
3321 } 3635 }
3322 return ret; 3636 return ret;
3323 } 3637 }
3638
3639 static void add_map_point(Navit_Point_on_Map element)
3640 {
3641 if (element == null)
3642 {
3643 return;
3644 }
3645 if (map_points == null)
3646 {
3647 map_points = new ArrayList<Navit_Point_on_Map>();
3648 }
3649 int max_points = 10;
3650 if (map_points.size() > max_points)
3651 {
3652 try
3653 {
3654 map_points.remove(0);
3655 }
3656 catch (Exception e)
3657 {
3658
3659 }
3660 }
3661
3662 if (!check_dup_destination(element))
3663 {
3664 // if not duplicate, then add
3665 map_points.add(element);
3666 }
3667 }
3668
3669 void read_map_points()
3670 {
3671 deserialize_map_points();
3672 }
3673
3674 static void write_map_points()
3675 {
3676 if (map_points != null)
3677 {
3678 serialize_map_points();
3679 }
3680 }
3681
3682 private static void serialize_map_points()
3683 {
3684 FileOutputStream fos;
3685 try
3686 {
3687 fos = new FileOutputStream(CFG_FILENAME_PATH + Navit_DEST_FILENAME);
3688 // openFileOutput(CFG_FILENAME_PATH + Navit_DEST_FILENAME, Context.MODE_PRIVATE);
3689 ObjectOutputStream oos = new ObjectOutputStream(fos);
3690 oos.writeObject(map_points);
3691 oos.close();
3692 }
3693 catch (FileNotFoundException e)
3694 {
3695 e.printStackTrace();
3696 }
3697 catch (IOException e)
3698 {
3699 e.printStackTrace();
3700 }
3701 catch (Exception e)
3702 {
3703 e.printStackTrace();
3704 }
3705 }
3706
3707 @SuppressWarnings("unchecked")
3708 private void deserialize_map_points()
3709 {
3710 try
3711 {
3712 FileInputStream fis = new FileInputStream(CFG_FILENAME_PATH + Navit_DEST_FILENAME);
3713 // openFileInput(CFG_FILENAME_PATH + Navit_DEST_FILENAME);
3714 ObjectInputStream ois = new ObjectInputStream(fis);
3715 map_points = (ArrayList<Navit_Point_on_Map>) ois.readObject();
3716 }
3717 catch (FileNotFoundException e)
3718 {
3719 e.printStackTrace();
3720 map_points = new ArrayList<Navit_Point_on_Map>();
3721 }
3722 catch (IOException e)
3723 {
3724 e.printStackTrace();
3725 map_points = new ArrayList<Navit_Point_on_Map>();
3726 }
3727 catch (ClassNotFoundException e)
3728 {
3729 e.printStackTrace();
3730 map_points = new ArrayList<Navit_Point_on_Map>();
3731 }
3732 catch (Exception e)
3733 {
3734 e.printStackTrace();
3735 map_points = new ArrayList<Navit_Point_on_Map>();
3736 }
3737
3738 // for (int j = 0; j < map_points.size(); j++)
3739 // {
3740 // System.out.println("####******************" + j + ":" + map_points.get(j).point_name);
3741 // }
3742 }
3743
3744 static void remember_destination_xy(String name, int x, int y)
3745 {
3746 // i=1 -> pixel a,b (x,y) -> geo string "lat(float):lng(float)"
3747 // i=2 -> geo a,b (lat,lng) -> pixel string "x(int):y(int)"
3748 String lat_lon = NavitGraphics.CallbackGeoCalc(1, x, y);
3749 try
3750 {
3751 String tmp[] = lat_lon.split(":", 2);
3752 //System.out.println("tmp=" + lat_lon);
3753 float lat = Float.parseFloat(tmp[0]);
3754 float lon = Float.parseFloat(tmp[1]);
3755 //System.out.println("ret=" + lat_lon + " lat=" + lat + " lon=" + lon);
3756 remember_destination(name, lat, lon);
3757 }
3758 catch (Exception e)
3759 {
3760 e.printStackTrace();
3761 }
3762 }
3763
3764 static void remember_destination(String name, String lat, String lon)
3765 {
3766 try
3767 {
3768 //System.out.println("22 **## " + name + " " + lat + " " + lon + " ##**");
3769 remember_destination(name, Float.parseFloat(lat), Float.parseFloat(lon));
3770 }
3771 catch (Exception e)
3772 {
3773 e.printStackTrace();
3774 }
3775 }
3776
3777 static void remember_destination(String name, float lat, float lon)
3778 {
3779 //System.out.println("11 **## " + name + " " + lat + " " + lon + " ##**");
3780 Navit_Point_on_Map t = new Navit_Point_on_Map();
3781 t.point_name = name;
3782 t.lat = lat;
3783 t.lon = lon;
3784 add_map_point(t);
3785 }
3786
3787 static void destination_set()
3788 {
3789 // status = "destination set"
3790 NavitGraphics.navit_route_status = 1;
3791 }
3792
3793 static Boolean check_dup_destination(Navit_Point_on_Map element)
3794 {
3795 Boolean ret = false;
3796 Navit_Point_on_Map t;
3797 for (int i = 0; i < map_points.size(); i++)
3798 {
3799 t = map_points.get(i);
3800 if ((t.point_name.equals(element.point_name)) && (t.lat == element.lat) && (t.lon == element.lon))
3801 {
3802 return true;
3803 }
3804 }
3805 return ret;
3806 }
3807
3324} 3808}

Legend:
Removed from v.21  
changed lines
  Added in v.22

   
Visit the ZANavi Wiki