mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Simplify code for drawing header
This commit is contained in:
@@ -240,7 +240,6 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
|
||||
private String previousMonth;
|
||||
private String previousYear;
|
||||
private boolean justPrintedYear;
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas)
|
||||
@@ -250,10 +249,9 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
baseLocation.set(0, 0, columnWidth - squareSpacing, columnWidth - squareSpacing);
|
||||
baseLocation.offset(getPaddingLeft(), getPaddingTop());
|
||||
|
||||
headerOverflow = 0;
|
||||
previousMonth = "";
|
||||
previousYear = "";
|
||||
justPrintedYear = false;
|
||||
|
||||
pTextHeader.setColor(textColor);
|
||||
|
||||
updateDate();
|
||||
@@ -307,44 +305,26 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
}
|
||||
}
|
||||
|
||||
private boolean justSkippedColumn = false;
|
||||
private float headerOverflow = 0;
|
||||
|
||||
private void drawColumnHeader(Canvas canvas, Rect location, GregorianCalendar date)
|
||||
{
|
||||
String month = dfMonth.format(date.getTime());
|
||||
String year = dfYear.format(date.getTime());
|
||||
|
||||
String text = null;
|
||||
if (!month.equals(previousMonth))
|
||||
text = previousMonth = month;
|
||||
else if(!year.equals(previousYear))
|
||||
text = previousYear = year;
|
||||
|
||||
if(text != null)
|
||||
{
|
||||
int offset = 0;
|
||||
if (justPrintedYear)
|
||||
{
|
||||
offset += columnWidth;
|
||||
justSkippedColumn = true;
|
||||
canvas.drawText(text, location.left + headerOverflow, location.bottom - headerTextOffset, pTextHeader);
|
||||
headerOverflow += pTextHeader.measureText(text) + columnWidth * 0.2f;
|
||||
}
|
||||
|
||||
canvas.drawText(month, location.left + offset, location.bottom - headerTextOffset,
|
||||
pTextHeader);
|
||||
|
||||
previousMonth = month;
|
||||
justPrintedYear = false;
|
||||
}
|
||||
else if (!year.equals(previousYear))
|
||||
{
|
||||
if(!justSkippedColumn)
|
||||
{
|
||||
canvas.drawText(year, location.left, location.bottom - headerTextOffset, pTextHeader);
|
||||
previousYear = year;
|
||||
justPrintedYear = true;
|
||||
}
|
||||
|
||||
justSkippedColumn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
justSkippedColumn = false;
|
||||
justPrintedYear = false;
|
||||
}
|
||||
headerOverflow = Math.max(0, headerOverflow - columnWidth);
|
||||
}
|
||||
|
||||
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
||||
|
||||
Reference in New Issue
Block a user