Search in sources :

Example 1 with ResTable

use of org.robolectric.res.android.ResTable in project robolectric by robolectric.

the class ShadowArscAssetManager method loadResourceValue.

@HiddenApi
@Implementation
protected int loadResourceValue(int ident, short density, TypedValue outValue, boolean resolve) {
    if (outValue == null) {
        throw new NullPointerException("outValue");
    // return 0;
    }
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return 0;
    }
    final ResTable res = am.getResources();
    final Ref<Res_value> value = new Ref<>(null);
    final Ref<ResTable_config> config = new Ref<>(null);
    final Ref<Integer> typeSpecFlags = new Ref<>(null);
    int block = res.getResource(ident, value, false, density, typeSpecFlags, config);
    if (kThrowOnBadId) {
        if (block == BAD_INDEX) {
            throw new IllegalStateException("Bad resource!");
        // return 0;
        }
    }
    final Ref<Integer> ref = new Ref<>(ident);
    if (resolve) {
        block = res.resolveReference(value, block, ref, typeSpecFlags, config);
        if (kThrowOnBadId) {
            if (block == BAD_INDEX) {
                throw new IllegalStateException("Bad resource!");
            // return 0;
            }
        }
    }
    if (block >= 0) {
        // return copyValue(env, outValue, &res, value, ref, block, typeSpecFlags, &config);
        return copyValue(outValue, res, value.get(), ref.get(), block, typeSpecFlags.get(), config.get());
    }
    return block;
}
Also used : Ref(org.robolectric.res.android.Ref) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable_config(org.robolectric.res.android.ResTable_config) ResTable(org.robolectric.res.android.ResTable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 2 with ResTable

use of org.robolectric.res.android.ResTable in project robolectric by robolectric.

the class ShadowArscAssetManager method retrieveArray.

@Implementation
@HiddenApi
protected int retrieveArray(int id, int[] outValues) {
    if (outValues == null) {
        throw new NullPointerException("out values");
    }
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return 0;
    }
    ResTable res = am.getResources();
    final Ref<ResTable_config> config = new Ref<>(new ResTable_config());
    Res_value value;
    int block;
    int NV = outValues.length;
    // int[] baseDest = (int[])env->GetPrimitiveArrayCritical(outValues, 0);
    int[] baseDest = outValues;
    int[] dest = baseDest;
    // if (dest == null) {
    // throw new NullPointerException(env, "java/lang/OutOfMemoryError", "");
    // return JNI_FALSE;
    // }
    // Now lock down the resource object and start pulling stuff from it.
    res.lock();
    final Ref<bag_entry[]> arrayEnt = new Ref<>(null);
    final Ref<Integer> arrayTypeSetFlags = new Ref<>(0);
    int bagOff = res.getBagLocked(id, arrayEnt, arrayTypeSetFlags);
    // final ResTable::bag_entry* endArrayEnt = arrayEnt +
    // (bagOff >= 0 ? bagOff : 0);
    int destOffset = 0;
    final Ref<Integer> typeSetFlags = new Ref<>(0);
    while (destOffset < NV && destOffset < bagOff * STYLE_NUM_ENTRIES) /*&& arrayEnt < endArrayEnt*/
    {
        bag_entry curArrayEnt = arrayEnt.get()[destOffset / STYLE_NUM_ENTRIES];
        block = curArrayEnt.stringBlock;
        typeSetFlags.set(arrayTypeSetFlags.get());
        config.get().density = 0;
        value = curArrayEnt.map.value;
        final Ref<Integer> resid = new Ref<>(0);
        if (value.dataType != DataType.NULL.code()) {
            // Take care of resolving the found resource to its final value.
            // printf("Resolving attribute reference\n");
            final Ref<Res_value> resValueRef = new Ref<>(value);
            int newBlock = res.resolveReference(resValueRef, block, resid, typeSetFlags, config);
            value = resValueRef.get();
            if (kThrowOnBadId) {
                if (newBlock == BAD_INDEX) {
                    throw new IllegalStateException("Bad resource!");
                }
            }
            if (newBlock >= 0)
                block = newBlock;
        }
        // Deal with the special @null value -- it turns back to TYPE_NULL.
        if (value.dataType == DataType.REFERENCE.code() && value.data == 0) {
            value = Res_value.NULL_VALUE;
        }
        // printf("Attribute 0x%08x: final type=0x%x, data=0x%08x\n", curIdent, value.dataType, value.data);
        // Write the final value back to Java.
        dest[destOffset + STYLE_TYPE] = value.dataType;
        dest[destOffset + STYLE_DATA] = value.data;
        dest[destOffset + STYLE_ASSET_COOKIE] = res.getTableCookie(block);
        dest[destOffset + STYLE_RESOURCE_ID] = resid.get();
        dest[destOffset + STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags.get();
        dest[destOffset + STYLE_DENSITY] = config.get().density;
        // dest += STYLE_NUM_ENTRIES;
        destOffset += STYLE_NUM_ENTRIES;
    // arrayEnt++;
    }
    destOffset /= STYLE_NUM_ENTRIES;
    res.unlock();
    return destOffset;
}
Also used : Res_value(org.robolectric.res.android.ResourceTypes.Res_value) CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable_config(org.robolectric.res.android.ResTable_config) ResTable(org.robolectric.res.android.ResTable) Ref(org.robolectric.res.android.Ref) ResTable.bag_entry(org.robolectric.res.android.ResTable.bag_entry) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 3 with ResTable

use of org.robolectric.res.android.ResTable in project robolectric by robolectric.

the class ShadowArscAssetManager method getAssignedPackageIdentifiers.

@Implementation
protected final SparseArray<String> getAssignedPackageIdentifiers() {
    CppAssetManager am = assetManagerForJavaObject();
    final ResTable res = am.getResources();
    SparseArray<String> sparseArray = new SparseArray<>();
    final int N = res.getBasePackageCount();
    for (int i = 0; i < N; i++) {
        final String name = res.getBasePackageName(i);
        sparseArray.put(res.getBasePackageId(i), name);
    }
    return sparseArray;
}
Also used : SparseArray(android.util.SparseArray) CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable(org.robolectric.res.android.ResTable) Implementation(org.robolectric.annotation.Implementation)

Example 4 with ResTable

use of org.robolectric.res.android.ResTable in project robolectric by robolectric.

the class ShadowArscAssetManager method retrieveAttributes.

@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected final boolean retrieveAttributes(long xmlParserToken, int[] attrs, int[] outValues, int[] outIndices) {
    if (xmlParserToken == 0) {
        throw new NullPointerException("xmlParserToken");
    // return JNI_FALSE;
    }
    if (attrs == null) {
        throw new NullPointerException("attrs");
    // return JNI_FALSE;
    }
    if (outValues == null) {
        throw new NullPointerException("out values");
    // return JNI_FALSE;
    }
    CppAssetManager am = assetManagerForJavaObject();
    // if (am == null) {
    // return JNI_FALSE;
    // }
    ResTable res = am.getResources();
    // ResXMLParser xmlParser = (ResXMLParser*)xmlParserToken;
    ResXMLParser xmlParser = Registries.NATIVE_RES_XML_PARSERS.getNativeObject(xmlParserToken);
    // const int NI = env.GetArrayLength(attrs);
    // const int NV = env.GetArrayLength(outValues);
    final int NI = attrs.length;
    final int NV = outValues.length;
    if (NV < (NI * STYLE_NUM_ENTRIES)) {
        throw new IndexOutOfBoundsException("out values too small");
    // return JNI_FALSE;
    }
    // int[] src = (int[])env.GetPrimitiveArrayCritical(attrs, 0);
    // if (src == null) {
    // return JNI_FALSE;
    // }
    int[] src = attrs;
    // int[] baseDest = (int[])env.GetPrimitiveArrayCritical(outValues, 0);
    int[] baseDest = outValues;
    if (baseDest == null) {
        // return JNI_FALSE;
        return false;
    }
    int[] indices = null;
    if (outIndices != null) {
        if (outIndices.length > NI) {
            // indices = (int[])env.GetPrimitiveArrayCritical(outIndices, 0);
            indices = outIndices;
        }
    }
    boolean result = AttributeResolution.RetrieveAttributes(res, xmlParser, src, NI, baseDest, indices);
    if (indices != null) {
    // indices[0] = indicesIdx;
    // env.ReleasePrimitiveArrayCritical(outIndices, indices, 0);
    }
    return result;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable(org.robolectric.res.android.ResTable) ResXMLParser(org.robolectric.res.android.ResXMLParser) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 5 with ResTable

use of org.robolectric.res.android.ResTable in project robolectric by robolectric.

the class ShadowArscAssetManager method getArraySize.

@HiddenApi
@Implementation
protected int getArraySize(int id) {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return 0;
    }
    final ResTable res = am.getResources();
    res.lock();
    final Ref<bag_entry[]> defStyleEnt = new Ref<>(null);
    int bagOff = res.getBagLocked(id, defStyleEnt, null);
    res.unlock();
    return bagOff;
}
Also used : Ref(org.robolectric.res.android.Ref) CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable(org.robolectric.res.android.ResTable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

Implementation (org.robolectric.annotation.Implementation)10 ResTable (org.robolectric.res.android.ResTable)10 HiddenApi (org.robolectric.annotation.HiddenApi)9 CppAssetManager (org.robolectric.res.android.CppAssetManager)9 Ref (org.robolectric.res.android.Ref)7 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)6 ResTable.bag_entry (org.robolectric.res.android.ResTable.bag_entry)4 ResTable_config (org.robolectric.res.android.ResTable_config)2 SparseArray (android.util.SparseArray)1 ResStringPool (org.robolectric.res.android.ResStringPool)1 ResTableTheme (org.robolectric.res.android.ResTableTheme)1 ResXMLParser (org.robolectric.res.android.ResXMLParser)1