Search in sources :

Example 21 with CppAssetManager2

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

the class ShadowArscAssetManager10 method NdkAssetManagerForJavaObject.

// ----------------------------------------------------------------------------
// interface AAssetManager {}
// 
// // Let the opaque type AAssetManager refer to a guarded AssetManager2 instance.
// static class GuardedAssetManager implements AAssetManager {
// CppAssetManager2 guarded_assetmanager = new CppAssetManager2();
// }
static CppAssetManager2 NdkAssetManagerForJavaObject(/* JNIEnv* env,*/
AssetManager jassetmanager) {
    // long assetmanager_handle = env.GetLongField(jassetmanager, gAssetManagerOffsets.mObject);
    long assetmanager_handle = ReflectionHelpers.getField(jassetmanager, "mObject");
    CppAssetManager2 am = Registries.NATIVE_ASSET_MANAGER_REGISTRY.getNativeObject(assetmanager_handle);
    if (am == null) {
        throw new IllegalStateException("AssetManager has been finalized!");
    }
    return am;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2)

Example 22 with CppAssetManager2

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

the class ShadowArscAssetManager10 method nativeThemeCopy.

// static void NativeThemeCopy(JNIEnv* env, jclass /*clazz*/, jlong dst_asset_manager_ptr,
// jlong dst_theme_ptr, jlong src_asset_manager_ptr, jlong src_theme_ptr) {
@Implementation(minSdk = Q)
protected static void nativeThemeCopy(long dst_asset_manager_ptr, long dst_theme_ptr, long src_asset_manager_ptr, long src_theme_ptr) {
    Theme dst_theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(dst_theme_ptr);
    Theme src_theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(src_theme_ptr);
    if (dst_asset_manager_ptr != src_asset_manager_ptr) {
        CppAssetManager2 dst_assetmanager = AssetManagerFromLong(dst_asset_manager_ptr);
        CHECK(dst_theme.GetAssetManager() == dst_assetmanager);
        // (void) dst_assetmanager;
        CppAssetManager2 src_assetmanager = AssetManagerFromLong(src_asset_manager_ptr);
        CHECK(src_theme.GetAssetManager() == src_assetmanager);
        // (void) src_assetmanager;
        dst_theme.SetTo(src_theme);
    } else {
        dst_theme.SetTo(src_theme);
    }
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) Theme(org.robolectric.res.android.CppAssetManager2.Theme) Implementation(org.robolectric.annotation.Implementation)

Example 23 with CppAssetManager2

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

the class ShadowArscAssetManager10 method nativeThemeGetAttributeValue.

// static jint NativeThemeGetAttributeValue(JNIEnv* env, jclass /*clazz*/, jlong ptr, jlong
// theme_ptr,
// jint resid, jobject typed_value,
// jboolean resolve_references) {
@Implementation(minSdk = P)
protected static int nativeThemeGetAttributeValue(long ptr, long theme_ptr, @AttrRes int resid, @NonNull TypedValue typed_value, boolean resolve_references) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
    CHECK(theme.GetAssetManager() == assetmanager);
    // (void) assetmanager; // huh?
    final Ref<Res_value> value = new Ref<>(null);
    final Ref<Integer> flags = new Ref<>(null);
    ApkAssetsCookie cookie = theme.GetAttribute(resid, value, flags);
    if (cookie.intValue() == kInvalidCookie) {
        return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
    }
    final Ref<Integer> ref = new Ref<>(0);
    if (resolve_references) {
        final Ref<ResTable_config> selected_config = new Ref<>(null);
        cookie = theme.GetAssetManager().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(), null, 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) Theme(org.robolectric.res.android.CppAssetManager2.Theme) ResTable_config(org.robolectric.res.android.ResTable_config) Implementation(org.robolectric.annotation.Implementation)

Example 24 with CppAssetManager2

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

the class ShadowArscAssetManager10 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 25 with CppAssetManager2

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

the class ShadowArscAssetManager10 method nativeGetResourceName.

// static jstring NativeGetResourceName(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid) {
@Implementation(minSdk = P)
@Nullable
protected static String nativeGetResourceName(long ptr, @AnyRes int resid) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    CppAssetManager2.ResourceName name = new ResourceName();
    if (!assetmanager.GetResourceName(resid, name)) {
        return null;
    }
    StringBuilder result = new StringBuilder();
    if (name.package_ != null) {
        result.append(name.package_);
    }
    if (name.type != null) /*|| name.type16 != null*/
    {
        if (!(result.length() == 0)) {
            result.append(":");
        }
        // if (name.type != null) {
        result.append(name.type);
    // } else {
    // result.append( /*util.Utf16ToUtf8(StringPiece16(*/ name.type16 /*, name.type_len))*/);
    // }
    }
    if (name.entry != null) /*|| name.entry16 != null*/
    {
        if (!(result.length() == 0)) {
            result.append("/");
        }
        // if (name.entry != null) {
        result.append(name.entry);
    // } else {
    // result.append( /*util.Utf16ToUtf8(StringPiece16(*/ name.entry16 /*, name.entry_len)*/);
    // }
    }
    return result.toString();
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResourceName(org.robolectric.res.android.CppAssetManager2.ResourceName) ResourceName(org.robolectric.res.android.CppAssetManager2.ResourceName) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

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