use of org.robolectric.res.android.CppAssetManager2.ResolvedBag in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeGetResourceIntArray.
// static jintArray NativeGetResourceIntArray(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint
// resid) {
@Implementation(minSdk = P)
@Nullable
protected static int[] nativeGetResourceIntArray(long ptr, @ArrayRes int resid) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
ResolvedBag bag = assetmanager.GetBag(resid);
if (bag == null) {
return null;
}
int[] array = new int[bag.entry_count];
// if (array == null) {
// return null;
// }
// reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(array, null));
int[] buffer = array;
for (int i = 0; i < bag.entry_count; i++) {
ResolvedBag.Entry entry = bag.entries[i];
final Ref<Res_value> value = new Ref<>(entry.value);
final Ref<ResTable_config> selected_config = new Ref<>(null);
final Ref<Integer> flags = new Ref<>(0);
final Ref<Integer> ref = new Ref<>(0);
ApkAssetsCookie cookie = assetmanager.ResolveReference(entry.cookie, value, selected_config, flags, ref);
if (cookie.intValue() == kInvalidCookie) {
// env.ReleasePrimitiveArrayCritical(array, buffer, JNI_ABORT);
return null;
}
if (value.get().dataType >= Res_value.TYPE_FIRST_INT && value.get().dataType <= Res_value.TYPE_LAST_INT) {
buffer[i] = (int) (value.get().data);
}
}
// env.ReleasePrimitiveArrayCritical(array, buffer, 0);
return array;
}
use of org.robolectric.res.android.CppAssetManager2.ResolvedBag in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeGetResourceBagValue.
// static jint NativeGetResourceBagValue(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid,
// jint bag_entry_id, jobject typed_value) {
@Implementation(minSdk = P)
protected static int nativeGetResourceBagValue(long ptr, @AnyRes int resid, int bag_entry_id, @NonNull TypedValue typed_value) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
ResolvedBag bag = assetmanager.GetBag(resid);
if (bag == null) {
return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
}
final Ref<Integer> type_spec_flags = new Ref<>(bag.type_spec_flags);
ApkAssetsCookie cookie = K_INVALID_COOKIE;
Res_value bag_value = null;
for (ResolvedBag.Entry entry : bag.entries) {
if (entry.key == (int) (bag_entry_id)) {
cookie = entry.cookie;
bag_value = entry.value;
// Keep searching (the old implementation did that).
}
}
if (cookie.intValue() == kInvalidCookie) {
return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
}
final Ref<Res_value> value = new Ref<>(bag_value);
final Ref<Integer> ref = new Ref<>(resid);
final Ref<ResTable_config> selected_config = new Ref<>(null);
cookie = assetmanager.ResolveReference(cookie, value, selected_config, type_spec_flags, ref);
if (cookie.intValue() == kInvalidCookie) {
return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
}
return CopyValue(cookie, value.get(), ref.get(), type_spec_flags.get(), null, typed_value);
}
use of org.robolectric.res.android.CppAssetManager2.ResolvedBag in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeGetResourceStringArrayInfo.
// static jintArray NativeGetResourceStringArrayInfo(JNIEnv* env, jclass /*clazz*/, jlong ptr,
// jint resid) {
@Implementation(minSdk = P)
@Nullable
protected static int[] nativeGetResourceStringArrayInfo(long ptr, @ArrayRes int resid) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
ResolvedBag bag = assetmanager.GetBag(resid);
if (bag == null) {
return null;
}
int[] array = new int[bag.entry_count * 2];
// if (array == null) {
// return null;
// }
// reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(array, null));
int[] buffer = array;
for (int i = 0; i < bag.entry_count; i++) {
ResolvedBag.Entry entry = bag.entries[i];
final Ref<Res_value> value = new Ref<>(entry.value);
final Ref<ResTable_config> selected_config = new Ref<>(null);
final Ref<Integer> flags = new Ref<>(0);
final Ref<Integer> ref = new Ref<>(0);
ApkAssetsCookie cookie = assetmanager.ResolveReference(entry.cookie, value, selected_config, flags, ref);
if (cookie.intValue() == kInvalidCookie) {
// env.ReleasePrimitiveArrayCritical(array, buffer, JNI_ABORT);
return null;
}
int string_index = -1;
if (value.get().dataType == Res_value.TYPE_STRING) {
string_index = (int) (value.get().data);
}
buffer[i * 2] = ApkAssetsCookieToJavaCookie(cookie);
buffer[(i * 2) + 1] = string_index;
}
// env.ReleasePrimitiveArrayCritical(array, buffer, 0);
return array;
}
use of org.robolectric.res.android.CppAssetManager2.ResolvedBag in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeGetStyleAttributes.
// static jintArray NativeGetStyleAttributes(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid)
// {
@Implementation(minSdk = P)
@Nullable
@AttrRes
protected static int[] nativeGetStyleAttributes(long ptr, @StyleRes int resid) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
ResolvedBag bag = assetmanager.GetBag(resid);
if (bag == null) {
return null;
}
int[] array = new int[bag.entry_count];
for (int i = 0; i < bag.entry_count; i++) {
int attr_resid = bag.entries[i].key;
// env.SetIntArrayRegion(array, i, 1, &attr_resid);
array[i] = attr_resid;
}
return array;
}
use of org.robolectric.res.android.CppAssetManager2.ResolvedBag in project robolectric by robolectric.
the class ShadowArscAssetManager9 method nativeGetResourceArraySize.
// static jint NativeGetResourceArraySize(JNIEnv* /*env*/, jclass /*clazz*/, jlong ptr, jint
// resid) {
@Implementation(minSdk = P)
protected static int nativeGetResourceArraySize(long ptr, @ArrayRes int resid) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
ResolvedBag bag = assetmanager.GetBag(resid);
if (bag == null) {
return -1;
}
return (int) (bag.entry_count);
}
Aggregations