mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -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 previousMonth;
|
||||||
private String previousYear;
|
private String previousYear;
|
||||||
private boolean justPrintedYear;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas)
|
protected void onDraw(Canvas canvas)
|
||||||
@@ -250,10 +249,9 @@ public class HabitHistoryView extends ScrollableDataView
|
|||||||
baseLocation.set(0, 0, columnWidth - squareSpacing, columnWidth - squareSpacing);
|
baseLocation.set(0, 0, columnWidth - squareSpacing, columnWidth - squareSpacing);
|
||||||
baseLocation.offset(getPaddingLeft(), getPaddingTop());
|
baseLocation.offset(getPaddingLeft(), getPaddingTop());
|
||||||
|
|
||||||
|
headerOverflow = 0;
|
||||||
previousMonth = "";
|
previousMonth = "";
|
||||||
previousYear = "";
|
previousYear = "";
|
||||||
justPrintedYear = false;
|
|
||||||
|
|
||||||
pTextHeader.setColor(textColor);
|
pTextHeader.setColor(textColor);
|
||||||
|
|
||||||
updateDate();
|
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)
|
private void drawColumnHeader(Canvas canvas, Rect location, GregorianCalendar date)
|
||||||
{
|
{
|
||||||
String month = dfMonth.format(date.getTime());
|
String month = dfMonth.format(date.getTime());
|
||||||
String year = dfYear.format(date.getTime());
|
String year = dfYear.format(date.getTime());
|
||||||
|
|
||||||
|
String text = null;
|
||||||
if (!month.equals(previousMonth))
|
if (!month.equals(previousMonth))
|
||||||
|
text = previousMonth = month;
|
||||||
|
else if(!year.equals(previousYear))
|
||||||
|
text = previousYear = year;
|
||||||
|
|
||||||
|
if(text != null)
|
||||||
{
|
{
|
||||||
int offset = 0;
|
canvas.drawText(text, location.left + headerOverflow, location.bottom - headerTextOffset, pTextHeader);
|
||||||
if (justPrintedYear)
|
headerOverflow += pTextHeader.measureText(text) + columnWidth * 0.2f;
|
||||||
{
|
|
||||||
offset += columnWidth;
|
|
||||||
justSkippedColumn = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.drawText(month, location.left + offset, location.bottom - headerTextOffset,
|
headerOverflow = Math.max(0, headerOverflow - columnWidth);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
||||||
|
|||||||
Reference in New Issue
Block a user