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

Contents of /navit/navit/graphics/android/graphics_android.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (show annotations) (download)
Tue Aug 21 19:31:50 2012 UTC (11 years, 7 months ago) by zoff99
File MIME type: text/plain
File size: 37449 byte(s)
some 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 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 #include <unistd.h>
40 #include <glib.h>
41 #include "config.h"
42 #include "window.h"
43 #include "point.h"
44 #include "graphics.h"
45 #include "color.h"
46 #include "plugin.h"
47 #include "event.h"
48 #include "debug.h"
49 #include "callback.h"
50 #include "android.h"
51
52 int dummy;
53
54 struct graphics_priv
55 {
56 jclass NavitGraphicsClass;
57 jmethodID NavitGraphics_draw_polyline, NavitGraphics_draw_polyline2, NavitGraphics_draw_polyline3, NavitGraphics_draw_polyline4, NavitGraphics_draw_polyline_dashed, NavitGraphics_set_dashes, NavitGraphics_draw_polygon, NavitGraphics_draw_polygon2, NavitGraphics_draw_rectangle, NavitGraphics_draw_circle, NavitGraphics_draw_text, NavitGraphics_draw_image,
58 NavitGraphics_draw_bigmap, NavitGraphics_send_osd_values, NavitGraphics_draw_mode, NavitGraphics_draw_drag, NavitGraphics_overlay_disable, NavitGraphics_overlay_resize, NavitGraphics_SetCamera, NavitGraphicsClass_rotate_and_scale_bitmap;
59
60 jclass PaintClass;
61 jmethodID Paint_init, Paint_setStrokeWidth, Paint_setARGB;
62
63 jobject NavitGraphics;
64 jobject Paint;
65
66 jclass BitmapFactoryClass;
67 jmethodID BitmapFactory_decodeFile, BitmapFactory_decodeResource;
68
69 jclass BitmapClass;
70 jmethodID Bitmap_getHeight, Bitmap_getWidth;
71
72 jclass ContextClass;
73 jmethodID Context_getResources;
74
75 jclass ResourcesClass;
76 jobject Resources;
77 jmethodID Resources_getIdentifier;
78
79 struct callback_list *cbl;
80 struct window win;
81 };
82
83 struct graphics_font_priv
84 {
85 int size;
86 };
87
88 struct graphics_gc_priv
89 {
90 struct graphics_priv *gra;
91 int linewidth;
92 enum draw_mode_num mode;
93 int a, r, g, b;
94 };
95
96 struct graphics_image_priv
97 {
98 jobject Bitmap;
99 int width;
100 int height;
101 struct point hot;
102 };
103
104 static GHashTable *image_cache_hash = NULL;
105
106 static int find_class_global(char *name, jclass *ret)
107 {
108 //DBG dbg(0,"EEnter\n");
109 *ret = (*jnienv)->FindClass(jnienv, name);
110 if (!*ret)
111 {
112 //DBG dbg(0, "Failed to get Class %s\n", name);
113 return 0;
114 }
115 *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
116 return 1;
117 }
118
119 static int find_method(jclass class, char *name, char *args, jmethodID *ret)
120 {
121 //DBG dbg(0,"EEnter\n");
122 *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
123 if (*ret == NULL)
124 {
125 //DBG dbg(0, "Failed to get Method %s with signature %s\n", name, args);
126 return 0;
127 }
128 return 1;
129 }
130
131 static int find_static_method(jclass class, char *name, char *args, jmethodID *ret)
132 {
133 //DBG dbg(0,"EEnter\n");
134 *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
135 if (*ret == NULL)
136 {
137 //DBG dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
138 return 0;
139 }
140 return 1;
141 }
142
143 static void graphics_destroy(struct graphics_priv *gr)
144 {
145 }
146
147 static void font_destroy(struct graphics_font_priv *font)
148 {
149 g_free(font);
150 }
151
152 static struct graphics_font_methods font_methods =
153 { font_destroy };
154
155 static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags)
156 {
157 struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
158 *meth = font_methods;
159
160 ret->size = size;
161 return ret;
162 }
163
164 static void gc_destroy(struct graphics_gc_priv *gc)
165 {
166 //DBG dbg(0,"EEnter\n");
167
168 g_free(gc);
169 }
170
171 static void gc_set_linewidth(struct graphics_gc_priv *gc, int w)
172 {
173 gc->linewidth = w;
174 }
175
176 static void gc_set_dashes(struct graphics_priv *gra, struct graphics_gc_priv *gc, int w, int offset, int dash_list[], int order)
177 {
178 JNIEnv *jnienv2;
179 jnienv2 = jni_getenv();
180 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_set_dashes, gc->gra->Paint, dash_list[0], order);
181 }
182
183 static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
184 {
185 gc->r = c->r >> 8;
186 gc->g = c->g >> 8;
187 gc->b = c->b >> 8;
188 gc->a = c->a >> 8;
189 }
190
191 static void gc_set_background(struct graphics_gc_priv *gc, struct color *c)
192 {
193 }
194
195 static struct graphics_gc_methods gc_methods =
196 { gc_destroy, gc_set_linewidth, gc_set_dashes, gc_set_foreground, gc_set_background };
197
198 static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
199 {
200 ////DBG dbg(0,"EEnter\n");
201
202 struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
203 *meth = gc_methods;
204
205 ret->gra = gr;
206 ret->a = ret->r = ret->g = ret->b = 255;
207 ret->linewidth = 1;
208 return ret;
209 }
210
211 static void image_destroy(struct graphics_image_priv *img)
212 {
213 // unused?
214 }
215
216 static struct graphics_image_methods image_methods =
217 { image_destroy };
218
219 static struct graphics_image_priv *
220 image_new(struct graphics_priv *gra, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation)
221 {
222 //DBG dbg(0,"EEnter\n");
223
224 JNIEnv *jnienv2;
225 jnienv2 = jni_getenv();
226
227 struct graphics_image_priv* ret = NULL;
228
229 if (!g_hash_table_lookup_extended(image_cache_hash, path, NULL, (gpointer) & ret))
230 {
231 ret=g_new0(struct graphics_image_priv, 1);
232 jstring string;
233 int id;
234
235 // // dbg(1, "enter %s\n", path);
236 if (!strncmp(path, "res/drawable/", 13))
237 {
238 jstring a = (*jnienv2)->NewStringUTF(jnienv2, "drawable");
239 jstring b = (*jnienv2)->NewStringUTF(jnienv2, "com.zoffcc.applications.zanavi");
240 char *path_noext = g_strdup(path + 13);
241 char *pos = strrchr(path_noext, '.');
242 if (pos)
243 *pos = '\0';
244 //DBG dbg(0, "path_noext=%s\n", path_noext);
245 string = (*jnienv2)->NewStringUTF(jnienv2, path_noext);
246 g_free(path_noext);
247 id = (*jnienv2)->CallIntMethod(jnienv2, gra->Resources, gra->Resources_getIdentifier, string, a, b);
248 //DBG dbg(0, "id=%d\n", id);
249 //DBG dbg(0,"JNI\n");
250 if (id)
251 {
252 ret->Bitmap = (*jnienv2)->CallStaticObjectMethod(jnienv2, gra->BitmapFactoryClass, gra->BitmapFactory_decodeResource, gra->Resources, id);
253 }
254 (*jnienv2)->DeleteLocalRef(jnienv2, b);
255 (*jnienv2)->DeleteLocalRef(jnienv2, a);
256 }
257 else
258 {
259 string = (*jnienv2)->NewStringUTF(jnienv2, path);
260 //DBG dbg(0,"JNI\n");
261 ret->Bitmap = (*jnienv2)->CallStaticObjectMethod(jnienv2, gra->BitmapFactoryClass, gra->BitmapFactory_decodeFile, string);
262 // there should be a check here, if we really want any rotation/scaling
263 // otherwise the call is overkill
264 //DBG dbg(0,"JNI\n");
265 ret->Bitmap = (*jnienv2)->CallStaticObjectMethod(jnienv2, gra->NavitGraphicsClass, gra->NavitGraphicsClass_rotate_and_scale_bitmap, ret->Bitmap, *w, *h, rotation);
266 }
267 //// dbg(1, "result=%p\n", ret->Bitmap);
268 if (ret->Bitmap)
269 {
270 //DBG dbg(0,"JNI\n");
271 ret->Bitmap = (*jnienv2)->NewGlobalRef(jnienv2, ret->Bitmap);
272 // ICS (*jnienv2)->DeleteLocalRef(jnienv2, ret->Bitmap);
273 //DBG dbg(0,"JNI\n");
274 ret->width = (*jnienv2)->CallIntMethod(jnienv2, ret->Bitmap, gra->Bitmap_getWidth);
275 //DBG dbg(0,"JNI\n");
276 ret->height = (*jnienv2)->CallIntMethod(jnienv2, ret->Bitmap, gra->Bitmap_getHeight);
277 //// dbg(1, "w=%d h=%d for %s\n", ret->width, ret->height, path);
278 ret->hot.x = ret->width / 2;
279 ret->hot.y = ret->height / 2;
280 }
281 else
282 {
283 g_free(ret);
284 ret = NULL;
285 //DBG dbg(0, "Failed to open %s\n", path);
286 }
287 //DBG dbg(0,"JNI\n");
288 (*jnienv2)->DeleteLocalRef(jnienv2, string);
289 //DBG dbg(0,"JNI\n");
290 g_hash_table_insert(image_cache_hash, g_strdup(path), (gpointer) ret);
291 }
292 if (ret)
293 {
294 *w = ret->width;
295 *h = ret->height;
296 if (hot)
297 {
298 *hot = ret->hot;
299 }
300 }
301
302 return ret;
303 }
304
305 static void initPaint(struct graphics_priv *gra, struct graphics_gc_priv *gc)
306 {
307 //DBG dbg(0,"EEnter\n");
308
309 JNIEnv *jnienv2;
310 jnienv2 = jni_getenv();
311
312 float wf = gc->linewidth;
313 (*jnienv2)->CallVoidMethod(jnienv2, gc->gra->Paint, gra->Paint_setStrokeWidth, wf);
314 (*jnienv2)->CallVoidMethod(jnienv2, gc->gra->Paint, gra->Paint_setARGB, gc->a, gc->r, gc->g, gc->b);
315 }
316
317 static void draw_lines(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
318 {
319 //DBG dbg(0,"EEnter\n");
320 jint pc[count * 2];
321 int i;
322 jintArray points;
323
324 if (count <= 0)
325 return;
326
327 JNIEnv *jnienv2;
328 jnienv2 = jni_getenv();
329
330 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
331 for (i = 0; i < count; i++)
332 {
333 pc[i * 2] = p[i].x;
334 pc[i * 2 + 1] = p[i].y;
335 }
336 initPaint(gra, gc);
337 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
338 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polyline, gc->gra->Paint, points);
339 (*jnienv2)->DeleteLocalRef(jnienv2, points);
340 }
341
342 static void draw_lines3(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int width)
343 {
344 //DBG dbg(0,"EEnter\n");
345 jint pc[count * 2];
346 int i;
347 jintArray points;
348 if (count <= 0)
349 {
350 return;
351 }
352
353 JNIEnv *jnienv2;
354 jnienv2 = jni_getenv();
355
356 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
357 for (i = 0; i < count; i++)
358 {
359 pc[i * 2] = p[i].x;
360 pc[i * 2 + 1] = p[i].y;
361 }
362 initPaint(gra, gc);
363 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
364 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polyline3, gc->gra->Paint, points, order, width);
365 (*jnienv2)->DeleteLocalRef(jnienv2, points);
366 }
367
368 static void draw_lines4(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int width, int type)
369 {
370 //DBG dbg(0,"EEnter\n");
371
372 // draw tunnel-street or bridge-street
373 // type:1 -> tunnel
374 // type:2 -> bridge
375
376 JNIEnv *jnienv2;
377 jnienv2 = jni_getenv();
378
379
380 if (type > 90)
381 {
382 // "***" signal
383 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polyline4, NULL, NULL, order, width, type);
384 }
385 else
386 {
387 jint pc[count * 2];
388 int i;
389 jintArray points;
390 if (count <= 0)
391 {
392 return;
393 }
394 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
395 for (i = 0; i < count; i++)
396 {
397 pc[i * 2] = p[i].x;
398 pc[i * 2 + 1] = p[i].y;
399 }
400 initPaint(gra, gc);
401 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
402 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polyline4, gc->gra->Paint, points, order, width, type);
403 (*jnienv2)->DeleteLocalRef(jnienv2, points);
404 }
405 }
406
407 static void draw_lines2(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int oneway)
408 {
409 //DBG dbg(0,"EEnter\n");
410 jint pc[count * 2];
411 int i;
412 jintArray points;
413 if (count <= 0)
414 return;
415
416 JNIEnv *jnienv2;
417 jnienv2 = jni_getenv();
418
419 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
420 for (i = 0; i < count; i++)
421 {
422 pc[i * 2] = p[i].x;
423 pc[i * 2 + 1] = p[i].y;
424 }
425 initPaint(gra, gc);
426 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
427 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polyline2, gc->gra->Paint, points, order, oneway);
428 (*jnienv2)->DeleteLocalRef(jnienv2, points);
429 }
430
431 static void draw_lines_dashed(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int oneway)
432 {
433 jint pc[count * 2];
434 int i;
435 jintArray points;
436 if (count <= 0)
437 return;
438
439 JNIEnv *jnienv2;
440 jnienv2 = jni_getenv();
441
442 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
443 for (i = 0; i < count; i++)
444 {
445 pc[i * 2] = p[i].x;
446 pc[i * 2 + 1] = p[i].y;
447 }
448 initPaint(gra, gc);
449 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
450 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polyline_dashed, gc->gra->Paint, points, order, oneway);
451 (*jnienv2)->DeleteLocalRef(jnienv2, points);
452 }
453
454 static void draw_polygon(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
455 {
456 jint pc[count * 2];
457 int i;
458 jintArray points;
459 if (count <= 0)
460 return;
461
462 JNIEnv *jnienv2;
463 jnienv2 = jni_getenv();
464
465 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
466 for (i = 0; i < count; i++)
467 {
468 pc[i * 2] = p[i].x;
469 pc[i * 2 + 1] = p[i].y;
470 }
471 initPaint(gra, gc);
472 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
473 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polygon, gc->gra->Paint, points);
474 (*jnienv2)->DeleteLocalRef(jnienv2, points);
475 }
476
477 static void draw_polygon2(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int oneway)
478 {
479 jint pc[count * 2];
480 int i;
481 jintArray points;
482 if (count <= 0)
483 return;
484
485 JNIEnv *jnienv2;
486 jnienv2 = jni_getenv();
487
488 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
489 for (i = 0; i < count; i++)
490 {
491 pc[i * 2] = p[i].x;
492 pc[i * 2 + 1] = p[i].y;
493 }
494 initPaint(gra, gc);
495 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
496 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polygon2, gc->gra->Paint, points, order, oneway);
497 (*jnienv2)->DeleteLocalRef(jnienv2, points);
498 }
499
500 static void draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h)
501 {
502 JNIEnv *jnienv2;
503 jnienv2 = jni_getenv();
504
505 initPaint(gra, gc);
506 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w, h);
507 }
508
509 static void draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r)
510 {
511 JNIEnv *jnienv2;
512 jnienv2 = jni_getenv();
513
514 initPaint(gra, gc);
515 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_circle, gc->gra->Paint, p->x, p->y, r);
516 }
517
518 static void draw_text(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy)
519 {
520 //// dbg(1, "enter %s\n", text);
521 JNIEnv *jnienv2;
522 jnienv2 = jni_getenv();
523
524 initPaint(gra, fg);
525 jstring string = (*jnienv2)->NewStringUTF(jnienv2, text);
526 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_text, fg->gra->Paint, p->x, p->y, string, font->size, dx, dy);
527 (*jnienv2)->DeleteLocalRef(jnienv2, string);
528 }
529
530 static void draw_image(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
531 {
532 //DBG dbg(0,"EEnter\n");
533
534 JNIEnv *jnienv2;
535 jnienv2 = jni_getenv();
536
537 //// dbg(1, "enter %p\n", img);
538 initPaint(gra, fg);
539 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_image, fg->gra->Paint, p->x, p->y, img->Bitmap);
540
541 }
542
543 static void draw_bigmap(struct graphics_priv *gra, struct graphics_gc_priv *fg, int yaw, int order, float clat, float clng, int x, int y, int scx, int scy, int px, int py, int valid)
544 {
545 //DBG dbg(0,"EEnter\n");
546
547 JNIEnv *jnienv2;
548 jnienv2 = jni_getenv();
549
550 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_bigmap, yaw, order, clat, clng, x, y, scx, scy, px, py, valid);
551
552 //DBG dbg(0,"leave\n");
553 }
554
555 static void send_osd_values(struct graphics_priv *gra, struct graphics_gc_priv *fg, char *id, char *text1, char *text2, char *text3, int i1, int i2, int i3, int i4, float f1, float f2, float f3)
556 {
557 //DBG dbg(0,"EEnter\n");
558
559 JNIEnv *jnienv2;
560 jnienv2 = jni_getenv();
561
562 jstring string1 = (*jnienv2)->NewStringUTF(jnienv2, id);
563 jstring string2 = (*jnienv2)->NewStringUTF(jnienv2, text1);
564 jstring string3 = (*jnienv2)->NewStringUTF(jnienv2, text2);
565 jstring string4 = (*jnienv2)->NewStringUTF(jnienv2, text3);
566 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_send_osd_values, string1, string2, string3, string4, i1, i2, i3, i4, f1, f2, f3);
567 (*jnienv2)->DeleteLocalRef(jnienv2, string1);
568 (*jnienv2)->DeleteLocalRef(jnienv2, string2);
569 (*jnienv2)->DeleteLocalRef(jnienv2, string3);
570 (*jnienv2)->DeleteLocalRef(jnienv2, string4);
571 }
572
573 static void draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, char *data)
574 {
575 }
576
577 static void draw_restore(struct graphics_priv *gr, struct point *p, int w, int h)
578 {
579 }
580
581 static void draw_drag(struct graphics_priv *gra, struct point *p)
582 {
583 //DBG dbg(0,"EEnter\n");
584 JNIEnv *jnienv2;
585 jnienv2 = jni_getenv();
586
587 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_drag, p ? p->x : 0, p ? p->y : 0);
588 }
589
590 static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
591 {
592 }
593
594 static void draw_mode(struct graphics_priv *gra, enum draw_mode_num mode)
595 {
596 //DBG dbg(0,"EEnter\n");
597 JNIEnv *jnienv2;
598 jnienv2 = jni_getenv();
599
600 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int) mode);
601 }
602
603 static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int alpha, int wraparound);
604
605 static void *
606 get_data(struct graphics_priv *this, const char *type)
607 {
608 //DBG dbg(0,"EEnter\n");
609
610 if (strcmp(type, "window"))
611 {
612 return NULL;
613 }
614
615 return &this->win;
616 }
617
618 static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
619 {
620 }
621
622 static void get_text_bbox(struct graphics_priv *gr, struct graphics_font_priv *font, char *text, int dx, int dy, struct point *ret, int estimate)
623 {
624 ////DBG dbg(0,"EEnter\n");
625
626 // this is a rough estimate!! otherwise java methods would be called, and thats too slow!
627
628 int len = g_utf8_strlen(text, -1);
629 int xMin = 0;
630 int yMin = 0;
631 int yMax = 13 * font->size / 256;
632 int xMax = 9 * font->size * len / 256;
633
634 ret[0].x = xMin;
635 ret[0].y = -yMin;
636 ret[1].x = xMin;
637 ret[1].y = -yMax;
638 ret[2].x = xMax;
639 ret[2].y = -yMax;
640 ret[3].x = xMax;
641 ret[3].y = -yMin;
642 }
643
644 static void overlay_disable(struct graphics_priv *gra, int disable)
645 {
646 //DBG dbg(0,"EEnter\n");
647 JNIEnv *jnienv2;
648 jnienv2 = jni_getenv();
649
650 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable);
651 }
652
653 static void overlay_resize(struct graphics_priv *gra, struct point *pnt, int w, int h, int alpha, int wraparound)
654 {
655 //DBG dbg(0,"EEnter\n");
656 JNIEnv *jnienv2;
657 jnienv2 = jni_getenv();
658
659 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_overlay_resize, pnt ? pnt->x : 0, pnt ? pnt->y : 0, w, h, alpha, wraparound);
660 }
661
662 static int set_attr(struct graphics_priv *gra, struct attr *attr)
663 {
664 //DBG dbg(0,"EEnter\n");
665 JNIEnv *jnienv2;
666 jnienv2 = jni_getenv();
667
668 switch (attr->type)
669 {
670 case attr_use_camera:
671 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num);
672 return 1;
673 default:
674 return 0;
675 }
676 }
677
678 static struct graphics_methods graphics_methods =
679 { graphics_destroy, draw_mode, draw_lines, draw_lines2, draw_lines3, draw_lines4, draw_lines_dashed, draw_polygon, draw_polygon2, draw_rectangle, draw_circle, draw_text, draw_image, draw_bigmap, send_osd_values, draw_image_warp, draw_restore, draw_drag, font_new, gc_new, background_gc, overlay_new, image_new, get_data,
680 image_free, get_text_bbox, overlay_disable, overlay_resize, set_attr, };
681
682 /*
683 static void resize_callback(struct graphics_priv *gra, int w, int h)
684 {
685 //DBG dbg(0,"EEnter\n");
686 // //DBG dbg(0,"w=%d h=%d ok\n",w,h);
687 // callback_list_call_attr_2(gra->cbl, attr_resize, (void *) w, (void *) h);
688 navit_resize(attr_resize, this_);
689 }
690 */
691
692 /*
693 static void motion_callback(struct graphics_priv *gra, int x, int y)
694 {
695 //DBG dbg(0,"EEnter\n");
696
697 struct point p;
698 p.x = x;
699 p.y = y;
700 callback_list_call_attr_1(gra->cbl, attr_motion, (void *) &p);
701 }
702 */
703
704 /*
705 static void keypress_callback(struct graphics_priv *gra, char *s)
706 {
707 //DBG dbg(0,"EEnter\n");
708 callback_list_call_attr_1(gra->cbl, attr_keypress, s);
709 }
710 */
711
712 /*
713 static void button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y)
714 {
715 //DBG dbg(0,"EEnter\n");
716
717 struct point p;
718 p.x = x;
719 p.y = y;
720 // //DBG dbg(0,"XXXXXXXYYYYYYYYY\n");
721 callback_list_call_attr_3(gra->cbl, attr_button, (void *) pressed, (void *) button, (void *) &p);
722 }
723 */
724
725 static int set_activity(jobject graphics)
726 {
727 //DBG dbg(0,"EEnter\n");
728
729 jclass ActivityClass;
730 jmethodID cid;
731
732 ActivityClass = (*jnienv)->GetObjectClass(jnienv, android_activity);
733 // //DBG dbg(0,"at 5\n");
734 if (ActivityClass == NULL)
735 {
736 //DBG dbg(0, "no activity class found\n");
737 return 0;
738 }
739 // //DBG dbg(0,"at 6\n");
740 cid = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setContentView", "(Landroid/view/View;)V");
741 if (cid == NULL)
742 {
743 //DBG dbg(0, "no setContentView method found\n");
744 return 0;
745 }
746 //DBG dbg(0,"at 7\n");
747 (*jnienv)->CallVoidMethod(jnienv, android_activity, cid, graphics);
748 //DBG dbg(0,"at 8\n");
749 return 1;
750 }
751
752 static int graphics_android_init(struct graphics_priv *ret, struct graphics_priv *parent, struct point *pnt, int w, int h, int alpha, int wraparound, int use_camera)
753 {
754 struct callback *cb;
755 jmethodID cid;
756
757 dbg(0, "at 2 jnienv=%p\n", jnienv);
758 //DBG dbg(0,"a1\n");
759 if (!find_class_global("android/graphics/Paint", &ret->PaintClass))
760 return 0;
761 //DBG dbg(0,"a2\n");
762 if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init))
763 return 0;
764 //DBG dbg(0,"a3\n");
765 if (!find_method(ret->PaintClass, "setARGB", "(IIII)V", &ret->Paint_setARGB))
766 return 0;
767 //DBG dbg(0,"a4\n");
768 if (!find_method(ret->PaintClass, "setStrokeWidth", "(F)V", &ret->Paint_setStrokeWidth))
769 return 0;
770
771 //DBG dbg(0,"a4.1\n");
772 if (!find_class_global("android/graphics/BitmapFactory", &ret->BitmapFactoryClass))
773 return 0;
774 //DBG dbg(0,"a4.2\n");
775 if (!find_static_method(ret->BitmapFactoryClass, "decodeFile", "(Ljava/lang/String;)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeFile))
776 return 0;
777 //DBG dbg(0,"a4.3\n");
778 if (!find_static_method(ret->BitmapFactoryClass, "decodeResource", "(Landroid/content/res/Resources;I)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeResource))
779 return 0;
780
781 //DBG dbg(0,"a4.4\n");
782 if (!find_class_global("android/graphics/Bitmap", &ret->BitmapClass))
783 return 0;
784 //DBG dbg(0,"a4.5\n");
785 if (!find_method(ret->BitmapClass, "getHeight", "()I", &ret->Bitmap_getHeight))
786 return 0;
787 //DBG dbg(0,"a4.6\n");
788 if (!find_method(ret->BitmapClass, "getWidth", "()I", &ret->Bitmap_getWidth))
789 return 0;
790 //DBG dbg(0,"a4.7\n");
791 if (!find_class_global("android/content/Context", &ret->ContextClass))
792 return 0;
793 //DBG dbg(0,"a4.8\n");
794 if (!find_method(ret->ContextClass, "getResources", "()Landroid/content/res/Resources;", &ret->Context_getResources))
795 return 0;
796 //DBG dbg(0,"a5\n");
797 ret->Resources = (*jnienv)->CallObjectMethod(jnienv, android_activity, ret->Context_getResources);
798 //DBG dbg(0,"a6\n");
799 if (ret->Resources)
800 {
801 ret->Resources = (*jnienv)->NewGlobalRef(jnienv, ret->Resources);
802 }
803 //DBG dbg(0,"a7\n");
804 if (!find_class_global("android/content/res/Resources", &ret->ResourcesClass))
805 return 0;
806 //DBG dbg(0,"a8\n");
807 if (!find_method(ret->ResourcesClass, "getIdentifier", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", &ret->Resources_getIdentifier))
808 return 0;
809 //DBG dbg(0,"a9\n");
810 if (!find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &ret->NavitGraphicsClass))
811 return 0;
812 //DBG dbg(0, "at 3\n");
813 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>", "(Landroid/app/Activity;Lcom/zoffcc/applications/zanavi/NavitGraphics;IIIIIII)V");
814 if (cid == NULL)
815 {
816 //DBG dbg(0, "no method found\n");
817 return 0; /* exception thrown */
818 }
819 //DBG dbg(0, "at 4 android_activity=%p\n", android_activity);
820 ret->NavitGraphics = (*jnienv)->NewObject(jnienv, ret->NavitGraphicsClass, cid, android_activity, parent ? parent->NavitGraphics : NULL, pnt ? pnt->x : 0, pnt ? pnt->y : 0, w, h, alpha, wraparound, use_camera);
821 dbg(0, "result=%p\n", ret->NavitGraphics);
822 if (ret->NavitGraphics)
823 {
824 ret->NavitGraphics = (*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics);
825 }
826
827 /* Create a single global Paint, otherwise android will quickly run out
828 * of global refs.*/
829 /* 0x101 = text kerning (default), antialiasing */
830 ret->Paint = (*jnienv)->NewObject(jnienv, ret->PaintClass, ret->Paint_init, 0x101);
831
832 //DBG dbg(0, "l result=%p\n", ret->Paint);
833 if (ret->Paint)
834 {
835 ret->Paint = (*jnienv)->NewGlobalRef(jnienv, ret->Paint);
836 }
837 //DBG dbg(0, "g result=%p\n", ret->Paint);
838
839 /*
840 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setSizeChangedCallback", "(I)V");
841 if (cid == NULL)
842 {
843 //DBG dbg(0, "no SetResizeCallback method found\n");
844 return 0;
845 }
846 cb = callback_new_1(callback_cast(resize_callback), ret);
847 (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb);
848 */
849
850 /*
851 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setButtonCallback", "(I)V");
852 if (cid == NULL)
853 {
854 //DBG dbg(0, "no SetButtonCallback method found\n");
855 return 0;
856 }
857 cb = callback_new_1(callback_cast(button_callback), ret);
858 (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb);
859 */
860
861 /*
862 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setMotionCallback", "(I)V");
863 if (cid == NULL)
864 {
865 //DBG dbg(0, "no SetMotionCallback method found\n");
866 return 0;
867 }
868 cb = callback_new_1(callback_cast(motion_callback), ret);
869 (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb);
870 */
871
872 // sets the graphics object for the JAVA code (this is bad, please fix me!!)
873 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "NavitSetGrObj", "()V");
874 if (cid == NULL)
875 {
876 //DBG dbg(0, "no SetMotionCallback method found\n");
877 return 0;
878 }
879 (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid);
880
881
882 // public Bitmap rotate_and_scale_bitmap(Bitmap in, int w, int h, int angle)
883
884 if (!find_static_method(ret->NavitGraphicsClass, "rotate_and_scale_bitmap", "(Landroid/graphics/Bitmap;III)Landroid/graphics/Bitmap;", &ret->NavitGraphicsClass_rotate_and_scale_bitmap))
885 return 0;
886
887 //
888 //cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "rotate_and_scale_bitmap", "(Landroid/graphics/Bitmap;III)Landroid/graphics/Bitmap;");
889 //if (cid == NULL) {
890 // //DBG dbg(0,"no rotate_and_scale_bitmap method found\n");
891 // return 0; /* exception thrown */
892 //}
893
894 /*
895 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setKeypressCallback", "(I)V");
896 if (cid == NULL)
897 {
898 //DBG dbg(0, "no SetKeypressCallback method found\n");
899 return 0;
900 }
901 cb = callback_new_1(callback_cast(keypress_callback), ret);
902 (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb);
903 */
904
905 if (!find_method(ret->NavitGraphicsClass, "draw_polyline", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polyline))
906 return 0;
907 if (!find_method(ret->NavitGraphicsClass, "draw_polyline2", "(Landroid/graphics/Paint;[III)V", &ret->NavitGraphics_draw_polyline2))
908 return 0;
909 if (!find_method(ret->NavitGraphicsClass, "draw_polyline3", "(Landroid/graphics/Paint;[III)V", &ret->NavitGraphics_draw_polyline3))
910 return 0;
911 if (!find_method(ret->NavitGraphicsClass, "draw_polyline4", "(Landroid/graphics/Paint;[IIII)V", &ret->NavitGraphics_draw_polyline4))
912 return 0;
913 if (!find_method(ret->NavitGraphicsClass, "draw_polyline_dashed", "(Landroid/graphics/Paint;[III)V", &ret->NavitGraphics_draw_polyline_dashed))
914 return 0;
915 if (!find_method(ret->NavitGraphicsClass, "set_dashes", "(Landroid/graphics/Paint;II)V", &ret->NavitGraphics_set_dashes))
916 return 0;
917 if (!find_method(ret->NavitGraphicsClass, "draw_polygon", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polygon))
918 return 0;
919 if (!find_method(ret->NavitGraphicsClass, "draw_polygon2", "(Landroid/graphics/Paint;[III)V", &ret->NavitGraphics_draw_polygon2))
920 return 0;
921 if (!find_method(ret->NavitGraphicsClass, "draw_rectangle", "(Landroid/graphics/Paint;IIII)V", &ret->NavitGraphics_draw_rectangle))
922 return 0;
923 if (!find_method(ret->NavitGraphicsClass, "draw_circle", "(Landroid/graphics/Paint;III)V", &ret->NavitGraphics_draw_circle))
924 return 0;
925 if (!find_method(ret->NavitGraphicsClass, "draw_text", "(Landroid/graphics/Paint;IILjava/lang/String;III)V", &ret->NavitGraphics_draw_text))
926 return 0;
927 if (!find_method(ret->NavitGraphicsClass, "draw_image", "(Landroid/graphics/Paint;IILandroid/graphics/Bitmap;)V", &ret->NavitGraphics_draw_image))
928 return 0;
929 if (!find_method(ret->NavitGraphicsClass, "draw_bigmap", "(IIFFIIIIIII)V", &ret->NavitGraphics_draw_bigmap))
930 return 0;
931 if (!find_method(ret->NavitGraphicsClass, "send_osd_values", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIIFFF)V", &ret->NavitGraphics_send_osd_values))
932 return 0;
933 if (!find_method(ret->NavitGraphicsClass, "draw_mode", "(I)V", &ret->NavitGraphics_draw_mode))
934 return 0;
935 if (!find_method(ret->NavitGraphicsClass, "draw_drag", "(II)V", &ret->NavitGraphics_draw_drag))
936 return 0;
937 if (!find_method(ret->NavitGraphicsClass, "overlay_disable", "(I)V", &ret->NavitGraphics_overlay_disable))
938 return 0;
939 if (!find_method(ret->NavitGraphicsClass, "overlay_resize", "(IIIIII)V", &ret->NavitGraphics_overlay_resize))
940 return 0;
941 /*
942 if (!find_method(ret->NavitGraphicsClass, "SetCamera", "(I)V", &ret->NavitGraphics_SetCamera))
943 return 0;
944 */
945
946 //DBG dbg(0,"99\n");
947 #if 0
948 set_activity(ret->NavitGraphics);
949 #endif
950 return 1;
951 }
952
953 static int graphics_android_fullscreen(struct window *win, int on)
954 {
955 return 1;
956 }
957
958 static jclass NavitClass;
959 static jmethodID Navit_disableSuspend, Navit_exit;
960
961 static void graphics_android_disable_suspend(struct window *win)
962 {
963 //DBG dbg(0,"enter\n");
964 JNIEnv *jnienv2;
965 jnienv2 = jni_getenv();
966
967 (*jnienv2)->CallVoidMethod(jnienv2, android_activity, Navit_disableSuspend);
968 }
969
970 static struct graphics_priv *
971 graphics_android_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
972 {
973 //DBG dbg(0,"EEnter\n");
974
975 struct graphics_priv *ret;
976 struct attr *attr;
977 int use_camera = 0;
978
979 if (!event_request_system("android", "graphics_android"))
980 {
981 return NULL;
982 }
983
984 ret=g_new0(struct graphics_priv, 1);
985 ret->cbl = cbl;
986 *meth = graphics_methods;
987 ret->win.priv = ret;
988 ret->win.fullscreen = graphics_android_fullscreen;
989 ret->win.disable_suspend = graphics_android_disable_suspend;
990 if ((attr = attr_search(attrs, NULL, attr_use_camera)))
991 {
992 use_camera = attr->u.num;
993 }
994 image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
995 if (graphics_android_init(ret, NULL, NULL, 0, 0, 0, 0, use_camera))
996 {
997 ////DBG dbg(0,"returning %p\n",ret);
998 return ret;
999 }
1000 else
1001 {
1002 g_free(ret);
1003 return NULL;
1004 }
1005 }
1006
1007 static struct graphics_priv *
1008 overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int alpha, int wraparound)
1009 {
1010 //DBG dbg(0,"EEnter\n");
1011
1012 struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
1013 *meth = graphics_methods;
1014 if (graphics_android_init(ret, gr, p, w, h, alpha, wraparound, 0))
1015 {
1016 //DBG dbg(0, "returning %p\n", ret);
1017 return ret;
1018 }
1019 else
1020 {
1021 g_free(ret);
1022 return NULL;
1023 }
1024 }
1025
1026 static void event_android_main_loop_run(void)
1027 {
1028 dbg(0, "enter\n");
1029 }
1030
1031 static void event_android_main_loop_quit(void)
1032 {
1033 dbg(0, "enter\n");
1034 // ******* exit(0);
1035 (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_exit);
1036 }
1037
1038 static jclass NavitTimeoutClass;
1039 static jmethodID NavitTimeout_init;
1040 static jmethodID NavitTimeout_remove;
1041
1042 static jclass NavitIdleClass;
1043 static jmethodID NavitIdle_init;
1044 static jmethodID NavitIdle_remove;
1045
1046 static jclass NavitWatchClass;
1047 static jmethodID NavitWatch_init;
1048 static jmethodID NavitWatch_remove;
1049
1050 static struct event_watch *
1051 event_android_add_watch(void *h, enum event_watch_cond cond, struct callback *cb)
1052 {
1053 //DBG dbg(0,"enter\n");
1054 jobject ret;
1055 ret = (*jnienv)->NewObject(jnienv, NavitWatchClass, NavitWatch_init, (int) h, (int) cond, (int) cb);
1056 // //DBG dbg(0,"result for %p,%d,%p=%p\n",h,cond,cb,ret);
1057 if (ret)
1058 {
1059 //DBG dbg(0,"result for %p,%p\n",h,ret);
1060 ret = (*jnienv)->NewGlobalRef(jnienv, ret);
1061 //DBG dbg(0,"g ret %p\n",ret);
1062 }
1063 return (struct event_watch *) ret;
1064 }
1065
1066 static void event_android_remove_watch(struct event_watch *ev)
1067 {
1068 //DBG dbg(0,"enter\n");
1069 if (ev)
1070 {
1071 //DBG dbg(0,"enter %p\n",ev);
1072 jobject obj = (jobject) ev;
1073 // maybe need this ? ICS obj = (*jnienv)->NewGlobalRef(jnienv, obj);
1074 (*jnienv)->CallVoidMethod(jnienv, obj, NavitWatch_remove);
1075 // ICS (*jnienv)->DeleteGlobalRef(jnienv, obj);
1076 }
1077 }
1078
1079 static struct event_timeout *
1080 event_android_add_timeout(int timeout, int multi, struct callback *cb)
1081 {
1082 //dbg(0,"EEnter\n");
1083
1084 // timeout -> delay in milliseconds
1085
1086 jobject ret;
1087 jobject ret_g = NULL;
1088 ret = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int) cb);
1089 //dbg(0, "result for %d,%d,%p\n", timeout, multi, cb);
1090
1091 if (ret)
1092 {
1093 dbg(0,"l ret=%p\n",ret);
1094 ret_g = (*jnienv)->NewGlobalRef(jnienv, ret);
1095 dbg(0,"g ret=%p\n",ret_g);
1096 }
1097 //dbg(0,"leave\n");
1098 return (struct event_timeout *) ret_g;
1099 }
1100
1101 static void event_android_remove_timeout(struct event_timeout *to)
1102 {
1103 //dbg(0,"EEnter\n");
1104
1105 if (to)
1106 {
1107 dbg(0, "remove %p\n", to);
1108 jobject obj = (jobject) to;
1109 (*jnienv)->CallVoidMethod(jnienv, obj, NavitTimeout_remove);
1110 // ICS
1111 dbg(0, "remove 1\n");
1112 (*jnienv)->DeleteGlobalRef(jnienv, obj);
1113 dbg(0, "remove 2\n");
1114 }
1115 }
1116
1117 static struct event_idle *
1118 event_android_add_idle(int priority, struct callback *cb)
1119 {
1120 // ----------------------------------------------------
1121 // ----------------------------------------------------
1122 // "priority" param is now misused here as "multi"
1123 // priority == 1000 -> set multi = 0
1124 // ----------------------------------------------------
1125 // ----------------------------------------------------
1126
1127 //dbg(0,"EEnter\n");
1128
1129 #if 0
1130 jobject ret;
1131 // dbg(1,"enter\n");
1132 ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb);
1133 // dbg(1,"result for %p=%p\n",cb,ret);
1134 if (ret)
1135 (*jnienv)->NewGlobalRef(jnienv, ret);
1136 return (struct event_idle *)ret;
1137 #endif
1138 // ----- xxxxxxxx ------
1139 if (priority == 1000)
1140 {
1141 return (struct event_idle *) event_android_add_timeout(10, 0, cb);
1142 }
1143 else
1144 {
1145 return (struct event_idle *) event_android_add_timeout(10, 1, cb);
1146 }
1147 }
1148
1149 static void event_android_remove_idle(struct event_idle *ev)
1150 {
1151 //DBG dbg(0,"EEnter\n");
1152
1153 #if 0
1154 // dbg(1,"enter %p\n",ev);
1155 if (ev)
1156 {
1157 jobject obj=(jobject )ev;
1158 (*jnienv)->CallVoidMethod(jnienv, obj, NavitIdle_remove);
1159 (*jnienv)->DeleteGlobalRef(jnienv, obj);
1160 }
1161 #endif
1162 event_android_remove_timeout((struct event_timeout *) ev);
1163 }
1164
1165 static void event_android_call_callback(struct callback_list *cb)
1166 {
1167 //DBG dbg(0,"enter\n");
1168 }
1169
1170 static struct event_methods event_android_methods =
1171 { event_android_main_loop_run, event_android_main_loop_quit, event_android_add_watch, event_android_remove_watch, event_android_add_timeout, event_android_remove_timeout, event_android_add_idle, event_android_remove_idle, event_android_call_callback, };
1172
1173 static struct event_priv *
1174 event_android_new(struct event_methods *meth)
1175 {
1176 //DBG dbg(0,"enter\n");
1177 if (!find_class_global("com/zoffcc/applications/zanavi/NavitTimeout", &NavitTimeoutClass))
1178 return NULL;
1179 NavitTimeout_init = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "<init>", "(IZI)V");
1180 if (NavitTimeout_init == NULL)
1181 return NULL;
1182 NavitTimeout_remove = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "remove", "()V");
1183 if (NavitTimeout_remove == NULL)
1184 return NULL;
1185 #if 0
1186 if (!find_class_global("com/zoffcc/applications/zanavi/NavitIdle", &NavitIdleClass))
1187 return NULL;
1188 NavitIdle_init = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "<init>", "(I)V");
1189 if (NavitIdle_init == NULL)
1190 return NULL;
1191 NavitIdle_remove = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "remove", "()V");
1192 if (NavitIdle_remove == NULL)
1193 return NULL;
1194 #endif
1195
1196 if (!find_class_global("com/zoffcc/applications/zanavi/NavitWatch", &NavitWatchClass))
1197 return NULL;
1198 NavitWatch_init = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "<init>", "(III)V");
1199 if (NavitWatch_init == NULL)
1200 return NULL;
1201 NavitWatch_remove = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "remove", "()V");
1202 if (NavitWatch_remove == NULL)
1203 return NULL;
1204
1205 if (!find_class_global("com/zoffcc/applications/zanavi/Navit", &NavitClass))
1206 return NULL;
1207 Navit_disableSuspend = (*jnienv)->GetMethodID(jnienv, NavitClass, "disableSuspend", "()V");
1208 if (Navit_disableSuspend == NULL)
1209 return NULL;
1210 Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit2", "()V");
1211 if (Navit_exit == NULL)
1212 return NULL;
1213 //DBG dbg(0,"ok\n");
1214 *meth = event_android_methods;
1215 return NULL;
1216 }
1217
1218 void plugin_init(void)
1219 {
1220 //DBG dbg(0,"enter\n");
1221 plugin_register_graphics_type("android", graphics_android_new);
1222 plugin_register_event_type("android", event_android_new);
1223 }
1224

   
Visit the ZANavi Wiki