class ThemeUtil {

    public static Drawable getDrawable(Context context, final TypedArray typedArray, final int index) {
        final TypedValue value = typedArray.peekValue(index);
        if (value == null) {
            return null;
        }
        if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING) {
            // if it is reference to some drawable.
            return typedArray.getDrawable(index);
        } else if (value.type == TypedValue.TYPE_INT_COLOR_ARGB8 || value.type == TypedValue.TYPE_INT_COLOR_ARGB4 || value.type ==
                TypedValue.TYPE_INT_COLOR_RGB8 || value.type == TypedValue.TYPE_INT_COLOR_RGB4) {
            // if it is reference to some color.
            return new ColorDrawable(typedArray.getColor(index, 0xFF000000)); // black color
        } else {
            throw new IllegalArgumentException(
                    context.getString(R.string.msdkui_exception_attribute_invalid, index));
        }
    }

    private  ThemeUtil();

}