Search in sources :

Example 6 with Theme

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

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

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

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

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

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

the class ShadowArscAssetManager10 method nativeThemeApplyStyle.

// static void NativeThemeApplyStyle(JNIEnv* env, jclass /*clazz*/, jlong ptr, jlong theme_ptr,
// jint resid, jboolean force) {
@Implementation(minSdk = P)
protected static void nativeThemeApplyStyle(long ptr, long theme_ptr, @StyleRes int resid, boolean force) {
    // AssetManager is accessed via the theme, so grab an explicit lock here.
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
    CHECK(theme.GetAssetManager() == assetmanager);
    // (void) assetmanager;
    theme.ApplyStyle(resid, force);
// TODO(adamlesinski): Consider surfacing exception when result is failure.
// CTS currently expects no exceptions from this method.
// std::string error_msg = StringPrintf("Failed to apply style 0x%08x to theme", resid);
// throw new IllegalArgumentException(error_msg.c_str());
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) Theme(org.robolectric.res.android.CppAssetManager2.Theme) Implementation(org.robolectric.annotation.Implementation)

Aggregations

Theme (org.robolectric.res.android.CppAssetManager2.Theme)12 CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)11 Implementation (org.robolectric.annotation.Implementation)10 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)6 ResolvedBag (org.robolectric.res.android.CppAssetManager2.ResolvedBag)4 Entry (org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry)4 ApkAssetsCookie (org.robolectric.res.android.ApkAssetsCookie)2 Ref (org.robolectric.res.android.Ref)2 ResTable_config (org.robolectric.res.android.ResTable_config)2 ResXMLParser (org.robolectric.res.android.ResXMLParser)2