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