Determining the Device Size at Run Time
If a target platform supports multiple panes, one way to determine whether to use the multiple-pane logic rather than use a single-screen logic is by determining the size of the device on which the application is running. After determining the size of the device, the application can then execute the appropriate logic for the device size.
At run time, the physical screen size of the device is not available because this value is not stored anywhere. However, the application can determine the screen size by checking the screen resolution against the screen’s pixels per inch (PPI). The screen resolution and PPI values are stored in the device profile. At run time, the application can query the values using the CURRENT_SCREEN_WIDTH, CURRENT_SCREEN_HEIGHT and CURRENT_SCREEN_PPI variables, which are part of the com.softwareag.mobile.runtime.core.CanvasDimensions class.
Note: | Not all device profiles will contain PPI information. Handsets targets that are "generic for any resolution" (that is, Android3xAPI) will use a dynamic canvas and will set CURRENT_SCREEN_PPI directly, as will targets for specific handsets. Generic targets for a given resolution (that is, Android320x480 and WindowsPhoneWVGA) will need to query System.getProperty("mobiledesigner.display.ppi") directly. |
You code the application to determine what size is considered a tablet. For example, the logic might consider that any device with a screen size that exceeds six inches diagonally is a tablet.
To see sample code that performs this logic, review the code in the Mobile Designer NativeUIDemo sample.