/[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 28 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)
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
378static void draw_lines2(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int oneway) 431static void draw_lines_dashed(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int oneway)
379{ 432{
380 //DBG dbg(0,"EEnter\n");
381 jint pc[count * 2]; 433 jint pc[count * 2];
382 int i; 434 int i;
383 jintArray points; 435 jintArray points;
384 if (count <= 0) 436 if (count <= 0)
385 return; 437 return;
438
439 JNIEnv *jnienv2;
440 jnienv2 = jni_getenv();
441
386 points = (*jnienv)->NewIntArray(jnienv, count * 2); 442 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
387 for (i = 0; i < count; i++) 443 for (i = 0; i < count; i++)
388 { 444 {
389 pc[i * 2] = p[i].x; 445 pc[i * 2] = p[i].x;
390 pc[i * 2 + 1] = p[i].y; 446 pc[i * 2 + 1] = p[i].y;
391 } 447 }
392 initPaint(gra, gc); 448 initPaint(gra, gc);
393 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count * 2, pc); 449 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
394 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polyline2, gc->gra->Paint, points, order, oneway); 450 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polyline_dashed, gc->gra->Paint, points, order, oneway);
395 (*jnienv)->DeleteLocalRef(jnienv, points); 451 (*jnienv2)->DeleteLocalRef(jnienv2, points);
396} 452}
397 453
398static void draw_lines_dashed(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)
399{ 455{
400 jint pc[count * 2]; 456 jint pc[count * 2];
401 int i; 457 int i;
402 jintArray points; 458 jintArray points;
403 if (count <= 0) 459 if (count <= 0)
404 return; 460 return;
461
462 JNIEnv *jnienv2;
463 jnienv2 = jni_getenv();
464
405 points = (*jnienv)->NewIntArray(jnienv, count * 2); 465 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
406 for (i = 0; i < count; i++) 466 for (i = 0; i < count; i++)
407 { 467 {
408 pc[i * 2] = p[i].x; 468 pc[i * 2] = p[i].x;
409 pc[i * 2 + 1] = p[i].y; 469 pc[i * 2 + 1] = p[i].y;
410 } 470 }
411 initPaint(gra, gc); 471 initPaint(gra, gc);
412 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count * 2, pc); 472 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
413 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polyline_dashed, gc->gra->Paint, points, order, oneway); 473 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polygon, gc->gra->Paint, points);
414 (*jnienv)->DeleteLocalRef(jnienv, points); 474 (*jnienv2)->DeleteLocalRef(jnienv2, points);
415} 475}
416 476
417static void draw_polygon(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count) 477static void draw_polygon2(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int oneway)
418{ 478{
419 jint pc[count * 2]; 479 jint pc[count * 2];
420 int i; 480 int i;
421 jintArray points; 481 jintArray points;
422 if (count <= 0) 482 if (count <= 0)
423 return; 483 return;
484
485 JNIEnv *jnienv2;
486 jnienv2 = jni_getenv();
487
424 points = (*jnienv)->NewIntArray(jnienv, count * 2); 488 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
425 for (i = 0; i < count; i++) 489 for (i = 0; i < count; i++)
426 { 490 {
427 pc[i * 2] = p[i].x; 491 pc[i * 2] = p[i].x;
428 pc[i * 2 + 1] = p[i].y; 492 pc[i * 2 + 1] = p[i].y;
429 } 493 }
430 initPaint(gra, gc); 494 initPaint(gra, gc);
431 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count * 2, pc); 495 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
432 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polygon, gc->gra->Paint, points); 496 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_polygon2, gc->gra->Paint, points, order, oneway);
433 (*jnienv)->DeleteLocalRef(jnienv, points); 497 (*jnienv2)->DeleteLocalRef(jnienv2, points);
434} 498}
435 499
436static void draw_polygon2(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count, int order, int oneway) 500static void draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h)
437{ 501{
438 jint pc[count * 2]; 502 JNIEnv *jnienv2;
439 int i; 503 jnienv2 = jni_getenv();
440 jintArray points; 504
441 if (count <= 0)
442 return;
443 points = (*jnienv)->NewIntArray(jnienv, count * 2);
444 for (i = 0; i < count; i++)
445 {
446 pc[i * 2] = p[i].x;
447 pc[i * 2 + 1] = p[i].y;
448 }
449 initPaint(gra, gc); 505 initPaint(gra, gc);
450 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count * 2, pc);
451 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polygon2, gc->gra->Paint, points, order, oneway); 506 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w, h);
452 (*jnienv)->DeleteLocalRef(jnienv, points);
453} 507}
454 508
455static void draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h) 509static void draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r)
456{ 510{
511 JNIEnv *jnienv2;
512 jnienv2 = jni_getenv();
513
457 initPaint(gra, gc); 514 initPaint(gra, gc);
458 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w, h);
459}
460
461static void draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r)
462{
463 initPaint(gra, gc);
464 (*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);
465} 516}
466 517
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) 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)
468{ 519{
469 //// dbg(1, "enter %s\n", text); 520 //// dbg(1, "enter %s\n", text);
521 JNIEnv *jnienv2;
522 jnienv2 = jni_getenv();
523
470 initPaint(gra, fg); 524 initPaint(gra, fg);
471 jstring string = (*jnienv)->NewStringUTF(jnienv, text); 525 jstring string = (*jnienv2)->NewStringUTF(jnienv2, text);
472 (*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);
473 (*jnienv)->DeleteLocalRef(jnienv, string); 527 (*jnienv2)->DeleteLocalRef(jnienv2, string);
474} 528}
475 529
476static 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)
477{ 531{
478 //DBG dbg(0,"EEnter\n"); 532 //DBG dbg(0,"EEnter\n");
533
534 JNIEnv *jnienv2;
535 jnienv2 = jni_getenv();
479 536
480 //// dbg(1, "enter %p\n", img); 537 //// dbg(1, "enter %p\n", img);
481 initPaint(gra, fg); 538 initPaint(gra, fg);
482 (*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);
483 540
484} 541}
485 542
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) 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)
487{ 544{
488 //DBG dbg(0,"EEnter\n"); 545 //DBG dbg(0,"EEnter\n");
489 546
547 JNIEnv *jnienv2;
548 jnienv2 = jni_getenv();
549
490 (*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);
491 551
492 //DBG dbg(0,"leave\n"); 552 //DBG dbg(0,"leave\n");
493} 553}
494 554
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) 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)
496{ 556{
497 //DBG dbg(0,"EEnter\n"); 557 //DBG dbg(0,"EEnter\n");
498 558
559 JNIEnv *jnienv2;
560 jnienv2 = jni_getenv();
561
499 jstring string1 = (*jnienv)->NewStringUTF(jnienv, id); 562 jstring string1 = (*jnienv2)->NewStringUTF(jnienv2, id);
500 jstring string2 = (*jnienv)->NewStringUTF(jnienv, text1); 563 jstring string2 = (*jnienv2)->NewStringUTF(jnienv2, text1);
501 jstring string3 = (*jnienv)->NewStringUTF(jnienv, text2); 564 jstring string3 = (*jnienv2)->NewStringUTF(jnienv2, text2);
502 jstring string4 = (*jnienv)->NewStringUTF(jnienv, text3); 565 jstring string4 = (*jnienv2)->NewStringUTF(jnienv2, text3);
503 (*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);
504 (*jnienv)->DeleteLocalRef(jnienv, string1); 567 (*jnienv2)->DeleteLocalRef(jnienv2, string1);
505 (*jnienv)->DeleteLocalRef(jnienv, string2); 568 (*jnienv2)->DeleteLocalRef(jnienv2, string2);
506 (*jnienv)->DeleteLocalRef(jnienv, string3); 569 (*jnienv2)->DeleteLocalRef(jnienv2, string3);
507 (*jnienv)->DeleteLocalRef(jnienv, string4); 570 (*jnienv2)->DeleteLocalRef(jnienv2, string4);
508} 571}
509 572
510static 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)
511{ 574{
512} 575}
516} 579}
517 580
518static void draw_drag(struct graphics_priv *gra, struct point *p) 581static void draw_drag(struct graphics_priv *gra, struct point *p)
519{ 582{
520 //DBG dbg(0,"EEnter\n"); 583 //DBG dbg(0,"EEnter\n");
584 JNIEnv *jnienv2;
585 jnienv2 = jni_getenv();
521 586
522 (*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);
523} 588}
524 589
525static 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)
526{ 591{
527} 592}
528 593
529static 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)
530{ 595{
531 //DBG dbg(0,"EEnter\n"); 596 //DBG dbg(0,"EEnter\n");
597 JNIEnv *jnienv2;
598 jnienv2 = jni_getenv();
532 599
533 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int) mode); 600 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int) mode);
534} 601}
535 602
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); 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);
537 604
538static void * 605static void *
539get_data(struct graphics_priv *this, const char *type) 606get_data(struct graphics_priv *this, const char *type)
540{ 607{
541 //DBG dbg(0,"EEnter\n"); 608 //DBG dbg(0,"EEnter\n");
542 609
543 if (strcmp(type, "window")) 610 if (strcmp(type, "window"))
611 {
544 return NULL; 612 return NULL;
613 }
614
545 return &this->win; 615 return &this->win;
546} 616}
547 617
548static 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)
549{ 619{
572} 642}
573 643
574static void overlay_disable(struct graphics_priv *gra, int disable) 644static void overlay_disable(struct graphics_priv *gra, int disable)
575{ 645{
576 //DBG dbg(0,"EEnter\n"); 646 //DBG dbg(0,"EEnter\n");
647 JNIEnv *jnienv2;
648 jnienv2 = jni_getenv();
649
577 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable); 650 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable);
578} 651}
579 652
580static 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)
581{ 654{
582 //DBG dbg(0,"EEnter\n"); 655 //DBG dbg(0,"EEnter\n");
656 JNIEnv *jnienv2;
657 jnienv2 = jni_getenv();
658
583 (*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);
584} 660}
585 661
586static int set_attr(struct graphics_priv *gra, struct attr *attr) 662static int set_attr(struct graphics_priv *gra, struct attr *attr)
587{ 663{
588 //DBG dbg(0,"EEnter\n"); 664 //DBG dbg(0,"EEnter\n");
665 JNIEnv *jnienv2;
666 jnienv2 = jni_getenv();
667
589 switch (attr->type) 668 switch (attr->type)
590 { 669 {
591 case attr_use_camera: 670 case attr_use_camera:
592 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num); 671 (*jnienv2)->CallVoidMethod(jnienv2, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num);
593 return 1; 672 return 1;
594 default: 673 default:
595 return 0; 674 return 0;
596 } 675 }
597} 676}
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) 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)
674{ 753{
675 struct callback *cb; 754 struct callback *cb;
676 jmethodID cid; 755 jmethodID cid;
677 756
678 //DBG dbg(0, "at 2 jnienv=%p\n", jnienv); 757 dbg(0, "at 2 jnienv=%p\n", jnienv);
679 //DBG dbg(0,"a1\n"); 758 //DBG dbg(0,"a1\n");
680 if (!find_class_global("android/graphics/Paint", &ret->PaintClass)) 759 if (!find_class_global("android/graphics/Paint", &ret->PaintClass))
681 return 0; 760 return 0;
682 //DBG dbg(0,"a2\n"); 761 //DBG dbg(0,"a2\n");
683 if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init)) 762 if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init))
737 //DBG dbg(0, "no method found\n"); 816 //DBG dbg(0, "no method found\n");
738 return 0; /* exception thrown */ 817 return 0; /* exception thrown */
739 } 818 }
740 //DBG dbg(0, "at 4 android_activity=%p\n", android_activity); 819 //DBG dbg(0, "at 4 android_activity=%p\n", android_activity);
741 ret->NavitGraphics = (*jnienv)->NewObject(jnienv, ret->NavitGraphicsClass, cid, android_activity, parent ? parent->NavitGraphics : NULL, pnt ? pnt->x : 0, pnt ? pnt->y : 0, w, h, alpha, wraparound, use_camera); 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);
742 //DBG dbg(0, "result=%p\n", ret->NavitGraphics); 821 dbg(0, "result=%p\n", ret->NavitGraphics);
743 if (ret->NavitGraphics) 822 if (ret->NavitGraphics)
744 { 823 {
745 ret->NavitGraphics = (*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics); 824 ret->NavitGraphics = (*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics);
746 } 825 }
747 826
880static jmethodID Navit_disableSuspend, Navit_exit; 959static jmethodID Navit_disableSuspend, Navit_exit;
881 960
882static void graphics_android_disable_suspend(struct window *win) 961static void graphics_android_disable_suspend(struct window *win)
883{ 962{
884 //DBG dbg(0,"enter\n"); 963 //DBG dbg(0,"enter\n");
964 JNIEnv *jnienv2;
965 jnienv2 = jni_getenv();
966
885 (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_disableSuspend); 967 (*jnienv2)->CallVoidMethod(jnienv2, android_activity, Navit_disableSuspend);
886} 968}
887 969
888static struct graphics_priv * 970static struct graphics_priv *
889graphics_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)
890{ 972{
891 //DBG dbg(0,"EEnter\n"); 973 //DBG dbg(0,"EEnter\n");
892 974
893 struct graphics_priv *ret; 975 struct graphics_priv *ret;
894 struct attr *attr; 976 struct attr *attr;
895 int use_camera = 0; 977 int use_camera = 0;
978
896 if (!event_request_system("android", "graphics_android")) 979 if (!event_request_system("android", "graphics_android"))
980 {
981 return NULL;
982 }
983
897 return NULL;ret=g_new0(struct graphics_priv, 1); 984 ret=g_new0(struct graphics_priv, 1);
898
899 ret->cbl = cbl; 985 ret->cbl = cbl;
900 *meth = graphics_methods; 986 *meth = graphics_methods;
901 ret->win.priv = ret; 987 ret->win.priv = ret;
902 ret->win.fullscreen = graphics_android_fullscreen; 988 ret->win.fullscreen = graphics_android_fullscreen;
903 ret->win.disable_suspend = graphics_android_disable_suspend; 989 ret->win.disable_suspend = graphics_android_disable_suspend;
996 //dbg(0,"EEnter\n"); 1082 //dbg(0,"EEnter\n");
997 1083
998 // timeout -> delay in milliseconds 1084 // timeout -> delay in milliseconds
999 1085
1000 jobject ret; 1086 jobject ret;
1087 jobject ret_g = NULL;
1001 ret = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int) cb); 1088 ret = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int) cb);
1002 //dbg(0, "result for %d,%d,%p\n", timeout, multi, cb); 1089 //dbg(0, "result for %d,%d,%p\n", timeout, multi, cb);
1003 1090
1004 if (ret) 1091 if (ret)
1005 { 1092 {
1006 //DBG dbg(0,"l ret=%p\n",ret); 1093 dbg(0,"l ret=%p\n",ret);
1007 ret = (*jnienv)->NewGlobalRef(jnienv, ret); 1094 ret_g = (*jnienv)->NewGlobalRef(jnienv, ret);
1008 //DBG dbg(0,"g ret=%p\n",ret); 1095 dbg(0,"g ret=%p\n",ret_g);
1009 } 1096 }
1010 //dbg(0,"leave\n"); 1097 //dbg(0,"leave\n");
1011 return (struct event_timeout *) ret; 1098 return (struct event_timeout *) ret_g;
1012} 1099}
1013 1100
1014static void event_android_remove_timeout(struct event_timeout *to) 1101static void event_android_remove_timeout(struct event_timeout *to)
1015{ 1102{
1016 //dbg(0,"EEnter\n"); 1103 //dbg(0,"EEnter\n");
1017 1104
1018 if (to) 1105 if (to)
1019 { 1106 {
1020 // //DBG dbg(0, "remove %p\n", to); 1107 dbg(0, "remove %p\n", to);
1021 //dbg(0, "remove\n");
1022 jobject obj = (jobject) to; 1108 jobject obj = (jobject) to;
1023 (*jnienv)->CallVoidMethod(jnienv, obj, NavitTimeout_remove); 1109 (*jnienv)->CallVoidMethod(jnienv, obj, NavitTimeout_remove);
1110 // ICS
1111 dbg(0, "remove 1\n");
1024 // ICS (*jnienv)->DeleteGlobalRef(jnienv, obj); 1112 (*jnienv)->DeleteGlobalRef(jnienv, obj);
1113 dbg(0, "remove 2\n");
1025 } 1114 }
1026} 1115}
1027 1116
1028static struct event_idle * 1117static struct event_idle *
1029event_android_add_idle(int priority, struct callback *cb) 1118event_android_add_idle(int priority, struct callback *cb)

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

   
Visit the ZANavi Wiki