use of org.robolectric.res.android.ResTable in project robolectric by robolectric.
the class ShadowArscAssetManager method loadResourceBagValue.
/**
* Returns true if the resource was found, filling in mRetStringBlock and
* mRetData.
*/
@Implementation
@HiddenApi
protected final int loadResourceBagValue(int ident, int bagEntryId, TypedValue outValue, boolean resolve) {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return 0;
}
final ResTable res = am.getResources();
return loadResourceBagValueInternal(ident, bagEntryId, outValue, resolve, res);
}
use of org.robolectric.res.android.ResTable in project robolectric by robolectric.
the class ShadowArscAssetManager method getArrayStringResource.
@HiddenApi
@Implementation
protected final String[] getArrayStringResource(int arrayResId) {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return null;
}
final ResTable res = am.getResources();
final Ref<bag_entry[]> startOfBag = new Ref<>(null);
final int N = res.lockBag(arrayResId, startOfBag);
if (N < 0) {
return null;
}
String[] array = new String[N];
final Ref<Res_value> valueRef = new Ref<>(null);
final bag_entry[] bag = startOfBag.get();
int strLen = 0;
for (int i = 0; ((int) i) < N; i++) {
valueRef.set(bag[i].map.value);
String str = null;
// Take care of resolving the found resource to its final value.
int block = res.resolveReference(valueRef, bag[i].stringBlock, null);
if (kThrowOnBadId) {
if (block == BAD_INDEX) {
throw new IllegalStateException("Bad resource!");
}
}
if (valueRef.get().dataType == DataType.STRING.code()) {
final ResStringPool pool = res.getTableStringBlock(block);
str = pool.stringAt(valueRef.get().data);
// }
if (str == null) {
res.unlockBag(startOfBag);
return null;
}
array[i] = str;
// str is not NULL at that point, otherwise ExceptionCheck would have been true.
// If we have a large amount of strings in our array, we might
// overflow the local reference table of the VM.
// env.DeleteLocalRef(str);
}
}
res.unlockBag(startOfBag);
return array;
}
use of org.robolectric.res.android.ResTable in project robolectric by robolectric.
the class ShadowArscAssetManager method getArrayStringInfo.
@HiddenApi
@Implementation
protected final int[] getArrayStringInfo(int arrayResId) {
CppAssetManager am = assetManagerForJavaObject();
ResTable res = am.getResources();
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 * 2];
final Ref<Res_value> value = new Ref<>(null);
bag_entry[] bag = startOfBag.get();
for (int i = 0, j = 0; i < N; i++) {
int stringIndex = -1;
int stringBlock = 0;
value.set(bag[i].map.value);
// Take care of resolving the found resource to its final value.
stringBlock = res.resolveReference(value, bag[i].stringBlock, null);
if (value.get().dataType == DataType.STRING.code()) {
stringIndex = value.get().data;
}
if (kThrowOnBadId) {
if (stringBlock == BAD_INDEX) {
throw new IllegalStateException("Bad resource!");
}
}
// todo: It might be faster to allocate a C array to contain
// the blocknums and indices, put them in there and then
// do just one SetIntArrayRegion()
// env->SetIntArrayRegion(array, j, 1, &stringBlock);
array[j] = stringBlock;
// env->SetIntArrayRegion(array, j + 1, 1, &stringIndex);
array[j + 1] = stringIndex;
j += 2;
}
res.unlockBag(startOfBag);
return array;
}
use of org.robolectric.res.android.ResTable 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.ResTable in project robolectric by robolectric.
the class ShadowArscAssetManager method loadThemeAttributeValue.
@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected static int loadThemeAttributeValue(long themeHandle, int ident, TypedValue outValue, boolean resolve) {
ResTableTheme theme = Preconditions.checkNotNull(Registries.NATIVE_THEME_REGISTRY.getNativeObject(themeHandle));
ResTable res = theme.getResTable();
final Ref<Res_value> value = new Ref<>(null);
// XXX value could be different in different configs!
final Ref<Integer> typeSpecFlags = new Ref<>(0);
int block = theme.GetAttribute(ident, value, typeSpecFlags);
final Ref<Integer> ref = new Ref<>(0);
if (resolve) {
block = res.resolveReference(value, block, ref, typeSpecFlags);
if (kThrowOnBadId) {
if (block == BAD_INDEX) {
throw new IllegalStateException("Bad resource!");
}
}
}
return block >= 0 ? copyValue(outValue, res, value.get(), ref.get(), block, typeSpecFlags.get(), null) : block;
}
Aggregations