com.android.ide.common.rendering.api
Class RenderSession

java.lang.Object
  extended by com.android.ide.common.rendering.api.RenderSession

public class RenderSession
extends java.lang.Object

An object allowing interaction with an Android layout. This is returned by Bridge.createSession(SessionParams). and can then be used for subsequent actions on the layout.

Since:
5

Constructor Summary
RenderSession()
           
 
Method Summary
 Result animate(java.lang.Object targetObject, java.lang.String animationName, boolean isFrameworkAnimation, IAnimationListener listener)
          Starts playing an given animation on a given object.
 void dispose()
          Discards the layout.
 java.util.Map<java.lang.String,java.lang.String> getDefaultProperties(java.lang.Object viewObject)
          Returns a map of (XML attribute name, attribute value) containing only default attribute values, for the given view Object.
 java.awt.image.BufferedImage getImage()
          Returns the rendering of the full layout.
 Result getProperty(java.lang.Object objectView, java.lang.String propertyName)
          returns the value of a given property on a given object.
 Result getResult()
          Returns the last operation result.
 java.util.List<ViewInfo> getRootViews()
          Returns the ViewInfo objects for the top level views.
 Result insertChild(java.lang.Object parentView, ILayoutPullParser childXml, int index, IAnimationListener listener)
          Inserts a new child in a ViewGroup object, and renders the result.
 boolean isAlphaChannelImage()
          Returns true if the current image alpha channel is relevant.
 Result moveChild(java.lang.Object parentView, java.lang.Object childView, int index, java.util.Map<java.lang.String,java.lang.String> layoutParams, IAnimationListener listener)
          Move a new child to a different ViewGroup object.
 Result removeChild(java.lang.Object childView, IAnimationListener listener)
          Removes a child from a ViewGroup object.
 Result render()
          Re-renders the layout as-is.
 Result render(long timeout)
          Re-renders the layout as-is, with a given timeout in case other renderings are being done.
 Result setProperty(java.lang.Object objectView, java.lang.String propertyName, java.lang.String propertyValue)
          Sets the value of a given property on a given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RenderSession

public RenderSession()
Method Detail

getResult

public Result getResult()
Returns the last operation result.


getRootViews

public java.util.List<ViewInfo> getRootViews()
Returns the ViewInfo objects for the top level views.

In most case the list will only contain one item. If the top level node is merge though then it will contain all the items under the merge tag.

This is reset to a new instance every time render() is called and can be null if the call failed (and the method returned a Result with Result.Status.ERROR_UNKNOWN or Result.Status.NOT_IMPLEMENTED.

This can be safely modified by the caller.

Returns:
the list of ViewInfo or null if there aren't any.

getImage

public java.awt.image.BufferedImage getImage()
Returns the rendering of the full layout.

This is reset to a new instance every time render() is called and can be null if the call failed (and the method returned a Result with Result.Status.ERROR_UNKNOWN or Result.Status.NOT_IMPLEMENTED.

This can be safely modified by the caller.


isAlphaChannelImage

public boolean isAlphaChannelImage()
Returns true if the current image alpha channel is relevant.

Returns:
whether the image alpha channel is relevant.

getDefaultProperties

public java.util.Map<java.lang.String,java.lang.String> getDefaultProperties(java.lang.Object viewObject)
Returns a map of (XML attribute name, attribute value) containing only default attribute values, for the given view Object.

Parameters:
viewObject - the view object.
Returns:
a map of the default property values or null.

render

public Result render()
Re-renders the layout as-is. In case of success, this should be followed by calls to getRootViews() and getImage() to access the result of the rendering. This is equivalent to calling render(SceneParams.DEFAULT_TIMEOUT)

Returns:
a Result indicating the status of the action.

render

public Result render(long timeout)
Re-renders the layout as-is, with a given timeout in case other renderings are being done. In case of success, this should be followed by calls to getRootViews() and getImage() to access the result of the rendering. The Bridge is only able to inflate or render one layout at a time. There is an internal lock object whenever such an action occurs. The timeout parameter is used when attempting to acquire the lock. If the timeout expires, the method will return Result.Status.ERROR_TIMEOUT.

Parameters:
timeout - timeout for the rendering, in milliseconds.
Returns:
a Result indicating the status of the action.

setProperty

public Result setProperty(java.lang.Object objectView,
                          java.lang.String propertyName,
                          java.lang.String propertyValue)
Sets the value of a given property on a given object.

This does nothing more than change the property. To render the scene in its new state, a call to render() is required.

Any amount of actions can be taken on the scene before render() is called.

Parameters:
objectView -
propertyName -
propertyValue -
Returns:
a Result indicating the status of the action.
Throws:
java.lang.IllegalArgumentException - if the view object is not an android.view.View

getProperty

public Result getProperty(java.lang.Object objectView,
                          java.lang.String propertyName)
returns the value of a given property on a given object.

This returns a Result object. If the operation of querying the object for its property was successful (check Result.isSuccess()), then the property value is set in the result and can be accessed through Result.getData().

Parameters:
objectView -
propertyName -
Returns:
a Result indicating the status of the action.
Throws:
java.lang.IllegalArgumentException - if the view object is not an android.view.View

insertChild

public Result insertChild(java.lang.Object parentView,
                          ILayoutPullParser childXml,
                          int index,
                          IAnimationListener listener)
Inserts a new child in a ViewGroup object, and renders the result.

The child is first inflated and then added to its new parent, at the given index position. If the index is -1 then the child is added at the end of the parent.

If an animation listener is passed then the rendering is done asynchronously and the result is sent to the listener. If the listener is null, then the rendering is done synchronously.

The child stays in the view hierarchy after the rendering is done. To remove it call removeChild(Object, IAnimationListener)

The returned Result object will contain the android.view.View object for the newly inflated child. It is accessible through Result.getData().

Parameters:
parentView - the parent View object to receive the new child.
childXml - an ILayoutPullParser containing the content of the new child, including ViewGroup.LayoutParams attributes.
index - the index at which position to add the new child into the parent. -1 means at the end.
listener - an optional IAnimationListener.
Returns:
a Result indicating the status of the action.

moveChild

public Result moveChild(java.lang.Object parentView,
                        java.lang.Object childView,
                        int index,
                        java.util.Map<java.lang.String,java.lang.String> layoutParams,
                        IAnimationListener listener)
Move a new child to a different ViewGroup object.

The child is first removed from its current parent, and then added to its new parent, at the given index position. In case the parentView is the current parent of childView then the index must be the value with the childView removed from its parent. If the index is -1 then the child is added at the end of the parent.

If an animation listener is passed then the rendering is done asynchronously and the result is sent to the listener. If the listener is null, then the rendering is done synchronously.

The child stays in the view hierarchy after the rendering is done. To remove it call removeChild(Object, IAnimationListener)

The returned Result object will contain the android.view.ViewGroup.LayoutParams object created from the layoutParams map if it was non null.

Parameters:
parentView - the parent View object to receive the child. Can be the current parent already.
childView - the view to move.
index - the index at which position to add the new child into the parent. -1 means at the end.
layoutParams - an optional map of new ViewGroup.LayoutParams attribute. If non null, then the current layout params of the view will be removed and a new one will be inflated and set with the content of the map.
listener - an optional IAnimationListener.
Returns:
a Result indicating the status of the action.

removeChild

public Result removeChild(java.lang.Object childView,
                          IAnimationListener listener)
Removes a child from a ViewGroup object.

This does nothing more than change the layout. To render the scene in its new state, a call to render() is required.

Any amount of actions can be taken on the scene before render() is called.

Parameters:
childView - the view object to remove from its parent
listener - an optional IAnimationListener.
Returns:
a Result indicating the status of the action.

animate

public Result animate(java.lang.Object targetObject,
                      java.lang.String animationName,
                      boolean isFrameworkAnimation,
                      IAnimationListener listener)
Starts playing an given animation on a given object.

The animation playback is asynchronous and the rendered frame is sent vi the listener.

Parameters:
targetObject - the view object to animate
animationName - the name of the animation (res/anim) to play.
listener - the listener callback.
Returns:
a Result indicating the status of the action.

dispose

public void dispose()
Discards the layout. No more actions can be called on this object.