use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method getArrayIntResource.
@HiddenApi
@Implementation
public int[] getArrayIntResource(int arrayResId) {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return null;
}
final ResTable res = am.getResources();
// final ResTable::bag_entry* startOfBag;
final Ref<bag_entry[]> startOfBag = new Ref<>(null);
final int N = res.lockBag(arrayResId, startOfBag);
if (N < 0) {
return null;
}
int[] array = new int[N];
if (array == null) {
res.unlockBag(startOfBag);
return null;
}
final Ref<Res_value> valueRef = new Ref<>(null);
bag_entry[] bag = startOfBag.get();
for (int i = 0; i < N; i++) {
valueRef.set(bag[i].map.value);
// Take care of resolving the found resource to its final value.
int block = res.resolveReference(valueRef, bag[i].stringBlock, null, null, null);
if (kThrowOnBadId) {
if (block == BAD_INDEX) {
// seems like this is missing from android_util_AssetManager.cpp?
res.unlockBag(startOfBag);
throw new IllegalStateException("Bad resource!");
// return array;
}
}
Res_value value = valueRef.get();
if (value.dataType >= DataType.TYPE_FIRST_INT && value.dataType <= DataType.TYPE_LAST_INT) {
int intVal = value.data;
// env->SetIntArrayRegion(array, i, 1, &intVal);
array[i] = intVal;
}
}
res.unlockBag(startOfBag);
return array;
}
use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method openNonAssetNative.
@HiddenApi
@Implementation
protected final Number openNonAssetNative(int cookie, String fileName, int accessMode) throws FileNotFoundException {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return RuntimeEnvironment.castNativePtr(0);
}
ALOGV("openNonAssetNative in %s (Java object %s)\n", am, AssetManager.class);
String fileName8 = fileName;
if (fileName8 == null) {
return RuntimeEnvironment.castNativePtr(-1);
}
AccessMode mode = AccessMode.fromInt(accessMode);
if (mode != Asset.AccessMode.ACCESS_UNKNOWN && mode != Asset.AccessMode.ACCESS_RANDOM && mode != Asset.AccessMode.ACCESS_STREAMING && mode != Asset.AccessMode.ACCESS_BUFFER) {
throw new IllegalArgumentException("Bad access mode");
}
Asset a = isTruthy(cookie) ? am.openNonAsset(cookie, fileName8, mode) : am.openNonAsset(fileName8, mode, null);
if (a == null) {
throw new FileNotFoundException(fileName8);
}
long assetId = Registries.NATIVE_ASSET_REGISTRY.register(a);
// todo: something better than this [xw]
a.onClose = () -> destroyAsset(assetId);
// printf("Created Asset Stream: %p\n", a);
return RuntimeEnvironment.castNativePtr(assetId);
}
use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method getResourceName.
@Implementation
protected String getResourceName(int resid) {
CppAssetManager am = assetManagerForJavaObject();
ResourceName name = new ResourceName();
if (!am.getResources().getResourceName(resid, true, name)) {
return null;
}
StringBuilder str = new StringBuilder();
if (name.packageName != null) {
str.append(name.packageName.trim());
}
if (name.type != null) {
if (str.length() > 0) {
char div = ':';
str.append(div);
}
str.append(name.type);
}
if (name.name != null) {
if (str.length() > 0) {
char div = '/';
str.append(div);
}
str.append(name.name);
}
return str.toString();
}
use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method newTheme.
@HiddenApi
@Implementation
protected final Number newTheme() {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return RuntimeEnvironment.castNativePtr(0);
}
ResTableTheme theme = new ResTableTheme(am.getResources());
return RuntimeEnvironment.castNativePtr(Registries.NATIVE_THEME_REGISTRY.register(theme));
}
Aggregations