/[zanavi_public1]/navit/navit/android.c
ZANavi

Contents of /navit/navit/android.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 8 months ago) by zoff99
File MIME type: text/plain
File size: 96209 byte(s)
many fixes, and new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2014 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 #include <stdlib.h>
21 #include <string.h>
22 #include <poll.h>
23 #include <glib.h>
24 #include "android.h"
25 #include <android/log.h>
26 #include <android/bitmap.h>
27 #include "navit.h"
28 #include "config_.h"
29 #include "command.h"
30 #include "debug.h"
31 #include "event.h"
32 #include "callback.h"
33 #include "projection.h"
34 #include "map.h"
35 #include "transform.h"
36 #include "color.h"
37 #include "types.h"
38 #include "search.h"
39 #include "start_real.h"
40 #include "route.h"
41 #include "track.h"
42 #include "file.h"
43 #include "roadprofile.h"
44 #include "navit_nls.h"
45
46 // #include "layout.h"
47
48 JNIEnv *jnienv;
49 jobject *android_activity;
50 jobject *main_map_bitmap;
51 AndroidBitmapInfo *main_map_bitmapinfo;
52 struct callback_list *android_activity_cbl;
53 int android_version;
54
55 jclass NavitGraphicsClass2 = NULL;
56 jmethodID return_generic_int;
57 jmethodID send_generic_text;
58 jclass NavitMapPreviewActivityClass = NULL;
59 jmethodID DrawMapPreview_target;
60 jmethodID DrawMapPreview_polyline = NULL;
61 jmethodID DrawMapPreview_text = NULL;
62 jmethodID NavitGraphics_send_osd_values2 = NULL;
63 jmethodID NavitGraphics_set_vehicle_values2 = NULL;
64 jmethodID NavitGraphics_set_vehicle_values3 = NULL;
65 jmethodID NavitGraphics_send_route_rect_to_java = NULL;
66
67 struct attr attr;
68
69
70
71
72
73
74
75 // #define NAVIT_FUNC_CALLS_DEBUG_PRINT 1
76
77
78 // --------------- debug function calls ------------------
79 // --------------- debug function calls ------------------
80 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
81 #undef return2
82 #define return2 dbg_func(0, global_func_indent_counter, "return(%d)\n", __LINE__);global_func_indent_counter--;return
83
84 #define __F_START__ global_func_indent_counter++;dbg_func(0, global_func_indent_counter, "enter\n");
85 #define __F_END__ dbg_func(0, global_func_indent_counter, "leave\n");global_func_indent_counter--;
86 #else
87 #undef return2
88 #define return2 return
89
90 #define __F_START__
91 #define __F_END__
92 #endif
93 // --------------- debug function calls ------------------
94 // --------------- debug function calls ------------------
95
96
97
98
99
100
101
102
103
104
105 // ------------------------- COPIED STUFF --- this is generally bad ------------------
106 // ------------------------- COPIED STUFF --- this is generally bad ------------------
107 // ------------------------- COPIED STUFF --- this is generally bad ------------------
108
109
110 // copyied from config_.c !!! (always keep in sync!!!)
111 struct config
112 {
113 struct attr **attrs;
114 struct callback_list *cbl;
115 }*config;
116
117 // copied from gui_internal.c (always keep in sync!!!)
118 struct gui_config_settings
119 {
120 int font_size;
121 int icon_xs;
122 int icon_s;
123 int icon_l;
124 int spacing;
125 };
126
127 // dummy def!!
128 struct gui_internal_methods
129 {
130 int dummy;
131 };
132
133 // dummy def!!
134 struct gui_internal_widget_methods
135 {
136 int dummy;
137 };
138
139 // forward def
140 struct gui_priv;
141
142 // copied from gui_internal.h (always keep in sync!!!)
143 struct gui_internal_data
144 {
145 struct gui_priv *priv;
146 struct gui_internal_methods *gui;
147 struct gui_internal_widget_methods *widget;
148 };
149
150 // copied from gui_internal.c (always keep in sync!!!)
151 struct route_data
152 {
153 struct widget * route_table;
154 int route_showing;
155
156 };
157
158 // copied from gui_internal.h (always keep in sync!!!)
159 enum flags
160 {
161 gravity_none = 0x00, gravity_left = 1, gravity_xcenter = 2, gravity_right = 4, gravity_top = 8, gravity_ycenter = 16, gravity_bottom = 32, gravity_left_top = gravity_left | gravity_top, gravity_top_center = gravity_xcenter | gravity_top, gravity_right_top = gravity_right | gravity_top, gravity_left_center = gravity_left | gravity_ycenter, gravity_center = gravity_xcenter | gravity_ycenter, gravity_right_center = gravity_right | gravity_ycenter, gravity_left_bottom = gravity_left | gravity_bottom, gravity_bottom_center = gravity_xcenter | gravity_bottom, gravity_right_bottom = gravity_right | gravity_bottom, flags_expand = 0x100, flags_fill = 0x200, orientation_horizontal = 0x10000, orientation_vertical = 0x20000, orientation_horizontal_vertical = 0x40000,
162 };
163
164 // copied from gui_internal.h (always keep in sync!!!)
165 enum widget_type
166 {
167 widget_box = 1, widget_button, widget_label, widget_image, widget_table, widget_table_row
168 };
169
170 // copied from gui_internal.c (always keep in sync!!!)
171 struct widget
172 {
173 enum widget_type type;
174 struct graphics_gc *background, *text_background;
175 struct graphics_gc *foreground_frame;
176 struct graphics_gc *foreground;
177 char *text;
178 struct graphics_image *img;
179 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
180 int reason;
181 int datai;
182 void *data;
183 void (*data_free)(void *data);
184 void (*free)(struct gui_priv *this_, struct widget * w);
185 char *prefix;
186 char *name;
187 char *speech;
188 char *command;
189 struct pcoord c;
190 struct item item;
191 int selection_id;
192 int state;
193 struct point p;
194 int wmin, hmin;
195 int w, h;
196 int textw, texth;
197 int font_idx;
198 int bl, br, bt, bb, spx, spy;
199 int border;
200 int packed;
201 int cols;
202 enum flags flags;
203 int flags2;
204 void *instance;
205 int (*set_attr)(void *, struct attr *);
206 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
207 void (*remove_cb)(void *, struct callback *cb);
208 struct callback *cb;
209 struct attr on;
210 struct attr off;
211 int deflt;
212 int is_on;
213 int redraw;
214 struct menu_data *menu_data;
215 struct form *form;
216 GList *children;
217 };
218
219 // copied from gui_internal.c !!!!!! (always keep in sync!!!)
220 struct gui_priv
221 {
222 struct navit *nav;
223 struct attr self;
224 struct window *win;
225 struct graphics *gra;
226 struct graphics_gc *background;
227 struct graphics_gc *background2;
228 struct graphics_gc *highlight_background;
229 struct graphics_gc *foreground;
230 struct graphics_gc *text_foreground;
231 struct graphics_gc *text_background;
232 struct color background_color, background2_color, text_foreground_color, text_background_color;
233 int spacing;
234 int font_size;
235 int fullscreen;
236 struct graphics_font *fonts[3];
237 int icon_xs;
238 int icon_s;
239 int icon_l;
240 int pressed;
241 struct widget *widgets;
242 int widgets_count;
243 int redraw;
244 struct widget root;
245 struct widget *highlighted, *editable;
246 struct widget *highlighted_menu;
247 int clickp_valid, vehicle_valid;
248 struct pcoord clickp, vehiclep;
249 struct attr *click_coord_geo, *position_coord_geo;
250 struct search_list *sl;
251 int ignore_button;
252 int menu_on_map_click;
253 int signal_on_map_click;
254 char *country_iso2;
255 int speech;
256 int keyboard;
257 int keyboard_required;
258 struct gui_config_settings config;
259 struct event_idle *idle;
260 struct callback *motion_cb, *button_cb, *resize_cb, *keypress_cb, *window_closed_cb, *idle_cb, *motion_timeout_callback;
261 struct event_timeout *motion_timeout_event;
262 struct point current;
263 struct callback * vehicle_cb;
264 struct route_data route_data;
265 struct gui_internal_data data;
266 struct callback_list *cbl;
267 int flags;
268 int cols;
269 struct attr osd_configuration;
270 int pitch;
271 int flags_town, flags_street, flags_house_number;
272 int radius;
273 char *html_text;
274 int html_depth;
275 struct widget *html_container;
276 int html_skip;
277 char *html_anchor;
278 char *href;
279 int html_anchor_found;
280 struct form *form;
281 struct html
282 {
283 int skip;
284 enum html_tag
285 {
286 html_tag_none, html_tag_a, html_tag_h1, html_tag_html, html_tag_img, html_tag_script, html_tag_form, html_tag_input, html_tag_div,
287 } tag;
288 char *command;
289 char *name;
290 char *href;
291 char *refresh_cond;
292 struct widget *w;
293 struct widget *container;
294 } html[10];
295 };
296
297 // ------------------------- COPIED STUFF --- this is generally bad ------------------
298 // ------------------------- COPIED STUFF --- this is generally bad ------------------
299 // ------------------------- COPIED STUFF --- this is generally bad ------------------
300
301
302 JavaVM *cachedJVM = NULL;
303
304 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
305 {
306 JNIEnv *env_this;
307 cachedJVM = jvm;
308 if ((*jvm)->GetEnv(jvm, (void**) &env_this, JNI_VERSION_1_6))
309 {
310 // dbg(0,"Could not get JVM\n");
311 return JNI_ERR;
312 }
313
314 // dbg(0,"++ Found JVM ++\n");
315 return JNI_VERSION_1_6;
316 }
317
318 JNIEnv* jni_getenv()
319 {
320 JNIEnv* env_this;
321 (*cachedJVM)->GetEnv(cachedJVM, (void**) &env_this, JNI_VERSION_1_6);
322 return env_this;
323 }
324
325 static void gui_internal_search_list_set_default_country2(struct gui_priv *this)
326 {
327 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
328 dbg(0,"+#+:enter\n");
329 #endif
330 struct attr search_attr, country_name, country_iso2, *country_attr;
331 struct item *item;
332 struct country_search *cs;
333 struct tracking *tracking;
334 struct search_list_result *res;
335
336 ////DBG // dbg(0,"### 1");
337
338 country_attr = country_default();
339 tracking = navit_get_tracking(this->nav);
340
341 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
342 country_attr = &search_attr;
343 if (country_attr)
344 {
345 ////DBG // dbg(0,"### 2");
346 cs = country_search_new(country_attr, 0);
347 item = country_search_get_item(cs);
348 if (item && item_attr_get(item, attr_country_name, &country_name))
349 {
350 search_attr.type = attr_country_all;
351 ////DBG // dbg(0,"country %s\n", country_name.u.str);
352 search_attr.u.str = country_name.u.str;
353 search_list_search(this->sl, &search_attr, 0);
354 while ((res = search_list_get_result(this->sl)))
355 ;
356 if (this->country_iso2)
357 {
358 // this seems to cause a crash, no idea why
359 //g_free(this->country_iso2);
360 this->country_iso2 = NULL;
361 }
362 if (item_attr_get(item, attr_country_iso2, &country_iso2))
363 {
364 this->country_iso2 = g_strdup(country_iso2.u.str);
365 }
366 }
367 country_search_destroy(cs);
368 }
369 else
370 {
371 //DBG // dbg(0, "warning: no default country found\n");
372 if (this->country_iso2)
373 {
374 //DBG // dbg(0, "attempting to use country '%s'\n", this->country_iso2);
375 search_attr.type = attr_country_iso2;
376 search_attr.u.str = this->country_iso2;
377 search_list_search(this->sl, &search_attr, 0);
378 while ((res = search_list_get_result(this->sl)))
379 ;
380 }
381 }
382 ////DBG // dbg(0,"### 99");
383 }
384
385 // forward rev
386 struct navit *global_navit;
387
388 int android_find_class_global(char *name, jclass *ret)
389 {
390 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
391 dbg(0,"+#+:enter\n");
392 #endif
393
394 JNIEnv *jnienv2;
395 jnienv2 = jni_getenv();
396
397 *ret = (*jnienv2)->FindClass(jnienv2, name);
398 if (!*ret)
399 {
400 //DBG // dbg(0, "Failed to get Class %s\n", name);
401 return 0;
402 }
403 //DBG // dbg(0,"lclass %p\n", *ret);
404 *ret = (*jnienv2)->NewGlobalRef(jnienv2, *ret);
405 // ICS (*jnienv2)->DeleteGlobalRef(jnienv2, *lret);
406 //DBG // dbg(0,"gclass %p\n", *ret);
407 return 1;
408 }
409
410 int android_find_method(jclass class, char *name, char *args, jmethodID *ret)
411 {
412 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
413 dbg(0,"+#+:enter\n");
414 #endif
415
416 JNIEnv *jnienv2;
417 jnienv2 = jni_getenv();
418
419 *ret = (*jnienv2)->GetMethodID(jnienv2, class, name, args);
420 if (*ret == NULL)
421 {
422 //DBG // dbg(0, "Failed to get Method %s with signature %s\n", name, args);
423 return 0;
424 }
425 //DBG // dbg(0,"l meth %p\n", *ret);
426 return 1;
427 }
428
429 int android_find_static_method(jclass class, char *name, char *args, jmethodID *ret)
430 {
431 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
432 dbg(0,"+#+:enter\n");
433 #endif
434
435 JNIEnv *jnienv2;
436 jnienv2 = jni_getenv();
437
438 *ret = (*jnienv2)->GetStaticMethodID(jnienv2, class, name, args);
439 if (*ret == NULL)
440 {
441 //DBG // dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
442 return 0;
443 }
444 //DBG // dbg(0,"l meth %p\n", *ret);
445 return 1;
446 }
447
448
449 JNIEXPORT void JNICALL
450 Java_com_zoffcc_applications_zanavi_Navit_NavitMain(JNIEnv* env, jobject thiz, jobject activity, jobject lang, int version, jobject display_density_string, jobject n_datadir, jobject n_sharedir, jobject bitmap)
451 {
452 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
453 dbg(0,"+#+:enter\n");
454 #endif
455
456 #ifdef DEBUG_GLIB_MEM_FUNCTIONS
457 // GLIB debugging
458 // GLIB debugging
459 // GLIB debugging
460 /*
461 dbg(0,"GLIB debugging ----------------------");
462 dbg(0,"GLIB debugging ----------------------");
463 dbg(0,"GLIB debugging ----------------------");
464 dbg(0,"GLIB debugging ----------------------");
465 dbg(0,"GLIB debugging ----------------------");
466 dbg(0,"GLIB debugging ----------------------");
467 dbg(0,"GLIB debugging ----------------------");
468 dbg(0,"GLIB debugging ----------------------");
469 dbg(0,"GLIB debugging 1 --------------------");
470 */
471 //*******???******** g_mem_set_vtable(glib_mem_profiler_table);
472 //char *dummy_997;
473 //dummy_997 = g_malloc(1024*1024*10); // 10 MByte
474 //g_free(dummy_997);
475 //dummy_997 = NULL;
476 //g_mem_profile();
477 /*
478 dbg(0,"GLIB debugging 2 --------------------");
479 dbg(0,"GLIB debugging ----------------------");
480 dbg(0,"GLIB debugging ----------------------");
481 dbg(0,"GLIB debugging ----------------------");
482 dbg(0,"GLIB debugging ----------------------");
483 dbg(0,"GLIB debugging ----------------------");
484 dbg(0,"GLIB debugging ----------------------");
485 dbg(0,"GLIB debugging ----------------------");
486 dbg(0,"GLIB debugging ----------------------");
487 */
488 // GLIB debugging
489 // GLIB debugging
490 // GLIB debugging
491 #endif
492
493 int thread_id = gettid();
494 // dbg(0, "THREAD ID=%d\n", thread_id);
495
496 char *strings[] = { "/data/data/com.zoffcc.applications.zanavi/bin/navit", NULL };
497 const char *langstr;
498 const char *displaydensitystr;
499 const char *s;
500 android_version = version;
501 //__android_log_print(ANDROID_LOG_ERROR,"test","called");
502 android_activity_cbl = callback_list_new("Java_com_zoffcc_applications_zanavi_Navit_NavitMain:android_activity_cbl");
503
504 // SET GLOBAL JNIENV here, this is bad!!
505 // SET GLOBAL JNIENV here, this is bad!!
506 // SET GLOBAL JNIENV here, this is bad!!
507 jnienv = env;
508 // dbg(0,"jnienv=%p\n", env);
509 // SET GLOBAL JNIENV here, this is bad!!
510 // SET GLOBAL JNIENV here, this is bad!!
511 // SET GLOBAL JNIENV here, this is bad!!
512
513 //jclass someClass = env->FindClass("SomeClass");
514 //gSomeClass = env->NewGlobalRef(someClass);
515
516
517
518 #if 0
519 // runtime TEST INT / FLOAT ----------
520 // runtime TEST INT / FLOAT ----------
521 // runtime TEST INT / FLOAT ----------
522 int v1 = 27;
523 int v2 = 13;
524 int r2;
525 int r3;
526
527 int ij1a;
528 int ccc = 10000000;
529 clock_t s_;
530
531 s_ = debug_measure_start();
532 for (ij1a=0; ij1a < ccc; ij1a++)
533 {
534 r2 = ( v1 * 100 * (v2 * 10.0 ) / 10000);
535 }
536 debug_mrp("TEST:INT :", debug_measure_end(s_));
537
538 s_ = debug_measure_start();
539 for (ij1a=0; ij1a < ccc; ij1a++)
540 {
541 r3 = (int)( (float)v1 * ((float)v2 / 10.0f ));
542 }
543 debug_mrp("TEST:FLOAT:", debug_measure_end(s_));
544 // runtime TEST INT / FLOAT ----------
545 // runtime TEST INT / FLOAT ----------
546 // runtime TEST INT / FLOAT ----------
547 #endif
548
549
550
551 main_map_bitmap = (*env)->NewGlobalRef(env, bitmap); // --> ANDROID_BITMAP_FORMAT_RGBA_8888
552 main_map_bitmapinfo = NULL;
553
554 // enum AndroidBitmapFormat {
555 // ANDROID_BITMAP_FORMAT_NONE = 0,
556 // ANDROID_BITMAP_FORMAT_RGBA_8888 = 1,
557 // ANDROID_BITMAP_FORMAT_RGB_565 = 4,
558 // ANDROID_BITMAP_FORMAT_RGBA_4444 = 7,
559 // ANDROID_BITMAP_FORMAT_A_8 = 8,
560 // };
561
562
563 // *only local* android_activity = activity;
564 // android_activity = (*jnienv)->NewGlobalRef(jnienv, activity);
565 android_activity = (*env)->NewGlobalRef(env, activity);
566 langstr = (*env)->GetStringUTFChars(env, lang, NULL);
567 //DBG // dbg(0, "enter env=%p thiz=%p activity=%p lang=%s version=%d\n", env, thiz, activity, langstr, version);
568 //DBG // dbg(0, "enter env=%p thiz=%p activity=%p lang=%s version=%d\n", env, thiz, android_activity, langstr, version);
569 setenv("LANG", langstr, 1);
570 (*env)->ReleaseStringUTFChars(env, lang, langstr);
571
572 s = (*env)->GetStringUTFChars(env, n_datadir, NULL);
573 navit_data_dir = g_strdup(s);
574 (*env)->ReleaseStringUTFChars(env, n_datadir, s);
575
576 s = (*env)->GetStringUTFChars(env, n_sharedir, NULL);
577 navit_share_dir = g_strdup(s);
578 (*env)->ReleaseStringUTFChars(env, n_sharedir, s);
579
580
581 displaydensitystr = (*env)->GetStringUTFChars(env, display_density_string, NULL);
582 dbg(0, "*****displaydensity=%s\n", displaydensitystr);
583 setenv("ANDROID_DENSITY", displaydensitystr, 1);
584
585 // calc DPI value
586 global_have_dpi_value = atoi(displaydensitystr);
587 dbg(0, "*****displaydensity int=%d\n", (int) global_have_dpi_value);
588
589 if (global_have_dpi_value >= 320)
590 {
591 global_dpi_factor = (float) global_have_dpi_value / 240.0f; // multiply with this factor where needed!
592 }
593 else
594 {
595 global_dpi_factor = 1.0f;
596 }
597
598 (*env)->ReleaseStringUTFChars(env, display_density_string, displaydensitystr);
599
600 //// dbg(0,"before main_real call\n");
601 //main_real(1, strings);
602 //// dbg(0,"after main_real call\n");
603
604 /* -- mem test --
605 char *dummy_99;
606 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
607 g_free(dummy_99);
608 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
609 g_free(dummy_99);
610 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
611 g_free(dummy_99);
612 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
613 g_free(dummy_99);
614 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
615 g_free(dummy_99);
616 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
617 g_free(dummy_99);
618 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
619 g_free(dummy_99);
620 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
621 g_free(dummy_99);
622 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
623 g_free(dummy_99);
624 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
625 g_free(dummy_99);
626 dummy_997 = NULL;
627 */
628
629
630
631 #if 0
632
633 double lat = 48.6936931;
634 double lon = 16.0135909;
635 float latf = 48.6936931;
636 float lonf = 16.0135909;
637
638
639 //transform_to_geo_lat(transform_from_geo_lat(lat));
640 //transform_to_geo_lon(transform_from_geo_lon(lon));
641
642
643 long long j=0;
644 double ddd;
645 int in_y=12278278;
646
647 clock_t s_;
648 clock_t diff_time;
649
650 s_ = clock();
651 for(j=0;j<10000000L;j++)
652 {
653 ddd = atan(exp((in_y/2.00) / 6378137.0)) / M_PI * 360 - 90;
654 }
655 diff_time = clock() - s_;
656 dbg(0, "1:%fs\n", (double) ((double) diff_time / (double) CLOCKS_PER_SEC));
657
658 s_ = clock();
659 for(j=0;j<10000000L;j++)
660 {
661 ddd = TO_GEO_LAT_(in_y);
662 // fprintf(stderr, "lon=%.17f\n", ddd);
663 }
664 diff_time = clock() - s_;
665 dbg(0, "2:%fs\n", (double) ((double) diff_time / (double) CLOCKS_PER_SEC));
666
667 s_ = clock();
668 for(j=0;j<10000000L;j++)
669 {
670 ddd = TO_GEO_LAT_FAST_(in_y);
671 }
672 diff_time = clock() - s_;
673 dbg(0, "3:%fs\n", (double) ((double) diff_time / (double) CLOCKS_PER_SEC));
674
675
676 #endif
677
678
679
680
681
682 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
683 dbg(0,"+#+:leave\n");
684 #endif
685
686 }
687
688 JNIEXPORT void JNICALL
689 Java_com_zoffcc_applications_zanavi_Navit_NavitActivity(JNIEnv* env, jobject thiz, int param)
690 {
691 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
692 dbg(0,"+#+:enter\n");
693 #endif
694
695 dbg(0, "enter %d\n", param);
696
697 int thread_id = gettid();
698 // dbg(0, "THREAD ID=%d\n", thread_id);
699
700 #ifndef NAVIT_DEBUG_BAREMETAL
701
702 if (param == -2)
703 {
704 // onStop() -> called in Java app
705 // save center.txt
706 if (global_navit->bookmarks)
707 {
708 config_get_attr(config, attr_navit, &attr, NULL);
709 //DBG // dbg(0, "save position to file");
710 char *center_file = bookmarks_get_center_file(TRUE);
711 bookmarks_write_center_to_file(attr.u.navit->bookmarks, center_file);
712 // dbg(0, "save pos to file -> ready");
713 g_free(center_file);
714 // bookmarks_destroy(global_navit->bookmarks);
715 }
716 }
717 #endif
718
719 // param == 3 // onCreate
720 // param == 2 // onStart
721 // param == 1 // onResume
722 // param == 0 // onRestart
723 // param == -1 // onPause
724 // param == -2 // onStop
725 // param == -3 // onDestroy
726 // param == -4 // exit() [java function]
727
728
729 if (param == 3)
730 {
731 // in onCreate at startup
732 char *strings[] = { "/data/data/com.zoffcc.applications.zanavi/bin/navit", NULL };
733
734 // ------------ send initial values for GEO calcs to Java ---------------
735 // ------------ send initial values for GEO calcs to Java ---------------
736 char *temp_t = NULL;
737
738 temp_t = g_strdup_printf("%.17f\n", (double)__EARTH_RADIUS__);
739 android_send_generic_text(21, temp_t);
740 g_free(temp_t);
741
742 temp_t = g_strdup_printf("%.17f\n", (double)__GEO_ACCURACY_FACTOR__);
743 android_send_generic_text(22, temp_t);
744 g_free(temp_t);
745
746 temp_t = NULL;
747 // ------------ send initial values for GEO calcs to Java ---------------
748 // ------------ send initial values for GEO calcs to Java ---------------
749
750 // dbg(0,"before main_real call\n");
751 main_real(1, strings);
752 // dbg(0,"after main_real call\n");
753
754 #ifndef NAVIT_DEBUG_BAREMETAL
755 navit_draw(global_navit);
756 #endif
757 }
758
759
760 // dbg(0, "acti: 001\n");
761 // callback_list_call_1(android_activity_cbl, param);
762 //// dbg(0, "acti: 002\n");
763
764 //if (param == -4)
765 //{
766 // // dbg(0, "acti: 003\n");
767 // // *********EXIT******EXIT******** // exit(0);
768 //}
769
770 #ifndef NAVIT_DEBUG_BAREMETAL
771 if (param == -4)
772 {
773 // dbg(0, "acti: 004\n");
774 navit_destroy(global_navit);
775 // dbg(0, "acti: 005\n");
776 event_main_loop_quit();
777 // dbg(0, "acti: 006\n");
778 }
779 #endif
780
781 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
782 dbg(0,"+#+:leave\n");
783 #endif
784 }
785
786 JNIEXPORT void JNICALL
787 Java_com_zoffcc_applications_zanavi_NavitGraphics_SizeChangedCallbackReal(JNIEnv* env, jobject thiz, int w, int h, jobject bitmap)
788 {
789 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
790 dbg(0,"+#+:enter\n");
791 #endif
792 // dbg(0,"enter %d %d\n", w, h);
793
794 int thread_id = gettid();
795 // dbg(0, "THREAD ID=%d\n", thread_id);
796
797
798 #ifndef NAVIT_DEBUG_BAREMETAL
799
800 if (main_map_bitmap)
801 {
802 (*env)->DeleteGlobalRef(env, main_map_bitmap);
803 }
804 main_map_bitmap = (*env)->NewGlobalRef(env, bitmap); // --> ANDROID_BITMAP_FORMAT_RGBA_8888
805 main_map_bitmapinfo = NULL;
806
807 navit_handle_resize(global_navit, w, h);
808
809 #endif
810
811 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
812 dbg(0,"+#+:leave\n");
813 #endif
814 }
815
816 JNIEXPORT void JNICALL
817 Java_com_zoffcc_applications_zanavi_NavitGraphics_MotionCallbackReal(JNIEnv* env, jobject thiz, int x1, int y1, int x2, int y2, int draw)
818 {
819 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
820 dbg(0,"+#+:enter\n");
821 #endif
822
823 //int thread_id = gettid();
824 // dbg(0, "THREAD ID=%d\n", thread_id);
825
826
827 #ifndef NAVIT_DEBUG_BAREMETAL
828
829 struct point p_end;
830 struct point p_start;
831
832 p_start.x = x1;
833 p_start.y = y1;
834 p_end.x = x2;
835 p_end.y = y2;
836 update_transformation(global_navit->trans, &p_start, &p_end, NULL);
837 // graphics_draw_drag(this_->gra, NULL);
838 transform_copy(global_navit->trans, global_navit->trans_cursor);
839 global_navit->moved = 1;
840
841 /*
842 struct coord c;
843 struct pcoord pc;
844 p.x = x;
845 p.y = y;
846 transform_reverse(global_navit->trans, &p, &c);
847 pc.x = c.x;
848 pc.y = c.y;
849 pc.pro = transform_get_projection(global_navit->trans);
850 navit_set_position(global_navit, &pc);
851 */
852
853 // dbg(0,"call async java draw -start-\n");
854 if (draw == 1)
855 {
856 navit_draw(global_navit);
857 }
858 else
859 {
860 // if we dont want to draw, then also cancel any drawing that is already in progress!
861 cancel_drawing_global = 1;
862 }
863 // navit_draw_async(global_navit, 1);
864 // dbg(0,"call async java draw --end--\n");
865
866 // remove the "wait" screen
867 //#ifdef HAVE_API_ANDROID
868 // android_return_generic_int(2, 0);
869 //#endif
870
871 #endif
872
873 }
874
875 JNIEXPORT void JNICALL
876 Java_com_zoffcc_applications_zanavi_NavitGraphics_TimeoutCallback(JNIEnv* env, jobject thiz, int delete, int id)
877 {
878 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
879 dbg(0,"+#+:enter\n");
880 #endif
881
882 #ifndef NAVIT_DEBUG_BAREMETAL
883
884 JNIEnv *jnienv2;
885 jnienv2 = jni_getenv();
886
887 //int thread_id = gettid();
888 //dbg(0, "THREAD ID=%d\n", thread_id);
889
890 //DBG // dbg(0,"enter %p %d %p\n",thiz, delete, (void *)id);
891 //dbg(0,"timeout 1\n");
892 // ICS
893 //if (id != 0)
894 //{
895 // dbg(0,"callback struct=%p %d\n", id, id);
896 callback_call_0((struct callback *) id);
897 //}
898 // ICS
899 //dbg(0,"timeout 2\n");
900
901 /*
902 if (delete)
903 {
904 //dbg(0,"timeout 3\n");
905 // ICS
906 jobject this_global = (*jnienv2)->NewGlobalRef(jnienv2, thiz);
907 //dbg(0,"timeout 3.1\n");
908 (*jnienv2)->DeleteGlobalRef(jnienv2, this_global);
909 // ICS
910 //dbg(0,"timeout 4\n");
911 }
912 */
913 #endif
914 }
915
916 JNIEXPORT void JNICALL
917 Java_com_zoffcc_applications_zanavi_NavitIdle_IdleCallback(JNIEnv* env, jobject thiz, int id)
918 {
919 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
920 dbg(0,"+#+:enter\n");
921 #endif
922
923 //int thread_id = gettid();
924 // dbg(0, "THREAD ID=%d\n", thread_id);
925
926 //DBG // dbg(0,"enter %p %p\n",thiz, (void *)id);
927 // dbg(0,"idlecall back 1\n");
928 callback_call_0((struct callback *) id);
929 // dbg(0,"idlecall back 2\n");
930 }
931
932 JNIEXPORT void JNICALL
933 Java_com_zoffcc_applications_zanavi_NavitWatch_poll(JNIEnv* env, jobject thiz, int fd, int cond)
934 {
935 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
936 dbg(0,"+#+:enter\n");
937 #endif
938 struct pollfd pfd;
939 pfd.fd = fd;
940 //DBG // dbg(0, "%p poll called for %d %d\n", env, fd, cond);
941 switch ((enum event_watch_cond) cond)
942 {
943 case event_watch_cond_read:
944 pfd.events = POLLIN;
945 break;
946 case event_watch_cond_write:
947 pfd.events = POLLOUT;
948 break;
949 case event_watch_cond_except:
950 pfd.events = POLLERR;
951 break;
952 default:
953 pfd.events = 0;
954 }
955 pfd.revents = 0;
956 poll(&pfd, 1, -1);
957 }
958
959 JNIEXPORT void JNICALL
960 Java_com_zoffcc_applications_zanavi_NavitWatch_WatchCallback(JNIEnv* env, jobject thiz, int id)
961 {
962 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
963 dbg(0,"+#+:enter\n");
964 #endif
965 //DBG // dbg(0, "enter %p %p\n", thiz, (void *) id);
966 callback_call_0((struct callback *) id);
967 }
968
969 JNIEXPORT void JNICALL
970 Java_com_zoffcc_applications_zanavi_NavitSensors_SensorCallback(JNIEnv* env, jobject thiz, int id, int sensor, float x, float y, float z)
971 {
972 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
973 dbg(0,"+#+:enter\n");
974 #endif
975 // JNIEnv *jnienv2;
976 // jnienv2 = jni_getenv();
977
978 //int thread_id = gettid();
979 // dbg(0, "THREAD ID=%d\n", thread_id);
980
981 //DBG // dbg(0, "enter %p %p %f %f %f\n", thiz, (void *) id, x, y, z);
982 callback_call_4((struct callback *) id, sensor, &x, &y, &z);
983 }
984
985 JNIEXPORT void JNICALL
986 Java_com_zoffcc_applications_zanavi_NavitVehicle_VehicleCallback(JNIEnv *env, jobject thiz, double lat, double lon, float speed, float direction, double height, float radius, long gpstime)
987 {
988 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
989 dbg(0,"+#+:enter\n");
990 #endif
991
992 #ifndef NAVIT_DEBUG_BAREMETAL
993
994 // JNIEnv *jnienv2;
995 // jnienv2 = jni_getenv();
996 //int thread_id = gettid();
997 //dbg(0, "THREAD ID=%d\n", thread_id);
998
999 //dbg(0,"VehicleCallback location=%p\n", location);
1000 //+++jobject location2 = (*env)->NewGlobalRef(env, location);
1001 //+++(*env)->DeleteLocalRef(env, location);
1002 //// dbg(0,"location=%p\n", location2);
1003
1004 if ((global_navit) && (global_navit->vehicle) && (global_navit->vehicle->vehicle))
1005 {
1006 vehicle_update_(global_navit->vehicle->vehicle, lat, lon, speed, direction, height, radius, gpstime);
1007 }
1008 else
1009 {
1010 dbg(0, "no vehicle set !!\n");
1011 }
1012
1013 #endif
1014
1015 //dbg(0,"leave\n");
1016
1017 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1018 dbg(0,"+#+:leave\n");
1019 #endif
1020 }
1021
1022 void android_return_search_result(struct jni_object *jni_o, char *str)
1023 {
1024 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1025 dbg(0,"+#+:enter\n");
1026 #endif
1027 // dbg(0,"EEnter\n");
1028
1029 // int thread_id = gettid();
1030 // dbg(0, "THREAD ID=%d\n", thread_id);
1031
1032 jstring js2 = NULL;
1033 JNIEnv* env2;
1034 env2 = jni_o->env;
1035 js2 = (*env2)->NewStringUTF(jni_o->env, str);
1036 (*env2)->CallVoidMethod(jni_o->env, jni_o->jo, jni_o->jm, js2);
1037 (*env2)->DeleteLocalRef(jni_o->env, js2);
1038 }
1039
1040 void android_return_generic_int(int id, int i)
1041 {
1042 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1043 dbg(0,"+#+:enter\n");
1044 #endif
1045 //DBG // dbg(0,"Enter\n");
1046
1047 // int thread_id = gettid();
1048 // dbg(0, "THREAD ID=%d\n", thread_id);
1049
1050 JNIEnv *jnienv2;
1051 jnienv2 = jni_getenv();
1052
1053 if (NavitGraphicsClass2 == NULL)
1054 {
1055 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
1056 {
1057 NavitGraphicsClass2 = NULL;
1058 return;
1059 }
1060 }
1061 //DBG // dbg(0,"xx1\n");
1062 if (return_generic_int == NULL)
1063 {
1064 android_find_static_method(NavitGraphicsClass2, "return_generic_int", "(II)V", &return_generic_int);
1065 }
1066 //DBG // dbg(0,"xx2\n");
1067 if (return_generic_int == NULL)
1068 {
1069 //DBG // dbg(0, "no method found\n");
1070 return; /* exception thrown */
1071 }
1072 //DBG // dbg(0,"xa1\n");
1073 // -crash- (*jnienv2)->CallVoidMethod(jnienv2, NavitGraphicsClass2, return_generic_int, id, i);
1074 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, return_generic_int, id, i);
1075 // -works- (*jnienv2)->CallStaticObjectMethod(jnienv2, NavitGraphicsClass2, return_generic_int, id, i);
1076 //DBG // dbg(0,"xa2\n");
1077 }
1078
1079 JNIEXPORT void JNICALL
1080 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackSearchResultList(JNIEnv* env, jobject thiz, int id, int partial, jobject str, jobject str_town, jobject str_hn, int search_flags, jobject search_country, jobject latlon, int radius)
1081 {
1082 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1083 dbg(0,"+#+:enter\n");
1084 #endif
1085
1086 int thread_id = gettid();
1087 // dbg(0, "THREAD ID=%d\n", thread_id);
1088
1089 const char *s;
1090 s = (*env)->GetStringUTFChars(env, str, NULL);
1091 ////DBG // dbg(0,"*****string=%s\n",s);
1092
1093
1094 config_get_attr(config, attr_navit, &attr, NULL);
1095 // attr.u.navit
1096
1097 jstring js2 = NULL;
1098 jclass cls_local = (*env)->GetObjectClass(env, thiz);
1099
1100 // ICS ???
1101 jclass cls = (*env)->NewGlobalRef(env, cls_local);
1102 // ICS ???
1103
1104 jmethodID aMethodID = (*env)->GetMethodID(env, cls, "fillStringArray", "(Ljava/lang/String;)V");
1105 if (aMethodID == 0)
1106 {
1107 ////DBG // dbg(0,"**** Unable to get methodID: fillStringArray");
1108 return;
1109 }
1110
1111 if (id)
1112 {
1113 // search for town in variable "s" within current country -> return a list of towns as result
1114 if (id == 1)
1115 {
1116 // unused now!!
1117 }
1118 // new experimental street-index search
1119 else if (id == 2)
1120 {
1121 offline_search_break_searching = 0;
1122
1123 struct jni_object my_jni_object;
1124 my_jni_object.env = env;
1125 my_jni_object.jo = thiz;
1126 my_jni_object.jm = aMethodID;
1127
1128 const char *s_town;
1129 s_town = (*env)->GetStringUTFChars(env, str_town, NULL);
1130 const char *s_hn;
1131 s_hn = (*env)->GetStringUTFChars(env, str_hn, NULL);
1132
1133 search_v2(s, s_town, s_hn, partial, &my_jni_object);
1134
1135 (*env)->ReleaseStringUTFChars(env, str_town, s_town);
1136 (*env)->ReleaseStringUTFChars(env, str_hn, s_hn);
1137
1138 }
1139 // search for street in variable "s" within "search_country" -> return a list of streets as result
1140 else if (id == 29)
1141 {
1142 //struct attr s_attr4;
1143 //struct gui_priv *gp4;
1144 //struct gui_priv gp_24;
1145
1146 offline_search_break_searching = 0;
1147
1148 struct jni_object my_jni_object;
1149 my_jni_object.env = env;
1150 my_jni_object.jo = thiz;
1151 my_jni_object.jm = aMethodID;
1152
1153 //gp4=&gp_24;
1154 //gp4->nav=attr.u.navit;
1155 struct mapset *ms4 = navit_get_mapset(attr.u.navit);
1156 GList *ret = NULL;
1157 int flags = search_flags;
1158 char *search_country_string = (*env)->GetStringUTFChars(env, search_country, NULL);
1159 ret = search_by_address(ret, ms4, s, partial, &my_jni_object, flags, search_country_string);
1160 (*env)->ReleaseStringUTFChars(env, search_country, search_country_string);
1161
1162 // free the memory
1163 g_list_free(ret);
1164 ////DBG // dbg(0,"ret=%p\n",ret);
1165
1166
1167 //if (gp4->sl)
1168 //{
1169 // //search_list_destroy(gp4->sl);
1170 // gp4->sl=NULL;
1171 //}
1172 }
1173 // do a full search in all mapfiles for string in variable "s" -> return a list of streets as result
1174 else if (id == 3)
1175 {
1176 const char *s3;
1177 s3 = (*env)->GetStringUTFChars(env, latlon, NULL);
1178 char parse_str[strlen(s3) + 1];
1179 strcpy(parse_str, s3);
1180 (*env)->ReleaseStringUTFChars(env, latlon, s3);
1181
1182 struct coord_geo g7;
1183 char *p;
1184 char *stopstring;
1185
1186 // lat
1187 p = strtok(parse_str, "#");
1188 g7.lat = strtof(p, &stopstring);
1189 // lon
1190 p = strtok(NULL, "#");
1191 g7.lng = strtof(p, &stopstring);
1192
1193 struct jni_object my_jni_object;
1194 my_jni_object.env = env;
1195 my_jni_object.jo = thiz;
1196 my_jni_object.jm = aMethodID;
1197
1198 offline_search_break_searching = 0;
1199
1200 // search_flags --> is search_order (search at what "order" level)
1201 search_full_world(s, partial, search_flags, &my_jni_object, &g7, radius);
1202 }
1203 }
1204
1205 (*env)->ReleaseStringUTFChars(env, str, s);
1206 }
1207
1208 JNIEXPORT jint JNICALL
1209 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackDestinationValid(JNIEnv* env, jobject thiz)
1210 {
1211 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1212 dbg(0,"+#+:enter\n");
1213 #endif
1214 //DBG // dbg(0,"EEnter\n");
1215 config_get_attr(config, attr_navit, &attr, NULL);
1216 // //DBG // dbg(0,"destination_valid=%d\n",attr.u.navit->destination_valid);
1217 jint i = 0;
1218 if (attr.u.navit->route)
1219 {
1220 struct route *r;
1221 r = attr.u.navit->route;
1222 i = r->route_status;
1223 // //DBG // dbg(0,"route_status=%d\n",i);
1224 }
1225 return i;
1226 }
1227
1228 static void map_preview_label_line(struct point *p, int count, char *label, int font_size)
1229 {
1230 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1231 dbg(0,"+#+:enter\n");
1232 #endif
1233 int i, x, y, tl, tlm, th, thm, tlsq, l;
1234 float lsq;
1235 double dx, dy;
1236 struct point p_t;
1237 struct point pb[5];
1238
1239 int len = g_utf8_strlen(label, -1);
1240 int xMin = 0;
1241 int yMin = 0;
1242 int yMax = 13 * font_size / 256;
1243 int xMax = 9 * font_size * len / 256;
1244
1245 ////DBG // dbg(0,"xMax=%d\n", xMax);
1246 ////DBG // dbg(0,"yMax=%d\n", yMax);
1247
1248 pb[0].x = xMin;
1249 pb[0].y = -yMin;
1250 pb[1].x = xMin;
1251 pb[1].y = -yMax;
1252 pb[2].x = xMax;
1253 pb[2].y = -yMax;
1254 pb[3].x = xMax;
1255 pb[3].y = -yMin;
1256
1257 tl = (pb[2].x - pb[0].x);
1258 th = (pb[0].y - pb[1].y);
1259
1260 // calc "tl" text length
1261 // tl=strlen(label)*4;
1262 // calc "th" text height
1263 // th=8;
1264
1265 tlm = tl * 32;
1266 thm = th * 36;
1267 tlsq = (tlm * 0.7) * (tlm * 0.7);
1268
1269 for (i = 0; i < count - 1; i++)
1270 {
1271 dx = p[i + 1].x - p[i].x;
1272 dx *= 32;
1273 dy = p[i + 1].y - p[i].y;
1274 dy *= 32;
1275 lsq = dx * dx + dy * dy;
1276
1277 if (lsq > tlsq)
1278 {
1279 ////DBG // dbg(0,"-------- label=%s\n",label);
1280 ////DBG // dbg(0,"px i=%d py i=%d px i+1=%d py i+1=%d\n",p[i].x,p[i].y,p[i+1].x,p[i+1].y);
1281 ////DBG // dbg(0,"dx=%f dy=%f\n",dx,dy);
1282 l = (int) sqrtf(lsq);
1283 ////DBG // dbg(0,"l=%d lsq=%f\n",l,lsq);
1284 x = p[i].x;
1285 y = p[i].y;
1286 if (dx < 0)
1287 {
1288 dx = -dx;
1289 dy = -dy;
1290 x = p[i + 1].x;
1291 y = p[i + 1].y;
1292 }
1293 x += (l - tlm) * dx / l / 64;
1294 y += (l - tlm) * dy / l / 64;
1295 x -= dy * thm / l / 64;
1296 y += dx * thm / l / 64;
1297 p_t.x = x;
1298 p_t.y = y;
1299
1300 ////DBG // dbg(0,"dx=%f dy=%f\n",dx,dy);
1301 ////DBG // dbg(0,"dx=%d dy=%d\n",(int)dx,(int)dy);
1302 ////DBG // dbg(0,"draw px=%d py=%d\n",p_t.x,p_t.y);
1303 ////DBG // dbg(0,"l=%d\n",l);
1304 ////DBG // dbg(0,"+++++++++++++\n");
1305 // **OLD and wrong** android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, dx*0x10000/l, dy*0x10000/l);
1306 android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, (int) dx, (int) dy);
1307 }
1308 }
1309 }
1310
1311 JNIEXPORT void JNICALL
1312 Java_com_zoffcc_applications_zanavi_NavitMapPreviewActivity_DrawMapPreview(JNIEnv* env, jobject thiz, jobject latlonzoom, int width, int height, int font_size, int scale, int sel_range)
1313 {
1314 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1315 dbg(0,"+#+:enter\n");
1316 #endif
1317 // config_get_attr(config, attr_navit, &attr, NULL);
1318
1319 const char *s;
1320 int zoom;
1321 s = (*env)->GetStringUTFChars(env, latlonzoom, NULL);
1322 char parse_str[strlen(s) + 1];
1323 strcpy(parse_str, s);
1324 (*env)->ReleaseStringUTFChars(env, latlonzoom, s);
1325 ////DBG // dbg(0,"*****string=%s\n",s);
1326
1327 // show map preview for (lat#lon#zoom)
1328 struct coord_geo g;
1329 char *p;
1330 char *stopstring;
1331
1332 // lat
1333 p = strtok(parse_str, "#");
1334 g.lat = strtof(p, &stopstring);
1335 // lon
1336 p = strtok(NULL, "#");
1337 g.lng = strtof(p, &stopstring);
1338 // zoom
1339 p = strtok(NULL, "#");
1340 zoom = atoi(p);
1341
1342 ////DBG // dbg(0,"lat=%f\n",g.lat);
1343 ////DBG // dbg(0,"lng=%f\n",g.lng);
1344 ////DBG // dbg(0,"zoom=%d\n",zoom);
1345 ////DBG // dbg(0,"w=%d\n",width);
1346 ////DBG // dbg(0,"h=%d\n",height);
1347
1348 struct coord c;
1349 transform_from_geo(projection_mg, &g, &c);
1350
1351 // struct pcoord pc;
1352 // pc.x=c.x;
1353 // pc.y=c.y;
1354 // pc.pro=projection_mg;
1355
1356
1357 // ----------------------- big draw loop -----------------------
1358 // ----------------------- big draw loop -----------------------
1359 // ----------------------- big draw loop -----------------------
1360 // ----------------------- big draw loop -----------------------
1361 struct item *item;
1362 struct map_rect *mr = NULL;
1363 struct mapset *ms;
1364 struct mapset_handle *msh;
1365 struct map* map = NULL;
1366 struct attr map_name_attr;
1367 struct attr attr;
1368
1369 struct map_selection sel;
1370 const int selection_range = sel_range; // should be something with "width" and "height" i guess ??!!
1371
1372 const int max = 100;
1373 int count;
1374 struct coord *ca = g_alloca(sizeof(struct coord) * max);
1375 struct point *pa = g_alloca(sizeof(struct point) * max);
1376
1377 sel.next = NULL;
1378 sel.order = zoom;
1379 sel.range.min = type_none;
1380 sel.range.max = type_last;
1381 sel.u.c_rect.lu.x = c.x - selection_range;
1382 sel.u.c_rect.lu.y = c.y + selection_range;
1383 sel.u.c_rect.rl.x = c.x + selection_range;
1384 sel.u.c_rect.rl.y = c.y - selection_range;
1385
1386 struct transformation *tr;
1387 tr = transform_dup(global_navit->trans);
1388 struct point p_center;
1389 p_center.x = width / 2;
1390 p_center.y = height / 2;
1391 transform_set_screen_center(tr, &p_center);
1392 transform_set_center(tr, &c);
1393 transform_set_scale(tr, scale);
1394 enum projection pro = transform_get_projection(global_navit->trans_cursor);
1395
1396 ms = global_navit->mapsets->data;
1397 msh = mapset_open(ms);
1398 while (msh && (map = mapset_next(msh, 0)))
1399 {
1400 if (map_get_attr(map, attr_name, &map_name_attr, NULL))
1401 {
1402 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
1403 {
1404 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/borders.bin", map_name_attr.u.str, 41) == 0)
1405 {
1406 // country borders
1407 // //DBG // dbg(0,"map name=%s",map_name_attr.u.str);
1408 mr = map_rect_new(map, NULL);
1409 if (mr)
1410 {
1411 while ((item = map_rect_get_item(mr)))
1412 {
1413
1414 // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
1415 count = item_coord_get_within_selection(item, ca, max, &sel);
1416 if (!count)
1417 {
1418 continue;
1419 }
1420 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
1421
1422 // //DBG // dbg(0,"uu %s\n",item_to_name(item->type));
1423
1424 if (item->type == type_border_country)
1425 {
1426 // //DBG // dbg(0,"BB** %s\n",item_to_name(item->type));
1427 android_DrawMapPreview_polyline(pa, count, 2);
1428 }
1429 }
1430 map_rect_destroy(mr);
1431 }
1432 }
1433 else if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0)
1434 {
1435 // its an sdcard map
1436 // //DBG // dbg(0,"map name=%s",map_name_attr.u.str);
1437 mr = map_rect_new(map, &sel);
1438 if (mr)
1439 {
1440 //char *streetname_last=NULL;
1441
1442 while ((item = map_rect_get_item(mr)))
1443 {
1444 int label_count = 0;
1445 char *labels[2];
1446
1447 // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
1448 count = item_coord_get_within_selection(item, ca, max, &sel);
1449
1450 // count=item_coord_get_within_selection(item, ca, max, &sel);
1451 // count=item_coord_get(item, ca, item->type < type_line ? 1: max);
1452 if (!count)
1453 {
1454 continue;
1455 }
1456 ////DBG // dbg(0,"count 1=%d\n", count);
1457
1458 if (count == max)
1459 {
1460 ////DBG // dbg(0,"count overflow!!\n");
1461 }
1462
1463 struct attr attr_77;
1464 if (item_attr_get(item, attr_flags, &attr_77))
1465 {
1466 ////DBG // dbg(0,"uuuuuuuuuuuuu %s uuuuu %d\n",item_to_name(item->type), attr_77.u.num);
1467 item->flags = attr_77.u.num;
1468 }
1469 else
1470 {
1471 item->flags = 0;
1472 }
1473
1474 //if (item_is_street(*item))
1475 //{
1476 // int i3;
1477 // for (i3 = 0 ; i3 < count ; i3++)
1478 // {
1479 // if (i3)
1480 // {
1481 // //DBG // dbg(0,"1 x1=%d\n",ca[i3-1].x);
1482 // //DBG // dbg(0,"1 y1=%d\n",ca[i3-1].y);
1483 // //DBG // dbg(0,"1 x2=%d\n",ca[i3].x);
1484 // //DBG // dbg(0,"1 y2=%d\n",ca[i3].y);
1485 // }
1486 // }
1487 //}
1488
1489 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
1490
1491 ////DBG // dbg(0,"count 2=%d\n", count);
1492
1493 // --- LABEL ---
1494 labels[1] = NULL;
1495 label_count = 0;
1496 if (item_attr_get(item, attr_label, &attr))
1497 {
1498 labels[0] = attr.u.str;
1499 ////DBG // dbg(0,"labels[0]=%s\n",attr.u.str);
1500 if (!label_count)
1501 {
1502 label_count = 2;
1503 }
1504 }
1505 else
1506 {
1507 labels[0] = NULL;
1508 }
1509 // --- LABEL ---
1510
1511 if (item_is_street(*item))
1512 {
1513 //int i3;
1514 //for (i3 = 0 ; i3 < count ; i3++)
1515 //{
1516 // if (i3)
1517 // {
1518 // //DBG // dbg(0,"2 x1=%d\n",pa[i3-1].x);
1519 // //DBG // dbg(0,"2 y1=%d\n",pa[i3-1].y);
1520 // //DBG // dbg(0,"2 x2=%d\n",pa[i3].x);
1521 // //DBG // dbg(0,"2 y2=%d\n",pa[i3].y);
1522 // }
1523 //}
1524 android_DrawMapPreview_polyline(pa, count, 0);
1525 if (labels[0] != NULL)
1526 {
1527 map_preview_label_line(pa, count, labels[0], font_size);
1528 }
1529 }
1530 else if (item_is_district(*item))
1531 {
1532 if (zoom > 6)
1533 {
1534 // //DBG // dbg(0,"xx** %s - %s\n",item_to_name(item->type),labels[0]);
1535 if (count >= 1)
1536 {
1537 android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size * 2, 0x10000, 0);
1538 }
1539 }
1540 }
1541 else if (item_is_town(*item))
1542 {
1543 // //DBG // dbg(0,"yy** %s - %s\n",item_to_name(item->type),labels[0]);
1544 if (count >= 1)
1545 {
1546 android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size * 3, 0x10000, 0);
1547 }
1548 }
1549
1550 //if (item_is_street(*item))
1551 //{
1552 // if (item_attr_get(item, attr_label, &attr))
1553 // {
1554 // ////DBG // dbg(0,"street1=%s\n",map_convert_string(item->map, attr.u.str));
1555 // if ( (streetname_last==NULL) || (strcmp(streetname_last,attr.u.str) != 0) )
1556 // {
1557 // ////DBG // dbg(0,"street2=%s\n",map_convert_string(item->map, attr.u.str));
1558 // }
1559 // }
1560 //}
1561 }
1562 //g_free(streetname_last);
1563 map_rect_destroy(mr);
1564 }
1565 }
1566 }
1567 }
1568 }
1569 mapset_close(msh);
1570
1571 enum projection pro2 = transform_get_projection(global_navit->trans_cursor);
1572 struct point pnt;
1573 transform(tr, pro2, &c, &pnt, 1, 0, 0, NULL);
1574 transform_destroy(tr);
1575 // ----------------------- big draw loop -----------------------
1576 // ----------------------- big draw loop -----------------------
1577 // ----------------------- big draw loop -----------------------
1578 // ----------------------- big draw loop -----------------------
1579
1580 android_DrawMapPreview_target(pnt.x, pnt.y);
1581 }
1582
1583 void android_DrawMapPreview_target(int x, int y)
1584 {
1585 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1586 dbg(0,"+#+:enter\n");
1587 #endif
1588
1589 JNIEnv *jnienv2;
1590 jnienv2 = jni_getenv();
1591
1592 if (NavitMapPreviewActivityClass == NULL)
1593 {
1594 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1595 {
1596 NavitMapPreviewActivityClass = NULL;
1597 return;
1598 }
1599 }
1600 if (DrawMapPreview_target == NULL)
1601 {
1602 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_target", "(II)V", &DrawMapPreview_target);
1603 }
1604 if (DrawMapPreview_target == NULL)
1605 {
1606 //DBG // dbg(0, "no method found\n");
1607 return; /* exception thrown */
1608 }
1609 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_target, x, y);
1610 }
1611
1612 void android_DrawMapPreview_text(int x, int y, char *text, int size, int dx, int dy)
1613 {
1614 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1615 dbg(0,"+#+:enter\n");
1616 #endif
1617
1618 JNIEnv *jnienv2;
1619 jnienv2 = jni_getenv();
1620
1621 if (NavitMapPreviewActivityClass == NULL)
1622 {
1623 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1624 {
1625 NavitMapPreviewActivityClass = NULL;
1626 return;
1627 }
1628 }
1629 if (DrawMapPreview_text == NULL)
1630 {
1631 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_text", "(IILjava/lang/String;III)V", &DrawMapPreview_text);
1632 }
1633 if (DrawMapPreview_text == NULL)
1634 {
1635 //DBG // dbg(0, "no method found\n");
1636 return; /* exception thrown */
1637 }
1638
1639 ////DBG // dbg(0,"** dx=%d,dy=%d\n",dx,dy);
1640
1641 jstring string1 = (*jnienv2)->NewStringUTF(jnienv2, text);
1642 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_text, x, y, string1, size, dx, dy);
1643 (*jnienv2)->DeleteLocalRef(jnienv2, string1);
1644 }
1645
1646 void android_DrawMapPreview_polyline(struct point *p, int count, int type)
1647 {
1648 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1649 dbg(0,"+#+:enter\n");
1650 #endif
1651 // type:
1652 // 0 -> normal street
1653 // 2 -> country border
1654
1655 JNIEnv *jnienv2;
1656 jnienv2 = jni_getenv();
1657
1658 if (NavitMapPreviewActivityClass == NULL)
1659 {
1660 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1661 {
1662 NavitMapPreviewActivityClass = NULL;
1663 return;
1664 }
1665 }
1666 if (DrawMapPreview_polyline == NULL)
1667 {
1668 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_polyline", "(I[I)V", &DrawMapPreview_polyline);
1669 }
1670 if (DrawMapPreview_polyline == NULL)
1671 {
1672 //DBG // dbg(0, "no method found\n");
1673 return; /* exception thrown */
1674 }
1675
1676 jint pc[count * 2];
1677 int i;
1678 jintArray points;
1679 if (count <= 0)
1680 {
1681 return;
1682 }
1683 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
1684 for (i = 0; i < count; i++)
1685 {
1686 pc[i * 2] = p[i].x;
1687 pc[i * 2 + 1] = p[i].y;
1688 }
1689 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
1690 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_polyline, type, points);
1691 (*jnienv2)->DeleteLocalRef(jnienv2, points);
1692 }
1693
1694
1695 JNIEXPORT jobjectArray JNICALL
1696 Java_com_zoffcc_applications_zanavi_NavitGraphics_GetRoadBookItems(JNIEnv *env, jobject thiz, int result_id)
1697 {
1698 jobjectArray ret;
1699 int i;
1700 jclass *string_class = (*env)->FindClass(env, "java/lang/String");
1701
1702 // get roadbook
1703 GList *result = navit_route_export_to_java_string(global_navit, result_id);
1704
1705 if (result == NULL)
1706 {
1707 return NULL;
1708 }
1709
1710 ret = (jobjectArray)(*env)->NewObjectArray(env, g_list_length(result), string_class, (*env)->NewStringUTF(env, ""));
1711
1712 GList *result2 = result;
1713 i = 0;
1714 while (result2)
1715 {
1716 char *str = result2->data;
1717
1718 if (str != NULL)
1719 {
1720 (*env)->SetObjectArrayElement(env, ret, i, (*env)->NewStringUTF(env, str));
1721 g_free(str);
1722 }
1723 else
1724 {
1725 (*env)->SetObjectArrayElement(env, ret, i, (*env)->NewStringUTF(env, ""));
1726 }
1727 i++;
1728
1729 result2 = g_list_next(result2);
1730 }
1731
1732 g_list_free(result);
1733
1734 return(ret);
1735 }
1736
1737
1738
1739
1740
1741 JNIEXPORT jstring JNICALL
1742 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackGeoCalc(JNIEnv* env, jobject thiz, int i, float a, float b)
1743 {
1744 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1745 dbg(0,"+#+:enter\n");
1746 #endif
1747 // dbg(0,"EEnter i=%d\n", i);
1748
1749
1750 int thread_id = gettid();
1751 // dbg(0, "THREAD ID=%d\n", thread_id);
1752
1753 // const char *result;
1754 gchar *result = NULL;
1755
1756 #ifndef NAVIT_DEBUG_BAREMETAL
1757
1758 if (i == 1)
1759 {
1760 // pixel-on-screen to geo
1761 struct coord_geo g22;
1762 struct coord c22;
1763 struct point p;
1764 p.x = a;
1765 p.y = b;
1766 transform_reverse(global_navit->trans, &p, &c22);
1767 ////DBG // dbg(0,"%f, %f\n",a, b);
1768 ////DBG // dbg(0,"%d, %d\n",p.x, p.y);
1769 transform_to_geo(projection_mg, &c22, &g22);
1770 ////DBG // dbg(0,"%d, %d, %f, %f\n",c22.x, c22.y, g22.lat, g22.lng);
1771 result = g_strdup_printf("%f:%f", g22.lat, g22.lng);
1772 }
1773 else if (i == 2)
1774 {
1775 // geo to pixel-on-screen
1776 struct coord c99;
1777 struct coord_geo g99;
1778 g99.lat = a;
1779 g99.lng = b;
1780 ////DBG // dbg(0,"zzzzz %f, %f\n",a, b);
1781 ////DBG // dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1782 transform_from_geo(projection_mg, &g99, &c99);
1783 ////DBG // dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1784
1785 enum projection pro = transform_get_projection(global_navit->trans_cursor);
1786 struct point pnt;
1787 transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
1788 ////DBG // dbg(0,"x=%d\n",pnt.x);
1789 ////DBG // dbg(0,"y=%d\n",pnt.y);
1790
1791 result = g_strdup_printf("%d:%d", pnt.x, pnt.y);
1792 }
1793 else if (i == 3)
1794 {
1795 // show lat,lng position on screen center
1796 struct coord c99;
1797 struct pcoord pc99;
1798 struct coord_geo g99;
1799 g99.lat = a;
1800 g99.lng = b;
1801 ////DBG // dbg(0,"zzzzz %f, %f\n",a, b);
1802 ////DBG // dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1803 transform_from_geo(projection_mg, &g99, &c99);
1804 ////DBG // dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1805
1806 //enum projection pro=transform_get_projection(global_navit->trans_cursor);
1807 //struct point pnt;
1808 //transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
1809 ////DBG // dbg(0,"x=%d\n",pnt.x);
1810 ////DBG // dbg(0,"y=%d\n",pnt.y);
1811 pc99.x = c99.x;
1812 pc99.y = c99.y;
1813 pc99.pro = projection_mg;
1814
1815 navit_set_center(global_navit, &pc99, 0);
1816
1817 result = g_strdup("1:1");
1818 }
1819 else if (i == 4)
1820 {
1821 // return current target (the end point, not waypoints)
1822 struct coord_geo g22;
1823 struct pcoord c22;
1824 struct coord c99;
1825
1826 c22 = global_navit->destination;
1827 c99.x = c22.x;
1828 c99.y = c22.y;
1829
1830 transform_to_geo(projection_mg, &c99, &g22);
1831 result = g_strdup_printf("%f:%f", g22.lat, g22.lng);
1832 }
1833 else if (i == 5)
1834 {
1835 // input: x,y pixel on screen
1836 // output: streetname nearest that position
1837 struct coord c22;
1838 struct point p;
1839 struct pcoord c24;
1840 p.x = a;
1841 p.y = b;
1842 transform_reverse(global_navit->trans, &p, &c22);
1843 c24.x = c22.x;
1844 c24.y = c22.y;
1845 c24.pro = transform_get_projection(global_navit->trans);
1846 result = navit_find_nearest_street(global_navit->mapsets->data, &c24);
1847 }
1848 else if (i == 6)
1849 {
1850 // input: lat, lon
1851 // output: streetname nearest that position
1852 struct coord c22;
1853 struct point p;
1854 struct pcoord c24;
1855 struct coord_geo g99;
1856 g99.lat = a;
1857 g99.lng = b;
1858 transform_from_geo(projection_mg, &g99, &c22);
1859 c24.x = c22.x;
1860 c24.y = c22.y;
1861 c24.pro = transform_get_projection(global_navit->trans);
1862 result = navit_find_nearest_street(global_navit->mapsets->data, &c24);
1863 }
1864 else if (i == 7)
1865 {
1866 // input: x,y pixel on screen
1867 // output: 0xFFFF 0xFFFF\n... -> string that can be used for traffic distortion file
1868 struct coord c22;
1869 struct point p;
1870 struct pcoord c24;
1871 p.x = a;
1872 p.y = b;
1873 transform_reverse(global_navit->trans, &p, &c22);
1874 c24.x = c22.x;
1875 c24.y = c22.y;
1876 c24.pro = transform_get_projection(global_navit->trans);
1877 result = navit_find_nearest_street_coords(global_navit->mapsets->data, &c24);
1878 }
1879 else if (i == 8)
1880 {
1881 // input: x,y pixel on screen
1882 // output: nearest street or housenumber
1883 struct coord c22;
1884 struct point p;
1885 struct pcoord c24;
1886 p.x = a;
1887 p.y = b;
1888 transform_reverse(global_navit->trans, &p, &c22);
1889 c24.x = c22.x;
1890 c24.y = c22.y;
1891 c24.pro = transform_get_projection(global_navit->trans);
1892 result = navit_find_nearest_street_hn(global_navit->mapsets->data, &c24);
1893 }
1894 else if (i == 9)
1895 {
1896 // input: x,y pixel on screen
1897 // output: item dump of nearest item
1898 struct coord c22;
1899 struct point p;
1900 struct pcoord c24;
1901 p.x = a;
1902 p.y = b;
1903 transform_reverse(global_navit->trans, &p, &c22);
1904 c24.x = c22.x;
1905 c24.y = c22.y;
1906 c24.pro = transform_get_projection(global_navit->trans);
1907 result = navit_find_nearest_item_dump(global_navit->mapsets->data, &c24, 0);
1908 }
1909 else if (i == 10)
1910 {
1911 // input: x,y pixel on screen
1912 // output: item dump of nearest item (pretty output to show to user)
1913 struct coord c22;
1914 struct point p;
1915 struct pcoord c24;
1916 p.x = a;
1917 p.y = b;
1918 transform_reverse(global_navit->trans, &p, &c22);
1919 c24.x = c22.x;
1920 c24.y = c22.y;
1921 c24.pro = transform_get_projection(global_navit->trans);
1922 result = navit_find_nearest_item_dump(global_navit->mapsets->data, &c24, 1);
1923 }
1924 else if (i == 11)
1925 {
1926 // coord to pixel-on-screen
1927 struct coord c99;
1928 c99.x = a;
1929 c99.y = b;
1930 struct point pnt;
1931 transform(global_navit->trans, projection_mg, &c99, &pnt, 1, 0, 0, NULL);
1932 result = g_strdup_printf("%d:%d", pnt.x, pnt.y);
1933 }
1934 // else if (i == 13)
1935 // {
1936 // // get roadbook
1937 // result = navit_route_export_to_java_string(global_navit, NULL, (int)a);
1938 // }
1939 else if (i == 12)
1940 {
1941 // calculate next position in interpolation on route
1942 // return string: lat:lon:direction
1943 // example : 48.62:16.775:45.5
1944
1945 struct route *route2 = NULL;
1946 struct map *route_map2 = NULL;
1947 struct map_rect *mr2 = NULL;
1948 struct item *item2 = NULL;
1949 struct coord pos;
1950 struct coord *pos2;
1951 struct coord c;
1952 struct coord c2;
1953 struct coord ci;
1954 struct coord_geo g99;
1955 struct attr attr;
1956 // struct street_data *sd;
1957 int seg_speed;
1958 int seg_speed_old;
1959 int len;
1960 int slen;
1961 int dx;
1962 int dy;
1963 float dir;
1964 int interval = 1000; // milliseconds
1965 int speed = 50; // km/h
1966
1967
1968 if (global_demo_vehicle == 0)
1969 {
1970 route2 = navit_get_route(global_navit);
1971
1972 if (route2)
1973 {
1974 route_map2 = route_get_map(route2);
1975 }
1976
1977 if (route_map2)
1978 {
1979 mr2 = map_rect_new(route_map2, NULL);
1980 }
1981
1982 if (mr2)
1983 {
1984 item2 = map_rect_get_item(mr2);
1985 }
1986
1987 if (item2 && item2->type == type_route_start)
1988 {
1989 item2 = map_rect_get_item(mr2);
1990 }
1991
1992 if (item2 && item2->type == type_route_start_reverse)
1993 {
1994 item2 = map_rect_get_item(mr2);
1995 }
1996
1997 if (item2 && item_coord_get(item2, &pos, 1))
1998 {
1999 pos2 = tracking_get_pos(global_navit->tracking);
2000 pos.x = pos2->x;
2001 pos.y = pos2->y;
2002
2003 dbg(0,"extrapl:002 posx=%d posy=%d itemtype=%s\n", pos.x, pos.y, item_to_name(item2->type));
2004
2005 seg_speed = speed;
2006 // item_dump_attr_stdout(item2, route_map2);
2007 if (item_attr_get(item2, attr_maxspeed, &attr))
2008 {
2009 dbg(0, "extrapl:002.2 max speed=%d\n", attr.u.num);
2010 seg_speed = attr.u.num;
2011 }
2012 seg_speed_old = seg_speed;
2013
2014 len = (seg_speed * interval / 1000) / 3.6; // distance in meters that we drive in 1 second with "seg_speed" km/h !!
2015
2016 while (item2)
2017 {
2018 if (!item_coord_get(item2, &c, 1))
2019 {
2020 item2 = map_rect_get_item(mr2);
2021
2022 if (item2)
2023 {
2024 dbg(0,"extrapl:004 item type=%s\n", item_to_name(item2->type));
2025
2026 // item_dump_attr_stdout(item2, route_map2);
2027 if (item_attr_get(item2, attr_maxspeed, &attr))
2028 {
2029 dbg(0, "extrapl:004.2 max speed=%d\n", attr.u.num);
2030 seg_speed = attr.u.num;
2031 }
2032 }
2033 continue;
2034 }
2035
2036 slen = transform_distance(projection_mg, &pos, &c); // distance between position and current route coord
2037 dbg(0,"extrapl:004.1 slen=%d len=%d\n", slen, len);
2038
2039 if (slen < len) // need to move along the route some more ...
2040 {
2041 len = len - slen;
2042 dbg(0,"extrapl:005 cx=%d cy=%d len=%d\n", c.x, c.y, len);
2043 // now compensate "len" for maybe other speed on next item
2044 if (seg_speed != seg_speed_old)
2045 {
2046 if ((len > 0) && (seg_speed_old > 0)&&(seg_speed > 0))
2047 {
2048 len = (int)((float)len / (float)seg_speed_old * (float)seg_speed);
2049 dbg(0,"extrapl:005.1 len comp.=%d speed=%d speed old=%d\n", len, seg_speed, seg_speed_old);
2050 }
2051 seg_speed_old = seg_speed;
2052 }
2053
2054 pos = c;
2055 }
2056 else
2057 {
2058 if (item_coord_get(item2, &c2, 1) || map_rect_get_item(mr2))
2059 {
2060 dbg(0,"extrapl:006 c2x=%d c2y=%d\n", c2.x, c2.y);
2061 dbg(0,"extrapl:006 cx=%d cy=%d\n", c.x, c.y);
2062
2063 dx = c.x - pos.x;
2064 dy = c.y - pos.y;
2065 ci.x = pos.x + dx * len / slen;
2066 ci.y = pos.y + dy * len / slen;
2067
2068 dbg(0,"extrapl:006 cix=%d ciy=%d\n", ci.x, ci.y);
2069
2070 dir = (float)transform_get_angle_delta(&pos, &c, 0);
2071 }
2072 else
2073 {
2074 ci.x = pos.x;
2075 ci.y = pos.y;
2076 dir = 0.0f;
2077 dbg(0, "extrapl:destination reached\n");
2078 }
2079
2080 transform_to_geo(projection_mg, &ci, &g99);
2081 dbg(0,"extrapl:099=%f:%f:%f\n", g99.lat, g99.lng, dir);
2082 result = g_strdup_printf("%f:%f:%f", g99.lat, g99.lng, dir);
2083
2084 break;
2085 }
2086 }
2087 }
2088 else
2089 {
2090 result = g_strdup("*ERROR*");
2091 }
2092
2093 if (mr2)
2094 {
2095 map_rect_destroy(mr2);
2096 }
2097 }
2098 else
2099 {
2100 result = g_strdup("*ERROR*");
2101 }
2102 }
2103 else if (i == 14)
2104 {
2105 // return current position
2106 // dbg(0, "PPPOS:2:%f %f", ggggg_lat, ggggg_lon);
2107 result = g_strdup_printf("%f:%f", (float)ggggg_lat, (float)ggggg_lon);
2108 }
2109 else if (i == 15)
2110 {
2111 // show lat,lng position on screen center, without map redraw!
2112 struct coord c99;
2113 struct pcoord pc99;
2114 struct coord_geo g99;
2115 g99.lat = a;
2116 g99.lng = b;
2117 ////DBG // dbg(0,"zzzzz %f, %f\n",a, b);
2118 ////DBG // dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
2119 transform_from_geo(projection_mg, &g99, &c99);
2120 ////DBG // dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
2121
2122 //enum projection pro=transform_get_projection(global_navit->trans_cursor);
2123 //struct point pnt;
2124 //transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
2125 ////DBG // dbg(0,"x=%d\n",pnt.x);
2126 ////DBG // dbg(0,"y=%d\n",pnt.y);
2127 pc99.x = c99.x;
2128 pc99.y = c99.y;
2129 pc99.pro = projection_mg;
2130
2131 navit_set_center_no_draw(global_navit, &pc99, 0);
2132
2133 result = g_strdup("1:1");
2134 }
2135
2136
2137
2138 #else
2139 result = g_strdup("*ERROR*");
2140 #endif
2141
2142 // // dbg(0, "result=%s\n", result);
2143 jstring js = (*env)->NewStringUTF(env, result);
2144
2145 if (result)
2146 {
2147 g_free(result);
2148 }
2149
2150 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2151 dbg(0,"+#+:leave\n");
2152 #endif
2153
2154 return js;
2155 }
2156
2157 JNIEXPORT jstring JNICALL
2158 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackLocalizedString(JNIEnv* env, jobject thiz, jobject str)
2159 {
2160 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2161 dbg(0,"+#+:enter\n");
2162 #endif
2163 // // dbg(0,"EEnter\n");
2164
2165 int thread_id = gettid();
2166 // dbg(0, "THREAD ID=%d\n", thread_id);
2167
2168 const char *s;
2169 const char *localized_str;
2170
2171 s = (*env)->GetStringUTFChars(env, str, NULL);
2172 ////DBG // dbg(0,"*****string=%s\n",s);
2173
2174 localized_str = gettext(s);
2175 ////DBG // dbg(0,"localized string=%s",localized_str);
2176
2177 // jstring dataStringValue = (jstring) localized_str;
2178 jstring js = (*env)->NewStringUTF(env, localized_str);
2179
2180 (*env)->ReleaseStringUTFChars(env, str, s);
2181
2182 return js;
2183 }
2184
2185 JNIEXPORT jint JNICALL
2186 Java_com_zoffcc_applications_zanavi_NavitGraphics_GetThreadId(JNIEnv* env, jobject thiz)
2187 {
2188 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2189 dbg(0,"+#+:enter\n");
2190 #endif
2191
2192 int thread_id = gettid();
2193 // // dbg(0, "THREAD ID=%d\n", thread_id);
2194
2195 jint i = thread_id;
2196 return i;
2197 }
2198
2199 JNIEXPORT void JNICALL
2200 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackMessageChannelReal(JNIEnv* env, jobject thiz, int i, jobject str2)
2201 {
2202 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2203 dbg(0,"+#+:enter\n");
2204 #endif
2205
2206 __F_START__
2207
2208 int thread_id = gettid();
2209 // dbg(0, "THREAD ID=%d\n", thread_id);
2210
2211 #ifndef NAVIT_DEBUG_BAREMETAL
2212
2213 const char *s;
2214 jobject str = (*env)->NewGlobalRef(env, str2);
2215
2216 config_get_attr(config, attr_navit, &attr, NULL);
2217 // attr.u.navit
2218
2219 //DBG // dbg(0,"c1\n");
2220
2221
2222 if (i)
2223 {
2224 if (i == 1)
2225 {
2226 // zoom in
2227 navit_zoom_in_cursor(global_navit, 2);
2228 // navit_zoom_in_cursor(attr.u.navit, 2);
2229 }
2230 else if (i == 2)
2231 {
2232 // zoom out
2233 navit_zoom_out_cursor(global_navit, 2);
2234 // navit_zoom_out_cursor(attr.u.navit, 2);
2235 }
2236 else if (i == 111)
2237 {
2238 // show real gps position on map
2239 s = (*env)->GetStringUTFChars(env, str, NULL);
2240 global_tracking_show_real_gps_pos = atoi(s);
2241 // dbg(0, "show_real_gps_pos=%d\n", global_tracking_show_real_gps_pos);
2242 (*env)->ReleaseStringUTFChars(env, str, s);
2243 }
2244 else if (i == 110)
2245 {
2246 // generic int option CallBack [<option name>:<option value "int">]
2247 s = (*env)->GetStringUTFChars(env, str, NULL);
2248
2249 char *str_copy = strdup(s);
2250 char *option_name = NULL;
2251 char *option_value = NULL;
2252
2253 option_name = strsep(&str_copy, ":");
2254 option_value = strsep(&str_copy, ":");
2255
2256 // dbg(0, "a=%s b=%s\n", option_name, option_value);
2257
2258 /*
2259 street_0,living_street" speed="20" route_weight="20" route_prio_weight="30">
2260 street_1_city" speed="35" route_weight="35" route_prio_weight="30">
2261 track_paved" speed="35" route_weight="35" route_prio_weight="30">
2262 street_2_city,ramp_street_2_city" speed="50" route_weight="50" route_prio_weight="30">
2263 street_3_city,ramp_street_3_city" speed="50" route_weight="50" route_prio_weight="20">
2264 ramp_street_4_city" speed="49" route_weight="49" route_prio_weight="12">
2265 street_4_city" speed="50" route_weight="50" route_prio_weight="11">
2266 highway_city" speed="80" route_weight="80" route_prio_weight="9">
2267 street_1_land" speed="35" route_weight="35" route_prio_weight="30">
2268 street_2_land" speed="50" route_weight="50" route_prio_weight="11">
2269 street_3_land" speed="50" route_weight="50" route_prio_weight="11">
2270 street_4_land" speed="80" route_weight="80" route_prio_weight="11">
2271 street_n_lanes" speed="120" route_weight="120" route_prio_weight="9">
2272 ramp_highway_land" speed="119" route_weight="119" route_prio_weight="10">
2273 highway_land" speed="120" route_weight="120" route_prio_weight="9">
2274 */
2275
2276 struct roadprofile *roadprofile = NULL;
2277 int value_ = 0;
2278
2279 if (strcmp(option_name, "street_1_city#route_prio_weight") == 0)
2280 {
2281 roadprofile = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_street_1_city);
2282 if (roadprofile)
2283 {
2284 value_ = roadprofile->route_prio_weight;
2285 dbg(0, "VPR:old=%d\n", value_);
2286 roadprofile->route_prio_weight = atoi(option_value);
2287 dbg(0, "VPR:new=%d\n", roadprofile->route_prio_weight);
2288 vehicleprofile_change_roadprofile_attr(global_navit->vehicleprofile, roadprofile, type_street_1_city, roadprofile->route_prio_weight);
2289 }
2290
2291
2292 roadprofile = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_street_1_city);
2293 if (roadprofile)
2294 {
2295 value_ = roadprofile->route_prio_weight;
2296 dbg(0, "VPR:new2=%d\n", value_);
2297 }
2298 }
2299
2300 // global_level2_announcement = atoi(option_value);
2301
2302 g_free(str_copy);
2303
2304 (*env)->ReleaseStringUTFChars(env, str, s);
2305 }
2306 else if (i == 109)
2307 {
2308 // level 2 announcement seconds
2309 s = (*env)->GetStringUTFChars(env, str, NULL);
2310 global_level2_announcement = (float)atoi(s) / 10.0f;
2311 (*env)->ReleaseStringUTFChars(env, str, s);
2312 }
2313 else if (i == 108)
2314 {
2315 // level 1 announcement seconds
2316 s = (*env)->GetStringUTFChars(env, str, NULL);
2317 global_level1_announcement = (float)atoi(s) / 10.0f;
2318 (*env)->ReleaseStringUTFChars(env, str, s);
2319 }
2320 else if (i == 107)
2321 {
2322 // level 0 announcement seconds
2323 s = (*env)->GetStringUTFChars(env, str, NULL);
2324 global_level0_announcement = (float)atoi(s) / 10.0f;
2325 (*env)->ReleaseStringUTFChars(env, str, s);
2326 }
2327 else if (i == 106)
2328 {
2329 // factor for routing/road speed
2330 s = (*env)->GetStringUTFChars(env, str, NULL);
2331 global_road_speed_factor = (float)atoi(s) / 100.0f;
2332 (*env)->ReleaseStringUTFChars(env, str, s);
2333 }
2334 else if (i == 105)
2335 {
2336 // zoom to specific zoomlevel without redrawing the map!
2337 s = (*env)->GetStringUTFChars(env, str, NULL);
2338 int zoom_level = atoi(s);
2339 navit_zoom_to_scale_no_draw(global_navit, zoom_level);
2340 (*env)->ReleaseStringUTFChars(env, str, s);
2341 }
2342 else if (i == 104)
2343 {
2344 // send OVERSPILL_FACTOR to C-code
2345 s = (*env)->GetStringUTFChars(env, str, NULL);
2346 int value = atoi(s);
2347
2348 global_overspill_factor = (float)((float)value / 100.0f);
2349
2350 (*env)->ReleaseStringUTFChars(env, str, s);
2351 }
2352 else if (i == 103)
2353 {
2354 // draw location of self (car) x% lower than screen center
2355 s = (*env)->GetStringUTFChars(env, str, NULL);
2356 int value = atoi(s);
2357
2358 global_navit->radius = value;
2359
2360 (*env)->ReleaseStringUTFChars(env, str, s);
2361 }
2362 else if (i == 102)
2363 {
2364 // set gpsfix flag
2365 s = (*env)->GetStringUTFChars(env, str, NULL);
2366 int value = atoi(s);
2367
2368 global_has_gpsfix = value;
2369
2370 (*env)->ReleaseStringUTFChars(env, str, s);
2371 }
2372 else if (i == 101)
2373 {
2374 // set demo vehicle flag for tracking
2375 dbg(0, "DEMO VEHICLE* flag set\n");
2376 global_demo_vehicle_short_switch = 1;
2377 }
2378 else if (i == 100)
2379 {
2380 // dump callbacks to log
2381 callback_dump_callbacks();
2382 }
2383 else if (i == 99)
2384 {
2385 // set angle_pref value
2386 if (global_navit->tracking)
2387 {
2388 s = (*env)->GetStringUTFChars(env, str, NULL);
2389 int value = atoi(s);
2390
2391 struct attr attr99;
2392 attr99.type = attr_angle_pref;
2393 attr99.u.num = value;
2394
2395 tracking_set_attr(global_navit->tracking, &attr99);
2396
2397 (*env)->ReleaseStringUTFChars(env, str, s);
2398 }
2399 }
2400 else if (i == 98)
2401 {
2402 // set connected_pref value
2403 if (global_navit->tracking)
2404 {
2405 s = (*env)->GetStringUTFChars(env, str, NULL);
2406 int value = atoi(s);
2407
2408 struct attr attr99;
2409 attr99.type = attr_connected_pref;
2410 attr99.u.num = value;
2411
2412 tracking_set_attr(global_navit->tracking, &attr99);
2413
2414 (*env)->ReleaseStringUTFChars(env, str, s);
2415 }
2416 }
2417 else if (i == 97)
2418 {
2419 // set position to (lat#lon#name)
2420 char *name;
2421 s = (*env)->GetStringUTFChars(env, str, NULL);
2422 char parse_str[strlen(s) + 1];
2423 strcpy(parse_str, s);
2424 (*env)->ReleaseStringUTFChars(env, str, s);
2425
2426 struct coord_geo g;
2427 char *p;
2428 char *stopstring;
2429
2430 // lat
2431 p = strtok(parse_str, "#");
2432 g.lat = strtof(p, &stopstring);
2433 // lon
2434 p = strtok(NULL, "#");
2435 g.lng = strtof(p, &stopstring);
2436 // description
2437 name = strtok(NULL, "#");
2438
2439 ////DBG // dbg(0,"lat=%f\n",g.lat);
2440 ////DBG // dbg(0,"lng=%f\n",g.lng);
2441 ////DBG // dbg(0,"str1=%s\n",name);
2442
2443 struct coord c;
2444 transform_from_geo(projection_mg, &g, &c);
2445
2446 struct pcoord pc;
2447 pc.x = c.x;
2448 pc.y = c.y;
2449 pc.pro = projection_mg;
2450
2451 // set position
2452 navit_set_position(global_navit, &pc);
2453 }
2454 else if (i == 96)
2455 {
2456 // dump route to GPX file
2457 s = (*env)->GetStringUTFChars(env, str, NULL);
2458 if (global_navit->route)
2459 {
2460 if (global_navit->route->destinations)
2461 {
2462 navit_route_export_gpx_to_file(global_navit, s);
2463 }
2464 }
2465 (*env)->ReleaseStringUTFChars(env, str, s);
2466 }
2467 else if (i == 95)
2468 {
2469 // change priority for cycle tracks
2470 if (global_vehicle_profile == 1)
2471 {
2472 int old_value = global_cycle_track_prio;
2473 s = (*env)->GetStringUTFChars(env, str, NULL);
2474 global_cycle_track_prio = atoi(s);
2475
2476 if (old_value != atoi(s))
2477 {
2478 if (global_navit->route)
2479 {
2480 if (global_navit->route->destinations)
2481 {
2482 route_path_update(global_navit->route, 1, 1);
2483 }
2484 }
2485 }
2486
2487 (*env)->ReleaseStringUTFChars(env, str, s);
2488 }
2489 }
2490 else if (i == 94)
2491 {
2492 // change priority for cycle lanes
2493 if (global_vehicle_profile == 1)
2494 {
2495 int old_value = global_cycle_lanes_prio;
2496 s = (*env)->GetStringUTFChars(env, str, NULL);
2497 global_cycle_lanes_prio = atoi(s);
2498
2499 if (old_value != atoi(s))
2500 {
2501 if (global_navit->route)
2502 {
2503 if (global_navit->route->destinations)
2504 {
2505 route_path_update(global_navit->route, 1, 1);
2506 }
2507 }
2508 }
2509
2510 (*env)->ReleaseStringUTFChars(env, str, s);
2511 }
2512 }
2513 else if (i == 93)
2514 {
2515 // change vehicle profile's roadprofile values 003
2516
2517 if (global_vehicle_profile == 1)
2518 {
2519
2520 int old_value = 0;
2521 s = (*env)->GetStringUTFChars(env, str, NULL);
2522
2523 struct roadprofile *rp = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_street_3_land);
2524
2525 if (rp)
2526 {
2527 old_value = rp->route_prio_weight;
2528 }
2529
2530 if (rp)
2531 {
2532 rp->route_prio_weight = atoi(s);
2533 }
2534
2535 rp = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_street_4_land);
2536 if (rp)
2537 {
2538 rp->route_prio_weight = atoi(s);
2539 }
2540
2541 // calc route new!
2542 if (rp)
2543 {
2544 if (old_value != atoi(s))
2545 {
2546 if (global_navit->route)
2547 {
2548 if (global_navit->route->destinations)
2549 {
2550 route_path_update(global_navit->route, 1, 1);
2551 }
2552 }
2553 }
2554 }
2555
2556 (*env)->ReleaseStringUTFChars(env, str, s);
2557 }
2558
2559 }
2560 else if (i == 92)
2561 {
2562 // change vehicle profile's roadprofile values 002
2563
2564 if (global_vehicle_profile == 1)
2565 {
2566
2567 int old_value = 0;
2568 s = (*env)->GetStringUTFChars(env, str, NULL);
2569
2570 struct roadprofile *rp = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_street_3_city);
2571
2572 if (rp)
2573 {
2574 old_value = rp->route_prio_weight;
2575 }
2576
2577 if (rp)
2578 {
2579 rp->route_prio_weight = atoi(s);
2580 }
2581
2582 rp = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_street_4_city);
2583 if (rp)
2584 {
2585 rp->route_prio_weight = atoi(s);
2586 }
2587
2588 //rp = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_ramp);
2589 //if (rp)
2590 //{
2591 // rp->route_prio_weight = atoi(s);
2592 //}
2593
2594 // calc route new!
2595 if (rp)
2596 {
2597 if (old_value != atoi(s))
2598 {
2599 if (global_navit->route)
2600 {
2601 if (global_navit->route->destinations)
2602 {
2603 route_path_update(global_navit->route, 1, 1);
2604 }
2605 }
2606 }
2607 }
2608
2609 (*env)->ReleaseStringUTFChars(env, str, s);
2610 }
2611
2612 }
2613 else if (i == 91)
2614 {
2615 // change vehicle profile's roadprofile values 001
2616
2617 if (global_vehicle_profile == 1)
2618 {
2619
2620 int old_value = 0;
2621 s = (*env)->GetStringUTFChars(env, str, NULL);
2622
2623 struct roadprofile *rp = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_street_2_city);
2624
2625 if (rp)
2626 {
2627 old_value = rp->route_prio_weight;
2628 }
2629
2630 if (rp)
2631 {
2632 rp->route_prio_weight = atoi(s);
2633 }
2634
2635 rp = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_street_1_land);
2636 if (rp)
2637 {
2638 rp->route_prio_weight = atoi(s);
2639 }
2640
2641 rp = vehicleprofile_get_roadprofile(global_navit->vehicleprofile, type_street_2_land);
2642 if (rp)
2643 {
2644 rp->route_prio_weight = atoi(s);
2645 }
2646
2647 // calc route new!
2648 if (rp)
2649 {
2650 if (old_value != atoi(s))
2651 {
2652 if (global_navit->route)
2653 {
2654 if (global_navit->route->destinations)
2655 {
2656 route_path_update(global_navit->route, 1, 1);
2657 }
2658 }
2659 }
2660 }
2661
2662 (*env)->ReleaseStringUTFChars(env, str, s);
2663
2664 // <roadprofile item_types="street_0,street_1_city,living_street" speed="20" route_weight="20" route_prio_weight="2">
2665 // <roadprofile item_types="street_2_city,street_1_land,street_2_land" speed="15" route_weight="15" route_prio_weight="90">
2666
2667 }
2668
2669 }
2670 else if (i == 90)
2671 {
2672 // set vehicleprofile to value of string s ('car','bike')
2673 s = (*env)->GetStringUTFChars(env, str, NULL);
2674 if (!navit_set_vehicleprofile(global_navit, s))
2675 {
2676 }
2677 else
2678 {
2679 if (!strcmp(s, "car"))
2680 {
2681 global_vehicle_profile = 0; // car
2682
2683 if (global_enhance_cycleway == 1)
2684 {
2685 navit_reset_cycleway(global_navit);
2686 }
2687 }
2688 else if (!strcmp(s, "bike-normal"))
2689 {
2690 global_vehicle_profile = 1; // bicycle
2691
2692 if (global_enhance_cycleway == 0)
2693 {
2694 navit_enhance_cycleway(global_navit);
2695 }
2696 }
2697 else if (!strcmp(s, "bike-avoid-roads"))
2698 {
2699 global_vehicle_profile = 1; // bicycle
2700
2701 if (global_enhance_cycleway == 0)
2702 {
2703 navit_enhance_cycleway(global_navit);
2704 }
2705 }
2706 else if (!strcmp(s, "bike-no-oneway"))
2707 {
2708 global_vehicle_profile = 2; // bicycle no one-way!
2709
2710 if (global_enhance_cycleway == 0)
2711 {
2712 navit_enhance_cycleway(global_navit);
2713 }
2714 }
2715 else
2716 {
2717 global_vehicle_profile = 0; // car
2718
2719 if (global_enhance_cycleway == 1)
2720 {
2721 navit_reset_cycleway(global_navit);
2722 }
2723 }
2724 // dbg(0, "global_vehicle_profile=%d\n", global_vehicle_profile);
2725 }
2726 (*env)->ReleaseStringUTFChars(env, str, s);
2727 }
2728 else if (i == 89)
2729 {
2730 // search this far around street-coord to find potential housenumbers for this street
2731 s = (*env)->GetStringUTFChars(env, str, NULL);
2732 global_search_radius_for_housenumbers = atoi(s);
2733 (*env)->ReleaseStringUTFChars(env, str, s);
2734 }
2735 else if (i == 88)
2736 {
2737 // avoid sharp turns penalty
2738 s = (*env)->GetStringUTFChars(env, str, NULL);
2739 global_avoid_sharp_turns_min_penalty = atoi(s);
2740 (*env)->ReleaseStringUTFChars(env, str, s);
2741 }
2742 else if (i == 87)
2743 {
2744 // avoid sharp turns minimum angle. if turn is harder than this angle then set penalty
2745 s = (*env)->GetStringUTFChars(env, str, NULL);
2746 global_avoid_sharp_turns_min_angle = atoi(s);
2747 (*env)->ReleaseStringUTFChars(env, str, s);
2748 }
2749 else if (i == 86)
2750 {
2751 // avoid sharp turns flag to 0 or 1
2752 s = (*env)->GetStringUTFChars(env, str, NULL);
2753 global_avoid_sharp_turns_flag = atoi(s);
2754 (*env)->ReleaseStringUTFChars(env, str, s);
2755 }
2756 else if (i == 85)
2757 {
2758 // C-linedrawing flag to 0 or 1
2759 s = (*env)->GetStringUTFChars(env, str, NULL);
2760 global_clinedrawing_active = atoi(s);
2761 (*env)->ReleaseStringUTFChars(env, str, s);
2762 }
2763 else if (i == 84)
2764 {
2765 // report data dir
2766 s = (*env)->GetStringUTFChars(env, str, NULL);
2767 navit_data_dir = g_strdup(s);
2768 (*env)->ReleaseStringUTFChars(env, str, s);
2769 }
2770 else if (i == 83)
2771 {
2772 // spill all the index files to log output
2773 spill_index();
2774 }
2775 else if (i == 82)
2776 {
2777 // report share dir
2778 s = (*env)->GetStringUTFChars(env, str, NULL);
2779 navit_share_dir = g_strdup(s);
2780 (*env)->ReleaseStringUTFChars(env, str, s);
2781 }
2782 else if (i == 81)
2783 {
2784 // resize layout items by factor
2785 s = (*env)->GetStringUTFChars(env, str, NULL);
2786 displaylist_shift_for_dpi_value_in_layers(global_navit, (double)(atof(s)));
2787 (*env)->ReleaseStringUTFChars(env, str, s);
2788 }
2789 else if (i == 80)
2790 {
2791 // autozoom flag to 0 or 1
2792 s = (*env)->GetStringUTFChars(env, str, NULL);
2793 global_navit->autozoom_active = atoi(s);
2794 (*env)->ReleaseStringUTFChars(env, str, s);
2795 }
2796 else if (i == 79)
2797 {
2798 // set traffic light delay
2799 s = (*env)->GetStringUTFChars(env, str, NULL);
2800 global_traffic_light_delay = atoi(s);
2801 (*env)->ReleaseStringUTFChars(env, str, s);
2802 }
2803 else if (i == 78)
2804 {
2805 // shift layout "order" values
2806 s = (*env)->GetStringUTFChars(env, str, NULL);
2807 displaylist_shift_order_in_map_layers(global_navit, atoi(s));
2808 (*env)->ReleaseStringUTFChars(env, str, s);
2809 }
2810 else if (i == 77)
2811 {
2812 // do not show route rectangles
2813 global_show_route_rectangles = 0;
2814 }
2815 else if (i == 76)
2816 {
2817 // show route rectangles
2818 global_show_route_rectangles = 1;
2819 }
2820 else if (i == 75)
2821 {
2822 // stop demo vechile
2823 global_stop_demo_vehicle = 1;
2824 }
2825 else if (i == 74)
2826 {
2827 // allow demo vechile to move
2828 global_stop_demo_vehicle = 0;
2829 }
2830 else if (i == 73)
2831 {
2832 // update the route path and route graph (e.g. after setting new roadblocks)
2833 // this destroys the route graph and calcs everything totally new!
2834 if (global_navit->route)
2835 {
2836 if (global_navit->route->destinations)
2837 {
2838 route_path_update(global_navit->route, 1, 1);
2839 }
2840 }
2841 }
2842 else if (i == 72)
2843 {
2844 // update the route path and route graph (e.g. after setting new roadblocks)
2845 // does not update destinations!!!
2846 if (global_navit->route)
2847 {
2848 if (global_navit->route->destinations)
2849 {
2850 route_path_update(global_navit->route, 0, 1);
2851 }
2852 }
2853 }
2854 else if (i == 71)
2855 {
2856 // activate/deactivate "route graph" display
2857 // 0 -> deactivate
2858 // 1 -> activate
2859
2860 // _ms_route_graph
2861 // _ms_navigation
2862 s = (*env)->GetStringUTFChars(env, str, NULL);
2863 navit_map_active_flag(global_navit, atoi(s), "_ms_route_graph");
2864 navit_map_active_flag(global_navit, atoi(s), "_ms_navigation");
2865 (*env)->ReleaseStringUTFChars(env, str, s);
2866 }
2867 else if (i == 70)
2868 {
2869 // allow drawing map
2870 hold_drawing = 0;
2871 }
2872 else if (i == 69)
2873 {
2874 // stop drawing map
2875 hold_drawing = 1;
2876 }
2877 else if (i == 68)
2878 {
2879 // shift "order" by this value (only for drawing objects)
2880 s = (*env)->GetStringUTFChars(env, str, NULL);
2881 shift_order = atoi(s);
2882 (*env)->ReleaseStringUTFChars(env, str, s);
2883 }
2884 else if (i == 67)
2885 {
2886 // disable "multipolygons"
2887 global_draw_multipolygons = 0;
2888 }
2889 else if (i == 66)
2890 {
2891 // enable "multipolygons"
2892 global_draw_multipolygons = 1;
2893 }
2894 else if (i == 65)
2895 {
2896 // draw map async
2897 navit_draw_async(global_navit, 1);
2898 }
2899 else if (i == 64)
2900 {
2901 // draw map
2902 navit_draw(global_navit);
2903 }
2904 else if (i == 63)
2905 {
2906 // enable map drawing
2907 disable_map_drawing = 0;
2908 }
2909 else if (i == 62)
2910 {
2911 // disable map drawing
2912 disable_map_drawing = 1;
2913 }
2914 else if (i == 61)
2915 {
2916 // zoom to specific zoomlevel at given point as center
2917 struct point p;
2918 char *pstr;
2919
2920 s = (*env)->GetStringUTFChars(env, str, NULL);
2921 char parse_str[strlen(s) + 1];
2922 strcpy(parse_str, s);
2923 (*env)->ReleaseStringUTFChars(env, str, s);
2924 // (pixel-x#pixel-y#zoom-level)
2925 // pixel-x
2926 pstr = strtok(parse_str, "#");
2927 p.x = atoi(pstr);
2928 // pixel-y
2929 pstr = strtok(NULL, "#");
2930 p.y = atoi(pstr);
2931 // zoom
2932 pstr = strtok(NULL, "#");
2933 int zoom_level = atoi(pstr);
2934 // now call zoom function
2935 navit_zoom_to_scale_with_center_point(global_navit, zoom_level, &p);
2936 }
2937 else if (i == 60)
2938 {
2939 // disable layer "name"
2940 s = (*env)->GetStringUTFChars(env, str, NULL);
2941 navit_layer_set_active(global_navit, s, 0, 0);
2942 (*env)->ReleaseStringUTFChars(env, str, s);
2943 }
2944 else if (i == 59)
2945 {
2946 // enable layer "name"
2947 s = (*env)->GetStringUTFChars(env, str, NULL);
2948 navit_layer_set_active(global_navit, s, 1, 0);
2949 (*env)->ReleaseStringUTFChars(env, str, s);
2950 }
2951 else if (i == 58)
2952 {
2953 // make street search radius bigger to the factor "s"
2954 s = (*env)->GetStringUTFChars(env, str, NULL);
2955 global_search_street_size_factor = atoi(s);
2956 (*env)->ReleaseStringUTFChars(env, str, s);
2957 }
2958 else if (i == 57)
2959 {
2960 // keep drawing streets as if at "order" level xxx
2961 s = (*env)->GetStringUTFChars(env, str, NULL);
2962 limit_order_corrected = atoi(s);
2963 (*env)->ReleaseStringUTFChars(env, str, s);
2964 }
2965 else if (i == 56)
2966 {
2967 // draw polylines with/without circles at the end
2968 //// dbg(0, "dpf1\n");
2969 s = (*env)->GetStringUTFChars(env, str, NULL);
2970 //// dbg(0, "dpf2\n");
2971 draw_polylines_fast = atoi(s);
2972 //// dbg(0, "dpf=%d\n", draw_polylines_fast);
2973 (*env)->ReleaseStringUTFChars(env, str, s);
2974 }
2975 else if (i == 55)
2976 {
2977 // set cache size for (map-)files
2978 //// dbg(0, "csf1\n");
2979 s = (*env)->GetStringUTFChars(env, str, NULL);
2980 //// dbg(0, "csf2\n");
2981 cache_size_file = atoi(s);
2982 file_cache_init();
2983 // dbg(0, "csf=%d\n", cache_size_file);
2984 (*env)->ReleaseStringUTFChars(env, str, s);
2985 }
2986 else if (i == 54)
2987 {
2988 // speak streetnames
2989 global_speak_streetnames = 1;
2990 }
2991 else if (i == 53)
2992 {
2993 // dont speak streetnames
2994 global_speak_streetnames = 0;
2995 }
2996 else if (i == 52)
2997 {
2998 // switch to demo vehicle
2999
3000 s = (*env)->GetStringUTFChars(env, str, NULL);
3001
3002 dbg(0, "**SWITCH TO:DEMO VEHICLE**\n");
3003 global_demo_vehicle_short_switch = 0;
3004 global_demo_vehicle = 1;
3005
3006 if (global_navit->vehicle)
3007 {
3008 navit_remove_cursors(global_navit);
3009 vehicle_destroy(global_navit->vehicle->vehicle);
3010 global_navit->vehicles = NULL;
3011 global_navit->vehicle = NULL;
3012 }
3013
3014 struct attr parent;
3015 struct attr source;
3016 struct attr active;
3017 struct attr follow;
3018 struct attr speed;
3019 struct attr interval;
3020 struct attr *attrs[6];
3021 parent.type = attr_navit;
3022 parent.u.navit = global_navit;
3023
3024 source.type = attr_source;
3025 source.u.str = "demo://";
3026
3027 active.type = attr_active;
3028 active.u.num = 1;
3029
3030 follow.type = attr_follow;
3031 follow.u.num = 1;
3032
3033 speed.type = attr_speed;
3034
3035 if ((global_vehicle_profile == 1) || (global_vehicle_profile == 2))
3036 {
3037 // for bicycle it's always 27 km/h
3038 speed.u.num = 27;
3039 }
3040 else
3041 {
3042 // should be 45 km/h
3043 speed.u.num = atoi(s);
3044 }
3045
3046 interval.type = attr_interval;
3047 interval.u.num = 1000; // 1 sec.
3048 // interval.u.num = 5000; // 5 sec.
3049
3050 attrs[0] = &source;
3051 attrs[1] = &active;
3052 attrs[2] = &follow;
3053 attrs[3] = &speed;
3054 attrs[4] = &interval;
3055 attrs[5] = NULL;
3056 // attr_source -> source->u.str='demo://'
3057 // <!-- vehicle name="Demo" profilename="car" enabled="no" active="yes" source="demo://" -->
3058 struct vehicle *v;
3059 //DBG // dbg(0, "demo vehicle new start\n");
3060 v = vehicle_new(&parent, attrs);
3061 //DBG // dbg(0, "demo vehicle new end\n");
3062
3063 if (v != NULL)
3064 {
3065 //DBG // dbg(0, "adding demo vehicle\n");
3066 navit_add_vehicle(global_navit, v);
3067 //DBG // dbg(0, "setting cursor\n");
3068 navit_set_cursors(global_navit);
3069
3070 struct attr follow2;
3071 follow2.type = attr_follow;
3072 follow2.u.num = 1;
3073 navit_set_attr(global_navit, &follow2);
3074
3075 // switch "Map follows Vehicle" ON
3076 struct attr attrx;
3077 attrx.type = attr_follow_cursor;
3078 attrx.u.num = 1;
3079 navit_set_attr(global_navit, &attrx);
3080 }
3081 else
3082 {
3083 //DBG // dbg(0, "ERROR adding demo vehicle\n");
3084 }
3085 // **no** navit_set_vehicle(global_navit, global_navit->vehicle);
3086 //DBG // dbg(0, "ready\n");
3087
3088 (*env)->ReleaseStringUTFChars(env, str, s);
3089 }
3090 else if (i == 51)
3091 {
3092 // set position to pixel x,y
3093 //DBG // dbg(0, "sp 1\n");
3094 char *pstr;
3095 struct point p;
3096 struct coord c;
3097 struct pcoord pc;
3098
3099 s = (*env)->GetStringUTFChars(env, str, NULL);
3100 char parse_str[strlen(s) + 1];
3101 strcpy(parse_str, s);
3102 (*env)->ReleaseStringUTFChars(env, str, s);
3103
3104 // (pixel-x#pixel-y)
3105 // pixel-x
3106 pstr = strtok(parse_str, "#");
3107 p.x = atoi(pstr);
3108 // pixel-y
3109 pstr = strtok(NULL, "#");
3110 p.y = atoi(pstr);
3111
3112 //DBG // dbg(0, "sp 2\n");
3113 transform_reverse(global_navit->trans, &p, &c);
3114 //DBG // dbg(0, "sp 3\n");
3115
3116 pc.x = c.x;
3117 pc.y = c.y;
3118 //DBG // dbg(0, "sp 4\n");
3119 pc.pro = transform_get_projection(global_navit->trans);
3120 //DBG // dbg(0, "sp 5\n");
3121
3122 //DBG // dbg(0, "%d %d\n", pc.x, pc.y);
3123 // set position
3124 //DBG // dbg(0, "sp 6\n");
3125 navit_set_position(global_navit, &pc);
3126 //DBG // dbg(0, "ready\n");
3127 }
3128 else if (i == 50)
3129 {
3130 // we request to stop drawing the map
3131 // dbg(0, "DO__DRAW:cancel_drawing_global=1\n");
3132 cancel_drawing_global = 1;
3133 }
3134 else if (i == 47)
3135 {
3136 // change maps data dir
3137 s = (*env)->GetStringUTFChars(env, str, NULL);
3138 navit_maps_dir = g_strdup(s);
3139 (*env)->ReleaseStringUTFChars(env, str, s);
3140 // //DBG // dbg(0,"*****string use=%s\n",navit_maps_dir);
3141 }
3142 else if (i == 46)
3143 {
3144 // stop searching and show results found until now
3145 offline_search_break_searching = 1;
3146 }
3147 else if (i == 45)
3148 {
3149 // filter duplicates in search results
3150 offline_search_filter_duplicates = 1;
3151 }
3152 else if (i == 44)
3153 {
3154 // show duplicates in search results
3155 offline_search_filter_duplicates = 0;
3156 }
3157 else if (i == 43)
3158 {
3159 // routing mode "normal roads"
3160 routing_mode = 1;
3161 }
3162 else if (i == 42)
3163 {
3164 // routing mode "highways"
3165 routing_mode = 0;
3166 }
3167 else if (i == 41)
3168 {
3169 // switch "Map follows Vehicle" OFF
3170 struct attr attrx;
3171 attrx.type = attr_follow_cursor;
3172 attrx.u.num = 0;
3173 navit_set_attr(global_navit, &attrx);
3174 }
3175 else if (i == 40)
3176 {
3177 // switch "Map follows Vehicle" ON
3178 struct attr attrx;
3179 attrx.type = attr_follow_cursor;
3180 attrx.u.num = 1;
3181 navit_set_attr(global_navit, &attrx);
3182 }
3183 else if (i == 39)
3184 {
3185 // switch "Northing" OFF
3186 struct attr attrx;
3187 attrx.type = attr_orientation;
3188 attrx.u.num = 0;
3189 navit_set_attr(global_navit, &attrx);
3190 }
3191 else if (i == 38)
3192 {
3193 // switch "Northing" ON
3194 struct attr attrx;
3195 attrx.type = attr_orientation;
3196 attrx.u.num = 1;
3197 navit_set_attr(global_navit, &attrx);
3198 }
3199 else if (i == 37)
3200 {
3201 // switch "Lock on road" OFF
3202 struct attr attrx;
3203 attrx.type = attr_tracking;
3204 attrx.u.num = 0;
3205 navit_set_attr(global_navit, &attrx);
3206 }
3207 else if (i == 36)
3208 {
3209 // switch "Lock on road" ON
3210 struct attr attrx;
3211 attrx.type = attr_tracking;
3212 attrx.u.num = 1;
3213 navit_set_attr(global_navit, &attrx);
3214 }
3215 else if (i == 35)
3216 {
3217 // announcer voice ON
3218 navit_cmd_announcer_on(global_navit);
3219 }
3220 else if (i == 34)
3221 {
3222 // announcer voice OFF
3223 navit_cmd_announcer_off(global_navit);
3224 }
3225 else if (i == 33)
3226 {
3227 // zoom to specific zoomlevel
3228 s = (*env)->GetStringUTFChars(env, str, NULL);
3229 int zoom_level = atoi(s);
3230 navit_zoom_to_scale(global_navit, zoom_level);
3231 (*env)->ReleaseStringUTFChars(env, str, s);
3232 }
3233 else if (i == 32)
3234 {
3235 // switch to specific 3D pitch
3236 struct attr pitch_attr;
3237 s = (*env)->GetStringUTFChars(env, str, NULL);
3238 pitch_attr.type = attr_pitch;
3239 pitch_attr.u.num = atoi(s);
3240 navit_set_attr(global_navit, &pitch_attr);
3241 (*env)->ReleaseStringUTFChars(env, str, s);
3242 }
3243 else if (i == 31)
3244 {
3245 // switch to 3D
3246 struct attr pitch_attr;
3247 pitch_attr.type = attr_pitch;
3248 pitch_attr.u.num = 30;
3249 navit_set_attr(global_navit, &pitch_attr);
3250 }
3251 else if (i == 30)
3252 {
3253 // switch to 2D
3254 struct attr pitch_attr;
3255 pitch_attr.type = attr_pitch;
3256 pitch_attr.u.num = 0;
3257 navit_set_attr(global_navit, &pitch_attr);
3258 }
3259 // 21 - 25 are used in java, so leave a hole here to make it easier to understand
3260
3261 else if (i == 20)
3262 {
3263 // add all scdard maps
3264 navit_add_all_maps(global_navit);
3265 // get the current vehicle position to the route struct -> set effective starting position for routing
3266 navit_set_vehicle_position_to_screen_center_only_for_route_struct(global_navit);
3267 }
3268 else if (i == 19)
3269 {
3270 // remove all scdard maps
3271 navit_remove_all_maps(global_navit);
3272 }
3273 else if (i == 18)
3274 {
3275 // reload scdard maps
3276 navit_reload_maps(global_navit);
3277 }
3278 else if (i == 17)
3279 {
3280 // zoom to route
3281 navit_zoom_to_route(global_navit, 0);
3282
3283 // return new zoom level to android
3284 long scale = transform_get_scale(global_navit->trans);
3285 dbg(0, "A:new scale=%lld\n", scale);
3286 android_return_generic_int(3, (int) scale);
3287 }
3288 else if (i == 16)
3289 {
3290 // use imperial units
3291 global_navit->imperial = 1;
3292 }
3293 else if (i == 15)
3294 {
3295 // use metric units
3296 global_navit->imperial = 0;
3297 }
3298 else if (i == 14)
3299 {
3300 // draw location of self (car) in the screen center
3301 global_navit->radius = 0;
3302 }
3303 else if (i == 13)
3304 {
3305 // draw location of self (car) 30% lower than screen center
3306 global_navit->radius = 30;
3307 }
3308 else if (i == 12)
3309 {
3310 // draw map only at speeds higher than 5 km/h
3311 struct attr static_speed_attr;
3312 static_speed_attr.type = attr_static_speed;
3313 static_speed_attr.u.num = 5;
3314 vehicleprofile_set_attr(global_navit->vehicleprofile, &static_speed_attr);
3315 }
3316 else if (i == 11)
3317 {
3318 // allow redraw map at ZERO speed
3319 struct attr static_speed_attr;
3320 static_speed_attr.type = attr_static_speed;
3321 static_speed_attr.u.num = 0;
3322 vehicleprofile_set_attr(global_navit->vehicleprofile, &static_speed_attr);
3323 }
3324 else if (i == 10)
3325 {
3326 // allow internal GUI
3327 allow_gui_internal = 1;
3328 }
3329 else if (i == 9)
3330 {
3331 // disable internal GUI
3332 allow_gui_internal = 0;
3333 }
3334 else if (i == 8)
3335 {
3336 // zoom to zoomlevel
3337 //DBG // dbg(0,"-8- a\n");
3338 navit_zoom_to_scale(global_navit, 524288);
3339 //DBG // dbg(0,"-8- b\n");
3340 }
3341 else if (i == 7)
3342 {
3343 // stop navigation
3344 if (attr.u.navit->destination_valid != 0)
3345 {
3346 navit_set_destination(&attr.u.navit->self, NULL, NULL, 0);
3347 #ifdef DEBUG_GLIB_MEM_FUNCTIONS
3348 g_mem_profile();
3349 #endif
3350 }
3351 }
3352 else if (i == 6)
3353 {
3354 // not used now!
3355 }
3356 else if (i == 5)
3357 {
3358 // toggle layer on/off
3359 s = (*env)->GetStringUTFChars(env, str, NULL);
3360 navit_layer_toggle_active(global_navit, s, 1);
3361 (*env)->ReleaseStringUTFChars(env, str, s);
3362 }
3363 else if (i == 49)
3364 {
3365 // add waypoint at pixel x,y on screen
3366
3367 char *pstr;
3368 struct point p;
3369 struct coord c;
3370 struct pcoord pc;
3371
3372 s = (*env)->GetStringUTFChars(env, str, NULL);
3373 char parse_str[strlen(s) + 1];
3374 strcpy(parse_str, s);
3375 (*env)->ReleaseStringUTFChars(env, str, s);
3376
3377 // add waypoint (pixel-x#pixel-y)
3378 // pixel-x
3379 pstr = strtok(parse_str, "#");
3380 p.x = atoi(pstr);
3381 // pixel-y
3382 pstr = strtok(NULL, "#");
3383 p.y = atoi(pstr);
3384
3385 transform_reverse(global_navit->trans, &p, &c);
3386
3387 pc.x = c.x;
3388 pc.y = c.y;
3389 pc.pro = transform_get_projection(global_navit->trans);
3390
3391 // append new waypoint to navigation
3392 navit_add_waypoint_to_route(global_navit, &pc, parse_str, 1);
3393 }
3394 else if (i == 4)
3395 {
3396 // set destination to pixel x,y on screen
3397
3398 char *pstr;
3399 struct point p;
3400 struct coord c;
3401 struct pcoord pc;
3402
3403 s = (*env)->GetStringUTFChars(env, str, NULL);
3404 char parse_str[strlen(s) + 1];
3405 strcpy(parse_str, s);
3406 (*env)->ReleaseStringUTFChars(env, str, s);
3407
3408 // set destination to (pixel-x#pixel-y)
3409 // pixel-x
3410 pstr = strtok(parse_str, "#");
3411 p.x = atoi(pstr);
3412 // pixel-y
3413 pstr = strtok(NULL, "#");
3414 p.y = atoi(pstr);
3415
3416 transform_reverse(global_navit->trans, &p, &c);
3417
3418 pc.x = c.x;
3419 pc.y = c.y;
3420 pc.pro = transform_get_projection(global_navit->trans);
3421
3422 // start navigation asynchronous
3423 navit_set_destination(global_navit, &pc, parse_str, 1);
3424 }
3425 else if (i == 55548)
3426 {
3427 // append waypoint at lat, lng
3428
3429 char *name;
3430 s = (*env)->GetStringUTFChars(env, str, NULL);
3431 char parse_str[strlen(s) + 1];
3432 strcpy(parse_str, s);
3433 (*env)->ReleaseStringUTFChars(env, str, s);
3434
3435 // waypoint (lat#lon#title)
3436 struct coord_geo g;
3437 char *p;
3438 char *stopstring;
3439
3440 // lat
3441 p = strtok(parse_str, "#");
3442 g.lat = strtof(p, &stopstring);
3443 // lon
3444 p = strtok(NULL, "#");
3445 g.lng = strtof(p, &stopstring);
3446 // description
3447 name = strtok(NULL, "#");
3448
3449 ////DBG // dbg(0,"lat=%f\n",g.lat);
3450 ////DBG // dbg(0,"lng=%f\n",g.lng);
3451 ////DBG // dbg(0,"str1=%s\n",name);
3452
3453 struct coord c;
3454 transform_from_geo(projection_mg, &g, &c);
3455
3456 struct pcoord pc;
3457 pc.x = c.x;
3458 pc.y = c.y;
3459 pc.pro = projection_mg;
3460
3461 if (global_navit->destination_valid == 1)
3462 {
3463 route_add_destination_no_calc(global_navit->route, &pc, 1);
3464
3465 global_navit->destination = pc;
3466 global_navit->destination_valid = 1;
3467 }
3468 else
3469 {
3470 route_set_destination_no_calc(global_navit->route, &pc, 1);
3471 }
3472 }
3473 else if (i == 55598)
3474 {
3475 s = (*env)->GetStringUTFChars(env, str, NULL);
3476 int value = atoi(s);
3477
3478 global_routing_engine = value;
3479
3480 (*env)->ReleaseStringUTFChars(env, str, s);
3481 }
3482 else if (i == 55599)
3483 {
3484 route_after_destination_start_calc(global_navit->route, 1);
3485 }
3486 else if (i == 48)
3487 {
3488 // append waypoint at lat, lng
3489
3490 char *name;
3491 s = (*env)->GetStringUTFChars(env, str, NULL);
3492 char parse_str[strlen(s) + 1];
3493 strcpy(parse_str, s);
3494 (*env)->ReleaseStringUTFChars(env, str, s);
3495
3496 // waypoint (lat#lon#title)
3497 struct coord_geo g;
3498 char *p;
3499 char *stopstring;
3500
3501 // lat
3502 p = strtok(parse_str, "#");
3503 g.lat = strtof(p, &stopstring);
3504 // lon
3505 p = strtok(NULL, "#");
3506 g.lng = strtof(p, &stopstring);
3507 // description
3508 name = strtok(NULL, "#");
3509
3510 ////DBG // dbg(0,"lat=%f\n",g.lat);
3511 ////DBG // dbg(0,"lng=%f\n",g.lng);
3512 ////DBG // dbg(0,"str1=%s\n",name);
3513
3514 struct coord c;
3515 transform_from_geo(projection_mg, &g, &c);
3516
3517 struct pcoord pc;
3518 pc.x = c.x;
3519 pc.y = c.y;
3520 pc.pro = projection_mg;
3521
3522 // append new waypoint to navigation
3523 navit_add_waypoint_to_route(global_navit, &pc, name, 1);
3524 }
3525 else if (i == 55503)
3526 {
3527
3528 // set destination to lat, lng
3529
3530 char *name;
3531 s = (*env)->GetStringUTFChars(env, str, NULL);
3532 char parse_str[strlen(s) + 1];
3533 strcpy(parse_str, s);
3534 (*env)->ReleaseStringUTFChars(env, str, s);
3535 ////DBG // dbg(0,"*****string=%s\n",s);
3536
3537 // set destination to (lat#lon#title)
3538 struct coord_geo g;
3539 char *p;
3540 char *stopstring;
3541
3542 // lat
3543 p = strtok(parse_str, "#");
3544 g.lat = strtof(p, &stopstring);
3545 // lon
3546 p = strtok(NULL, "#");
3547 g.lng = strtof(p, &stopstring);
3548 // description
3549 name = strtok(NULL, "#");
3550
3551 ////DBG // dbg(0,"lat=%f\n",g.lat);
3552 ////DBG // dbg(0,"lng=%f\n",g.lng);
3553 ////DBG // dbg(0,"str1=%s\n",name);
3554
3555 struct coord c;
3556 transform_from_geo(projection_mg, &g, &c);
3557
3558 struct pcoord pc;
3559 pc.x = c.x;
3560 pc.y = c.y;
3561 pc.pro = projection_mg;
3562
3563 global_navit->destination = pc;
3564 global_navit->destination_valid = 1;
3565
3566 if (global_navit->route)
3567 {
3568 route_set_destination_no_calc(global_navit->route, &pc, 1);
3569 }
3570 }
3571 else if (i == 3)
3572 {
3573 // set destination to lat, lng
3574
3575 char *name;
3576 s = (*env)->GetStringUTFChars(env, str, NULL);
3577 char parse_str[strlen(s) + 1];
3578 strcpy(parse_str, s);
3579 (*env)->ReleaseStringUTFChars(env, str, s);
3580 ////DBG // dbg(0,"*****string=%s\n",s);
3581
3582 // set destination to (lat#lon#title)
3583 struct coord_geo g;
3584 char *p;
3585 char *stopstring;
3586
3587 // lat
3588 p = strtok(parse_str, "#");
3589 g.lat = strtof(p, &stopstring);
3590 // lon
3591 p = strtok(NULL, "#");
3592 g.lng = strtof(p, &stopstring);
3593 // description
3594 name = strtok(NULL, "#");
3595
3596 ////DBG // dbg(0,"lat=%f\n",g.lat);
3597 ////DBG // dbg(0,"lng=%f\n",g.lng);
3598 ////DBG // dbg(0,"str1=%s\n",name);
3599
3600 struct coord c;
3601 transform_from_geo(projection_mg, &g, &c);
3602
3603 struct pcoord pc;
3604 pc.x = c.x;
3605 pc.y = c.y;
3606 pc.pro = projection_mg;
3607
3608 // start navigation asynchronous
3609 navit_set_destination(global_navit, &pc, name, 1);
3610
3611 }
3612 }
3613
3614 (*env)->DeleteGlobalRef(env, str);
3615 str = NULL;
3616
3617 // dbg(0,"leave %d\n",i);
3618
3619 #endif
3620
3621 __F_END__
3622
3623 }
3624
3625 void android_send_generic_text(int id, char *text)
3626 {
3627 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3628 dbg(0,"+#+:enter\n");
3629 #endif
3630 //DBG // dbg(0,"Enter\n");
3631
3632 if (NavitGraphicsClass2 == NULL)
3633 {
3634 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
3635 {
3636 NavitGraphicsClass2 = NULL;
3637 return;
3638 }
3639 }
3640 //DBG // dbg(0,"x1\n");
3641 if (send_generic_text == NULL)
3642 {
3643 android_find_static_method(NavitGraphicsClass2, "send_generic_text", "(ILjava/lang/String;)V", &send_generic_text);
3644 }
3645 //DBG // dbg(0,"x2\n");
3646 if (send_generic_text == NULL)
3647 {
3648 //DBG // dbg(0, "no method found\n");
3649 return; /* exception thrown */
3650 }
3651 //DBG // dbg(0,"x3\n");
3652
3653 JNIEnv *jnienv2;
3654 jnienv2 = jni_getenv();
3655
3656 jstring string1 = (*jnienv2)->NewStringUTF(jnienv2, text);
3657 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, send_generic_text, id, string1);
3658 (*jnienv2)->DeleteLocalRef(jnienv2, string1);
3659
3660 // // dbg(0,"leave\n");
3661 }
3662
3663 void send_osd_values(char *id, char *text1, char *text2, char *text3, int i1, int i2, int i3, int i4, float f1, float f2, float f3)
3664 {
3665 //DBG // dbg(0,"EEnter\n");
3666 JNIEnv *jnienv2;
3667 jnienv2 = jni_getenv();
3668
3669 jstring string1 = (*jnienv2)->NewStringUTF(jnienv2, id);
3670 jstring string2 = (*jnienv2)->NewStringUTF(jnienv2, text1);
3671 jstring string3 = (*jnienv2)->NewStringUTF(jnienv2, text2);
3672 jstring string4 = (*jnienv2)->NewStringUTF(jnienv2, text3);
3673
3674 // static
3675 if (NavitGraphicsClass2 == NULL)
3676 {
3677 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
3678 {
3679 NavitGraphicsClass2 = NULL;
3680 return;
3681 }
3682 }
3683
3684 if (NavitGraphics_send_osd_values2 == NULL)
3685 {
3686 if (!android_find_static_method(NavitGraphicsClass2, "send_osd_values", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIIFFF)V", &NavitGraphics_send_osd_values2))
3687 {
3688 return;
3689 }
3690 }
3691
3692 // static
3693 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, NavitGraphics_send_osd_values2, string1, string2, string3, string4, i1, i2, i3, i4, f1, f2, f3);
3694
3695 (*jnienv2)->DeleteLocalRef(jnienv2, string1);
3696 (*jnienv2)->DeleteLocalRef(jnienv2, string2);
3697 (*jnienv2)->DeleteLocalRef(jnienv2, string3);
3698 (*jnienv2)->DeleteLocalRef(jnienv2, string4);
3699 }
3700
3701 void set_vehicle_values_to_java(int x, int y, int angle, int speed)
3702 {
3703 //DBG // dbg(0,"EEnter\n");
3704 JNIEnv *jnienv2;
3705 jnienv2 = jni_getenv();
3706
3707 //int thread_id = gettid();
3708 //dbg(0, "THREAD ID=%d\n", thread_id);
3709
3710 if (NavitGraphicsClass2 == NULL)
3711 {
3712 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
3713 {
3714 NavitGraphicsClass2 = NULL;
3715 return;
3716 }
3717 }
3718
3719 if (NavitGraphics_set_vehicle_values2 == NULL)
3720 {
3721 if (!android_find_static_method(NavitGraphicsClass2, "set_vehicle_values", "(IIII)V", &NavitGraphics_set_vehicle_values2))
3722 {
3723 return;
3724 }
3725 }
3726
3727 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, NavitGraphics_set_vehicle_values2, x, y, angle, speed);
3728 }
3729
3730 void set_vehicle_values_to_java_delta(int dx, int dy, int dangle, int dzoom, int l_old, int l_new)
3731 {
3732 JNIEnv *jnienv2;
3733 jnienv2 = jni_getenv();
3734
3735 //int thread_id = gettid();
3736 //dbg(0, "THREAD ID=%d\n", thread_id);
3737
3738 if (NavitGraphicsClass2 == NULL)
3739 {
3740 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
3741 {
3742 NavitGraphicsClass2 = NULL;
3743 return;
3744 }
3745 }
3746
3747 if (NavitGraphics_set_vehicle_values3 == NULL)
3748 {
3749 if (!android_find_static_method(NavitGraphicsClass2, "set_vehicle_values_delta", "(IIIIII)V", &NavitGraphics_set_vehicle_values3))
3750 {
3751 return;
3752 }
3753 }
3754
3755 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, NavitGraphics_set_vehicle_values3, dx, dy, dangle, dzoom, l_old, l_new);
3756 }
3757
3758 void send_route_rect_to_java(int x1, int y1, int x2, int y2, int order)
3759 {
3760 JNIEnv *jnienv2;
3761 jnienv2 = jni_getenv();
3762
3763 //int thread_id = gettid();
3764 //dbg(0, "THREAD ID=%d\n", thread_id);
3765
3766 if (NavitGraphicsClass2 == NULL)
3767 {
3768 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
3769 {
3770 NavitGraphicsClass2 = NULL;
3771 return;
3772 }
3773 }
3774
3775 if (NavitGraphics_send_route_rect_to_java == NULL)
3776 {
3777 if (!android_find_static_method(NavitGraphicsClass2, "send_route_rect_to_java", "(IIIII)V", &NavitGraphics_send_route_rect_to_java))
3778 {
3779 return;
3780 }
3781 }
3782
3783 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, NavitGraphics_send_route_rect_to_java, x1, y1, x2, y2, order);
3784 }
3785

   
Visit the ZANavi Wiki