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

Contents of /navit/navit/android.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (9 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 35620 byte(s)
import files
1 #include <stdlib.h>
2 #include <string.h>
3 #include <poll.h>
4 #include <glib.h>
5 #include "android.h"
6 #include <android/log.h>
7 #include "navit.h"
8 #include "config_.h"
9 #include "command.h"
10 #include "debug.h"
11 #include "event.h"
12 #include "callback.h"
13 #include "projection.h"
14 #include "map.h"
15 #include "transform.h"
16 #include "color.h"
17 #include "types.h"
18 #include "search.h"
19 #include "start_real.h"
20 #include "route.h"
21
22 // #include "layout.h"
23
24 JNIEnv *jnienv;
25 jobject *android_activity;
26 struct callback_list *android_activity_cbl;
27 int android_version;
28
29 jclass NavitGraphicsClass2=NULL;
30 jmethodID return_generic_int;
31 jclass NavitMapPreviewActivityClass=NULL;
32 jmethodID DrawMapPreview_target;
33 jmethodID DrawMapPreview_polyline=NULL;
34 jmethodID DrawMapPreview_text=NULL;
35
36 struct attr attr;
37
38 struct config {
39 struct attr **attrs;
40 struct callback_list *cbl;
41 } *config;
42
43
44 struct gui_config_settings {
45 int dummy;
46 };
47
48 struct gui_internal_data {
49 int dummy;
50 };
51
52 struct route_data {
53 int dummy;
54 };
55
56 struct widget {
57 int dummy;
58 };
59
60 struct gui_priv {
61 struct navit *nav;
62 struct attr self;
63 struct window *win;
64 struct graphics *gra;
65 struct graphics_gc *background;
66 struct graphics_gc *background2;
67 struct graphics_gc *highlight_background;
68 struct graphics_gc *foreground;
69 struct graphics_gc *text_foreground;
70 struct graphics_gc *text_background;
71 struct color background_color, background2_color, text_foreground_color, text_background_color;
72 int spacing;
73 int font_size;
74 int fullscreen;
75 struct graphics_font *fonts[3];
76 /**
77 * The size (in pixels) that xs style icons should be scaled to.
78 * This icon size can be too small to click it on some devices.
79 */
80 int icon_xs;
81 /**
82 * The size (in pixels) that s style icons (small) should be scaled to
83 */
84 int icon_s;
85 /**
86 * The size (in pixels) that l style icons should be scaled to
87 */
88 int icon_l;
89 int pressed;
90 struct widget *widgets;
91 int widgets_count;
92 int redraw;
93 struct widget root;
94 struct widget *highlighted,*editable;
95 struct widget *highlighted_menu;
96 int clickp_valid, vehicle_valid;
97 struct pcoord clickp, vehiclep;
98 struct attr *click_coord_geo, *position_coord_geo;
99 struct search_list *sl;
100 int ignore_button;
101 int menu_on_map_click;
102 int signal_on_map_click;
103 char *country_iso2;
104 int speech;
105 int keyboard;
106 int keyboard_required;
107 /**
108 * The setting information read from the configuration file.
109 * values of -1 indicate no value was specified in the config file.
110 */
111 struct gui_config_settings config;
112 struct event_idle *idle;
113 struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
114 struct event_timeout *motion_timeout_event;
115 struct point current;
116
117 struct callback * vehicle_cb;
118 /**
119 * Stores information about the route.
120 */
121 struct route_data route_data;
122
123 struct gui_internal_data data;
124 struct callback_list *cbl;
125 int flags;
126 int cols;
127 struct attr osd_configuration;
128 int pitch;
129 int flags_town,flags_street,flags_house_number;
130 int radius;
131 /* html */
132 char *html_text;
133 int html_depth;
134 struct widget *html_container;
135 int html_skip;
136 char *html_anchor;
137 char *href;
138 int html_anchor_found;
139 struct form *form;
140 struct html {
141 int skip;
142 enum html_tag {
143 html_tag_none,
144 html_tag_a,
145 html_tag_h1,
146 html_tag_html,
147 html_tag_img,
148 html_tag_script,
149 html_tag_form,
150 html_tag_input,
151 html_tag_div,
152 } tag;
153 char *command;
154 char *name;
155 char *href;
156 char *refresh_cond;
157 struct widget *w;
158 struct widget *container;
159 } html[10];
160 };
161
162
163
164
165 static void
166 gui_internal_search_list_set_default_country2(struct gui_priv *this)
167 {
168 struct attr search_attr, country_name, country_iso2, *country_attr;
169 struct item *item;
170 struct country_search *cs;
171 struct tracking *tracking;
172 struct search_list_result *res;
173
174 //dbg(0,"### 1");
175
176 country_attr=country_default();
177 tracking=navit_get_tracking(this->nav);
178
179 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
180 country_attr=&search_attr;
181 if (country_attr) {
182 //dbg(0,"### 2");
183 cs=country_search_new(country_attr, 0);
184 item=country_search_get_item(cs);
185 if (item && item_attr_get(item, attr_country_name, &country_name)) {
186 search_attr.type=attr_country_all;
187 //dbg(0,"country %s\n", country_name.u.str);
188 search_attr.u.str=country_name.u.str;
189 search_list_search(this->sl, &search_attr, 0);
190 while((res=search_list_get_result(this->sl)));
191 if(this->country_iso2)
192 {
193 // this seems to cause a crash, no idea why
194 //g_free(this->country_iso2);
195 this->country_iso2=NULL;
196 }
197 if (item_attr_get(item, attr_country_iso2, &country_iso2))
198 {
199 this->country_iso2=g_strdup(country_iso2.u.str);
200 }
201 }
202 country_search_destroy(cs);
203 } else {
204 dbg(0,"warning: no default country found\n");
205 if (this->country_iso2) {
206 dbg(0,"attempting to use country '%s'\n",this->country_iso2);
207 search_attr.type=attr_country_iso2;
208 search_attr.u.str=this->country_iso2;
209 search_list_search(this->sl, &search_attr, 0);
210 while((res=search_list_get_result(this->sl)));
211 }
212 }
213 //dbg(0,"### 99");
214 }
215
216
217
218 struct navit *global_navit;
219
220
221 int
222 android_find_class_global(char *name, jclass *ret)
223 {
224 *ret=(*jnienv)->FindClass(jnienv, name);
225 if (! *ret) {
226 dbg(0,"Failed to get Class %s\n",name);
227 return 0;
228 }
229 (*jnienv)->NewGlobalRef(jnienv, *ret);
230 return 1;
231 }
232
233 int
234 android_find_method(jclass class, char *name, char *args, jmethodID *ret)
235 {
236 *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
237 if (*ret == NULL) {
238 dbg(0,"Failed to get Method %s with signature %s\n",name,args);
239 return 0;
240 }
241 return 1;
242 }
243
244 int
245 android_find_static_method(jclass class, char *name, char *args, jmethodID *ret)
246 {
247 *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
248 if (*ret == NULL) {
249 dbg(0,"Failed to get static Method %s with signature %s\n",name,args);
250 return 0;
251 }
252 return 1;
253 }
254
255 JNIEXPORT void JNICALL
256 Java_com_zoffcc_applications_zanavi_Navit_NavitMain( JNIEnv* env, jobject thiz, jobject activity, jobject lang, int version, jobject display_density_string)
257 {
258 char *strings[]={"/data/data/com.zoffcc.applications.zanavi/bin/navit",NULL};
259 const char *langstr;
260 const char *displaydensitystr;
261 android_version=version;
262 //__android_log_print(ANDROID_LOG_ERROR,"test","called");
263 android_activity_cbl=callback_list_new();
264 jnienv=env;
265 android_activity=activity;
266 (*jnienv)->NewGlobalRef(jnienv, activity);
267 langstr=(*env)->GetStringUTFChars(env, lang, NULL);
268 dbg(0,"enter env=%p thiz=%p activity=%p lang=%s version=%d\n",env,thiz,activity,langstr,version);
269 setenv("LANG",langstr,1);
270 (*env)->ReleaseStringUTFChars(env, lang, langstr);
271
272 displaydensitystr=(*env)->GetStringUTFChars(env, display_density_string, NULL);
273 dbg(0,"*****displaydensity=%s\n",displaydensitystr);
274 setenv("ANDROID_DENSITY",displaydensitystr,1);
275 (*env)->ReleaseStringUTFChars(env, display_density_string, displaydensitystr);
276 main_real(1, strings);
277 }
278
279 JNIEXPORT void JNICALL
280 Java_com_zoffcc_applications_zanavi_Navit_NavitActivity( JNIEnv* env, jobject thiz, int param)
281 {
282 dbg(0,"enter %d\n",param);
283
284 if (param == -2)
285 {
286 // onStop() -> called in Java app
287 // save center.txt
288 if (global_navit->bookmarks)
289 {
290 config_get_attr(config, attr_navit, &attr, NULL);
291 dbg(0,"save position to file");
292 char *center_file = bookmarks_get_center_file(TRUE);
293 bookmarks_write_center_to_file(attr.u.navit->bookmarks, center_file);
294 g_free(center_file);
295 // bookmarks_destroy(global_navit->bookmarks);
296 }
297 }
298
299 callback_list_call_1(android_activity_cbl, param);
300 if (param == -3)
301 {
302 exit(0);
303 }
304 //if (param == -3)
305 //{
306 // event_main_loop_quit();
307 //}
308 }
309
310 JNIEXPORT void JNICALL
311 Java_com_zoffcc_applications_zanavi_NavitGraphics_SizeChangedCallback( JNIEnv* env, jobject thiz, int id, int w, int h)
312 {
313 //dbg(0,"enter %p %d %d\n",(struct callback *)id,w,h);
314 if (id)
315 {
316 callback_call_2((struct callback *)id,w,h);
317 }
318 }
319
320 JNIEXPORT void JNICALL
321 Java_com_zoffcc_applications_zanavi_NavitGraphics_ButtonCallback( JNIEnv* env, jobject thiz, int id, int pressed, int button, int x, int y)
322 {
323 dbg(1,"enter %p %d %d\n",(struct callback *)id,pressed,button);
324 if (id)
325 callback_call_4((struct callback *)id,pressed,button,x,y);
326 }
327
328 JNIEXPORT void JNICALL
329 Java_com_zoffcc_applications_zanavi_NavitGraphics_MotionCallback( JNIEnv* env, jobject thiz, int id, int x, int y)
330 {
331 dbg(1,"enter %p %d %d\n",(struct callback *)id,x,y);
332 if (id)
333 callback_call_2((struct callback *)id,x,y);
334 }
335
336 JNIEXPORT void JNICALL
337 Java_com_zoffcc_applications_zanavi_NavitGraphics_KeypressCallback( JNIEnv* env, jobject thiz, int id, jobject str)
338 {
339 const char *s;
340 //dbg(0,"enter %p %p\n",(struct callback *)id,str);
341 s=(*env)->GetStringUTFChars(env, str, NULL);
342 //dbg(0,"key=%s\n",s);
343 if (id)
344 callback_call_1((struct callback *)id,s);
345 (*env)->ReleaseStringUTFChars(env, str, s);
346 }
347
348 JNIEXPORT void JNICALL
349 Java_com_zoffcc_applications_zanavi_NavitTimeout_TimeoutCallback( JNIEnv* env, jobject thiz, int delete, int id)
350 {
351 // dbg(1,"enter %p %d %p\n",thiz, delete, (void *)id);
352 callback_call_0((struct callback *)id);
353 if (delete)
354 {
355 (*jnienv)->DeleteGlobalRef(jnienv, thiz);
356 }
357 }
358
359 JNIEXPORT void JNICALL
360 Java_com_zoffcc_applications_zanavi_NavitVehicle_VehicleCallback( JNIEnv * env, jobject thiz, int id, jobject location)
361 {
362 // dbg(0,"enter %p %p\n",thiz, (void *)id);
363
364 // ***** calls: vehicle_android.c -> vehicle_android_callback()
365 callback_call_1((struct callback *)id, (void *)location);
366 }
367
368 JNIEXPORT void JNICALL
369 Java_com_zoffcc_applications_zanavi_NavitIdle_IdleCallback( JNIEnv* env, jobject thiz, int id)
370 {
371 // dbg(0,"enter %p %p\n",thiz, (void *)id);
372 callback_call_0((struct callback *)id);
373 }
374
375 JNIEXPORT void JNICALL
376 Java_com_zoffcc_applications_zanavi_NavitWatch_poll( JNIEnv* env, jobject thiz, int fd, int cond)
377 {
378 struct pollfd pfd;
379 pfd.fd=fd;
380 dbg(1,"%p poll called for %d %d\n",env, fd, cond);
381 switch ((enum event_watch_cond)cond) {
382 case event_watch_cond_read:
383 pfd.events=POLLIN;
384 break;
385 case event_watch_cond_write:
386 pfd.events=POLLOUT;
387 break;
388 case event_watch_cond_except:
389 pfd.events=POLLERR;
390 break;
391 default:
392 pfd.events=0;
393 }
394 pfd.revents=0;
395 poll(&pfd, 1, -1);
396 }
397
398 JNIEXPORT void JNICALL
399 Java_com_zoffcc_applications_zanavi_NavitWatch_WatchCallback( JNIEnv* env, jobject thiz, int id)
400 {
401 dbg(1,"enter %p %p\n",thiz, (void *)id);
402 callback_call_0((struct callback *)id);
403 }
404
405
406 JNIEXPORT void JNICALL
407 Java_com_zoffcc_applications_zanavi_NavitSensors_SensorCallback( JNIEnv* env, jobject thiz, int id, int sensor, float x, float y, float z)
408 {
409 dbg(1,"enter %p %p %f %f %f\n",thiz, (void *)id,x,y,z);
410 callback_call_4((struct callback *)id, sensor, &x, &y, &z);
411 }
412
413 void
414 android_return_search_result(struct jni_object *jni_o, char *str)
415 {
416 jstring js2 = NULL;
417 JNIEnv* env2;
418 env2=jni_o->env;
419 js2 = (*env2)->NewStringUTF(jni_o->env,str);
420 (*env2)->CallVoidMethod(jni_o->env, jni_o->jo, jni_o->jm, js2);
421 (*env2)->DeleteLocalRef(jni_o->env, js2);
422 }
423
424 void
425 android_return_generic_int(int id, int i)
426 {
427 if (NavitGraphicsClass2 == NULL)
428 {
429 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
430 {
431 NavitGraphicsClass2=NULL;
432 return;
433 }
434 }
435 if (return_generic_int == NULL)
436 {
437 android_find_static_method(NavitGraphicsClass2,"return_generic_int", "(II)V", &return_generic_int);
438 }
439 if (return_generic_int == NULL)
440 {
441 dbg(0,"no method found\n");
442 return; /* exception thrown */
443 }
444 // -crash- (*jnienv)->CallVoidMethod(jnienv, NavitGraphicsClass2, return_generic_int, id, i);
445 (*jnienv)->CallStaticVoidMethod(jnienv, NavitGraphicsClass2, return_generic_int, id, i);
446 // -works- (*jnienv)->CallStaticObjectMethod(jnienv, NavitGraphicsClass2, return_generic_int, id, i);
447 }
448
449
450 JNIEXPORT void JNICALL
451 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)
452 {
453 const char *s;
454 s=(*env)->GetStringUTFChars(env, str, NULL);
455 //dbg(0,"*****string=%s\n",s);
456
457
458 config_get_attr(config, attr_navit, &attr, NULL);
459 // attr.u.navit
460
461 jstring js2 = NULL;
462 jclass cls = (*env)->GetObjectClass(env,thiz);
463 jmethodID aMethodID = (*env)->GetMethodID(env, cls, "fillStringArray", "(Ljava/lang/String;)V");
464 if(aMethodID == 0)
465 {
466 //dbg(0,"**** Unable to get methodID: fillStringArray");
467 return;
468 }
469
470 if (id)
471 {
472 // search for town in variable "s" within current country -> return a list of towns as result
473 if (id==1)
474 {
475 // unused now!!
476 }
477 // search for street in variable "s" within "search_country" -> return a list of streets as result
478 else if (id == 2)
479 {
480 //struct attr s_attr4;
481 //struct gui_priv *gp4;
482 //struct gui_priv gp_24;
483
484
485 struct jni_object my_jni_object;
486 my_jni_object.env=env;
487 my_jni_object.jo=thiz;
488 my_jni_object.jm=aMethodID;
489
490 //gp4=&gp_24;
491 //gp4->nav=attr.u.navit;
492 struct mapset *ms4=navit_get_mapset(attr.u.navit);
493 GList *ret=NULL;
494 int flags=search_flags;
495 char *search_country_string=(*env)->GetStringUTFChars(env, search_country, NULL);
496 ret=search_by_address(ret,ms4,s,partial,&my_jni_object,flags,search_country_string);
497 (*env)->ReleaseStringUTFChars(env, search_country, search_country_string);
498
499 // free the memory
500 g_list_free(ret);
501 //dbg(0,"ret=%p\n",ret);
502
503
504 //if (gp4->sl)
505 //{
506 // //search_list_destroy(gp4->sl);
507 // gp4->sl=NULL;
508 //}
509 }
510 // do a full search in all mapfiles for string in variable "s" -> return a list of streets as result
511 else if (id == 3)
512 {
513 const char *s3;
514 s3=(*env)->GetStringUTFChars(env, latlon, NULL);
515 char parse_str[strlen(s3) + 1];
516 strcpy(parse_str, s3);
517 (*env)->ReleaseStringUTFChars(env, latlon, s3);
518
519 struct coord_geo g7;
520 char *p;
521 char *stopstring;
522
523 // lat
524 p = strtok (parse_str,"#");
525 g7.lat = strtof(p, &stopstring);
526 // lon
527 p = strtok (NULL, "#");
528 g7.lng = strtof(p, &stopstring);
529
530 struct jni_object my_jni_object;
531 my_jni_object.env=env;
532 my_jni_object.jo=thiz;
533 my_jni_object.jm=aMethodID;
534 // search_flags --> is search_order (search at what "order" level)
535 search_full_world(s, partial, search_flags, &my_jni_object, &g7, radius);
536 }
537 }
538
539 (*env)->ReleaseStringUTFChars(env, str, s);
540 }
541
542 JNIEXPORT jint JNICALL
543 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackDestinationValid( JNIEnv* env, jobject thiz)
544 {
545 config_get_attr(config, attr_navit, &attr, NULL);
546 // dbg(0,"destination_valid=%d\n",attr.u.navit->destination_valid);
547 jint i=0;
548 if (attr.u.navit->route)
549 {
550 struct route *r;
551 r=attr.u.navit->route;
552 i=r->route_status;
553 // dbg(0,"route_status=%d\n",i);
554 }
555 return i;
556 }
557
558 static void map_preview_label_line(struct point *p, int count, char *label, int font_size)
559 {
560 int i,x,y,tl,tlm,th,thm,tlsq,l;
561 float lsq;
562 double dx,dy;
563 struct point p_t;
564 struct point pb[5];
565
566 int len = g_utf8_strlen(label, -1);
567 int xMin = 0;
568 int yMin = 0;
569 int yMax = 13*font_size/256;
570 int xMax = 9*font_size*len/256;
571
572 //dbg(0,"xMax=%d\n", xMax);
573 //dbg(0,"yMax=%d\n", yMax);
574
575 pb[0].x = xMin;
576 pb[0].y = -yMin;
577 pb[1].x = xMin;
578 pb[1].y = -yMax;
579 pb[2].x = xMax;
580 pb[2].y = -yMax;
581 pb[3].x = xMax;
582 pb[3].y = -yMin;
583
584 tl=(pb[2].x-pb[0].x);
585 th=(pb[0].y-pb[1].y);
586
587 // calc "tl" text length
588 // tl=strlen(label)*4;
589 // calc "th" text height
590 // th=8;
591
592 tlm=tl*32;
593 thm=th*36;
594 tlsq = (tlm*0.7)*(tlm*0.7);
595
596 for (i = 0 ; i < count-1 ; i++)
597 {
598 dx=p[i+1].x-p[i].x;
599 dx*=32;
600 dy=p[i+1].y-p[i].y;
601 dy*=32;
602 lsq = dx*dx+dy*dy;
603
604 if (lsq > tlsq)
605 {
606 //dbg(0,"-------- label=%s\n",label);
607 //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);
608 //dbg(0,"dx=%f dy=%f\n",dx,dy);
609 l=(int)sqrtf(lsq);
610 //dbg(0,"l=%d lsq=%f\n",l,lsq);
611 x=p[i].x;
612 y=p[i].y;
613 if (dx < 0)
614 {
615 dx=-dx;
616 dy=-dy;
617 x=p[i+1].x;
618 y=p[i+1].y;
619 }
620 x+=(l-tlm)*dx/l/64;
621 y+=(l-tlm)*dy/l/64;
622 x-=dy*thm/l/64;
623 y+=dx*thm/l/64;
624 p_t.x=x;
625 p_t.y=y;
626
627 //dbg(0,"dx=%f dy=%f\n",dx,dy);
628 //dbg(0,"dx=%d dy=%d\n",(int)dx,(int)dy);
629 //dbg(0,"draw px=%d py=%d\n",p_t.x,p_t.y);
630 //dbg(0,"l=%d\n",l);
631 //dbg(0,"+++++++++++++\n");
632 // **OLD and wrong** android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, dx*0x10000/l, dy*0x10000/l);
633 android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, (int)dx, (int)dy);
634 }
635 }
636 }
637
638
639 JNIEXPORT void JNICALL
640 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)
641 {
642 // config_get_attr(config, attr_navit, &attr, NULL);
643
644 const char *s;
645 int zoom;
646 s=(*env)->GetStringUTFChars(env, latlonzoom, NULL);
647 char parse_str[strlen(s) + 1];
648 strcpy(parse_str, s);
649 (*env)->ReleaseStringUTFChars(env, latlonzoom, s);
650 //dbg(0,"*****string=%s\n",s);
651
652 // show map preview for (lat#lon#zoom)
653 struct coord_geo g;
654 char *p;
655 char *stopstring;
656
657 // lat
658 p = strtok (parse_str,"#");
659 g.lat = strtof(p, &stopstring);
660 // lon
661 p = strtok (NULL, "#");
662 g.lng = strtof(p, &stopstring);
663 // zoom
664 p = strtok (NULL, "#");
665 zoom=atoi(p);
666
667 //dbg(0,"lat=%f\n",g.lat);
668 //dbg(0,"lng=%f\n",g.lng);
669 //dbg(0,"zoom=%d\n",zoom);
670 //dbg(0,"w=%d\n",width);
671 //dbg(0,"h=%d\n",height);
672
673 struct coord c;
674 transform_from_geo(projection_mg, &g, &c);
675
676 // struct pcoord pc;
677 // pc.x=c.x;
678 // pc.y=c.y;
679 // pc.pro=projection_mg;
680
681
682 // ----------------------- big draw loop -----------------------
683 // ----------------------- big draw loop -----------------------
684 // ----------------------- big draw loop -----------------------
685 // ----------------------- big draw loop -----------------------
686 struct item *item;
687 struct map_rect *mr=NULL;
688 struct mapset *ms;
689 struct mapset_handle *msh;
690 struct map* map = NULL;
691 struct attr map_name_attr;
692 struct attr attr;
693
694 struct map_selection sel;
695 const int selection_range = sel_range; // should be something with "width" and "height" i guess ??!!
696
697 const int max=100;
698 int count;
699 struct coord *ca=g_alloca(sizeof(struct coord)*max);
700 struct point *pa=g_alloca(sizeof(struct point)*max);
701
702 sel.next=NULL;
703 sel.order=zoom;
704 sel.range.min=type_none;
705 sel.range.max=type_last;
706 sel.u.c_rect.lu.x=c.x-selection_range;
707 sel.u.c_rect.lu.y=c.y+selection_range;
708 sel.u.c_rect.rl.x=c.x+selection_range;
709 sel.u.c_rect.rl.y=c.y-selection_range;
710
711 struct transformation *tr;
712 tr=transform_dup(global_navit->trans);
713 struct point p_center;
714 p_center.x=width/2;
715 p_center.y=height/2;
716 transform_set_screen_center(tr, &p_center);
717 transform_set_center(tr, &c);
718 transform_set_scale(tr, scale);
719 enum projection pro=transform_get_projection(global_navit->trans_cursor);
720
721 ms=global_navit->mapsets->data;
722 msh=mapset_open(ms);
723 while (msh && (map=mapset_next(msh, 0)))
724 {
725 if(map_get_attr(map,attr_name, &map_name_attr,NULL))
726 {
727 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
728 {
729 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/borders.bin", map_name_attr.u.str, 41) == 0)
730 {
731 // country borders
732 // dbg(0,"map name=%s",map_name_attr.u.str);
733 mr=map_rect_new(map, NULL);
734 if (mr)
735 {
736 while ((item=map_rect_get_item(mr)))
737 {
738
739 // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
740 count=item_coord_get_within_selection(item, ca, max, &sel);
741 if (! count)
742 {
743 continue;
744 }
745 count=transform(tr, pro, ca, pa, count, 0, 0, NULL);
746
747 // dbg(0,"uu %s\n",item_to_name(item->type));
748
749 if (item->type == type_border_country)
750 {
751 // dbg(0,"BB** %s\n",item_to_name(item->type));
752 android_DrawMapPreview_polyline(pa, count, 2);
753 }
754 }
755 map_rect_destroy(mr);
756 }
757 }
758 else if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0)
759 {
760 // its an sdcard map
761 // dbg(0,"map name=%s",map_name_attr.u.str);
762 mr=map_rect_new(map, &sel);
763 if (mr)
764 {
765 //char *streetname_last=NULL;
766
767 while ((item=map_rect_get_item(mr)))
768 {
769 int label_count=0;
770 char *labels[2];
771
772 // count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, &sel);
773 count=item_coord_get_within_selection(item, ca, max, &sel);
774
775
776 // count=item_coord_get_within_selection(item, ca, max, &sel);
777 // count=item_coord_get(item, ca, item->type < type_line ? 1: max);
778 if (! count)
779 {
780 continue;
781 }
782 //dbg(0,"count 1=%d\n", count);
783
784 if (count == max)
785 {
786 //dbg(0,"count overflow!!\n");
787 }
788
789 struct attr attr_77;
790 if (item_attr_get(item, attr_flags, &attr_77))
791 {
792 //dbg(0,"uuuuuuuuuuuuu %s uuuuu %d\n",item_to_name(item->type), attr_77.u.num);
793 item->flags=attr_77.u.num;
794 }
795 else
796 {
797 item->flags=0;
798 }
799
800 //if (item_is_street(*item))
801 //{
802 // int i3;
803 // for (i3 = 0 ; i3 < count ; i3++)
804 // {
805 // if (i3)
806 // {
807 // dbg(0,"1 x1=%d\n",ca[i3-1].x);
808 // dbg(0,"1 y1=%d\n",ca[i3-1].y);
809 // dbg(0,"1 x2=%d\n",ca[i3].x);
810 // dbg(0,"1 y2=%d\n",ca[i3].y);
811 // }
812 // }
813 //}
814
815 count=transform(tr, pro, ca, pa, count, 0, 0, NULL);
816
817 //dbg(0,"count 2=%d\n", count);
818
819 // --- LABEL ---
820 labels[1]=NULL;
821 label_count=0;
822 if (item_attr_get(item, attr_label, &attr))
823 {
824 labels[0]=attr.u.str;
825 //dbg(0,"labels[0]=%s\n",attr.u.str);
826 if (!label_count)
827 {
828 label_count=2;
829 }
830 }
831 else
832 {
833 labels[0]=NULL;
834 }
835 // --- LABEL ---
836
837 if (item_is_street(*item))
838 {
839 //int i3;
840 //for (i3 = 0 ; i3 < count ; i3++)
841 //{
842 // if (i3)
843 // {
844 // dbg(0,"2 x1=%d\n",pa[i3-1].x);
845 // dbg(0,"2 y1=%d\n",pa[i3-1].y);
846 // dbg(0,"2 x2=%d\n",pa[i3].x);
847 // dbg(0,"2 y2=%d\n",pa[i3].y);
848 // }
849 //}
850 android_DrawMapPreview_polyline(pa, count, 0);
851 if (labels[0] != NULL)
852 {
853 map_preview_label_line(pa, count, labels[0], font_size);
854 }
855 }
856 else if (item_is_district(*item))
857 {
858 if (zoom > 6)
859 {
860 // dbg(0,"xx** %s - %s\n",item_to_name(item->type),labels[0]);
861 if (count >= 1)
862 {
863 android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size*2, 0x10000, 0);
864 }
865 }
866 }
867 else if (item_is_town(*item))
868 {
869 // dbg(0,"yy** %s - %s\n",item_to_name(item->type),labels[0]);
870 if (count >= 1)
871 {
872 android_DrawMapPreview_text(pa[0].x, pa[0].y, labels[0], font_size*3, 0x10000, 0);
873 }
874 }
875
876 //if (item_is_street(*item))
877 //{
878 // if (item_attr_get(item, attr_label, &attr))
879 // {
880 // //dbg(0,"street1=%s\n",map_convert_string(item->map, attr.u.str));
881 // if ( (streetname_last==NULL) || (strcmp(streetname_last,attr.u.str) != 0) )
882 // {
883 // //dbg(0,"street2=%s\n",map_convert_string(item->map, attr.u.str));
884 // }
885 // }
886 //}
887 }
888 //g_free(streetname_last);
889 map_rect_destroy(mr);
890 }
891 }
892 }
893 }
894 }
895 mapset_close(msh);
896
897 enum projection pro2=transform_get_projection(global_navit->trans_cursor);
898 struct point pnt;
899 transform(tr, pro2, &c, &pnt, 1, 0, 0, NULL);
900 transform_destroy(tr);
901 // ----------------------- big draw loop -----------------------
902 // ----------------------- big draw loop -----------------------
903 // ----------------------- big draw loop -----------------------
904 // ----------------------- big draw loop -----------------------
905
906 android_DrawMapPreview_target(pnt.x, pnt.y);
907 }
908
909 void
910 android_DrawMapPreview_target(int x, int y)
911 {
912 if (NavitMapPreviewActivityClass==NULL)
913 {
914 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
915 {
916 NavitMapPreviewActivityClass=NULL;
917 return;
918 }
919 }
920 if (DrawMapPreview_target == NULL)
921 {
922 android_find_static_method(NavitMapPreviewActivityClass,"DrawMapPreview_target", "(II)V", &DrawMapPreview_target);
923 }
924 if (DrawMapPreview_target == NULL)
925 {
926 dbg(0,"no method found\n");
927 return; /* exception thrown */
928 }
929 (*jnienv)->CallStaticVoidMethod(jnienv, NavitMapPreviewActivityClass, DrawMapPreview_target, x, y);
930 }
931
932 void
933 android_DrawMapPreview_text(int x, int y, char *text, int size, int dx, int dy)
934 {
935
936 if (NavitMapPreviewActivityClass==NULL)
937 {
938 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
939 {
940 NavitMapPreviewActivityClass=NULL;
941 return;
942 }
943 }
944 if (DrawMapPreview_text==NULL)
945 {
946 android_find_static_method(NavitMapPreviewActivityClass,"DrawMapPreview_text", "(IILjava/lang/String;III)V", &DrawMapPreview_text);
947 }
948 if (DrawMapPreview_text == NULL)
949 {
950 dbg(0,"no method found\n");
951 return; /* exception thrown */
952 }
953
954 //dbg(0,"** dx=%d,dy=%d\n",dx,dy);
955
956 jstring string1 = (*jnienv)->NewStringUTF(jnienv, text);
957 (*jnienv)->CallStaticVoidMethod(jnienv, NavitMapPreviewActivityClass, DrawMapPreview_text, x, y, string1, size, dx, dy);
958 (*jnienv)->DeleteLocalRef(jnienv, string1);
959 }
960
961
962 void
963 android_DrawMapPreview_polyline(struct point *p, int count, int type)
964 {
965 // type:
966 // 0 -> normal street
967 // 2 -> country border
968
969 if (NavitMapPreviewActivityClass==NULL)
970 {
971 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitMapPreviewActivity", &NavitMapPreviewActivityClass))
972 {
973 NavitMapPreviewActivityClass=NULL;
974 return;
975 }
976 }
977 if (DrawMapPreview_polyline==NULL)
978 {
979 android_find_static_method(NavitMapPreviewActivityClass,"DrawMapPreview_polyline", "(I[I)V", &DrawMapPreview_polyline);
980 }
981 if (DrawMapPreview_polyline == NULL)
982 {
983 dbg(0,"no method found\n");
984 return; /* exception thrown */
985 }
986
987 jint pc[count*2];
988 int i;
989 jintArray points;
990 if (count <= 0)
991 {
992 return;
993 }
994 points = (*jnienv)->NewIntArray(jnienv,count*2);
995 for (i = 0 ; i < count ; i++)
996 {
997 pc[i*2]=p[i].x;
998 pc[i*2+1]=p[i].y;
999 }
1000 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count*2, pc);
1001 (*jnienv)->CallStaticVoidMethod(jnienv, NavitMapPreviewActivityClass, DrawMapPreview_polyline, type, points);
1002 (*jnienv)->DeleteLocalRef(jnienv, points);
1003 }
1004
1005
1006
1007
1008
1009
1010
1011
1012 JNIEXPORT jstring JNICALL
1013 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackGeoCalc( JNIEnv* env, jobject thiz, int i, float a, float b)
1014 {
1015 // const char *result;
1016 gchar *result;
1017
1018 if (i == 1)
1019 {
1020 // pixel-on-screen to geo
1021 struct coord_geo g22;
1022 struct coord c22;
1023 struct point p;
1024 p.x=a;
1025 p.y=b;
1026 transform_reverse(global_navit->trans, &p, &c22);
1027 //dbg(0,"%f, %f\n",a, b);
1028 //dbg(0,"%d, %d\n",p.x, p.y);
1029 transform_to_geo(projection_mg, &c22, &g22);
1030 //dbg(0,"%d, %d, %f, %f\n",c22.x, c22.y, g22.lat, g22.lng);
1031 result=g_strdup_printf("%f:%f",g22.lat,g22.lng);
1032 }
1033 else if (i == 2)
1034 {
1035 // geo to pixel-on-screen
1036 struct coord c99;
1037 struct coord_geo g99;
1038 g99.lat=a;
1039 g99.lng=b;
1040 //dbg(0,"zzzzz %f, %f\n",a, b);
1041 //dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1042 transform_from_geo(projection_mg, &g99, &c99);
1043 //dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1044
1045 enum projection pro=transform_get_projection(global_navit->trans_cursor);
1046 struct point pnt;
1047 transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
1048 //dbg(0,"x=%d\n",pnt.x);
1049 //dbg(0,"y=%d\n",pnt.y);
1050
1051 result=g_strdup_printf("%d:%d",pnt.x,pnt.y);
1052 }
1053 else if (i == 3)
1054 {
1055 // show lat,lng position on screen center
1056 struct coord c99;
1057 struct pcoord pc99;
1058 struct coord_geo g99;
1059 g99.lat=a;
1060 g99.lng=b;
1061 //dbg(0,"zzzzz %f, %f\n",a, b);
1062 //dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
1063 transform_from_geo(projection_mg, &g99, &c99);
1064 //dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
1065
1066 //enum projection pro=transform_get_projection(global_navit->trans_cursor);
1067 //struct point pnt;
1068 //transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
1069 //dbg(0,"x=%d\n",pnt.x);
1070 //dbg(0,"y=%d\n",pnt.y);
1071 pc99.x=c99.x;
1072 pc99.y=c99.y;
1073 pc99.pro=projection_mg;
1074
1075 navit_set_center(global_navit, &pc99, 0);
1076
1077 result=g_strdup_printf("1:1");
1078 }
1079
1080 //dbg(0,"result=%s\n", result);
1081 jstring js = (*env)->NewStringUTF(env,result);
1082 g_free(result);
1083
1084 return js;
1085 }
1086
1087 JNIEXPORT jstring JNICALL
1088 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackLocalizedString( JNIEnv* env, jobject thiz, jobject str)
1089 {
1090 const char *s;
1091 const char *localized_str;
1092
1093 s=(*env)->GetStringUTFChars(env, str, NULL);
1094 //dbg(0,"*****string=%s\n",s);
1095
1096 localized_str=gettext(s);
1097 //dbg(0,"localized string=%s",localized_str);
1098
1099 // jstring dataStringValue = (jstring) localized_str;
1100 jstring js = (*env)->NewStringUTF(env,localized_str);
1101
1102 (*env)->ReleaseStringUTFChars(env, str, s);
1103
1104 return js;
1105 }
1106
1107 JNIEXPORT void JNICALL
1108 Java_com_zoffcc_applications_zanavi_NavitGraphics_CallbackMessageChannel( JNIEnv* env, jobject thiz, int i, jobject str)
1109 {
1110 const char *s;
1111 //dbg(0,"enter %p %p\n",(struct callback *)i,str);
1112
1113 config_get_attr(config, attr_navit, &attr, NULL);
1114 // attr.u.navit
1115
1116 if (i)
1117 {
1118 if (i == 1)
1119 {
1120 // zoom in
1121 navit_zoom_in_cursor(global_navit, 2);
1122 // navit_zoom_in_cursor(attr.u.navit, 2);
1123 }
1124 else if (i == 2)
1125 {
1126 // zoom out
1127 navit_zoom_out_cursor(global_navit, 2);
1128 // navit_zoom_out_cursor(attr.u.navit, 2);
1129 }
1130 else if (i == 43)
1131 {
1132 // routing mode "normal roads"
1133 routing_mode=1;
1134 }
1135 else if (i == 42)
1136 {
1137 // routing mode "highways"
1138 routing_mode=0;
1139 }
1140 else if (i == 41)
1141 {
1142 // switch "Map follows Vehicle" OFF
1143 struct attr attrx;
1144 attrx.type=attr_follow_cursor;
1145 attrx.u.num=0;
1146 navit_set_attr(global_navit,&attrx);
1147 }
1148 else if (i == 40)
1149 {
1150 // switch "Map follows Vehicle" ON
1151 struct attr attrx;
1152 attrx.type=attr_follow_cursor;
1153 attrx.u.num=1;
1154 navit_set_attr(global_navit,&attrx);
1155 }
1156 else if (i == 39)
1157 {
1158 // switch "Northing" OFF
1159 struct attr attrx;
1160 attrx.type=attr_orientation;
1161 attrx.u.num=0;
1162 navit_set_attr(global_navit,&attrx);
1163 }
1164 else if (i == 38)
1165 {
1166 // switch "Northing" ON
1167 struct attr attrx;
1168 attrx.type=attr_orientation;
1169 attrx.u.num=1;
1170 navit_set_attr(global_navit,&attrx);
1171 }
1172 else if (i == 37)
1173 {
1174 // switch "Lock on road" OFF
1175 struct attr attrx;
1176 attrx.type=attr_tracking;
1177 attrx.u.num=0;
1178 navit_set_attr(global_navit,&attrx);
1179 }
1180 else if (i == 36)
1181 {
1182 // switch "Lock on road" ON
1183 struct attr attrx;
1184 attrx.type=attr_tracking;
1185 attrx.u.num=1;
1186 navit_set_attr(global_navit,&attrx);
1187 }
1188 else if (i == 35)
1189 {
1190 // announcer voice ON
1191 navit_cmd_announcer_on(global_navit);
1192 }
1193 else if (i == 34)
1194 {
1195 // announcer voice OFF
1196 navit_cmd_announcer_off(global_navit);
1197 }
1198 else if (i == 33)
1199 {
1200 // zoom to specific zoomlevel
1201 s=(*env)->GetStringUTFChars(env, str, NULL);
1202 int zoom_level = atoi(s);
1203 navit_zoom_to_scale(global_navit, zoom_level);
1204 (*env)->ReleaseStringUTFChars(env, str, s);
1205 }
1206 else if (i == 32)
1207 {
1208 // switch to specific 3D pitch
1209 struct attr pitch_attr;
1210 s=(*env)->GetStringUTFChars(env, str, NULL);
1211 pitch_attr.type=attr_pitch;
1212 pitch_attr.u.num = atoi(s);
1213 navit_set_attr(global_navit,&pitch_attr);
1214 (*env)->ReleaseStringUTFChars(env, str, s);
1215 }
1216 else if (i == 31)
1217 {
1218 // switch to 3D
1219 struct attr pitch_attr;
1220 pitch_attr.type=attr_pitch;
1221 pitch_attr.u.num=30;
1222 navit_set_attr(global_navit,&pitch_attr);
1223 }
1224 else if (i == 30)
1225 {
1226 // switch to 2D
1227 struct attr pitch_attr;
1228 pitch_attr.type=attr_pitch;
1229 pitch_attr.u.num=0;
1230 navit_set_attr(global_navit,&pitch_attr);
1231 }
1232 // 21 - 25 are used in java, so leave a hole here to make it easier to understand
1233 else if (i == 20)
1234 {
1235 // add all scdard maps
1236 navit_add_all_maps(global_navit);
1237 }
1238 else if (i == 19)
1239 {
1240 // remove all scdard maps
1241 navit_remove_all_maps(global_navit);
1242 }
1243 else if (i == 18)
1244 {
1245 // reload scdard maps
1246 navit_reload_maps(global_navit);
1247 }
1248 else if (i == 17)
1249 {
1250 // zoom to route
1251 navit_zoom_to_route(global_navit, 0);
1252 }
1253 else if (i == 16)
1254 {
1255 // use imperial units
1256 global_navit->imperial=1;
1257 }
1258 else if (i == 15)
1259 {
1260 // use metric units
1261 global_navit->imperial=0;
1262 }
1263 else if (i == 14)
1264 {
1265 // draw location of self (car) in the screen center
1266 global_navit->radius=0;
1267 }
1268 else if (i == 13)
1269 {
1270 // draw location of self (car) 30% lower than screen center
1271 global_navit->radius=30;
1272 }
1273 else if (i == 12)
1274 {
1275 // draw map only at speeds higher than 5 km/h
1276 struct attr static_speed_attr;
1277 static_speed_attr.type=attr_static_speed;
1278 static_speed_attr.u.num=5;
1279 vehicleprofile_set_attr(global_navit->vehicleprofile, &static_speed_attr);
1280 }
1281 else if (i == 11)
1282 {
1283 // allow redraw map at ZERO speed
1284 struct attr static_speed_attr;
1285 static_speed_attr.type=attr_static_speed;
1286 static_speed_attr.u.num=0;
1287 vehicleprofile_set_attr(global_navit->vehicleprofile, &static_speed_attr);
1288 }
1289 else if (i == 10)
1290 {
1291 // allow internal GUI
1292 allow_gui_internal = 1;
1293 }
1294 else if (i == 9)
1295 {
1296 // disable internal GUI
1297 allow_gui_internal = 0;
1298 }
1299 else if (i == 8)
1300 {
1301 // zoom to zoomlevel
1302 // navit_zoom_to_scale(global_navit, 262144);
1303 navit_zoom_to_scale(global_navit, 524288);
1304 }
1305 else if (i == 7)
1306 {
1307 // stop navigation
1308 if (attr.u.navit->destination_valid != 0)
1309 {
1310 navit_set_destination(&attr.u.navit->self, NULL, NULL, 0);
1311 }
1312 }
1313 else if (i==6)
1314 {
1315 // not used now!
1316 }
1317 else if (i==5)
1318 {
1319 // call a command (like in gui) --> seems not many commands really work with this :-(
1320 s=(*env)->GetStringUTFChars(env, str, NULL);
1321 //dbg(0,"*****string=%s\n",s);
1322 command_evaluate(&attr.u.navit->self,s);
1323 (*env)->ReleaseStringUTFChars(env, str, s);
1324 }
1325 else if (i == 4)
1326 {
1327 // set destination to pixel x,y on screen
1328
1329 char *pstr;
1330 struct point p;
1331 struct coord c;
1332 struct pcoord pc;
1333
1334 s=(*env)->GetStringUTFChars(env, str, NULL);
1335 char parse_str[strlen(s) + 1];
1336 strcpy(parse_str, s);
1337 (*env)->ReleaseStringUTFChars(env, str, s);
1338 //dbg(0,"*****string=%s\n",parse_str);
1339
1340 // set destination to (pixel-x#pixel-y)
1341 // pixel-x
1342 pstr = strtok (parse_str,"#");
1343 p.x = atoi(pstr);
1344 // pixel-y
1345 pstr = strtok (NULL, "#");
1346 p.y = atoi(pstr);
1347
1348 //dbg(0,"11x=%d\n",p.x);
1349 //dbg(0,"11y=%d\n",p.y);
1350
1351 transform_reverse(global_navit->trans, &p, &c);
1352
1353
1354 pc.x = c.x;
1355 pc.y = c.y;
1356 pc.pro = transform_get_projection(global_navit->trans);
1357
1358 //dbg(0,"22x=%d\n",pc.x);
1359 //dbg(0,"22y=%d\n",pc.y);
1360
1361 // start navigation asynchronous
1362 navit_set_destination(global_navit, &pc, parse_str, 1);
1363 }
1364 else if (i == 3)
1365 {
1366 // set destination to lat, lng
1367
1368 char *name;
1369 s=(*env)->GetStringUTFChars(env, str, NULL);
1370 char parse_str[strlen(s) + 1];
1371 strcpy(parse_str, s);
1372 (*env)->ReleaseStringUTFChars(env, str, s);
1373 //dbg(0,"*****string=%s\n",s);
1374
1375 // set destination to (lat#lon#title)
1376 struct coord_geo g;
1377 char *p;
1378 char *stopstring;
1379
1380 // lat
1381 p = strtok (parse_str,"#");
1382 g.lat = strtof(p, &stopstring);
1383 // lon
1384 p = strtok (NULL, "#");
1385 g.lng = strtof(p, &stopstring);
1386 // description
1387 name = strtok (NULL, "#");
1388
1389 //dbg(0,"lat=%f\n",g.lat);
1390 //dbg(0,"lng=%f\n",g.lng);
1391 //dbg(0,"str1=%s\n",name);
1392
1393 struct coord c;
1394 transform_from_geo(projection_mg, &g, &c);
1395
1396 struct pcoord pc;
1397 pc.x=c.x;
1398 pc.y=c.y;
1399 pc.pro=projection_mg;
1400
1401 // start navigation asynchronous
1402 navit_set_destination(global_navit, &pc, name, 1);
1403
1404 }
1405 }
1406 }
1407

   
Visit the ZANavi Wiki