Handling Project Resources for Different Configurations


One of the most common causes of device fragmentation is different screen sizes on mobile devices. Disparate screen sizes require different resources, and usually, it is not advisable to include unused resources in the distribution JAR file.

Imagine the scenario in which your application has a fixed-size splash-screen image, and you want to include only the correct-size image with each configuration. There are two different methodologies that you can use to manage this problem using NetBeans Mobility Pack. Which method you should use depends on whether you are working with an existing project structure or have the freedom to handle the problem in any way that suits you.

Using Different Resource Locations

One technique is to create size-specific resource JAR files or folders that contain identically named resources. For example, you might have a directory structure like this:

/res/small/splashScreen.png /res/medium/splashScreen.png /res/large/splashScreen.png


Your source code would read simply:

Image splashScreen = Image.createImage("splashScreen.png");


Then you can modify the Libraries & Resource panel such that each configuration imports only the correct resource file for the screen size on the devices to which it will be deployed.

Using Configuration-Specific Code Blocks and the Filtering Panel

An alternative solution is to have distinctly named resources all contained under the project's source root. So you might have a directory structure something like this:

/src/res/splashScreenSmall.png /src/res/splashScreenMedium.png /src/res/splashScreenLarge.png


Then you would need three configuration-specific code blocks in your source code for the create statement, meaning that your source would look like the code in Figure 14-5.

Figure 14-5. Example of configuration-specific code blocks in the Source Editor


Finally, the Filtering Sources panel would be modified for each configuration such that only the used resource would be selected in each.

Both of these solutions result in similar-size application JAR files that include only the used resources. Therefore, it is up to you which technique is best suited to your project structures.



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net