/[zanavi_public1]/navit/navit/android.c
ZANavi

Diff of /navit/navit/android.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 49 Revision 50
56jmethodID return_generic_int; 56jmethodID return_generic_int;
57jmethodID send_generic_text; 57jmethodID send_generic_text;
58jclass NavitMapPreviewActivityClass = NULL; 58jclass NavitMapPreviewActivityClass = NULL;
59jmethodID DrawMapPreview_target; 59jmethodID DrawMapPreview_target;
60jmethodID DrawMapPreview_polyline = NULL; 60jmethodID DrawMapPreview_polyline = NULL;
61jmethodID DrawPreview_polyline = NULL;
61jmethodID DrawMapPreview_text = NULL; 62jmethodID DrawMapPreview_text = NULL;
62jmethodID NavitGraphics_send_osd_values2 = NULL; 63jmethodID NavitGraphics_send_osd_values2 = NULL;
63jmethodID NavitGraphics_set_vehicle_values2 = NULL; 64jmethodID NavitGraphics_set_vehicle_values2 = NULL;
64jmethodID NavitGraphics_set_vehicle_values3 = NULL; 65jmethodID NavitGraphics_set_vehicle_values3 = NULL;
65jmethodID NavitGraphics_send_route_rect_to_java = NULL; 66jmethodID NavitGraphics_send_route_rect_to_java = NULL;
292 struct widget *w; 293 struct widget *w;
293 struct widget *container; 294 struct widget *container;
294 } html[10]; 295 } html[10];
295}; 296};
296 297
298
299// copied from graphics_android.c !!!!!! (always keep in sync!!!)
300struct graphics_priv
301{
302 jclass NavitGraphicsClass;
303 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,
304 NavitGraphics_draw_bigmap, NavitGraphics_draw_image_warp, NavitGraphics_draw_mode, NavitGraphics_draw_drag, NavitGraphics_overlay_disable, NavitGraphics_overlay_resize, NavitGraphics_SetCamera, NavitGraphicsClass_rotate_and_scale_bitmap;
305
306 jclass PaintClass;
307 jmethodID Paint_init, Paint_setStrokeWidth, Paint_setARGB;
308
309 jobject NavitGraphics;
310 jobject Paint;
311
312 jclass BitmapFactoryClass;
313 jmethodID BitmapFactory_decodeFile, BitmapFactory_decodeResource;
314
315 jclass BitmapClass;
316 jmethodID Bitmap_getHeight, Bitmap_getWidth;
317
318 jclass ContextClass;
319 jmethodID Context_getResources;
320
321 jclass ResourcesClass;
322 jobject Resources;
323 jmethodID Resources_getIdentifier;
324
325};
326
327// copied from graphics.c !!!!!! (always keep in sync!!!)
328struct graphics
329{
330 struct graphics_priv *priv;
331};
332
333
297// ------------------------- COPIED STUFF --- this is generally bad ------------------ 334// ------------------------- COPIED STUFF --- this is generally bad ------------------
298// ------------------------- COPIED STUFF --- this is generally bad ------------------ 335// ------------------------- COPIED STUFF --- this is generally bad ------------------
299// ------------------------- COPIED STUFF --- this is generally bad ------------------ 336// ------------------------- COPIED STUFF --- this is generally bad ------------------
300 337
301 338
1048 // dbg(0, "THREAD ID=%d\n", thread_id); 1085 // dbg(0, "THREAD ID=%d\n", thread_id);
1049 1086
1050 JNIEnv *jnienv2; 1087 JNIEnv *jnienv2;
1051 jnienv2 = jni_getenv(); 1088 jnienv2 = jni_getenv();
1052 1089
1090
1053 if (NavitGraphicsClass2 == NULL) 1091 if (NavitGraphicsClass2 == NULL)
1054 { 1092 {
1055 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2)) 1093 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
1056 { 1094 {
1057 NavitGraphicsClass2 = NULL; 1095 NavitGraphicsClass2 = NULL;
1135 (*env)->ReleaseStringUTFChars(env, str_town, s_town); 1173 (*env)->ReleaseStringUTFChars(env, str_town, s_town);
1136 (*env)->ReleaseStringUTFChars(env, str_hn, s_hn); 1174 (*env)->ReleaseStringUTFChars(env, str_hn, s_hn);
1137 1175
1138 } 1176 }
1139 // search for street in variable "s" within "search_country" -> return a list of streets as result 1177 // search for street in variable "s" within "search_country" -> return a list of streets as result
1178 // ------- normal search ----------
1179 // ------- normal search ----------
1180 // ------- normal search ----------
1181 // ------- normal search ----------
1182 // ------- normal search ----------
1183 // ------- normal search ----------
1140 else if (id == 29) 1184 else if (id == 29)
1141 { 1185 {
1142 //struct attr s_attr4; 1186 //struct attr s_attr4;
1143 //struct gui_priv *gp4; 1187 //struct gui_priv *gp4;
1144 //struct gui_priv gp_24; 1188 //struct gui_priv gp_24;
1305 // **OLD and wrong** android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, dx*0x10000/l, dy*0x10000/l); 1349 // **OLD and wrong** android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, dx*0x10000/l, dy*0x10000/l);
1306 android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, (int) dx, (int) dy); 1350 android_DrawMapPreview_text(p_t.x, p_t.y, label, font_size, (int) dx, (int) dy);
1307 } 1351 }
1308 } 1352 }
1309} 1353}
1354
1355
1356
1357JNIEXPORT void JNICALL
1358Java_com_zoffcc_applications_zanavi_NavitGraphics_DrawLowqualMap(JNIEnv* env, jobject thiz, jobject latlonzoom, int width, int height, int font_size, int scale, int sel_range)
1359{
1360#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1361 dbg(0,"+#+:enter\n");
1362#endif
1363 // config_get_attr(config, attr_navit, &attr, NULL);
1364
1365 const char *s;
1366 int zoom;
1367 s = (*env)->GetStringUTFChars(env, latlonzoom, NULL);
1368 char parse_str[strlen(s) + 1];
1369 strcpy(parse_str, s);
1370 (*env)->ReleaseStringUTFChars(env, latlonzoom, s);
1371 ////DBG // dbg(0,"*****string=%s\n",s);
1372
1373 // show map preview for (lat#lon#zoom)
1374 struct coord_geo g;
1375 char *p;
1376 char *stopstring;
1377
1378 // lat
1379 p = strtok(parse_str, "#");
1380 g.lat = strtof(p, &stopstring);
1381 // lon
1382 p = strtok(NULL, "#");
1383 g.lng = strtof(p, &stopstring);
1384 // zoom
1385 p = strtok(NULL, "#");
1386 zoom = atoi(p);
1387
1388 ////DBG // dbg(0,"lat=%f\n",g.lat);
1389 ////DBG // dbg(0,"lng=%f\n",g.lng);
1390 ////DBG // dbg(0,"zoom=%d\n",zoom);
1391 ////DBG // dbg(0,"w=%d\n",width);
1392 ////DBG // dbg(0,"h=%d\n",height);
1393
1394 struct coord c;
1395 transform_from_geo(projection_mg, &g, &c);
1396
1397 // struct pcoord pc;
1398 // pc.x=c.x;
1399 // pc.y=c.y;
1400 // pc.pro=projection_mg;
1401
1402
1403 // ----------------------- big draw loop -----------------------
1404 // ----------------------- big draw loop -----------------------
1405 // ----------------------- big draw loop -----------------------
1406 // ----------------------- big draw loop -----------------------
1407 struct item *item;
1408 struct map_rect *mr = NULL;
1409 struct mapset *ms;
1410 struct mapset_handle *msh;
1411 struct map* map = NULL;
1412 struct attr map_name_attr;
1413 struct attr attr;
1414
1415 struct map_selection sel;
1416 const int selection_range = sel_range; // should be something with "width" and "height" i guess ??!!
1417
1418 const int max = 100;
1419 int count;
1420 struct coord *ca = g_alloca(sizeof(struct coord) * max);
1421 struct point *pa = g_alloca(sizeof(struct point) * max);
1422
1423 sel.next = NULL;
1424 sel.order = zoom;
1425 sel.range.min = type_none;
1426 sel.range.max = type_last;
1427 sel.u.c_rect.lu.x = c.x - selection_range;
1428 sel.u.c_rect.lu.y = c.y + selection_range;
1429 sel.u.c_rect.rl.x = c.x + selection_range;
1430 sel.u.c_rect.rl.y = c.y - selection_range;
1431
1432 struct transformation *tr;
1433 tr = transform_dup(global_navit->trans);
1434 struct point p_center;
1435 p_center.x = width / 2;
1436 p_center.y = height / 2;
1437 transform_set_screen_center(tr, &p_center);
1438 transform_set_center(tr, &c);
1439 transform_set_scale(tr, scale);
1440 enum projection pro = transform_get_projection(global_navit->trans_cursor);
1441
1442 // reset cancel flag
1443 global_cancel_preview_map_drawing = 0;
1444
1445 ms = global_navit->mapsets->data;
1446 msh = mapset_open(ms);
1447 while (msh && (map = mapset_next(msh, 0)))
1448 {
1449 if (map_get_attr(map, attr_name, &map_name_attr, NULL))
1450 {
1451 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
1452 {
1453 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0)
1454 {
1455 // its an sdcard map
1456 mr = map_rect_new(map, &sel);
1457 if (mr)
1458 {
1459 while ((item = map_rect_get_item(mr)))
1460 {
1461
1462 if (global_cancel_preview_map_drawing == 1)
1463 {
1464 dbg(0, "global_cancel_preview_map_drawing = 1");
1465 break;
1466 }
1467
1468 count = item_coord_get_within_selection(item, ca, max, &sel);
1469
1470 if (!count)
1471 {
1472 continue;
1473 }
1474
1475 struct attr attr_77;
1476 if (item_attr_get(item, attr_flags, &attr_77))
1477 {
1478 item->flags = attr_77.u.num;
1479 }
1480 else
1481 {
1482 item->flags = 0;
1483 }
1484
1485 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
1486
1487 if (item_is_street(*item))
1488 {
1489 android_DrawPreview_polyline(pa, count, 0, item_to_name(item->type));
1490 }
1491
1492 }
1493 map_rect_destroy(mr);
1494 }
1495 }
1496 }
1497 }
1498 }
1499 mapset_close(msh);
1500
1501// ===============================================
1502
1503 if (global_cancel_preview_map_drawing == 1)
1504 {
1505 dbg(0, "global_cancel_preview_map_drawing = 1");
1506 return;
1507 }
1508
1509
1510// ===============================================
1511
1512
1513 msh = mapset_open(ms);
1514 while (msh && (map = mapset_next(msh, 0)))
1515 {
1516 if (map_get_attr(map, attr_name, &map_name_attr, NULL))
1517 {
1518 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
1519 {
1520 if (strncmp("_ms_sdcard_map:/sdcard/zanavi/maps/navitmap", map_name_attr.u.str, 38) == 0)
1521 {
1522 // its an sdcard map
1523 mr = map_rect_new(map, &sel);
1524 if (mr)
1525 {
1526 while ((item = map_rect_get_item(mr)))
1527 {
1528
1529 if (global_cancel_preview_map_drawing == 1)
1530 {
1531 dbg(0, "global_cancel_preview_map_drawing = 1");
1532 break;
1533 }
1534
1535 count = item_coord_get_within_selection(item, ca, max, &sel);
1536
1537 if (!count)
1538 {
1539 continue;
1540 }
1541
1542 struct attr attr_77;
1543 if (item_attr_get(item, attr_flags, &attr_77))
1544 {
1545 item->flags = attr_77.u.num;
1546 }
1547 else
1548 {
1549 item->flags = 0;
1550 }
1551
1552 count = transform(tr, pro, ca, pa, count, 0, 0, NULL);
1553
1554 if (item_type_is_area(item->type))
1555 {
1556 android_DrawPreview_polyline(pa, count, 0, item_to_name(item->type));
1557 }
1558
1559 }
1560 map_rect_destroy(mr);
1561 }
1562 }
1563 }
1564 }
1565 }
1566 mapset_close(msh);
1567
1568
1569
1570
1571
1572
1573/*
1574 enum projection pro2 = transform_get_projection(global_navit->trans_cursor);
1575 struct point pnt;
1576 transform(tr, pro2, &c, &pnt, 1, 0, 0, NULL);
1577 transform_destroy(tr);
1578
1579*/
1580}
1581
1582
1583
1584
1585
1586
1587
1588
1310 1589
1311JNIEXPORT void JNICALL 1590JNIEXPORT void JNICALL
1312Java_com_zoffcc_applications_zanavi_NavitMapPreviewActivity_DrawMapPreview(JNIEnv* env, jobject thiz, jobject latlonzoom, int width, int height, int font_size, int scale, int sel_range) 1591Java_com_zoffcc_applications_zanavi_NavitMapPreviewActivity_DrawMapPreview(JNIEnv* env, jobject thiz, jobject latlonzoom, int width, int height, int font_size, int scale, int sel_range)
1313{ 1592{
1314#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT 1593#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1690 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_polyline, type, points); 1969 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitMapPreviewActivityClass, DrawMapPreview_polyline, type, points);
1691 (*jnienv2)->DeleteLocalRef(jnienv2, points); 1970 (*jnienv2)->DeleteLocalRef(jnienv2, points);
1692} 1971}
1693 1972
1694 1973
1974void android_DrawPreview_polyline(struct point *p, int count, int type, const char* item_type)
1975{
1976#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1977 dbg(0,"+#+:enter\n");
1978#endif
1979 // type:
1980 // 0 -> normal street
1981 // 2 -> country border
1982
1983 JNIEnv *jnienv2;
1984 jnienv2 = jni_getenv();
1985
1986
1987 if (NavitGraphicsClass2 == NULL)
1988 {
1989 if (!android_find_class_global("com/zoffcc/applications/zanavi/NavitGraphics", &NavitGraphicsClass2))
1990 {
1991 NavitGraphicsClass2 = NULL;
1992 return;
1993 }
1994 }
1995
1996
1997 if (DrawPreview_polyline == NULL)
1998 {
1999 android_find_static_method(NavitGraphicsClass2, "DrawPreview_polyline", "(I[ILjava/lang/String;)V", &DrawPreview_polyline);
2000 }
2001
2002 if (DrawPreview_polyline == NULL)
2003 {
2004 //DBG // dbg(0, "no method found\n");
2005 return; /* exception thrown */
2006 }
2007
2008 jint pc[count * 2];
2009 int i;
2010 jintArray points;
2011 if (count <= 0)
2012 {
2013 return;
2014 }
2015
2016 if (global_cancel_preview_map_drawing == 1)
2017 {
2018 return;
2019 }
2020
2021
2022 points = (*jnienv2)->NewIntArray(jnienv2, count * 2);
2023
2024 for (i = 0; i < count; i++)
2025 {
2026 pc[i * 2] = p[i].x;
2027 pc[i * 2 + 1] = p[i].y;
2028 }
2029
2030 jstring string1;
2031 if (item_type)
2032 {
2033 string1 = (*jnienv2)->NewStringUTF(jnienv2, item_type);
2034 }
2035 else
2036 {
2037 string1 = (*jnienv2)->NewStringUTF(jnienv2, "xx__unknown__xx");
2038 }
2039
2040 (*jnienv2)->SetIntArrayRegion(jnienv2, points, 0, count * 2, pc);
2041 (*jnienv2)->CallStaticVoidMethod(jnienv2, NavitGraphicsClass2, DrawPreview_polyline, type, points, string1);
2042 (*jnienv2)->DeleteLocalRef(jnienv2, points);
2043 (*jnienv2)->DeleteLocalRef(jnienv2, string1);
2044}
2045
2046
1695JNIEXPORT jobjectArray JNICALL 2047JNIEXPORT jobjectArray JNICALL
1696Java_com_zoffcc_applications_zanavi_NavitGraphics_GetRoadBookItems(JNIEnv *env, jobject thiz, int result_id) 2048Java_com_zoffcc_applications_zanavi_NavitGraphics_GetRoadBookItems(JNIEnv *env, jobject thiz, int result_id)
1697{ 2049{
1698 jobjectArray ret; 2050 jobjectArray ret;
1699 int i; 2051 int i;
1705 if (result == NULL) 2057 if (result == NULL)
1706 { 2058 {
1707 return NULL; 2059 return NULL;
1708 } 2060 }
1709 2061
2062
2063 jstring string77 = (*env)->NewStringUTF(env, "");
1710 ret = (jobjectArray)(*env)->NewObjectArray(env, g_list_length(result), string_class, (*env)->NewStringUTF(env, "")); 2064 ret = (jobjectArray)(*env)->NewObjectArray(env, g_list_length(result), string_class, string77);
2065 (*env)->DeleteLocalRef(env, string77);
2066
2067
2068 jstring string88 = (*env)->NewStringUTF(env, "");
1711 2069
1712 GList *result2 = result; 2070 GList *result2 = result;
1713 i = 0; 2071 i = 0;
1714 while (result2) 2072 while (result2)
1715 { 2073 {
1716 char *str = result2->data; 2074 char *str = result2->data;
1717 2075
1718 if (str != NULL) 2076 if (str != NULL)
1719 { 2077 {
2078 jstring string99 = (*env)->NewStringUTF(env, str);
1720 (*env)->SetObjectArrayElement(env, ret, i, (*env)->NewStringUTF(env, str)); 2079 (*env)->SetObjectArrayElement(env, ret, i, string99);
2080 (*env)->DeleteLocalRef(env, string99);
1721 g_free(str); 2081 g_free(str);
1722 } 2082 }
1723 else 2083 else
1724 { 2084 {
1725 (*env)->SetObjectArrayElement(env, ret, i, (*env)->NewStringUTF(env, "")); 2085 (*env)->SetObjectArrayElement(env, ret, i, string88);
1726 } 2086 }
1727 i++; 2087 i++;
1728 2088
1729 result2 = g_list_next(result2); 2089 result2 = g_list_next(result2);
1730 } 2090 }
1731 2091
1732 g_list_free(result); 2092 g_list_free(result);
2093
2094 (*env)->DeleteLocalRef(env, string88);
1733 2095
1734 return(ret); 2096 return(ret);
1735 } 2097 }
1736 2098
1737 2099
2231 { 2593 {
2232 // zoom out 2594 // zoom out
2233 navit_zoom_out_cursor(global_navit, 2); 2595 navit_zoom_out_cursor(global_navit, 2);
2234 // navit_zoom_out_cursor(attr.u.navit, 2); 2596 // navit_zoom_out_cursor(attr.u.navit, 2);
2235 } 2597 }
2598 else if (i == 113)
2599 {
2600 // cancel preview map drawing
2601 global_cancel_preview_map_drawing = 1;
2602 }
2236 else if (i == 112) 2603 else if (i == 112)
2237 { 2604 {
2238 // show maps debug view 2605 // show maps debug view (show maps on lower zoom levels)
2239 s = (*env)->GetStringUTFChars(env, str, NULL); 2606 s = (*env)->GetStringUTFChars(env, str, NULL);
2240 global_show_maps_debug_view = atoi(s); 2607 global_show_maps_debug_view = atoi(s);
2241 (*env)->ReleaseStringUTFChars(env, str, s); 2608 (*env)->ReleaseStringUTFChars(env, str, s);
2242 } 2609 }
2243 else if (i == 111) 2610 else if (i == 111)

Legend:
Removed from v.49  
changed lines
  Added in v.50

   
Visit the ZANavi Wiki