Search in sources :

Example 6 with BridgeContext

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

the class BaseAdapter method getView.

protected View getView(AdapterItem item, AdapterItem parentItem, View convertView, ViewGroup parent) {
    // 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*/
    mSkipCallbackParser);
    View view = pair.getFirst();
    mSkipCallbackParser |= pair.getSecond();
    if (view != null) {
        fillView(context, view, item, parentItem);
    } 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 view;
}
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 7 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project platform_frameworks_base by android.

the class Resources_Theme_Delegate method resolveStyle.

@Nullable
private static StyleResourceValue resolveStyle(int nativeResid) {
    if (nativeResid == 0) {
        return null;
    }
    BridgeContext context = RenderSessionImpl.getCurrentContext();
    ResourceReference theme = context.resolveId(nativeResid);
    if (theme.isFramework()) {
        return (StyleResourceValue) context.getRenderResources().getFrameworkResource(ResourceType.STYLE, theme.getName());
    } else {
        return (StyleResourceValue) context.getRenderResources().getProjectResource(ResourceType.STYLE, theme.getName());
    }
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) Nullable(android.annotation.Nullable)

Example 8 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project platform_frameworks_base by android.

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

use of com.android.layoutlib.bridge.android.BridgeContext in project platform_frameworks_base by android.

the class Bitmap_Delegate method createBitmap.

/**
     * Creates and returns a {@link Bitmap} initialized with the given file content.
     *
     * @param input the file from which to read the bitmap content
     * @param density the density associated with the bitmap
     *
     * @see Bitmap#isPremultiplied()
     * @see Bitmap#isMutable()
     * @see Bitmap#getDensity()
     */
private static Bitmap createBitmap(File input, Set<BitmapCreateFlags> createFlags, Density density) throws IOException {
    // create a delegate with the content of the file.
    BufferedImage image = ImageIO.read(input);
    if (image == null && input.exists()) {
        // There was a problem decoding the image, or the decoder isn't registered. Webp maybe.
        // Replace with a broken image icon.
        BridgeContext currentContext = RenderAction.getCurrentContext();
        if (currentContext != null) {
            RenderResources resources = currentContext.getRenderResources();
            ResourceValue broken = resources.getFrameworkResource(ResourceType.DRAWABLE, "ic_menu_report_image");
            File brokenFile = new File(broken.getValue());
            if (brokenFile.exists()) {
                image = ImageIO.read(brokenFile);
            }
        }
    }
    Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.ARGB_8888);
    return createBitmap(delegate, createFlags, density.getDpiValue());
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 10 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project platform_frameworks_base by android.

the class Preference_Delegate method getView.

@LayoutlibDelegate
static /*package*/
View getView(Preference pref, View convertView, ViewGroup parent) {
    Context context = pref.getContext();
    BridgeContext bc = context instanceof BridgeContext ? ((BridgeContext) context) : null;
    convertView = pref.getView_Original(convertView, parent);
    if (bc != null) {
        Object cookie = bc.getCookie(pref);
        if (cookie != null) {
            bc.addViewKey(convertView, cookie);
        }
    }
    return convertView;
}
Also used : 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)

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