Search in sources :

Example 31 with BridgeContext

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

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

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

the class CustomBar method setStyle.

protected void setStyle(String themeEntryName) {
    BridgeContext bridgeContext = getContext();
    RenderResources res = bridgeContext.getRenderResources();
    ResourceValue value = res.findItemInTheme(themeEntryName, true);
    value = res.resolveResValue(value);
    if (!(value instanceof StyleResourceValue)) {
        return;
    }
    StyleResourceValue style = (StyleResourceValue) value;
    // get the background
    ResourceValue backgroundValue = res.findItemInStyle(style, "background", true);
    backgroundValue = res.resolveResValue(backgroundValue);
    if (backgroundValue != null) {
        Drawable d = ResourceHelper.getDrawable(backgroundValue, bridgeContext);
        if (d != null) {
            setBackground(d);
        }
    }
    TextView textView = getStyleableTextView();
    if (textView != null) {
        // get the text style
        ResourceValue textStyleValue = res.findItemInStyle(style, "titleTextStyle", true);
        textStyleValue = res.resolveResValue(textStyleValue);
        if (textStyleValue instanceof StyleResourceValue) {
            StyleResourceValue textStyle = (StyleResourceValue) textStyleValue;
            ResourceValue textSize = res.findItemInStyle(textStyle, "textSize", true);
            textSize = res.resolveResValue(textSize);
            if (textSize != null) {
                TypedValue out = new TypedValue();
                if (ResourceHelper.parseFloatAttribute("textSize", textSize.getValue(), out, true)) {
                    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, out.getDimension(bridgeContext.getResources().getDisplayMetrics()));
                }
            }
            ResourceValue textColor = res.findItemInStyle(textStyle, "textColor", true);
            textColor = res.resolveResValue(textColor);
            if (textColor != null) {
                ColorStateList stateList = ResourceHelper.getColorStateList(textColor, bridgeContext);
                if (stateList != null) {
                    textView.setTextColor(stateList);
                }
            }
        }
    }
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) RenderResources(com.android.ide.common.rendering.api.RenderResources) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ColorStateList(android.content.res.ColorStateList) TextView(android.widget.TextView) TypedValue(android.util.TypedValue)

Example 33 with BridgeContext

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

the class BridgeInflater method setupViewInContext.

private void setupViewInContext(View view, AttributeSet attrs) {
    Context context = getContext();
    context = getBaseContext(context);
    if (context instanceof BridgeContext) {
        BridgeContext bc = (BridgeContext) context;
        // get the view key
        Object viewKey = getViewKeyFromParser(attrs, bc, mResourceReference, mIsInMerge);
        if (viewKey != null) {
            bc.addViewKey(view, viewKey);
        }
        String scrollPosX = attrs.getAttributeValue(BridgeConstants.NS_RESOURCES, "scrollX");
        if (scrollPosX != null && scrollPosX.endsWith("px")) {
            int value = Integer.parseInt(scrollPosX.substring(0, scrollPosX.length() - 2));
            bc.setScrollXPos(view, value);
        }
        String scrollPosY = attrs.getAttributeValue(BridgeConstants.NS_RESOURCES, "scrollY");
        if (scrollPosY != null && scrollPosY.endsWith("px")) {
            int value = Integer.parseInt(scrollPosY.substring(0, scrollPosY.length() - 2));
            bc.setScrollYPos(view, value);
        }
        if (ReflectionUtils.isInstanceOf(view, RecyclerViewUtil.CN_RECYCLER_VIEW)) {
            Integer resourceId = null;
            String attrVal = attrs.getAttributeValue(BridgeConstants.NS_TOOLS_URI, BridgeConstants.ATTR_LIST_ITEM);
            if (attrVal != null && !attrVal.isEmpty()) {
                ResourceValue resValue = bc.getRenderResources().findResValue(attrVal, false);
                if (resValue.isFramework()) {
                    resourceId = Bridge.getResourceId(resValue.getResourceType(), resValue.getName());
                } else {
                    resourceId = mLayoutlibCallback.getResourceId(resValue.getResourceType(), resValue.getName());
                }
            }
            if (resourceId == null) {
                resourceId = 0;
            }
            RecyclerViewUtil.setAdapter(view, bc, mLayoutlibCallback, resourceId);
        } else if (ReflectionUtils.isInstanceOf(view, DrawerLayoutUtil.CN_DRAWER_LAYOUT)) {
            String attrVal = attrs.getAttributeValue(BridgeConstants.NS_TOOLS_URI, BridgeConstants.ATTR_OPEN_DRAWER);
            if (attrVal != null) {
                getDrawerLayoutMap().put(view, attrVal);
            }
        }
    }
}
Also used : Context(android.content.Context) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) BridgeContext.getBaseContext(com.android.layoutlib.bridge.android.BridgeContext.getBaseContext) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext)

Example 34 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 35 with BridgeContext

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

the class BridgePreferenceInflater method onCreateItem.

@Override
protected Preference onCreateItem(String name, AttributeSet attrs) throws ClassNotFoundException {
    Object viewKey = null;
    BridgeContext bc = null;
    Context context = getContext();
    if (context instanceof BridgeContext) {
        bc = (BridgeContext) context;
    }
    if (attrs instanceof BridgeXmlBlockParser) {
        viewKey = ((BridgeXmlBlockParser) attrs).getViewCookie();
    }
    Preference preference = super.onCreateItem(name, attrs);
    if (viewKey != null && bc != null) {
        bc.addCookie(preference, viewKey);
    }
    return preference;
}
Also used : Context(android.content.Context) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser)

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