Search in sources :

Example 6 with RenderSessionImpl

use of com.android.layoutlib.bridge.impl.RenderSessionImpl in project android_frameworks_base by crdroidandroid.

the class Bridge method createSession.

/**
     * Starts a layout session by inflating and rendering it. The method returns a
     * {@link RenderSession} on which further actions can be taken.
     * <p/>
     * If {@link SessionParams} includes the {@link RenderParamsFlags#FLAG_DO_NOT_RENDER_ON_CREATE},
     * this method will only inflate the layout but will NOT render it.
     * @param params the {@link SessionParams} object with all the information necessary to create
     *           the scene.
     * @return a new {@link RenderSession} object that contains the result of the layout.
     * @since 5
     */
@Override
public RenderSession createSession(SessionParams params) {
    try {
        Result lastResult = SUCCESS.createResult();
        RenderSessionImpl scene = new RenderSessionImpl(params);
        try {
            prepareThread();
            lastResult = scene.init(params.getTimeout());
            if (lastResult.isSuccess()) {
                lastResult = scene.inflate();
                boolean doNotRenderOnCreate = Boolean.TRUE.equals(params.getFlag(RenderParamsFlags.FLAG_DO_NOT_RENDER_ON_CREATE));
                if (lastResult.isSuccess() && !doNotRenderOnCreate) {
                    lastResult = scene.render(true);
                }
            }
        } finally {
            scene.release();
            cleanupThread();
        }
        return new BridgeRenderSession(scene, lastResult);
    } catch (Throwable t) {
        // get the real cause of the exception.
        Throwable t2 = t;
        while (t2.getCause() != null) {
            t2 = t.getCause();
        }
        return new BridgeRenderSession(null, ERROR_UNKNOWN.createResult(t2.getMessage(), t));
    }
}
Also used : RenderSessionImpl(com.android.layoutlib.bridge.impl.RenderSessionImpl) Result(com.android.ide.common.rendering.api.Result)

Aggregations

Result (com.android.ide.common.rendering.api.Result)6 RenderSessionImpl (com.android.layoutlib.bridge.impl.RenderSessionImpl)6