Search in sources :

Example 16 with ArrayResourceValue

use of com.android.ide.common.rendering.api.ArrayResourceValue in project android_frameworks_base by ResurrectionRemix.

the class Resources_Delegate method getTextArray.

@LayoutlibDelegate
static CharSequence[] getTextArray(Resources resources, int id) throws NotFoundException {
    ResourceValue resValue = getArrayResourceValue(resources, id);
    if (resValue == null) {
        // Error already logged by getArrayResourceValue.
        return new CharSequence[0];
    } else if (!(resValue instanceof ArrayResourceValue)) {
        return new CharSequence[] { resolveReference(resources, resValue.getValue(), resValue.isFramework()) };
    }
    ArrayResourceValue arv = ((ArrayResourceValue) resValue);
    return fillValues(resources, arv, new CharSequence[arv.getElementCount()]);
}
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) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 17 with ArrayResourceValue

use of com.android.ide.common.rendering.api.ArrayResourceValue in project android_frameworks_base by ResurrectionRemix.

the class Resources_Delegate method getArrayResourceValue.

/**
     * Try to find the ArrayResourceValue for the given id.
     * <p/>
     * If the ResourceValue found is not of type {@link ResourceType#ARRAY}, the method logs an
     * error and return null. However, if the ResourceValue found has type {@code
     * ResourceType.ARRAY}, but the value is not an instance of {@link ArrayResourceValue}, the
     * method returns the ResourceValue. This happens on older versions of the IDE, which did not
     * parse the array resources properly.
     * <p/>
     *
     * @throws NotFoundException if no resource if found
     */
@Nullable
private static ResourceValue getArrayResourceValue(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> v = getResourceValue(resources, id, mPlatformResourceFlag);
    if (v != null) {
        ResourceValue resValue = v.getSecond();
        assert resValue != null;
        if (resValue != null) {
            final ResourceType type = resValue.getResourceType();
            if (type != ResourceType.ARRAY) {
                Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE, String.format("Resource with id 0x%1$X is not an array resource, but %2$s", id, type == null ? "null" : type.getDisplayName()), null);
                return null;
            }
            if (!(resValue instanceof ArrayResourceValue)) {
                Bridge.getLog().warning(LayoutLog.TAG_UNSUPPORTED, "Obtaining resource arrays via getTextArray, getStringArray or getIntArray is not fully supported in this version of the IDE.", null);
            }
            return resValue;
        }
    }
    // 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) ResourceType(com.android.resources.ResourceType) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) Nullable(android.annotation.Nullable)

Example 18 with ArrayResourceValue

use of com.android.ide.common.rendering.api.ArrayResourceValue in project android_frameworks_base by crdroidandroid.

the class Resources_Delegate method getStringArray.

@LayoutlibDelegate
static String[] getStringArray(Resources resources, int id) throws NotFoundException {
    ResourceValue resValue = getArrayResourceValue(resources, id);
    if (resValue == null) {
        // Error already logged by getArrayResourceValue.
        return new String[0];
    } else if (!(resValue instanceof ArrayResourceValue)) {
        return new String[] { resolveReference(resources, resValue.getValue(), resValue.isFramework()) };
    }
    ArrayResourceValue arv = ((ArrayResourceValue) resValue);
    return fillValues(resources, arv, new String[arv.getElementCount()]);
}
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) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 19 with ArrayResourceValue

use of com.android.ide.common.rendering.api.ArrayResourceValue in project android_frameworks_base by crdroidandroid.

the class Resources_Delegate method getArrayResourceValue.

/**
     * Try to find the ArrayResourceValue for the given id.
     * <p/>
     * If the ResourceValue found is not of type {@link ResourceType#ARRAY}, the method logs an
     * error and return null. However, if the ResourceValue found has type {@code
     * ResourceType.ARRAY}, but the value is not an instance of {@link ArrayResourceValue}, the
     * method returns the ResourceValue. This happens on older versions of the IDE, which did not
     * parse the array resources properly.
     * <p/>
     *
     * @throws NotFoundException if no resource if found
     */
@Nullable
private static ResourceValue getArrayResourceValue(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> v = getResourceValue(resources, id, mPlatformResourceFlag);
    if (v != null) {
        ResourceValue resValue = v.getSecond();
        assert resValue != null;
        if (resValue != null) {
            final ResourceType type = resValue.getResourceType();
            if (type != ResourceType.ARRAY) {
                Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE, String.format("Resource with id 0x%1$X is not an array resource, but %2$s", id, type == null ? "null" : type.getDisplayName()), null);
                return null;
            }
            if (!(resValue instanceof ArrayResourceValue)) {
                Bridge.getLog().warning(LayoutLog.TAG_UNSUPPORTED, "Obtaining resource arrays via getTextArray, getStringArray or getIntArray is not fully supported in this version of the IDE.", null);
            }
            return resValue;
        }
    }
    // 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) ResourceType(com.android.resources.ResourceType) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) Nullable(android.annotation.Nullable)

Example 20 with ArrayResourceValue

use of com.android.ide.common.rendering.api.ArrayResourceValue in project android_frameworks_base by crdroidandroid.

the class Resources_Delegate method getTextArray.

@LayoutlibDelegate
static CharSequence[] getTextArray(Resources resources, int id) throws NotFoundException {
    ResourceValue resValue = getArrayResourceValue(resources, id);
    if (resValue == null) {
        // Error already logged by getArrayResourceValue.
        return new CharSequence[0];
    } else if (!(resValue instanceof ArrayResourceValue)) {
        return new CharSequence[] { resolveReference(resources, resValue.getValue(), resValue.isFramework()) };
    }
    ArrayResourceValue arv = ((ArrayResourceValue) resValue);
    return fillValues(resources, arv, new CharSequence[arv.getElementCount()]);
}
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) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)20 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)20 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)16 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)12 Nullable (android.annotation.Nullable)4 NotFoundException (android.content.res.Resources.NotFoundException)4 AttrResourceValue (com.android.ide.common.rendering.api.AttrResourceValue)4 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)4 ResourceType (com.android.resources.ResourceType)4