mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -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 textColors[];
|
||||
|
||||
private RectF baseLocation;
|
||||
|
||||
private int primaryColor;
|
||||
|
||||
private boolean isBackgroundTransparent;
|
||||
|
||||
private int textColor;
|
||||
|
||||
private int reverseTextColor;
|
||||
|
||||
private boolean isEditable;
|
||||
@@ -232,6 +232,7 @@ public class HistoryChart extends ScrollableChart
|
||||
pTextHeader.setAntiAlias(true);
|
||||
|
||||
pSquareBg = new Paint();
|
||||
pSquareBg.setAntiAlias(true);
|
||||
|
||||
pSquareFg = new Paint();
|
||||
pSquareFg.setAntiAlias(true);
|
||||
@@ -250,7 +251,7 @@ public class HistoryChart extends ScrollableChart
|
||||
headerOverflow = 0;
|
||||
previousMonth = "";
|
||||
previousYear = "";
|
||||
pTextHeader.setColor(textColor);
|
||||
pTextHeader.setColor(textColors[1]);
|
||||
|
||||
updateDate();
|
||||
GregorianCalendar currentDate = (GregorianCalendar) baseDate.clone();
|
||||
@@ -367,27 +368,41 @@ public class HistoryChart extends ScrollableChart
|
||||
GregorianCalendar date,
|
||||
int checkmarkOffset)
|
||||
{
|
||||
|
||||
int checkmark = 0;
|
||||
if (checkmarkOffset >= checkmarks.length) pSquareBg.setColor(colors[0]);
|
||||
if (checkmarkOffset >= checkmarks.length)
|
||||
{
|
||||
pSquareBg.setColor(colors[0]);
|
||||
pSquareFg.setColor(textColors[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkmark = checkmarks[checkmarkOffset];
|
||||
if(checkmark == 0)
|
||||
{
|
||||
pSquareBg.setColor(colors[0]);
|
||||
pSquareFg.setColor(textColors[1]);
|
||||
}
|
||||
else if(checkmark < target)
|
||||
{
|
||||
pSquareBg.setColor(colors[1]);
|
||||
pSquareFg.setColor(textColors[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
pSquareBg.setColor(colors[2]);
|
||||
pSquareFg.setColor(textColors[2]);
|
||||
}
|
||||
}
|
||||
|
||||
pSquareFg.setColor(reverseTextColor);
|
||||
pSquareFg.setStrokeWidth(columnWidth * 0.025f);
|
||||
|
||||
float round = dpToPixels(getContext(), 2);
|
||||
canvas.drawRoundRect(location, round, round, pSquareBg);
|
||||
|
||||
if (!isNumerical && checkmark == SKIPPED)
|
||||
{
|
||||
pSquareBg.setColor(colors[0]);
|
||||
pSquareBg.setStrokeWidth(columnWidth * 0.025f);
|
||||
|
||||
canvas.save();
|
||||
canvas.clipRect(location);
|
||||
float offset = - columnWidth;
|
||||
@@ -398,7 +413,7 @@ public class HistoryChart extends ScrollableChart
|
||||
location.bottom,
|
||||
location.right + offset,
|
||||
location.top,
|
||||
pSquareFg);
|
||||
pSquareBg);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
@@ -448,7 +463,11 @@ public class HistoryChart extends ScrollableChart
|
||||
colors[0] = Color.argb(16, 255, 255, 255);
|
||||
colors[1] = Color.argb(128, red, green, blue);
|
||||
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;
|
||||
}
|
||||
else
|
||||
@@ -457,9 +476,12 @@ public class HistoryChart extends ScrollableChart
|
||||
colors[0] = res.getColor(R.attr.lowContrastTextColor);
|
||||
colors[1] = Color.argb(127, red, green, blue);
|
||||
colors[2] = primaryColor;
|
||||
textColor = res.getColor(R.attr.mediumContrastTextColor);
|
||||
reverseTextColor =
|
||||
res.getColor(R.attr.highContrastReverseTextColor);
|
||||
|
||||
textColors = new int[3];
|
||||
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[] textColors;
|
||||
|
||||
private RectF rect;
|
||||
|
||||
private int baseSize;
|
||||
@@ -70,8 +72,6 @@ public class StreakChart extends View
|
||||
|
||||
private int textColor;
|
||||
|
||||
private int reverseTextColor;
|
||||
|
||||
public StreakChart(Context context)
|
||||
{
|
||||
super(context);
|
||||
@@ -213,7 +213,7 @@ public class StreakChart extends View
|
||||
|
||||
float yOffset = rect.centerY() + 0.3f * em;
|
||||
|
||||
paint.setColor(reverseTextColor);
|
||||
paint.setColor(percentageToTextColor(percentage));
|
||||
paint.setTextAlign(Paint.Align.CENTER);
|
||||
canvas.drawText(Long.toString(streak.getLength()), rect.centerX(),
|
||||
yOffset, paint);
|
||||
@@ -223,7 +223,7 @@ public class StreakChart extends View
|
||||
String startLabel = dateFormat.format(streak.getStart().toJavaDate());
|
||||
String endLabel = dateFormat.format(streak.getEnd().toJavaDate());
|
||||
|
||||
paint.setColor(textColor);
|
||||
paint.setColor(textColors[1]);
|
||||
paint.setTextAlign(Paint.Align.RIGHT);
|
||||
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[1] = Color.argb(96, red, green, blue);
|
||||
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()
|
||||
@@ -277,6 +280,12 @@ public class StreakChart extends View
|
||||
return colors[0];
|
||||
}
|
||||
|
||||
private int percentageToTextColor(float percentage)
|
||||
{
|
||||
if (percentage >= 0.5f) return textColors[2];
|
||||
return textColors[1];
|
||||
}
|
||||
|
||||
private void updateMaxMinLengths()
|
||||
{
|
||||
maxLength = 0;
|
||||
|
||||
Reference in New Issue
Block a user