Skip to content

Commit

Permalink
Simplify code for drawing header
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Mar 14, 2016
1 parent 45a7433 commit f7f4b5e
Showing 1 changed file with 11 additions and 31 deletions.
42 changes: 11 additions & 31 deletions app/src/main/java/org/isoron/uhabits/views/HabitHistoryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ private void generateRandomData()

private String previousMonth;
private String previousYear;
private boolean justPrintedYear;

@Override
protected void onDraw(Canvas canvas)
Expand All @@ -250,10 +249,9 @@ protected void onDraw(Canvas canvas)
baseLocation.set(0, 0, columnWidth - squareSpacing, columnWidth - squareSpacing);
baseLocation.offset(getPaddingLeft(), getPaddingTop());

headerOverflow = 0;
previousMonth = "";
previousYear = "";
justPrintedYear = false;

pTextHeader.setColor(textColor);

updateDate();
Expand Down Expand Up @@ -307,44 +305,26 @@ private void drawAxis(Canvas canvas, Rect location)
}
}

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))
{
int offset = 0;
if (justPrintedYear)
{
offset += columnWidth;
justSkippedColumn = true;
}
text = previousMonth = month;
else if(!year.equals(previousYear))
text = previousYear = year;

canvas.drawText(month, location.left + offset, location.bottom - headerTextOffset,
pTextHeader);

previousMonth = month;
justPrintedYear = false;
}
else if (!year.equals(previousYear))
if(text != null)
{
if(!justSkippedColumn)
{
canvas.drawText(year, location.left, location.bottom - headerTextOffset, pTextHeader);
previousYear = year;
justPrintedYear = true;
}

justSkippedColumn = false;
}
else
{
justSkippedColumn = false;
justPrintedYear = false;
canvas.drawText(text, location.left + headerOverflow, location.bottom - headerTextOffset, pTextHeader);
headerOverflow += pTextHeader.measureText(text) + columnWidth * 0.2f;
}

headerOverflow = Math.max(0, headerOverflow - columnWidth);
}

public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
Expand Down

0 comments on commit f7f4b5e

Please sign in to comment.