diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index 1d55cc9..3f81ee4 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -9,11 +9,11 @@
-
+
-
@@ -26,6 +26,8 @@
+
+
diff --git a/android/jni/main.c b/android/jni/main.c
index e97b302..6c1feb9 100644
--- a/android/jni/main.c
+++ b/android/jni/main.c
@@ -17,10 +17,8 @@
#include
#include
-
#include
#include
-
#include
#include
#include
@@ -303,6 +301,9 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
* event loop for receiving input events and doing other things.
*/
void android_main(struct android_app* state) {
+ time_t t1 = time(NULL), t2 = time(NULL);
+ struct gps_data *gpspos;
+
// Make sure glue isn't stripped.
app_dummy();
@@ -340,8 +341,7 @@ void android_main(struct android_app* state) {
// If not animating, we will block forever waiting for events.
// If animating, we loop until all events are read, then continue
// to draw the next frame of animation.
- while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
- (void**)&source)) >= 0) {
+ while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) {
// Process this event.
if (source != NULL) {
@@ -367,18 +367,14 @@ void android_main(struct android_app* state) {
return;
}
}
-
- if (engine.animating) {
- // Done with events; draw next animation frame.
- engine.state.angle += .01f;
- if (engine.state.angle > 1) {
- engine.state.angle = 0;
- }
-
- // Drawing is throttled to the screen update rate, so there
- // is no need to do timing here.
- draw();
- // test_draw ();
+ t1 = time(NULL);
+ if (t1 != t2) {
+ t2 = t1;
+ if (gps_isrunning () > 0) {
+ if ((gpspos = gps_loop ())) {
+ drawgps_set_pos (gpspos);
+ }
+ }
}
}
}
@@ -394,3 +390,88 @@ void main_wnd_loop (long long int cur, long long int max) {
void main_wnd_update () {
}
+
+
+/*************************************************************************
+ *
+ * calling java code here for using the internal GPS devices.
+ *
+ *************************************************************************/
+
+int gps_android_device_open () {
+ d_printf ("gps_android_device_open:");
+ ANativeActivity* activity = engine.app->activity;
+ JavaVM* jvm = engine.app->activity->vm;
+ JNIEnv* env = NULL;
+ (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6);
+ jint res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);
+ if (res == JNI_ERR) {
+ // Failed to retrieve JVM environment
+ d_printf ("gps_android_device_open: JNI_Error");
+ return 0;
+ }
+ jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
+ jmethodID methodID = (*env)->GetMethodID(env, clazz, "GPSDataStart", "()V");
+ (*env)->CallVoidMethod(env, activity->clazz, methodID);
+ (*jvm)->DetachCurrentThread(jvm);
+ return 1;
+};
+
+void gps_android_device_close () {
+ ANativeActivity* activity = engine.app->activity;
+ JavaVM* jvm = engine.app->activity->vm;
+ JNIEnv* env = NULL;
+ (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6);
+ jint res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);
+ if (res == JNI_ERR) {
+ // Failed to retrieve JVM environment
+ d_printf ("gps_android_device_close: JNI_Error");
+ return;
+ }
+
+ jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
+ jmethodID methodID = (*env)->GetMethodID(env, clazz, "GPSDataStop", "()V");
+ (*env)->CallVoidMethod(env, activity->clazz, methodID);
+ (*jvm)->DetachCurrentThread(jvm);
+ return;
+};
+
+int gps_android_device_read (char *ptr, int ptrsize) {
+ ANativeActivity* activity = engine.app->activity;
+ JavaVM* jvm = engine.app->activity->vm;
+ JNIEnv* env = NULL;
+ jstring jstr;
+ const char *str;
+
+ (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6);
+ jint res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);
+ if (res == JNI_ERR) {
+ // Failed to retrieve JVM environment
+ d_printf ("gps_android_device_read: JNI_Error");
+ return 0;
+ }
+
+ d_printf ("gps_android_device_read:");
+
+ jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
+ jmethodID methodID = (*env)->GetMethodID(env, clazz, "GPSDataGetLine", "()V");
+ (*env)->CallVoidMethod(env, activity->clazz, methodID);
+
+ d_printf ("try to get line");
+ jfieldID fid = (*env)->GetFieldID(env, clazz, "gpsline", "Ljava/lang/String;");
+ jobject obj = (*env)->AllocObject(env, clazz);
+ if (!obj) {
+ d_printf ("error getting obj");
+ exit (1);
+ }
+
+ jstr = (*env)->GetObjectField(env, obj, fid);
+ str = (*env)->GetStringUTFChars(env, jstr, 0);
+ d_printf(" c.s = \"%s\"\n", str);
+ (*env)->ReleaseStringUTFChars(env, jstr, str);
+ d_printf ("release string");
+
+ (*jvm)->DetachCurrentThread(jvm);
+
+ return -1;
+};
diff --git a/android/src/de/gulpe/sposmroute/spOSMrNActivity.java b/android/src/de/gulpe/sposmroute/spOSMrNActivity.java
new file mode 100644
index 0000000..5d54a04
--- /dev/null
+++ b/android/src/de/gulpe/sposmroute/spOSMrNActivity.java
@@ -0,0 +1,43 @@
+package de.gulpe.sposmroute;
+
+import android.app.NativeActivity;
+
+import android.os.Bundle;
+import android.util.Log;
+
+
+public class spOSMrNActivity extends NativeActivity {
+ private static final String TAG = "spOSMroute Java";
+ spOSMrNActivity _activity;
+ String gpsline;
+ int i = 0;
+
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // Make your custom init here
+ _activity = this;
+ }
+
+ // get gps data fill one line into gpsline
+ public void GPSDataGetLine() {
+ i++;
+ gpsline = "Number: " + i;
+ Log.i(TAG, "GPSDataGetLine called");
+ }
+
+ // start gps part
+ public void GPSDataStart() {
+ Log.i(TAG, "GPSDataStart called");
+ }
+
+ // stop gps part
+ public void GPSDataStop() {
+ Log.i(TAG, "GPSDataStop called");
+ }
+
+ // Do some cleanup
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+}
diff --git a/draw/draw.c b/draw/draw.c
index 2b7ed7f..5b2dc0c 100644
--- a/draw/draw.c
+++ b/draw/draw.c
@@ -790,6 +790,7 @@ int draw_mapcopy () {
void draw () {
static int still_drawing = 0;
+ d_printf ("draw()");
/* only run once at the time.. */
if (still_drawing) return;
still_drawing = 1;
diff --git a/gui/gui_entry.c b/gui/gui_entry.c
index 401f53c..59ef2e1 100644
--- a/gui/gui_entry.c
+++ b/gui/gui_entry.c
@@ -1,4 +1,4 @@
-/* $Id: gui_entry.c,v 1.13 2013/03/11 23:08:39 steffen Exp $ */
+/* $Id: gui_entry.c,v 1.14 2013/03/24 00:38:50 steffen Exp $ */
/***************************************************************************
* gui_entry.c
*
@@ -117,6 +117,7 @@ int gui_entry_event (GUIItem *item, GUIEvent *event) {
}
}
currentwin->screen_changed = 1;
+ draw ();
return 1;
};
diff --git a/gui/gui_list.c b/gui/gui_list.c
index 1da1e84..a7f3ef3 100644
--- a/gui/gui_list.c
+++ b/gui/gui_list.c
@@ -1,4 +1,4 @@
-/* $Id: gui_list.c,v 1.8 2013/03/11 23:08:39 steffen Exp $ */
+/* $Id: gui_list.c,v 1.9 2013/03/24 00:38:50 steffen Exp $ */
/***************************************************************************
* gui_list.c
*
@@ -85,22 +85,26 @@ int gui_list_event (GUIItem *item, GUIEvent *event) {
int y = event->mousepos.y - item->y;
int i;
GUIList *list = NULL;
+ static GUIItem *olditem = NULL;
if (item == NULL) return 0;
else list = (GUIList *) item->data;
/* set focus */
- if (event->event == EGUI_MOUSERELEASED) {
- gui_set_focus (item);
-
- if (y <= 5 && x >= item->w - 10) list->vs--;
- else if (y >= item->h - 5 && x >= item->w - 10) list->vs++;
- else { /* select entry */
- i = (y-5)/16 + list->vs;
- list->selected = i;
- if (list->callback_selectitem) list->callback_selectitem (i);
- }
+ if (event->event == EGUI_MOUSEPRESSED) {
+ olditem = item;
+ }
+ else if (event->event == EGUI_MOUSERELEASED && olditem == item) {
+ gui_set_focus (item);
+
+ if (y <= 5 && x >= item->w - 10) list->vs--;
+ else if (y >= item->h - 5 && x >= item->w - 10) list->vs++;
+ else { /* select entry */
+ i = (y-5)/16 + list->vs;
+ list->selected = i;
+ if (list->callback_selectitem) list->callback_selectitem (i);
}
+ }
currentwin->screen_changed = 1;
draw ();
diff --git a/gui/gui_softkeyboard.c b/gui/gui_softkeyboard.c
index 82a348a..caa2a55 100644
--- a/gui/gui_softkeyboard.c
+++ b/gui/gui_softkeyboard.c
@@ -1,4 +1,4 @@
-/* $Id: gui_softkeyboard.c,v 1.4 2013/03/10 23:32:28 steffen Exp $ */
+/* $Id: gui_softkeyboard.c,v 1.5 2013/03/24 00:38:50 steffen Exp $ */
/***************************************************************************
* gui_softkeyboard.c
*
@@ -182,6 +182,8 @@ int gui_softkeyb_event (GUIEvent event) {
softkeyb->last_line = -1;
softkeyb->last_col = -1;
}
+ currentwin->screen_changed = 1;
+ draw ();
return 1;
}
}
diff --git a/main/gps.c b/main/gps.c
index 3579b13..99a7d50 100644
--- a/main/gps.c
+++ b/main/gps.c
@@ -47,9 +47,13 @@ struct gps_data gpspos;
struct gps_data gpsposvalid;
#if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) && !defined(__MINGW32__)
-char gpsdevice[GPS_DEVICELEN] = "serial:/dev/rfcomm0";
+ #if defined ANDROID
+ char gpsdevice[GPS_DEVICELEN] = "android:";
+ #else
+ char gpsdevice[GPS_DEVICELEN] = "serial:/dev/rfcomm0";
+ #endif
#else
-char gpsdevice[GPS_DEVICELEN] = "serial:com1,38400";
+ char gpsdevice[GPS_DEVICELEN] = "serial:com1,38400";
#endif
int gpsflags = GPSF_LOG;
@@ -387,6 +391,7 @@ float gps_getlat (char *text) {
int gps_get_devicetype () {
if (strncmp (gpsdevice, "serial:", 7) == 0) return GPS_T_SERIAL;
else if (strncmp (gpsdevice, "file:", 5) == 0) return GPS_T_FILE;
+ else if (strncmp (gpsdevice, "android:", 8) == 0) return GPS_T_ANDROID;
else return GPS_T_NONE;
};
@@ -433,6 +438,9 @@ void gps_start () {
gpslasttype = gps_get_devicetype ();
if (gpslasttype == GPS_T_SERIAL) error = gps_serial_device_open ();
else if (gpslasttype == GPS_T_FILE) error = gps_file_device_open ();
+#ifdef ANDROID
+ else if (gpslasttype == GPS_T_ANDROID) error = gps_android_device_open ();
+#endif
else error = 0;
if (error) {
@@ -447,12 +455,16 @@ void gps_start () {
}
gpsdatalen = 0;
+ draw ();
};
void gps_stop () {
d_printf ("%s:%d gps_stop", __FILE__, __LINE__);
if (gpslasttype == GPS_T_SERIAL) gps_serial_device_close ();
+#ifdef ANDROID
+ else if (gpslasttype == GPS_T_ANDROID) gps_android_device_close ();
+#endif
else if (gpslasttype == GPS_T_FILE) gps_file_device_close ();
gpsstatus = 0;
gpsdatalen = 0;
@@ -624,6 +636,8 @@ struct gps_data *gps_loop () {
setlocale(LC_ALL, "C");
#endif
+ d_printf ("gps_loop");
+
gpspos.valid = gpsposvalid.valid = 0;
call = time (NULL);
/*
@@ -634,14 +648,21 @@ struct gps_data *gps_loop () {
/*
* check if gps is open and fillup the buffer
*/
- if (gpsstatus <= 0) return NULL;
+ if (gpsstatus <= 0) {
+ d_printf ("gps loop : status:%d", gpsstatus);
+ return NULL;
+ }
if (gpslasttype == GPS_T_SERIAL) dataread = gps_serial_device_read (gpsdata + gpsdatalen, GPS_INBUFSIZE - gpsdatalen);
+#ifdef ANDROID
+ else if (gpslasttype == GPS_T_ANDROID) dataread = gps_android_device_read (gpsdata + gpsdatalen, GPS_INBUFSIZE - gpsdatalen);
+#endif
else if (gpslasttype == GPS_T_FILE) dataread = gps_file_device_read (gpsdata + gpsdatalen, GPS_INBUFSIZE - gpsdatalen);
else dataread = -1;
if (dataread < 0) {
gps_stop();
gpsstatus = -1;
+ return NULL;
}
else if (dataread+gpsdatalen > GPS_INBUFSIZE) {
d_printf ("%s:%d gps_loop: ERROR datapos(%d) > GPS_INBUFSIZE(%d)", __FILE__, __LINE__, gpsdatalen + dataread, GPS_INBUFSIZE);
diff --git a/main/gps.h b/main/gps.h
index 244b07b..5f326dc 100644
--- a/main/gps.h
+++ b/main/gps.h
@@ -50,6 +50,7 @@
enum {
GPS_T_NONE,
GPS_T_SERIAL,
+ GPS_T_ANDROID,
GPS_T_FILE
};
@@ -149,5 +150,11 @@ extern void gps_file_set_pos (int newpos);
extern int gps_file_get_pos ();
extern int gps_file_get_size ();
+#ifdef ANDROID
+extern int gps_android_device_open ();
+extern void gps_android_device_close ();
+extern int gps_android_device_read (char *ptr, int ptrsize);
+#endif
+
#endif
diff --git a/main/gui_buttons.c b/main/gui_buttons.c
index f247240..3b9e681 100644
--- a/main/gui_buttons.c
+++ b/main/gui_buttons.c
@@ -137,7 +137,6 @@ void gui_buttons_zoomout() {
void gui_buttons_gps() {
if (gps_isrunning () <= 0) {
gps_start ();
- main_wnd_update();
}
else {
if (view_flags & DRAW_GPSFOLLOW) {