mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Improve readability of history and streak charts
Fixes #432 Co-authored-by: Alinson S. Xavier <git@axavier.org>
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 66 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 64 KiB |
@@ -75,14 +75,14 @@ public class HistoryChart extends ScrollableChart
|
|||||||
|
|
||||||
private int colors[];
|
private int colors[];
|
||||||
|
|
||||||
|
private int textColors[];
|
||||||
|
|
||||||
private RectF baseLocation;
|
private RectF baseLocation;
|
||||||
|
|
||||||
private int primaryColor;
|
private int primaryColor;
|
||||||
|
|
||||||
private boolean isBackgroundTransparent;
|
private boolean isBackgroundTransparent;
|
||||||
|
|
||||||
private int textColor;
|
|
||||||
|
|
||||||
private int reverseTextColor;
|
private int reverseTextColor;
|
||||||
|
|
||||||
private boolean isEditable;
|
private boolean isEditable;
|
||||||
@@ -232,6 +232,7 @@ public class HistoryChart extends ScrollableChart
|
|||||||
pTextHeader.setAntiAlias(true);
|
pTextHeader.setAntiAlias(true);
|
||||||
|
|
||||||
pSquareBg = new Paint();
|
pSquareBg = new Paint();
|
||||||
|
pSquareBg.setAntiAlias(true);
|
||||||
|
|
||||||
pSquareFg = new Paint();
|
pSquareFg = new Paint();
|
||||||
pSquareFg.setAntiAlias(true);
|
pSquareFg.setAntiAlias(true);
|
||||||
@@ -250,7 +251,7 @@ public class HistoryChart extends ScrollableChart
|
|||||||
headerOverflow = 0;
|
headerOverflow = 0;
|
||||||
previousMonth = "";
|
previousMonth = "";
|
||||||
previousYear = "";
|
previousYear = "";
|
||||||
pTextHeader.setColor(textColor);
|
pTextHeader.setColor(textColors[1]);
|
||||||
|
|
||||||
updateDate();
|
updateDate();
|
||||||
GregorianCalendar currentDate = (GregorianCalendar) baseDate.clone();
|
GregorianCalendar currentDate = (GregorianCalendar) baseDate.clone();
|
||||||
@@ -367,27 +368,41 @@ public class HistoryChart extends ScrollableChart
|
|||||||
GregorianCalendar date,
|
GregorianCalendar date,
|
||||||
int checkmarkOffset)
|
int checkmarkOffset)
|
||||||
{
|
{
|
||||||
|
|
||||||
int checkmark = 0;
|
int checkmark = 0;
|
||||||
if (checkmarkOffset >= checkmarks.length) pSquareBg.setColor(colors[0]);
|
if (checkmarkOffset >= checkmarks.length)
|
||||||
|
{
|
||||||
|
pSquareBg.setColor(colors[0]);
|
||||||
|
pSquareFg.setColor(textColors[1]);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
checkmark = checkmarks[checkmarkOffset];
|
checkmark = checkmarks[checkmarkOffset];
|
||||||
if(checkmark == 0)
|
if(checkmark == 0)
|
||||||
|
{
|
||||||
pSquareBg.setColor(colors[0]);
|
pSquareBg.setColor(colors[0]);
|
||||||
|
pSquareFg.setColor(textColors[1]);
|
||||||
|
}
|
||||||
else if(checkmark < target)
|
else if(checkmark < target)
|
||||||
|
{
|
||||||
pSquareBg.setColor(colors[1]);
|
pSquareBg.setColor(colors[1]);
|
||||||
|
pSquareFg.setColor(textColors[2]);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
pSquareBg.setColor(colors[2]);
|
pSquareBg.setColor(colors[2]);
|
||||||
|
pSquareFg.setColor(textColors[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pSquareFg.setColor(reverseTextColor);
|
|
||||||
pSquareFg.setStrokeWidth(columnWidth * 0.025f);
|
|
||||||
|
|
||||||
float round = dpToPixels(getContext(), 2);
|
float round = dpToPixels(getContext(), 2);
|
||||||
canvas.drawRoundRect(location, round, round, pSquareBg);
|
canvas.drawRoundRect(location, round, round, pSquareBg);
|
||||||
|
|
||||||
if (!isNumerical && checkmark == SKIPPED)
|
if (!isNumerical && checkmark == SKIPPED)
|
||||||
{
|
{
|
||||||
|
pSquareBg.setColor(colors[0]);
|
||||||
|
pSquareBg.setStrokeWidth(columnWidth * 0.025f);
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.clipRect(location);
|
canvas.clipRect(location);
|
||||||
float offset = - columnWidth;
|
float offset = - columnWidth;
|
||||||
@@ -398,7 +413,7 @@ public class HistoryChart extends ScrollableChart
|
|||||||
location.bottom,
|
location.bottom,
|
||||||
location.right + offset,
|
location.right + offset,
|
||||||
location.top,
|
location.top,
|
||||||
pSquareFg);
|
pSquareBg);
|
||||||
}
|
}
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
@@ -448,7 +463,11 @@ public class HistoryChart extends ScrollableChart
|
|||||||
colors[0] = Color.argb(16, 255, 255, 255);
|
colors[0] = Color.argb(16, 255, 255, 255);
|
||||||
colors[1] = Color.argb(128, red, green, blue);
|
colors[1] = Color.argb(128, red, green, blue);
|
||||||
colors[2] = primaryColor;
|
colors[2] = primaryColor;
|
||||||
textColor = Color.WHITE;
|
|
||||||
|
textColors = new int[3];
|
||||||
|
textColors[0] = Color.WHITE;
|
||||||
|
textColors[1] = Color.WHITE;
|
||||||
|
textColors[2] = Color.WHITE;
|
||||||
reverseTextColor = Color.WHITE;
|
reverseTextColor = Color.WHITE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -457,9 +476,12 @@ public class HistoryChart extends ScrollableChart
|
|||||||
colors[0] = res.getColor(R.attr.lowContrastTextColor);
|
colors[0] = res.getColor(R.attr.lowContrastTextColor);
|
||||||
colors[1] = Color.argb(127, red, green, blue);
|
colors[1] = Color.argb(127, red, green, blue);
|
||||||
colors[2] = primaryColor;
|
colors[2] = primaryColor;
|
||||||
textColor = res.getColor(R.attr.mediumContrastTextColor);
|
|
||||||
reverseTextColor =
|
textColors = new int[3];
|
||||||
res.getColor(R.attr.highContrastReverseTextColor);
|
textColors[0] = res.getColor(R.attr.lowContrastReverseTextColor);
|
||||||
|
textColors[1] = res.getColor(R.attr.mediumContrastTextColor);
|
||||||
|
textColors[2] = res.getColor(R.attr.highContrastReverseTextColor);
|
||||||
|
reverseTextColor = res.getColor(R.attr.highContrastReverseTextColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ public class StreakChart extends View
|
|||||||
|
|
||||||
private int[] colors;
|
private int[] colors;
|
||||||
|
|
||||||
|
private int[] textColors;
|
||||||
|
|
||||||
private RectF rect;
|
private RectF rect;
|
||||||
|
|
||||||
private int baseSize;
|
private int baseSize;
|
||||||
@@ -70,8 +72,6 @@ public class StreakChart extends View
|
|||||||
|
|
||||||
private int textColor;
|
private int textColor;
|
||||||
|
|
||||||
private int reverseTextColor;
|
|
||||||
|
|
||||||
public StreakChart(Context context)
|
public StreakChart(Context context)
|
||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
@@ -213,7 +213,7 @@ public class StreakChart extends View
|
|||||||
|
|
||||||
float yOffset = rect.centerY() + 0.3f * em;
|
float yOffset = rect.centerY() + 0.3f * em;
|
||||||
|
|
||||||
paint.setColor(reverseTextColor);
|
paint.setColor(percentageToTextColor(percentage));
|
||||||
paint.setTextAlign(Paint.Align.CENTER);
|
paint.setTextAlign(Paint.Align.CENTER);
|
||||||
canvas.drawText(Long.toString(streak.getLength()), rect.centerX(),
|
canvas.drawText(Long.toString(streak.getLength()), rect.centerX(),
|
||||||
yOffset, paint);
|
yOffset, paint);
|
||||||
@@ -223,7 +223,7 @@ public class StreakChart extends View
|
|||||||
String startLabel = dateFormat.format(streak.getStart().toJavaDate());
|
String startLabel = dateFormat.format(streak.getStart().toJavaDate());
|
||||||
String endLabel = dateFormat.format(streak.getEnd().toJavaDate());
|
String endLabel = dateFormat.format(streak.getEnd().toJavaDate());
|
||||||
|
|
||||||
paint.setColor(textColor);
|
paint.setColor(textColors[1]);
|
||||||
paint.setTextAlign(Paint.Align.RIGHT);
|
paint.setTextAlign(Paint.Align.RIGHT);
|
||||||
canvas.drawText(startLabel, gap - textMargin, yOffset, paint);
|
canvas.drawText(startLabel, gap - textMargin, yOffset, paint);
|
||||||
|
|
||||||
@@ -258,8 +258,11 @@ public class StreakChart extends View
|
|||||||
colors[2] = Color.argb(192, red, green, blue);
|
colors[2] = Color.argb(192, red, green, blue);
|
||||||
colors[1] = Color.argb(96, red, green, blue);
|
colors[1] = Color.argb(96, red, green, blue);
|
||||||
colors[0] = res.getColor(R.attr.lowContrastTextColor);
|
colors[0] = res.getColor(R.attr.lowContrastTextColor);
|
||||||
textColor = res.getColor(R.attr.mediumContrastTextColor);
|
|
||||||
reverseTextColor = res.getColor(R.attr.highContrastReverseTextColor);
|
textColors = new int[3];
|
||||||
|
textColors[2] = res.getColor(R.attr.highContrastReverseTextColor);
|
||||||
|
textColors[1] = res.getColor(R.attr.mediumContrastTextColor);
|
||||||
|
textColors[0] = res.getColor(R.attr.lowContrastReverseTextColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPaints()
|
private void initPaints()
|
||||||
@@ -277,6 +280,12 @@ public class StreakChart extends View
|
|||||||
return colors[0];
|
return colors[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int percentageToTextColor(float percentage)
|
||||||
|
{
|
||||||
|
if (percentage >= 0.5f) return textColors[2];
|
||||||
|
return textColors[1];
|
||||||
|
}
|
||||||
|
|
||||||
private void updateMaxMinLengths()
|
private void updateMaxMinLengths()
|
||||||
{
|
{
|
||||||
maxLength = 0;
|
maxLength = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user