public final class

ResManager

extends Object
java.lang.Object
   ↳ com.neomades.app.ResManager

Class Overview

Resource Manager.

To use the resource manager into application screens, you could call ResManager methods.

Example :
 public class MyScreen extends Screen {
 	protected void onCreate() {
 		// return the text contained into the project csv
 		ResManager.getString(Res.string.ID_OF_THE_TEXT);
 	}
 }
 

Note: Do not call ResManager in any static initializer.

Summary

Public Methods
static void clearImageCache()
Clear the image cache.
static Background getBackground(int backgroundResId)
Gets a XML background resource.
static boolean getBool(int booleanResId)
Gets a XML boolean resource.
static Color getColor(int colorResId)
Gets a XML color resource.
static int getDimen(int dimenResId)
Gets a XML dimen resource.
static Font getFont(int resId)
Loads a TTF font from resources, with the platform's default font size.
static Font getFont(int resId, int size)
Loads a TTF font from resources and specify in parameter the size (height) of the font.
static Image getImage(int resId)
Gets an image from a resource identifier.
static int getInteger(int integerResId)
Gets a XML integer resource.
static View getLayout(int layoutResId)
Gets a XML Layout resource.
static byte[] getRawData(int resId)
Gets a raw data resource.
static InputStream getResourceAsStream(String path)
Finds a resource with a given name.
static Sound getSound(int resId)
Gets a sound from a resource identifier.
static String getString(int resId, Object... formatArgs)
Gets a localized string from a resource identifier.
static Style getStyle(int styleResId)
Gets a XML style resource.
static InputStream openAsset(String assetPath)
Opens a resource stream from assets folder.
static InputStream openRaw(int resId)
Opens a raw resource as stream.
static void setImageCacheEnabled(boolean enabled)
By default, the image cache is enabled in iOS.
static void setLanguage(int languageID)
Sets the language for multi-languages binaries.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static void clearImageCache ()

Clear the image cache.

public static Background getBackground (int backgroundResId)

Gets a XML background resource.

Parameters
backgroundResId resource identifier from Res.background
Returns
  • background from XML definition
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static boolean getBool (int booleanResId)

Gets a XML boolean resource.

Parameters
booleanResId resource identifier from Res.bool
Returns
  • boolean from XML definition
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static Color getColor (int colorResId)

Gets a XML color resource.

Parameters
colorResId resource identifier from Res.color
Returns
  • color from XML definition
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static int getDimen (int dimenResId)

Gets a XML dimen resource.

Parameters
dimenResId resource identifier from Res.dimen
Returns
  • dimen from XML definition
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static Font getFont (int resId)

Loads a TTF font from resources, with the platform's default font size.

See <font> declaration in the URS file.

Cross Platform Considerations

For the iOS platform, bold and italic fonts must be provided in order to be able to use a TTF font with these styles. In other platforms the system will apply the style on the TTF font even if the related TTF files are not provided.

Parameters
resId resource identifier from Res.font
Returns
  • the found font from the resources or null if not found
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found or cannot be loaded

public static Font getFont (int resId, int size)

Loads a TTF font from resources and specify in parameter the size (height) of the font.

See <font> declaration in the URS file.

Parameters
resId resource identifier from Res.font
size size of the font
Returns
  • the found font from the resources or null if not found
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found or cannot be loaded

public static Image getImage (int resId)

Gets an image from a resource identifier. The identifier is given in the class Resources, generated by NeoMAD.

ResManager uses a cache of loaded images.

See <image> declaration in the URS file.

Parameters
resId resource identifier from Res.image
Returns
  • the loaded image
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static int getInteger (int integerResId)

Gets a XML integer resource.

Parameters
integerResId resource identifier from Res.integer
Returns
  • integer from XML definition
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static View getLayout (int layoutResId)

Gets a XML Layout resource.

Parameters
layoutResId resource identifier from Res.layout
Returns
  • view from XML layout definition
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found
See Also

public static byte[] getRawData (int resId)

Gets a raw data resource.

Parameters
resId resource identifier from Res.raw
Returns
  • raw data as a byte array
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static InputStream getResourceAsStream (String path)

Finds a resource with a given name. This method returns null if no resource with this name is found.

Replace the Class method : getResourceAsStream(String) .

This method could be used to load a resource declared as <jarfiles> in the URS.

EG. a jar file declared with the path "./folder/file.txt" can be loaded using this method setting the path "folder/file.txt" in parameter.

Parameters
path the resource path from the binary
Returns
  • the loaded data stream, or null if not found

public static Sound getSound (int resId)

Gets a sound from a resource identifier. The identifier is given in the class Resources, generated by NeoMAD.

See <sound> declaration in the URS file.

Parameters
resId resource identifier from Res.music
Returns
  • the loaded sound resource
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static String getString (int resId, Object... formatArgs)

Gets a localized string from a resource identifier. See documentation for more details about how to declare string resources.

If this method is invoked with format arguments, the string resource is formatted using the StringUtils#format(String, Object[]) method. See java.util.Formatter for a list of valid format specifiers that can be used. If no format arguments are given during the invocation, the exact string resource is returned.

Note: If a string resource is not available for the device's current locale (it is not declared in the corresponding XML file), the name of the resource is returned.

Parameters
resId resource identifier from Res.string
formatArgs arguments used to format the string resource
Returns
  • the string resource (optionally with formatting)
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static Style getStyle (int styleResId)

Gets a XML style resource.

Parameters
styleResId resource identifier from Res.style
Returns
  • style from XML definition
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static InputStream openAsset (String assetPath)

Opens a resource stream from assets folder.

Parameters
assetPath relative path from assets folder
Returns
  • file stream
Throws
ResourceNotFoundException when the resource corresponding to the assetPath parameter was not found

public static InputStream openRaw (int resId)

Opens a raw resource as stream.

Parameters
resId resource identifier from Res.raw
Returns
  • raw as stream
Throws
ResourceNotFoundException when the resource corresponding to the resId parameter was not found

public static void setImageCacheEnabled (boolean enabled)

By default, the image cache is enabled in iOS. The image cache is cleared between each creation of screens.

Parameters
enabled true to enable cache

public static void setLanguage (int languageID)

Sets the language for multi-languages binaries.

Parameters
languageID language identifier from Res.lang