Knowledge Base

SimpleHMI: Getting fancy with cursor positioning and screen sizes

One of the challenges of programming for Android devices is that they come in a huge variety of screen resolutions (pixel counts) and aspect ratios. The aspect ratio is the ratio between the long side and the short side. Typical aspect ratio figures are 4:3 (old TV), 3:2, 5:3 and 16:9 (modern wide-screen TV). Graphic display resolutions on Wikipedia. If you are programming for a single “target” device, it is fairly simple. If you are writing a program that should look OK on many different devices, it gets a bit trickier.

To help you out with all this we have done three things:

  1. Provided a way of specifying screen positions relative to the screen size, screen edges and screen center lines, and the sizes of buttons relative to the screen size. This will allow you, without too much difficulty, to lay out a screen that can flex and look reasonably balanced with different device sizes.
  2. Provided a way for you to specify the number of characters to fit into the width of the screen. You can for instance fit more onto a 10″ tablet than onto a 3.5″ ‘phone.
  3. Made the SimpleHMI in SPLat/PC configurable for different screen aspect ratios. This will allow you to test how your SPLat program will work on different Android devices.

In practice is is virtually impossible to accurately simulate every possible Android device without access to a physical sample. Even then, it would not be sure-fire, because there is no guarantee that different versions of the Android operating system won’t use up different amounts of screen space for status bar, default soft buttons etc. What the SimpleHMI in SPLat/PC does is allow you to set the number of character columns across, and the aspect ratio. It will then estimate the number of character rows.

The ScreenWidthEvent hash function lets you set the number of characters across the SimpleHMI screen. In the SimpleHMI device a special routine identifies the largest font size that will fit the required number of characters. An event is raised when this is done, so your program can draw or re-draw the screen. Note that the SimpleHMI device is not able to re-draw anything automatically when you change the screen width.