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

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

   
Visit the ZANavi Wiki