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

Contents of /navit/navit/android.c

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki