Java Reference
In-Depth Information
Here is a snippet of code taken from DisplayDetectorMIDlet in
the Java ME Detectors suite:
public void detectScreenSize() {
MyCanvas canvas = new MyCanvas();
// detect normal size
int width = canvas.getWidth();
int height = canvas.getHeight();
form.append("width:" + width);
form.append("height:" + height);
// detect full screen size
canvas.setFullScreenMode(true);
width = canvas.getWidth();
height = canvas.getHeight();
form.append("full width:" + width);
form.append("full height:" + height);
}
Please note the second check of width and height, after setting the
screen mode to full screen.
A few of the generic solutions to diversity in screen size are tiling,
centering the application view, scaling the view images and deployment
of multiple size images.
Using tiling you can use smaller images and render them repeatedly
to cover the whole screen or parts of the screen. You could use a single
image and render it at various locations or you could use multiple images
and tile them according to some policy. For example, you could use three
images, rendering two of them at the corners and tiling the third across
the screen between the two corners (see Figure 4.14).
Figure 4.14 An image tiled between two others
You could query the screen dimensions and render the image in the
center. To fill the gaps left between the image and the edges of the screen,
you could use a background color or tiling.
MIDP does not have a library for image scaling. However, you could
find such a library or develop it yourself. Then, you need to decide when
in the execution of the application is the most appropriate time to do the
scaling. For example, you could do the scaling once at the first launch
and cache the scaled images in the file system to be loaded for subsequent
runs.
Search WWH ::




Custom Search