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

   
Visit the ZANavi Wiki