Build 1.0_r1(from source)

android.content.res
Class AssetManager

java.lang.Object
  extended by android.content.res.AssetManager

public final class AssetManager
extends Object

Provides access to an application's raw asset files; see Resources for the way most applications will want to retrieve their resource data. This class presents a lower-level API that allows you to open and read raw files that have been bundled with the application as a simple stream of bytes.


Nested Class Summary
 class AssetManager.AssetInputStream
           
 
Field Summary
static int ACCESS_BUFFER
          Mode for open(String, int): Attempt to load contents into memory, for fast small reads.
static int ACCESS_RANDOM
          Mode for open(String, int): Read chunks, and seek forward and backward.
static int ACCESS_STREAMING
          Mode for open(String, int): Read sequentially, with an occasional forward seek.
static int ACCESS_UNKNOWN
          Mode for open(String, int): no specific information about how data will be accessed.
(package private) static int STYLE_ASSET_COOKIE
           
(package private) static int STYLE_CHANGING_CONFIGURATIONS
           
(package private) static int STYLE_DATA
           
(package private) static int STYLE_NUM_ENTRIES
           
(package private) static int STYLE_RESOURCE_ID
           
(package private) static int STYLE_TYPE
           
 
Constructor Summary
AssetManager()
          Create a new AssetManager containing only the basic system assets.
 
Method Summary
 int addAssetPath(String path)
          Add an additional set of assets to the asset manager.
(package private) static boolean applyStyle(int theme, int defStyleAttr, int defStyleRes, int xmlParser, int[] inAttrs, int[] outValues, int[] outIndices)
           
(package private) static void applyThemeStyle(int theme, int styleRes, boolean force)
           
 void close()
          Close this asset manager.
(package private) static void copyTheme(int dest, int source)
           
(package private)  int createTheme()
           
(package private) static void dumpTheme(int theme, int priority, String tag, String prefix)
           
(package private)  void ensureStringBlocks()
           
protected  void finalize()
          Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
(package private)  int[] getArrayIntResource(int arrayRes)
           
(package private)  int getArraySize(int resource)
           
 String getCookieName(int cookie)
          
static int getGlobalAssetCount()
          
static int getGlobalAssetManagerCount()
          
 String[] getLocales()
          Get the locales that this asset manager contains data for.
(package private)  CharSequence getPooledString(int block, int id)
           
(package private)  CharSequence getResourceBagText(int ident, int bagEntryId)
          Retrieve the string value associated with a particular resource identifier for the current configuration / skin.
(package private)  String getResourceEntryName(int resid)
           
(package private)  int getResourceIdentifier(String type, String name, String defPackage)
          Retrieve the resource identifier for the given resource name.
(package private)  String getResourceName(int resid)
           
(package private)  String getResourcePackageName(int resid)
           
(package private)  String[] getResourceStringArray(int id)
          Retrieve the string array associated with a particular resource identifier.
(package private)  CharSequence getResourceText(int ident)
          Retrieve the string value associated with a particular resource identifier for the current configuration / skin.
(package private)  CharSequence[] getResourceTextArray(int id)
          Retrieve the text array associated with a particular resource identifier.
(package private)  String getResourceTypeName(int resid)
           
(package private)  boolean getResourceValue(int ident, TypedValue outValue, boolean resolveRefs)
           
static AssetManager getSystem()
          Return a global shared asset manager that provides access to only system assets (no application assets).
(package private)  boolean getThemeValue(int theme, int ident, TypedValue outValue, boolean resolveRefs)
           
 boolean isUpToDate()
          Determine whether the state in this asset manager is up-to-date with the files on the filesystem.
 String[] list(String path)
          Return a String array of all the assets at the given path.
(package private) static int loadThemeAttributeValue(int theme, int ident, TypedValue outValue, boolean resolve)
           
 InputStream open(String fileName)
          Open an asset using ACCESS_STREAMING mode.
 InputStream open(String fileName, int accessMode)
          Open an asset using an explicit access mode, returning an InputStream to read its contents.
 AssetFileDescriptor openFd(String fileName)
           
 InputStream openNonAsset(int cookie, String fileName)
           Open a non-asset in a specified package.
 InputStream openNonAsset(int cookie, String fileName, int accessMode)
           Open a non-asset in a specified package.
 InputStream openNonAsset(String fileName)
           Open a non-asset file as an asset using ACCESS_STREAMING mode.
 InputStream openNonAsset(String fileName, int accessMode)
           Open a non-asset file as an asset using a specific access mode.
 AssetFileDescriptor openNonAssetFd(int cookie, String fileName)
           
 AssetFileDescriptor openNonAssetFd(String fileName)
           
(package private)  XmlBlock openXmlBlockAsset(int cookie, String fileName)
           Retrieve a non-asset as a compiled XML file.
(package private)  XmlBlock openXmlBlockAsset(String fileName)
           Retrieve a non-asset as a compiled XML file.
 XmlResourceParser openXmlResourceParser(int cookie, String fileName)
          Retrieve a parser for a compiled XML file.
 XmlResourceParser openXmlResourceParser(String fileName)
          Retrieve a parser for a compiled XML file.
(package private)  void releaseTheme(int theme)
           
(package private)  int retrieveArray(int resource, int[] outValues)
           
(package private)  boolean retrieveAttributes(int xmlParser, int[] inAttrs, int[] outValues, int[] outIndices)
           
 void setConfiguration(int mcc, int mnc, String locale, int orientation, int touchscreen, int density, int keyboard, int keyboardHidden, int navigation, int screenWidth, int screenHeight, int majorVersion)
          Change the configuation used when retrieving resources.
 void setLocale(String locale)
          Change the locale being used by this asset manager.
(package private)  void xmlBlockGone()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCESS_UNKNOWN

public static final int ACCESS_UNKNOWN
Mode for open(String, int): no specific information about how data will be accessed.

See Also:
Constant Field Values

ACCESS_RANDOM

public static final int ACCESS_RANDOM
Mode for open(String, int): Read chunks, and seek forward and backward.

See Also:
Constant Field Values

ACCESS_STREAMING

public static final int ACCESS_STREAMING
Mode for open(String, int): Read sequentially, with an occasional forward seek.

See Also:
Constant Field Values

ACCESS_BUFFER

public static final int ACCESS_BUFFER
Mode for open(String, int): Attempt to load contents into memory, for fast small reads.

See Also:
Constant Field Values

STYLE_NUM_ENTRIES

static final int STYLE_NUM_ENTRIES
See Also:
Constant Field Values

STYLE_TYPE

static final int STYLE_TYPE
See Also:
Constant Field Values

STYLE_DATA

static final int STYLE_DATA
See Also:
Constant Field Values

STYLE_ASSET_COOKIE

static final int STYLE_ASSET_COOKIE
See Also:
Constant Field Values

STYLE_RESOURCE_ID

static final int STYLE_RESOURCE_ID
See Also:
Constant Field Values

STYLE_CHANGING_CONFIGURATIONS

static final int STYLE_CHANGING_CONFIGURATIONS
See Also:
Constant Field Values
Constructor Detail

AssetManager

public AssetManager()
Create a new AssetManager containing only the basic system assets. Applications will not generally use this method, instead retrieving the appropriate asset manager with Resources.getAssets(). Not for use by applications.

Method Detail

getSystem

public static AssetManager getSystem()
Return a global shared asset manager that provides access to only system assets (no application assets).


close

public void close()
Close this asset manager.


getResourceText

final CharSequence getResourceText(int ident)
Retrieve the string value associated with a particular resource identifier for the current configuration / skin.


getResourceBagText

final CharSequence getResourceBagText(int ident,
                                      int bagEntryId)
Retrieve the string value associated with a particular resource identifier for the current configuration / skin.


getResourceStringArray

final String[] getResourceStringArray(int id)
Retrieve the string array associated with a particular resource identifier.

Parameters:
id - Resource id of the string array

getResourceValue

final boolean getResourceValue(int ident,
                               TypedValue outValue,
                               boolean resolveRefs)

getResourceTextArray

final CharSequence[] getResourceTextArray(int id)
Retrieve the text array associated with a particular resource identifier.

Parameters:
id - Resource id of the string array

getThemeValue

final boolean getThemeValue(int theme,
                            int ident,
                            TypedValue outValue,
                            boolean resolveRefs)

ensureStringBlocks

final void ensureStringBlocks()

getPooledString

final CharSequence getPooledString(int block,
                                   int id)

open

public final InputStream open(String fileName)
                       throws IOException
Open an asset using ACCESS_STREAMING mode. This provides access to files that have been bundled with an application as assets -- that is, files placed in to the "assets" directory.

Parameters:
fileName - The name of the asset to open. This name can be hierarchical.
Throws:
IOException
See Also:
open(String, int), list(java.lang.String)

open

public final InputStream open(String fileName,
                              int accessMode)
                       throws IOException
Open an asset using an explicit access mode, returning an InputStream to read its contents. This provides access to files that have been bundled with an application as assets -- that is, files placed in to the "assets" directory.

Parameters:
fileName - The name of the asset to open. This name can be hierarchical.
accessMode - Desired access mode for retrieving the data.
Throws:
IOException
See Also:
ACCESS_UNKNOWN, ACCESS_STREAMING, ACCESS_RANDOM, ACCESS_BUFFER, open(String), list(java.lang.String)

openFd

public final AssetFileDescriptor openFd(String fileName)
                                 throws IOException
Throws:
IOException

list

public final String[] list(String path)
                    throws IOException
Return a String array of all the assets at the given path.

Parameters:
path - A relative path within the assets, i.e., "docs/home.html".
Returns:
String[] Array of strings, one for each asset. These file names are relative to 'path'. You can open the file by concatenating 'path' and a name in the returned string (via File) and passing that to open().
Throws:
IOException
See Also:
open(java.lang.String)

openNonAsset

public final InputStream openNonAsset(String fileName)
                               throws IOException
Open a non-asset file as an asset using ACCESS_STREAMING mode. This provides direct access to all of the files included in an application package (not only its assets). Applications should not normally use this.

Throws:
IOException
See Also:
open(String)

openNonAsset

public final InputStream openNonAsset(String fileName,
                                      int accessMode)
                               throws IOException
Open a non-asset file as an asset using a specific access mode. This provides direct access to all of the files included in an application package (not only its assets). Applications should not normally use this.

Throws:
IOException
See Also:
open(String, int)

openNonAsset

public final InputStream openNonAsset(int cookie,
                                      String fileName)
                               throws IOException
Open a non-asset in a specified package. Not for use by applications.

Parameters:
cookie - Identifier of the package to be opened.
fileName - Name of the asset to retrieve.
Throws:
IOException

openNonAsset

public final InputStream openNonAsset(int cookie,
                                      String fileName,
                                      int accessMode)
                               throws IOException
Open a non-asset in a specified package. Not for use by applications.

Parameters:
cookie - Identifier of the package to be opened.
fileName - Name of the asset to retrieve.
accessMode - Desired access mode for retrieving the data.
Throws:
IOException

openNonAssetFd

public final AssetFileDescriptor openNonAssetFd(String fileName)
                                         throws IOException
Throws:
IOException

openNonAssetFd

public final AssetFileDescriptor openNonAssetFd(int cookie,
                                                String fileName)
                                         throws IOException
Throws:
IOException

openXmlResourceParser

public final XmlResourceParser openXmlResourceParser(String fileName)
                                              throws IOException
Retrieve a parser for a compiled XML file.

Parameters:
fileName - The name of the file to retrieve.
Throws:
IOException

openXmlResourceParser

public final XmlResourceParser openXmlResourceParser(int cookie,
                                                     String fileName)
                                              throws IOException
Retrieve a parser for a compiled XML file.

Parameters:
cookie - Identifier of the package to be opened.
fileName - The name of the file to retrieve.
Throws:
IOException

openXmlBlockAsset

final XmlBlock openXmlBlockAsset(String fileName)
                          throws IOException
Retrieve a non-asset as a compiled XML file. Not for use by applications.

Parameters:
fileName - The name of the file to retrieve.
Throws:
IOException

openXmlBlockAsset

final XmlBlock openXmlBlockAsset(int cookie,
                                 String fileName)
                          throws IOException
Retrieve a non-asset as a compiled XML file. Not for use by applications.

Parameters:
cookie - Identifier of the package to be opened.
fileName - Name of the asset to retrieve.
Throws:
IOException

xmlBlockGone

void xmlBlockGone()

createTheme

final int createTheme()

releaseTheme

final void releaseTheme(int theme)

finalize

protected void finalize()
                 throws Throwable
Description copied from class: Object
Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Overrides:
finalize in class Object
Throws:
Throwable - The virtual machine ignores any exceptions which are thrown during finalization.

addAssetPath

public final int addAssetPath(String path)
Add an additional set of assets to the asset manager. This can be either a directory or ZIP file. Not for use by applications. A zero return value indicates failure.


isUpToDate

public final boolean isUpToDate()
Determine whether the state in this asset manager is up-to-date with the files on the filesystem. If false is returned, you need to instantiate a new AssetManager class to see the new data.


setLocale

public final void setLocale(String locale)
Change the locale being used by this asset manager. Not for use by applications.


getLocales

public final String[] getLocales()
Get the locales that this asset manager contains data for.


setConfiguration

public final void setConfiguration(int mcc,
                                   int mnc,
                                   String locale,
                                   int orientation,
                                   int touchscreen,
                                   int density,
                                   int keyboard,
                                   int keyboardHidden,
                                   int navigation,
                                   int screenWidth,
                                   int screenHeight,
                                   int majorVersion)
Change the configuation used when retrieving resources. Not for use by applications.


getResourceIdentifier

final int getResourceIdentifier(String type,
                                String name,
                                String defPackage)
Retrieve the resource identifier for the given resource name.


getResourceName

final String getResourceName(int resid)

getResourcePackageName

final String getResourcePackageName(int resid)

getResourceTypeName

final String getResourceTypeName(int resid)

getResourceEntryName

final String getResourceEntryName(int resid)

applyStyle

static final boolean applyStyle(int theme,
                                int defStyleAttr,
                                int defStyleRes,
                                int xmlParser,
                                int[] inAttrs,
                                int[] outValues,
                                int[] outIndices)

retrieveAttributes

final boolean retrieveAttributes(int xmlParser,
                                 int[] inAttrs,
                                 int[] outValues,
                                 int[] outIndices)

getArraySize

final int getArraySize(int resource)

retrieveArray

final int retrieveArray(int resource,
                        int[] outValues)

getCookieName

public final String getCookieName(int cookie)


getGlobalAssetCount

public static final int getGlobalAssetCount()


getGlobalAssetManagerCount

public static final int getGlobalAssetManagerCount()


applyThemeStyle

static final void applyThemeStyle(int theme,
                                  int styleRes,
                                  boolean force)

copyTheme

static final void copyTheme(int dest,
                            int source)

loadThemeAttributeValue

static final int loadThemeAttributeValue(int theme,
                                         int ident,
                                         TypedValue outValue,
                                         boolean resolve)

dumpTheme

static final void dumpTheme(int theme,
                            int priority,
                            String tag,
                            String prefix)

getArrayIntResource

final int[] getArrayIntResource(int arrayRes)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature