use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.
the class RawResourceLoaderTest method shouldReturnRawResourcesWithoutExtensions.
@Test
public void shouldReturnRawResourcesWithoutExtensions() throws Exception {
String f = (String) resourceTable.getValue(R.raw.raw_no_ext, new ResTable_config()).getData();
assertThat(f).isEqualTo(TestUtil.testResources().getResourceBase().resolve("raw").resolve("raw_no_ext").toString());
}
use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeGetResourceArray.
// static jint NativeGetResourceArray(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid,
// jintArray out_data) {
@Implementation(minSdk = P)
protected static int nativeGetResourceArray(long ptr, @ArrayRes int resid, @NonNull int[] out_data) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
ResolvedBag bag = assetmanager.GetBag(resid);
if (bag == null) {
return -1;
}
int out_data_length = out_data.length;
if ((int) (bag.entry_count) > out_data_length * STYLE_NUM_ENTRIES) {
throw new IllegalArgumentException("Input array is not large enough");
}
int[] buffer = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_data, null));
out_data;
if (buffer == null) {
return -1;
}
int[] cursor = buffer;
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<>(new ResTable_config());
selected_config.get().density = 0;
final Ref<Integer> flags = new Ref<>(bag.type_spec_flags);
final Ref<Integer> ref = new Ref<>(0);
ApkAssetsCookie cookie = assetmanager.ResolveReference(entry.cookie, value, selected_config, flags, ref);
if (cookie.intValue() == kInvalidCookie) {
// env.ReleasePrimitiveArrayCritical(out_data, buffer, JNI_ABORT);
return -1;
}
// Deal with the special @null value -- it turns back to TYPE_NULL.
if (value.get().dataType == Res_value.TYPE_REFERENCE && value.get().data == 0) {
value.set(Res_value.NULL_VALUE);
}
int offset = i * STYLE_NUM_ENTRIES;
cursor[offset + STYLE_TYPE] = (int) (value.get().dataType);
cursor[offset + STYLE_DATA] = (int) (value.get().data);
cursor[offset + STYLE_ASSET_COOKIE] = ApkAssetsCookieToJavaCookie(cookie);
cursor[offset + STYLE_RESOURCE_ID] = (int) (ref.get());
cursor[offset + STYLE_CHANGING_CONFIGURATIONS] = (int) (flags.get());
cursor[offset + STYLE_DENSITY] = (int) (selected_config.get().density);
// cursor += STYLE_NUM_ENTRIES;
}
// env.ReleasePrimitiveArrayCritical(out_data, buffer, 0);
return (int) (bag.entry_count);
}
use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeGetSizeConfigurations.
// static jobjectArray NativeGetSizeConfigurations(JNIEnv* env, jclass /*clazz*/, jlong ptr) {
@Implementation(minSdk = P)
@Nullable
protected static Configuration[] nativeGetSizeConfigurations(long ptr) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
Set<ResTable_config> configurations = assetmanager.GetResourceConfigurations(true, /*exclude_system*/
false);
Configuration[] array = new Configuration[configurations.size()];
// env.NewObjectArray(configurations.size(), gConfigurationOffsets.classObject, null);
// if (array == null) {
// return null;
// }
int idx = 0;
for (ResTable_config configuration : configurations) {
Configuration java_configuration = ConstructConfigurationObject(configuration);
// if (java_configuration == null) {
// return null;
// }
// env.SetObjectArrayElement(array, idx++, java_configuration);
array[idx++] = java_configuration;
// env.DeleteLocalRef(java_configuration);
}
return array;
}
use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeGetResourceValue.
// static jint NativeGetResourceValue(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid,
// jshort density, jobject typed_value,
// jboolean resolve_references) {
@Implementation(minSdk = P)
protected static int nativeGetResourceValue(long ptr, @AnyRes int resid, short density, @NonNull TypedValue typed_value, boolean resolve_references) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
final Ref<Res_value> value = new Ref<>(null);
final Ref<ResTable_config> selected_config = new Ref<>(null);
final Ref<Integer> flags = new Ref<>(0);
ApkAssetsCookie cookie = assetmanager.GetResource(resid, false, /*may_be_bag*/
(short) (density), value, selected_config, flags);
if (cookie.intValue() == kInvalidCookie) {
return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
}
final Ref<Integer> ref = new Ref<>(resid);
if (resolve_references) {
cookie = assetmanager.ResolveReference(cookie, value, selected_config, flags, ref);
if (cookie.intValue() == kInvalidCookie) {
return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
}
}
return CopyValue(cookie, value.get(), ref.get(), flags.get(), selected_config.get(), typed_value);
}
use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.
the class ShadowArscAssetManager10 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;
}
Aggregations