summaryrefslogtreecommitdiff
path: root/navit/android.c
diff options
context:
space:
mode:
authorzoff99 <zoff99@ffa7fe5e-494d-0410-b361-a75ebd5db220>2011-02-26 18:00:45 +0000
committerzoff99 <zoff99@ffa7fe5e-494d-0410-b361-a75ebd5db220>2011-02-26 18:00:45 +0000
commit8a43befa0a5399d3e1212d151627a9ab3411ea82 (patch)
tree7f8200bd99e84df0a66a98bad667b807fcd99550 /navit/android.c
parent26f741648a45ee47f4b3bca1c1341b1c69685ec0 (diff)
downloadnavit-8a43befa0a5399d3e1212d151627a9ab3411ea82.tar.gz
Add:Search:switch on search on arbitrary string (also ready for android java part)
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@4249 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/android.c')
-rw-r--r--navit/android.c317
1 files changed, 315 insertions, 2 deletions
diff --git a/navit/android.c b/navit/android.c
index 032d26f4d..fe7c9a41e 100644
--- a/navit/android.c
+++ b/navit/android.c
@@ -13,6 +13,9 @@
#include "projection.h"
#include "map.h"
#include "transform.h"
+#include "color.h"
+#include "types.h"
+#include "search.h"
JNIEnv *jnienv;
@@ -82,15 +85,191 @@ struct navit {
int border;
};
-struct navit *global_navit;
-
struct attr attr;
+
struct config {
struct attr **attrs;
struct callback_list *cbl;
} *config;
+struct gui_config_settings {
+ int dummy;
+};
+
+struct gui_internal_data {
+ int dummy;
+};
+
+struct route_data {
+ int dummy;
+};
+
+struct widget {
+ int dummy;
+};
+
+struct gui_priv {
+ struct navit *nav;
+ struct attr self;
+ struct window *win;
+ struct graphics *gra;
+ struct graphics_gc *background;
+ struct graphics_gc *background2;
+ struct graphics_gc *highlight_background;
+ struct graphics_gc *foreground;
+ struct graphics_gc *text_foreground;
+ struct graphics_gc *text_background;
+ struct color background_color, background2_color, text_foreground_color, text_background_color;
+ int spacing;
+ int font_size;
+ int fullscreen;
+ struct graphics_font *fonts[3];
+ /**
+ * The size (in pixels) that xs style icons should be scaled to.
+ * This icon size can be too small to click it on some devices.
+ */
+ int icon_xs;
+ /**
+ * The size (in pixels) that s style icons (small) should be scaled to
+ */
+ int icon_s;
+ /**
+ * The size (in pixels) that l style icons should be scaled to
+ */
+ int icon_l;
+ int pressed;
+ struct widget *widgets;
+ int widgets_count;
+ int redraw;
+ struct widget root;
+ struct widget *highlighted,*editable;
+ struct widget *highlighted_menu;
+ int clickp_valid, vehicle_valid;
+ struct pcoord clickp, vehiclep;
+ struct attr *click_coord_geo, *position_coord_geo;
+ struct search_list *sl;
+ int ignore_button;
+ int menu_on_map_click;
+ int signal_on_map_click;
+ char *country_iso2;
+ int speech;
+ int keyboard;
+ int keyboard_required;
+ /**
+ * The setting information read from the configuration file.
+ * values of -1 indicate no value was specified in the config file.
+ */
+ struct gui_config_settings config;
+ struct event_idle *idle;
+ struct callback *motion_cb,*button_cb,*resize_cb,*keypress_cb,*window_closed_cb,*idle_cb, *motion_timeout_callback;
+ struct event_timeout *motion_timeout_event;
+ struct point current;
+
+ struct callback * vehicle_cb;
+ /**
+ * Stores information about the route.
+ */
+ struct route_data route_data;
+
+ struct gui_internal_data data;
+ struct callback_list *cbl;
+ int flags;
+ int cols;
+ struct attr osd_configuration;
+ int pitch;
+ int flags_town,flags_street,flags_house_number;
+ int radius;
+/* html */
+ char *html_text;
+ int html_depth;
+ struct widget *html_container;
+ int html_skip;
+ char *html_anchor;
+ char *href;
+ int html_anchor_found;
+ struct form *form;
+ struct html {
+ int skip;
+ enum html_tag {
+ html_tag_none,
+ html_tag_a,
+ html_tag_h1,
+ html_tag_html,
+ html_tag_img,
+ html_tag_script,
+ html_tag_form,
+ html_tag_input,
+ html_tag_div,
+ } tag;
+ char *command;
+ char *name;
+ char *href;
+ char *refresh_cond;
+ struct widget *w;
+ struct widget *container;
+ } html[10];
+};
+
+
+
+
+static void
+gui_internal_search_list_set_default_country2(struct gui_priv *this)
+{
+ struct attr search_attr, country_name, country_iso2, *country_attr;
+ struct item *item;
+ struct country_search *cs;
+ struct tracking *tracking;
+ struct search_list_result *res;
+
+ dbg(0,"### 1");
+
+ country_attr=country_default();
+ tracking=navit_get_tracking(this->nav);
+
+ if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
+ country_attr=&search_attr;
+ if (country_attr) {
+ dbg(0,"### 2");
+ cs=country_search_new(country_attr, 0);
+ item=country_search_get_item(cs);
+ if (item && item_attr_get(item, attr_country_name, &country_name)) {
+ search_attr.type=attr_country_all;
+ dbg(0,"country %s\n", country_name.u.str);
+ search_attr.u.str=country_name.u.str;
+ search_list_search(this->sl, &search_attr, 0);
+ while((res=search_list_get_result(this->sl)));
+ if(this->country_iso2)
+ {
+ // this seems to cause a crash, no idea why
+ //g_free(this->country_iso2);
+ this->country_iso2=NULL;
+ }
+ if (item_attr_get(item, attr_country_iso2, &country_iso2))
+ {
+ this->country_iso2=g_strdup(country_iso2.u.str);
+ }
+ }
+ country_search_destroy(cs);
+ } else {
+ dbg(0,"warning: no default country found\n");
+ if (this->country_iso2) {
+ dbg(0,"attempting to use country '%s'\n",this->country_iso2);
+ search_attr.type=attr_country_iso2;
+ search_attr.u.str=this->country_iso2;
+ search_list_search(this->sl, &search_attr, 0);
+ while((res=search_list_get_result(this->sl)));
+ }
+ }
+ dbg(0,"### 99");
+}
+
+
+
+struct navit *global_navit;
+
+
int
android_find_class_global(char *name, jclass *ret)
{
@@ -255,6 +434,140 @@ Java_org_navitproject_navit_NavitSensors_SensorCallback( JNIEnv* env, jobject th
}
+JNIEXPORT void JNICALL
+Java_org_navitproject_navit_NavitGraphics_CallbackSearchResultList( JNIEnv* env, jobject thiz, int id, int partial, jobject str)
+{
+ const char *s;
+ s=(*env)->GetStringUTFChars(env, str, NULL);
+ dbg(0,"*****string=%s\n",s);
+
+
+ config_get_attr(config, attr_navit, &attr, NULL);
+ // attr.u.navit
+
+ jstring js2 = NULL;
+ jclass cls = (*env)->GetObjectClass(env,thiz);
+ jmethodID aMethodID = (*env)->GetMethodID(env, cls, "fillStringArray", "(Ljava/lang/String;)V");
+ if(aMethodID == 0)
+ {
+ dbg(0,"**** Unable to get methodID: fillStringArray");
+ return;
+ }
+
+ if (id)
+ {
+ // search for town in variable "s" within current country -> return a list of towns as result
+ if (id==1)
+ {
+ // try to search for a town in the current country
+ struct attr s_attr;
+ struct gui_priv *gp;
+ struct gui_priv gp_2;
+ gp=&gp_2;
+ gp->nav=global_navit;
+ struct mapset *ms=navit_get_mapset(gp->nav);
+ gp->sl=search_list_new(ms);
+
+ s_attr.type=attr_town_or_district_name;
+ // search for variable "s" as town name
+ s_attr.u.str=s;
+
+ gui_internal_search_list_set_default_country2(gp);
+
+ if (gp->sl)
+ {
+ search_list_select(gp->sl, attr_country_all, 0, 0);
+ search_list_search(gp->sl, &s_attr, partial);
+
+ struct search_list_result *res;
+ struct attr attr;
+ while((res=search_list_get_result(gp->sl)))
+ {
+ dbg(0,"**** aaa8");
+ if (item_attr_get(&res->town->itemt, attr_label, &attr))
+ {
+ dbg(0,"***search result C=%s T=%s",res->country->iso2,attr.u.str);
+ // return all the town names
+ js2 = (*env)->NewStringUTF(env,attr.u.str);
+ (*env)->CallVoidMethod(env, thiz, aMethodID, js2);
+ (*env)->DeleteLocalRef(env, js2);
+ }
+
+ //if (res->town->common.district_name)
+ //{
+ // dbg(0,"***444-ccc %s",res->town->common.district_name);
+ //}
+ }
+ }
+ g_free(gp->country_iso2);
+ gp->country_iso2=NULL;
+
+ if (gp->sl)
+ {
+ search_list_destroy(gp->sl);
+ gp->sl=NULL;
+ }
+ }
+ // search for street in variable "s" within current country -> return a list of streets as result
+ else if (id == 2)
+ {
+ struct attr s_attr4;
+ struct gui_priv *gp4;
+ struct gui_priv gp_24;
+ gp4=&gp_24;
+ gp4->nav=global_navit;
+ struct mapset *ms4=navit_get_mapset(gp4->nav);
+ GList *ret=NULL;
+ ret=search_by_address(ret,ms4,s,partial);
+ dbg(0,"ret=%p\n",ret);
+
+ struct search_list_result *res;
+
+ // get the list in the right order
+ ret=g_list_reverse(ret);
+ // set to first element
+ ret=g_list_first(ret);
+ // iterate thru the list
+ dbg(0,"ret=%p\n",ret);
+ while (ret)
+ {
+ res=ret->data;
+ dbg(0,"result list iterate %s\n",res->street->name);
+
+ // coords of result
+ struct coord_geo g;
+ struct coord c;
+ c.x=res->street->common.c->x;
+ c.y=res->street->common.c->y;
+ transform_to_geo(res->street->common.c->pro, &c, &g);
+ dbg(0,"g=%f %f\n",g.lat,g.lng);
+
+ // return all the results to java
+ const char *buffer;
+ // return a string like: "16.766:48.76:full address name is at the end"
+ sprintf(buffer,"%f:%f:%s",g.lat, g.lng, res->street->name);
+ js2 = (*env)->NewStringUTF(env, buffer);
+ (*env)->CallVoidMethod(env, thiz, aMethodID, js2);
+ (*env)->DeleteLocalRef(env, js2);
+
+ ret=g_list_next(ret);
+ }
+ // free the memory
+ g_list_free(ret);
+ dbg(0,"ret=%p\n",ret);
+
+ if (gp4->sl)
+ {
+ search_list_destroy(gp4->sl);
+ gp4->sl=NULL;
+ }
+ }
+ }
+
+ (*env)->ReleaseStringUTFChars(env, str, s);
+}
+
+
JNIEXPORT jstring JNICALL
Java_org_navitproject_navit_NavitGraphics_CallbackLocalizedString( JNIEnv* env, jobject thiz, jobject str)
{