use of com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder 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.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder 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.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder in project Diaguard by Faltenreich.
the class PdfLog method getRow.
private List<Cell> getRow(PdfExportCache cache, String title, String subtitle, String description, int backgroundColor, int foregroundColor) {
List<Cell> entryRow = new ArrayList<>();
float width = cache.getPage().getWidth();
Cell titleCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(PdfLog.TIME_WIDTH).setText(title).setBackgroundColor(backgroundColor).setForegroundColor(Color.gray).build();
entryRow.add(titleCell);
Cell subtitleCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(getLabelWidth()).setText(subtitle).setBackgroundColor(backgroundColor).setForegroundColor(Color.gray).build();
entryRow.add(subtitleCell);
Cell descriptionCell = new CellBuilder(new MultilineCell(cache.getFontNormal())).setWidth(width - titleCell.getWidth() - subtitleCell.getWidth()).setText(description).setBackgroundColor(backgroundColor).setForegroundColor(foregroundColor).build();
entryRow.add(descriptionCell);
return entryRow;
}
use of com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder in project Diaguard by Faltenreich.
the class PdfLog method init.
private void init() {
PdfExportConfig config = cache.getConfig();
Context context = config.getContext();
List<List<Cell>> data = new ArrayList<>();
List<Cell> headerRow = new ArrayList<>();
Cell headerCell = new CellBuilder(new Cell(cache.getFontBold())).setWidth(getLabelWidth()).setText(DateTimeUtils.toWeekDayAndDate(cache.getDateTime())).build();
headerRow.add(headerCell);
data.add(headerRow);
for (Entry entry : entriesOfDay) {
List<Measurement> measurements = EntryDao.getInstance().getMeasurements(entry, cache.getConfig().getCategories());
entry.setMeasurementCache(measurements);
}
int rowIndex = 0;
for (Entry entry : entriesOfDay) {
int backgroundColor = rowIndex % 2 == 0 ? cache.getColorDivider() : Color.white;
int oldSize = data.size();
String time = entry.getDate().toString("HH:mm");
for (Measurement measurement : entry.getMeasurementCache()) {
Category category = measurement.getCategory();
int textColor = Color.black;
if (category == Category.BLOODSUGAR && config.highlightLimits()) {
BloodSugar bloodSugar = (BloodSugar) measurement;
float value = bloodSugar.getMgDl();
if (value > PreferenceStore.getInstance().getLimitHyperglycemia()) {
textColor = cache.getColorHyperglycemia();
} else if (value < PreferenceStore.getInstance().getLimitHypoglycemia()) {
textColor = cache.getColorHypoglycemia();
}
}
String measurementText = measurement.print(context);
if (category == Category.MEAL && config.exportFood()) {
List<String> foodOfDay = new ArrayList<>();
Meal meal = (Meal) MeasurementDao.getInstance(Meal.class).getMeasurement(entry);
if (meal != null) {
for (FoodEaten foodEaten : FoodEatenDao.getInstance().getAll(meal)) {
String foodNote = foodEaten.print();
if (foodNote != null) {
foodOfDay.add(foodNote);
}
}
}
if (!foodOfDay.isEmpty()) {
String foodText = TextUtils.join(", ", foodOfDay);
measurementText = String.format("%s\n%s", measurementText, foodText);
}
}
data.add(getRow(cache, data.size() == oldSize ? time : null, context.getString(category.getStringAcronymResId()), measurementText, backgroundColor, textColor));
}
if (config.exportTags()) {
List<EntryTag> entryTags = EntryTagDao.getInstance().getAll(entry);
if (!entryTags.isEmpty()) {
List<String> tagNames = new ArrayList<>();
for (EntryTag entryTag : entryTags) {
Tag tag = entryTag.getTag();
if (tag != null) {
String tagName = tag.getName();
if (!StringUtils.isBlank(tagName)) {
tagNames.add(tagName);
}
}
}
data.add(getRow(cache, data.size() == oldSize ? time : null, context.getString(R.string.tags), TextUtils.join(", ", tagNames), backgroundColor));
}
}
if (config.exportNotes()) {
if (!StringUtils.isBlank(entry.getNote())) {
data.add(getRow(cache, data.size() == oldSize ? time : null, context.getString(R.string.note), entry.getNote(), backgroundColor));
}
}
rowIndex++;
}
boolean hasData = data.size() > 1;
if (!hasData) {
data.add(CellFactory.createEmptyRow(cache));
}
try {
table.setData(data);
} catch (Exception exception) {
Log.e(TAG, exception.toString());
}
}
Aggregations