Search in sources :

Example 26 with ResTable_config

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());
}
Also used : ResTable_config(org.robolectric.res.android.ResTable_config) Test(org.junit.Test)

Example 27 with ResTable_config

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);
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResolvedBag(org.robolectric.res.android.CppAssetManager2.ResolvedBag) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable_config(org.robolectric.res.android.ResTable_config) Ref(org.robolectric.res.android.Ref) ApkAssetsCookie(org.robolectric.res.android.ApkAssetsCookie) Implementation(org.robolectric.annotation.Implementation)

Example 28 with ResTable_config

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;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) Configuration(android.content.res.Configuration) ResTable_config(org.robolectric.res.android.ResTable_config) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Example 29 with ResTable_config

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);
}
Also used : Ref(org.robolectric.res.android.Ref) CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ApkAssetsCookie(org.robolectric.res.android.ApkAssetsCookie) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable_config(org.robolectric.res.android.ResTable_config) Implementation(org.robolectric.annotation.Implementation)

Example 30 with ResTable_config

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;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResolvedBag(org.robolectric.res.android.CppAssetManager2.ResolvedBag) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable_config(org.robolectric.res.android.ResTable_config) Ref(org.robolectric.res.android.Ref) ApkAssetsCookie(org.robolectric.res.android.ApkAssetsCookie) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Aggregations

ResTable_config (org.robolectric.res.android.ResTable_config)31 Implementation (org.robolectric.annotation.Implementation)22 CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)18 Ref (org.robolectric.res.android.Ref)17 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)16 ApkAssetsCookie (org.robolectric.res.android.ApkAssetsCookie)14 ResolvedBag (org.robolectric.res.android.CppAssetManager2.ResolvedBag)10 Nullable (android.annotation.Nullable)8 Test (org.junit.Test)5 HiddenApi (org.robolectric.annotation.HiddenApi)4 CppAssetManager (org.robolectric.res.android.CppAssetManager)3 Configuration (android.content.res.Configuration)2 Path (java.nio.file.Path)2 CppApkAssets (org.robolectric.res.android.CppApkAssets)2 Theme (org.robolectric.res.android.CppAssetManager2.Theme)2 ResStringPool (org.robolectric.res.android.ResStringPool)2 ResTable (org.robolectric.res.android.ResTable)2 SuppressLint (android.annotation.SuppressLint)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Locale (java.util.Locale)1