Search in sources :

Example 21 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project platform_frameworks_base by android.

the class Resources_Delegate method getInteger.

@LayoutlibDelegate
static int getInteger(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
    if (value != null) {
        ResourceValue resValue = value.getSecond();
        assert resValue != null;
        if (resValue != null) {
            String v = resValue.getValue();
            if (v != null) {
                try {
                    return getInt(v);
                } catch (NumberFormatException e) {
                // return exception below
                }
            }
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(resources, id);
    // this is not used since the method above always throws
    return 0;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 22 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project platform_frameworks_base by android.

the class Resources_Delegate method getText.

@LayoutlibDelegate
static CharSequence getText(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
    if (value != null) {
        ResourceValue resValue = value.getSecond();
        assert resValue != null;
        if (resValue != null) {
            String v = resValue.getValue();
            if (v != null) {
                return v;
            }
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(resources, id);
    // this is not used since the method above always throws
    return null;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 23 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project platform_frameworks_base by android.

the class Resources_Delegate method getDimension.

@LayoutlibDelegate
static float getDimension(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
    if (value != null) {
        ResourceValue resValue = value.getSecond();
        assert resValue != null;
        if (resValue != null) {
            String v = resValue.getValue();
            if (v != null) {
                if (v.equals(BridgeConstants.MATCH_PARENT) || v.equals(BridgeConstants.FILL_PARENT)) {
                    return LayoutParams.MATCH_PARENT;
                } else if (v.equals(BridgeConstants.WRAP_CONTENT)) {
                    return LayoutParams.WRAP_CONTENT;
                }
                TypedValue tmpValue = new TypedValue();
                if (ResourceHelper.parseFloatAttribute(value.getFirst(), v, tmpValue, true) && tmpValue.type == TypedValue.TYPE_DIMENSION) {
                    return tmpValue.getDimension(resources.getDisplayMetrics());
                }
            }
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(resources, id);
    // this is not used since the method above always throws
    return 0;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) TypedValue(android.util.TypedValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 24 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project platform_frameworks_base by android.

the class Resources_Delegate method getBoolean.

@LayoutlibDelegate
static boolean getBoolean(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
    if (value != null) {
        ResourceValue resValue = value.getSecond();
        if (resValue != null) {
            String v = resValue.getValue();
            if (v != null) {
                return Boolean.parseBoolean(v);
            }
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(resources, id);
    // this is not used since the method above always throws
    return false;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 25 with LayoutlibDelegate

use of com.android.tools.layoutlib.annotations.LayoutlibDelegate in project platform_frameworks_base by android.

the class PathParser_Delegate method nParseStringForPath.

@LayoutlibDelegate
static /*package*/
void nParseStringForPath(long pathPtr, @NonNull String pathString, int stringLength) {
    Path_Delegate path_delegate = Path_Delegate.getDelegate(pathPtr);
    if (path_delegate == null) {
        return;
    }
    assert pathString.length() == stringLength;
    PathDataNode.nodesToPath(createNodesFromPathData(pathString), path_delegate);
}
Also used : Path_Delegate(android.graphics.Path_Delegate) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)334 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)56 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)56 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)56 BufferedImage (java.awt.image.BufferedImage)46 AffineTransform (java.awt.geom.AffineTransform)42 Area (java.awt.geom.Area)42 File (java.io.File)30 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)29 FileNotFoundException (java.io.FileNotFoundException)24 Graphics2D (java.awt.Graphics2D)19 TypedValue (android.util.TypedValue)17 NotFoundException (android.content.res.Resources.NotFoundException)16 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)16 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)16 ArrayList (java.util.ArrayList)16 XmlPullParser (org.xmlpull.v1.XmlPullParser)16 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)16 IOException (java.io.IOException)14 NinePatchInputStream (com.android.layoutlib.bridge.util.NinePatchInputStream)12