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());
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations