Search in sources :

Example 26 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ParanoidAndroid.

the class CustomBar method loadIcon.

protected Drawable loadIcon(int index, ResourceType type, String name) {
    BridgeContext bridgeContext = (BridgeContext) mContext;
    RenderResources res = bridgeContext.getRenderResources();
    // find the resource
    ResourceValue value = res.getFrameworkResource(type, name);
    // resolve it if needed
    value = res.resolveResValue(value);
    return loadIcon(index, value);
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext)

Example 27 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ParanoidAndroid.

the class CustomBar method setStyle.

protected void setStyle(String themeEntryName) {
    BridgeContext bridgeContext = (BridgeContext) mContext;
    RenderResources res = bridgeContext.getRenderResources();
    ResourceValue value = res.findItemInTheme(themeEntryName, true);
    value = res.resolveResValue(value);
    if (value instanceof StyleResourceValue == false) {
        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(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 28 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ParanoidAndroid.

the class RenderAction 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()
     */
public Result init(long timeout) {
    // acquire the lock. if the result is null, lock was just acquired, otherwise, return
    // the result.
    Result result = acquireLock(timeout);
    if (result != null) {
        return result;
    }
    HardwareConfig hardwareConfig = mParams.getHardwareConfig();
    // setup the display Metrics.
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.densityDpi = metrics.noncompatDensityDpi = hardwareConfig.getDensity().getDpiValue();
    metrics.density = metrics.noncompatDensity = metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT;
    metrics.scaledDensity = metrics.noncompatScaledDensity = metrics.density;
    metrics.widthPixels = metrics.noncompatWidthPixels = hardwareConfig.getScreenWidth();
    metrics.heightPixels = metrics.noncompatHeightPixels = hardwareConfig.getScreenHeight();
    metrics.xdpi = metrics.noncompatXdpi = hardwareConfig.getXdpi();
    metrics.ydpi = metrics.noncompatYdpi = hardwareConfig.getYdpi();
    RenderResources resources = mParams.getResources();
    // build the context
    mContext = new BridgeContext(mParams.getProjectKey(), metrics, resources, mParams.getProjectCallback(), getConfiguration(), mParams.getTargetSdkVersion());
    setUp();
    return SUCCESS.createResult();
}
Also used : HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) RenderResources(com.android.ide.common.rendering.api.RenderResources) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) DisplayMetrics(android.util.DisplayMetrics) Result(com.android.ide.common.rendering.api.Result)

Example 29 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ParanoidAndroid.

the class CustomBar method getResourceValue.

private ResourceValue getResourceValue(String reference) {
    BridgeContext bridgeContext = (BridgeContext) mContext;
    RenderResources res = bridgeContext.getRenderResources();
    // find the resource
    ResourceValue value = res.findResValue(reference, false);
    // resolve it if needed
    return res.resolveResValue(value);
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext)

Example 30 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by DirtyUnicorns.

the class BridgeTypedArray method resolveEnumAttribute.

/**
     * Searches for the string in the attributes (flag or enums) and returns the integer.
     * If found, it will return an integer matching the value.
     *
     * @param index Index of attribute to retrieve.
     *
     * @return Attribute int value, or null if not defined.
     */
private Integer resolveEnumAttribute(int index) {
    // Get the map of attribute-constant -> IntegerValue
    Map<String, Integer> map = null;
    if (mIsFramework[index]) {
        map = Bridge.getEnumValues(mNames[index]);
    } else {
        // get the styleable matching the resolved name
        RenderResources res = mContext.getRenderResources();
        ResourceValue attr = res.getProjectResource(ResourceType.ATTR, mNames[index]);
        if (attr instanceof AttrResourceValue) {
            map = ((AttrResourceValue) attr).getAttributeValues();
        }
    }
    if (map != null) {
        // accumulator to store the value of the 1+ constants.
        int result = 0;
        boolean found = false;
        // split the value in case this is a mix of several flags.
        String[] keywords = mResourceData[index].getValue().split("\\|");
        for (String keyword : keywords) {
            Integer i = map.get(keyword.trim());
            if (i != null) {
                result |= i;
                found = true;
            }
        // TODO: We should act smartly and log a warning for incorrect keywords. However,
        // this method is currently called even if the resourceValue is not an enum.
        }
        if (found) {
            return result;
        }
    }
    return null;
}
Also used : AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) RenderResources(com.android.ide.common.rendering.api.RenderResources) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue)

Aggregations

RenderResources (com.android.ide.common.rendering.api.RenderResources)64 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)48 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)28 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)24 DisplayMetrics (android.util.DisplayMetrics)12 TypedValue (android.util.TypedValue)11 Result (com.android.ide.common.rendering.api.Result)7 ColorStateList (android.content.res.ColorStateList)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 Drawable (android.graphics.drawable.Drawable)6 TextView (android.widget.TextView)6 HardwareConfig (com.android.ide.common.rendering.api.HardwareConfig)6 Nullable (android.annotation.Nullable)5 Context (android.content.Context)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 View (android.view.View)5 ViewGroup (android.view.ViewGroup)5 AbsListView (android.widget.AbsListView)5 ActionMenuView (android.widget.ActionMenuView)5 AdapterView (android.widget.AdapterView)5