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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.2  
changed lines
  Added in v.28

   
Visit the ZANavi Wiki