Search in sources :

Example 1 with ResXMLParser

use of org.robolectric.res.android.ResXMLParser 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)

Example 2 with ResXMLParser

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

the class ShadowXmlBlock method nativeCreateParseState.

@Implementation(minSdk = VERSION_CODES.Q)
protected static long nativeCreateParseState(long obj, int resid) {
    ResXMLTree osb = Registries.NATIVE_RES_XML_TREES.getNativeObject(obj);
    // if (osb == NULL) {
    // jniThrowNullPointerException(env, NULL);
    // return 0;
    // }
    ResXMLParser st = new ResXMLParser(osb);
    // if (st == NULL) {
    // jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
    // return 0;
    // }
    st.setSourceResourceId(resid);
    st.restart();
    return Registries.NATIVE_RES_XML_PARSERS.register(st);
}
Also used : ResXMLTree(org.robolectric.res.android.ResXMLTree) ResXMLParser(org.robolectric.res.android.ResXMLParser) Implementation(org.robolectric.annotation.Implementation)

Example 3 with ResXMLParser

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

the class ShadowXmlBlock method nativeGetIdAttribute.

@Implementation(minSdk = VERSION_CODES.LOLLIPOP)
protected static int nativeGetIdAttribute(long state) {
    ResXMLParser resXMLParser = getResXMLParser(state);
    int idx = resXMLParser.indexOfID();
    return idx >= 0 ? resXMLParser.getAttributeValueStringID(idx) : -1;
}
Also used : ResXMLParser(org.robolectric.res.android.ResXMLParser) Implementation(org.robolectric.annotation.Implementation)

Example 4 with ResXMLParser

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

the class ShadowXmlBlock method nativeGetStyleAttribute.

@Implementation(minSdk = VERSION_CODES.LOLLIPOP)
protected static int nativeGetStyleAttribute(long state) {
    ResXMLParser resXMLParser = getResXMLParser(state);
    int idx = resXMLParser.indexOfStyle();
    if (idx < 0) {
        return 0;
    }
    final Ref<Res_value> valueRef = new Ref<>(new Res_value());
    if (resXMLParser.getAttributeValue(idx, valueRef) < 0) {
        return 0;
    }
    Res_value value = valueRef.get();
    return value.dataType == org.robolectric.res.android.ResourceTypes.Res_value.TYPE_REFERENCE || value.dataType == org.robolectric.res.android.ResourceTypes.Res_value.TYPE_ATTRIBUTE ? value.data : 0;
}
Also used : Ref(org.robolectric.res.android.Ref) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResXMLParser(org.robolectric.res.android.ResXMLParser) Implementation(org.robolectric.annotation.Implementation)

Example 5 with ResXMLParser

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

the class ShadowXmlBlock method nativeGetClassAttribute.

@Implementation(minSdk = VERSION_CODES.LOLLIPOP)
protected static int nativeGetClassAttribute(long state) {
    ResXMLParser resXMLParser = getResXMLParser(state);
    int idx = resXMLParser.indexOfClass();
    return idx >= 0 ? resXMLParser.getAttributeValueStringID(idx) : -1;
}
Also used : ResXMLParser(org.robolectric.res.android.ResXMLParser) Implementation(org.robolectric.annotation.Implementation)

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