adding java calls needed for android gps types..

master
steffen 13 years ago
parent b1e2fca3f9
commit 6527314883

@ -9,11 +9,11 @@
<uses-sdk android:minSdkVersion="9" /> <uses-sdk android:minSdkVersion="9" />
<!-- This .apk has no Java code itself, so set hasCode to false. --> <!-- This .apk has no Java code itself, so set hasCode to false. -->
<application android:label="@string/app_name" android:hasCode="false" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> <application android:label="@string/app_name" android:hasCode="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<!-- Our activity is the built-in NativeActivity framework class. <!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. --> This will take care of integrating with our NDK code. -->
<activity android:name="android.app.NativeActivity" <activity android:name="de.gulpe.sposmroute.spOSMrNActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"> android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of or .so --> <!-- Tell NativeActivity the name of or .so -->
@ -26,6 +26,8 @@
</activity> </activity>
</application> </application>
<uses-feature android:glEsVersion="0x00020000" /> <uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
</uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permission> </uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE">

@ -17,10 +17,8 @@
#include <jni.h> #include <jni.h>
#include <errno.h> #include <errno.h>
#include <EGL/egl.h> #include <EGL/egl.h>
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <android/sensor.h> #include <android/sensor.h>
#include <android/log.h> #include <android/log.h>
#include <android_native_app_glue.h> #include <android_native_app_glue.h>
@ -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. * event loop for receiving input events and doing other things.
*/ */
void android_main(struct android_app* state) { 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. // Make sure glue isn't stripped.
app_dummy(); app_dummy();
@ -340,8 +341,7 @@ void android_main(struct android_app* state) {
// If not animating, we will block forever waiting for events. // If not animating, we will block forever waiting for events.
// If animating, we loop until all events are read, then continue // If animating, we loop until all events are read, then continue
// to draw the next frame of animation. // to draw the next frame of animation.
while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events, while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) {
(void**)&source)) >= 0) {
// Process this event. // Process this event.
if (source != NULL) { if (source != NULL) {
@ -367,18 +367,14 @@ void android_main(struct android_app* state) {
return; return;
} }
} }
t1 = time(NULL);
if (engine.animating) { if (t1 != t2) {
// Done with events; draw next animation frame. t2 = t1;
engine.state.angle += .01f; if (gps_isrunning () > 0) {
if (engine.state.angle > 1) { if ((gpspos = gps_loop ())) {
engine.state.angle = 0; drawgps_set_pos (gpspos);
}
} }
// Drawing is throttled to the screen update rate, so there
// is no need to do timing here.
draw();
// test_draw ();
} }
} }
} }
@ -394,3 +390,88 @@ void main_wnd_loop (long long int cur, long long int max) {
void main_wnd_update () { 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;
};

@ -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();
}
}

@ -790,6 +790,7 @@ int draw_mapcopy () {
void draw () { void draw () {
static int still_drawing = 0; static int still_drawing = 0;
d_printf ("draw()");
/* only run once at the time.. */ /* only run once at the time.. */
if (still_drawing) return; if (still_drawing) return;
still_drawing = 1; still_drawing = 1;

@ -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 * gui_entry.c
* *
@ -117,6 +117,7 @@ int gui_entry_event (GUIItem *item, GUIEvent *event) {
} }
} }
currentwin->screen_changed = 1; currentwin->screen_changed = 1;
draw ();
return 1; return 1;
}; };

@ -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 * gui_list.c
* *
@ -85,12 +85,16 @@ int gui_list_event (GUIItem *item, GUIEvent *event) {
int y = event->mousepos.y - item->y; int y = event->mousepos.y - item->y;
int i; int i;
GUIList *list = NULL; GUIList *list = NULL;
static GUIItem *olditem = NULL;
if (item == NULL) return 0; if (item == NULL) return 0;
else list = (GUIList *) item->data; else list = (GUIList *) item->data;
/* set focus */ /* set focus */
if (event->event == EGUI_MOUSERELEASED) { if (event->event == EGUI_MOUSEPRESSED) {
olditem = item;
}
else if (event->event == EGUI_MOUSERELEASED && olditem == item) {
gui_set_focus (item); gui_set_focus (item);
if (y <= 5 && x >= item->w - 10) list->vs--; if (y <= 5 && x >= item->w - 10) list->vs--;

@ -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 * gui_softkeyboard.c
* *
@ -182,6 +182,8 @@ int gui_softkeyb_event (GUIEvent event) {
softkeyb->last_line = -1; softkeyb->last_line = -1;
softkeyb->last_col = -1; softkeyb->last_col = -1;
} }
currentwin->screen_changed = 1;
draw ();
return 1; return 1;
} }
} }

@ -47,9 +47,13 @@ struct gps_data gpspos;
struct gps_data gpsposvalid; struct gps_data gpsposvalid;
#if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) && !defined(__MINGW32__) #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 #else
char gpsdevice[GPS_DEVICELEN] = "serial:com1,38400"; char gpsdevice[GPS_DEVICELEN] = "serial:com1,38400";
#endif #endif
int gpsflags = GPSF_LOG; int gpsflags = GPSF_LOG;
@ -387,6 +391,7 @@ float gps_getlat (char *text) {
int gps_get_devicetype () { int gps_get_devicetype () {
if (strncmp (gpsdevice, "serial:", 7) == 0) return GPS_T_SERIAL; 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, "file:", 5) == 0) return GPS_T_FILE;
else if (strncmp (gpsdevice, "android:", 8) == 0) return GPS_T_ANDROID;
else return GPS_T_NONE; else return GPS_T_NONE;
}; };
@ -433,6 +438,9 @@ void gps_start () {
gpslasttype = gps_get_devicetype (); gpslasttype = gps_get_devicetype ();
if (gpslasttype == GPS_T_SERIAL) error = gps_serial_device_open (); if (gpslasttype == GPS_T_SERIAL) error = gps_serial_device_open ();
else if (gpslasttype == GPS_T_FILE) error = gps_file_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; else error = 0;
if (error) { if (error) {
@ -447,12 +455,16 @@ void gps_start () {
} }
gpsdatalen = 0; gpsdatalen = 0;
draw ();
}; };
void gps_stop () { void gps_stop () {
d_printf ("%s:%d gps_stop", __FILE__, __LINE__); d_printf ("%s:%d gps_stop", __FILE__, __LINE__);
if (gpslasttype == GPS_T_SERIAL) gps_serial_device_close (); 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 (); else if (gpslasttype == GPS_T_FILE) gps_file_device_close ();
gpsstatus = 0; gpsstatus = 0;
gpsdatalen = 0; gpsdatalen = 0;
@ -624,6 +636,8 @@ struct gps_data *gps_loop () {
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
#endif #endif
d_printf ("gps_loop");
gpspos.valid = gpsposvalid.valid = 0; gpspos.valid = gpsposvalid.valid = 0;
call = time (NULL); call = time (NULL);
/* /*
@ -634,14 +648,21 @@ struct gps_data *gps_loop () {
/* /*
* check if gps is open and fillup the buffer * 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); 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 if (gpslasttype == GPS_T_FILE) dataread = gps_file_device_read (gpsdata + gpsdatalen, GPS_INBUFSIZE - gpsdatalen);
else dataread = -1; else dataread = -1;
if (dataread < 0) { if (dataread < 0) {
gps_stop(); gps_stop();
gpsstatus = -1; gpsstatus = -1;
return NULL;
} }
else if (dataread+gpsdatalen > GPS_INBUFSIZE) { else if (dataread+gpsdatalen > GPS_INBUFSIZE) {
d_printf ("%s:%d gps_loop: ERROR datapos(%d) > GPS_INBUFSIZE(%d)", __FILE__, __LINE__, gpsdatalen + dataread, GPS_INBUFSIZE); d_printf ("%s:%d gps_loop: ERROR datapos(%d) > GPS_INBUFSIZE(%d)", __FILE__, __LINE__, gpsdatalen + dataread, GPS_INBUFSIZE);

@ -50,6 +50,7 @@
enum { enum {
GPS_T_NONE, GPS_T_NONE,
GPS_T_SERIAL, GPS_T_SERIAL,
GPS_T_ANDROID,
GPS_T_FILE 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_pos ();
extern int gps_file_get_size (); 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 #endif

@ -137,7 +137,6 @@ void gui_buttons_zoomout() {
void gui_buttons_gps() { void gui_buttons_gps() {
if (gps_isrunning () <= 0) { if (gps_isrunning () <= 0) {
gps_start (); gps_start ();
main_wnd_update();
} }
else { else {
if (view_flags & DRAW_GPSFOLLOW) { if (view_flags & DRAW_GPSFOLLOW) {

Loading…
Cancel
Save