Search in sources :

Example 1 with Cell

use of com.pdfjet.Cell in project Diaguard by Faltenreich.

the class PdfTable method init.

private void init() {
    PdfExportConfig config = cache.getConfig();
    Context context = config.getContext();
    List<List<Cell>> data = new ArrayList<>();
    List<Cell> cells = new ArrayList<>();
    Cell headerCell = new CellBuilder(new Cell(cache.getFontBold())).setWidth(getLabelWidth()).setText(DateTimeUtils.toWeekDayAndDate(cache.getDateTime())).build();
    cells.add(headerCell);
    float cellWidth = (cache.getPage().getWidth() - getLabelWidth()) / (DateTimeConstants.HOURS_PER_DAY / 2f);
    for (int hour = 0; hour < DateTimeConstants.HOURS_PER_DAY; hour += PdfTable.HOURS_TO_SKIP) {
        Cell hourCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(cellWidth).setText(Integer.toString(hour)).setForegroundColor(Color.gray).setTextAlignment(Align.CENTER).build();
        cells.add(hourCell);
    }
    data.add(cells);
    LinkedHashMap<Category, CategoryValueListItem[]> values = EntryDao.getInstance().getAverageDataTable(cache.getDateTime(), config.getCategories(), HOURS_TO_SKIP);
    int rowIndex = 0;
    for (Category category : values.keySet()) {
        CategoryValueListItem[] items = values.get(category);
        if (items != null) {
            String label = context.getString(category.getStringAcronymResId());
            int backgroundColor = rowIndex % 2 == 0 ? cache.getColorDivider() : Color.white;
            switch(category) {
                case INSULIN:
                    if (config.splitInsulin()) {
                        data.add(createMeasurementRows(cache, items, cellWidth, 0, label + " " + context.getString(R.string.bolus), backgroundColor));
                        data.add(createMeasurementRows(cache, items, cellWidth, 1, label + " " + context.getString(R.string.correction), backgroundColor));
                        data.add(createMeasurementRows(cache, items, cellWidth, 2, label + " " + context.getString(R.string.basal), backgroundColor));
                    } else {
                        data.add(createMeasurementRows(cache, items, cellWidth, -1, label, backgroundColor));
                    }
                    break;
                case PRESSURE:
                    data.add(createMeasurementRows(cache, items, cellWidth, 0, label + " " + context.getString(R.string.systolic_acronym), backgroundColor));
                    data.add(createMeasurementRows(cache, items, cellWidth, 1, label + " " + context.getString(R.string.diastolic_acronym), backgroundColor));
                    break;
                default:
                    data.add(createMeasurementRows(cache, items, cellWidth, 0, label, backgroundColor));
                    break;
            }
            rowIndex++;
        }
    }
    if (config.exportNotes() || config.exportTags() || config.exportFood()) {
        List<PdfNote> pdfNotes = new ArrayList<>();
        for (Entry entry : entriesOfDay) {
            PdfNote pdfNote = PdfNoteFactory.createNote(config, entry);
            if (pdfNote != null) {
                pdfNotes.add(pdfNote);
            }
        }
        data.addAll(CellFactory.createRowsForNotes(cache, pdfNotes, getLabelWidth()));
    }
    boolean hasData = data.size() > 1;
    if (!hasData) {
        data.add(CellFactory.createEmptyRow(cache));
    }
    try {
        table.setData(data);
    } catch (Exception exception) {
        Log.e(TAG, exception.toString());
    }
}
Also used : PdfExportConfig(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig) Context(android.content.Context) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) ArrayList(java.util.ArrayList) CategoryValueListItem(com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem) Point(com.pdfjet.Point) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) CellBuilder(com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Cell(com.pdfjet.Cell) PdfNote(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote)

Example 2 with Cell

use of com.pdfjet.Cell in project Diaguard by Faltenreich.

the class PdfTable method createMeasurementRows.

private List<Cell> createMeasurementRows(PdfExportCache cache, CategoryValueListItem[] items, float cellWidth, int valueIndex, String label, int backgroundColor) {
    List<Cell> cells = new ArrayList<>();
    Cell labelCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(getLabelWidth()).setText(label).setBackgroundColor(backgroundColor).setForegroundColor(Color.gray).build();
    cells.add(labelCell);
    for (CategoryValueListItem item : items) {
        Category category = item.getCategory();
        float value = 0;
        switch(valueIndex) {
            case -1:
                value = item.getValueTotal();
                break;
            case 0:
                value = item.getValueOne();
                break;
            case 1:
                value = item.getValueTwo();
                break;
            case 2:
                value = item.getValueThree();
                break;
        }
        int textColor = Color.black;
        if (category == Category.BLOODSUGAR && cache.getConfig().highlightLimits()) {
            if (value > PreferenceStore.getInstance().getLimitHyperglycemia()) {
                textColor = cache.getColorHyperglycemia();
            } else if (value < PreferenceStore.getInstance().getLimitHypoglycemia()) {
                textColor = cache.getColorHypoglycemia();
            }
        }
        float customValue = PreferenceStore.getInstance().formatDefaultToCustomUnit(category, value);
        String text = customValue > 0 ? FloatUtils.parseFloat(customValue) : "";
        Cell measurementCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(cellWidth).setText(text).setTextAlignment(Align.CENTER).setBackgroundColor(backgroundColor).setForegroundColor(textColor).build();
        cells.add(measurementCell);
    }
    return cells;
}
Also used : Category(com.faltenreich.diaguard.shared.data.database.entity.Category) CellBuilder(com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder) ArrayList(java.util.ArrayList) CategoryValueListItem(com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem) Cell(com.pdfjet.Cell) Point(com.pdfjet.Point)

Example 3 with Cell

use of com.pdfjet.Cell in project Diaguard by Faltenreich.

the class PdfTimeline method createRowForMeasurements.

private List<Cell> createRowForMeasurements(Category category, CategoryValueListItem[] values, int rowIndex, int valueIndex, String label) {
    List<Cell> row = new ArrayList<>();
    Cell titleCell = new Cell(cache.getFontNormal());
    titleCell.setText(label);
    titleCell.setWidth(getLabelWidth());
    titleCell.setBgColor(rowIndex % 2 == 0 ? cache.getColorDivider() : Color.white);
    titleCell.setFgColor(Color.gray);
    titleCell.setPenColor(Color.gray);
    row.add(titleCell);
    for (CategoryValueListItem item : values) {
        Cell valueCell = new Cell(cache.getFontNormal());
        float value = 0;
        switch(valueIndex) {
            case -1:
                value = item.getValueTotal();
                break;
            case 0:
                value = item.getValueOne();
                break;
            case 1:
                value = item.getValueTwo();
                break;
            case 2:
                value = item.getValueThree();
                break;
        }
        float customValue = PreferenceStore.getInstance().formatDefaultToCustomUnit(category, value);
        String text = customValue > 0 ? FloatUtils.parseFloat(customValue) : "";
        valueCell.setText(text);
        valueCell.setWidth((cache.getPage().getWidth() - getLabelWidth()) / (DateTimeConstants.HOURS_PER_DAY / HOUR_INTERVAL));
        valueCell.setBgColor(rowIndex % 2 == 0 ? cache.getColorDivider() : Color.white);
        valueCell.setFgColor(Color.black);
        valueCell.setPenColor(Color.gray);
        valueCell.setTextAlignment(Align.CENTER);
        row.add(valueCell);
    }
    return row;
}
Also used : ArrayList(java.util.ArrayList) CategoryValueListItem(com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem) Cell(com.pdfjet.Cell)

Example 4 with Cell

use of com.pdfjet.Cell in project Diaguard by Faltenreich.

the class CellFactory method createRowsForNotes.

public static List<List<Cell>> createRowsForNotes(PdfExportCache cache, List<PdfNote> pdfNotes, float labelWidth) {
    List<List<Cell>> rows = new ArrayList<>();
    for (PdfNote note : pdfNotes) {
        boolean isFirst = pdfNotes.indexOf(note) == 0;
        boolean isLast = pdfNotes.indexOf(note) == pdfNotes.size() - 1;
        ArrayList<Cell> noteCells = new ArrayList<>();
        Cell timeCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(labelWidth).setText(Helper.getTimeFormat().print(note.getDateTime())).setForegroundColor(Color.gray).build();
        if (isFirst) {
            timeCell.setBorder(Border.TOP, true);
        }
        if (isLast) {
            timeCell.setBorder(Border.BOTTOM, true);
        }
        noteCells.add(timeCell);
        Cell noteCell = new CellBuilder(new MultilineCell(cache.getFontNormal())).setWidth(cache.getPage().getWidth() - labelWidth).setText(note.getNote()).setForegroundColor(Color.gray).build();
        if (isFirst) {
            noteCell.setBorder(Border.TOP, true);
        }
        if (isLast) {
            noteCell.setBorder(Border.BOTTOM, true);
        }
        noteCells.add(noteCell);
        rows.add(noteCells);
    }
    return rows;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PdfNote(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote) Cell(com.pdfjet.Cell)

Example 5 with Cell

use of com.pdfjet.Cell in project Diaguard by Faltenreich.

the class SizedTable method getHeight.

public float getHeight() {
    float height = 0;
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        try {
            float maxHeightOfRow = 0f;
            for (Cell cell : getRowAtIndex(rowIndex)) {
                float cellHeight = cell.getHeight();
                if (cellHeight > maxHeightOfRow) {
                    maxHeightOfRow = cellHeight;
                }
            }
            height += maxHeightOfRow;
        } catch (Exception exception) {
            Log.e(TAG, exception.toString());
        }
    }
    return height;
}
Also used : Cell(com.pdfjet.Cell)

Aggregations

Cell (com.pdfjet.Cell)7 ArrayList (java.util.ArrayList)6 CellBuilder (com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder)4 CategoryValueListItem (com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem)3 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)3 Point (com.pdfjet.Point)3 List (java.util.List)3 Context (android.content.Context)2 PdfExportConfig (com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig)2 PdfNote (com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote)2 MultilineCell (com.faltenreich.diaguard.feature.export.job.pdf.view.MultilineCell)2 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)2 BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)1 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)1 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)1 Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)1 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)1 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)1