com.android.ide.common.rendering.api
Interface IProjectCallback


public interface IProjectCallback

Callback for project information needed by the Layout Library. Classes implementing this interface provide methods giving access to some project data, like resource resolution, namespace information, and instantiation of custom view.


Nested Class Summary
static class IProjectCallback.ViewAttribute
           
 
Method Summary
 ActionBarCallback getActionBarCallback()
          Returns a callback for Action Bar information needed by the Layout Library.
 AdapterBinding getAdapterBinding(ResourceReference adapterViewRef, java.lang.Object adapterCookie, java.lang.Object viewObject)
          Returns an adapter binding for a given adapter view.
 java.lang.Object getAdapterItemValue(ResourceReference adapterView, java.lang.Object adapterCookie, ResourceReference itemRef, int fullPosition, int positionPerType, int fullParentPosition, int parentPositionPerType, ResourceReference viewRef, IProjectCallback.ViewAttribute viewAttribute, java.lang.Object defaultValue)
          Returns the value of an item used by an adapter.
 java.lang.String getNamespace()
          Returns the namespace of the application.
 ILayoutPullParser getParser(ResourceValue layoutResource)
          Returns a custom parser for a given layout.
 ILayoutPullParser getParser(java.lang.String layoutName)
          Deprecated. This is replaced by getParser(ResourceValue) but older version of the layoutlib (before API7) will still call this method.
 java.lang.Integer getResourceId(ResourceType type, java.lang.String name)
          Returns the id of a resource.
 java.lang.Object loadView(java.lang.String name, java.lang.Class[] constructorSignature, java.lang.Object[] constructorArgs)
          Loads a custom view with the given constructor signature and arguments.
 Pair<ResourceType,java.lang.String> resolveResourceId(int id)
          Resolves the id of a resource Id.
 java.lang.String resolveResourceId(int[] id)
          Resolves the id of a resource Id of type int[]

The resource id is the value of a R.styleable.<name>, and this method will return the name of the resource.

 

Method Detail

loadView

java.lang.Object loadView(java.lang.String name,
                          java.lang.Class[] constructorSignature,
                          java.lang.Object[] constructorArgs)
                          throws java.lang.ClassNotFoundException,
                                 java.lang.Exception
Loads a custom view with the given constructor signature and arguments.

Parameters:
name - The fully qualified name of the class.
constructorSignature - The signature of the class to use
constructorArgs - The arguments to use on the constructor
Returns:
A newly instantiated android.view.View object.
Throws:
java.lang.ClassNotFoundException
java.lang.Exception

getNamespace

java.lang.String getNamespace()
Returns the namespace of the application.

This lets the Layout Lib load custom attributes for custom views.


resolveResourceId

Pair<ResourceType,java.lang.String> resolveResourceId(int id)
Resolves the id of a resource Id.

The resource id is the value of a R.<type>.<name>, and this method will return both the type and name of the resource.

Parameters:
id - the Id to resolve.
Returns:
a Pair of ResourceType and resource name, or null if the id does not match any resource.

resolveResourceId

java.lang.String resolveResourceId(int[] id)
Resolves the id of a resource Id of type int[]

The resource id is the value of a R.styleable.<name>, and this method will return the name of the resource.

Parameters:
id - the Id to resolve.
Returns:
the name of the resource or null if not found.

getResourceId

java.lang.Integer getResourceId(ResourceType type,
                                java.lang.String name)
Returns the id of a resource.

The provided type and name must match an existing constant defined as R.<type>.<name>.

Parameters:
type - the type of the resource
name - the name of the resource
Returns:
an Integer containing the resource Id, or null if not found.

getParser

@Deprecated
ILayoutPullParser getParser(java.lang.String layoutName)
Deprecated. This is replaced by getParser(ResourceValue) but older version of the layoutlib (before API7) will still call this method.

Returns a custom parser for the layout of the given name.

Parameters:
layoutName - the name of the layout.
Returns:
returns a custom parser or null if no custom parsers are needed.

getParser

ILayoutPullParser getParser(ResourceValue layoutResource)
Returns a custom parser for a given layout.

Parameters:
layoutResource - The layout.
Returns:
returns a custom parser or null if no custom parsers are needed.

getAdapterItemValue

java.lang.Object getAdapterItemValue(ResourceReference adapterView,
                                     java.lang.Object adapterCookie,
                                     ResourceReference itemRef,
                                     int fullPosition,
                                     int positionPerType,
                                     int fullParentPosition,
                                     int parentPositionPerType,
                                     ResourceReference viewRef,
                                     IProjectCallback.ViewAttribute viewAttribute,
                                     java.lang.Object defaultValue)
Returns the value of an item used by an adapter.

Parameters:
adapterView - The ResourceReference for the adapter view info.
adapterCookie - the view cookie for this particular view.
itemRef - the ResourceReference for the layout used by the adapter item.
fullPosition - the position of the item in the full list.
positionPerType - the position of the item if only items of the same type are considered. If there is only one type of items, this is the same as fullPosition.
fullParentPosition - the full position of the item's parent. This is only valid if the adapter view is an ExpandableListView.
parentPositionPerType - the position of the parent's item, only considering items of the same type. This is only valid if the adapter view is an ExpandableListView. If there is only one type of items, this is the same as fullParentPosition.
viewRef - The ResourceReference for the view we're trying to fill.
viewAttribute - the attribute being queried.
defaultValue - the default value for this attribute. The object class matches the class associated with the IProjectCallback.ViewAttribute.
Returns:
the item value or null if there's no value.
See Also:
IProjectCallback.ViewAttribute.getAttributeClass()

getAdapterBinding

AdapterBinding getAdapterBinding(ResourceReference adapterViewRef,
                                 java.lang.Object adapterCookie,
                                 java.lang.Object viewObject)
Returns an adapter binding for a given adapter view. This is only called if SessionParams does not have an AdapterBinding for the given ResourceReference already.

Parameters:
adapterViewRef - the reference of adapter view to return the adapter binding for.
adapterCookie - the view cookie for this particular view.
viewObject - the view object for the adapter.
Returns:
an adapter binding for the given view or null if there's no data.

getActionBarCallback

ActionBarCallback getActionBarCallback()
Returns a callback for Action Bar information needed by the Layout Library. The callback provides information like the menus to add to the Action Bar.

Since:
API 11