Search in sources :

Example 6 with ResXMLParser

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

the class ShadowArscAssetManager method retrieveAttributes.

@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected final boolean retrieveAttributes(long xmlParserToken, int[] attrs, int[] outValues, int[] outIndices) {
    if (xmlParserToken == 0) {
        throw new NullPointerException("xmlParserToken");
    // return JNI_FALSE;
    }
    if (attrs == null) {
        throw new NullPointerException("attrs");
    // return JNI_FALSE;
    }
    if (outValues == null) {
        throw new NullPointerException("out values");
    // return JNI_FALSE;
    }
    CppAssetManager am = assetManagerForJavaObject();
    // if (am == null) {
    // return JNI_FALSE;
    // }
    ResTable res = am.getResources();
    // ResXMLParser xmlParser = (ResXMLParser*)xmlParserToken;
    ResXMLParser xmlParser = Registries.NATIVE_RES_XML_PARSERS.getNativeObject(xmlParserToken);
    // const int NI = env.GetArrayLength(attrs);
    // const int NV = env.GetArrayLength(outValues);
    final int NI = attrs.length;
    final int NV = outValues.length;
    if (NV < (NI * STYLE_NUM_ENTRIES)) {
        throw new IndexOutOfBoundsException("out values too small");
    // return JNI_FALSE;
    }
    // int[] src = (int[])env.GetPrimitiveArrayCritical(attrs, 0);
    // if (src == null) {
    // return JNI_FALSE;
    // }
    int[] src = attrs;
    // int[] baseDest = (int[])env.GetPrimitiveArrayCritical(outValues, 0);
    int[] baseDest = outValues;
    if (baseDest == null) {
        // return JNI_FALSE;
        return false;
    }
    int[] indices = null;
    if (outIndices != null) {
        if (outIndices.length > NI) {
            // indices = (int[])env.GetPrimitiveArrayCritical(outIndices, 0);
            indices = outIndices;
        }
    }
    boolean result = AttributeResolution.RetrieveAttributes(res, xmlParser, src, NI, baseDest, indices);
    if (indices != null) {
    // indices[0] = indicesIdx;
    // env.ReleasePrimitiveArrayCritical(outIndices, indices, 0);
    }
    return result;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable(org.robolectric.res.android.ResTable) ResXMLParser(org.robolectric.res.android.ResXMLParser) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 7 with ResXMLParser

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

the class ShadowArscAssetManager method applyStyle.

@HiddenApi
@Implementation(minSdk = LOLLIPOP, maxSdk = N_MR1)
protected static void applyStyle(long themeToken, int defStyleAttr, int defStyleRes, long xmlParserToken, int[] attrs, int[] outValues, int[] outIndices) {
    ResTableTheme theme = Registries.NATIVE_THEME_REGISTRY.getNativeObject(themeToken);
    ResXMLParser xmlParser = xmlParserToken == 0 ? null : Registries.NATIVE_RES_XML_PARSERS.getNativeObject(xmlParserToken);
    AttributeResolution.ApplyStyle(theme, xmlParser, defStyleAttr, defStyleRes, attrs, attrs.length, outValues, outIndices);
}
Also used : ResTableTheme(org.robolectric.res.android.ResTableTheme) ResXMLParser(org.robolectric.res.android.ResXMLParser) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 8 with ResXMLParser

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

the class ShadowArscAssetManager9 method nativeApplyStyle_measured.

private static void nativeApplyStyle_measured(long ptr, long theme_ptr, @AttrRes int def_style_attr, @StyleRes int def_style_resid, long xml_parser_ptr, @NonNull int[] java_attrs, long out_values_ptr, long out_indices_ptr) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
    CHECK(theme.GetAssetManager() == assetmanager);
    // (void) assetmanager;
    ResXMLParser xml_parser = xml_parser_ptr == 0 ? null : NATIVE_RES_XML_PARSERS.getNativeObject(xml_parser_ptr);
    // int[] out_values = reinterpret_cast<int*>(out_values_ptr);
    // int[] out_indices = reinterpret_cast<int*>(out_indices_ptr);
    ShadowVMRuntime shadowVMRuntime = Shadow.extract(VMRuntime.getRuntime());
    int[] out_values = (int[]) shadowVMRuntime.getObjectForAddress(out_values_ptr);
    int[] out_indices = (int[]) shadowVMRuntime.getObjectForAddress(out_indices_ptr);
    int attrs_len = java_attrs.length;
    int[] attrs = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null));
    java_attrs;
    // if (attrs == null) {
    // return;
    // }
    ApplyStyle(theme, xml_parser, (int) (def_style_attr), (int) (def_style_resid), attrs, attrs_len, out_values, out_indices);
// env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) Theme(org.robolectric.res.android.CppAssetManager2.Theme) ResXMLParser(org.robolectric.res.android.ResXMLParser)

Example 9 with ResXMLParser

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

the class ShadowArscAssetManager10 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)

Example 10 with ResXMLParser

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

the class ShadowArscAssetManager10 method nativeApplyStyle_measured.

private static void nativeApplyStyle_measured(long ptr, long theme_ptr, @AttrRes int def_style_attr, @StyleRes int def_style_resid, long xml_parser_ptr, @NonNull int[] java_attrs, long out_values_ptr, long out_indices_ptr) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
    CHECK(theme.GetAssetManager() == assetmanager);
    // (void) assetmanager;
    ResXMLParser xml_parser = xml_parser_ptr == 0 ? null : NATIVE_RES_XML_PARSERS.getNativeObject(xml_parser_ptr);
    // int[] out_values = reinterpret_cast<int*>(out_values_ptr);
    // int[] out_indices = reinterpret_cast<int*>(out_indices_ptr);
    ShadowVMRuntime shadowVMRuntime = Shadow.extract(VMRuntime.getRuntime());
    int[] out_values = (int[]) shadowVMRuntime.getObjectForAddress(out_values_ptr);
    int[] out_indices = (int[]) shadowVMRuntime.getObjectForAddress(out_indices_ptr);
    int attrs_len = java_attrs.length;
    int[] attrs = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null));
    java_attrs;
    // if (attrs == null) {
    // return;
    // }
    ApplyStyle(theme, xml_parser, (int) (def_style_attr), (int) (def_style_resid), attrs, attrs_len, out_values, out_indices);
// env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) Theme(org.robolectric.res.android.CppAssetManager2.Theme) ResXMLParser(org.robolectric.res.android.ResXMLParser)

Aggregations

ResXMLParser (org.robolectric.res.android.ResXMLParser)12 Implementation (org.robolectric.annotation.Implementation)10 CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)4 HiddenApi (org.robolectric.annotation.HiddenApi)2 Theme (org.robolectric.res.android.CppAssetManager2.Theme)2 ResXMLTree (org.robolectric.res.android.ResXMLTree)2 CppAssetManager (org.robolectric.res.android.CppAssetManager)1 Ref (org.robolectric.res.android.Ref)1 ResTable (org.robolectric.res.android.ResTable)1 ResTableTheme (org.robolectric.res.android.ResTableTheme)1 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)1