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

Contents of /navit/navit/android.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (show annotations) (download)
Mon Apr 9 21:27:36 2012 UTC (10 years, 7 months ago) by zoff99
File MIME type: text/plain
File size: 46345 byte(s)
lots of new stuff, tranlsations, bug fixes ...
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include <stdlib.h>
21 #include <string.h>
22 #include <poll.h>
23 #include <glib.h>
24 #include "android.h"
25 #include <android/log.h>
26 #include "navit.h"
27 #include "config_.h"
28 #include "command.h"
29 #include "debug.h"
30 #include "event.h"
31 #include "callback.h"
32 #include "projection.h"
33 #include "map.h"
34 #include "transform.h"
35 #include "color.h"
36 #include "types.h"
37 #include "search.h"
38 #include "start_real.h"
39 #include "route.h"
40 #include "file.h"
41
42 // #include "layout.h"
43
44 JNIEnv *jnienv;
45 jobject *android_activity;
46 struct callback_list *android_activity_cbl;
47 int android_version;
48
49 jclass NavitGraphicsClass2 = NULL;
50 jmethodID return_generic_int;
51 jmethodID send_generic_text;
52 jclass NavitMapPreviewActivityClass = NULL;
53 jmethodID DrawMapPreview_target;
54 jmethodID DrawMapPreview_polyline = NULL;
55 jmethodID DrawMapPreview_text = NULL;
56
57 struct attr attr;
58
59 struct config
60 {
61 struct attr **attrs;
62 struct callback_list *cbl;
63 }*config;
64
65 struct gui_config_settings
66 {
67 int dummy;
68 };
69
70 struct gui_internal_data
71 {
72 int dummy;
73 };
74
75 struct route_data
76 {
77 int dummy;
78 };
79
80 struct widget
81 {
82 int dummy;
83 };
84
85 struct gui_priv
86 {
87 struct navit *nav;
88 struct attr self;
89 struct window *win;
90 struct graphics *gra;
91 struct graphics_gc *background;
92 struct graphics_gc *background2;
93 struct graphics_gc *highlight_background;
94 struct graphics_gc *foreground;
95 struct graphics_gc *text_foreground;
96 struct graphics_gc *text_background;
97 struct color background_color, background2_color, text_foreground_color, text_background_color;
98 int spacing;
99 int font_size;
100 int fullscreen;
101 struct graphics_font *fonts[3];
102 /**
103 * The size (in pixels) that xs style icons should be scaled to.
104 * This icon size can be too small to click it on some devices.
105 */
106 int icon_xs;
107 /**
108 * The size (in pixels) that s style icons (small) should be scaled to
109 */
110 int icon_s;
111 /**
112 * The size (in pixels) that l style icons should be scaled to
113 */
114 int icon_l;
115 int pressed;
116 struct widget *widgets;
117 int widgets_count;
118 int redraw;
119 struct widget root;
120 struct widget *highlighted, *editable;
121 struct widget *highlighted_menu;
122 int clickp_valid, vehicle_valid;
123 struct pcoord clickp, vehiclep;
124 struct attr *click_coord_geo, *position_coord_geo;
125 struct search_list *sl;
126 int ignore_button;
127 int menu_on_map_click;
128 int signal_on_map_click;
129 char *country_iso2;
130 int speech;
131 int keyboard;
132 int keyboard_required;
133 /**
134 * The setting information read from the configuration file.
135 * values of -1 indicate no value was specified in the config file.
136 */
137 struct gui_config_settings config;
138 struct event_idle *idle;
139 struct callback *motion_cb, *button_cb, *resize_cb, *keypress_cb, *window_closed_cb, *idle_cb, *motion_timeout_callback;
140 struct event_timeout *motion_timeout_event;
141 struct point current;
142
143 struct callback * vehicle_cb;
144 /**
145 * Stores information about the route.
146 */
147 struct route_data route_data;
148
149 struct gui_internal_data data;
150 struct callback_list *cbl;
151 int flags;
152 int cols;
153 struct attr osd_configuration;
154 int pitch;
155 int flags_town, flags_street, flags_house_number;
156 int radius;
157 /* html */
158 char *html_text;
159 int html_depth;
160 struct widget *html_container;
161 int html_skip;
162 char *html_anchor;
163 char *href;
164 int html_anchor_found;
165 struct form *form;
166 struct html
167 {
168 int skip;
169 enum html_tag
170 {
171 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,
172 } tag;
173 char *command;
174 char *name;
175 char *href;
176 char *refresh_cond;
177 struct widget *w;
178 struct widget *container;
179 } html[10];
180 };
181
182 static void gui_internal_search_list_set_default_country2(struct gui_priv *this)
183 {
184 struct attr search_attr, country_name, country_iso2, *country_attr;
185 struct item *item;
186 struct country_search *cs;
187 struct tracking *tracking;
188 struct search_list_result *res;
189
190 ////DBG dbg(0,"### 1");
191
192 country_attr = country_default();
193 tracking = navit_get_tracking(this->nav);
194
195 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
196 country_attr = &search_attr;
197 if (country_attr)
198 {
199 ////DBG dbg(0,"### 2");
200 cs = country_search_new(country_attr, 0);
201 item = country_search_get_item(cs);
202 if (item && item_attr_get(item, attr_country_name, &country_name))
203 {
204 search_attr.type = attr_country_all;
205 ////DBG dbg(0,"country %s\n", country_name.u.str);
206 search_attr.u.str = country_name.u.str;
207 search_list_search(this->sl, &search_attr, 0);
208 while ((res = search_list_get_result(this->sl)))
209 ;
210 if (this->country_iso2)
211 {
212 // this seems to cause a crash, no idea why
213 //g_free(this->country_iso2);
214 this->country_iso2 = NULL;
215 }
216 if (item_attr_get(item, attr_country_iso2, &country_iso2))
217 {
218 this->country_iso2 = g_strdup(country_iso2.u.str);
219 }
220 }
221 country_search_destroy(cs);
222 }
223 else
224 {
225 //DBG dbg(0, "warning: no default country found\n");
226 if (this->country_iso2)
227 {
228 //DBG dbg(0, "attempting to use country '%s'\n", this->country_iso2);
229 search_attr.type = attr_country_iso2;
230 search_attr.u.str = this->country_iso2;
231 search_list_search(this->sl, &search_attr, 0);
232 while ((res = search_list_get_result(this->sl)))
233 ;
234 }
235 }
236 ////DBG dbg(0,"### 99");
237 }
238
239 struct navit *global_navit;
240
241 int android_find_class_global(char *name, jclass *ret)
242 {
243 *ret = (*jnienv)->FindClass(jnienv, name);
244 if (!*ret)
245 {
246 //DBG dbg(0, "Failed to get Class %s\n", name);
247 return 0;
248 }
249 //DBG dbg(0,"lclass %p\n", *ret);
250 *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
251 // ICS (*jnienv)->DeleteGlobalRef(jnienv, *lret);
252 //DBG dbg(0,"gclass %p\n", *ret);
253 return 1;
254 }
255
256 int android_find_method(jclass class, char *name, char *args, jmethodID *ret)
257 {
258 *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
259 if (*ret == NULL)
260 {
261 //DBG dbg(0, "Failed to get Method %s with signature %s\n", name, args);
262 return 0;
263 }
264 //DBG dbg(0,"l meth %p\n", *ret);
265 return 1;
266 }
267
268 int android_find_static_method(jclass class, char *name, char *args, jmethodID *ret)
269 {
270 *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
271 if (*ret == NULL)
272 {
273 //DBG dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
274 return 0;
275 }
276 //DBG dbg(0,"l meth %p\n", *ret);
277 return 1;
278 }
279
280 JNIEXPORT void JNICALL
281 Java_com_zoffcc_applications_zanavi_Navit_NavitMain(JNIEnv* env, jobject thiz, jobject activity, jobject lang, int version, jobject display_density_string)
282 {
283 char *strings[] =
284 { "/data/data/com.zoffcc.applications.zanavi/bin/navit", NULL };
285 const char *langstr;
286 const char *displaydensitystr;
287 android_version = version;
288 //__android_log_print(ANDROID_LOG_ERROR,"test","called");
289 android_activity_cbl = callback_list_new();
290
291 // set global JNIenv here ----------
292 // set global JNIenv here ----------
293 // set global JNIenv here ----------
294 jnienv = env;
295 // set global JNIenv here ----------
296 // set global JNIenv here ----------
297 // set global JNIenv here ----------
298
299 //jclass someClass = env->FindClass("SomeClass");
300 //gSomeClass = env->NewGlobalRef(someClass);
301
302
303 // *only local* android_activity = activity;
304 // android_activity = (*jnienv)->NewGlobalRef(jnienv, activity);
305 android_activity = (*env)->NewGlobalRef(env, activity);
306 langstr = (*env)->GetStringUTFChars(env, lang, NULL);
307 //DBG dbg(0, "enter env=%p thiz=%p activity=%p lang=%s version=%d\n", env, thiz, activity, langstr, version);
308 //DBG dbg(0, "enter env=%p thiz=%p activity=%p lang=%s version=%d\n", env, thiz, android_activity, langstr, version);
309 setenv("LANG", langstr, 1);
310 (*env)->ReleaseStringUTFChars(env, lang, langstr);
311
312 displaydensitystr = (*env)->GetStringUTFChars(env, display_density_string, NULL);
313 //DBG dbg(0, "*****displaydensity=%s\n", displaydensitystr);
314 setenv("ANDROID_DENSITY", displaydensitystr, 1);
315 (*env)->ReleaseStringUTFChars(env, display_density_string, displaydensitystr);
316 main_real(1, strings);
317 }
318
319 JNIEXPORT void JNICALL
320 Java_com_zoffcc_applications_zanavi_Navit_NavitActivity(JNIEnv* env, jobject thiz, int param)
321 {
322 dbg(0, "enter %d\n", param);
323
324 if (param == -2)
325 {
326 // onStop() -> called in Java app
327 // save center.txt
328 if (global_navit->bookmarks)
329 {
330 config_get_attr(config, attr_navit, &attr, NULL);
331 //DBG dbg(0, "save position to file");
332 char *center_file = bookmarks_get_center_file(TRUE);
333 bookmarks_write_center_to_file(attr.u.navit->bookmarks, center_file);
334 dbg(0,"save pos to file -> ready");
335 g_free(center_file);
336 // bookmarks_destroy(global_navit->bookmarks);
337 }
338 }
339
340 dbg(0,"acti: 001\n");
341 callback_list_call_1(android_activity_cbl, param);
342 dbg(0,"acti: 002\n");
343 if (param == -4)
344 {
345 dbg(0,"acti: 003\n");
346 exit(0);
347 }
348 //if (param == -3)
349 //{
350 // event_main_loop_quit();
351 //}
352 }
353
354 JNIEXPORT void JNICALL
355 Java_com_zoffcc_applications_zanavi_NavitGraphics_SizeChangedCallback(JNIEnv* env, jobject thiz, int id, int w, int h)
356 {
357 //DBG dbg(0,"enter %p %d %d\n", id, w, h);
358 navit_handle_resize(global_navit, w, h);
359
360 // //DBG dbg(0,"== part2 ==\n");
361
362 //if (id)
363 //{
364 // callback_call_2((struct callback *) id, w, h);
365 //}
366
367 //DBG dbg(0,"leave\n");
368 }
369
370 JNIEXPORT void JNICALL
371 Java_com_zoffcc_applications_zanavi_NavitGraphics_ButtonCallback(JNIEnv* env, jobject thiz, int id, int pressed, int button, int x, int y)
372 {
373 //DBG dbg(0, "enter %p %d %d\n", (struct callback *) id, pressed, button);
374 if (id)
375 callback_call_4((struct callback *) id, pressed, button, x, y);
376 }
377
378 JNIEXPORT void JNICALL
379 Java_com_zoffcc_applications_zanavi_NavitGraphics_MotionCallback(JNIEnv* env, jobject thiz, int id, int x, int y)
380 {
381 //DBG dbg(0, "enter %p %d %d\n", (struct callback *) id, x, y);
382 if (id)
383 callback_call_2((struct callback *) id, x, y);
384 }
385
386 JNIEXPORT void JNICALL
387 Java_com_zoffcc_applications_zanavi_NavitGraphics_KeypressCallback(JNIEnv* env, jobject thiz, int id, jobject str)
388 {
389 //DBG dbg(0,"EEnter\n");
390 const char *s;
391 ////DBG dbg(0,"enter %p %p\n",(struct callback *)id,str);
392 s = (*env)->GetStringUTFChars(env, str, NULL);
393 ////DBG dbg(0,"key=%s\n",s);
394 if (id)
395 {
396 callback_call_1((struct callback *) id, s);
397 }
398 (*env)->ReleaseStringUTFChars(env, str, s);
399 }
400
401 JNIEXPORT void JNICALL
402 Java_com_zoffcc_applications_zanavi_NavitTimeout_TimeoutCallback(JNIEnv* env, jobject thiz, int delete, int id)
403 {
404 //DBG dbg(0,"enter %p %d %p\n",thiz, delete, (void *)id);
405 //DBG dbg(0,"timeout 1\n");
406 // ICS
407 callback_call_0((struct callback *) id);
408 // ICS
409 //DBG dbg(0,"timeout 2\n");
410 if (delete)
411 {
412 //DBG dbg(0,"timeout 3\n");
413 // ICS
414 // (*jnienv)->DeleteGlobalRef(jnienv, thiz);
415 // ICS
416 //DBG dbg(0,"timeout 4\n");
417 }
418 }
419
420 JNIEXPORT void JNICALL
421 Java_com_zoffcc_applications_zanavi_NavitVehicle_VehicleCallback(JNIEnv * env, jobject thiz, int id, jobject location)
422 {
423 //DBG dbg(0,"enter %p %p\n",thiz, (void *)id);
424
425 // ***** calls: vehicle_android.c -> vehicle_android_callback()
426 callback_call_1((struct callback *) id, (void *) location);
427 }
428
429 JNIEXPORT void JNICALL
430 Java_com_zoffcc_applications_zanavi_NavitIdle_IdleCallback(JNIEnv* env, jobject thiz, int id)
431 {
432 //DBG dbg(0,"enter %p %p\n",thiz, (void *)id);
433 callback_call_0((struct callback *) id);
434 }
435
436 JNIEXPORT void JNICALL
437 Java_com_zoffcc_applications_zanavi_NavitWatch_poll(JNIEnv* env, jobject thiz, int fd, int cond)
438 {
439 struct pollfd pfd;
440 pfd.fd = fd;
441 //DBG dbg(0, "%p poll called for %d %d\n", env, fd, cond);
442 switch ((enum event_watch_cond) cond)
443 {
444 case event_watch_cond_read:
445 pfd.events = POLLIN;
446 break;
447 case event_watch_cond_write:
448 pfd.events = POLLOUT;
449 break;
450 case event_watch_cond_except:
451 pfd.events = POLLERR;
452 break;
453 default:
454 pfd.events = 0;
455 }
456 pfd.revents = 0;
457 poll(&pfd, 1, -1);
458 }
459
460 JNIEXPORT void JNICALL
461 Java_com_zoffcc_applications_zanavi_NavitWatch_WatchCallback(JNIEnv* env, jobject thiz, int id)
462 {
463 //DBG dbg(0, "enter %p %p\n", thiz, (void *) id);
464 callback_call_0((struct callback *) id);
465 }
466
467 JNIEXPORT void JNICALL
468 Java_com_zoffcc_applications_zanavi_NavitSensors_SensorCallback(JNIEnv* env, jobject thiz, int id, int sensor, float x, float y, float z)
469 {
470 //DBG dbg(0, "enter %p %p %f %f %f\n", thiz, (void *) id, x, y, z);
471 callback_call_4((struct callback *) id, sensor, &x, &y, &z);
472 }
473
474 void android_return_search_result(struct jni_object *jni_o, char *str)
475 {
476 //DBG dbg(0,"EEnter\n");
477 jstring js2 = NULL;
478 JNIEnv* env2;
479 env2 = jni_o->env;
480 js2 = (*env2)->NewStringUTF(jni_o->env, str);
481 (*env2)->CallVoidMethod(jni_o->env, jni_o->jo, jni_o->jm, js2);
482 (*env2)->DeleteLocalRef(jni_o->env, js2);
483 }
484
485 void android_return_generic_int(int id, int i)
486 {
487 //DBG dbg(0,"Enter\n");
488 if (NavitGraphicsClass2 == NULL)
489 {
490 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
491 {
492 NavitGraphicsClass2 = NULL;
493 return;
494 }
495 }
496 //DBG dbg(0,"xx1\n");
497 if (return_generic_int == NULL)
498 {
499 android_find_static_method(NavitGraphicsClass2, "return_generic_int", "(II)V", &return_generic_int);
500 }
501 //DBG dbg(0,"xx2\n");
502 if (return_generic_int == NULL)
503 {
504 //DBG dbg(0, "no method found\n");
505 return; /* exception thrown */
506 }
507 //DBG dbg(0,"xa1\n");
508 // -crash- (*jnienv)->CallVoidMethod(jnienv, NavitGraphicsClass2, return_generic_int, id, i);
509 (*jnienv)->CallStaticVoidMethod(jnienv, NavitGraphicsClass2, return_generic_int, id, i);
510 // -works- (*jnienv)->CallStaticObjectMethod(jnienv, NavitGraphicsClass2, return_generic_int, id, i);
511 //DBG dbg(0,"xa2\n");
512 }
513
514 JNIEXPORT void JNICALL
515 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)
516 {
517 const char *s;
518 s = (*env)->GetStringUTFChars(env, str, NULL);
519 ////DBG dbg(0,"*****string=%s\n",s);
520
521
522 config_get_attr(config, attr_navit, &attr, NULL);
523 // attr.u.navit
524
525 jstring js2 = NULL;
526 jclass cls_local = (*env)->GetObjectClass(env, thiz);
527
528 // ICS ???
529 jclass cls = (*env)->NewGlobalRef(env, cls_local);
530 // ICS ???
531
532 jmethodID aMethodID = (*env)->GetMethodID(env, cls, "fillStringArray", "(Ljava/lang/String;)V");
533 if (aMethodID == 0)
534 {
535 ////DBG dbg(0,"**** Unable to get methodID: fillStringArray");
536 return;
537 }
538
539 if (id)
540 {
541 // search for town in variable "s" within current country -> return a list of towns as result
542 if (id == 1)
543 {
544 // unused now!!
545 }
546 // search for street in variable "s" within "search_country" -> return a list of streets as result
547 else if (id == 2)
548 {
549 //struct attr s_attr4;
550 //struct gui_priv *gp4;
551 //struct gui_priv gp_24;
552
553 offline_search_break_searching = 0;
554
555 struct jni_object my_jni_object;
556 my_jni_object.env = env;
557 my_jni_object.jo = thiz;
558 my_jni_object.jm = aMethodID;
559
560 //gp4=&gp_24;
561 //gp4->nav=attr.u.navit;
562 struct mapset *ms4 = navit_get_mapset(attr.u.navit);
563 GList *ret = NULL;
564 int flags = search_flags;
565 char *search_country_string = (*env)->GetStringUTFChars(env, search_country, NULL);
566 ret = search_by_address(ret, ms4, s, partial, &my_jni_object, flags, search_country_string);
567 (*env)->ReleaseStringUTFChars(env, search_country, search_country_string);
568
569 // free the memory
570 g_list_free(ret);
571 ////DBG dbg(0,"ret=%p\n",ret);
572
573
574 //if (gp4->sl)
575 //{
576 // //search_list_destroy(gp4->sl);
577 // gp4->sl=NULL;
578 //}
579 }
580 // do a full search in all mapfiles for string in variable "s" -> return a list of streets as result
581 else if (id == 3)
582 {
583 const char *s3;
584 s3 = (*env)->GetStringUTFChars(env, latlon, NULL);
585 char parse_str[strlen(s3) + 1];
586 strcpy(parse_str, s3);
587 (*env)->ReleaseStringUTFChars(env, latlon, s3);
588
589 struct coord_geo g7;
590 char *p;
591 char *stopstring;
592
593 // lat
594 p = strtok(parse_str, "#");
595 g7.lat = strtof(p, &stopstring);
596 // lon
597 p = strtok(NULL, "#");
598 g7.lng = strtof(p, &stopstring);
599
600 struct jni_object my_jni_object;
601 my_jni_object.env = env;
602 my_jni_object.jo = thiz;
603 my_jni_object.jm = aMethodID;
604 // search_flags --> is search_order (search at what "order" level)
605 search_full_world(s, partial, search_flags, &my_jni_object, &g7, radius);
606 }
607 }
608
609 (*env)->ReleaseStringUTFChars(env, str, s);
610 }
611
612 JNIEXPORT jint JNICALL
613 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackDestinationValid(JNIEnv* env, jobject thiz)
614 {
615 //DBG dbg(0,"EEnter\n");
616 config_get_attr(config, attr_navit, &attr, NULL);
617 // //DBG dbg(0,"destination_valid=%d\n",attr.u.navit->destination_valid);
618 jint i = 0;
619 if (attr.u.navit->route)
620 {
621 struct route *r;
622 r = attr.u.navit->route;
623 i = r->route_status;
624 // //DBG dbg(0,"route_status=%d\n",i);
625 }
626 return i;
627 }
628
629 static void map_preview_label_line(struct point *p, int count, char *label, int font_size)
630 {
631 int i, x, y, tl, tlm, th, thm, tlsq, l;
632 float lsq;
633 double dx, dy;
634 struct point p_t;
635 struct point pb[5];
636
637 int len = g_utf8_strlen(label, -1);
638 int xMin = 0;
639 int yMin = 0;
640 int yMax = 13 * font_size / 256;
641 int xMax = 9 * font_size * len / 256;
642
643 ////DBG dbg(0,"xMax=%d\n", xMax);
644 ////DBG dbg(0,"yMax=%d\n", yMax);
645
646 pb[0].x = xMin;
647 pb[0].y = -yMin;
648 pb[1].x = xMin;
649 pb[1].y = -yMax;
650 pb[2].x = xMax;
651 pb[2].y = -yMax;
652 pb[3].x = xMax;
653 pb[3].y = -yMin;
654
655 tl = (pb[2].x - pb[0].x);
656 th = (pb[0].y - pb[1].y);
657
658 // calc "tl" text length
659 // tl=strlen(label)*4;
660 // calc "th" text height
661 // th=8;
662
663 tlm = tl * 32;
664 thm = th * 36;
665 tlsq = (tlm * 0.7) * (tlm * 0.7);
666
667 for (i = 0; i < count - 1; i++)
668 {
669 dx = p[i + 1].x - p[i].x;
670 dx *= 32;
671 dy = p[i + 1].y - p[i].y;
672 dy *= 32;
673 lsq = dx * dx + dy * dy;
674
675 if (lsq > tlsq)
676 {
677 ////DBG dbg(0,"-------- label=%s\n",label);
678 ////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);
679 ////DBG dbg(0,"dx=%f dy=%f\n",dx,dy);
680 l = (int) sqrtf(lsq);
681 ////DBG dbg(0,"l=%d lsq=%f\n",l,lsq);
682 x = p[i].x;
683 y = p[i].y;
684 if (dx < 0)
685 {
686 dx = -dx;
687 dy = -dy;
688 x = p[i + 1].x;
689 y = p[i + 1].y;
690 }
691 x += (l - tlm) * dx / l / 64;
692 y += (l - tlm) * dy / l / 64;
693 x -= dy * thm / l / 64;
694 y += dx * thm / l / 64;
695 p_t.x = x;
696 p_t.y = y;
697
698 ////DBG dbg(0,"dx=%f dy=%f\n",dx,dy);
699 ////DBG dbg(0,"dx=%d dy=%d\n",(int)dx,(int)dy);
700 ////DBG dbg(0,"draw px=%d py=%d\n",p_t.x,p_t.y);
701 ////DBG dbg(0,"l=%d\n",l);
702 ////DBG dbg(0,"+++++++++++++\n");
703 // **OLD and wrong** android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, dx*0x10000/l, dy*0x10000/l);
704 android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, (int) dx, (int) dy);
705 }
706 }
707 }
708
709 JNIEXPORT void JNICALL
710 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)
711 {
712 // config_get_attr(config, attr_navit, &attr, NULL);
713
714 const char *s;
715 int zoom;
716 s = (*env)->GetStringUTFChars(env, latlonzoom, NULL);
717 char parse_str[strlen(s) + 1];
718 strcpy(parse_str, s);
719 (*env)->ReleaseStringUTFChars(env, latlonzoom, s);
720 ////DBG dbg(0,"*****string=%s\n",s);
721
722 // show map preview for (lat#lon#zoom)
723 struct coord_geo g;
724 char *p;
725 char *stopstring;
726
727 // lat
728 p = strtok(parse_str, "#");
729 g.lat = strtof(p, &stopstring);
730 // lon
731 p = strtok(NULL, "#");
732 g.lng = strtof(p, &stopstring);
733 // zoom
734 p = strtok(NULL, "#");
735 zoom = atoi(p);
736
737 ////DBG dbg(0,"lat=%f\n",g.lat);
738 ////DBG dbg(0,"lng=%f\n",g.lng);
739 ////DBG dbg(0,"zoom=%d\n",zoom);
740 ////DBG dbg(0,"w=%d\n",width);
741 ////DBG dbg(0,"h=%d\n",height);
742
743 struct coord c;
744 transform_from_geo(projection_mg, &g, &c);
745
746 // struct pcoord pc;
747 // pc.x=c.x;
748 // pc.y=c.y;
749 // pc.pro=projection_mg;
750
751
752 // ----------------------- big draw loop -----------------------
753 // ----------------------- big draw loop -----------------------
754 // ----------------------- big draw loop -----------------------
755 // ----------------------- big draw loop -----------------------
756 struct item *item;
757 struct map_rect *mr = NULL;
758 struct mapset *ms;
759 struct mapset_handle *msh;
760 struct map* map = NULL;
761 struct attr map_name_attr;
762 struct attr attr;
763
764 struct map_selection sel;
765 const int selection_range = sel_range; // should be something with "width" and "height" i guess ??!!
766
767 const int max = 100;
768 int count;
769 struct coord *ca = g_alloca(sizeof(struct coord) * max);
770 struct point *pa = g_alloca(sizeof(struct point) * max);
771
772 sel.next = NULL;
773 sel.order = zoom;
774 sel.range.min = type_none;
775 sel.range.max = type_last;
776 sel.u.c_rect.lu.x = c.x - selection_range;
777 sel.u.c_rect.lu.y = c.y + selection_range;
778 sel.u.c_rect.rl.x = c.x + selection_range;
779 sel.u.c_rect.rl.y = c.y - selection_range;
780
781 struct transformation *tr;
782 tr = transform_dup(global_navit->trans);
783 struct point p_center;
784 p_center.x = width / 2;
785 p_center.y = height / 2;
786 transform_set_screen_center(tr, &p_center);
787 transform_set_center(tr, &c);
788 transform_set_scale(tr, scale);
789 enum projection pro = transform_get_projection(global_navit->trans_cursor);
790
791 ms = global_navit->mapsets->data;
792 msh = mapset_open(ms);
793 while (msh && (map = mapset_next(msh, 0)))
794 {
795 if (map_get_attr(map, attr_name, &map_name_attr, NULL))
796 {
797 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
798 {
799 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/borders.bin", map_name_attr.u.str, 41) == 0)
800 {
801 // country borders
802 // //DBG dbg(0,"map name=%s",map_name_attr.u.str);
803 mr = map_rect_new(map, NULL);
804 if (mr)
805 {
806 while ((item = map_rect_get_item(mr)))
807 {
808
809 // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
810 count = item_coord_get_within_selection(item, ca, max, &sel);
811 if (!count)
812 {
813 continue;
814 }
815 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
816
817 // //DBG dbg(0,"uu %s\n",item_to_name(item->type));
818
819 if (item->type == type_border_country)
820 {
821 // //DBG dbg(0,"BB** %s\n",item_to_name(item->type));
822 android_DrawMapPreview_polyline(pa, count, 2);
823 }
824 }
825 map_rect_destroy(mr);
826 }
827 }
828 else if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0)
829 {
830 // its an sdcard map
831 // //DBG dbg(0,"map name=%s",map_name_attr.u.str);
832 mr = map_rect_new(map, &sel);
833 if (mr)
834 {
835 //char *streetname_last=NULL;
836
837 while ((item = map_rect_get_item(mr)))
838 {
839 int label_count = 0;
840 char *labels[2];
841
842 // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
843 count = item_coord_get_within_selection(item, ca, max, &sel);
844
845 // count=item_coord_get_within_selection(item, ca, max, &sel);
846 // count=item_coord_get(item, ca, item->type < type_line ? 1: max);
847 if (!count)
848 {
849 continue;
850 }
851 ////DBG dbg(0,"count 1=%d\n", count);
852
853 if (count == max)
854 {
855 ////DBG dbg(0,"count overflow!!\n");
856 }
857
858 struct attr attr_77;
859 if (item_attr_get(item, attr_flags, &attr_77))
860 {
861 ////DBG dbg(0,"uuuuuuuuuuuuu %s uuuuu %d\n",item_to_name(item->type), attr_77.u.num);
862 item->flags = attr_77.u.num;
863 }
864 else
865 {
866 item->flags = 0;
867 }
868
869 //if (item_is_street(*item))
870 //{
871 // int i3;
872 // for (i3 = 0 ; i3 < count ; i3++)
873 // {
874 // if (i3)
875 // {
876 // //DBG dbg(0,"1 x1=%d\n",ca[i3-1].x);
877 // //DBG dbg(0,"1 y1=%d\n",ca[i3-1].y);
878 // //DBG dbg(0,"1 x2=%d\n",ca[i3].x);
879 // //DBG dbg(0,"1 y2=%d\n",ca[i3].y);
880 // }
881 // }
882 //}
883
884 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
885
886 ////DBG dbg(0,"count 2=%d\n", count);
887
888 // --- LABEL ---
889 labels[1] = NULL;
890 label_count = 0;
891 if (item_attr_get(item, attr_label, &attr))
892 {
893 labels[0] = attr.u.str;
894 ////DBG dbg(0,"labels[0]=%s\n",attr.u.str);
895 if (!label_count)
896 {
897 label_count = 2;
898 }
899 }
900 else
901 {
902 labels[0] = NULL;
903 }
904 // --- LABEL ---
905
906 if (item_is_street(*item))
907 {
908 //int i3;
909 //for (i3 = 0 ; i3 < count ; i3++)
910 //{
911 // if (i3)
912 // {
913 // //DBG dbg(0,"2 x1=%d\n",pa[i3-1].x);
914 // //DBG dbg(0,"2 y1=%d\n",pa[i3-1].y);
915 // //DBG dbg(0,"2 x2=%d\n",pa[i3].x);
916 // //DBG dbg(0,"2 y2=%d\n",pa[i3].y);
917 // }
918 //}
919 android_DrawMapPreview_polyline(pa, count, 0);
920 if (labels[0] != NULL)
921 {
922 map_preview_label_line(pa, count, labels[0], font_size);
923 }
924 }
925 else if (item_is_district(*item))
926 {
927 if (zoom > 6)
928 {
929 // //DBG dbg(0,"xx** %s - %s\n",item_to_name(item->type),labels[0]);
930 if (count >= 1)
931 {
932 android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size * 2, 0x10000, 0);
933 }
934 }
935 }
936 else if (item_is_town(*item))
937 {
938 // //DBG dbg(0,"yy** %s - %s\n",item_to_name(item->type),labels[0]);
939 if (count >= 1)
940 {
941 android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size * 3, 0x10000, 0);
942 }
943 }
944
945 //if (item_is_street(*item))
946 //{
947 // if (item_attr_get(item, attr_label, &attr))
948 // {
949 // ////DBG dbg(0,"street1=%s\n",map_convert_string(item->map, attr.u.str));
950 // if ( (streetname_last==NULL) || (strcmp(streetname_last,attr.u.str) != 0) )
951 // {
952 // ////DBG dbg(0,"street2=%s\n",map_convert_string(item->map, attr.u.str));
953 // }
954 // }
955 //}
956 }
957 //g_free(streetname_last);
958 map_rect_destroy(mr);
959 }
960 }
961 }
962 }
963 }
964 mapset_close(msh);
965
966 enum projection pro2 = transform_get_projection(global_navit->trans_cursor);
967 struct point pnt;
968 transform(tr, pro2, &c, &pnt, 1, 0, 0, NULL);
969 transform_destroy(tr);
970 // ----------------------- big draw loop -----------------------
971 // ----------------------- big draw loop -----------------------
972 // ----------------------- big draw loop -----------------------
973 // ----------------------- big draw loop -----------------------
974
975 android_DrawMapPreview_target(pnt.x, pnt.y);
976 }
977
978 void android_DrawMapPreview_target(int x, int y)
979 {
980 if (NavitMapPreviewActivityClass == NULL)
981 {
982 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
983 {
984 NavitMapPreviewActivityClass = NULL;
985 return;
986 }
987 }
988 if (DrawMapPreview_target == NULL)
989 {
990 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_target", "(II)V", &DrawMapPreview_target);
991 }
992 if (DrawMapPreview_target == NULL)
993 {
994 //DBG dbg(0, "no method found\n");
995 return; /* exception thrown */
996 }
997 (*jnienv)->CallStaticVoidMethod(jnienv, NavitMapPreviewActivityClass, DrawMapPreview_target, x, y);
998 }
999
1000 void android_DrawMapPreview_text(int x, int y, char *text, int size, int dx, int dy)
1001 {
1002
1003 if (NavitMapPreviewActivityClass == NULL)
1004 {
1005 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1006 {
1007 NavitMapPreviewActivityClass = NULL;
1008 return;
1009 }
1010 }
1011 if (DrawMapPreview_text == NULL)
1012 {
1013 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_text", "(IILjava/lang/String;III)V", &DrawMapPreview_text);
1014 }
1015 if (DrawMapPreview_text == NULL)
1016 {
1017 //DBG dbg(0, "no method found\n");
1018 return; /* exception thrown */
1019 }
1020
1021 ////DBG dbg(0,"** dx=%d,dy=%d\n",dx,dy);
1022
1023 jstring string1 = (*jnienv)->NewStringUTF(jnienv, text);
1024 (*jnienv)->CallStaticVoidMethod(jnienv, NavitMapPreviewActivityClass, DrawMapPreview_text, x, y, string1, size, dx, dy);
1025 (*jnienv)->DeleteLocalRef(jnienv, string1);
1026 }
1027
1028 void android_DrawMapPreview_polyline(struct point *p, int count, int type)
1029 {
1030 // type:
1031 // 0 -> normal street
1032 // 2 -> country border
1033
1034 if (NavitMapPreviewActivityClass == NULL)
1035 {
1036 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
1037 {
1038 NavitMapPreviewActivityClass = NULL;
1039 return;
1040 }
1041 }
1042 if (DrawMapPreview_polyline == NULL)
1043 {
1044 android_find_static_method(NavitMapPreviewActivityClass, "DrawMapPreview_polyline", "(I[I)V", &DrawMapPreview_polyline);
1045 }
1046 if (DrawMapPreview_polyline == NULL)
1047 {
1048 //DBG dbg(0, "no method found\n");
1049 return; /* exception thrown */
1050 }
1051
1052 jint pc[count * 2];
1053 int i;
1054 jintArray points;
1055 if (count <= 0)
1056 {
1057 return;
1058 }
1059 points = (*jnienv)->NewIntArray(jnienv, count * 2);
1060 for (i = 0; i < count; i++)
1061 {
1062 pc[i * 2] = p[i].x;
1063 pc[i * 2 + 1] = p[i].y;
1064 }
1065 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count * 2, pc);
1066 (*jnienv)->CallStaticVoidMethod(jnienv, NavitMapPreviewActivityClass, DrawMapPreview_polyline, type, points);
1067 (*jnienv)->DeleteLocalRef(jnienv, points);
1068 }
1069
1070 JNIEXPORT jstring JNICALL
1071 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackGeoCalc(JNIEnv* env, jobject thiz, int i, float a, float b)
1072 {
1073 // dbg(0,"EEnter i=%d\n", i);
1074
1075 // const char *result;
1076 gchar *result;
1077
1078 if (i == 1)
1079 {
1080 // pixel-on-screen to geo
1081 struct coord_geo g22;
1082 struct coord c22;
1083 struct point p;
1084 p.x = a;
1085 p.y = b;
1086 transform_reverse(global_navit->trans, &p, &c22);
1087 ////DBG dbg(0,"%f, %f\n",a, b);
1088 ////DBG dbg(0,"%d, %d\n",p.x, p.y);
1089 transform_to_geo(projection_mg, &c22, &g22);
1090 ////DBG dbg(0,"%d, %d, %f, %f\n",c22.x, c22.y, g22.lat, g22.lng);
1091 result = g_strdup_printf("%f:%f", g22.lat, g22.lng);
1092 }
1093 else if (i == 2)
1094 {
1095 // geo to pixel-on-screen
1096 struct coord c99;
1097 struct coord_geo g99;
1098 g99.lat = a;
1099 g99.lng = b;
1100 ////DBG dbg(0,"zzzzz %f, %f\n",a, b);
1101 ////DBG dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1102 transform_from_geo(projection_mg, &g99, &c99);
1103 ////DBG dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1104
1105 enum projection pro = transform_get_projection(global_navit->trans_cursor);
1106 struct point pnt;
1107 transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
1108 ////DBG dbg(0,"x=%d\n",pnt.x);
1109 ////DBG dbg(0,"y=%d\n",pnt.y);
1110
1111 result = g_strdup_printf("%d:%d", pnt.x, pnt.y);
1112 }
1113 else if (i == 3)
1114 {
1115 // show lat,lng position on screen center
1116 struct coord c99;
1117 struct pcoord pc99;
1118 struct coord_geo g99;
1119 g99.lat = a;
1120 g99.lng = b;
1121 ////DBG dbg(0,"zzzzz %f, %f\n",a, b);
1122 ////DBG dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1123 transform_from_geo(projection_mg, &g99, &c99);
1124 ////DBG dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1125
1126 //enum projection pro=transform_get_projection(global_navit->trans_cursor);
1127 //struct point pnt;
1128 //transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
1129 ////DBG dbg(0,"x=%d\n",pnt.x);
1130 ////DBG dbg(0,"y=%d\n",pnt.y);
1131 pc99.x = c99.x;
1132 pc99.y = c99.y;
1133 pc99.pro = projection_mg;
1134
1135 navit_set_center(global_navit, &pc99, 0);
1136
1137 result = g_strdup_printf("1:1");
1138 }
1139 else if (i == 4)
1140 {
1141 // return current target (the end point, not waypoints)
1142 struct coord_geo g22;
1143 struct pcoord c22;
1144 struct coord c99;
1145
1146 c22 = global_navit->destination;
1147 c99.x = c22.x;
1148 c99.y = c22.y;
1149
1150 transform_to_geo(projection_mg, &c99, &g22);
1151 result = g_strdup_printf("%f:%f", g22.lat, g22.lng);
1152 }
1153
1154 // dbg(0, "result=%s\n", result);
1155 jstring js = (*env)->NewStringUTF(env, result);
1156 g_free(result);
1157
1158 return js;
1159 }
1160
1161 JNIEXPORT jstring JNICALL
1162 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackLocalizedString(JNIEnv* env, jobject thiz, jobject str)
1163 {
1164 //DBG dbg(0,"EEnter\n");
1165
1166 const char *s;
1167 const char *localized_str;
1168
1169 s = (*env)->GetStringUTFChars(env, str, NULL);
1170 ////DBG dbg(0,"*****string=%s\n",s);
1171
1172 localized_str = gettext(s);
1173 ////DBG dbg(0,"localized string=%s",localized_str);
1174
1175 // jstring dataStringValue = (jstring) localized_str;
1176 jstring js = (*env)->NewStringUTF(env, localized_str);
1177
1178 (*env)->ReleaseStringUTFChars(env, str, s);
1179
1180 return js;
1181 }
1182
1183 JNIEXPORT void JNICALL
1184 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackMessageChannel(JNIEnv* env, jobject thiz, int i, jobject str2)
1185 {
1186 const char *s;
1187 jobject str = (*env)->NewGlobalRef(env, str2);
1188
1189 //DBG dbg(0,"enter %d %p\n",i,str);
1190
1191 config_get_attr(config, attr_navit, &attr, NULL);
1192 // attr.u.navit
1193
1194 //DBG dbg(0,"c1\n");
1195
1196 if (i)
1197 {
1198 if (i == 1)
1199 {
1200 // zoom in
1201 navit_zoom_in_cursor(global_navit, 2);
1202 // navit_zoom_in_cursor(attr.u.navit, 2);
1203 }
1204 else if (i == 2)
1205 {
1206 // zoom out
1207 navit_zoom_out_cursor(global_navit, 2);
1208 // navit_zoom_out_cursor(attr.u.navit, 2);
1209 }
1210 else if (i == 58)
1211 {
1212 // make street search radius bigger to the factor "s"
1213 s = (*env)->GetStringUTFChars(env, str, NULL);
1214 global_search_street_size_factor = atoi(s);
1215 (*env)->ReleaseStringUTFChars(env, str, s);
1216 }
1217 else if (i == 57)
1218 {
1219 // keep drawing streets as if at "order" level xxx
1220 s = (*env)->GetStringUTFChars(env, str, NULL);
1221 limit_order_corrected = atoi(s);
1222 (*env)->ReleaseStringUTFChars(env, str, s);
1223 }
1224 else if (i == 56)
1225 {
1226 // draw polylines with/without circles at the end
1227 //dbg(0, "dpf1\n");
1228 s = (*env)->GetStringUTFChars(env, str, NULL);
1229 //dbg(0, "dpf2\n");
1230 draw_polylines_fast = atoi(s);
1231 //dbg(0, "dpf=%d\n", draw_polylines_fast);
1232 (*env)->ReleaseStringUTFChars(env, str, s);
1233 }
1234 else if (i == 55)
1235 {
1236 // set cache size for (map-)files
1237 dbg(0, "csf1\n");
1238 s = (*env)->GetStringUTFChars(env, str, NULL);
1239 dbg(0, "csf2\n");
1240 cache_size_file = atoi(s);
1241 file_cache_init();
1242 dbg(0, "csf=%d\n", cache_size_file);
1243 (*env)->ReleaseStringUTFChars(env, str, s);
1244 }
1245 else if (i == 54)
1246 {
1247 // speak streetnames
1248 global_speak_streetnames = 1;
1249 }
1250 else if (i == 53)
1251 {
1252 // dont speak streetnames
1253 global_speak_streetnames = 0;
1254 }
1255 else if (i == 52)
1256 {
1257 // switch to demo vehicle
1258 if (global_navit->vehicle)
1259 {
1260 navit_remove_cursors(global_navit);
1261 vehicle_destroy(global_navit->vehicle->vehicle);
1262 global_navit->vehicles = NULL;
1263 global_navit->vehicle = NULL;
1264 }
1265
1266 struct attr parent;
1267 struct attr source;
1268 struct attr active;
1269 struct attr follow;
1270 struct attr speed;
1271 struct attr interval;
1272 struct attr *attrs[6];
1273 parent.type = attr_navit;
1274 parent.u.navit = global_navit;
1275
1276 source.type = attr_source;
1277 source.u.str = "demo://";
1278
1279 active.type = attr_active;
1280 active.u.num = 1;
1281
1282 follow.type = attr_follow;
1283 follow.u.num = 1;
1284
1285 speed.type = attr_speed;
1286 speed.u.num = 45;
1287
1288 interval.type = attr_interval;
1289 interval.u.num = 1000;
1290
1291 attrs[0] = &source;
1292 attrs[1] = &active;
1293 attrs[2] = &follow;
1294 attrs[3] = &speed;
1295 attrs[4] = &interval;
1296 attrs[5] = NULL;
1297 // attr_source -> source->u.str='demo://'
1298 // <!-- vehicle name="Demo" profilename="car" enabled="no" active="yes" source="demo://" -->
1299 struct vehicle *v;
1300 //DBG dbg(0, "demo vehicle new start\n");
1301 v = vehicle_new(&parent, attrs);
1302 //DBG dbg(0, "demo vehicle new end\n");
1303
1304 if (v != NULL)
1305 {
1306 //DBG dbg(0, "adding demo vehicle\n");
1307 navit_add_vehicle(global_navit, v);
1308 //DBG dbg(0, "setting cursor\n");
1309 navit_set_cursors(global_navit);
1310
1311 struct attr follow2;
1312 follow2.type = attr_follow;
1313 follow2.u.num = 1;
1314 navit_set_attr(global_navit, &follow2);
1315
1316 // switch "Map follows Vehicle" ON
1317 struct attr attrx;
1318 attrx.type = attr_follow_cursor;
1319 attrx.u.num = 1;
1320 navit_set_attr(global_navit, &attrx);
1321 }
1322 else
1323 {
1324 //DBG dbg(0, "ERROR adding demo vehicle\n");
1325 }
1326 // **no** navit_set_vehicle(global_navit, global_navit->vehicle);
1327 //DBG dbg(0, "ready\n");
1328 }
1329 else if (i == 51)
1330 {
1331 // set position to pixel x,y
1332 //DBG dbg(0, "sp 1\n");
1333 char *pstr;
1334 struct point p;
1335 struct coord c;
1336 struct pcoord pc;
1337
1338 s = (*env)->GetStringUTFChars(env, str, NULL);
1339 char parse_str[strlen(s) + 1];
1340 strcpy(parse_str, s);
1341 (*env)->ReleaseStringUTFChars(env, str, s);
1342
1343 // (pixel-x#pixel-y)
1344 // pixel-x
1345 pstr = strtok(parse_str, "#");
1346 p.x = atoi(pstr);
1347 // pixel-y
1348 pstr = strtok(NULL, "#");
1349 p.y = atoi(pstr);
1350
1351 //DBG dbg(0, "sp 2\n");
1352 transform_reverse(global_navit->trans, &p, &c);
1353 //DBG dbg(0, "sp 3\n");
1354
1355 pc.x = c.x;
1356 pc.y = c.y;
1357 //DBG dbg(0, "sp 4\n");
1358 pc.pro = transform_get_projection(global_navit->trans);
1359 //DBG dbg(0, "sp 5\n");
1360
1361 //DBG dbg(0, "%d %d\n", pc.x, pc.y);
1362 // set position
1363 //DBG dbg(0, "sp 6\n");
1364 navit_set_position(global_navit, &pc);
1365 //DBG dbg(0, "ready\n");
1366 }
1367 else if (i == 50)
1368 {
1369 // we request to stop drawing the map
1370 // //DBG dbg(0, "cancel_drawing_global=1\n");
1371 cancel_drawing_global = 1;
1372 }
1373 else if (i == 47)
1374 {
1375 // change maps data dir
1376 s = (*env)->GetStringUTFChars(env, str, NULL);
1377 navit_maps_dir = g_strdup(s);
1378 (*env)->ReleaseStringUTFChars(env, str, s);
1379 // //DBG dbg(0,"*****string use=%s\n",navit_maps_dir);
1380 }
1381 else if (i == 46)
1382 {
1383 // stop searching and show results found until now
1384 offline_search_break_searching = 1;
1385 }
1386 else if (i == 45)
1387 {
1388 // filter duplicates in search results
1389 offline_search_filter_duplicates = 1;
1390 }
1391 else if (i == 44)
1392 {
1393 // show duplicates in search results
1394 offline_search_filter_duplicates = 0;
1395 }
1396 else if (i == 43)
1397 {
1398 // routing mode "normal roads"
1399 routing_mode = 1;
1400 }
1401 else if (i == 42)
1402 {
1403 // routing mode "highways"
1404 routing_mode = 0;
1405 }
1406 else if (i == 41)
1407 {
1408 // switch "Map follows Vehicle" OFF
1409 struct attr attrx;
1410 attrx.type = attr_follow_cursor;
1411 attrx.u.num = 0;
1412 navit_set_attr(global_navit, &attrx);
1413 }
1414 else if (i == 40)
1415 {
1416 // switch "Map follows Vehicle" ON
1417 struct attr attrx;
1418 attrx.type = attr_follow_cursor;
1419 attrx.u.num = 1;
1420 navit_set_attr(global_navit, &attrx);
1421 }
1422 else if (i == 39)
1423 {
1424 // switch "Northing" OFF
1425 struct attr attrx;
1426 attrx.type = attr_orientation;
1427 attrx.u.num = 0;
1428 navit_set_attr(global_navit, &attrx);
1429 }
1430 else if (i == 38)
1431 {
1432 // switch "Northing" ON
1433 struct attr attrx;
1434 attrx.type = attr_orientation;
1435 attrx.u.num = 1;
1436 navit_set_attr(global_navit, &attrx);
1437 }
1438 else if (i == 37)
1439 {
1440 // switch "Lock on road" OFF
1441 struct attr attrx;
1442 attrx.type = attr_tracking;
1443 attrx.u.num = 0;
1444 navit_set_attr(global_navit, &attrx);
1445 }
1446 else if (i == 36)
1447 {
1448 // switch "Lock on road" ON
1449 struct attr attrx;
1450 attrx.type = attr_tracking;
1451 attrx.u.num = 1;
1452 navit_set_attr(global_navit, &attrx);
1453 }
1454 else if (i == 35)
1455 {
1456 // announcer voice ON
1457 navit_cmd_announcer_on(global_navit);
1458 }
1459 else if (i == 34)
1460 {
1461 // announcer voice OFF
1462 navit_cmd_announcer_off(global_navit);
1463 }
1464 else if (i == 33)
1465 {
1466 // zoom to specific zoomlevel
1467 s = (*env)->GetStringUTFChars(env, str, NULL);
1468 int zoom_level = atoi(s);
1469 navit_zoom_to_scale(global_navit, zoom_level);
1470 (*env)->ReleaseStringUTFChars(env, str, s);
1471 }
1472 else if (i == 32)
1473 {
1474 // switch to specific 3D pitch
1475 struct attr pitch_attr;
1476 s = (*env)->GetStringUTFChars(env, str, NULL);
1477 pitch_attr.type = attr_pitch;
1478 pitch_attr.u.num = atoi(s);
1479 navit_set_attr(global_navit, &pitch_attr);
1480 (*env)->ReleaseStringUTFChars(env, str, s);
1481 }
1482 else if (i == 31)
1483 {
1484 // switch to 3D
1485 struct attr pitch_attr;
1486 pitch_attr.type = attr_pitch;
1487 pitch_attr.u.num = 30;
1488 navit_set_attr(global_navit, &pitch_attr);
1489 }
1490 else if (i == 30)
1491 {
1492 // switch to 2D
1493 struct attr pitch_attr;
1494 pitch_attr.type = attr_pitch;
1495 pitch_attr.u.num = 0;
1496 navit_set_attr(global_navit, &pitch_attr);
1497 }
1498 // 21 - 25 are used in java, so leave a hole here to make it easier to understand
1499
1500 else if (i == 20)
1501 {
1502 // add all scdard maps
1503 navit_add_all_maps(global_navit);
1504 }
1505 else if (i == 19)
1506 {
1507 // remove all scdard maps
1508 navit_remove_all_maps(global_navit);
1509 }
1510 else if (i == 18)
1511 {
1512 // reload scdard maps
1513 navit_reload_maps(global_navit);
1514 }
1515 else if (i == 17)
1516 {
1517 // zoom to route
1518 navit_zoom_to_route(global_navit, 0);
1519 }
1520 else if (i == 16)
1521 {
1522 // use imperial units
1523 global_navit->imperial = 1;
1524 }
1525 else if (i == 15)
1526 {
1527 // use metric units
1528 global_navit->imperial = 0;
1529 }
1530 else if (i == 14)
1531 {
1532 // draw location of self (car) in the screen center
1533 global_navit->radius = 0;
1534 }
1535 else if (i == 13)
1536 {
1537 // draw location of self (car) 30% lower than screen center
1538 global_navit->radius = 30;
1539 }
1540 else if (i == 12)
1541 {
1542 // draw map only at speeds higher than 5 km/h
1543 struct attr static_speed_attr;
1544 static_speed_attr.type = attr_static_speed;
1545 static_speed_attr.u.num = 5;
1546 vehicleprofile_set_attr(global_navit->vehicleprofile, &static_speed_attr);
1547 }
1548 else if (i == 11)
1549 {
1550 // allow redraw map at ZERO speed
1551 struct attr static_speed_attr;
1552 static_speed_attr.type = attr_static_speed;
1553 static_speed_attr.u.num = 0;
1554 vehicleprofile_set_attr(global_navit->vehicleprofile, &static_speed_attr);
1555 }
1556 else if (i == 10)
1557 {
1558 // allow internal GUI
1559 allow_gui_internal = 1;
1560 }
1561 else if (i == 9)
1562 {
1563 // disable internal GUI
1564 allow_gui_internal = 0;
1565 }
1566 else if (i == 8)
1567 {
1568 // zoom to zoomlevel
1569 //DBG dbg(0,"-8- a\n");
1570 navit_zoom_to_scale(global_navit, 524288);
1571 //DBG dbg(0,"-8- b\n");
1572 }
1573 else if (i == 7)
1574 {
1575 // stop navigation
1576 if (attr.u.navit->destination_valid != 0)
1577 {
1578 navit_set_destination(&attr.u.navit->self, NULL, NULL, 0);
1579 }
1580 }
1581 else if (i == 6)
1582 {
1583 // not used now!
1584 }
1585 else if (i == 5)
1586 {
1587 // call a command (like in gui) --> seems not many commands really work with this :-(
1588 s = (*env)->GetStringUTFChars(env, str, NULL);
1589 ////DBG dbg(0,"*****string=%s\n",s);
1590 command_evaluate(&attr.u.navit->self, s);
1591 (*env)->ReleaseStringUTFChars(env, str, s);
1592 }
1593 else if (i == 49)
1594 {
1595 // add waypoint at pixel x,y on screen
1596
1597 char *pstr;
1598 struct point p;
1599 struct coord c;
1600 struct pcoord pc;
1601
1602 s = (*env)->GetStringUTFChars(env, str, NULL);
1603 char parse_str[strlen(s) + 1];
1604 strcpy(parse_str, s);
1605 (*env)->ReleaseStringUTFChars(env, str, s);
1606
1607 // add waypoint (pixel-x#pixel-y)
1608 // pixel-x
1609 pstr = strtok(parse_str, "#");
1610 p.x = atoi(pstr);
1611 // pixel-y
1612 pstr = strtok(NULL, "#");
1613 p.y = atoi(pstr);
1614
1615 transform_reverse(global_navit->trans, &p, &c);
1616
1617 pc.x = c.x;
1618 pc.y = c.y;
1619 pc.pro = transform_get_projection(global_navit->trans);
1620
1621 // append new waypoint to navigation
1622 navit_add_waypoint_to_route(global_navit, &pc, parse_str, 1);
1623 }
1624 else if (i == 4)
1625 {
1626 // set destination to pixel x,y on screen
1627
1628 char *pstr;
1629 struct point p;
1630 struct coord c;
1631 struct pcoord pc;
1632
1633 s = (*env)->GetStringUTFChars(env, str, NULL);
1634 char parse_str[strlen(s) + 1];
1635 strcpy(parse_str, s);
1636 (*env)->ReleaseStringUTFChars(env, str, s);
1637
1638 // set destination to (pixel-x#pixel-y)
1639 // pixel-x
1640 pstr = strtok(parse_str, "#");
1641 p.x = atoi(pstr);
1642 // pixel-y
1643 pstr = strtok(NULL, "#");
1644 p.y = atoi(pstr);
1645
1646 transform_reverse(global_navit->trans, &p, &c);
1647
1648 pc.x = c.x;
1649 pc.y = c.y;
1650 pc.pro = transform_get_projection(global_navit->trans);
1651
1652 // start navigation asynchronous
1653 navit_set_destination(global_navit, &pc, parse_str, 1);
1654 }
1655 else if (i == 48)
1656 {
1657 // append waypoint at lat, lng
1658
1659 char *name;
1660 s = (*env)->GetStringUTFChars(env, str, NULL);
1661 char parse_str[strlen(s) + 1];
1662 strcpy(parse_str, s);
1663 (*env)->ReleaseStringUTFChars(env, str, s);
1664
1665 // waypoint (lat#lon#title)
1666 struct coord_geo g;
1667 char *p;
1668 char *stopstring;
1669
1670 // lat
1671 p = strtok(parse_str, "#");
1672 g.lat = strtof(p, &stopstring);
1673 // lon
1674 p = strtok(NULL, "#");
1675 g.lng = strtof(p, &stopstring);
1676 // description
1677 name = strtok(NULL, "#");
1678
1679 ////DBG dbg(0,"lat=%f\n",g.lat);
1680 ////DBG dbg(0,"lng=%f\n",g.lng);
1681 ////DBG dbg(0,"str1=%s\n",name);
1682
1683 struct coord c;
1684 transform_from_geo(projection_mg, &g, &c);
1685
1686 struct pcoord pc;
1687 pc.x = c.x;
1688 pc.y = c.y;
1689 pc.pro = projection_mg;
1690
1691 // append new waypoint to navigation
1692 navit_add_waypoint_to_route(global_navit, &pc, name, 1);
1693 }
1694 else if (i == 3)
1695 {
1696 // set destination to lat, lng
1697
1698 char *name;
1699 s = (*env)->GetStringUTFChars(env, str, NULL);
1700 char parse_str[strlen(s) + 1];
1701 strcpy(parse_str, s);
1702 (*env)->ReleaseStringUTFChars(env, str, s);
1703 ////DBG dbg(0,"*****string=%s\n",s);
1704
1705 // set destination to (lat#lon#title)
1706 struct coord_geo g;
1707 char *p;
1708 char *stopstring;
1709
1710 // lat
1711 p = strtok(parse_str, "#");
1712 g.lat = strtof(p, &stopstring);
1713 // lon
1714 p = strtok(NULL, "#");
1715 g.lng = strtof(p, &stopstring);
1716 // description
1717 name = strtok(NULL, "#");
1718
1719 ////DBG dbg(0,"lat=%f\n",g.lat);
1720 ////DBG dbg(0,"lng=%f\n",g.lng);
1721 ////DBG dbg(0,"str1=%s\n",name);
1722
1723 struct coord c;
1724 transform_from_geo(projection_mg, &g, &c);
1725
1726 struct pcoord pc;
1727 pc.x = c.x;
1728 pc.y = c.y;
1729 pc.pro = projection_mg;
1730
1731 // start navigation asynchronous
1732 navit_set_destination(global_navit, &pc, name, 1);
1733
1734 }
1735 }
1736
1737 //DBG dbg(0,"deleteglobalref\n");
1738
1739 (*env)->DeleteGlobalRef(env, str);
1740 str = NULL;
1741
1742 //DBG dbg(0,"leave\n");
1743
1744 }
1745
1746 void android_send_generic_text(int id, char *text)
1747 {
1748 //DBG dbg(0,"Enter\n");
1749
1750 if (NavitGraphicsClass2 == NULL)
1751 {
1752 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
1753 {
1754 NavitGraphicsClass2 = NULL;
1755 return;
1756 }
1757 }
1758 //DBG dbg(0,"x1\n");
1759 if (send_generic_text == NULL)
1760 {
1761 android_find_static_method(NavitGraphicsClass2, "send_generic_text", "(ILjava/lang/String;)V", &send_generic_text);
1762 }
1763 //DBG dbg(0,"x2\n");
1764 if (send_generic_text == NULL)
1765 {
1766 //DBG dbg(0, "no method found\n");
1767 return; /* exception thrown */
1768 }
1769 //DBG dbg(0,"x3\n");
1770
1771 jstring string1 = (*jnienv)->NewStringUTF(jnienv, text);
1772 (*jnienv)->CallStaticVoidMethod(jnienv, NavitGraphicsClass2, send_generic_text, id, string1);
1773 (*jnienv)->DeleteLocalRef(jnienv, string1);
1774
1775 //DBG dbg(0,"leave\n");
1776 }
1777

   
Visit the ZANavi Wiki