Page 1 of 1

getScreenRotation function for Android

Posted: Thu Mar 14, 2013 10:48 pm
by Rado1
When working with Android sensors, it is necessary to know the current rotation of the screen from its "natural" orientation. Even if ZGE can specify either landscape or portrait orientation, "natural" orientation of each device can vary. Mobiles have usually portrait and tablets landscape orientation.

Android SDK provides the method Display.getRotation() which should be used for this purpose. I could implement its wrapper in ZGESensor library, but this would require usage of JNI and instantiation of another JVM, which is too cumbersome and not optimal for sure. (That's because NKD provides just a limited API and getRotation() was not included there.)

Ville, I expect that implementation of getScreenRotation() (or name it differently) function in ZGE would be technically more easier; similar to implementation of touchGet* functions. If so, I'm kindly asking you to add such a function to ZGE; it is really necessary for portable sensor-aware applications. Thanks.

Posted: Thu Mar 14, 2013 11:45 pm
by Kjell
:idea:

Slightly related .. would be nice if the orientation could be set dynamically as well. If only to be able to debug Android apps that are meant to be played in portrait mode ( the debugger is landscape only / by default ).

K

Posted: Fri Mar 15, 2013 9:30 am
by VilleK
How about if ZGE provides the current JVM instance to the loaded modules, would that make it simple for you to implement the function yourself? I'm thinking it would be useful for other things. ZGE could look for a function named "setJvmInstance" in any module it loads and if it exists then call it.

I currently knee deep in trying to implement GLES2 support. For latest progress of that see the source commits to Google Code.

Posted: Fri Mar 15, 2013 11:17 am
by Rado1
VilleK wrote:How about if ZGE provides the current JVM instance to the loaded modules, would that make it simple for you to implement the function yourself? I'm thinking it would be useful for other things. ZGE could look for a function named "setJvmInstance" in any module it loads and if it exists then call it.
This looks interesting, however, I'm going to experiment with JNI's function GetJavaVM(). It can maybe help. In the case of success I'll add the getScreenRotation() function to ZGESensor library.

I'm not sure the function setJvmInstance() could set JVM in the form compatible with NDK's type JavaVM. If so, then it could help, if not, JNI must be used instead.

Posted: Sat Mar 16, 2013 2:30 pm
by Rado1
Hi Kjell,

I experimented with JNI and I think the only way to obtain ZGE application's JVM instance in library is to call a function you named setJvmInstance(). Its signature in C++ should be similar to JNI_OnLoad, maybe except of the "reserved" parameter:

Code: Select all

JNIEXPORT void setJvmInstance(JavaVM* vm);
BTW would it be possible to use standard JNI functions JNI_OnLoad and JNI_OnUnload instead of setJvmInstance?