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

   
Visit the ZANavi Wiki