Search in sources :

Example 36 with Res_value

use of org.robolectric.res.android.ResourceTypes.Res_value 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

Res_value (org.robolectric.res.android.ResourceTypes.Res_value)36 Ref (org.robolectric.res.android.Ref)22 Implementation (org.robolectric.annotation.Implementation)21 ResTable_config (org.robolectric.res.android.ResTable_config)16 ApkAssetsCookie (org.robolectric.res.android.ApkAssetsCookie)14 CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)14 ResolvedBag (org.robolectric.res.android.CppAssetManager2.ResolvedBag)14 Nullable (android.annotation.Nullable)6 HiddenApi (org.robolectric.annotation.HiddenApi)6 ResTable (org.robolectric.res.android.ResTable)6 ResTable.bag_entry (org.robolectric.res.android.ResTable.bag_entry)6 CppAssetManager (org.robolectric.res.android.CppAssetManager)5 Entry (org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry)5 ResStringPool (org.robolectric.res.android.ResStringPool)3 ResTable_map_entry (org.robolectric.res.android.ResourceTypes.ResTable_map_entry)3 CppApkAssets (org.robolectric.res.android.CppApkAssets)2 Theme (org.robolectric.res.android.CppAssetManager2.Theme)2 ResTable_map (org.robolectric.res.android.ResourceTypes.ResTable_map)2 ResTable_sparseTypeEntry (org.robolectric.res.android.ResourceTypes.ResTable_sparseTypeEntry)2 AttributeSet (android.util.AttributeSet)1