Search in sources :

Example 6 with Style

use of org.robolectric.res.Style in project robolectric by robolectric.

the class ShadowLegacyAssetManager method attrsToTypedArray.

TypedArray attrsToTypedArray(Resources resources, AttributeSet set, int[] attrs, int defStyleAttr, long nativeTheme, int defStyleRes) {
    CharSequence[] stringData = new CharSequence[attrs.length];
    int[] data = new int[attrs.length * STYLE_NUM_ENTRIES];
    int[] indices = new int[attrs.length + 1];
    int nextIndex = 0;
    Style themeStyleSet = nativeTheme == 0 ? new EmptyStyle() : getNativeTheme(nativeTheme).themeStyleSet;
    for (int i = 0; i < attrs.length; i++) {
        int offset = i * STYLE_NUM_ENTRIES;
        TypedValue typedValue = buildTypedValue(set, attrs[i], defStyleAttr, themeStyleSet, defStyleRes);
        if (typedValue != null) {
            // noinspection PointlessArithmeticExpression
            data[offset + STYLE_TYPE] = typedValue.type;
            data[offset + STYLE_DATA] = typedValue.type == TypedValue.TYPE_STRING ? i : typedValue.data;
            data[offset + STYLE_ASSET_COOKIE] = typedValue.assetCookie;
            data[offset + STYLE_RESOURCE_ID] = typedValue.resourceId;
            data[offset + STYLE_CHANGING_CONFIGURATIONS] = typedValue.changingConfigurations;
            data[offset + STYLE_DENSITY] = typedValue.density;
            stringData[i] = typedValue.string;
            indices[nextIndex + 1] = i;
            nextIndex++;
        }
    }
    indices[0] = nextIndex;
    TypedArray typedArray = ShadowTypedArray.create(resources, attrs, data, indices, nextIndex, stringData);
    if (set != null) {
        ShadowTypedArray shadowTypedArray = Shadow.extract(typedArray);
        shadowTypedArray.positionDescription = set.getPositionDescription();
    }
    return typedArray;
}
Also used : EmptyStyle(org.robolectric.res.EmptyStyle) TypedArray(android.content.res.TypedArray) EmptyStyle(org.robolectric.res.EmptyStyle) Style(org.robolectric.res.Style) SuppressLint(android.annotation.SuppressLint) TypedValue(android.util.TypedValue)

Aggregations

EmptyStyle (org.robolectric.res.EmptyStyle)6 Style (org.robolectric.res.Style)6 TypedValue (android.util.TypedValue)4 TypedArray (android.content.res.TypedArray)2 HiddenApi (org.robolectric.annotation.HiddenApi)2 Implementation (org.robolectric.annotation.Implementation)2 AttributeResource (org.robolectric.res.AttributeResource)2 ResName (org.robolectric.res.ResName)2 SuppressLint (android.annotation.SuppressLint)1