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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (show annotations) (download)
Fri Aug 14 13:23:01 2015 UTC (8 years, 7 months ago) by zoff99
File size: 458202 byte(s)
quick fix
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2015 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 package com.zoffcc.applications.zanavi;
40
41 import java.io.File;
42 import java.io.FileInputStream;
43 import java.io.FileNotFoundException;
44 import java.io.FileOutputStream;
45 import java.io.IOException;
46 import java.io.InputStream;
47 import java.io.InputStreamReader;
48 import java.io.ObjectInputStream;
49 import java.io.ObjectOutputStream;
50 import java.io.OutputStream;
51 import java.io.OutputStreamWriter;
52 import java.io.Reader;
53 import java.io.Serializable;
54 import java.net.URL;
55 import java.net.URLDecoder;
56 import java.nio.channels.FileChannel;
57 import java.text.DecimalFormat;
58 import java.text.SimpleDateFormat;
59 import java.util.ArrayList;
60 import java.util.Calendar;
61 import java.util.Collections;
62 import java.util.Date;
63 import java.util.HashSet;
64 import java.util.Iterator;
65 import java.util.List;
66 import java.util.Locale;
67 import java.util.Map;
68 import java.util.Random;
69 import java.util.Set;
70 import java.util.TimeZone;
71 import java.util.concurrent.LinkedBlockingQueue;
72
73 import org.json.JSONArray;
74 import org.json.JSONObject;
75 import org.xml.sax.InputSource;
76
77 import android.annotation.SuppressLint;
78 import android.annotation.TargetApi;
79 import android.app.Activity;
80 import android.app.AlertDialog;
81 import android.app.Dialog;
82 import android.app.Notification;
83 import android.app.NotificationManager;
84 import android.app.PendingIntent;
85 import android.app.ProgressDialog;
86 import android.app.backup.BackupManager;
87 import android.content.ActivityNotFoundException;
88 import android.content.ComponentName;
89 import android.content.ContentResolver;
90 import android.content.Context;
91 import android.content.DialogInterface;
92 import android.content.DialogInterface.OnCancelListener;
93 import android.content.Intent;
94 import android.content.ServiceConnection;
95 import android.content.SharedPreferences;
96 import android.content.pm.PackageInfo;
97 import android.content.pm.PackageManager.NameNotFoundException;
98 import android.content.res.AssetManager;
99 import android.content.res.Configuration;
100 import android.content.res.Resources;
101 import android.database.Cursor;
102 import android.graphics.Bitmap;
103 import android.graphics.BitmapFactory;
104 import android.graphics.Color;
105 import android.graphics.Paint;
106 import android.graphics.Rect;
107 import android.graphics.RectF;
108 import android.graphics.Typeface;
109 import android.hardware.Sensor;
110 import android.hardware.SensorEvent;
111 import android.hardware.SensorEventListener;
112 import android.hardware.SensorManager;
113 import android.location.Address;
114 import android.location.Geocoder;
115 import android.location.GpsStatus;
116 import android.location.Location;
117 import android.location.LocationManager;
118 import android.media.AudioManager;
119 import android.media.AudioManager.OnAudioFocusChangeListener;
120 import android.media.ToneGenerator;
121 import android.net.Uri;
122 import android.os.AsyncTask;
123 import android.os.Build;
124 import android.os.Bundle;
125 import android.os.Debug;
126 import android.os.Environment;
127 import android.os.Handler;
128 import android.os.IBinder;
129 import android.os.Looper;
130 import android.os.Message;
131 import android.os.PowerManager;
132 import android.os.RemoteException;
133 import android.os.SystemClock;
134 import android.preference.PreferenceManager;
135 import android.speech.tts.TextToSpeech;
136 import android.support.v4.app.FragmentManager;
137 import android.support.v4.app.FragmentTransaction;
138 import android.support.v7.app.ActionBar;
139 import android.support.v7.app.ActionBarActivity;
140 import android.support.v7.widget.Toolbar;
141 import android.text.Html;
142 import android.text.SpannableString;
143 import android.text.method.LinkMovementMethod;
144 import android.text.util.Linkify;
145 import android.util.DisplayMetrics;
146 import android.util.Log;
147 import android.util.TypedValue;
148 import android.view.Display;
149 import android.view.GestureDetector;
150 import android.view.GestureDetector.SimpleOnGestureListener;
151 import android.view.Gravity;
152 import android.view.KeyEvent;
153 import android.view.Menu;
154 import android.view.MenuItem;
155 import android.view.MotionEvent;
156 import android.view.View;
157 import android.view.ViewConfiguration;
158 import android.view.ViewTreeObserver;
159 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
160 import android.view.Window;
161 import android.view.WindowManager;
162 import android.view.animation.Animation;
163 import android.view.animation.Animation.AnimationListener;
164 import android.view.animation.TranslateAnimation;
165 import android.view.inputmethod.InputMethodManager;
166 import android.widget.Button;
167 import android.widget.FrameLayout;
168 import android.widget.ImageView;
169 import android.widget.LinearLayout;
170 import android.widget.RelativeLayout;
171 import android.widget.TextView;
172 import android.widget.Toast;
173 import bpi.sdbm.illuminance.SolarPosition;
174
175 import com.lamerman.FileDialog;
176 import com.lamerman.SelectionMode;
177 import com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator;
178 import com.luckycatlabs.sunrisesunset.calculator.SolarEventCalculator;
179 import com.luckycatlabs.sunrisesunset.dto.Location2;
180 import com.zoffcc.applications.zanavi.NavitMapDownloader.ProgressThread;
181 import com.zoffcc.applications.zanavi.NavitOSDJava.drawOSDThread;
182 import com.zoffcc.applications.zanavi.NavitVehicle.location_coords;
183 import com.zoffcc.applications.zanavi.ZANaviListViewAdapter.ListViewItem;
184 import com.zoffcc.applications.zanavi_msg.ZanaviCloudApi;
185
186 import de.oberoner.gpx2navit_txt.MainFrame;
187
188 public class Navit extends ActionBarActivity implements Handler.Callback, SensorEventListener
189 {
190 public static final String VERSION_TEXT_LONG_INC_REV = "3581";
191 public static String NavitAppVersion = "0";
192 public static String NavitAppVersion_prev = "-1";
193 public static String NavitAppVersion_string = "0";
194 public final Boolean NAVIT_IS_EMULATOR = false; // when running on emulator set to true!!
195 public static boolean has_hw_menu_button = false;
196 static int NAVIT_MIN_HORIZONTAL_DP_FOR_ACTIONBAR = 400;
197 static int actionbar_item_width = 100;
198 static int actionbar_items_will_fit = 2;
199 static boolean actionbar_all_items_will_fit = false;
200 static boolean actionabar_download_icon_visible = false;
201 static boolean is_navigating = false;
202 static boolean is_paused = true;
203
204 static int api_version_int = 6;
205
206 static boolean PAINT_OLD_API = true;
207
208 static long SHOWCASEVIEW_ID_001 = 93457181726L;
209
210 //static final int DEFAULT_THEME_DARK = android.R.style.Theme_WithActionBar;
211 //static final int DEFAULT_THEME_LIGHT = android.R.style.Theme_Material_Light;
212 static final int DEFAULT_THEME_OLD_LIGHT = R.style.CustomActionBarThemeLight;
213 static final int DEFAULT_THEME_OLD_DARK = R.style.CustomActionBarTheme;
214
215 static final int DEFAULT_THEME_OLD_LIGHT_M = R.style.CustomActionBarThemeLightM;
216 static final int DEFAULT_THEME_OLD_DARK_M = R.style.CustomActionBarThemeM;
217
218 // GLSurfaceView glSurfaceView;
219
220 static int OSD_blueish_bg_color = 0;
221
222 // ----------------- DEBUG ----------------
223 // ----------------- DEBUG ----------------
224 // ----------------- DEBUG ----------------
225 static final boolean METHOD_DEBUG = false; // for debugging only, set this to "false" on release builds!!
226 static final boolean DEBUG_DRAW_VEHICLE = true; // if "false" then dont draw green vehicle, set this to "true" on release builds!!
227 static final boolean NAVIT_ALWAYS_UNPACK_XMLFILE = false; // always unpacks the navit.xml file, set this to "false" on release builds!!
228 static final boolean NAVIT_DEBUG_TEXT_VIEW = false; // show overlay with debug messages, set this to "false" on release builds!!
229 static final boolean GFX_OVERSPILL = true; // make gfx canvas bigger for rotation and zoom smoothness
230 // ----------------- DEBUG ----------------
231 // ----------------- DEBUG ----------------
232 // ----------------- DEBUG ----------------
233
234 // ----------------------------------------
235 // ----------------------------------------
236 static final boolean FDBL = false;
237 // ----------------------------------------
238 // ----------------------------------------
239
240 static final float OVERSPILL_FACTOR = 1.4f; // 20% percent on each side
241
242 // ------------------ BitCoin Addr --------
243 // ------------------ BitCoin Addr --------
244 // ------------------ BitCoin Addr --------
245 final static String BITCOIN_DONATE_ADDR = "1ZANav18WY8ytM7bhnAEBS3bdrTohsD9p";
246 // ------------------ BitCoin Addr --------
247 // ------------------ BitCoin Addr --------
248 // ------------------ BitCoin Addr --------
249
250 private static ZanaviCloudApi plugin_api = null;
251 static final int PLUGIN_MSG_ID = 1;
252 static final int PLUGIN_MSG_CAT_zanavi_version = 1;
253 static final int PLUGIN_MSG_CAT_installed_maps = 2;
254 static final int PLUGIN_MSG_CAT_3d_mode = 3;
255
256 static ZANaviPrefs p = new ZANaviPrefs();
257 static ZANaviPrefs p_old = new ZANaviPrefs();
258 static final int STREET_SEARCH_STRINGS_SAVE_COUNT = 10;
259
260 // static AnimationDrawable mFrameAnimation;
261 static Menu cur_menu = null;
262
263 static long NAVIT_START_INTENT_DRIVE_HOME = 1L;
264
265 static final int NAVIT_BACKBUTTON_TO_EXIT_TIME = 2000; // 2 secs.
266
267 static int NavitOverflowMenuItemID = -1;
268
269 static ContentResolver content_resolver = null;
270 public static final String CR_AUTHORITY = "com.zoffcc.applications.zanavi_udonate.provider";
271 public static final Uri CR_CONTENT_URI = Uri.parse("content://" + CR_AUTHORITY + "/" + "table1");
272
273 public static Intent ZANaviMapDownloaderServiceIntent = null;
274
275 static float last_y_bottom_bar_touch = 0;
276 static float cur_y_margin_bottom_bar_touch = 0;
277 static int map_view_height = 100;
278 static float bottom_y_margin_bottom_bar_touch = 0;
279 static int actionBarHeight = 0;
280 static int bottom_bar_px = 80;
281 static int bottom_bar_slider_shadow_px = 4;
282 static GestureDetector mGestureDetector = null;
283 static int swipeMaxOffPath = 20;
284 static ZANaviRoadbookFragment road_book = null;
285 static FragmentManager fragmentManager = null;
286 static ImageView push_pin_view = null;
287 static List<ListViewItem> road_book_items = null;
288
289 TextToSpeech mTts = null;
290
291 static ToneGenerator toneG = null;
292 static boolean toneG_heared = false;
293
294 public static int Global_Init_Finished = 0; // 0 -> no init
295 // 1 -> all C structures are ready for use
296 public static int Global_Location_update_not_allowed = 0; // 0 -> send location update to C functions
297 // 1 -> DO NOT send location update to C functions, it may crash in this phase
298
299 //static BackupManager backupManager = null;
300 static Object backupManager = null;
301
302 // AlertDialog dialog_info_popup = null;
303 Dialog dialog_info_popup = null;
304 int info_popup_seen_count = 0;
305 final int info_popup_seen_count_max = 2; // must look at the info pop 2 times
306 boolean info_popup_seen_count_end = false;
307
308 static Navit Global_Navit_Object = null;
309 static AssetManager asset_mgr = null;
310
311 static boolean Navit_doubleBackToExitPressedOnce = false;
312
313 // define graphics here (this is bad, please fix me!)
314 public static NavitGraphics N_NavitGraphics = null;
315
316 public static int usedMegs_old = -1;
317 public static String usedMegs_str_old = "";
318 public static int Routgraph_enabled = 0;
319
320 // -------- SUN / MOON ----------
321 long sun_moon__mLastCalcSunMillis = -1L;
322 public double azmiuth_cache = -1;
323 public double zenith_cache = -1;
324 public static String sunrise_cache = "";
325 public static boolean is_night = false;
326 public static boolean is_twilight = false;
327 public static String sunset_cache = "";
328 public static double elevation = 0;
329 public double moon_azimuth_cache = -1;
330 public double moon_evelation_cache = -1;
331 Boolean sun_moon__must_calc_new = true;
332 SunriseSunsetCalculator sun_moon__calc = null;
333 Calendar sun_moon__cx = null;
334 SolarPosition.SunCoordinates sun_moon__sc = null;
335 public static boolean calc_sun_enabled = true;
336 // -------- SUN / MOON ----------
337
338 public static CWorkerThread cwthr = null;
339 public static NavitGraphics NG__map_main = null;
340 public static NavitGraphics NG__vehicle = null;
341 public static NavitVehicle NV = null;
342 public static NavitSpeech2 NSp = null;
343 public static drawOSDThread draw_osd_thread = null;
344
345 public static boolean use_index_search = false;
346 public static boolean index_search_realtime = false;
347
348 static AlertDialog.Builder generic_alert_box = null;
349
350 private Boolean xmlconfig_unpack_file = true;
351 private Boolean write_new_version_file = true;
352 final static int Navit_Status_COMPLETE_NEW_INSTALL = 1;
353 final static int Navit_Status_UPGRADED_TO_NEW_VERSION = 2;
354 final static int Navit_Status_NORMAL_STARTUP = 0;
355 static Boolean Navit_DonateVersion_Installed = false;
356 static Boolean Navit_Plugin_001_Installed = false;
357 static Boolean Navit_index_on_but_no_idx_files = false;
358 static Boolean Navit_maps_too_old = false;
359 static Boolean Navit_Largemap_DonateVersion_Installed = false;
360 private int startup_status = Navit_Status_NORMAL_STARTUP;
361 final static int Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL = 8;
362 static Boolean unsupported = false;
363 static Boolean Navit_maps_loaded = false;
364 final static int Navit_MAX_RECENT_DESTINATIONS = 50;
365 static String debug_item_dump = "";
366
367 // for future use ...
368 // public static String NavitDataDirectory = "/sdcard/";
369 public static String NavitDataDirectory_Maps = "/sdcard/zanavi/maps/";
370 static File[] NavitDataStorageDirs = null;
371
372 public static int GlobalScaleLevel = 0;
373
374 public class CopyFiles
375 {
376 public void copyFiles(File sourceLocation, File targetLocation) throws IOException
377 {
378 if (sourceLocation.isDirectory())
379 {
380 if (!targetLocation.exists())
381 {
382 targetLocation.mkdir();
383 }
384 File[] files = sourceLocation.listFiles();
385 for (File file : files)
386 {
387 InputStream in = new FileInputStream(file);
388 OutputStream out = new FileOutputStream(targetLocation + "/" + file.getName());
389
390 // Copy the bits from input stream to output stream
391 byte[] buf = new byte[1024];
392 int len;
393 while ((len = in.read(buf)) > 0)
394 {
395 out.write(buf, 0, len);
396 }
397 in.close();
398 out.close();
399 }
400
401 }
402 }
403 }
404
405 private static void copyFile(File sourceFile, File destFile) throws IOException
406 {
407 if (!sourceFile.exists())
408 {
409 return;
410 }
411 if (!destFile.exists())
412 {
413 destFile.createNewFile();
414 }
415 FileChannel source = null;
416 FileChannel destination = null;
417 source = new FileInputStream(sourceFile).getChannel();
418 destination = new FileOutputStream(destFile).getChannel();
419 if (destination != null && source != null)
420 {
421 destination.transferFrom(source, 0, source.size());
422 }
423 if (source != null)
424 {
425 source.close();
426 }
427 if (destination != null)
428 {
429 destination.close();
430 }
431
432 }
433
434 public static final class Navit_Address_Result_Struct implements Comparable<Navit_Address_Result_Struct>
435 {
436 String result_type; // TWN,STR,SHN
437 String item_id; // H<ddddd>L<ddddd> -> item.id_hi item.id_lo
438 float lat;
439 float lon;
440 String addr;
441
442 // function to sort address result list
443 public int compareTo(Navit_Address_Result_Struct comp)
444 {
445 return this.addr.toLowerCase().compareTo(comp.addr.toLowerCase());
446 }
447 }
448
449 public static final class Navit_Point_on_Map implements Serializable
450 {
451 /**
452 * struct for a point on the map
453 */
454 private static final long serialVersionUID = 6899215049749155051L;
455 String point_name = "";
456 String addon = null; // null -> normal, "1" -> home location
457 float lat = 0.0f;
458 float lon = 0.0f;
459 }
460
461 static ArrayList<Navit_Point_on_Map> map_points;
462
463 public static Set<String> Navit_Address_Result_double_index = new HashSet<String>();
464
465 public NavitAndroidOverlay NavitAOverlay2;
466 public static NavitAndroidOverlay NavitAOverlay2_s;
467
468 public static final class Navit_OSD_compass
469 {
470 Boolean angle_north_valid = false;
471 float angle_north = 0.0f;
472 Boolean angle_target_valid = false;
473 float angle_target = 0.0f;
474 Boolean direct_distance_to_target_valid = false;
475 String direct_distance_to_target = "";
476 }
477
478 public static final class Navit_OSD_route_001
479 {
480 Boolean driving_distance_to_target_valid = false;
481 String driving_distance_to_target = "";
482 Boolean arriving_time_valid = false;
483 String arriving_time = "";
484 Boolean arriving_secs_to_dest_valid = false;
485 String arriving_secs_to_dest = "";
486 }
487
488 public static final class Navit_OSD_route_nextturn
489 {
490 Boolean nextturn_image_filename_valid = false;
491 String nextturn_image_filename = "";
492 Boolean nextturn_image_valid = false;
493 Bitmap nextturn_image = null;
494 Boolean nextturn_distance_valid = false;
495 String nextturn_distance = "";
496 String nextturn_streetname = "";
497 String nextturn_streetname_systematic = "";
498 }
499
500 public static final class Navit_OSD_scale
501 {
502 Boolean scale_valid = false;
503 String scale_text = "";
504 int base = 0;
505 int var = 0;
506 }
507
508 public static Navit_OSD_compass OSD_compass = new Navit_OSD_compass();
509 public static Navit_OSD_route_001 OSD_route_001 = new Navit_OSD_route_001();
510 public static Navit_OSD_route_nextturn OSD_nextturn = new Navit_OSD_route_nextturn();
511 public static Navit_OSD_scale OSD_scale = new Navit_OSD_scale();
512
513 SimGPS Simulate = null;
514 WatchMem watchmem = null;
515
516 public static int sats = 0;
517 public static int satsInFix = 0;
518
519 // -------------- GPS fix and extrapolation vars -------------
520 // -------------- GPS fix and extrapolation vars -------------
521 // -------------- GPS fix and extrapolation vars -------------
522 static Location mLastLocation = null;
523 static long mLastLocationMillis = -1;
524 static boolean isGPSFix = false;
525 static int pos_is_underground = 0;
526 static boolean tunnel_extrapolation = false;
527 // -------------- GPS fix and extrapolation vars -------------
528 // -------------- GPS fix and extrapolation vars -------------
529 // -------------- GPS fix and extrapolation vars -------------
530
531 // public static Vibrator vibrator = null;
532
533 public Handler handler;
534 static PowerManager.WakeLock wl;
535 static PowerManager.WakeLock wl_cpu;
536 static PowerManager.WakeLock wl_navigating;
537 private NavitActivityResult ActivityResults[];
538 static AudioManager NavitAudioManager = null;
539 public static InputMethodManager mgr = null;
540 public static DisplayMetrics metrics = null;
541 public static Boolean show_soft_keyboard = false;
542 public static Boolean show_soft_keyboard_now_showing = false;
543 public static long last_pressed_menu_key = 0L;
544 public static long time_pressed_menu_key = 0L;
545 private static Intent startup_intent = null;
546 private static long startup_intent_timestamp = 0L;
547 public static String my_display_density = "mdpi";
548 private boolean searchBoxShown = false;
549 public static final int MAPDOWNLOAD_PRI_DIALOG = 1;
550 public static final int MAPDOWNLOAD_SEC_DIALOG = 2;
551 public static final int SEARCHRESULTS_WAIT_DIALOG = 3;
552 public static final int SEARCHRESULTS_WAIT_DIALOG_OFFLINE = 4;
553 public static final int ADDRESS_RESULTS_DIALOG_MAX = 10;
554 public ProgressDialog mapdownloader_dialog_pri = null;
555 public ProgressDialog mapdownloader_dialog_sec = null;
556 public ProgressDialog search_results_wait = null;
557 public ProgressDialog search_results_wait_offline = null;
558 public static Handler Navit_progress_h = null;
559 public static NavitMapDownloader mapdownloader_pri = null;
560 public static NavitMapDownloader mapdownloader_sec = null;
561 public static final int NavitDownloaderPriSelectMap_id = 967;
562 public static final int NavitDownloaderSecSelectMap_id = 968;
563 public static final int NavitDeleteSecSelectMap_id = 969;
564 public static final int NavitRecentDest_id = 970;
565 public static final int NavitGeoCoordEnter_id = 971;
566 public static final int NavitGPXConvChooser_id = 972;
567 public static final int NavitSendFeedback_id = 973;
568 public static final int NavitReplayFileConvChooser_id = 974;
569 public static int download_map_id = 0;
570 ProgressThread progressThread_pri = null;
571 ProgressThread progressThread_sec = null;
572 public static int search_results_towns = 0;
573 public static int search_results_streets = 0;
574 public static int search_results_streets_hn = 0;
575 public static int search_results_poi = 0;
576 public static Boolean search_hide_duplicates = false;
577 public static Boolean NavitStartupAlreadySearching = false;
578 SearchResultsThread searchresultsThread = null;
579 SearchResultsThread searchresultsThread_offline = null;
580 SearchResultsThreadSpinnerThread spinner_thread = null;
581 SearchResultsThreadSpinnerThread spinner_thread_offline = null;
582 public static Boolean NavitAddressSearchSpinnerActive = false;
583 public static final int MAP_NUM_PRIMARY = 11;
584 public static final int NavitAddressSearch_id_offline = 70;
585 public static final int NavitAddressSearch_id_online = 73;
586 public static final int NavitAddressResultList_id = 71;
587 public static final int NavitAddressSearchCountry_id = 74;
588 public static final int NavitMapPreview_id = 75;
589 public static final int NavitAddressSearch_id_gmaps = 76;
590 public static final int NavitAddressSearch_id_sharedest = 77;
591 public static final int ZANaviVoiceInput_id = 78;
592 public static final int NavitDonateFromSearch_id = 79;
593 public static int NavitSearchresultBarIndex = -1;
594 public static String NavitSearchresultBar_title = "";
595 public static String NavitSearchresultBar_text = "";
596 public static List<Navit_Address_Result_Struct> NavitAddressResultList_foundItems = new ArrayList<Navit_Address_Result_Struct>();
597
598 public static Boolean DemoVehicle = false;
599
600 static Typeface NavitStreetnameFont = null;
601
602 public SensorManager sensorManager = null;
603 //private static SensorManager sensorManager_ = null;
604
605 public static Context getBaseContext_ = null;
606 public static GpsStatus gps_st = null;
607
608 static Bitmap lane_none = null;
609 static Bitmap lane_left = null;
610 static Bitmap lane_right = null;
611 static Bitmap lane_merge_to_left = null;
612 static Bitmap lane_merge_to_right = null;
613 static String lane_destination = "";
614 static String lanes_text = "";
615 static String lanes_text1 = "";
616 static String lane_choices = "";
617 static String lane_choices1 = "";
618 static String lane_choices2 = "";
619 static int lanes_num = 0;
620 static int lanes_num_forward = 0;
621 static int lanes_num1 = 0;
622 static int lanes_num_forward1 = 0;
623 static int seg_len = 0;
624 static int cur_max_speed = -1;
625 static int cur_max_speed_corr = -1;
626 static boolean your_are_speeding = false;
627
628 // ------- new features -----------
629 // ------- new features -----------
630 // ------- new features -----------
631 // static boolean new_features = false; // for development ONLY !!
632 // ------- new features -----------
633 // ------- new features -----------
634 // ------- new features -----------
635
636 public static Bitmap long_green_arrow = null;
637 public static Bitmap menu_button = null;
638 public static RectF menu_button_rect = new RectF(-100, 1, 1, 1);
639 public static RectF menu_button_rect_touch = new RectF(-100, 1, 1, 1);
640 public static Bitmap follow_on = null;
641 public static Bitmap follow_off = null;
642 public static Bitmap follow_current = null;
643 public static Bitmap zoomin = null;
644 public static Bitmap zoomout = null;
645 // public static Bitmap bigmap_bitmap = null;
646 public static Bitmap oneway_arrow = null;
647 public static Bitmap oneway_bicycle_arrow = null;
648 public static Bitmap nav_arrow_stopped = null;
649 public static Bitmap nav_arrow_stopped_small = null;
650 public static Bitmap nav_arrow_moving = null;
651 public static Bitmap nav_arrow_moving_grey = null;
652 public static Bitmap nav_arrow_moving_small = null;
653 public static Bitmap nav_arrow_moving_shadow = null;
654 public static Bitmap nav_arrow_moving_shadow_small = null;
655
656 public static String Navit_last_address_search_string = "";
657 public static String Navit_last_address_hn_string = "";
658 public static Boolean Navit_last_address_full_file_search = false;
659 public static String Navit_last_address_search_country_iso2_string = "";
660 public static int Navit_last_address_search_country_flags = 3;
661 public static int Navit_last_address_search_country_id = 0;
662 public static Boolean Navit_last_address_partial_match = true;
663 public static Geocoder Navit_Geocoder = null;
664 public static String UserAgentString = null;
665 public static String UserAgentString_bind = null;
666 public static Boolean first_ever_startup = false;
667
668 public static Boolean Navit_Announcer = true;
669
670 public static final int MAP_NUM_SECONDARY = 12;
671 static String MAP_FILENAME_PATH = "/sdcard/zanavi/maps/";
672 static String MAPMD5_FILENAME_PATH = "/sdcard/zanavi/md5/";
673 static String CFG_FILENAME_PATH = "/sdcard/zanavi/";
674 static String NAVIT_DATA_DIR = "/data/data/com.zoffcc.applications.zanavi"; // later use: Context.getFilesDir().getPath();
675 static String NAVIT_DATA_SHARE_DIR = NAVIT_DATA_DIR + "/share";
676 static String NAVIT_DATA_DEBUG_DIR = CFG_FILENAME_PATH + "../debug/";
677 static String FIRST_STARTUP_FILE = NAVIT_DATA_SHARE_DIR + "/has_run_once.txt";
678 static String VERSION_FILE = NAVIT_DATA_SHARE_DIR + "/version.txt";
679 static final String Navit_DEST_FILENAME = "destinations.dat";
680 static final String Navit_CENTER_FILENAME = "center.txt";
681
682 static boolean need_recalc_route = false;
683
684 static Resources res_ = null;
685 static Window app_window = null;
686
687 public static String get_text(String in)
688 {
689 return NavitTextTranslations.get_text(in);
690 }
691
692 private boolean extractRes(String resname, String result)
693 {
694 int slash = -1;
695 boolean needs_update = false;
696 File resultfile;
697 Resources res = getResources();
698 Log.e("Navit", "Res Obj " + res);
699 Log.e("Navit", "Res Name " + resname);
700 Log.e("Navit", "result " + result);
701 int id = res.getIdentifier(resname, "raw", "com.zoffcc.applications.zanavi");
702 // int id = res.getIdentifier(resname, "raw", getPackageName());
703
704 Log.e("Navit", "Res ID " + id);
705
706 if (id == 0)
707 {
708 return false;
709 }
710
711 while ((slash = result.indexOf("/", slash + 1)) != -1)
712 {
713 if (slash != 0)
714 {
715 Log.e("Navit", "Checking " + result.substring(0, slash));
716 resultfile = new File(result.substring(0, slash));
717 if (!resultfile.exists())
718 {
719 Log.e("Navit", "Creating dir");
720 if (!resultfile.mkdir()) return false;
721 needs_update = true;
722 }
723 }
724 }
725
726 resultfile = new File(result);
727
728 if (!resultfile.exists())
729 {
730 needs_update = true;
731 }
732
733 if (!needs_update)
734 {
735 try
736 {
737 InputStream resourcestream = res.openRawResource(id);
738 FileInputStream resultfilestream = new FileInputStream(resultfile);
739 byte[] resourcebuf = new byte[1024];
740 byte[] resultbuf = new byte[1024];
741 int i = 0;
742
743 while ((i = resourcestream.read(resourcebuf)) != -1)
744 {
745 if (resultfilestream.read(resultbuf) != i)
746 {
747 Log.e("Navit", "Result is too short");
748 needs_update = true;
749 break;
750 }
751
752 for (int j = 0; j < i; j++)
753 {
754 if (resourcebuf[j] != resultbuf[j])
755 {
756 Log.e("Navit", "Result is different");
757 needs_update = true;
758 break;
759 }
760 }
761 if (needs_update) break;
762 }
763
764 if (!needs_update && resultfilestream.read(resultbuf) != -1)
765 {
766 Log.e("Navit", "Result is too long");
767 needs_update = true;
768 }
769
770 if (resultfilestream != null)
771 {
772 resultfilestream.close();
773 }
774 }
775 catch (Exception e)
776 {
777 Log.e("Navit", "Exception " + e.getMessage());
778 return false;
779 }
780 }
781
782 if (needs_update)
783 {
784 Log.e("Navit", "Extracting resource");
785 try
786 {
787 InputStream resourcestream = res.openRawResource(id);
788 FileOutputStream resultfilestream = new FileOutputStream(resultfile);
789 byte[] buf = new byte[1024];
790 int i = 0;
791
792 while ((i = resourcestream.read(buf)) != -1)
793 {
794 resultfilestream.write(buf, 0, i);
795 }
796
797 if (resultfilestream != null)
798 {
799 resultfilestream.close();
800 }
801 }
802 catch (Exception e)
803 {
804 Log.e("Navit", "Exception " + e.getMessage());
805 return false;
806 }
807 }
808 return true;
809 }
810
811 static OnAudioFocusChangeListener focusChangeListener = new OnAudioFocusChangeListener()
812 {
813 public void onAudioFocusChange(int focusChange)
814 {
815 // AudioManager am = Navit.NavitAudioManager;
816 switch (focusChange)
817 {
818
819 case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK):
820 // Lower the volume while ducking.
821 //mediaPlayer.setVolume(0.2f, 0.2f);
822 break;
823 case (AudioManager.AUDIOFOCUS_LOSS_TRANSIENT):
824 //pause();
825 break;
826
827 case (AudioManager.AUDIOFOCUS_LOSS):
828 //stop();
829 //ComponentName component = new ComponentName(AudioPlayerActivity.this, MediaControlReceiver.class);
830 //am.unregisterMediaButtonEventReceiver(component);
831 break;
832
833 case (AudioManager.AUDIOFOCUS_GAIN):
834 // Return the volume to normal and resume if paused.
835 //mediaPlayer.setVolume(1f, 1f);
836 //mediaPlayer.start();
837 break;
838 default:
839 break;
840 }
841 }
842 };
843
844 // private boolean checkPlayServices()
845
846 // {
847 // int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
848 //
849 // Log.i("PlayServices", "isGooglePlayServicesAvailable=" + status);
850 //
851 // if (status != ConnectionResult.SUCCESS)
852 // {
853 // if (GooglePlayServicesUtil.isUserRecoverableError(status))
854 // {
855 // Toast.makeText(this, "Recoverable error.", Toast.LENGTH_LONG).show();
856 // // showErrorDialog(status);
857 // }
858 // else
859 // {
860 // Toast.makeText(this, "This device is not supported.", Toast.LENGTH_LONG).show();
861 // }
862 // return false;
863 // }
864 // return true;
865 // }
866
867 // ----------------------------------------------------------------------------------------------------------
868 // thanks to: http://stackoverflow.com/questions/843675/how-do-i-find-out-if-the-gps-of-an-android-device-is-enabled
869 // ----------------------------------------------------------------------------------------------------------
870 private void buildAlertMessageNoGps()
871 {
872 try
873 {
874 AlertDialog.Builder builder = new AlertDialog.Builder(this);
875 builder.setMessage(Navit.get_text("Your GPS is disabled, do you want to enable it?")).setCancelable(false).setPositiveButton(Navit.get_text("Yes"), new DialogInterface.OnClickListener()
876 {
877 public void onClick(final DialogInterface dialog, final int id)
878 {
879 startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
880 }
881 }).setNegativeButton(Navit.get_text("No"), new DialogInterface.OnClickListener()
882 {
883 public void onClick(final DialogInterface dialog, final int id)
884 {
885 dialog.cancel();
886 }
887 });
888 AlertDialog alert = builder.create();
889 alert.show();
890 }
891 catch (Exception e)
892 {
893 e.printStackTrace();
894 }
895 }
896
897 /** Called when the activity is first created. */
898
899 // ----------- remove later -------------
900 // ----------- remove later -------------
901 @SuppressLint("NewApi")
902 // ----------- remove later -------------
903 // ----------- remove later -------------
904 @TargetApi(Build.VERSION_CODES.FROYO)
905 @Override
906 public void onCreate(Bundle savedInstanceState)
907 {
908 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
909
910 // ------- only after API level 9 -------
911 // ------- only after API level 9 -------
912 // try
913 // {
914 // StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDeath().penaltyLog().build());
915 // StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
916 //
917 // StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
918 // StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(old).permitDiskWrites().build());
919 // old = StrictMode.getThreadPolicy();
920 // StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(old).permitDiskReads().build());
921 //
922 // }
923 // catch (NoClassDefFoundError e)
924 // {
925 // }
926 // ------- only after API level 9 -------
927 // ------- only after API level 9 -------
928
929 // Log.e("Navit", "OnCreate");
930
931 // if (checkPlayServices())
932 // {
933 // }
934
935 getPrefs_theme();
936 getPrefs_theme_main();
937 Navit.applySharedTheme(this, p.PREF_current_theme_M);
938
939 super.onCreate(savedInstanceState);
940
941 Global_Navit_Object = this;
942 asset_mgr = getAssets();
943
944 OSD_blueish_bg_color = getResources().getColor(R.color.blueish_bg_color);
945
946 // getBaseContext_ = getBaseContext().getApplicationContext();
947 getBaseContext_ = getBaseContext();
948
949 last_orientation = getResources().getConfiguration().orientation;
950
951 content_resolver = getContentResolver();
952 // get_reglevel();
953
954 Display display_ = getWindowManager().getDefaultDisplay();
955 metrics = new DisplayMetrics();
956 display_.getMetrics(Navit.metrics);
957
958 road_book_items = new ArrayList<ListViewItem>();
959 fragmentManager = getSupportFragmentManager();
960
961 setContentView(R.layout.main_layout);
962 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
963 if (toolbar != null)
964 {
965 try
966 {
967 setSupportActionBar(toolbar);
968 // System.out.println("TTT01:" + toolbar);
969 }
970 catch (NoClassDefFoundError e)
971 {
972 }
973 }
974
975 try
976 {
977 getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
978 getSupportActionBar().setDisplayUseLogoEnabled(false);
979 getSupportActionBar().setIcon(R.drawable.icon);
980 getSupportActionBar().setDisplayShowHomeEnabled(true);
981 getSupportActionBar().setDisplayShowTitleEnabled(false);
982 }
983 catch (NoClassDefFoundError e)
984 {
985 }
986 catch (Exception e)
987 {
988 e.printStackTrace();
989 }
990
991 // ------------ bottom bar slider ----------------
992 // ------------ bottom bar slider ----------------
993 // ------------ bottom bar slider ----------------
994
995 bottom_bar_px = (int) getResources().getDimension(R.dimen.gui_top_container_height);
996 // System.out.println("VVV:bottom_bar_height:" + bottom_bar_px);
997 bottom_bar_slider_shadow_px = (int) getResources().getDimension(R.dimen.bottom_slide_view_shadow_compat_height);
998 // System.out.println("VVV:bottom_bar_slider_shadow_px:" + bottom_bar_slider_shadow_px);
999
1000 // final RelativeLayout a = (RelativeLayout) findViewById(R.id.bottom_bar_container);
1001 final FrameLayout a = (FrameLayout) findViewById(R.id.bottom_bar_slide);
1002 final RelativeLayout.LayoutParams pp22 = (RelativeLayout.LayoutParams) a.getLayoutParams();
1003
1004 // Calculate ToolBar height
1005 try
1006 {
1007 TypedValue tv = new TypedValue();
1008 if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
1009 {
1010 actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
1011 System.out.println("VVV:abh:" + actionBarHeight);
1012 }
1013 else
1014 {
1015 actionBarHeight = NavitGraphics.dp_to_px(144);
1016 }
1017 }
1018 catch (Exception e)
1019 {
1020 actionBarHeight = NavitGraphics.dp_to_px(144);
1021 }
1022
1023 final android.support.v7.widget.Toolbar view_toolbar_top = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
1024 ViewTreeObserver vto = view_toolbar_top.getViewTreeObserver();
1025 vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener()
1026 {
1027 @Override
1028 public void onGlobalLayout()
1029 {
1030 view_toolbar_top.getViewTreeObserver().removeGlobalOnLayoutListener(this);
1031 // int width = view_toolbar_top.getMeasuredWidth();
1032 int height = view_toolbar_top.getMeasuredHeight();
1033 Navit.actionBarHeight = height;
1034 // System.out.println("hhh:88=" + Navit.actionBarHeight);
1035 Navit.cur_y_margin_bottom_bar_touch = Navit.map_view_height + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px; // try to put view at bottom
1036
1037 pp22.setMargins(0, (int) Navit.cur_y_margin_bottom_bar_touch, 0, 0); // left, top, right, bottom
1038 a.setLayoutParams(pp22);
1039 a.requestLayout();
1040 }
1041 });
1042
1043 // actionBarHeight = 168;
1044
1045 // final int SWIPE_MIN_DISTANCE = NavitGraphics.dp_to_px(25);
1046 // final float SWIPE_THRESHOLD_VELOCITY = 5.5f;
1047 // final float FLING_PIXELS_PER_SECOND = 100;
1048 // final float maxFlingVelocity = ViewConfiguration.get(this).getScaledMaximumFlingVelocity();
1049 final ViewConfiguration vc = ViewConfiguration.get(this);
1050 final int swipeMinDistance = vc.getScaledPagingTouchSlop();
1051 final int swipeThresholdVelocity = vc.getScaledMinimumFlingVelocity();
1052 swipeMaxOffPath = vc.getScaledTouchSlop();
1053 // (there is also vc.getScaledMaximumFlingVelocity() one could check against)
1054
1055 // setup some values --------
1056 NavitGraphics.long_press_on_screen_max_distance = swipeMaxOffPath;
1057 // setup some values --------
1058
1059 class MyGestureDetector extends SimpleOnGestureListener
1060 {
1061 @Override
1062 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
1063 {
1064 try
1065 {
1066 // float velocityPercentY = velocityY / maxFlingVelocity; // the percent is a value in the range of (0, 1]
1067 // float normalizedVelocityY = velocityPercentY * FLING_PIXELS_PER_SECOND; // where PIXELS_PER_SECOND is a device-independent measurement
1068
1069 // System.out.println("VVV:" + (e1.getY() - e2.getY()) + " " + NavitGraphics.dp_to_px((int) (e1.getY() - e2.getY())) + " " + maxFlingVelocity + " " + velocityY + " " + velocityPercentY + " " + normalizedVelocityY + " " + SWIPE_THRESHOLD_VELOCITY);
1070
1071 // System.out.println("VVV:2:" + swipeMinDistance + " " + swipeThresholdVelocity + " " + swipeMaxOffPath);
1072
1073 // bottom to top
1074 if (e1.getY() - e2.getY() > swipeMinDistance && Math.abs(velocityY) > swipeThresholdVelocity)
1075 {
1076 //int featureWidth = getMeasuredWidth();
1077 //mActiveFeature = (mActiveFeature < (mItems.size() - 1)) ? mActiveFeature + 1 : mItems.size() - 1;
1078 //smoothScrollTo(mActiveFeature * featureWidth, 0);
1079 //System.out.println("GS:002:up:" + velocityY + " " + e2.getY() + " " + e1.getY());
1080
1081 animate_bottom_bar_up();
1082
1083 return true;
1084 }
1085 // top to bottom
1086 else if (e2.getY() - e1.getY() > swipeMinDistance && Math.abs(velocityY) > swipeThresholdVelocity)
1087 {
1088 //int featureWidth = getMeasuredWidth();
1089 //mActiveFeature = (mActiveFeature > 0) ? mActiveFeature - 1 : 0;
1090 //smoothScrollTo(mActiveFeature * featureWidth, 0);
1091 //System.out.println("GS:003:down:" + velocityY + " " + e1.getY() + " " + e2.getY());
1092
1093 animate_bottom_bar_down();
1094
1095 return true;
1096 }
1097 }
1098 catch (Exception e)
1099 {
1100 //System.out.println("GS:009:EE:" + e.getMessage());
1101 }
1102 return false;
1103 }
1104 }
1105 mGestureDetector = new GestureDetector(new MyGestureDetector());
1106
1107 push_pin_view = (ImageView) findViewById(R.id.bottom_slide_left_side);
1108 push_pin_view.setOnClickListener(new ImageView.OnClickListener()
1109 {
1110 public void onClick(View v)
1111 {
1112 try
1113 {
1114 toggle_follow_button();
1115 }
1116 catch (Exception e)
1117 {
1118 }
1119 }
1120 });
1121
1122 cur_y_margin_bottom_bar_touch = 0; // try to put view at bottom
1123
1124 a.setOnTouchListener(new View.OnTouchListener()
1125 {
1126 @Override
1127 synchronized public boolean onTouch(View v, MotionEvent m)
1128 {
1129
1130 int action = m.getAction();
1131
1132 if (mGestureDetector.onTouchEvent(m))
1133 {
1134 //System.out.println("GS:001:fling!!");
1135 // System.out.println("FRAG:fling:011");
1136 return true;
1137 }
1138 else if (action == MotionEvent.ACTION_DOWN)
1139 {
1140 last_y_bottom_bar_touch = m.getY();
1141
1142 // put roadbook into layout -----------
1143 FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
1144
1145 try
1146 {
1147 if (road_book == null)
1148 {
1149 road_book = new ZANaviRoadbookFragment();
1150 // System.out.println("FRAG:attach:001");
1151 fragmentTransaction.replace(R.id.roadbook_fragment_container, road_book, "");
1152 fragmentTransaction.commitAllowingStateLoss();
1153 // fragmentTransaction.show(road_book);
1154 }
1155 else
1156 {
1157 // System.out.println("FRAG:attached:003");
1158 }
1159 }
1160 catch (Exception ef)
1161 {
1162 }
1163 // put roadbook into layout -----------
1164
1165 return true;
1166 }
1167 else if ((action == MotionEvent.ACTION_UP) || (action == MotionEvent.ACTION_CANCEL))
1168 {
1169 // System.out.println("FRAG:up/cancel:012");
1170
1171 // release
1172 if (cur_y_margin_bottom_bar_touch > (bottom_y_margin_bottom_bar_touch / 2))
1173 {
1174 // snap back to bottom
1175 animate_bottom_bar_down();
1176 }
1177 else
1178 {
1179 // snap top top
1180 animate_bottom_bar_up();
1181 }
1182 }
1183 else
1184 // if (action == MotionEvent.ACTION_MOVE)
1185 {
1186 // System.out.println("FRAG:*else*:012");
1187
1188 if (Math.abs(last_y_bottom_bar_touch - m.getY()) > 2)
1189 {
1190 float last_margin = cur_y_margin_bottom_bar_touch;
1191 cur_y_margin_bottom_bar_touch = cur_y_margin_bottom_bar_touch - (last_y_bottom_bar_touch - m.getY());
1192
1193 if ((cur_y_margin_bottom_bar_touch >= 0) && (cur_y_margin_bottom_bar_touch <= bottom_y_margin_bottom_bar_touch))
1194 {
1195 // System.out.println("VVV:move:" + cur_y_margin_bottom_bar_touch + " " + bottom_y_margin_bottom_bar_touch);
1196
1197 last_y_bottom_bar_touch = m.getY() + (last_y_bottom_bar_touch - m.getY());
1198 RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) a.getLayoutParams();
1199 relativeParams.setMargins(0, (int) cur_y_margin_bottom_bar_touch, 0, 0); // left, top, right, bottom
1200 a.setLayoutParams(relativeParams);
1201 a.requestLayout();
1202 }
1203 else
1204 {
1205 // System.out.println("VVV:revert");
1206
1207 // revert position
1208 cur_y_margin_bottom_bar_touch = last_margin;
1209 }
1210 }
1211
1212 }
1213 return true;
1214 }
1215 });
1216 // ------------ bottom bar slider ----------------
1217 // ------------ bottom bar slider ----------------
1218 // ------------ bottom bar slider ----------------
1219
1220 // init cancel dialog!! ----------
1221 // init cancel dialog!! ----------
1222 Message msg2 = new Message();
1223 Bundle b2 = new Bundle();
1224 b2.putString("text", "");
1225 msg2.what = 0;
1226 msg2.setData(b2);
1227 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg2);
1228 // init cancel dialog!! ----------
1229 // init cancel dialog!! ----------
1230
1231 app_window = getWindow();
1232
1233 // ---------------- set some directories -----------------
1234 // ---------------- set some directories -----------------
1235 NAVIT_DATA_DIR = this.getFilesDir().getPath();
1236 this.getFilesDir().mkdirs();
1237 // ---
1238 // System.out.println("data dir=" + NAVIT_DATA_DIR);
1239 NAVIT_DATA_SHARE_DIR = NAVIT_DATA_DIR + "/share/";
1240 File tmp3 = new File(NAVIT_DATA_SHARE_DIR);
1241 tmp3.mkdirs();
1242 // ---
1243 FIRST_STARTUP_FILE = NAVIT_DATA_SHARE_DIR + "/has_run_once.txt";
1244 VERSION_FILE = NAVIT_DATA_SHARE_DIR + "/version.txt";
1245 // ---------------- set some directories -----------------
1246 // ---------------- set some directories -----------------
1247
1248 try
1249 {
1250 toneG = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
1251 }
1252 catch (Exception e)
1253 {
1254 }
1255
1256 try
1257 {
1258 Class.forName("android.app.backup.BackupManager");
1259 backupManager = new BackupManager(this);
1260 }
1261 catch (ClassNotFoundException e)
1262 {
1263 e.printStackTrace();
1264 }
1265 catch (Exception e)
1266 {
1267 e.printStackTrace();
1268 }
1269
1270 int width_ = display_.getWidth();
1271 int height_ = display_.getHeight();
1272 Log.e("Navit", "Navit -> pixels x=" + width_ + " pixels y=" + height_);
1273 Log.e("Navit", "Navit -> dpi=" + Navit.metrics.densityDpi);
1274 Log.e("Navit", "Navit -> density=" + Navit.metrics.density);
1275 Log.e("Navit", "Navit -> scaledDensity=" + Navit.metrics.scaledDensity);
1276
1277 try
1278 {
1279 // send overspill factor to C-code
1280 Message msg33 = new Message();
1281 Bundle b33 = new Bundle();
1282 b33.putInt("Callback", 104);
1283 msg33.setData(b33);
1284 NavitGraphics.callback_handler.sendMessage(msg33);
1285 }
1286 catch (Exception eee)
1287 {
1288 }
1289
1290 // ----- service -----
1291 // ----- service -----
1292 ZANaviMapDownloaderServiceIntent = new Intent(Navit.getBaseContext_, ZANaviMapDownloaderService.class);
1293 // ----- service -----
1294 // ----- service -----
1295
1296 System.out.println("Navit:onCreate:JTHREAD ID=" + Thread.currentThread().getId());
1297 System.out.println("Navit:onCreate:THREAD ID=" + NavitGraphics.GetThreadId());
1298
1299 // bitmaps for lanes
1300 lane_left = BitmapFactory.decodeResource(getResources(), R.drawable.lane_left);
1301 lane_right = BitmapFactory.decodeResource(getResources(), R.drawable.lane_right);
1302 lane_merge_to_left = BitmapFactory.decodeResource(getResources(), R.drawable.lane_merge_to_left);
1303 lane_merge_to_right = BitmapFactory.decodeResource(getResources(), R.drawable.lane_merge_to_right);
1304 lane_none = BitmapFactory.decodeResource(getResources(), R.drawable.lane_none);
1305 // bitmaps for lanes
1306
1307 // paint for bitmapdrawing on map
1308 NavitGraphics.paint_for_map_display.setAntiAlias(true);
1309 NavitGraphics.paint_for_map_display.setFilterBitmap(true);
1310
1311 // sky
1312 NavitGraphics.paint_sky_day.setAntiAlias(true);
1313 NavitGraphics.paint_sky_day.setColor(Color.parseColor("#79BAEC"));
1314 NavitGraphics.paint_sky_night.setAntiAlias(true);
1315 NavitGraphics.paint_sky_night.setColor(Color.parseColor("#090909"));
1316 // stars
1317 NavitGraphics.paint_sky_night_stars.setColor(Color.parseColor("#DEDDEF"));
1318 // twilight
1319 NavitGraphics.paint_sky_twilight1.setColor(Color.parseColor("#090909"));
1320 NavitGraphics.paint_sky_twilight2.setColor(Color.parseColor("#113268"));
1321 NavitGraphics.paint_sky_twilight3.setColor(Color.parseColor("#79BAEC"));
1322
1323 Random m = new Random();
1324 int i6 = 0;
1325 for (i6 = 0; i6 < (NavitGraphics.max_stars + 1); i6++)
1326 {
1327 NavitGraphics.stars_x[i6] = m.nextFloat();
1328 NavitGraphics.stars_y[i6] = m.nextFloat();
1329 NavitGraphics.stars_size[i6] = m.nextInt(3) + 1;
1330 }
1331
1332 res_ = getResources();
1333 int ii = 0;
1334 NavitGraphics.dl_thread_cur = 0;
1335 for (ii = 0; ii < NavitGraphics.dl_thread_max; ii++)
1336 {
1337 NavitGraphics.dl_thread[ii] = null;
1338 }
1339
1340 String font_file_name = "Roboto-Regular.ttf"; // "LiberationSans-Regular.ttf";
1341 NavitStreetnameFont = Typeface.createFromAsset(getBaseContext().getAssets(), font_file_name);
1342 // System.out.println("NavitStreetnameFont" + NavitStreetnameFont);
1343
1344 Navit_maps_loaded = false;
1345
1346 // only take arguments here, onResume gets called all the time (e.g. when screenblanks, etc.)
1347 Navit.startup_intent = this.getIntent();
1348 // hack! remeber timstamp, and only allow 4 secs. later in onResume to set target!
1349 Navit.startup_intent_timestamp = System.currentTimeMillis();
1350 Log.e("Navit", "**1**A " + startup_intent.getAction());
1351 Log.e("Navit", "**1**D " + startup_intent.getDataString());
1352 Log.e("Navit", "**1**I " + startup_intent.toString());
1353 try
1354 {
1355 Log.e("Navit", "**1**DH E " + startup_intent.getExtras().describeContents());
1356 }
1357 catch (Exception ee)
1358 {
1359 }
1360
1361 startup_status = Navit_Status_NORMAL_STARTUP;
1362
1363 // glSurfaceView = (GLSurfaceView) findViewById(R.id.glSurfaceView_001);
1364 // glSurfaceView.setEGLContextClientVersion(2); // enable OpenGL 2.0
1365 // glSurfaceView.setRenderer(new GlRenderer());
1366 // glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); // only render on demand
1367 //
1368 // // draw some sample lines ----
1369 // // draw some sample lines ----
1370 // // draw some sample lines ----
1371 // ZANaviGlLine vertLine = new ZANaviGlLine();
1372 // vertLine.SetVerts(1000f, 1000f, 0f, -1000f, -1000f, 0f);
1373 // vertLine.SetColor(.8f, .8f, 0f, 1.0f);
1374 //
1375 // float[] mMVPMatrix = new float[16];
1376 //
1377 // // Position the eye behind the origin.
1378 // final float eyeX = 0.0f;
1379 // final float eyeY = 0.0f;
1380 // final float eyeZ = 1.5f;
1381 //
1382 // // We are looking toward the distance
1383 // final float lookX = 0.0f;
1384 // final float lookY = 0.0f;
1385 // final float lookZ = -5.0f;
1386 //
1387 // // Set our up vector. This is where our head would be pointing were we holding the camera.
1388 // final float upX = 0.0f;
1389 // final float upY = 1.0f;
1390 // final float upZ = 0.0f;
1391 //
1392 // // Set the view matrix. This matrix can be said to represent the camera position.
1393 // // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
1394 // // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
1395 // Matrix.setLookAtM(mMVPMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
1396 //
1397 // vertLine.draw(mMVPMatrix);
1398 //
1399 // glSurfaceView.postInvalidate();
1400 // glSurfaceView.requestRender();
1401 // glSurfaceView.postInvalidate();
1402 // // draw some sample lines ----
1403 // // draw some sample lines ----
1404 // // draw some sample lines ----
1405
1406 // setup graphics objects
1407 // setup graphics objects
1408 // setup graphics objects
1409 NG__vehicle = new NavitGraphics(this, 1, 0, 0, 50, 50, 65535, 0, 0);
1410 NG__map_main = new NavitGraphics(this, 0, 0, 0, 100, 100, 0, 0, 0);
1411 Navit.N_NavitGraphics = NG__map_main;
1412 // setup graphics objects
1413 // setup graphics objects
1414 // setup graphics objects
1415
1416 NV = new NavitVehicle(this);
1417 NSp = new NavitSpeech2(this);
1418
1419 // init translated text
1420 NavitTextTranslations.init();
1421
1422 // set the new locale here -----------------------------------
1423 getPrefs_loc();
1424 activatePrefs_loc();
1425 // set the new locale here -----------------------------------
1426
1427 // get the local language -------------
1428 Locale locale = java.util.Locale.getDefault();
1429 String lang = locale.getLanguage();
1430 String langu = lang;
1431 String langc = lang;
1432 Log.e("Navit", "lang=" + lang);
1433 int pos = langu.indexOf('_');
1434 if (pos != -1)
1435 {
1436 langc = langu.substring(0, pos);
1437 langu = langc + langu.substring(pos).toUpperCase(locale);
1438 Log.e("Navit", "substring lang " + langu.substring(pos).toUpperCase(locale));
1439 // set lang. for translation
1440 NavitTextTranslations.main_language = langc;
1441 NavitTextTranslations.sub_language = langu.substring(pos).toUpperCase(locale);
1442 }
1443 else
1444 {
1445 String country = locale.getCountry();
1446 Log.e("Navit", "Country1 " + country);
1447 Log.e("Navit", "Country2 " + country.toUpperCase(locale));
1448 langu = langc + "_" + country.toUpperCase(locale);
1449 // set lang. for translation
1450 NavitTextTranslations.main_language = langc;
1451 NavitTextTranslations.sub_language = country.toUpperCase(locale);
1452 }
1453 Log.e("Navit", "Language " + lang);
1454 // get the local language -------------
1455
1456 TextView no_maps_text = (TextView) this.findViewById(R.id.no_maps_text);
1457 no_maps_text.setText("\n\n\n" + Navit.get_text("No Maps installed") + "\n" + Navit.get_text("Please download a map") + "\n\n");
1458 // no_maps_text.postInvalidate();
1459
1460 // set map cache size here -----------------------------------
1461 getPrefs_mapcache();
1462 activatePrefs_mapcache();
1463 // set map cache size here -----------------------------------
1464
1465 // get map data dir and set it -----------------------------
1466 getPrefs_mapdir();
1467 activatePrefs_mapdir(true);
1468 // get map data dir and set it -----------------------------
1469
1470 // get special prefs here ------------------------------------
1471 get_prefs_highdpi();
1472 // get special prefs here ------------------------------------
1473
1474 // make sure the new path for the navitmap.bin file(s) exist!!
1475 File navit_maps_dir = new File(MAP_FILENAME_PATH);
1476 navit_maps_dir.mkdirs();
1477 // create nomedia files
1478 File nomedia_file = new File(MAP_FILENAME_PATH + ".nomedia");
1479 try
1480 {
1481 nomedia_file.createNewFile();
1482 }
1483 catch (Exception e1)
1484 {
1485 e1.printStackTrace();
1486 }
1487 // create nomedia files
1488
1489 // check if we already have a borders.bin file (if not, then extract the included simplified one)
1490 File b_ = new File(MAP_FILENAME_PATH + "/borders.bin");
1491 try
1492 {
1493 if (!b_.exists())
1494 {
1495 try
1496 {
1497 File c_ = new File(MAPMD5_FILENAME_PATH + "/borders.bin.md5");
1498 c_.delete();
1499 }
1500 catch (Exception e2)
1501 {
1502
1503 }
1504 Log.e("Navit", "trying to extract borders simple resource to:" + MAP_FILENAME_PATH + "/borders.bin");
1505 if (!extractRes("borders_simple", MAP_FILENAME_PATH + "/borders.bin"))
1506 {
1507 Log.e("Navit", "Failed to extract borders simple resource to:" + MAP_FILENAME_PATH + "/borders.bin");
1508 }
1509 }
1510 }
1511 catch (Exception e)
1512 {
1513
1514 }
1515 // check if we already have a borders.bin file
1516
1517 // make sure the new path for config files exist
1518 File navit_cfg_dir = new File(CFG_FILENAME_PATH);
1519 navit_cfg_dir.mkdirs();
1520
1521 // make sure the new path for the navitmap.bin file(s) exist!!
1522 File navit_mapsmd5_dir = new File(MAPMD5_FILENAME_PATH);
1523 navit_mapsmd5_dir.mkdirs();
1524
1525 // make sure the share dir exists, otherwise the infobox will not show
1526 File navit_data_share_dir = new File(NAVIT_DATA_SHARE_DIR);
1527 navit_data_share_dir.mkdirs();
1528
1529 File dd = new File(NAVIT_DATA_DEBUG_DIR);
1530 dd.mkdirs();
1531
1532 // try to create cat. file if it does not exist
1533 File navit_maps_catalogue = new File(CFG_FILENAME_PATH + NavitMapDownloader.CAT_FILE);
1534 if (!navit_maps_catalogue.exists())
1535 {
1536 FileOutputStream fos_temp;
1537 try
1538 {
1539 fos_temp = new FileOutputStream(navit_maps_catalogue);
1540 fos_temp.write((NavitMapDownloader.MAP_CAT_HEADER + "\n").getBytes()); // just write header to the file
1541 fos_temp.flush();
1542 fos_temp.close();
1543 }
1544 catch (Exception e)
1545 {
1546 e.printStackTrace();
1547 }
1548 }
1549
1550 // ---------- downloader threads ----------------
1551 NavitMapDownloader.MULTI_NUM_THREADS = 1;
1552 PackageInfo pkgInfo;
1553 Navit_DonateVersion_Installed = false;
1554 try
1555 {
1556 // is the donate version installed?
1557 pkgInfo = getPackageManager().getPackageInfo("com.zoffcc.applications.zanavi_donate", 0);
1558 String sharedUserId = pkgInfo.sharedUserId;
1559 System.out.println("str nd=" + sharedUserId);
1560 if (sharedUserId.equals("com.zoffcc.applications.zanavi"))
1561 {
1562 System.out.println("##bonus 001##");
1563 Navit_DonateVersion_Installed = true;
1564 NavitMapDownloader.MULTI_NUM_THREADS = NavitMapDownloader.MULTI_NUM_THREADS_MAX;
1565 }
1566 }
1567 catch (NameNotFoundException e)
1568 {
1569 e.printStackTrace();
1570 }
1571 catch (Exception e)
1572 {
1573 e.printStackTrace();
1574 }
1575
1576 try
1577 {
1578 if (get_reglevel() == 1)
1579 {
1580 System.out.println("##U:bonus 001##");
1581 Navit_DonateVersion_Installed = true;
1582 NavitMapDownloader.MULTI_NUM_THREADS = NavitMapDownloader.MULTI_NUM_THREADS_MAX;
1583 }
1584 }
1585 catch (Exception e)
1586 {
1587 e.printStackTrace();
1588 }
1589
1590 try
1591 {
1592 // is the "large map" donate version installed?
1593 pkgInfo = getPackageManager().getPackageInfo("com.zoffcc.applications.zanavi_largemap_donate", 0);
1594 String sharedUserId = pkgInfo.sharedUserId;
1595 System.out.println("str lm=" + sharedUserId);
1596
1597 if (sharedUserId.equals("com.zoffcc.applications.zanavi"))
1598 {
1599 System.out.println("##bonus 002##");
1600 Navit_DonateVersion_Installed = true;
1601 Navit_Largemap_DonateVersion_Installed = true;
1602 NavitMapDownloader.MULTI_NUM_THREADS = NavitMapDownloader.MULTI_NUM_THREADS_MAX;
1603 }
1604 }
1605 catch (NameNotFoundException e)
1606 {
1607 e.printStackTrace();
1608 }
1609 catch (Exception e)
1610 {
1611 e.printStackTrace();
1612 }
1613
1614 try
1615 {
1616 if (get_reglevel() == 1)
1617 {
1618 System.out.println("##U:bonus 002##");
1619 Navit_DonateVersion_Installed = true;
1620 Navit_Largemap_DonateVersion_Installed = true;
1621 NavitMapDownloader.MULTI_NUM_THREADS = NavitMapDownloader.MULTI_NUM_THREADS_MAX;
1622 }
1623 }
1624 catch (Exception e)
1625 {
1626 e.printStackTrace();
1627 }
1628
1629 // update map list
1630 NavitMapDownloader.init_maps_without_donate_largemaps();
1631 // ---------- downloader threads ----------------
1632
1633 // ---- detect menu button ----
1634 detect_menu_button();
1635
1636 if (Navit.metrics.densityDpi >= 320) //&& (PREF_shrink_on_high_dpi))
1637 {
1638 Navit.menu_button = BitmapFactory.decodeResource(getResources(), R.drawable.menu_001);
1639 }
1640 else
1641 {
1642 Navit.menu_button = BitmapFactory.decodeResource(getResources(), R.drawable.menu_001_small);
1643 }
1644
1645 Navit.long_green_arrow = BitmapFactory.decodeResource(getResources(), R.drawable.long_green_arrow);
1646
1647 Navit.follow_on = BitmapFactory.decodeResource(getResources(), R.drawable.follow);
1648 Navit.follow_off = BitmapFactory.decodeResource(getResources(), R.drawable.follow_off);
1649 Navit.follow_current = Navit.follow_on;
1650
1651 if ((Navit.metrics.densityDpi >= 320) && (p.PREF_shrink_on_high_dpi))
1652 {
1653 float factor;
1654 factor = (float) NavitGraphics.Global_Scaled_DPI_normal / (float) Navit.metrics.densityDpi;
1655 factor = factor * 1.7f;
1656 //
1657 BitmapFactory.Options o = new BitmapFactory.Options();
1658 o.inDither = true;
1659 //o.inScaled = true;
1660 //o.inTargetDensity = NavitGraphics.Global_Scaled_DPI_normal;
1661 Navit.nav_arrow_stopped = BitmapFactory.decodeResource(getResources(), R.drawable.navigation_arrow_stopped, o);
1662 Navit.nav_arrow_moving = BitmapFactory.decodeResource(getResources(), R.drawable.navigation_arrow_moving, o);
1663 Navit.nav_arrow_moving_grey = BitmapFactory.decodeResource(getResources(), R.drawable.navigation_arrow_moving_grey, o);
1664 Navit.nav_arrow_moving_shadow = BitmapFactory.decodeResource(getResources(), R.drawable.navigation_arrow_moving_shadow, o);
1665
1666 Navit.nav_arrow_stopped_small = Bitmap.createScaledBitmap(Navit.nav_arrow_stopped, (int) (Navit.nav_arrow_stopped.getWidth() / NavitGraphics.strech_factor_3d_map * factor), (int) (Navit.nav_arrow_stopped.getHeight() / NavitGraphics.strech_factor_3d_map * factor), true);
1667 Navit.nav_arrow_moving_small = Bitmap.createScaledBitmap(Navit.nav_arrow_moving, (int) (Navit.nav_arrow_moving.getWidth() / NavitGraphics.strech_factor_3d_map * factor), (int) (Navit.nav_arrow_moving.getHeight() / NavitGraphics.strech_factor_3d_map * factor), true);
1668 Navit.nav_arrow_moving_shadow_small = Bitmap.createScaledBitmap(Navit.nav_arrow_moving_shadow, (int) (Navit.nav_arrow_moving_shadow.getWidth() / NavitGraphics.strech_factor_3d_map * factor), (int) (Navit.nav_arrow_moving_shadow.getHeight() / NavitGraphics.strech_factor_3d_map * factor), true);
1669 }
1670 else
1671 {
1672 Navit.nav_arrow_stopped = BitmapFactory.decodeResource(getResources(), R.drawable.navigation_arrow_stopped);
1673 Navit.nav_arrow_moving = BitmapFactory.decodeResource(getResources(), R.drawable.navigation_arrow_moving);
1674 Navit.nav_arrow_moving_grey = BitmapFactory.decodeResource(getResources(), R.drawable.navigation_arrow_moving_grey);
1675 Navit.nav_arrow_moving_shadow = BitmapFactory.decodeResource(getResources(), R.drawable.navigation_arrow_moving_shadow);
1676
1677 Navit.nav_arrow_stopped_small = Bitmap.createScaledBitmap(Navit.nav_arrow_stopped, (int) (Navit.nav_arrow_stopped.getWidth() / NavitGraphics.strech_factor_3d_map), (int) (Navit.nav_arrow_stopped.getHeight() / NavitGraphics.strech_factor_3d_map), true);
1678 Navit.nav_arrow_moving_small = Bitmap.createScaledBitmap(Navit.nav_arrow_moving, (int) (Navit.nav_arrow_moving.getWidth() / NavitGraphics.strech_factor_3d_map), (int) (1.5 * Navit.nav_arrow_moving.getHeight() / NavitGraphics.strech_factor_3d_map), true);
1679 Navit.nav_arrow_moving_shadow_small = Bitmap.createScaledBitmap(Navit.nav_arrow_moving_shadow, (int) (Navit.nav_arrow_moving_shadow.getWidth() / NavitGraphics.strech_factor_3d_map), (int) (1.5 * Navit.nav_arrow_moving_shadow.getHeight() / NavitGraphics.strech_factor_3d_map), true);
1680 }
1681
1682 Navit.zoomin = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_in_32_32);
1683 Navit.zoomout = BitmapFactory.decodeResource(getResources(), R.drawable.zoom_out_32_32);
1684
1685 //Navit.oneway_arrow = BitmapFactory.decodeResource(getResources(), R.drawable.oneway);
1686 Navit.oneway_arrow = BitmapFactory.decodeResource(getResources(), R.drawable.oneway_large);
1687 Navit.oneway_bicycle_arrow = BitmapFactory.decodeResource(getResources(), R.drawable.oneway_bicycle_large);
1688
1689 // *******************
1690 // *******************
1691 // *******************
1692 // *******************
1693 // check/init the catalogue file for downloaded maps
1694 NavitMapDownloader.init_cat_file();
1695 // *******************
1696 // *******************
1697 // *******************
1698 // *******************
1699
1700 xmlconfig_unpack_file = false;
1701 write_new_version_file = false;
1702 try
1703 {
1704 NavitAppVersion = "" + this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
1705 NavitAppVersion_string = "" + this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
1706 }
1707 catch (NameNotFoundException e)
1708 {
1709 e.printStackTrace();
1710 NavitAppVersion = "1";
1711 NavitAppVersion_string = "1";
1712 }
1713 catch (Exception e)
1714 {
1715 e.printStackTrace();
1716 NavitAppVersion = "2";
1717 NavitAppVersion_string = "2";
1718 }
1719
1720 try
1721 {
1722 File navit_version = new File(VERSION_FILE);
1723 if (!navit_version.exists())
1724 {
1725 System.out.println("version file does not exist");
1726 NavitAppVersion_prev = "-1";
1727 write_new_version_file = true;
1728 }
1729 else
1730 {
1731 // files exists, read in the prev. verison number
1732 System.out.println("version file is here");
1733 FileInputStream fos_temp;
1734 byte[] buffer = new byte[101];
1735 fos_temp = new FileInputStream(navit_version);
1736 int len = fos_temp.read(buffer, 0, 100);
1737 if (len != -1)
1738 {
1739 // use only len bytes to make the string (the rest is garbage!!)
1740 NavitAppVersion_prev = new String(buffer).substring(0, len);
1741 }
1742 else
1743 {
1744 NavitAppVersion_prev = "-1";
1745 write_new_version_file = true;
1746 }
1747 fos_temp.close();
1748 }
1749
1750 }
1751 catch (Exception e)
1752 {
1753 NavitAppVersion_prev = "-1";
1754 write_new_version_file = true;
1755 e.printStackTrace();
1756 }
1757
1758 System.out.println("vprev:" + NavitAppVersion_prev + " vcur:" + NavitAppVersion);
1759
1760 if (NavitAppVersion_prev.compareTo(NavitAppVersion) != 0)
1761 {
1762 // different version
1763 System.out.println("different version!!");
1764 write_new_version_file = true;
1765 xmlconfig_unpack_file = true;
1766
1767 //if ((NavitAppVersion_prev.compareTo("-1") != 0) && (NavitAppVersion.compareTo("-1") != 0))
1768 //{
1769 // user has upgraded to a new version of ZANavi
1770 startup_status = Navit_Status_UPGRADED_TO_NEW_VERSION;
1771 //}
1772 }
1773 else
1774 {
1775 // same version
1776 System.out.println("same version");
1777 xmlconfig_unpack_file = false;
1778 }
1779
1780 // write new version file
1781 if (write_new_version_file)
1782 {
1783 try
1784 {
1785 System.out.println("write version file");
1786 FileOutputStream fos_temp;
1787 File navit_version = new File(VERSION_FILE);
1788 navit_version.delete();
1789 fos_temp = new FileOutputStream(navit_version);
1790 fos_temp.write(NavitAppVersion.getBytes());
1791 fos_temp.flush();
1792 fos_temp.close();
1793 }
1794 catch (Exception e)
1795 {
1796 e.printStackTrace();
1797 }
1798 }
1799
1800 // Sample useragent strings:
1801 //
1802 // Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0a1) Gecko/20110616 Firefox/7.0a1 SeaMonkey/2.4a1
1803 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; GT-I9100 Build/GINGERBREAD)
1804 // Dalvik/1.2.0 (Linux; U; Android 2.2.1; GT-S5830 Build/FROYO)
1805 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; HTC Desire S Build/GRI40)
1806 // Dalvik/1.2.0 (Linux; U; Android 2.2.2; MB525 Build/3.4.2-179)
1807 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; HTC Wildfire S A510e Build/GRI40)
1808 // Wget/1.10.2
1809 // Dalvik/1.4.0 (Linux; U; Android 2.3.3; sdk Build/GRI34)
1810 // Dalvik/1.2.0 (Linux; U; Android 2.2.2; MB525 Build/3.4.2-164)
1811 // Dalvik/1.2.0 (Linux; U; Android 2.2; GT-I9000 Build/FROYO)
1812 // Dalvik/1.2.0 (Linux; U; Android 2.2.1; GT-S5570L Build/FROYO)
1813 // Dalvik/1.2.0 (Linux; U; Android 2.2.1; GT-I9000 Build/FROYO)
1814 // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
1815 String ANDROID = android.os.Build.VERSION.SDK; //The current development codename, or the string "REL" if this is a release build.
1816 //String BOARD = android.os.Build.BOARD; //The name of the underlying board, like "goldfish".
1817 //String BOOTLOADER = android.os.Build.BOOTLOADER; // The system bootloader version number.
1818 String BRAND = android.os.Build.BRAND; //The brand (e.g., carrier) the software is customized for, if any.
1819 //String CPU_ABI = android.os.Build.CPU_ABI; //The name of the instruction set (CPU type + ABI convention) of native code.
1820 //String CPU_ABI2 = android.os.Build.CPU_ABI2; // The name of the second instruction set (CPU type + ABI convention) of native code.
1821 String DEVICE = android.os.Build.DEVICE; // The name of the industrial design.
1822 String DISPLAY = android.os.Build.DISPLAY; //A build ID string meant for displaying to the user
1823 //String FINGERPRINT = android.os.Build.FINGERPRINT; //A string that uniquely identifies this build.
1824 //String HARDWARE = android.os.Build.HARDWARE; //The name of the hardware (from the kernel command line or /proc).
1825 //String HOST = android.os.Build.HOST;
1826 //String ID = android.os.Build.ID; //Either a changelist number, or a label like "M4-rc20".
1827 String MANUFACTURER = android.os.Build.MANUFACTURER; //The manufacturer of the product/hardware.
1828 //String MODEL = android.os.Build.MODEL; //The end-user-visible name for the end product.
1829 //String PRODUCT = android.os.Build.PRODUCT; //The name of the overall product.
1830 //String RADIO = android.os.Build.RADIO; //The radio firmware version number.
1831 //String TAGS = android.os.Build.TAGS; //Comma-separated tags describing the build, like "unsigned,debug".
1832 //String TYPE = android.os.Build.TYPE; //The type of build, like "user" or "eng".
1833 //String USER = android.os.Build.USER;
1834
1835 String android_version = "Android " + ANDROID;
1836 String android_device = MANUFACTURER + " " + BRAND + " " + DEVICE;
1837
1838 api_version_int = Integer.valueOf(android.os.Build.VERSION.SDK);
1839 System.out.println("XXX:API=" + api_version_int);
1840 if (api_version_int > 10)
1841 {
1842 Navit.PAINT_OLD_API = false;
1843 }
1844 else
1845 {
1846 Navit.PAINT_OLD_API = true;
1847 }
1848
1849 if (MANUFACTURER.equalsIgnoreCase("amazon"))
1850 {
1851 // we are on amazon device
1852 ZANaviNormalDonateActivity.on_amazon_device = true;
1853 }
1854
1855 // debug
1856 // debug
1857 // android_device = "telechips telechips m801";
1858 // debug
1859 // debug
1860
1861 String android_rom_name = DISPLAY;
1862
1863 if (FDBL)
1864 {
1865 android_rom_name = android_rom_name + "; FD";
1866 }
1867
1868 if (Navit_DonateVersion_Installed == false)
1869 {
1870 UserAgentString = "Mozilla/5.0 (Linux; U; " + "Z" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
1871 UserAgentString_bind = "Mozilla/5.0 @__THREAD__@ (Linux; U; " + "Z" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
1872 }
1873 else
1874 {
1875 if (Navit_Largemap_DonateVersion_Installed == false)
1876 {
1877 UserAgentString = "Mozilla/5.0 (Linux; U; " + "donateZ" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
1878 UserAgentString_bind = "Mozilla/5.0 @__THREAD__@ (Linux; U; " + "donateZ" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
1879 }
1880 else
1881
1882 {
1883 UserAgentString = "Mozilla/5.0 (Linux; U; " + "LMdonateLMZ" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
1884 UserAgentString_bind = "Mozilla/5.0 @__THREAD__@ (Linux; U; " + "LMdonateLMZ" + NavitAppVersion + "; " + android_version + "; " + android_device + " " + android_rom_name + ")";
1885 }
1886 }
1887 // System.out.println("UA=" + UserAgentString);
1888
1889 // --------- enable GPS ? --------------
1890 // --------- enable GPS ? --------------
1891 // try
1892 // {
1893 // final LocationManager llmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
1894 // if (!llmanager.isProviderEnabled(LocationManager.GPS_PROVIDER))
1895 // {
1896 // buildAlertMessageNoGps();
1897 // }
1898 // }
1899 // catch (Exception e)
1900 // {
1901 // e.printStackTrace();
1902 // }
1903 // --------- enable GPS ? --------------
1904 // --------- enable GPS ? --------------
1905
1906 unsupported = false;
1907 try
1908 {
1909 if (android_device.toLowerCase().contains("telechips"))
1910 {
1911 if (android_device.toLowerCase().contains("m801"))
1912 {
1913 // if the donate version is already installed, dont disable the app
1914 if (Navit_DonateVersion_Installed == false)
1915 {
1916 if (Navit_Largemap_DonateVersion_Installed == false)
1917 {
1918 // activate [Weltbild] Cat Nova again (19.12.2011)
1919 // ** // unsupported = true;
1920 }
1921 }
1922 }
1923 }
1924 }
1925 catch (Exception e)
1926 {
1927 e.printStackTrace();
1928 }
1929
1930 try
1931 {
1932 // this hangs the emulator, if emulator < 2.3 (only works in emulator >= 2.3)!!
1933 if (!NAVIT_IS_EMULATOR)
1934 {
1935 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
1936 }
1937 }
1938 catch (Exception e3)
1939 {
1940 e3.printStackTrace();
1941 }
1942
1943 // try
1944 // {
1945 // vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
1946 // }
1947 // catch (Exception e)
1948 // {
1949 // e.printStackTrace();
1950 // }
1951 //sensorManager_ = sensorManager;
1952
1953 generic_alert_box = new AlertDialog.Builder(this);
1954 /*
1955 * show info box for first time users
1956 */
1957 AlertDialog.Builder infobox = new AlertDialog.Builder(this);
1958 //. english text: Welcome to ZANavi
1959 infobox.setTitle(Navit.get_text("__INFO_BOX_TITLE__")); //TRANS
1960 infobox.setCancelable(false);
1961 final TextView message = new TextView(this);
1962 message.setFadingEdgeLength(20);
1963 message.setVerticalFadingEdgeEnabled(true);
1964 message.setPadding(10, 5, 10, 5);
1965 message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
1966 message.setGravity(Gravity.LEFT);
1967 // message.setScrollBarStyle(TextView.SCROLLBARS_INSIDE_OVERLAY);
1968 // message.setVerticalScrollBarEnabled(true);
1969 RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1970 rlp.leftMargin = 7;
1971 rlp.rightMargin = 7;
1972
1973 Navit.Navit_Geocoder = null;
1974 try
1975 {
1976 // for online search
1977 Navit.Navit_Geocoder = new Geocoder(this);
1978 }
1979 catch (Exception e)
1980 {
1981 e.printStackTrace();
1982 }
1983
1984 //TRANS
1985 infobox.setPositiveButton(Navit.get_text("Ok"), new DialogInterface.OnClickListener()
1986 {
1987 public void onClick(DialogInterface arg0, int arg1)
1988 {
1989 Log.e("Navit", "Ok, user saw the infobox");
1990 }
1991 });
1992
1993 //TRANS
1994 infobox.setNeutralButton(Navit.get_text("More info"), new DialogInterface.OnClickListener()
1995 {
1996 public void onClick(DialogInterface arg0, int arg1)
1997 {
1998 Log.e("Navit", "user wants more info, show the website");
1999 // URL to ZANavi Manual (in english language)
2000 String url = "http://zanavi.cc/index.php/Manual";
2001 if (FDBL)
2002 {
2003 url = "http://fd.zanavi.cc/manual";
2004 }
2005 Intent i = new Intent(Intent.ACTION_VIEW);
2006 i.setData(Uri.parse(url));
2007 startActivity(i);
2008 }
2009 });
2010
2011 info_popup_seen_count_end = false;
2012 File navit_first_startup = new File(FIRST_STARTUP_FILE);
2013 // if file does NOT exist, show the info box
2014 if (!navit_first_startup.exists())
2015 {
2016 // set first-ever-startup flag
2017 first_ever_startup = true;
2018 info_popup_seen_count_end = true; // don't show on first ever start of the app
2019 startup_status = Navit_Status_COMPLETE_NEW_INSTALL;
2020 FileOutputStream fos_temp;
2021 try
2022 {
2023 info_popup_seen_count++;
2024 fos_temp = new FileOutputStream(navit_first_startup);
2025 fos_temp.write((int) info_popup_seen_count); // use to store info popup seen count
2026 fos_temp.flush();
2027 fos_temp.close();
2028
2029 message.setLayoutParams(rlp);
2030 //. TRANSLATORS: multiline info text for first startup of application (see en_US for english text)
2031 final SpannableString s = new SpannableString(" " + Navit.get_text("__INFO_BOX_TEXT__")); //TRANS
2032 Linkify.addLinks(s, Linkify.WEB_URLS);
2033 message.setText(s);
2034 message.setMovementMethod(LinkMovementMethod.getInstance());
2035 infobox.setView(message);
2036
2037 infobox.show();
2038 }
2039 catch (Exception e)
2040 {
2041 e.printStackTrace();
2042 }
2043 }
2044 else
2045 {
2046 FileOutputStream fos_temp;
2047 FileInputStream fis_temp;
2048 try
2049 {
2050 fis_temp = new FileInputStream(navit_first_startup);
2051 info_popup_seen_count = fis_temp.read();
2052 fis_temp.close();
2053
2054 if (info_popup_seen_count < 0)
2055 {
2056 info_popup_seen_count = 0;
2057 }
2058
2059 // we wrote "A" -> (int)65 previously, so account for that
2060 if (info_popup_seen_count == 65)
2061 {
2062 info_popup_seen_count = 0;
2063 }
2064
2065 if (info_popup_seen_count > info_popup_seen_count_max)
2066 {
2067 info_popup_seen_count_end = true;
2068 }
2069 else
2070 {
2071 info_popup_seen_count++;
2072 fos_temp = new FileOutputStream(navit_first_startup);
2073 fos_temp.write((int) info_popup_seen_count); // use to store info popup seen count
2074 fos_temp.flush();
2075 fos_temp.close();
2076 }
2077 }
2078 catch (Exception e)
2079 {
2080 e.printStackTrace();
2081 }
2082 }
2083 /*
2084 * show info box for first time users
2085 */
2086
2087 // show info box for upgrade
2088 // if (startup_status == Navit_Status_UPGRADED_TO_NEW_VERSION)
2089 // {
2090 // try
2091 // {
2092 // message.setLayoutParams(rlp);
2093 // // upgrade message
2094 // String upgrade_summary = "\n\n***********\n";
2095 // // upgrade message
2096 // final SpannableString s = new SpannableString("\n" + "ZANavi " + NavitAppVersion_string + "\n\n" + "upgraded" + upgrade_summary);
2097 // Linkify.addLinks(s, Linkify.WEB_URLS);
2098 // message.setText(s);
2099 // message.setMovementMethod(LinkMovementMethod.getInstance());
2100 // infobox.setView(message);
2101 //
2102 // infobox.show();
2103 // }
2104 // catch (Exception e)
2105 // {
2106 // e.printStackTrace();
2107 // }
2108 //
2109 // }
2110 // show info box for upgrade
2111
2112 //
2113 // ----------- info popup
2114 // ----------- info popup
2115 // ----------- info popup
2116 // ----------- info popup
2117 //
2118 if ((!info_popup_seen_count_end) || (startup_status == Navit_Status_UPGRADED_TO_NEW_VERSION))
2119 {
2120 try
2121 {
2122 //Builder a1 = new AlertDialog.Builder(this);
2123 //dialog_info_popup = a1.show();
2124 dialog_info_popup = new Dialog(this);
2125
2126 dialog_info_popup.setContentView(R.layout.info_popup);
2127 Button b_i1 = (Button) dialog_info_popup.findViewById(R.id.dialogButtonOK_i1);
2128
2129 TextView tv_i1 = (TextView) dialog_info_popup.findViewById(R.id.text_i1);
2130 final String ZANAVI_MSG_PLUGIN_MARKET_LINK = "https://play.google.com/store/apps/details?id=com.zoffcc.applications.zanavi_msg";
2131 tv_i1.setText(Html.fromHtml("\n<br>Try the new Plugin to be notified when there are updates to your downloaded maps.\n" + "<br><a href=\"" + ZANAVI_MSG_PLUGIN_MARKET_LINK + "\">install Plugin</a>\n<br>\n<br>" + "Probier das neue Plugin damit du immer benachrichtigt wirst wenn es Kartenupdates gibt.\n<br>" + "<a href=\"" + ZANAVI_MSG_PLUGIN_MARKET_LINK + "\">Plugin installieren</a>\n<br>"));
2132
2133 try
2134 {
2135 tv_i1.setMovementMethod(LinkMovementMethod.getInstance());
2136 }
2137 catch (Exception ee3)
2138 {
2139 }
2140
2141 b_i1.setText("Ok (" + (1 + info_popup_seen_count_max - info_popup_seen_count) + ")");
2142 b_i1.setOnClickListener(new View.OnClickListener()
2143 {
2144 public void onClick(View v)
2145 {
2146 try
2147 {
2148 dialog_info_popup.cancel();
2149 }
2150 catch (Exception e)
2151 {
2152
2153 }
2154
2155 try
2156 {
2157 dialog_info_popup.dismiss();
2158 }
2159 catch (Exception e)
2160 {
2161
2162 }
2163
2164 try
2165 {
2166 // draw map no-async
2167 Message msg = new Message();
2168 Bundle b = new Bundle();
2169 b.putInt("Callback", 64);
2170 msg.setData(b);
2171 NavitGraphics.callback_handler.sendMessage(msg);
2172 }
2173 catch (Exception e)
2174 {
2175 e.printStackTrace();
2176 }
2177
2178 }
2179 });
2180 dialog_info_popup.setCancelable(true);
2181 dialog_info_popup.show();
2182 dialog_info_popup.getWindow().getDecorView().setBackgroundResource(R.drawable.rounded_bg);
2183 dialog_info_popup.setTitle(" Try the new Plugin");
2184 }
2185 catch (Exception e)
2186 {
2187 e.printStackTrace();
2188 }
2189 }
2190 //
2191 // ----------- info popup
2192 // ----------- info popup
2193 // ----------- info popup
2194 //
2195
2196 // make handler statically available for use in "msg_to_msg_handler"
2197 Navit_progress_h = this.progress_handler;
2198
2199 // try
2200 // {
2201 // Navit.bigmap_bitmap = BitmapFactory.decodeResource(getResources(), R.raw.bigmap_colors_zanavi2);
2202 // }
2203 // catch (Exception e)
2204 // {
2205 // // when not enough memory is available, then disable large world overview map!
2206 // System.gc();
2207 // Navit.bigmap_bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
2208 // }
2209 // // ------no----- // Navit.bigmap_bitmap.setDensity(120); // set our dpi!!
2210
2211 try
2212 {
2213 setVolumeControlStream(AudioManager.STREAM_MUSIC);
2214 ActivityResults = new NavitActivityResult[16];
2215 }
2216 catch (Exception e)
2217 {
2218 e.printStackTrace();
2219 }
2220
2221 try
2222 {
2223 NavitAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
2224 }
2225 catch (Exception e)
2226 {
2227 e.printStackTrace();
2228 }
2229
2230 PowerManager pm = null;
2231 try
2232 {
2233 pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
2234 }
2235 catch (Exception e)
2236 {
2237 e.printStackTrace();
2238 }
2239
2240 try
2241 {
2242 // -- // pm.wakeUp(SystemClock.uptimeMillis()); // -- //
2243 // **screen always full on** // wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen");
2244 // **screen can go off, cpu will stay on** // wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen");
2245
2246 // this works so far, lets the screen dim, but it cpu and screen stays on
2247 wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen");
2248 }
2249 catch (Exception e)
2250 {
2251 e.printStackTrace();
2252 wl = null;
2253 }
2254
2255 try
2256 {
2257 wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ZANaviNeedCpu");
2258 }
2259 catch (Exception e)
2260 {
2261 e.printStackTrace();
2262 wl_cpu = null;
2263 }
2264
2265 try
2266 {
2267 wl_navigating = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "ZANaviNavigationOn");
2268 }
2269 catch (Exception e)
2270 {
2271 Log.e("Navit", "WakeLock NAV: create failed!!");
2272 e.printStackTrace();
2273 wl_navigating = null;
2274 }
2275
2276 // try
2277 // {
2278 // if (wl_navigating != null)
2279 // {
2280 // wl_navigating.acquire();
2281 // Log.e("Navit", "WakeLock NAV: acquire 00");
2282 // }
2283 // }
2284 // catch (Exception e)
2285 // {
2286 // Log.e("Navit", "WakeLock NAV: something wrong 00");
2287 // e.printStackTrace();
2288 // }
2289
2290 // try
2291 // {
2292 // if (wl != null)
2293 // {
2294 // try
2295 // {
2296 // wl.release();
2297 // }
2298 // catch (Exception e2)
2299 // {
2300 // }
2301 // wl.acquire();
2302 // Log.e("Navit", "WakeLock: acquire 1");
2303 // }
2304 // }
2305 // catch (Exception e)
2306 // {
2307 // e.printStackTrace();
2308 // }
2309
2310 // -- extract overview maps --
2311 // -- extract overview maps --
2312
2313 // File navit_worldmap2_file = new File(NAVIT_DATA_DIR + "/share/worldmap2.txt");
2314 File navit_worldmap2_file = new File(MAP_FILENAME_PATH + "/worldmap2.txt");
2315 if (!navit_worldmap2_file.exists())
2316 {
2317 if (!extractRes("worldmap2", MAP_FILENAME_PATH + "/worldmap2.txt"))
2318 {
2319 Log.e("Navit", "Failed to extract worldmap2.txt");
2320 }
2321 }
2322
2323 File navit_worldmap5_file = new File(MAP_FILENAME_PATH + "/worldmap5.txt");
2324 if (!navit_worldmap5_file.exists())
2325 {
2326 if (!extractRes("worldmap5", MAP_FILENAME_PATH + "/worldmap5.txt"))
2327 {
2328 Log.e("Navit", "Failed to extract worldmap5.txt");
2329 }
2330 }
2331 // -- extract overview maps --
2332 // -- extract overview maps --
2333
2334 Log.e("Navit", "trying to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language);
2335 if (!extractRes(NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language, NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language + "/LC_MESSAGES/navit.mo"))
2336 {
2337 Log.e("Navit", "Failed to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language);
2338 }
2339
2340 Log.e("Navit", "trying to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language.toLowerCase());
2341 if (!extractRes(NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language.toLowerCase(), NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language + "/LC_MESSAGES/navit.mo"))
2342 {
2343 Log.e("Navit", "Failed to extract language resource " + NavitTextTranslations.main_language + "_" + NavitTextTranslations.sub_language.toLowerCase());
2344 }
2345
2346 Log.e("Navit", "trying to extract language resource " + NavitTextTranslations.main_language);
2347 if (!extractRes(NavitTextTranslations.main_language, NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "/LC_MESSAGES/navit.mo"))
2348 {
2349 Log.e("Navit", "Failed to extract language resource " + NavitTextTranslations.main_language);
2350 }
2351
2352 // DEBUG - check if language file is on SDCARD -
2353 try
2354 {
2355 File debug_mo_src = new File("/sdcard/zanavi/debug/navit.mo");
2356 File debug_mo_dest = new File(NAVIT_DATA_DIR + "/locale/" + NavitTextTranslations.main_language + "/LC_MESSAGES/navit.mo");
2357 //* File navit_debug_dir = new File("/sdcard/zanavi/debug/");
2358 //* navit_debug_dir.mkdirs();
2359 copyFile(debug_mo_src, debug_mo_dest);
2360 }
2361 catch (Exception e)
2362 {
2363 e.printStackTrace();
2364 }
2365 // DEBUG - check if language file is on SDCARD -
2366
2367 File navit_config_xml_file = new File(NAVIT_DATA_SHARE_DIR + "/navit.xml");
2368 if ((!navit_config_xml_file.exists()) || (NAVIT_ALWAYS_UNPACK_XMLFILE))
2369 {
2370 xmlconfig_unpack_file = true;
2371 Log.e("Navit", "navit.xml does not exist, unpacking in any case");
2372 }
2373
2374 my_display_density = "mdpi";
2375 // ldpi display (120 dpi)
2376
2377 NavitGraphics.Global_want_dpi = Navit.metrics.densityDpi;
2378 NavitGraphics.Global_want_dpi_other = Navit.metrics.densityDpi;
2379
2380 if (Navit.metrics.densityDpi <= 120)
2381 {
2382 my_display_density = "ldpi";
2383 if (xmlconfig_unpack_file)
2384 {
2385 if (!extractRes("navitldpi", NAVIT_DATA_SHARE_DIR + "/navit.xml"))
2386 {
2387 Log.e("Navit", "Failed to extract navit.xml for ldpi device(s)");
2388 }
2389 }
2390 }
2391 // mdpi display (160 dpi)
2392 else if ((Navit.metrics.densityDpi > 120) && (Navit.metrics.densityDpi <= 160))
2393 {
2394 my_display_density = "mdpi";
2395 if (xmlconfig_unpack_file)
2396 {
2397 if (!extractRes("navitmdpi", NAVIT_DATA_SHARE_DIR + "/navit.xml"))
2398 {
2399 Log.e("Navit", "Failed to extract navit.xml for mdpi device(s)");
2400 }
2401 }
2402 }
2403 // hdpi display (240 dpi)
2404 else if ((Navit.metrics.densityDpi > 160) && (Navit.metrics.densityDpi < 320))
2405 //else if (Navit.metrics.densityDpi == 240)
2406 {
2407 my_display_density = "hdpi";
2408 if (xmlconfig_unpack_file)
2409 {
2410 if (!extractRes("navithdpi", NAVIT_DATA_SHARE_DIR + "/navit.xml"))
2411 {
2412 Log.e("Navit", "Failed to extract navit.xml for hdpi device(s)");
2413 }
2414 }
2415 }
2416 // xhdpi display (320 dpi)
2417 else if (Navit.metrics.densityDpi >= 320)
2418 {
2419 // set the map display DPI down. otherwise everything will be very small and unreadable
2420 // and performance will be very low
2421 if (p.PREF_shrink_on_high_dpi)
2422 {
2423 NavitGraphics.Global_want_dpi = NavitGraphics.Global_Scaled_DPI_normal;
2424 }
2425 NavitGraphics.Global_want_dpi_other = NavitGraphics.Global_Scaled_DPI_normal;
2426
2427 Log.e("Navit", "found xhdpi device, this is not fully supported yet");
2428 Log.e("Navit", "using hdpi values for compatibility");
2429 my_display_density = "hdpi";
2430 if (xmlconfig_unpack_file)
2431 {
2432 if (!extractRes("navithdpi", NAVIT_DATA_SHARE_DIR + "/navit.xml"))
2433 {
2434 Log.e("Navit", "Failed to extract navit.xml for xhdpi device(s)");
2435 }
2436 }
2437 }
2438 else
2439 {
2440 /* default, meaning we just dont know what display this is */
2441 if (xmlconfig_unpack_file)
2442 {
2443 if (!extractRes("navitmdpi", NAVIT_DATA_SHARE_DIR + "/navit.xml"))
2444 {
2445 Log.e("Navit", "Failed to extract navit.xml (default version)");
2446 }
2447 }
2448 }
2449 // Debug.startMethodTracing("calc");
2450
2451 // if (unsupported)
2452 // {
2453 // class CustomListener implements View.OnClickListener
2454 // {
2455 // private final Dialog dialog;
2456 //
2457 // public CustomListener(Dialog dialog)
2458 // {
2459 // this.dialog = dialog;
2460 // }
2461 //
2462 // @Override
2463 // public void onClick(View v)
2464 // {
2465 //
2466 // // Do whatever you want here
2467 //
2468 // // If tou want to close the dialog, uncomment the line below
2469 // //dialog.dismiss();
2470 // }
2471 // }
2472 //
2473 // AlertDialog.Builder dialog = new AlertDialog.Builder(this);
2474 // dialog.setTitle(Navit.get_text("WeltBild Tablet")); //TRANS
2475 // dialog.setCancelable(false);
2476 // dialog.setMessage("Your device is not supported!");
2477 // dialog.show();
2478 // //Button theButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
2479 // //theButton.setOnClickListener(new CustomListener(dialog));
2480 // }
2481
2482 int have_dpi = Navit.metrics.densityDpi;
2483 if (NavitGraphics.Global_want_dpi == have_dpi)
2484 {
2485 NavitGraphics.Global_dpi_factor = 1;
2486 }
2487 {
2488 NavitGraphics.Global_dpi_factor = ((float) NavitGraphics.Global_want_dpi / (float) have_dpi);
2489 }
2490
2491 // gggggggggggggggggggggggggg new !!!!!!!!!!!!!!!!!!!!
2492
2493 // --> dont use!! NavitMain(this, langu, android.os.Build.VERSION.SDK_INT);
2494 Log.e("Navit", "android.os.Build.VERSION.SDK_INT=" + Integer.valueOf(android.os.Build.VERSION.SDK));
2495
2496 // -- report share dir back to C-code --
2497 //Message msg2 = new Message();
2498 //Bundle b2 = new Bundle();
2499 //b2.putInt("Callback", 82);
2500 //b2.putString("s", NAVIT_DATA_DIR + "/share/");
2501 //msg2.setData(b2);
2502 //N_NavitGraphics.callback_handler.sendMessage(msg2);
2503 // -- report share dir back to C-code --
2504
2505 // -- report data dir back to C-code --
2506 //msg2 = new Message();
2507 //b2 = new Bundle();
2508 //b2.putInt("Callback", 84);
2509 //b2.putString("s", NAVIT_DATA_DIR + "/");
2510 //msg2.setData(b2);
2511 //N_NavitGraphics.callback_handler.sendMessage(msg2);
2512 // -- report share dir back to C-code --
2513
2514 draw_osd_thread = new drawOSDThread();
2515 draw_osd_thread.start();
2516
2517 cwthr = new CWorkerThread();
2518 cwthr.start();
2519
2520 // --new--
2521 cwthr.StartMain(this, langu, Integer.valueOf(android.os.Build.VERSION.SDK), "" + Navit.metrics.densityDpi, NAVIT_DATA_DIR, NAVIT_DATA_SHARE_DIR);
2522
2523 // --old--
2524 // NavitMain(this, langu, Integer.valueOf(android.os.Build.VERSION.SDK), my_display_density);
2525 // --old--
2526 // NavitActivity(3);
2527
2528 // CAUTION: don't use android.os.Build.VERSION.SDK_INT if <uses-sdk android:minSdkVersion="3" />
2529 // You will get exception on all devices with Android 1.5 and lower
2530 // because Build.VERSION.SDK_INT is since SDK 4 (Donut 1.6)
2531
2532 // (see: http://developer.android.com/guide/appendix/api-levels.html)
2533 // Platform Version API Level
2534 // =============================================
2535 // Android 4.0.3 15
2536 // Android 4.0, 4.0.1, 4.0.2 14
2537 // Android 3.2 13
2538 // Android 3.1 12
2539 // Android 3.0 11
2540 // Android 2.3.3 10
2541 // Android 2.3.1 9
2542 // Android 2.2 8
2543 // Android 2.1 7
2544 // Android 2.0.1 6
2545 // Android 2.0 5
2546 // Android 1.6 4
2547 // Android 1.5 3
2548 // Android 1.1 2
2549 // Android 1.0 1
2550
2551 Navit.mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
2552
2553 //try
2554 //{
2555 // Thread.sleep(2000);
2556 //}
2557 //catch (InterruptedException e)
2558 //{
2559 //}
2560
2561 //getPrefs();
2562 //activatePrefs();
2563
2564 // unpack some localized Strings
2565 // a test now, later we will unpack all needed strings for java, here at this point!!
2566 //String x = NavitGraphics.getLocalizedString("Austria");
2567 //Log.e("Navit", "x=" + x);
2568 Navit.show_mem_used();
2569
2570 /*
2571 * GpsStatus.Listener listener = new GpsStatus.Listener()
2572 * {
2573 * public void onGpsStatusChanged(int event)
2574 * {
2575 * //System.out.println("xxxxx");
2576 * if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS)
2577 * {
2578 * }
2579 * }
2580 * };
2581 */
2582
2583 try
2584 {
2585 Intent sintent = new Intent();
2586 sintent.setPackage("com.zoffcc.applications.zanavi_msg");
2587 sintent.setAction("com.zoffcc.applications.zanavi_msg.ZanaviCloudService");
2588 // ComponentName cname = startService(sintent);
2589 // Log.i("NavitPlugin", "start Service res=" + cname);
2590 // System.out.println("NavitPlugin:bind to Service");
2591 boolean res_bind = bindService(sintent, serviceConnection, Context.BIND_AUTO_CREATE);
2592 // Log.i("NavitPlugin", "bind to Service res=" + res_bind);
2593 }
2594 catch (Exception e)
2595 {
2596 e.printStackTrace();
2597 }
2598 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
2599 }
2600
2601 public static void show_mem_used() // wrapper
2602 {
2603 try
2604 {
2605 Message msg = Navit_progress_h.obtainMessage();
2606 Bundle b = new Bundle();
2607 msg.what = 14;
2608 msg.setData(b);
2609 Navit_progress_h.sendMessage(msg);
2610 }
2611 catch (Exception e)
2612 {
2613 e.printStackTrace();
2614 }
2615 }
2616
2617 public static void show_mem_used_real()
2618 {
2619 try
2620 {
2621 if (p.PREF_show_debug_messages)
2622 {
2623 // --------- OLD method -----------
2624 // --------- OLD method -----------
2625 // int usedMegs;
2626 // //System.gc();
2627 // usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
2628 // //Debug.MemoryInfo meminfo = new Debug.MemoryInfo();
2629 // //Debug.getMemoryInfo(meminfo);
2630 //
2631 // if (usedMegs_old != usedMegs)
2632 // {
2633 // String usedMegsString = String.format("Memory Used: %d MB", usedMegs);
2634 // //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);
2635 // Navit.set_debug_messages2(usedMegsString);
2636 // }
2637 // usedMegs_old = usedMegs;
2638 // --------- OLD method -----------
2639 // --------- OLD method -----------
2640
2641 // --------- NEW method -----------
2642 // --------- NEW method -----------
2643 String usedMegs = logHeap(Global_Navit_Object.getClass());
2644 if (usedMegs_str_old.compareTo(usedMegs) != 0)
2645 {
2646 Navit.set_debug_messages2(usedMegs);
2647 }
2648 usedMegs_str_old = usedMegs;
2649 // --------- NEW method -----------
2650 // --------- NEW method -----------
2651 }
2652 }
2653 catch (Exception e)
2654 {
2655 e.printStackTrace();
2656 }
2657 }
2658
2659 public static void set_debug_messages(String texta, String textb, String textc)
2660 {
2661 try
2662 {
2663 NavitGraphics.debug_line_1 = texta;
2664 NavitGraphics.debug_line_2 = textb;
2665 NavitGraphics.debug_line_3 = textc;
2666 NavitGraphics.NavitMsgTv_.setMaxLines(4);
2667 NavitGraphics.NavitMsgTv_.setLines(4);
2668 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3 + "\n " + NavitGraphics.debug_line_4);
2669 //System.out.println("invalidate 022");
2670 NavitGraphics.NavitMsgTv_.postInvalidate();
2671 }
2672 catch (Exception e)
2673 {
2674 e.printStackTrace();
2675 }
2676 }
2677
2678 public static void set_debug_messages1(String text)
2679 {
2680 try
2681 {
2682 NavitGraphics.debug_line_1 = text;
2683 NavitGraphics.NavitMsgTv_.setMaxLines(4);
2684 NavitGraphics.NavitMsgTv_.setLines(4);
2685 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3 + "\n " + NavitGraphics.debug_line_4);
2686 //System.out.println("invalidate 023");
2687 NavitGraphics.NavitMsgTv_.postInvalidate();
2688 }
2689 catch (Exception e)
2690 {
2691 e.printStackTrace();
2692 }
2693 }
2694
2695 public static void set_debug_messages2(String text)
2696 {
2697 try
2698 {
2699 NavitGraphics.debug_line_2 = text;
2700 //NavitGraphics.NavitMsgTv_.setMaxLines(4);
2701 //NavitGraphics.NavitMsgTv_.setLines(4);
2702
2703 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3 + "\n " + NavitGraphics.debug_line_4);
2704 //System.out.println("invalidate 024");
2705 NavitGraphics.NavitMsgTv_.postInvalidate();
2706 }
2707 catch (Exception e)
2708 {
2709 e.printStackTrace();
2710 }
2711 }
2712
2713 public static void set_debug_messages3(String text)
2714 {
2715 try
2716 {
2717 NavitGraphics.debug_line_3 = text;
2718 NavitGraphics.NavitMsgTv_.setMaxLines(4);
2719 NavitGraphics.NavitMsgTv_.setLines(4);
2720 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3 + "\n " + NavitGraphics.debug_line_4);
2721 //System.out.println("invalidate 025");
2722 NavitGraphics.NavitMsgTv_.postInvalidate();
2723 }
2724 catch (Exception e)
2725 {
2726 e.printStackTrace();
2727 }
2728 }
2729
2730 public static void set_debug_messages4(String text)
2731 {
2732 try
2733 {
2734 NavitGraphics.debug_line_4 = text;
2735 NavitGraphics.NavitMsgTv_.setMaxLines(4);
2736 NavitGraphics.NavitMsgTv_.setLines(4);
2737 NavitGraphics.NavitMsgTv_.setText(" " + NavitGraphics.debug_line_1 + "\n " + NavitGraphics.debug_line_2 + "\n " + NavitGraphics.debug_line_3 + "\n " + NavitGraphics.debug_line_4);
2738 //System.out.println("invalidate 026");
2739 NavitGraphics.NavitMsgTv_.postInvalidate();
2740 }
2741 catch (Exception e)
2742 {
2743 e.printStackTrace();
2744 }
2745 }
2746
2747 public static void set_debug_messages3_wrapper(String text)
2748 {
2749 try
2750 {
2751 Message msg = Navit_progress_h.obtainMessage();
2752 Bundle b = new Bundle();
2753 msg.what = 15;
2754 b.putString("text", text);
2755 msg.setData(b);
2756 Navit_progress_h.sendMessage(msg);
2757 }
2758 catch (Exception e)
2759 {
2760 e.printStackTrace();
2761 }
2762 }
2763
2764 public static void set_debug_messages_say_wrapper(String text)
2765 {
2766 try
2767 {
2768 Message msg = Navit_progress_h.obtainMessage();
2769 Bundle b = new Bundle();
2770 msg.what = 30;
2771 b.putString("text", text);
2772 msg.setData(b);
2773 Navit_progress_h.sendMessage(msg);
2774 }
2775 catch (Exception e)
2776 {
2777 e.printStackTrace();
2778 }
2779 }
2780
2781 protected void onNewIntent(Intent intent)
2782 {
2783 super.onNewIntent(intent);
2784
2785 try
2786 {
2787 System.out.println("XXIIXX(2):111");
2788 String mid_str = intent.getExtras().getString("com.zoffcc.applications.zanavi.mid");
2789
2790 System.out.println("XXIIXX(2):111a:mid_str=" + mid_str);
2791
2792 if (mid_str != null)
2793 {
2794 if (mid_str.equals("201:UPDATE-APP"))
2795 {
2796 // a new ZANavi version is available, show something to the user here -------------------
2797 // a new ZANavi version is available, show something to the user here -------------------
2798 // a new ZANavi version is available, show something to the user here -------------------
2799 // a new ZANavi version is available, show something to the user here -------------------
2800 // a new ZANavi version is available, show something to the user here -------------------
2801 // a new ZANavi version is available, show something to the user here -------------------
2802 }
2803 else if (mid_str.startsWith("202:UPDATE-MAP:"))
2804 {
2805 // System.out.println("need to update1:" + mid_str);
2806 // System.out.println("need to update2:" + mid_str.substring(15));
2807
2808 auto_start_update_map(mid_str.substring(15));
2809 }
2810 }
2811
2812 System.out.println("XXIIXX(2):111b:mid_str=" + mid_str);
2813 }
2814 catch (Exception e)
2815 {
2816 e.printStackTrace();
2817 System.out.println("XXIIXX(2):111:EEEE");
2818 }
2819
2820 // ---- Intent dump ----
2821 // ---- Intent dump ----
2822 // ---- Intent dump ----
2823 // ---- Intent dump ----
2824 try
2825 {
2826 System.out.println("XXIIXX(2):" + intent);
2827 Bundle bundle77 = intent.getExtras();
2828 System.out.println("XXIIXX(2):" + intent_flags_to_string(intent.getFlags()));
2829 if (bundle77 == null)
2830 {
2831 System.out.println("XXIIXX(2):" + "null");
2832 }
2833 else
2834 {
2835 for (String key : bundle77.keySet())
2836 {
2837 Object value = bundle77.get(key);
2838 System.out.println("XXIIXX(2):" + String.format("%s %s (%s)", key, value.toString(), value.getClass().getName()));
2839 }
2840 }
2841 }
2842 catch (Exception ee22)
2843 {
2844 String exst = Log.getStackTraceString(ee22);
2845 System.out.println("XXIIXX(2):ERR:" + exst);
2846 }
2847 // ---- Intent dump ----
2848 // ---- Intent dump ----
2849 // ---- Intent dump ----
2850 // ---- Intent dump ----
2851
2852 Log.e("Navit", "3:**1**A " + intent.getAction());
2853 Log.e("Navit", "3:**1**D " + intent.getDataString());
2854 Log.e("Navit", "3:**1**S " + intent.toString());
2855 try
2856 {
2857 Log.e("Navit", "3:**1**S " + intent.getExtras().describeContents());
2858 }
2859 catch (Exception ee3)
2860 {
2861 }
2862
2863 // if (Navit.startup_intent == null)
2864 {
2865 try
2866 {
2867 // make a copy of the given intent object
2868 // Navit.startup_intent = intent.cloneFilter();
2869 Navit.startup_intent = intent;
2870
2871 Log.e("Navit", "3a:**1**001");
2872 Bundle extras2 = intent.getExtras();
2873 Log.e("Navit", "3a:**1**002");
2874 try
2875 {
2876 Navit.startup_intent.putExtras(extras2);
2877 Log.e("Navit", "3a:**1**003");
2878 }
2879 catch (Exception e4)
2880 {
2881 if (startup_intent.getDataString() != null)
2882 {
2883 // we have a "geo:" thingy intent, use it
2884 // or "gpx file"
2885 Log.e("Navit", "3c:**1**A " + startup_intent.getAction());
2886 Log.e("Navit", "3c:**1**D " + startup_intent.getDataString());
2887 Log.e("Navit", "3c:**1**S " + startup_intent.toString());
2888 }
2889 else
2890 {
2891 Log.e("Navit", "3X:**1**X ");
2892 Navit.startup_intent = null;
2893 }
2894
2895 // hack! remeber timstamp, and only allow 4 secs. later in onResume to set target!
2896 Navit.startup_intent_timestamp = System.currentTimeMillis();
2897
2898 return;
2899 }
2900
2901 // Intent { act=android.intent.action.VIEW
2902 // cat=[android.intent.category.DEFAULT]
2903 // dat=file:///mnt/sdcard/zanavi_pos_recording_347834278.gpx
2904 // cmp=com.zoffcc.applications.zanavi/.Navit }
2905
2906 // hack! remeber timstamp, and only allow 4 secs. later in onResume to set target!
2907 Navit.startup_intent_timestamp = System.currentTimeMillis();
2908 Log.e("Navit", "3a:**1**A " + startup_intent.getAction());
2909 Log.e("Navit", "3a:**1**D " + startup_intent.getDataString());
2910 Log.e("Navit", "3a:**1**S " + startup_intent.toString());
2911 if (extras2 != null)
2912 {
2913 long l = extras2.getLong("com.zoffcc.applications.zanavi.ZANAVI_INTENT_type");
2914 // System.out.println("DH:a007 l=" + l);
2915 if (l != 0L)
2916 {
2917 if (l == Navit.NAVIT_START_INTENT_DRIVE_HOME)
2918 {
2919 // Log.e("Navit", "2:**1** started via drive home");
2920 // we have been called from "drive home" widget
2921
2922 // drive home
2923
2924 // check if we have a home location
2925 int home_id = find_home_point();
2926
2927 if (home_id != -1)
2928 {
2929 Message msg7 = progress_handler.obtainMessage();
2930 Bundle b7 = new Bundle();
2931 msg7.what = 2; // long Toast message
2932 b7.putString("text", Navit.get_text("driving to Home Location")); //TRANS
2933 msg7.setData(b7);
2934 progress_handler.sendMessage(msg7);
2935
2936 // clear any previous destinations
2937 Message msg2 = new Message();
2938 Bundle b2 = new Bundle();
2939 b2.putInt("Callback", 7);
2940 msg2.setData(b2);
2941 NavitGraphics.callback_handler.sendMessage(msg2);
2942
2943 // set position to middle of screen -----------------------
2944 // set position to middle of screen -----------------------
2945 // set position to middle of screen -----------------------
2946 // Message msg67 = new Message();
2947 // Bundle b67 = new Bundle();
2948 // b67.putInt("Callback", 51);
2949 // b67.putInt("x", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getWidth() / 2));
2950 // b67.putInt("y", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getHeight() / 2));
2951 // msg67.setData(b67);
2952 // N_NavitGraphics.callback_handler.sendMessage(msg67);
2953 // set position to middle of screen -----------------------
2954 // set position to middle of screen -----------------------
2955 // set position to middle of screen -----------------------
2956
2957 try
2958 {
2959 Thread.sleep(60);
2960 }
2961 catch (Exception e)
2962 {
2963 }
2964
2965 route_wrapper(map_points.get(home_id).point_name, 0, 0, false, map_points.get(home_id).lat, map_points.get(home_id).lon, true);
2966
2967 // Navit.destination_set();
2968 //
2969 // // set destination to home location
2970 // String lat = String.valueOf(map_points.get(home_id).lat);
2971 // String lon = String.valueOf(map_points.get(home_id).lon);
2972 // String q = map_points.get(home_id).point_name;
2973 //
2974 // // System.out.println("lat=" + lat + " lon=" + lon + " name=" + q);
2975 //
2976 // Message msg55 = new Message();
2977 // Bundle b55 = new Bundle();
2978 // b55.putInt("Callback", 3);
2979 // b55.putString("lat", lat);
2980 // b55.putString("lon", lon);
2981 // b55.putString("q", q);
2982 // msg55.setData(b55);
2983 // NavitGraphics.callback_handler.sendMessage(msg55);
2984
2985 final Thread zoom_to_route_001 = new Thread()
2986 {
2987 int wait = 1;
2988 int count = 0;
2989 int max_count = 60;
2990
2991 @Override
2992 public void run()
2993 {
2994 while (wait == 1)
2995 {
2996 try
2997 {
2998 if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33))
2999 {
3000 zoom_to_route();
3001 wait = 0;
3002 }
3003 else
3004 {
3005 wait = 1;
3006 }
3007
3008 count++;
3009 if (count > max_count)
3010 {
3011 wait = 0;
3012 }
3013 else
3014 {
3015 Thread.sleep(400);
3016 }
3017 }
3018 catch (Exception e)
3019 {
3020 }
3021 }
3022 }
3023 };
3024 zoom_to_route_001.start();
3025
3026 // try
3027 // {
3028 // show_geo_on_screen(Float.parseFloat(lat), Float.parseFloat(lon));
3029 // }
3030 // catch (Exception e2)
3031 // {
3032 // e2.printStackTrace();
3033 // }
3034
3035 try
3036 {
3037 Navit.follow_button_on();
3038 }
3039 catch (Exception e2)
3040 {
3041 e2.printStackTrace();
3042 }
3043 }
3044 else
3045 {
3046 // no home location set
3047 Message msg = progress_handler.obtainMessage();
3048 Bundle b = new Bundle();
3049 msg.what = 2; // long Toast message
3050 b.putString("text", Navit.get_text("No Home Location set")); //TRANS
3051 msg.setData(b);
3052 progress_handler.sendMessage(msg);
3053 }
3054
3055 }
3056 }
3057 else
3058 {
3059 if (startup_intent.getDataString() != null)
3060 {
3061 // we have a "geo:" thingy intent, use it
3062 // or "gpx file"
3063 }
3064 else
3065 {
3066 Navit.startup_intent = null;
3067 }
3068 }
3069 }
3070 else
3071 {
3072 if (startup_intent.getDataString() != null)
3073 {
3074 // we have a "geo:" thingy intent, use it
3075 }
3076 else
3077 {
3078 Navit.startup_intent = null;
3079 }
3080 }
3081 }
3082 catch (Exception e99)
3083 {
3084 Navit.startup_intent = null;
3085 }
3086
3087 }
3088
3089 }
3090
3091 @Override
3092 public void onStart()
3093 {
3094 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
3095
3096 Navit.show_mem_used();
3097
3098 super.onStart();
3099
3100 Log.e("Navit", "OnStart");
3101
3102 while (Global_Init_Finished == 0)
3103 {
3104 Log.e("Navit", "OnStart:Global_Init_Finished==0 !!!!!");
3105 try
3106 {
3107 Thread.sleep(60, 0); // sleep
3108 }
3109 catch (InterruptedException e)
3110 {
3111 }
3112 }
3113
3114 cwthr.NavitActivity2(2);
3115
3116 getPrefs();
3117 activatePrefs();
3118 sun_moon__mLastCalcSunMillis = -1L;
3119
3120 // paint for bitmapdrawing on map
3121 if (p.PREF_use_anti_aliasing)
3122 {
3123 NavitGraphics.paint_for_map_display.setAntiAlias(true);
3124 }
3125 else
3126 {
3127 NavitGraphics.paint_for_map_display.setAntiAlias(false);
3128 }
3129 if (p.PREF_use_map_filtering)
3130 {
3131 NavitGraphics.paint_for_map_display.setFilterBitmap(true);
3132 }
3133 else
3134 {
3135 NavitGraphics.paint_for_map_display.setFilterBitmap(false);
3136 }
3137
3138 // activate gps AFTER 3g-location
3139 NavitVehicle.turn_on_precise_provider();
3140
3141 Navit.show_mem_used();
3142
3143 // restore points
3144 read_map_points();
3145
3146 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
3147 }
3148
3149 @Override
3150 public void onRestart()
3151 {
3152 super.onRestart();
3153 Log.e("Navit", "OnRestart");
3154
3155 while (Global_Init_Finished == 0)
3156 {
3157 Log.e("Navit", "onRestart:Global_Init_Finished==0 !!!!!");
3158 try
3159 {
3160 Thread.sleep(60, 0); // sleep
3161 }
3162 catch (InterruptedException e)
3163 {
3164 }
3165 }
3166
3167 cwthr.NavitActivity2(0);
3168 NavitVehicle.turn_on_sat_status();
3169 }
3170
3171 @SuppressLint("NewApi")
3172 @Override
3173 public void onResume()
3174 {
3175 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
3176
3177 // System.gc();
3178 super.onResume();
3179
3180 // get the intent fresh !! ----------
3181 startup_intent = this.getIntent();
3182 // get the intent fresh !! ----------
3183
3184 PackageInfo pkgInfo;
3185 Navit_Plugin_001_Installed = false;
3186 try
3187 {
3188 // is the donate version installed?
3189 pkgInfo = getPackageManager().getPackageInfo("com.zoffcc.applications.zanavi_msg", 0);
3190 String sharedUserId = pkgInfo.sharedUserId;
3191 System.out.println("str nd=" + sharedUserId);
3192 if (sharedUserId.equals("com.zoffcc.applications.zanavi"))
3193 {
3194 System.out.println("##plugin 001##");
3195 Navit_Plugin_001_Installed = true;
3196 }
3197 }
3198 catch (Exception e)
3199 {
3200 e.printStackTrace();
3201 }
3202
3203 // ---- Intent dump ----
3204 // ---- Intent dump ----
3205 // ---- Intent dump ----
3206 // ---- Intent dump ----
3207
3208 try
3209 {
3210 System.out.println("XXIIXX:111");
3211 String mid_str = this.getIntent().getExtras().getString("com.zoffcc.applications.zanavi.mid");
3212 System.out.println("XXIIXX:111a:mid_str=" + mid_str);
3213
3214 if (mid_str != null)
3215 {
3216 if (mid_str.equals("201:UPDATE-APP"))
3217 {
3218 // a new ZANavi version is available, show something to the user here -------------------
3219 // a new ZANavi version is available, show something to the user here -------------------
3220 // a new ZANavi version is available, show something to the user here -------------------
3221 // a new ZANavi version is available, show something to the user here -------------------
3222 // a new ZANavi version is available, show something to the user here -------------------
3223 // a new ZANavi version is available, show something to the user here -------------------
3224 }
3225 else if (mid_str.startsWith("202:UPDATE-MAP:"))
3226 {
3227 System.out.println("need to update1:" + mid_str);
3228 System.out.println("need to update2:" + mid_str.substring(15));
3229
3230 auto_start_update_map(mid_str.substring(15));
3231 }
3232 }
3233
3234 System.out.println("XXIIXX:111b:mid_str=" + mid_str);
3235 }
3236 catch (Exception e)
3237 {
3238 e.printStackTrace();
3239 System.out.println("XXIIXX:111:EEEE");
3240 }
3241
3242 try
3243 {
3244 System.out.println("XXIIXX:" + this.getIntent());
3245 Bundle bundle77 = this.getIntent().getExtras();
3246 System.out.println("XXIIXX:" + intent_flags_to_string(this.getIntent().getFlags()));
3247 if (bundle77 == null)
3248 {
3249 System.out.println("XXIIXX:" + "null");
3250 }
3251 else
3252 {
3253 for (String key : bundle77.keySet())
3254 {
3255 Object value = bundle77.get(key);
3256 System.out.println("XXIIXX:" + String.format("%s %s (%s)", key, value.toString(), value.getClass().getName()));
3257 }
3258 }
3259 }
3260 catch (Exception ee22)
3261 {
3262 String exst = Log.getStackTraceString(ee22);
3263 System.out.println("XXIIXX:ERR:" + exst);
3264 }
3265 // ---- Intent dump ----
3266 // ---- Intent dump ----
3267 // ---- Intent dump ----
3268 // ---- Intent dump ----
3269
3270 is_paused = false;
3271
3272 Navit_doubleBackToExitPressedOnce = false;
3273
3274 app_window = getWindow();
3275
3276 Log.e("Navit", "OnResume");
3277
3278 while (Global_Init_Finished == 0)
3279 {
3280 Log.e("Navit", "OnResume:Global_Init_Finished==0 !!!!!");
3281 try
3282 {
3283 Thread.sleep(30, 0); // sleep
3284 }
3285 catch (InterruptedException e)
3286 {
3287 }
3288 }
3289
3290 //InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
3291 cwthr.NavitActivity2(1);
3292
3293 try
3294 {
3295 NSp.resume_me();
3296 }
3297 catch (Exception e)
3298 {
3299 e.printStackTrace();
3300 }
3301
3302 NavitVehicle.turn_on_sat_status();
3303
3304 try
3305 {
3306 if (wl != null)
3307 {
3308 // try
3309 // {
3310 // wl.release();
3311 // }
3312 // catch (Exception e2)
3313 // {
3314 // }
3315 wl.acquire();
3316 Log.e("Navit", "WakeLock: acquire 2");
3317 }
3318 }
3319 catch (Exception e)
3320 {
3321 e.printStackTrace();
3322 }
3323
3324 //Intent caller = this.getIntent();
3325 //System.out.println("A=" + caller.getAction() + " D=" + caller.getDataString());
3326 //System.out.println("C=" + caller.getComponent().flattenToString());
3327
3328 if (unsupported)
3329 {
3330 class CustomListener implements View.OnClickListener
3331 {
3332 private final Dialog dialog;
3333
3334 public CustomListener(Dialog dialog)
3335 {
3336 this.dialog = dialog;
3337 }
3338
3339 @Override
3340 public void onClick(View v)
3341 {
3342
3343 // Do whatever you want here
3344
3345 // If you want to close the dialog, uncomment the line below
3346 //dialog.dismiss();
3347 }
3348 }
3349
3350 AlertDialog.Builder dialog = new AlertDialog.Builder(this);
3351 dialog.setTitle("WeltBild Tablet");
3352 dialog.setCancelable(false);
3353 dialog.setMessage("Your device is not supported!");
3354 dialog.show();
3355 //Button theButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
3356 //theButton.setOnClickListener(new CustomListener(dialog));
3357 }
3358
3359 // reset "maps too old" flag
3360 Navit_maps_too_old = false;
3361
3362 if (Navit_maps_loaded == false)
3363 {
3364 Navit_maps_loaded = true;
3365 // activate all maps
3366 Log.e("Navit", "**** LOAD ALL MAPS **** start");
3367 Message msg3 = new Message();
3368 Bundle b3 = new Bundle();
3369 b3.putInt("Callback", 20);
3370 msg3.setData(b3);
3371 NavitGraphics.callback_handler.sendMessage(msg3);
3372 Log.e("Navit", "**** LOAD ALL MAPS **** end");
3373 }
3374
3375 try
3376 {
3377 if (!have_maps_installed())
3378 {
3379 // System.out.println("MMMM=no maps installed");
3380 // show semi transparent box "no maps installed" ------------------
3381 // show semi transparent box "no maps installed" ------------------
3382 NavitGraphics.no_maps_container.setVisibility(View.VISIBLE);
3383 try
3384 {
3385 NavitGraphics.no_maps_container.setActivated(true);
3386 }
3387 catch (NoSuchMethodError e)
3388 {
3389 }
3390
3391 show_case_001();
3392
3393 // show semi transparent box "no maps installed" ------------------
3394 // show semi transparent box "no maps installed" ------------------
3395 }
3396 else
3397 {
3398 NavitGraphics.no_maps_container.setVisibility(View.INVISIBLE);
3399 try
3400 {
3401 NavitGraphics.no_maps_container.setActivated(false);
3402 }
3403 catch (NoSuchMethodError e)
3404 {
3405 }
3406 }
3407 }
3408 catch (Exception e)
3409 {
3410 e.printStackTrace();
3411 }
3412
3413 try
3414 {
3415 // draw map no-async
3416 Message msg = new Message();
3417 Bundle b = new Bundle();
3418 b.putInt("Callback", 64);
3419 msg.setData(b);
3420 NavitGraphics.callback_handler.sendMessage(msg);
3421 }
3422 catch (Exception e)
3423 {
3424 e.printStackTrace();
3425 }
3426
3427 String intent_data = null;
3428 try
3429 {
3430 //Log.e("Navit", "**9**A " + startup_intent.getAction());
3431 //Log.e("Navit", "**9**D " + startup_intent.getDataString());
3432
3433 int type = 1; // default = assume it's a map coords intent
3434
3435 try
3436 {
3437 String si = startup_intent.getDataString();
3438 String tmp2 = si.split(":", 2)[0];
3439 Log.e("Navit", "**9a**A " + startup_intent.getAction());
3440 Log.e("Navit", "**9a**D " + startup_intent.getDataString() + " " + tmp2);
3441 if (tmp2.equals("file"))
3442 {
3443 Log.e("Navit", "**9b**D " + startup_intent.getDataString() + " " + tmp2);
3444 if (si.toLowerCase().endsWith(".gpx"))
3445 {
3446 Log.e("Navit", "**9c**D " + startup_intent.getDataString() + " " + tmp2);
3447 type = 4;
3448 }
3449 }
3450 }
3451 catch (Exception e2)
3452 {
3453 }
3454
3455 if (type != 4)
3456 {
3457 Bundle extras = startup_intent.getExtras();
3458 // System.out.println("DH:001");
3459 if (extras != null)
3460 {
3461 // System.out.println("DH:002");
3462 long l = extras.getLong("com.zoffcc.applications.zanavi.ZANAVI_INTENT_type");
3463 // System.out.println("DH:003 l=" + l);
3464 if (l != 0L)
3465 {
3466 // System.out.println("DH:004");
3467 if (l == Navit.NAVIT_START_INTENT_DRIVE_HOME)
3468 {
3469 // System.out.println("DH:005");
3470 type = 2; // call from drive-home-widget
3471 }
3472 // ok, now remove that key
3473 extras.remove("com.zoffcc.applications.zanavi");
3474 startup_intent.replaceExtras((Bundle) null);
3475 // System.out.println("DH:006");
3476 }
3477 }
3478 }
3479
3480 // ------------------------ BIG LOOP ------------------------
3481 // ------------------------ BIG LOOP ------------------------
3482 if (type == 2)
3483 {
3484 // drive home
3485
3486 // check if we have a home location
3487 int home_id = find_home_point();
3488
3489 if (home_id != -1)
3490 {
3491 Message msg7 = progress_handler.obtainMessage();
3492 Bundle b7 = new Bundle();
3493 msg7.what = 2; // long Toast message
3494 b7.putString("text", Navit.get_text("driving to Home Location")); //TRANS
3495 msg7.setData(b7);
3496 progress_handler.sendMessage(msg7);
3497
3498 // clear any previous destinations
3499 Message msg2 = new Message();
3500 Bundle b2 = new Bundle();
3501 b2.putInt("Callback", 7);
3502 msg2.setData(b2);
3503 NavitGraphics.callback_handler.sendMessage(msg2);
3504
3505 // set position to middle of screen -----------------------
3506 // set position to middle of screen -----------------------
3507 // set position to middle of screen -----------------------
3508 // Message msg67 = new Message();
3509 // Bundle b67 = new Bundle();
3510 // b67.putInt("Callback", 51);
3511 // b67.putInt("x", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getWidth() / 2));
3512 // b67.putInt("y", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getHeight() / 2));
3513 // msg67.setData(b67);
3514 // N_NavitGraphics.callback_handler.sendMessage(msg67);
3515 // set position to middle of screen -----------------------
3516 // set position to middle of screen -----------------------
3517 // set position to middle of screen -----------------------
3518
3519 try
3520 {
3521 Thread.sleep(60);
3522 }
3523 catch (Exception e)
3524 {
3525 }
3526
3527 Navit.destination_set();
3528
3529 // set destination to home location
3530 String lat = String.valueOf(map_points.get(home_id).lat);
3531 String lon = String.valueOf(map_points.get(home_id).lon);
3532 String q = map_points.get(home_id).point_name;
3533
3534 // System.out.println("lat=" + lat + " lon=" + lon + " name=" + q);
3535
3536 Message msg55 = new Message();
3537 Bundle b55 = new Bundle();
3538 b55.putInt("Callback", 3);
3539 b55.putString("lat", lat);
3540 b55.putString("lon", lon);
3541 b55.putString("q", q);
3542 msg55.setData(b55);
3543 NavitGraphics.callback_handler.sendMessage(msg55);
3544
3545 final Thread zoom_to_route_001 = new Thread()
3546 {
3547 int wait = 1;
3548 int count = 0;
3549 int max_count = 60;
3550
3551 @Override
3552 public void run()
3553 {
3554 while (wait == 1)
3555 {
3556 try
3557 {
3558 if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33))
3559 {
3560 zoom_to_route();
3561 wait = 0;
3562 }
3563 else
3564 {
3565 wait = 1;
3566 }
3567
3568 count++;
3569 if (count > max_count)
3570 {
3571 wait = 0;
3572 }
3573 else
3574 {
3575 Thread.sleep(400);
3576 }
3577 }
3578 catch (Exception e)
3579 {
3580 }
3581 }
3582 }
3583 };
3584 zoom_to_route_001.start();
3585
3586 // try
3587 // {
3588 // show_geo_on_screen(Float.parseFloat(lat), Float.parseFloat(lon));
3589 // }
3590 // catch (Exception e2)
3591 // {
3592 // e2.printStackTrace();
3593 // }
3594
3595 try
3596 {
3597 Navit.follow_button_on();
3598 }
3599 catch (Exception e2)
3600 {
3601 e2.printStackTrace();
3602 }
3603 }
3604 else
3605 {
3606 // no home location set
3607 Message msg = progress_handler.obtainMessage();
3608 Bundle b = new Bundle();
3609 msg.what = 2; // long Toast message
3610 b.putString("text", Navit.get_text("No Home Location set")); //TRANS
3611 msg.setData(b);
3612 progress_handler.sendMessage(msg);
3613 }
3614 }
3615 else if (type == 4)
3616 {
3617
3618 if (startup_intent != null)
3619 {
3620 // Log.e("Navit", "**7**A " + startup_intent.getAction() + System.currentTimeMillis() + " " + Navit.startup_intent_timestamp);
3621 if (System.currentTimeMillis() <= Navit.startup_intent_timestamp + 4000L)
3622 {
3623 Log.e("Navit", "**7**A " + startup_intent.getAction());
3624 Log.e("Navit", "**7**D " + startup_intent.getDataString());
3625 intent_data = startup_intent.getDataString();
3626 try
3627 {
3628 intent_data = java.net.URLDecoder.decode(intent_data, "UTF-8");
3629 }
3630 catch (Exception e1)
3631 {
3632 e1.printStackTrace();
3633 }
3634
3635 // we consumed the intent, so reset timestamp value to avoid double consuming of event
3636 Navit.startup_intent_timestamp = 0L;
3637
3638 if (intent_data != null)
3639 {
3640 // file:///mnt/sdcard/zanavi_pos_recording_347834278.gpx
3641 String tmp1;
3642 tmp1 = intent_data.split(":", 2)[1].substring(2);
3643
3644 Log.e("Navit", "**7**f=" + tmp1);
3645
3646 // convert gpx file ---------------------
3647 convert_gpx_file_real(tmp1);
3648 }
3649 }
3650 }
3651 }
3652 else if (type == 1)
3653 {
3654 if (startup_intent != null)
3655 {
3656 if (System.currentTimeMillis() <= Navit.startup_intent_timestamp + 4000L)
3657 {
3658 Log.e("Navit", "**2**A " + startup_intent.getAction());
3659 Log.e("Navit", "**2**D " + startup_intent.getDataString());
3660 intent_data = startup_intent.getDataString();
3661 // we consumed the intent, so reset timestamp value to avoid double consuming of event
3662 Navit.startup_intent_timestamp = 0L;
3663
3664 if (intent_data != null)
3665 {
3666 // set position to middle of screen -----------------------
3667 // set position to middle of screen -----------------------
3668 // set position to middle of screen -----------------------
3669 // Message msg67 = new Message();
3670 // Bundle b67 = new Bundle();
3671 // b67.putInt("Callback", 51);
3672 // b67.putInt("x", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getWidth() / 2));
3673 // b67.putInt("y", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getHeight() / 2));
3674 // msg67.setData(b67);
3675 // N_NavitGraphics.callback_handler.sendMessage(msg67);
3676 // set position to middle of screen -----------------------
3677 // set position to middle of screen -----------------------
3678 // set position to middle of screen -----------------------
3679 }
3680 }
3681 else
3682 {
3683 Log.e("Navit", "timestamp for navigate_to expired! not using data");
3684 }
3685 }
3686
3687 System.out.println("SUI:000a " + intent_data);
3688
3689 if ((intent_data != null) && ((substring_without_ioobe(intent_data, 0, 18).equals("google.navigation:")) || (substring_without_ioobe(intent_data, 0, 23).equals("http://maps.google.com/")) || (substring_without_ioobe(intent_data, 0, 24).equals("https://maps.google.com/"))))
3690 {
3691
3692 System.out.println("SUI:000b");
3693
3694 // better use regex later, but for now to test this feature its ok :-)
3695 // better use regex later, but for now to test this feature its ok :-)
3696
3697 // g: google.navigation:///?ll=49.4086,17.4855&entry=w&opt=
3698 // d: google.navigation:q=blabla-strasse # (this happens when you are offline, or from contacts)
3699 // b: google.navigation:q=48.25676,16.643
3700 // a: google.navigation:ll=48.25676,16.643&q=blabla-strasse
3701 // e: google.navigation:ll=48.25676,16.643&title=blabla-strasse
3702 // sample: -> google.navigation:ll=48.026096,16.023993&title=N%C3%B6stach+43%2C+2571+N%C3%B6stach&entry=w
3703 // -> google.navigation:ll=48.014413,16.005579&title=Hainfelder+Stra%C3%9Fe+44%2C+2571%2C+Austria&entry=w
3704 // f: google.navigation:ll=48.25676,16.643&...
3705 // c: google.navigation:ll=48.25676,16.643
3706 // h: http://maps.google.com/?q=48.222210,16.387058&z=16
3707 // i: https://maps.google.com/?q=48.222210,16.387058&z=16
3708 // i:,h: https://maps.google.com/maps/place?ftid=0x476d07075e933fc5:0xccbeba7fe1e3dd36&q=48.222210,16.387058&ui=maps_mini
3709 //
3710 // ??!!new??!!: http://maps.google.com/?cid=10549738100504591748&hl=en&gl=gb
3711
3712 String lat;
3713 String lon;
3714 String q;
3715
3716 String temp1 = null;
3717 String temp2 = null;
3718 String temp3 = null;
3719 boolean parsable = false;
3720 boolean unparsable_info_box = true;
3721 try
3722 {
3723 intent_data = java.net.URLDecoder.decode(intent_data, "UTF-8");
3724 }
3725 catch (Exception e1)
3726 {
3727 e1.printStackTrace();
3728 }
3729
3730 // DEBUG
3731 // DEBUG
3732 // DEBUG
3733 // intent_data = "google.navigation:q=Wien Burggasse 27";
3734 // intent_data = "google.navigation:q=48.25676,16.643";
3735 // intent_data = "google.navigation:ll=48.25676,16.643&q=blabla-strasse";
3736 // intent_data = "google.navigation:ll=48.25676,16.643";
3737 // DEBUG
3738 // DEBUG
3739 // DEBUG
3740
3741 try
3742 {
3743 Log.e("Navit", "found DEBUG 1: " + intent_data.substring(0, 20));
3744 Log.e("Navit", "found DEBUG 2: " + intent_data.substring(20, 22));
3745 Log.e("Navit", "found DEBUG 3: " + intent_data.substring(20, 21));
3746 Log.e("Navit", "found DEBUG 4: " + intent_data.split("&").length);
3747 Log.e("Navit", "found DEBUG 4.1: yy" + intent_data.split("&")[1].substring(0, 1).toLowerCase() + "yy");
3748 Log.e("Navit", "found DEBUG 5: xx" + intent_data.split("&")[1] + "xx");
3749 }
3750 catch (Exception e)
3751 {
3752 e.printStackTrace();
3753 }
3754
3755 if (!Navit.NavitStartupAlreadySearching)
3756 {
3757 if (intent_data.length() > 19)
3758 {
3759 // if h: then show target
3760 if (substring_without_ioobe(intent_data, 0, 23).equals("http://maps.google.com/"))
3761 {
3762 Uri uri = Uri.parse(intent_data);
3763 Log.e("Navit", "target found (h): " + uri.getQueryParameter("q"));
3764 parsable = true;
3765 intent_data = "google.navigation:ll=" + uri.getQueryParameter("q") + "&q=Target";
3766 }
3767 // if i: then show target
3768 else if (substring_without_ioobe(intent_data, 0, 24).equals("https://maps.google.com/"))
3769 {
3770 Uri uri = Uri.parse(intent_data);
3771 Log.e("Navit", "target found (i): " + uri.getQueryParameter("q"));
3772 parsable = true;
3773 intent_data = "google.navigation:ll=" + uri.getQueryParameter("q") + "&q=Target";
3774 }
3775 // if d: then start target search
3776 else if ((substring_without_ioobe(intent_data, 0, 20).equals("google.navigation:q=")) && ((!substring_without_ioobe(intent_data, 20, 21).equals('+')) && (!substring_without_ioobe(intent_data, 20, 21).equals('-')) && (!substring_without_ioobe(intent_data, 20, 22).matches("[0-9][0-9]"))))
3777 {
3778 Log.e("Navit", "target found (d): " + intent_data.split("q=", -1)[1]);
3779 Navit.NavitStartupAlreadySearching = true;
3780 start_targetsearch_from_intent(intent_data.split("q=", -1)[1]);
3781 // dont use this here, already starting search, so set to "false"
3782 parsable = false;
3783 unparsable_info_box = false;
3784 }
3785 // if b: then remodel the input string to look like a:
3786 else if (substring_without_ioobe(intent_data, 0, 20).equals("google.navigation:q="))
3787 {
3788 intent_data = "ll=" + intent_data.split("q=", -1)[1] + "&q=Target";
3789 Log.e("Navit", "target found (b): " + intent_data);
3790 parsable = true;
3791 }
3792 // if g: [google.navigation:///?ll=49.4086,17.4855&...] then remodel the input string to look like a:
3793 else if (substring_without_ioobe(intent_data, 0, 25).equals("google.navigation:///?ll="))
3794 {
3795 intent_data = "google.navigation:ll=" + intent_data.split("ll=", -1)[1].split("&", -1)[0] + "&q=Target";
3796 Log.e("Navit", "target found (g): " + intent_data);
3797 parsable = true;
3798 }
3799 // if e: then remodel the input string to look like a:
3800 else if ((substring_without_ioobe(intent_data, 0, 21).equals("google.navigation:ll=")) && (intent_data.split("&").length > 1) && (substring_without_ioobe(intent_data.split("&")[1], 0, 1).toLowerCase().equals("f")))
3801 {
3802 int idx = intent_data.indexOf("&");
3803 intent_data = substring_without_ioobe(intent_data, 0, idx) + "&q=Target";
3804 Log.e("Navit", "target found (e): " + intent_data);
3805 parsable = true;
3806 }
3807 // if f: then remodel the input string to look like a:
3808 else if ((substring_without_ioobe(intent_data, 0, 21).equals("google.navigation:ll=")) && (intent_data.split("&").length > 1))
3809 {
3810 int idx = intent_data.indexOf("&");
3811 intent_data = intent_data.substring(0, idx) + "&q=Target";
3812 Log.e("Navit", "target found (f): " + intent_data);
3813 parsable = true;
3814 }
3815 // already looks like a: just set flag
3816 else if ((substring_without_ioobe(intent_data, 0, 21).equals("google.navigation:ll=")) && (intent_data.split("&q=").length > 1))
3817 {
3818 // dummy, just set the flag
3819 Log.e("Navit", "target found (a): " + intent_data);
3820 Log.e("Navit", "target found (a): " + intent_data.split("&q=").length);
3821 parsable = true;
3822 }
3823 // if c: then remodel the input string to look like a:
3824 else if ((substring_without_ioobe(intent_data, 0, 21).equals("google.navigation:ll=")) && (intent_data.split("&q=").length < 2))
3825 {
3826
3827 intent_data = intent_data + "&q=Target";
3828 Log.e("Navit", "target found (c): " + intent_data);
3829 parsable = true;
3830 }
3831 }
3832 }
3833 else
3834 {
3835 Log.e("Navit", "already started search from startup intent");
3836 parsable = false;
3837 unparsable_info_box = false;
3838 }
3839
3840 if (parsable)
3841 {
3842 // now string should be in form --> a:
3843 // now split the parts off
3844 temp1 = intent_data.split("&q=", -1)[0];
3845 try
3846 {
3847 temp3 = temp1.split("ll=", -1)[1];
3848 temp2 = intent_data.split("&q=", -1)[1];
3849 }
3850 catch (Exception e)
3851 {
3852 // java.lang.ArrayIndexOutOfBoundsException most likely
3853 // so let's assume we dont have '&q=xxxx'
3854 temp3 = temp1;
3855 }
3856
3857 if (temp2 == null)
3858 {
3859 // use some default name
3860 temp2 = "Target";
3861 }
3862
3863 lat = temp3.split(",", -1)[0];
3864 lon = temp3.split(",", -1)[1];
3865 q = temp2;
3866 // is the "search name" url-encoded? i think so, lets url-decode it here
3867 q = URLDecoder.decode(q);
3868 // System.out.println();
3869
3870 Navit.remember_destination(q, lat, lon);
3871 Navit.destination_set();
3872
3873 Message msg = new Message();
3874 Bundle b = new Bundle();
3875 b.putInt("Callback", 3);
3876 b.putString("lat", lat);
3877 b.putString("lon", lon);
3878 b.putString("q", q);
3879 msg.setData(b);
3880 NavitGraphics.callback_handler.sendMessage(msg);
3881
3882 final Thread zoom_to_route_002 = new Thread()
3883 {
3884 int wait = 1;
3885 int count = 0;
3886 int max_count = 60;
3887
3888 @Override
3889 public void run()
3890 {
3891 while (wait == 1)
3892 {
3893 try
3894 {
3895 if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33))
3896 {
3897 zoom_to_route();
3898 wait = 0;
3899 }
3900 else
3901 {
3902 wait = 1;
3903 }
3904
3905 count++;
3906 if (count > max_count)
3907 {
3908 wait = 0;
3909 }
3910 else
3911 {
3912 Thread.sleep(400);
3913 }
3914 }
3915 catch (Exception e)
3916 {
3917 }
3918 }
3919 }
3920 };
3921 zoom_to_route_002.start();
3922
3923 // try
3924 // {
3925 // Thread.sleep(400);
3926 // }
3927 // catch (InterruptedException e)
3928 // {
3929 // }
3930 //
3931 // // try
3932 // // {
3933 // // show_geo_on_screen(Float.parseFloat(lat), Float.parseFloat(lon));
3934 // // }
3935 // // catch (Exception e2)
3936 // // {
3937 // // e2.printStackTrace();
3938 // // }
3939
3940 try
3941 {
3942 Navit.follow_button_on();
3943 }
3944 catch (Exception e2)
3945
3946 {
3947 e2.printStackTrace();
3948 }
3949 }
3950 else
3951 {
3952 if (unparsable_info_box && !searchBoxShown)
3953 {
3954 try
3955 {
3956 searchBoxShown = true;
3957 String searchString = intent_data.split("q=")[1];
3958 searchString = searchString.split("&")[0];
3959 searchString = URLDecoder.decode(searchString); // decode the URL: e.g. %20 -> space
3960 Log.e("Navit", "Search String :" + searchString);
3961 executeSearch(searchString);
3962 }
3963 catch (Exception e)
3964 {
3965 // safety net
3966 try
3967 {
3968 Log.e("Navit", "problem with startup search 7 str=" + intent_data);
3969 }
3970 catch (Exception e2)
3971 {
3972 e2.printStackTrace();
3973 }
3974 }
3975 }
3976 }
3977 }
3978 else if ((intent_data != null) && (substring_without_ioobe(intent_data, 0, 10).equals("geo:0,0?q=")))
3979 {
3980 // g: geo:0,0?q=wien%20burggasse
3981
3982 System.out.println("SUI:001");
3983
3984 boolean parsable = false;
3985 boolean unparsable_info_box = true;
3986 try
3987 {
3988 intent_data = java.net.URLDecoder.decode(intent_data, "UTF-8");
3989 }
3990 catch (Exception e1)
3991 {
3992 e1.printStackTrace();
3993
3994 }
3995
3996 System.out.println("SUI:002");
3997
3998 if (!Navit.NavitStartupAlreadySearching)
3999 {
4000 if (intent_data.length() > 10)
4001 {
4002 // if g: then start target search
4003 Log.e("Navit", "target found (g): " + intent_data.split("q=", -1)[1]);
4004 Navit.NavitStartupAlreadySearching = true;
4005 start_targetsearch_from_intent(intent_data.split("q=", -1)[1]);
4006 // dont use this here, already starting search, so set to "false"
4007 parsable = false;
4008 unparsable_info_box = false;
4009 }
4010 }
4011 else
4012 {
4013 Log.e("Navit", "already started search from startup intent");
4014 parsable = false;
4015 unparsable_info_box = false;
4016 }
4017
4018 if (unparsable_info_box && !searchBoxShown)
4019 {
4020 try
4021 {
4022 searchBoxShown = true;
4023 String searchString = intent_data.split("q=")[1];
4024 searchString = searchString.split("&")[0];
4025 searchString = URLDecoder.decode(searchString); // decode the URL: e.g. %20 -> space
4026 Log.e("Navit", "Search String :" + searchString);
4027 executeSearch(searchString);
4028 }
4029 catch (Exception e)
4030 {
4031 // safety net
4032 try
4033 {
4034 Log.e("Navit", "problem with startup search 88 str=" + intent_data);
4035 }
4036 catch (Exception e2)
4037 {
4038 e2.printStackTrace();
4039 }
4040 }
4041 }
4042
4043 }
4044 else if ((intent_data != null) && (substring_without_ioobe(intent_data, 0, 4).equals("geo:")))
4045 {
4046 // g: geo:16.8,46.3?z=15
4047
4048 System.out.println("SUI:002a");
4049
4050 boolean parsable = false;
4051 boolean unparsable_info_box = true;
4052
4053 String tmp1;
4054 String tmp2;
4055 String tmp3;
4056 float lat1 = 0;
4057 float lon1 = 0;
4058 int zoom1 = 15;
4059
4060 try
4061 {
4062 intent_data = java.net.URLDecoder.decode(intent_data, "UTF-8");
4063 }
4064 catch (Exception e1)
4065 {
4066 e1.printStackTrace();
4067 }
4068
4069 if (!Navit.NavitStartupAlreadySearching)
4070 {
4071 try
4072 {
4073 tmp1 = intent_data.split(":", 2)[1];
4074 tmp2 = tmp1.split("\\?", 2)[0];
4075 tmp3 = tmp1.split("\\?", 2)[1];
4076 lat1 = Float.parseFloat(tmp2.split(",", 2)[0]);
4077 lon1 = Float.parseFloat(tmp2.split(",", 2)[1]);
4078 zoom1 = Integer.parseInt(tmp3.split("z=", 2)[1]);
4079 parsable = true;
4080 }
4081 catch (Exception e4)
4082 {
4083 e4.printStackTrace();
4084 }
4085 }
4086
4087 if (parsable)
4088 {
4089 // geo: intent -> only show destination on map!
4090
4091 // set nice zoomlevel before we show destination
4092 // int zoom_want = zoom1;
4093 // //
4094 // Message msg = new Message();
4095 // Bundle b = new Bundle();
4096 // b.putInt("Callback", 33);
4097 // b.putString("s", Integer.toString(zoom_want));
4098 // msg.setData(b);
4099 // try
4100 // {
4101 // N_NavitGraphics.callback_handler.sendMessage(msg);
4102 // Navit.GlobalScaleLevel = Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL;
4103 // if ((zoom_want > 8) && (zoom_want < 17))
4104 // {
4105 // Navit.GlobalScaleLevel = (int) (Math.pow(2, (18 - zoom_want)));
4106 // System.out.println("GlobalScaleLevel=" + Navit.GlobalScaleLevel);
4107 // }
4108 // }
4109 // catch (Exception e)
4110 // {
4111 // e.printStackTrace();
4112 // }
4113 // if (PREF_save_zoomlevel)
4114 // {
4115 // setPrefs_zoomlevel();
4116 // }
4117 // set nice zoomlevel before we show destination
4118
4119 try
4120 {
4121 Navit.follow_button_off();
4122 }
4123 catch (Exception e2)
4124 {
4125 e2.printStackTrace();
4126 }
4127
4128 show_geo_on_screen(lat1, lon1);
4129 // final Thread zoom_to_route_003 = new Thread()
4130 // {
4131 // @Override
4132 // public void run()
4133 // {
4134 // try
4135 // {
4136 // Thread.sleep(200);
4137 // show_geo_on_screen(lat1, lon1);
4138 // }
4139 // catch (Exception e)
4140 // {
4141 // }
4142 // }
4143 // };
4144 // zoom_to_route_003.start();
4145
4146 }
4147 }
4148 }
4149
4150 System.out.println("SUI:099 XX" + substring_without_ioobe(intent_data, 0, 10) + "XX");
4151
4152 // clear intent
4153 startup_intent = null;
4154 // ------------------------ BIG LOOP ------------------------
4155 // ------------------------ BIG LOOP ------------------------
4156 }
4157 catch (Exception e)
4158 {
4159 e.printStackTrace();
4160 System.out.println("SUI:199");
4161 }
4162
4163 // clear intent
4164 startup_intent = null;
4165
4166 // hold all map drawing -----------
4167 Message msg = new Message();
4168 Bundle b = new Bundle();
4169 b.putInt("Callback", 69);
4170 msg.setData(b);
4171 try
4172 {
4173 NavitGraphics.callback_handler.sendMessage(msg);
4174 }
4175 catch (Exception e)
4176 {
4177 }
4178 // hold all map drawing -----------
4179
4180 getPrefs();
4181 activatePrefs();
4182 sun_moon__mLastCalcSunMillis = -1L;
4183
4184 push_pin_view = (ImageView) findViewById(R.id.bottom_slide_left_side);
4185 if (p.PREF_follow_gps)
4186 {
4187 push_pin_view.setImageResource(R.drawable.pin1_down);
4188 }
4189 else
4190 {
4191 push_pin_view.setImageResource(R.drawable.pin1_up);
4192 }
4193
4194 // paint for bitmapdrawing on map
4195 if (p.PREF_use_anti_aliasing)
4196 {
4197 NavitGraphics.paint_for_map_display.setAntiAlias(true);
4198 }
4199 else
4200 {
4201 NavitGraphics.paint_for_map_display.setAntiAlias(false);
4202 }
4203 if (p.PREF_use_map_filtering)
4204 {
4205 NavitGraphics.paint_for_map_display.setFilterBitmap(true);
4206 }
4207 else
4208 {
4209 NavitGraphics.paint_for_map_display.setFilterBitmap(false);
4210 }
4211
4212 // activate gps AFTER 3g-location
4213 NavitVehicle.turn_on_precise_provider();
4214
4215 // allow all map drawing -----------
4216 msg = new Message();
4217 b = new Bundle();
4218 b.putInt("Callback", 70);
4219 msg.setData(b);
4220 try
4221 {
4222 NavitGraphics.callback_handler.sendMessage(msg);
4223 }
4224 catch (Exception e)
4225 {
4226 }
4227 // allow all map drawing -----------
4228
4229 // --- disabled --- NavitVehicle.set_last_known_pos_fast_provider();
4230
4231 try
4232 {
4233 //Simulate = new SimGPS(NavitVehicle.vehicle_handler_);
4234 //Simulate.start();
4235 }
4236 catch (Exception e)
4237 {
4238 e.printStackTrace();
4239 }
4240
4241 try
4242 {
4243 watchmem = new WatchMem();
4244 watchmem.start();
4245 }
4246 catch (Exception e)
4247 {
4248 e.printStackTrace();
4249 }
4250
4251 // ----- check if we have some index files downloaded -----
4252 if (Navit.have_maps_installed())
4253 {
4254 if (Navit_maps_too_old)
4255 {
4256 TextView no_maps_text = (TextView) this.findViewById(R.id.no_maps_text);
4257 no_maps_text.setText("\n\n\n" + Navit.get_text("Some Maps are too old!") + "\n" + Navit.get_text("Please update your maps") + "\n\n");
4258
4259 try
4260 {
4261 NavitGraphics.no_maps_container.setVisibility(View.VISIBLE);
4262 try
4263 {
4264 NavitGraphics.no_maps_container.setActivated(true);
4265 }
4266 catch (NoSuchMethodError e)
4267 {
4268 }
4269 NavitGraphics.no_maps_container.bringToFront();
4270 }
4271 catch (Exception e)
4272 {
4273 e.printStackTrace();
4274 }
4275 }
4276 else
4277 {
4278 allow_use_index_search();
4279 if (Navit_index_on_but_no_idx_files)
4280 {
4281 TextView no_maps_text = (TextView) this.findViewById(R.id.no_maps_text);
4282 no_maps_text.setText("\n\n\n" + Navit.get_text("No Index for some Maps") + "\n" + Navit.get_text("Please update your maps") + "\n\n");
4283
4284 try
4285 {
4286 NavitGraphics.no_maps_container.setVisibility(View.VISIBLE);
4287 try
4288 {
4289 NavitGraphics.no_maps_container.setActivated(true);
4290 }
4291 catch (NoSuchMethodError e)
4292 {
4293 }
4294 NavitGraphics.no_maps_container.bringToFront();
4295 }
4296 catch (Exception e)
4297 {
4298 e.printStackTrace();
4299 }
4300 }
4301 else
4302 {
4303 try
4304 {
4305 NavitGraphics.no_maps_container.setVisibility(View.INVISIBLE);
4306 try
4307 {
4308 NavitGraphics.no_maps_container.setActivated(false);
4309 }
4310 catch (NoSuchMethodError e)
4311 {
4312 }
4313 }
4314 catch (Exception e)
4315 {
4316 e.printStackTrace();
4317 }
4318 }
4319 }
4320 }
4321 // ----- check if we have some index files downloaded -----
4322
4323 // ---- DEBUG ----
4324 // ---- DEBUG ----
4325 // ---- DEBUG ----
4326 try
4327 {
4328 if (!NavitVehicle.is_pos_recording)
4329 {
4330 if (p.PREF_enable_debug_write_gpx)
4331 {
4332 NavitVehicle.pos_recording_start();
4333 NavitVehicle.pos_recording_add(0, 0, 0, 0, 0, 0);
4334 }
4335 }
4336 }
4337 catch (Exception e)
4338 {
4339 }
4340 // ---- DEBUG ----
4341 // ---- DEBUG ----
4342 // ---- DEBUG ----
4343
4344 // glSurfaceView.onResume();
4345
4346 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
4347 }
4348
4349 @TargetApi(Build.VERSION_CODES.FROYO)
4350 @Override
4351 public void onPause()
4352 {
4353
4354 // if COMM stuff is running, stop it!
4355 ZANaviDebugReceiver.stop_me = true;
4356
4357 // ---- DEBUG ----
4358 // ---- DEBUG ----
4359 // ---- DEBUG ----
4360 // -- dump all callbacks --
4361 try
4362 {
4363 if (p.PREF_enable_debug_functions)
4364 {
4365 Message msg99a = new Message();
4366 Bundle b99a = new Bundle();
4367 b99a.putInt("Callback", 100);
4368 msg99a.setData(b99a);
4369 N_NavitGraphics.callback_handler.sendMessage(msg99a);
4370 }
4371 }
4372 catch (Exception e)
4373 {
4374 }
4375 // -- dump all callbacks --
4376 // ---- DEBUG ----
4377 // ---- DEBUG ----
4378 // ---- DEBUG ----
4379
4380 // ---- DEBUG ----
4381 // ---- DEBUG ----
4382 // ---- DEBUG ----
4383 try
4384 {
4385 if (!Navit.is_navigating)
4386 {
4387 if (p.PREF_enable_debug_write_gpx)
4388 {
4389 NavitVehicle.pos_recording_end();
4390 }
4391 }
4392 }
4393 catch (Exception e)
4394 {
4395 }
4396 // ---- DEBUG ----
4397 // ---- DEBUG ----
4398 // ---- DEBUG ----
4399
4400 // System.out.println("@@ onPause @@");
4401 Log.e("Navit", "OnPause");
4402 try
4403 {
4404 setPrefs_zoomlevel();
4405 }
4406 catch (Exception e)
4407 {
4408 e.printStackTrace();
4409 }
4410
4411 try
4412 {
4413 watchmem.stop_me();
4414 }
4415 catch (Exception e)
4416 {
4417 e.printStackTrace();
4418 }
4419
4420 try
4421 {
4422 //watchmem.join();
4423 }
4424 catch (Exception e)
4425 {
4426 e.printStackTrace();
4427 }
4428
4429 try
4430 {
4431 //Simulate.stop_me();
4432 }
4433 catch (Exception e)
4434 {
4435 e.printStackTrace();
4436 }
4437
4438 try
4439 {
4440 //Simulate.join();
4441 }
4442 catch (Exception e)
4443 {
4444 e.printStackTrace();
4445 }
4446
4447 Navit.show_mem_used();
4448
4449 // if (!Navit.is_navigating)
4450 // {
4451 // try
4452 // {
4453 // mTts.stop();
4454 // }
4455 // catch (Exception e)
4456 // {
4457 //
4458 // }
4459 //
4460 // try
4461 // {
4462 // mTts.shutdown();
4463 // }
4464 // catch (Exception e)
4465 // {
4466 //
4467 // }
4468 //
4469 // mTts = null;
4470 // }
4471
4472 super.onPause();
4473
4474 // signal to backupmanager that data "is / could have" changed
4475 try
4476 {
4477 Class.forName("android.app.backup.BackupManager");
4478 BackupManager b = (BackupManager) backupManager;
4479 b.dataChanged();
4480 }
4481 catch (ClassNotFoundException e)
4482 {
4483 e.printStackTrace();
4484 }
4485 catch (Exception e)
4486 {
4487 e.printStackTrace();
4488 }
4489
4490 turn_off_compass();
4491
4492 // System.out.println("XXNAV: onpause:001");
4493 if (!Navit.is_navigating)
4494 {
4495 // System.out.println("XXNAV: onpause:002");
4496 NavitVehicle.turn_off_all_providers();
4497 NavitVehicle.turn_off_sat_status();
4498 // System.out.println("XXNAV: onpause:003");
4499 }
4500
4501 // Log.e("Navit", "OnPause");
4502 cwthr.NavitActivity2(-1);
4503
4504 Navit.show_mem_used();
4505
4506 try
4507 {
4508 if (wl != null)
4509 {
4510 wl.release();
4511 Log.e("Navit", "WakeLock: release 1");
4512 }
4513 }
4514 catch (Exception e)
4515 {
4516 e.printStackTrace();
4517 }
4518
4519 try
4520 {
4521 if (wl_cpu != null)
4522 {
4523 if (wl_cpu.isHeld())
4524 {
4525 wl_cpu.release();
4526 Log.e("Navit", "WakeLock CPU: release 1");
4527 }
4528 }
4529 }
4530 catch (Exception e)
4531 {
4532 e.printStackTrace();
4533 }
4534
4535 // glSurfaceView.onPause();
4536
4537 is_paused = true;
4538 }
4539
4540 @Override
4541 public void onStop()
4542 {
4543 super.onStop();
4544 Log.e("Navit", "OnStop");
4545
4546 if (!Navit.is_navigating)
4547 {
4548 NavitVehicle.turn_off_all_providers();
4549 NavitVehicle.turn_off_sat_status();
4550 }
4551
4552 cwthr.NavitActivity2(-2);
4553 Navit.show_mem_used();
4554
4555 // if (!Navit.is_navigating)
4556 // {
4557 // try
4558 // {
4559 // mTts.stop();
4560 // }
4561 // catch (Exception e)
4562 // {
4563 //
4564 // }
4565 //
4566 // try
4567 // {
4568 // mTts.shutdown();
4569 // }
4570 // catch (Exception e)
4571 // {
4572 //
4573 // }
4574 //
4575 // mTts = null;
4576 // }
4577
4578 // save points
4579 write_map_points();
4580 }
4581
4582 @Override
4583 public void onDestroy()
4584 {
4585 super.onDestroy();
4586 Log.e("Navit", "OnDestroy");
4587
4588 try
4589 {
4590 try
4591 {
4592 plugin_api.removeListener(zclientListener);
4593 }
4594 catch (Exception e)
4595 {
4596 e.printStackTrace();
4597 Log.i("NavitPlugin", "Failed to remove Listener", e);
4598 }
4599 unbindService(serviceConnection);
4600 Log.i("NavitPlugin", "Unbind from the service");
4601 }
4602 catch (Throwable t)
4603 {
4604 // catch any issues, typical for destroy routines
4605 // even if we failed to destroy something, we need to continue destroying
4606 Log.i("NavitPlugin", "Failed to unbind from the service", t);
4607 }
4608
4609 try
4610 {
4611 mTts.stop();
4612 }
4613 catch (Exception e)
4614 {
4615
4616 }
4617
4618 try
4619 {
4620 mTts.shutdown();
4621 }
4622 catch (Exception e)
4623 {
4624
4625 }
4626
4627 mTts = null;
4628
4629 // ----- service stop -----
4630 // ----- service stop -----
4631 System.out.println("Navit:onDestroy -> stop ZANaviMapDownloaderService ---------");
4632 stopService(Navit.ZANaviMapDownloaderServiceIntent);
4633 try
4634 {
4635 Thread.sleep(1000);
4636 }
4637 catch (InterruptedException e)
4638 {
4639 }
4640 // ----- service stop -----
4641 // ----- service stop -----
4642
4643 NavitActivity(-3);
4644 Navit.show_mem_used();
4645 }
4646
4647 public void setActivityResult(int requestCode, NavitActivityResult ActivityResult)
4648 {
4649 Log.e("Navit", "setActivityResult " + requestCode);
4650 ActivityResults[requestCode] = ActivityResult;
4651 }
4652
4653 @Override
4654 public boolean onKeyUp(int keyCode, KeyEvent event)
4655 {
4656 if (keyCode == KeyEvent.KEYCODE_MENU)
4657 {
4658 if (cur_menu != null)
4659 {
4660 // open the overflow menu
4661 cur_menu.performIdentifierAction(R.id.item_overflow, 0);
4662 return true;
4663 }
4664 }
4665 return super.onKeyUp(keyCode, event);
4666 }
4667
4668 // @Override
4669 // public boolean onKeyDown(int keyCode, KeyEvent event)
4670 // {
4671 // if (keyCode == KeyEvent.KEYCODE_MENU)
4672 // {
4673 // return true;
4674 // }
4675 // return super.onKeyUp(keyCode, event);
4676 // }
4677
4678 @Override
4679 public boolean onPrepareOptionsMenu(Menu menu)
4680 {
4681 super.onPrepareOptionsMenu(menu);
4682 //
4683 menu.clear();
4684
4685 // load the menu from XML
4686 getMenuInflater().inflate(R.menu.actionbaricons, menu);
4687
4688 // NavitOverflowMenuItemID = R.id.item_overflow_menu_button;
4689 menu.findItem(R.id.share_menu_destination).setTitle(Navit.get_text("Share Destination"));
4690 menu.findItem(R.id.share_menu_location).setTitle(Navit.get_text("Share my Location"));
4691 menu.findItem(R.id.search_menu_offline).setTitle(get_text("address search (offline)"));
4692 menu.findItem(R.id.search_menu_online).setTitle(get_text("address search (online)"));
4693 menu.findItem(R.id.item_recentdest_menu_button).setTitle(get_text("Recent destinations"));
4694 menu.findItem(R.id.item_settings_menu_button).setTitle(get_text("Settings"));
4695 menu.findItem(R.id.item_search_menu_button).setTitle(get_text("Search"));
4696 menu.findItem(R.id.item_download_menu_button).setTitle(get_text("downloading map"));
4697 //
4698 menu.findItem(R.id.overflow_share_location).setTitle(Navit.get_text("Share my Location"));
4699 menu.findItem(R.id.overflow_share_destination).setTitle(Navit.get_text("Share Destination"));
4700 menu.findItem(R.id.overflow_settings).setTitle(Navit.get_text("Settings"));
4701 menu.findItem(R.id.overflow_zoom_to_route).setTitle(Navit.get_text("Zoom to Route"));
4702
4703 if (ZANaviNormalDonateActivity.on_amazon_device)
4704 {
4705 menu.findItem(R.id.overflow_donate_item).setTitle(Navit.get_text("Donate"));
4706 }
4707 else
4708 {
4709 menu.findItem(R.id.overflow_donate_item).setTitle(Navit.get_text("Donate with Google Play"));
4710 }
4711 menu.findItem(R.id.overflow_donate_bitcoins_item).setTitle(Navit.get_text("Donate with Bitcoin"));
4712 //. TRANSLATORS: text to translate is: exit ZANavi
4713 menu.findItem(R.id.overflow_exit).setTitle(Navit.get_text("exit navit"));
4714 menu.findItem(R.id.overflow_toggle_poi).setTitle(Navit.get_text("toggle POI"));
4715 menu.findItem(R.id.overflow_announcer_on).setTitle(Navit.get_text("Announcer On"));
4716 menu.findItem(R.id.overflow_announcer_off).setTitle(Navit.get_text("Announcer Off"));
4717 menu.findItem(R.id.overflow_download_maps).setTitle(Navit.get_text("download maps"));
4718 menu.findItem(R.id.overflow_delete_maps).setTitle(Navit.get_text("delete maps"));
4719 menu.findItem(R.id.overflow_maps_age).setTitle(Navit.get_text("show Maps age"));
4720 menu.findItem(R.id.overflow_coord_dialog).setTitle(Navit.get_text("Coord Dialog"));
4721 menu.findItem(R.id.overflow_add_traffic_block).setTitle(Navit.get_text("add Traffic block"));
4722 menu.findItem(R.id.overflow_clear_traffic_block).setTitle(Navit.get_text("clear Traffic blocks"));
4723 menu.findItem(R.id.overflow_convert_gpx_file).setTitle(Navit.get_text("convert GPX file"));
4724 menu.findItem(R.id.overflow_replay_gps_file).setTitle(Navit.get_text("replay a ZANavi gps file"));
4725 menu.findItem(R.id.overflow_clear_gpx_map).setTitle(Navit.get_text("clear GPX map"));
4726 // menu.findItem(R.id.overflow_dummy2)
4727 menu.findItem(R.id.overflow_demo_v_normal).setTitle(get_text("Demo Vehicle") + " [normal]");
4728 menu.findItem(R.id.overflow_demo_v_fast).setTitle(get_text("Demo Vehicle") + " [fast]");
4729 menu.findItem(R.id.overflow_speech_texts).setTitle(Navit.get_text("Speech Texts"));
4730 menu.findItem(R.id.overflow_nav_commands).setTitle(Navit.get_text("Nav. Commands"));
4731 menu.findItem(R.id.overflow_toggle_route_graph).setTitle(Navit.get_text("toggle Routegraph"));
4732 //menu.findItem(R.id.overflow_dummy1)
4733 menu.findItem(R.id.overflow_export_map_points_to_sdcard).setTitle(Navit.get_text("export Destinations"));
4734 menu.findItem(R.id.overflow_import_map_points_from_sdcard).setTitle(Navit.get_text("import Destinations"));
4735 menu.findItem(R.id.overflow_send_feedback).setTitle(Navit.get_text("send feedback"));
4736 menu.findItem(R.id.overflow_online_help).setTitle(Navit.get_text("online Help"));
4737 //. TRANSLATORS: it means: "show current target in google maps"
4738 //. TRANSLATORS: please keep this text short, to fit in the android menu!
4739 menu.findItem(R.id.overflow_target_in_gmaps).setTitle(Navit.get_text("Target in gmaps"));
4740 //
4741 //
4742 menu.findItem(R.id.item_share_menu_button).setTitle(get_text("Share"));
4743
4744 Display display_ = getWindowManager().getDefaultDisplay();
4745 Log.e("Navit", "Navit width in DP -> " + display_.getWidth() / Navit.metrics.density);
4746 Log.e("Navit", "Navit width in DP -> density=" + Navit.metrics.density);
4747
4748 try
4749 {
4750 View v4 = findViewById(R.id.item_settings_menu_button);
4751 // Log.e("Navit", "Navit width in DP -> v4=" + v4);
4752 if ((v4 != null) && (v4.getWidth() > 0))
4753 {
4754 Log.e("Navit", "Navit width in DP -> v4.w=" + v4.getWidth());
4755 MenuItem menuItem = menu.findItem(R.id.item_settings_menu_button);
4756 // Log.e("Navit", "Navit width in DP -> mi=" + menuItem);
4757 // Log.e("Navit", "Navit width in DP -> i=" + menuItem.getIcon());
4758 Log.e("Navit", "Navit width in DP -> i.w=" + menuItem.getIcon().getIntrinsicWidth());
4759 actionbar_item_width = (int) ((v4.getWidth() + (menuItem.getIcon().getIntrinsicWidth() * 1.5f)) / 2);
4760 }
4761 else
4762 {
4763 MenuItem menuItem = menu.findItem(R.id.item_settings_menu_button);
4764 // Log.e("Navit", "Navit width in DP -> mi=" + menuItem);
4765 // Log.e("Navit", "Navit width in DP -> i=" + menuItem.getIcon());
4766 Log.e("Navit", "Navit width in DP -> i.w=" + menuItem.getIcon().getIntrinsicWidth());
4767 actionbar_item_width = (int) ((menuItem.getIcon().getIntrinsicWidth()) * 1.7f);
4768 }
4769
4770 actionbar_items_will_fit = display_.getWidth() / actionbar_item_width;
4771 Log.e("Navit", "Navit width in DP -> number of items that will fit=" + actionbar_items_will_fit);
4772 if (actionbar_items_will_fit > 6) // now we need to fit max. 6 items on actionbar
4773 {
4774 actionbar_all_items_will_fit = true;
4775 }
4776 else
4777 {
4778 actionbar_all_items_will_fit = false;
4779 }
4780 }
4781 catch (Exception e)
4782 {
4783 if ((display_.getWidth() / Navit.metrics.density) < NAVIT_MIN_HORIZONTAL_DP_FOR_ACTIONBAR)
4784 {
4785 actionbar_all_items_will_fit = false;
4786 }
4787 else
4788 {
4789 actionbar_all_items_will_fit = true;
4790 }
4791 }
4792
4793 if (actionbar_all_items_will_fit == false)
4794 {
4795 menu.findItem(R.id.item_share_menu_button).setVisible(false);
4796 menu.findItem(R.id.overflow_share_location).setVisible(true);
4797 if (NavitGraphics.CallbackDestinationValid2() == 0)
4798 {
4799 menu.findItem(R.id.overflow_share_destination).setVisible(false);
4800 }
4801 else
4802 {
4803 menu.findItem(R.id.overflow_share_destination).setVisible(true);
4804 }
4805
4806 if (actionbar_items_will_fit < 6)
4807 {
4808 // also push the settings icons to overflow menu
4809 menu.findItem(R.id.item_settings_menu_button).setVisible(false);
4810 menu.findItem(R.id.overflow_settings).setVisible(true);
4811 }
4812 else
4813 {
4814 menu.findItem(R.id.item_settings_menu_button).setVisible(true);
4815 menu.findItem(R.id.overflow_settings).setVisible(false);
4816 }
4817 }
4818 else
4819 {
4820 menu.findItem(R.id.item_settings_menu_button).setVisible(true);
4821 menu.findItem(R.id.overflow_settings).setVisible(false);
4822 menu.findItem(R.id.overflow_share_location).setVisible(false);
4823 menu.findItem(R.id.overflow_share_destination).setVisible(false);
4824 menu.findItem(R.id.item_share_menu_button).setVisible(true);
4825 }
4826
4827 cur_menu = menu;
4828
4829 if (actionabar_download_icon_visible)
4830 {
4831 menu.findItem(R.id.item_download_menu_button).setVisible(true);
4832 }
4833 else
4834 {
4835 menu.findItem(R.id.item_download_menu_button).setVisible(false);
4836 }
4837
4838 if (NavitGraphics.CallbackDestinationValid2() > 0)
4839 {
4840 menu.findItem(R.id.item_endnavigation_menu_button).setVisible(true);
4841 menu.findItem(R.id.item_endnavigation_menu_button).setTitle(get_text("Stop Navigation"));
4842 menu.findItem(R.id.overflow_zoom_to_route).setVisible(true);
4843 menu.findItem(R.id.overflow_target_in_gmaps).setVisible(true);
4844 menu.findItem(R.id.share_menu_destination).setVisible(true);
4845 }
4846 else
4847 {
4848 menu.findItem(R.id.item_endnavigation_menu_button).setVisible(false);
4849 menu.findItem(R.id.overflow_zoom_to_route).setVisible(false);
4850 menu.findItem(R.id.overflow_target_in_gmaps).setVisible(false);
4851 menu.findItem(R.id.share_menu_destination).setVisible(false);
4852 }
4853
4854 if (Navit_Announcer == true)
4855 {
4856 menu.findItem(R.id.overflow_announcer_off).setVisible(true);
4857 menu.findItem(R.id.overflow_announcer_on).setVisible(false);
4858 }
4859 else
4860 {
4861 menu.findItem(R.id.overflow_announcer_off).setVisible(false);
4862 menu.findItem(R.id.overflow_announcer_on).setVisible(true);
4863 }
4864
4865 if (p.PREF_enable_debug_functions)
4866 {
4867 menu.findItem(R.id.overflow_dummy2).setVisible(true);
4868 menu.findItem(R.id.overflow_demo_v_normal).setVisible(true);
4869 menu.findItem(R.id.overflow_demo_v_fast).setVisible(true);
4870 menu.findItem(R.id.overflow_speech_texts).setVisible(true);
4871 menu.findItem(R.id.overflow_nav_commands).setVisible(true);
4872 menu.findItem(R.id.overflow_toggle_route_graph).setVisible(true);
4873 menu.findItem(R.id.overflow_replay_gps_file).setVisible(true);
4874 }
4875 else
4876 {
4877 menu.findItem(R.id.overflow_dummy2).setVisible(false);
4878 menu.findItem(R.id.overflow_demo_v_normal).setVisible(false);
4879 menu.findItem(R.id.overflow_demo_v_fast).setVisible(false);
4880 menu.findItem(R.id.overflow_speech_texts).setVisible(false);
4881 menu.findItem(R.id.overflow_nav_commands).setVisible(false);
4882 menu.findItem(R.id.overflow_toggle_route_graph).setVisible(false);
4883 menu.findItem(R.id.overflow_replay_gps_file).setVisible(false);
4884 }
4885
4886 return true;
4887 }
4888
4889 public void start_targetsearch_from_intent(String target_address)
4890 {
4891 Navit_last_address_partial_match = true; // this will overwrite the default setting --> this is not good
4892 Navit_last_address_search_string = target_address;
4893 Navit_last_address_hn_string = "";
4894
4895 // ----------- CONFIG ---------
4896 // ----------- CONFIG ---------
4897 // ----------- CONFIG ---------
4898 Boolean use_online_searchmode_here = true;
4899 Boolean hide_duplicates_searchmode_here = false;
4900 // ----------- CONFIG ---------
4901 // ----------- CONFIG ---------
4902 // ----------- CONFIG ---------
4903
4904 int dialog_num_;
4905
4906 if (use_online_searchmode_here)
4907 {
4908 dialog_num_ = Navit.SEARCHRESULTS_WAIT_DIALOG;
4909 Navit.use_index_search = false;
4910 Log.e("Navit", "*google*:online search");
4911 }
4912 else
4913 {
4914 dialog_num_ = Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE;
4915 Navit.use_index_search = Navit.allow_use_index_search();
4916 }
4917
4918 // clear results
4919 Navit.NavitAddressResultList_foundItems.clear();
4920 Navit.Navit_Address_Result_double_index.clear();
4921 Navit.NavitSearchresultBarIndex = -1;
4922 Navit.NavitSearchresultBar_title = "";
4923 Navit.NavitSearchresultBar_text = "";
4924 search_hide_duplicates = false;
4925
4926 if (Navit_last_address_search_string.equals(""))
4927 {
4928 // empty search string entered
4929 Toast.makeText(getApplicationContext(), Navit.get_text("No address found"), Toast.LENGTH_LONG).show(); //TRANS
4930 }
4931 else
4932 {
4933 // show dialog
4934 try
4935 {
4936 Log.e("Navit", "*google*:call-11: (0)num " + dialog_num_);
4937 }
4938 catch (Exception e)
4939 {
4940 e.printStackTrace();
4941 }
4942
4943 if (hide_duplicates_searchmode_here)
4944 {
4945 search_hide_duplicates = true;
4946 // hide duplicates when searching
4947 // hide duplicates when searching
4948 Message msg22 = new Message();
4949 Bundle b22 = new Bundle();
4950 b22.putInt("Callback", 45);
4951 msg22.setData(b22);
4952 NavitGraphics.callback_handler.sendMessage(msg22);
4953 // hide duplicates when searching
4954 // hide duplicates when searching
4955 }
4956
4957 Message msg = progress_handler.obtainMessage();
4958 Bundle b = new Bundle();
4959 msg.what = 11;
4960 b.putInt("dialog_num", dialog_num_);
4961 msg.setData(b);
4962 progress_handler.sendMessage(msg);
4963 }
4964 }
4965
4966 @Override
4967 public boolean onCreateOptionsMenu(Menu menu)
4968 {
4969 super.onCreateOptionsMenu(menu);
4970
4971 return true;
4972 }
4973
4974 @Override
4975 public boolean onOptionsItemSelected(MenuItem item)
4976 {
4977 //System.out.println("menu button pressed ID=" + item.getItemId());
4978
4979 if ((item.getItemId() == R.id.share_menu_destination) || (item.getItemId() == R.id.overflow_share_destination) || (item.getItemId() == 23020))
4980 {
4981 // System.out.println("share destination pressed ID=" + item.getItemId());
4982 // ------------
4983 // ------------
4984 // share the current destination with your friends
4985 String current_target_string2 = NavitGraphics.CallbackGeoCalc(4, 1, 1);
4986 if (current_target_string2.equals("x:x"))
4987 {
4988 Log.e("Navit", "no target set!");
4989 }
4990 else
4991 {
4992 try
4993 {
4994 String tmp[] = current_target_string2.split(":", 2);
4995
4996 if (Navit.OSD_route_001.arriving_time_valid)
4997 {
4998 share_location(tmp[0], tmp[1], Navit.get_text("Meeting Point"), Navit.get_text("Meeting Point"), Navit.OSD_route_001.arriving_time, true);
4999 }
5000 else
5001 {
5002 share_location(tmp[0], tmp[1], Navit.get_text("Meeting Point"), Navit.get_text("Meeting Point"), "", true);
5003 }
5004
5005 }
5006 catch (Exception e)
5007 {
5008 e.printStackTrace();
5009 Log.e("Navit", "problem with target!");
5010 }
5011 }
5012 return true;
5013 }
5014 else if (item.getItemId() == R.id.item_download_menu_button)
5015 {
5016 // System.out.println("download icon pressed(1) ID=" + item.getItemId());
5017
5018 Intent mapdownload_cancel_activity = new Intent(this, ZANaviDownloadMapCancelActivity.class);
5019 mapdownload_cancel_activity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
5020 startActivity(mapdownload_cancel_activity);
5021
5022 return true;
5023 }
5024 else if ((item.getItemId() == R.id.share_menu_location) || (item.getItemId() == R.id.overflow_share_location) || (item.getItemId() == 23000))
5025 {
5026 // System.out.println("share location pressed ID=" + item.getItemId());
5027 // ------------
5028 // ------------
5029 // share the current location with your friends
5030 location_coords cur_target = null;
5031 try
5032 {
5033 geo_coord tmp = get_current_vehicle_position();
5034 cur_target.lat = tmp.Latitude;
5035 cur_target.lon = tmp.Longitude;
5036 // cur_target = NavitVehicle.get_last_known_pos();
5037 }
5038 catch (Exception e)
5039 {
5040 }
5041
5042 if (cur_target == null)
5043 {
5044 Log.e("Navit", "no location found!");
5045 }
5046 else
5047 {
5048 try
5049 {
5050 share_location(String.valueOf(cur_target.lat), String.valueOf(cur_target.lon), Navit.get_text("my Location"), Navit.get_text("my Location"), "", false);
5051 }
5052 catch (Exception e)
5053 {
5054 e.printStackTrace();
5055 Log.e("Navit", "problem with location!");
5056 }
5057 }
5058 return true;
5059 }
5060 else if ((item.getItemId() == R.id.item_settings_menu_button) || (item.getItemId() == R.id.overflow_settings) || (item.getItemId() == 490))
5061 {
5062 // open settings menu
5063 Intent settingsActivity = new Intent(getBaseContext(), NavitPreferences.class);
5064 startActivity(settingsActivity);
5065
5066 return true;
5067 }
5068 else if (item.getItemId() == R.id.search_menu_offline)
5069 {
5070 // ok startup address search activity (offline binfile search)
5071 Navit.use_index_search = Navit.allow_use_index_search();
5072 Intent search_intent2 = new Intent(this, NavitAddressSearchActivity.class);
5073 search_intent2.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
5074 search_intent2.putExtra("address_string", Navit_last_address_search_string);
5075 search_intent2.putExtra("hn_string", Navit_last_address_hn_string);
5076 search_intent2.putExtra("type", "offline");
5077 search_intent2.putExtra("search_country_id", Navit_last_address_search_country_id);
5078
5079 String pm_temp2 = "0";
5080 if (Navit_last_address_partial_match)
5081 {
5082 pm_temp2 = "1";
5083 }
5084
5085 search_intent2.putExtra("partial_match", pm_temp2);
5086
5087 Navit.use_index_search = Navit.allow_use_index_search();
5088 if (Navit.use_index_search)
5089 {
5090 this.startActivityForResult(search_intent2, NavitAddressResultList_id);
5091 }
5092 else
5093 {
5094 this.startActivityForResult(search_intent2, NavitAddressSearch_id_offline);
5095 }
5096
5097 return true;
5098 }
5099 else if (item.getItemId() == R.id.search_menu_online)
5100 {
5101 // ok startup address search activity (online google maps search)
5102 Navit.use_index_search = false;
5103 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
5104 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
5105 search_intent.putExtra("address_string", Navit_last_address_search_string);
5106 //search_intent.putExtra("hn_string", Navit_last_address_hn_string);
5107 search_intent.putExtra("type", "online");
5108 String pm_temp = "0";
5109 if (Navit_last_address_partial_match)
5110 {
5111 pm_temp = "1";
5112 }
5113 search_intent.putExtra("partial_match", pm_temp);
5114 this.startActivityForResult(search_intent, NavitAddressSearch_id_online);
5115
5116 return true;
5117 }
5118 else if (item.getItemId() == R.id.item_endnavigation_menu_button)
5119 {
5120 // stop navigation (this menu should only appear when navigation is actually on!)
5121 NavitGraphics.deactivate_nav_wakelock();
5122 Message msg2 = new Message();
5123 Bundle b2 = new Bundle();
5124 b2.putInt("Callback", 7);
5125 msg2.setData(b2);
5126 NavitGraphics.callback_handler.sendMessage(msg2);
5127 Log.e("Navit", "stop navigation");
5128
5129 if (p.PREF_enable_debug_write_gpx)
5130 {
5131 NavitVehicle.speech_recording_end();
5132 }
5133
5134 // redraw all OSD elements
5135 Navit.OSD_route_001.arriving_time_valid = false;
5136 Navit.OSD_route_001.arriving_secs_to_dest_valid = false;
5137 Navit.OSD_route_001.driving_distance_to_target_valid = false;
5138 Navit.OSD_nextturn.nextturn_distance_valid = false;
5139 Navit.OSD_nextturn.nextturn_image_valid = false;
5140 Navit.OSD_compass.direct_distance_to_target_valid = false;
5141 NavitGraphics.OSD_new.postInvalidate();
5142
5143 return true;
5144 }
5145 else if (item.getItemId() == R.id.item_recentdest_menu_button)
5146 {
5147 // show recent destination list
5148 Intent i2 = new Intent(this, NavitRecentDestinationActivity.class);
5149 this.startActivityForResult(i2, Navit.NavitRecentDest_id);
5150
5151 return true;
5152 }
5153 else if (item.getItemId() == R.id.overflow_zoom_to_route)
5154 {
5155 return onOptionsItemSelected_wrapper(11);
5156 }
5157 else if (item.getItemId() == R.id.overflow_donate_item)
5158 {
5159 return onOptionsItemSelected_wrapper(26);
5160 }
5161 else if (item.getItemId() == R.id.overflow_donate_bitcoins_item)
5162 {
5163 return onOptionsItemSelected_wrapper(27);
5164 }
5165 else if (item.getItemId() == R.id.overflow_exit)
5166 {
5167 return onOptionsItemSelected_wrapper(99);
5168 }
5169 else if (item.getItemId() == R.id.overflow_toggle_poi)
5170 {
5171 return onOptionsItemSelected_wrapper(5);
5172 }
5173 else if (item.getItemId() == R.id.overflow_announcer_on)
5174 {
5175 return onOptionsItemSelected_wrapper(13);
5176 }
5177 else if (item.getItemId() == R.id.overflow_announcer_off)
5178 {
5179 return onOptionsItemSelected_wrapper(12);
5180 }
5181 else if (item.getItemId() == R.id.overflow_download_maps)
5182 {
5183 return onOptionsItemSelected_wrapper(3);
5184 }
5185 else if (item.getItemId() == R.id.overflow_delete_maps)
5186 {
5187 return onOptionsItemSelected_wrapper(8);
5188 }
5189 else if (item.getItemId() == R.id.overflow_maps_age)
5190 {
5191 return onOptionsItemSelected_wrapper(17);
5192 }
5193 else if (item.getItemId() == R.id.overflow_coord_dialog)
5194 {
5195 return onOptionsItemSelected_wrapper(19);
5196 }
5197 else if (item.getItemId() == R.id.overflow_add_traffic_block)
5198 {
5199 return onOptionsItemSelected_wrapper(21);
5200 }
5201 else if (item.getItemId() == R.id.overflow_clear_traffic_block)
5202 {
5203 return onOptionsItemSelected_wrapper(22);
5204 }
5205 else if (item.getItemId() == R.id.overflow_convert_gpx_file)
5206 {
5207 return onOptionsItemSelected_wrapper(20);
5208 }
5209 else if (item.getItemId() == R.id.overflow_clear_gpx_map)
5210 {
5211 return onOptionsItemSelected_wrapper(23);
5212 }
5213 else if (item.getItemId() == R.id.overflow_replay_gps_file)
5214 {
5215 return onOptionsItemSelected_wrapper(28);
5216 }
5217 else if (item.getItemId() == R.id.overflow_demo_v_normal)
5218 {
5219 return onOptionsItemSelected_wrapper(601);
5220 }
5221 else if (item.getItemId() == R.id.overflow_demo_v_fast)
5222 {
5223 return onOptionsItemSelected_wrapper(604);
5224 }
5225 else if (item.getItemId() == R.id.overflow_speech_texts)
5226 {
5227 return onOptionsItemSelected_wrapper(602);
5228 }
5229 else if (item.getItemId() == R.id.overflow_nav_commands)
5230 {
5231 return onOptionsItemSelected_wrapper(603);
5232 }
5233 else if (item.getItemId() == R.id.overflow_toggle_route_graph)
5234 {
5235 return onOptionsItemSelected_wrapper(605);
5236 }
5237 else if (item.getItemId() == R.id.overflow_export_map_points_to_sdcard)
5238 {
5239 return onOptionsItemSelected_wrapper(607);
5240 }
5241 else if (item.getItemId() == R.id.overflow_import_map_points_from_sdcard)
5242 {
5243 return onOptionsItemSelected_wrapper(608);
5244 }
5245 else if (item.getItemId() == R.id.overflow_send_feedback)
5246 {
5247 return onOptionsItemSelected_wrapper(24);
5248 }
5249 else if (item.getItemId() == R.id.overflow_online_help)
5250 {
5251 return onOptionsItemSelected_wrapper(16);
5252 }
5253 else if (item.getItemId() == R.id.overflow_target_in_gmaps)
5254 {
5255 return onOptionsItemSelected_wrapper(15);
5256 }
5257 // else
5258 // {
5259 // return onOptionsItemSelected_wrapper(item.getItemId());
5260 // }
5261
5262 return false;
5263 }
5264
5265 @SuppressLint("NewApi")
5266 public boolean onOptionsItemSelected_wrapper(int id)
5267 {
5268 // Handle item selection
5269 switch (id)
5270 {
5271 case 1:
5272 // zoom in
5273 Message msg = new Message();
5274 Bundle b = new Bundle();
5275 b.putInt("Callback", 1);
5276 msg.setData(b);
5277 NavitGraphics.callback_handler.sendMessage(msg);
5278 // if we zoom, hide the bubble
5279 if (N_NavitGraphics.NavitAOverlay != null)
5280 {
5281 N_NavitGraphics.NavitAOverlay.hide_bubble();
5282 }
5283 Log.e("Navit", "onOptionsItemSelected -> zoom in");
5284 break;
5285 case 2:
5286 // zoom out
5287 msg = new Message();
5288 b = new Bundle();
5289 b.putInt("Callback", 2);
5290 msg.setData(b);
5291 NavitGraphics.callback_handler.sendMessage(msg);
5292 // if we zoom, hide the bubble
5293 if (N_NavitGraphics.NavitAOverlay != null)
5294 {
5295 N_NavitGraphics.NavitAOverlay.hide_bubble();
5296 }
5297 Log.e("Navit", "onOptionsItemSelected -> zoom out");
5298 break;
5299 case 3:
5300 // map download menu
5301 Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class);
5302 this.startActivityForResult(map_download_list_activity, Navit.NavitDownloaderPriSelectMap_id);
5303 break;
5304 case 5:
5305 toggle_poi_pref();
5306 set_poi_layers();
5307 draw_map();
5308 break;
5309 case 6:
5310 // ok startup address search activity (online google maps search)
5311 Navit.use_index_search = false;
5312 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
5313 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
5314 search_intent.putExtra("address_string", Navit_last_address_search_string);
5315 //search_intent.putExtra("hn_string", Navit_last_address_hn_string);
5316 search_intent.putExtra("type", "online");
5317 String pm_temp = "0";
5318 if (Navit_last_address_partial_match)
5319 {
5320 pm_temp = "1";
5321 }
5322 search_intent.putExtra("partial_match", pm_temp);
5323 this.startActivityForResult(search_intent, NavitAddressSearch_id_online);
5324 break;
5325 case 7:
5326 // ok startup address search activity (offline binfile search)
5327 Navit.use_index_search = Navit.allow_use_index_search();
5328 Intent search_intent2 = new Intent(this, NavitAddressSearchActivity.class);
5329 search_intent2.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
5330 search_intent2.putExtra("address_string", Navit_last_address_search_string);
5331 search_intent2.putExtra("hn_string", Navit_last_address_hn_string);
5332 search_intent2.putExtra("type", "offline");
5333 search_intent2.putExtra("search_country_id", Navit_last_address_search_country_id);
5334
5335 String pm_temp2 = "0";
5336 if (Navit_last_address_partial_match)
5337 {
5338 pm_temp2 = "1";
5339 }
5340
5341 search_intent2.putExtra("partial_match", pm_temp2);
5342 this.startActivityForResult(search_intent2, NavitAddressSearch_id_offline);
5343 break;
5344 case 8:
5345 // map delete menu
5346 Intent map_delete_list_activity2 = new Intent(this, NavitDeleteSelectMapActivity.class);
5347 this.startActivityForResult(map_delete_list_activity2, Navit.NavitDeleteSecSelectMap_id);
5348 break;
5349 case 9:
5350 // stop navigation (this menu should only appear when navigation is actually on!)
5351 Message msg2 = new Message();
5352 Bundle b2 = new Bundle();
5353 b2.putInt("Callback", 7);
5354 msg2.setData(b2);
5355 NavitGraphics.callback_handler.sendMessage(msg2);
5356 Log.e("Navit", "stop navigation");
5357 break;
5358 case 10:
5359 // open settings menu
5360 Intent settingsActivity = new Intent(getBaseContext(), NavitPreferences.class);
5361 startActivity(settingsActivity);
5362 break;
5363 case 11:
5364 //zoom_to_route
5365 zoom_to_route();
5366 break;
5367 case 12:
5368 // announcer off
5369 Navit_Announcer = false;
5370 msg = new Message();
5371 b = new Bundle();
5372 b.putInt("Callback", 34);
5373 msg.setData(b);
5374 NavitGraphics.callback_handler.sendMessage(msg);
5375 try
5376 {
5377 invalidateOptionsMenu();
5378 }
5379 catch (Exception e)
5380 {
5381 }
5382 break;
5383 case 13:
5384 // announcer on
5385 Navit_Announcer = true;
5386 msg = new Message();
5387 b = new Bundle();
5388 b.putInt("Callback", 35);
5389 msg.setData(b);
5390 NavitGraphics.callback_handler.sendMessage(msg);
5391 try
5392 {
5393 invalidateOptionsMenu();
5394 }
5395 catch (Exception e)
5396 {
5397 }
5398 break;
5399 case 14:
5400 // show recent destination list
5401 Intent i2 = new Intent(this, NavitRecentDestinationActivity.class);
5402 this.startActivityForResult(i2, Navit.NavitRecentDest_id);
5403 break;
5404 case 15:
5405 // show current target on googlemaps
5406 String current_target_string = NavitGraphics.CallbackGeoCalc(4, 1, 1);
5407 // Log.e("Navit", "got target 1: "+current_target_string);
5408 if (current_target_string.equals("x:x"))
5409 {
5410 Log.e("Navit", "no target set!");
5411 }
5412 else
5413 {
5414 try
5415 {
5416 String tmp[] = current_target_string.split(":", 2);
5417 googlemaps_show(tmp[0], tmp[1], "ZANavi Target");
5418 }
5419 catch (Exception e)
5420 {
5421 e.printStackTrace();
5422 Log.e("Navit", "problem with target!");
5423 }
5424 }
5425 break;
5426 case 16:
5427 // show online manual
5428 Log.e("Navit", "user wants online help, show the website lang=" + NavitTextTranslations.main_language.toLowerCase());
5429 // URL to ZANavi Manual (in english language)
5430 String url = "http://zanavi.cc/index.php/Manual";
5431 if (FDBL)
5432 {
5433 url = "http://fd.zanavi.cc/manual";
5434 }
5435 if (NavitTextTranslations.main_language.toLowerCase().equals("de"))
5436 {
5437 // show german manual
5438 url = "http://zanavi.cc/index.php/Manual/de";
5439 if (FDBL)
5440 {
5441 url = "http://fd.zanavi.cc/manualde";
5442 }
5443 }
5444
5445 Intent i = new Intent(Intent.ACTION_VIEW);
5446 i.setData(Uri.parse(url));
5447 startActivity(i);
5448 break;
5449 case 17:
5450 // show age of maps (online)
5451 Intent i3 = new Intent(Intent.ACTION_VIEW);
5452 i3.setData(Uri.parse(NavitMapDownloader.ZANAVI_MAPS_AGE_URL));
5453 startActivity(i3);
5454 break;
5455 case 18:
5456 Intent intent_latlon = new Intent(Intent.ACTION_MAIN);
5457 //intent_latlon.setAction("android.intent.action.POINTPICK");
5458 intent_latlon.setPackage("com.cruthu.latlongcalc1");
5459 intent_latlon.setClassName("com.cruthu.latlongcalc1", "com.cruthu.latlongcalc1.LatLongMain");
5460 //intent_latlon.setClassName("com.cruthu.latlongcalc1", "com.cruthu.latlongcalc1.LatLongPointPick");
5461 try
5462 {
5463 startActivity(intent_latlon);
5464 }
5465 catch (Exception e88)
5466 {
5467 e88.printStackTrace();
5468 // show install page
5469 try
5470 {
5471 // String urlx = "http://market.android.com/details?id=com.cruthu.latlongcalc1";
5472 String urlx = "market://details?id=com.cruthu.latlongcalc1";
5473 Intent ix = new Intent(Intent.ACTION_VIEW);
5474 ix.setData(Uri.parse(urlx));
5475 startActivity(ix);
5476 }
5477 catch (Exception ex)
5478 {
5479 ex.printStackTrace();
5480 }
5481 }
5482 break;
5483 case 19:
5484 // GeoCoordEnterDialog
5485 Intent it001 = new Intent(this, GeoCoordEnterDialog.class);
5486 this.startActivityForResult(it001, Navit.NavitGeoCoordEnter_id);
5487 break;
5488 case 20:
5489 // convert GPX file
5490 Intent intent77 = new Intent(getBaseContext(), FileDialog.class);
5491 File a = new File(p.PREF_last_selected_dir_gpxfiles);
5492 try
5493 {
5494 // convert the "/../" in the path to normal absolut dir
5495 intent77.putExtra(FileDialog.START_PATH, a.getCanonicalPath());
5496 //can user select directories or not
5497 intent77.putExtra(FileDialog.CAN_SELECT_DIR, false);
5498 // disable the "new" button
5499 intent77.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
5500 //alternatively you can set file filter
5501 //intent.putExtra(FileDialog.FORMAT_FILTER, new String[] { "gpx" });
5502 startActivityForResult(intent77, Navit.NavitGPXConvChooser_id);
5503 }
5504 catch (IOException e1)
5505 {
5506 e1.printStackTrace();
5507 }
5508 break;
5509 case 21:
5510 // add traffic block (like blocked road, or construction site) at current location of crosshair
5511 try
5512 {
5513 String traffic = "";
5514 if (Navit.GFX_OVERSPILL)
5515 {
5516 traffic = NavitGraphics.CallbackGeoCalc(7, (int) (NavitGraphics.Global_dpi_factor * (NavitGraphics.mCanvasWidth / 2 + NavitGraphics.mCanvasWidth_overspill)), (int) (NavitGraphics.Global_dpi_factor * (NavitGraphics.mCanvasHeight / 2 + NavitGraphics.mCanvasHeight_overspill)));
5517 }
5518 else
5519 {
5520 traffic = NavitGraphics.CallbackGeoCalc(7, (int) (NavitGraphics.Global_dpi_factor * NavitGraphics.mCanvasWidth / 2), (int) (NavitGraphics.Global_dpi_factor * NavitGraphics.mCanvasHeight / 2));
5521 }
5522
5523 // System.out.println("traffic=" + traffic);
5524 File traffic_file_dir = new File(MAP_FILENAME_PATH);
5525 traffic_file_dir.mkdirs();
5526 File traffic_file = new File(MAP_FILENAME_PATH + "/traffic.txt");
5527 FileOutputStream fOut = null;
5528 OutputStreamWriter osw = null;
5529 try
5530 {
5531 fOut = new FileOutputStream(traffic_file, true);
5532 osw = new OutputStreamWriter(fOut);
5533 osw.write("type=traffic_distortion maxspeed=0" + "\n"); // item header
5534 osw.write(traffic); // item coordinates
5535 osw.close();
5536 fOut.close();
5537 }
5538 catch (Exception ef)
5539 {
5540 ef.printStackTrace();
5541 }
5542
5543 // update route, if a route is set
5544 msg = new Message();
5545 b = new Bundle();
5546 b.putInt("Callback", 73);
5547 msg.setData(b);
5548 NavitGraphics.callback_handler.sendMessage(msg);
5549
5550 // draw map no-async
5551 msg = new Message();
5552 b = new Bundle();
5553 b.putInt("Callback", 64);
5554 msg.setData(b);
5555 NavitGraphics.callback_handler.sendMessage(msg);
5556 }
5557 catch (Exception e)
5558 {
5559 e.printStackTrace();
5560 }
5561 break;
5562 case 22:
5563 // clear all traffic blocks
5564 try
5565 {
5566 File traffic_file = new File(MAP_FILENAME_PATH + "/traffic.txt");
5567 traffic_file.delete();
5568
5569 // update route, if a route is set
5570 msg = new Message();
5571 b = new Bundle();
5572 b.putInt("Callback", 73);
5573 msg.setData(b);
5574 NavitGraphics.callback_handler.sendMessage(msg);
5575
5576 // draw map no-async
5577 msg = new Message();
5578 b = new Bundle();
5579 b.putInt("Callback", 64);
5580 msg.setData(b);
5581 NavitGraphics.callback_handler.sendMessage(msg);
5582 }
5583 catch (Exception e)
5584 {
5585 }
5586 break;
5587 case 23:
5588 // clear all GPX maps
5589 try
5590 {
5591 File gpx_file = new File(MAP_FILENAME_PATH + "/gpxtracks.txt");
5592 gpx_file.delete();
5593
5594 // draw map no-async
5595 msg = new Message();
5596 b = new Bundle();
5597 b.putInt("Callback", 64);
5598 msg.setData(b);
5599 NavitGraphics.callback_handler.sendMessage(msg);
5600 }
5601 catch (Exception e)
5602 {
5603 }
5604 break;
5605 case 24:
5606 // show feedback form
5607 Intent i4 = new Intent(this, NavitFeedbackFormActivity.class);
5608 this.startActivityForResult(i4, Navit.NavitSendFeedback_id);
5609 break;
5610 case 25:
5611 // share the current destination with your friends
5612 String current_target_string2 = NavitGraphics.CallbackGeoCalc(4, 1, 1);
5613 if (current_target_string2.equals("x:x"))
5614 {
5615 Log.e("Navit", "no target set!");
5616 }
5617 else
5618 {
5619 try
5620 {
5621 String tmp[] = current_target_string2.split(":", 2);
5622
5623 if (Navit.OSD_route_001.arriving_time_valid)
5624 {
5625 share_location(tmp[0], tmp[1], Navit.get_text("Meeting Point"), Navit.get_text("Meeting Point"), Navit.OSD_route_001.arriving_time, true);
5626 }
5627 else
5628 {
5629 share_location(tmp[0], tmp[1], Navit.get_text("Meeting Point"), Navit.get_text("Meeting Point"), "", true);
5630 }
5631 }
5632 catch (Exception e)
5633 {
5634 e.printStackTrace();
5635 Log.e("Navit", "problem with target!");
5636 }
5637 }
5638 break;
5639 case 26:
5640 // donate
5641 Log.e("Navit", "start donate app");
5642 donate();
5643 break;
5644 case 27:
5645 // donate
5646 Log.e("Navit", "donate bitcoins");
5647 donate_bitcoins();
5648 break;
5649 case 28:
5650 // replay GPS file
5651 Intent intent771 = new Intent(getBaseContext(), FileDialog.class);
5652 File a1 = new File(Navit.NAVIT_DATA_DEBUG_DIR);
5653 try
5654 {
5655 // convert the "/../" in the path to normal absolut dir
5656 intent771.putExtra(FileDialog.START_PATH, a1.getCanonicalPath());
5657 //can user select directories or not
5658 intent771.putExtra(FileDialog.CAN_SELECT_DIR, false);
5659 // disable the "new" button
5660 intent771.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
5661 //alternatively you can set file filter
5662 intent771.putExtra(FileDialog.FORMAT_FILTER, new String[] { "txt", "yaml" });
5663 startActivityForResult(intent771, Navit.NavitReplayFileConvChooser_id);
5664 }
5665 catch (IOException e1)
5666 {
5667 e1.printStackTrace();
5668 }
5669 break;
5670
5671 case 88:
5672 // dummy entry, just to make "breaks" in the menu
5673 break;
5674 case 601:
5675 // DEBUG: activate demo vehicle and set position to position to screen center
5676
5677 Navit.DemoVehicle = true;
5678
5679 msg = new Message();
5680 b = new Bundle();
5681 b.putInt("Callback", 101);
5682 msg.setData(b);
5683 NavitGraphics.callback_handler.sendMessage(msg);
5684
5685 final Thread demo_v_001 = new Thread()
5686 {
5687 @Override
5688 public void run()
5689 {
5690 try
5691 {
5692 Thread.sleep(1000); // wait 1 seconds before we start
5693
5694 try
5695 {
5696 float lat = 0;
5697 float lon = 0;
5698
5699 String lat_lon = "";
5700 if (Navit.GFX_OVERSPILL)
5701 {
5702 lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * (NG__map_main.view.getWidth() / 2 + NavitGraphics.mCanvasWidth_overspill), NavitGraphics.Global_dpi_factor * (NG__map_main.view.getHeight() / 2 + NavitGraphics.mCanvasHeight_overspill));
5703 }
5704 else
5705 {
5706 lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * NG__map_main.view.getWidth() / 2, NavitGraphics.Global_dpi_factor * NG__map_main.view.getHeight() / 2);
5707 }
5708 String tmp[] = lat_lon.split(":", 2);
5709 //System.out.println("tmp=" + lat_lon);
5710 lat = Float.parseFloat(tmp[0]);
5711 lon = Float.parseFloat(tmp[1]);
5712 //System.out.println("ret=" + lat_lon + " lat=" + lat + " lon=" + lon);
5713 Location l = null;
5714 l = new Location("ZANavi Demo 001");
5715 l.setLatitude(lat);
5716 l.setLongitude(lon);
5717 l.setBearing(0.0f);
5718 l.setSpeed(0);
5719 l.setAccuracy(4.0f); // accuracy 4 meters
5720 // NavitVehicle.update_compass_heading(0.0f);
5721 NavitVehicle.set_mock_location__fast(l);
5722 }
5723 catch (Exception e)
5724 {
5725 }
5726
5727 Message msg = new Message();
5728 Bundle b = new Bundle();
5729 b.putInt("Callback", 52);
5730 b.putString("s", "45"); // speed in km/h of Demo-Vehicle
5731 // b.putString("s", "20");
5732
5733 msg.setData(b);
5734 NavitGraphics.callback_handler.sendMessage(msg);
5735 }
5736 catch (Exception e)
5737 {
5738 }
5739 }
5740 };
5741 demo_v_001.start();
5742
5743 msg = new Message();
5744 b = new Bundle();
5745 b.putInt("Callback", 51);
5746
5747 if (Navit.GFX_OVERSPILL)
5748 {
5749 b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getWidth() / 2) + NavitGraphics.mCanvasWidth_overspill)));
5750 b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getHeight() / 2) + NavitGraphics.mCanvasHeight_overspill)));
5751 }
5752 else
5753 {
5754 b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getWidth() / 2));
5755 b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getHeight() / 2));
5756 }
5757 msg.setData(b);
5758 NavitGraphics.callback_handler.sendMessage(msg);
5759
5760 break;
5761 case 602:
5762 // DEBUG: toggle textview with spoken and translated string (to help with translation)
5763 try
5764 {
5765 if (NavitGraphics.NavitMsgTv2_.getVisibility() == View.VISIBLE)
5766 {
5767 NavitGraphics.NavitMsgTv2_.setVisibility(View.GONE);
5768 NavitGraphics.NavitMsgTv2_.setEnabled(false);
5769 NavitGraphics.NavitMsgTv2sc_.setVisibility(View.GONE);
5770 NavitGraphics.NavitMsgTv2sc_.setEnabled(false);
5771 }
5772 else
5773 {
5774 NavitGraphics.NavitMsgTv2sc_.setVisibility(View.VISIBLE);
5775 NavitGraphics.NavitMsgTv2sc_.setEnabled(true);
5776 NavitGraphics.NavitMsgTv2_.setVisibility(View.VISIBLE);
5777 NavitGraphics.NavitMsgTv2_.setEnabled(true);
5778 }
5779 }
5780 catch (Exception e)
5781 {
5782 e.printStackTrace();
5783 }
5784 break;
5785 case 603:
5786 // DEBUG: show all possible navigation commands (also translated)
5787 NavitGraphics.generate_all_speech_commands();
5788 break;
5789 case 604:
5790 // DEBUG: activate FAST driving demo vehicle and set position to screen center
5791
5792 Navit.DemoVehicle = true;
5793
5794 msg = new Message();
5795
5796 b = new Bundle();
5797 b.putInt("Callback", 52);
5798 b.putString("s", "800"); // speed in ~km/h of Demo-Vehicle
5799 msg.setData(b);
5800 NavitGraphics.callback_handler.sendMessage(msg);
5801
5802 msg = new Message();
5803 b = new Bundle();
5804 b.putInt("Callback", 51);
5805 if (Navit.GFX_OVERSPILL)
5806 {
5807 b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getWidth() / 2) + NavitGraphics.mCanvasWidth_overspill)));
5808 b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getHeight() / 2) + NavitGraphics.mCanvasHeight_overspill)));
5809 }
5810 else
5811 {
5812 b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getWidth() / 2));
5813 b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getHeight() / 2));
5814 }
5815 msg.setData(b);
5816 NavitGraphics.callback_handler.sendMessage(msg);
5817
5818 try
5819 {
5820 float lat = 0;
5821 float lon = 0;
5822
5823 lat = 0;
5824 lon = 0;
5825 String lat_lon = "";
5826 if (Navit.GFX_OVERSPILL)
5827 {
5828 lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * (NG__map_main.view.getWidth() / 2 + NavitGraphics.mCanvasWidth_overspill), NavitGraphics.Global_dpi_factor * (NG__map_main.view.getHeight() / 2 + NavitGraphics.mCanvasHeight_overspill));
5829 }
5830 else
5831 {
5832 lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * NG__map_main.view.getWidth() / 2, NavitGraphics.Global_dpi_factor * NG__map_main.view.getHeight() / 2);
5833 }
5834
5835 String tmp[] = lat_lon.split(":", 2);
5836 //System.out.println("tmp=" + lat_lon);
5837 lat = Float.parseFloat(tmp[0]);
5838 lon = Float.parseFloat(tmp[1]);
5839 //System.out.println("ret=" + lat_lon + " lat=" + lat + " lon=" + lon);
5840 Location l = null;
5841 l = new Location("ZANavi Demo 001");
5842 l.setLatitude(lat);
5843 l.setLongitude(lon);
5844 l.setBearing(0.0f);
5845 l.setSpeed(0);
5846 l.setAccuracy(4.0f); // accuracy 4 meters
5847 // NavitVehicle.update_compass_heading(0.0f);
5848 NavitVehicle.set_mock_location__fast(l);
5849 }
5850 catch (Exception e)
5851 {
5852 }
5853
5854 break;
5855 case 605:
5856 // DEBUG: toggle Routgraph on/off
5857 msg = new Message();
5858 b = new Bundle();
5859 b.putInt("Callback", 71);
5860 Navit.Routgraph_enabled = 1 - Navit.Routgraph_enabled;
5861 b.putString("s", "" + Navit.Routgraph_enabled);
5862 msg.setData(b);
5863 NavitGraphics.callback_handler.sendMessage(msg);
5864 break;
5865 case 606:
5866 // DEBUG: spill contents of index file(s)
5867 msg = new Message();
5868 b = new Bundle();
5869 b.putInt("Callback", 83);
5870 msg.setData(b);
5871 NavitGraphics.callback_handler.sendMessage(msg);
5872 break;
5873 case 607:
5874 export_map_points_to_sdcard();
5875 break;
5876 case 608:
5877 import_map_points_from_sdcard();
5878 break;
5879 case 99:
5880 try
5881 {
5882 if (wl_navigating != null)
5883 {
5884 //if (wl_navigating.isHeld())
5885 //{
5886 wl_navigating.release();
5887 Log.e("Navit", "WakeLock Nav: release 1");
5888 //}
5889 }
5890 }
5891 catch (Exception e)
5892 {
5893 e.printStackTrace();
5894 }
5895 // exit
5896 this.onPause();
5897 this.onStop();
5898 this.exit();
5899 //msg = new Message();
5900 //b = new Bundle();
5901 //b.putInt("Callback", 5);
5902 //b.putString("cmd", "quit();");
5903 //msg.setData(b);
5904 //N_NavitGraphics.callback_handler.sendMessage(msg);
5905 break;
5906 }
5907 return true;
5908 }
5909
5910 protected void onActivityResult(int requestCode, int resultCode, Intent data)
5911 {
5912 Log.e("Navit", "onActivityResult");
5913 switch (requestCode)
5914 {
5915 case Navit.NavitGPXConvChooser_id:
5916 try
5917 {
5918 Log.e("Navit", "onActivityResult 001");
5919 if (resultCode == ActionBarActivity.RESULT_OK)
5920 {
5921 String in_ = data.getStringExtra(FileDialog.RESULT_PATH);
5922 convert_gpx_file_real(in_);
5923 }
5924 }
5925 catch (Exception e77)
5926 {
5927 e77.printStackTrace();
5928 }
5929 break;
5930
5931 case NavitReplayFileConvChooser_id:
5932 try
5933 {
5934 if (resultCode == ActionBarActivity.RESULT_OK)
5935 {
5936 final String in_ = data.getStringExtra(FileDialog.RESULT_PATH);
5937 final Thread replay_gpx_file_001 = new Thread()
5938 {
5939 @Override
5940 public void run()
5941 {
5942 try
5943 {
5944 Thread.sleep(2000); // wait 2 seconds before we start
5945 ZANaviDebugReceiver.DR_replay_gps_file(in_);
5946 }
5947 catch (Exception e)
5948 {
5949 }
5950 }
5951 };
5952 replay_gpx_file_001.start();
5953 }
5954 }
5955 catch (Exception e77)
5956 {
5957 e77.printStackTrace();
5958 }
5959 break;
5960
5961 case Navit.NavitDeleteSecSelectMap_id:
5962 try
5963 {
5964 if (resultCode == ActionBarActivity.RESULT_OK)
5965 {
5966 System.out.println("Global_Location_update_not_allowed = 1");
5967 Navit.Global_Location_update_not_allowed = 1; // dont allow location updates now!
5968
5969 // remove all sdcard maps
5970 Message msg = new Message();
5971 Bundle b = new Bundle();
5972 b.putInt("Callback", 19);
5973 msg.setData(b);
5974 NavitGraphics.callback_handler.sendMessage(msg);
5975
5976 try
5977 {
5978 Thread.sleep(100);
5979 }
5980 catch (InterruptedException e)
5981 {
5982 }
5983
5984 Log.d("Navit", "delete map id=" + Integer.parseInt(data.getStringExtra("selected_id")));
5985 String map_full_line = NavitMapDownloader.OSM_MAP_NAME_ondisk_ORIG_LIST[Integer.parseInt(data.getStringExtra("selected_id"))];
5986 Log.d("Navit", "delete map full line=" + map_full_line);
5987
5988 String del_map_name = MAP_FILENAME_PATH + map_full_line.split(":", 2)[0];
5989 System.out.println("del map file :" + del_map_name);
5990 // remove from cat file
5991 NavitMapDownloader.remove_from_cat_file(map_full_line);
5992 // remove from disk
5993 File del_map_name_file = new File(del_map_name);
5994 del_map_name_file.delete();
5995 for (int jkl = 1; jkl < 51; jkl++)
5996 {
5997 File del_map_name_fileSplit = new File(del_map_name + "." + String.valueOf(jkl));
5998 del_map_name_fileSplit.delete();
5999 }
6000 // also remove index file
6001 File del_map_name_file_idx = new File(del_map_name + ".idx");
6002 del_map_name_file_idx.delete();
6003 // remove also any MD5 files for this map that may be on disk
6004 try
6005 {
6006 String tmp = map_full_line.split(":", 2)[1];
6007 if (!tmp.equals(NavitMapDownloader.MAP_URL_NAME_UNKNOWN))
6008 {
6009 tmp = tmp.replace("*", "");
6010 tmp = tmp.replace("/", "");
6011 tmp = tmp.replace("\\", "");
6012 tmp = tmp.replace(" ", "");
6013 tmp = tmp.replace(">", "");
6014 tmp = tmp.replace("<", "");
6015 System.out.println("removing md5 file:" + Navit.MAPMD5_FILENAME_PATH + tmp + ".md5");
6016 File md5_final_filename = new File(Navit.MAPMD5_FILENAME_PATH + tmp + ".md5");
6017 md5_final_filename.delete();
6018 }
6019 }
6020 catch (Exception e)
6021 {
6022 e.printStackTrace();
6023 }
6024
6025 // remove map, and zoom out
6026 // ***** onStop();
6027 // ***** onCreate(getIntent().getExtras());
6028
6029 try
6030 {
6031 Thread.sleep(100);
6032 }
6033 catch (InterruptedException e)
6034 {
6035 }
6036
6037 // add all sdcard maps
6038 msg = new Message();
6039 b = new Bundle();
6040 b.putInt("Callback", 20);
6041 msg.setData(b);
6042 NavitGraphics.callback_handler.sendMessage(msg);
6043
6044 final Thread zoom_to_route_004 = new Thread()
6045 {
6046 int wait = 1;
6047 int count = 0;
6048 int max_count = 60;
6049
6050 @Override
6051 public void run()
6052 {
6053 while (wait == 1)
6054 {
6055 try
6056 {
6057 if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33))
6058 {
6059 zoom_to_route();
6060 wait = 0;
6061 }
6062 else
6063 {
6064 wait = 1;
6065 }
6066
6067 count++;
6068 if (count > max_count)
6069 {
6070 wait = 0;
6071 }
6072 else
6073 {
6074 Thread.sleep(400);
6075 }
6076 }
6077 catch (Exception e)
6078 {
6079 }
6080 }
6081 }
6082 };
6083 zoom_to_route_004.start();
6084
6085 System.out.println("Global_Location_update_not_allowed = 0");
6086 Navit.Global_Location_update_not_allowed = 0; // DO allow location updates now!
6087 }
6088 }
6089 catch (Exception e)
6090 {
6091 Log.d("Navit", "error on onActivityResult 3");
6092 e.printStackTrace();
6093 }
6094 break;
6095 case Navit.NavitDownloaderPriSelectMap_id:
6096 try
6097 {
6098 if (resultCode == ActionBarActivity.RESULT_OK)
6099 {
6100 try
6101 {
6102 // Log.d("Navit", "PRI id=" + Integer.parseInt(data.getStringExtra("selected_id")));
6103 // set map id to download
6104 Navit.download_map_id = NavitMapDownloader.OSM_MAP_NAME_ORIG_ID_LIST[Integer.parseInt(data.getStringExtra("selected_id"))];
6105 // show the map download progressbar, and download the map
6106 if (Navit.download_map_id > -1)
6107 {
6108 // --------- start a map download (highest level) ---------
6109 // --------- start a map download (highest level) ---------
6110 // --------- start a map download (highest level) ---------
6111 // showDialog(Navit.MAPDOWNLOAD_PRI_DIALOG); // old method in app
6112
6113 // new method in service
6114 Message msg = progress_handler.obtainMessage();
6115 // Bundle b = new Bundle();
6116 msg.what = 22;
6117 progress_handler.sendMessage(msg);
6118
6119 // show license for OSM maps
6120 //. TRANSLATORS: please only translate the first word "Map data" and leave the other words in english
6121 Toast.makeText(getApplicationContext(), Navit.get_text("Map data (c) OpenStreetMap contributors, CC-BY-SA"), Toast.LENGTH_SHORT).show(); //TRANS
6122 // --------- start a map download (highest level) ---------
6123 // --------- start a map download (highest level) ---------
6124 // --------- start a map download (highest level) ---------
6125 }
6126 }
6127 catch (NumberFormatException e)
6128 {
6129 Log.d("Navit", "NumberFormatException selected_id");
6130 }
6131 }
6132 else
6133 {
6134 // user pressed back key
6135 }
6136 }
6137 catch (Exception e)
6138 {
6139 Log.d("Navit", "error on onActivityResult");
6140 e.printStackTrace();
6141 }
6142 break;
6143 case Navit.NavitDownloaderSecSelectMap_id: // unused!!! unused!!! unused!!! unused!!! unused!!!
6144 break;
6145 case ZANaviVoiceInput_id:
6146 if (resultCode == ActionBarActivity.RESULT_OK)
6147 {
6148 try
6149 {
6150 String addr = data.getStringExtra("address_string");
6151 double lat = data.getDoubleExtra("lat", 0);
6152 double lon = data.getDoubleExtra("lon", 0);
6153 String hn = "";
6154
6155 // save last address entry string
6156 p.PREF_StreetSearchStrings = pushToArray(p.PREF_StreetSearchStrings, addr, STREET_SEARCH_STRINGS_SAVE_COUNT);
6157 saveArray(p.PREF_StreetSearchStrings, "xxStrtSrhStrxx", STREET_SEARCH_STRINGS_SAVE_COUNT);
6158
6159 Boolean partial_match = true;
6160 Navit.use_index_search = false;
6161
6162 Navit_last_address_partial_match = partial_match;
6163 Navit_last_address_search_string = addr;
6164 Navit_last_address_hn_string = hn;
6165
6166 Navit_last_address_full_file_search = false;
6167
6168 // clear results
6169 Navit.NavitAddressResultList_foundItems.clear();
6170 Navit.Navit_Address_Result_double_index.clear();
6171 Navit.NavitSearchresultBarIndex = -1;
6172 Navit.NavitSearchresultBar_title = "";
6173 Navit.NavitSearchresultBar_text = "";
6174 Navit.search_results_towns = 0;
6175 Navit.search_results_streets = 0;
6176 Navit.search_results_streets_hn = 0;
6177 Navit.search_results_poi = 0;
6178
6179 if (addr.equals(""))
6180 {
6181 // empty search string entered
6182 Toast.makeText(getApplicationContext(), Navit.get_text("No search string"), Toast.LENGTH_LONG).show(); //TRANS
6183 }
6184 else
6185 {
6186 System.out.println("Global_Location_update_not_allowed = 1");
6187 Navit.Global_Location_update_not_allowed = 1; // dont allow location updates now!
6188
6189 // --> this still does the search // google_online_search_and_set_destination(addr);
6190 result_set_destination(lat, lon, addr);
6191
6192 System.out.println("Global_Location_update_not_allowed = 0");
6193 Navit.Global_Location_update_not_allowed = 0; // DO allow location updates now!
6194 }
6195
6196 }
6197 catch (Exception e)
6198 {
6199
6200 }
6201 }
6202 break;
6203 case NavitAddressSearch_id_online:
6204 case NavitAddressSearch_id_offline:
6205 Log.e("Navit", "NavitAddressSearch_id_:001");
6206 try
6207 {
6208 if (resultCode == ActionBarActivity.RESULT_OK)
6209 {
6210 try
6211 {
6212 String addr = data.getStringExtra("address_string");
6213 String hn = "";
6214 try
6215 {
6216 // only from offline mask!
6217 hn = data.getStringExtra("hn_string");
6218 }
6219 catch (Exception e)
6220 {
6221 hn = "";
6222 }
6223
6224 // save last address entry string
6225 p.PREF_StreetSearchStrings = pushToArray(p.PREF_StreetSearchStrings, addr, STREET_SEARCH_STRINGS_SAVE_COUNT);
6226 saveArray(p.PREF_StreetSearchStrings, "xxStrtSrhStrxx", STREET_SEARCH_STRINGS_SAVE_COUNT);
6227
6228 Boolean partial_match = false;
6229 try
6230 {
6231 // only from offline mask!
6232 partial_match = data.getStringExtra("partial_match").equals("1");
6233 }
6234 catch (Exception e)
6235 {
6236 }
6237
6238 Message msg2 = new Message();
6239 Bundle b2 = new Bundle();
6240 b2.putInt("Callback", 44);
6241 msg2.setData(b2);
6242 NavitGraphics.callback_handler.sendMessage(msg2);
6243
6244 if (requestCode == NavitAddressSearch_id_offline)
6245 {
6246 search_hide_duplicates = false;
6247 try
6248 {
6249 Boolean hide_dup = data.getStringExtra("hide_dup").equals("1");
6250 if (hide_dup)
6251 {
6252 search_hide_duplicates = true;
6253 Message msg = new Message();
6254 Bundle b = new Bundle();
6255 b.putInt("Callback", 45);
6256 msg.setData(b);
6257 NavitGraphics.callback_handler.sendMessage(msg);
6258 }
6259 }
6260 catch (Exception e)
6261 {
6262 }
6263 Navit.use_index_search = Navit.allow_use_index_search();
6264 }
6265 else
6266 {
6267 Navit.use_index_search = false;
6268 }
6269
6270 Navit_last_address_partial_match = partial_match;
6271 Navit_last_address_search_string = addr;
6272 Navit_last_address_hn_string = hn;
6273
6274 try
6275 {
6276 // only from offline mask!
6277 Navit_last_address_full_file_search = data.getStringExtra("full_file_search").equals("1");
6278 }
6279 catch (Exception e)
6280 {
6281 Navit_last_address_full_file_search = false;
6282 }
6283
6284 try
6285 {
6286 // only from offline mask!
6287 Navit_last_address_search_country_iso2_string = data.getStringExtra("address_country_iso2");
6288
6289 Navit_last_address_search_country_flags = data.getIntExtra("address_country_flags", 3);
6290 // System.out.println("Navit_last_address_search_country_flags=" + Navit_last_address_search_country_flags);
6291 Navit_last_address_search_country_id = data.getIntExtra("search_country_id", 1); // default=*ALL*
6292 p.PREF_search_country = Navit_last_address_search_country_id;
6293 setPrefs_search_country();
6294 }
6295 catch (Exception e)
6296 {
6297
6298 }
6299
6300 // clear results
6301 Navit.NavitAddressResultList_foundItems.clear();
6302 Navit.Navit_Address_Result_double_index.clear();
6303 Navit.NavitSearchresultBarIndex = -1;
6304 Navit.NavitSearchresultBar_title = "";
6305 Navit.NavitSearchresultBar_text = "";
6306 Navit.search_results_towns = 0;
6307 Navit.search_results_streets = 0;
6308 Navit.search_results_streets_hn = 0;
6309 Navit.search_results_poi = 0;
6310
6311 if (addr.equals(""))
6312 {
6313 // empty search string entered
6314 Toast.makeText(getApplicationContext(), Navit.get_text("No search string entered"), Toast.LENGTH_LONG).show(); //TRANS
6315 }
6316 else
6317 {
6318 System.out.println("Global_Location_update_not_allowed = 1");
6319 Navit.Global_Location_update_not_allowed = 1; // dont allow location updates now!
6320
6321 if (requestCode == NavitAddressSearch_id_online)
6322 {
6323 // online googlemaps search
6324 try
6325 {
6326 Log.e("Navit", "call-11: (1)num " + Navit.SEARCHRESULTS_WAIT_DIALOG);
6327 }
6328 catch (Exception e)
6329 {
6330 e.printStackTrace();
6331 }
6332
6333 System.out.println("online googlemaps search");
6334 Message msg = progress_handler.obtainMessage();
6335 Bundle b = new Bundle();
6336 msg.what = 11;
6337 b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG);
6338 msg.setData(b);
6339 progress_handler.sendMessage(msg);
6340 }
6341 else if (requestCode == NavitAddressSearch_id_offline)
6342 {
6343 // offline binfile search
6344 try
6345 {
6346 Log.e("Navit", "call-11: (2)num " + Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
6347 }
6348 catch (Exception e)
6349 {
6350 e.printStackTrace();
6351 }
6352
6353 // show dialog, and start search for the results
6354 // make it indirect, to give our activity a chance to startup
6355 // (remember we come straight from another activity and ours is still paused!)
6356 Message msg = progress_handler.obtainMessage();
6357 Bundle b = new Bundle();
6358 msg.what = 11;
6359 b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
6360 msg.setData(b);
6361 progress_handler.sendMessage(msg);
6362 }
6363 }
6364 }
6365 catch (NumberFormatException e)
6366 {
6367 Log.d("Navit", "NumberFormatException selected_id");
6368 }
6369 }
6370 else
6371 {
6372 // user pressed back key
6373 Log.e("Navit", "NavitAddressSearch_id_:900");
6374 }
6375 }
6376 catch (Exception e)
6377 {
6378 Log.d("Navit", "error on onActivityResult");
6379 e.printStackTrace();
6380 }
6381 Log.e("Navit", "NavitAddressSearch_id_:999");
6382 break;
6383 case Navit.NavitAddressResultList_id:
6384 try
6385 {
6386 if (resultCode == ActionBarActivity.RESULT_OK)
6387 {
6388 try
6389 {
6390 if (data.getStringExtra("what").equals("view"))
6391 {
6392 // get the coords for the destination
6393 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
6394
6395 // save last address entry string
6396 String addr = data.getStringExtra("address_string");
6397 p.PREF_StreetSearchStrings = pushToArray(p.PREF_StreetSearchStrings, addr, STREET_SEARCH_STRINGS_SAVE_COUNT);
6398 saveArray(p.PREF_StreetSearchStrings, "xxStrtSrhStrxx", STREET_SEARCH_STRINGS_SAVE_COUNT);
6399
6400 try
6401 {
6402 Navit.follow_button_off();
6403 }
6404 catch (Exception e2)
6405 {
6406 e2.printStackTrace();
6407 }
6408
6409 System.out.println("XSOM:009");
6410
6411 if (Navit.use_index_search)
6412 {
6413 show_geo_on_screen_with_zoom_and_delay((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));
6414 }
6415 else
6416 {
6417 show_geo_on_screen_with_zoom_and_delay(Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
6418 }
6419 }
6420 else if (data.getStringExtra("what").equals("set"))
6421 {
6422 Log.d("Navit", "adress result list id=" + Integer.parseInt(data.getStringExtra("selected_id")));
6423
6424 // save last address entry string
6425 String addr = data.getStringExtra("address_string");
6426 p.PREF_StreetSearchStrings = pushToArray(p.PREF_StreetSearchStrings, addr, STREET_SEARCH_STRINGS_SAVE_COUNT);
6427 saveArray(p.PREF_StreetSearchStrings, "xxStrtSrhStrxx", STREET_SEARCH_STRINGS_SAVE_COUNT);
6428
6429 // get the coords for the destination
6430 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
6431
6432 String _addr = "";
6433 double _lat = 0;
6434 double _lon = 0;
6435
6436 // (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)
6437 // (float) Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(destination_id).lat)
6438
6439 // ok now set target
6440 try
6441 {
6442 if (Navit.use_index_search)
6443 {
6444 _addr = Navit.NavitAddressResultList_foundItems.get(destination_id).addr;
6445 _lat = Navit.transform_to_geo_lat(Navit.NavitAddressResultList_foundItems.get(destination_id).lat);
6446 _lon = Navit.transform_to_geo_lon(Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
6447 //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));
6448 }
6449 else
6450 {
6451 _addr = Navit.NavitAddressResultList_foundItems.get(destination_id).addr;
6452 _lat = Navit.NavitAddressResultList_foundItems.get(destination_id).lat;
6453 _lon = Navit.NavitAddressResultList_foundItems.get(destination_id).lon;
6454 //Navit.remember_destination(Navit.NavitAddressResultList_foundItems.get(destination_id).addr, Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
6455 }
6456 // save points
6457 //write_map_points();
6458 }
6459 catch (Exception e)
6460 {
6461 e.printStackTrace();
6462 }
6463
6464 route_wrapper(_addr, 0, 0, false, _lat, _lon, true);
6465
6466 final Thread zoom_to_route_005 = new Thread()
6467 {
6468 int wait = 1;
6469 int count = 0;
6470 int max_count = 60;
6471
6472 @Override
6473 public void run()
6474 {
6475 while (wait == 1)
6476 {
6477 try
6478 {
6479 if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33))
6480 {
6481 zoom_to_route();
6482 wait = 0;
6483 }
6484 else
6485 {
6486 wait = 1;
6487 }
6488
6489 count++;
6490 if (count > max_count)
6491 {
6492 wait = 0;
6493 }
6494 else
6495 {
6496 Thread.sleep(400);
6497 }
6498 }
6499 catch (Exception e)
6500 {
6501 }
6502 }
6503 }
6504 };
6505 zoom_to_route_005.start();
6506 // zoom_to_route();
6507
6508 // ---------- DEBUG: write route to file ----------
6509 // ---------- DEBUG: write route to file ----------
6510 // ---------- DEBUG: write route to file ----------
6511 if (p.PREF_enable_debug_write_gpx)
6512 {
6513 write_route_to_gpx_file();
6514 }
6515 // ---------- DEBUG: write route to file ----------
6516 // ---------- DEBUG: write route to file ----------
6517
6518 try
6519 {
6520 Navit.follow_button_on();
6521 }
6522 catch (Exception e2)
6523 {
6524 e2.printStackTrace();
6525 }
6526
6527 // if (Navit.use_index_search)
6528 // {
6529 // 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));
6530 // }
6531 // else
6532 // {
6533 // show_geo_on_screen(Navit.NavitAddressResultList_foundItems.get(destination_id).lat, Navit.NavitAddressResultList_foundItems.get(destination_id).lon);
6534 // }
6535 }
6536 else
6537 {
6538 // -- nothing --
6539 }
6540 }
6541 catch (NumberFormatException e)
6542 {
6543 Log.d("Navit", "NumberFormatException selected_id");
6544 }
6545 catch (Exception e)
6546 {
6547
6548 }
6549 }
6550 else
6551 {
6552 // user pressed back key
6553 }
6554 }
6555 catch (Exception e)
6556 {
6557 Log.d("Navit", "error on onActivityResult");
6558 e.printStackTrace();
6559 }
6560 break;
6561 case NavitAddressSearch_id_gmaps:
6562 try
6563 {
6564 if (resultCode == ActionBarActivity.RESULT_OK)
6565 {
6566
6567 }
6568 }
6569 catch (Exception e)
6570 {
6571 e.printStackTrace();
6572 }
6573 break;
6574 case NavitAddressSearch_id_sharedest:
6575 try
6576 {
6577 if (resultCode == ActionBarActivity.RESULT_OK)
6578 {
6579
6580 }
6581 Log.d("Navit", "sharedest: finished");
6582 }
6583 catch (Exception e)
6584 {
6585 e.printStackTrace();
6586 }
6587 break;
6588 case NavitGeoCoordEnter_id:
6589 try
6590 {
6591 if (resultCode == ActionBarActivity.RESULT_OK)
6592 {
6593 // lat lon enter activitiy result
6594
6595 try
6596 {
6597 if (data.getStringExtra("what").equals("view"))
6598 {
6599 // get the coords for the destination
6600 float lat = Float.parseFloat(data.getStringExtra("lat"));
6601 float lon = Float.parseFloat(data.getStringExtra("lon"));
6602
6603 // Log.d("Navit", "coord picker: " + lat);
6604 // Log.d("Navit", "coord picker: " + lon);
6605
6606 // set nice zoomlevel before we show destination
6607 // int zoom_want = Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL;
6608 // //
6609 // Message msg = new Message();
6610 // Bundle b = new Bundle();
6611 // b.putInt("Callback", 33);
6612 // b.putString("s", Integer.toString(zoom_want));
6613 // msg.setData(b);
6614 // try
6615 // {
6616 // N_NavitGraphics.callback_handler.sendMessage(msg);
6617 // Navit.GlobalScaleLevel = zoom_want;
6618 // }
6619 // catch (Exception e)
6620 // {
6621 // e.printStackTrace();
6622 // }
6623 // if (PREF_save_zoomlevel)
6624 // {
6625 // setPrefs_zoomlevel();
6626 // }
6627 // set nice zoomlevel before we show destination
6628
6629 try
6630 {
6631 Navit.follow_button_off();
6632 }
6633 catch (Exception e2)
6634 {
6635 e2.printStackTrace();
6636 }
6637
6638 show_geo_on_screen(lat, lon);
6639 }
6640 else
6641 {
6642 // get the coords for the destination
6643 float lat = Float.parseFloat(data.getStringExtra("lat"));
6644 float lon = Float.parseFloat(data.getStringExtra("lat"));
6645 String dest_name = "manual coordinates";
6646
6647 // ok now set target
6648 try
6649 {
6650 dest_name = NavitGraphics.CallbackGeoCalc(8, lat, lon);
6651 if ((dest_name.equals(" ")) || (dest_name == null))
6652 {
6653 dest_name = "manual coordinates";
6654 }
6655 // Navit.remember_destination(dest_name, lat, lon);
6656 // // save points
6657 // write_map_points();
6658 }
6659 catch (Exception e)
6660 {
6661 e.printStackTrace();
6662 }
6663
6664 // // DEBUG: clear route rectangle list
6665 // NavitGraphics.route_rects.clear();
6666 //
6667 // if (NavitGraphics.navit_route_status == 0)
6668 // {
6669 // Navit.destination_set();
6670 //
6671 // Message msg = new Message();
6672 // Bundle b = new Bundle();
6673 // b.putInt("Callback", 3);
6674 // b.putString("lat", String.valueOf(lat));
6675 // b.putString("lon", String.valueOf(lon));
6676 // b.putString("q", dest_name);
6677 // msg.setData(b);
6678 // NavitGraphics.callback_handler.sendMessage(msg);
6679 // }
6680 // else
6681 // {
6682 // Message msg = new Message();
6683 // Bundle b = new Bundle();
6684 // b.putInt("Callback", 48);
6685 // b.putString("lat", String.valueOf(lat));
6686 // b.putString("lon", String.valueOf(lon));
6687 // b.putString("q", dest_name);
6688 // msg.setData(b);
6689 // NavitGraphics.callback_handler.sendMessage(msg);
6690 // }
6691 //
6692
6693 route_wrapper(dest_name, 0, 0, false, lat, lon, true);
6694
6695 final Thread zoom_to_route_006 = new Thread()
6696 {
6697 int wait = 1;
6698 int count = 0;
6699 int max_count = 60;
6700
6701 @Override
6702 public void run()
6703 {
6704 while (wait == 1)
6705 {
6706 try
6707 {
6708 if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33))
6709 {
6710 zoom_to_route();
6711 wait = 0;
6712 }
6713 else
6714 {
6715 wait = 1;
6716 }
6717
6718 count++;
6719 if (count > max_count)
6720 {
6721 wait = 0;
6722 }
6723 else
6724 {
6725 Thread.sleep(400);
6726 }
6727 }
6728 catch (Exception e)
6729 {
6730 }
6731 }
6732 }
6733 };
6734 zoom_to_route_006.start();
6735 // zoom_to_route();
6736
6737 // ---------- DEBUG: write route to file ----------
6738 // ---------- DEBUG: write route to file ----------
6739 // ---------- DEBUG: write route to file ----------
6740 if (p.PREF_enable_debug_write_gpx)
6741 {
6742 write_route_to_gpx_file();
6743 }
6744 // ---------- DEBUG: write route to file ----------
6745 // ---------- DEBUG: write route to file ----------
6746
6747 try
6748 {
6749 Navit.follow_button_on();
6750 }
6751 catch (Exception e2)
6752 {
6753 e2.printStackTrace();
6754 }
6755
6756 // show_geo_on_screen(lat, lon);
6757 }
6758 }
6759 catch (NumberFormatException e)
6760 {
6761 Log.d("Navit", "NumberFormatException selected_id");
6762 }
6763 catch (Exception e)
6764 {
6765
6766 }
6767 }
6768 }
6769 catch (Exception e)
6770 {
6771 e.printStackTrace();
6772 }
6773 break;
6774 case NavitRecentDest_id:
6775 try
6776 {
6777 if (resultCode == ActionBarActivity.RESULT_OK)
6778 {
6779 Log.d("Navit", "recent dest id=" + Integer.parseInt(data.getStringExtra("selected_id")));
6780 // get the coords for the destination
6781 int destination_id = Integer.parseInt(data.getStringExtra("selected_id"));
6782
6783 if (data.getStringExtra("what").equals("view"))
6784 {
6785 try
6786 {
6787 Navit.follow_button_off();
6788 }
6789 catch (Exception e2)
6790 {
6791 e2.printStackTrace();
6792 }
6793
6794 float lat = Navit.map_points.get(destination_id).lat;
6795 float lon = Navit.map_points.get(destination_id).lon;
6796 show_geo_on_screen_with_zoom_and_delay(lat, lon, 150);
6797 }
6798 else
6799 {
6800 // ok now set target
6801 String dest_name = Navit.map_points.get(destination_id).point_name;
6802 float lat = Navit.map_points.get(destination_id).lat;
6803 float lon = Navit.map_points.get(destination_id).lon;
6804
6805 // System.out.println("XXXXXX:" + lat + " " + lon);
6806
6807 route_wrapper(dest_name, 0, 0, false, lat, lon, true);
6808
6809 final Thread zoom_to_route_007 = new Thread()
6810 {
6811 int wait = 1;
6812 int count = 0;
6813 int max_count = 60;
6814
6815 @Override
6816 public void run()
6817 {
6818 while (wait == 1)
6819 {
6820 try
6821 {
6822 if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33))
6823 {
6824 zoom_to_route();
6825 wait = 0;
6826 }
6827 else
6828 {
6829 wait = 1;
6830 }
6831
6832 count++;
6833 if (count > max_count)
6834 {
6835 wait = 0;
6836 }
6837 else
6838 {
6839 Thread.sleep(400);
6840 }
6841 }
6842 catch (Exception e)
6843 {
6844 }
6845 }
6846 }
6847 };
6848 zoom_to_route_007.start();
6849
6850 // ---------- DEBUG: write route to file ----------
6851 // ---------- DEBUG: write route to file ----------
6852 // ---------- DEBUG: write route to file ----------
6853 if (p.PREF_enable_debug_write_gpx)
6854 {
6855 write_route_to_gpx_file();
6856 }
6857 // ---------- DEBUG: write route to file ----------
6858 // ---------- DEBUG: write route to file ----------
6859
6860 try
6861 {
6862 Navit.follow_button_on();
6863 }
6864 catch (Exception e2)
6865 {
6866 e2.printStackTrace();
6867 }
6868
6869 }
6870 }
6871 }
6872 catch (Exception e)
6873 {
6874 e.printStackTrace();
6875 }
6876 break;
6877
6878 case NavitSendFeedback_id:
6879 try
6880 {
6881 if (resultCode == ActionBarActivity.RESULT_OK)
6882 {
6883 String feedback_text = data.getStringExtra("feedback_text");
6884
6885 String subject_d_version = "";
6886 if (Navit_DonateVersion_Installed)
6887 {
6888 subject_d_version = subject_d_version + "D,";
6889 }
6890
6891 if (Navit_Largemap_DonateVersion_Installed)
6892 {
6893 subject_d_version = subject_d_version + "L,";
6894 }
6895
6896 try
6897 {
6898 int rl = get_reglevel();
6899
6900 if (rl > 0)
6901 {
6902 subject_d_version = "U" + rl + ",";
6903 }
6904 }
6905 catch (Exception e)
6906 {
6907 e.printStackTrace();
6908 }
6909
6910 String FD_addon = "";
6911 if (FDBL)
6912 {
6913 FD_addon = ",FD";
6914 }
6915
6916 sendEmail("feedback@zanavi.cc", "ZANavi Feedback (v:" + subject_d_version + FD_addon + NavitAppVersion + " a:" + android.os.Build.VERSION.SDK + ")", feedback_text);
6917 }
6918 }
6919 catch (Exception e)
6920 {
6921 e.printStackTrace();
6922 Toast.makeText(getApplicationContext(), Navit.get_text("there was a problem with sending feedback"), Toast.LENGTH_SHORT).show(); //TRANS
6923 }
6924 break;
6925
6926 default:
6927 Log.e("Navit", "onActivityResult " + requestCode + " " + resultCode);
6928 try
6929 {
6930 // ---------- what is this doing ????? ----------
6931 // ---------- what is this doing ????? ----------
6932 // ---------- what is this doing ????? ----------
6933 // ---------- what is this doing ????? ----------
6934 // ---------- what is this doing ????? ----------
6935 // ---------- what is this doing ????? ----------
6936 // ---------- what is this doing ????? ----------
6937 // ---------- what is this doing ????? ----------
6938 // ---------- what is this doing ????? ----------
6939 // ---------- what is this doing ????? ----------
6940 // ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data);
6941 // ---------- what is this doing ????? ----------
6942 // ---------- what is this doing ????? ----------
6943 // ---------- what is this doing ????? ----------
6944 // ---------- what is this doing ????? ----------
6945 // ---------- what is this doing ????? ----------
6946 // ---------- what is this doing ????? ----------
6947 // ---------- what is this doing ????? ----------
6948 // ---------- what is this doing ????? ----------
6949 }
6950 catch (Exception e)
6951 {
6952 e.printStackTrace();
6953 }
6954 break;
6955 }
6956 Log.e("Navit", "onActivityResult finished");
6957 }
6958
6959 public class SCCB_object
6960 {
6961 int w;
6962 int h;
6963 Bitmap mb;
6964 }
6965
6966 public class CMC_object
6967 {
6968 int i;
6969 String s;
6970 }
6971
6972 public class MCB_object
6973 {
6974 int x1;
6975 int y1;
6976 int x2;
6977
6978 int y2;
6979 }
6980
6981 public class TCB_object
6982 {
6983 int del;
6984 int id;
6985 NavitTimeout nt;
6986 }
6987
6988 public class GeCB_Object
6989 {
6990 int type;
6991 int a;
6992 float b;
6993 float c;
6994 }
6995
6996 public class CWorkerThread extends Thread
6997 {
6998 private Boolean running;
6999 Boolean startmain = false;
7000 private CMC_object l2;
7001 private Integer l3;
7002 private MCB_object l4;
7003 private TCB_object l5;
7004 private SCCB_object l6;
7005 private Location l7;
7006 private GeCB_Object l8;
7007
7008 Navit x;
7009 String lang;
7010 int version;
7011 String display_density_string;
7012 int timeout_loop_counter = 0;
7013 String n_datadir;
7014 String n_sharedir;
7015
7016 private final LinkedBlockingQueue<CMC_object> queue = new LinkedBlockingQueue<CMC_object>();
7017 private final LinkedBlockingQueue<Integer> queue2 = new LinkedBlockingQueue<Integer>();
7018 private final LinkedBlockingQueue<MCB_object> queue3 = new LinkedBlockingQueue<MCB_object>();
7019 private final LinkedBlockingQueue<TCB_object> queue4 = new LinkedBlockingQueue<TCB_object>();
7020 private final LinkedBlockingQueue<SCCB_object> queue5 = new LinkedBlockingQueue<SCCB_object>();
7021 private final LinkedBlockingQueue<Location> queue6 = new LinkedBlockingQueue<Location>();
7022 private final LinkedBlockingQueue<GeCB_Object> queue7 = new LinkedBlockingQueue<GeCB_Object>();
7023
7024 CWorkerThread()
7025 {
7026 this.running = true;
7027 }
7028
7029 public void SizeChangedCallback(int w, int h, Bitmap main_map_bitmap)
7030 {
7031 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
7032
7033 SCCB_object sccbo = new SCCB_object();
7034 sccbo.w = w;
7035 sccbo.h = h;
7036 sccbo.mb = main_map_bitmap;
7037 queue5.offer(sccbo);
7038 this.interrupt();
7039
7040 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
7041 }
7042
7043 public void TimeoutCallback2(NavitTimeout nt, int del, int id)
7044 {
7045 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
7046
7047 TCB_object tcbo = new TCB_object();
7048 tcbo.del = del;
7049 tcbo.id = id;
7050 tcbo.nt = nt;
7051 queue4.offer(tcbo);
7052 this.interrupt();
7053 //timeout_loop_counter++;
7054
7055 //if (timeout_loop_counter > 100)
7056 //{
7057 // timeout_loop_counter = 0;
7058 // // run GC at every 100th loop
7059 // // System.gc();
7060 //}
7061 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
7062 }
7063
7064 public void CallbackMessageChannel(int i, String s)
7065 {
7066 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0, "id=" + i);
7067 CMC_object cmco = new CMC_object();
7068 cmco.i = i;
7069 cmco.s = s;
7070 queue.offer(cmco);
7071 this.interrupt();
7072 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
7073 }
7074
7075 public void MotionCallback(int x1, int y1, int x2, int y2)
7076 {
7077 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
7078
7079 //System.out.println("MotionCallback:enter queue=" + queue3.size());
7080 MCB_object mcbo = new MCB_object();
7081 mcbo.x1 = x1;
7082 mcbo.y1 = y1;
7083 mcbo.x2 = x2;
7084 mcbo.y2 = y2;
7085 queue3.offer(mcbo);
7086 this.interrupt();
7087 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
7088 }
7089
7090 public void NavitActivity2(int i)
7091 {
7092 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
7093
7094 queue2.offer(Integer.valueOf(i));
7095 this.interrupt();
7096 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
7097 }
7098
7099 public void CallbackGeoCalc2(int type, int a, float b, float c)
7100 {
7101 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
7102
7103 GeCB_Object gcco = new GeCB_Object();
7104 gcco.type = type;
7105 gcco.a = a;
7106 gcco.b = b;
7107 gcco.c = c;
7108 queue7.offer(gcco);
7109 this.interrupt();
7110
7111 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
7112 }
7113
7114 public void StartMain(Navit x, String lang, int version, String display_density_string, String n_datadir, String n_sharedir)
7115 {
7116 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
7117
7118 //System.out.println("CWorkerThread:StartMain:JTHREAD ID=" + this.getId());
7119 //System.out.println("CWorkerThread:StartMain:THREAD ID=" + NavitGraphics.GetThreadId());
7120
7121 this.startmain = true;
7122 this.x = x;
7123 this.lang = lang;
7124 this.version = version;
7125 this.n_datadir = n_datadir;
7126 this.n_sharedir = n_sharedir;
7127 this.display_density_string = display_density_string;
7128 this.interrupt();
7129
7130 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
7131 }
7132
7133 public void VehicleCallback3(Location location)
7134 {
7135 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
7136
7137 boolean your_are_speeding_old = Navit.your_are_speeding;
7138
7139 if ((Navit.cur_max_speed != -1) && (Navit.isGPSFix))
7140 {
7141 if ((location.getSpeed() * 3.6f) > ((float) Navit.cur_max_speed * (((float) p.PREF_roadspeed_warning_margin + 100.0f) / 100.0f)))
7142 {
7143 Navit.your_are_speeding = true;
7144
7145 try
7146 {
7147
7148 if (!toneG_heared)
7149 {
7150 // make "beep" sound to indicate we are going to fast!!
7151 if (toneG != null)
7152 {
7153 if (p.PREF_roadspeed_warning)
7154 {
7155 toneG.stopTone();
7156 toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 500);
7157 }
7158 toneG_heared = true;
7159 }
7160
7161 }
7162 }
7163 catch (Exception e)
7164 {
7165 }
7166 }
7167 else
7168 {
7169 // reset "beep" flag
7170 Navit.toneG_heared = false;
7171 Navit.your_are_speeding = false;
7172 }
7173 }
7174 else
7175 {
7176 Navit.your_are_speeding = false;
7177 }
7178
7179 if (your_are_speeding_old != Navit.your_are_speeding)
7180 {
7181 //System.out.println("xx paint 6 xx");
7182 // NavitOSDJava.draw_real_wrapper(false, true);
7183 ZANaviLinearLayout.redraw_OSD(8);
7184 }
7185
7186 if (queue6.size() > 5)
7187 {
7188 while (queue6.size() > 5)
7189 {
7190 try
7191 {
7192 // if too many gps updates are waiting, then only process the last few entry!!
7193 queue6.poll();
7194 }
7195 catch (Exception e)
7196 {
7197 }
7198 }
7199 }
7200
7201 queue6.offer(location);
7202 this.interrupt();
7203
7204 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
7205 }
7206
7207 public void calc_sun_stats()
7208 {
7209 //
7210 //
7211 // SUN ----------------
7212 //
7213 //
7214 sun_moon__must_calc_new = (SystemClock.elapsedRealtime() - sun_moon__mLastCalcSunMillis) > (60000 * 3); // calc new every 3 minutes
7215
7216 if ((sun_moon__must_calc_new) || (azmiuth_cache == -1))
7217 {
7218 float lat = 0;
7219 float lon = 0;
7220 try
7221 {
7222 // String lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * NG__map_main.view.getWidth() / 2, NavitGraphics.Global_dpi_factor * NG__map_main.view.getHeight() / 2);
7223 String lat_lon = "";
7224 if (Navit.GFX_OVERSPILL)
7225 {
7226 lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * (NG__map_main.view.getWidth() / 2 + NavitGraphics.mCanvasWidth_overspill), NavitGraphics.Global_dpi_factor * (NG__map_main.view.getHeight() / 2 + NavitGraphics.mCanvasHeight_overspill));
7227 }
7228 else
7229 {
7230 lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * NG__map_main.view.getWidth() / 2, NavitGraphics.Global_dpi_factor * NG__map_main.view.getHeight() / 2);
7231 }
7232
7233 String tmp[] = lat_lon.split(":", 2);
7234 //System.out.println("tmp=" + lat_lon);
7235 lat = Float.parseFloat(tmp[0]);
7236 lon = Float.parseFloat(tmp[1]);
7237 //System.out.println("ret=" + lat_lon + " lat=" + lat + " lon=" + lon);
7238 }
7239 catch (Exception e)
7240 {
7241 }
7242
7243 try
7244 {
7245 sun_moon__mLastCalcSunMillis = SystemClock.elapsedRealtime();
7246 TimeZone t = TimeZone.getDefault(); // Since the user's time zone changes dynamically, avoid caching this value. Instead, use this method to look it up for each use.
7247 //System.out.println(t.getID());
7248 sun_moon__calc = new SunriseSunsetCalculator(new Location2(String.valueOf(lat), String.valueOf(lon)), t.getID());
7249 sun_moon__cx = Calendar.getInstance();
7250 sun_moon__sc = SolarPosition.getSunPosition(new Date(), lat, lon);
7251
7252 azmiuth_cache = sun_moon__sc.azimuth;
7253 zenith_cache = sun_moon__sc.zenithAngle;
7254 sunrise_cache = sun_moon__calc.getOfficialSunriseForDate(sun_moon__cx);
7255 sunset_cache = sun_moon__calc.getOfficialSunsetForDate(sun_moon__cx);
7256 //System.out.println("calc moon");
7257 SolarEventCalculator.moonCoor_ret moon_stats = sun_moon__calc.computeMoon(sun_moon__cx);
7258 moon_azimuth_cache = moon_stats.az;
7259 moon_evelation_cache = moon_stats.alt;
7260 }
7261 catch (Exception e)
7262 {
7263 }
7264 }
7265 //
7266 elevation = 90 - zenith_cache;
7267 //
7268 // day -> +90.0 to - 0.83
7269 // evening dusk -> - 0.83 to -10.00
7270 if (elevation < -0.83)
7271 {
7272 is_night = true;
7273 if (elevation < -10.00)
7274 {
7275 is_twilight = false;
7276 }
7277 else
7278 {
7279 is_twilight = true;
7280 }
7281 //System.out.println("***NIGHT***");
7282 }
7283 else
7284 {
7285 is_night = false;
7286 //System.out.println("###DAY###");
7287 }
7288 //
7289 // SUN ----------------
7290 //
7291 //
7292 }
7293
7294 public void do_sun_calc()
7295 {
7296 //
7297 //
7298 // SUN ----------------
7299 //
7300 //
7301 try
7302 {
7303 this.calc_sun_stats();
7304 }
7305 catch (Exception e)
7306 {
7307 // on some systems BigInteger seems to crash, or maybe some values are out of range
7308 // until the bug is found, night modus is deactivated
7309 calc_sun_enabled = false;
7310 is_twilight = false;
7311 is_night = false;
7312 }
7313 //System.out.println("sunrise: " + sunrise_cache);
7314 //System.out.println("sunset: " + sunset_cache);
7315 //System.out.println("azimuth: " + roundTwoDecimals(azmiuth_cache));
7316 //System.out.println("elevation: " + elevation);
7317 //
7318 //
7319 // SUN ----------------
7320 //
7321 //
7322 }
7323
7324 public void run()
7325 {
7326 //System.out.println("CWorkerThread -- started --");
7327 while (this.running)
7328 {
7329 if ((queue4.size() == 0) && (queue6.size() == 0))
7330 {
7331 try
7332 {
7333 Thread.sleep(2000); // 2 secs.
7334 }
7335 catch (InterruptedException e)
7336 {
7337 }
7338 }
7339
7340 if (this.startmain)
7341 {
7342 //System.out.println("CWorkerThread:startup_calls:JTHREAD ID=" + this.getId());
7343 //System.out.println("CWorkerThread:startup_calls:THREAD ID=" + NavitGraphics.GetThreadId());
7344
7345 this.startmain = false;
7346 System.out.println("CWorkerThread -- NavitMain --");
7347 NavitMain(x, lang, version, display_density_string, n_datadir, n_sharedir, NavitGraphics.draw_bitmap_s);
7348 System.out.println("CWorkerThread -- NavitActivity(3) --");
7349 NavitActivity(3);
7350
7351 // -- set map detail level (after app startup) --
7352 // -- set map detail level (after app startup) --
7353 // -- set map detail level (after app startup) --
7354 try
7355 {
7356 getPrefs_more_map_detail();
7357 if (p.PREF_more_map_detail > 0)
7358 {
7359 Message msg2 = new Message();
7360 Bundle b2 = new Bundle();
7361 b2.putInt("Callback", 78);
7362 b2.putString("s", "" + p.PREF_more_map_detail);
7363 msg2.setData(b2);
7364 NavitGraphics.callback_handler.sendMessage(msg2);
7365 }
7366 }
7367 catch (Exception e)
7368 {
7369 // e.printStackTrace();
7370 }
7371 // -- set map detail level (after app startup) --
7372 // -- set map detail level (after app startup) --
7373 // -- set map detail level (after app startup) --
7374
7375 // -- set map DPI factor (after app startup) --
7376 // -- set map DPI factor (after app startup) --
7377 // -- set map DPI factor (after app startup) --
7378 try
7379 {
7380 if ((Navit.metrics.densityDpi >= 320) && (!p.PREF_shrink_on_high_dpi))
7381 {
7382 double factor;
7383 factor = (double) Navit.metrics.densityDpi / (double) NavitGraphics.Global_Scaled_DPI_normal;
7384
7385 Message msg2 = new Message();
7386 Bundle b2 = new Bundle();
7387 b2.putInt("Callback", 81);
7388 b2.putString("s", "" + factor);
7389 msg2.setData(b2);
7390 NavitGraphics.callback_handler.sendMessage(msg2);
7391 }
7392 }
7393 catch (Exception e)
7394 {
7395 // e.printStackTrace();
7396 }
7397 // -- set map DPI factor (after app startup) --
7398 // -- set map DPI factor (after app startup) --
7399 // -- set map DPI factor (after app startup) --
7400 Global_Init_Finished = 1;
7401 //x.runOnUiThread(new Runnable()
7402 //{
7403 // public void run()
7404 // {
7405 // NavitActivity(3);
7406 // }
7407 //});
7408
7409 //**getPrefs();
7410 //**activatePrefs();
7411
7412 System.out.println("CWorkerThread -- calling:ready --");
7413 }
7414
7415 while (queue6.size() > 0)
7416 {
7417 try
7418 {
7419 // blocking call
7420 // l2 = queue6.take();
7421 // non-blocking call
7422 l7 = queue6.poll();
7423 if (l2 != null)
7424 {
7425 NavitVehicle.VehicleCallback(l7.getLatitude(), l7.getLongitude(), (l7.getSpeed() * 3.6f), l7.getBearing(), l7.getAltitude(), l7.getAccuracy(), (l7.getTime() / 1000L));
7426 }
7427 }
7428
7429 catch (Exception e)
7430 {
7431 }
7432
7433 }
7434
7435 while (queue.size() > 0)
7436 {
7437 try
7438 {
7439 // blocking call
7440 // l2 = queue.take();
7441 // non-blocking call
7442 l2 = queue.poll();
7443 if (l2 != null)
7444 {
7445 //System.out.println("CWorkerThread:CallbackMessageChannelReal_call:JTHREAD ID=" + this.getId());
7446 //System.out.println("CWorkerThread:CallbackMessageChannelReal_call:THREAD ID=" + NavitGraphics.GetThreadId());
7447 //System.out.println("CWorkerThread:CallbackMessageChannelReal:" + l2.i);
7448 NavitGraphics.CallbackMessageChannelReal(l2.i, l2.s);
7449 //System.out.println("CWorkerThread:CallbackMessageChannelReal:finished");
7450 }
7451 }
7452 catch (Exception e)
7453 {
7454 }
7455
7456 // if GPS updates are pending, process them
7457 if (queue6.size() > 0)
7458 {
7459 try
7460 {
7461 // blocking call
7462 // l2 = queue6.take();
7463 // non-blocking call
7464 l7 = queue6.poll();
7465 if (l2 != null)
7466 {
7467 NavitVehicle.VehicleCallback(l7.getLatitude(), l7.getLongitude(), (l7.getSpeed() * 3.6f), l7.getBearing(), l7.getAltitude(), l7.getAccuracy(), (l7.getTime() / 1000L));
7468 }
7469 }
7470 catch (Exception e)
7471 {
7472 }
7473 }
7474
7475 }
7476
7477 while (queue5.size() > 0)
7478 {
7479 try
7480 {
7481 // blocking call
7482 // l6 = queue5.take();
7483 // non-blocking call
7484 l6 = queue5.poll();
7485 if (l6 != null)
7486 {
7487 //System.out.println("CWorkerThread:SizeChangedCallbackReal_call:JTHREAD ID=" + this.getId());
7488 //System.out.println("CWorkerThread:SizeChangedCallbackReal_call:THREAD ID=" + NavitGraphics.GetThreadId());
7489 NavitGraphics.SizeChangedCallbackReal(l6.w, l6.h, l6.mb);
7490 }
7491 }
7492 catch (Exception e)
7493 {
7494 }
7495
7496 }
7497
7498 int count_timeout_callbacks = 0;
7499 while (count_timeout_callbacks < 10 && queue4.size() > 0)
7500 {
7501 count_timeout_callbacks++;
7502 try
7503 {
7504 // blocking call
7505 // l5 = queue4.take();
7506 // non-blocking call
7507 l5 = queue4.poll();
7508 if (l5 != null)
7509 {
7510 //System.out.println("CWorkerThread:TimeoutCallback_call:JTHREAD ID=" + this.getId());
7511 //System.out.println("CWorkerThread:TimeoutCallback_call:THREAD ID=" + NavitGraphics.GetThreadId());
7512 if ((l5.nt.running) || (!l5.nt.event_multi))
7513 {
7514 NavitGraphics.TimeoutCallback(l5.del, l5.id);
7515 }
7516 else
7517 {
7518 // System.out.println("CWorkerThread:TimeoutCallback_call:running=false! cid=" + l5.id);
7519 }
7520 }
7521 }
7522 catch (Exception e)
7523 {
7524 }
7525
7526 // if GPS updates are pending, process them
7527 if (queue6.size() > 0)
7528 {
7529 try
7530 {
7531 // blocking call
7532 // l2 = queue6.take();
7533 // non-blocking call
7534 l7 = queue6.poll();
7535 if (l2 != null)
7536 {
7537 NavitVehicle.VehicleCallback(l7.getLatitude(), l7.getLongitude(), (l7.getSpeed() * 3.6f), l7.getBearing(), l7.getAltitude(), l7.getAccuracy(), (l7.getTime() / 1000L));
7538 }
7539 }
7540 catch (Exception e)
7541 {
7542 }
7543 }
7544
7545 }
7546
7547 while (queue3.size() > 0)
7548 {
7549 try
7550 {
7551 // blocking call
7552 // l4 = queue3.take();
7553 // non-blocking call
7554 l4 = queue3.poll();
7555 if (l4 != null)
7556 {
7557 //System.out.println("CWorkerThread:MotionCallbackReal_call:JTHREAD ID=" + this.getId());
7558 //System.out.println("CWorkerThread:MotionCallbackReal_call:THREAD ID=" + NavitGraphics.GetThreadId());
7559 if (queue3.size() > 0)
7560 {
7561 // if more moves are queued up, disable map drawing!
7562 NavitGraphics.MotionCallbackReal(l4.x1, l4.y1, l4.x2, l4.y2, 0);
7563 }
7564 else
7565 {
7566 // ok, also draw the map
7567 NavitGraphics.MotionCallbackReal(l4.x1, l4.y1, l4.x2, l4.y2, 1);
7568 }
7569 }
7570 }
7571 catch (Exception e)
7572 {
7573 }
7574
7575 }
7576
7577 while (queue7.size() > 0)
7578 {
7579 try
7580 {
7581
7582 // if GPS updates are pending, process them
7583 if (queue6.size() > 0)
7584 {
7585 try
7586 {
7587 // blocking call
7588 // l2 = queue6.take();
7589 // non-blocking call
7590 l7 = queue6.poll();
7591 if (l2 != null)
7592 {
7593 NavitVehicle.VehicleCallback(l7.getLatitude(), l7.getLongitude(), (l7.getSpeed() * 3.6f), l7.getBearing(), l7.getAltitude(), l7.getAccuracy(), (l7.getTime() / 1000L));
7594 }
7595 }
7596 catch (Exception e)
7597 {
7598 }
7599 }
7600
7601 l8 = queue7.poll();
7602 if (l8 != null)
7603 {
7604 if (l8.type == 1)
7605 {
7606 Navit.OSD_nextturn.nextturn_streetname_systematic = "";
7607 Navit.OSD_nextturn.nextturn_streetname = NavitGraphics.CallbackGeoCalc(8, l8.b, l8.c);
7608 if (p.PREF_item_dump)
7609 {
7610 // -------- DEBUG ------- DEBUG ---------
7611 // -------- DEBUG ------- DEBUG ---------
7612 // -------- DEBUG ------- DEBUG ---------
7613 Navit.debug_item_dump = NavitGraphics.CallbackGeoCalc(9, l8.b, l8.c);
7614 //System.out.println("xx paint 22 xx");
7615 NavitGraphics.NavitAOverlay_s.postInvalidate();
7616 // -------- DEBUG ------- DEBUG ---------
7617 // -------- DEBUG ------- DEBUG ---------
7618 // -------- DEBUG ------- DEBUG ---------
7619 }
7620 //System.out.println("OSD postinvalidate***");
7621 //System.out.println("xx paint 7 xx");
7622 // NavitOSDJava.draw_real_wrapper(true, false);
7623 ZANaviLinearLayout.redraw_OSD(1);
7624 //++ NavitGraphics.NavitAOSDJava_.postInvalidate();
7625 }
7626 else if (l8.type == 2)
7627 {
7628 NavitGraphics.CallbackGeoCalc(l8.a, l8.b, l8.c);
7629 }
7630 else if (l8.type == 13)
7631 {
7632 try
7633 {
7634 // get roadbook
7635 // String road_book_res = NavitGraphics.CallbackGeoCalc(13, l8.b, l8.c);
7636 String[] separated = NavitGraphics.GetRoadBookItems(12345);
7637 // System.out.println("ROADBOOK_RES=" + separated);
7638
7639 // parse roadbook data ------------
7640 road_book_items.clear();
7641 ZANaviListViewAdapter.ListViewItem l = null;
7642
7643 // String[] separated = road_book_res.split("\13");
7644 int jk = 0;
7645 int ResId = 0;
7646 for (jk = 0; jk < separated.length; jk++)
7647 {
7648 if (jk > 1)
7649 {
7650 // System.out.println("ROADBOOK_RES=" + jk + ":" + separated[jk]);
7651 String[] values = separated[jk].split(":");
7652 // 0 string:distance short form
7653 // 1 lat
7654 // 2 lon
7655 // 3 icon name
7656 // 4 text
7657
7658 // System.out.println("RBI:008:img=" + values[3]);
7659
7660 if (values[3].compareTo("nav_waypoint") == 0)
7661 {
7662 try
7663 {
7664 ResId = Navit.res_.getIdentifier("com.zoffcc.applications.zanavi:drawable/" + "nav_waypoint_bk_center", null, null);
7665 }
7666 catch (Exception e_res_id)
7667 {
7668 ResId = 0;
7669 e_res_id.printStackTrace();
7670 }
7671 }
7672 else if (values[3].compareTo("nav_destination") == 0)
7673 {
7674 try
7675 {
7676 ResId = Navit.res_.getIdentifier("com.zoffcc.applications.zanavi:drawable/" + "nav_destination_bk_center", null, null);
7677 }
7678 catch (Exception e_res_id)
7679 {
7680 ResId = 0;
7681 e_res_id.printStackTrace();
7682 }
7683 }
7684 else
7685 {
7686
7687 try
7688 {
7689 ResId = Navit.res_.getIdentifier("com.zoffcc.applications.zanavi:drawable/" + values[3] + "_bk", null, null);
7690 }
7691 catch (Exception e_res_id)
7692 {
7693 ResId = 0;
7694 e_res_id.printStackTrace();
7695 }
7696 }
7697
7698 // System.out.println("RBI:008+" + ResId);
7699 if (ResId != 0)
7700 {
7701 l = new ListViewItem(values[0], res_.getDrawable(ResId), "", values[4], Float.parseFloat(values[1]), Float.parseFloat(values[2]));
7702 }
7703 else
7704 {
7705 l = new ListViewItem(values[0], res_.getDrawable(R.drawable.mini_roundabout), "", values[4], Float.parseFloat(values[1]), Float.parseFloat(values[2]));
7706 }
7707 // System.out.println("RBI:008");
7708 road_book_items.add(l);
7709 // System.out.println("RBI:009");
7710 }
7711 }
7712 // System.out.println("RBI:010");
7713
7714 try
7715 {
7716 Message msg = Navit_progress_h.obtainMessage();
7717 Bundle b = new Bundle();
7718 msg.what = 33;
7719 msg.setData(b);
7720 Navit_progress_h.sendMessage(msg);
7721 }
7722 catch (Exception e)
7723 {
7724 e.printStackTrace();
7725 }
7726 // System.out.println("RBI:011");
7727 }
7728 catch (Exception eerb)
7729 {
7730 eerb.printStackTrace();
7731 }
7732 // parse roadbook data ------------
7733
7734 }
7735 }
7736 }
7737 catch (Exception e)
7738 {
7739 }
7740
7741 }
7742
7743 while (queue2.size() > 0)
7744 {
7745 try
7746 {
7747 // blocking call
7748 // l3 = queue2.take();
7749 // non-blocking call
7750 l3 = queue2.poll();
7751 if (l3 != null)
7752 {
7753 int i3 = l3.intValue();
7754 //System.out.println("CWorkerThread:NavitActivity_call:JTHREAD ID=" + this.getId());
7755 //System.out.println("CWorkerThread:NavitActivity_call:THREAD ID=" + NavitGraphics.GetThreadId());
7756 //System.out.println("CWorkerThread:NavitActivity:" + i3);
7757 NavitActivity(i3);
7758 }
7759 }
7760 catch (Exception e)
7761 {
7762 }
7763 }
7764
7765 // check sun position (and after interval, recalc values)
7766 do_sun_calc();
7767 }
7768 //System.out.println("CWorkerThread -- stopped --");
7769 }
7770
7771 public void stop_me()
7772 {
7773 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
7774
7775 this.running = false;
7776 this.interrupt();
7777
7778 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
7779 }
7780 }
7781
7782 public class SmoothVehicle extends Thread
7783 {
7784 private Boolean running;
7785
7786 SmoothVehicle()
7787 {
7788 this.running = true;
7789 }
7790
7791 public void run()
7792 {
7793 while (this.running)
7794 {
7795 try
7796 {
7797 Thread.sleep(5000); // 5 secs.
7798 }
7799 catch (InterruptedException e)
7800 {
7801 }
7802 }
7803 }
7804
7805 public void stop_me()
7806 {
7807 this.running = false;
7808 }
7809 }
7810
7811 public class WatchMem extends Thread
7812 {
7813 private Boolean running;
7814
7815 WatchMem()
7816 {
7817 this.running = true;
7818 }
7819
7820 public void run()
7821 {
7822 //System.out.println("WatchMem -- started --");
7823 while (this.running)
7824 {
7825 Navit.show_mem_used();
7826
7827 try
7828 {
7829 Thread.sleep(5000); // 5 secs.
7830 }
7831 catch (InterruptedException e)
7832 {
7833 }
7834 }
7835 //System.out.println("WatchMem -- stopped --");
7836 }
7837
7838 public void stop_me()
7839 {
7840 this.running = false;
7841 }
7842 }
7843
7844 public class SimGPS extends Thread
7845 {
7846 private Boolean running;
7847 private Handler h;
7848
7849 SimGPS(Handler h_)
7850 {
7851 System.out.println("SimGPS -- inited --");
7852 this.h = h_;
7853 this.running = true;
7854 }
7855
7856 public void run()
7857 {
7858 System.out.println("SimGPS -- started --");
7859 while (this.running)
7860 {
7861 float rnd_heading = (float) (Math.random() * 360d);
7862 float lat = 48.216023f;
7863 float lng = 16.391664f;
7864 //Location l = new Location("Network");
7865 //l.setLatitude(lat);
7866 //l.setLongitude(lng);
7867 //l.setBearing(rnd_heading);
7868 // NavitVehicle.set_mock_location__fast(l);
7869 // NavitVehicle.update_compass_heading(rnd_heading);
7870 if (this.h != null)
7871 {
7872 Message msg = this.h.obtainMessage();
7873 Bundle b = new Bundle();
7874 msg.what = 1;
7875 b.putFloat("b", rnd_heading);
7876 b.putFloat("lat", lat);
7877 b.putFloat("lng", lng);
7878 msg.setData(b);
7879 this.h.sendMessage(msg);
7880 }
7881 try
7882 {
7883 Thread.sleep(800);
7884 }
7885 catch (InterruptedException e)
7886 {
7887 }
7888 }
7889 System.out.println("SimGPS -- stopped --");
7890 }
7891
7892 public void stop_me()
7893 {
7894 this.running = false;
7895 }
7896 }
7897
7898 public class SearchResultsThreadSpinnerThread extends Thread
7899 {
7900 int dialog_num;
7901 int spinner_current_value;
7902 private Boolean running;
7903 Handler mHandler;
7904
7905 SearchResultsThreadSpinnerThread(Handler h, int dialog_num)
7906 {
7907 this.dialog_num = dialog_num;
7908 this.mHandler = h;
7909 this.spinner_current_value = 0;
7910
7911 this.running = true;
7912 Log.e("Navit", "SearchResultsThreadSpinnerThread created");
7913 }
7914
7915 public void run()
7916 {
7917 Log.e("Navit", "SearchResultsThreadSpinnerThread started");
7918 while (this.running)
7919 {
7920 if (Navit.NavitAddressSearchSpinnerActive == false)
7921 {
7922 this.running = false;
7923 }
7924 else
7925 {
7926 Message msg = mHandler.obtainMessage();
7927 Bundle b = new Bundle();
7928 msg.what = 10;
7929 b.putInt("dialog_num", this.dialog_num);
7930 b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
7931 b.putInt("cur", this.spinner_current_value % (Navit.ADDRESS_RESULTS_DIALOG_MAX + 1));
7932 if ((Navit.NavitSearchresultBar_title.equals("")) && (Navit.NavitSearchresultBar_text.equals("")))
7933 {
7934 b.putString("title", Navit.get_text("getting search results")); //TRANS
7935 b.putString("text", Navit.get_text("searching ...")); //TRANS
7936 }
7937 else
7938 {
7939 b.putString("title", Navit.NavitSearchresultBar_title);
7940 b.putString("text", Navit.NavitSearchresultBar_text);
7941 }
7942 msg.setData(b);
7943 mHandler.sendMessage(msg);
7944 try
7945 {
7946 Thread.sleep(700);
7947 }
7948 catch (InterruptedException e)
7949 {
7950 // e.printStackTrace();
7951 }
7952 this.spinner_current_value++;
7953 }
7954 }
7955 Log.e("Navit", "SearchResultsThreadSpinnerThread ended");
7956 }
7957 }
7958
7959 public class SearchResultsThread extends Thread
7960 {
7961 private Boolean running;
7962 Handler mHandler;
7963 int my_dialog_num;
7964
7965 SearchResultsThread(Handler h, int dialog_num)
7966 {
7967 this.running = true;
7968 this.mHandler = h;
7969 this.my_dialog_num = dialog_num;
7970 Log.e("Navit", "SearchResultsThread created");
7971 }
7972
7973 public void stop_me()
7974 {
7975 this.running = false;
7976 }
7977
7978 public void run()
7979 {
7980 Log.e("Navit", "SearchResultsThread started");
7981
7982 System.out.println("Global_Location_update_not_allowed = 1");
7983 Navit.Global_Location_update_not_allowed = 1; // dont allow location updates now!
7984
7985 // initialize the dialog with sane values
7986 Message msg = mHandler.obtainMessage();
7987 Bundle b = new Bundle();
7988 msg.what = 10;
7989 b.putInt("dialog_num", this.my_dialog_num);
7990 b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
7991 b.putInt("cur", 0);
7992 b.putString("title", Navit.get_text("getting search results")); //TRANS
7993 b.putString("text", Navit.get_text("searching ...")); //TRANS
7994 msg.setData(b);
7995 mHandler.sendMessage(msg);
7996
7997 int partial_match_i = 0;
7998 if (Navit_last_address_partial_match)
7999 {
8000 partial_match_i = 1;
8001 }
8002
8003 if (this.my_dialog_num == Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE)
8004 {
8005 // start the search, this could take a long time!!
8006 Log.e("Navit", "SearchResultsThread run1");
8007 // need lowercase to find stuff !!
8008 Navit_last_address_search_string = filter_bad_chars(Navit_last_address_search_string).toLowerCase();
8009 if ((Navit_last_address_hn_string != null) && (Navit_last_address_hn_string.equals("")))
8010 {
8011 Navit_last_address_hn_string = filter_bad_chars(Navit_last_address_hn_string).toLowerCase();
8012 }
8013
8014 if (Navit_last_address_full_file_search)
8015 {
8016 // flags (18) -> order level to search at
8017 // ================
8018 // 0#0 0 -> search full world
8019 // lat#lon radius -> search only this area, around lat,lon
8020 // ================
8021 N_NavitGraphics.SearchResultList(3, partial_match_i, Navit_last_address_search_string, "", "", 18, Navit_last_address_search_country_iso2_string, "0#0", 0);
8022 }
8023 else
8024 {
8025 if (Navit.use_index_search)
8026 {
8027 // new method with index search
8028 // -----------------
8029 //Navit_last_address_search_string
8030 String street_ = "";
8031 String town_ = "";
8032 String hn_ = Navit_last_address_hn_string;
8033
8034 int last_space = Navit_last_address_search_string.lastIndexOf(" ");
8035 if (last_space != -1)
8036 {
8037 street_ = Navit_last_address_search_string.substring(0, last_space);
8038 town_ = Navit_last_address_search_string.substring(last_space + 1);
8039 // System.out.println("XX" + street_ + "YY" + town_ + "ZZ");
8040 }
8041 else
8042 {
8043 street_ = Navit_last_address_search_string;
8044 town_ = "";
8045 }
8046 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);
8047
8048 // sort result list
8049 Collections.sort(Navit.NavitAddressResultList_foundItems);
8050 }
8051 else
8052 {
8053 // old method search
8054 // -----------------
8055 // flags --> 3: search all countries
8056 // 2: search <iso2 string> country
8057 // 1: search default country (what you have set as language in prefs)
8058 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);
8059
8060 // sort result list
8061 Collections.sort(Navit.NavitAddressResultList_foundItems);
8062 }
8063 }
8064 Log.e("Navit", "SearchResultsThread run2");
8065 }
8066 else if (this.my_dialog_num == Navit.SEARCHRESULTS_WAIT_DIALOG)
8067 {
8068 // online googlemaps search
8069 // google search
8070 Log.e("Navit", "SearchResultsThread run1 -> online googlemaps search");
8071 String addressInput = filter_bad_chars(Navit_last_address_search_string);
8072 try
8073 {
8074 List<Address> foundAdresses = Navit.Navit_Geocoder.getFromLocationName(addressInput, 3); //Search addresses
8075 System.out.println("found " + foundAdresses.size() + " results");
8076 // System.out.println("addr=" + foundAdresses.get(0).getLatitude() + " " + foundAdresses.get(0).getLongitude() + "" + foundAdresses.get(0).getAddressLine(0));
8077
8078 Navit.NavitAddressSearchSpinnerActive = false;
8079
8080 for (int results_step = 0; results_step < foundAdresses.size(); results_step++)
8081 {
8082 Navit.Navit_Address_Result_Struct tmp_addr = new Navit_Address_Result_Struct();
8083 tmp_addr.result_type = "STR";
8084 tmp_addr.item_id = "0";
8085 tmp_addr.lat = (float) foundAdresses.get(results_step).getLatitude();
8086 tmp_addr.lon = (float) foundAdresses.get(results_step).getLongitude();
8087 tmp_addr.addr = "";
8088
8089 String c_code = foundAdresses.get(results_step).getCountryCode();
8090 if (c_code != null)
8091 {
8092 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getCountryCode() + ",";
8093 }
8094
8095 String p_code = foundAdresses.get(results_step).getPostalCode();
8096 if (p_code != null)
8097 {
8098 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getPostalCode() + " ";
8099 }
8100
8101 if (foundAdresses.get(results_step).getMaxAddressLineIndex() > -1)
8102 {
8103 for (int addr_line = 0; addr_line < foundAdresses.get(results_step).getMaxAddressLineIndex(); addr_line++)
8104 {
8105 if (addr_line > 0) tmp_addr.addr = tmp_addr.addr + " ";
8106 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getAddressLine(addr_line);
8107 }
8108 }
8109
8110 Navit.NavitAddressResultList_foundItems.add(tmp_addr);
8111
8112 if (tmp_addr.result_type.equals("TWN"))
8113 {
8114 Navit.search_results_towns++;
8115 }
8116 else if (tmp_addr.result_type.equals("STR"))
8117 {
8118 Navit.search_results_streets++;
8119 }
8120 else if (tmp_addr.result_type.equals("SHN"))
8121 {
8122 Navit.search_results_streets_hn++;
8123 }
8124 else if (tmp_addr.result_type.equals("POI"))
8125 {
8126 Navit.search_results_poi++;
8127 }
8128
8129 // make the dialog move its bar ...
8130 Bundle b2 = new Bundle();
8131 b2.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG);
8132 b2.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
8133 b2.putInt("cur", Navit.NavitAddressResultList_foundItems.size() % (Navit.ADDRESS_RESULTS_DIALOG_MAX + 1));
8134 b2.putString("title", Navit.get_text("loading search results")); //TRANS
8135 b2.putString("text", Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn + " " + Navit.get_text("POI") + ":" + Navit.search_results_poi);
8136
8137 Navit.msg_to_msg_handler(b2, 10);
8138 }
8139 }
8140 catch (Exception e)
8141 {
8142 e.printStackTrace();
8143 System.out.println("seems googlemaps API is not working, try offline search");
8144 }
8145 }
8146
8147 Navit.NavitAddressSearchSpinnerActive = false;
8148
8149 if (Navit.NavitAddressResultList_foundItems.size() > 0)
8150 {
8151 open_search_result_list();
8152 }
8153 else
8154 {
8155 // no results found, show toast
8156 msg = mHandler.obtainMessage();
8157 b = new Bundle();
8158 msg.what = 2;
8159 b.putString("text", Navit.get_text("No Results found!")); //TRANS
8160 msg.setData(b);
8161 mHandler.sendMessage(msg);
8162 }
8163
8164 // ok, remove dialog
8165 msg = mHandler.obtainMessage();
8166 b = new Bundle();
8167 msg.what = 99;
8168 b.putInt("dialog_num", this.my_dialog_num);
8169 msg.setData(b);
8170 mHandler.sendMessage(msg);
8171
8172 // reset the startup-search flag
8173 Navit.NavitStartupAlreadySearching = false;
8174
8175 System.out.println("Global_Location_update_not_allowed = 0");
8176 Navit.Global_Location_update_not_allowed = 0; // DO allow location updates now!
8177
8178 Log.e("Navit", "SearchResultsThread ended");
8179 }
8180 }
8181
8182 public static String filter_bad_chars(String in)
8183 {
8184 String out = in;
8185 out = out.replaceAll("\\n", " "); // newline -> space
8186 out = out.replaceAll("\\r", " "); // return -> space
8187 out = out.replaceAll("\\t", " "); // tab -> space
8188 out = out.trim();
8189 return out;
8190 }
8191
8192 public static void msg_to_msg_handler(Bundle b, int id)
8193 {
8194 Message msg = Navit_progress_h.obtainMessage();
8195 msg.what = id;
8196 msg.setData(b);
8197 Navit_progress_h.sendMessage(msg);
8198 }
8199
8200 public void open_search_result_list()
8201 {
8202 // open result list
8203 Intent address_result_list_activity = new Intent(this, NavitAddressResultListActivity.class);
8204 this.startActivityForResult(address_result_list_activity, Navit.NavitAddressResultList_id);
8205 }
8206
8207 public static Handler callback_handler_55 = new Handler()
8208 {
8209 public void handleMessage(Message msg)
8210 {
8211 // handle 111111
8212 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0, "" + msg.getData().getInt("Callback"));
8213
8214 if (msg.getData().getInt("Callback") == 1)
8215 {
8216 // zoom in
8217 NavitGraphics.CallbackMessageChannel(1, "");
8218 }
8219 else if (msg.getData().getInt("Callback") == 2)
8220 {
8221 // zoom out
8222 NavitGraphics.CallbackMessageChannel(2, "");
8223 }
8224 else if (msg.getData().getInt("Callback") == 55599)
8225 {
8226 // calc route after adding points
8227 NavitGraphics.CallbackMessageChannel(55599, "");
8228 }
8229 else if (msg.getData().getInt("Callback") == 55503)
8230 {
8231 try
8232 {
8233 NavitVehicle.pos_recording_add(2, 0, 0, 0, 0, 0);
8234 NavitVehicle.pos_recording_add(3, Float.parseFloat(msg.getData().getString("lat")), Float.parseFloat(msg.getData().getString("lon")), 0, 0, 0);
8235 }
8236 catch (Exception e)
8237 {
8238 }
8239
8240 // get values
8241 String lat = msg.getData().getString("lat");
8242 String lon = msg.getData().getString("lon");
8243 String q = msg.getData().getString("q");
8244 // set routing target to lat,lon
8245 NavitGraphics.CallbackMessageChannel(55503, lat + "#" + lon + "#" + q);
8246 }
8247 else if (msg.getData().getInt("Callback") == 3)
8248 {
8249 try
8250 {
8251 NavitVehicle.pos_recording_add(2, 0, 0, 0, 0, 0);
8252 NavitVehicle.pos_recording_add(3, Float.parseFloat(msg.getData().getString("lat")), Float.parseFloat(msg.getData().getString("lon")), 0, 0, 0);
8253 }
8254 catch (Exception e)
8255 {
8256 }
8257
8258 // get values
8259 String lat = msg.getData().getString("lat");
8260 String lon = msg.getData().getString("lon");
8261 String q = msg.getData().getString("q");
8262 // set routing target to lat,lon
8263 NavitGraphics.CallbackMessageChannel(3, lat + "#" + lon + "#" + q);
8264 }
8265 else if (msg.getData().getInt("Callback") == 55548)
8266 {
8267 try
8268 {
8269 NavitVehicle.pos_recording_add(3, Float.parseFloat(msg.getData().getString("lat")), Float.parseFloat(msg.getData().getString("lon")), 0, 0, 0);
8270 }
8271 catch (Exception e)
8272 {
8273 }
8274
8275 // get values
8276 String lat = msg.getData().getString("lat");
8277 String lon = msg.getData().getString("lon");
8278 String q = msg.getData().getString("q");
8279 // append to routing, add waypoint at lat,lon
8280 NavitGraphics.CallbackMessageChannel(55548, lat + "#" + lon + "#" + q);
8281 }
8282 else if (msg.getData().getInt("Callback") == 48)
8283 {
8284 try
8285 {
8286 NavitVehicle.pos_recording_add(3, Float.parseFloat(msg.getData().getString("lat")), Float.parseFloat(msg.getData().getString("lon")), 0, 0, 0);
8287 }
8288 catch (Exception e)
8289 {
8290 }
8291
8292 // get values
8293 String lat = msg.getData().getString("lat");
8294 String lon = msg.getData().getString("lon");
8295 String q = msg.getData().getString("q");
8296 // append to routing, add waypoint at lat,lon
8297 NavitGraphics.CallbackMessageChannel(48, lat + "#" + lon + "#" + q);
8298 }
8299 else if (msg.getData().getInt("Callback") == 4)
8300 {
8301 // set routing target to pixel x,y
8302 int x = msg.getData().getInt("x");
8303 int y = msg.getData().getInt("y");
8304
8305 NavitGraphics.CallbackMessageChannel(4, "" + x + "#" + y);
8306 try
8307 {
8308 Navit.follow_button_on();
8309 }
8310 catch (Exception e2)
8311 {
8312 e2.printStackTrace();
8313 }
8314 }
8315 else if (msg.getData().getInt("Callback") == 49)
8316 {
8317 // set routing target to pixel x,y
8318 int x = msg.getData().getInt("x");
8319 int y = msg.getData().getInt("y");
8320
8321 NavitGraphics.CallbackMessageChannel(49, "" + x + "#" + y);
8322 try
8323 {
8324 Navit.follow_button_on();
8325 }
8326 catch (Exception e2)
8327 {
8328 e2.printStackTrace();
8329 }
8330 }
8331 else if (msg.getData().getInt("Callback") == 5)
8332 {
8333 // toggle layer on/off
8334 String s = msg.getData().getString("s");
8335 NavitGraphics.CallbackMessageChannel(5, s);
8336 }
8337 else if (msg.getData().getInt("Callback") == 7)
8338 {
8339 NavitGraphics.CallbackMessageChannel(7, "");
8340 }
8341 else if ((msg.getData().getInt("Callback") > 7) && (msg.getData().getInt("Callback") < 21))
8342 {
8343 NavitGraphics.CallbackMessageChannel(msg.getData().getInt("Callback"), "");
8344 }
8345 else if (msg.getData().getInt("Callback") == 21)
8346 {
8347 int x = msg.getData().getInt("x");
8348 int y = msg.getData().getInt("y");
8349 // ??? // ButtonCallback(1, 1, x, y); // down
8350 }
8351 else if (msg.getData().getInt("Callback") == 22)
8352 {
8353 int x = msg.getData().getInt("x");
8354 int y = msg.getData().getInt("y");
8355 // ??? // ButtonCallback(0, 1, x, y); // up
8356 }
8357 else if (msg.getData().getInt("Callback") == 23)
8358 {
8359 int x = msg.getData().getInt("x");
8360 int y = msg.getData().getInt("y");
8361 int x2 = msg.getData().getInt("x2");
8362 int y2 = msg.getData().getInt("y2");
8363 NavitGraphics.MotionCallback(x, y, x2, y2);
8364 }
8365 else if (msg.getData().getInt("Callback") == 24)
8366 {
8367 try
8368 {
8369 NavitGraphics.NavitMsgTv_.setEnabled(true);
8370 NavitGraphics.NavitMsgTv_.setVisibility(View.VISIBLE);
8371 }
8372 catch (Exception e)
8373 {
8374
8375 }
8376 }
8377 else if (msg.getData().getInt("Callback") == 25)
8378 {
8379 try
8380 {
8381 NavitGraphics.NavitMsgTv_.setVisibility(View.INVISIBLE);
8382 NavitGraphics.NavitMsgTv_.setEnabled(false);
8383 NavitGraphics.NavitMsgTv_.setVisibility(View.GONE);
8384 }
8385 catch (Exception e)
8386 {
8387
8388 }
8389 }
8390 else if (msg.getData().getInt("Callback") == 30)
8391 {
8392 // 2D
8393 // String s = msg.getData().getString("s");
8394 NavitGraphics.CallbackMessageChannel(30, "");
8395 }
8396 else if (msg.getData().getInt("Callback") == 31)
8397 {
8398 // 3D
8399 // String s = msg.getData().getString("s");
8400 NavitGraphics.CallbackMessageChannel(31, "");
8401 }
8402 else if (msg.getData().getInt("Callback") == 32)
8403 {
8404 // switch to specific 3D pitch
8405 String s = msg.getData().getString("s");
8406 NavitGraphics.CallbackMessageChannel(32, s);
8407 }
8408 else if (msg.getData().getInt("Callback") == 33)
8409 {
8410 // zoom to specific zoomlevel
8411 String s = msg.getData().getString("s");
8412 NavitGraphics.CallbackMessageChannel(33, s);
8413 }
8414 else if (msg.getData().getInt("Callback") == 34)
8415 {
8416 // announcer voice OFF
8417 NavitGraphics.CallbackMessageChannel(34, "");
8418 }
8419 else if (msg.getData().getInt("Callback") == 35)
8420 {
8421 // announcer voice ON
8422 NavitGraphics.CallbackMessageChannel(35, "");
8423 }
8424 else if (msg.getData().getInt("Callback") == 36)
8425 {
8426 // switch "Lock on road" ON
8427 NavitGraphics.CallbackMessageChannel(36, "");
8428 }
8429 else if (msg.getData().getInt("Callback") == 37)
8430 {
8431 // switch "Lock on road" OFF
8432 NavitGraphics.CallbackMessageChannel(37, "");
8433 }
8434 else if (msg.getData().getInt("Callback") == 38)
8435 {
8436 // switch "Northing" ON
8437 NavitGraphics.CallbackMessageChannel(38, "");
8438 }
8439 else if (msg.getData().getInt("Callback") == 39)
8440 {
8441 // switch "Northing" OFF
8442 NavitGraphics.CallbackMessageChannel(39, "");
8443 }
8444 else if (msg.getData().getInt("Callback") == 40)
8445 {
8446 // switch "Map follows Vehicle" ON
8447 NavitGraphics.CallbackMessageChannel(40, "");
8448 }
8449 else if (msg.getData().getInt("Callback") == 41)
8450 {
8451 // switch "Map follows Vehicle" OFF
8452 NavitGraphics.CallbackMessageChannel(41, "");
8453 }
8454 else if (msg.getData().getInt("Callback") == 42)
8455 {
8456 // routing mode "highways"
8457 NavitGraphics.CallbackMessageChannel(42, "");
8458 }
8459 else if (msg.getData().getInt("Callback") == 43)
8460 {
8461 // routing mode "normal roads"
8462 NavitGraphics.CallbackMessageChannel(43, "");
8463 }
8464 else if (msg.getData().getInt("Callback") == 44)
8465 {
8466 // show duplicates in search results
8467 NavitGraphics.CallbackMessageChannel(44, "");
8468 }
8469 else if (msg.getData().getInt("Callback") == 45)
8470 {
8471 // filter duplicates in search results
8472 NavitGraphics.CallbackMessageChannel(45, "");
8473 }
8474 else if (msg.getData().getInt("Callback") == 46)
8475 {
8476 // stop searching and show results found until now
8477 NavitGraphics.CallbackMessageChannel(46, "");
8478 }
8479 else if (msg.getData().getInt("Callback") == 47)
8480 {
8481 // change maps data dir
8482 String s = msg.getData().getString("s");
8483 NavitGraphics.CallbackMessageChannel(47, s);
8484 }
8485 else if (msg.getData().getInt("Callback") == 50)
8486 {
8487 // we request to stop drawing the map
8488 NavitGraphics.CallbackMessageChannel(50, "");
8489 }
8490 else if (msg.getData().getInt("Callback") == 51)
8491 {
8492 // set position to pixel x,y
8493 int x = msg.getData().getInt("x");
8494 int y = msg.getData().getInt("y");
8495 NavitGraphics.CallbackMessageChannel(51, "" + x + "#" + y);
8496 }
8497 else if (msg.getData().getInt("Callback") == 52)
8498 {
8499 // switch to demo vehicle
8500 String s = msg.getData().getString("s");
8501 NavitGraphics.CallbackMessageChannel(52, s);
8502 }
8503 else if (msg.getData().getInt("Callback") == 53)
8504 {
8505 // dont speak streetnames
8506 NavitGraphics.CallbackMessageChannel(53, "");
8507 }
8508 else if (msg.getData().getInt("Callback") == 54)
8509 {
8510 // speak streetnames
8511 NavitGraphics.CallbackMessageChannel(54, "");
8512 }
8513 else if (msg.getData().getInt("Callback") == 55)
8514 {
8515 // set cache size for (map-)files
8516 String s = msg.getData().getString("s");
8517 NavitGraphics.CallbackMessageChannel(55, s);
8518 }
8519 // else if (msg.getData().getInt("Callback") == 56)
8520 // {
8521 // // draw polylines with/without circles at the end
8522 // String s = msg.getData().getString("s");
8523 // NavitGraphics.CallbackMessageChannel(56, s); // 0 -> draw circles, 1 -> DO NOT draw circles
8524 // }
8525 else if (msg.getData().getInt("Callback") == 57)
8526 {
8527 // keep drawing streets as if at "order" level xxx
8528 String s = msg.getData().getString("s");
8529 NavitGraphics.CallbackMessageChannel(57, s);
8530 }
8531 else if (msg.getData().getInt("Callback") == 58)
8532 {
8533 // street search radius factor (multiplier)
8534 String s = msg.getData().getString("s");
8535 NavitGraphics.CallbackMessageChannel(58, s);
8536 }
8537 else if (msg.getData().getInt("Callback") == 59)
8538 {
8539 // enable layer "name"
8540 String s = msg.getData().getString("s");
8541 NavitGraphics.CallbackMessageChannel(59, s);
8542 }
8543 else if (msg.getData().getInt("Callback") == 60)
8544 {
8545 // disable layer "name"
8546 String s = msg.getData().getString("s");
8547 NavitGraphics.CallbackMessageChannel(60, s);
8548 }
8549 else if (msg.getData().getInt("Callback") == 61)
8550 {
8551 // zoom to specific zoomlevel at given point as center
8552 // pixel-x#pixel-y#zoom-level
8553 String s = msg.getData().getString("s");
8554 NavitGraphics.CallbackMessageChannel(61, s);
8555 }
8556 else if (msg.getData().getInt("Callback") == 62)
8557 {
8558 // disable map drawing
8559 NavitGraphics.CallbackMessageChannel(62, "");
8560 }
8561 else if (msg.getData().getInt("Callback") == 63)
8562 {
8563 // enable map drawing
8564 NavitGraphics.CallbackMessageChannel(63, "");
8565 }
8566 else if (msg.getData().getInt("Callback") == 64)
8567 {
8568 // draw map
8569 NavitGraphics.CallbackMessageChannel(64, "");
8570 }
8571 else if (msg.getData().getInt("Callback") == 65)
8572 {
8573 // draw map async
8574 NavitGraphics.CallbackMessageChannel(65, "");
8575 }
8576 else if (msg.getData().getInt("Callback") == 66)
8577 {
8578 // enable "multipolygons"
8579 NavitGraphics.CallbackMessageChannel(66, "");
8580 }
8581 else if (msg.getData().getInt("Callback") == 67)
8582 {
8583 // disable "multipolygons"
8584 NavitGraphics.CallbackMessageChannel(67, "");
8585 }
8586 else if (msg.getData().getInt("Callback") == 68)
8587 {
8588 // shift "order" by this value (only for drawing objects)
8589 String s = msg.getData().getString("s");
8590 NavitGraphics.CallbackMessageChannel(68, s);
8591 }
8592 else if (msg.getData().getInt("Callback") == 69)
8593 {
8594 // stop drawing map
8595 NavitGraphics.CallbackMessageChannel(69, "");
8596 }
8597 else if (msg.getData().getInt("Callback") == 70)
8598 {
8599 // allow drawing map
8600 NavitGraphics.CallbackMessageChannel(70, "");
8601 }
8602 else if (msg.getData().getInt("Callback") == 71)
8603 {
8604 // activate/deactivate "route graph" display
8605 // 0 -> deactivate
8606 // 1 -> activate
8607 String s = msg.getData().getString("s");
8608 NavitGraphics.CallbackMessageChannel(71, s);
8609 }
8610 else if (msg.getData().getInt("Callback") == 72)
8611 {
8612 // update the route path and route graph (e.g. after setting new roadblocks)
8613 // does not update destinations!!!
8614 NavitGraphics.CallbackMessageChannel(72, "");
8615 }
8616 else if (msg.getData().getInt("Callback") == 73)
8617 {
8618 // update the route path and route graph (e.g. after setting new roadblocks)
8619 // this destroys the route graph and calcs everything totally new!
8620 NavitGraphics.CallbackMessageChannel(73, "");
8621 }
8622
8623 else if (msg.getData().getInt("Callback") == 74)
8624 {
8625 // allow demo vechile to move
8626 NavitGraphics.CallbackMessageChannel(74, "");
8627 }
8628 else if (msg.getData().getInt("Callback") == 75)
8629 {
8630 // stop demo vechile
8631 NavitGraphics.CallbackMessageChannel(75, "");
8632 }
8633 else if (msg.getData().getInt("Callback") == 76)
8634 {
8635 // show route rectangles
8636 NavitGraphics.CallbackMessageChannel(76, "");
8637 }
8638 else if (msg.getData().getInt("Callback") == 77)
8639 {
8640 // do not show route rectangles
8641 NavitGraphics.CallbackMessageChannel(77, "");
8642 }
8643 else if (msg.getData().getInt("Callback") == 78)
8644 {
8645 // shift layout "order" values
8646 String s = msg.getData().getString("s");
8647 NavitGraphics.CallbackMessageChannel(78, s);
8648 }
8649 else if (msg.getData().getInt("Callback") == 79)
8650 {
8651 // set traffic light delay/cost
8652 String s = msg.getData().getString("s");
8653 NavitGraphics.CallbackMessageChannel(79, s);
8654 }
8655 else if (msg.getData().getInt("Callback") == 80)
8656 {
8657 // set autozoom flag to 0 or 1
8658 String s = msg.getData().getString("s");
8659 NavitGraphics.CallbackMessageChannel(80, s);
8660 }
8661 else if (msg.getData().getInt("Callback") == 81)
8662 {
8663 // resize layout items by factor
8664 String s = msg.getData().getString("s");
8665 NavitGraphics.CallbackMessageChannel(81, s);
8666 }
8667 else if (msg.getData().getInt("Callback") == 82)
8668 {
8669 // report share dir
8670 String s = msg.getData().getString("s");
8671 NavitGraphics.CallbackMessageChannel(82, s);
8672 }
8673 else if (msg.getData().getInt("Callback") == 83)
8674 {
8675 // spill all the index files to log output
8676 NavitGraphics.CallbackMessageChannel(83, "");
8677 }
8678 else if (msg.getData().getInt("Callback") == 84)
8679 {
8680 // report data dir
8681 String s = msg.getData().getString("s");
8682 NavitGraphics.CallbackMessageChannel(84, s);
8683 }
8684 else if (msg.getData().getInt("Callback") == 85)
8685 {
8686 // C linedrawing flag
8687 String s = msg.getData().getString("s");
8688 NavitGraphics.CallbackMessageChannel(85, s);
8689 }
8690 else if (msg.getData().getInt("Callback") == 86)
8691 {
8692 // avoid sharp turns flag to 0 or 1
8693 String s = msg.getData().getString("s");
8694 NavitGraphics.CallbackMessageChannel(86, s);
8695 }
8696 else if (msg.getData().getInt("Callback") == 87)
8697 {
8698 // // avoid sharp turns minimum angle. if turn is harder than this angle then set penalty
8699 String s = msg.getData().getString("s");
8700 NavitGraphics.CallbackMessageChannel(87, s);
8701 }
8702 else if (msg.getData().getInt("Callback") == 88)
8703 {
8704 // avoid sharp turns penalty
8705 String s = msg.getData().getString("s");
8706 NavitGraphics.CallbackMessageChannel(88, s);
8707 }
8708 else if (msg.getData().getInt("Callback") == 89)
8709 {
8710 // search radius for housenumbers for streets
8711 String s = msg.getData().getString("s");
8712 NavitGraphics.CallbackMessageChannel(89, s);
8713 }
8714 else if (msg.getData().getInt("Callback") == 90)
8715 {
8716 // set vehicleprofile to value of string s ('car','bike')
8717 String s = msg.getData().getString("s");
8718 NavitGraphics.CallbackMessageChannel(90, s);
8719 }
8720 else if (msg.getData().getInt("Callback") == 91)
8721 {
8722 // change vehicle profile's roadprofile values
8723 String s = msg.getData().getString("s");
8724 NavitGraphics.CallbackMessageChannel(91, s);
8725 }
8726 else if (msg.getData().getInt("Callback") == 92)
8727 {
8728 // change vehicle profile's roadprofile values 2
8729 String s = msg.getData().getString("s");
8730 NavitGraphics.CallbackMessageChannel(92, s);
8731 }
8732 else if (msg.getData().getInt("Callback") == 93)
8733 {
8734 // change vehicle profile's roadprofile values 3
8735 String s = msg.getData().getString("s");
8736 NavitGraphics.CallbackMessageChannel(93, s);
8737 }
8738 else if (msg.getData().getInt("Callback") == 94)
8739 {
8740 // change priority for cycle lanes
8741 String s = msg.getData().getString("s");
8742 NavitGraphics.CallbackMessageChannel(94, s);
8743 }
8744 //else if (msg.getData().getInt("Callback") == 95)
8745 //{
8746 // // change priority for cycle tracks
8747 // String s = msg.getData().getString("s");
8748 // NavitGraphics.CallbackMessageChannel(95, s);
8749 //}
8750 else if (msg.getData().getInt("Callback") == 96)
8751 {
8752 // dump route to GPX file, "s" -> full pathname to output file
8753 String s = msg.getData().getString("s");
8754 NavitGraphics.CallbackMessageChannel(96, s);
8755 }
8756 else if (msg.getData().getInt("Callback") == 97)
8757 {
8758 // set positon to lat#lon#name
8759 String lat = msg.getData().getString("lat");
8760 String lon = msg.getData().getString("lon");
8761 String q = msg.getData().getString("q");
8762 NavitGraphics.CallbackMessageChannel(97, lat + "#" + lon + "#" + q);
8763 }
8764 else if (msg.getData().getInt("Callback") == 98)
8765 {
8766 // set connected_pref value
8767 String s = msg.getData().getString("s");
8768 NavitGraphics.CallbackMessageChannel(98, s);
8769 }
8770 else if (msg.getData().getInt("Callback") == 99)
8771 {
8772 // set angle_pref value
8773 String s = msg.getData().getString("s");
8774 NavitGraphics.CallbackMessageChannel(99, s);
8775 }
8776 else if (msg.getData().getInt("Callback") == 100)
8777 {
8778 // dump callbacks to log
8779 NavitGraphics.CallbackMessageChannel(100, "");
8780 }
8781 else if (msg.getData().getInt("Callback") == 101)
8782 {
8783 // set demo vehicle flag for tracking
8784 NavitGraphics.CallbackMessageChannel(101, "");
8785 }
8786 else if (msg.getData().getInt("Callback") == 102)
8787 {
8788 // set gpsfix flag
8789 String s = msg.getData().getString("s");
8790 NavitGraphics.CallbackMessageChannel(102, s);
8791 }
8792 else if (msg.getData().getInt("Callback") == 103)
8793 {
8794 // draw location of self (car) x% lower than screen center
8795 String s = msg.getData().getString("s");
8796 NavitGraphics.CallbackMessageChannel(103, s);
8797 }
8798 else if (msg.getData().getInt("Callback") == 104)
8799 {
8800 // send OVERSPILL_FACTOR to C-code
8801 String s;
8802 if (Navit.GFX_OVERSPILL)
8803 {
8804 s = "" + (OVERSPILL_FACTOR * 100);
8805 }
8806 else
8807 {
8808 s = "" + 100;
8809 }
8810
8811 NavitGraphics.CallbackMessageChannel(104, s);
8812 }
8813 else if (msg.getData().getInt("Callback") == 105)
8814 {
8815 // zoom to specific zoomlevel without redrawing the map!
8816 String s = msg.getData().getString("s");
8817 NavitGraphics.CallbackMessageChannel(105, s);
8818 }
8819 else if (msg.getData().getInt("Callback") == 106)
8820 {
8821 // factor for routing/road speed
8822 String s = msg.getData().getString("s");
8823 NavitGraphics.CallbackMessageChannel(106, s);
8824 }
8825 else if (msg.getData().getInt("Callback") == 107)
8826 {
8827 // level 0 announcement seconds
8828 String s = msg.getData().getString("s");
8829 NavitGraphics.CallbackMessageChannel(107, s);
8830 }
8831 else if (msg.getData().getInt("Callback") == 108)
8832 {
8833 // level 1 announcement seconds
8834 String s = msg.getData().getString("s");
8835 NavitGraphics.CallbackMessageChannel(108, s);
8836 }
8837 else if (msg.getData().getInt("Callback") == 109)
8838 {
8839 // level 2 announcement seconds
8840 String s = msg.getData().getString("s");
8841 NavitGraphics.CallbackMessageChannel(109, s);
8842 }
8843 else if (msg.getData().getInt("Callback") == 110)
8844 {
8845 // generic int option CallBack [<option name>:<option value "int">]
8846 String s = msg.getData().getString("s");
8847 NavitGraphics.CallbackMessageChannel(110, s);
8848 }
8849 else if (msg.getData().getInt("Callback") == 111)
8850 {
8851 // show real gps position on map
8852 String s = msg.getData().getString("s");
8853 NavitGraphics.CallbackMessageChannel(111, s);
8854 }
8855 else if (msg.getData().getInt("Callback") == 9901)
8856 {
8857 // if follow mode is on, then dont show freeview streetname
8858 //if (!Navit.PREF_follow_gps)
8859 //{
8860 // Navit.cwthr.CallbackGeoCalc2(1, 0, mCanvasWidth / 2, mCanvasHeight / 2);
8861 //}
8862 }
8863 else if (msg.getData().getInt("Callback") == 98001)
8864 {
8865 int id = msg.getData().getInt("id");
8866 int i = msg.getData().getInt("i");
8867 NavitGraphics.return_generic_int_real(id, i);
8868 }
8869 else if (msg.getData().getInt("Callback") == 9001)
8870 {
8871 NavitGraphics.busyspinner_.setVisibility(View.INVISIBLE);
8872 NavitGraphics.busyspinnertext_.setVisibility(View.INVISIBLE);
8873 }
8874 else if (msg.getData().getInt("Callback") == 9002)
8875 {
8876 NavitGraphics.busyspinner_.setVisibility(View.VISIBLE);
8877 NavitGraphics.busyspinnertext_.setVisibility(View.VISIBLE);
8878 }
8879
8880 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
8881 }
8882 };
8883
8884 public Handler progress_handler = new Handler()
8885 {
8886
8887 @SuppressLint("NewApi")
8888 public void handleMessage(Message msg)
8889 {
8890 switch (msg.what)
8891 {
8892 case 0:
8893 // dismiss dialog, remove dialog
8894 try
8895 {
8896 Log.e("Navit", "0: dismiss dialog num " + msg.getData().getInt("dialog_num"));
8897 }
8898 catch (Exception e)
8899 {
8900 e.printStackTrace();
8901 }
8902
8903 try
8904 {
8905 dismissDialog(msg.getData().getInt("dialog_num"));
8906 removeDialog(msg.getData().getInt("dialog_num"));
8907 }
8908 catch (Exception e)
8909 {
8910 }
8911
8912 // exit_code=0 -> OK, map was downloaded fine
8913 if (msg.getData().getInt("exit_code") == 0)
8914 {
8915 // try to use the new downloaded map (works fine now!)
8916 //Log.d("Navit", "instance count=" + Navit.getInstanceCount()); // where did this go to?
8917
8918 // **** onStop();
8919 // **** onCreate(getIntent().getExtras());
8920
8921 String this_map_name = "map";
8922 try
8923 {
8924 this_map_name = msg.getData().getString("map_name");
8925 }
8926 catch (Exception e)
8927 {
8928 }
8929
8930 // reload sdcard maps
8931 Message msg2 = new Message();
8932 Bundle b2 = new Bundle();
8933 b2.putInt("Callback", 18);
8934 msg2.setData(b2);
8935 NavitGraphics.callback_handler.sendMessage(msg2);
8936
8937 // ----- service stop -----
8938 // ----- service stop -----
8939 Navit.getBaseContext_.stopService(Navit.ZANaviMapDownloaderServiceIntent);
8940 // ----- service stop -----
8941 // ----- service stop -----
8942
8943 try
8944 {
8945 // show notification that map is ready
8946 String Notification_header = "ZANavi";
8947 String Notification_text = this_map_name + " ready";
8948
8949 NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
8950 Notification notification = new Notification(R.drawable.icon, "ZANavi download finished", System.currentTimeMillis());
8951 notification.flags = Notification.FLAG_AUTO_CANCEL;
8952 Intent in = new Intent();
8953 in.setClass(getBaseContext_, Navit.class);
8954 in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
8955 PendingIntent p_activity = PendingIntent.getActivity(getBaseContext_, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
8956 notification.setLatestEventInfo(getBaseContext_, Notification_header, Notification_text, p_activity);
8957
8958 try
8959 {
8960 nm.notify(ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2, notification);
8961 }
8962 catch (Exception e)
8963 {
8964 e.printStackTrace();
8965
8966 try
8967 {
8968 p_activity = PendingIntent.getActivity(getBaseContext_, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
8969
8970 notification.setLatestEventInfo(getBaseContext_, Notification_header, Notification_text, p_activity);
8971 nm.notify(ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2, notification);
8972 }
8973 catch (Exception e2)
8974 {
8975 e2.printStackTrace();
8976 }
8977 }
8978 }
8979 catch (Exception e)
8980 {
8981 e.printStackTrace();
8982 }
8983
8984 zoom_out_full();
8985
8986 /*
8987 * Intent intent = getIntent();
8988 * System.out.println("ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ**********************");
8989 * startActivity(intent);
8990 * System.out.println("FFFFFFFFFFFFFFFFFFF**********************");
8991 * Log.d("Navit", "instance count=" + Navit.getInstanceCount());
8992 * onStop();
8993 * System.out.println("HHHHHHHHHHHHHHHHHHH**********************");
8994 */
8995
8996 //Message msg2 = new Message();
8997 //Bundle b2 = new Bundle();
8998 //b2.putInt("Callback", 6);
8999 //msg2.setData(b2);
9000 //N_NavitGraphics.callback_handler.sendMessage(msg2);
9001 }
9002 else
9003 {
9004 // there was a problem downloading the map
9005 // ----- service stop -----
9006 // ----- service stop -----
9007 Navit.getBaseContext_.stopService(Navit.ZANaviMapDownloaderServiceIntent);
9008 // ----- service stop -----
9009 // ----- service stop -----
9010
9011 String this_map_name = "map";
9012 try
9013 {
9014 this_map_name = msg.getData().getString("map_name");
9015 }
9016 catch (Exception e)
9017 {
9018 }
9019
9020 try
9021 {
9022
9023 // show notification that there was a download problem
9024 String Notification_header = "ZANavi";
9025 String Notification_text = "ERROR while downloading " + this_map_name;
9026
9027 NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
9028 Notification notification = new Notification(R.drawable.icon, "ZANavi download ERROR", System.currentTimeMillis());
9029 notification.flags = Notification.FLAG_AUTO_CANCEL;
9030 Intent in = new Intent();
9031 in.setClass(getBaseContext_, Navit.class);
9032 in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
9033 PendingIntent p_activity = PendingIntent.getActivity(getBaseContext_, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
9034 notification.setLatestEventInfo(getBaseContext_, Notification_header, Notification_text, p_activity);
9035
9036 try
9037 {
9038 nm.notify(ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2, notification);
9039 // ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2++;
9040 // if (ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2 > 2000)
9041 // {
9042 // ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2 = 1001;
9043 // }
9044
9045 }
9046 catch (Exception e)
9047 {
9048 e.printStackTrace();
9049
9050 try
9051 {
9052 p_activity = PendingIntent.getActivity(getBaseContext_, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
9053
9054 notification.setLatestEventInfo(getBaseContext_, Notification_header, Notification_text, p_activity);
9055 nm.notify(ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2, notification);
9056 // ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2++;
9057 // if (ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2 > 2000)
9058 // {
9059 // ZANaviMapDownloaderService.NOTIFICATION_ID__DUMMY2 = 1001;
9060 // }
9061 }
9062 catch (Exception e2)
9063 {
9064 e2.printStackTrace();
9065 }
9066 }
9067 }
9068 catch (Exception e)
9069 {
9070 e.printStackTrace();
9071 }
9072 }
9073 break;
9074 case 1:
9075 // change progressbar values
9076 try
9077 {
9078 int what_dialog = msg.getData().getInt("dialog_num");
9079 if (what_dialog == MAPDOWNLOAD_PRI_DIALOG)
9080 {
9081 mapdownloader_dialog_pri.setMax(msg.getData().getInt("max"));
9082 mapdownloader_dialog_pri.setProgress(msg.getData().getInt("cur"));
9083 mapdownloader_dialog_pri.setTitle(msg.getData().getString("title"));
9084 mapdownloader_dialog_pri.setMessage(msg.getData().getString("text"));
9085 }
9086 else if (what_dialog == MAPDOWNLOAD_SEC_DIALOG)
9087 {
9088 mapdownloader_dialog_sec.setMax(msg.getData().getInt("max"));
9089 mapdownloader_dialog_sec.setProgress(msg.getData().getInt("cur"));
9090 mapdownloader_dialog_sec.setTitle(msg.getData().getString("title"));
9091 mapdownloader_dialog_sec.setMessage(msg.getData().getString("text"));
9092 }
9093 }
9094 catch (Exception e)
9095 {
9096 }
9097 break;
9098 case 2:
9099 Toast.makeText(getApplicationContext(), msg.getData().getString("text"), Toast.LENGTH_SHORT).show();
9100 break;
9101 case 3:
9102 Toast.makeText(getApplicationContext(), msg.getData().getString("text"), Toast.LENGTH_LONG).show();
9103 break;
9104 case 10:
9105 // change values - generic
9106 try
9107 {
9108 int what_dialog_generic = msg.getData().getInt("dialog_num");
9109 if (what_dialog_generic == SEARCHRESULTS_WAIT_DIALOG)
9110 {
9111 search_results_wait.setMax(msg.getData().getInt("max"));
9112 search_results_wait.setProgress(msg.getData().getInt("cur"));
9113 search_results_wait.setTitle(msg.getData().getString("title"));
9114 search_results_wait.setMessage(msg.getData().getString("text"));
9115 }
9116 else if (what_dialog_generic == SEARCHRESULTS_WAIT_DIALOG_OFFLINE)
9117 {
9118 search_results_wait_offline.setMax(msg.getData().getInt("max"));
9119 search_results_wait_offline.setProgress(msg.getData().getInt("cur"));
9120 search_results_wait_offline.setTitle(msg.getData().getString("title"));
9121 search_results_wait_offline.setMessage(msg.getData().getString("text"));
9122 }
9123 }
9124 catch (Exception e)
9125 {
9126 }
9127 break;
9128 case 11:
9129 // show dialog - generic
9130 try
9131 {
9132 // just in case, remove the dialog if it should be shown already!
9133 dismissDialog(msg.getData().getInt("dialog_num"));
9134 removeDialog(msg.getData().getInt("dialog_num"));
9135 }
9136 catch (Exception e)
9137 {
9138 // System.out.println("Ex D1: " + e.toString());
9139 }
9140 showDialog(msg.getData().getInt("dialog_num"));
9141 break;
9142 case 12:
9143 // turn on compass
9144 turn_on_compass();
9145 break;
9146 case 13:
9147 // turn off compass
9148 turn_off_compass();
9149 break;
9150 case 14:
9151 // set used mem in textview
9152 show_mem_used_real();
9153 break;
9154 case 15:
9155 // set debug text line 3
9156 Navit.set_debug_messages3(msg.getData().getString("text"));
9157 break;
9158 case 16:
9159 // refresh NavitAndriodOverlay
9160 try
9161 {
9162 //Log.e("NavitGraphics", "xx 1");
9163 //System.out.println("invalidate 027");
9164 NavitGraphics.NavitAOverlay_s.invalidate();
9165 //Log.e("NavitGraphics", "xx 2");
9166 }
9167 catch (Exception e)
9168 {
9169 e.printStackTrace();
9170 }
9171 break;
9172 case 17:
9173 try
9174 {
9175
9176 generic_alert_box.setMessage(Navit.get_text("Possibly not enough space on your device!")).setPositiveButton(Navit.get_text("Ok"), new DialogInterface.OnClickListener() // TRANS
9177 {
9178 public void onClick(DialogInterface dialog, int id)
9179 {
9180 // Handle Ok
9181 }
9182 }).create();
9183 generic_alert_box.setCancelable(false);
9184 generic_alert_box.setTitle(Navit.get_text("device space")); // TRANS
9185 generic_alert_box.show();
9186 }
9187 catch (Exception e)
9188 {
9189 e.printStackTrace();
9190 }
9191 break;
9192 // case 18:
9193 // try
9194 // {
9195 // openOptionsMenu_wrapper();
9196 // }
9197 // catch (Exception e)
9198 // {
9199 // }
9200 // break;
9201 case 19:
9202 open_voice_recog_screen();
9203 break;
9204 case 20:
9205 dim_screen();
9206 break;
9207 case 21:
9208 default_brightness_screen();
9209 break;
9210 case 22:
9211 try
9212 {
9213 // ----- service start -----
9214 // ----- service start -----
9215 startService(Navit.ZANaviMapDownloaderServiceIntent);
9216 // ----- service start -----
9217 // ----- service start -----
9218
9219 // try
9220 // {
9221 // Thread.sleep(200);
9222 // }
9223 // catch (InterruptedException e)
9224 // {
9225 // }
9226
9227 // if (!ZANaviMapDownloaderService.service_running)
9228 // {
9229 // System.out.println("ZANaviMapDownloaderService -> not running yet ...");
9230 // try
9231 // {
9232 // Thread.sleep(2000);
9233 // }
9234 // catch (InterruptedException e)
9235 // {
9236 // }
9237 // }
9238 //
9239 // if (!ZANaviMapDownloaderService.service_running)
9240 // {
9241 // System.out.println("ZANaviMapDownloaderService -> not running yet ...");
9242 // try
9243 // {
9244 // Thread.sleep(2000);
9245 // }
9246 // catch (InterruptedException e)
9247 // {
9248 // }
9249 // }
9250
9251 // -------- // ZANaviMapDownloaderService.start_map_download();
9252 }
9253 catch (Exception e)
9254 {
9255 e.printStackTrace();
9256 }
9257 break;
9258 case 23:
9259
9260 // show actionbar download icon
9261 try
9262 {
9263 // show download actionbar icon
9264 //cur_menu.findItem(R.id.item_download_menu_button).setTitle("");
9265 actionabar_download_icon_visible = true;
9266 cur_menu.findItem(R.id.item_download_menu_button).setVisible(true);
9267 //cur_menu.findItem(R.id.item_download_menu_button).setEnabled(true);
9268 // ****** // cur_menu.findItem(R.id.item_download_menu_button).setIcon(R.drawable.anim_download_icon);
9269 // cur_menu.findItem(R.id.item_download_menu_button).setIcon((Drawable) null);
9270 }
9271 catch (Exception e)
9272 {
9273 e.printStackTrace();
9274 }
9275
9276 try
9277 {
9278 show_status_bar();
9279 getSupportActionBar().setDisplayShowTitleEnabled(true);
9280 }
9281 catch (Exception e)
9282 {
9283 e.printStackTrace();
9284 }
9285
9286 // try
9287 // {
9288 // View menuItemView = findViewById(R.id.item_download_menu_button);
9289 // menuItemView.setBackgroundResource(R.drawable.anim_download_icon_2);
9290 // // menuItemView.setOnClickListener(new View.OnClickListener()
9291 // // {
9292 // // public void onClick(View v)
9293 // // {
9294 // // try
9295 // // {
9296 // // //menuItemView.setBackgroundResource(R.drawable.anim_download_icon_1);
9297 // // //AnimationDrawable frameAnimation = (AnimationDrawable) menuItemView.getBackground();
9298 // // //frameAnimation.start();
9299 // // // menuItemView.setAlpha(100);
9300 // // View menuItemView = findViewById(R.id.item_download_menu_button);
9301 // // menuItemView.setBackgroundResource(R.drawable.anim_download_icon_1);
9302 // //
9303 // // System.out.println("download icon pressed(2)");
9304 // //
9305 // // Intent mapdownload_cancel_activity = new Intent(Navit.getBaseContext_, ZANaviDownloadMapCancelActivity.class);
9306 // // mapdownload_cancel_activity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
9307 // // startActivity(mapdownload_cancel_activity);
9308 // //
9309 // // new Handler().postDelayed(new Runnable()
9310 // // {
9311 // // @Override
9312 // // public void run()
9313 // // {
9314 // // if (Navit.cur_menu.findItem(R.id.item_download_menu_button).isVisible())
9315 // // {
9316 // // View menuItemView = findViewById(R.id.item_download_menu_button);
9317 // // menuItemView.setBackgroundResource(R.drawable.anim_download_icon_2);
9318 // // AnimationDrawable frameAnimation = (AnimationDrawable) menuItemView.getBackground();
9319 // // frameAnimation.start();
9320 // // }
9321 // // }
9322 // // }, 50);
9323 // // }
9324 // // catch (Exception e)
9325 // // {
9326 // // }
9327 // // }
9328 // // });
9329 // AnimationDrawable frameAnimation = (AnimationDrawable) menuItemView.getBackground();
9330 // frameAnimation.start();
9331 // }
9332 // catch (Exception e)
9333 // {
9334 // e.printStackTrace();
9335 // }
9336
9337 break;
9338 case 24:
9339 // hide actionbar download icon
9340
9341 // try
9342 // {
9343 // View menuItemView = findViewById(R.id.item_download_menu_button);
9344 // menuItemView.setBackground((Drawable) null);
9345 //
9346 // new Handler().postDelayed(new Runnable()
9347 // {
9348 // @Override
9349 // public void run()
9350 // {
9351 // if (Navit.cur_menu.findItem(R.id.item_download_menu_button).isVisible())
9352 // {
9353 // View menuItemView = findViewById(R.id.item_download_menu_button);
9354 // menuItemView.setBackground((Drawable) null);
9355 // }
9356 // }
9357 // }, 50);
9358 // }
9359 // catch (Exception e)
9360 // {
9361 // e.printStackTrace();
9362 // }
9363
9364 try
9365 {
9366 // hide download actionbar icon
9367 actionabar_download_icon_visible = false;
9368 cur_menu.findItem(R.id.item_download_menu_button).setVisible(false);
9369 //cur_menu.findItem(R.id.item_download_menu_button).setEnabled(false);
9370 // cur_menu.findItem(R.id.item_download_menu_button).setIcon((Drawable) null);
9371 }
9372 catch (Exception e)
9373 {
9374 e.printStackTrace();
9375 }
9376
9377 try
9378 {
9379 getSupportActionBar().setDisplayShowTitleEnabled(false);
9380 }
9381 catch (Exception e)
9382 {
9383 e.printStackTrace();
9384 }
9385
9386 try
9387 {
9388 hide_status_bar();
9389 }
9390 catch (Exception e)
9391 {
9392 e.printStackTrace();
9393 }
9394
9395 break;
9396 case 25:
9397 // Log.e("Navit", "nav: 25");
9398 NavitGraphics.deactivate_nav_wakelock_real();
9399 break;
9400 case 26:
9401 // Log.e("Navit", "nav: 26");
9402 NavitGraphics.activate_nav_wakelock_real();
9403 break;
9404 case 27:
9405 show_status_bar();
9406 break;
9407 case 28:
9408 hide_status_bar();
9409 break;
9410 case 29:
9411 invalidateOptionsMenu();
9412 break;
9413 case 30:
9414 try
9415 {
9416 NavitGraphics.NavitMsgTv2_.append(msg.getData().getString("text"));
9417 }
9418 catch (Exception e)
9419 {
9420 e.printStackTrace();
9421 }
9422 break;
9423 case 31:
9424 try
9425 {
9426 // map download menu
9427 Intent map_download_list_activity = new Intent(getBaseContext_, NavitDownloadSelectMapActivity.class);
9428 startActivityForResult(map_download_list_activity, Navit.NavitDownloaderPriSelectMap_id);
9429 }
9430 catch (Exception e)
9431 {
9432 e.printStackTrace();
9433 }
9434 break;
9435 case 32:
9436 try
9437 {
9438 if (p.PREF_follow_gps)
9439 {
9440 push_pin_view.setImageResource(R.drawable.pin1_down);
9441 }
9442 else
9443 {
9444 push_pin_view.setImageResource(R.drawable.pin1_up);
9445 }
9446 }
9447 catch (Exception e)
9448 {
9449 e.printStackTrace();
9450 }
9451 break;
9452 case 33:
9453 if (road_book != null)
9454 {
9455 if (road_book_items != null)
9456 {
9457 try
9458 {
9459 // send new roadbook items to fragment and reload it
9460 road_book.reload_items(road_book_items);
9461 }
9462 catch (Exception e)
9463 {
9464 }
9465 }
9466 }
9467 break;
9468 case 34:
9469 // show bubble
9470 NavitGraphics.whats_here_container_wrap.setVisibility(View.VISIBLE);
9471 NavitGraphics.whats_here_text.setText(" " + Navit.get_text("loading ...") + " ");
9472 break;
9473 case 35:
9474 // hide bubble
9475 NavitGraphics.whats_here_container_wrap.setVisibility(View.INVISIBLE);
9476 NavitGraphics.whats_here_text.setText(" " + Navit.get_text("loading ...") + " ");
9477 // and move out of screen
9478
9479 if (!Navit.PAINT_OLD_API)
9480 {
9481 NavitGraphics.whats_here_container_wrap.setX(-2000);
9482 NavitGraphics.whats_here_container_wrap.setY(-2000);
9483 // NavitGraphics.whats_here_container_wrap.requestLayout();
9484
9485 NavitGraphics.whats_here_pointer_image.setX(0);
9486 }
9487 else
9488 {
9489 NavitGraphics.params_whats_here_container_wrap = (android.widget.RelativeLayout.LayoutParams) NavitGraphics.whats_here_container_wrap.getLayoutParams();
9490 NavitGraphics.params_whats_here_container_wrap.leftMargin = -2000;
9491 NavitGraphics.params_whats_here_container_wrap.topMargin = -2000;
9492 NavitGraphics.whats_here_container_wrap.setLayoutParams(NavitGraphics.params_whats_here_container_wrap);
9493 NavitGraphics.whats_here_container_wrap.requestLayout();
9494
9495 NavitGraphics.params_whats_here_pointer_image = (RelativeLayout.LayoutParams) NavitGraphics.whats_here_pointer_image.getLayoutParams();
9496 // NavitGraphics.params_whats_here_pointer_image.leftMargin = 0;
9497 NavitGraphics.whats_here_pointer_image.setLayoutParams(NavitGraphics.params_whats_here_pointer_image);
9498 NavitGraphics.whats_here_pointer_image.requestLayout();
9499
9500 }
9501 break;
9502 case 36:
9503 // move bubble to x,y
9504 int width_in_px = getResources().getDimensionPixelSize(R.dimen.whats_here_container_width);
9505 int new_x = NavitGraphics.NavitAOverlay_s.bubble_001.x;
9506 int new_diff = 0;
9507 if ((NavitGraphics.NavitAOverlay_s.bubble_001.x + width_in_px) > NavitGraphics.mCanvasWidth)
9508 {
9509 new_diff = (NavitGraphics.NavitAOverlay_s.bubble_001.x + width_in_px) - NavitGraphics.mCanvasWidth;
9510 new_x = NavitGraphics.NavitAOverlay_s.bubble_001.x - ((NavitGraphics.NavitAOverlay_s.bubble_001.x + width_in_px) - NavitGraphics.mCanvasWidth);
9511 }
9512
9513 new_x = new_x - NavitGraphics.dp_to_px(17);
9514
9515 if (!Navit.PAINT_OLD_API)
9516 {
9517 NavitGraphics.whats_here_container_wrap.setX(new_x);
9518 NavitGraphics.whats_here_container_wrap.setY(NavitGraphics.NavitAOverlay_s.bubble_001.y + NavitGraphics.dp_to_px(17));
9519 // NavitGraphics.whats_here_container_wrap.requestLayout();
9520
9521 NavitGraphics.whats_here_pointer_image.setX(new_diff);
9522 }
9523 else
9524 {
9525 NavitGraphics.params_whats_here_container_wrap = (android.widget.RelativeLayout.LayoutParams) NavitGraphics.whats_here_container_wrap.getLayoutParams();
9526 NavitGraphics.params_whats_here_container_wrap.leftMargin = new_x;
9527 NavitGraphics.params_whats_here_container_wrap.topMargin = NavitGraphics.NavitAOverlay_s.bubble_001.y - NavitGraphics.whats_here_container_wrap.getHeight() + NavitGraphics.dp_to_px(17);
9528 NavitGraphics.whats_here_container_wrap.setLayoutParams(NavitGraphics.params_whats_here_container_wrap);
9529 NavitGraphics.whats_here_container_wrap.requestLayout();
9530
9531 NavitGraphics.params_whats_here_pointer_image = (RelativeLayout.LayoutParams) NavitGraphics.whats_here_pointer_image.getLayoutParams();
9532 // NavitGraphics.params_whats_here_pointer_image.leftMargin = (NavitGraphics.NavitAOverlay_s.bubble_001.x + width_in_px) - NavitGraphics.mCanvasWidth;
9533 NavitGraphics.whats_here_pointer_image.setLayoutParams(NavitGraphics.params_whats_here_pointer_image);
9534 NavitGraphics.whats_here_pointer_image.requestLayout();
9535 }
9536 break;
9537 case 37:
9538 // set text for point on screen
9539 String dest_name = "Point on Screen";
9540
9541 try
9542 {
9543 if (Navit.GFX_OVERSPILL)
9544 {
9545 dest_name = NavitGraphics.CallbackGeoCalc(8, (NavitGraphics.NavitAOverlay_s.bubble_001.x + NavitGraphics.mCanvasWidth_overspill) * NavitGraphics.Global_dpi_factor, (NavitGraphics.NavitAOverlay_s.bubble_001.y + NavitGraphics.mCanvasHeight_overspill) * NavitGraphics.Global_dpi_factor);
9546 }
9547 else
9548 {
9549 dest_name = NavitGraphics.CallbackGeoCalc(8, NavitGraphics.NavitAOverlay_s.bubble_001.x * NavitGraphics.Global_dpi_factor, NavitGraphics.NavitAOverlay_s.bubble_001.y * NavitGraphics.Global_dpi_factor);
9550 }
9551
9552 if ((dest_name.equals(" ")) || (dest_name == null))
9553 {
9554 dest_name = "Point on Screen";
9555 }
9556 }
9557 catch (Exception e)
9558 {
9559 e.printStackTrace();
9560 }
9561
9562 NavitGraphics.whats_here_text.setText(dest_name);
9563 break;
9564 case 38:
9565 try
9566 {
9567 NavitAddressSearchActivity.adapter.clear();
9568 NavitAddressSearchActivity.adapter.notifyDataSetChanged();
9569 // NavitAddressSearchActivity.listview.postInvalidate();
9570 }
9571 catch (Exception e)
9572 {
9573 System.out.println("AAEE:001");
9574 }
9575 break;
9576 case 39:
9577 try
9578 {
9579 NavitAddressSearchActivity.adapter.notifyDataSetChanged();
9580 }
9581 catch (Exception e)
9582 {
9583 System.out.println("AAEE:008");
9584 }
9585 break;
9586 case 99:
9587 // dismiss dialog, remove dialog - generic
9588 try
9589 {
9590 Log.e("Navit", "99: dismiss dialog num " + msg.getData().getInt("dialog_num"));
9591 }
9592 catch (Exception e)
9593 {
9594 e.printStackTrace();
9595 }
9596 try
9597 {
9598 dismissDialog(msg.getData().getInt("dialog_num"));
9599 }
9600 catch (Exception e)
9601 {
9602 e.printStackTrace();
9603 }
9604 try
9605 {
9606 removeDialog(msg.getData().getInt("dialog_num"));
9607 }
9608 catch (Exception e)
9609 {
9610 e.printStackTrace();
9611 }
9612 break;
9613 }
9614 }
9615 };
9616
9617 @TargetApi(Build.VERSION_CODES.FROYO)
9618 protected Dialog onCreateDialog(int id)
9619 {
9620 switch (id)
9621 {
9622 case Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE:
9623 search_results_wait_offline = new ProgressDialog(this);
9624 search_results_wait_offline.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
9625 search_results_wait_offline.setTitle("--");
9626 search_results_wait_offline.setMessage("--");
9627 search_results_wait_offline.setCancelable(true); // allow to stop search
9628 search_results_wait_offline.setProgress(0);
9629 search_results_wait_offline.setMax(10);
9630
9631 search_results_wait_offline.setOnCancelListener(new OnCancelListener()
9632 {
9633 public void onCancel(DialogInterface dialog)
9634 {
9635 Message msg = new Message();
9636 Bundle b = new Bundle();
9637 b.putInt("Callback", 46);
9638 msg.setData(b);
9639 try
9640 {
9641 NavitGraphics.callback_handler.sendMessage(msg);
9642 }
9643 catch (Exception e)
9644 {
9645 }
9646 Log.e("Navit", "onCancel: search_results_wait offline");
9647 }
9648 });
9649
9650 /*
9651 * search_results_wait.setButton("stop", new DialogInterface.OnClickListener()
9652 * {
9653 * public void onClick(DialogInterface dialog, int which)
9654 * {
9655 * // Use either finish() or return() to either close the activity or just the dialog
9656 * return;
9657 * }
9658 * });
9659 */
9660
9661 DialogInterface.OnDismissListener mOnDismissListener4 = new DialogInterface.OnDismissListener()
9662 {
9663 public void onDismiss(DialogInterface dialog)
9664 {
9665 Log.e("Navit", "onDismiss: search_results_wait offline");
9666 dialog.dismiss();
9667 dialog.cancel();
9668 searchresultsThread_offline.stop_me();
9669 }
9670 };
9671 search_results_wait_offline.setOnDismissListener(mOnDismissListener4);
9672 searchresultsThread_offline = new SearchResultsThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
9673 searchresultsThread_offline.start();
9674
9675 NavitAddressSearchSpinnerActive = true;
9676 spinner_thread_offline = new SearchResultsThreadSpinnerThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
9677 spinner_thread_offline.start();
9678
9679 return search_results_wait_offline;
9680 case Navit.SEARCHRESULTS_WAIT_DIALOG:
9681 search_results_wait = new ProgressDialog(this);
9682 search_results_wait.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
9683 search_results_wait.setTitle("--");
9684 search_results_wait.setMessage("--");
9685 search_results_wait.setCancelable(false);
9686 search_results_wait.setProgress(0);
9687 search_results_wait.setMax(10);
9688
9689 DialogInterface.OnDismissListener mOnDismissListener3 = new DialogInterface.OnDismissListener()
9690 {
9691 public void onDismiss(DialogInterface dialog)
9692 {
9693 Log.e("Navit", "onDismiss: search_results_wait");
9694 dialog.dismiss();
9695 dialog.cancel();
9696 searchresultsThread.stop_me();
9697 }
9698 };
9699 search_results_wait.setOnDismissListener(mOnDismissListener3);
9700 searchresultsThread = new SearchResultsThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG);
9701 searchresultsThread.start();
9702
9703 NavitAddressSearchSpinnerActive = true;
9704 spinner_thread = new SearchResultsThreadSpinnerThread(progress_handler, Navit.SEARCHRESULTS_WAIT_DIALOG);
9705 spinner_thread.start();
9706
9707 return search_results_wait;
9708 case Navit.MAPDOWNLOAD_PRI_DIALOG:
9709 mapdownloader_dialog_pri = new ProgressDialog(this);
9710 mapdownloader_dialog_pri.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
9711 mapdownloader_dialog_pri.setTitle("--");
9712 mapdownloader_dialog_pri.setMessage("--");
9713 mapdownloader_dialog_pri.setCancelable(false);
9714 mapdownloader_dialog_pri.setCanceledOnTouchOutside(false);
9715 mapdownloader_dialog_pri.setProgress(0);
9716 mapdownloader_dialog_pri.setMax(200);
9717
9718 WindowManager.LayoutParams dialog_lparams = mapdownloader_dialog_pri.getWindow().getAttributes();
9719 dialog_lparams.screenBrightness = 0.1f;
9720 mapdownloader_dialog_pri.getWindow().setAttributes(dialog_lparams);
9721
9722 DialogInterface.OnDismissListener mOnDismissListener1 = new DialogInterface.OnDismissListener()
9723 {
9724 public void onDismiss(DialogInterface dialog)
9725 {
9726 android.view.WindowManager.LayoutParams dialog_lparams = mapdownloader_dialog_pri.getWindow().getAttributes();
9727 mapdownloader_dialog_pri.getWindow().setAttributes((WindowManager.LayoutParams) dialog_lparams);
9728 mapdownloader_dialog_pri.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
9729 mapdownloader_dialog_pri.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
9730 Log.e("Navit", "onDismiss: mapdownloader_dialog pri");
9731 dialog.dismiss();
9732 dialog.cancel();
9733 progressThread_pri.stop_thread();
9734 }
9735 };
9736
9737 try
9738 {
9739 mapdownloader_dialog_pri.setButton(AlertDialog.BUTTON_NEGATIVE, Navit.get_text("Cancel"), new DialogInterface.OnClickListener()
9740 {
9741 @Override
9742 public void onClick(DialogInterface dialog, int which)
9743 {
9744 mapdownloader_dialog_pri.dismiss();
9745 }
9746 });
9747 }
9748 catch (Exception e)
9749 {
9750 e.printStackTrace();
9751 }
9752
9753 mapdownloader_dialog_pri.setOnDismissListener(mOnDismissListener1);
9754 mapdownloader_pri = new NavitMapDownloader(this);
9755 progressThread_pri = mapdownloader_pri.new ProgressThread(progress_handler, NavitMapDownloader.z_OSM_MAPS[Navit.download_map_id], MAP_NUM_PRIMARY);
9756 progressThread_pri.start();
9757 //
9758 // show license for OSM maps
9759 //. TRANSLATORS: please only translate the first word "Map data" and leave the other words in english
9760 Toast.makeText(getApplicationContext(), Navit.get_text("Map data (c) OpenStreetMap contributors, CC-BY-SA"), Toast.LENGTH_SHORT).show(); //TRANS
9761 return mapdownloader_dialog_pri;
9762 case Navit.MAPDOWNLOAD_SEC_DIALOG:
9763 mapdownloader_dialog_sec = new ProgressDialog(this);
9764 mapdownloader_dialog_sec.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
9765 mapdownloader_dialog_sec.setTitle("--");
9766 mapdownloader_dialog_sec.setMessage("--");
9767
9768 mapdownloader_dialog_sec.setCancelable(true);
9769 mapdownloader_dialog_sec.setProgress(0);
9770 mapdownloader_dialog_sec.setMax(200);
9771 DialogInterface.OnDismissListener mOnDismissListener2 = new DialogInterface.OnDismissListener()
9772 {
9773 public void onDismiss(DialogInterface dialog)
9774 {
9775 Log.e("Navit", "onDismiss: mapdownloader_dialog sec");
9776 dialog.dismiss();
9777 dialog.cancel();
9778 progressThread_sec.stop_thread();
9779 }
9780 };
9781 mapdownloader_dialog_sec.setOnDismissListener(mOnDismissListener2);
9782 mapdownloader_sec = new NavitMapDownloader(this);
9783 progressThread_sec = mapdownloader_sec.new ProgressThread(progress_handler, NavitMapDownloader.z_OSM_MAPS[Navit.download_map_id], MAP_NUM_SECONDARY);
9784 progressThread_sec.start();
9785 //
9786 // show license for OSM maps
9787 //. TRANSLATORS: please only translate the first word "Map data" and leave the other words in english
9788 Toast.makeText(getApplicationContext(), Navit.get_text("Map data (c) OpenStreetMap contributors, CC-BY-SA"), Toast.LENGTH_SHORT).show(); //TRANS
9789 return mapdownloader_dialog_sec;
9790 }
9791 // should never get here!!
9792 return null;
9793 }
9794
9795 public void disableSuspend()
9796 {
9797 // wl.acquire();
9798 // wl.release();
9799 }
9800
9801 public void exit2()
9802 {
9803 System.out.println("in exit2");
9804 }
9805
9806 public void exit()
9807 {
9808 try
9809 {
9810 if (toneG != null)
9811 {
9812 toneG.stopTone();
9813 toneG.release();
9814
9815 }
9816 }
9817 catch (Exception e)
9818 {
9819 }
9820
9821 NavitVehicle.turn_off_all_providers();
9822 //try
9823 //{
9824 // NavitSpeech.stop_me();
9825 //}
9826 //catch (Exception s)
9827 //{
9828 // s.printStackTrace();
9829 //}
9830
9831 try
9832 {
9833 mTts.stop();
9834 }
9835 catch (Exception e)
9836 {
9837
9838 }
9839
9840 try
9841 {
9842 mTts.shutdown();
9843 }
9844 catch (Exception e)
9845 {
9846
9847 }
9848 mTts = null;
9849
9850 try
9851 {
9852 try
9853 {
9854 plugin_api.removeListener(zclientListener);
9855 }
9856 catch (Exception e)
9857 {
9858 e.printStackTrace();
9859 Log.i("NavitPlugin", "Failed to remove Listener", e);
9860 }
9861 unbindService(serviceConnection);
9862 Log.i("NavitPlugin", "Unbind from the service");
9863 }
9864 catch (Throwable t)
9865 {
9866 // catch any issues, typical for destroy routines
9867 // even if we failed to destroy something, we need to continue destroying
9868 Log.i("NavitPlugin", "Failed to unbind from the service", t);
9869 }
9870
9871 try
9872 {
9873 if (wl_navigating != null)
9874 {
9875 //if (wl_navigating.isHeld())
9876 //{
9877 wl_navigating.release();
9878 Log.e("Navit", "WakeLock Nav: release 1");
9879 //}
9880 }
9881 }
9882 catch (Exception e)
9883 {
9884 e.printStackTrace();
9885 }
9886
9887 Log.e("Navit", "1***************** exit called ****************");
9888 Log.e("Navit", "2***************** exit called ****************");
9889 Log.e("Navit", "3***************** exit called ****************");
9890 Log.e("Navit", "4***************** exit called ****************");
9891 Log.e("Navit", "5***************** exit called ****************");
9892 Log.e("Navit", "6***************** exit called ****************");
9893 Log.e("Navit", "7***************** exit called ****************");
9894 Log.e("Navit", "8***************** exit called ****************");
9895
9896 // try
9897 // {
9898 // // hide download actionbar icon
9899 // Navit.cur_menu.findItem(R.id.item_download_menu_button).setVisible(false);
9900 // Navit.cur_menu.findItem(R.id.item_download_menu_button).setEnabled(false);
9901 // }
9902 // catch (Exception e)
9903 // {
9904 // }
9905
9906 // ----- service stop -----
9907 // ----- service stop -----
9908 System.out.println("Navit:exit -> stop ZANaviMapDownloaderService ---------");
9909 ZANaviMapDownloaderService.stop_downloading();
9910 stopService(Navit.ZANaviMapDownloaderServiceIntent);
9911 // ----- service stop -----
9912 // ----- service stop -----
9913
9914 // +++++ // System.gc();
9915 NavitActivity(-4);
9916 Log.e("Navit", "XX1***************** exit called ****************");
9917 finish();
9918 Log.e("Navit", "XX2***************** exit called ****************");
9919 System.runFinalizersOnExit(true);
9920 Log.e("Navit", "XX3***************** exit called ****************");
9921 System.exit(0);
9922 Log.e("Navit", "XX4***************** exit called ****************");
9923 }
9924
9925 public boolean handleMessage(Message m)
9926 {
9927 //Log.e("Navit", "Handler received message");
9928 return true;
9929 }
9930
9931 public static void set_2d3d_mode_in_settings()
9932 {
9933 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
9934 SharedPreferences.Editor editor = prefs.edit();
9935 editor.putBoolean("show_3d_map", p.PREF_show_3d_map);
9936 editor.commit();
9937 }
9938
9939 public static void follow_button_on()
9940 {
9941 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
9942 SharedPreferences.Editor editor = prefs.edit();
9943 Navit.follow_current = Navit.follow_on;
9944 p.PREF_follow_gps = true;
9945 editor.putBoolean("follow_gps", p.PREF_follow_gps);
9946 editor.commit();
9947
9948 // hold all map drawing -----------
9949 Message msg = new Message();
9950 Bundle b = new Bundle();
9951 b.putInt("Callback", 69);
9952 msg.setData(b);
9953 try
9954 {
9955 NavitGraphics.callback_handler.sendMessage(msg);
9956 }
9957 catch (Exception e)
9958 {
9959 e.printStackTrace();
9960 }
9961 // hold all map drawing -----------
9962
9963 msg = Navit_progress_h.obtainMessage();
9964 b = new Bundle();
9965 msg.what = 32;
9966 try
9967 {
9968 Navit_progress_h.sendMessage(msg);
9969 }
9970 catch (Exception e)
9971 {
9972 }
9973
9974 getPrefs();
9975 activatePrefs(1);
9976
9977 // follow mode ON -----------
9978 msg = new Message();
9979 b = new Bundle();
9980 b.putInt("Callback", 74);
9981 msg.setData(b);
9982 try
9983 {
9984 NavitGraphics.callback_handler.sendMessage(msg);
9985 }
9986 catch (Exception e)
9987 {
9988 e.printStackTrace();
9989 }
9990 // follow mode ON -----------
9991
9992 // allow all map drawing -----------
9993 msg = new Message();
9994 b = new Bundle();
9995 b.putInt("Callback", 70);
9996 msg.setData(b);
9997 try
9998 {
9999 NavitGraphics.callback_handler.sendMessage(msg);
10000 }
10001 catch (Exception e)
10002 {
10003 }
10004 // allow all map drawing -----------
10005
10006 NavitVehicle.set_last_known_pos_fast_provider();
10007
10008 // JB fix
10009 //NavitGraphics.NavitAOSDJava_.postInvalidate();
10010 //System.out.println("xx paint 12 xx");
10011 NavitGraphics.OSD_new.postInvalidate();
10012 NavitGraphics.NavitAOverlay_s.postInvalidate();
10013 }
10014
10015 public static void follow_button_off()
10016 {
10017 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10018 SharedPreferences.Editor editor = prefs.edit();
10019 Navit.follow_current = Navit.follow_off;
10020 p.PREF_follow_gps = false;
10021 editor.putBoolean("follow_gps", p.PREF_follow_gps);
10022 editor.commit();
10023 getPrefs();
10024 activatePrefs(1);
10025
10026 // follow mode OFF -----------
10027 Message msg = new Message();
10028 Bundle b = new Bundle();
10029 b.putInt("Callback", 75);
10030 msg.setData(b);
10031 try
10032 {
10033 NavitGraphics.callback_handler.sendMessage(msg);
10034 }
10035 catch (Exception e)
10036 {
10037 }
10038 // follow mode OFF -----------
10039
10040 msg = Navit_progress_h.obtainMessage();
10041 b = new Bundle();
10042 msg.what = 32;
10043 try
10044 {
10045 Navit_progress_h.sendMessage(msg);
10046 }
10047 catch (Exception e)
10048 {
10049 }
10050
10051 // JB fix
10052 //NavitGraphics.NavitAOSDJava_.postInvalidate();
10053 //System.out.println("xx paint 13 xx");
10054 NavitGraphics.OSD_new.postInvalidate();
10055 NavitGraphics.NavitAOverlay_s.postInvalidate();
10056
10057 }
10058
10059 public static void toggle_poi_pref()
10060 {
10061 // PREF_show_poi_on_map
10062 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10063 SharedPreferences.Editor editor = prefs.edit();
10064 if (p.PREF_show_poi_on_map)
10065 {
10066 p.PREF_show_poi_on_map = false;
10067 }
10068 else
10069 {
10070 p.PREF_show_poi_on_map = true;
10071 }
10072 editor.putBoolean("show_poi_on_map", p.PREF_show_poi_on_map);
10073 editor.commit();
10074 }
10075
10076 public static void toggle_follow_button()
10077 {
10078 // the "red needle" OSD calls this function only!!
10079 //Log.e("NavitVehicle", "toggle_follow_button");
10080 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10081 SharedPreferences.Editor editor = prefs.edit();
10082 if (p.PREF_follow_gps)
10083 {
10084 Navit.follow_current = Navit.follow_off;
10085 p.PREF_follow_gps = false;
10086
10087 // follow mode OFF -----------
10088 Message msg = new Message();
10089 Bundle b = new Bundle();
10090 b.putInt("Callback", 75);
10091 msg.setData(b);
10092 try
10093 {
10094 NavitGraphics.callback_handler.sendMessage(msg);
10095 }
10096
10097 catch (Exception e)
10098 {
10099 e.printStackTrace();
10100 }
10101 // follow mode OFF -----------
10102 }
10103 else
10104 {
10105 Navit.follow_current = Navit.follow_on;
10106 p.PREF_follow_gps = true;
10107
10108 // follow mode ON -----------
10109 Message msg = new Message();
10110 Bundle b = new Bundle();
10111 b.putInt("Callback", 74);
10112 msg.setData(b);
10113 try
10114 {
10115 NavitGraphics.callback_handler.sendMessage(msg);
10116 }
10117 catch (Exception e)
10118 {
10119 e.printStackTrace();
10120 }
10121 // follow mode ON -----------
10122 }
10123 editor.putBoolean("follow_gps", p.PREF_follow_gps);
10124 editor.commit();
10125 //if (!PREF_follow_gps)
10126 //{
10127 // // no compass turning without follow mode!
10128 // PREF_use_compass_heading_base = false;
10129 //}
10130 //if (!PREF_use_compass_heading_base)
10131 //{
10132 // // child is always "false" when parent is "false" !!
10133 // PREF_use_compass_heading_always = false;
10134 //}
10135
10136 Message msg = Navit_progress_h.obtainMessage();
10137 Bundle b = new Bundle();
10138 msg.what = 32;
10139 try
10140 {
10141 Navit_progress_h.sendMessage(msg);
10142 }
10143 catch (Exception e)
10144 {
10145 }
10146
10147 // hold all map drawing -----------
10148 msg = new Message();
10149 b = new Bundle();
10150 b.putInt("Callback", 69);
10151 msg.setData(b);
10152 try
10153 {
10154 NavitGraphics.callback_handler.sendMessage(msg);
10155 }
10156 catch (Exception e)
10157 {
10158 e.printStackTrace();
10159 }
10160 // hold all map drawing -----------
10161
10162 getPrefs();
10163 activatePrefs(1);
10164
10165 // allow all map drawing -----------
10166 msg = new Message();
10167 b = new Bundle();
10168 b.putInt("Callback", 70);
10169 msg.setData(b);
10170 try
10171 {
10172 NavitGraphics.callback_handler.sendMessage(msg);
10173 }
10174 catch (Exception e)
10175 {
10176 }
10177 // allow all map drawing -----------
10178
10179 NavitVehicle.set_last_known_pos_fast_provider();
10180
10181 // JB fix
10182 //NavitGraphics.NavitAOSDJava_.postInvalidate();
10183 //System.out.println("xx paint 14 xx");
10184 NavitGraphics.OSD_new.postInvalidate();
10185 NavitGraphics.NavitAOverlay_s.postInvalidate();
10186 }
10187
10188 public static void setPrefs_search_country()
10189 {
10190 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
10191
10192 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10193 SharedPreferences.Editor editor = prefs.edit();
10194 editor.putInt("search_country_id", p.PREF_search_country);
10195 editor.commit();
10196
10197 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
10198 }
10199
10200 public static void setPrefs_zoomlevel()
10201 {
10202 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
10203
10204 //System.out.println("1 save zoom level: " + Navit.GlobalScaleLevel);
10205 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10206 SharedPreferences.Editor editor = prefs.edit();
10207 editor.putInt("zoomlevel_num", Navit.GlobalScaleLevel);
10208 editor.commit();
10209 //System.out.println("2 save zoom level: " + Navit.GlobalScaleLevel);
10210
10211 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
10212 }
10213
10214 public static void setPrefs_selected_gpx_dir()
10215 {
10216 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
10217
10218 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10219 SharedPreferences.Editor editor = prefs.edit();
10220 editor.putString("last_selected_dir_gpxfiles", p.PREF_last_selected_dir_gpxfiles);
10221 editor.commit();
10222
10223 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
10224 }
10225
10226 private static void getPrefs_more_map_detail()
10227 {
10228 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
10229
10230 // int ret = 0;
10231 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10232 try
10233 {
10234 p.PREF_more_map_detail = Integer.parseInt(prefs.getString("more_map_detail", "0"));
10235 }
10236 catch (Exception e)
10237 {
10238 p.PREF_more_map_detail = 0;
10239 }
10240
10241 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
10242 }
10243
10244 private static void get_prefs_highdpi()
10245 {
10246 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
10247
10248 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10249 try
10250 {
10251 p.PREF_shrink_on_high_dpi = prefs.getBoolean("shrink_on_high_dpi", true);
10252 }
10253 catch (Exception e)
10254 {
10255 p.PREF_shrink_on_high_dpi = true;
10256 }
10257
10258 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
10259 }
10260
10261 public static boolean saveArray(String[] array, String arrayName, int size)
10262 {
10263 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10264 SharedPreferences.Editor editor = prefs.edit();
10265 editor.putInt(arrayName + "_size", size);
10266 for (int i = 0; i < array.length; i++)
10267 {
10268 if (array[i] == null)
10269 {
10270 editor.putString(arrayName + "_" + i, "");
10271 }
10272 else
10273 {
10274 editor.putString(arrayName + "_" + i, array[i]);
10275 }
10276 }
10277 return editor.commit();
10278 }
10279
10280 public static String[] loadArray(String arrayName, int size)
10281 {
10282 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10283 String[] array = new String[size];
10284 for (int i = 0; i < size; i++)
10285 {
10286 try
10287
10288 {
10289 array[i] = prefs.getString(arrayName + "_" + i, "");
10290 }
10291 catch (Exception e)
10292 {
10293 array[i] = "";
10294 }
10295 //System.out.println("array" + i + "=" + array[i]);
10296 }
10297
10298 return array;
10299 }
10300
10301 public static String[] pushToArray(String[] array_in, String value, int size)
10302 {
10303 for (int j = 0; j < size; j++)
10304 {
10305 if (array_in[j].equals(value))
10306 {
10307 // our value is already in the array, dont add it twice!
10308 return array_in;
10309 }
10310 }
10311
10312 String[] array = new String[size];
10313 for (int i = size - 1; i > 0; i--)
10314 {
10315 array[i] = array_in[i - 1];
10316 }
10317 array[0] = value;
10318 return array;
10319 }
10320
10321 private static void getPrefs()
10322 {
10323 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
10324
10325 // save old pref values ---------------
10326 ZANaviPrefs.deep_copy(p, p_old);
10327 // save old pref values ---------------
10328
10329 // Get the xml/preferences.xml preferences
10330 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
10331 p.PREF_use_fast_provider = prefs.getBoolean("use_fast_provider", true);
10332 p.PREF_allow_gui_internal = prefs.getBoolean("allow_gui_internal", false);
10333 p.PREF_follow_gps = prefs.getBoolean("follow_gps", true);
10334 p.PREF_use_compass_heading_base = prefs.getBoolean("use_compass_heading_base", false);
10335 p.PREF_use_compass_heading_always = prefs.getBoolean("use_compass_heading_always", false);
10336 p.PREF_use_compass_heading_fast = prefs.getBoolean("use_compass_heading_fast", false);
10337 p.PREF_use_anti_aliasing = prefs.getBoolean("use_anti_aliasing", true);
10338 p.PREF_use_map_filtering = prefs.getBoolean("use_map_filtering", true);
10339 p.PREF_gui_oneway_arrows = prefs.getBoolean("gui_oneway_arrows", true);
10340 p.PREF_c_linedrawing = prefs.getBoolean("c_linedrawing", false);
10341
10342 p.PREF_show_debug_messages = prefs.getBoolean("show_debug_messages", false);
10343
10344 p.PREF_show_3d_map = prefs.getBoolean("show_3d_map", false);
10345 send_data_to_plugin_bg(PLUGIN_MSG_CAT_3d_mode, String.valueOf(p.PREF_show_3d_map));
10346
10347 p.PREF_use_smooth_drawing = prefs.getBoolean("use_smooth_drawing", true);
10348 p.PREF_use_more_smooth_drawing = prefs.getBoolean("use_more_smooth_drawing", false);
10349 if (p.PREF_use_smooth_drawing == false)
10350 {
10351 p.PREF_use_more_smooth_drawing = false;
10352 }
10353 if (p.PREF_use_more_smooth_drawing == true)
10354 {
10355 p.PREF_use_smooth_drawing = true;
10356 }
10357
10358 boolean b1 = prefs.getBoolean("show_real_gps_pos", false);
10359 if (b1 == false)
10360 {
10361 p.PREF_show_real_gps_pos = 0;
10362 }
10363 else
10364 {
10365 p.PREF_show_real_gps_pos = 1;
10366 }
10367
10368 if (p.PREF_use_more_smooth_drawing)
10369 {
10370 NavitGraphics.Vehicle_delay_real_gps_position = 595;
10371 }
10372 else
10373 {
10374 NavitGraphics.Vehicle_delay_real_gps_position = 450;
10375 }
10376
10377 p.PREF_use_lock_on_roads = prefs.getBoolean("use_lock_on_roads", true);
10378 p.PREF_use_route_highways = prefs.getBoolean("use_route_highways", true);
10379 p.PREF_save_zoomlevel = prefs.getBoolean("save_zoomlevel", true);
10380 p.PREF_search_country = prefs.getInt("search_country_id", 1); // default=*ALL*
10381 p.PREF_zoomlevel_num = prefs.getInt("zoomlevel_num", 174698); // default zoom level = 174698 // shows almost the whole world
10382 p.PREF_show_sat_status = prefs.getBoolean("show_sat_status", true);
10383 p.PREF_use_agps = prefs.getBoolean("use_agps", true);
10384 p.PREF_enable_debug_functions = prefs.getBoolean("enable_debug_functions", false);
10385
10386 try
10387 {
10388 // recreate the menu items
10389 Message msg = Navit_progress_h.obtainMessage();
10390 Bundle b = new Bundle();
10391 msg.what = 29;
10392 msg.setData(b);
10393 Navit_progress_h.sendMessage(msg);
10394 }
10395 catch (Exception e)
10396 {
10397 e.printStackTrace();
10398 }
10399
10400 p.PREF_enable_debug_write_gpx = prefs.getBoolean("enable_debug_write_gpx", false);
10401 p.PREF_enable_debug_enable_comm = prefs.getBoolean("enable_debug_enable_comm", false);
10402
10403 p.PREF_speak_street_names = prefs.getBoolean("speak_street_names", true);
10404 p.PREF_use_custom_font = prefs.getBoolean("use_custom_font", true);
10405 p.PREF_draw_polyline_circles = prefs.getBoolean("draw_polyline_circles", true);
10406 p.PREF_streetsearch_r = prefs.getString("streetsearch_r", "2");
10407 p.PREF_route_style = prefs.getString("route_style", "3");
10408 p.PREF_item_dump = prefs.getBoolean("item_dump", false);
10409 p.PREF_show_route_rects = prefs.getBoolean("show_route_rects", false);
10410 p.PREF_trafficlights_delay = prefs.getString("trafficlights_delay", "0");
10411 boolean tmp = prefs.getBoolean("avoid_sharp_turns", false);
10412 p.PREF_avoid_sharp_turns = "0";
10413 //if (tmp)
10414 //{
10415 // p.PREF_avoid_sharp_turns = "1";
10416 //}
10417 p.PREF_autozoom_flag = prefs.getBoolean("autozoom_flag", true);
10418
10419 p.PREF_show_multipolygons = prefs.getBoolean("show_multipolygons", true);
10420 p.PREF_use_index_search = true; // prefs.getBoolean("use_index_search", true);
10421
10422 // PREF_show_2d3d_toggle = prefs.getBoolean("show_2d3d_toggle", true);
10423 p.PREF_show_2d3d_toggle = true;
10424
10425 // PREF_show_vehicle_3d = prefs.getBoolean("show_vehicle_3d", true);
10426 p.PREF_show_vehicle_3d = true;
10427
10428 p.PREF_speak_filter_special_chars = prefs.getBoolean("speak_filter_special_chars", true);
10429 try
10430 {
10431 p.PREF_routing_engine = Integer.parseInt(prefs.getString("routing_engine", "0"));
10432 }
10433 catch (Exception e)
10434 {
10435 p.PREF_routing_engine = 0;
10436 }
10437
10438 // send to C code --------
10439 NavitGraphics.CallbackMessageChannel(55598, "" + p.PREF_routing_engine);
10440 // send to C code --------
10441
10442 p.PREF_routing_profile = prefs.getString("routing_profile", "car");
10443 p.PREF_road_priority_001 = (prefs.getInt("road_priority_001", (68 - 10)) + 10); // must ADD minimum value!!
10444 p.PREF_road_priority_002 = (prefs.getInt("road_priority_002", (329 - 10)) + 10); // must ADD minimum value!!
10445 p.PREF_road_priority_003 = (prefs.getInt("road_priority_003", (5000 - 10)) + 10); // must ADD minimum value!!
10446 p.PREF_road_priority_004 = (prefs.getInt("road_priority_004", (5 - 0)) + 0); // must ADD minimum value!!
10447
10448 // p.PREF_road_prio_weight_street_1_city = (prefs.getInt("road_prio_weight_street_1_city", (30 - 10)) + 10); // must ADD minimum value!!
10449
10450 p.PREF_traffic_speed_factor = (prefs.getInt("traffic_speed_factor", (83 - 20)) + 20); // must ADD minimum value!!
10451
10452 p.PREF_tracking_connected_pref = (prefs.getInt("tracking_connected_pref", (250 - 0)) + 0); // must ADD minimum value!!
10453 p.PREF_tracking_angle_pref = (prefs.getInt("tracking_angle_pref", (40 - 0)) + 0); // must ADD minimum value!!
10454
10455 p.PREF_streets_only = prefs.getBoolean("streets_only", false);
10456 p.PREF_show_status_bar = prefs.getBoolean("show_status_bar", true);
10457 p.PREF_show_poi_on_map = prefs.getBoolean("show_poi_on_map", false);
10458 p.PREF_last_selected_dir_gpxfiles = prefs.getString("last_selected_dir_gpxfiles", MAP_FILENAME_PATH + "/../");
10459
10460 p.PREF_roadspeed_warning = prefs.getBoolean("roadspeed_warning", false);
10461 p.PREF_lane_assist = prefs.getBoolean("lane_assist", false);
10462
10463 try
10464 {
10465 p.PREF_roadspeed_warning_margin = Integer.parseInt(prefs.getString("roadspeed_warning_margin", "20"));
10466 }
10467 catch (Exception e)
10468 {
10469 p.PREF_roadspeed_warning_margin = 20;
10470 }
10471
10472 p.PREF_StreetSearchStrings = loadArray("xxStrtSrhStrxx", STREET_SEARCH_STRINGS_SAVE_COUNT);
10473
10474 try
10475 {
10476 p.PREF_drawatorder = Integer.parseInt(prefs.getString("drawatorder", "0"));
10477 }
10478 catch (Exception e)
10479 {
10480 p.PREF_drawatorder = 0;
10481 }
10482
10483 //try
10484 //{
10485 // PREF_cancel_map_drawing_timeout = Integer.parseInt(prefs.getString("cancel_map_drawing_timeout", "1"));
10486 //}
10487 //catch (Exception e)
10488 //{
10489 p.PREF_cancel_map_drawing_timeout = 1;
10490 //}
10491
10492 try
10493 {
10494 p.PREF_map_font_size = Integer.parseInt(prefs.getString("map_font_size", "3"));
10495 }
10496 catch (Exception e)
10497 {
10498 p.PREF_map_font_size = 2;
10499 }
10500
10501 Navit_last_address_search_country_id = p.PREF_search_country;
10502 Navit_last_address_search_country_iso2_string = NavitAddressSearchCountrySelectActivity.CountryList_Human[p.PREF_search_country][0];
10503
10504 if (!p.PREF_follow_gps)
10505 {
10506 // no compass turning without follow mode!
10507 p.PREF_use_compass_heading_base = false;
10508 }
10509
10510 if (!p.PREF_use_compass_heading_base)
10511 {
10512 // child is always "false" when parent is "false" !!
10513 p.PREF_use_compass_heading_always = false;
10514 }
10515 p.PREF_show_vehicle_in_center = prefs.getBoolean("show_vehicle_in_center", false);
10516 p.PREF_use_imperial = prefs.getBoolean("use_imperial", false);
10517 Navit.cur_max_speed = -1; // to update speedwarning graphics
10518
10519 // System.out.println("get settings");
10520 // System.out.println("PREF_search_country=" + PREF_search_country);
10521 // System.out.println("PREF_follow_gps=" + PREF_follow_gps);
10522 // System.out.println("PREF_use_fast_provider=" + PREF_use_fast_provider);
10523 // System.out.println("PREF_allow_gui_internal=" + PREF_allow_gui_internal);
10524 // System.out.println("PREF_use_compass_heading_base=" + PREF_use_compass_heading_base);
10525 // System.out.println("PREF_use_compass_heading_always=" + PREF_use_compass_heading_always);
10526 // System.out.println("PREF_show_vehicle_in_center=" + PREF_show_vehicle_in_center);
10527 // System.out.println("PREF_use_imperial=" + PREF_use_imperial);
10528
10529 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
10530 }
10531
10532 private static void activatePrefs()
10533 {
10534 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
10535
10536 activatePrefs(1);
10537
10538 if (p.PREF_save_zoomlevel)
10539 {
10540 // only if really started, but NOT if returning from our own child activities!!
10541
10542 //System.out.println("3 restore zoom level: " + Navit.GlobalScaleLevel);
10543 //System.out.println("4 restore zoom level: " + PREF_zoomlevel_num);
10544
10545 Message msg = new Message();
10546 Bundle b = new Bundle();
10547 b.putInt("Callback", 33);
10548 b.putString("s", Integer.toString(p.PREF_zoomlevel_num));
10549 msg.setData(b);
10550 try
10551 {
10552 NavitGraphics.callback_handler.sendMessage(msg);
10553 Navit.GlobalScaleLevel = p.PREF_zoomlevel_num;
10554 //System.out.println("5 restore zoom level: " + PREF_zoomlevel_num);
10555 }
10556 catch (Exception e)
10557 {
10558 }
10559 }
10560 else
10561 {
10562 p.PREF_zoomlevel_num = Navit.GlobalScaleLevel;
10563 }
10564
10565 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
10566 }
10567
10568 private static void set_poi_layers()
10569 {
10570 int on_ = 59;
10571 int off_ = 60;
10572
10573 // System.out.println("POI:1");
10574 if (p.PREF_show_poi_on_map)
10575 {
10576 // System.out.println("POI:2");
10577 on_ = 60;
10578 off_ = 59;
10579 }
10580
10581 // toggle the normal POI layers (to avoid double POIs)
10582 Message msg = new Message();
10583 Bundle b = new Bundle();
10584 b.putInt("Callback", on_);
10585 b.putString("s", "POI Symbols");
10586 msg.setData(b);
10587 NavitGraphics.callback_handler.sendMessage(msg);
10588
10589 msg = new Message();
10590 b = new Bundle();
10591 b.putInt("Callback", on_);
10592 b.putString("s", "POI Labels");
10593 msg.setData(b);
10594 NavitGraphics.callback_handler.sendMessage(msg);
10595
10596 // toggle full POI icons on/off
10597 msg = new Message();
10598 b = new Bundle();
10599 b.putInt("Callback", off_);
10600 b.putString("s", "Android-POI-Icons-full");
10601 msg.setData(b);
10602 NavitGraphics.callback_handler.sendMessage(msg);
10603
10604 msg = new Message();
10605 b = new Bundle();
10606 b.putInt("Callback", off_);
10607 b.putString("s", "Android-POI-Labels-full");
10608 msg.setData(b);
10609 NavitGraphics.callback_handler.sendMessage(msg);
10610
10611 // draw_map();
10612 }
10613
10614 private static void activatePrefs(int dummy)
10615 {
10616
10617 need_recalc_route = false; // do we need to recalc the route?
10618
10619 // call some functions to activate the new settings
10620 if (p.PREF_follow_gps)
10621 {
10622 Navit.follow_current = Navit.follow_on;
10623 }
10624 else
10625 {
10626 Navit.follow_current = Navit.follow_off;
10627 }
10628
10629 if (p.PREF_use_fast_provider)
10630 {
10631 NavitVehicle.turn_on_fast_provider();
10632 }
10633 else
10634 {
10635 NavitVehicle.turn_off_fast_provider();
10636 }
10637
10638 if (p.PREF_show_sat_status)
10639 {
10640 NavitVehicle.turn_on_sat_status();
10641 }
10642 else
10643 {
10644 // status always on !
10645 //
10646 // NavitVehicle.turn_off_sat_status();
10647 NavitVehicle.turn_on_sat_status();
10648 }
10649
10650 if (p.PREF_show_status_bar)
10651 {
10652 show_status_bar_wrapper();
10653 }
10654 else
10655 {
10656 hide_status_bar_wrapper();
10657 }
10658
10659 if (p.PREF_allow_gui_internal)
10660 {
10661 Message msg = new Message();
10662 Bundle b = new Bundle();
10663 b.putInt("Callback", 10);
10664 msg.setData(b);
10665 try
10666 {
10667 NavitGraphics.callback_handler.sendMessage(msg);
10668 }
10669 catch (Exception e)
10670 {
10671 }
10672 }
10673 else
10674 {
10675 Message msg = new Message();
10676 Bundle b = new Bundle();
10677 b.putInt("Callback", 9);
10678 msg.setData(b);
10679 try
10680 {
10681 NavitGraphics.callback_handler.sendMessage(msg);
10682 }
10683 catch (Exception e)
10684 {
10685 }
10686 }
10687
10688 if (p.PREF_use_compass_heading_base)
10689 {
10690 // turn on compass
10691 msg_to_msg_handler(new Bundle(), 12);
10692 Message msg = new Message();
10693 Bundle b = new Bundle();
10694 b.putInt("Callback", 11);
10695 msg.setData(b);
10696 try
10697 {
10698 NavitGraphics.callback_handler.sendMessage(msg);
10699 }
10700 catch (Exception e)
10701 {
10702 }
10703 }
10704 else
10705 {
10706 // turn off compass
10707 msg_to_msg_handler(new Bundle(), 13);
10708 Message msg = new Message();
10709 Bundle b = new Bundle();
10710 b.putInt("Callback", 12);
10711 msg.setData(b);
10712 try
10713 {
10714 NavitGraphics.callback_handler.sendMessage(msg);
10715 }
10716 catch (Exception e)
10717 {
10718 }
10719 }
10720
10721 if (p.PREF_show_real_gps_pos == 1)
10722 {
10723 // show real gps pos
10724 Message msg = new Message();
10725 Bundle b = new Bundle();
10726 b.putInt("Callback", 111);
10727 b.putString("s", "1");
10728 msg.setData(b);
10729 try
10730 {
10731 NavitGraphics.callback_handler.sendMessage(msg);
10732 }
10733 catch (Exception e)
10734 {
10735 }
10736 }
10737 else
10738 {
10739 Message msg = new Message();
10740 Bundle b = new Bundle();
10741 b.putInt("Callback", 111);
10742 b.putString("s", "0");
10743 msg.setData(b);
10744 try
10745 {
10746 NavitGraphics.callback_handler.sendMessage(msg);
10747 }
10748 catch (Exception e)
10749 {
10750 }
10751 }
10752
10753 // search radius for housenumbers near streets -----------------
10754 Message msg43 = new Message();
10755 Bundle b43 = new Bundle();
10756 b43.putInt("Callback", 89);
10757 b43.putString("s", "1500");
10758 msg43.setData(b43);
10759 try
10760 {
10761 NavitGraphics.callback_handler.sendMessage(msg43);
10762 }
10763 catch (Exception e)
10764 {
10765 }
10766 // search radius for housenumbers near streets -----------------
10767
10768 // set routing profile -----------------
10769 if (Navit_Largemap_DonateVersion_Installed == true)
10770 {
10771 Message msg43a = new Message();
10772 Bundle b43a = new Bundle();
10773 b43a.putInt("Callback", 90);
10774 b43a.putString("s", p.PREF_routing_profile); // set routing profile
10775 msg43a.setData(b43a);
10776 try
10777 {
10778 NavitGraphics.callback_handler.sendMessage(msg43a);
10779 }
10780 catch (Exception e)
10781 {
10782 }
10783
10784 // need_recalc_route = true;
10785 }
10786 // set routing profile -----------------
10787
10788 Message msg99a = new Message();
10789 Bundle b99a = new Bundle();
10790 b99a.putInt("Callback", 98);
10791 // System.out.println("tracking_connected_pref=" + PREF_tracking_connected_pref);
10792 b99a.putString("s", "" + p.PREF_tracking_connected_pref); // set routing profile
10793 msg99a.setData(b99a);
10794 try
10795 {
10796 NavitGraphics.callback_handler.sendMessage(msg99a);
10797 }
10798 catch (Exception e)
10799 {
10800 }
10801
10802 msg99a = new Message();
10803 b99a = new Bundle();
10804 b99a.putInt("Callback", 99);
10805 // System.out.println("tracking_angle_pref=" + PREF_tracking_angle_pref);
10806 b99a.putString("s", "" + p.PREF_tracking_angle_pref); // set routing profile
10807 msg99a.setData(b99a);
10808 try
10809 {
10810 NavitGraphics.callback_handler.sendMessage(msg99a);
10811 }
10812 catch (Exception e)
10813 {
10814 }
10815
10816 // change road profile -----------------
10817 if (Navit_Largemap_DonateVersion_Installed == true)
10818 {
10819 if (p.PREF_routing_profile.equals("bike-normal"))
10820 {
10821 Message msg43b = new Message();
10822 Bundle b43b = new Bundle();
10823 b43b.putInt("Callback", 91);
10824 System.out.println("road_priority_001=" + p.PREF_road_priority_001);
10825 b43b.putString("s", "" + p.PREF_road_priority_001); // set routing profile
10826 msg43b.setData(b43b);
10827 try
10828 {
10829 NavitGraphics.callback_handler.sendMessage(msg43b);
10830 }
10831 catch (Exception e)
10832 {
10833 }
10834
10835 msg43b = new Message();
10836 b43b = new Bundle();
10837 b43b.putInt("Callback", 92);
10838 System.out.println("road_priority_002=" + p.PREF_road_priority_002);
10839 b43b.putString("s", "" + p.PREF_road_priority_002); // set routing profile
10840 msg43b.setData(b43b);
10841 try
10842 {
10843 NavitGraphics.callback_handler.sendMessage(msg43b);
10844 }
10845 catch (Exception e)
10846 {
10847 }
10848
10849 msg43b = new Message();
10850 b43b = new Bundle();
10851 b43b.putInt("Callback", 93);
10852 System.out.println("road_priority_003=" + p.PREF_road_priority_003);
10853 b43b.putString("s", "" + p.PREF_road_priority_003); // set routing profile
10854 msg43b.setData(b43b);
10855 try
10856 {
10857 NavitGraphics.callback_handler.sendMessage(msg43b);
10858 }
10859 catch (Exception e)
10860 {
10861 }
10862
10863 msg43b = new Message();
10864 b43b = new Bundle();
10865 b43b.putInt("Callback", 94);
10866 System.out.println("road_priority_004=" + p.PREF_road_priority_004);
10867 b43b.putString("s", "" + p.PREF_road_priority_004); // set routing profile
10868 msg43b.setData(b43b);
10869 try
10870 {
10871 NavitGraphics.callback_handler.sendMessage(msg43b);
10872 }
10873 catch (Exception e)
10874 {
10875 }
10876
10877 // switch off layers --------------------
10878 msg43b = new Message();
10879 b43b = new Bundle();
10880 b43b.putInt("Callback", 60);
10881 b43b.putString("s", "POI traffic lights");
10882 msg43b.setData(b43b);
10883 try
10884 {
10885 NavitGraphics.callback_handler.sendMessage(msg43b);
10886 }
10887 catch (Exception e)
10888 {
10889 }
10890 // switch off layers --------------------
10891
10892 // switch ON layers --------------------
10893 msg43b = new Message();
10894 b43b = new Bundle();
10895 b43b.putInt("Callback", 59);
10896 b43b.putString("s", "POI bicycle");
10897 msg43b.setData(b43b);
10898 try
10899 {
10900 NavitGraphics.callback_handler.sendMessage(msg43b);
10901 }
10902 catch (Exception e)
10903 {
10904 }
10905 // switch ON layers --------------------
10906
10907 }
10908 else
10909 {
10910 // switch off layers --------------------
10911 Message msg43b = new Message();
10912 Bundle b43b = new Bundle();
10913 b43b.putInt("Callback", 60);
10914 b43b.putString("s", "POI bicycle");
10915 msg43b.setData(b43b);
10916 try
10917 {
10918 NavitGraphics.callback_handler.sendMessage(msg43b);
10919 }
10920 catch (Exception e)
10921 {
10922 }
10923 // switch off layers --------------------
10924
10925 // switch ON layers --------------------
10926 msg43b = new Message();
10927 b43b = new Bundle();
10928 b43b.putInt("Callback", 59);
10929 b43b.putString("s", "POI traffic lights");
10930 msg43b.setData(b43b);
10931 try
10932 {
10933 NavitGraphics.callback_handler.sendMessage(msg43b);
10934 }
10935 catch (Exception e)
10936 {
10937 }
10938 // switch ON layers --------------------
10939 }
10940 }
10941 // change road profile -----------------
10942
10943 // -- debug -- change some prio weights --
10944 // if ((!p.PREF_routing_profile.equals("bike-normal")) && (!p.PREF_routing_profile.equals("bike-no-oneway")) && (!p.PREF_routing_profile.equals("bike-avoid-roads")))
10945 // {
10946 // Message msg93 = new Message();
10947 // Bundle b93 = new Bundle();
10948 // b93.putInt("Callback", 110);
10949 // b93.putString("s", "street_1_city#route_prio_weight:" + p.PREF_road_prio_weight_street_1_city);
10950 // msg93.setData(b93);
10951 // try
10952 // {
10953 // NavitGraphics.callback_handler.sendMessage(msg93);
10954 // }
10955 // catch (Exception e)
10956 // {
10957 // }
10958 //
10959 // if (p_old.PREF_road_prio_weight_street_1_city != p.PREF_road_prio_weight_street_1_city)
10960 // {
10961 // need_recalc_route = true;
10962 // }
10963 // }
10964 // -- debug -- change some prio weights --
10965
10966 if (NavitGraphics.navit_route_status == 0)
10967 {
10968 if (p.PREF_c_linedrawing)
10969 {
10970 Message msg = new Message();
10971 Bundle b = new Bundle();
10972 b.putInt("Callback", 85);
10973 b.putString("s", "1");
10974 msg.setData(b);
10975 try
10976 {
10977 NavitGraphics.callback_handler.sendMessage(msg);
10978 }
10979 catch (Exception e)
10980 {
10981 }
10982 }
10983 else
10984 {
10985 Message msg = new Message();
10986 Bundle b = new Bundle();
10987 b.putInt("Callback", 85);
10988 b.putString("s", "0");
10989 msg.setData(b);
10990 try
10991 {
10992 NavitGraphics.callback_handler.sendMessage(msg);
10993 }
10994 catch (Exception e)
10995 {
10996 }
10997 }
10998 }
10999
11000 Message msg33 = new Message();
11001 Bundle b33 = new Bundle();
11002 b33.putInt("Callback", 103);
11003 if (p.PREF_show_vehicle_in_center)
11004 {
11005 b33.putString("s", "0");
11006 }
11007 else
11008 {
11009 b33.putString("s", "" + NavitGraphics.lower_than_center_percent);
11010 }
11011 msg33.setData(b33);
11012 try
11013 {
11014 NavitGraphics.callback_handler.sendMessage(msg33);
11015 }
11016 catch (Exception e88)
11017 {
11018 }
11019
11020 if (p.PREF_use_imperial)
11021 {
11022 Message msg = new Message();
11023 Bundle b = new Bundle();
11024 b.putInt("Callback", 16);
11025 msg.setData(b);
11026 try
11027 {
11028 NavitGraphics.callback_handler.sendMessage(msg);
11029 }
11030 catch (Exception e)
11031 {
11032 }
11033 }
11034 else
11035 {
11036 Message msg = new Message();
11037 Bundle b = new Bundle();
11038 b.putInt("Callback", 15);
11039 msg.setData(b);
11040 try
11041 {
11042 NavitGraphics.callback_handler.sendMessage(msg);
11043 }
11044 catch (Exception e)
11045 {
11046 }
11047 }
11048
11049 if (p.PREF_show_debug_messages)
11050 {
11051 Message msg = new Message();
11052 Bundle b = new Bundle();
11053 b.putInt("Callback", 24);
11054 msg.setData(b);
11055 try
11056 {
11057 NavitGraphics.callback_handler.sendMessage(msg);
11058 }
11059 catch (Exception e)
11060 {
11061 }
11062 }
11063 else
11064 {
11065 Message msg = new Message();
11066 Bundle b = new Bundle();
11067 b.putInt("Callback", 25);
11068 msg.setData(b);
11069 try
11070 {
11071 NavitGraphics.callback_handler.sendMessage(msg);
11072 }
11073 catch (Exception e)
11074 {
11075 }
11076 }
11077
11078 // if (PREF_show_3d_map)
11079 // {
11080 // Message msg = new Message();
11081 // Bundle b = new Bundle();
11082 // b.putInt("Callback", 31);
11083 // msg.setData(b);
11084 // try
11085 // {
11086 // N_NavitGraphics.callback_handler.sendMessage(msg);
11087 // }
11088 // catch (Exception e)
11089 // {
11090 // }
11091 // }
11092 // else
11093 // {
11094 // Message msg = new Message();
11095 // Bundle b = new Bundle();
11096 // b.putInt("Callback", 30);
11097 // msg.setData(b);
11098 // try
11099 // {
11100 // N_NavitGraphics.callback_handler.sendMessage(msg);
11101 // }
11102 // catch (Exception e)
11103 // {
11104 // }
11105 // }
11106
11107 if (p.PREF_use_lock_on_roads)
11108 {
11109 Message msg = new Message();
11110 Bundle b = new Bundle();
11111 b.putInt("Callback", 36);
11112 msg.setData(b);
11113 try
11114 {
11115 NavitGraphics.callback_handler.sendMessage(msg);
11116 }
11117 catch (Exception e)
11118 {
11119 }
11120 }
11121 else
11122 {
11123 Message msg = new Message();
11124 Bundle b = new Bundle();
11125 b.putInt("Callback", 37);
11126 msg.setData(b);
11127 try
11128 {
11129 NavitGraphics.callback_handler.sendMessage(msg);
11130 }
11131 catch (Exception e)
11132 {
11133 }
11134 }
11135
11136 // if (PREF_draw_polyline_circles)
11137 // {
11138 // Message msg = new Message();
11139 // Bundle b = new Bundle();
11140 // b.putString("s", "0");
11141 // b.putInt("Callback", 56);
11142 // msg.setData(b);
11143 // try
11144 // {
11145 // N_NavitGraphics.callback_handler.sendMessage(msg);
11146 // }
11147 // catch (Exception e)
11148 // {
11149 // }
11150 // }
11151 // else
11152 // {
11153 // Message msg = new Message();
11154 // Bundle b = new Bundle();
11155 // b.putString("s", "1");
11156 // b.putInt("Callback", 56);
11157 // msg.setData(b);
11158 // try
11159 // {
11160 // N_NavitGraphics.callback_handler.sendMessage(msg);
11161 // }
11162 // catch (Exception e)
11163 // {
11164 // }
11165 // }
11166
11167 if (p.PREF_use_route_highways)
11168 {
11169 Message msg = new Message();
11170 Bundle b = new Bundle();
11171 b.putInt("Callback", 42);
11172 msg.setData(b);
11173 try
11174 {
11175 NavitGraphics.callback_handler.sendMessage(msg);
11176 }
11177 catch (Exception e)
11178 {
11179 }
11180 }
11181 else
11182 {
11183 Message msg = new Message();
11184 Bundle b = new Bundle();
11185 b.putInt("Callback", 43);
11186 msg.setData(b);
11187 try
11188 {
11189 NavitGraphics.callback_handler.sendMessage(msg);
11190 }
11191 catch (Exception e)
11192 {
11193 }
11194 }
11195
11196 Message msg7 = new Message();
11197 Bundle b7 = new Bundle();
11198 b7.putInt("Callback", 57);
11199 b7.putString("s", "" + p.PREF_drawatorder);
11200 msg7.setData(b7);
11201 try
11202 {
11203 NavitGraphics.callback_handler.sendMessage(msg7);
11204 }
11205 catch (Exception e)
11206 {
11207 }
11208
11209 msg7 = new Message();
11210 b7 = new Bundle();
11211 b7.putInt("Callback", 58);
11212 b7.putString("s", p.PREF_streetsearch_r);
11213 msg7.setData(b7);
11214 try
11215 {
11216 NavitGraphics.callback_handler.sendMessage(msg7);
11217 }
11218 catch (Exception e)
11219 {
11220 }
11221
11222 if (p.PREF_speak_street_names)
11223 {
11224 Message msg = new Message();
11225 Bundle b = new Bundle();
11226 b.putInt("Callback", 54);
11227 msg.setData(b);
11228 try
11229 {
11230 NavitGraphics.callback_handler.sendMessage(msg);
11231 }
11232 catch (Exception e)
11233 {
11234 }
11235 }
11236 else
11237 {
11238 Message msg = new Message();
11239 Bundle b = new Bundle();
11240 b.putInt("Callback", 53);
11241 msg.setData(b);
11242 try
11243 {
11244 NavitGraphics.callback_handler.sendMessage(msg);
11245 }
11246 catch (Exception e)
11247 {
11248 }
11249
11250 }
11251
11252 try
11253 {
11254 NavitGraphics.OverlayDrawThread_cancel_drawing_timeout = NavitGraphics.OverlayDrawThread_cancel_drawing_timeout__options[p.PREF_cancel_map_drawing_timeout];
11255 NavitGraphics.OverlayDrawThread_cancel_thread_sleep_time = NavitGraphics.OverlayDrawThread_cancel_thread_sleep_time__options[p.PREF_cancel_map_drawing_timeout];
11256 NavitGraphics.OverlayDrawThread_cancel_thread_timeout = NavitGraphics.OverlayDrawThread_cancel_thread_timeout__options[p.PREF_cancel_map_drawing_timeout];
11257 }
11258 catch (Exception e)
11259 {
11260
11261 }
11262
11263 // route variant
11264 Message msg67 = new Message();
11265 Bundle b67 = new Bundle();
11266 // turn off 1
11267 b67.putInt("Callback", 60);
11268 b67.putString("s", "route_001");
11269 msg67.setData(b67);
11270
11271 try
11272 {
11273 NavitGraphics.callback_handler.sendMessage(msg67);
11274 }
11275 catch (Exception e)
11276 {
11277 }
11278 // turn off 2
11279 msg67 = new Message();
11280 b67 = new Bundle();
11281 b67.putInt("Callback", 60);
11282 b67.putString("s", "route_002");
11283 msg67.setData(b67);
11284 try
11285 {
11286 NavitGraphics.callback_handler.sendMessage(msg67);
11287 }
11288 catch (Exception e)
11289 {
11290 }
11291 // turn off 3
11292 msg67 = new Message();
11293 b67 = new Bundle();
11294 b67.putInt("Callback", 60);
11295 b67.putString("s", "route_003");
11296 msg67.setData(b67);
11297 try
11298 {
11299 NavitGraphics.callback_handler.sendMessage(msg67);
11300 }
11301 catch (Exception e)
11302 {
11303 }
11304
11305 // turn on the wanted route style
11306 msg67 = new Message();
11307 b67 = new Bundle();
11308 b67.putInt("Callback", 59);
11309 b67.putString("s", "route_00" + p.PREF_route_style);
11310 msg67.setData(b67);
11311 try
11312 {
11313 NavitGraphics.callback_handler.sendMessage(msg67);
11314 }
11315 catch (Exception e)
11316 {
11317 }
11318 // route variant
11319
11320 // show route rectanlges -----
11321 if (p.PREF_show_route_rects)
11322 {
11323 msg67 = new Message();
11324 b67 = new Bundle();
11325 b67.putInt("Callback", 76);
11326 msg67.setData(b67);
11327 try
11328 {
11329 NavitGraphics.callback_handler.sendMessage(msg67);
11330 }
11331 catch (Exception e)
11332 {
11333 }
11334 }
11335 else
11336 {
11337 msg67 = new Message();
11338 b67 = new Bundle();
11339 b67.putInt("Callback", 77);
11340 msg67.setData(b67);
11341 try
11342 {
11343 NavitGraphics.callback_handler.sendMessage(msg67);
11344 }
11345 catch (Exception e)
11346 {
11347 }
11348 }
11349 // show route rectanlges -----
11350
11351 // show route multipolygons -----
11352 if (p.PREF_show_multipolygons)
11353 {
11354 msg67 = new Message();
11355 b67 = new Bundle();
11356 b67.putInt("Callback", 66);
11357 msg67.setData(b67);
11358 try
11359 {
11360 NavitGraphics.callback_handler.sendMessage(msg67);
11361 }
11362 catch (Exception e)
11363 {
11364 }
11365 }
11366 else
11367 {
11368 msg67 = new Message();
11369 b67 = new Bundle();
11370 b67.putInt("Callback", 67);
11371 msg67.setData(b67);
11372 try
11373 {
11374 NavitGraphics.callback_handler.sendMessage(msg67);
11375 }
11376 catch (Exception e)
11377 {
11378 }
11379 }
11380 // show route multipolygons -----
11381
11382 // traffic lights delay ----
11383 msg67 = new Message();
11384 b67 = new Bundle();
11385 b67.putInt("Callback", 79);
11386 //System.out.println("traffic lights delay:" + PREF_trafficlights_delay);
11387 // (PREF_trafficlights_delay / 10) seconds delay for each traffic light
11388 b67.putString("s", p.PREF_trafficlights_delay); // (delay in 1/10 of a second)
11389 msg67.setData(b67);
11390 try
11391 {
11392 NavitGraphics.callback_handler.sendMessage(msg67);
11393 }
11394 catch (Exception e)
11395 {
11396 }
11397 // traffic lights delay ----
11398
11399 // avoid sharp turns ----
11400 msg67 = new Message();
11401 b67 = new Bundle();
11402 b67.putInt("Callback", 86);
11403 b67.putString("s", p.PREF_avoid_sharp_turns);
11404 msg67.setData(b67);
11405 try
11406 {
11407 NavitGraphics.callback_handler.sendMessage(msg67);
11408 }
11409 catch (Exception e)
11410 {
11411 }
11412
11413 msg67 = new Message();
11414 b67 = new Bundle();
11415 b67.putInt("Callback", 87);
11416 b67.putString("s", "47"); // **DANGER** sharp turn max angle hardcoded here!! **DANGER**
11417 msg67.setData(b67);
11418 try
11419 {
11420 NavitGraphics.callback_handler.sendMessage(msg67);
11421 }
11422 catch (Exception e)
11423 {
11424 }
11425
11426 msg67 = new Message();
11427 b67 = new Bundle();
11428 b67.putInt("Callback", 88);
11429 b67.putString("s", "6000");
11430 msg67.setData(b67);
11431 try
11432 {
11433 NavitGraphics.callback_handler.sendMessage(msg67);
11434 }
11435 catch (Exception e)
11436 {
11437 }
11438 // avoid sharp turns ----
11439
11440 // autozoom flag ----
11441 msg67 = new Message();
11442 b67 = new Bundle();
11443 b67.putInt("Callback", 80);
11444 if (p.PREF_autozoom_flag)
11445 {
11446 b67.putString("s", "1"); // (0 or 1)
11447 }
11448 else
11449 {
11450 b67.putString("s", "0"); // (0 or 1)
11451 }
11452 msg67.setData(b67);
11453 try
11454 {
11455 NavitGraphics.callback_handler.sendMessage(msg67);
11456 }
11457 catch (Exception e)
11458 {
11459
11460 }
11461 // autozoom flag ----
11462
11463 if ((Navit.Navit_Largemap_DonateVersion_Installed) || (Navit.Navit_DonateVersion_Installed))
11464 {
11465 // use pref
11466 }
11467 else
11468 {
11469 p.PREF_roadspeed_warning = false;
11470 }
11471
11472 if ((Navit.Navit_Largemap_DonateVersion_Installed) || (Navit.Navit_DonateVersion_Installed))
11473 {
11474 // use pref
11475 }
11476 else
11477 {
11478 p.PREF_lane_assist = false;
11479 }
11480
11481 if (p.PREF_streets_only)
11482 {
11483 // ----------------------- streets only pref -------------------
11484 // 59 -> enable
11485 // 60 -> disable
11486 Message msg31 = new Message();
11487 Bundle b31 = new Bundle();
11488 b31.putInt("Callback", 60);
11489 b31.putString("s", "polygons001");
11490 msg31.setData(b31);
11491 NavitGraphics.callback_handler.sendMessage(msg31);
11492
11493 msg31 = new Message();
11494 b31 = new Bundle();
11495 b31.putInt("Callback", 60);
11496 b31.putString("s", "polygons");
11497 msg31.setData(b31);
11498 NavitGraphics.callback_handler.sendMessage(msg31);
11499
11500 msg31 = new Message();
11501 b31 = new Bundle();
11502 b31.putInt("Callback", 60);
11503 b31.putString("s", "POI Symbols");
11504 msg31.setData(b31);
11505 NavitGraphics.callback_handler.sendMessage(msg31);
11506
11507 msg31 = new Message();
11508 b31 = new Bundle();
11509 b31.putInt("Callback", 60);
11510 b31.putString("s", "POI Labels");
11511 msg31.setData(b31);
11512 NavitGraphics.callback_handler.sendMessage(msg31);
11513
11514 msg31 = new Message();
11515 b31 = new Bundle();
11516 b31.putInt("Callback", 60);
11517 b31.putString("s", "Android-POI-Icons-full");
11518 msg31.setData(b31);
11519 NavitGraphics.callback_handler.sendMessage(msg31);
11520
11521 msg31 = new Message();
11522 b31 = new Bundle();
11523 b31.putInt("Callback", 60);
11524 b31.putString("s", "Android-POI-Labels-full");
11525 msg31.setData(b31);
11526 NavitGraphics.callback_handler.sendMessage(msg31);
11527
11528 msg31 = new Message();
11529 b31 = new Bundle();
11530 b31.putInt("Callback", 60);
11531 b31.putString("s", "streets");
11532 msg31.setData(b31);
11533 NavitGraphics.callback_handler.sendMessage(msg31);
11534
11535 msg31 = new Message();
11536 b31 = new Bundle();
11537 b31.putInt("Callback", 60);
11538 b31.putString("s", "streets_1");
11539 msg31.setData(b31);
11540 NavitGraphics.callback_handler.sendMessage(msg31);
11541
11542 msg31 = new Message();
11543 b31 = new Bundle();
11544 b31.putInt("Callback", 60);
11545 b31.putString("s", "streets_2");
11546 msg31.setData(b31);
11547 NavitGraphics.callback_handler.sendMessage(msg31);
11548
11549 msg31 = new Message();
11550 b31 = new Bundle();
11551 b31.putInt("Callback", 59);
11552 b31.putString("s", "streets_STR_ONLY");
11553 msg31.setData(b31);
11554 NavitGraphics.callback_handler.sendMessage(msg31);
11555
11556 msg31 = new Message();
11557 b31 = new Bundle();
11558 b31.putInt("Callback", 59);
11559 b31.putString("s", "streets_1_STR_ONLY");
11560 msg31.setData(b31);
11561 NavitGraphics.callback_handler.sendMessage(msg31);
11562
11563 msg31 = new Message();
11564 b31 = new Bundle();
11565 b31.putInt("Callback", 59);
11566 b31.putString("s", "streets_2_STR_ONLY");
11567 msg31.setData(b31);
11568 NavitGraphics.callback_handler.sendMessage(msg31);
11569 // ----------------------- streets only pref -------------------
11570 }
11571 else
11572 {
11573 // ----------------------- streets only pref -------------------
11574 // 59 -> enable
11575 // 60 -> disable
11576 Message msg31 = new Message();
11577 Bundle b31 = new Bundle();
11578 b31.putInt("Callback", 59);
11579 b31.putString("s", "polygons001");
11580 msg31.setData(b31);
11581 NavitGraphics.callback_handler.sendMessage(msg31);
11582
11583 msg31 = new Message();
11584 b31 = new Bundle();
11585 b31.putInt("Callback", 59);
11586 b31.putString("s", "polygons");
11587 msg31.setData(b31);
11588 NavitGraphics.callback_handler.sendMessage(msg31);
11589
11590 msg31 = new Message();
11591 b31 = new Bundle();
11592 b31.putInt("Callback", 59);
11593 b31.putString("s", "POI Symbols");
11594 msg31.setData(b31);
11595 NavitGraphics.callback_handler.sendMessage(msg31);
11596
11597 msg31 = new Message();
11598 b31 = new Bundle();
11599 b31.putInt("Callback", 59);
11600 b31.putString("s", "POI Labels");
11601 msg31.setData(b31);
11602 NavitGraphics.callback_handler.sendMessage(msg31);
11603
11604 msg31 = new Message();
11605 b31 = new Bundle();
11606 b31.putInt("Callback", 60);
11607 b31.putString("s", "Android-POI-Icons-full");
11608 msg31.setData(b31);
11609 NavitGraphics.callback_handler.sendMessage(msg31);
11610
11611 msg31 = new Message();
11612 b31 = new Bundle();
11613 b31.putInt("Callback", 60);
11614 b31.putString("s", "Android-POI-Labels-full");
11615 msg31.setData(b31);
11616 NavitGraphics.callback_handler.sendMessage(msg31);
11617
11618 msg31 = new Message();
11619 b31 = new Bundle();
11620 b31.putInt("Callback", 59);
11621 b31.putString("s", "streets");
11622 msg31.setData(b31);
11623 NavitGraphics.callback_handler.sendMessage(msg31);
11624
11625 msg31 = new Message();
11626 b31 = new Bundle();
11627 b31.putInt("Callback", 59);
11628 b31.putString("s", "streets_1");
11629 msg31.setData(b31);
11630 NavitGraphics.callback_handler.sendMessage(msg31);
11631
11632 msg31 = new Message();
11633 b31 = new Bundle();
11634 b31.putInt("Callback", 59);
11635 b31.putString("s", "streets_2");
11636 msg31.setData(b31);
11637 NavitGraphics.callback_handler.sendMessage(msg31);
11638
11639 msg31 = new Message();
11640 b31 = new Bundle();
11641 b31.putInt("Callback", 60);
11642 b31.putString("s", "streets_STR_ONLY");
11643 msg31.setData(b31);
11644 NavitGraphics.callback_handler.sendMessage(msg31);
11645
11646 msg31 = new Message();
11647 b31 = new Bundle();
11648 b31.putInt("Callback", 60);
11649 b31.putString("s", "streets_1_STR_ONLY");
11650 msg31.setData(b31);
11651 NavitGraphics.callback_handler.sendMessage(msg31);
11652
11653 msg31 = new Message();
11654 b31 = new Bundle();
11655 b31.putInt("Callback", 60);
11656 b31.putString("s", "streets_2_STR_ONLY");
11657 msg31.setData(b31);
11658 NavitGraphics.callback_handler.sendMessage(msg31);
11659 // ----------------------- streets only pref -------------------
11660 }
11661
11662 // ---------- set traffic factor for road speeds ------------
11663 try
11664 {
11665 Message msg_ss1 = new Message();
11666 Bundle b_ss1 = new Bundle();
11667 b_ss1.putInt("Callback", 106);
11668 b_ss1.putString("s", Integer.toString(p.PREF_traffic_speed_factor));
11669 msg_ss1.setData(b_ss1);
11670 NavitGraphics.callback_handler.sendMessage(msg_ss1);
11671 }
11672 catch (Exception e)
11673 {
11674 }
11675 // ---------- set traffic factor for road speeds ------------
11676
11677 // ------- PREF_show_poi_on_map ---------------------------------
11678 set_poi_layers();
11679 // ------- PREF_show_poi_on_map ---------------------------------
11680
11681 // set vars for mapdir change (only really takes effect after restart!)
11682 getPrefs_mapdir();
11683
11684 if (need_recalc_route)
11685 {
11686 recalculate_route();
11687 need_recalc_route = false;
11688 }
11689
11690 }
11691
11692 @SuppressLint("NewApi")
11693 private static void getPrefs_mapdir()
11694 {
11695 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
11696
11697 // Get the xml/preferences.xml preferences
11698 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
11699 String default_sdcard_dir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/zanavi/maps/";
11700 String default_sdcard_dir_1 = default_sdcard_dir;
11701 System.out.println("DataStorageDir[s1]=" + default_sdcard_dir_1);
11702
11703 // check for Android KitKat 4.4 ---------------
11704 try
11705 {
11706 if (Integer.valueOf(android.os.Build.VERSION.SDK) > 18)
11707 {
11708 // use app private dir
11709 default_sdcard_dir = Navit.getBaseContext_.getExternalFilesDir(null).getAbsolutePath();
11710 }
11711 }
11712 catch (Exception e)
11713 {
11714 }
11715 // check for Android KitKat 4.4 ---------------
11716
11717 try
11718 {
11719 NavitDataStorageDirs = android.support.v4.content.ContextCompat.getExternalFilesDirs(Navit.getBaseContext_, null);
11720
11721 if (NavitDataStorageDirs.length > 0)
11722 {
11723 // use new method
11724 default_sdcard_dir = NavitDataStorageDirs[0].getAbsolutePath() + "/zanavi/maps/";
11725 System.out.println("DataStorageDir count=" + NavitDataStorageDirs.length);
11726
11727 for (int jj2 = 0; jj2 < NavitDataStorageDirs.length; jj2++)
11728 {
11729 if (NavitDataStorageDirs[jj2] != null)
11730 {
11731 System.out.println("DataStorageDir[" + jj2 + "]=" + NavitDataStorageDirs[jj2].getAbsolutePath() + "/zanavi/maps/");
11732 }
11733 }
11734 }
11735
11736 if (NavitDataStorageDirs.length == 1)
11737 {
11738 File tf = null;
11739 File[] NavitDataStorageDirs_ = new File[NavitDataStorageDirs.length + 1];
11740
11741 try
11742 {
11743 Map<String, File> externalLocations = ExternalStorage.getAllStorageLocations();
11744 // String sdCard__ = externalLocations.get(ExternalStorage.SD_CARD).getAbsolutePath();
11745 String externalSdCard__ = externalLocations.get(ExternalStorage.EXTERNAL_SD_CARD).getAbsolutePath();
11746 // System.out.println("DataStorageDir[sd]=" + sdCard__);
11747 System.out.println("DataStorageDir[external sd]=" + externalSdCard__);
11748
11749 for (int jj2 = 0; jj2 < NavitDataStorageDirs.length; jj2++)
11750 {
11751 if (NavitDataStorageDirs[jj2] == null)
11752 {
11753 NavitDataStorageDirs_[jj2] = null;
11754 }
11755 else
11756 {
11757 NavitDataStorageDirs_[jj2] = new File(NavitDataStorageDirs[jj2].getAbsolutePath() + "/zanavi/maps/");
11758 }
11759 }
11760
11761 tf = new File(externalLocations.get(ExternalStorage.EXTERNAL_SD_CARD).getAbsolutePath() + "/Android/data/com.zoffcc.applications.zanavi/files" + "/zanavi/maps/");
11762 }
11763 catch (Exception e)
11764 {
11765 tf = null;
11766 }
11767
11768 if (tf != null)
11769 {
11770 NavitDataStorageDirs_[NavitDataStorageDirs.length] = tf;
11771 NavitDataStorageDirs = null;
11772 NavitDataStorageDirs = NavitDataStorageDirs_;
11773 }
11774 }
11775
11776 }
11777 catch (Exception e)
11778 {
11779 System.out.println("DataStorageDir Ex002");
11780 e.printStackTrace();
11781 }
11782
11783 //Log.e("Navit", "old sdcard dir=" + NavitDataDirectory_Maps);
11784 //Log.e("Navit", "default sdcard dir=" + default_sdcard_dir);
11785 NavitDataDirectory_Maps = prefs.getString("map_directory", default_sdcard_dir + "/zanavi/maps/");
11786 String Navit_storage_directory_select = prefs.getString("storage_directory", "-1");
11787 int Navit_storage_directory_select_i = 0;
11788 try
11789 {
11790 Navit_storage_directory_select_i = Integer.parseInt(Navit_storage_directory_select);
11791 }
11792 catch (Exception e)
11793 {
11794
11795 }
11796 System.out.println("DataStorageDir[sel 1]=" + NavitDataDirectory_Maps);
11797 System.out.println("DataStorageDir[sel 2]=" + Navit_storage_directory_select);
11798
11799 if (Navit_storage_directory_select_i > 0)
11800 {
11801 NavitDataDirectory_Maps = NavitDataStorageDirs[Navit_storage_directory_select_i - 1].getAbsolutePath();
11802 }
11803 System.out.println("DataStorageDir[*in use*]=" + NavitDataDirectory_Maps);
11804
11805 // Navit_storage_directory_select:
11806 // -1 --> first run -> select best dir for user
11807 // 0 --> use custom directory
11808 // 1..n --> select default dir on SD Card number 1..n
11809
11810 // ** DEBUG ** set dir manually ** // NavitDataDirectory_Maps = default_sdcard_dir + "/zanavi/maps/";
11811 // ** DEBUG ** NavitDataDirectory_Maps = prefs.getString("navit_mapsdir", "/sdcard" + "/zanavi/maps/");
11812 //Log.e("Navit", "new sdcard dir=" + NavitDataDirectory_Maps);
11813
11814 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
11815 }
11816
11817 static String sanity_check_maps_dir(String check_dir)
11818 {
11819 String ret = check_dir;
11820 ret = ret.replaceAll("\\n", ""); // newline -> ""
11821 ret = ret.replaceAll("\\r", ""); // return -> ""
11822 ret = ret.replaceAll("\\t", ""); // tab -> ""
11823 ret = ret.replaceAll(" ", ""); // space -> ""
11824 ret = ret.replaceAll("\"", ""); // \" -> ""
11825 ret = ret.replaceAll("'", ""); // \' -> ""
11826 ret = ret.replaceAll("\\\\", ""); // "\" -> ""
11827 if (!ret.endsWith("/"))
11828 {
11829 ret = ret + "/";
11830 }
11831 // System.out.println("sanity check:" + ret);
11832 return ret;
11833 }
11834
11835 private static void activatePrefs_mapdir(Boolean at_startup)
11836 {
11837 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
11838
11839 // activate the new directory
11840 NavitDataDirectory_Maps = sanity_check_maps_dir(NavitDataDirectory_Maps);
11841 MAP_FILENAME_PATH = NavitDataDirectory_Maps;
11842 MAPMD5_FILENAME_PATH = NavitDataDirectory_Maps + "/../md5/";
11843 CFG_FILENAME_PATH = NavitDataDirectory_Maps + "/../";
11844 NAVIT_DATA_DEBUG_DIR = CFG_FILENAME_PATH + "../debug/";
11845
11846 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
11847 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
11848 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
11849 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
11850 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
11851 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
11852 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
11853 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
11854 //System.out.println("xxxxxxxx************XXXXXXXXXXX");
11855
11856 Handler h_temp = null;
11857 h_temp = NavitGraphics.callback_handler_s;
11858 //System.out.println("handler 1=" + h_temp.toString());
11859
11860 Message msg1 = new Message();
11861 Bundle b1 = new Bundle();
11862 b1.putInt("Callback", 47);
11863 b1.putString("s", MAP_FILENAME_PATH);
11864 msg1.setData(b1);
11865 h_temp.sendMessage(msg1);
11866
11867 if (!at_startup)
11868 {
11869 Message msg2 = new Message();
11870 Bundle b2 = new Bundle();
11871 b2.putInt("Callback", 18);
11872 msg2.setData(b2);
11873 h_temp.sendMessage(msg2);
11874 }
11875
11876 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
11877 }
11878
11879 private void getPrefs_theme()
11880 {
11881 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
11882 int theme_tmp = Integer.parseInt(prefs.getString("current_theme", "0"));
11883 // 0 -> Navit.DEFAULT_THEME_OLD_DARK
11884 // 1 -> Navit.DEFAULT_THEME_OLD_LIGHT
11885 p.PREF_current_theme = Navit.DEFAULT_THEME_OLD_DARK;
11886 if (theme_tmp == 1)
11887 {
11888 p.PREF_current_theme = Navit.DEFAULT_THEME_OLD_LIGHT;
11889 }
11890 else
11891 {
11892 p.PREF_current_theme = Navit.DEFAULT_THEME_OLD_DARK;
11893 }
11894
11895 }
11896
11897 private void getPrefs_theme_main()
11898 {
11899 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
11900 int theme_tmp = Integer.parseInt(prefs.getString("current_theme", "0"));
11901 // 0 -> Navit.DEFAULT_THEME_OLD_DARK
11902 // 1 -> Navit.DEFAULT_THEME_OLD_LIGHT
11903 p.PREF_current_theme_M = Navit.DEFAULT_THEME_OLD_DARK_M;
11904 if (theme_tmp == 1)
11905 {
11906 p.PREF_current_theme_M = Navit.DEFAULT_THEME_OLD_LIGHT_M;
11907 }
11908 else
11909 {
11910 p.PREF_current_theme_M = Navit.DEFAULT_THEME_OLD_DARK_M;
11911 }
11912
11913 }
11914
11915 private static void getPrefs_loc()
11916 {
11917 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
11918
11919 // Get the xml/preferences.xml preferences
11920 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
11921 p.PREF_navit_lang = prefs.getString("navit_lang", "*DEFAULT*");
11922 System.out.println("**** ***** **** pref lang=" + p.PREF_navit_lang);
11923
11924 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
11925 }
11926
11927 private static void activatePrefs_loc()
11928 {
11929 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
11930
11931 // creating locale
11932 if (!p.PREF_navit_lang.equals("*DEFAULT*"))
11933 {
11934 Locale locale2 = null;
11935 if (p.PREF_navit_lang.contains("_"))
11936 {
11937 String _lang = p.PREF_navit_lang.split("_", 2)[0];
11938 String _country = p.PREF_navit_lang.split("_", 2)[1];
11939 System.out.println("l=" + _lang + " c=" + _country);
11940 locale2 = new Locale(_lang, _country);
11941 }
11942 else
11943 {
11944 locale2 = new Locale(p.PREF_navit_lang);
11945 }
11946 Locale.setDefault(locale2);
11947 Configuration config2 = new Configuration();
11948 config2.locale = locale2;
11949 // updating locale
11950 getBaseContext_.getResources().updateConfiguration(config2, null);
11951 }
11952
11953 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
11954 }
11955
11956 private static void getPrefs_mapcache()
11957 {
11958 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Navit.getBaseContext_);
11959 try
11960 {
11961 p.PREF_mapcache = Integer.parseInt(prefs.getString("mapcache", "" + (10 * 1024)));
11962 }
11963 catch (Exception e)
11964 {
11965 e.printStackTrace();
11966 p.PREF_mapcache = 10 * 1024;
11967 }
11968 System.out.println("**** ***** **** pref mapcache=" + p.PREF_mapcache);
11969 }
11970
11971 private static void activatePrefs_mapcache()
11972 {
11973 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
11974
11975 Handler h_temp2 = null;
11976 h_temp2 = NavitGraphics.callback_handler_s;
11977 System.out.println("activatePrefs_mapcache " + NavitGraphics.callback_handler_s);
11978 Message msg7 = new Message();
11979 Bundle b7 = new Bundle();
11980 b7.putInt("Callback", 55);
11981 b7.putString("s", String.valueOf(p.PREF_mapcache * 1024));
11982 msg7.setData(b7);
11983 h_temp2.sendMessage(msg7);
11984
11985 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
11986 }
11987
11988 public native void NavitMain(Navit x, String lang, int version, String display_density_string, String n_datadir, String n_sharedir, Bitmap main_map_bitmap);
11989
11990 public native void NavitActivity(int activity);
11991
11992 /*
11993 * this is used to load the 'navit' native library on
11994 * application startup. The library has already been unpacked at
11995 * installation time by the package manager.
11996 */
11997 static
11998 {
11999 System.loadLibrary("navit");
12000 }
12001
12002 /*
12003 * Show a search activity with the string "search" filled in
12004 */
12005 private void executeSearch(String search)
12006 {
12007 Navit.use_index_search = Navit.allow_use_index_search();
12008 Intent search_intent = new Intent(this, NavitAddressSearchActivity.class);
12009 search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS
12010 search_intent.putExtra("address_string", search);
12011 search_intent.putExtra("type", "offline");
12012 search_intent.putExtra("search_country_id", Navit_last_address_search_country_id);
12013 String pm_temp = "0";
12014 if (Navit_last_address_partial_match)
12015 {
12016 pm_temp = "1";
12017 }
12018 search_intent.putExtra("partial_match", pm_temp);
12019 this.startActivityForResult(search_intent, NavitAddressSearch_id_offline);
12020 }
12021
12022 private void share_location(String lat, String lon, String name, String subject_text, String time_at_destination, boolean is_dest)
12023 {
12024 Intent intent = new Intent(Intent.ACTION_SEND);
12025 intent.setType("text/plain");
12026 String url;
12027 final String map_zoomlevel = "18";
12028 // url = "" + lat + "," + lon + "\n" + name;
12029 url = "http://maps.google.com/?q=" + lat + "," + lon + "&z=" + map_zoomlevel + "\n\n" + name;
12030
12031 if (is_dest)
12032 {
12033 if (time_at_destination.compareTo("") != 0)
12034 {
12035 url = url + " " + time_at_destination;
12036 }
12037 }
12038
12039 intent.putExtra(Intent.EXTRA_TEXT, url);
12040 intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject_text);
12041 //Uri uri = Uri.parse("geo:0,0?z=16&q=" + lat + "," + lon);
12042 //intent.putExtra(Intent.EXTRA_STREAM, uri);
12043
12044 // shut down TTS ---------------
12045 // if (!Navit.is_navigating)
12046 // {
12047 // try
12048 // {
12049 // mTts.stop();
12050 // }
12051 // catch (Exception e)
12052 // {
12053 //
12054 // }
12055 //
12056 // try
12057 // {
12058 // mTts.shutdown();
12059 // }
12060 // catch (Exception e)
12061 // {
12062 //
12063 // }
12064 // }
12065 // shut down TTS ---------------
12066
12067 startActivityForResult(Intent.createChooser(intent, Navit.get_text("Share")), NavitAddressSearch_id_sharedest); // TRANS
12068 }
12069
12070 /*
12071 * open google maps at a given coordinate
12072 */
12073 private void googlemaps_show(String lat, String lon, String name)
12074 {
12075 // geo:latitude,longitude
12076 String url = null;
12077 Intent gmaps_intent = new Intent(Intent.ACTION_VIEW);
12078
12079 //url = "geo:" + lat + "," + lon + "?z=" + "16";
12080 //url = "geo:0,0?q=" + lat + "," + lon + " (" + name + ")";
12081 url = "geo:0,0?z=16&q=" + lat + "," + lon + " (" + name + ")";
12082
12083 gmaps_intent.setData(Uri.parse(url));
12084 this.startActivityForResult(gmaps_intent, NavitAddressSearch_id_gmaps);
12085 }
12086
12087 public void zoom_out_full()
12088 {
12089 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
12090
12091 System.out.println("");
12092 System.out.println("*** Zoom out FULL ***");
12093 System.out.println("");
12094 Message msg = new Message();
12095 Bundle b = new Bundle();
12096 b.putInt("Callback", 8);
12097 msg.setData(b);
12098 NavitGraphics.callback_handler.sendMessage(msg);
12099
12100 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
12101 }
12102
12103 static public void show_geo_on_screen_with_zoom_and_delay(float lat, float lon)
12104 {
12105 show_geo_on_screen_with_zoom_and_delay(lat, lon, 0);
12106 }
12107
12108 @SuppressLint("NewApi")
12109 static public void show_geo_on_screen_with_zoom_and_delay(final float lat, final float lon, final int millis_start_delay)
12110 {
12111 System.out.println("XSOM:010");
12112
12113 // if (api_version_int < 11)
12114 // {
12115 //
12116 // new AsyncTask<Void, Void, String>()
12117 // {
12118 // @Override
12119 // protected String doInBackground(Void... params)
12120 // {
12121 // System.out.println("XSOM:011");
12122 //
12123 // try
12124 // {
12125 // System.out.println("XSOM:001");
12126 // Thread.sleep((long) millis_start_delay);
12127 // Navit.show_geo_on_screen_no_draw(lat, lon);
12128 // System.out.println("XSOM:002");
12129 // Thread.sleep(100);
12130 // Navit.set_zoom_level_no_draw(Navit.Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL);
12131 // System.out.println("XSOM:004");
12132 // Thread.sleep(120);
12133 // Navit.draw_map();
12134 // System.out.println("XSOM:005");
12135 // }
12136 // catch (Exception e)
12137 // {
12138 // }
12139 //
12140 // return "";
12141 // }
12142 //
12143 // @Override
12144 // protected void onPostExecute(String msg)
12145 // {
12146 //
12147 // }
12148 // }.execute(null, null, null);
12149 //
12150 // }
12151 // else
12152 // {
12153 // new AsyncTask<Void, Void, String>()
12154 // {
12155 // @Override
12156 // protected String doInBackground(Void... params)
12157 // {
12158 // System.out.println("XSOM:011");
12159 //
12160 // try
12161 // {
12162 // System.out.println("XSOM:001");
12163 // Thread.sleep((long) millis_start_delay);
12164 // Navit.show_geo_on_screen_no_draw(lat, lon);
12165 // System.out.println("XSOM:002");
12166 // Thread.sleep(100);
12167 // Navit.set_zoom_level_no_draw(Navit.Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL);
12168 // System.out.println("XSOM:004");
12169 // Thread.sleep(120);
12170 // Navit.draw_map();
12171 // System.out.println("XSOM:005");
12172 // }
12173 // catch (Exception e)
12174 // {
12175 // }
12176 //
12177 // return "";
12178 // }
12179 //
12180 // @Override
12181 // protected void onPostExecute(String msg)
12182 // {
12183 //
12184 // }
12185 // }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
12186 //
12187 // }
12188
12189 final Thread temp_work_thread = new Thread()
12190 {
12191 @Override
12192 public void run()
12193 {
12194 try
12195 {
12196 Thread.sleep((long) millis_start_delay);
12197 Navit.show_geo_on_screen_no_draw(lat, lon);
12198 Thread.sleep(500);
12199 Navit.set_zoom_level_no_draw(Navit.Navit_SHOW_DEST_ON_MAP_ZOOMLEVEL);
12200 Thread.sleep(120);
12201 Navit.draw_map();
12202 }
12203 catch (Exception e2)
12204 {
12205 e2.printStackTrace();
12206 }
12207 }
12208 };
12209 temp_work_thread.start();
12210 }
12211
12212 static public void show_geo_on_screen(float lat, float lng)
12213 {
12214 // this function sets screen center to "lat, lon", and just returns a dummy string!
12215 Navit.cwthr.CallbackGeoCalc2(2, 3, lat, lng);
12216 }
12217
12218 static public void show_geo_on_screen_no_draw(float lat, float lng)
12219 {
12220 // this function sets screen center to "lat, lon", and just returns a dummy string!
12221 Navit.cwthr.CallbackGeoCalc2(2, 15, lat, lng);
12222 }
12223
12224 public static void zoom_to_route()
12225 {
12226 try
12227 {
12228 //System.out.println("");
12229 //System.out.println("*** Zoom to ROUTE ***");
12230 //System.out.println("");
12231 Message msg = new Message();
12232 Bundle b = new Bundle();
12233 b.putInt("Callback", 17);
12234 msg.setData(b);
12235 NavitGraphics.callback_handler.sendMessage(msg);
12236
12237 set_map_position_to_screen_center();
12238 }
12239 catch (Exception e)
12240 {
12241 }
12242 }
12243
12244 static void set_map_position_to_screen_center()
12245 {
12246 try
12247 {
12248 Message msg = new Message();
12249 Bundle b = new Bundle();
12250 b.putInt("Callback", 51);
12251
12252 if (Navit.GFX_OVERSPILL)
12253 {
12254 b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getWidth() / 2) + NavitGraphics.mCanvasWidth_overspill)));
12255 b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getHeight() / 2) + NavitGraphics.mCanvasHeight_overspill)));
12256 }
12257 else
12258 {
12259 b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getWidth() / 2));
12260 b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getHeight() / 2));
12261 }
12262 msg.setData(b);
12263 NavitGraphics.callback_handler.sendMessage(msg);
12264 }
12265 catch (Exception e)
12266 {
12267 }
12268 }
12269
12270 public void turn_on_compass()
12271 {
12272 try
12273 {
12274 if (!p.PREF_use_compass_heading_fast)
12275
12276 {
12277 // Slower
12278 sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
12279 }
12280 else
12281 {
12282 // FAST
12283 sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_UI);
12284 }
12285 }
12286 catch (Exception e)
12287 {
12288 e.printStackTrace();
12289 }
12290 }
12291
12292 public void turn_off_compass()
12293 {
12294 try
12295 {
12296 sensorManager.unregisterListener(this);
12297 }
12298 catch (Exception e)
12299 {
12300 e.printStackTrace();
12301 }
12302 }
12303
12304 public void onSensorChanged(SensorEvent event)
12305 {
12306
12307 if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
12308 {
12309 // System.out.println("Sensor.TYPE_MAGNETIC_FIELD");
12310 return;
12311 }
12312
12313 if (event.sensor.getType() == Sensor.TYPE_ORIENTATION)
12314 {
12315 // System.out.println("Sensor.TYPE_ORIENTATION");
12316
12317 // compass
12318 float myAzimuth = event.values[0];
12319 // double myPitch = event.values[1];
12320 // double myRoll = event.values[2];
12321
12322 //String out = String.format("Azimuth: %.2f", myAzimuth);
12323 //System.out.println("compass: " + out);
12324 NavitVehicle.update_compass_heading(myAzimuth);
12325 }
12326 }
12327
12328 public void onAccuracyChanged(Sensor sensor, int accuracy)
12329 {
12330 // compass
12331 }
12332
12333 public void hide_status_bar()
12334 {
12335 if (!p.PREF_show_status_bar)
12336 {
12337 // Hide the Status Bar
12338 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN | WindowManager.LayoutParams.FLAG_FULLSCREEN);
12339 }
12340 }
12341
12342 public void show_status_bar()
12343 {
12344 // Show the Status Bar
12345 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN | WindowManager.LayoutParams.FLAG_FULLSCREEN);
12346 }
12347
12348 public void hide_title_bar()
12349 {
12350 // -- unsued !!!! --
12351 // -- unsued !!!! --
12352 // -- unsued !!!! --
12353
12354 // Hide the Title Bar - this works ONLY before setcontent in onCreate!!
12355 requestWindowFeature(Window.FEATURE_NO_TITLE);
12356 }
12357
12358 public void show_title_bar()
12359 {
12360 // -- unsued !!!! --
12361 // -- unsued !!!! --
12362 // -- unsued !!!! --
12363
12364 // Hide the Title Bar - this works ONLY before setcontent in onCreate!!
12365 // ?? requestWindowFeature(Window.);
12366 }
12367
12368 public static Boolean downloadGPSXtra(Context context)
12369 {
12370 Boolean ret = false;
12371 Boolean ret2 = false;
12372 try
12373 {
12374 LocationManager locationmanager2 = (LocationManager) context.getSystemService("location");
12375 Bundle bundle = new Bundle();
12376 //ret2 = locationmanager2.sendExtraCommand("gps", "delete_aiding_data", null);
12377 //ret = ret2;
12378 // System.out.println("ret0=" + ret);
12379 ret2 = locationmanager2.sendExtraCommand("gps", "force_xtra_injection", bundle);
12380 ret = ret2;
12381 //System.out.println("ret1=" + ret2);
12382 ret2 = locationmanager2.sendExtraCommand("gps", "force_time_injection", bundle);
12383 ret = ret || ret2;
12384 //System.out.println("ret2=" + ret2);
12385 }
12386 catch (Exception e)
12387 {
12388 //System.out.println("*XX*");
12389 e.printStackTrace();
12390 }
12391 return ret;
12392 }
12393
12394 static void remove_oldest_normal_point()
12395 {
12396 int i;
12397 for (i = 0; i < map_points.size(); i++)
12398 {
12399 Navit_Point_on_Map element_temp = map_points.get(i);
12400 if (element_temp.addon == null)
12401 {
12402 // its a normal (non home, non special item), so can remove it, and return.
12403 break;
12404 }
12405 }
12406 }
12407
12408 static int find_home_point()
12409 {
12410 int home_id = -1;
12411 int i;
12412
12413 for (i = 0; i < map_points.size(); i++)
12414 {
12415 Navit_Point_on_Map element_temp = map_points.get(i);
12416 if (element_temp.addon != null)
12417 {
12418 if (element_temp.addon.equals("1"))
12419 {
12420 // found home
12421 return i;
12422 }
12423 }
12424 }
12425 return home_id;
12426 }
12427
12428 static void readd_home_point()
12429 {
12430 try
12431 {
12432 int home_id = find_home_point();
12433 if (home_id != -1)
12434 {
12435 Navit_Point_on_Map element_old = map_points.get(home_id);
12436 map_points.remove(home_id);
12437 map_points.add(element_old);
12438 }
12439 }
12440 catch (Exception e)
12441 {
12442 }
12443 }
12444
12445 static void add_map_point(Navit_Point_on_Map element)
12446 {
12447 if (element == null)
12448 {
12449 return;
12450 }
12451
12452 if (map_points == null)
12453 {
12454 map_points = new ArrayList<Navit_Point_on_Map>();
12455 }
12456
12457 int el_pos = get_destination_pos(element);
12458 // int home_id = find_home_point();
12459 boolean is_home = is_home_element(element);
12460
12461 // System.out.println("EEPOS:el_pos=" + el_pos + " is_home=" + is_home);
12462
12463 if (is_home)
12464 {
12465 // its the "home" destination
12466 return;
12467 }
12468
12469 if (map_points.size() > Navit_MAX_RECENT_DESTINATIONS)
12470 {
12471 try
12472 {
12473 // map_points.remove(0);
12474 remove_oldest_normal_point();
12475 }
12476 catch (Exception e)
12477 {
12478 }
12479 }
12480
12481 if (el_pos == -1)
12482 {
12483 // if not duplicate, then add
12484 map_points.add(element);
12485 readd_home_point();
12486 write_map_points();
12487 }
12488 else
12489 {
12490 try
12491 {
12492 // if already in list, then first remove and add again
12493 // that moves it to the top of the list
12494 Navit_Point_on_Map element_old = map_points.get(el_pos);
12495 map_points.remove(el_pos);
12496 map_points.add(element_old);
12497 readd_home_point();
12498 write_map_points();
12499 }
12500 catch (Exception e)
12501 {
12502 e.printStackTrace();
12503 }
12504 }
12505 }
12506
12507 void read_map_points()
12508 {
12509 deserialize_map_points();
12510 }
12511
12512 static void write_map_points()
12513 {
12514 if (map_points != null)
12515 {
12516 serialize_map_points();
12517 }
12518 }
12519
12520 private static void serialize_map_points()
12521 {
12522 FileOutputStream fos;
12523 try
12524 {
12525 fos = new FileOutputStream(NAVIT_DATA_SHARE_DIR + Navit_DEST_FILENAME);
12526 // openFileOutput(CFG_FILENAME_PATH + Navit_DEST_FILENAME, Context.MODE_PRIVATE);
12527 ObjectOutputStream oos = new ObjectOutputStream(fos);
12528 oos.writeObject(map_points);
12529 oos.close();
12530 }
12531 catch (FileNotFoundException e)
12532 {
12533 e.printStackTrace();
12534 }
12535 catch (IOException e)
12536 {
12537 e.printStackTrace();
12538 }
12539 catch (Exception e)
12540 {
12541 e.printStackTrace();
12542 }
12543 }
12544
12545 private void export_map_points_to_sdcard()
12546 {
12547 String orig_file = NAVIT_DATA_SHARE_DIR + Navit_DEST_FILENAME;
12548 String dest_file_dir = CFG_FILENAME_PATH + "../export/";
12549
12550 try
12551 {
12552 File dir = new File(dest_file_dir);
12553 dir.mkdirs();
12554 }
12555 catch (Exception e)
12556 {
12557 e.printStackTrace();
12558 }
12559
12560 try
12561 {
12562 File source = new File(orig_file);
12563 File destination = new File(dest_file_dir + Navit_DEST_FILENAME);
12564
12565 if (source.exists())
12566 {
12567 FileInputStream fi = new FileInputStream(source);
12568 FileOutputStream fo = new FileOutputStream(destination);
12569 FileChannel src = fi.getChannel();
12570 FileChannel dst = fo.getChannel();
12571 dst.transferFrom(src, 0, src.size());
12572 src.close();
12573 dst.close();
12574 fi.close();
12575 fo.close();
12576 }
12577 }
12578 catch (Exception e)
12579 {
12580 e.printStackTrace();
12581 }
12582 }
12583
12584 private void import_map_points_from_sdcard()
12585 {
12586 String orig_file = NAVIT_DATA_SHARE_DIR + Navit_DEST_FILENAME;
12587 String dest_file_dir = CFG_FILENAME_PATH + "../export/";
12588
12589 try
12590 {
12591 File source = new File(dest_file_dir + Navit_DEST_FILENAME);
12592 File destination = new File(orig_file);
12593
12594 if (source.exists())
12595 {
12596 FileInputStream fi = new FileInputStream(source);
12597 FileOutputStream fo = new FileOutputStream(destination);
12598 FileChannel src = fi.getChannel();
12599 FileChannel dst = fo.getChannel();
12600 dst.transferFrom(src, 0, src.size());
12601 src.close();
12602 dst.close();
12603 fi.close();
12604 fo.close();
12605 }
12606 }
12607 catch (Exception e)
12608 {
12609 e.printStackTrace();
12610 }
12611
12612 read_map_points();
12613 }
12614
12615 //@SuppressWarnings("unchecked")
12616 private void deserialize_map_points()
12617 {
12618 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
12619
12620 FileInputStream fis = null;
12621 ObjectInputStream ois = null;
12622
12623 try
12624 {
12625 fis = new FileInputStream(NAVIT_DATA_SHARE_DIR + Navit_DEST_FILENAME);
12626 // openFileInput(CFG_FILENAME_PATH + Navit_DEST_FILENAME);
12627 ois = new ObjectInputStream(fis);
12628 map_points = (ArrayList<Navit_Point_on_Map>) ois.readObject();
12629 }
12630 catch (FileNotFoundException e)
12631 {
12632 e.printStackTrace();
12633 map_points = new ArrayList<Navit_Point_on_Map>();
12634 }
12635 catch (IOException e)
12636 {
12637 e.printStackTrace();
12638 map_points = new ArrayList<Navit_Point_on_Map>();
12639 }
12640 catch (ClassNotFoundException e)
12641 {
12642 e.printStackTrace();
12643 map_points = new ArrayList<Navit_Point_on_Map>();
12644 }
12645 catch (Exception e)
12646 {
12647 e.printStackTrace();
12648 map_points = new ArrayList<Navit_Point_on_Map>();
12649 }
12650
12651 try
12652 {
12653 if (ois != null)
12654 {
12655 ois.close();
12656 }
12657 }
12658 catch (Exception e)
12659 {
12660 }
12661
12662 try
12663 {
12664 if (fis != null)
12665 {
12666 ois.close();
12667 }
12668 }
12669 catch (Exception e)
12670 {
12671 }
12672
12673 // for (int j = 0; j < map_points.size(); j++)
12674 // {
12675 // System.out.println("####******************" + j + ":" + map_points.get(j).point_name);
12676 // }
12677
12678 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
12679
12680 }
12681
12682 static void remember_destination_xy(String name, int x, int y)
12683 {
12684 // i=1 -> pixel a,b (x,y) -> geo string "lat(float):lng(float)"
12685 // i=2 -> geo a,b (lat,lng) -> pixel string "x(int):y(int)"
12686 String lat_lon = NavitGraphics.CallbackGeoCalc(1, (x + NavitGraphics.mCanvasWidth_overspill) * NavitGraphics.Global_dpi_factor, (y + NavitGraphics.mCanvasHeight_overspill) * NavitGraphics.Global_dpi_factor);
12687 try
12688 {
12689 String tmp[] = lat_lon.split(":", 2);
12690 //System.out.println("tmp=" + lat_lon);
12691 float lat = Float.parseFloat(tmp[0]);
12692 float lon = Float.parseFloat(tmp[1]);
12693 //System.out.println("ret=" + lat_lon + " lat=" + lat + " lon=" + lon);
12694 remember_destination(name, lat, lon);
12695 }
12696 catch (Exception e)
12697 {
12698 e.printStackTrace();
12699
12700 }
12701 }
12702
12703 static void remember_destination(String name, String lat, String lon)
12704 {
12705 try
12706 {
12707 //System.out.println("22 **## " + name + " " + lat + " " + lon + " ##**");
12708 remember_destination(name, Float.parseFloat(lat), Float.parseFloat(lon));
12709 }
12710 catch (Exception e)
12711 {
12712 e.printStackTrace();
12713 }
12714 }
12715
12716 static void remember_destination(String name, float lat, float lon)
12717 {
12718 //System.out.println("11 **## " + name + " " + lat + " " + lon + " ##**");
12719 Navit_Point_on_Map t = new Navit_Point_on_Map();
12720 t.point_name = name;
12721 t.lat = lat;
12722 t.lon = lon;
12723 add_map_point(t);
12724 }
12725
12726 static void destination_set()
12727 {
12728 // status = "destination set"
12729 NavitGraphics.navit_route_status = 1;
12730 }
12731
12732 static Boolean check_dup_destination(Navit_Point_on_Map element)
12733 {
12734 Boolean ret = false;
12735 Navit_Point_on_Map t;
12736 for (int i = 0; i < map_points.size(); i++)
12737 {
12738 t = map_points.get(i);
12739 if (t.addon == null)
12740 {
12741 if ((t.point_name.equals(element.point_name)) && (t.lat == element.lat) && (t.lon == element.lon) && (element.addon == null))
12742 {
12743 return true;
12744 }
12745 }
12746 else
12747 {
12748 if ((t.point_name.equals(element.point_name)) && (t.lat == element.lat) && (t.lon == element.lon) && (t.addon.equals(element.addon)))
12749 {
12750 return true;
12751 }
12752 }
12753 }
12754 return ret;
12755 }
12756
12757 static int get_destination_pos(Navit_Point_on_Map element)
12758 {
12759 int ret = -1;
12760 Navit_Point_on_Map t;
12761 for (int i = 0; i < map_points.size(); i++)
12762 {
12763 t = map_points.get(i);
12764 if (t.addon == null)
12765 {
12766 if ((t.point_name.equals(element.point_name)) && (t.lat == element.lat) && (t.lon == element.lon) && (element.addon == null))
12767 {
12768 return i;
12769 }
12770 }
12771 else
12772 {
12773 if ((t.point_name.equals(element.point_name)) && (t.lat == element.lat) && (t.lon == element.lon) && (t.addon.equals(element.addon)))
12774 {
12775 return i;
12776 }
12777 }
12778 }
12779 return ret;
12780 }
12781
12782 static boolean is_home_element(Navit_Point_on_Map element)
12783 {
12784 int home_id = find_home_point();
12785 if (home_id != -1)
12786 {
12787 Navit_Point_on_Map home_element = map_points.get(home_id);
12788
12789 if ((home_element.point_name.equals(element.point_name)) && (home_element.lat == element.lat) && (home_element.lon == element.lon))
12790 {
12791 return true;
12792 }
12793
12794 }
12795
12796 return false;
12797 }
12798
12799 static NavitSpeech2 get_speech_object()
12800 {
12801 System.out.println("get_speech_object");
12802 return NSp;
12803 }
12804
12805 static NavitVehicle get_vehicle_object()
12806 {
12807 System.out.println("get_vehicle_object");
12808 return NV;
12809 }
12810
12811 static NavitGraphics get_graphics_object_by_name(String name)
12812 {
12813 System.out.println("get_graphics_object_by_name:*" + name + "*");
12814
12815 if (name.equals("type:map-main"))
12816 {
12817 System.out.println("map-main");
12818 return NG__map_main;
12819 }
12820 else
12821 {
12822 System.out.println("vehicle");
12823 return NG__vehicle;
12824 }
12825 }
12826
12827 public static Handler vehicle_handler = new Handler()
12828 {
12829 public void handleMessage(Message msg)
12830 {
12831 //System.out.println("vehicle_handler:handleMessage:JTHREAD ID=" + Thread.currentThread().getId());
12832 //System.out.println("vehicle_handler:handleMessage:THREAD ID=" + NavitGraphics.GetThreadId());
12833
12834 switch (msg.what)
12835 {
12836 case 1:
12837 Location l = new Location("Network");
12838 l.setLatitude(msg.getData().getFloat("lat"));
12839 l.setLongitude(msg.getData().getFloat("lng"));
12840 l.setBearing(msg.getData().getFloat("b"));
12841 l.setSpeed(0.8f);
12842 NavitVehicle.set_mock_location__fast(l);
12843 break;
12844 case 2:
12845 if (NavitVehicle.update_location_in_progress)
12846 {
12847 }
12848 else
12849 {
12850 NavitVehicle.update_location_in_progress = true;
12851 NavitVehicle.VehicleCallback2(NavitVehicle.last_location);
12852 NavitVehicle.update_location_in_progress = false;
12853 }
12854 break;
12855 }
12856 }
12857 };
12858
12859 public String roundTwoDecimals(double d)
12860 {
12861 return String.format(Locale.US, "%.2f", d);
12862 }
12863
12864 /* ZZ GEO TRANS ZZ */
12865 static double __EARTH_RADIUS__ = 6378137.000;
12866 static double __GEO_ACCURACY_FACTOR__ = 2.000;
12867 final static double M_PI_div_360 = 0.008726646259971647884618;
12868 final static double M_PI_div_180 = 0.01745329251994329576;
12869 final static double M_PI_mul_360 = 1130.97335529232556584560;
12870 final static double M_PI_mul_180 = 565.48667764616278292280;
12871
12872 /* ZZ GEO TRANS ZZ */
12873
12874 public static int transform_from_geo_lat(double lat)
12875 {
12876 /* ZZ GEO TRANS ZZ */
12877 int ret = (int) ((Math.log(Math.tan((Math.PI / 4f) + lat * M_PI_div_360)) * __EARTH_RADIUS__) * __GEO_ACCURACY_FACTOR__);
12878 return ret;
12879 }
12880
12881 public static int transform_from_geo_lon(double lon)
12882 {
12883 /* ZZ GEO TRANS ZZ */
12884 int ret = (int) ((lon * __EARTH_RADIUS__ * M_PI_div_180) * __GEO_ACCURACY_FACTOR__);
12885
12886 return ret;
12887 }
12888
12889 public static double transform_to_geo_lat(float y) // y
12890 {
12891 /* ZZ GEO TRANS ZZ */
12892 return (Math.atan(Math.exp((y / __GEO_ACCURACY_FACTOR__) / __EARTH_RADIUS__)) / M_PI_div_360 - 90);
12893 }
12894
12895 public static double transform_to_geo_lon(float x) // x
12896 {
12897 /* ZZ GEO TRANS ZZ */
12898 return ((x / __GEO_ACCURACY_FACTOR__) / __EARTH_RADIUS__ / M_PI_div_180);
12899 }
12900
12901 public static boolean allow_use_index_search()
12902 {
12903 if ((!Navit_DonateVersion_Installed) && (!Navit_Largemap_DonateVersion_Installed))
12904 {
12905 // no donate version installed
12906 Log.e("Navit", "no donate version installed");
12907
12908 Navit_index_on_but_no_idx_files = false;
12909 return false;
12910 }
12911
12912 boolean ret = false;
12913
12914 // MAP_FILENAME_PATH
12915 File folder = new File(MAP_FILENAME_PATH);
12916 File[] listOfFiles = folder.listFiles();
12917 File idx = null;
12918 File md5_file = null;
12919 FileOutputStream fos = null;
12920
12921 int files = 0;
12922 int file_without_index = 0;
12923
12924 for (File file : listOfFiles)
12925 {
12926 if (file.isFile())
12927 {
12928 // System.out.println("FFNN:" + file.getName());
12929
12930 if (file.getName().endsWith(".bin"))
12931 {
12932 if (!file.getName().equals("borders.bin"))
12933 {
12934 if (!file.getName().equals("coastline.bin"))
12935 {
12936 files++;
12937 idx = new File(folder, file.getName() + ".idx");
12938 if (idx.exists())
12939 {
12940 }
12941 else
12942 {
12943 file_without_index++;
12944
12945 String servername = "";
12946 try
12947 {
12948 servername = NavitMapDownloader.is_in_cat_file_disk_name(file.getName()).split(":", 2)[1];
12949 }
12950 catch (Exception ee)
12951 {
12952 }
12953
12954 if (!servername.equals(""))
12955 {
12956
12957 // index for this map is missing. hack MD5 file so we can download it again
12958 md5_file = new File(Navit.MAPMD5_FILENAME_PATH + "/" + servername + ".md5");
12959
12960 // System.out.println("FFNN:hack MD5:" + md5_file.getAbsolutePath() + " s=" + servername);
12961
12962 if ((md5_file.exists()) && (md5_file.canWrite()))
12963 {
12964 try
12965 {
12966 fos = new FileOutputStream(md5_file);
12967 fos.write(65);
12968 fos.write(65);
12969 fos.write(65);
12970 fos.close();
12971 }
12972 catch (Exception e1)
12973 {
12974 // System.out.println("FFNN:EEEEEEEEEEEEEE");
12975 }
12976 }
12977 }
12978 }
12979 }
12980 }
12981 }
12982
12983 if (file.getName().endsWith(".bin.idx"))
12984 {
12985 ret = true;
12986 }
12987 }
12988 }
12989
12990 if (files > 0)
12991 {
12992 if (file_without_index > 0)
12993 {
12994 Navit_index_on_but_no_idx_files = true;
12995 }
12996 else
12997 {
12998 Navit_index_on_but_no_idx_files = false;
12999 }
13000 }
13001
13002 return ret;
13003 }
13004
13005 private void sendEmail(String recipient, String subject, String message)
13006 {
13007 try
13008 {
13009 final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
13010 emailIntent.setType("plain/text");
13011 if (recipient != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { recipient });
13012 if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
13013 if (message != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
13014
13015 startActivity(Intent.createChooser(emailIntent, Navit.get_text("Send feedback via email ...")));
13016
13017 }
13018 catch (ActivityNotFoundException e)
13019 {
13020 // cannot send email for some reason
13021 }
13022 }
13023
13024 @SuppressLint("NewApi")
13025 void detect_menu_button()
13026 {
13027 // default: we dont have a real menu button
13028 has_hw_menu_button = false;
13029
13030 try
13031 {
13032 if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 14)
13033 {
13034 if (ViewConfiguration.get(getApplicationContext()).hasPermanentMenuKey())
13035 {
13036 has_hw_menu_button = true;
13037 }
13038 else
13039 {
13040 has_hw_menu_button = false;
13041 }
13042 }
13043 else
13044 {
13045 has_hw_menu_button = true;
13046 }
13047 }
13048 catch (Exception e)
13049 {
13050 // on error we must be on android API < 14 and therfore we have a menu button (that is what we assume)
13051 has_hw_menu_button = true;
13052 }
13053
13054 // now always show menu button icon
13055 has_hw_menu_button = false;
13056 }
13057
13058 public void onBackPressed()
13059 {
13060 // do something on back.
13061 //System.out.println("no back key!");
13062 // super.onBackPressed();
13063 // !!disable the back key otherwise!!
13064
13065 if (Navit_doubleBackToExitPressedOnce)
13066 {
13067
13068 try
13069 {
13070 if (wl_navigating != null)
13071 {
13072 //if (wl_navigating.isHeld())
13073 //{
13074 wl_navigating.release();
13075 Log.e("Navit", "WakeLock Nav: release 1");
13076 //}
13077 }
13078 }
13079 catch (Exception e)
13080 {
13081 e.printStackTrace();
13082 }
13083
13084 // super.onBackPressed(); --> this would only put the app in background
13085 // --------
13086 // exit the app here
13087 this.onPause();
13088 this.onStop();
13089 this.exit();
13090 // --------
13091 return;
13092 }
13093
13094 try
13095 {
13096 Navit_doubleBackToExitPressedOnce = true;
13097 Toast.makeText(this, Navit.get_text("Please press BACK again to Exit"), Toast.LENGTH_SHORT).show();
13098
13099 new Handler().postDelayed(new Runnable()
13100 {
13101 @Override
13102 public void run()
13103 {
13104 Navit_doubleBackToExitPressedOnce = false;
13105 }
13106 }, NAVIT_BACKBUTTON_TO_EXIT_TIME);
13107 }
13108 catch (Exception e)
13109 {
13110 }
13111
13112 try
13113 {
13114 // if bottom bar is up, animate it down on "back" press
13115 animate_bottom_bar_down();
13116 }
13117 catch (Exception e)
13118 {
13119 }
13120
13121 }
13122
13123 // public void openOptionsMenu_wrapper()
13124 // {
13125 // //openOptionsMenu();
13126 //
13127 // prepare_emu_options_menu();
13128 // NavitGraphics.emu_menu_view.set_adapter(EmulatedMenuView.MenuItemsList2, EmulatedMenuView.MenuItemsIdMapping2);
13129 // NavitGraphics.emu_menu_view.bringToFront();
13130 // NavitGraphics.emu_menu_view.setVisibility(View.VISIBLE);
13131 // }
13132
13133 public static String logHeap(Class clazz)
13134 {
13135 Double allocated = Double.valueOf(Debug.getNativeHeapAllocatedSize()) / Double.valueOf((1048576));
13136 Double sum_size = Double.valueOf(Debug.getNativeHeapSize() / Double.valueOf(1048576.0));
13137 Double free = Double.valueOf(Debug.getNativeHeapFreeSize() / Double.valueOf(1048576.0));
13138 DecimalFormat df = new DecimalFormat();
13139 df.setMaximumFractionDigits(2);
13140 df.setMinimumFractionDigits(2);
13141
13142 // Log.d("Navit", "MemMem:DEBUG: =================================");
13143 Log.d("Navit", "MemMem:DEBUG:heap native: allc " + df.format(allocated) + "MB sum=" + df.format(sum_size) + "MB (" + df.format(free) + "MB free) in [" + clazz.getName().replaceAll("com.zoffcc.applications.zanavi.", "") + "]");
13144 Log.d("Navit", "MemMem:DEBUG:java memory: allc: " + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "MB sum=" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "MB (" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)");
13145
13146 calcAvailableMemory();
13147
13148 String mem_type = "NATIVE";
13149 try
13150 {
13151 if (android.os.Build.VERSION.SDK_INT >= 11)
13152 {
13153 mem_type = "JAVA";
13154 }
13155 }
13156 catch (Exception e)
13157 {
13158 }
13159 return ("" + df.format(allocated) + "/" + df.format(sum_size) + "(" + df.format(free) + ")" + ":" + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "/" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "(" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + ") " + mem_type);
13160 }
13161
13162 private static long calcAvailableMemory()
13163 {
13164 try
13165 {
13166 long value = Runtime.getRuntime().maxMemory();
13167 String type = "";
13168 if (android.os.Build.VERSION.SDK_INT >= 11)
13169 {
13170 value = (value / 1024 / 1024) - (Runtime.getRuntime().totalMemory() / 1024 / 1024);
13171 type = "JAVA";
13172 }
13173 else
13174 {
13175 value = (value / 1024 / 1024) - (Debug.getNativeHeapAllocatedSize() / 1024 / 1024);
13176 type = "NATIVE";
13177 }
13178 Log.i("Navit", "avail.mem size=" + value + "MB, type=" + type);
13179 return value;
13180 }
13181 catch (Exception e)
13182 {
13183 return 0L;
13184 }
13185 }
13186
13187 public void google_online_search_and_set_destination(String address_string)
13188 {
13189 // online googlemaps search
13190 // String addressInput = filter_bad_chars(address_string);
13191 String addressInput = address_string;
13192 try
13193 {
13194 List<Address> foundAdresses = Navit.Navit_Geocoder.getFromLocationName(addressInput, 1); //Search addresses
13195 //System.out.println("found " + foundAdresses.size() + " results");
13196 //System.out.println("addr=" + foundAdresses.get(0).getLatitude() + " " + foundAdresses.get(0).getLongitude() + "" + foundAdresses.get(0).getAddressLine(0));
13197
13198 int results_step = 0;
13199 Navit.Navit_Address_Result_Struct tmp_addr = new Navit_Address_Result_Struct();
13200 tmp_addr.result_type = "STR";
13201 tmp_addr.item_id = "0";
13202 tmp_addr.lat = (float) foundAdresses.get(results_step).getLatitude();
13203 tmp_addr.lon = (float) foundAdresses.get(results_step).getLongitude();
13204 tmp_addr.addr = "";
13205
13206 String c_code = foundAdresses.get(results_step).getCountryCode();
13207 if (c_code != null)
13208 {
13209 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getCountryCode() + ",";
13210 }
13211
13212 String p_code = foundAdresses.get(results_step).getPostalCode();
13213 if (p_code != null)
13214 {
13215 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getPostalCode() + " ";
13216 }
13217
13218 if (foundAdresses.get(results_step).getMaxAddressLineIndex() > -1)
13219 {
13220 for (int addr_line = 0; addr_line < foundAdresses.get(results_step).getMaxAddressLineIndex(); addr_line++)
13221 {
13222 if (addr_line > 0) tmp_addr.addr = tmp_addr.addr + " ";
13223 tmp_addr.addr = tmp_addr.addr + foundAdresses.get(results_step).getAddressLine(addr_line);
13224 }
13225 }
13226
13227 // // DEBUG: clear route rectangle list
13228 // NavitGraphics.route_rects.clear();
13229 //
13230 // System.out.println("found:" + tmp_addr.addr + " " + tmp_addr.lat + " " + tmp_addr.lon);
13231 //
13232 // try
13233 // {
13234 // Navit.remember_destination(tmp_addr.addr, tmp_addr.lat, tmp_addr.lon);
13235 // // save points
13236 // write_map_points();
13237 // }
13238 // catch (Exception e)
13239 // {
13240 // e.printStackTrace();
13241 // }
13242 //
13243 // if (NavitGraphics.navit_route_status == 0)
13244 // {
13245 // Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + tmp_addr.addr, Toast.LENGTH_SHORT).show(); //TRANS
13246 // Navit.destination_set();
13247 //
13248 // Message msg = new Message();
13249 // Bundle b = new Bundle();
13250 // b.putInt("Callback", 3);
13251 // b.putString("lat", String.valueOf(tmp_addr.lat));
13252 // b.putString("lon", String.valueOf(tmp_addr.lon));
13253 // b.putString("q", tmp_addr.addr);
13254 // msg.setData(b);
13255 // NavitGraphics.callback_handler.sendMessage(msg);
13256 // }
13257 // else
13258 // {
13259 // Toast.makeText(getApplicationContext(), Navit.get_text("new Waypoint") + "\n" + tmp_addr.addr, Toast.LENGTH_SHORT).show(); //TRANS
13260 // Message msg = new Message();
13261 // Bundle b = new Bundle();
13262 // b.putInt("Callback", 48);
13263 // b.putString("lat", String.valueOf(tmp_addr.lat));
13264 // b.putString("lon", String.valueOf(tmp_addr.lon));
13265 // b.putString("q", tmp_addr.addr);
13266 // msg.setData(b);
13267 // NavitGraphics.callback_handler.sendMessage(msg);
13268 // }
13269
13270 route_wrapper(tmp_addr.addr, 0, 0, false, tmp_addr.lat, tmp_addr.lon, true);
13271
13272 // ---------- DEBUG: write route to file ----------
13273 // ---------- DEBUG: write route to file ----------
13274 // ---------- DEBUG: write route to file ----------
13275 if (p.PREF_enable_debug_write_gpx)
13276 {
13277 write_route_to_gpx_file();
13278 }
13279 // ---------- DEBUG: write route to file ----------
13280 // ---------- DEBUG: write route to file ----------
13281
13282 try
13283 {
13284 Navit.follow_button_on();
13285 }
13286 catch (Exception e2)
13287 {
13288 e2.printStackTrace();
13289 }
13290
13291 show_geo_on_screen(tmp_addr.lat, tmp_addr.lon);
13292
13293 }
13294 catch (Exception e)
13295 {
13296 e.printStackTrace();
13297 Toast.makeText(getApplicationContext(), Navit.get_text("google search API is not working at this moment, try offline search"), Toast.LENGTH_SHORT).show();
13298 }
13299 }
13300
13301 public void result_set_destination(double lat, double lon, String addr)
13302 {
13303 try
13304 {
13305 int results_step = 0;
13306 Navit.Navit_Address_Result_Struct tmp_addr = new Navit_Address_Result_Struct();
13307 tmp_addr.result_type = "STR";
13308 tmp_addr.item_id = "0";
13309 tmp_addr.lat = (float) lat;
13310 tmp_addr.lon = (float) lon;
13311 tmp_addr.addr = addr;
13312
13313 // // DEBUG: clear route rectangle list
13314 // NavitGraphics.route_rects.clear();
13315 //
13316 // System.out.println("found:" + tmp_addr.addr + " " + tmp_addr.lat + " " + tmp_addr.lon);
13317 //
13318 // try
13319 // {
13320 // Navit.remember_destination(tmp_addr.addr, tmp_addr.lat, tmp_addr.lon);
13321 // // save points
13322 // write_map_points();
13323 // }
13324 // catch (Exception e)
13325 // {
13326 // e.printStackTrace();
13327 // }
13328 //
13329 // if (NavitGraphics.navit_route_status == 0)
13330 // {
13331 // Toast.makeText(getApplicationContext(), Navit.get_text("setting destination to") + "\n" + tmp_addr.addr, Toast.LENGTH_SHORT).show(); //TRANS
13332 // Navit.destination_set();
13333 //
13334 // Message msg = new Message();
13335 // Bundle b = new Bundle();
13336 // b.putInt("Callback", 3);
13337 // b.putString("lat", String.valueOf(tmp_addr.lat));
13338 // b.putString("lon", String.valueOf(tmp_addr.lon));
13339 // b.putString("q", tmp_addr.addr);
13340 // msg.setData(b);
13341 // NavitGraphics.callback_handler.sendMessage(msg);
13342 // }
13343 // else
13344 // {
13345 // Toast.makeText(getApplicationContext(), Navit.get_text("new Waypoint") + "\n" + tmp_addr.addr, Toast.LENGTH_SHORT).show(); //TRANS
13346 // Message msg = new Message();
13347 // Bundle b = new Bundle();
13348 // b.putInt("Callback", 48);
13349 // b.putString("lat", String.valueOf(tmp_addr.lat));
13350 // b.putString("lon", String.valueOf(tmp_addr.lon));
13351 // b.putString("q", tmp_addr.addr);
13352 // msg.setData(b);
13353 // NavitGraphics.callback_handler.sendMessage(msg);
13354 // }
13355
13356 route_wrapper(tmp_addr.addr, 0, 0, false, tmp_addr.lat, tmp_addr.lon, true);
13357
13358 try
13359 {
13360 Navit.follow_button_on();
13361 }
13362 catch (Exception e2)
13363 {
13364 e2.printStackTrace();
13365 }
13366
13367 // ---------- DEBUG: write route to file ----------
13368 // ---------- DEBUG: write route to file ----------
13369 // ---------- DEBUG: write route to file ----------
13370 if (p.PREF_enable_debug_write_gpx)
13371 {
13372 write_route_to_gpx_file();
13373 }
13374 // ---------- DEBUG: write route to file ----------
13375 // ---------- DEBUG: write route to file ----------
13376
13377 show_geo_on_screen(tmp_addr.lat, tmp_addr.lon);
13378
13379 }
13380 catch (Exception e)
13381 {
13382 e.printStackTrace();
13383 Toast.makeText(getApplicationContext(), Navit.get_text("google search API is not working at this moment, try offline search"), Toast.LENGTH_SHORT).show();
13384 }
13385 }
13386
13387 void open_voice_recog_screen()
13388 {
13389 Intent ii = new Intent(this, ZANaviVoiceInput.class);
13390 this.startActivityForResult(ii, Navit.ZANaviVoiceInput_id);
13391 }
13392
13393 static void dim_screen_wrapper()
13394 {
13395 try
13396 {
13397 Message msg = Navit.Navit_progress_h.obtainMessage();
13398 Bundle b = new Bundle();
13399 msg.what = 20;
13400 msg.setData(b);
13401 Navit.Navit_progress_h.sendMessage(msg);
13402 }
13403 catch (Exception e)
13404 {
13405 e.printStackTrace();
13406 }
13407 }
13408
13409 static void show_status_bar_wrapper()
13410 {
13411 try
13412 {
13413 Message msg = Navit.Navit_progress_h.obtainMessage();
13414 Bundle b = new Bundle();
13415 msg.what = 27;
13416 msg.setData(b);
13417 Navit.Navit_progress_h.sendMessage(msg);
13418 }
13419 catch (Exception e)
13420 {
13421 e.printStackTrace();
13422 }
13423 }
13424
13425 static void hide_status_bar_wrapper()
13426 {
13427 try
13428 {
13429 Message msg = Navit.Navit_progress_h.obtainMessage();
13430 Bundle b = new Bundle();
13431 msg.what = 28;
13432 msg.setData(b);
13433 Navit.Navit_progress_h.sendMessage(msg);
13434 }
13435 catch (Exception e)
13436 {
13437 e.printStackTrace();
13438 }
13439 }
13440
13441 static void default_brightness_screen_wrapper()
13442 {
13443 try
13444 {
13445 Message msg = Navit.Navit_progress_h.obtainMessage();
13446 Bundle b = new Bundle();
13447 msg.what = 21;
13448 msg.setData(b);
13449 Navit.Navit_progress_h.sendMessage(msg);
13450 }
13451 catch (Exception e)
13452 {
13453 e.printStackTrace();
13454 }
13455 }
13456
13457 static void dim_screen()
13458 {
13459 try
13460 {
13461 WindowManager.LayoutParams params_wm = app_window.getAttributes();
13462 // params_wm.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
13463 params_wm.screenBrightness = 0.1f;
13464 app_window.setAttributes(params_wm);
13465 //app_window.addFlags(WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
13466 }
13467 catch (Exception e)
13468 {
13469 e.printStackTrace();
13470 }
13471 }
13472
13473 static void default_brightness_screen()
13474 {
13475 try
13476 {
13477 WindowManager.LayoutParams params_wm = app_window.getAttributes();
13478 // params_wm.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
13479 params_wm.screenBrightness = -1f;
13480 app_window.setAttributes(params_wm);
13481 //app_window.clearFlags(WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
13482 }
13483 catch (Exception e)
13484 {
13485 e.printStackTrace();
13486 }
13487 }
13488
13489 void donate_bitcoins()
13490 {
13491 try
13492 {
13493 Intent donate_activity = new Intent(this, ZANaviDonateActivity.class);
13494 // donate_activity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
13495 startActivity(donate_activity);
13496 }
13497 catch (Exception e)
13498 {
13499 }
13500 }
13501
13502 void donate()
13503 {
13504 try
13505 {
13506 Intent donate_activity = new Intent(this, ZANaviNormalDonateActivity.class);
13507 // donate_activity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
13508 startActivity(donate_activity);
13509 }
13510 catch (Exception e)
13511 {
13512 }
13513 }
13514
13515 static int debug_indent = -1;
13516 static String debug_indent_spaces = " ";
13517
13518 // type: 0 -> enter, 1 -> leave, 2 .. n -> return(#n)
13519 static void my_func_name(int type)
13520 {
13521 int debug_indent2;
13522
13523 // -- switch off !! --
13524 // -- switch off !! --
13525 debug_indent = 0;
13526 // -- switch off !! --
13527 // -- switch off !! --
13528
13529 try
13530 {
13531 StackTraceElement[] a = Thread.currentThread().getStackTrace();
13532 if (type == 0)
13533 {
13534 //debug_indent++;
13535 debug_indent2 = debug_indent;
13536 //if (debug_indent2 > debug_indent_spaces.length())
13537 //{
13538 // debug_indent2 = debug_indent_spaces.length() - 1;
13539 //}
13540 System.out.println("FUNJ:" + debug_indent_spaces.substring(0, Math.abs(2 * debug_indent2)) + "zanav:" + a[3].getClassName() + "." + a[3].getMethodName() + ":enter");
13541 }
13542 else if (type == 1)
13543 {
13544 debug_indent2 = debug_indent;
13545 //if (debug_indent2 > debug_indent_spaces.length())
13546 //{
13547 // debug_indent2 = debug_indent_spaces.length() - 1;
13548 //}
13549 System.out.println("FUNJ:" + debug_indent_spaces.substring(0, Math.abs(2 * debug_indent2)) + "zanav:" + a[3].getClassName() + "." + a[3].getMethodName() + ":leave");
13550 //debug_indent--;
13551 }
13552 else
13553 {
13554 debug_indent2 = debug_indent;
13555 //if (debug_indent2 > debug_indent_spaces.length())
13556 //{
13557 // debug_indent2 = debug_indent_spaces.length() - 1;
13558 //}
13559 System.out.println("FUNJ:" + debug_indent_spaces.substring(0, Math.abs(2 * debug_indent2)) + "zanav:" + a[3].getClassName() + "." + a[3].getMethodName() + ":return(" + type + ")");
13560 //debug_indent--;
13561 }
13562 }
13563 catch (Exception e)
13564 {
13565 e.printStackTrace();
13566 }
13567 }
13568
13569 // type: 0 -> enter, 1 -> leave, 2 .. n -> return(#n)
13570 static void my_func_name(int type, String msg)
13571 {
13572 int debug_indent2;
13573
13574 // -- switch off !! --
13575 // -- switch off !! --
13576 debug_indent = 0;
13577 // -- switch off !! --
13578 // -- switch off !! --
13579
13580 try
13581 {
13582 StackTraceElement[] a = Thread.currentThread().getStackTrace();
13583 if (type == 0)
13584 {
13585 //debug_indent++;
13586 debug_indent2 = debug_indent;
13587 //if (debug_indent2 > debug_indent_spaces.length())
13588 //{
13589 // debug_indent2 = debug_indent_spaces.length() - 1;
13590 //}
13591 System.out.println("FUNJ:" + debug_indent_spaces.substring(0, Math.abs(2 * debug_indent2)) + "zanav:" + a[3].getClassName() + "." + a[3].getMethodName() + ":enter" + ":" + msg);
13592 }
13593 else if (type == 1)
13594 {
13595 debug_indent2 = debug_indent;
13596 //if (debug_indent2 > debug_indent_spaces.length())
13597 //{
13598 // debug_indent2 = debug_indent_spaces.length() - 1;
13599 //}
13600 System.out.println("FUNJ:" + debug_indent_spaces.substring(0, Math.abs(2 * debug_indent2)) + "zanav:" + a[3].getClassName() + "." + a[3].getMethodName() + ":leave" + ":" + msg);
13601 //debug_indent--;
13602 }
13603 else
13604 {
13605 debug_indent2 = debug_indent;
13606 //if (debug_indent2 > debug_indent_spaces.length())
13607 //{
13608 // debug_indent2 = debug_indent_spaces.length() - 1;
13609 //}
13610 System.out.println("FUNJ:" + debug_indent_spaces.substring(0, Math.abs(2 * debug_indent2)) + "zanav:" + a[3].getClassName() + "." + a[3].getMethodName() + ":return(" + type + ")" + ":" + msg);
13611 //debug_indent--;
13612 }
13613 }
13614 catch (Exception e)
13615 {
13616 e.printStackTrace();
13617 }
13618 }
13619
13620 public static void write_route_to_gpx_file()
13621 {
13622 final Thread write_route_to_gpx_file_001 = new Thread()
13623 {
13624 int wait = 1;
13625 int count = 0;
13626 int max_count = 60;
13627
13628 @Override
13629 public void run()
13630 {
13631 while (wait == 1)
13632 {
13633 try
13634 {
13635 if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33))
13636 {
13637 Message msg = new Message();
13638 Bundle b = new Bundle();
13639 b.putInt("Callback", 96);
13640 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
13641 String filename = Navit.NAVIT_DATA_DEBUG_DIR + "zanavi_route_" + date + ".gpx";
13642 b.putString("s", filename);
13643 System.out.println("Debug:" + "file=" + filename);
13644 msg.setData(b);
13645 NavitGraphics.callback_handler.sendMessage(msg);
13646
13647 Message msg7 = Navit_progress_h.obtainMessage();
13648 Bundle b7 = new Bundle();
13649 msg7.what = 2; // long Toast message
13650 b7.putString("text", Navit.get_text("saving route to GPX-file") + " " + filename); //TRANS
13651 msg7.setData(b7);
13652 Navit_progress_h.sendMessage(msg7);
13653
13654 wait = 0;
13655 }
13656 else
13657 {
13658 wait = 1;
13659 }
13660
13661 count++;
13662 if (count > max_count)
13663 {
13664 wait = 0;
13665
13666 Message msg7 = Navit_progress_h.obtainMessage();
13667 Bundle b7 = new Bundle();
13668 msg7.what = 2; // long Toast message
13669 b7.putString("text", Navit.get_text("saving route to GPX-file failed")); //TRANS
13670 msg7.setData(b7);
13671 Navit_progress_h.sendMessage(msg7);
13672 }
13673 else
13674 {
13675 Thread.sleep(400);
13676 }
13677 }
13678 catch (Exception e)
13679 {
13680 }
13681 }
13682 }
13683 };
13684 write_route_to_gpx_file_001.start();
13685 }
13686
13687 void convert_gpx_file_real(String gpx_file)
13688 {
13689 File tt2 = new File(gpx_file);
13690 p.PREF_last_selected_dir_gpxfiles = tt2.getParent();
13691 Log.e("Navit", "last_selected_dir_gpxfiles " + p.PREF_last_selected_dir_gpxfiles);
13692 setPrefs_selected_gpx_dir();
13693
13694 String out_ = MAP_FILENAME_PATH + "/gpxtracks.txt";
13695 Log.e("Navit", "onActivityResult 002 " + gpx_file + " " + out_);
13696 MainFrame.do_conversion(gpx_file, out_);
13697
13698 // draw map no-async
13699 Message msg = new Message();
13700 Bundle b = new Bundle();
13701 b.putInt("Callback", 64);
13702 msg.setData(b);
13703 NavitGraphics.callback_handler.sendMessage(msg);
13704 }
13705
13706 String intent_flags_to_string(int flags)
13707 {
13708 String ret = "(" + String.format("%#x", flags) + ") ";
13709
13710 // Intent flags
13711 final int FLAG_GRANT_READ_URI_PERMISSION = 0x00000001;
13712 final int FLAG_GRANT_WRITE_URI_PERMISSION = 0x00000002;
13713 final int FLAG_FROM_BACKGROUND = 0x00000004;
13714 final int FLAG_DEBUG_LOG_RESOLUTION = 0x00000008;
13715 final int FLAG_EXCLUDE_STOPPED_PACKAGES = 0x00000010;
13716 final int FLAG_INCLUDE_STOPPED_PACKAGES = 0x00000020;
13717 final int FLAG_ACTIVITY_NO_HISTORY = 0x40000000;
13718 final int FLAG_ACTIVITY_SINGLE_TOP = 0x20000000;
13719 final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
13720 final int FLAG_ACTIVITY_MULTIPLE_TASK = 0x08000000;
13721 final int FLAG_ACTIVITY_CLEAR_TOP = 0x04000000;
13722 final int FLAG_ACTIVITY_FORWARD_RESULT = 0x02000000;
13723 final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 0x01000000;
13724 final int FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS = 0x00800000;
13725 final int FLAG_ACTIVITY_BROUGHT_TO_FRONT = 0x00400000;
13726 final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
13727 final int FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY = 0x00100000;
13728 final int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET = 0x00080000;
13729 final int FLAG_ACTIVITY_NO_USER_ACTION = 0x00040000;
13730 final int FLAG_ACTIVITY_REORDER_TO_FRONT = 0X00020000;
13731 final int FLAG_ACTIVITY_NO_ANIMATION = 0X00010000;
13732 final int FLAG_ACTIVITY_CLEAR_TASK = 0X00008000;
13733 final int FLAG_ACTIVITY_TASK_ON_HOME = 0X00004000;
13734 /*
13735 * final int FLAG_RECEIVER_REGISTERED_ONLY = 0x40000000;
13736 * final int FLAG_RECEIVER_REPLACE_PENDING = 0x20000000;
13737 * final int FLAG_RECEIVER_FOREGROUND = 0x10000000;
13738 * final int FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT = 0x08000000;
13739 * final int FLAG_RECEIVER_BOOT_UPGRADE = 0x04000000;
13740 */
13741
13742 int first = 1;
13743 String sep = "";
13744
13745 if ((flags & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
13746 {
13747 if (first == 1)
13748 {
13749 first = 0;
13750 sep = "";
13751 }
13752 else
13753 {
13754 sep = ",";
13755 }
13756 ret = ret + sep + "FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS";
13757 }
13758 if ((flags & FLAG_ACTIVITY_BROUGHT_TO_FRONT) == FLAG_ACTIVITY_BROUGHT_TO_FRONT)
13759 {
13760 if (first == 1)
13761 {
13762 first = 0;
13763 sep = "";
13764 }
13765 else
13766 {
13767 sep = ",";
13768 }
13769 ret = ret + sep + "FLAG_ACTIVITY_BROUGHT_TO_FRONT";
13770 }
13771 if ((flags & FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) == FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
13772 {
13773 if (first == 1)
13774 {
13775 first = 0;
13776 sep = "";
13777 }
13778 else
13779 {
13780 sep = ",";
13781 }
13782 ret = ret + sep + "FLAG_ACTIVITY_RESET_TASK_IF_NEEDED";
13783 }
13784 if ((flags & FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)
13785 {
13786 if (first == 1)
13787 {
13788 first = 0;
13789 sep = "";
13790 }
13791 else
13792 {
13793 sep = ",";
13794 }
13795 ret = ret + sep + "FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY";
13796 }
13797 if ((flags & FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) == FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
13798 {
13799 if (first == 1)
13800 {
13801 first = 0;
13802 sep = "";
13803 }
13804 else
13805 {
13806 sep = ",";
13807 }
13808 ret = ret + sep + "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET";
13809 }
13810 if ((flags & FLAG_ACTIVITY_NO_USER_ACTION) == FLAG_ACTIVITY_NO_USER_ACTION)
13811 {
13812 if (first == 1)
13813 {
13814 first = 0;
13815 sep = "";
13816 }
13817 else
13818 {
13819 sep = ",";
13820 }
13821 ret = ret + sep + "FLAG_ACTIVITY_NO_USER_ACTION";
13822 }
13823 if ((flags & FLAG_ACTIVITY_REORDER_TO_FRONT) == FLAG_ACTIVITY_REORDER_TO_FRONT)
13824 {
13825 if (first == 1)
13826 {
13827 first = 0;
13828 sep = "";
13829 }
13830 else
13831 {
13832 sep = ",";
13833 }
13834 ret = ret + sep + "FLAG_ACTIVITY_REORDER_TO_FRONT";
13835 }
13836 if ((flags & FLAG_ACTIVITY_NO_ANIMATION) == FLAG_ACTIVITY_NO_ANIMATION)
13837 {
13838 if (first == 1)
13839 {
13840 first = 0;
13841 sep = "";
13842 }
13843 else
13844 {
13845 sep = ",";
13846 }
13847 ret = ret + sep + "FLAG_ACTIVITY_NO_ANIMATION";
13848 }
13849 if ((flags & FLAG_ACTIVITY_CLEAR_TASK) == FLAG_ACTIVITY_CLEAR_TASK)
13850 {
13851 if (first == 1)
13852 {
13853 first = 0;
13854 sep = "";
13855 }
13856 else
13857 {
13858 sep = ",";
13859 }
13860 ret = ret + sep + "FLAG_ACTIVITY_CLEAR_TASK";
13861 }
13862 if ((flags & FLAG_ACTIVITY_TASK_ON_HOME) == FLAG_ACTIVITY_TASK_ON_HOME)
13863 {
13864 if (first == 1)
13865 {
13866 first = 0;
13867 sep = "";
13868 }
13869 else
13870 {
13871 sep = ",";
13872 }
13873 ret = ret + sep + "FLAG_ACTIVITY_TASK_ON_HOME";
13874 }
13875
13876 if ((flags & FLAG_GRANT_READ_URI_PERMISSION) == FLAG_GRANT_READ_URI_PERMISSION)
13877 {
13878 if (first == 1)
13879 {
13880 first = 0;
13881 sep = "";
13882 }
13883 else
13884 {
13885 sep = ",";
13886 }
13887 ret = ret + sep + "FLAG_GRANT_READ_URI_PERMISSION";
13888 }
13889
13890 if ((flags & FLAG_GRANT_WRITE_URI_PERMISSION) == FLAG_GRANT_WRITE_URI_PERMISSION)
13891 {
13892 if (first == 1)
13893 {
13894 first = 0;
13895 sep = "";
13896 }
13897 else
13898 {
13899 sep = ",";
13900 }
13901 ret = ret + sep + "FLAG_GRANT_WRITE_URI_PERMISSION";
13902 }
13903
13904 if ((flags & FLAG_FROM_BACKGROUND) == FLAG_FROM_BACKGROUND)
13905 {
13906 if (first == 1)
13907 {
13908 first = 0;
13909 sep = "";
13910 }
13911 else
13912 {
13913 sep = ",";
13914 }
13915 ret = ret + sep + "FLAG_FROM_BACKGROUND";
13916 }
13917 if ((flags & FLAG_DEBUG_LOG_RESOLUTION) == FLAG_DEBUG_LOG_RESOLUTION)
13918 {
13919 if (first == 1)
13920 {
13921 first = 0;
13922 sep = "";
13923 }
13924 else
13925 {
13926 sep = ",";
13927 }
13928 ret = ret + sep + "FLAG_DEBUG_LOG_RESOLUTION";
13929 }
13930 if ((flags & FLAG_EXCLUDE_STOPPED_PACKAGES) == FLAG_EXCLUDE_STOPPED_PACKAGES)
13931 {
13932 if (first == 1)
13933 {
13934 first = 0;
13935 sep = "";
13936 }
13937 else
13938 {
13939 sep = ",";
13940 }
13941 ret = ret + sep + "FLAG_EXCLUDE_STOPPED_PACKAGES";
13942 }
13943 if ((flags & FLAG_INCLUDE_STOPPED_PACKAGES) == FLAG_INCLUDE_STOPPED_PACKAGES)
13944 {
13945 if (first == 1)
13946 {
13947 first = 0;
13948 sep = "";
13949 }
13950 else
13951 {
13952 sep = ",";
13953 }
13954 ret = ret + sep + "FLAG_INCLUDE_STOPPED_PACKAGES";
13955 }
13956 if ((flags & FLAG_ACTIVITY_NO_HISTORY) == FLAG_ACTIVITY_NO_HISTORY)
13957 {
13958 if (first == 1)
13959 {
13960 first = 0;
13961 sep = "";
13962 }
13963 else
13964 {
13965 sep = ",";
13966 }
13967 ret = ret + sep + "FLAG_ACTIVITY_NO_HISTORY";
13968 }
13969 if ((flags & FLAG_ACTIVITY_SINGLE_TOP) == FLAG_ACTIVITY_SINGLE_TOP)
13970 {
13971 if (first == 1)
13972 {
13973 first = 0;
13974 sep = "";
13975 }
13976 else
13977 {
13978 sep = ",";
13979 }
13980 ret = ret + sep + "FLAG_ACTIVITY_SINGLE_TOP";
13981 }
13982 if ((flags & FLAG_ACTIVITY_NEW_TASK) == FLAG_ACTIVITY_NEW_TASK)
13983 {
13984 if (first == 1)
13985 {
13986 first = 0;
13987 sep = "";
13988 }
13989 else
13990 {
13991 sep = ",";
13992 }
13993 ret = ret + sep + "FLAG_ACTIVITY_NEW_TASK";
13994 }
13995 if ((flags & FLAG_ACTIVITY_MULTIPLE_TASK) == FLAG_ACTIVITY_MULTIPLE_TASK)
13996 {
13997 if (first == 1)
13998 {
13999 first = 0;
14000 sep = "";
14001 }
14002 else
14003 {
14004 sep = ",";
14005 }
14006 ret = ret + sep + "FLAG_ACTIVITY_MULTIPLE_TASK";
14007 }
14008 if ((flags & FLAG_ACTIVITY_CLEAR_TOP) == FLAG_ACTIVITY_CLEAR_TOP)
14009 {
14010 if (first == 1)
14011 {
14012 first = 0;
14013 sep = "";
14014 }
14015 else
14016 {
14017 sep = ",";
14018 }
14019 ret = ret + sep + "FLAG_ACTIVITY_CLEAR_TOP";
14020 }
14021 if ((flags & FLAG_ACTIVITY_FORWARD_RESULT) == FLAG_ACTIVITY_FORWARD_RESULT)
14022 {
14023 if (first == 1)
14024 {
14025 first = 0;
14026 sep = "";
14027 }
14028 else
14029 {
14030 sep = ",";
14031 }
14032 ret = ret + sep + "FLAG_ACTIVITY_FORWARD_RESULT";
14033 }
14034 if ((flags & FLAG_ACTIVITY_PREVIOUS_IS_TOP) == FLAG_ACTIVITY_PREVIOUS_IS_TOP)
14035 {
14036 if (first == 1)
14037 {
14038 first = 0;
14039 sep = "";
14040 }
14041 else
14042 {
14043 sep = ",";
14044 }
14045 ret = ret + sep + "FLAG_ACTIVITY_PREVIOUS_IS_TOP";
14046 }
14047
14048 return ret;
14049 }
14050
14051 static boolean want_tunnel_extrapolation()
14052 {
14053 if ((!isGPSFix) && (pos_is_underground == 1) && (NavitGraphics.CallbackDestinationValid2() > 0))
14054 {
14055 // gps fix is lost
14056 // and
14057 // our position is underground
14058 // and
14059 // we have a destination set
14060 //
14061 // --> we want tunnel extrapolation
14062 return true;
14063 }
14064
14065 return false;
14066 }
14067
14068 public static void applySharedTheme(Activity act, int Theme_id)
14069 {
14070 act.setTheme(Theme_id);
14071 }
14072
14073 private com.zoffcc.applications.zanavi_msg.ZListener.Stub zclientListener = new com.zoffcc.applications.zanavi_msg.ZListener.Stub()
14074 {
14075 @Override
14076 public String handleUpdated(String data) throws RemoteException
14077 {
14078 // Log.i("NavitPlugin", "update from Plugin=" + data);
14079 return "Navit says:\"PONG\"";
14080 }
14081 };
14082
14083 static Object sync_plugin_send = new Object();
14084
14085 public static void send_data_to_plugin_bg(final int msg_cat, final String data)
14086 {
14087 // send data to plugin (plugin will send to server) in another task! --------------------------
14088 new AsyncTask<Void, Void, String>()
14089 {
14090 @Override
14091 protected String doInBackground(Void... params)
14092 {
14093 synchronized (sync_plugin_send)
14094 {
14095 try
14096 {
14097 if (plugin_api == null)
14098 {
14099 try
14100 {
14101 Thread.sleep(3000); // wait until the service is bound
14102 }
14103 catch (Exception e)
14104 {
14105 }
14106 }
14107
14108 String response = plugin_api.getResult(PLUGIN_MSG_ID, msg_cat, data);
14109
14110 }
14111 catch (RemoteException e)
14112 {
14113 // Log.e("NavitPlugin", "Failed(1) to send msg to plugin:cat=" + PLUGIN_MSG_CAT_zanavi_version + " data=" + data, e);
14114 }
14115 catch (Exception e)
14116 {
14117 // Log.e("NavitPlugin", "Failed(2) to send msg to plugin:cat=" + PLUGIN_MSG_CAT_zanavi_version + " data=" + data, e);
14118 }
14119 }
14120 return "";
14121 }
14122
14123 @Override
14124 protected void onPostExecute(String msg)
14125 {
14126
14127 }
14128 }.execute(null, null, null);
14129 // send data to plugin (plugin will send to server) in another task! --------------------------
14130 }
14131
14132 private ServiceConnection serviceConnection = new ServiceConnection()
14133 {
14134 @Override
14135 public void onServiceConnected(ComponentName name, IBinder service)
14136 {
14137 Log.i("NavitPlugin", "Service connection established");
14138
14139 // that's how we get the client side of the IPC connection
14140 plugin_api = ZanaviCloudApi.Stub.asInterface((IBinder) service);
14141 try
14142 {
14143 plugin_api.addListener(zclientListener);
14144 }
14145 catch (RemoteException e)
14146 {
14147 Log.e("NavitPlugin", "Failed(1) to add listener", e);
14148 }
14149 catch (Exception e)
14150 {
14151 Log.e("NavitPlugin", "Failed(2) to add listener", e);
14152 }
14153
14154 send_installed_maps_to_plugin();
14155 send_data_to_plugin_bg(PLUGIN_MSG_CAT_zanavi_version, Navit.NavitAppVersion);
14156 }
14157
14158 @Override
14159 public void onServiceDisconnected(ComponentName name)
14160 {
14161 plugin_api = null;
14162 Log.i("NavitPlugin", "Service connection closed");
14163 }
14164 };
14165
14166 /**
14167 * send installed maps and download date/time (time up to minute) in UTC to plugin
14168 */
14169 static void send_installed_maps_to_plugin()
14170 {
14171 try
14172 {
14173 /*
14174 * { "201502032311":"austria.bin","201502032312":"germany.bin" }
14175 */
14176
14177 String data = "";
14178
14179 // dirty hardcode JSON data struct
14180 final String maps_and_timestamp_data_start = "{ \"";
14181 final String maps_and_timestamp_data_sep1 = "\":\"";
14182 final String maps_and_timestamp_data_sep2 = "\",\"";
14183 final String maps_and_timestamp_data_end = "\" }";
14184
14185 NavitMapDownloader.init_cat_file_maps_timestamps();
14186
14187 data = data + maps_and_timestamp_data_start;
14188
14189 String map_name = "";
14190 Iterator<String> k = NavitMapDownloader.map_catalogue_date.listIterator();
14191 while (k.hasNext())
14192 {
14193 map_name = k.next();
14194 data = data + map_name.split(":", 2)[1];
14195 data = data + maps_and_timestamp_data_sep1;
14196 data = data + map_name.split(":", 2)[0];
14197 if (k.hasNext())
14198 {
14199 data = data + maps_and_timestamp_data_sep2;
14200 }
14201 }
14202 data = data + maps_and_timestamp_data_end;
14203
14204 // System.out.println("PLUGIN:MAPS:" + data);
14205
14206 send_data_to_plugin_bg(PLUGIN_MSG_CAT_installed_maps, data);
14207 }
14208 catch (Exception e)
14209 {
14210 }
14211 }
14212
14213 static boolean have_maps_installed()
14214 {
14215 int count_maps_installed = NavitMapDownloader.cat_file_maps_have_installed_any();
14216 if (count_maps_installed == 0)
14217 {
14218 return false;
14219 }
14220 else
14221 {
14222 return true;
14223 }
14224 }
14225
14226 /**
14227 * auto start map download/update
14228 *
14229 * @param map_name
14230 * mapfilename with ending ".bin"
14231 */
14232 void auto_start_update_map(String map_name)
14233 {
14234
14235 int count = NavitMapDownloader.z_OSM_MAPS.length;
14236 Navit.download_map_id = -1;
14237 for (int i = 0; i < count; i++)
14238 {
14239 if (!NavitMapDownloader.z_OSM_MAPS[i].is_continent)
14240 {
14241 // System.out.println("mmm1=" + NavitMapDownloader.z_OSM_MAPS[i].url);
14242 if (NavitMapDownloader.z_OSM_MAPS[i].url.equals(map_name))
14243 {
14244 Navit.download_map_id = i;
14245 System.out.println("mMM2=" + NavitMapDownloader.z_OSM_MAPS[i].map_name);
14246 }
14247 }
14248 }
14249
14250 // show the map download progressbar, and download the map
14251 if (Navit.download_map_id > -1)
14252 {
14253 // new method in service
14254 Message msg = progress_handler.obtainMessage();
14255 Bundle b = new Bundle();
14256 msg.what = 22;
14257 progress_handler.sendMessage(msg);
14258 }
14259 }
14260
14261 void show_case_001()
14262 {
14263 // try
14264 // {
14265 // new ShowcaseView.Builder(this).setTarget(new ViewTarget(R.id.no_maps_button, this)).setContentTitle("").setContentText("").singleShot(Navit.SHOWCASEVIEW_ID_001).build();
14266 // }
14267 // catch (Exception e1)
14268 // {
14269 // }
14270 // catch (NoSuchMethodError e2)
14271 // {
14272 // }
14273 // catch (NoClassDefFoundError e3)
14274 // {
14275 // }
14276 }
14277
14278 static void set_zoom_level(int want_zoom_level)
14279 {
14280 try
14281 {
14282 Bundle b = new Bundle();
14283 Message msg = new Message();
14284 b.putInt("Callback", 33);
14285 b.putString("s", Integer.toString(want_zoom_level));
14286 msg.setData(b);
14287 NavitGraphics.callback_handler.sendMessage(msg);
14288 }
14289 catch (Exception e)
14290 {
14291 e.printStackTrace();
14292 }
14293 }
14294
14295 static void set_zoom_level_no_draw(int want_zoom_level)
14296 {
14297 try
14298 {
14299 Bundle b = new Bundle();
14300 Message msg = new Message();
14301 b.putInt("Callback", 105);
14302 b.putString("s", Integer.toString(want_zoom_level));
14303 msg.setData(b);
14304 NavitGraphics.callback_handler.sendMessage(msg);
14305 }
14306 catch (Exception e)
14307 {
14308 e.printStackTrace();
14309 }
14310 }
14311
14312 static void draw_map()
14313 {
14314 try
14315 {
14316 // draw map no-async
14317 Message msg = new Message();
14318 Bundle b = new Bundle();
14319 b.putInt("Callback", 64);
14320 msg.setData(b);
14321 NavitGraphics.callback_handler.sendMessage(msg);
14322 }
14323 catch (Exception e)
14324 {
14325 e.printStackTrace();
14326 }
14327 }
14328
14329 final static int bottom_bar_snap_duration = 190;
14330
14331 void animate_bottom_bar_up()
14332 {
14333 final FrameLayout a = (FrameLayout) findViewById(R.id.bottom_bar_slide);
14334 TranslateAnimation animation = new TranslateAnimation(0, 0, 0, -cur_y_margin_bottom_bar_touch);
14335 animation.setDuration(bottom_bar_snap_duration); // animation duration
14336 animation.setFillAfter(true);
14337 animation.setFillEnabled(true);
14338 animation.setRepeatCount(0); // animation repeat count
14339 animation.setAnimationListener(new AnimationListener()
14340 {
14341 @Override
14342 public void onAnimationStart(Animation animation)
14343 {
14344 }
14345
14346 @Override
14347 public void onAnimationRepeat(Animation animation)
14348 {
14349 }
14350
14351 @Override
14352 public void onAnimationEnd(Animation animation)
14353 {
14354 cur_y_margin_bottom_bar_touch = 0;
14355 RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) a.getLayoutParams();
14356 relativeParams.setMargins(0, (int) cur_y_margin_bottom_bar_touch, 0, 0); // left, top, right, bottom
14357 a.setLayoutParams(relativeParams);
14358 a.requestLayout();
14359
14360 TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0);
14361 anim.setFillAfter(true);
14362 anim.setFillEnabled(true);
14363 anim.setDuration(1);
14364 a.startAnimation(anim);
14365 }
14366 });
14367 a.startAnimation(animation);
14368 }
14369
14370 static void animate_bottom_bar_down()
14371 {
14372 final FrameLayout a = (FrameLayout) Global_Navit_Object.findViewById(R.id.bottom_bar_slide);
14373
14374 // System.out.println("FRAG:animate_bottom_bar_down:014");
14375
14376 // set bottom end positon correctly??
14377 bottom_y_margin_bottom_bar_touch = Navit.map_view_height + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px;
14378
14379 final int move_by = (int) (bottom_y_margin_bottom_bar_touch - cur_y_margin_bottom_bar_touch);
14380 TranslateAnimation animation = new TranslateAnimation(0, 0, 0, move_by); // new TranslateAnimation(xFrom,xTo, yFrom,yTo)
14381 animation.setDuration(bottom_bar_snap_duration); // animation duration
14382 animation.setFillAfter(true);
14383 animation.setFillEnabled(true);
14384 animation.setRepeatCount(0); // animation repeat count
14385 animation.setAnimationListener(new AnimationListener()
14386 {
14387
14388 @Override
14389 public void onAnimationStart(Animation animation)
14390 {
14391 }
14392
14393 @Override
14394 public void onAnimationRepeat(Animation animation)
14395 {
14396 }
14397
14398 @Override
14399 public void onAnimationEnd(Animation animation)
14400 {
14401 // set bottom end positon correctly??
14402 bottom_y_margin_bottom_bar_touch = Navit.map_view_height + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px;
14403
14404 cur_y_margin_bottom_bar_touch = bottom_y_margin_bottom_bar_touch;
14405 RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) a.getLayoutParams();
14406 relativeParams.setMargins(0, (int) bottom_y_margin_bottom_bar_touch, 0, 0); // left, top, right, bottom
14407 a.setLayoutParams(relativeParams);
14408 a.requestLayout();
14409
14410 TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0);
14411 anim.setFillAfter(true);
14412 anim.setFillEnabled(true);
14413 anim.setDuration(1);
14414 a.startAnimation(anim);
14415
14416 // remove roadbook fragment -----------
14417 try
14418 {
14419 if (road_book != null)
14420 {
14421 FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
14422 // System.out.println("FRAG:dettach:002");
14423 fragmentTransaction.detach(road_book);
14424 fragmentTransaction.remove(road_book).commit();
14425 road_book = null;
14426 }
14427 }
14428 catch (Exception ef)
14429 {
14430 }
14431 // remove roadbook fragment -----------
14432
14433 }
14434 });
14435 a.startAnimation(animation);
14436 }
14437
14438 synchronized static int find_max_font_size_for_height(String sample_text, int height, int max_font_size, int padding_in_dp)
14439 {
14440 String s = sample_text;
14441 int bh = 0;
14442 Paint p = new Paint();
14443 Rect bounds = new Rect();
14444 p.setTextSize(max_font_size);
14445 // p.measureText(s);
14446 p.getTextBounds(s, 0, s.length(), bounds);
14447
14448 int ret_font_size = max_font_size;
14449
14450 int loop_counter_max = 400;
14451 int loop_counter = 0;
14452 int padding_in_px = 0;
14453 if (padding_in_dp > 0)
14454 {
14455 padding_in_px = NavitGraphics.dp_to_px(padding_in_dp);
14456 }
14457
14458 bh = bounds.height();
14459 //System.out.println("bh(1)=" + bh);
14460 while ((bh + padding_in_px) > height)
14461 {
14462 loop_counter++;
14463 if (loop_counter > loop_counter_max)
14464 {
14465 break;
14466 }
14467
14468 ret_font_size--;
14469 p.setTextSize(ret_font_size);
14470 // p.measureText(s);
14471 p.getTextBounds(s, 0, s.length(), bounds);
14472 bh = bounds.height();
14473 }
14474
14475 return ret_font_size;
14476 }
14477
14478 synchronized static int find_max_letters_for_width_and_fontsize(String max_length_text, int width, int max_font_size, int padding_in_dp)
14479 {
14480 int ret_max_letters = 10;
14481
14482 int padding_in_px = 0;
14483 if (padding_in_dp > 0)
14484 {
14485 //System.out.println("aaa2:l:1:x:" + padding_in_dp);
14486 padding_in_px = NavitGraphics.dp_to_px(padding_in_dp);
14487 //System.out.println("aaa2:l:1:x:2=" + padding_in_dp + " " + padding_in_px + " " + NavitGraphics.dp_to_px(padding_in_dp) + " " + NavitGraphics.Global_dpi_factor_better);
14488 }
14489 //System.out.println("aaa2:l:1:x:1=" + padding_in_px);
14490
14491 int c = 0;
14492 Paint p = new Paint();
14493 p.setTextSize(max_font_size);
14494
14495 String s = max_length_text;
14496
14497 if ((s == null) || (s.equals("")))
14498 {
14499 s = "Mlox3miwoMlox3miwoMlox3miwoMlox3miwoMlox3miwoMlox3miwoMlox3miwoMlox3miwoMlox3miwoMlox3miwo";
14500 }
14501
14502 int l = s.length();
14503 ret_max_letters = l;
14504 float mt = p.measureText(s);
14505 //System.out.println("aaa2:l:1:" + l + " " + s);
14506 //System.out.println("aaa2:l:22:." + mt + " padding_in_px=" + padding_in_px + " " + width);
14507
14508 while (mt + padding_in_px > width)
14509 {
14510 //System.out.println("aaa2:l:22:+" + mt + " " + padding_in_px + " " + width);
14511
14512 c++;
14513 if (c == l)
14514 {
14515 // no more letters
14516 //System.out.println("aaa2:l:1:no more letters:" + l + " " + s);
14517 break;
14518 }
14519 s = s.substring(0, s.length() - 1);
14520 mt = p.measureText(s);
14521 ret_max_letters--;
14522 }
14523
14524 //System.out.println("aaa2:l:1:res=" + ret_max_letters);
14525 return ret_max_letters;
14526 }
14527
14528 synchronized static int find_max_font_size_for_width(String sample_text, int width, int max_font_size, int padding_in_dp)
14529 {
14530 final String s = sample_text;
14531 int bh = 0;
14532 Paint p = new Paint();
14533 Rect bounds = new Rect();
14534 p.setTextSize(max_font_size);
14535 p.getTextBounds(s, 0, s.length(), bounds);
14536
14537 int ret_font_size = max_font_size;
14538
14539 int loop_counter_max = 400;
14540 int loop_counter = 0;
14541 int padding_in_px = 0;
14542 if (padding_in_dp > 0)
14543 {
14544 padding_in_px = NavitGraphics.dp_to_px(padding_in_dp);
14545 }
14546
14547 bh = bounds.width();
14548 while ((bh + padding_in_px) > width)
14549 {
14550 loop_counter++;
14551 if (loop_counter > loop_counter_max)
14552 {
14553 break;
14554 }
14555
14556 ret_font_size--;
14557 p.setTextSize(ret_font_size);
14558 p.getTextBounds(s, 0, s.length(), bounds);
14559 bh = bounds.width();
14560 // mt = p.measureText(s);
14561 }
14562
14563 return ret_font_size;
14564 }
14565
14566 static int last_orientation = Configuration.ORIENTATION_LANDSCAPE;
14567
14568 @Override
14569 public void onConfigurationChanged(Configuration newConfig)
14570 {
14571 super.onConfigurationChanged(newConfig);
14572
14573 if (last_orientation != newConfig.orientation)
14574 {
14575 // Checks the orientation of the screen
14576 if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
14577 {
14578 // setContentView(R.layout.main_layout);
14579
14580 // -- bottom bar --
14581 int h = NavitGraphics.mCanvasHeight;
14582 try
14583 {
14584 int h001;
14585 android.view.ViewGroup.LayoutParams lp001;
14586
14587 View v003 = (View) findViewById(R.id.osd_nextturn_new);
14588 h001 = getResources().getDimensionPixelSize(R.dimen.osd_nextturn_new_height);
14589 lp001 = v003.getLayoutParams();
14590 lp001.height = h001;
14591 v003.requestLayout();
14592
14593 v003 = (View) findViewById(R.id.bottom_bar);
14594 h001 = getResources().getDimensionPixelSize(R.dimen.bottom_bar_height);
14595 lp001 = v003.getLayoutParams();
14596 lp001.height = h001;
14597 v003.requestLayout();
14598
14599 LinearLayout v002 = (LinearLayout) findViewById(R.id.bottom_slide_view);
14600 h001 = getResources().getDimensionPixelSize(R.dimen.bottom_slide_view_height);
14601 lp001 = v002.getLayoutParams();
14602 lp001.height = h001;
14603 v002.requestLayout();
14604
14605 v003 = (View) findViewById(R.id.osd_timetodest_new);
14606 h001 = getResources().getDimensionPixelSize(R.dimen.osd_timetodest_new_height);
14607 lp001 = v003.getLayoutParams();
14608 lp001.height = h001;
14609 v003.requestLayout();
14610
14611 v002 = (LinearLayout) findViewById(R.id.bottom_line_container);
14612 h001 = getResources().getDimensionPixelSize(R.dimen.bottom_line_container_height);
14613 lp001 = v002.getLayoutParams();
14614 lp001.height = h001;
14615 v002.requestLayout();
14616
14617 RelativeLayout v001 = (RelativeLayout) findViewById(R.id.gui_top_container);
14618 h001 = getResources().getDimensionPixelSize(R.dimen.gui_top_container_height);
14619 lp001 = v001.getLayoutParams();
14620 lp001.height = h001;
14621 v001.requestLayout();
14622
14623 int ml = getResources().getDimensionPixelSize(R.dimen.margin_left_speeding);
14624 int mb = getResources().getDimensionPixelSize(R.dimen.margin_bottom_speeding);
14625 v003 = (View) findViewById(R.id.view_speeding);
14626 RelativeLayout.LayoutParams relativeParams_001 = (RelativeLayout.LayoutParams) v003.getLayoutParams();
14627 relativeParams_001.setMargins(ml, 0, 0, mb); // left, top, right, bottom
14628 v003.setLayoutParams(relativeParams_001);
14629 v003.requestLayout();
14630
14631 // Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
14632
14633 bottom_bar_px = (int) getResources().getDimension(R.dimen.gui_top_container_height);
14634 bottom_bar_slider_shadow_px = (int) getResources().getDimension(R.dimen.bottom_slide_view_shadow_compat_height);
14635
14636 Navit.cur_y_margin_bottom_bar_touch = h + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px; // try to put view at bottom
14637 }
14638 catch (Exception e)
14639 {
14640 Navit.cur_y_margin_bottom_bar_touch = h + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px; // try to put view at bottom
14641 }
14642 Navit.bottom_y_margin_bottom_bar_touch = Navit.cur_y_margin_bottom_bar_touch;
14643 // -- bottom bar --
14644 }
14645 else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
14646 {
14647 // setContentView(R.layout.main_layout);
14648
14649 // -- bottom bar --
14650 int h = NavitGraphics.mCanvasHeight;
14651 try
14652 {
14653 int h001;
14654 android.view.ViewGroup.LayoutParams lp001;
14655
14656 View v003 = (View) findViewById(R.id.osd_nextturn_new);
14657 h001 = getResources().getDimensionPixelSize(R.dimen.osd_nextturn_new_height);
14658 lp001 = v003.getLayoutParams();
14659 lp001.height = h001;
14660 v003.requestLayout();
14661
14662 v003 = (View) findViewById(R.id.bottom_bar);
14663 h001 = getResources().getDimensionPixelSize(R.dimen.bottom_bar_height);
14664 lp001 = v003.getLayoutParams();
14665 lp001.height = h001;
14666 v003.requestLayout();
14667
14668 LinearLayout v002 = (LinearLayout) findViewById(R.id.bottom_slide_view);
14669 h001 = getResources().getDimensionPixelSize(R.dimen.bottom_slide_view_height);
14670 lp001 = v002.getLayoutParams();
14671 lp001.height = h001;
14672 v002.requestLayout();
14673
14674 v003 = (View) findViewById(R.id.osd_timetodest_new);
14675 h001 = getResources().getDimensionPixelSize(R.dimen.osd_timetodest_new_height);
14676 lp001 = v003.getLayoutParams();
14677 lp001.height = h001;
14678 v003.requestLayout();
14679
14680 v002 = (LinearLayout) findViewById(R.id.bottom_line_container);
14681 h001 = getResources().getDimensionPixelSize(R.dimen.bottom_line_container_height);
14682 lp001 = v002.getLayoutParams();
14683 lp001.height = h001;
14684 v002.requestLayout();
14685
14686 RelativeLayout v001 = (RelativeLayout) findViewById(R.id.gui_top_container);
14687 h001 = getResources().getDimensionPixelSize(R.dimen.gui_top_container_height);
14688 lp001 = v001.getLayoutParams();
14689 lp001.height = h001;
14690 v001.requestLayout();
14691
14692 int ml = getResources().getDimensionPixelSize(R.dimen.margin_left_speeding);
14693 int mb = getResources().getDimensionPixelSize(R.dimen.margin_bottom_speeding);
14694 v003 = (View) findViewById(R.id.view_speeding);
14695 RelativeLayout.LayoutParams relativeParams_001 = (RelativeLayout.LayoutParams) v003.getLayoutParams();
14696 relativeParams_001.setMargins(ml, 0, 0, mb); // left, top, right, bottom
14697 v003.setLayoutParams(relativeParams_001);
14698 v003.requestLayout();
14699
14700 // Toast.makeText(this, "protrait", Toast.LENGTH_SHORT).show();
14701
14702 bottom_bar_px = (int) getResources().getDimension(R.dimen.gui_top_container_height);
14703 bottom_bar_slider_shadow_px = (int) getResources().getDimension(R.dimen.bottom_slide_view_shadow_compat_height);
14704
14705 Navit.cur_y_margin_bottom_bar_touch = h + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px; // try to put view at bottom
14706 }
14707 catch (Exception e)
14708 {
14709 Navit.cur_y_margin_bottom_bar_touch = h + Navit.actionBarHeight + bottom_bar_px - Navit.bottom_bar_slider_shadow_px; // try to put view at bottom
14710 }
14711 Navit.bottom_y_margin_bottom_bar_touch = Navit.cur_y_margin_bottom_bar_touch;
14712 // -- bottom bar --
14713 }
14714
14715 last_orientation = newConfig.orientation;
14716 }
14717 }
14718
14719 static void long_toast(String msg)
14720 {
14721 try
14722 {
14723 Message msg7 = Navit_progress_h.obtainMessage();
14724 Bundle b7 = new Bundle();
14725 msg7.what = 2; // long Toast message
14726 b7.putString("text", msg);
14727 msg7.setData(b7);
14728 Navit_progress_h.sendMessage(msg7);
14729 }
14730 catch (Exception e)
14731 {
14732 }
14733 }
14734
14735 static void short_toast(String msg)
14736 {
14737 try
14738 {
14739 Message msg7 = Navit_progress_h.obtainMessage();
14740 Bundle b7 = new Bundle();
14741 msg7.what = 3; // short Toast message
14742 b7.putString("text", msg);
14743 msg7.setData(b7);
14744 Navit_progress_h.sendMessage(msg7);
14745 }
14746 catch (Exception e)
14747 {
14748 }
14749 }
14750
14751 public static void route_wrapper(String addr, float lat_start, float lon_start, boolean start_coords_valid, double lat_end, double lon_end, boolean remember_dest)
14752 {
14753 if (p.PREF_routing_engine == 1)
14754 {
14755 route_online_OSRM(addr, lat_start, lon_start, start_coords_valid, lat_end, lon_end, remember_dest);
14756 }
14757 else if (p.PREF_routing_engine == 0)
14758 {
14759 route_offline_ZANavi(addr, lat_start, lon_start, start_coords_valid, lat_end, lon_end, remember_dest);
14760 }
14761 }
14762
14763 public static void route_offline_ZANavi(String addr, float lat_start, float lon_start, boolean start_coords_valid, double lat_end, double lon_end, boolean remember_dest)
14764 {
14765 if (remember_dest)
14766 {
14767 try
14768 {
14769 Navit.remember_destination(addr, "" + lat_end, "" + lon_end);
14770 // save points
14771 write_map_points();
14772 }
14773 catch (Exception e)
14774 {
14775 e.printStackTrace();
14776 }
14777 }
14778
14779 // DEBUG: clear route rectangle list
14780 NavitGraphics.route_rects.clear();
14781
14782 if (NavitGraphics.navit_route_status == 0)
14783 {
14784 short_toast(Navit.get_text("setting destination to") + "\n" + addr);
14785
14786 Navit.destination_set();
14787
14788 Message msg = new Message();
14789 Bundle b = new Bundle();
14790 b.putInt("Callback", 3);
14791 b.putString("lat", "" + lat_end);
14792 b.putString("lon", "" + lon_end);
14793 b.putString("q", addr);
14794 msg.setData(b);
14795 NavitGraphics.callback_handler.sendMessage(msg);
14796 }
14797 else
14798 {
14799 short_toast(Navit.get_text("new Waypoint") + "\n" + addr);
14800
14801 Message msg = new Message();
14802 Bundle b = new Bundle();
14803 b.putInt("Callback", 48);
14804 b.putString("lat", "" + lat_end);
14805 b.putString("lon", "" + lon_end);
14806 b.putString("q", addr);
14807 msg.setData(b);
14808 NavitGraphics.callback_handler.sendMessage(msg);
14809 }
14810
14811 }
14812
14813 public static void route_online_OSRM(final String addr, float lat_start, float lon_start, boolean start_coords_valid, final double lat_end, final double lon_end, final boolean remember_dest)
14814 {
14815 // http://router.project-osrm.org/viaroute?loc=46.3456438,17.450&loc=47.34122,17.5332&instructions=false&alt=false
14816
14817 if (!start_coords_valid)
14818 {
14819 location_coords cur_target = new location_coords();
14820 try
14821 {
14822 geo_coord tmp = get_current_vehicle_position();
14823 cur_target.lat = tmp.Latitude;
14824 cur_target.lon = tmp.Longitude;
14825 }
14826 catch (Exception e)
14827 {
14828 }
14829
14830 try
14831 {
14832 lat_start = (float) cur_target.lat;
14833 lon_start = (float) cur_target.lon;
14834 }
14835 catch (Exception e)
14836 {
14837 e.printStackTrace();
14838 Log.e("Navit", "problem with location!");
14839 }
14840 }
14841
14842 final String request_url = String.format(Locale.US, "http://router.project-osrm.org/viaroute?loc=%4.6f,%4.6f&loc=%4.6f,%4.6f&instructions=true&alt=false", lat_start, lon_start, lat_end, lon_end);
14843
14844 // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
14845 // StrictMode.setThreadPolicy(policy);
14846
14847 try
14848 {
14849 // System.out.println("XML:S:001 url=" + request_url);
14850 final URL url = new URL(request_url);
14851 // System.out.println("XML:S:002");
14852 // SAXParserFactory factory = SAXParserFactory.newInstance();
14853 // System.out.println("XML:S:003");
14854 // SAXParser parser = factory.newSAXParser();
14855 // System.out.println("XML:S:004");
14856 // XMLReader xmlreader = parser.getXMLReader();
14857 // System.out.println("XML:S:005");
14858 // xmlreader.setContentHandler(new ZANaviXMLHandler());
14859 // System.out.println("XML:S:006");
14860
14861 final Thread add_to_route = new Thread()
14862 {
14863 @Override
14864 public void run()
14865 {
14866 try
14867 {
14868
14869 // --------------
14870 // --------------
14871 // --------------
14872 // ------- allow this HTTPS cert ---
14873 // --------------
14874 // --------------
14875 // --------------
14876 // X509HostnameVerifier hnv = new X509HostnameVerifier()
14877 // {
14878 //
14879 // @Override
14880 // public void verify(String hostname, SSLSocket arg1) throws IOException
14881 // {
14882 // Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
14883 // }
14884 //
14885 // @Override
14886 // public void verify(String hostname, X509Certificate cert) throws SSLException
14887 // {
14888 // Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
14889 // }
14890 //
14891 // @Override
14892 // public void verify(String hostname, String[] cns, String[] subjectAlts) throws SSLException
14893 // {
14894 // Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
14895 // }
14896 //
14897 // @Override
14898 // public boolean verify(String hostname, SSLSession session)
14899 // {
14900 // Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
14901 // return true;
14902 // }
14903 // };
14904 //
14905 // SSLContext context = SSLContext.getInstance("TLS");
14906 // context.init(null, new X509TrustManager[] { new X509TrustManager()
14907 // {
14908 // public java.security.cert.X509Certificate[] getAcceptedIssuers()
14909 // {
14910 // return new java.security.cert.X509Certificate[0];
14911 // }
14912 //
14913 // @Override
14914 // public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
14915 // {
14916 // }
14917 //
14918 // @Override
14919 // public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
14920 // {
14921 // }
14922 // } }, new SecureRandom());
14923 // javax.net.ssl.SSLSocketFactory sslf = context.getSocketFactory();
14924 //
14925 // HostnameVerifier hnv_default = HttpsURLConnection.getDefaultHostnameVerifier();
14926 // javax.net.ssl.SSLSocketFactory sslf_default = HttpsURLConnection.getDefaultSSLSocketFactory();
14927 // HttpsURLConnection.setDefaultHostnameVerifier(hnv);
14928 // HttpsURLConnection.setDefaultSSLSocketFactory(sslf);
14929 //
14930 // DefaultHttpClient client = new DefaultHttpClient();
14931 //
14932 // SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
14933 // SchemeRegistry registry = new SchemeRegistry();
14934 // registry.register(new Scheme("https", socketFactory, 443));
14935 // ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(client.getParams(), registry);
14936 // DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());
14937 //
14938 // socketFactory.setHostnameVerifier(hnv);
14939 //
14940 // HttpGet get_request = new HttpGet(request_url);
14941 // HttpResponse http_response = httpClient.execute(get_request);
14942 // HttpEntity responseEntity = http_response.getEntity();
14943 //
14944 // HttpsURLConnection.setDefaultHostnameVerifier(hnv_default);
14945 // HttpsURLConnection.setDefaultSSLSocketFactory(sslf_default);
14946 // --------------
14947 // --------------
14948 // --------------
14949 // ------- allow this HTTPS cert ---
14950 // --------------
14951 // --------------
14952 // --------------
14953
14954 InputSource is = new InputSource();
14955 is.setEncoding("utf-8");
14956 // is.setByteStream(responseEntity.getContent());
14957 is.setByteStream(url.openStream());
14958 // System.out.println("XML:S:007");
14959
14960 String response = slurp(is.getByteStream(), 16384);
14961 // response = response.replaceAll("&", "&amp;");
14962
14963 // System.out.println("XML:S:007.a res=" + response);
14964
14965 final JSONObject obj = new JSONObject(response);
14966
14967 // System.out.println(person.getInt("id"));
14968
14969 final String route_geometry = obj.getString("route_geometry");
14970 final JSONArray route_instructions_array = obj.getJSONArray("route_instructions");
14971
14972 int loop_i = 0;
14973 JSONArray instruction;
14974 int[] instruction_pos = new int[route_instructions_array.length()];
14975 for (loop_i = 0; loop_i < route_instructions_array.length(); loop_i++)
14976 {
14977 instruction = (JSONArray) route_instructions_array.get(loop_i);
14978 instruction_pos[loop_i] = Integer.parseInt(instruction.get(3).toString());
14979 // System.out.println("XML:instr. pos=" + instruction_pos[loop_i]);
14980 }
14981
14982 // System.out.println("XML:S:009 o=" + route_geometry);
14983
14984 List<geo_coord> gc_list = decode_function(route_geometry, 6);
14985
14986 if (gc_list.size() < 2)
14987 {
14988 // no real route found!! (only 1 point)
14989 }
14990 else
14991 {
14992
14993 Message msg = new Message();
14994 Bundle b = new Bundle();
14995
14996 int loop = 0;
14997
14998 geo_coord cur = new geo_coord();
14999 geo_coord old = new geo_coord();
15000 geo_coord corr = new geo_coord();
15001
15002 cur.Latitude = gc_list.get(loop).Latitude;
15003 cur.Longitude = gc_list.get(loop).Longitude;
15004
15005 int first_found = 1;
15006
15007 if (gc_list.size() > 2)
15008 {
15009 int instr_count = 1;
15010
15011 for (loop = 1; loop < gc_list.size(); loop++)
15012 {
15013
15014 old.Latitude = cur.Latitude;
15015 old.Longitude = cur.Longitude;
15016 cur.Latitude = gc_list.get(loop).Latitude;
15017 cur.Longitude = gc_list.get(loop).Longitude;
15018
15019 if ((instruction_pos[instr_count] == loop) || (loop == (gc_list.size() - 1)))
15020 {
15021
15022 if (loop == (gc_list.size() - 1))
15023 {
15024 corr = cur;
15025 }
15026 else
15027 {
15028 corr = get_point_on_line(old, cur, 70);
15029 }
15030
15031 // -- add waypoint --
15032 // b.putInt("Callback", 55548);
15033 // b.putString("lat", "" + corr.Latitude);
15034 // b.putString("lon", "" + corr.Longitude);
15035 // b.putString("q", " ");
15036 // msg.setData(b);
15037 try
15038 {
15039 // NavitGraphics.callback_handler.sendMessage(msg);
15040 if (first_found == 1)
15041 {
15042 first_found = 0;
15043 NavitGraphics.CallbackMessageChannel(55503, corr.Latitude + "#" + corr.Longitude + "#" + "");
15044 // System.out.println("XML:rR:" + loop + " " + corr.Latitude + " " + corr.Longitude);
15045 }
15046 else
15047 {
15048 NavitGraphics.CallbackMessageChannel(55548, corr.Latitude + "#" + corr.Longitude + "#" + "");
15049 // System.out.println("XML:rw:" + loop + " " + corr.Latitude + " " + corr.Longitude);
15050 }
15051 // Thread.sleep(25);
15052 }
15053 catch (Exception e)
15054 {
15055 e.printStackTrace();
15056 }
15057 // -- add waypoint --
15058
15059 instr_count++;
15060
15061 }
15062
15063 }
15064 }
15065
15066 if (remember_dest)
15067 {
15068 try
15069 {
15070 Navit.remember_destination(addr, "" + lat_end, "" + lon_end);
15071 // save points
15072 write_map_points();
15073 }
15074 catch (Exception e)
15075 {
15076 e.printStackTrace();
15077 }
15078 }
15079
15080 b.putInt("Callback", 55599);
15081 msg.setData(b);
15082 try
15083 {
15084 // System.out.println("XML:calc:");
15085 Thread.sleep(10);
15086 NavitGraphics.callback_handler.sendMessage(msg);
15087 }
15088 catch (Exception e)
15089 {
15090 e.printStackTrace();
15091 }
15092
15093 }
15094
15095 }
15096 catch (Exception e2)
15097 {
15098 e2.printStackTrace();
15099 }
15100 }
15101 };
15102 add_to_route.start();
15103
15104 // convert to coords -------------
15105 // convert to coords -------------
15106
15107 }
15108 catch (Exception e)
15109 {
15110 // System.out.println("XML:S:EEE");
15111 e.printStackTrace();
15112 }
15113 }
15114
15115 static List<geo_coord> decode_function(String encoded, double precision)
15116 {
15117
15118 precision = Math.pow(10, -precision);
15119 int len = encoded.length();
15120 int index = 0;
15121 int lat = 0;
15122 int lng = 0;
15123 double lat_f;
15124 double lon_f;
15125
15126 final List<geo_coord> latLongList = new ArrayList<geo_coord>();
15127 latLongList.clear();
15128
15129 while (index < len)
15130 {
15131
15132 int b;
15133 int shift = 0;
15134 int result = 0;
15135
15136 do
15137 {
15138 b = encoded.charAt(index++) - 63;
15139 result |= (b & 0x1f) << shift;
15140 shift += 5;
15141
15142 }
15143 while (b >= 0x20);
15144
15145 int dlat = 0;
15146 if ((result & 1) != 0)
15147 {
15148 dlat = ~(result >> 1);
15149 }
15150 else
15151 {
15152 dlat = (result >> 1);
15153 }
15154
15155 lat += dlat;
15156 shift = 0;
15157 result = 0;
15158
15159 do
15160 {
15161 b = encoded.charAt(index++) - 63;
15162 result |= (b & 0x1f) << shift;
15163 shift += 5;
15164 }
15165 while (b >= 0x20);
15166
15167 int dlng = 0;
15168 if ((result & 1) != 0)
15169 {
15170 dlng = ~(result >> 1);
15171 }
15172 else
15173 {
15174 dlng = (result >> 1);
15175 }
15176
15177 lng += dlng;
15178 //array.push( {lat: lat * precision, lng: lng * precision} );
15179 // array.push( [lat * precision, lng * precision] );
15180
15181 // System.out.println("XML:lat=" + (lat * precision) + " lon=" + (lng * precision));
15182
15183 lat_f = lat * precision;
15184 lon_f = lng * precision;
15185
15186 geo_coord gc = new geo_coord();
15187 gc.Latitude = lat_f;
15188 gc.Longitude = lon_f;
15189 latLongList.add(gc);
15190 }
15191
15192 return latLongList;
15193 }
15194
15195 public static class geo_coord
15196 {
15197 public double Latitude;
15198 public double Longitude;
15199 }
15200
15201 static geo_coord get_current_vehicle_position()
15202 {
15203 geo_coord ret = new geo_coord();
15204 String current_target_string2 = NavitGraphics.CallbackGeoCalc(14, 1, 1);
15205 // System.out.println("GET CUR POS:" + current_target_string2);
15206 ret.Latitude = 0;
15207 ret.Longitude = 0;
15208 try
15209 {
15210 String tmp[] = current_target_string2.split(":", 2);
15211 ret.Latitude = Double.parseDouble(tmp[0]);
15212 ret.Longitude = Double.parseDouble(tmp[1]);
15213 }
15214 catch (Exception e)
15215 {
15216 // System.out.println("GET CUR POS:ERROR " + e.getMessage());
15217 }
15218 return ret;
15219 }
15220
15221 static int[] geo_to_px(float lat, float lon)
15222 {
15223 int[] ret = new int[3];
15224
15225 ret[0] = -100;
15226 ret[1] = -100;
15227 ret[2] = 0; // invalid
15228
15229 try
15230 {
15231 String x_y = NavitGraphics.CallbackGeoCalc(2, lat, lon);
15232
15233 if (Navit.GFX_OVERSPILL)
15234 {
15235 String tmp[] = x_y.split(":", 2);
15236 int x = Integer.parseInt(tmp[0]);
15237 int y = Integer.parseInt(tmp[1]);
15238
15239 ret[0] = (int) (((float) x + (float) NavitGraphics.mCanvasWidth_overspill) * NavitGraphics.Global_dpi_factor);
15240 ret[1] = (int) (((float) y + (float) NavitGraphics.mCanvasHeight_overspill) * NavitGraphics.Global_dpi_factor);
15241
15242 ret[2] = 1; // VALID
15243 }
15244 else
15245 {
15246 String tmp[] = x_y.split(":", 2);
15247 int x = Integer.parseInt(tmp[0]);
15248 int y = Integer.parseInt(tmp[1]);
15249
15250 ret[0] = (int) ((float) x * NavitGraphics.Global_dpi_factor);
15251 ret[1] = (int) ((float) y * NavitGraphics.Global_dpi_factor);
15252
15253 ret[2] = 1; // VALID
15254 }
15255
15256 }
15257 catch (Exception e)
15258 {
15259 }
15260
15261 return ret;
15262 }
15263
15264 static geo_coord px_to_geo(int x, int y)
15265 {
15266 geo_coord out = new geo_coord();
15267 try
15268 {
15269
15270 String lat_lon = "";
15271 if (Navit.GFX_OVERSPILL)
15272 {
15273 lat_lon = NavitGraphics.CallbackGeoCalc(1, (x + NavitGraphics.mCanvasWidth_overspill) * NavitGraphics.Global_dpi_factor, (y + NavitGraphics.mCanvasHeight_overspill) * NavitGraphics.Global_dpi_factor);
15274 }
15275 else
15276 {
15277 lat_lon = NavitGraphics.CallbackGeoCalc(1, x * NavitGraphics.Global_dpi_factor, y * NavitGraphics.Global_dpi_factor);
15278 }
15279
15280 String tmp[] = lat_lon.split(":", 2);
15281 out.Latitude = Float.parseFloat(tmp[0]);
15282 out.Longitude = Float.parseFloat(tmp[1]);
15283 }
15284 catch (Exception e)
15285 {
15286 }
15287
15288 return out;
15289 }
15290
15291 static double get_percent_coord(double start, double end, int perecent_pos)
15292 {
15293 double out = start + (end - start) * ((float) perecent_pos / 100.0f);
15294 return out;
15295 }
15296
15297 static geo_coord get_point_on_line(geo_coord start, geo_coord end, int perecent_pos)
15298 {
15299 geo_coord out = new geo_coord();
15300
15301 out.Latitude = start.Latitude + (end.Latitude - start.Latitude) * ((float) perecent_pos / 100.0f);
15302 out.Longitude = start.Longitude + (end.Longitude - start.Longitude) * ((float) perecent_pos / 100.0f);
15303
15304 return out;
15305 }
15306
15307 public static String slurp(final InputStream is, final int bufferSize)
15308 {
15309 final char[] buffer = new char[bufferSize];
15310 final StringBuilder out = new StringBuilder();
15311 Reader in = null;
15312
15313 try
15314 {
15315
15316 in = new InputStreamReader(is, "UTF-8");
15317
15318 for (;;)
15319 {
15320 int rsz;
15321 rsz = in.read(buffer, 0, buffer.length);
15322
15323 if (rsz < 0)
15324 {
15325 break;
15326 }
15327 out.append(buffer, 0, rsz);
15328 }
15329
15330 }
15331 catch (IOException e)
15332 {
15333 }
15334 catch (Exception ex)
15335 {
15336 }
15337
15338 return out.toString();
15339 }
15340
15341 public static Handler UIHandler;
15342 static
15343 {
15344 UIHandler = new Handler(Looper.getMainLooper());
15345 }
15346
15347 public static void recalculate_route()
15348 {
15349 try
15350 {
15351 // update route, if a route is set
15352 Message msg = new Message();
15353 Bundle b = new Bundle();
15354 b.putInt("Callback", 73);
15355 msg.setData(b);
15356 NavitGraphics.callback_handler.sendMessage(msg);
15357 }
15358 catch (Exception e)
15359 {
15360 }
15361 }
15362
15363 public static void runOnUI(Runnable runnable)
15364 {
15365 UIHandler.post(runnable);
15366 }
15367
15368 String substring_without_ioobe(String in, int start, int end)
15369 {
15370 String ret = ";:;:****no match****;:;:";
15371
15372 try
15373 {
15374 ret = in.substring(start, end);
15375 }
15376 catch (Exception e)
15377 {
15378 // return dummy-no-match String
15379 }
15380
15381 return ret;
15382 }
15383
15384 static private int get_reglevel()
15385 {
15386 int ret = 0;
15387
15388 try
15389 {
15390 Uri uri = CR_CONTENT_URI;
15391 Cursor c = content_resolver.query(uri, null, null, null, null);
15392
15393 if (c == null)
15394 {
15395 System.out.println("CPVD:Cursor c == null.");
15396 System.out.println("CPVD:reg(0)=" + ret);
15397 return ret;
15398 }
15399
15400 while (c.moveToNext())
15401 {
15402 String column1 = c.getString(0);
15403 String column2 = c.getString(1);
15404 String column3 = c.getString(2);
15405
15406 System.out.println("CPVD:column1=" + column1 + " column2=" + column2 + " column3=" + column3);
15407
15408 if (Integer.parseInt(column1) == 1)
15409 {
15410 if (column2.equals("reg"))
15411 {
15412 ret = Integer.parseInt(column3);
15413 System.out.println("CPVD:reg(1)=" + ret);
15414 }
15415 }
15416 }
15417 c.close();
15418 }
15419 catch (Exception e)
15420 {
15421 e.printStackTrace();
15422 }
15423
15424 System.out.println("CPVD:reg(2)=" + ret);
15425 return ret;
15426 }
15427
15428 static void take_map_screenshot(String dir_name, String name_base)
15429 {
15430 try
15431 {
15432 View v1 = Navit.N_NavitGraphics.view;
15433 v1.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
15434 v1.setDrawingCacheEnabled(true);
15435 Bitmap bm = v1.getDrawingCache();
15436
15437 FileOutputStream out = null;
15438 try
15439 {
15440 out = new FileOutputStream(dir_name + "/" + name_base + ".png");
15441 bm.compress(Bitmap.CompressFormat.PNG, 100, out);
15442 }
15443 catch (Exception e)
15444 {
15445 e.printStackTrace();
15446 System.out.println("TSCR:004 " + e.getMessage());
15447 }
15448 finally
15449 {
15450 v1.setDrawingCacheEnabled(false);
15451
15452 try
15453 {
15454 if (out != null)
15455 {
15456 out.close();
15457 }
15458 }
15459 catch (IOException e)
15460 {
15461 e.printStackTrace();
15462 }
15463 }
15464 }
15465 catch (Exception e4)
15466 {
15467 }
15468 }
15469 }

   
Visit the ZANavi Wiki