Java Reference
In-Depth Information
If you deploy multiple images of various sizes, your application can
choose at run time which one is closest to the required dimensions.
Display detection is less frequently used but is still useful in certain
cases. A few display properties can be retrieved using the static Display
instance, such as the number of colors that can be represented, the
supported number of alpha transparency levels, the best image height
and width for a given image type, and the color specifiers that match well
with the native color scheme.
The following code displays some of those properties, as shown in
Figure 4.15:
public void detectDisplay() {
Display display = Display.getDisplay(this);
form.append(" \ nnumColors:" + display.numColors());
form.append(" \ nalpha:" + display.numAlphaLevels());
form.append(" \ nfg color:" + Display.COLOR_FOREGROUND);
form.append(" \ nbg color:" + Display.COLOR_BACKGROUND);
form.append(" \ nleh:" +
display.getBestImageHeight(Display.LIST_ELEMENT));
form.append(" \ nlew:" + display.getBestImageWidth(Display.LIST_ELEMENT));
}
(a)
(b)
Figure 4.15 Querying Display and detecting screen dimensions
Generally the display attributes are useful for creating CustomItem
objects that match the user interface of other items and for creating user
interfaces within the canvas that match the user interface of the rest of
the system.
Another point related to screen size is orientation. It can change, for
example, when the device slider shifts, flip opens or closes. When the
orientation changes, the implementation calls the Displayable.size-
Changed(int, int) method. Overriding this method is useful for
 
Search WWH ::




Custom Search