Method for constructing portable BREW ™ applications September 12, 2003 Author: Qualcomm mobile front line
Follow the principles to make the BREW application have portability:
Use the resource file to use different MIF files for each target device Reference screen coordinate positioning control Use the appropriate color depth image to dynamically find a specific image or sound type handler custom menu style
1. Use resource files - Separate resource and code Separation BREW applications can be designed to be implemented on a variety of different devices and execute in a variety of different languages. You don't have to create an application separately for each device and each language, just create multiple resource files (.bar files) using the resource editor - each device language. Separation of resources and code separation will enable your BREW application to transplant across devices and languages.
You should use the resource editor to add all strings, images, and dialog resources used by the application. Then, each resource is associated with a name, and the name will be used in the application code. For more information on how to generate a resource (.bar) file, see the Resource Editor Guide with the BREW SDKTM.
2. Use a different MIF file MIF file for each target device contains strings and images for displaying applications in the menu that can perform applications. Therefore, you should create different MIF files for each device language.
3. Refer to the screen size Positioning Control - Do not use absolute pixel values as the target devices different from the screen coordinates have different screen sizes and different font heights, width. The following BREW APIs can be used to obtain these features, which will be used to arrange text, images, and controls on the device: these APIs:
• iShell_getDeviceInfo ()
IShell_getDeviceInfo is used to determine the screen size of the device running the application.
AeedeviceInfo Di;
INT CX, CY;
Ishell_getDeviceInfo (Pishell, & Di);
CX = di.cxscreen; // device width (pixel)
Cy = Di.Cyscreen; // Equipment height (pixel)
• Idisplay_GetFontMetrics ()
IDisplay_getfontmetrics () is used to find the character height of a specific font.
Int fontheight;
Fontheight = iDisplay_getfontmetrics (PME-> A.M_PIDISPLAY,
AEE_FONT_BOLD, NULL,
NULL);
• iDisplay_measureText ()
When drawing the specified font, you can use iDisplay_measureText () to measure the pixel width of the given string.
Int stringwidth = idisplay_measureText (PME-> A.M_PIDISPLAY,
AEE_FONT_NORMAL,
Textstring);
• iDisplay_measureTexTex ()
If you give a maximum pixel width and font for displaying a string, you can use iDisplay_measureTextex () to determine the number of characters that can be displayed.
Pixelwidth = idisplay_measureTextex (PME-> M_PIDISPLAY,
AEE_FONT_BOLD,
(AECHAR *) TextString, // Text string
-1,
Di.cxscreen, // maximum width
& pnfits); // can accommodate the number of characters
// Maximum width
Pixelwidth contains the pixel width of the input text string.
PNFits contains the number of characters of the input text string that can accommodate in a row.
• IIMAGE_GETINFO ()
IIMAGE_GETINFO () is used to get image size.
AeeImageInfo Imginfo;
INT CX, Cy; IIMAGE_GETINFO (PiImage, & Imginfo);
Cx = imginfo.cx; // Image width
Cy = imginfo.cy; // Image height
With the above API, you can locate the elements on the screen without hardcoding the pixel value.
E.g:
To draw text across multi-line:
// Get device information
ISHELL_GETDEVICEINFO (PME-> M_Pishell, & di);
// Get font metric information
Charheight = iDisplay_getfontmetrics (PME-> M_PIDISPLAY,
AEE_FONT_NORMAL, & PNASCENT, & PNDESCENT
// Convert to a wide string (Unicode)
STR_TO_WSTR ((char *) DisplayStr, WideStr, SizeOf (WideStr));
/ / PSZ tracking string point to start writing in the string buffer
// To prevent you from being able to accommodate strings in a row, you need to change it.
// Next line.
PSZ = WIDESTR;
/ / Need to calculate the total length of the string to determine if
// Remove.
Totalch = Strlen ((char *) WIDESTR);
// If the text string cannot be fully displayed in a single line,
// Multi-line display.
While ((Totalch> 0) && (* psz! = null) {
// Get information on the number of characters in a row.
Pixelwidth = iDisplay_measureTextex (PME-> M_PIDISPLAY, FONT,
(AECHAR *) PSZ, -1, Di.cxscreen - 5, & pnfits
Idisplay_drawtext (PME-> M_PIDISPLAY, AEE_FONT_NORMAL,
PSZ,
PNFITS, 5, DY, 0, 0);
PSZ = pnfits; // Move the pointer to the next to display
// segment
Totalch - = pnfits; // Reduce characters that still need to be displayed
/ / Total
DY = charheight; // Place the next line with the Charheight pixels of the previous line
// the following.
Idisplay_update (PME-> M_PIDISPLAY);
IF (Totalch PNFITS = Totalch; // If the total number is less than PNFITS, // Adjust PNFITS } } To display an image on the screen: // Get equipment coordinates ISHELL_GETDEVICEINFO (PME-> A.M_Pishell, & DINFO); / / Load the image from the resource file PiImage = ishell_loadResimage (pme-> a.m_pishell, szressfile, IDB_BROWSER_ICON); IF (PiImage) { // Get image size IIMAGE_GETINFO (PiImage, & Aii); // Calculate bitmap coordinates - / / Display bitmap at the center of the screen IMG_X = (DINFO.CXSCREEN - AII.CX) / 2; IMG_Y = (DINFO.CYSCREEN - AII.CY) / 2; / / Set the grating operation IIMAGE_SETPARM (PiImage, iParm_rop, aee_ro_not, 0); / / Draw a non-moving bitmap at the specified coordinate IIMAGE_DRAW (PIImage, IMG1_X, IMG1_Y); / / Release the image interface IIMAGE_RELEASE (PIIMAGE); } 4. Use appropriate color depths For different target devices, different resource files should be used. In these files, the image of the device is suitable for the device. If you get images from the external network, you can check the color depth of the device (including screen size) and use these values to get the appropriate image. AeedeviceInfo Di; INT CX, CY, ColorDepth; Ishell_getDeviceInfo (Pishell, & Di); CX = di.cxscreen; // device width (pixel) Cy = Di.Cyscreen; // Equipment height (pixel) ColorDepth = di.ncolorDepth; // The color depth of the device 5. Extended images In the BREW SDK version 1.1, IGRAPHICS_STRETCHBLT () can extend the bitmap to the desired width and height. You can compare the screen size (using iShell_getDeviceInfo) and image size (iimage_getinfo), then extend bitmaps to a more appropriate size as needed. Igraphics_stretchblt (Pigraphics, X and Y in the XStart, // Image of the upper left corner YStart, // coordinate Width, // desired image width Height, // Desired image height SourceBMP // source bitmap Rastercode 6. Dynamically look up a handler for a specific image or sound type to determine the Class ID of the handler function of the image / sound type, and then create an instance of the BREW class. / / Find the class ID of the BMP image handler IF ((CLS = ishell_gethandler (pme-> a.m_pishell, htype_viewer, "image / bmp")) == 0) Break; // Create an instance of an image handler using the returned class ID ISHELL_CREATEINSTANCE (PME-> A.M_Pishell, CLS, (Void **)); IF (PiImage == Null) Break; 7. Custom menu style When you create a menu style using the standard menu style, the menu may be different on different target devices. To keep your menu consistent appearance, you can use the iMenu_setStyle () custom menu style (the border type of the item, the population of the IP in the project, the filling of the Y direction in the project, and draw the image of the image). Aeeitemstyle Si, Ni; // Select the item style of the menu item Si.ft = aee_ft_tab_top_sel; // Border type of the project Si.xoffset = 8; // Fill in the X direction in the project (excluding the size of the border) Si.yoffset = 8; // Fill in the Y direction in the project (excluding the size of the border) Si.RoImage = aee_ro_copy; // Draw an image in the project // Project // Project style of the general menu item Ni.ft = aee_ft_tab_top; // Border type of the project Ni.xoffset = 8; // Fill in the x direction in the project (excluding the size of the border) Ni.yoffset = 8; // Filled in the Y direction in the project (excluding the size of the border) Ni.RoImage = aee_ro_copy; // Draw an image in the project // Project // Now set the project style you just created