Search in sources :

Example 41 with SessionParams

use of com.android.ide.common.rendering.api.SessionParams in project android_frameworks_base by AOSPA.

the class Main method testVectorDrawable.

/**
     * Test a vector drawable that uses trimStart and trimEnd. It also tests all the primitives
     * for vector drawables (lines, moves and cubic and quadratic curves).
     */
@Test
public void testVectorDrawable() throws ClassNotFoundException {
    // Create the layout pull parser.
    LayoutPullParser parser = createLayoutPullParser("vector_drawable.xml");
    // Create LayoutLibCallback.
    LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(getLogger());
    layoutLibCallback.initResources();
    SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, layoutLibCallback, "Theme.Material.NoActionBar.Fullscreen", false, RenderingMode.V_SCROLL, 22);
    renderAndVerify(params, "vector_drawable.png", TimeUnit.SECONDS.toNanos(2));
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) LayoutLibTestCallback(com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback) LayoutPullParser(com.android.layoutlib.bridge.intensive.setup.LayoutPullParser) Test(org.junit.Test)

Example 42 with SessionParams

use of com.android.ide.common.rendering.api.SessionParams in project android_frameworks_base by AOSPA.

the class Main method testGetResourceNameVariants.

@Test
public void testGetResourceNameVariants() throws Exception {
    // Setup
    SessionParams params = createSessionParams("", ConfigGenerator.NEXUS_4);
    AssetManager assetManager = AssetManager.getSystem();
    DisplayMetrics metrics = new DisplayMetrics();
    Configuration configuration = RenderAction.getConfiguration(params);
    Resources resources = new Resources(assetManager, metrics, configuration);
    resources.mLayoutlibCallback = params.getLayoutlibCallback();
    resources.mContext = new BridgeContext(params.getProjectKey(), metrics, params.getResources(), params.getAssets(), params.getLayoutlibCallback(), configuration, params.getTargetSdkVersion(), params.isRtlSupported());
    // Test
    assertEquals("android:style/ButtonBar", resources.getResourceName(android.R.style.ButtonBar));
    assertEquals("android", resources.getResourcePackageName(android.R.style.ButtonBar));
    assertEquals("ButtonBar", resources.getResourceEntryName(android.R.style.ButtonBar));
    assertEquals("style", resources.getResourceTypeName(android.R.style.ButtonBar));
    int id = resources.mLayoutlibCallback.getResourceId(ResourceType.STRING, "app_name");
    assertEquals("com.android.layoutlib.test.myapplication:string/app_name", resources.getResourceName(id));
    assertEquals("com.android.layoutlib.test.myapplication", resources.getResourcePackageName(id));
    assertEquals("string", resources.getResourceTypeName(id));
    assertEquals("app_name", resources.getResourceEntryName(id));
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) AssetManager(android.content.res.AssetManager) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(android.content.res.Configuration) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) FrameworkResources(com.android.ide.common.resources.FrameworkResources) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics) Test(org.junit.Test)

Example 43 with SessionParams

use of com.android.ide.common.rendering.api.SessionParams in project android_frameworks_base by AOSPA.

the class Main method getSessionParams.

/**
     * Uses Theme.Material and Target sdk version as 22.
     */
private SessionParams getSessionParams(LayoutPullParser layoutParser, ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback, String themeName, boolean isProjectTheme, RenderingMode renderingMode, int targetSdk) {
    FolderConfiguration config = configGenerator.getFolderConfig();
    ResourceResolver resourceResolver = ResourceResolver.create(sProjectResources.getConfiguredResources(config), sFrameworkRepo.getConfiguredResources(config), themeName, isProjectTheme);
    SessionParams sessionParams = new SessionParams(layoutParser, renderingMode, null, /*used for caching*/
    configGenerator.getHardwareConfig(), resourceResolver, layoutLibCallback, 0, targetSdk, getLayoutLog());
    sessionParams.setFlag(RenderParamsFlags.FLAG_DO_NOT_RENDER_ON_CREATE, true);
    return sessionParams;
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) ResourceResolver(com.android.ide.common.resources.ResourceResolver) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 44 with SessionParams

use of com.android.ide.common.rendering.api.SessionParams in project android_frameworks_base by ResurrectionRemix.

the class RenderSessionImpl method init.

/**
     * Initializes and acquires the scene, creating various Android objects such as context,
     * inflater, and parser.
     *
     * @param timeout the time to wait if another rendering is happening.
     *
     * @return whether the scene was prepared
     *
     * @see #acquire(long)
     * @see #release()
     */
@Override
public Result init(long timeout) {
    Result result = super.init(timeout);
    if (!result.isSuccess()) {
        return result;
    }
    SessionParams params = getParams();
    BridgeContext context = getContext();
    // use default of true in case it's not found to use alpha by default
    mIsAlphaChannelImage = ResourceHelper.getBooleanThemeValue(params.getResources(), "windowIsFloating", true, true);
    mLayoutBuilder = new Layout.Builder(params, context);
    // FIXME: find those out, and possibly add them to the render params
    boolean hasNavigationBar = true;
    //noinspection ConstantConditions
    IWindowManager iwm = new IWindowManagerImpl(getContext().getConfiguration(), context.getMetrics(), Surface.ROTATION_0, hasNavigationBar);
    WindowManagerGlobal_Delegate.setWindowManagerService(iwm);
    // build the inflater and parser.
    mInflater = new BridgeInflater(context, params.getLayoutlibCallback());
    context.setBridgeInflater(mInflater);
    mBlockParser = new BridgeXmlBlockParser(params.getLayoutDescription(), context, false);
    return SUCCESS.createResult();
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) BridgeInflater(android.view.BridgeInflater) LinearLayout(android.widget.LinearLayout) FrameLayout(android.widget.FrameLayout) IWindowManager(android.view.IWindowManager) IWindowManagerImpl(android.view.IWindowManagerImpl) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser) Result(com.android.ide.common.rendering.api.Result)

Example 45 with SessionParams

use of com.android.ide.common.rendering.api.SessionParams in project android_frameworks_base by ResurrectionRemix.

the class RenderSessionImpl method render.

/**
     * Renders the scene.
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @param freshRender whether the render is a new one and should erase the existing bitmap (in
     *      the case where bitmaps are reused). This is typically needed when not playing
     *      animations.)
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #acquire(long)} was not called.
     *
     * @see SessionParams#getRenderingMode()
     * @see RenderSession#render(long)
     */
public Result render(boolean freshRender) {
    checkLock();
    SessionParams params = getParams();
    try {
        if (mViewRoot == null) {
            return ERROR_NOT_INFLATED.createResult();
        }
        measure(params);
        HardwareConfig hardwareConfig = params.getHardwareConfig();
        Result renderResult = SUCCESS.createResult();
        if (params.isLayoutOnly()) {
            // delete the canvas and image to reset them on the next full rendering
            mImage = null;
            mCanvas = null;
        } else {
            // draw the views
            // create the BufferedImage into which the layout will be rendered.
            boolean newImage = false;
            // When disableBitmapCaching is true, we do not reuse mImage and
            // we create a new one in every render.
            // This is useful when mImage is just a wrapper of Graphics2D so
            // it doesn't get cached.
            boolean disableBitmapCaching = Boolean.TRUE.equals(params.getFlag(RenderParamsFlags.FLAG_KEY_DISABLE_BITMAP_CACHING));
            if (mNewRenderSize || mCanvas == null || disableBitmapCaching) {
                mNewRenderSize = false;
                if (params.getImageFactory() != null) {
                    mImage = params.getImageFactory().getImage(mMeasuredScreenWidth, mMeasuredScreenHeight);
                } else {
                    mImage = new BufferedImage(mMeasuredScreenWidth, mMeasuredScreenHeight, BufferedImage.TYPE_INT_ARGB);
                    newImage = true;
                }
                if (params.isBgColorOverridden()) {
                    // since we override the content, it's the same as if it was a new image.
                    newImage = true;
                    Graphics2D gc = mImage.createGraphics();
                    gc.setColor(new Color(params.getOverrideBgColor(), true));
                    gc.setComposite(AlphaComposite.Src);
                    gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
                    gc.dispose();
                }
                // create an Android bitmap around the BufferedImage
                Bitmap bitmap = Bitmap_Delegate.createBitmap(mImage, true, /*isMutable*/
                hardwareConfig.getDensity());
                if (mCanvas == null) {
                    // create a Canvas around the Android bitmap
                    mCanvas = new Canvas(bitmap);
                } else {
                    mCanvas.setBitmap(bitmap);
                }
                mCanvas.setDensity(hardwareConfig.getDensity().getDpiValue());
            }
            if (freshRender && !newImage) {
                Graphics2D gc = mImage.createGraphics();
                gc.setComposite(AlphaComposite.Src);
                gc.setColor(new Color(0x00000000, true));
                gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
                // done
                gc.dispose();
            }
            if (mElapsedFrameTimeNanos >= 0) {
                long initialTime = System_Delegate.nanoTime();
                if (!mFirstFrameExecuted) {
                    // We need to run an initial draw call to initialize the animations
                    render(getContext(), mViewRoot, NOP_CANVAS, mMeasuredScreenWidth, mMeasuredScreenHeight);
                    // The first frame will initialize the animations
                    Choreographer_Delegate.doFrame(initialTime);
                    mFirstFrameExecuted = true;
                }
                // Second frame will move the animations
                Choreographer_Delegate.doFrame(initialTime + mElapsedFrameTimeNanos);
            }
            renderResult = render(getContext(), mViewRoot, mCanvas, mMeasuredScreenWidth, mMeasuredScreenHeight);
        }
        mSystemViewInfoList = visitAllChildren(mViewRoot, 0, params.getExtendedViewInfoMode(), false);
        // success!
        return renderResult;
    } catch (Throwable e) {
        // get the real cause of the exception.
        Throwable t = e;
        while (t.getCause() != null) {
            t = t.getCause();
        }
        return ERROR_UNKNOWN.createResult(t.getMessage(), t);
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) Bitmap(android.graphics.Bitmap) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) Color(java.awt.Color) Canvas(android.graphics.Canvas) NopCanvas(com.android.layoutlib.bridge.android.graphics.NopCanvas) BufferedImage(java.awt.image.BufferedImage) Result(com.android.ide.common.rendering.api.Result) Graphics2D(java.awt.Graphics2D)

Aggregations

SessionParams (com.android.ide.common.rendering.api.SessionParams)54 Test (org.junit.Test)25 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)23 LayoutLibTestCallback (com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback)20 LayoutPullParser (com.android.layoutlib.bridge.intensive.setup.LayoutPullParser)20 View (android.view.View)12 AbsListView (android.widget.AbsListView)12 AdapterView (android.widget.AdapterView)12 ExpandableListView (android.widget.ExpandableListView)12 ListView (android.widget.ListView)12 Result (com.android.ide.common.rendering.api.Result)11 ActionMenuView (android.widget.ActionMenuView)10 FrameLayout (android.widget.FrameLayout)10 LinearLayout (android.widget.LinearLayout)10 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)10 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)10 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)10 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)10 MenuView (com.android.internal.view.menu.MenuView)10 ViewGroup (android.view.ViewGroup)7