Search in sources :

Example 26 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

the class MenuInflater_Delegate method registerMenu.

@LayoutlibDelegate
static /*package*/
void registerMenu(MenuInflater thisInflater, MenuItem menuItem, AttributeSet attrs) {
    if (menuItem instanceof BridgeMenuItemImpl) {
        Context context = thisInflater.getContext();
        context = BridgeContext.getBaseContext(context);
        if (context instanceof BridgeContext) {
            Object viewKey = BridgeInflater.getViewKeyFromParser(attrs, ((BridgeContext) context), null, false);
            ((BridgeMenuItemImpl) menuItem).setViewCookie(viewKey);
            return;
        }
    }
    // This means that Bridge did not take over the instantiation of some object properly.
    // This is most likely a bug in the LayoutLib code.
    Bridge.getLog().warning(LayoutLog.TAG_BROKEN, "Action Bar Menu rendering may be incorrect.", null);
}
Also used : BridgeMenuItemImpl(com.android.internal.view.menu.BridgeMenuItemImpl) Context(android.content.Context) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 27 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

the class RenderDrawable method render.

public Result render() {
    checkLock();
    // get the drawable resource value
    DrawableParams params = getParams();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ResourceValue drawableResource = params.getDrawable();
    // resolve it
    BridgeContext context = getContext();
    drawableResource = context.getRenderResources().resolveResValue(drawableResource);
    if (drawableResource == null) {
        return Status.ERROR_NOT_A_DRAWABLE.createResult();
    }
    ResourceType resourceType = drawableResource.getResourceType();
    if (resourceType != ResourceType.DRAWABLE && resourceType != ResourceType.MIPMAP) {
        return Status.ERROR_NOT_A_DRAWABLE.createResult();
    }
    Drawable d = ResourceHelper.getDrawable(drawableResource, context);
    final Boolean allStates = params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
    if (allStates == Boolean.TRUE) {
        final List<BufferedImage> result;
        if (d instanceof StateListDrawable) {
            result = new ArrayList<BufferedImage>();
            final StateListDrawable stateList = (StateListDrawable) d;
            for (int i = 0; i < stateList.getStateCount(); i++) {
                final Drawable stateDrawable = stateList.getStateDrawable(i);
                result.add(renderImage(hardwareConfig, stateDrawable, context));
            }
        } else {
            result = Collections.singletonList(renderImage(hardwareConfig, d, context));
        }
        return Status.SUCCESS.createResult(result);
    } else {
        BufferedImage image = renderImage(hardwareConfig, d, context);
        return Status.SUCCESS.createResult(image);
    }
}
Also used : HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceType(com.android.resources.ResourceType) StateListDrawable(android.graphics.drawable.StateListDrawable) BufferedImage(java.awt.image.BufferedImage) DrawableParams(com.android.ide.common.rendering.api.DrawableParams)

Example 28 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

the class AdapterHelper method getView.

@SuppressWarnings("deprecation")
static Pair<View, Boolean> getView(AdapterItem item, AdapterItem parentItem, ViewGroup parent, LayoutlibCallback callback, ResourceReference adapterRef, boolean skipCallbackParser) {
    // we don't care about recycling here because we never scroll.
    DataBindingItem dataBindingItem = item.getDataBindingItem();
    BridgeContext context = RenderAction.getCurrentContext();
    Pair<View, Boolean> pair = context.inflateView(dataBindingItem.getViewReference(), parent, false, /*attachToRoot*/
    skipCallbackParser);
    View view = pair.getFirst();
    skipCallbackParser |= pair.getSecond();
    if (view != null) {
        fillView(context, view, item, parentItem, callback, adapterRef);
    } else {
        // create a text view to display an error.
        TextView tv = new TextView(context);
        tv.setText("Unable to find layout: " + dataBindingItem.getViewReference().getName());
        view = tv;
    }
    return Pair.of(view, skipCallbackParser);
}
Also used : BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) DataBindingItem(com.android.ide.common.rendering.api.DataBindingItem) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 29 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

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 30 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

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)

Aggregations

BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)112 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)40 Context (android.content.Context)31 View (android.view.View)24 AdapterView (android.widget.AdapterView)24 RenderResources (com.android.ide.common.rendering.api.RenderResources)24 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)24 SessionParams (com.android.ide.common.rendering.api.SessionParams)23 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)20 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)20 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)20 AbsListView (android.widget.AbsListView)18 ExpandableListView (android.widget.ExpandableListView)18 ListView (android.widget.ListView)18 Result (com.android.ide.common.rendering.api.Result)18 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)17 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)16 ActionMenuView (android.widget.ActionMenuView)15 MenuView (com.android.internal.view.menu.MenuView)15 Drawable (android.graphics.drawable.Drawable)13