2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
36 struct graphics_priv {
37 jclass NavitGraphicsClass;
38 jmethodID NavitGraphics_draw_polyline, NavitGraphics_draw_polygon, NavitGraphics_draw_rectangle, NavitGraphics_draw_circle, NavitGraphics_draw_text, NavitGraphics_draw_image, NavitGraphics_draw_mode, NavitGraphics_draw_drag, NavitGraphics_overlay_disable, NavitGraphics_overlay_resize, NavitGraphics_SetCamera;
41 jmethodID Paint_init,Paint_setStrokeWidth,Paint_setARGB;
43 jobject NavitGraphics;
46 jclass BitmapFactoryClass;
47 jmethodID BitmapFactory_decodeFile, BitmapFactory_decodeResource;
50 jmethodID Bitmap_getHeight, Bitmap_getWidth;
53 jmethodID Context_getResources;
55 jclass ResourcesClass;
57 jmethodID Resources_getIdentifier;
61 struct callback_list *cbl;
65 struct graphics_font_priv {
69 struct graphics_gc_priv {
70 struct graphics_priv *gra;
72 enum draw_mode_num mode;
76 struct graphics_image_priv {
83 static GHashTable *image_cache_hash = NULL;
86 find_class_global(char *name, jclass *ret)
88 *ret=(*jnienv)->FindClass(jnienv, name);
90 dbg(0,"Failed to get Class %s\n",name);
93 *ret = (*jnienv)->NewGlobalRef(jnienv, *ret);
98 find_method(jclass class, char *name, char *args, jmethodID *ret)
100 *ret = (*jnienv)->GetMethodID(jnienv, class, name, args);
102 dbg(0,"Failed to get Method %s with signature %s\n",name,args);
109 find_static_method(jclass class, char *name, char *args, jmethodID *ret)
111 *ret = (*jnienv)->GetStaticMethodID(jnienv, class, name, args);
113 dbg(0,"Failed to get static Method %s with signature %s\n",name,args);
120 graphics_destroy(struct graphics_priv *gr)
124 static void font_destroy(struct graphics_font_priv *font)
129 static struct graphics_font_methods font_methods = {
133 static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct graphics_font_methods *meth, char *font, int size, int flags)
135 struct graphics_font_priv *ret=g_new0(struct graphics_font_priv, 1);
143 gc_destroy(struct graphics_gc_priv *gc)
149 gc_set_linewidth(struct graphics_gc_priv *gc, int w)
155 gc_set_dashes(struct graphics_gc_priv *gc, int w, int offset, unsigned char *dash_list, int n)
160 gc_set_foreground(struct graphics_gc_priv *gc, struct color *c)
169 gc_set_background(struct graphics_gc_priv *gc, struct color *c)
173 static struct graphics_gc_methods gc_methods = {
181 static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics_gc_methods *meth)
183 struct graphics_gc_priv *ret=g_new0(struct graphics_gc_priv, 1);
187 ret->a = ret->r = ret->g = ret->b = 255;
192 static void image_destroy(struct graphics_image_priv *img)
197 static struct graphics_image_methods image_methods = {
202 static struct graphics_image_priv *
203 image_new(struct graphics_priv *gra, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation)
205 struct graphics_image_priv* ret = NULL;
207 if ( !g_hash_table_lookup_extended( image_cache_hash, path, NULL, (gpointer)&ret) )
209 ret=g_new0(struct graphics_image_priv, 1);
211 jclass localBitmap = NULL;
214 dbg(1,"enter %s\n",path);
215 if (!strncmp(path,"res/drawable/",13)) {
216 jstring a=(*jnienv)->NewStringUTF(jnienv, "drawable");
217 char *path_noext=g_strdup(path+13);
218 char *pos=strrchr(path_noext, '.');
221 dbg(1,"path_noext=%s\n",path_noext);
222 string = (*jnienv)->NewStringUTF(jnienv, path_noext);
224 id=(*jnienv)->CallIntMethod(jnienv, gra->Resources, gra->Resources_getIdentifier, string, a, gra->packageName);
227 localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeResource, gra->Resources, id);
228 (*jnienv)->DeleteLocalRef(jnienv, a);
230 string = (*jnienv)->NewStringUTF(jnienv, path);
231 localBitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeFile, string);
233 dbg(1,"result=%p\n",localBitmap);
235 ret->Bitmap = (*jnienv)->NewGlobalRef(jnienv, localBitmap);
236 (*jnienv)->DeleteLocalRef(jnienv, localBitmap);
237 ret->width=(*jnienv)->CallIntMethod(jnienv, ret->Bitmap, gra->Bitmap_getWidth);
238 ret->height=(*jnienv)->CallIntMethod(jnienv, ret->Bitmap, gra->Bitmap_getHeight);
239 dbg(1,"w=%d h=%d for %s\n",ret->width,ret->height,path);
240 ret->hot.x=ret->width/2;
241 ret->hot.y=ret->height/2;
245 dbg(0,"Failed to open %s\n",path);
247 (*jnienv)->DeleteLocalRef(jnienv, string);
248 g_hash_table_insert(image_cache_hash, g_strdup( path ), (gpointer)ret );
260 static void initPaint(struct graphics_priv *gra, struct graphics_gc_priv *gc)
262 float wf = gc->linewidth;
263 (*jnienv)->CallVoidMethod(jnienv, gc->gra->Paint, gra->Paint_setStrokeWidth, wf);
264 (*jnienv)->CallVoidMethod(jnienv, gc->gra->Paint, gra->Paint_setARGB, gc->a, gc->r, gc->g, gc->b);
268 draw_lines(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
275 points = (*jnienv)->NewIntArray(jnienv,count*2);
276 for (i = 0 ; i < count ; i++) {
281 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count*2, pc);
282 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polyline, gc->gra->Paint, points);
283 (*jnienv)->DeleteLocalRef(jnienv, points);
287 draw_polygon(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
294 points = (*jnienv)->NewIntArray(jnienv,count*2);
295 for (i = 0 ; i < count ; i++) {
300 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count*2, pc);
301 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polygon, gc->gra->Paint, points);
302 (*jnienv)->DeleteLocalRef(jnienv, points);
306 draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h)
309 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w, h);
313 draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r)
316 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_circle, gc->gra->Paint, p->x, p->y, r);
321 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)
323 dbg(1,"enter %s\n", text);
325 jstring string = (*jnienv)->NewStringUTF(jnienv, text);
326 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_text, fg->gra->Paint, p->x, p->y, string, font->size, dx, dy);
327 (*jnienv)->DeleteLocalRef(jnienv, string);
331 draw_image(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
333 dbg(1,"enter %p\n",img);
335 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_image, fg->gra->Paint, p->x, p->y, img->Bitmap);
340 draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, char *data)
345 draw_restore(struct graphics_priv *gr, struct point *p, int w, int h)
349 static void draw_drag(struct graphics_priv *gra, struct point *p)
351 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_drag, p ? p->x : 0, p ? p->y : 0);
355 background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
360 draw_mode(struct graphics_priv *gra, enum draw_mode_num mode)
362 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int)mode);
365 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);
368 get_data(struct graphics_priv *this, const char *type)
370 if (strcmp(type,"window"))
375 static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
379 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)
381 int len = g_utf8_strlen(text, -1);
384 int yMax = 13*font->size/256;
385 int xMax = 9*font->size*len/256;
397 static void overlay_disable(struct graphics_priv *gra, int disable)
399 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable);
402 static void overlay_resize(struct graphics_priv *gra, struct point *pnt, int w, int h, int alpha, int wraparound)
404 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_resize, pnt ? pnt->x:0 , pnt ? pnt->y:0, w, h, alpha, wraparound);
408 set_attr(struct graphics_priv *gra, struct attr *attr)
410 switch (attr->type) {
411 case attr_use_camera:
412 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num);
419 static struct graphics_methods graphics_methods = {
445 resize_callback(struct graphics_priv *gra, int w, int h)
447 dbg(0,"w=%d h=%d ok\n",w,h);
448 callback_list_call_attr_2(gra->cbl, attr_resize, (void *)w, (void *)h);
452 motion_callback(struct graphics_priv *gra, int x, int y)
457 callback_list_call_attr_1(gra->cbl, attr_motion, (void *)&p);
461 keypress_callback(struct graphics_priv *gra, char *s)
463 dbg(0,"enter %s\n",s);
464 callback_list_call_attr_1(gra->cbl, attr_keypress, s);
468 button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y)
473 callback_list_call_attr_3(gra->cbl, attr_button, (void *)pressed, (void *)button, (void *)&p);
478 set_activity(jobject graphics)
480 jclass ActivityClass;
483 ActivityClass = (*jnienv)->GetObjectClass(jnienv, android_activity);
485 if (ActivityClass == NULL) {
486 dbg(0,"no activity class found\n");
490 cid = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setContentView", "(Landroid/view/View;)V");
492 dbg(0,"no setContentView method found\n");
496 (*jnienv)->CallVoidMethod(jnienv, android_activity, cid, graphics);
502 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)
505 jmethodID cid, Context_getPackageName;
507 dbg(0,"at 2 jnienv=%p\n",jnienv);
508 if (!find_class_global("android/graphics/Paint", &ret->PaintClass))
510 if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init))
512 if (!find_method(ret->PaintClass, "setARGB", "(IIII)V", &ret->Paint_setARGB))
514 if (!find_method(ret->PaintClass, "setStrokeWidth", "(F)V", &ret->Paint_setStrokeWidth))
517 if (!find_class_global("android/graphics/BitmapFactory", &ret->BitmapFactoryClass))
519 if (!find_static_method(ret->BitmapFactoryClass, "decodeFile", "(Ljava/lang/String;)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeFile))
521 if (!find_static_method(ret->BitmapFactoryClass, "decodeResource", "(Landroid/content/res/Resources;I)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeResource))
524 if (!find_class_global("android/graphics/Bitmap", &ret->BitmapClass))
526 if (!find_method(ret->BitmapClass, "getHeight", "()I", &ret->Bitmap_getHeight))
528 if (!find_method(ret->BitmapClass, "getWidth", "()I", &ret->Bitmap_getWidth))
531 if (!find_class_global("android/content/Context", &ret->ContextClass))
533 if (!find_method(ret->ContextClass, "getResources", "()Landroid/content/res/Resources;", &ret->Context_getResources))
537 ret->Resources=(*jnienv)->CallObjectMethod(jnienv, android_activity, ret->Context_getResources);
539 ret->Resources = (*jnienv)->NewGlobalRef(jnienv, ret->Resources);
540 if (!find_class_global("android/content/res/Resources", &ret->ResourcesClass))
542 if (!find_method(ret->ResourcesClass, "getIdentifier", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", &ret->Resources_getIdentifier))
545 if (!find_method(ret->ContextClass, "getPackageName", "()Ljava/lang/String;", &Context_getPackageName))
547 ret->packageName=(*jnienv)->CallObjectMethod(jnienv, android_activity, Context_getPackageName);
548 ret->packageName=(*jnienv)->NewGlobalRef(jnienv, ret->packageName);
550 if (!find_class_global("org/navitproject/navit/NavitGraphics", &ret->NavitGraphicsClass))
553 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>", "(Landroid/app/Activity;Lorg/navitproject/navit/NavitGraphics;IIIIIII)V");
555 dbg(0,"no method found\n");
556 return 0; /* exception thrown */
558 dbg(0,"at 4 android_activity=%p\n",android_activity);
559 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);
560 dbg(0,"result=%p\n",ret->NavitGraphics);
561 if (ret->NavitGraphics)
562 ret->NavitGraphics = (*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics);
564 /* Create a single global Paint, otherwise android will quickly run out
566 /* 0x101 = text kerning (default), antialiasing */
567 ret->Paint=(*jnienv)->NewObject(jnienv, ret->PaintClass, ret->Paint_init, 0x101);
569 dbg(0,"result=%p\n",ret->Paint);
571 ret->Paint = (*jnienv)->NewGlobalRef(jnienv, ret->Paint);
573 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setSizeChangedCallback", "(I)V");
575 dbg(0,"no SetResizeCallback method found\n");
576 return 0; /* exception thrown */
578 cb=callback_new_1(callback_cast(resize_callback), ret);
579 (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
581 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setButtonCallback", "(I)V");
583 dbg(0,"no SetButtonCallback method found\n");
584 return 0; /* exception thrown */
586 cb=callback_new_1(callback_cast(button_callback), ret);
587 (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
589 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setMotionCallback", "(I)V");
591 dbg(0,"no SetMotionCallback method found\n");
592 return 0; /* exception thrown */
594 cb=callback_new_1(callback_cast(motion_callback), ret);
595 (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
597 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setKeypressCallback", "(I)V");
599 dbg(0,"no SetKeypressCallback method found\n");
600 return 0; /* exception thrown */
602 cb=callback_new_1(callback_cast(keypress_callback), ret);
603 (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int)cb);
605 if (!find_method(ret->NavitGraphicsClass, "draw_polyline", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polyline))
607 if (!find_method(ret->NavitGraphicsClass, "draw_polygon", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polygon))
609 if (!find_method(ret->NavitGraphicsClass, "draw_rectangle", "(Landroid/graphics/Paint;IIII)V", &ret->NavitGraphics_draw_rectangle))
611 if (!find_method(ret->NavitGraphicsClass, "draw_circle", "(Landroid/graphics/Paint;III)V", &ret->NavitGraphics_draw_circle))
613 if (!find_method(ret->NavitGraphicsClass, "draw_text", "(Landroid/graphics/Paint;IILjava/lang/String;III)V", &ret->NavitGraphics_draw_text))
615 if (!find_method(ret->NavitGraphicsClass, "draw_image", "(Landroid/graphics/Paint;IILandroid/graphics/Bitmap;)V", &ret->NavitGraphics_draw_image))
617 if (!find_method(ret->NavitGraphicsClass, "draw_mode", "(I)V", &ret->NavitGraphics_draw_mode))
619 if (!find_method(ret->NavitGraphicsClass, "draw_drag", "(II)V", &ret->NavitGraphics_draw_drag))
621 if (!find_method(ret->NavitGraphicsClass, "overlay_disable", "(I)V", &ret->NavitGraphics_overlay_disable))
623 if (!find_method(ret->NavitGraphicsClass, "overlay_resize", "(IIIIII)V", &ret->NavitGraphics_overlay_resize))
625 if (!find_method(ret->NavitGraphicsClass, "SetCamera", "(I)V", &ret->NavitGraphics_SetCamera))
628 set_activity(ret->NavitGraphics);
634 graphics_android_fullscreen(struct window *win, int on)
639 static jclass NavitClass;
640 static jmethodID Navit_disableSuspend, Navit_exit;
643 graphics_android_disable_suspend(struct window *win)
646 (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_disableSuspend);
650 static struct graphics_priv *
651 graphics_android_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
653 struct graphics_priv *ret;
656 if (!event_request_system("android","graphics_android"))
658 ret=g_new0(struct graphics_priv, 1);
661 *meth=graphics_methods;
663 ret->win.fullscreen=graphics_android_fullscreen;
664 ret->win.disable_suspend=graphics_android_disable_suspend;
665 if ((attr=attr_search(attrs, NULL, attr_use_camera))) {
666 use_camera=attr->u.num;
668 image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
669 if (graphics_android_init(ret, NULL, NULL, 0, 0, 0, 0, use_camera)) {
670 dbg(0,"returning %p\n",ret);
678 static struct graphics_priv *
679 overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int alpha, int wraparound)
681 struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
682 *meth=graphics_methods;
683 if (graphics_android_init(ret, gr, p, w, h, alpha, wraparound, 0)) {
684 dbg(0,"returning %p\n",ret);
694 event_android_main_loop_run(void)
699 static void event_android_main_loop_quit(void)
702 (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_exit);
706 static jclass NavitTimeoutClass;
707 static jmethodID NavitTimeout_init;
708 static jmethodID NavitTimeout_remove;
710 static jclass NavitIdleClass;
711 static jmethodID NavitIdle_init;
712 static jmethodID NavitIdle_remove;
714 static jclass NavitWatchClass;
715 static jmethodID NavitWatch_init;
716 static jmethodID NavitWatch_remove;
719 static void do_poll(JNIEnv *env, int fd, int cond)
723 dbg(1,"%p poll called for %d %d\n", fd, cond);
724 switch ((enum event_watch_cond)cond) {
725 case event_watch_cond_read:
728 case event_watch_cond_write:
731 case event_watch_cond_except:
741 static struct event_watch *
742 event_android_add_watch(void *h, enum event_watch_cond cond, struct callback *cb)
745 ret=(*jnienv)->NewObject(jnienv, NavitWatchClass, NavitWatch_init, (int)do_poll, (int) h, (int) cond, (int)cb);
746 dbg(0,"result for %p,%d,%p=%p\n",h,cond,cb,ret);
748 ret = (*jnienv)->NewGlobalRef(jnienv, ret);
749 return (struct event_watch *)ret;
753 event_android_remove_watch(struct event_watch *ev)
755 dbg(0,"enter %p\n",ev);
757 jobject obj=(jobject )ev;
758 (*jnienv)->CallVoidMethod(jnienv, obj, NavitWatch_remove);
759 (*jnienv)->DeleteGlobalRef(jnienv, obj);
765 void (*handle_timeout)(struct event_timeout *priv);
772 event_android_remove_timeout(struct event_timeout *priv)
774 if (priv && priv->jni_timeout) {
775 (*jnienv)->CallVoidMethod(jnienv, priv->jni_timeout, NavitTimeout_remove);
776 (*jnienv)->DeleteGlobalRef(jnienv, priv->jni_timeout);
777 priv->jni_timeout = NULL;
781 static void event_android_handle_timeout(struct event_timeout *priv)
783 callback_call_0(priv->cb);
785 event_android_remove_timeout(priv);
788 static struct event_timeout *
789 event_android_add_timeout(int timeout, int multi, struct callback *cb)
791 struct event_timeout *ret = g_new0(struct event_timeout, 1);
794 ret->handle_timeout = event_android_handle_timeout;
795 ret->jni_timeout = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int)ret);
796 if (ret->jni_timeout)
797 ret->jni_timeout = (*jnienv)->NewGlobalRef(jnienv, ret->jni_timeout);
802 static struct event_idle *
803 event_android_add_idle(int priority, struct callback *cb)
808 ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb);
809 dbg(1,"result for %p=%p\n",cb,ret);
811 ret = (*jnienv)->NewGlobalRef(jnienv, ret);
812 return (struct event_idle *)ret;
814 return (struct event_idle *)event_android_add_timeout(1, 1, cb);
818 event_android_remove_idle(struct event_idle *ev)
821 dbg(1,"enter %p\n",ev);
823 jobject obj=(jobject )ev;
824 (*jnienv)->CallVoidMethod(jnienv, obj, NavitIdle_remove);
825 (*jnienv)->DeleteGlobalRef(jnienv, obj);
828 event_android_remove_timeout((struct event_timeout *)ev);
832 event_android_call_callback(struct callback_list *cb)
837 static struct event_methods event_android_methods = {
838 event_android_main_loop_run,
839 event_android_main_loop_quit,
840 event_android_add_watch,
841 event_android_remove_watch,
842 event_android_add_timeout,
843 event_android_remove_timeout,
844 event_android_add_idle,
845 event_android_remove_idle,
846 event_android_call_callback,
849 static struct event_priv *
850 event_android_new(struct event_methods *meth)
853 if (!find_class_global("org/navitproject/navit/NavitTimeout", &NavitTimeoutClass))
855 NavitTimeout_init = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "<init>", "(IZI)V");
856 if (NavitTimeout_init == NULL)
858 NavitTimeout_remove = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "remove", "()V");
859 if (NavitTimeout_remove == NULL)
862 if (!find_class_global("org/navitproject/navit/NavitIdle", &NavitIdleClass))
864 NavitIdle_init = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "<init>", "(I)V");
865 if (NavitIdle_init == NULL)
867 NavitIdle_remove = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "remove", "()V");
868 if (NavitIdle_remove == NULL)
872 if (!find_class_global("org/navitproject/navit/NavitWatch", &NavitWatchClass))
874 NavitWatch_init = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "<init>", "(IIII)V");
875 if (NavitWatch_init == NULL)
877 NavitWatch_remove = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "remove", "()V");
878 if (NavitWatch_remove == NULL)
881 if (!find_class_global("org/navitproject/navit/Navit", &NavitClass))
883 Navit_disableSuspend = (*jnienv)->GetMethodID(jnienv, NavitClass, "disableSuspend", "()V");
884 if (Navit_disableSuspend == NULL)
886 Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit", "()V");
887 if (Navit_exit == NULL)
890 *meth=event_android_methods;
899 plugin_register_graphics_type("android", graphics_android_new);
900 plugin_register_event_type("android", event_android_new);