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

Contents of /navit/navit/android.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (7 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 zoff99 27 /**
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 zoff99 2 #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 zoff99 27 #include "file.h"
41 zoff99 2
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 zoff99 27 jclass NavitGraphicsClass2 = NULL;
50 zoff99 2 jmethodID return_generic_int;
51 zoff99 27 jmethodID send_generic_text;
52     jclass NavitMapPreviewActivityClass = NULL;
53 zoff99 2 jmethodID DrawMapPreview_target;
54 zoff99 27 jmethodID DrawMapPreview_polyline = NULL;
55     jmethodID DrawMapPreview_text = NULL;
56 zoff99 30 jmethodID NavitGraphics_send_osd_values2 = NULL;
57     jmethodID NavitGraphics_set_vehicle_values2 = NULL;
58     jmethodID NavitGraphics_set_vehicle_values3 = NULL;
59 zoff99 31 jmethodID NavitGraphics_send_route_rect_to_java = NULL;
60 zoff99 2
61     struct attr attr;
62    
63 zoff99 28 // ------------------------- 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 zoff99 30 struct config
70     {
71 zoff99 27 struct attr **attrs;
72     struct callback_list *cbl;
73 zoff99 30 }*config;
74 zoff99 2
75 zoff99 28 // copied from gui_internal.c (always keep in sync!!!)
76 zoff99 30 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 zoff99 2 };
84    
85 zoff99 28 // dummy def!!
86 zoff99 30 struct gui_internal_methods
87     {
88 zoff99 2 int dummy;
89     };
90    
91 zoff99 28 // dummy def!!
92 zoff99 30 struct gui_internal_widget_methods
93     {
94 zoff99 2 int dummy;
95     };
96    
97 zoff99 28 // forward def
98     struct gui_priv;
99    
100     // copied from gui_internal.h (always keep in sync!!!)
101 zoff99 30 struct gui_internal_data
102     {
103 zoff99 28 struct gui_priv *priv;
104     struct gui_internal_methods *gui;
105     struct gui_internal_widget_methods *widget;
106 zoff99 2 };
107    
108 zoff99 28 // copied from gui_internal.c (always keep in sync!!!)
109 zoff99 30 struct route_data
110     {
111     struct widget * route_table;
112     int route_showing;
113 zoff99 28
114     };
115    
116     // copied from gui_internal.h (always keep in sync!!!)
117 zoff99 30 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 zoff99 28 };
121    
122     // copied from gui_internal.h (always keep in sync!!!)
123 zoff99 30 enum widget_type
124     {
125     widget_box = 1, widget_button, widget_label, widget_image, widget_table, widget_table_row
126 zoff99 28 };
127    
128     // copied from gui_internal.c (always keep in sync!!!)
129 zoff99 30 struct widget
130     {
131 zoff99 28 enum widget_type type;
132 zoff99 30 struct graphics_gc *background, *text_background;
133 zoff99 28 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 zoff99 30 void (*free)(struct gui_priv *this_, struct widget * w);
143 zoff99 28 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 zoff99 30 int wmin, hmin;
153     int w, h;
154     int textw, texth;
155 zoff99 28 int font_idx;
156 zoff99 30 int bl, br, bt, bb, spx, spy;
157 zoff99 28 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 zoff99 30 struct gui_priv
179     {
180 zoff99 2 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 zoff99 30 struct widget *highlighted, *editable;
204 zoff99 2 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 zoff99 27 struct gui_config_settings config;
217 zoff99 2 struct event_idle *idle;
218 zoff99 30 struct callback *motion_cb, *button_cb, *resize_cb, *keypress_cb, *window_closed_cb, *idle_cb, *motion_timeout_callback;
219 zoff99 2 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 zoff99 30 int flags_town, flags_street, flags_house_number;
230 zoff99 2 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 zoff99 30 struct html
240     {
241 zoff99 2 int skip;
242 zoff99 30 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 zoff99 2 } 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 zoff99 28 // ------------------------- COPIED STUFF --- this is generally bad ------------------
256     // ------------------------- COPIED STUFF --- this is generally bad ------------------
257     // ------------------------- COPIED STUFF --- this is generally bad ------------------
258    
259    
260 zoff99 29 JavaVM *cachedJVM = NULL;
261 zoff99 28
262 zoff99 29 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
263     {
264 zoff99 30 JNIEnv *env_this;
265     cachedJVM = jvm;
266     if ((*jvm)->GetEnv(jvm, (void**) &env_this, JNI_VERSION_1_6))
267 zoff99 29 {
268 zoff99 30 // dbg(0,"Could not get JVM\n");
269     return JNI_ERR;
270     }
271 zoff99 28
272 zoff99 30 // dbg(0,"++ Found JVM ++\n");
273     return JNI_VERSION_1_6;
274 zoff99 29 }
275 zoff99 28
276 zoff99 29 JNIEnv* jni_getenv()
277     {
278 zoff99 30 JNIEnv* env_this;
279     (*cachedJVM)->GetEnv(cachedJVM, (void**) &env_this, JNI_VERSION_1_6);
280     return env_this;
281 zoff99 29 }
282    
283 zoff99 27 static void gui_internal_search_list_set_default_country2(struct gui_priv *this)
284 zoff99 2 {
285 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
286 zoff99 30 // dbg(0,"+#+:enter\n");
287 zoff99 28 #endif
288 zoff99 2 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 zoff99 30 ////DBG // dbg(0,"### 1");
295 zoff99 2
296 zoff99 27 country_attr = country_default();
297     tracking = navit_get_tracking(this->nav);
298 zoff99 2
299     if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
300 zoff99 27 country_attr = &search_attr;
301     if (country_attr)
302     {
303 zoff99 30 ////DBG // dbg(0,"### 2");
304 zoff99 27 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 zoff99 30 ////DBG // dbg(0,"country %s\n", country_name.u.str);
310 zoff99 27 search_attr.u.str = country_name.u.str;
311 zoff99 2 search_list_search(this->sl, &search_attr, 0);
312 zoff99 27 while ((res = search_list_get_result(this->sl)))
313     ;
314     if (this->country_iso2)
315 zoff99 2 {
316     // this seems to cause a crash, no idea why
317     //g_free(this->country_iso2);
318 zoff99 27 this->country_iso2 = NULL;
319 zoff99 2 }
320     if (item_attr_get(item, attr_country_iso2, &country_iso2))
321     {
322 zoff99 27 this->country_iso2 = g_strdup(country_iso2.u.str);
323 zoff99 2 }
324     }
325     country_search_destroy(cs);
326 zoff99 27 }
327     else
328     {
329 zoff99 30 //DBG // dbg(0, "warning: no default country found\n");
330 zoff99 27 if (this->country_iso2)
331     {
332 zoff99 30 //DBG // dbg(0, "attempting to use country '%s'\n", this->country_iso2);
333 zoff99 27 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 zoff99 2 }
339     }
340 zoff99 30 ////DBG // dbg(0,"### 99");
341 zoff99 2 }
342    
343 zoff99 30 // forward rev
344 zoff99 2 struct navit *global_navit;
345    
346 zoff99 27 int android_find_class_global(char *name, jclass *ret)
347 zoff99 2 {
348 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
349 zoff99 30 // dbg(0,"+#+:enter\n");
350 zoff99 28 #endif
351 zoff99 30
352     JNIEnv *jnienv2;
353     jnienv2 = jni_getenv();
354    
355     *ret = (*jnienv2)->FindClass(jnienv2, name);
356 zoff99 27 if (!*ret)
357     {
358 zoff99 30 //DBG // dbg(0, "Failed to get Class %s\n", name);
359 zoff99 2 return 0;
360     }
361 zoff99 30 //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 zoff99 2 return 1;
366     }
367    
368 zoff99 27 int android_find_method(jclass class, char *name, char *args, jmethodID *ret)
369 zoff99 2 {
370 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
371 zoff99 30 // dbg(0,"+#+:enter\n");
372 zoff99 28 #endif
373 zoff99 30
374     JNIEnv *jnienv2;
375     jnienv2 = jni_getenv();
376    
377     *ret = (*jnienv2)->GetMethodID(jnienv2, class, name, args);
378 zoff99 27 if (*ret == NULL)
379     {
380 zoff99 30 //DBG // dbg(0, "Failed to get Method %s with signature %s\n", name, args);
381 zoff99 2 return 0;
382     }
383 zoff99 30 //DBG // dbg(0,"l meth %p\n", *ret);
384 zoff99 2 return 1;
385     }
386    
387 zoff99 27 int android_find_static_method(jclass class, char *name, char *args, jmethodID *ret)
388 zoff99 2 {
389 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
390 zoff99 30 // dbg(0,"+#+:enter\n");
391 zoff99 28 #endif
392 zoff99 30
393     JNIEnv *jnienv2;
394     jnienv2 = jni_getenv();
395    
396     *ret = (*jnienv2)->GetStaticMethodID(jnienv2, class, name, args);
397 zoff99 27 if (*ret == NULL)
398     {
399 zoff99 30 //DBG // dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
400 zoff99 2 return 0;
401     }
402 zoff99 30 //DBG // dbg(0,"l meth %p\n", *ret);
403 zoff99 2 return 1;
404     }
405    
406     JNIEXPORT void JNICALL
407 zoff99 27 Java_com_zoffcc_applications_zanavi_Navit_NavitMain(JNIEnv* env, jobject thiz, jobject activity, jobject lang, int version, jobject display_density_string)
408 zoff99 2 {
409 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
410 zoff99 30 // dbg(0,"+#+:enter\n");
411 zoff99 28 #endif
412 zoff99 30
413 zoff99 31 #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 zoff99 30 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 zoff99 2 const char *langstr;
451     const char *displaydensitystr;
452 zoff99 27 android_version = version;
453 zoff99 2 //__android_log_print(ANDROID_LOG_ERROR,"test","called");
454 zoff99 27 android_activity_cbl = callback_list_new();
455    
456 zoff99 30 // SET GLOBAL JNIENV here, this is bad!!
457     // SET GLOBAL JNIENV here, this is bad!!
458     // SET GLOBAL JNIENV here, this is bad!!
459 zoff99 27 jnienv = env;
460 zoff99 30 // 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 zoff99 27
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 zoff99 30 //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 zoff99 27 setenv("LANG", langstr, 1);
476 zoff99 2 (*env)->ReleaseStringUTFChars(env, lang, langstr);
477    
478 zoff99 27 displaydensitystr = (*env)->GetStringUTFChars(env, display_density_string, NULL);
479 zoff99 30 //DBG // dbg(0, "*****displaydensity=%s\n", displaydensitystr);
480 zoff99 27 setenv("ANDROID_DENSITY", displaydensitystr, 1);
481 zoff99 2 (*env)->ReleaseStringUTFChars(env, display_density_string, displaydensitystr);
482 zoff99 28
483 zoff99 30 //// dbg(0,"before main_real call\n");
484     //main_real(1, strings);
485     //// dbg(0,"after main_real call\n");
486 zoff99 28
487 zoff99 31 /* -- 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 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
513 zoff99 30 // dbg(0,"+#+:leave\n");
514 zoff99 28 #endif
515    
516 zoff99 2 }
517    
518     JNIEXPORT void JNICALL
519 zoff99 27 Java_com_zoffcc_applications_zanavi_Navit_NavitActivity(JNIEnv* env, jobject thiz, int param)
520 zoff99 2 {
521 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
522 zoff99 30 // dbg(0,"+#+:enter\n");
523 zoff99 28 #endif
524 zoff99 2
525 zoff99 30 //dbg(0, "enter %d\n", param);
526    
527     int thread_id = gettid();
528     // dbg(0, "THREAD ID=%d\n", thread_id);
529    
530 zoff99 2 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 zoff99 30 //DBG // dbg(0, "save position to file");
538 zoff99 2 char *center_file = bookmarks_get_center_file(TRUE);
539     bookmarks_write_center_to_file(attr.u.navit->bookmarks, center_file);
540 zoff99 30 // dbg(0, "save pos to file -> ready");
541 zoff99 2 g_free(center_file);
542     // bookmarks_destroy(global_navit->bookmarks);
543     }
544     }
545    
546 zoff99 28 // 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 zoff99 2 {
557 zoff99 30 // 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 zoff99 28 navit_draw(global_navit);
565 zoff99 2 }
566    
567 zoff99 30 // dbg(0, "acti: 001\n");
568 zoff99 28 // callback_list_call_1(android_activity_cbl, param);
569 zoff99 30 //// dbg(0, "acti: 002\n");
570 zoff99 27
571 zoff99 28 //if (param == -4)
572 zoff99 27 //{
573 zoff99 30 // // dbg(0, "acti: 003\n");
574 zoff99 28 // // *********EXIT******EXIT******** // exit(0);
575 zoff99 27 //}
576    
577 zoff99 28 if (param == -4)
578     {
579 zoff99 30 // dbg(0, "acti: 004\n");
580 zoff99 28 navit_destroy(global_navit);
581 zoff99 30 // dbg(0, "acti: 005\n");
582 zoff99 28 event_main_loop_quit();
583 zoff99 30 // dbg(0, "acti: 006\n");
584 zoff99 28 }
585 zoff99 2 }
586    
587     JNIEXPORT void JNICALL
588 zoff99 30 Java_com_zoffcc_applications_zanavi_NavitGraphics_SizeChangedCallbackReal(JNIEnv* env, jobject thiz, int w, int h)
589 zoff99 2 {
590 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
591 zoff99 30 // dbg(0,"+#+:enter\n");
592 zoff99 28 #endif
593 zoff99 30 // 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 zoff99 28 navit_handle_resize(global_navit, w, h);
599     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
600 zoff99 30 // dbg(0,"+#+:leave\n");
601 zoff99 28 #endif
602 zoff99 2 }
603    
604     JNIEXPORT void JNICALL
605 zoff99 30 Java_com_zoffcc_applications_zanavi_NavitGraphics_MotionCallbackReal(JNIEnv* env, jobject thiz, int x1, int y1, int x2, int y2)
606 zoff99 2 {
607 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
608 zoff99 30 // dbg(0,"+#+:enter\n");
609 zoff99 28 #endif
610 zoff99 2
611 zoff99 30 //int thread_id = gettid();
612     // dbg(0, "THREAD ID=%d\n", thread_id);
613    
614 zoff99 28 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 zoff99 30 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 zoff99 28
638 zoff99 30 // dbg(0,"call async java draw -start-\n");
639 zoff99 28 navit_draw(global_navit);
640 zoff99 29 // navit_draw_async(global_navit, 1);
641 zoff99 30 // dbg(0,"call async java draw --end--\n");
642 zoff99 29
643     // remove the "wait" screen
644 zoff99 30 //#ifdef HAVE_API_ANDROID
645     // android_return_generic_int(2, 0);
646     //#endif
647 zoff99 29
648 zoff99 2 }
649    
650     JNIEXPORT void JNICALL
651 zoff99 30 Java_com_zoffcc_applications_zanavi_NavitGraphics_TimeoutCallback(JNIEnv* env, jobject thiz, int delete, int id)
652 zoff99 2 {
653 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
654 zoff99 30 // dbg(0,"+#+:enter\n");
655 zoff99 28 #endif
656 zoff99 30
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 zoff99 28 //dbg(0,"timeout 1\n");
665 zoff99 27 // ICS
666 zoff99 30 //if (id != 0)
667     //{
668     // dbg(0,"callback struct=%p %d\n", id, id);
669 zoff99 27 callback_call_0((struct callback *) id);
670 zoff99 30 //}
671 zoff99 27 // ICS
672 zoff99 28 //dbg(0,"timeout 2\n");
673 zoff99 30
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 zoff99 2 }
687    
688     JNIEXPORT void JNICALL
689 zoff99 27 Java_com_zoffcc_applications_zanavi_NavitIdle_IdleCallback(JNIEnv* env, jobject thiz, int id)
690 zoff99 2 {
691 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
692 zoff99 30 // dbg(0,"+#+:enter\n");
693 zoff99 28 #endif
694 zoff99 30
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 zoff99 27 callback_call_0((struct callback *) id);
701 zoff99 30 // dbg(0,"idlecall back 2\n");
702 zoff99 2 }
703    
704     JNIEXPORT void JNICALL
705 zoff99 27 Java_com_zoffcc_applications_zanavi_NavitWatch_poll(JNIEnv* env, jobject thiz, int fd, int cond)
706 zoff99 2 {
707 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
708 zoff99 30 // dbg(0,"+#+:enter\n");
709 zoff99 28 #endif
710 zoff99 2 struct pollfd pfd;
711 zoff99 27 pfd.fd = fd;
712 zoff99 30 //DBG // dbg(0, "%p poll called for %d %d\n", env, fd, cond);
713 zoff99 27 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 zoff99 2 }
727 zoff99 27 pfd.revents = 0;
728 zoff99 2 poll(&pfd, 1, -1);
729     }
730    
731     JNIEXPORT void JNICALL
732 zoff99 27 Java_com_zoffcc_applications_zanavi_NavitWatch_WatchCallback(JNIEnv* env, jobject thiz, int id)
733 zoff99 2 {
734 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
735 zoff99 30 // dbg(0,"+#+:enter\n");
736 zoff99 28 #endif
737 zoff99 30 //DBG // dbg(0, "enter %p %p\n", thiz, (void *) id);
738 zoff99 27 callback_call_0((struct callback *) id);
739 zoff99 2 }
740    
741     JNIEXPORT void JNICALL
742 zoff99 27 Java_com_zoffcc_applications_zanavi_NavitSensors_SensorCallback(JNIEnv* env, jobject thiz, int id, int sensor, float x, float y, float z)
743 zoff99 2 {
744 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
745 zoff99 30 // dbg(0,"+#+:enter\n");
746 zoff99 28 #endif
747 zoff99 30 // 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 zoff99 27 callback_call_4((struct callback *) id, sensor, &x, &y, &z);
755 zoff99 2 }
756    
757 zoff99 28 JNIEXPORT void JNICALL
758 zoff99 30 Java_com_zoffcc_applications_zanavi_NavitVehicle_VehicleCallback(JNIEnv *env, jobject thiz, jobject location)
759 zoff99 28 {
760     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
761 zoff99 30 // dbg(0,"+#+:enter\n");
762 zoff99 28 #endif
763    
764 zoff99 30 // JNIEnv *jnienv2;
765     // jnienv2 = jni_getenv();
766     //int thread_id = gettid();
767     //dbg(0, "THREAD ID=%d\n", thread_id);
768 zoff99 28
769 zoff99 30 //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 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
786 zoff99 30 // dbg(0,"+#+:leave\n");
787 zoff99 28 #endif
788     }
789    
790 zoff99 27 void android_return_search_result(struct jni_object *jni_o, char *str)
791 zoff99 2 {
792 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
793 zoff99 30 // dbg(0,"+#+:enter\n");
794 zoff99 28 #endif
795 zoff99 31 // dbg(0,"EEnter\n");
796 zoff99 30
797     // int thread_id = gettid();
798     // dbg(0, "THREAD ID=%d\n", thread_id);
799    
800 zoff99 2 jstring js2 = NULL;
801     JNIEnv* env2;
802 zoff99 27 env2 = jni_o->env;
803     js2 = (*env2)->NewStringUTF(jni_o->env, str);
804 zoff99 2 (*env2)->CallVoidMethod(jni_o->env, jni_o->jo, jni_o->jm, js2);
805     (*env2)->DeleteLocalRef(jni_o->env, js2);
806     }
807    
808 zoff99 27 void android_return_generic_int(int id, int i)
809 zoff99 2 {
810 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
811 zoff99 30 // dbg(0,"+#+:enter\n");
812 zoff99 28 #endif
813 zoff99 30 //DBG // dbg(0,"Enter\n");
814 zoff99 29
815 zoff99 30 // int thread_id = gettid();
816     // dbg(0, "THREAD ID=%d\n", thread_id);
817    
818 zoff99 29 JNIEnv *jnienv2;
819     jnienv2 = jni_getenv();
820    
821 zoff99 2 if (NavitGraphicsClass2 == NULL)
822     {
823     if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
824     {
825 zoff99 27 NavitGraphicsClass2 = NULL;
826 zoff99 2 return;
827     }
828     }
829 zoff99 30 //DBG // dbg(0,"xx1\n");
830 zoff99 2 if (return_generic_int == NULL)
831     {
832 zoff99 27 android_find_static_method(NavitGraphicsClass2, "return_generic_int", "(II)V", &return_generic_int);
833 zoff99 2 }
834 zoff99 30 //DBG // dbg(0,"xx2\n");
835 zoff99 2 if (return_generic_int == NULL)
836     {
837 zoff99 30 //DBG // dbg(0, "no method found\n");
838 zoff99 2 return; /* exception thrown */
839     }
840 zoff99 30 //DBG // dbg(0,"xa1\n");
841 zoff99 29 // -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 zoff99 30 //DBG // dbg(0,"xa2\n");
845 zoff99 2 }
846    
847     JNIEXPORT void JNICALL
848 zoff99 31 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 zoff99 2 {
850 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
851 zoff99 30 // dbg(0,"+#+:enter\n");
852 zoff99 28 #endif
853 zoff99 30
854     int thread_id = gettid();
855     // dbg(0, "THREAD ID=%d\n", thread_id);
856    
857 zoff99 2 const char *s;
858 zoff99 27 s = (*env)->GetStringUTFChars(env, str, NULL);
859 zoff99 30 ////DBG // dbg(0,"*****string=%s\n",s);
860 zoff99 2
861    
862     config_get_attr(config, attr_navit, &attr, NULL);
863     // attr.u.navit
864    
865     jstring js2 = NULL;
866 zoff99 27 jclass cls_local = (*env)->GetObjectClass(env, thiz);
867    
868     // ICS ???
869     jclass cls = (*env)->NewGlobalRef(env, cls_local);
870     // ICS ???
871    
872 zoff99 2 jmethodID aMethodID = (*env)->GetMethodID(env, cls, "fillStringArray", "(Ljava/lang/String;)V");
873 zoff99 27 if (aMethodID == 0)
874 zoff99 2 {
875 zoff99 30 ////DBG // dbg(0,"**** Unable to get methodID: fillStringArray");
876 zoff99 2 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 zoff99 27 if (id == 1)
883 zoff99 2 {
884     // unused now!!
885     }
886 zoff99 31 // new experimental street-index search
887 zoff99 2 else if (id == 2)
888     {
889 zoff99 31 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 zoff99 2 //struct attr s_attr4;
911     //struct gui_priv *gp4;
912     //struct gui_priv gp_24;
913    
914 zoff99 15 offline_search_break_searching = 0;
915 zoff99 2
916     struct jni_object my_jni_object;
917 zoff99 27 my_jni_object.env = env;
918     my_jni_object.jo = thiz;
919     my_jni_object.jm = aMethodID;
920 zoff99 2
921     //gp4=&gp_24;
922     //gp4->nav=attr.u.navit;
923 zoff99 27 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 zoff99 2 (*env)->ReleaseStringUTFChars(env, search_country, search_country_string);
929    
930     // free the memory
931     g_list_free(ret);
932 zoff99 30 ////DBG // dbg(0,"ret=%p\n",ret);
933 zoff99 2
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 zoff99 27 s3 = (*env)->GetStringUTFChars(env, latlon, NULL);
946 zoff99 2 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 zoff99 27 p = strtok(parse_str, "#");
956 zoff99 2 g7.lat = strtof(p, &stopstring);
957     // lon
958 zoff99 27 p = strtok(NULL, "#");
959 zoff99 2 g7.lng = strtof(p, &stopstring);
960    
961     struct jni_object my_jni_object;
962 zoff99 27 my_jni_object.env = env;
963     my_jni_object.jo = thiz;
964     my_jni_object.jm = aMethodID;
965 zoff99 28
966     offline_search_break_searching = 0;
967    
968 zoff99 2 // 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 zoff99 27 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackDestinationValid(JNIEnv* env, jobject thiz)
978 zoff99 2 {
979 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
980 zoff99 30 // dbg(0,"+#+:enter\n");
981 zoff99 28 #endif
982 zoff99 30 //DBG // dbg(0,"EEnter\n");
983 zoff99 2 config_get_attr(config, attr_navit, &attr, NULL);
984 zoff99 30 // //DBG // dbg(0,"destination_valid=%d\n",attr.u.navit->destination_valid);
985 zoff99 27 jint i = 0;
986 zoff99 2 if (attr.u.navit->route)
987     {
988     struct route *r;
989 zoff99 27 r = attr.u.navit->route;
990     i = r->route_status;
991 zoff99 30 // //DBG // dbg(0,"route_status=%d\n",i);
992 zoff99 2 }
993     return i;
994     }
995    
996     static void map_preview_label_line(struct point *p, int count, char *label, int font_size)
997     {
998 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
999 zoff99 30 // dbg(0,"+#+:enter\n");
1000 zoff99 28 #endif
1001 zoff99 27 int i, x, y, tl, tlm, th, thm, tlsq, l;
1002 zoff99 2 float lsq;
1003 zoff99 27 double dx, dy;
1004 zoff99 2 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 zoff99 27 int yMax = 13 * font_size / 256;
1011     int xMax = 9 * font_size * len / 256;
1012 zoff99 2
1013 zoff99 30 ////DBG // dbg(0,"xMax=%d\n", xMax);
1014     ////DBG // dbg(0,"yMax=%d\n", yMax);
1015 zoff99 2
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 zoff99 27 tl = (pb[2].x - pb[0].x);
1026     th = (pb[0].y - pb[1].y);
1027 zoff99 2
1028     // calc "tl" text length
1029     // tl=strlen(label)*4;
1030     // calc "th" text height
1031     // th=8;
1032    
1033 zoff99 27 tlm = tl * 32;
1034     thm = th * 36;
1035     tlsq = (tlm * 0.7) * (tlm * 0.7);
1036 zoff99 2
1037 zoff99 27 for (i = 0; i < count - 1; i++)
1038 zoff99 2 {
1039 zoff99 27 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 zoff99 2
1045     if (lsq > tlsq)
1046     {
1047 zoff99 30 ////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 zoff99 27 l = (int) sqrtf(lsq);
1051 zoff99 30 ////DBG // dbg(0,"l=%d lsq=%f\n",l,lsq);
1052 zoff99 27 x = p[i].x;
1053     y = p[i].y;
1054 zoff99 2 if (dx < 0)
1055     {
1056 zoff99 27 dx = -dx;
1057     dy = -dy;
1058     x = p[i + 1].x;
1059     y = p[i + 1].y;
1060 zoff99 2 }
1061 zoff99 27 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 zoff99 2
1068 zoff99 30 ////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 zoff99 2 // **OLD and wrong** android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, dx*0x10000/l, dy*0x10000/l);
1074 zoff99 27 android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, (int) dx, (int) dy);
1075 zoff99 2 }
1076     }
1077     }
1078    
1079     JNIEXPORT void JNICALL
1080 zoff99 27 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 zoff99 2 {
1082 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1083 zoff99 30 // dbg(0,"+#+:enter\n");
1084 zoff99 28 #endif
1085 zoff99 2 // config_get_attr(config, attr_navit, &attr, NULL);
1086    
1087     const char *s;
1088     int zoom;
1089 zoff99 27 s = (*env)->GetStringUTFChars(env, latlonzoom, NULL);
1090 zoff99 2 char parse_str[strlen(s) + 1];
1091     strcpy(parse_str, s);
1092     (*env)->ReleaseStringUTFChars(env, latlonzoom, s);
1093 zoff99 30 ////DBG // dbg(0,"*****string=%s\n",s);
1094 zoff99 2
1095     // show map preview for (lat#lon#zoom)
1096     struct coord_geo g;
1097     char *p;
1098     char *stopstring;
1099    
1100     // lat
1101 zoff99 27 p = strtok(parse_str, "#");
1102 zoff99 2 g.lat = strtof(p, &stopstring);
1103     // lon
1104 zoff99 27 p = strtok(NULL, "#");
1105 zoff99 2 g.lng = strtof(p, &stopstring);
1106     // zoom
1107 zoff99 27 p = strtok(NULL, "#");
1108     zoom = atoi(p);
1109 zoff99 2
1110 zoff99 30 ////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 zoff99 2
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 zoff99 27 struct map_rect *mr = NULL;
1131 zoff99 2 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 zoff99 27 const int max = 100;
1141 zoff99 2 int count;
1142 zoff99 27 struct coord *ca = g_alloca(sizeof(struct coord) * max);
1143     struct point *pa = g_alloca(sizeof(struct point) * max);
1144 zoff99 2
1145 zoff99 27 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 zoff99 2
1154     struct transformation *tr;
1155 zoff99 27 tr = transform_dup(global_navit->trans);
1156 zoff99 2 struct point p_center;
1157 zoff99 27 p_center.x = width / 2;
1158     p_center.y = height / 2;
1159 zoff99 2 transform_set_screen_center(tr, &p_center);
1160     transform_set_center(tr, &c);
1161     transform_set_scale(tr, scale);
1162 zoff99 27 enum projection pro = transform_get_projection(global_navit->trans_cursor);
1163 zoff99 2
1164 zoff99 27 ms = global_navit->mapsets->data;
1165     msh = mapset_open(ms);
1166     while (msh && (map = mapset_next(msh, 0)))
1167 zoff99 2 {
1168 zoff99 27 if (map_get_attr(map, attr_name, &map_name_attr, NULL))
1169 zoff99 2 {
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 zoff99 30 // //DBG // dbg(0,"map name=%s",map_name_attr.u.str);
1176 zoff99 27 mr = map_rect_new(map, NULL);
1177 zoff99 2 if (mr)
1178     {
1179 zoff99 27 while ((item = map_rect_get_item(mr)))
1180 zoff99 2 {
1181    
1182     // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
1183 zoff99 27 count = item_coord_get_within_selection(item, ca, max, &sel);
1184     if (!count)
1185 zoff99 2 {
1186     continue;
1187     }
1188 zoff99 27 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
1189 zoff99 2
1190 zoff99 30 // //DBG // dbg(0,"uu %s\n",item_to_name(item->type));
1191 zoff99 2
1192     if (item->type == type_border_country)
1193     {
1194 zoff99 30 // //DBG // dbg(0,"BB** %s\n",item_to_name(item->type));
1195 zoff99 2 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 zoff99 30 // //DBG // dbg(0,"map name=%s",map_name_attr.u.str);
1205 zoff99 27 mr = map_rect_new(map, &sel);
1206 zoff99 2 if (mr)
1207     {
1208     //char *streetname_last=NULL;
1209    
1210 zoff99 27 while ((item = map_rect_get_item(mr)))
1211 zoff99 2 {
1212 zoff99 27 int label_count = 0;
1213 zoff99 2 char *labels[2];
1214    
1215     // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
1216 zoff99 27 count = item_coord_get_within_selection(item, ca, max, &sel);
1217 zoff99 2
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 zoff99 27 if (!count)
1221 zoff99 2 {
1222     continue;
1223     }
1224 zoff99 30 ////DBG // dbg(0,"count 1=%d\n", count);
1225 zoff99 2
1226     if (count == max)
1227     {
1228 zoff99 30 ////DBG // dbg(0,"count overflow!!\n");
1229 zoff99 2 }
1230    
1231     struct attr attr_77;
1232     if (item_attr_get(item, attr_flags, &attr_77))
1233     {
1234 zoff99 30 ////DBG // dbg(0,"uuuuuuuuuuuuu %s uuuuu %d\n",item_to_name(item->type), attr_77.u.num);
1235 zoff99 27 item->flags = attr_77.u.num;
1236 zoff99 2 }
1237     else
1238     {
1239 zoff99 27 item->flags = 0;
1240 zoff99 2 }
1241    
1242     //if (item_is_street(*item))
1243     //{
1244     // int i3;
1245     // for (i3 = 0 ; i3 < count ; i3++)
1246     // {
1247     // if (i3)
1248     // {
1249 zoff99 30 // //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 zoff99 2 // }
1254     // }
1255     //}
1256    
1257 zoff99 27 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
1258 zoff99 2
1259 zoff99 30 ////DBG // dbg(0,"count 2=%d\n", count);
1260 zoff99 2
1261     // --- LABEL ---
1262 zoff99 27 labels[1] = NULL;
1263     label_count = 0;
1264 zoff99 2 if (item_attr_get(item, attr_label, &attr))
1265     {
1266 zoff99 27 labels[0] = attr.u.str;
1267 zoff99 30 ////DBG // dbg(0,"labels[0]=%s\n",attr.u.str);
1268 zoff99 2 if (!label_count)
1269     {
1270 zoff99 27 label_count = 2;
1271 zoff99 2 }
1272     }
1273     else
1274     {
1275 zoff99 27 labels[0] = NULL;
1276 zoff99 2 }
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 zoff99 30 // //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 zoff99 2 // }
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 zoff99 27 if (zoom > 6)
1301     {
1302 zoff99 30 // //DBG // dbg(0,"xx** %s - %s\n",item_to_name(item->type),labels[0]);
1303 zoff99 27 if (count >= 1)
1304 zoff99 2 {
1305 zoff99 27 android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size * 2, 0x10000, 0);
1306 zoff99 2 }
1307 zoff99 27 }
1308 zoff99 2 }
1309     else if (item_is_town(*item))
1310     {
1311 zoff99 30 // //DBG // dbg(0,"yy** %s - %s\n",item_to_name(item->type),labels[0]);
1312 zoff99 27 if (count >= 1)
1313     {
1314     android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size * 3, 0x10000, 0);
1315     }
1316 zoff99 2 }
1317    
1318     //if (item_is_street(*item))
1319     //{
1320     // if (item_attr_get(item, attr_label, &attr))
1321     // {
1322 zoff99 30 // ////DBG // dbg(0,"street1=%s\n",map_convert_string(item->map, attr.u.str));
1323 zoff99 2 // if ( (streetname_last==NULL) || (strcmp(streetname_last,attr.u.str) != 0) )
1324     // {
1325 zoff99 30 // ////DBG // dbg(0,"street2=%s\n",map_convert_string(item->map, attr.u.str));
1326 zoff99 2 // }
1327     // }
1328     //}
1329     }
1330     //g_free(streetname_last);
1331     map_rect_destroy(mr);
1332     }
1333     }
1334     }
1335     }
1336     }
1337     mapset_close(msh);
1338    
1339 zoff99 27 enum projection pro2 = transform_get_projection(global_navit->trans_cursor);
1340 zoff99 2 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 zoff99 27 void android_DrawMapPreview_target(int x, int y)
1352 zoff99 2 {
1353 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1354 zoff99 30 // dbg(0,"+#+:enter\n");
1355 zoff99 28 #endif
1356 zoff99 30
1357     JNIEnv *jnienv2;
1358     jnienv2 = jni_getenv();
1359    
1360 zoff99 27 if (NavitMapPreviewActivityClass == NULL)
1361 zoff99 2 {
1362     if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1363     {
1364 zoff99 27 NavitMapPreviewActivityClass = NULL;
1365 zoff99 2 return;
1366     }
1367     }
1368     if (DrawMapPreview_target == NULL)
1369     {
1370 zoff99 27 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_target", "(II)V", &DrawMapPreview_target);
1371 zoff99 2 }
1372     if (DrawMapPreview_target == NULL)
1373     {
1374 zoff99 30 //DBG // dbg(0, "no method found\n");
1375 zoff99 2 return; /* exception thrown */
1376     }
1377 zoff99 30 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_target, x, y);
1378 zoff99 2 }
1379    
1380 zoff99 27 void android_DrawMapPreview_text(int x, int y, char *text, int size, int dx, int dy)
1381 zoff99 2 {
1382 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1383 zoff99 30 // dbg(0,"+#+:enter\n");
1384 zoff99 28 #endif
1385 zoff99 2
1386 zoff99 30 JNIEnv *jnienv2;
1387     jnienv2 = jni_getenv();
1388    
1389 zoff99 27 if (NavitMapPreviewActivityClass == NULL)
1390 zoff99 2 {
1391     if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1392     {
1393 zoff99 27 NavitMapPreviewActivityClass = NULL;
1394 zoff99 2 return;
1395     }
1396     }
1397 zoff99 27 if (DrawMapPreview_text == NULL)
1398 zoff99 2 {
1399 zoff99 27 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_text", "(IILjava/lang/String;III)V", &DrawMapPreview_text);
1400 zoff99 2 }
1401     if (DrawMapPreview_text == NULL)
1402     {
1403 zoff99 30 //DBG // dbg(0, "no method found\n");
1404 zoff99 2 return; /* exception thrown */
1405     }
1406    
1407 zoff99 30 ////DBG // dbg(0,"** dx=%d,dy=%d\n",dx,dy);
1408 zoff99 2
1409 zoff99 30 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 zoff99 2 }
1413    
1414 zoff99 27 void android_DrawMapPreview_polyline(struct point *p, int count, int type)
1415 zoff99 2 {
1416 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1417 zoff99 30 // dbg(0,"+#+:enter\n");
1418 zoff99 28 #endif
1419 zoff99 2 // type:
1420     // 0 -> normal street
1421     // 2 -> country border
1422    
1423 zoff99 30 JNIEnv *jnienv2;
1424     jnienv2 = jni_getenv();
1425    
1426 zoff99 27 if (NavitMapPreviewActivityClass == NULL)
1427 zoff99 2 {
1428     if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1429     {
1430 zoff99 27 NavitMapPreviewActivityClass = NULL;
1431 zoff99 2 return;
1432     }
1433     }
1434 zoff99 27 if (DrawMapPreview_polyline == NULL)
1435 zoff99 2 {
1436 zoff99 27 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_polyline", "(I[I)V", &DrawMapPreview_polyline);
1437 zoff99 2 }
1438     if (DrawMapPreview_polyline == NULL)
1439     {
1440 zoff99 30 //DBG // dbg(0, "no method found\n");
1441 zoff99 2 return; /* exception thrown */
1442     }
1443    
1444 zoff99 27 jint pc[count * 2];
1445 zoff99 2 int i;
1446     jintArray points;
1447     if (count <= 0)
1448     {
1449     return;
1450     }
1451 zoff99 30 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
1452 zoff99 27 for (i = 0; i < count; i++)
1453 zoff99 2 {
1454 zoff99 27 pc[i * 2] = p[i].x;
1455     pc[i * 2 + 1] = p[i].y;
1456 zoff99 2 }
1457 zoff99 30 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
1458     (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_polyline, type, points);
1459     (*jnienv2)->DeleteLocalRef(jnienv2, points);
1460 zoff99 2 }
1461    
1462     JNIEXPORT jstring JNICALL
1463 zoff99 27 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackGeoCalc(JNIEnv* env, jobject thiz, int i, float a, float b)
1464 zoff99 2 {
1465 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1466 zoff99 30 // dbg(0,"+#+:enter\n");
1467 zoff99 28 #endif
1468 zoff99 27 // dbg(0,"EEnter i=%d\n", i);
1469    
1470 zoff99 30 int thread_id = gettid();
1471     // dbg(0, "THREAD ID=%d\n", thread_id);
1472    
1473 zoff99 2 // 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 zoff99 27 p.x = a;
1483     p.y = b;
1484 zoff99 2 transform_reverse(global_navit->trans, &p, &c22);
1485 zoff99 30 ////DBG // dbg(0,"%f, %f\n",a, b);
1486     ////DBG // dbg(0,"%d, %d\n",p.x, p.y);
1487 zoff99 2 transform_to_geo(projection_mg, &c22, &g22);
1488 zoff99 30 ////DBG // dbg(0,"%d, %d, %f, %f\n",c22.x, c22.y, g22.lat, g22.lng);
1489 zoff99 27 result = g_strdup_printf("%f:%f", g22.lat, g22.lng);
1490 zoff99 2 }
1491     else if (i == 2)
1492     {
1493     // geo to pixel-on-screen
1494     struct coord c99;
1495     struct coord_geo g99;
1496 zoff99 27 g99.lat = a;
1497     g99.lng = b;
1498 zoff99 30 ////DBG // dbg(0,"zzzzz %f, %f\n",a, b);
1499     ////DBG // dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1500 zoff99 2 transform_from_geo(projection_mg, &g99, &c99);
1501 zoff99 30 ////DBG // dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1502 zoff99 2
1503 zoff99 27 enum projection pro = transform_get_projection(global_navit->trans_cursor);
1504 zoff99 2 struct point pnt;
1505     transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
1506 zoff99 30 ////DBG // dbg(0,"x=%d\n",pnt.x);
1507     ////DBG // dbg(0,"y=%d\n",pnt.y);
1508 zoff99 2
1509 zoff99 27 result = g_strdup_printf("%d:%d", pnt.x, pnt.y);
1510 zoff99 2 }
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 zoff99 27 g99.lat = a;
1518     g99.lng = b;
1519 zoff99 30 ////DBG // dbg(0,"zzzzz %f, %f\n",a, b);
1520     ////DBG // dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1521 zoff99 2 transform_from_geo(projection_mg, &g99, &c99);
1522 zoff99 30 ////DBG // dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1523 zoff99 2
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 zoff99 30 ////DBG // dbg(0,"x=%d\n",pnt.x);
1528     ////DBG // dbg(0,"y=%d\n",pnt.y);
1529 zoff99 27 pc99.x = c99.x;
1530     pc99.y = c99.y;
1531     pc99.pro = projection_mg;
1532 zoff99 2
1533     navit_set_center(global_navit, &pc99, 0);
1534    
1535 zoff99 27 result = g_strdup_printf("1:1");
1536 zoff99 2 }
1537 zoff99 27 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 zoff99 2
1544 zoff99 27 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 zoff99 28 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 zoff99 29 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 zoff99 31 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 zoff99 27
1653 zoff99 30 // // dbg(0, "result=%s\n", result);
1654 zoff99 27 jstring js = (*env)->NewStringUTF(env, result);
1655 zoff99 2 g_free(result);
1656    
1657     return js;
1658     }
1659    
1660     JNIEXPORT jstring JNICALL
1661 zoff99 27 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackLocalizedString(JNIEnv* env, jobject thiz, jobject str)
1662 zoff99 2 {
1663 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1664 zoff99 30 // dbg(0,"+#+:enter\n");
1665 zoff99 28 #endif
1666 zoff99 30 // // dbg(0,"EEnter\n");
1667 zoff99 27
1668 zoff99 30 int thread_id = gettid();
1669     // dbg(0, "THREAD ID=%d\n", thread_id);
1670    
1671 zoff99 2 const char *s;
1672     const char *localized_str;
1673    
1674 zoff99 27 s = (*env)->GetStringUTFChars(env, str, NULL);
1675 zoff99 30 ////DBG // dbg(0,"*****string=%s\n",s);
1676 zoff99 2
1677 zoff99 27 localized_str = gettext(s);
1678 zoff99 30 ////DBG // dbg(0,"localized string=%s",localized_str);
1679 zoff99 2
1680     // jstring dataStringValue = (jstring) localized_str;
1681 zoff99 27 jstring js = (*env)->NewStringUTF(env, localized_str);
1682 zoff99 2
1683     (*env)->ReleaseStringUTFChars(env, str, s);
1684    
1685     return js;
1686     }
1687    
1688 zoff99 30 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 zoff99 2 JNIEXPORT void JNICALL
1703 zoff99 30 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackMessageChannelReal(JNIEnv* env, jobject thiz, int i, jobject str2)
1704 zoff99 2 {
1705 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1706 zoff99 30 // dbg(0,"+#+:enter\n");
1707 zoff99 28 #endif
1708 zoff99 30
1709     int thread_id = gettid();
1710     // dbg(0, "THREAD ID=%d\n", thread_id);
1711    
1712 zoff99 2 const char *s;
1713 zoff99 27 jobject str = (*env)->NewGlobalRef(env, str2);
1714 zoff99 2
1715 zoff99 30 // dbg(0,"enter %d\n",i);
1716 zoff99 27
1717 zoff99 2 config_get_attr(config, attr_navit, &attr, NULL);
1718     // attr.u.navit
1719    
1720 zoff99 30 //DBG // dbg(0,"c1\n");
1721 zoff99 27
1722 zoff99 2 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 zoff99 31 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 zoff99 30 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 zoff99 28 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 zoff99 31 // disable "multipolygons"
1826     global_draw_multipolygons = 0;
1827 zoff99 28 }
1828     else if (i == 66)
1829     {
1830 zoff99 31 // enable "multipolygons"
1831     global_draw_multipolygons = 1;
1832 zoff99 28 }
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 zoff99 27 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 zoff99 30 //// dbg(0, "dpf1\n");
1908 zoff99 27 s = (*env)->GetStringUTFChars(env, str, NULL);
1909 zoff99 30 //// dbg(0, "dpf2\n");
1910 zoff99 27 draw_polylines_fast = atoi(s);
1911 zoff99 30 //// dbg(0, "dpf=%d\n", draw_polylines_fast);
1912 zoff99 27 (*env)->ReleaseStringUTFChars(env, str, s);
1913     }
1914     else if (i == 55)
1915     {
1916     // set cache size for (map-)files
1917 zoff99 30 //// dbg(0, "csf1\n");
1918 zoff99 27 s = (*env)->GetStringUTFChars(env, str, NULL);
1919 zoff99 30 //// dbg(0, "csf2\n");
1920 zoff99 27 cache_size_file = atoi(s);
1921     file_cache_init();
1922 zoff99 30 // dbg(0, "csf=%d\n", cache_size_file);
1923 zoff99 27 (*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 zoff99 28
1939     s = (*env)->GetStringUTFChars(env, str, NULL);
1940    
1941 zoff99 27 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 zoff99 28 speed.u.num = atoi(s);
1970 zoff99 27
1971     interval.type = attr_interval;
1972 zoff99 30 interval.u.num = 1000; // 1 sec.
1973     // interval.u.num = 5000; // 5 sec.
1974 zoff99 27
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 zoff99 30 //DBG // dbg(0, "demo vehicle new start\n");
1985 zoff99 27 v = vehicle_new(&parent, attrs);
1986 zoff99 30 //DBG // dbg(0, "demo vehicle new end\n");
1987 zoff99 27
1988     if (v != NULL)
1989     {
1990 zoff99 30 //DBG // dbg(0, "adding demo vehicle\n");
1991 zoff99 27 navit_add_vehicle(global_navit, v);
1992 zoff99 30 //DBG // dbg(0, "setting cursor\n");
1993 zoff99 27 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 zoff99 30 //DBG // dbg(0, "ERROR adding demo vehicle\n");
2009 zoff99 27 }
2010     // **no** navit_set_vehicle(global_navit, global_navit->vehicle);
2011 zoff99 30 //DBG // dbg(0, "ready\n");
2012 zoff99 28
2013     (*env)->ReleaseStringUTFChars(env, str, s);
2014 zoff99 27 }
2015     else if (i == 51)
2016     {
2017     // set position to pixel x,y
2018 zoff99 30 //DBG // dbg(0, "sp 1\n");
2019 zoff99 27 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 zoff99 30 //DBG // dbg(0, "sp 2\n");
2038 zoff99 27 transform_reverse(global_navit->trans, &p, &c);
2039 zoff99 30 //DBG // dbg(0, "sp 3\n");
2040 zoff99 27
2041     pc.x = c.x;
2042     pc.y = c.y;
2043 zoff99 30 //DBG // dbg(0, "sp 4\n");
2044 zoff99 27 pc.pro = transform_get_projection(global_navit->trans);
2045 zoff99 30 //DBG // dbg(0, "sp 5\n");
2046 zoff99 27
2047 zoff99 30 //DBG // dbg(0, "%d %d\n", pc.x, pc.y);
2048 zoff99 27 // set position
2049 zoff99 30 //DBG // dbg(0, "sp 6\n");
2050 zoff99 27 navit_set_position(global_navit, &pc);
2051 zoff99 30 //DBG // dbg(0, "ready\n");
2052 zoff99 27 }
2053     else if (i == 50)
2054     {
2055     // we request to stop drawing the map
2056 zoff99 30 // dbg(0, "DO__DRAW:cancel_drawing_global=1\n");
2057 zoff99 27 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 zoff99 30 // //DBG // dbg(0,"*****string use=%s\n",navit_maps_dir);
2066 zoff99 27 }
2067 zoff99 15 else if (i == 46)
2068     {
2069     // stop searching and show results found until now
2070 zoff99 27 offline_search_break_searching = 1;
2071 zoff99 15 }
2072     else if (i == 45)
2073     {
2074     // filter duplicates in search results
2075 zoff99 27 offline_search_filter_duplicates = 1;
2076 zoff99 15 }
2077     else if (i == 44)
2078     {
2079     // show duplicates in search results
2080 zoff99 27 offline_search_filter_duplicates = 0;
2081 zoff99 15 }
2082 zoff99 2 else if (i == 43)
2083     {
2084     // routing mode "normal roads"
2085 zoff99 27 routing_mode = 1;
2086 zoff99 2 }
2087     else if (i == 42)
2088     {
2089     // routing mode "highways"
2090 zoff99 27 routing_mode = 0;
2091 zoff99 2 }
2092     else if (i == 41)
2093     {
2094     // switch "Map follows Vehicle" OFF
2095     struct attr attrx;
2096 zoff99 27 attrx.type = attr_follow_cursor;
2097     attrx.u.num = 0;
2098     navit_set_attr(global_navit, &attrx);
2099 zoff99 2 }
2100     else if (i == 40)
2101     {
2102     // switch "Map follows Vehicle" ON
2103     struct attr attrx;
2104 zoff99 27 attrx.type = attr_follow_cursor;
2105     attrx.u.num = 1;
2106     navit_set_attr(global_navit, &attrx);
2107 zoff99 2 }
2108     else if (i == 39)
2109     {
2110     // switch "Northing" OFF
2111     struct attr attrx;
2112 zoff99 27 attrx.type = attr_orientation;
2113     attrx.u.num = 0;
2114     navit_set_attr(global_navit, &attrx);
2115 zoff99 2 }
2116     else if (i == 38)
2117     {
2118     // switch "Northing" ON
2119     struct attr attrx;
2120 zoff99 27 attrx.type = attr_orientation;
2121     attrx.u.num = 1;
2122     navit_set_attr(global_navit, &attrx);
2123 zoff99 2 }
2124     else if (i == 37)
2125     {
2126     // switch "Lock on road" OFF
2127     struct attr attrx;
2128 zoff99 27 attrx.type = attr_tracking;
2129     attrx.u.num = 0;
2130     navit_set_attr(global_navit, &attrx);
2131 zoff99 2 }
2132     else if (i == 36)
2133     {
2134     // switch "Lock on road" ON
2135     struct attr attrx;
2136 zoff99 27 attrx.type = attr_tracking;
2137     attrx.u.num = 1;
2138     navit_set_attr(global_navit, &attrx);
2139 zoff99 2 }
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 zoff99 27 s = (*env)->GetStringUTFChars(env, str, NULL);
2154 zoff99 2 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 zoff99 27 s = (*env)->GetStringUTFChars(env, str, NULL);
2163     pitch_attr.type = attr_pitch;
2164 zoff99 2 pitch_attr.u.num = atoi(s);
2165 zoff99 27 navit_set_attr(global_navit, &pitch_attr);
2166 zoff99 2 (*env)->ReleaseStringUTFChars(env, str, s);
2167     }
2168     else if (i == 31)
2169     {
2170     // switch to 3D
2171     struct attr pitch_attr;
2172 zoff99 27 pitch_attr.type = attr_pitch;
2173     pitch_attr.u.num = 30;
2174     navit_set_attr(global_navit, &pitch_attr);
2175 zoff99 2 }
2176     else if (i == 30)
2177     {
2178     // switch to 2D
2179     struct attr pitch_attr;
2180 zoff99 27 pitch_attr.type = attr_pitch;
2181     pitch_attr.u.num = 0;
2182     navit_set_attr(global_navit, &pitch_attr);
2183 zoff99 2 }
2184     // 21 - 25 are used in java, so leave a hole here to make it easier to understand
2185 zoff99 27
2186 zoff99 2 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 zoff99 27 global_navit->imperial = 1;
2210 zoff99 2 }
2211     else if (i == 15)
2212     {
2213     // use metric units
2214 zoff99 27 global_navit->imperial = 0;
2215 zoff99 2 }
2216     else if (i == 14)
2217     {
2218     // draw location of self (car) in the screen center
2219 zoff99 27 global_navit->radius = 0;
2220 zoff99 2 }
2221     else if (i == 13)
2222     {
2223     // draw location of self (car) 30% lower than screen center
2224 zoff99 27 global_navit->radius = 30;
2225 zoff99 2 }
2226     else if (i == 12)
2227     {
2228     // draw map only at speeds higher than 5 km/h
2229     struct attr static_speed_attr;
2230 zoff99 27 static_speed_attr.type = attr_static_speed;
2231     static_speed_attr.u.num = 5;
2232 zoff99 2 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 zoff99 27 static_speed_attr.type = attr_static_speed;
2239     static_speed_attr.u.num = 0;
2240 zoff99 2 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 zoff99 30 //DBG // dbg(0,"-8- a\n");
2256 zoff99 2 navit_zoom_to_scale(global_navit, 524288);
2257 zoff99 30 //DBG // dbg(0,"-8- b\n");
2258 zoff99 2 }
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 zoff99 31 #ifdef DEBUG_GLIB_MEM_FUNCTIONS
2266     g_mem_profile();
2267     #endif
2268 zoff99 2 }
2269     }
2270 zoff99 27 else if (i == 6)
2271 zoff99 2 {
2272     // not used now!
2273     }
2274 zoff99 27 else if (i == 5)
2275 zoff99 2 {
2276     // call a command (like in gui) --> seems not many commands really work with this :-(
2277 zoff99 27 s = (*env)->GetStringUTFChars(env, str, NULL);
2278 zoff99 30 ////DBG // dbg(0,"*****string=%s\n",s);
2279 zoff99 27 command_evaluate(&attr.u.navit->self, s);
2280 zoff99 2 (*env)->ReleaseStringUTFChars(env, str, s);
2281     }
2282 zoff99 27 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 zoff99 2 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 zoff99 27 s = (*env)->GetStringUTFChars(env, str, NULL);
2323 zoff99 2 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 zoff99 27 pstr = strtok(parse_str, "#");
2330 zoff99 2 p.x = atoi(pstr);
2331     // pixel-y
2332 zoff99 27 pstr = strtok(NULL, "#");
2333 zoff99 2 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 zoff99 27 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 zoff99 30 ////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 zoff99 27
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 zoff99 2 else if (i == 3)
2384     {
2385     // set destination to lat, lng
2386    
2387     char *name;
2388 zoff99 27 s = (*env)->GetStringUTFChars(env, str, NULL);
2389 zoff99 2 char parse_str[strlen(s) + 1];
2390     strcpy(parse_str, s);
2391     (*env)->ReleaseStringUTFChars(env, str, s);
2392 zoff99 30 ////DBG // dbg(0,"*****string=%s\n",s);
2393 zoff99 2
2394     // set destination to (lat#lon#title)
2395     struct coord_geo g;
2396     char *p;
2397     char *stopstring;
2398    
2399     // lat
2400 zoff99 27 p = strtok(parse_str, "#");
2401 zoff99 2 g.lat = strtof(p, &stopstring);
2402     // lon
2403 zoff99 27 p = strtok(NULL, "#");
2404 zoff99 2 g.lng = strtof(p, &stopstring);
2405     // description
2406 zoff99 27 name = strtok(NULL, "#");
2407 zoff99 2
2408 zoff99 30 ////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 zoff99 2
2412     struct coord c;
2413     transform_from_geo(projection_mg, &g, &c);
2414    
2415     struct pcoord pc;
2416 zoff99 27 pc.x = c.x;
2417     pc.y = c.y;
2418     pc.pro = projection_mg;
2419 zoff99 2
2420     // start navigation asynchronous
2421     navit_set_destination(global_navit, &pc, name, 1);
2422    
2423     }
2424     }
2425 zoff99 27
2426     (*env)->DeleteGlobalRef(env, str);
2427     str = NULL;
2428    
2429 zoff99 30 // dbg(0,"leave %d\n",i);
2430 zoff99 27
2431 zoff99 2 }
2432    
2433 zoff99 27 void android_send_generic_text(int id, char *text)
2434     {
2435 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2436 zoff99 30 // dbg(0,"+#+:enter\n");
2437 zoff99 28 #endif
2438 zoff99 30 //DBG // dbg(0,"Enter\n");
2439 zoff99 27
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 zoff99 30 //DBG // dbg(0,"x1\n");
2449 zoff99 27 if (send_generic_text == NULL)
2450     {
2451     android_find_static_method(NavitGraphicsClass2, "send_generic_text", "(ILjava/lang/String;)V", &send_generic_text);
2452     }
2453 zoff99 30 //DBG // dbg(0,"x2\n");
2454 zoff99 27 if (send_generic_text == NULL)
2455     {
2456 zoff99 30 //DBG // dbg(0, "no method found\n");
2457 zoff99 27 return; /* exception thrown */
2458     }
2459 zoff99 30 //DBG // dbg(0,"x3\n");
2460 zoff99 27
2461 zoff99 29 JNIEnv *jnienv2;
2462     jnienv2 = jni_getenv();
2463 zoff99 27
2464 zoff99 29 jstring string1 = (*jnienv2)->NewStringUTF(jnienv2, text);
2465     (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, send_generic_text, id, string1);
2466     (*jnienv2)->DeleteLocalRef(jnienv2, string1);
2467    
2468 zoff99 30 // // dbg(0,"leave\n");
2469 zoff99 27 }
2470    
2471 zoff99 30 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 zoff99 31 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