Search in sources :

Example 1 with ResTableTheme

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

the class ShadowArscAssetManager method resolveAttrs.

@Implementation
@HiddenApi
protected static boolean resolveAttrs(long themeToken, int defStyleAttr, int defStyleRes, int[] inValues, int[] attrs, int[] outValues, int[] outIndices) {
    if (themeToken == 0) {
        throw new NullPointerException("theme token");
    }
    if (attrs == null) {
        throw new NullPointerException("attrs");
    }
    if (outValues == null) {
        throw new NullPointerException("out values");
    }
    final int NI = attrs.length;
    final int NV = outValues.length;
    if (NV < (NI * STYLE_NUM_ENTRIES)) {
        throw new IndexOutOfBoundsException("out values too small");
    }
    int[] src = attrs;
    // if (src == null) {
    // return JNI_FALSE;
    // }
    int[] srcValues = inValues;
    final int NSV = srcValues == null ? 0 : inValues.length;
    int[] baseDest = outValues;
    int destOffset = 0;
    if (baseDest == null) {
        return false;
    }
    int[] indices = null;
    if (outIndices != null) {
        if (outIndices.length > NI) {
            indices = outIndices;
        }
    }
    ResTableTheme theme = Registries.NATIVE_THEME_REGISTRY.getNativeObject(themeToken);
    boolean result = AttributeResolution.ResolveAttrs(theme, defStyleAttr, defStyleRes, srcValues, NSV, src, NI, baseDest, indices);
    if (indices != null) {
    // env.ReleasePrimitiveArrayCritical(outIndices, indices, 0);
    }
    return result;
}
Also used : ResTableTheme(org.robolectric.res.android.ResTableTheme) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 2 with ResTableTheme

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

the class ShadowArscAssetManager method copyTheme.

@HiddenApi
@Implementation(minSdk = LOLLIPOP, maxSdk = O_MR1)
public static void copyTheme(long destPtr, long sourcePtr) {
    ResTableTheme dest = Registries.NATIVE_THEME_REGISTRY.getNativeObject(destPtr);
    ResTableTheme src = Registries.NATIVE_THEME_REGISTRY.getNativeObject(sourcePtr);
    dest.setTo(src);
}
Also used : ResTableTheme(org.robolectric.res.android.ResTableTheme) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 3 with ResTableTheme

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

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

the class ShadowArscAssetManager method loadThemeAttributeValue.

@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected static int loadThemeAttributeValue(long themeHandle, int ident, TypedValue outValue, boolean resolve) {
    ResTableTheme theme = Preconditions.checkNotNull(Registries.NATIVE_THEME_REGISTRY.getNativeObject(themeHandle));
    ResTable res = theme.getResTable();
    final Ref<Res_value> value = new Ref<>(null);
    // XXX value could be different in different configs!
    final Ref<Integer> typeSpecFlags = new Ref<>(0);
    int block = theme.GetAttribute(ident, value, typeSpecFlags);
    final Ref<Integer> ref = new Ref<>(0);
    if (resolve) {
        block = res.resolveReference(value, block, ref, typeSpecFlags);
        if (kThrowOnBadId) {
            if (block == BAD_INDEX) {
                throw new IllegalStateException("Bad resource!");
            }
        }
    }
    return block >= 0 ? copyValue(outValue, res, value.get(), ref.get(), block, typeSpecFlags.get(), null) : block;
}
Also used : Ref(org.robolectric.res.android.Ref) ResTableTheme(org.robolectric.res.android.ResTableTheme) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable(org.robolectric.res.android.ResTable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 5 with ResTableTheme

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

the class ShadowArscAssetManager method newTheme.

@HiddenApi
@Implementation
protected final Number newTheme() {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return RuntimeEnvironment.castNativePtr(0);
    }
    ResTableTheme theme = new ResTableTheme(am.getResources());
    return RuntimeEnvironment.castNativePtr(Registries.NATIVE_THEME_REGISTRY.register(theme));
}
Also used : ResTableTheme(org.robolectric.res.android.ResTableTheme) CppAssetManager(org.robolectric.res.android.CppAssetManager) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

HiddenApi (org.robolectric.annotation.HiddenApi)5 Implementation (org.robolectric.annotation.Implementation)5 ResTableTheme (org.robolectric.res.android.ResTableTheme)5 CppAssetManager (org.robolectric.res.android.CppAssetManager)1 Ref (org.robolectric.res.android.Ref)1 ResTable (org.robolectric.res.android.ResTable)1 ResXMLParser (org.robolectric.res.android.ResXMLParser)1 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)1