Search in sources :

Example 26 with SessionParams

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

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 27 with SessionParams

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

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 28 with SessionParams

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

the class RenderSessionImpl method inflate.

/**
     * Inflates the layout.
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #init(long)} was not called.
     */
public Result inflate() {
    checkLock();
    try {
        mViewRoot = new Layout(mLayoutBuilder);
        // Done with the builder.
        mLayoutBuilder = null;
        mContentRoot = ((Layout) mViewRoot).getContentRoot();
        SessionParams params = getParams();
        BridgeContext context = getContext();
        // Sets the project callback (custom view loader) to the fragment delegate so that
        // it can instantiate the custom Fragment.
        Fragment_Delegate.setLayoutlibCallback(params.getLayoutlibCallback());
        String rootTag = params.getFlag(RenderParamsFlags.FLAG_KEY_ROOT_TAG);
        boolean isPreference = "PreferenceScreen".equals(rootTag);
        View view;
        if (isPreference) {
            view = Preference_Delegate.inflatePreference(getContext(), mBlockParser, mContentRoot);
        } else {
            view = mInflater.inflate(mBlockParser, mContentRoot);
        }
        // done with the parser, pop it.
        context.popParser();
        Fragment_Delegate.setLayoutlibCallback(null);
        // set the AttachInfo on the root view.
        AttachInfo_Accessor.setAttachInfo(mViewRoot);
        // post-inflate process. For now this supports TabHost/TabWidget
        postInflateProcess(view, params.getLayoutlibCallback(), isPreference ? view : null);
        mInflater.onDoneInflation();
        setActiveToolbar(view, context, params);
        measure(params);
        measureView(mViewRoot, null, /*measuredView*/
        mMeasuredScreenWidth, MeasureSpec.EXACTLY, mMeasuredScreenHeight, MeasureSpec.EXACTLY);
        mViewRoot.layout(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
        mSystemViewInfoList = visitAllChildren(mViewRoot, 0, params.getExtendedViewInfoMode(), false);
        return SUCCESS.createResult();
    } catch (PostInflateException e) {
        return ERROR_INFLATION.createResult(e.getMessage(), e);
    } catch (Throwable e) {
        // get the real cause of the exception.
        Throwable t = e;
        while (t.getCause() != null) {
            t = t.getCause();
        }
        return ERROR_INFLATION.createResult(t.getMessage(), t);
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) LinearLayout(android.widget.LinearLayout) FrameLayout(android.widget.FrameLayout) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView)

Example 29 with SessionParams

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

the class RenderSessionImpl method postInflateProcess.

/**
     * Post process on a view hierarchy that was just inflated.
     * <p/>
     * At the moment this only supports TabHost: If {@link TabHost} is detected, look for the
     * {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
     * based on the content of the {@link FrameLayout}.
     * @param view the root view to process.
     * @param layoutlibCallback callback to the project.
     * @param skip the view and it's children are not processed.
     */
// For the use of Pair
@SuppressWarnings("deprecation")
private void postInflateProcess(View view, LayoutlibCallback layoutlibCallback, View skip) throws PostInflateException {
    if (view == skip) {
        return;
    }
    if (view instanceof TabHost) {
        setupTabHost((TabHost) view, layoutlibCallback);
    } else if (view instanceof QuickContactBadge) {
        QuickContactBadge badge = (QuickContactBadge) view;
        badge.setImageToDefault();
    } else if (view instanceof AdapterView<?>) {
        // get the view ID.
        int id = view.getId();
        BridgeContext context = getContext();
        // get a ResourceReference from the integer ID.
        ResourceReference listRef = context.resolveId(id);
        if (listRef != null) {
            SessionParams params = getParams();
            AdapterBinding binding = params.getAdapterBindings().get(listRef);
            // if there was no adapter binding, trying to get it from the call back.
            if (binding == null) {
                binding = layoutlibCallback.getAdapterBinding(listRef, context.getViewKey(view), view);
            }
            if (binding != null) {
                if (view instanceof AbsListView) {
                    if ((binding.getFooterCount() > 0 || binding.getHeaderCount() > 0) && view instanceof ListView) {
                        ListView list = (ListView) view;
                        boolean skipCallbackParser = false;
                        int count = binding.getHeaderCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getHeaderAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addHeaderView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                        count = binding.getFooterCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getFooterAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addFooterView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                    }
                    if (view instanceof ExpandableListView) {
                        ((ExpandableListView) view).setAdapter(new FakeExpandableAdapter(listRef, binding, layoutlibCallback));
                    } else {
                        ((AbsListView) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                    }
                } else if (view instanceof AbsSpinner) {
                    ((AbsSpinner) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                }
            }
        }
    } else if (view instanceof ViewGroup) {
        mInflater.postInflateProcess(view);
        ViewGroup group = (ViewGroup) view;
        final int count = group.getChildCount();
        for (int c = 0; c < count; c++) {
            View child = group.getChildAt(c);
            postInflateProcess(child, layoutlibCallback, skip);
        }
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) AbsListView(android.widget.AbsListView) FakeAdapter(com.android.layoutlib.bridge.impl.binding.FakeAdapter) FakeExpandableAdapter(com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) QuickContactBadge(android.widget.QuickContactBadge) AdapterBinding(com.android.ide.common.rendering.api.AdapterBinding) AbsSpinner(android.widget.AbsSpinner) AdapterView(android.widget.AdapterView) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) ExpandableListView(android.widget.ExpandableListView)

Example 30 with SessionParams

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

the class Main method testExpand.

/** Test expand_layout.xml */
@Test
public void testExpand() throws ClassNotFoundException {
    // Create the layout pull parser.
    LayoutPullParser parser = createLayoutPullParser("expand_vert_layout.xml");
    // Create LayoutLibCallback.
    LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(getLogger());
    layoutLibCallback.initResources();
    ConfigGenerator customConfigGenerator = new ConfigGenerator().setScreenWidth(300).setScreenHeight(20).setDensity(Density.XHIGH).setNavigation(Navigation.NONAV);
    SessionParams params = getSessionParams(parser, customConfigGenerator, layoutLibCallback, "Theme.Material.Light.NoActionBar.Fullscreen", false, RenderingMode.V_SCROLL, 22);
    renderAndVerify(params, "expand_vert_layout.png");
    customConfigGenerator = new ConfigGenerator().setScreenWidth(20).setScreenHeight(300).setDensity(Density.XHIGH).setNavigation(Navigation.NONAV);
    parser = createLayoutPullParser("expand_horz_layout.xml");
    params = getSessionParams(parser, customConfigGenerator, layoutLibCallback, "Theme.Material.Light.NoActionBar.Fullscreen", false, RenderingMode.H_SCROLL, 22);
    renderAndVerify(params, "expand_horz_layout.png");
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) ConfigGenerator(com.android.layoutlib.bridge.intensive.setup.ConfigGenerator) LayoutLibTestCallback(com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback) LayoutPullParser(com.android.layoutlib.bridge.intensive.setup.LayoutPullParser) Test(org.junit.Test)

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