… | |
… | |
331 | //DBG dbg(0,"EEnter\n"); |
331 | //DBG dbg(0,"EEnter\n"); |
332 | jint pc[count * 2]; |
332 | jint pc[count * 2]; |
333 | int i; |
333 | int i; |
334 | jintArray points; |
334 | jintArray points; |
335 | if (count <= 0) |
335 | if (count <= 0) |
|
|
336 | { |
336 | return; |
337 | return; |
|
|
338 | } |
337 | points = (*jnienv)->NewIntArray(jnienv, count * 2); |
339 | points = (*jnienv)->NewIntArray(jnienv, count * 2); |
338 | for (i = 0; i < count; i++) |
340 | for (i = 0; i < count; i++) |
339 | { |
341 | { |
340 | pc[i * 2] = p[i].x; |
342 | pc[i * 2] = p[i].x; |
341 | pc[i * 2 + 1] = p[i].y; |
343 | pc[i * 2 + 1] = p[i].y; |
… | |
… | |
549 | |
551 | |
550 | 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) |
552 | 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) |
551 | { |
553 | { |
552 | ////DBG dbg(0,"EEnter\n"); |
554 | ////DBG dbg(0,"EEnter\n"); |
553 | |
555 | |
|
|
556 | // this is a rough estimate!! otherwise java methods would be called, and thats too slow! |
|
|
557 | |
554 | int len = g_utf8_strlen(text, -1); |
558 | int len = g_utf8_strlen(text, -1); |
555 | int xMin = 0; |
559 | int xMin = 0; |
556 | int yMin = 0; |
560 | int yMin = 0; |
557 | int yMax = 13 * font->size / 256; |
561 | int yMax = 13 * font->size / 256; |
558 | int xMax = 9 * font->size * len / 256; |
562 | int xMax = 9 * font->size * len / 256; |
… | |
… | |
594 | |
598 | |
595 | static struct graphics_methods graphics_methods = |
599 | static struct graphics_methods graphics_methods = |
596 | { 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, |
600 | { graphics_destroy, draw_mode, draw_lines, draw_lines2, draw_lines3, draw_lines4, draw_lines_dashed, draw_polygon, draw_polygon2, draw_rectangle, draw_circle, draw_text, draw_image, draw_bigmap, send_osd_values, draw_image_warp, draw_restore, draw_drag, font_new, gc_new, background_gc, overlay_new, image_new, get_data, |
597 | image_free, get_text_bbox, overlay_disable, overlay_resize, set_attr, }; |
601 | image_free, get_text_bbox, overlay_disable, overlay_resize, set_attr, }; |
598 | |
602 | |
|
|
603 | /* |
599 | static void resize_callback(struct graphics_priv *gra, int w, int h) |
604 | static void resize_callback(struct graphics_priv *gra, int w, int h) |
600 | { |
605 | { |
601 | //DBG dbg(0,"EEnter\n"); |
606 | //DBG dbg(0,"EEnter\n"); |
602 | // //DBG dbg(0,"w=%d h=%d ok\n",w,h); |
607 | // //DBG dbg(0,"w=%d h=%d ok\n",w,h); |
603 | callback_list_call_attr_2(gra->cbl, attr_resize, (void *) w, (void *) h); |
608 | // callback_list_call_attr_2(gra->cbl, attr_resize, (void *) w, (void *) h); |
|
|
609 | navit_resize(attr_resize, this_); |
604 | } |
610 | } |
|
|
611 | */ |
605 | |
612 | |
|
|
613 | /* |
606 | static void motion_callback(struct graphics_priv *gra, int x, int y) |
614 | static void motion_callback(struct graphics_priv *gra, int x, int y) |
607 | { |
615 | { |
608 | //DBG dbg(0,"EEnter\n"); |
616 | //DBG dbg(0,"EEnter\n"); |
609 | |
617 | |
610 | struct point p; |
618 | struct point p; |
611 | p.x = x; |
619 | p.x = x; |
612 | p.y = y; |
620 | p.y = y; |
613 | callback_list_call_attr_1(gra->cbl, attr_motion, (void *) &p); |
621 | callback_list_call_attr_1(gra->cbl, attr_motion, (void *) &p); |
614 | } |
622 | } |
|
|
623 | */ |
615 | |
624 | |
|
|
625 | /* |
616 | static void keypress_callback(struct graphics_priv *gra, char *s) |
626 | static void keypress_callback(struct graphics_priv *gra, char *s) |
617 | { |
627 | { |
618 | //DBG dbg(0,"EEnter\n"); |
628 | //DBG dbg(0,"EEnter\n"); |
619 | callback_list_call_attr_1(gra->cbl, attr_keypress, s); |
629 | callback_list_call_attr_1(gra->cbl, attr_keypress, s); |
620 | } |
630 | } |
|
|
631 | */ |
621 | |
632 | |
|
|
633 | /* |
622 | static void button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y) |
634 | static void button_callback(struct graphics_priv *gra, int pressed, int button, int x, int y) |
623 | { |
635 | { |
624 | //DBG dbg(0,"EEnter\n"); |
636 | //DBG dbg(0,"EEnter\n"); |
625 | |
637 | |
626 | struct point p; |
638 | struct point p; |
627 | p.x = x; |
639 | p.x = x; |
628 | p.y = y; |
640 | p.y = y; |
629 | // //DBG dbg(0,"XXXXXXXYYYYYYYYY\n"); |
641 | // //DBG dbg(0,"XXXXXXXYYYYYYYYY\n"); |
630 | callback_list_call_attr_3(gra->cbl, attr_button, (void *) pressed, (void *) button, (void *) &p); |
642 | callback_list_call_attr_3(gra->cbl, attr_button, (void *) pressed, (void *) button, (void *) &p); |
631 | } |
643 | } |
|
|
644 | */ |
632 | |
645 | |
633 | static int set_activity(jobject graphics) |
646 | static int set_activity(jobject graphics) |
634 | { |
647 | { |
635 | //DBG dbg(0,"EEnter\n"); |
648 | //DBG dbg(0,"EEnter\n"); |
636 | |
649 | |
… | |
… | |
742 | { |
755 | { |
743 | ret->Paint = (*jnienv)->NewGlobalRef(jnienv, ret->Paint); |
756 | ret->Paint = (*jnienv)->NewGlobalRef(jnienv, ret->Paint); |
744 | } |
757 | } |
745 | //DBG dbg(0, "g result=%p\n", ret->Paint); |
758 | //DBG dbg(0, "g result=%p\n", ret->Paint); |
746 | |
759 | |
|
|
760 | /* |
747 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setSizeChangedCallback", "(I)V"); |
761 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setSizeChangedCallback", "(I)V"); |
748 | if (cid == NULL) |
762 | if (cid == NULL) |
749 | { |
763 | { |
750 | //DBG dbg(0, "no SetResizeCallback method found\n"); |
764 | //DBG dbg(0, "no SetResizeCallback method found\n"); |
751 | return 0; /* exception thrown */ |
765 | return 0; |
752 | } |
766 | } |
753 | cb = callback_new_1(callback_cast(resize_callback), ret); |
767 | cb = callback_new_1(callback_cast(resize_callback), ret); |
754 | (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb); |
768 | (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb); |
|
|
769 | */ |
755 | |
770 | |
|
|
771 | /* |
756 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setButtonCallback", "(I)V"); |
772 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setButtonCallback", "(I)V"); |
757 | if (cid == NULL) |
773 | if (cid == NULL) |
758 | { |
774 | { |
759 | //DBG dbg(0, "no SetButtonCallback method found\n"); |
775 | //DBG dbg(0, "no SetButtonCallback method found\n"); |
760 | return 0; /* exception thrown */ |
776 | return 0; |
761 | } |
777 | } |
762 | cb = callback_new_1(callback_cast(button_callback), ret); |
778 | cb = callback_new_1(callback_cast(button_callback), ret); |
763 | (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb); |
779 | (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb); |
|
|
780 | */ |
764 | |
781 | |
|
|
782 | /* |
765 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setMotionCallback", "(I)V"); |
783 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setMotionCallback", "(I)V"); |
766 | if (cid == NULL) |
784 | if (cid == NULL) |
767 | { |
785 | { |
768 | //DBG dbg(0, "no SetMotionCallback method found\n"); |
786 | //DBG dbg(0, "no SetMotionCallback method found\n"); |
769 | return 0; /* exception thrown */ |
787 | return 0; |
770 | } |
788 | } |
771 | cb = callback_new_1(callback_cast(motion_callback), ret); |
789 | cb = callback_new_1(callback_cast(motion_callback), ret); |
772 | (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb); |
790 | (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb); |
|
|
791 | */ |
|
|
792 | |
|
|
793 | // sets the graphics object for the JAVA code (this is bad, please fix me!!) |
|
|
794 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "NavitSetGrObj", "()V"); |
|
|
795 | if (cid == NULL) |
|
|
796 | { |
|
|
797 | //DBG dbg(0, "no SetMotionCallback method found\n"); |
|
|
798 | return 0; |
|
|
799 | } |
|
|
800 | (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid); |
|
|
801 | |
773 | |
802 | |
774 | // public Bitmap rotate_and_scale_bitmap(Bitmap in, int w, int h, int angle) |
803 | // public Bitmap rotate_and_scale_bitmap(Bitmap in, int w, int h, int angle) |
775 | |
804 | |
776 | if (!find_static_method(ret->NavitGraphicsClass, "rotate_and_scale_bitmap", "(Landroid/graphics/Bitmap;III)Landroid/graphics/Bitmap;", &ret->NavitGraphicsClass_rotate_and_scale_bitmap)) |
805 | if (!find_static_method(ret->NavitGraphicsClass, "rotate_and_scale_bitmap", "(Landroid/graphics/Bitmap;III)Landroid/graphics/Bitmap;", &ret->NavitGraphicsClass_rotate_and_scale_bitmap)) |
777 | return 0; |
806 | return 0; |
… | |
… | |
781 | //if (cid == NULL) { |
810 | //if (cid == NULL) { |
782 | // //DBG dbg(0,"no rotate_and_scale_bitmap method found\n"); |
811 | // //DBG dbg(0,"no rotate_and_scale_bitmap method found\n"); |
783 | // return 0; /* exception thrown */ |
812 | // return 0; /* exception thrown */ |
784 | //} |
813 | //} |
785 | |
814 | |
|
|
815 | /* |
786 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setKeypressCallback", "(I)V"); |
816 | cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "setKeypressCallback", "(I)V"); |
787 | if (cid == NULL) |
817 | if (cid == NULL) |
788 | { |
818 | { |
789 | //DBG dbg(0, "no SetKeypressCallback method found\n"); |
819 | //DBG dbg(0, "no SetKeypressCallback method found\n"); |
790 | return 0; /* exception thrown */ |
820 | return 0; |
791 | } |
821 | } |
792 | cb = callback_new_1(callback_cast(keypress_callback), ret); |
822 | cb = callback_new_1(callback_cast(keypress_callback), ret); |
793 | (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb); |
823 | (*jnienv)->CallVoidMethod(jnienv, ret->NavitGraphics, cid, (int) cb); |
|
|
824 | */ |
794 | |
825 | |
795 | if (!find_method(ret->NavitGraphicsClass, "draw_polyline", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polyline)) |
826 | if (!find_method(ret->NavitGraphicsClass, "draw_polyline", "(Landroid/graphics/Paint;[I)V", &ret->NavitGraphics_draw_polyline)) |
796 | return 0; |
827 | return 0; |
797 | if (!find_method(ret->NavitGraphicsClass, "draw_polyline2", "(Landroid/graphics/Paint;[III)V", &ret->NavitGraphics_draw_polyline2)) |
828 | if (!find_method(ret->NavitGraphicsClass, "draw_polyline2", "(Landroid/graphics/Paint;[III)V", &ret->NavitGraphics_draw_polyline2)) |
798 | return 0; |
829 | return 0; |
… | |
… | |
826 | return 0; |
857 | return 0; |
827 | if (!find_method(ret->NavitGraphicsClass, "overlay_disable", "(I)V", &ret->NavitGraphics_overlay_disable)) |
858 | if (!find_method(ret->NavitGraphicsClass, "overlay_disable", "(I)V", &ret->NavitGraphics_overlay_disable)) |
828 | return 0; |
859 | return 0; |
829 | if (!find_method(ret->NavitGraphicsClass, "overlay_resize", "(IIIIII)V", &ret->NavitGraphics_overlay_resize)) |
860 | if (!find_method(ret->NavitGraphicsClass, "overlay_resize", "(IIIIII)V", &ret->NavitGraphics_overlay_resize)) |
830 | return 0; |
861 | return 0; |
|
|
862 | /* |
831 | if (!find_method(ret->NavitGraphicsClass, "SetCamera", "(I)V", &ret->NavitGraphics_SetCamera)) |
863 | if (!find_method(ret->NavitGraphicsClass, "SetCamera", "(I)V", &ret->NavitGraphics_SetCamera)) |
832 | return 0; |
864 | return 0; |
|
|
865 | */ |
833 | |
866 | |
834 | //DBG dbg(0,"99\n"); |
867 | //DBG dbg(0,"99\n"); |
835 | #if 0 |
868 | #if 0 |
836 | set_activity(ret->NavitGraphics); |
869 | set_activity(ret->NavitGraphics); |
837 | #endif |
870 | #endif |
… | |
… | |
904 | } |
937 | } |
905 | } |
938 | } |
906 | |
939 | |
907 | static void event_android_main_loop_run(void) |
940 | static void event_android_main_loop_run(void) |
908 | { |
941 | { |
909 | //DBG dbg(0, "enter\n"); |
942 | dbg(0, "enter\n"); |
910 | } |
943 | } |
911 | |
944 | |
912 | static void event_android_main_loop_quit(void) |
945 | static void event_android_main_loop_quit(void) |
913 | { |
946 | { |
914 | //DBG dbg(0, "enter\n"); |
947 | dbg(0, "enter\n"); |
915 | // ******* exit(0); |
948 | // ******* exit(0); |
916 | (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_exit); |
949 | (*jnienv)->CallVoidMethod(jnienv, android_activity, Navit_exit); |
917 | } |
950 | } |
918 | |
951 | |
919 | static jclass NavitTimeoutClass; |
952 | static jclass NavitTimeoutClass; |
… | |
… | |
958 | } |
991 | } |
959 | |
992 | |
960 | static struct event_timeout * |
993 | static struct event_timeout * |
961 | event_android_add_timeout(int timeout, int multi, struct callback *cb) |
994 | event_android_add_timeout(int timeout, int multi, struct callback *cb) |
962 | { |
995 | { |
963 | //DBG dbg(0,"EEnter\n"); |
996 | //dbg(0,"EEnter\n"); |
|
|
997 | |
|
|
998 | // timeout -> delay in milliseconds |
964 | |
999 | |
965 | jobject ret; |
1000 | jobject ret; |
966 | ret = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int) cb); |
1001 | ret = (*jnienv)->NewObject(jnienv, NavitTimeoutClass, NavitTimeout_init, timeout, multi, (int) cb); |
967 | ////DBG dbg(0, "result for %d,%d,%p\n", timeout, multi, cb); |
1002 | //dbg(0, "result for %d,%d,%p\n", timeout, multi, cb); |
968 | |
1003 | |
969 | if (ret) |
1004 | if (ret) |
970 | { |
1005 | { |
971 | //DBG dbg(0,"l ret=%p\n",ret); |
1006 | //DBG dbg(0,"l ret=%p\n",ret); |
972 | ret = (*jnienv)->NewGlobalRef(jnienv, ret); |
1007 | ret = (*jnienv)->NewGlobalRef(jnienv, ret); |
973 | //DBG dbg(0,"g ret=%p\n",ret); |
1008 | //DBG dbg(0,"g ret=%p\n",ret); |
974 | } |
1009 | } |
975 | //DBG dbg(0,"leave\n"); |
1010 | //dbg(0,"leave\n"); |
976 | return (struct event_timeout *) ret; |
1011 | return (struct event_timeout *) ret; |
977 | } |
1012 | } |
978 | |
1013 | |
979 | static void event_android_remove_timeout(struct event_timeout *to) |
1014 | static void event_android_remove_timeout(struct event_timeout *to) |
980 | { |
1015 | { |
981 | //DBG dbg(0,"EEnter\n"); |
1016 | //dbg(0,"EEnter\n"); |
982 | |
1017 | |
983 | if (to) |
1018 | if (to) |
984 | { |
1019 | { |
985 | // //DBG dbg(0, "remove %p\n", to); |
1020 | // //DBG dbg(0, "remove %p\n", to); |
986 | //DBG dbg(0, "remove\n"); |
1021 | //dbg(0, "remove\n"); |
987 | jobject obj = (jobject) to; |
1022 | jobject obj = (jobject) to; |
988 | (*jnienv)->CallVoidMethod(jnienv, obj, NavitTimeout_remove); |
1023 | (*jnienv)->CallVoidMethod(jnienv, obj, NavitTimeout_remove); |
989 | // ICS (*jnienv)->DeleteGlobalRef(jnienv, obj); |
1024 | // ICS (*jnienv)->DeleteGlobalRef(jnienv, obj); |
990 | } |
1025 | } |
991 | } |
1026 | } |
992 | |
1027 | |
993 | static struct event_idle * |
1028 | static struct event_idle * |
994 | event_android_add_idle(int priority, struct callback *cb) |
1029 | event_android_add_idle(int priority, struct callback *cb) |
995 | { |
1030 | { |
|
|
1031 | // ---------------------------------------------------- |
|
|
1032 | // ---------------------------------------------------- |
|
|
1033 | // "priority" param is now misused here as "multi" |
|
|
1034 | // priority == 1000 -> set multi = 0 |
|
|
1035 | // ---------------------------------------------------- |
|
|
1036 | // ---------------------------------------------------- |
|
|
1037 | |
996 | //DBG dbg(0,"EEnter\n"); |
1038 | //dbg(0,"EEnter\n"); |
997 | |
1039 | |
998 | #if 0 |
1040 | #if 0 |
999 | jobject ret; |
1041 | jobject ret; |
1000 | // dbg(1,"enter\n"); |
1042 | // dbg(1,"enter\n"); |
1001 | ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb); |
1043 | ret=(*jnienv)->NewObject(jnienv, NavitIdleClass, NavitIdle_init, (int)cb); |
1002 | // dbg(1,"result for %p=%p\n",cb,ret); |
1044 | // dbg(1,"result for %p=%p\n",cb,ret); |
1003 | if (ret) |
1045 | if (ret) |
1004 | (*jnienv)->NewGlobalRef(jnienv, ret); |
1046 | (*jnienv)->NewGlobalRef(jnienv, ret); |
1005 | return (struct event_idle *)ret; |
1047 | return (struct event_idle *)ret; |
1006 | #endif |
1048 | #endif |
|
|
1049 | // ----- xxxxxxxx ------ |
|
|
1050 | if (priority == 1000) |
|
|
1051 | { |
|
|
1052 | return (struct event_idle *) event_android_add_timeout(10, 0, cb); |
|
|
1053 | } |
|
|
1054 | else |
|
|
1055 | { |
1007 | return (struct event_idle *) event_android_add_timeout(1, 1, cb); |
1056 | return (struct event_idle *) event_android_add_timeout(10, 1, cb); |
|
|
1057 | } |
1008 | } |
1058 | } |
1009 | |
1059 | |
1010 | static void event_android_remove_idle(struct event_idle *ev) |
1060 | static void event_android_remove_idle(struct event_idle *ev) |
1011 | { |
1061 | { |
1012 | //DBG dbg(0,"EEnter\n"); |
1062 | //DBG dbg(0,"EEnter\n"); |
… | |
… | |
1066 | if (!find_class_global("com/zoffcc/applications/zanavi/Navit", &NavitClass)) |
1116 | if (!find_class_global("com/zoffcc/applications/zanavi/Navit", &NavitClass)) |
1067 | return NULL; |
1117 | return NULL; |
1068 | Navit_disableSuspend = (*jnienv)->GetMethodID(jnienv, NavitClass, "disableSuspend", "()V"); |
1118 | Navit_disableSuspend = (*jnienv)->GetMethodID(jnienv, NavitClass, "disableSuspend", "()V"); |
1069 | if (Navit_disableSuspend == NULL) |
1119 | if (Navit_disableSuspend == NULL) |
1070 | return NULL; |
1120 | return NULL; |
1071 | Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit", "()V"); |
1121 | Navit_exit = (*jnienv)->GetMethodID(jnienv, NavitClass, "exit2", "()V"); |
1072 | if (Navit_exit == NULL) |
1122 | if (Navit_exit == NULL) |
1073 | return NULL; |
1123 | return NULL; |
1074 | //DBG dbg(0,"ok\n"); |
1124 | //DBG dbg(0,"ok\n"); |
1075 | *meth = event_android_methods; |
1125 | *meth = event_android_methods; |
1076 | return NULL; |
1126 | return NULL; |