getScreenRotation function for Android

If there is something important you think is missing in the current version of ZGameEditor then you can post a feature request here!

Moderator: Moderators

Post Reply
User avatar
Rado1
Posts: 771
Joined: Wed May 05, 2010 12:16 pm

getScreenRotation function for Android

Post by Rado1 » Thu Mar 14, 2013 10:48 pm

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.

User avatar
Kjell
Posts: 1721
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell » Thu Mar 14, 2013 11:45 pm

: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

User avatar
VilleK
Site Admin
Posts: 2052
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK » Fri Mar 15, 2013 9:30 am

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.

User avatar
Rado1
Posts: 771
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 » Fri Mar 15, 2013 11:17 am

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.

User avatar
Rado1
Posts: 771
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 » Sat Mar 16, 2013 2:30 pm

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?

Post Reply