Home | History | Annotate | Download | only in api
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.common.rendering.api;
     18 
     19 import static com.android.ide.common.rendering.api.Result.Status.NOT_IMPLEMENTED;
     20 
     21 import com.android.ide.common.rendering.api.Result.Status;
     22 
     23 import java.awt.image.BufferedImage;
     24 import java.util.List;
     25 import java.util.Map;
     26 
     27 /**
     28  * An object allowing interaction with an Android layout.
     29  *
     30  * This is returned by {@link Bridge#createScene(RenderParams)}.
     31  * and can then be used for subsequent actions on the layout.
     32  *
     33  * @since 5
     34  *
     35  */
     36 public class RenderSession {
     37 
     38     /**
     39      * Returns the last operation result.
     40      */
     41     public Result getResult() {
     42         return NOT_IMPLEMENTED.createResult();
     43     }
     44 
     45     /**
     46      * Returns the {@link ViewInfo} objects for the top level views.
     47      * <p/>
     48      * In most case the list will only contain one item. If the top level node is {@code merge}
     49      * though then it will contain all the items under the {@code merge} tag.
     50      * <p/>
     51      * This is reset to a new instance every time {@link #render()} is called and can be
     52      * <code>null</code> if the call failed (and the method returned a {@link Result} with
     53      * {@link Status#ERROR_UNKNOWN} or {@link Status#NOT_IMPLEMENTED}.
     54      * <p/>
     55      * This can be safely modified by the caller.
     56      *
     57      * @return the list of {@link ViewInfo} or null if there aren't any.
     58      */
     59     public List<ViewInfo> getRootViews() {
     60         return null;
     61     }
     62 
     63     /**
     64      * Returns the rendering of the full layout.
     65      * <p>
     66      * This is reset to a new instance every time {@link #render()} is called and can be
     67      * <code>null</code> if the call failed (and the method returned a {@link Result} with
     68      * {@link Status#ERROR_UNKNOWN} or {@link Status#NOT_IMPLEMENTED}.
     69      * <p/>
     70      * This can be safely modified by the caller.
     71      */
     72     public BufferedImage getImage() {
     73         return null;
     74     }
     75 
     76     /**
     77      * Returns true if the current image alpha channel is relevant.
     78      *
     79      * @return whether the image alpha channel is relevant.
     80      */
     81     public boolean isAlphaChannelImage() {
     82         return true;
     83     }
     84 
     85     /**
     86      * Returns a map of (XML attribute name, attribute value) containing only default attribute
     87      * values, for the given view Object.
     88      * @param viewObject the view object.
     89      * @return a map of the default property values or null.
     90      */
     91     public Map<String, String> getDefaultProperties(Object viewObject) {
     92         return null;
     93     }
     94 
     95     /**
     96      * Re-renders the layout as-is.
     97      * In case of success, this should be followed by calls to {@link #getRootView()} and
     98      * {@link #getImage()} to access the result of the rendering.
     99      *
    100      * This is equivalent to calling <code>render(SceneParams.DEFAULT_TIMEOUT)</code>
    101      *
    102      * @return a {@link Result} indicating the status of the action.
    103      */
    104     public Result render() {
    105         return render(RenderParams.DEFAULT_TIMEOUT);
    106     }
    107 
    108     /**
    109      * Re-renders the layout as-is, with a given timeout in case other renderings are being done.
    110      * In case of success, this should be followed by calls to {@link #getRootView()} and
    111      * {@link #getImage()} to access the result of the rendering.
    112      *
    113      * The {@link Bridge} is only able to inflate or render one layout at a time. There
    114      * is an internal lock object whenever such an action occurs. The timeout parameter is used
    115      * when attempting to acquire the lock. If the timeout expires, the method will return
    116      * {@link Status#ERROR_TIMEOUT}.
    117      *
    118      * @param timeout timeout for the rendering, in milliseconds.
    119      *
    120      * @return a {@link Result} indicating the status of the action.
    121      */
    122     public Result render(long timeout) {
    123         return NOT_IMPLEMENTED.createResult();
    124     }
    125 
    126     /**
    127      * Sets the value of a given property on a given object.
    128      * <p/>
    129      * This does nothing more than change the property. To render the scene in its new state, a
    130      * call to {@link #render()} is required.
    131      * <p/>
    132      * Any amount of actions can be taken on the scene before {@link #render()} is called.
    133      *
    134      * @param objectView
    135      * @param propertyName
    136      * @param propertyValue
    137      *
    138      * @return a {@link Result} indicating the status of the action.
    139      *
    140      * @throws IllegalArgumentException if the view object is not an android.view.View
    141      */
    142     public Result setProperty(Object objectView, String propertyName, String propertyValue) {
    143         return NOT_IMPLEMENTED.createResult();
    144     }
    145 
    146     /**
    147      * returns the value of a given property on a given object.
    148      * <p/>
    149      * This returns a {@link Result} object. If the operation of querying the object for its
    150      * property was successful (check {@link Result#isSuccess()}), then the property value
    151      * is set in the result and can be accessed through {@link Result#getData()}.
    152      *
    153      * @param objectView
    154      * @param propertyName
    155      *
    156      * @return a {@link Result} indicating the status of the action.
    157      *
    158      * @throws IllegalArgumentException if the view object is not an android.view.View
    159      */
    160     public Result getProperty(Object objectView, String propertyName) {
    161         return NOT_IMPLEMENTED.createResult();
    162     }
    163 
    164     /**
    165      * Inserts a new child in a ViewGroup object, and renders the result.
    166      * <p/>
    167      * The child is first inflated and then added to its new parent, at the given <var>index<var>
    168      * position. If the <var>index</var> is -1 then the child is added at the end of the parent.
    169      * <p/>
    170      * If an animation listener is passed then the rendering is done asynchronously and the
    171      * result is sent to the listener.
    172      * If the listener is null, then the rendering is done synchronously.
    173      * <p/>
    174      * The child stays in the view hierarchy after the rendering is done. To remove it call
    175      * {@link #removeChild(Object, IAnimationListener)}
    176      * <p/>
    177      * The returned {@link Result} object will contain the android.view.View object for
    178      * the newly inflated child. It is accessible through {@link Result#getData()}.
    179      *
    180      * @param parentView the parent View object to receive the new child.
    181      * @param childXml an {@link ILayoutPullParser} containing the content of the new child,
    182      *             including ViewGroup.LayoutParams attributes.
    183      * @param index the index at which position to add the new child into the parent. -1 means at
    184      *             the end.
    185      * @param listener an optional {@link IAnimationListener}.
    186      *
    187      * @return a {@link Result} indicating the status of the action.
    188      */
    189     public Result insertChild(Object parentView, ILayoutPullParser childXml, int index,
    190             IAnimationListener listener) {
    191         return NOT_IMPLEMENTED.createResult();
    192     }
    193 
    194     /**
    195      * Move a new child to a different ViewGroup object.
    196      * <p/>
    197      * The child is first removed from its current parent, and then added to its new parent, at the
    198      * given <var>index<var> position. In case the <var>parentView</var> is the current parent of
    199      * <var>childView</var> then the index must be the value with the <var>childView</var> removed
    200      * from its parent. If the <var>index</var> is -1 then the child is added at the end of
    201      * the parent.
    202      * <p/>
    203      * If an animation listener is passed then the rendering is done asynchronously and the
    204      * result is sent to the listener.
    205      * If the listener is null, then the rendering is done synchronously.
    206      * <p/>
    207      * The child stays in the view hierarchy after the rendering is done. To remove it call
    208      * {@link #removeChild(Object, IAnimationListener)}
    209      * <p/>
    210      * The returned {@link Result} object will contain the android.view.ViewGroup.LayoutParams
    211      * object created from the <var>layoutParams</var> map if it was non <code>null</code>.
    212      *
    213      * @param parentView the parent View object to receive the child. Can be the current parent
    214      *             already.
    215      * @param childView the view to move.
    216      * @param index the index at which position to add the new child into the parent. -1 means at
    217      *             the end.
    218      * @param layoutParams an optional map of new ViewGroup.LayoutParams attribute. If non null,
    219      *             then the current layout params of the view will be removed and a new one will
    220      *             be inflated and set with the content of the map.
    221      * @param listener an optional {@link IAnimationListener}.
    222      *
    223      * @return a {@link Result} indicating the status of the action.
    224      */
    225     public Result moveChild(Object parentView, Object childView, int index,
    226             Map<String, String> layoutParams, IAnimationListener listener) {
    227         return NOT_IMPLEMENTED.createResult();
    228     }
    229 
    230     /**
    231      * Removes a child from a ViewGroup object.
    232      * <p/>
    233      * This does nothing more than change the layout. To render the scene in its new state, a
    234      * call to {@link #render()} is required.
    235      * <p/>
    236      * Any amount of actions can be taken on the scene before {@link #render()} is called.
    237      *
    238      * @param childView the view object to remove from its parent
    239      * @param listener an optional {@link IAnimationListener}.
    240      *
    241      * @return a {@link Result} indicating the status of the action.
    242      */
    243     public Result removeChild(Object childView, IAnimationListener listener) {
    244         return NOT_IMPLEMENTED.createResult();
    245     }
    246 
    247     /**
    248      * Starts playing an given animation on a given object.
    249      * <p/>
    250      * The animation playback is asynchronous and the rendered frame is sent vi the
    251      * <var>listener</var>.
    252      *
    253      * @param targetObject the view object to animate
    254      * @param animationName the name of the animation (res/anim) to play.
    255      * @param listener the listener callback.
    256      *
    257      * @return a {@link Result} indicating the status of the action.
    258      */
    259     public Result animate(Object targetObject, String animationName,
    260             boolean isFrameworkAnimation, IAnimationListener listener) {
    261         return NOT_IMPLEMENTED.createResult();
    262     }
    263 
    264     /**
    265      * Discards the layout. No more actions can be called on this object.
    266      */
    267     public void dispose() {
    268     }
    269 }
    270