Search in sources :

Example 1 with ResolvedBag

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;
}
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)

Example 2 with ResolvedBag

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

Example 3 with ResolvedBag

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;
}
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)

Example 4 with ResolvedBag

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

Example 5 with ResolvedBag

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

Aggregations

ResolvedBag (org.robolectric.res.android.CppAssetManager2.ResolvedBag)18 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)15 Implementation (org.robolectric.annotation.Implementation)14 CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)14 ApkAssetsCookie (org.robolectric.res.android.ApkAssetsCookie)10 Ref (org.robolectric.res.android.Ref)10 ResTable_config (org.robolectric.res.android.ResTable_config)10 Nullable (android.annotation.Nullable)8 Entry (org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry)5 AttrRes (android.annotation.AttrRes)2 CppApkAssets (org.robolectric.res.android.CppApkAssets)2 ResStringPool (org.robolectric.res.android.ResStringPool)2 DynamicPackageEntry (org.robolectric.res.android.LoadedArsc.DynamicPackageEntry)1 ResTable_map (org.robolectric.res.android.ResourceTypes.ResTable_map)1 ResTable_map_entry (org.robolectric.res.android.ResourceTypes.ResTable_map_entry)1