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

Legend:
Removed from v.27  
changed lines
  Added in v.29

   
Visit the ZANavi Wiki