Search in sources :

Example 1 with ResourceValue

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

the class BridgeResources method getXml.

@Override
public XmlResourceParser getXml(int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
    if (value != null) {
        String v = value.getSecond().getValue();
        if (v != null) {
            // check this is a file
            File f = new File(v);
            if (f.isFile()) {
                try {
                    XmlPullParser parser = ParserFactory.create(f);
                    return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
                } catch (XmlPullParserException e) {
                    NotFoundException newE = new NotFoundException();
                    newE.initCause(e);
                    throw newE;
                } catch (FileNotFoundException e) {
                    NotFoundException newE = new NotFoundException();
                    newE.initCause(e);
                    throw newE;
                }
            }
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(id);
    // this is not used since the method above always throws
    return null;
}
Also used : ResourceValue(com.android.ide.common.rendering.api.ResourceValue) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser)

Example 2 with ResourceValue

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

the class BridgeResources method getBoolean.

@Override
public boolean getBoolean(int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
    if (value != null) {
        ResourceValue resValue = value.getSecond();
        assert resValue != null;
        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(id);
    // this is not used since the method above always throws
    return false;
}
Also used : ResourceValue(com.android.ide.common.rendering.api.ResourceValue)

Example 3 with ResourceValue

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

the class BridgeResources method getInteger.

@Override
public int getInteger(int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
    if (value != null) {
        ResourceValue resValue = value.getSecond();
        assert resValue != null;
        if (resValue != null) {
            String v = resValue.getValue();
            if (v != null) {
                int radix = 10;
                if (v.startsWith("0x")) {
                    v = v.substring(2);
                    radix = 16;
                }
                try {
                    return Integer.parseInt(v, radix);
                } catch (NumberFormatException e) {
                // return exception below
                }
            }
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(id);
    // this is not used since the method above always throws
    return 0;
}
Also used : ResourceValue(com.android.ide.common.rendering.api.ResourceValue)

Example 4 with ResourceValue

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

the class BridgeResources method getDimensionPixelOffset.

@Override
public int getDimensionPixelOffset(int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
    if (value != null) {
        ResourceValue resValue = value.getSecond();
        assert resValue != null;
        if (resValue != null) {
            String v = resValue.getValue();
            if (v != null) {
                if (ResourceHelper.parseFloatAttribute(value.getFirst(), v, mTmpValue, true) && mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                    return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, getDisplayMetrics());
                }
            }
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(id);
    // this is not used since the method above always throws
    return 0;
}
Also used : ResourceValue(com.android.ide.common.rendering.api.ResourceValue)

Example 5 with ResourceValue

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

the class BridgeTypedArray method getDrawable.

/**
     * Retrieve the Drawable for the attribute at <var>index</var>.  This
     * gets the resource ID of the selected attribute, and uses
     * {@link Resources#getDrawable Resources.getDrawable} of the owning
     * Resources object to retrieve its Drawable.
     *
     * @param index Index of attribute to retrieve.
     *
     * @return Drawable for the attribute, or null if not defined.
     */
@Override
public Drawable getDrawable(int index) {
    if (index < 0 || index >= mResourceData.length) {
        return null;
    }
    if (mResourceData[index] == null) {
        return null;
    }
    ResourceValue value = mResourceData[index];
    String stringValue = value.getValue();
    if (stringValue == null || RenderResources.REFERENCE_NULL.equals(stringValue)) {
        return null;
    }
    return ResourceHelper.getDrawable(value, mContext);
}
Also used : ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue)

Aggregations

ResourceValue (com.android.ide.common.rendering.api.ResourceValue)243 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)82 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)80 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)69 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)56 RenderResources (com.android.ide.common.rendering.api.RenderResources)48 File (java.io.File)44 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)40 ResourceType (com.android.resources.ResourceType)31 XmlPullParser (org.xmlpull.v1.XmlPullParser)28 TypedValue (android.util.TypedValue)26 FileNotFoundException (java.io.FileNotFoundException)26 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)23 AttrResourceValue (com.android.ide.common.rendering.api.AttrResourceValue)22 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)22 Context (android.content.Context)16 NotNull (org.jetbrains.annotations.NotNull)14 ResourceResolver (com.android.ide.common.resources.ResourceResolver)13 BridgeTypedArray (android.content.res.BridgeTypedArray)12 NotFoundException (android.content.res.Resources.NotFoundException)12