/[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 - (hide annotations) (download)
Tue Aug 21 19:31:50 2012 UTC (11 years, 8 months ago) by zoff99
File MIME type: text/plain
File size: 37449 byte(s)
some fixes
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 27 struct graphics_priv
55     {
56 zoff99 2 jclass NavitGraphicsClass;
57 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,
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 zoff99 2
60     jclass PaintClass;
61 zoff99 27 jmethodID Paint_init, Paint_setStrokeWidth, Paint_setARGB;
62 zoff99 2
63     jobject NavitGraphics;
64     jobject Paint;
65 zoff99 27
66     jclass BitmapFactoryClass;
67 zoff99 2 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 zoff99 27 struct graphics_font_priv
84     {
85 zoff99 2 int size;
86     };
87    
88 zoff99 27 struct graphics_gc_priv
89     {
90 zoff99 2 struct graphics_priv *gra;
91     int linewidth;
92     enum draw_mode_num mode;
93 zoff99 27 int a, r, g, b;
94 zoff99 2 };
95    
96 zoff99 27 struct graphics_image_priv
97     {
98 zoff99 2 jobject Bitmap;
99     int width;
100     int height;
101     struct point hot;
102     };
103    
104     static GHashTable *image_cache_hash = NULL;
105    
106 zoff99 27 static int find_class_global(char *name, jclass *ret)
107 zoff99 2 {
108 zoff99 27 //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 zoff99 2 return 0;
114     }
115 zoff99 27 *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
116 zoff99 2 return 1;
117     }
118    
119 zoff99 27 static int find_method(jclass class, char *name, char *args, jmethodID *ret)
120 zoff99 2 {
121 zoff99 27 //DBG dbg(0,"EEnter\n");
122 zoff99 2 *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
123 zoff99 27 if (*ret == NULL)
124     {
125     //DBG dbg(0, "Failed to get Method %s with signature %s\n", name, args);
126 zoff99 2 return 0;
127     }
128     return 1;
129     }
130    
131 zoff99 27 static int find_static_method(jclass class, char *name, char *args, jmethodID *ret)
132 zoff99 2 {
133 zoff99 27 //DBG dbg(0,"EEnter\n");
134 zoff99 2 *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
135 zoff99 27 if (*ret == NULL)
136     {
137     //DBG dbg(0, "Failed to get static Method %s with signature %s\n", name, args);
138 zoff99 2 return 0;
139     }
140     return 1;
141     }
142    
143 zoff99 27 static void graphics_destroy(struct graphics_priv *gr)
144 zoff99 2 {
145     }
146    
147     static void font_destroy(struct graphics_font_priv *font)
148     {
149     g_free(font);
150     }
151    
152 zoff99 27 static struct graphics_font_methods font_methods =
153     { font_destroy };
154 zoff99 2
155 zoff99 27 static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags)
156 zoff99 2 {
157     struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
158 zoff99 27 *meth = font_methods;
159 zoff99 2
160 zoff99 27 ret->size = size;
161 zoff99 2 return ret;
162     }
163    
164 zoff99 27 static void gc_destroy(struct graphics_gc_priv *gc)
165 zoff99 2 {
166 zoff99 27 //DBG dbg(0,"EEnter\n");
167 zoff99 2
168     g_free(gc);
169     }
170    
171 zoff99 27 static void gc_set_linewidth(struct graphics_gc_priv *gc, int w)
172 zoff99 2 {
173 zoff99 27 gc->linewidth = w;
174 zoff99 2 }
175    
176 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)
177 zoff99 2 {
178 zoff99 29 JNIEnv *jnienv2;
179     jnienv2 = jni_getenv();
180     (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_set_dashes, gc->gra->Paint, dash_list[0], order);
181 zoff99 2 }
182    
183 zoff99 27 static void gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
184 zoff99 2 {
185 zoff99 27 gc->r = c->r >> 8;
186     gc->g = c->g >> 8;
187     gc->b = c->b >> 8;
188     gc->a = c->a >> 8;
189 zoff99 2 }
190    
191 zoff99 27 static void gc_set_background(struct graphics_gc_priv *gc, struct color *c)
192 zoff99 2 {
193     }
194    
195 zoff99 27 static struct graphics_gc_methods gc_methods =
196     { gc_destroy, gc_set_linewidth, gc_set_dashes, gc_set_foreground, gc_set_background };
197 zoff99 2
198     static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
199     {
200 zoff99 27 ////DBG dbg(0,"EEnter\n");
201 zoff99 2
202     struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
203 zoff99 27 *meth = gc_methods;
204 zoff99 2
205     ret->gra = gr;
206     ret->a = ret->r = ret->g = ret->b = 255;
207 zoff99 27 ret->linewidth = 1;
208 zoff99 2 return ret;
209     }
210    
211     static void image_destroy(struct graphics_image_priv *img)
212     {
213 zoff99 27 // unused?
214 zoff99 2 }
215    
216 zoff99 27 static struct graphics_image_methods image_methods =
217     { image_destroy };
218 zoff99 2
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 zoff99 27 //DBG dbg(0,"EEnter\n");
223 zoff99 2
224 zoff99 29 JNIEnv *jnienv2;
225     jnienv2 = jni_getenv();
226    
227 zoff99 2 struct graphics_image_priv* ret = NULL;
228 zoff99 27
229     if (!g_hash_table_lookup_extended(image_cache_hash, path, NULL, (gpointer) & ret))
230 zoff99 2 {
231     ret=g_new0(struct graphics_image_priv, 1);
232     jstring string;
233     int id;
234    
235 zoff99 27 // // dbg(1, "enter %s\n", path);
236     if (!strncmp(path, "res/drawable/", 13))
237     {
238 zoff99 29 jstring a = (*jnienv2)->NewStringUTF(jnienv2, "drawable");
239     jstring b = (*jnienv2)->NewStringUTF(jnienv2, "com.zoffcc.applications.zanavi");
240 zoff99 27 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 zoff99 29 string = (*jnienv2)->NewStringUTF(jnienv2, path_noext);
246 zoff99 2 g_free(path_noext);
247 zoff99 29 id = (*jnienv2)->CallIntMethod(jnienv2, gra->Resources, gra->Resources_getIdentifier, string, a, b);
248 zoff99 27 //DBG dbg(0, "id=%d\n", id);
249     //DBG dbg(0,"JNI\n");
250 zoff99 2 if (id)
251 zoff99 27 {
252 zoff99 29 ret->Bitmap = (*jnienv2)->CallStaticObjectMethod(jnienv2, gra->BitmapFactoryClass, gra->BitmapFactory_decodeResource, gra->Resources, id);
253 zoff99 27 }
254 zoff99 29 (*jnienv2)->DeleteLocalRef(jnienv2, b);
255     (*jnienv2)->DeleteLocalRef(jnienv2, a);
256 zoff99 27 }
257     else
258     {
259 zoff99 29 string = (*jnienv2)->NewStringUTF(jnienv2, path);
260 zoff99 27 //DBG dbg(0,"JNI\n");
261 zoff99 29 ret->Bitmap = (*jnienv2)->CallStaticObjectMethod(jnienv2, gra->BitmapFactoryClass, gra->BitmapFactory_decodeFile, string);
262 zoff99 2 // there should be a check here, if we really want any rotation/scaling
263     // otherwise the call is overkill
264 zoff99 27 //DBG dbg(0,"JNI\n");
265 zoff99 29 ret->Bitmap = (*jnienv2)->CallStaticObjectMethod(jnienv2, gra->NavitGraphicsClass, gra->NavitGraphicsClass_rotate_and_scale_bitmap, ret->Bitmap, *w, *h, rotation);
266 zoff99 2 }
267 zoff99 27 //// dbg(1, "result=%p\n", ret->Bitmap);
268     if (ret->Bitmap)
269     {
270     //DBG dbg(0,"JNI\n");
271 zoff99 29 ret->Bitmap = (*jnienv2)->NewGlobalRef(jnienv2, ret->Bitmap);
272     // ICS (*jnienv2)->DeleteLocalRef(jnienv2, ret->Bitmap);
273 zoff99 27 //DBG dbg(0,"JNI\n");
274 zoff99 29 ret->width = (*jnienv2)->CallIntMethod(jnienv2, ret->Bitmap, gra->Bitmap_getWidth);
275 zoff99 27 //DBG dbg(0,"JNI\n");
276 zoff99 29 ret->height = (*jnienv2)->CallIntMethod(jnienv2, ret->Bitmap, gra->Bitmap_getHeight);
277 zoff99 27 //// 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 zoff99 2 g_free(ret);
284 zoff99 27 ret = NULL;
285     //DBG dbg(0, "Failed to open %s\n", path);
286 zoff99 2 }
287 zoff99 27 //DBG dbg(0,"JNI\n");
288 zoff99 29 (*jnienv2)->DeleteLocalRef(jnienv2, string);
289 zoff99 27 //DBG dbg(0,"JNI\n");
290     g_hash_table_insert(image_cache_hash, g_strdup(path), (gpointer) ret);
291 zoff99 2 }
292 zoff99 27 if (ret)
293     {
294     *w = ret->width;
295     *h = ret->height;
296 zoff99 2 if (hot)
297 zoff99 27 {
298     *hot = ret->hot;
299     }
300 zoff99 2 }
301    
302     return ret;
303     }
304    
305     static void initPaint(struct graphics_priv *gra, struct graphics_gc_priv *gc)
306     {
307 zoff99 27 //DBG dbg(0,"EEnter\n");
308 zoff99 2
309 zoff99 29 JNIEnv *jnienv2;
310     jnienv2 = jni_getenv();
311    
312 zoff99 27 float wf = gc->linewidth;
313 zoff99 29 (*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 zoff99 2 }
316    
317 zoff99 27 static void draw_lines(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
318 zoff99 2 {
319 zoff99 27 //DBG dbg(0,"EEnter\n");
320     jint pc[count * 2];
321 zoff99 2 int i;
322     jintArray points;
323 zoff99 29
324 zoff99 2 if (count <= 0)
325     return;
326 zoff99 29
327     JNIEnv *jnienv2;
328     jnienv2 = jni_getenv();
329    
330     points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
331 zoff99 27 for (i = 0; i < count; i++)
332     {
333     pc[i * 2] = p[i].x;
334     pc[i * 2 + 1] = p[i].y;
335 zoff99 2 }
336     initPaint(gra, gc);
337 zoff99 29 (*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 zoff99 2 }
341    
342 zoff99 27 static void draw_lines3(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int width)
343 zoff99 2 {
344 zoff99 27 //DBG dbg(0,"EEnter\n");
345     jint pc[count * 2];
346 zoff99 2 int i;
347     jintArray points;
348     if (count <= 0)
349 zoff99 28 {
350 zoff99 2 return;
351 zoff99 28 }
352 zoff99 29
353     JNIEnv *jnienv2;
354     jnienv2 = jni_getenv();
355    
356     points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
357 zoff99 27 for (i = 0; i < count; i++)
358     {
359     pc[i * 2] = p[i].x;
360     pc[i * 2 + 1] = p[i].y;
361 zoff99 2 }
362     initPaint(gra, gc);
363 zoff99 29 (*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 zoff99 2 }
367    
368 zoff99 27 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 zoff99 2
372 zoff99 27 // draw tunnel-street or bridge-street
373     // type:1 -> tunnel
374     // type:2 -> bridge
375    
376 zoff99 29 JNIEnv *jnienv2;
377     jnienv2 = jni_getenv();
378    
379    
380     if (type > 90)
381 zoff99 27 {
382 zoff99 29 // "***" signal
383     (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polyline4, NULL, NULL, order, width, type);
384 zoff99 27 }
385 zoff99 29 else
386 zoff99 27 {
387 zoff99 29 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 zoff99 27 }
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 zoff99 2 {
409 zoff99 27 //DBG dbg(0,"EEnter\n");
410     jint pc[count * 2];
411 zoff99 2 int i;
412     jintArray points;
413     if (count <= 0)
414     return;
415 zoff99 29
416     JNIEnv *jnienv2;
417     jnienv2 = jni_getenv();
418    
419     points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
420 zoff99 27 for (i = 0; i < count; i++)
421     {
422     pc[i * 2] = p[i].x;
423     pc[i * 2 + 1] = p[i].y;
424 zoff99 2 }
425     initPaint(gra, gc);
426 zoff99 29 (*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 zoff99 27 }
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 zoff99 29
439     JNIEnv *jnienv2;
440     jnienv2 = jni_getenv();
441    
442     points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
443 zoff99 27 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 zoff99 29 (*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 zoff99 2 }
453    
454 zoff99 27 static void draw_polygon(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
455 zoff99 2 {
456 zoff99 27 jint pc[count * 2];
457 zoff99 2 int i;
458     jintArray points;
459     if (count <= 0)
460     return;
461 zoff99 29
462     JNIEnv *jnienv2;
463     jnienv2 = jni_getenv();
464    
465     points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
466 zoff99 27 for (i = 0; i < count; i++)
467     {
468     pc[i * 2] = p[i].x;
469     pc[i * 2 + 1] = p[i].y;
470 zoff99 2 }
471     initPaint(gra, gc);
472 zoff99 29 (*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 zoff99 2 }
476    
477 zoff99 27 static void draw_polygon2(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int oneway)
478 zoff99 2 {
479 zoff99 27 jint pc[count * 2];
480 zoff99 2 int i;
481     jintArray points;
482     if (count <= 0)
483     return;
484 zoff99 29
485     JNIEnv *jnienv2;
486     jnienv2 = jni_getenv();
487    
488     points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
489 zoff99 27 for (i = 0; i < count; i++)
490     {
491     pc[i * 2] = p[i].x;
492     pc[i * 2 + 1] = p[i].y;
493 zoff99 2 }
494     initPaint(gra, gc);
495 zoff99 29 (*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 zoff99 2 }
499    
500 zoff99 27 static void draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h)
501 zoff99 2 {
502 zoff99 29 JNIEnv *jnienv2;
503     jnienv2 = jni_getenv();
504    
505 zoff99 27 initPaint(gra, gc);
506 zoff99 29 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w, h);
507 zoff99 2 }
508    
509 zoff99 27 static void draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r)
510 zoff99 2 {
511 zoff99 29 JNIEnv *jnienv2;
512     jnienv2 = jni_getenv();
513    
514 zoff99 27 initPaint(gra, gc);
515 zoff99 29 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_circle, gc->gra->Paint, p->x, p->y, r);
516 zoff99 2 }
517    
518 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)
519 zoff99 2 {
520 zoff99 27 //// dbg(1, "enter %s\n", text);
521 zoff99 29 JNIEnv *jnienv2;
522     jnienv2 = jni_getenv();
523    
524 zoff99 2 initPaint(gra, fg);
525 zoff99 29 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 zoff99 2 }
529    
530 zoff99 27 static void draw_image(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
531 zoff99 2 {
532 zoff99 27 //DBG dbg(0,"EEnter\n");
533 zoff99 2
534 zoff99 29 JNIEnv *jnienv2;
535     jnienv2 = jni_getenv();
536    
537 zoff99 27 //// dbg(1, "enter %p\n", img);
538 zoff99 2 initPaint(gra, fg);
539 zoff99 29 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_image, fg->gra->Paint, p->x, p->y, img->Bitmap);
540 zoff99 27
541 zoff99 2 }
542    
543 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)
544 zoff99 2 {
545 zoff99 27 //DBG dbg(0,"EEnter\n");
546 zoff99 2
547 zoff99 29 JNIEnv *jnienv2;
548     jnienv2 = jni_getenv();
549 zoff99 27
550 zoff99 29 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_bigmap, yaw, order, clat, clng, x, y, scx, scy, px, py, valid);
551    
552 zoff99 27 //DBG dbg(0,"leave\n");
553 zoff99 2 }
554    
555 zoff99 27 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 zoff99 2 {
557 zoff99 27 //DBG dbg(0,"EEnter\n");
558 zoff99 2
559 zoff99 29 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 zoff99 2 }
572    
573 zoff99 27 static void draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, char *data)
574 zoff99 2 {
575     }
576    
577 zoff99 27 static void draw_restore(struct graphics_priv *gr, struct point *p, int w, int h)
578 zoff99 2 {
579     }
580    
581     static void draw_drag(struct graphics_priv *gra, struct point *p)
582     {
583 zoff99 27 //DBG dbg(0,"EEnter\n");
584 zoff99 29 JNIEnv *jnienv2;
585     jnienv2 = jni_getenv();
586 zoff99 2
587 zoff99 29 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_drag, p ? p->x : 0, p ? p->y : 0);
588 zoff99 2 }
589    
590 zoff99 27 static void background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
591 zoff99 2 {
592     }
593    
594 zoff99 27 static void draw_mode(struct graphics_priv *gra, enum draw_mode_num mode)
595 zoff99 2 {
596 zoff99 27 //DBG dbg(0,"EEnter\n");
597 zoff99 29 JNIEnv *jnienv2;
598     jnienv2 = jni_getenv();
599 zoff99 2
600 zoff99 29 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int) mode);
601 zoff99 2 }
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 zoff99 27 //DBG dbg(0,"EEnter\n");
609 zoff99 2
610 zoff99 27 if (strcmp(type, "window"))
611 zoff99 29 {
612 zoff99 2 return NULL;
613 zoff99 29 }
614    
615 zoff99 2 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 zoff99 27 ////DBG dbg(0,"EEnter\n");
625 zoff99 2
626 zoff99 28 // this is a rough estimate!! otherwise java methods would be called, and thats too slow!
627    
628 zoff99 2 int len = g_utf8_strlen(text, -1);
629     int xMin = 0;
630     int yMin = 0;
631 zoff99 27 int yMax = 13 * font->size / 256;
632     int xMax = 9 * font->size * len / 256;
633 zoff99 2
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 zoff99 27 //DBG dbg(0,"EEnter\n");
647 zoff99 29 JNIEnv *jnienv2;
648     jnienv2 = jni_getenv();
649    
650     (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable);
651 zoff99 2 }
652    
653     static void overlay_resize(struct graphics_priv *gra, struct point *pnt, int w, int h, int alpha, int wraparound)
654     {
655 zoff99 27 //DBG dbg(0,"EEnter\n");
656 zoff99 29 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 zoff99 2 }
661    
662 zoff99 27 static int set_attr(struct graphics_priv *gra, struct attr *attr)
663 zoff99 2 {
664 zoff99 27 //DBG dbg(0,"EEnter\n");
665 zoff99 29 JNIEnv *jnienv2;
666     jnienv2 = jni_getenv();
667    
668 zoff99 27 switch (attr->type)
669     {
670     case attr_use_camera:
671 zoff99 29 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num);
672 zoff99 27 return 1;
673     default:
674     return 0;
675 zoff99 2 }
676     }
677    
678 zoff99 27 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 zoff99 2
682 zoff99 28 /*
683 zoff99 27 static void resize_callback(struct graphics_priv *gra, int w, int h)
684 zoff99 2 {
685 zoff99 27 //DBG dbg(0,"EEnter\n");
686     // //DBG dbg(0,"w=%d h=%d ok\n",w,h);
687 zoff99 28 // callback_list_call_attr_2(gra->cbl, attr_resize, (void *) w, (void *) h);
688     navit_resize(attr_resize, this_);
689 zoff99 2 }
690 zoff99 28 */
691 zoff99 2
692 zoff99 28 /*
693 zoff99 27 static void motion_callback(struct graphics_priv *gra, int x, int y)
694 zoff99 2 {
695 zoff99 27 //DBG dbg(0,"EEnter\n");
696 zoff99 2
697     struct point p;
698 zoff99 27 p.x = x;
699     p.y = y;
700     callback_list_call_attr_1(gra->cbl, attr_motion, (void *) &p);
701 zoff99 2 }
702 zoff99 28 */
703 zoff99 2
704 zoff99 28 /*
705 zoff99 27 static void keypress_callback(struct graphics_priv *gra, char *s)
706 zoff99 2 {
707 zoff99 27 //DBG dbg(0,"EEnter\n");
708 zoff99 2 callback_list_call_attr_1(gra->cbl, attr_keypress, s);
709     }
710 zoff99 28 */
711 zoff99 2
712 zoff99 28 /*
713 zoff99 27 static void button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y)
714 zoff99 2 {
715 zoff99 27 //DBG dbg(0,"EEnter\n");
716 zoff99 2
717     struct point p;
718 zoff99 27 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 zoff99 2 }
723 zoff99 28 */
724 zoff99 2
725 zoff99 27 static int set_activity(jobject graphics)
726 zoff99 2 {
727 zoff99 27 //DBG dbg(0,"EEnter\n");
728 zoff99 2
729     jclass ActivityClass;
730     jmethodID cid;
731    
732     ActivityClass = (*jnienv)->GetObjectClass(jnienv, android_activity);
733 zoff99 27 // //DBG dbg(0,"at 5\n");
734     if (ActivityClass == NULL)
735     {
736     //DBG dbg(0, "no activity class found\n");
737 zoff99 2 return 0;
738     }
739 zoff99 27 // //DBG dbg(0,"at 6\n");
740 zoff99 2 cid = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setContentView", "(Landroid/view/View;)V");
741 zoff99 27 if (cid == NULL)
742     {
743     //DBG dbg(0, "no setContentView method found\n");
744 zoff99 2 return 0;
745     }
746 zoff99 27 //DBG dbg(0,"at 7\n");
747 zoff99 2 (*jnienv)->CallVoidMethod(jnienv, android_activity, cid, graphics);
748 zoff99 27 //DBG dbg(0,"at 8\n");
749 zoff99 2 return 1;
750     }
751    
752 zoff99 27 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 zoff99 2 {
754     struct callback *cb;
755     jmethodID cid;
756    
757 zoff99 29 dbg(0, "at 2 jnienv=%p\n", jnienv);
758 zoff99 27 //DBG dbg(0,"a1\n");
759 zoff99 2 if (!find_class_global("android/graphics/Paint", &ret->PaintClass))
760     return 0;
761 zoff99 27 //DBG dbg(0,"a2\n");
762 zoff99 2 if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init))
763     return 0;
764 zoff99 27 //DBG dbg(0,"a3\n");
765 zoff99 2 if (!find_method(ret->PaintClass, "setARGB", "(IIII)V", &ret->Paint_setARGB))
766     return 0;
767 zoff99 27 //DBG dbg(0,"a4\n");
768 zoff99 2 if (!find_method(ret->PaintClass, "setStrokeWidth", "(F)V", &ret->Paint_setStrokeWidth))
769     return 0;
770    
771 zoff99 27 //DBG dbg(0,"a4.1\n");
772 zoff99 2 if (!find_class_global("android/graphics/BitmapFactory", &ret->BitmapFactoryClass))
773     return 0;
774 zoff99 27 //DBG dbg(0,"a4.2\n");
775 zoff99 2 if (!find_static_method(ret->BitmapFactoryClass, "decodeFile", "(Ljava/lang/String;)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeFile))
776     return 0;
777 zoff99 27 //DBG dbg(0,"a4.3\n");
778 zoff99 2 if (!find_static_method(ret->BitmapFactoryClass, "decodeResource", "(Landroid/content/res/Resources;I)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeResource))
779     return 0;
780    
781 zoff99 27 //DBG dbg(0,"a4.4\n");
782 zoff99 2 if (!find_class_global("android/graphics/Bitmap", &ret->BitmapClass))
783     return 0;
784 zoff99 27 //DBG dbg(0,"a4.5\n");
785 zoff99 2 if (!find_method(ret->BitmapClass, "getHeight", "()I", &ret->Bitmap_getHeight))
786     return 0;
787 zoff99 27 //DBG dbg(0,"a4.6\n");
788 zoff99 2 if (!find_method(ret->BitmapClass, "getWidth", "()I", &ret->Bitmap_getWidth))
789     return 0;
790 zoff99 27 //DBG dbg(0,"a4.7\n");
791 zoff99 2 if (!find_class_global("android/content/Context", &ret->ContextClass))
792     return 0;
793 zoff99 27 //DBG dbg(0,"a4.8\n");
794 zoff99 2 if (!find_method(ret->ContextClass, "getResources", "()Landroid/content/res/Resources;", &ret->Context_getResources))
795     return 0;
796 zoff99 27 //DBG dbg(0,"a5\n");
797     ret->Resources = (*jnienv)->CallObjectMethod(jnienv, android_activity, ret->Context_getResources);
798     //DBG dbg(0,"a6\n");
799 zoff99 2 if (ret->Resources)
800 zoff99 27 {
801     ret->Resources = (*jnienv)->NewGlobalRef(jnienv, ret->Resources);
802     }
803     //DBG dbg(0,"a7\n");
804 zoff99 2 if (!find_class_global("android/content/res/Resources", &ret->ResourcesClass))
805     return 0;
806 zoff99 27 //DBG dbg(0,"a8\n");
807 zoff99 2 if (!find_method(ret->ResourcesClass, "getIdentifier", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", &ret->Resources_getIdentifier))
808     return 0;
809 zoff99 27 //DBG dbg(0,"a9\n");
810 zoff99 2 if (!find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &ret->NavitGraphicsClass))
811     return 0;
812 zoff99 27 //DBG dbg(0, "at 3\n");
813 zoff99 2 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>", "(Landroid/app/Activity;Lcom/zoffcc/applications/zanavi/NavitGraphics;IIIIIII)V");
814 zoff99 27 if (cid == NULL)
815     {
816     //DBG dbg(0, "no method found\n");
817 zoff99 2 return 0; /* exception thrown */
818     }
819 zoff99 27 //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 zoff99 29 dbg(0, "result=%p\n", ret->NavitGraphics);
822 zoff99 2 if (ret->NavitGraphics)
823 zoff99 27 {
824     ret->NavitGraphics = (*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics);
825     }
826 zoff99 2
827     /* Create a single global Paint, otherwise android will quickly run out
828     * of global refs.*/
829     /* 0x101 = text kerning (default), antialiasing */
830 zoff99 27 ret->Paint = (*jnienv)->NewObject(jnienv, ret->PaintClass, ret->Paint_init, 0x101);
831 zoff99 2
832 zoff99 27 //DBG dbg(0, "l result=%p\n", ret->Paint);
833 zoff99 2 if (ret->Paint)
834 zoff99 27 {
835     ret->Paint = (*jnienv)->NewGlobalRef(jnienv, ret->Paint);
836     }
837     //DBG dbg(0, "g result=%p\n", ret->Paint);
838 zoff99 2
839 zoff99 28 /*
840 zoff99 2 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setSizeChangedCallback", "(I)V");
841 zoff99 27 if (cid == NULL)
842     {
843     //DBG dbg(0, "no SetResizeCallback method found\n");
844 zoff99 28 return 0;
845 zoff99 2 }
846 zoff99 27 cb = callback_new_1(callback_cast(resize_callback), ret);
847     (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb);
848 zoff99 28 */
849 zoff99 2
850 zoff99 28 /*
851 zoff99 2 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setButtonCallback", "(I)V");
852 zoff99 27 if (cid == NULL)
853     {
854     //DBG dbg(0, "no SetButtonCallback method found\n");
855 zoff99 28 return 0;
856 zoff99 2 }
857 zoff99 27 cb = callback_new_1(callback_cast(button_callback), ret);
858     (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb);
859 zoff99 28 */
860 zoff99 2
861 zoff99 28 /*
862 zoff99 2 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setMotionCallback", "(I)V");
863 zoff99 27 if (cid == NULL)
864     {
865     //DBG dbg(0, "no SetMotionCallback method found\n");
866 zoff99 28 return 0;
867 zoff99 2 }
868 zoff99 27 cb = callback_new_1(callback_cast(motion_callback), ret);
869     (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb);
870 zoff99 28 */
871 zoff99 2
872 zoff99 28 // 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 zoff99 2 // 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 zoff99 27 // //DBG dbg(0,"no rotate_and_scale_bitmap method found\n");
891 zoff99 2 // return 0; /* exception thrown */
892     //}
893    
894 zoff99 28 /*
895 zoff99 2 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setKeypressCallback", "(I)V");
896 zoff99 27 if (cid == NULL)
897     {
898     //DBG dbg(0, "no SetKeypressCallback method found\n");
899 zoff99 28 return 0;
900 zoff99 2 }
901 zoff99 27 cb = callback_new_1(callback_cast(keypress_callback), ret);
902     (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb);
903 zoff99 28 */
904 zoff99 2
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 zoff99 27 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 zoff99 2 if (!find_method(ret->NavitGraphicsClass, "draw_polyline_dashed", "(Landroid/graphics/Paint;[III)V", &ret->NavitGraphics_draw_polyline_dashed))
914     return 0;
915 zoff99 27 if (!find_method(ret->NavitGraphicsClass, "set_dashes", "(Landroid/graphics/Paint;II)V", &ret->NavitGraphics_set_dashes))
916     return 0;
917 zoff99 2 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 zoff99 28 /*
942 zoff99 2 if (!find_method(ret->NavitGraphicsClass, "SetCamera", "(I)V", &ret->NavitGraphics_SetCamera))
943     return 0;
944 zoff99 28 */
945 zoff99 27
946     //DBG dbg(0,"99\n");
947 zoff99 2 #if 0
948     set_activity(ret->NavitGraphics);
949     #endif
950     return 1;
951     }
952    
953 zoff99 27 static int graphics_android_fullscreen(struct window *win, int on)
954 zoff99 2 {
955     return 1;
956     }
957    
958     static jclass NavitClass;
959     static jmethodID Navit_disableSuspend, Navit_exit;
960    
961 zoff99 27 static void graphics_android_disable_suspend(struct window *win)
962 zoff99 2 {
963 zoff99 27 //DBG dbg(0,"enter\n");
964 zoff99 29 JNIEnv *jnienv2;
965     jnienv2 = jni_getenv();
966    
967     (*jnienv2)->CallVoidMethod(jnienv2, android_activity, Navit_disableSuspend);
968 zoff99 2 }
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 zoff99 27 //DBG dbg(0,"EEnter\n");
974 zoff99 2
975     struct graphics_priv *ret;
976     struct attr *attr;
977 zoff99 27 int use_camera = 0;
978 zoff99 29
979 zoff99 27 if (!event_request_system("android", "graphics_android"))
980 zoff99 29 {
981     return NULL;
982     }
983 zoff99 2
984 zoff99 29 ret=g_new0(struct graphics_priv, 1);
985 zoff99 27 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 zoff99 2 }
994     image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
995 zoff99 27 if (graphics_android_init(ret, NULL, NULL, 0, 0, 0, 0, use_camera))
996     {
997     ////DBG dbg(0,"returning %p\n",ret);
998 zoff99 2 return ret;
999 zoff99 27 }
1000     else
1001     {
1002 zoff99 2 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 zoff99 27 //DBG dbg(0,"EEnter\n");
1011 zoff99 2
1012     struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
1013 zoff99 27 *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 zoff99 2 return ret;
1018 zoff99 27 }
1019     else
1020     {
1021 zoff99 2 g_free(ret);
1022     return NULL;
1023     }
1024     }
1025    
1026 zoff99 27 static void event_android_main_loop_run(void)
1027 zoff99 2 {
1028 zoff99 28 dbg(0, "enter\n");
1029 zoff99 2 }
1030    
1031     static void event_android_main_loop_quit(void)
1032     {
1033 zoff99 28 dbg(0, "enter\n");
1034 zoff99 27 // ******* exit(0);
1035 zoff99 2 (*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 zoff99 27 //DBG dbg(0,"enter\n");
1054 zoff99 2 jobject ret;
1055 zoff99 27 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 zoff99 2 if (ret)
1058 zoff99 27 {
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 zoff99 2 }
1065    
1066 zoff99 27 static void event_android_remove_watch(struct event_watch *ev)
1067 zoff99 2 {
1068 zoff99 27 //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 zoff99 2 (*jnienv)->CallVoidMethod(jnienv, obj, NavitWatch_remove);
1075 zoff99 27 // ICS (*jnienv)->DeleteGlobalRef(jnienv, obj);
1076 zoff99 2 }
1077     }
1078    
1079     static struct event_timeout *
1080     event_android_add_timeout(int timeout, int multi, struct callback *cb)
1081     {
1082 zoff99 28 //dbg(0,"EEnter\n");
1083 zoff99 2
1084 zoff99 28 // timeout -> delay in milliseconds
1085    
1086 zoff99 2 jobject ret;
1087 zoff99 29 jobject ret_g = NULL;
1088 zoff99 27 ret = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int) cb);
1089 zoff99 28 //dbg(0, "result for %d,%d,%p\n", timeout, multi, cb);
1090 zoff99 27
1091 zoff99 2 if (ret)
1092 zoff99 27 {
1093 zoff99 29 dbg(0,"l ret=%p\n",ret);
1094     ret_g = (*jnienv)->NewGlobalRef(jnienv, ret);
1095     dbg(0,"g ret=%p\n",ret_g);
1096 zoff99 27 }
1097 zoff99 28 //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 28 //dbg(0,"EEnter\n");
1104 zoff99 2
1105 zoff99 27 if (to)
1106     {
1107 zoff99 29 dbg(0, "remove %p\n", to);
1108 zoff99 27 jobject obj = (jobject) to;
1109 zoff99 2 (*jnienv)->CallVoidMethod(jnienv, obj, NavitTimeout_remove);
1110 zoff99 29 // ICS
1111     dbg(0, "remove 1\n");
1112     (*jnienv)->DeleteGlobalRef(jnienv, obj);
1113     dbg(0, "remove 2\n");
1114 zoff99 2 }
1115     }
1116    
1117     static struct event_idle *
1118     event_android_add_idle(int priority, struct callback *cb)
1119     {
1120 zoff99 28 // ----------------------------------------------------
1121     // ----------------------------------------------------
1122     // "priority" param is now misused here as "multi"
1123     // priority == 1000 -> set multi = 0
1124     // ----------------------------------------------------
1125     // ----------------------------------------------------
1126 zoff99 2
1127 zoff99 28 //dbg(0,"EEnter\n");
1128    
1129 zoff99 2 #if 0
1130     jobject ret;
1131 zoff99 27 // dbg(1,"enter\n");
1132 zoff99 2 ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb);
1133 zoff99 27 // dbg(1,"result for %p=%p\n",cb,ret);
1134 zoff99 2 if (ret)
1135 zoff99 27 (*jnienv)->NewGlobalRef(jnienv, ret);
1136 zoff99 2 return (struct event_idle *)ret;
1137     #endif
1138 zoff99 28 // ----- 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 zoff99 2 }
1148    
1149 zoff99 27 static void event_android_remove_idle(struct event_idle *ev)
1150 zoff99 2 {
1151 zoff99 27 //DBG dbg(0,"EEnter\n");
1152 zoff99 2
1153     #if 0
1154 zoff99 27 // dbg(1,"enter %p\n",ev);
1155     if (ev)
1156     {
1157 zoff99 2 jobject obj=(jobject )ev;
1158     (*jnienv)->CallVoidMethod(jnienv, obj, NavitIdle_remove);
1159     (*jnienv)->DeleteGlobalRef(jnienv, obj);
1160     }
1161     #endif
1162 zoff99 27 event_android_remove_timeout((struct event_timeout *) ev);
1163 zoff99 2 }
1164    
1165 zoff99 27 static void event_android_call_callback(struct callback_list *cb)
1166 zoff99 2 {
1167 zoff99 27 //DBG dbg(0,"enter\n");
1168 zoff99 2 }
1169    
1170 zoff99 27 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 zoff99 2
1173     static struct event_priv *
1174     event_android_new(struct event_methods *meth)
1175     {
1176 zoff99 27 //DBG dbg(0,"enter\n");
1177 zoff99 2 if (!find_class_global("com/zoffcc/applications/zanavi/NavitTimeout", &NavitTimeoutClass))
1178     return NULL;
1179     NavitTimeout_init = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "<init>", "(IZI)V");
1180 zoff99 27 if (NavitTimeout_init == NULL)
1181 zoff99 2 return NULL;
1182     NavitTimeout_remove = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "remove", "()V");
1183 zoff99 27 if (NavitTimeout_remove == NULL)
1184 zoff99 2 return NULL;
1185     #if 0
1186     if (!find_class_global("com/zoffcc/applications/zanavi/NavitIdle", &NavitIdleClass))
1187 zoff99 27 return NULL;
1188 zoff99 2 NavitIdle_init = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "<init>", "(I)V");
1189 zoff99 27 if (NavitIdle_init == NULL)
1190     return NULL;
1191 zoff99 2 NavitIdle_remove = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "remove", "()V");
1192 zoff99 27 if (NavitIdle_remove == NULL)
1193     return NULL;
1194 zoff99 2 #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 zoff99 27 if (NavitWatch_init == NULL)
1200 zoff99 2 return NULL;
1201     NavitWatch_remove = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "remove", "()V");
1202 zoff99 27 if (NavitWatch_remove == NULL)
1203 zoff99 2 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 zoff99 27 if (Navit_disableSuspend == NULL)
1209 zoff99 2 return NULL;
1210 zoff99 28 Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit2", "()V");
1211 zoff99 27 if (Navit_exit == NULL)
1212 zoff99 2 return NULL;
1213 zoff99 27 //DBG dbg(0,"ok\n");
1214     *meth = event_android_methods;
1215     return NULL;
1216 zoff99 2 }
1217    
1218 zoff99 27 void plugin_init(void)
1219 zoff99 2 {
1220 zoff99 27 //DBG dbg(0,"enter\n");
1221     plugin_register_graphics_type("android", graphics_android_new);
1222 zoff99 2 plugin_register_event_type("android", event_android_new);
1223     }
1224 zoff99 27

   
Visit the ZANavi Wiki