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

Contents of /navit/navit/android.c

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki