[FIX] Possibile bug DisplayMetrics on Android 3.0

Apr 23, 2012 at 12:58 PM

Hi,

it seems that in Andorid 3.0, the height of system status bar is not included in DisplayMetrics's height.

To workaround this I've changed the Width and Height  properties of the Android/Graphics/DisplayMetric.cs class 
so they could return the Size.Width and Size.Height values of the AndroidGameView made by Xamarin.

public int Width
{
    get
    {
        return AndroidGameActivity.Game.Window.Size.Width;
    }
}

public int Height
{
    get
    {
        return AndroidGameActivity.Game.Window.Size.Height;
    }
}

It is also necessary:

1- Change the Initialize() method on the Graphics/GraphicsDevice.cs to set the correct width and height
of the viewport

internal Initialize()
{
    
    // Original code
    ... 
    ...

    // DisplayMetric Fix
#if ANDROID

    _viewport.Width = DisplayMode.Width;
    _viewport.Height = DisplayMode.Height;

#endif

}
 
2- Change and move the initialization of the clientBounds member inside the AndroidGameWindow.cs class:

protected override void CreateFrameBuffer()
{
    clientBounds = new Rectangle(0, 0, this.Size.Width, this.Size.Height);
}

3 - Change the DisplayWidth and DisplayHeight properties of the Input/TouchPanel.cs class

public static int DisplayWidth
{
    get
    {
        return AndroidGameActivity.Game.Window.Size.Width;
    }
}

public static int DisplayHeight
{
    get
    {
        return AndroidGameActivity.Game.Window.Size.Height;
    }
}