Search in sources :

Example 36 with BridgeContext

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

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

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

the class AppCompatActionBar method getInflater.

@Override
protected LayoutInflater getInflater(BridgeContext context) {
    // Other than the resource resolution part, the code has been taken from the support
    // library. see code from line 269 onwards in
    // https://android.googlesource.com/platform/frameworks/support/+/android-5.1.0_r1/v7/appcompat/src/android/support/v7/app/ActionBarActivityDelegateBase.java
    Context themedContext = context;
    RenderResources resources = context.getRenderResources();
    ResourceValue actionBarTheme = resources.findItemInTheme("actionBarTheme", false);
    if (actionBarTheme != null) {
        // resolve it, if needed.
        actionBarTheme = resources.resolveResValue(actionBarTheme);
    }
    if (actionBarTheme instanceof StyleResourceValue) {
        int styleId = context.getDynamicIdByStyle(((StyleResourceValue) actionBarTheme));
        if (styleId != 0) {
            themedContext = new ContextThemeWrapper(context, styleId);
        }
    }
    return LayoutInflater.from(themedContext);
}
Also used : Context(android.content.Context) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ContextThemeWrapper(android.view.ContextThemeWrapper) RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue)

Example 38 with BridgeContext

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

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)

Example 39 with BridgeContext

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

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)

Example 40 with BridgeContext

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

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)

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