DoJa Developer Network
NewsAbout DoJaFeaturesForumsDownloadsLinksHandsetsTips
Programming
Tips
 
Programming
How can I ensure automatic centering of images without left justification on all handsets?
If you use VisualPresenter to display images and do not set the X(IMAGE_XPOS) and Y (IMAGE_YPOS) coordinates, centering is done automatically. However, there is no clearly defined rule regarding the timing when X and Y coordinates are set. Thus, the implementation of automatic centering varies from case to case.

For instance, with the following code in Sample 1 centering is carried out on all handsets but on some handsets left justification is also done.

Sample 1) Assuming that the file XXX.gif exists in your jar file, the following code is included in Panel:

MediaImage imageObj;
imageObj = MediaManager.getImage(resource:///XXX.gif);
try {
imageObj.use();
} catch (Exception e) {///
}
add(vPresenterObj);
vPresenterObj.setImage(imageObj);
vPresenterObj.setSize(getWidth()/2+72, vPresenterObj.getHeight());

From research done at NTT DoCoMo, it has been found that by using the following code in Sample 2, automatic centering can be implemented on any handset without left justification.

Sample 2) Assuming the same situation as in Sample 1, only the order of the last two lines of code to be executed is changed:

/* Get image from resource */
MediaImage imageObj;
imageObj = MediaManager.getImage(resource:///XXX.gif);
/* Reading media */
try {
imageObj.use();
} catch (Exception e) {///
}
add(vPresenterObj);
vPresenterObj.setSize(getWidth()/2+72, vPresenterObj.getHeight());
vPresenterObj.setImage(imageObj);

-------------------------------------------------------------------------------------------------
InputStream#read(byte[] b) does not read all the data into byte[] b. Is it handset bug?
read(byte[] b) method must be called multiple times because it does not guarantee that the reading is completed in just one call of the method.
The return value tells you how many bytes are read for one method call.To read data directly into the byte array, the Java code should look something like:

byte inData[] = new byte[data_length_to_acquire];
int bytesRead = 0;
int bytesReadOnce = 0;
while ( (bytesReadOnce = (int)in.read(inData,
bytesRead,
length - bytesRead)) != -1 ) {
bytesRead += bytesReadOnce;
if (bytesRead == length) {
break;
}
}


-------------------------------------------------------------------------------------------------

If I set 0xffffff to Graphics#setColor(int), it throws IllegalArgumentException
on one handset, but it doesn't on another handset. Why?
The validity of values that can be specified to setColor(int) method is
implementation dependent. You have to use getColorOfRGB(int r, int g, int b)
method to acquire the valid color value.

-------------------------------------------------------------------------------------------------
Is there any way not to hard-code the server URL?
Try IApplication#getSourceURL(). It gives you the URL of the JAR file of the current running application except the JAR file name. If the JAR file is located at "http://www.foo.com/download/prog/App1.jar", the return value is "http://www.foo.com/download/prog/". You can put whatever resource files in the same directory of the JAR file, and the URL can be made by getSourceURL() + "resource_file.png".

-------------------------------------------------------------------------------------------------
The time acquired from Date and Calendar classes does not match the native clock. Why?
Do you use Calendar.getInstance()? Try using Calendar.getInstance(TimeZone) with the time zone specified because the default time zone in Java may be different from the one set in the native system. Please note that the return values of TimeZone.getAvailableIDs() are handset dependent and that only GMT is mandatory.

-------------------------------------------------------------------------------------------------
Please be sure to read all Terms & Conditions and Privacy Policy information in full.
"DoJa" and the "DoJa" logo are trademarks or registered trademarks of NTT DoCoMo, Inc. in Japan and other countries.
©2004 NTT DoCoMo, Inc. All Rights Reserved.
i-mode NTT DoCoMo