com.android.ide.common.rendering
Class LayoutLibrary

java.lang.Object
  extended by com.android.ide.common.rendering.LayoutLibrary

public class LayoutLibrary
extends java.lang.Object

Class to use the Layout library.

Use load(String, ILogger, String) to load the jar file.

Use the layout library with: init(java.util.Map, java.io.File, java.util.Map>, com.android.ide.common.rendering.api.LayoutLog), supports(int), createSession(SessionParams), dispose(), clearCaches(Object).

Layout libraries before API level 5 used IProjectCallback. Layout libraries from API level 5 to 14 used IProjectCallback. Layout libraries since API 15 use LayoutlibCallback. To target all Layout libraries, use LayoutlibCallback, which implements the other interfaces. Also, use ILegacyPullParser instead of ILayoutPullParser.

These interfaces will ensure that both new and older Layout libraries can be accessed.


Field Summary
static java.lang.String CLASS_BRIDGE
           
static java.lang.String FN_ICU_JAR
           
 
Constructor Summary
protected LayoutLibrary()
           
 
Method Summary
 void clearCaches(java.lang.Object projectKey)
          Clears the resource cache for a specific project.
 com.android.ide.common.rendering.api.RenderSession createSession(com.android.ide.common.rendering.api.SessionParams params)
          Starts a layout session by inflating and rendering it.
 boolean dispose()
          Prepares the layoutlib to unloaded.
 int getApiLevel()
          Returns the API level of the layout library.
 java.lang.ClassLoader getClassLoader()
          Returns the classloader used to load the classes in the layoutlib jar file.
 java.lang.String getLoadMessage()
          Returns the message associated with the LoadStatus.
 int getRevision()
          Returns the revision of the library inside a given (layoutlib) API level.
 LoadStatus getStatus()
          Returns the LoadStatus of the loading of the layoutlib jar file.
 com.android.ide.common.rendering.api.Result getViewIndex(java.lang.Object viewObject)
          Utility method returning the index of a given view in its parent.
 com.android.ide.common.rendering.api.Result getViewParent(java.lang.Object viewObject)
          Utility method returning the parent of a given view object.
 boolean init(java.util.Map<java.lang.String,java.lang.String> platformProperties, java.io.File fontLocation, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Integer>> enumValueMap, com.android.ide.common.rendering.api.LayoutLog log)
          Initializes the Layout Library object.
 boolean isRtl(java.lang.String locale)
          Returns true if the character orientation of the locale is right to left.
static LayoutLibrary load(java.lang.String layoutLibJarOsPath, com.android.utils.ILogger log, java.lang.String toolName)
          Loads the layoutlib.jar file located at the given path and returns a LayoutLibrary object representing the result.
 com.android.ide.common.rendering.api.Result renderDrawable(com.android.ide.common.rendering.api.DrawableParams params)
          Renders a Drawable.
 boolean supports(com.android.ide.common.rendering.api.Capability capability)
          Deprecated. use supports(int)
 boolean supports(int capability)
          Returns whether the LayoutLibrary supports a given Features.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_BRIDGE

public static final java.lang.String CLASS_BRIDGE
See Also:
Constant Field Values

FN_ICU_JAR

public static final java.lang.String FN_ICU_JAR
See Also:
Constant Field Values
Constructor Detail

LayoutLibrary

protected LayoutLibrary()
Method Detail

getStatus

public LoadStatus getStatus()
Returns the LoadStatus of the loading of the layoutlib jar file.


getLoadMessage

public java.lang.String getLoadMessage()
Returns the message associated with the LoadStatus. This is mostly used when getStatus() returns LoadStatus.FAILED.


getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the classloader used to load the classes in the layoutlib jar file.


load

public static LayoutLibrary load(java.lang.String layoutLibJarOsPath,
                                 com.android.utils.ILogger log,
                                 java.lang.String toolName)
Loads the layoutlib.jar file located at the given path and returns a LayoutLibrary object representing the result.

If loading failed getStatus() will reflect this, and mBridge will be null.

Parameters:
layoutLibJarOsPath - the path of the jar file
log - an optional log file.
Returns:
a LayoutLibrary object always.

getApiLevel

public int getApiLevel()
Returns the API level of the layout library.


getRevision

public int getRevision()
Returns the revision of the library inside a given (layoutlib) API level. The true version number of the library is getApiLevel().getRevision()


supports

@Deprecated
public boolean supports(com.android.ide.common.rendering.api.Capability capability)
Deprecated. use supports(int)

Returns whether the LayoutLibrary supports a given Capability.

Returns:
true if it supports it.
See Also:
Bridge.getCapabilities()

supports

public boolean supports(int capability)
Returns whether the LayoutLibrary supports a given Features.

See Also:
Bridge.supports(int)

init

public boolean init(java.util.Map<java.lang.String,java.lang.String> platformProperties,
                    java.io.File fontLocation,
                    java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Integer>> enumValueMap,
                    com.android.ide.common.rendering.api.LayoutLog log)
Initializes the Layout Library object. This must be called before any other action is taken on the instance.

Parameters:
platformProperties - The build properties for the platform.
fontLocation - the location of the fonts in the SDK target.
enumValueMap - map attrName => { map enumFlagName => Integer value }. This is typically read from attrs.xml in the SDK target.
log - a LayoutLog object. Can be null.
Returns:
true if success.

dispose

public boolean dispose()
Prepares the layoutlib to unloaded.

See Also:
Bridge.dispose()

createSession

public com.android.ide.common.rendering.api.RenderSession createSession(com.android.ide.common.rendering.api.SessionParams params)
Starts a layout session by inflating and rendering it. The method returns a RenderSession on which further actions can be taken.

Before taking further actions on the scene, it is recommended to use supports(int) to check what the scene can do.

Returns:
a new RenderSession object that contains the result of the scene creation and first rendering or null if getStatus() doesn't return LoadStatus.LOADED.
See Also:
Bridge.createSession(SessionParams)

renderDrawable

public com.android.ide.common.rendering.api.Result renderDrawable(com.android.ide.common.rendering.api.DrawableParams params)
Renders a Drawable. If the rendering is successful, the result image is accessible through Result.getData(). It is of type BufferedImage

Parameters:
params - the rendering parameters.
Returns:
the result of the action.

clearCaches

public void clearCaches(java.lang.Object projectKey)
Clears the resource cache for a specific project.

This cache contains bitmaps and nine patches that are loaded from the disk and reused until this method is called.

The cache is not configuration dependent and should only be cleared when a resource changes (at this time only bitmaps and 9 patches go into the cache).

Parameters:
projectKey - the key for the project.
See Also:
Bridge.clearCaches(Object)

getViewParent

public com.android.ide.common.rendering.api.Result getViewParent(java.lang.Object viewObject)
Utility method returning the parent of a given view object.

Parameters:
viewObject - the object for which to return the parent.
Returns:
a Result indicating the status of the action, and if success, the parent object in Result.getData()

getViewIndex

public com.android.ide.common.rendering.api.Result getViewIndex(java.lang.Object viewObject)
Utility method returning the index of a given view in its parent.

Parameters:
viewObject - the object for which to return the index.
Returns:
a Result indicating the status of the action, and if success, the index in the parent in Result.getData()

isRtl

public boolean isRtl(java.lang.String locale)
Returns true if the character orientation of the locale is right to left.

Parameters:
locale - The locale formatted as language-region
Returns:
true if the locale is right to left.