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

Contents of /navit/navit/android.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (6 years, 7 months ago) by zoff99
File MIME type: text/plain
File size: 67737 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 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 "navit.h"
27 #include "config_.h"
28 #include "command.h"
29 #include "debug.h"
30 #include "event.h"
31 #include "callback.h"
32 #include "projection.h"
33 #include "map.h"
34 #include "transform.h"
35 #include "color.h"
36 #include "types.h"
37 #include "search.h"
38 #include "start_real.h"
39 #include "route.h"
40 #include "file.h"
41
42 // #include "layout.h"
43
44 JNIEnv *jnienv;
45 jobject *android_activity;
46 struct callback_list *android_activity_cbl;
47 int android_version;
48
49 jclass NavitGraphicsClass2 = NULL;
50 jmethodID return_generic_int;
51 jmethodID send_generic_text;
52 jclass NavitMapPreviewActivityClass = NULL;
53 jmethodID DrawMapPreview_target;
54 jmethodID DrawMapPreview_polyline = NULL;
55 jmethodID DrawMapPreview_text = NULL;
56 jmethodID NavitGraphics_send_osd_values2 = NULL;
57 jmethodID NavitGraphics_set_vehicle_values2 = NULL;
58 jmethodID NavitGraphics_set_vehicle_values3 = NULL;
59 jmethodID NavitGraphics_send_route_rect_to_java = NULL;
60
61 struct attr attr;
62
63 // ------------------------- COPIED STUFF --- this is generally bad ------------------
64 // ------------------------- COPIED STUFF --- this is generally bad ------------------
65 // ------------------------- COPIED STUFF --- this is generally bad ------------------
66
67
68 // copyied from config_.c !!! (always keep in sync!!!)
69 struct config
70 {
71 struct attr **attrs;
72 struct callback_list *cbl;
73 }*config;
74
75 // copied from gui_internal.c (always keep in sync!!!)
76 struct gui_config_settings
77 {
78 int font_size;
79 int icon_xs;
80 int icon_s;
81 int icon_l;
82 int spacing;
83 };
84
85 // dummy def!!
86 struct gui_internal_methods
87 {
88 int dummy;
89 };
90
91 // dummy def!!
92 struct gui_internal_widget_methods
93 {
94 int dummy;
95 };
96
97 // forward def
98 struct gui_priv;
99
100 // copied from gui_internal.h (always keep in sync!!!)
101 struct gui_internal_data
102 {
103 struct gui_priv *priv;
104 struct gui_internal_methods *gui;
105 struct gui_internal_widget_methods *widget;
106 };
107
108 // copied from gui_internal.c (always keep in sync!!!)
109 struct route_data
110 {
111 struct widget * route_table;
112 int route_showing;
113
114 };
115
116 // copied from gui_internal.h (always keep in sync!!!)
117 enum flags
118 {
119 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,
120 };
121
122 // copied from gui_internal.h (always keep in sync!!!)
123 enum widget_type
124 {
125 widget_box = 1, widget_button, widget_label, widget_image, widget_table, widget_table_row
126 };
127
128 // copied from gui_internal.c (always keep in sync!!!)
129 struct widget
130 {
131 enum widget_type type;
132 struct graphics_gc *background, *text_background;
133 struct graphics_gc *foreground_frame;
134 struct graphics_gc *foreground;
135 char *text;
136 struct graphics_image *img;
137 void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
138 int reason;
139 int datai;
140 void *data;
141 void (*data_free)(void *data);
142 void (*free)(struct gui_priv *this_, struct widget * w);
143 char *prefix;
144 char *name;
145 char *speech;
146 char *command;
147 struct pcoord c;
148 struct item item;
149 int selection_id;
150 int state;
151 struct point p;
152 int wmin, hmin;
153 int w, h;
154 int textw, texth;
155 int font_idx;
156 int bl, br, bt, bb, spx, spy;
157 int border;
158 int packed;
159 int cols;
160 enum flags flags;
161 int flags2;
162 void *instance;
163 int (*set_attr)(void *, struct attr *);
164 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
165 void (*remove_cb)(void *, struct callback *cb);
166 struct callback *cb;
167 struct attr on;
168 struct attr off;
169 int deflt;
170 int is_on;
171 int redraw;
172 struct menu_data *menu_data;
173 struct form *form;
174 GList *children;
175 };
176
177 // copied from gui_internal.c !!!!!! (always keep in sync!!!)
178 struct gui_priv
179 {
180 struct navit *nav;
181 struct attr self;
182 struct window *win;
183 struct graphics *gra;
184 struct graphics_gc *background;
185 struct graphics_gc *background2;
186 struct graphics_gc *highlight_background;
187 struct graphics_gc *foreground;
188 struct graphics_gc *text_foreground;
189 struct graphics_gc *text_background;
190 struct color background_color, background2_color, text_foreground_color, text_background_color;
191 int spacing;
192 int font_size;
193 int fullscreen;
194 struct graphics_font *fonts[3];
195 int icon_xs;
196 int icon_s;
197 int icon_l;
198 int pressed;
199 struct widget *widgets;
200 int widgets_count;
201 int redraw;
202 struct widget root;
203 struct widget *highlighted, *editable;
204 struct widget *highlighted_menu;
205 int clickp_valid, vehicle_valid;
206 struct pcoord clickp, vehiclep;
207 struct attr *click_coord_geo, *position_coord_geo;
208 struct search_list *sl;
209 int ignore_button;
210 int menu_on_map_click;
211 int signal_on_map_click;
212 char *country_iso2;
213 int speech;
214 int keyboard;
215 int keyboard_required;
216 struct gui_config_settings config;
217 struct event_idle *idle;
218 struct callback *motion_cb, *button_cb, *resize_cb, *keypress_cb, *window_closed_cb, *idle_cb, *motion_timeout_callback;
219 struct event_timeout *motion_timeout_event;
220 struct point current;
221 struct callback * vehicle_cb;
222 struct route_data route_data;
223 struct gui_internal_data data;
224 struct callback_list *cbl;
225 int flags;
226 int cols;
227 struct attr osd_configuration;
228 int pitch;
229 int flags_town, flags_street, flags_house_number;
230 int radius;
231 char *html_text;
232 int html_depth;
233 struct widget *html_container;
234 int html_skip;
235 char *html_anchor;
236 char *href;
237 int html_anchor_found;
238 struct form *form;
239 struct html
240 {
241 int skip;
242 enum html_tag
243 {
244 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,
245 } tag;
246 char *command;
247 char *name;
248 char *href;
249 char *refresh_cond;
250 struct widget *w;
251 struct widget *container;
252 } html[10];
253 };
254
255 // ------------------------- COPIED STUFF --- this is generally bad ------------------
256 // ------------------------- COPIED STUFF --- this is generally bad ------------------
257 // ------------------------- COPIED STUFF --- this is generally bad ------------------
258
259
260 JavaVM *cachedJVM = NULL;
261
262 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
263 {
264 JNIEnv *env_this;
265 cachedJVM = jvm;
266 if ((*jvm)->GetEnv(jvm, (void**) &env_this, JNI_VERSION_1_6))
267 {
268 // dbg(0,"Could not get JVM\n");
269 return JNI_ERR;
270 }
271
272 // dbg(0,"++ Found JVM ++\n");
273 return JNI_VERSION_1_6;
274 }
275
276 JNIEnv* jni_getenv()
277 {
278 JNIEnv* env_this;
279 (*cachedJVM)->GetEnv(cachedJVM, (void**) &env_this, JNI_VERSION_1_6);
280 return env_this;
281 }
282
283 static void gui_internal_search_list_set_default_country2(struct gui_priv *this)
284 {
285 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
286 // dbg(0,"+#+:enter\n");
287 #endif
288 struct attr search_attr, country_name, country_iso2, *country_attr;
289 struct item *item;
290 struct country_search *cs;
291 struct tracking *tracking;
292 struct search_list_result *res;
293
294 ////DBG // dbg(0,"### 1");
295
296 country_attr = country_default();
297 tracking = navit_get_tracking(this->nav);
298
299 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
300 country_attr = &search_attr;
301 if (country_attr)
302 {
303 ////DBG // dbg(0,"### 2");
304 cs = country_search_new(country_attr, 0);
305 item = country_search_get_item(cs);
306 if (item && item_attr_get(item, attr_country_name, &country_name))
307 {
308 search_attr.type = attr_country_all;
309 ////DBG // dbg(0,"country %s\n", country_name.u.str);
310 search_attr.u.str = country_name.u.str;
311 search_list_search(this->sl, &search_attr, 0);
312 while ((res = search_list_get_result(this->sl)))
313 ;
314 if (this->country_iso2)
315 {
316 // this seems to cause a crash, no idea why
317 //g_free(this->country_iso2);
318 this->country_iso2 = NULL;
319 }
320 if (item_attr_get(item, attr_country_iso2, &country_iso2))
321 {
322 this->country_iso2 = g_strdup(country_iso2.u.str);
323 }
324 }
325 country_search_destroy(cs);
326 }
327 else
328 {
329 //DBG // dbg(0, "warning: no default country found\n");
330 if (this->country_iso2)
331 {
332 //DBG // dbg(0, "attempting to use country '%s'\n", this->country_iso2);
333 search_attr.type = attr_country_iso2;
334 search_attr.u.str = this->country_iso2;
335 search_list_search(this->sl, &search_attr, 0);
336 while ((res = search_list_get_result(this->sl)))
337 ;
338 }
339 }
340 ////DBG // dbg(0,"### 99");
341 }
342
343 // forward rev
344 struct navit *global_navit;
345
346 int android_find_class_global(char *name, jclass *ret)
347 {
348 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
349 // dbg(0,"+#+:enter\n");
350 #endif
351
352 JNIEnv *jnienv2;
353 jnienv2 = jni_getenv();
354
355 *ret = (*jnienv2)->FindClass(jnienv2, name);
356 if (!*ret)
357 {
358 //DBG // dbg(0, "Failed to get Class %s\n", name);
359 return 0;
360 }
361 //DBG // dbg(0,"lclass %p\n", *ret);
362 *ret = (*jnienv2)->NewGlobalRef(jnienv2, *ret);
363 // ICS (*jnienv2)->DeleteGlobalRef(jnienv2, *lret);
364 //DBG // dbg(0,"gclass %p\n", *ret);
365 return 1;
366 }
367
368 int android_find_method(jclass class, char *name, char *args, jmethodID *ret)
369 {
370 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
371 // dbg(0,"+#+:enter\n");
372 #endif
373
374 JNIEnv *jnienv2;
375 jnienv2 = jni_getenv();
376
377 *ret = (*jnienv2)->GetMethodID(jnienv2, class, name, args);
378 if (*ret == NULL)
379 {
380 //DBG // dbg(0, "Failed to get Method %s with signature %s\n", name, args);
381 return 0;
382 }
383 //DBG // dbg(0,"l meth %p\n", *ret);
384 return 1;
385 }
386
387 int android_find_static_method(jclass class, char *name, char *args, jmethodID *ret)
388 {
389 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
390 // dbg(0,"+#+:enter\n");
391 #endif
392
393 JNIEnv *jnienv2;
394 jnienv2 = jni_getenv();
395
396 *ret = (*jnienv2)->GetStaticMethodID(jnienv2, class, name, args);
397 if (*ret == NULL)
398 {
399 //DBG // dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
400 return 0;
401 }
402 //DBG // dbg(0,"l meth %p\n", *ret);
403 return 1;
404 }
405
406 JNIEXPORT void JNICALL
407 Java_com_zoffcc_applications_zanavi_Navit_NavitMain(JNIEnv* env, jobject thiz, jobject activity, jobject lang, int version, jobject display_density_string)
408 {
409 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
410 // dbg(0,"+#+:enter\n");
411 #endif
412
413 #ifdef DEBUG_GLIB_MEM_FUNCTIONS
414 // GLIB debugging
415 // GLIB debugging
416 // GLIB debugging
417 dbg(0,"GLIB debugging ----------------------");
418 dbg(0,"GLIB debugging ----------------------");
419 dbg(0,"GLIB debugging ----------------------");
420 dbg(0,"GLIB debugging ----------------------");
421 dbg(0,"GLIB debugging ----------------------");
422 dbg(0,"GLIB debugging ----------------------");
423 dbg(0,"GLIB debugging ----------------------");
424 dbg(0,"GLIB debugging ----------------------");
425 dbg(0,"GLIB debugging 1 --------------------");
426 g_mem_set_vtable(glib_mem_profiler_table);
427 //char *dummy_997;
428 //dummy_997 = g_malloc(1024*1024*10); // 10 MByte
429 //g_free(dummy_997);
430 //dummy_997 = NULL;
431 //g_mem_profile();
432 dbg(0,"GLIB debugging 2 --------------------");
433 dbg(0,"GLIB debugging ----------------------");
434 dbg(0,"GLIB debugging ----------------------");
435 dbg(0,"GLIB debugging ----------------------");
436 dbg(0,"GLIB debugging ----------------------");
437 dbg(0,"GLIB debugging ----------------------");
438 dbg(0,"GLIB debugging ----------------------");
439 dbg(0,"GLIB debugging ----------------------");
440 dbg(0,"GLIB debugging ----------------------");
441 // GLIB debugging
442 // GLIB debugging
443 // GLIB debugging
444 #endif
445
446 int thread_id = gettid();
447 // dbg(0, "THREAD ID=%d\n", thread_id);
448
449 char *strings[] = { "/data/data/com.zoffcc.applications.zanavi/bin/navit", NULL };
450 const char *langstr;
451 const char *displaydensitystr;
452 android_version = version;
453 //__android_log_print(ANDROID_LOG_ERROR,"test","called");
454 android_activity_cbl = callback_list_new();
455
456 // SET GLOBAL JNIENV here, this is bad!!
457 // SET GLOBAL JNIENV here, this is bad!!
458 // SET GLOBAL JNIENV here, this is bad!!
459 jnienv = env;
460 // dbg(0,"jnienv=%p\n", env);
461 // SET GLOBAL JNIENV here, this is bad!!
462 // SET GLOBAL JNIENV here, this is bad!!
463 // SET GLOBAL JNIENV here, this is bad!!
464
465 //jclass someClass = env->FindClass("SomeClass");
466 //gSomeClass = env->NewGlobalRef(someClass);
467
468
469 // *only local* android_activity = activity;
470 // android_activity = (*jnienv)->NewGlobalRef(jnienv, activity);
471 android_activity = (*env)->NewGlobalRef(env, activity);
472 langstr = (*env)->GetStringUTFChars(env, lang, NULL);
473 //DBG // dbg(0, "enter env=%p thiz=%p activity=%p lang=%s version=%d\n", env, thiz, activity, langstr, version);
474 //DBG // dbg(0, "enter env=%p thiz=%p activity=%p lang=%s version=%d\n", env, thiz, android_activity, langstr, version);
475 setenv("LANG", langstr, 1);
476 (*env)->ReleaseStringUTFChars(env, lang, langstr);
477
478 displaydensitystr = (*env)->GetStringUTFChars(env, display_density_string, NULL);
479 //DBG // dbg(0, "*****displaydensity=%s\n", displaydensitystr);
480 setenv("ANDROID_DENSITY", displaydensitystr, 1);
481 (*env)->ReleaseStringUTFChars(env, display_density_string, displaydensitystr);
482
483 //// dbg(0,"before main_real call\n");
484 //main_real(1, strings);
485 //// dbg(0,"after main_real call\n");
486
487 /* -- mem test --
488 char *dummy_99;
489 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
490 g_free(dummy_99);
491 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
492 g_free(dummy_99);
493 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
494 g_free(dummy_99);
495 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
496 g_free(dummy_99);
497 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
498 g_free(dummy_99);
499 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
500 g_free(dummy_99);
501 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
502 g_free(dummy_99);
503 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
504 g_free(dummy_99);
505 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
506 g_free(dummy_99);
507 dummy_99 = g_malloc(1024*1024*10); // 10 MByte
508 g_free(dummy_99);
509 dummy_997 = NULL;
510 */
511
512 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
513 // dbg(0,"+#+:leave\n");
514 #endif
515
516 }
517
518 JNIEXPORT void JNICALL
519 Java_com_zoffcc_applications_zanavi_Navit_NavitActivity(JNIEnv* env, jobject thiz, int param)
520 {
521 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
522 // dbg(0,"+#+:enter\n");
523 #endif
524
525 //dbg(0, "enter %d\n", param);
526
527 int thread_id = gettid();
528 // dbg(0, "THREAD ID=%d\n", thread_id);
529
530 if (param == -2)
531 {
532 // onStop() -> called in Java app
533 // save center.txt
534 if (global_navit->bookmarks)
535 {
536 config_get_attr(config, attr_navit, &attr, NULL);
537 //DBG // dbg(0, "save position to file");
538 char *center_file = bookmarks_get_center_file(TRUE);
539 bookmarks_write_center_to_file(attr.u.navit->bookmarks, center_file);
540 // dbg(0, "save pos to file -> ready");
541 g_free(center_file);
542 // bookmarks_destroy(global_navit->bookmarks);
543 }
544 }
545
546 // param == 3 // onCreate
547 // param == 2 // onStart
548 // param == 1 // onResume
549 // param == 0 // onRestart
550 // param == -1 // onPause
551 // param == -2 // onStop
552 // param == -3 // onDestroy
553 // param == -4 // exit() [java function]
554
555 if (param == 3)
556 {
557 // in onCreate at startup
558 char *strings[] = { "/data/data/com.zoffcc.applications.zanavi/bin/navit", NULL };
559
560 // dbg(0,"before main_real call\n");
561 main_real(1, strings);
562 // dbg(0,"after main_real call\n");
563
564 navit_draw(global_navit);
565 }
566
567 // dbg(0, "acti: 001\n");
568 // callback_list_call_1(android_activity_cbl, param);
569 //// dbg(0, "acti: 002\n");
570
571 //if (param == -4)
572 //{
573 // // dbg(0, "acti: 003\n");
574 // // *********EXIT******EXIT******** // exit(0);
575 //}
576
577 if (param == -4)
578 {
579 // dbg(0, "acti: 004\n");
580 navit_destroy(global_navit);
581 // dbg(0, "acti: 005\n");
582 event_main_loop_quit();
583 // dbg(0, "acti: 006\n");
584 }
585 }
586
587 JNIEXPORT void JNICALL
588 Java_com_zoffcc_applications_zanavi_NavitGraphics_SizeChangedCallbackReal(JNIEnv* env, jobject thiz, int w, int h)
589 {
590 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
591 // dbg(0,"+#+:enter\n");
592 #endif
593 // dbg(0,"enter %d %d\n", w, h);
594
595 int thread_id = gettid();
596 // dbg(0, "THREAD ID=%d\n", thread_id);
597
598 navit_handle_resize(global_navit, w, h);
599 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
600 // dbg(0,"+#+:leave\n");
601 #endif
602 }
603
604 JNIEXPORT void JNICALL
605 Java_com_zoffcc_applications_zanavi_NavitGraphics_MotionCallbackReal(JNIEnv* env, jobject thiz, int x1, int y1, int x2, int y2)
606 {
607 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
608 // dbg(0,"+#+:enter\n");
609 #endif
610
611 //int thread_id = gettid();
612 // dbg(0, "THREAD ID=%d\n", thread_id);
613
614 struct point p_end;
615 struct point p_start;
616
617 p_start.x = x1;
618 p_start.y = y1;
619 p_end.x = x2;
620 p_end.y = y2;
621 update_transformation(global_navit->trans, &p_start, &p_end, NULL);
622 // graphics_draw_drag(this_->gra, NULL);
623 transform_copy(global_navit->trans, global_navit->trans_cursor);
624 global_navit->moved = 1;
625
626 /*
627 struct coord c;
628 struct pcoord pc;
629 p.x = x;
630 p.y = y;
631 transform_reverse(global_navit->trans, &p, &c);
632 pc.x = c.x;
633 pc.y = c.y;
634 pc.pro = transform_get_projection(global_navit->trans);
635 navit_set_position(global_navit, &pc);
636 */
637
638 // dbg(0,"call async java draw -start-\n");
639 navit_draw(global_navit);
640 // navit_draw_async(global_navit, 1);
641 // dbg(0,"call async java draw --end--\n");
642
643 // remove the "wait" screen
644 //#ifdef HAVE_API_ANDROID
645 // android_return_generic_int(2, 0);
646 //#endif
647
648 }
649
650 JNIEXPORT void JNICALL
651 Java_com_zoffcc_applications_zanavi_NavitGraphics_TimeoutCallback(JNIEnv* env, jobject thiz, int delete, int id)
652 {
653 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
654 // dbg(0,"+#+:enter\n");
655 #endif
656
657 JNIEnv *jnienv2;
658 jnienv2 = jni_getenv();
659
660 //int thread_id = gettid();
661 //dbg(0, "THREAD ID=%d\n", thread_id);
662
663 //DBG // dbg(0,"enter %p %d %p\n",thiz, delete, (void *)id);
664 //dbg(0,"timeout 1\n");
665 // ICS
666 //if (id != 0)
667 //{
668 // dbg(0,"callback struct=%p %d\n", id, id);
669 callback_call_0((struct callback *) id);
670 //}
671 // ICS
672 //dbg(0,"timeout 2\n");
673
674 /*
675 if (delete)
676 {
677 //dbg(0,"timeout 3\n");
678 // ICS
679 jobject this_global = (*jnienv2)->NewGlobalRef(jnienv2, thiz);
680 //dbg(0,"timeout 3.1\n");
681 (*jnienv2)->DeleteGlobalRef(jnienv2, this_global);
682 // ICS
683 //dbg(0,"timeout 4\n");
684 }
685 */
686 }
687
688 JNIEXPORT void JNICALL
689 Java_com_zoffcc_applications_zanavi_NavitIdle_IdleCallback(JNIEnv* env, jobject thiz, int id)
690 {
691 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
692 // dbg(0,"+#+:enter\n");
693 #endif
694
695 //int thread_id = gettid();
696 // dbg(0, "THREAD ID=%d\n", thread_id);
697
698 //DBG // dbg(0,"enter %p %p\n",thiz, (void *)id);
699 // dbg(0,"idlecall back 1\n");
700 callback_call_0((struct callback *) id);
701 // dbg(0,"idlecall back 2\n");
702 }
703
704 JNIEXPORT void JNICALL
705 Java_com_zoffcc_applications_zanavi_NavitWatch_poll(JNIEnv* env, jobject thiz, int fd, int cond)
706 {
707 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
708 // dbg(0,"+#+:enter\n");
709 #endif
710 struct pollfd pfd;
711 pfd.fd = fd;
712 //DBG // dbg(0, "%p poll called for %d %d\n", env, fd, cond);
713 switch ((enum event_watch_cond) cond)
714 {
715 case event_watch_cond_read:
716 pfd.events = POLLIN;
717 break;
718 case event_watch_cond_write:
719 pfd.events = POLLOUT;
720 break;
721 case event_watch_cond_except:
722 pfd.events = POLLERR;
723 break;
724 default:
725 pfd.events = 0;
726 }
727 pfd.revents = 0;
728 poll(&pfd, 1, -1);
729 }
730
731 JNIEXPORT void JNICALL
732 Java_com_zoffcc_applications_zanavi_NavitWatch_WatchCallback(JNIEnv* env, jobject thiz, int id)
733 {
734 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
735 // dbg(0,"+#+:enter\n");
736 #endif
737 //DBG // dbg(0, "enter %p %p\n", thiz, (void *) id);
738 callback_call_0((struct callback *) id);
739 }
740
741 JNIEXPORT void JNICALL
742 Java_com_zoffcc_applications_zanavi_NavitSensors_SensorCallback(JNIEnv* env, jobject thiz, int id, int sensor, float x, float y, float z)
743 {
744 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
745 // dbg(0,"+#+:enter\n");
746 #endif
747 // JNIEnv *jnienv2;
748 // jnienv2 = jni_getenv();
749
750 //int thread_id = gettid();
751 // dbg(0, "THREAD ID=%d\n", thread_id);
752
753 //DBG // dbg(0, "enter %p %p %f %f %f\n", thiz, (void *) id, x, y, z);
754 callback_call_4((struct callback *) id, sensor, &x, &y, &z);
755 }
756
757 JNIEXPORT void JNICALL
758 Java_com_zoffcc_applications_zanavi_NavitVehicle_VehicleCallback(JNIEnv *env, jobject thiz, jobject location)
759 {
760 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
761 // dbg(0,"+#+:enter\n");
762 #endif
763
764 // JNIEnv *jnienv2;
765 // jnienv2 = jni_getenv();
766 //int thread_id = gettid();
767 //dbg(0, "THREAD ID=%d\n", thread_id);
768
769 //dbg(0,"VehicleCallback location=%p\n", location);
770 jobject location2 = (*env)->NewGlobalRef(env, location);
771 (*env)->DeleteLocalRef(env, location);
772 //// dbg(0,"location=%p\n", location2);
773
774 if ((global_navit) && (global_navit->vehicle) && (global_navit->vehicle->vehicle))
775 {
776 vehicle_update_(global_navit->vehicle->vehicle, location2);
777 }
778 else
779 {
780 dbg(0, "no vehicle set !!\n");
781 }
782
783 //dbg(0,"leave\n");
784
785 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
786 // dbg(0,"+#+:leave\n");
787 #endif
788 }
789
790 void android_return_search_result(struct jni_object *jni_o, char *str)
791 {
792 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
793 // dbg(0,"+#+:enter\n");
794 #endif
795 // dbg(0,"EEnter\n");
796
797 // int thread_id = gettid();
798 // dbg(0, "THREAD ID=%d\n", thread_id);
799
800 jstring js2 = NULL;
801 JNIEnv* env2;
802 env2 = jni_o->env;
803 js2 = (*env2)->NewStringUTF(jni_o->env, str);
804 (*env2)->CallVoidMethod(jni_o->env, jni_o->jo, jni_o->jm, js2);
805 (*env2)->DeleteLocalRef(jni_o->env, js2);
806 }
807
808 void android_return_generic_int(int id, int i)
809 {
810 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
811 // dbg(0,"+#+:enter\n");
812 #endif
813 //DBG // dbg(0,"Enter\n");
814
815 // int thread_id = gettid();
816 // dbg(0, "THREAD ID=%d\n", thread_id);
817
818 JNIEnv *jnienv2;
819 jnienv2 = jni_getenv();
820
821 if (NavitGraphicsClass2 == NULL)
822 {
823 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
824 {
825 NavitGraphicsClass2 = NULL;
826 return;
827 }
828 }
829 //DBG // dbg(0,"xx1\n");
830 if (return_generic_int == NULL)
831 {
832 android_find_static_method(NavitGraphicsClass2, "return_generic_int", "(II)V", &return_generic_int);
833 }
834 //DBG // dbg(0,"xx2\n");
835 if (return_generic_int == NULL)
836 {
837 //DBG // dbg(0, "no method found\n");
838 return; /* exception thrown */
839 }
840 //DBG // dbg(0,"xa1\n");
841 // -crash- (*jnienv2)->CallVoidMethod(jnienv2, NavitGraphicsClass2, return_generic_int, id, i);
842 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, return_generic_int, id, i);
843 // -works- (*jnienv2)->CallStaticObjectMethod(jnienv2, NavitGraphicsClass2, return_generic_int, id, i);
844 //DBG // dbg(0,"xa2\n");
845 }
846
847 JNIEXPORT void JNICALL
848 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)
849 {
850 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
851 // dbg(0,"+#+:enter\n");
852 #endif
853
854 int thread_id = gettid();
855 // dbg(0, "THREAD ID=%d\n", thread_id);
856
857 const char *s;
858 s = (*env)->GetStringUTFChars(env, str, NULL);
859 ////DBG // dbg(0,"*****string=%s\n",s);
860
861
862 config_get_attr(config, attr_navit, &attr, NULL);
863 // attr.u.navit
864
865 jstring js2 = NULL;
866 jclass cls_local = (*env)->GetObjectClass(env, thiz);
867
868 // ICS ???
869 jclass cls = (*env)->NewGlobalRef(env, cls_local);
870 // ICS ???
871
872 jmethodID aMethodID = (*env)->GetMethodID(env, cls, "fillStringArray", "(Ljava/lang/String;)V");
873 if (aMethodID == 0)
874 {
875 ////DBG // dbg(0,"**** Unable to get methodID: fillStringArray");
876 return;
877 }
878
879 if (id)
880 {
881 // search for town in variable "s" within current country -> return a list of towns as result
882 if (id == 1)
883 {
884 // unused now!!
885 }
886 // new experimental street-index search
887 else if (id == 2)
888 {
889 offline_search_break_searching = 0;
890
891 struct jni_object my_jni_object;
892 my_jni_object.env = env;
893 my_jni_object.jo = thiz;
894 my_jni_object.jm = aMethodID;
895
896 const char *s_town;
897 s_town = (*env)->GetStringUTFChars(env, str_town, NULL);
898 const char *s_hn;
899 s_hn = (*env)->GetStringUTFChars(env, str_hn, NULL);
900
901 search_v2(s, s_town, s_hn, partial, &my_jni_object);
902
903 (*env)->ReleaseStringUTFChars(env, str_town, s_town);
904 (*env)->ReleaseStringUTFChars(env, str_hn, s_hn);
905
906 }
907 // search for street in variable "s" within "search_country" -> return a list of streets as result
908 else if (id == 29)
909 {
910 //struct attr s_attr4;
911 //struct gui_priv *gp4;
912 //struct gui_priv gp_24;
913
914 offline_search_break_searching = 0;
915
916 struct jni_object my_jni_object;
917 my_jni_object.env = env;
918 my_jni_object.jo = thiz;
919 my_jni_object.jm = aMethodID;
920
921 //gp4=&gp_24;
922 //gp4->nav=attr.u.navit;
923 struct mapset *ms4 = navit_get_mapset(attr.u.navit);
924 GList *ret = NULL;
925 int flags = search_flags;
926 char *search_country_string = (*env)->GetStringUTFChars(env, search_country, NULL);
927 ret = search_by_address(ret, ms4, s, partial, &my_jni_object, flags, search_country_string);
928 (*env)->ReleaseStringUTFChars(env, search_country, search_country_string);
929
930 // free the memory
931 g_list_free(ret);
932 ////DBG // dbg(0,"ret=%p\n",ret);
933
934
935 //if (gp4->sl)
936 //{
937 // //search_list_destroy(gp4->sl);
938 // gp4->sl=NULL;
939 //}
940 }
941 // do a full search in all mapfiles for string in variable "s" -> return a list of streets as result
942 else if (id == 3)
943 {
944 const char *s3;
945 s3 = (*env)->GetStringUTFChars(env, latlon, NULL);
946 char parse_str[strlen(s3) + 1];
947 strcpy(parse_str, s3);
948 (*env)->ReleaseStringUTFChars(env, latlon, s3);
949
950 struct coord_geo g7;
951 char *p;
952 char *stopstring;
953
954 // lat
955 p = strtok(parse_str, "#");
956 g7.lat = strtof(p, &stopstring);
957 // lon
958 p = strtok(NULL, "#");
959 g7.lng = strtof(p, &stopstring);
960
961 struct jni_object my_jni_object;
962 my_jni_object.env = env;
963 my_jni_object.jo = thiz;
964 my_jni_object.jm = aMethodID;
965
966 offline_search_break_searching = 0;
967
968 // search_flags --> is search_order (search at what "order" level)
969 search_full_world(s, partial, search_flags, &my_jni_object, &g7, radius);
970 }
971 }
972
973 (*env)->ReleaseStringUTFChars(env, str, s);
974 }
975
976 JNIEXPORT jint JNICALL
977 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackDestinationValid(JNIEnv* env, jobject thiz)
978 {
979 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
980 // dbg(0,"+#+:enter\n");
981 #endif
982 //DBG // dbg(0,"EEnter\n");
983 config_get_attr(config, attr_navit, &attr, NULL);
984 // //DBG // dbg(0,"destination_valid=%d\n",attr.u.navit->destination_valid);
985 jint i = 0;
986 if (attr.u.navit->route)
987 {
988 struct route *r;
989 r = attr.u.navit->route;
990 i = r->route_status;
991 // //DBG // dbg(0,"route_status=%d\n",i);
992 }
993 return i;
994 }
995
996 static void map_preview_label_line(struct point *p, int count, char *label, int font_size)
997 {
998 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
999 // dbg(0,"+#+:enter\n");
1000 #endif
1001 int i, x, y, tl, tlm, th, thm, tlsq, l;
1002 float lsq;
1003 double dx, dy;
1004 struct point p_t;
1005 struct point pb[5];
1006
1007 int len = g_utf8_strlen(label, -1);
1008 int xMin = 0;
1009 int yMin = 0;
1010 int yMax = 13 * font_size / 256;
1011 int xMax = 9 * font_size * len / 256;
1012
1013 ////DBG // dbg(0,"xMax=%d\n", xMax);
1014 ////DBG // dbg(0,"yMax=%d\n", yMax);
1015
1016 pb[0].x = xMin;
1017 pb[0].y = -yMin;
1018 pb[1].x = xMin;
1019 pb[1].y = -yMax;
1020 pb[2].x = xMax;
1021 pb[2].y = -yMax;
1022 pb[3].x = xMax;
1023 pb[3].y = -yMin;
1024
1025 tl = (pb[2].x - pb[0].x);
1026 th = (pb[0].y - pb[1].y);
1027
1028 // calc "tl" text length
1029 // tl=strlen(label)*4;
1030 // calc "th" text height
1031 // th=8;
1032
1033 tlm = tl * 32;
1034 thm = th * 36;
1035 tlsq = (tlm * 0.7) * (tlm * 0.7);
1036
1037 for (i = 0; i < count - 1; i++)
1038 {
1039 dx = p[i + 1].x - p[i].x;
1040 dx *= 32;
1041 dy = p[i + 1].y - p[i].y;
1042 dy *= 32;
1043 lsq = dx * dx + dy * dy;
1044
1045 if (lsq > tlsq)
1046 {
1047 ////DBG // dbg(0,"-------- label=%s\n",label);
1048 ////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);
1049 ////DBG // dbg(0,"dx=%f dy=%f\n",dx,dy);
1050 l = (int) sqrtf(lsq);
1051 ////DBG // dbg(0,"l=%d lsq=%f\n",l,lsq);
1052 x = p[i].x;
1053 y = p[i].y;
1054 if (dx < 0)
1055 {
1056 dx = -dx;
1057 dy = -dy;
1058 x = p[i + 1].x;
1059 y = p[i + 1].y;
1060 }
1061 x += (l - tlm) * dx / l / 64;
1062 y += (l - tlm) * dy / l / 64;
1063 x -= dy * thm / l / 64;
1064 y += dx * thm / l / 64;
1065 p_t.x = x;
1066 p_t.y = y;
1067
1068 ////DBG // dbg(0,"dx=%f dy=%f\n",dx,dy);
1069 ////DBG // dbg(0,"dx=%d dy=%d\n",(int)dx,(int)dy);
1070 ////DBG // dbg(0,"draw px=%d py=%d\n",p_t.x,p_t.y);
1071 ////DBG // dbg(0,"l=%d\n",l);
1072 ////DBG // dbg(0,"+++++++++++++\n");
1073 // **OLD and wrong** android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, dx*0x10000/l, dy*0x10000/l);
1074 android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, (int) dx, (int) dy);
1075 }
1076 }
1077 }
1078
1079 JNIEXPORT void JNICALL
1080 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)
1081 {
1082 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1083 // dbg(0,"+#+:enter\n");
1084 #endif
1085 // config_get_attr(config, attr_navit, &attr, NULL);
1086
1087 const char *s;
1088 int zoom;
1089 s = (*env)->GetStringUTFChars(env, latlonzoom, NULL);
1090 char parse_str[strlen(s) + 1];
1091 strcpy(parse_str, s);
1092 (*env)->ReleaseStringUTFChars(env, latlonzoom, s);
1093 ////DBG // dbg(0,"*****string=%s\n",s);
1094
1095 // show map preview for (lat#lon#zoom)
1096 struct coord_geo g;
1097 char *p;
1098 char *stopstring;
1099
1100 // lat
1101 p = strtok(parse_str, "#");
1102 g.lat = strtof(p, &stopstring);
1103 // lon
1104 p = strtok(NULL, "#");
1105 g.lng = strtof(p, &stopstring);
1106 // zoom
1107 p = strtok(NULL, "#");
1108 zoom = atoi(p);
1109
1110 ////DBG // dbg(0,"lat=%f\n",g.lat);
1111 ////DBG // dbg(0,"lng=%f\n",g.lng);
1112 ////DBG // dbg(0,"zoom=%d\n",zoom);
1113 ////DBG // dbg(0,"w=%d\n",width);
1114 ////DBG // dbg(0,"h=%d\n",height);
1115
1116 struct coord c;
1117 transform_from_geo(projection_mg, &g, &c);
1118
1119 // struct pcoord pc;
1120 // pc.x=c.x;
1121 // pc.y=c.y;
1122 // pc.pro=projection_mg;
1123
1124
1125 // ----------------------- big draw loop -----------------------
1126 // ----------------------- big draw loop -----------------------
1127 // ----------------------- big draw loop -----------------------
1128 // ----------------------- big draw loop -----------------------
1129 struct item *item;
1130 struct map_rect *mr = NULL;
1131 struct mapset *ms;
1132 struct mapset_handle *msh;
1133 struct map* map = NULL;
1134 struct attr map_name_attr;
1135 struct attr attr;
1136
1137 struct map_selection sel;
1138 const int selection_range = sel_range; // should be something with "width" and "height" i guess ??!!
1139
1140 const int max = 100;
1141 int count;
1142 struct coord *ca = g_alloca(sizeof(struct coord) * max);
1143 struct point *pa = g_alloca(sizeof(struct point) * max);
1144
1145 sel.next = NULL;
1146 sel.order = zoom;
1147 sel.range.min = type_none;
1148 sel.range.max = type_last;
1149 sel.u.c_rect.lu.x = c.x - selection_range;
1150 sel.u.c_rect.lu.y = c.y + selection_range;
1151 sel.u.c_rect.rl.x = c.x + selection_range;
1152 sel.u.c_rect.rl.y = c.y - selection_range;
1153
1154 struct transformation *tr;
1155 tr = transform_dup(global_navit->trans);
1156 struct point p_center;
1157 p_center.x = width / 2;
1158 p_center.y = height / 2;
1159 transform_set_screen_center(tr, &p_center);
1160 transform_set_center(tr, &c);
1161 transform_set_scale(tr, scale);
1162 enum projection pro = transform_get_projection(global_navit->trans_cursor);
1163
1164 ms = global_navit->mapsets->data;
1165 msh = mapset_open(ms);
1166 while (msh && (map = mapset_next(msh, 0)))
1167 {
1168 if (map_get_attr(map, attr_name, &map_name_attr, NULL))
1169 {
1170 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
1171 {
1172 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/borders.bin", map_name_attr.u.str, 41) == 0)
1173 {
1174 // country borders
1175 // //DBG // dbg(0,"map name=%s",map_name_attr.u.str);
1176 mr = map_rect_new(map, NULL);
1177 if (mr)
1178 {
1179 while ((item = map_rect_get_item(mr)))
1180 {
1181
1182 // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
1183 count = item_coord_get_within_selection(item, ca, max, &sel);
1184 if (!count)
1185 {
1186 continue;
1187 }
1188 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
1189
1190 // //DBG // dbg(0,"uu %s\n",item_to_name(item->type));
1191
1192 if (item->type == type_border_country)
1193 {
1194 // //DBG // dbg(0,"BB** %s\n",item_to_name(item->type));
1195 android_DrawMapPreview_polyline(pa, count, 2);
1196 }
1197 }
1198 map_rect_destroy(mr);
1199 }
1200 }
1201 else if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0)
1202 {
1203 // its an sdcard map
1204 // //DBG // dbg(0,"map name=%s",map_name_attr.u.str);
1205 mr = map_rect_new(map, &sel);
1206 if (mr)
1207 {
1208 //char *streetname_last=NULL;
1209
1210 while ((item = map_rect_get_item(mr)))
1211 {
1212 int label_count = 0;
1213 char *labels[2];
1214
1215 // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
1216 count = item_coord_get_within_selection(item, ca, max, &sel);
1217
1218 // count=item_coord_get_within_selection(item, ca, max, &sel);
1219 // count=item_coord_get(item, ca, item->type < type_line ? 1: max);
1220 if (!count)
1221 {
1222 continue;
1223 }
1224 ////DBG // dbg(0,"count 1=%d\n", count);
1225
1226 if (count == max)
1227 {
1228 ////DBG // dbg(0,"count overflow!!\n");
1229 }
1230
1231 struct attr attr_77;
1232 if (item_attr_get(item, attr_flags, &attr_77))
1233 {
1234 ////DBG // dbg(0,"uuuuuuuuuuuuu %s uuuuu %d\n",item_to_name(item->type), attr_77.u.num);
1235 item->flags = attr_77.u.num;
1236 }
1237 else
1238 {
1239 item->flags = 0;
1240 }
1241
1242 //if (item_is_street(*item))
1243 //{
1244 // int i3;
1245 // for (i3 = 0 ; i3 < count ; i3++)
1246 // {
1247 // if (i3)
1248 // {
1249 // //DBG // dbg(0,"1 x1=%d\n",ca[i3-1].x);
1250 // //DBG // dbg(0,"1 y1=%d\n",ca[i3-1].y);
1251 // //DBG // dbg(0,"1 x2=%d\n",ca[i3].x);
1252 // //DBG // dbg(0,"1 y2=%d\n",ca[i3].y);
1253 // }
1254 // }
1255 //}
1256
1257 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
1258
1259 ////DBG // dbg(0,"count 2=%d\n", count);
1260
1261 // --- LABEL ---
1262 labels[1] = NULL;
1263 label_count = 0;
1264 if (item_attr_get(item, attr_label, &attr))
1265 {
1266 labels[0] = attr.u.str;
1267 ////DBG // dbg(0,"labels[0]=%s\n",attr.u.str);
1268 if (!label_count)
1269 {
1270 label_count = 2;
1271 }
1272 }
1273 else
1274 {
1275 labels[0] = NULL;
1276 }
1277 // --- LABEL ---
1278
1279 if (item_is_street(*item))
1280 {
1281 //int i3;
1282 //for (i3 = 0 ; i3 < count ; i3++)
1283 //{
1284 // if (i3)
1285 // {
1286 // //DBG // dbg(0,"2 x1=%d\n",pa[i3-1].x);
1287 // //DBG // dbg(0,"2 y1=%d\n",pa[i3-1].y);
1288 // //DBG // dbg(0,"2 x2=%d\n",pa[i3].x);
1289 // //DBG // dbg(0,"2 y2=%d\n",pa[i3].y);
1290 // }
1291 //}
1292 android_DrawMapPreview_polyline(pa, count, 0);
1293 if (labels[0] != NULL)
1294 {
1295 map_preview_label_line(pa, count, labels[0], font_size);
1296 }
1297 }
1298 else if (item_is_district(*item))
1299 {
1300 if (zoom > 6)
1301 {
1302 // //DBG // dbg(0,"xx** %s - %s\n",item_to_name(item->type),labels[0]);
1303 if (count >= 1)
1304 {
1305 android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size * 2, 0x10000, 0);
1306 }
1307 }
1308 }
1309 else if (item_is_town(*item))
1310 {
1311 // //DBG // dbg(0,"yy** %s - %s\n",item_to_name(item->type),labels[0]);
1312 if (count >= 1)
1313 {
1314 android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size * 3, 0x10000, 0);
1315 }
1316 }
1317
1318 //if (item_is_street(*item))
1319 //{
1320 // if (item_attr_get(item, attr_label, &attr))
1321 // {
1322 // ////DBG // dbg(0,"street1=%s\n",map_convert_string(item->map, attr.u.str));
1323 // if ( (streetname_last==NULL) || (strcmp(streetname_last,attr.u.str) != 0) )
1324 // {
1325 // ////DBG // dbg(0,"street2=%s\n",map_convert_string(item->map, attr.u.str));
1326 // }
1327 // }
1328 //}
1329 }
1330 //g_free(streetname_last);
1331 map_rect_destroy(mr);
1332 }
1333 }
1334 }
1335 }
1336 }
1337 mapset_close(msh);
1338
1339 enum projection pro2 = transform_get_projection(global_navit->trans_cursor);
1340 struct point pnt;
1341 transform(tr, pro2, &c, &pnt, 1, 0, 0, NULL);
1342 transform_destroy(tr);
1343 // ----------------------- big draw loop -----------------------
1344 // ----------------------- big draw loop -----------------------
1345 // ----------------------- big draw loop -----------------------
1346 // ----------------------- big draw loop -----------------------
1347
1348 android_DrawMapPreview_target(pnt.x, pnt.y);
1349 }
1350
1351 void android_DrawMapPreview_target(int x, int y)
1352 {
1353 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1354 // dbg(0,"+#+:enter\n");
1355 #endif
1356
1357 JNIEnv *jnienv2;
1358 jnienv2 = jni_getenv();
1359
1360 if (NavitMapPreviewActivityClass == NULL)
1361 {
1362 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1363 {
1364 NavitMapPreviewActivityClass = NULL;
1365 return;
1366 }
1367 }
1368 if (DrawMapPreview_target == NULL)
1369 {
1370 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_target", "(II)V", &DrawMapPreview_target);
1371 }
1372 if (DrawMapPreview_target == NULL)
1373 {
1374 //DBG // dbg(0, "no method found\n");
1375 return; /* exception thrown */
1376 }
1377 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_target, x, y);
1378 }
1379
1380 void android_DrawMapPreview_text(int x, int y, char *text, int size, int dx, int dy)
1381 {
1382 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1383 // dbg(0,"+#+:enter\n");
1384 #endif
1385
1386 JNIEnv *jnienv2;
1387 jnienv2 = jni_getenv();
1388
1389 if (NavitMapPreviewActivityClass == NULL)
1390 {
1391 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1392 {
1393 NavitMapPreviewActivityClass = NULL;
1394 return;
1395 }
1396 }
1397 if (DrawMapPreview_text == NULL)
1398 {
1399 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_text", "(IILjava/lang/String;III)V", &DrawMapPreview_text);
1400 }
1401 if (DrawMapPreview_text == NULL)
1402 {
1403 //DBG // dbg(0, "no method found\n");
1404 return; /* exception thrown */
1405 }
1406
1407 ////DBG // dbg(0,"** dx=%d,dy=%d\n",dx,dy);
1408
1409 jstring string1 = (*jnienv2)->NewStringUTF(jnienv2, text);
1410 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_text, x, y, string1, size, dx, dy);
1411 (*jnienv2)->DeleteLocalRef(jnienv2, string1);
1412 }
1413
1414 void android_DrawMapPreview_polyline(struct point *p, int count, int type)
1415 {
1416 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1417 // dbg(0,"+#+:enter\n");
1418 #endif
1419 // type:
1420 // 0 -> normal street
1421 // 2 -> country border
1422
1423 JNIEnv *jnienv2;
1424 jnienv2 = jni_getenv();
1425
1426 if (NavitMapPreviewActivityClass == NULL)
1427 {
1428 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1429 {
1430 NavitMapPreviewActivityClass = NULL;
1431 return;
1432 }
1433 }
1434 if (DrawMapPreview_polyline == NULL)
1435 {
1436 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_polyline", "(I[I)V", &DrawMapPreview_polyline);
1437 }
1438 if (DrawMapPreview_polyline == NULL)
1439 {
1440 //DBG // dbg(0, "no method found\n");
1441 return; /* exception thrown */
1442 }
1443
1444 jint pc[count * 2];
1445 int i;
1446 jintArray points;
1447 if (count <= 0)
1448 {
1449 return;
1450 }
1451 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
1452 for (i = 0; i < count; i++)
1453 {
1454 pc[i * 2] = p[i].x;
1455 pc[i * 2 + 1] = p[i].y;
1456 }
1457 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
1458 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_polyline, type, points);
1459 (*jnienv2)->DeleteLocalRef(jnienv2, points);
1460 }
1461
1462 JNIEXPORT jstring JNICALL
1463 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackGeoCalc(JNIEnv* env, jobject thiz, int i, float a, float b)
1464 {
1465 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1466 // dbg(0,"+#+:enter\n");
1467 #endif
1468 // dbg(0,"EEnter i=%d\n", i);
1469
1470 int thread_id = gettid();
1471 // dbg(0, "THREAD ID=%d\n", thread_id);
1472
1473 // const char *result;
1474 gchar *result;
1475
1476 if (i == 1)
1477 {
1478 // pixel-on-screen to geo
1479 struct coord_geo g22;
1480 struct coord c22;
1481 struct point p;
1482 p.x = a;
1483 p.y = b;
1484 transform_reverse(global_navit->trans, &p, &c22);
1485 ////DBG // dbg(0,"%f, %f\n",a, b);
1486 ////DBG // dbg(0,"%d, %d\n",p.x, p.y);
1487 transform_to_geo(projection_mg, &c22, &g22);
1488 ////DBG // dbg(0,"%d, %d, %f, %f\n",c22.x, c22.y, g22.lat, g22.lng);
1489 result = g_strdup_printf("%f:%f", g22.lat, g22.lng);
1490 }
1491 else if (i == 2)
1492 {
1493 // geo to pixel-on-screen
1494 struct coord c99;
1495 struct coord_geo g99;
1496 g99.lat = a;
1497 g99.lng = b;
1498 ////DBG // dbg(0,"zzzzz %f, %f\n",a, b);
1499 ////DBG // dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1500 transform_from_geo(projection_mg, &g99, &c99);
1501 ////DBG // dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1502
1503 enum projection pro = transform_get_projection(global_navit->trans_cursor);
1504 struct point pnt;
1505 transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
1506 ////DBG // dbg(0,"x=%d\n",pnt.x);
1507 ////DBG // dbg(0,"y=%d\n",pnt.y);
1508
1509 result = g_strdup_printf("%d:%d", pnt.x, pnt.y);
1510 }
1511 else if (i == 3)
1512 {
1513 // show lat,lng position on screen center
1514 struct coord c99;
1515 struct pcoord pc99;
1516 struct coord_geo g99;
1517 g99.lat = a;
1518 g99.lng = b;
1519 ////DBG // dbg(0,"zzzzz %f, %f\n",a, b);
1520 ////DBG // dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1521 transform_from_geo(projection_mg, &g99, &c99);
1522 ////DBG // dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1523
1524 //enum projection pro=transform_get_projection(global_navit->trans_cursor);
1525 //struct point pnt;
1526 //transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
1527 ////DBG // dbg(0,"x=%d\n",pnt.x);
1528 ////DBG // dbg(0,"y=%d\n",pnt.y);
1529 pc99.x = c99.x;
1530 pc99.y = c99.y;
1531 pc99.pro = projection_mg;
1532
1533 navit_set_center(global_navit, &pc99, 0);
1534
1535 result = g_strdup_printf("1:1");
1536 }
1537 else if (i == 4)
1538 {
1539 // return current target (the end point, not waypoints)
1540 struct coord_geo g22;
1541 struct pcoord c22;
1542 struct coord c99;
1543
1544 c22 = global_navit->destination;
1545 c99.x = c22.x;
1546 c99.y = c22.y;
1547
1548 transform_to_geo(projection_mg, &c99, &g22);
1549 result = g_strdup_printf("%f:%f", g22.lat, g22.lng);
1550 }
1551 else if (i == 5)
1552 {
1553 // input: x,y pixel on screen
1554 // output: streetname nearest that position
1555 struct coord c22;
1556 struct point p;
1557 struct pcoord c24;
1558 p.x = a;
1559 p.y = b;
1560 transform_reverse(global_navit->trans, &p, &c22);
1561 c24.x = c22.x;
1562 c24.y = c22.y;
1563 c24.pro = transform_get_projection(global_navit->trans);
1564 result = navit_find_nearest_street(global_navit->mapsets->data, &c24);
1565 }
1566 else if (i == 6)
1567 {
1568 // input: lat, lon
1569 // output: streetname nearest that position
1570 struct coord c22;
1571 struct point p;
1572 struct pcoord c24;
1573 struct coord_geo g99;
1574 g99.lat = a;
1575 g99.lng = b;
1576 transform_from_geo(projection_mg, &g99, &c22);
1577 c24.x = c22.x;
1578 c24.y = c22.y;
1579 c24.pro = transform_get_projection(global_navit->trans);
1580 result = navit_find_nearest_street(global_navit->mapsets->data, &c24);
1581 }
1582 else if (i == 7)
1583 {
1584 // input: x,y pixel on screen
1585 // output: 0xFFFF 0xFFFF\n... -> string that can be used for traffic distortion file
1586 struct coord c22;
1587 struct point p;
1588 struct pcoord c24;
1589 p.x = a;
1590 p.y = b;
1591 transform_reverse(global_navit->trans, &p, &c22);
1592 c24.x = c22.x;
1593 c24.y = c22.y;
1594 c24.pro = transform_get_projection(global_navit->trans);
1595 result = navit_find_nearest_street_coords(global_navit->mapsets->data, &c24);
1596 }
1597 else if (i == 8)
1598 {
1599 // input: x,y pixel on screen
1600 // output: nearest street or housenumber
1601 struct coord c22;
1602 struct point p;
1603 struct pcoord c24;
1604 p.x = a;
1605 p.y = b;
1606 transform_reverse(global_navit->trans, &p, &c22);
1607 c24.x = c22.x;
1608 c24.y = c22.y;
1609 c24.pro = transform_get_projection(global_navit->trans);
1610 result = navit_find_nearest_street_hn(global_navit->mapsets->data, &c24);
1611 }
1612 else if (i == 9)
1613 {
1614 // input: x,y pixel on screen
1615 // output: item dump of nearest item
1616 struct coord c22;
1617 struct point p;
1618 struct pcoord c24;
1619 p.x = a;
1620 p.y = b;
1621 transform_reverse(global_navit->trans, &p, &c22);
1622 c24.x = c22.x;
1623 c24.y = c22.y;
1624 c24.pro = transform_get_projection(global_navit->trans);
1625 result = navit_find_nearest_item_dump(global_navit->mapsets->data, &c24, 0);
1626 }
1627 else if (i == 10)
1628 {
1629 // input: x,y pixel on screen
1630 // output: item dump of nearest item (pretty output to show to user)
1631 struct coord c22;
1632 struct point p;
1633 struct pcoord c24;
1634 p.x = a;
1635 p.y = b;
1636 transform_reverse(global_navit->trans, &p, &c22);
1637 c24.x = c22.x;
1638 c24.y = c22.y;
1639 c24.pro = transform_get_projection(global_navit->trans);
1640 result = navit_find_nearest_item_dump(global_navit->mapsets->data, &c24, 1);
1641 }
1642 else if (i == 11)
1643 {
1644 // coord to pixel-on-screen
1645 struct coord c99;
1646 c99.x = a;
1647 c99.y = b;
1648 struct point pnt;
1649 transform(global_navit->trans, projection_mg, &c99, &pnt, 1, 0, 0, NULL);
1650 result = g_strdup_printf("%d:%d", pnt.x, pnt.y);
1651 }
1652
1653 // // dbg(0, "result=%s\n", result);
1654 jstring js = (*env)->NewStringUTF(env, result);
1655 g_free(result);
1656
1657 return js;
1658 }
1659
1660 JNIEXPORT jstring JNICALL
1661 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackLocalizedString(JNIEnv* env, jobject thiz, jobject str)
1662 {
1663 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1664 // dbg(0,"+#+:enter\n");
1665 #endif
1666 // // dbg(0,"EEnter\n");
1667
1668 int thread_id = gettid();
1669 // dbg(0, "THREAD ID=%d\n", thread_id);
1670
1671 const char *s;
1672 const char *localized_str;
1673
1674 s = (*env)->GetStringUTFChars(env, str, NULL);
1675 ////DBG // dbg(0,"*****string=%s\n",s);
1676
1677 localized_str = gettext(s);
1678 ////DBG // dbg(0,"localized string=%s",localized_str);
1679
1680 // jstring dataStringValue = (jstring) localized_str;
1681 jstring js = (*env)->NewStringUTF(env, localized_str);
1682
1683 (*env)->ReleaseStringUTFChars(env, str, s);
1684
1685 return js;
1686 }
1687
1688 JNIEXPORT jint JNICALL
1689 Java_com_zoffcc_applications_zanavi_NavitGraphics_GetThreadId(JNIEnv* env, jobject thiz)
1690 {
1691 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1692 // dbg(0,"+#+:enter\n");
1693 #endif
1694
1695 int thread_id = gettid();
1696 // // dbg(0, "THREAD ID=%d\n", thread_id);
1697
1698 jint i = thread_id;
1699 return i;
1700 }
1701
1702 JNIEXPORT void JNICALL
1703 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackMessageChannelReal(JNIEnv* env, jobject thiz, int i, jobject str2)
1704 {
1705 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1706 // dbg(0,"+#+:enter\n");
1707 #endif
1708
1709 int thread_id = gettid();
1710 // dbg(0, "THREAD ID=%d\n", thread_id);
1711
1712 const char *s;
1713 jobject str = (*env)->NewGlobalRef(env, str2);
1714
1715 // dbg(0,"enter %d\n",i);
1716
1717 config_get_attr(config, attr_navit, &attr, NULL);
1718 // attr.u.navit
1719
1720 //DBG // dbg(0,"c1\n");
1721
1722 if (i)
1723 {
1724 if (i == 1)
1725 {
1726 // zoom in
1727 navit_zoom_in_cursor(global_navit, 2);
1728 // navit_zoom_in_cursor(attr.u.navit, 2);
1729 }
1730 else if (i == 2)
1731 {
1732 // zoom out
1733 navit_zoom_out_cursor(global_navit, 2);
1734 // navit_zoom_out_cursor(attr.u.navit, 2);
1735 }
1736 else if (i == 79)
1737 {
1738 // set traffic light delay
1739 s = (*env)->GetStringUTFChars(env, str, NULL);
1740 global_traffic_light_delay = atoi(s);
1741 (*env)->ReleaseStringUTFChars(env, str, s);
1742 }
1743 else if (i == 78)
1744 {
1745 // shift layout "order" values
1746 s = (*env)->GetStringUTFChars(env, str, NULL);
1747 displaylist_shift_order_in_map_layers(global_navit, atoi(s));
1748 (*env)->ReleaseStringUTFChars(env, str, s);
1749 }
1750 else if (i == 77)
1751 {
1752 // do not show route rectangles
1753 global_show_route_rectangles = 0;
1754 }
1755 else if (i == 76)
1756 {
1757 // show route rectangles
1758 global_show_route_rectangles = 1;
1759 }
1760 else if (i == 75)
1761 {
1762 // stop demo vechile
1763 global_stop_demo_vehicle = 1;
1764 }
1765 else if (i == 74)
1766 {
1767 // allow demo vechile to move
1768 global_stop_demo_vehicle = 0;
1769 }
1770 else if (i == 73)
1771 {
1772 // update the route path and route graph (e.g. after setting new roadblocks)
1773 // this destroys the route graph and calcs everything totally new!
1774 if (global_navit->route)
1775 {
1776 if (global_navit->route->destinations)
1777 {
1778 route_path_update(global_navit->route, 1, 1);
1779 }
1780 }
1781 }
1782 else if (i == 72)
1783 {
1784 // update the route path and route graph (e.g. after setting new roadblocks)
1785 // does not update destinations!!!
1786 if (global_navit->route)
1787 {
1788 if (global_navit->route->destinations)
1789 {
1790 route_path_update(global_navit->route, 0, 1);
1791 }
1792 }
1793 }
1794 else if (i == 71)
1795 {
1796 // activate/deactivate "route graph" display
1797 // 0 -> deactivate
1798 // 1 -> activate
1799
1800 // _ms_route_graph
1801 // _ms_navigation
1802 s = (*env)->GetStringUTFChars(env, str, NULL);
1803 navit_map_active_flag(global_navit, atoi(s), "_ms_route_graph");
1804 (*env)->ReleaseStringUTFChars(env, str, s);
1805 }
1806 else if (i == 70)
1807 {
1808 // allow drawing map
1809 hold_drawing = 0;
1810 }
1811 else if (i == 69)
1812 {
1813 // stop drawing map
1814 hold_drawing = 1;
1815 }
1816 else if (i == 68)
1817 {
1818 // shift "order" by this value (only for drawing objects)
1819 s = (*env)->GetStringUTFChars(env, str, NULL);
1820 shift_order = atoi(s);
1821 (*env)->ReleaseStringUTFChars(env, str, s);
1822 }
1823 else if (i == 67)
1824 {
1825 // disable "multipolygons"
1826 global_draw_multipolygons = 0;
1827 }
1828 else if (i == 66)
1829 {
1830 // enable "multipolygons"
1831 global_draw_multipolygons = 1;
1832 }
1833 else if (i == 65)
1834 {
1835 // draw map async
1836 navit_draw_async(global_navit, 1);
1837 }
1838 else if (i == 64)
1839 {
1840 // draw map
1841 navit_draw(global_navit);
1842 }
1843 else if (i == 63)
1844 {
1845 // enable map drawing
1846 disable_map_drawing = 0;
1847 }
1848 else if (i == 62)
1849 {
1850 // disable map drawing
1851 disable_map_drawing = 1;
1852 }
1853 else if (i == 61)
1854 {
1855 // zoom to specific zoomlevel at given point as center
1856 struct point p;
1857 char *pstr;
1858
1859 s = (*env)->GetStringUTFChars(env, str, NULL);
1860 char parse_str[strlen(s) + 1];
1861 strcpy(parse_str, s);
1862 (*env)->ReleaseStringUTFChars(env, str, s);
1863 // (pixel-x#pixel-y#zoom-level)
1864 // pixel-x
1865 pstr = strtok(parse_str, "#");
1866 p.x = atoi(pstr);
1867 // pixel-y
1868 pstr = strtok(NULL, "#");
1869 p.y = atoi(pstr);
1870 // zoom
1871 pstr = strtok(NULL, "#");
1872 int zoom_level = atoi(pstr);
1873 // now call zoom function
1874 navit_zoom_to_scale_with_center_point(global_navit, zoom_level, &p);
1875 }
1876 else if (i == 60)
1877 {
1878 // disable layer "name"
1879 s = (*env)->GetStringUTFChars(env, str, NULL);
1880 navit_layer_set_active(global_navit, s, 0, 0);
1881 (*env)->ReleaseStringUTFChars(env, str, s);
1882 }
1883 else if (i == 59)
1884 {
1885 // enable layer "name"
1886 s = (*env)->GetStringUTFChars(env, str, NULL);
1887 navit_layer_set_active(global_navit, s, 1, 0);
1888 (*env)->ReleaseStringUTFChars(env, str, s);
1889 }
1890 else if (i == 58)
1891 {
1892 // make street search radius bigger to the factor "s"
1893 s = (*env)->GetStringUTFChars(env, str, NULL);
1894 global_search_street_size_factor = atoi(s);
1895 (*env)->ReleaseStringUTFChars(env, str, s);
1896 }
1897 else if (i == 57)
1898 {
1899 // keep drawing streets as if at "order" level xxx
1900 s = (*env)->GetStringUTFChars(env, str, NULL);
1901 limit_order_corrected = atoi(s);
1902 (*env)->ReleaseStringUTFChars(env, str, s);
1903 }
1904 else if (i == 56)
1905 {
1906 // draw polylines with/without circles at the end
1907 //// dbg(0, "dpf1\n");
1908 s = (*env)->GetStringUTFChars(env, str, NULL);
1909 //// dbg(0, "dpf2\n");
1910 draw_polylines_fast = atoi(s);
1911 //// dbg(0, "dpf=%d\n", draw_polylines_fast);
1912 (*env)->ReleaseStringUTFChars(env, str, s);
1913 }
1914 else if (i == 55)
1915 {
1916 // set cache size for (map-)files
1917 //// dbg(0, "csf1\n");
1918 s = (*env)->GetStringUTFChars(env, str, NULL);
1919 //// dbg(0, "csf2\n");
1920 cache_size_file = atoi(s);
1921 file_cache_init();
1922 // dbg(0, "csf=%d\n", cache_size_file);
1923 (*env)->ReleaseStringUTFChars(env, str, s);
1924 }
1925 else if (i == 54)
1926 {
1927 // speak streetnames
1928 global_speak_streetnames = 1;
1929 }
1930 else if (i == 53)
1931 {
1932 // dont speak streetnames
1933 global_speak_streetnames = 0;
1934 }
1935 else if (i == 52)
1936 {
1937 // switch to demo vehicle
1938
1939 s = (*env)->GetStringUTFChars(env, str, NULL);
1940
1941 if (global_navit->vehicle)
1942 {
1943 navit_remove_cursors(global_navit);
1944 vehicle_destroy(global_navit->vehicle->vehicle);
1945 global_navit->vehicles = NULL;
1946 global_navit->vehicle = NULL;
1947 }
1948
1949 struct attr parent;
1950 struct attr source;
1951 struct attr active;
1952 struct attr follow;
1953 struct attr speed;
1954 struct attr interval;
1955 struct attr *attrs[6];
1956 parent.type = attr_navit;
1957 parent.u.navit = global_navit;
1958
1959 source.type = attr_source;
1960 source.u.str = "demo://";
1961
1962 active.type = attr_active;
1963 active.u.num = 1;
1964
1965 follow.type = attr_follow;
1966 follow.u.num = 1;
1967
1968 speed.type = attr_speed;
1969 speed.u.num = atoi(s);
1970
1971 interval.type = attr_interval;
1972 interval.u.num = 1000; // 1 sec.
1973 // interval.u.num = 5000; // 5 sec.
1974
1975 attrs[0] = &source;
1976 attrs[1] = &active;
1977 attrs[2] = &follow;
1978 attrs[3] = &speed;
1979 attrs[4] = &interval;
1980 attrs[5] = NULL;
1981 // attr_source -> source->u.str='demo://'
1982 // <!-- vehicle name="Demo" profilename="car" enabled="no" active="yes" source="demo://" -->
1983 struct vehicle *v;
1984 //DBG // dbg(0, "demo vehicle new start\n");
1985 v = vehicle_new(&parent, attrs);
1986 //DBG // dbg(0, "demo vehicle new end\n");
1987
1988 if (v != NULL)
1989 {
1990 //DBG // dbg(0, "adding demo vehicle\n");
1991 navit_add_vehicle(global_navit, v);
1992 //DBG // dbg(0, "setting cursor\n");
1993 navit_set_cursors(global_navit);
1994
1995 struct attr follow2;
1996 follow2.type = attr_follow;
1997 follow2.u.num = 1;
1998 navit_set_attr(global_navit, &follow2);
1999
2000 // switch "Map follows Vehicle" ON
2001 struct attr attrx;
2002 attrx.type = attr_follow_cursor;
2003 attrx.u.num = 1;
2004 navit_set_attr(global_navit, &attrx);
2005 }
2006 else
2007 {
2008 //DBG // dbg(0, "ERROR adding demo vehicle\n");
2009 }
2010 // **no** navit_set_vehicle(global_navit, global_navit->vehicle);
2011 //DBG // dbg(0, "ready\n");
2012
2013 (*env)->ReleaseStringUTFChars(env, str, s);
2014 }
2015 else if (i == 51)
2016 {
2017 // set position to pixel x,y
2018 //DBG // dbg(0, "sp 1\n");
2019 char *pstr;
2020 struct point p;
2021 struct coord c;
2022 struct pcoord pc;
2023
2024 s = (*env)->GetStringUTFChars(env, str, NULL);
2025 char parse_str[strlen(s) + 1];
2026 strcpy(parse_str, s);
2027 (*env)->ReleaseStringUTFChars(env, str, s);
2028
2029 // (pixel-x#pixel-y)
2030 // pixel-x
2031 pstr = strtok(parse_str, "#");
2032 p.x = atoi(pstr);
2033 // pixel-y
2034 pstr = strtok(NULL, "#");
2035 p.y = atoi(pstr);
2036
2037 //DBG // dbg(0, "sp 2\n");
2038 transform_reverse(global_navit->trans, &p, &c);
2039 //DBG // dbg(0, "sp 3\n");
2040
2041 pc.x = c.x;
2042 pc.y = c.y;
2043 //DBG // dbg(0, "sp 4\n");
2044 pc.pro = transform_get_projection(global_navit->trans);
2045 //DBG // dbg(0, "sp 5\n");
2046
2047 //DBG // dbg(0, "%d %d\n", pc.x, pc.y);
2048 // set position
2049 //DBG // dbg(0, "sp 6\n");
2050 navit_set_position(global_navit, &pc);
2051 //DBG // dbg(0, "ready\n");
2052 }
2053 else if (i == 50)
2054 {
2055 // we request to stop drawing the map
2056 // dbg(0, "DO__DRAW:cancel_drawing_global=1\n");
2057 cancel_drawing_global = 1;
2058 }
2059 else if (i == 47)
2060 {
2061 // change maps data dir
2062 s = (*env)->GetStringUTFChars(env, str, NULL);
2063 navit_maps_dir = g_strdup(s);
2064 (*env)->ReleaseStringUTFChars(env, str, s);
2065 // //DBG // dbg(0,"*****string use=%s\n",navit_maps_dir);
2066 }
2067 else if (i == 46)
2068 {
2069 // stop searching and show results found until now
2070 offline_search_break_searching = 1;
2071 }
2072 else if (i == 45)
2073 {
2074 // filter duplicates in search results
2075 offline_search_filter_duplicates = 1;
2076 }
2077 else if (i == 44)
2078 {
2079 // show duplicates in search results
2080 offline_search_filter_duplicates = 0;
2081 }
2082 else if (i == 43)
2083 {
2084 // routing mode "normal roads"
2085 routing_mode = 1;
2086 }
2087 else if (i == 42)
2088 {
2089 // routing mode "highways"
2090 routing_mode = 0;
2091 }
2092 else if (i == 41)
2093 {
2094 // switch "Map follows Vehicle" OFF
2095 struct attr attrx;
2096 attrx.type = attr_follow_cursor;
2097 attrx.u.num = 0;
2098 navit_set_attr(global_navit, &attrx);
2099 }
2100 else if (i == 40)
2101 {
2102 // switch "Map follows Vehicle" ON
2103 struct attr attrx;
2104 attrx.type = attr_follow_cursor;
2105 attrx.u.num = 1;
2106 navit_set_attr(global_navit, &attrx);
2107 }
2108 else if (i == 39)
2109 {
2110 // switch "Northing" OFF
2111 struct attr attrx;
2112 attrx.type = attr_orientation;
2113 attrx.u.num = 0;
2114 navit_set_attr(global_navit, &attrx);
2115 }
2116 else if (i == 38)
2117 {
2118 // switch "Northing" ON
2119 struct attr attrx;
2120 attrx.type = attr_orientation;
2121 attrx.u.num = 1;
2122 navit_set_attr(global_navit, &attrx);
2123 }
2124 else if (i == 37)
2125 {
2126 // switch "Lock on road" OFF
2127 struct attr attrx;
2128 attrx.type = attr_tracking;
2129 attrx.u.num = 0;
2130 navit_set_attr(global_navit, &attrx);
2131 }
2132 else if (i == 36)
2133 {
2134 // switch "Lock on road" ON
2135 struct attr attrx;
2136 attrx.type = attr_tracking;
2137 attrx.u.num = 1;
2138 navit_set_attr(global_navit, &attrx);
2139 }
2140 else if (i == 35)
2141 {
2142 // announcer voice ON
2143 navit_cmd_announcer_on(global_navit);
2144 }
2145 else if (i == 34)
2146 {
2147 // announcer voice OFF
2148 navit_cmd_announcer_off(global_navit);
2149 }
2150 else if (i == 33)
2151 {
2152 // zoom to specific zoomlevel
2153 s = (*env)->GetStringUTFChars(env, str, NULL);
2154 int zoom_level = atoi(s);
2155 navit_zoom_to_scale(global_navit, zoom_level);
2156 (*env)->ReleaseStringUTFChars(env, str, s);
2157 }
2158 else if (i == 32)
2159 {
2160 // switch to specific 3D pitch
2161 struct attr pitch_attr;
2162 s = (*env)->GetStringUTFChars(env, str, NULL);
2163 pitch_attr.type = attr_pitch;
2164 pitch_attr.u.num = atoi(s);
2165 navit_set_attr(global_navit, &pitch_attr);
2166 (*env)->ReleaseStringUTFChars(env, str, s);
2167 }
2168 else if (i == 31)
2169 {
2170 // switch to 3D
2171 struct attr pitch_attr;
2172 pitch_attr.type = attr_pitch;
2173 pitch_attr.u.num = 30;
2174 navit_set_attr(global_navit, &pitch_attr);
2175 }
2176 else if (i == 30)
2177 {
2178 // switch to 2D
2179 struct attr pitch_attr;
2180 pitch_attr.type = attr_pitch;
2181 pitch_attr.u.num = 0;
2182 navit_set_attr(global_navit, &pitch_attr);
2183 }
2184 // 21 - 25 are used in java, so leave a hole here to make it easier to understand
2185
2186 else if (i == 20)
2187 {
2188 // add all scdard maps
2189 navit_add_all_maps(global_navit);
2190 }
2191 else if (i == 19)
2192 {
2193 // remove all scdard maps
2194 navit_remove_all_maps(global_navit);
2195 }
2196 else if (i == 18)
2197 {
2198 // reload scdard maps
2199 navit_reload_maps(global_navit);
2200 }
2201 else if (i == 17)
2202 {
2203 // zoom to route
2204 navit_zoom_to_route(global_navit, 0);
2205 }
2206 else if (i == 16)
2207 {
2208 // use imperial units
2209 global_navit->imperial = 1;
2210 }
2211 else if (i == 15)
2212 {
2213 // use metric units
2214 global_navit->imperial = 0;
2215 }
2216 else if (i == 14)
2217 {
2218 // draw location of self (car) in the screen center
2219 global_navit->radius = 0;
2220 }
2221 else if (i == 13)
2222 {
2223 // draw location of self (car) 30% lower than screen center
2224 global_navit->radius = 30;
2225 }
2226 else if (i == 12)
2227 {
2228 // draw map only at speeds higher than 5 km/h
2229 struct attr static_speed_attr;
2230 static_speed_attr.type = attr_static_speed;
2231 static_speed_attr.u.num = 5;
2232 vehicleprofile_set_attr(global_navit->vehicleprofile, &static_speed_attr);
2233 }
2234 else if (i == 11)
2235 {
2236 // allow redraw map at ZERO speed
2237 struct attr static_speed_attr;
2238 static_speed_attr.type = attr_static_speed;
2239 static_speed_attr.u.num = 0;
2240 vehicleprofile_set_attr(global_navit->vehicleprofile, &static_speed_attr);
2241 }
2242 else if (i == 10)
2243 {
2244 // allow internal GUI
2245 allow_gui_internal = 1;
2246 }
2247 else if (i == 9)
2248 {
2249 // disable internal GUI
2250 allow_gui_internal = 0;
2251 }
2252 else if (i == 8)
2253 {
2254 // zoom to zoomlevel
2255 //DBG // dbg(0,"-8- a\n");
2256 navit_zoom_to_scale(global_navit, 524288);
2257 //DBG // dbg(0,"-8- b\n");
2258 }
2259 else if (i == 7)
2260 {
2261 // stop navigation
2262 if (attr.u.navit->destination_valid != 0)
2263 {
2264 navit_set_destination(&attr.u.navit->self, NULL, NULL, 0);
2265 #ifdef DEBUG_GLIB_MEM_FUNCTIONS
2266 g_mem_profile();
2267 #endif
2268 }
2269 }
2270 else if (i == 6)
2271 {
2272 // not used now!
2273 }
2274 else if (i == 5)
2275 {
2276 // call a command (like in gui) --> seems not many commands really work with this :-(
2277 s = (*env)->GetStringUTFChars(env, str, NULL);
2278 ////DBG // dbg(0,"*****string=%s\n",s);
2279 command_evaluate(&attr.u.navit->self, s);
2280 (*env)->ReleaseStringUTFChars(env, str, s);
2281 }
2282 else if (i == 49)
2283 {
2284 // add waypoint at pixel x,y on screen
2285
2286 char *pstr;
2287 struct point p;
2288 struct coord c;
2289 struct pcoord pc;
2290
2291 s = (*env)->GetStringUTFChars(env, str, NULL);
2292 char parse_str[strlen(s) + 1];
2293 strcpy(parse_str, s);
2294 (*env)->ReleaseStringUTFChars(env, str, s);
2295
2296 // add waypoint (pixel-x#pixel-y)
2297 // pixel-x
2298 pstr = strtok(parse_str, "#");
2299 p.x = atoi(pstr);
2300 // pixel-y
2301 pstr = strtok(NULL, "#");
2302 p.y = atoi(pstr);
2303
2304 transform_reverse(global_navit->trans, &p, &c);
2305
2306 pc.x = c.x;
2307 pc.y = c.y;
2308 pc.pro = transform_get_projection(global_navit->trans);
2309
2310 // append new waypoint to navigation
2311 navit_add_waypoint_to_route(global_navit, &pc, parse_str, 1);
2312 }
2313 else if (i == 4)
2314 {
2315 // set destination to pixel x,y on screen
2316
2317 char *pstr;
2318 struct point p;
2319 struct coord c;
2320 struct pcoord pc;
2321
2322 s = (*env)->GetStringUTFChars(env, str, NULL);
2323 char parse_str[strlen(s) + 1];
2324 strcpy(parse_str, s);
2325 (*env)->ReleaseStringUTFChars(env, str, s);
2326
2327 // set destination to (pixel-x#pixel-y)
2328 // pixel-x
2329 pstr = strtok(parse_str, "#");
2330 p.x = atoi(pstr);
2331 // pixel-y
2332 pstr = strtok(NULL, "#");
2333 p.y = atoi(pstr);
2334
2335 transform_reverse(global_navit->trans, &p, &c);
2336
2337 pc.x = c.x;
2338 pc.y = c.y;
2339 pc.pro = transform_get_projection(global_navit->trans);
2340
2341 // start navigation asynchronous
2342 navit_set_destination(global_navit, &pc, parse_str, 1);
2343 }
2344 else if (i == 48)
2345 {
2346 // append waypoint at lat, lng
2347
2348 char *name;
2349 s = (*env)->GetStringUTFChars(env, str, NULL);
2350 char parse_str[strlen(s) + 1];
2351 strcpy(parse_str, s);
2352 (*env)->ReleaseStringUTFChars(env, str, s);
2353
2354 // waypoint (lat#lon#title)
2355 struct coord_geo g;
2356 char *p;
2357 char *stopstring;
2358
2359 // lat
2360 p = strtok(parse_str, "#");
2361 g.lat = strtof(p, &stopstring);
2362 // lon
2363 p = strtok(NULL, "#");
2364 g.lng = strtof(p, &stopstring);
2365 // description
2366 name = strtok(NULL, "#");
2367
2368 ////DBG // dbg(0,"lat=%f\n",g.lat);
2369 ////DBG // dbg(0,"lng=%f\n",g.lng);
2370 ////DBG // dbg(0,"str1=%s\n",name);
2371
2372 struct coord c;
2373 transform_from_geo(projection_mg, &g, &c);
2374
2375 struct pcoord pc;
2376 pc.x = c.x;
2377 pc.y = c.y;
2378 pc.pro = projection_mg;
2379
2380 // append new waypoint to navigation
2381 navit_add_waypoint_to_route(global_navit, &pc, name, 1);
2382 }
2383 else if (i == 3)
2384 {
2385 // set destination to lat, lng
2386
2387 char *name;
2388 s = (*env)->GetStringUTFChars(env, str, NULL);
2389 char parse_str[strlen(s) + 1];
2390 strcpy(parse_str, s);
2391 (*env)->ReleaseStringUTFChars(env, str, s);
2392 ////DBG // dbg(0,"*****string=%s\n",s);
2393
2394 // set destination to (lat#lon#title)
2395 struct coord_geo g;
2396 char *p;
2397 char *stopstring;
2398
2399 // lat
2400 p = strtok(parse_str, "#");
2401 g.lat = strtof(p, &stopstring);
2402 // lon
2403 p = strtok(NULL, "#");
2404 g.lng = strtof(p, &stopstring);
2405 // description
2406 name = strtok(NULL, "#");
2407
2408 ////DBG // dbg(0,"lat=%f\n",g.lat);
2409 ////DBG // dbg(0,"lng=%f\n",g.lng);
2410 ////DBG // dbg(0,"str1=%s\n",name);
2411
2412 struct coord c;
2413 transform_from_geo(projection_mg, &g, &c);
2414
2415 struct pcoord pc;
2416 pc.x = c.x;
2417 pc.y = c.y;
2418 pc.pro = projection_mg;
2419
2420 // start navigation asynchronous
2421 navit_set_destination(global_navit, &pc, name, 1);
2422
2423 }
2424 }
2425
2426 (*env)->DeleteGlobalRef(env, str);
2427 str = NULL;
2428
2429 // dbg(0,"leave %d\n",i);
2430
2431 }
2432
2433 void android_send_generic_text(int id, char *text)
2434 {
2435 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2436 // dbg(0,"+#+:enter\n");
2437 #endif
2438 //DBG // dbg(0,"Enter\n");
2439
2440 if (NavitGraphicsClass2 == NULL)
2441 {
2442 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
2443 {
2444 NavitGraphicsClass2 = NULL;
2445 return;
2446 }
2447 }
2448 //DBG // dbg(0,"x1\n");
2449 if (send_generic_text == NULL)
2450 {
2451 android_find_static_method(NavitGraphicsClass2, "send_generic_text", "(ILjava/lang/String;)V", &send_generic_text);
2452 }
2453 //DBG // dbg(0,"x2\n");
2454 if (send_generic_text == NULL)
2455 {
2456 //DBG // dbg(0, "no method found\n");
2457 return; /* exception thrown */
2458 }
2459 //DBG // dbg(0,"x3\n");
2460
2461 JNIEnv *jnienv2;
2462 jnienv2 = jni_getenv();
2463
2464 jstring string1 = (*jnienv2)->NewStringUTF(jnienv2, text);
2465 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, send_generic_text, id, string1);
2466 (*jnienv2)->DeleteLocalRef(jnienv2, string1);
2467
2468 // // dbg(0,"leave\n");
2469 }
2470
2471 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)
2472 {
2473 //DBG // dbg(0,"EEnter\n");
2474 JNIEnv *jnienv2;
2475 jnienv2 = jni_getenv();
2476
2477 jstring string1 = (*jnienv2)->NewStringUTF(jnienv2, id);
2478 jstring string2 = (*jnienv2)->NewStringUTF(jnienv2, text1);
2479 jstring string3 = (*jnienv2)->NewStringUTF(jnienv2, text2);
2480 jstring string4 = (*jnienv2)->NewStringUTF(jnienv2, text3);
2481
2482 // static
2483 if (NavitGraphicsClass2 == NULL)
2484 {
2485 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
2486 {
2487 NavitGraphicsClass2 = NULL;
2488 return;
2489 }
2490 }
2491
2492 if (NavitGraphics_send_osd_values2 == NULL)
2493 {
2494 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))
2495 {
2496 return;
2497 }
2498 }
2499
2500 // static
2501 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, NavitGraphics_send_osd_values2, string1, string2, string3, string4, i1, i2, i3, i4, f1, f2, f3);
2502
2503 (*jnienv2)->DeleteLocalRef(jnienv2, string1);
2504 (*jnienv2)->DeleteLocalRef(jnienv2, string2);
2505 (*jnienv2)->DeleteLocalRef(jnienv2, string3);
2506 (*jnienv2)->DeleteLocalRef(jnienv2, string4);
2507 }
2508
2509 void set_vehicle_values_to_java(int x, int y, int angle, int speed)
2510 {
2511 //DBG // dbg(0,"EEnter\n");
2512 JNIEnv *jnienv2;
2513 jnienv2 = jni_getenv();
2514
2515 //int thread_id = gettid();
2516 //dbg(0, "THREAD ID=%d\n", thread_id);
2517
2518 if (NavitGraphicsClass2 == NULL)
2519 {
2520 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
2521 {
2522 NavitGraphicsClass2 = NULL;
2523 return;
2524 }
2525 }
2526
2527 if (NavitGraphics_set_vehicle_values2 == NULL)
2528 {
2529 if (!android_find_static_method(NavitGraphicsClass2, "set_vehicle_values", "(IIII)V", &NavitGraphics_set_vehicle_values2))
2530 {
2531 return;
2532 }
2533 }
2534
2535 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, NavitGraphics_set_vehicle_values2, x, y, angle, speed);
2536 }
2537
2538 void set_vehicle_values_to_java_delta(int dx, int dy, int dangle)
2539 {
2540 JNIEnv *jnienv2;
2541 jnienv2 = jni_getenv();
2542
2543 //int thread_id = gettid();
2544 //dbg(0, "THREAD ID=%d\n", thread_id);
2545
2546 if (NavitGraphicsClass2 == NULL)
2547 {
2548 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
2549 {
2550 NavitGraphicsClass2 = NULL;
2551 return;
2552 }
2553 }
2554
2555 if (NavitGraphics_set_vehicle_values3 == NULL)
2556 {
2557 if (!android_find_static_method(NavitGraphicsClass2, "set_vehicle_values_delta", "(III)V", &NavitGraphics_set_vehicle_values3))
2558 {
2559 return;
2560 }
2561 }
2562
2563 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, NavitGraphics_set_vehicle_values3, dx, dy, dangle);
2564 }
2565
2566 void send_route_rect_to_java(int x1, int y1, int x2, int y2, int order)
2567 {
2568 JNIEnv *jnienv2;
2569 jnienv2 = jni_getenv();
2570
2571 //int thread_id = gettid();
2572 //dbg(0, "THREAD ID=%d\n", thread_id);
2573
2574 if (NavitGraphicsClass2 == NULL)
2575 {
2576 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
2577 {
2578 NavitGraphicsClass2 = NULL;
2579 return;
2580 }
2581 }
2582
2583 if (NavitGraphics_send_route_rect_to_java == NULL)
2584 {
2585 if (!android_find_static_method(NavitGraphicsClass2, "send_route_rect_to_java", "(IIIII)V", &NavitGraphics_send_route_rect_to_java))
2586 {
2587 return;
2588 }
2589 }
2590
2591 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, NavitGraphics_send_route_rect_to_java, x1, y1, x2, y2, order);
2592 }
2593

   
Visit the ZANavi Wiki