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 (*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);
213 dbg(1,"enter %s\n",path);
214 if (!strncmp(path,"res/drawable/",13)) {
215 jstring a=(*jnienv)->NewStringUTF(jnienv, "drawable");
216 char *path_noext=g_strdup(path+13);
217 char *pos=strrchr(path_noext, '.');
220 dbg(1,"path_noext=%s\n",path_noext);
221 string = (*jnienv)->NewStringUTF(jnienv, path_noext);
223 id=(*jnienv)->CallIntMethod(jnienv, gra->Resources, gra->Resources_getIdentifier, string, a, gra->packageName);
226 ret->Bitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeResource, gra->Resources, id);
227 (*jnienv)->DeleteLocalRef(jnienv, a);
229 string = (*jnienv)->NewStringUTF(jnienv, path);
230 ret->Bitmap=(*jnienv)->CallStaticObjectMethod(jnienv, gra->BitmapFactoryClass, gra->BitmapFactory_decodeFile, string);
232 dbg(1,"result=%p\n",ret->Bitmap);
234 (*jnienv)->NewGlobalRef(jnienv, ret->Bitmap);
235 (*jnienv)->DeleteLocalRef(jnienv, ret->Bitmap);
236 ret->width=(*jnienv)->CallIntMethod(jnienv, ret->Bitmap, gra->Bitmap_getWidth);
237 ret->height=(*jnienv)->CallIntMethod(jnienv, ret->Bitmap, gra->Bitmap_getHeight);
238 dbg(1,"w=%d h=%d for %s\n",ret->width,ret->height,path);
239 ret->hot.x=ret->width/2;
240 ret->hot.y=ret->height/2;
244 dbg(0,"Failed to open %s\n",path);
246 (*jnienv)->DeleteLocalRef(jnienv, string);
247 g_hash_table_insert(image_cache_hash, g_strdup( path ), (gpointer)ret );
259 static void initPaint(struct graphics_priv *gra, struct graphics_gc_priv *gc)
261 float wf = gc->linewidth;
262 (*jnienv)->CallVoidMethod(jnienv, gc->gra->Paint, gra->Paint_setStrokeWidth, wf);
263 (*jnienv)->CallVoidMethod(jnienv, gc->gra->Paint, gra->Paint_setARGB, gc->a, gc->r, gc->g, gc->b);
267 draw_lines(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
274 points = (*jnienv)->NewIntArray(jnienv,count*2);
275 for (i = 0 ; i < count ; i++) {
280 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count*2, pc);
281 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polyline, gc->gra->Paint, points);
282 (*jnienv)->DeleteLocalRef(jnienv, points);
286 draw_polygon(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int count)
293 points = (*jnienv)->NewIntArray(jnienv,count*2);
294 for (i = 0 ; i < count ; i++) {
299 (*jnienv)->SetIntArrayRegion(jnienv, points, 0, count*2, pc);
300 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_polygon, gc->gra->Paint, points);
301 (*jnienv)->DeleteLocalRef(jnienv, points);
305 draw_rectangle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int w, int h)
308 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_rectangle, gc->gra->Paint, p->x, p->y, w, h);
312 draw_circle(struct graphics_priv *gra, struct graphics_gc_priv *gc, struct point *p, int r)
315 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_circle, gc->gra->Paint, p->x, p->y, r);
320 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)
322 dbg(1,"enter %s\n", text);
324 jstring string = (*jnienv)->NewStringUTF(jnienv, text);
325 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_text, fg->gra->Paint, p->x, p->y, string, font->size, dx, dy);
326 (*jnienv)->DeleteLocalRef(jnienv, string);
330 draw_image(struct graphics_priv *gra, struct graphics_gc_priv *fg, struct point *p, struct graphics_image_priv *img)
332 dbg(1,"enter %p\n",img);
334 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_image, fg->gra->Paint, p->x, p->y, img->Bitmap);
339 draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, char *data)
344 draw_restore(struct graphics_priv *gr, struct point *p, int w, int h)
348 static void draw_drag(struct graphics_priv *gra, struct point *p)
350 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_drag, p ? p->x : 0, p ? p->y : 0);
354 background_gc(struct graphics_priv *gr, struct graphics_gc_priv *gc)
359 draw_mode(struct graphics_priv *gra, enum draw_mode_num mode)
361 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_draw_mode, (int)mode);
364 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);
367 get_data(struct graphics_priv *this, const char *type)
369 if (strcmp(type,"window"))
374 static void image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
378 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)
380 int len = g_utf8_strlen(text, -1);
383 int yMax = 13*font->size/256;
384 int xMax = 9*font->size*len/256;
396 static void overlay_disable(struct graphics_priv *gra, int disable)
398 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_disable, disable);
401 static void overlay_resize(struct graphics_priv *gra, struct point *pnt, int w, int h, int alpha, int wraparound)
403 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_overlay_resize, pnt ? pnt->x:0 , pnt ? pnt->y:0, w, h, alpha, wraparound);
407 set_attr(struct graphics_priv *gra, struct attr *attr)
409 switch (attr->type) {
410 case attr_use_camera:
411 (*jnienv)->CallVoidMethod(jnienv, gra->NavitGraphics, gra->NavitGraphics_SetCamera, attr->u.num);
418 static struct graphics_methods graphics_methods = {
444 resize_callback(struct graphics_priv *gra, int w, int h)
446 dbg(0,"w=%d h=%d ok\n",w,h);
447 callback_list_call_attr_2(gra->cbl, attr_resize, (void *)w, (void *)h);
451 motion_callback(struct graphics_priv *gra, int x, int y)
456 callback_list_call_attr_1(gra->cbl, attr_motion, (void *)&p);
460 keypress_callback(struct graphics_priv *gra, char *s)
462 dbg(0,"enter %s\n",s);
463 callback_list_call_attr_1(gra->cbl, attr_keypress, s);
467 button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y)
472 callback_list_call_attr_3(gra->cbl, attr_button, (void *)pressed, (void *)button, (void *)&p);
477 set_activity(jobject graphics)
479 jclass ActivityClass;
482 ActivityClass = (*jnienv)->GetObjectClass(jnienv, android_activity);
484 if (ActivityClass == NULL) {
485 dbg(0,"no activity class found\n");
489 cid = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setContentView", "(Landroid/view/View;)V");
491 dbg(0,"no setContentView method found\n");
495 (*jnienv)->CallVoidMethod(jnienv, android_activity, cid, graphics);
501 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)
504 jmethodID cid, Context_getPackageName;
506 dbg(0,"at 2 jnienv=%p\n",jnienv);
507 if (!find_class_global("android/graphics/Paint", &ret->PaintClass))
509 if (!find_method(ret->PaintClass, "<init>", "(I)V", &ret->Paint_init))
511 if (!find_method(ret->PaintClass, "setARGB", "(IIII)V", &ret->Paint_setARGB))
513 if (!find_method(ret->PaintClass, "setStrokeWidth", "(F)V", &ret->Paint_setStrokeWidth))
516 if (!find_class_global("android/graphics/BitmapFactory", &ret->BitmapFactoryClass))
518 if (!find_static_method(ret->BitmapFactoryClass, "decodeFile", "(Ljava/lang/String;)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeFile))
520 if (!find_static_method(ret->BitmapFactoryClass, "decodeResource", "(Landroid/content/res/Resources;I)Landroid/graphics/Bitmap;", &ret->BitmapFactory_decodeResource))
523 if (!find_class_global("android/graphics/Bitmap", &ret->BitmapClass))
525 if (!find_method(ret->BitmapClass, "getHeight", "()I", &ret->Bitmap_getHeight))
527 if (!find_method(ret->BitmapClass, "getWidth", "()I", &ret->Bitmap_getWidth))
530 if (!find_class_global("android/content/Context", &ret->ContextClass))
532 if (!find_method(ret->ContextClass, "getResources", "()Landroid/content/res/Resources;", &ret->Context_getResources))
536 ret->Resources=(*jnienv)->CallObjectMethod(jnienv, android_activity, ret->Context_getResources);
538 (*jnienv)->NewGlobalRef(jnienv, ret->Resources);
539 if (!find_class_global("android/content/res/Resources", &ret->ResourcesClass))
541 if (!find_method(ret->ResourcesClass, "getIdentifier", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", &ret->Resources_getIdentifier))
544 if (!find_method(ret->ContextClass, "getPackageName", "()Ljava/lang/String;", &Context_getPackageName))
546 ret->packageName=(*jnienv)->CallObjectMethod(jnienv, android_activity, Context_getPackageName);
547 (*jnienv)->NewGlobalRef(jnienv, ret->packageName);
549 if (!find_class_global("org/navitproject/navit/NavitGraphics", &ret->NavitGraphicsClass))
552 cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>", "(Landroid/app/Activity;Lorg/navitproject/navit/NavitGraphics;IIIIIII)V");
554 dbg(0,"no method found\n");
555 return 0; /* exception thrown */
557 dbg(0,"at 4 android_activity=%p\n",android_activity);
558 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);
559 dbg(0,"result=%p\n",ret->NavitGraphics);
560 if (ret->NavitGraphics)
561 (*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 (*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);
651 static struct graphics_priv *
652 graphics_android_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl)
654 struct graphics_priv *ret;
657 if (!event_request_system("android","graphics_android"))
659 ret=g_new0(struct graphics_priv, 1);
662 *meth=graphics_methods;
664 ret->win.fullscreen=graphics_android_fullscreen;
665 ret->win.disable_suspend=graphics_android_disable_suspend;
666 if ((attr=attr_search(attrs, NULL, attr_use_camera))) {
667 use_camera=attr->u.num;
669 image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
670 if (graphics_android_init(ret, NULL, NULL, 0, 0, 0, 0, use_camera)) {
671 dbg(0,"returning %p\n",ret);
679 static struct graphics_priv *
680 overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int alpha, int wraparound)
682 struct graphics_priv *ret=g_new0(struct graphics_priv, 1);
683 *meth=graphics_methods;
684 if (graphics_android_init(ret, gr, p, w, h, alpha, wraparound, 0)) {
685 dbg(0,"returning %p\n",ret);
695 event_android_main_loop_run(void)
700 static void event_android_main_loop_quit(void)
703 (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_exit);
707 static jclass NavitTimeoutClass;
708 static jmethodID NavitTimeout_init;
709 static jmethodID NavitTimeout_remove;
711 static jclass NavitIdleClass;
712 static jmethodID NavitIdle_init;
713 static jmethodID NavitIdle_remove;
715 static jclass NavitWatchClass;
716 static jmethodID NavitWatch_init;
717 static jmethodID NavitWatch_remove;
720 static void do_poll(JNIEnv *env, int fd, int cond)
724 dbg(1,"%p poll called for %d %d\n", fd, cond);
725 switch ((enum event_watch_cond)cond) {
726 case event_watch_cond_read:
729 case event_watch_cond_write:
732 case event_watch_cond_except:
742 static struct event_watch *
743 event_android_add_watch(void *h, enum event_watch_cond cond, struct callback *cb)
746 ret=(*jnienv)->NewObject(jnienv, NavitWatchClass, NavitWatch_init, (int)do_poll, (int) h, (int) cond, (int)cb);
747 dbg(0,"result for %p,%d,%p=%p\n",h,cond,cb,ret);
749 (*jnienv)->NewGlobalRef(jnienv, ret);
750 return (struct event_watch *)ret;
754 event_android_remove_watch(struct event_watch *ev)
756 dbg(0,"enter %p\n",ev);
758 jobject obj=(jobject )ev;
759 (*jnienv)->CallVoidMethod(jnienv, obj, NavitWatch_remove);
760 (*jnienv)->DeleteGlobalRef(jnienv, obj);
764 static struct event_timeout *
765 event_android_add_timeout(int timeout, int multi, struct callback *cb)
768 ret=(*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int)cb);
769 dbg(1,"result for %d,%d,%p=%p\n",timeout,multi,cb,ret);
771 (*jnienv)->NewGlobalRef(jnienv, ret);
772 return (struct event_timeout *)ret;
776 event_android_remove_timeout(struct event_timeout *to)
778 dbg(1,"enter %p\n",to);
780 jobject obj=(jobject )to;
781 (*jnienv)->CallVoidMethod(jnienv, obj, NavitTimeout_remove);
782 (*jnienv)->DeleteGlobalRef(jnienv, obj);
787 static struct event_idle *
788 event_android_add_idle(int priority, struct callback *cb)
793 ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb);
794 dbg(1,"result for %p=%p\n",cb,ret);
796 (*jnienv)->NewGlobalRef(jnienv, ret);
797 return (struct event_idle *)ret;
799 return (struct event_idle *)event_android_add_timeout(1, 1, cb);
803 event_android_remove_idle(struct event_idle *ev)
806 dbg(1,"enter %p\n",ev);
808 jobject obj=(jobject )ev;
809 (*jnienv)->CallVoidMethod(jnienv, obj, NavitIdle_remove);
810 (*jnienv)->DeleteGlobalRef(jnienv, obj);
813 event_android_remove_timeout((struct event_timeout *)ev);
817 event_android_call_callback(struct callback_list *cb)
822 static struct event_methods event_android_methods = {
823 event_android_main_loop_run,
824 event_android_main_loop_quit,
825 event_android_add_watch,
826 event_android_remove_watch,
827 event_android_add_timeout,
828 event_android_remove_timeout,
829 event_android_add_idle,
830 event_android_remove_idle,
831 event_android_call_callback,
834 static struct event_priv *
835 event_android_new(struct event_methods *meth)
838 if (!find_class_global("org/navitproject/navit/NavitTimeout", &NavitTimeoutClass))
840 NavitTimeout_init = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "<init>", "(IZI)V");
841 if (NavitTimeout_init == NULL)
843 NavitTimeout_remove = (*jnienv)->GetMethodID(jnienv, NavitTimeoutClass, "remove", "()V");
844 if (NavitTimeout_remove == NULL)
847 if (!find_class_global("org/navitproject/navit/NavitIdle", &NavitIdleClass))
849 NavitIdle_init = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "<init>", "(I)V");
850 if (NavitIdle_init == NULL)
852 NavitIdle_remove = (*jnienv)->GetMethodID(jnienv, NavitIdleClass, "remove", "()V");
853 if (NavitIdle_remove == NULL)
857 if (!find_class_global("org/navitproject/navit/NavitWatch", &NavitWatchClass))
859 NavitWatch_init = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "<init>", "(IIII)V");
860 if (NavitWatch_init == NULL)
862 NavitWatch_remove = (*jnienv)->GetMethodID(jnienv, NavitWatchClass, "remove", "()V");
863 if (NavitWatch_remove == NULL)
866 if (!find_class_global("org/navitproject/navit/Navit", &NavitClass))
868 Navit_disableSuspend = (*jnienv)->GetMethodID(jnienv, NavitClass, "disableSuspend", "()V");
869 if (Navit_disableSuspend == NULL)
871 Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit", "()V");
872 if (Navit_exit == NULL)
875 *meth=event_android_methods;
884 plugin_register_graphics_type("android", graphics_android_new);
885 plugin_register_event_type("android", event_android_new);