Search in sources :

Example 11 with CppAssetManager2

use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.

the class ShadowArscAssetManager9 method nativeSetApkAssets.

// static void NativeSetApkAssets(JNIEnv* env, jclass /*clazz*/, jlong ptr,
// jobjectArray apk_assets_array, jboolean invalidate_caches) {
@Implementation(minSdk = P)
protected static void nativeSetApkAssets(long ptr, @NonNull android.content.res.ApkAssets[] apk_assets_array, boolean invalidate_caches) {
    ATRACE_NAME("AssetManager::SetApkAssets");
    int apk_assets_len = apk_assets_array.length;
    List<CppApkAssets> apk_assets = new ArrayList<>();
    // apk_assets.reserve(apk_assets_len);
    for (int i = 0; i < apk_assets_len; i++) {
        android.content.res.ApkAssets apkAssets = // env.GetObjectArrayElement(apk_assets_array, i);
        apk_assets_array[i];
        if (apkAssets == null) {
            throw new NullPointerException(String.format("ApkAssets at index %d is null", i));
        }
        long apk_assets_native_ptr = ((ShadowArscApkAssets9) Shadow.extract(apkAssets)).getNativePtr();
        // if (env.ExceptionCheck()) {
        // return;
        // }
        apk_assets.add(Registries.NATIVE_APK_ASSETS_REGISTRY.getNativeObject(apk_assets_native_ptr));
    }
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    assetmanager.SetApkAssets(apk_assets, invalidate_caches);
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ArrayList(java.util.ArrayList) CppApkAssets(org.robolectric.res.android.CppApkAssets) ApkAssets(android.content.res.ApkAssets) Implementation(org.robolectric.annotation.Implementation)

Example 12 with CppAssetManager2

use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.

the class ShadowArscAssetManager9 method nativeResolveAttrs.

// static jboolean NativeResolveAttrs(JNIEnv* env, jclass /*clazz*/, jlong ptr, jlong theme_ptr,
// jint def_style_attr, jint def_style_resid, jintArray
// java_values,
// jintArray java_attrs, jintArray out_java_values,
// jintArray out_java_indices) {
@Implementation(minSdk = P)
protected static boolean nativeResolveAttrs(long ptr, long theme_ptr, @AttrRes int def_style_attr, @StyleRes int def_style_resid, @Nullable int[] java_values, @NonNull int[] java_attrs, @NonNull int[] out_java_values, @NonNull int[] out_java_indices) {
    int attrs_len = java_attrs.length;
    int out_values_len = out_java_values.length;
    if (out_values_len < (attrs_len * STYLE_NUM_ENTRIES)) {
        throw new IndexOutOfBoundsException("outValues too small");
    }
    int[] attrs = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null));
    java_attrs;
    if (attrs == null) {
        return JNI_FALSE;
    }
    int[] values = null;
    int values_len = 0;
    if (java_values != null) {
        values_len = java_values.length;
        values = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_values, null));
        java_values;
        if (values == null) {
            // env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
            return JNI_FALSE;
        }
    }
    int[] out_values = out_java_values;
    // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_java_values, null));
    if (out_values == null) {
        // }
        return JNI_FALSE;
    }
    int[] out_indices = null;
    if (out_java_indices != null) {
        int out_indices_len = out_java_indices.length;
        if (out_indices_len > attrs_len) {
            out_indices = out_java_indices;
            // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_java_indices, null));
            if (out_indices == null) {
                // env.ReleasePrimitiveArrayCritical(out_java_values, out_values, JNI_ABORT);
                return JNI_FALSE;
            }
        }
    }
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
    CHECK(theme.GetAssetManager() == assetmanager);
    // (void) assetmanager;
    boolean result = ResolveAttrs(theme, (int) (def_style_attr), (int) (def_style_resid), values, values_len, attrs, attrs_len, out_values, out_indices);
    // env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
    return result ? JNI_TRUE : JNI_FALSE;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) Theme(org.robolectric.res.android.CppAssetManager2.Theme) Implementation(org.robolectric.annotation.Implementation)

Example 13 with CppAssetManager2

use of org.robolectric.res.android.CppAssetManager2 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 14 with CppAssetManager2

use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.

the class ShadowArscAssetManager9 method nativeThemeDump.

// static void NativeThemeDump(JNIEnv* /*env*/, jclass /*clazz*/, jlong ptr, jlong theme_ptr,
// jint priority, jstring tag, jstring prefix) {
@Implementation(minSdk = P)
protected static void nativeThemeDump(long ptr, long theme_ptr, int priority, String tag, String prefix) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
    CHECK(theme.GetAssetManager() == assetmanager);
// (void) assetmanager;
// (void) theme;
// (void) priority;
// (void) tag;
// (void) prefix;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) Theme(org.robolectric.res.android.CppAssetManager2.Theme) Implementation(org.robolectric.annotation.Implementation)

Example 15 with CppAssetManager2

use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.

the class ShadowArscAssetManager9 method nativeRetrieveAttributes.

// static jboolean NativeRetrieveAttributes(JNIEnv* env, jclass /*clazz*/, jlong ptr,
// jlong xml_parser_ptr, jintArray java_attrs,
// jintArray out_java_values, jintArray out_java_indices)
// {
@Implementation(minSdk = P)
protected static boolean nativeRetrieveAttributes(long ptr, long xml_parser_ptr, @NonNull int[] java_attrs, @NonNull int[] out_java_values, @NonNull int[] out_java_indices) {
    int attrs_len = java_attrs.length;
    int out_values_len = out_java_values.length;
    if (out_values_len < (attrs_len * STYLE_NUM_ENTRIES)) {
        throw new IndexOutOfBoundsException("outValues too small");
    }
    int[] attrs = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null));
    java_attrs;
    if (attrs == null) {
        return JNI_FALSE;
    }
    int[] out_values = out_java_values;
    // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_java_values, null));
    if (out_values == null) {
        // env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
        return JNI_FALSE;
    }
    int[] out_indices = null;
    if (out_java_indices != null) {
        int out_indices_len = out_java_indices.length;
        if (out_indices_len > attrs_len) {
            out_indices = out_java_indices;
            // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_java_indices, null));
            if (out_indices == null) {
                // env.ReleasePrimitiveArrayCritical(out_java_values, out_values, JNI_ABORT);
                return JNI_FALSE;
            }
        }
    }
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    ResXMLParser xml_parser = NATIVE_RES_XML_PARSERS.getNativeObject(xml_parser_ptr);
    boolean result = RetrieveAttributes(assetmanager, xml_parser, attrs, attrs_len, out_values, out_indices);
    // env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
    return result;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResXMLParser(org.robolectric.res.android.ResXMLParser) Implementation(org.robolectric.annotation.Implementation)

Aggregations

CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)66 Implementation (org.robolectric.annotation.Implementation)62 Nullable (android.annotation.Nullable)24 ApkAssetsCookie (org.robolectric.res.android.ApkAssetsCookie)20 ResolvedBag (org.robolectric.res.android.CppAssetManager2.ResolvedBag)18 ResTable_config (org.robolectric.res.android.ResTable_config)18 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)18 Ref (org.robolectric.res.android.Ref)16 FileNotFoundException (java.io.FileNotFoundException)12 Asset (org.robolectric.res.android.Asset)11 Theme (org.robolectric.res.android.CppAssetManager2.Theme)11 ResourceName (org.robolectric.res.android.CppAssetManager2.ResourceName)8 CppApkAssets (org.robolectric.res.android.CppApkAssets)4 Entry (org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry)4 ResXMLParser (org.robolectric.res.android.ResXMLParser)4 AnyRes (android.annotation.AnyRes)2 AttrRes (android.annotation.AttrRes)2 NonNull (android.annotation.NonNull)2 ApkAssets (android.content.res.ApkAssets)2 Configuration (android.content.res.Configuration)2