Fix:Android:Googlenavigation support now really works fine, and small cleanups
authorzoff99 <zoff99@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 22 Jan 2011 09:26:09 +0000 (09:26 +0000)
committerzoff99 <zoff99@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 22 Jan 2011 09:26:09 +0000 (09:26 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3945 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/android.c
navit/navit/android/src/org/navitproject/navit/Navit.java
navit/navit/android/src/org/navitproject/navit/NavitGraphics.java
navit/navit/navit.c

index bd2064e..82d4ca6 100644 (file)
@@ -1,16 +1,30 @@
 #include <string.h>
 #include <poll.h>
+#include <glib.h>
+#include <stdlib.h>
 #include "android.h"
 #include <android/log.h>
 #include "debug.h"
 #include "event.h"
 #include "callback.h"
+#include "projection.h"
+#include "map.h"
+
 
 JNIEnv *jnienv;
 jobject *android_activity;
 struct callback_list *android_activity_cbl;
 int android_version;
 
+struct navit *global_navit;
+
+struct attr attr;
+struct config {
+        struct attr **attrs;
+        struct callback_list *cbl;
+} *config;
+
+
 int
 android_find_class_global(char *name, jclass *ret)
 {
@@ -173,20 +187,66 @@ Java_org_navitproject_navit_NavitGraphics_CallbackMessageChannel( JNIEnv* env, j
 {
        char *s;
        dbg(0,"enter %p %p\n",(struct callback *)i,str);
-       s=(*env)->GetStringUTFChars(env, str, NULL);
-       dbg(0,"string=%s\n",s);
+
+       config_get_attr(config, attr_navit, &attr, NULL);
+       // attr.u.navit
+
        if (i)
        {
                if (i == 1)
                {
                        // zoom in
-                       navit_cmd_zoom_in_void();
+                       navit_zoom_in_cursor(global_navit, 2);
+                       // navit_zoom_in_cursor(attr.u.navit, 2);
                }
-               if (i == 2)
+               else if (i == 2)
                {
                        // zoom out
-                       navit_cmd_zoom_out_void();
+                       navit_zoom_out_cursor(global_navit, 2);
+                       // navit_zoom_out_cursor(attr.u.navit, 2);
+               }
+               else if (i == 3)
+               {
+                       s=(*env)->GetStringUTFChars(env, str, NULL);
+                       dbg(0,"*****string=%s\n",s);
+
+                       // set destination to (lat#lon#title)
+                       struct coord_geo g;
+                       char *p;
+                       char name[strlen(s)];
+                       char *stopstring;
+
+                       // lat
+                       p = strtok (s,"#");
+                       g.lat = strtof(p, &stopstring);
+                       // lon
+                       p = strtok (NULL, "#");
+                       g.lng = strtof(p, &stopstring);
+                       // description
+                       *name = strtok (NULL, "#");
+
+                       dbg(0,"lat=%f\n",g.lat);
+                       dbg(0,"lng=%f\n",g.lng);
+                       dbg(0,"str1=%s\n",name);
+
+                       struct coord c;
+                       transform_from_geo(projection_mg, &g, &c);
+
+                       struct pcoord pc;
+                       pc.x=c.x;
+                       pc.y=c.y;
+                       pc.pro=projection_mg;
+
+                       dbg(0,"c x=%f\n",c.x);
+                       dbg(0,"c y=%f\n",c.y);
+
+                       dbg(0,"pc x=%f\n",pc.x);
+                       dbg(0,"pc y=%f\n",pc.y);
+
+                       // start navigation asynchronous
+                       navit_set_destination(global_navit, &pc, &name, 1);
+
+                       (*env)->ReleaseStringUTFChars(env, str, s);
                }
        }
-       (*env)->ReleaseStringUTFChars(env, str, s);
 }
index 8cf7c0c..25c29f5 100644 (file)
@@ -149,8 +149,8 @@ public class Navit extends Activity implements Handler.Callback
                super.onCreate(savedInstanceState);\r
                \r
                Intent startup_intent=this.getIntent();\r
-               Log.e("Navit","****A "+startup_intent.getAction());\r
-               Log.e("Navit","****D "+startup_intent.getDataString());\r
+               Log.e("Navit","**1**A "+startup_intent.getAction());\r
+               Log.e("Navit","**1**D "+startup_intent.getDataString());\r
                \r
                ActivityResults = new NavitActivityResult[16];\r
                setVolumeControlStream(AudioManager.STREAM_MUSIC);\r
@@ -212,6 +212,65 @@ public class Navit extends Activity implements Handler.Callback
                Log.e("Navit", "OnResume");\r
                //InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);\r
                NavitActivity(1);\r
+\r
+               Intent startup_intent=this.getIntent();\r
+               Log.e("Navit","**2**A "+startup_intent.getAction());\r
+               Log.e("Navit","**2**D "+startup_intent.getDataString());\r
+\r
+               String intent_data=startup_intent.getDataString();\r
+               if (intent_data != null)\r
+               {\r
+                       // a: google.navigation:ll=48.25676,16.643&q=blabla-strasse\r
+                       // b: google.navigation:q=48.25676,16.643\r
+                       String lat;\r
+                       String lon;\r
+                       String q;\r
+\r
+                       String temp1=null;\r
+                       String temp2=null;\r
+                       String temp3=null;\r
+\r
+                       // if b: then remodel the input string\r
+                       if (intent_data.substring(0,20).equals("google.navigation:q="))\r
+                       {\r
+                               intent_data="ll="+intent_data.split("q=",-1)[1]+"&q=Target";\r
+                       }\r
+\r
+\r
+                       // now split the parts off\r
+                       temp1=intent_data.split("&q=",-1)[0];\r
+                       try\r
+                       {\r
+                               temp3=temp1.split("ll=",-1)[1];\r
+                               temp2=intent_data.split("&q=",-1)[1];\r
+                       }\r
+                       catch (Exception e)\r
+                       {\r
+                               // java.lang.ArrayIndexOutOfBoundsException most likely\r
+                               // so let's assume we dont have '&q=xxxx'\r
+                               temp3=temp1;\r
+                       }\r
+\r
+                       if (temp2 == null)\r
+                       {\r
+                               // use some default name\r
+                               temp2 = "Target";\r
+                       }\r
+\r
+                       lat=temp3.split(",",-1)[0];\r
+                       lon=temp3.split(",",-1)[1];\r
+                       q=temp2;\r
+\r
+                       Message msg = new Message();\r
+                       Bundle b = new Bundle();\r
+                       b.putInt("Callback", 3);\r
+                       b.putString("lat", lat);\r
+                       b.putString("lon", lon);\r
+                       b.putString("q", q);\r
+                       msg.setData(b);\r
+                       N_NavitGraphics.callback_handler.sendMessage(msg);\r
+               }\r
+\r
        }\r
        @Override\r
        public void onPause()\r
index 65a5e30..dadf9e7 100644 (file)
@@ -848,7 +848,14 @@ public class NavitGraphics
         {
                 CallbackMessageChannel(2,"");
         }
+        else if (msg.getData().getInt("Callback") == 3)
 
+        {
+               String lat=msg.getData().getString("lat");
+               String lon=msg.getData().getString("lon");
+               String q=msg.getData().getString("q");
+                CallbackMessageChannel(3,lat+"#"+lon+"#"+q);
+        }
                                                                                                                        else if (msg.getData().getInt("Callback") == 21)
                                                                                                                        {
                                                                                                                                //Log.e("NavitGraphics","callback_handler -> handleMessage 2");
index 9176651..5ab4950 100644 (file)
@@ -697,17 +697,6 @@ navit_zoom_out_cursor(struct navit *this_, int factor)
                navit_zoom_out(this_, 2, NULL);
 }
 
-// zoom without args
-int navit_cmd_zoom_in_void()
-{
-       navit_zoom_in_cursor(global_navit, 2);
-}
-
-int navit_cmd_zoom_out_void()
-{
-       navit_zoom_out_cursor(global_navit, 2);
-}
-
 static int
 navit_cmd_zoom_in(struct navit *this_)
 {
@@ -1086,6 +1075,10 @@ navit_set_destination(struct navit *this_, struct pcoord *c, const char *descrip
        if (c) {
                this_->destination=*c;
                this_->destination_valid=1;
+
+           dbg(1, "navit->navit_set_destination %i\n", c->x);
+           dbg(1, "navit->navit_set_destination %i\n", c->y);
+
        } else
                this_->destination_valid=0;
        char *destination_file = bookmarks_get_destination_file(TRUE);