use of org.robolectric.res.android.CppAssetManager 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;
}
use of org.robolectric.res.android.CppAssetManager 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;
}
use of org.robolectric.res.android.CppAssetManager 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;
}
use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method list.
@Implementation
protected final String[] list(String path) throws IOException {
CppAssetManager am = assetManagerForJavaObject();
String fileName8 = path;
if (fileName8 == null) {
return null;
}
AssetDir dir = am.openDir(fileName8);
if (dir == null) {
throw new FileNotFoundException(fileName8);
}
int N = dir.getFileCount();
String[] array = new String[dir.getFileCount()];
for (int i = 0; i < N; i++) {
String8 name = dir.getFileName(i);
array[i] = name.string();
}
return array;
}
use of org.robolectric.res.android.CppAssetManager 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;
}
Aggregations