Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kindle Fire changes Screen Resolution at some point…

Disclaimer: this is a strange issue that only happens in a Kindle Fire (so far).

Technologies Involved: Android SDK, Eclipse, LibGDX.

I have a relatively simple app running with LibGDX. The way LibGDX works is by having an OpenGL thread that will call Create() (once) and then Render() as many times as possible (so you can do your render…).

So when you initialize the Device, your "Create()" method is called and then when the OpenGL surface is initialized (all this happens automagically), your Render() starts getting called.

If the OpenGL context is lost, destroyed, etc. your Resize(width,height) method is called by LibGDX.

So far. So good.

Now I came across a strange issue with a Kindle Fire where things looked a few pixels off or "cut". The Kindle Fire has a "softbar" at the bottom of the screen (20 pixels) that you can't hide or skip, which is "kind of ok" because the device doesn't have physical buttons. You're expected to touch this soft bar and get a bigger bar to go back, go home, etc. According to Amazon, this bar cannot be removed. (is not 100% clear but nobody has found a way -that is not breaking the Amazon rules). The only App I've seen that removes that is the Amazon Video Players for videos streamed from Amazon's Cloud only. So as you can see, there doesn't seem to be a way to "permanently" hide that bar.

So if the bar is there, your real screen state is not the hardware resolution 1024x600 (landscape) but 1024x580. So I added some logging to my methods to see what was going on, and was surprised with this… (remember the create(), render() and resize() methods):

12-23 15:17:04.119: I/myapp(19921): SCREEN HEIGHT AT CREATE(): 600
[snip other unrelated log stuff]
12-23 15:17:04.673: I/myapp(19921): SCREEN HEIGHT AT RENDER() LOOP: 600
[snip other unrelated log stuff]
12-23 15:17:04.705: I/myapp(19921): MyApp - Resize() Called.
12-23 15:17:04.705: I/myapp(19921): SCREEN HEIGHT AT RENDER() LOOP: 580

So the screen has been "resized" by the Kindle Fire, "at some point".

Has anyone come across something like this?

This is a screenshot (notice the black bar on top, that's not added by me!). Forgive me for blurring the image but this is a client's project and I can't "disclose" anything.

enter image description here

The fun part begins when sometimes, the bar won't be there and the app will look like the next (again, sry for the blur). Notice how the top bar is not there…

enter image description here

Upon a closer examination of both shots, you can tell that the bottom (which should be the same), is not. The kindle is doing strange things.

Any ideas?

The assets were originally packed as 1024x600 but we have changed that (580 now) and will assume that the viewport is now 1024x580 but I was wondering if anyone found a better way to deal with this nonsense? :)

note: we do have android:theme="@android:style/Theme.NoTitleBar.Fullscreen" in the manifest. Doesn't do anything.

Thanks in advance.

like image 352
Martin Marconcini Avatar asked Dec 23 '11 14:12

Martin Marconcini


1 Answers

Kindle fire has a strange behavior, once the app loads seems like it "moves" screen 20px up (Softbar height) therefore your app looks a few pixels off or cut. That's because when you create your GLSurfaceView and set your renderer it calls two times to onSurfaceChanged method.

First time, after onSurfaceCreated is called, with a resolution value of 1024x600 and a second time after first call to onDrawFrame with a value of 1024x580.

The solution, you must control the two calls to onSurfaceChanged and resize the opengl viewport.

    private static boolean appStarted = false;
    ...

    private static class Renderer implements GLSurfaceView.Renderer 
    {
        public void onSurfaceChanged(GL10 gl, int width, int height) 
        {
            if ( !appStarted )
            {
                 //Initialization (Resolution 1024x600)
            }
            else
            {
                 //Second call, screen resolution changed (Resolution 1024x580)
                 //Resize(width,height)
            }   
            appStarted = true;
        }

        public void onDrawFrame(GL10 gl) {
        //Render()
        }

        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        //Create()
        }
    }
like image 115
gergonzalez Avatar answered Nov 07 '22 22:11

gergonzalez