Incorrect screen height in honeycomb?

Discussion about using Moai SDK - post questions, bugs and issues here.

Moderators: seebs, franciscotufro

Incorrect screen height in honeycomb?

Postby tnlogy » Thu Apr 05, 2012 3:06 am

Hi, sitting here enjoying using Moai for an upcoming gallery exhibition.

I test it on a Samsung Galaxy Tab, and I get the screen resolution 1280x800. But since the menubar in Android Honeycomb takes up 48 pixels, the size should be 1280x752. If I use 1280x800, I get incorrect touch positions and misdisplayed graphics.

The wisdom of internet says that you should check the size of the main view of an app to get the correct resolution.

Is this a bug, or how should I handle it?

Have a nice day!
Tobias
User avatar
tnlogy
 
Posts: 17
Joined: Wed Mar 07, 2012 10:22 am

Re: Incorrect screen height in honeycomb?

Postby thebullno1 » Thu Apr 05, 2012 3:11 am

If you have a look at MoaiActivity.java, it queries the device's size, not the view size. This sounds like a bug to me.
I think deferring the initialization of MoaiView till layout phase might fix it.
I'll try to dig around the code later tonight.
Last edited by thebullno1 on Thu Apr 05, 2012 3:25 am, edited 1 time in total.
User avatar
thebullno1
 
Posts: 256
Joined: Sat Jul 02, 2011 8:53 am

Re: Incorrect screen height in honeycomb?

Postby ibisum » Thu Apr 05, 2012 3:21 am

Its true that the main view of the app should be returned for size, but are you also setting the viewport scale properly when you hard-code the resolution to 1280x800? Its important to map the relationship between view size and viewport scale ..
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1005
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: Incorrect screen height in honeycomb?

Postby tnlogy » Thu Apr 05, 2012 6:57 am

thebullno1 wrote:I'll try to dig around the code later tonight.


Nice! I have no time to look at it right now.
User avatar
tnlogy
 
Posts: 17
Joined: Wed Mar 07, 2012 10:22 am

Re: Incorrect screen height in honeycomb?

Postby sean » Thu Apr 05, 2012 4:43 pm

Interesting. I don't have a honeycomb tablet here to test this, but I can tell you that on a Kindle Fire, Moai properly compensates for the soft key menu. However, the status bar on Kindle fire is on top of the z-order so when it's displayed, it's on top of the Moai OpenGL surface.

If you instrument MoaiView.java with a call to MoaiLog in setScreenDimensions, you'll see that the dimensions are initially set to the display size. Subsequently, MoaiRenderer.onSurfaceChanged is called (when the surface is created) and they are again set to the display size. But, as soon as the layout completes, MoaiRenderer.onSurfaceChanged is called again, and the Kindle soft menu (20px) is now compensated for.

So, I'm surprised that the same does not happen for the Honeycomb menu bar. Let me see if I can commandeer a Honeycomb tablet and take a look.
User avatar
sean
 
Posts: 120
Joined: Wed Nov 09, 2011 5:57 pm

Re: Incorrect screen height in honeycomb?

Postby thebullno1 » Fri Apr 06, 2012 12:21 am

I tried to enable the title bar to test it (since Samsung thinks it's a good idea to make ICS look like Gingerbread).

onSurfaceCreated runs user scripts so the script is already informed of the wrong dimension (the screen dimensions) so when onSurfaceChanged is called, it is already too late.

Edit:

I think I kind of solve this problem

1) Detect viewable size using onMeasure: http://stackoverflow.com/questions/2485 ... ation-bars. The size should be cached since my log shows that it gets called quite often.
2) Setup projection based on MOAIGfxDevice.getViewSize instead of MOAIEnvironment.screenWidth, MOAIEnvironment.screenHeight
User avatar
thebullno1
 
Posts: 256
Joined: Sat Jul 02, 2011 8:53 am

Re: Incorrect screen height in honeycomb?

Postby thebullno1 » Fri Apr 06, 2012 2:10 am

I tested on my Galaxy S2 and it seems like everything works.
I don't have a device with a bottom bar so I'm not sure if my fix works properly.
If you do, please test it and let me know.

Attached with this post is an app with title bar. It will draw a cross on the screen. It should connect the corners of the visible area. Please test it on a device with a bottom bar and let me know it it works. The app also outputs touch coordinate to the log.

http://dl.dropbox.com/u/7948800/TestScreen-debug.apk
http://dl.dropbox.com/u/7948800/MoaiView.java

Note: my MoaiView.java contains lots of log spams and temporary hacks. If it works, I will clean it up and make a pull request.
User avatar
thebullno1
 
Posts: 256
Joined: Sat Jul 02, 2011 8:53 am

Re: Incorrect screen height in honeycomb?

Postby tnlogy » Fri Apr 06, 2012 2:34 am

Hi! This is the output when using your MoaiView.java. Seems like onMeasure gives the correct size, but not MOAIEnvironment.screenHeight which I print with "size 1280 x 800". Afraid your apk just crashed, no idea why. Will try to debug it better later on. Thanks for the effort!

I/MoaiLog (15913): onMeasure: 1280 x 800
I/MoaiLog (15913): onMeasure: 1280 x 752
I/MoaiLog (15913): MoaiRenderer onSurfaceCreated: surface CREATED
I/MoaiLog (15913): Dimension: 1280 x 752
I/MoaiLog (15913): MoaiRenderer onSurfaceChanged: surface CHANGED
I/MoaiLog (15913): Dimension: 1280 x 752
I/MoaiLog (15913): MoaiRenderer onSurfaceCreated: Running game scripts
I/MoaiLog (15913): MoaiRenderer runScripts: Running ../init.lua script
I/MoaiLog (15913): load: running init.lua
I/MoaiLog (15913): MoaiRenderer runScripts: Running main.lua script
I/MoaiLog (15913): userdata: 0x1a55e0
I/MoaiLog (15913): size 1280 x 800
I/MoaiLog (15913): MoaiActivity onWindowFocusChanged: activity FOCUS CHANGED
I/MoaiLog (15913): onMeasure: 1280 x 752
User avatar
tnlogy
 
Posts: 17
Joined: Wed Mar 07, 2012 10:22 am

Re: Incorrect screen height in honeycomb?

Postby thebullno1 » Fri Apr 06, 2012 2:50 am

Actually I just realized that I don't even need onMeasure.
onSurfaceChanged is called right after onSurfaceCreated and before scripts are run since that action is queued.

In short: forget what I said about onMeasure. All you need is to setup your viewport based on MOAIGfxDevice.getViewSize() instead of MOAIEnvironment.screenWidth
User avatar
thebullno1
 
Posts: 256
Joined: Sat Jul 02, 2011 8:53 am

Re: Incorrect screen height in honeycomb?

Postby tnlogy » Fri Apr 06, 2012 3:37 am

That seems to do the trick. I will remember to use getViewSize() instead in the future. Thanks a lot!
User avatar
tnlogy
 
Posts: 17
Joined: Wed Mar 07, 2012 10:22 am

Re: Incorrect screen height in honeycomb?

Postby sean » Fri Apr 06, 2012 12:32 pm

Correct. If you look at MoaiView.java, the constructor calls setScreenSize, which will have the dimensions as returned by the Android Display object. onSurfaceChanged calls setViewSize, which will be the actual size of the GL surface view. Note that on some devices, like the Kindle Fire, onSurfaceChanged is called multiple times - once with the full screen dimensions and subsequently with the adjusted view size. I've verified this on an Asus Transformer running Honeycomb as well. Thanks for your help @thebullno1!
User avatar
sean
 
Posts: 120
Joined: Wed Nov 09, 2011 5:57 pm

Re: Incorrect screen height in honeycomb?

Postby mbtmp » Thu Jun 21, 2012 2:25 pm

I have one more question, would it be possible I could trigger a Lua function (or a callback) everytime "onSurfaceChanged" is called?
mbtmp
 
Posts: 4
Joined: Thu May 10, 2012 5:01 pm


Return to Moai SDK

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 1 guest

x