Building Mobile Enterprise Applications : webMethods Mobile Development Help : Creating and Building a Mobile Application : Defining Resources for the Mobile Project : Extending the UniversalResHandler to Allow Storing Image Files in Custom Subfolders
Extending the UniversalResHandler to Allow Storing Image Files in Custom Subfolders
If you want to use the basic functionality of the UniversalResHandler resource handler, but want to use additional subfolders for the image files, you can create a custom resource handler that extends the UniversalResHandler resource handler. For example, suppose in addition to the standard iOS platform subfolders, which are NonRetina and Retina, you also want to use RetinaIPhone4 and RetinaIPhone5. In this case, you can create a custom resource handler the extends the UniversalResHandler resource handler and includes the logic to handle the new subfolders.
To extend the UniversalResHandler to support additional image subfolders
1. Create a new Java class, for example, MyUniversalResHandler, in the same folder where UniversalResHandler resides.
2. In the new Java class for the custom resource handler, add your custom logic.
The custom logic should:
*Extend UniversalResHandler.java.
*Perform a super call to provide the behavior of the UniversalResHandler resource handler.
*Determine the type device and if the device is one for which you have a custom folder, provide logic for that custom folder.
The following shows an example resource handler named MyUniversalResHandler that extends the UniversalResHandler resource handler. This custom resource handler accommodates storing image files in the following graphic subfolders. These subfolders are in addition to the subfolders that the UniversalResHandler resource handler supports.
*resources/graphics/iOS/RetinaIPhone4/
*resources/graphics/iOS/RetinaIPhone5/
*resources/graphics/general/w1000/

// Use the UniversalResHandler's package
package my_application_package;
 
public class MyUniversalResHandler extends UniversalResHandler {
 
@Override
public void projectResourceScript() {
  // This call provides the UniversalResHandler behavior as
// the default behavior.
super.projectResourceScript();
 
rh.setResourceReadSubdirectory("graphics");
// get current handset name
String selectedHandset = rh.getProperty("selected.handset");
 
if (selectedHandset.startsWith("IOS")) {
// Logic for IOS devices only
 
// Processes the "iOS/RetinaIPhone4" folder to
// make all images in the "RetinaIPhone4" folder
// available at the run time.
addResourceFolder("iOS", "RetinaIPhone4");
 
// Processes the "iOS/RetinaIPhone5" folder to
// make all images in the "RetinaIPhone5" folder
// available at the run time.
addResourceFolder("iOS", "RetinaIPhone5");
}
 
// Processes "general/w1000" folder to make all
// images in the "general/w1000" folder available
// at the runtime.
addResourceFolder("general", "w1000", false);
}
}
3. Update the mobile project’s properties so that the mobile project uses your custom resource handler.
a. Ensure the mobile project is open in the Outline Editor. For instructions, see Displaying a Mobile Project in the Outline Editor.
b. Select the top-level child node of the project, which is the root application node.
c. Set the Res Handler property to the name of your custom resource handler, package_name.custom_resource_handler_name.java, for example com.softwareag.mobile.myproject.MyUniversalResHandler.java.
4. In the application_nameAppControllerImpl.java, override the methods the application uses to obtain image files.
The method you override depends on where you add the new subfolders that need to be searched for image files. The following tables lists the methods to override:
If you add a subfolder to this resources/graphics folder...
Override this method
Android
getAndroidGraphicsFolder
iOS
getIOSGraphicsFolder
WinPhone
getWinPhoneGraphicFolder and getWinPhoneThemeFolder
general
getGeneralGraphicsFolder
Continuing with the example started in step 1 of this procedure, the following code sample shows how to override the getIOSGraphicsFolder method so that at run time the application searches following additional folders for image files:
*resources/graphics/iOS/RetinaIPhone4/
*resources/graphics/iOS/RetinaIPhone5/

protected String getIOSGraphicsFolders(int currentScreenPPI,
int viewBackGroundcolor) {
int height = Math.max(CanvasController.CURRENT_SCREEN_WIDTH,
CanvasController.CURRENT_SCREEN_HEIGHT);
if (currentScreenPPI >= 200) {
if (height == 960) {
return "RetinaIPhone4/"; // !!! Slash at the end is important!!!
} else if (height == 1136) {
return "RetinaIPhone5/"; // !!! Slash at the end is important!!!
 
}
}
// otherwise, return default folder
return super.getIOSGraphicsFolders(currentScreenPPI, viewBackGroundcolor);
}
Again, continuing with the example started in step 1 of this procedure, the following code sample shows how to override the getGeneralGraphicsFolder method so that at run time the application searches the resources/graphics/general/w1000/ folder for image files:
protected String getGeneralGraphicsFolder(int viewBackGroundcolor,
int containerWidth) {
if ( containerWidth >= 1000) {
return "w1000/"; // !!! Slash at the end is important!!!
}
// otherwise, return default folder
return super.getGeneralGraphicsFolder(viewBackGroundcolor,
containerWidth);
}
Copyright © 2007-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback