|
|
|
@ -27,7 +27,6 @@ import android.util.AttributeSet;
|
|
|
|
|
|
|
|
|
|
import org.isoron.helpers.ColorHelper;
|
|
|
|
|
import org.isoron.helpers.DateHelper;
|
|
|
|
|
import org.isoron.uhabits.R;
|
|
|
|
|
import org.isoron.uhabits.models.Habit;
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
@ -37,6 +36,10 @@ import java.util.Random;
|
|
|
|
|
public class HabitScoreView extends ScrollableDataView
|
|
|
|
|
{
|
|
|
|
|
public static final int BUCKET_SIZE = 7;
|
|
|
|
|
public static final PorterDuffXfermode XFERMODE_CLEAR =
|
|
|
|
|
new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
|
|
|
|
|
public static final PorterDuffXfermode XFERMODE_SRC =
|
|
|
|
|
new PorterDuffXfermode(PorterDuff.Mode.SRC);
|
|
|
|
|
|
|
|
|
|
private Paint pGrid;
|
|
|
|
|
private float em;
|
|
|
|
@ -48,14 +51,18 @@ public class HabitScoreView extends ScrollableDataView
|
|
|
|
|
private RectF rect, prevRect;
|
|
|
|
|
private int baseSize;
|
|
|
|
|
|
|
|
|
|
private int columnWidth;
|
|
|
|
|
private int columnHeight;
|
|
|
|
|
private int nColumns;
|
|
|
|
|
|
|
|
|
|
private int[] colors;
|
|
|
|
|
private int[] scores;
|
|
|
|
|
private int primaryColor;
|
|
|
|
|
private boolean isBackgroundTransparent;
|
|
|
|
|
|
|
|
|
|
public HabitScoreView(Context context, AttributeSet attrs)
|
|
|
|
|
{
|
|
|
|
|
super(context, attrs);
|
|
|
|
|
this.baseSize = (int) context.getResources().getDimension(R.dimen.small_square_size);
|
|
|
|
|
this.primaryColor = ColorHelper.palette[7];
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
@ -72,7 +79,6 @@ public class HabitScoreView extends ScrollableDataView
|
|
|
|
|
{
|
|
|
|
|
createPaints();
|
|
|
|
|
createColors();
|
|
|
|
|
updateDimensions();
|
|
|
|
|
|
|
|
|
|
dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
|
|
|
|
|
dfDay = new SimpleDateFormat("d", Locale.getDefault());
|
|
|
|
@ -109,18 +115,33 @@ public class HabitScoreView extends ScrollableDataView
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void updateDimensions()
|
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
|
|
|
|
{
|
|
|
|
|
this.columnWidth = baseSize;
|
|
|
|
|
int width = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
|
int height = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
|
|
|
|
|
|
int b = height / 9;
|
|
|
|
|
height = b * 9;
|
|
|
|
|
width = (width / b) * b;
|
|
|
|
|
|
|
|
|
|
setMeasuredDimension(width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
|
|
|
|
|
{
|
|
|
|
|
baseSize = height / 9;
|
|
|
|
|
setScrollerBucketSize(baseSize);
|
|
|
|
|
|
|
|
|
|
columnWidth = baseSize;
|
|
|
|
|
columnHeight = 8 * baseSize;
|
|
|
|
|
headerHeight = baseSize;
|
|
|
|
|
footerHeight = baseSize;
|
|
|
|
|
em = pText.getFontSpacing();
|
|
|
|
|
nColumns = width / baseSize;
|
|
|
|
|
|
|
|
|
|
pText.setTextSize(baseSize * 0.5f);
|
|
|
|
|
pGraph.setTextSize(baseSize * 0.5f);
|
|
|
|
|
pGraph.setStrokeWidth(baseSize * 0.1f);
|
|
|
|
|
pGrid.setStrokeWidth(baseSize * 0.05f);
|
|
|
|
|
em = pText.getFontSpacing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void fetchData()
|
|
|
|
@ -162,7 +183,6 @@ public class HabitScoreView extends ScrollableDataView
|
|
|
|
|
float lineHeight = pText.getFontSpacing();
|
|
|
|
|
|
|
|
|
|
rect.set(0, 0, nColumns * columnWidth, columnHeight);
|
|
|
|
|
rect.offset(0, headerHeight);
|
|
|
|
|
drawGrid(canvas, rect);
|
|
|
|
|
|
|
|
|
|
String previousMonth = "";
|
|
|
|
@ -172,7 +192,7 @@ public class HabitScoreView extends ScrollableDataView
|
|
|
|
|
|
|
|
|
|
long currentDate = DateHelper.getStartOfToday();
|
|
|
|
|
|
|
|
|
|
for(int k = 0; k < nColumns + dataOffset - 1; k++)
|
|
|
|
|
for(int k = 0; k < nColumns + getDataOffset() - 1; k++)
|
|
|
|
|
currentDate -= 7 * DateHelper.millisecondsInOneDay;
|
|
|
|
|
|
|
|
|
|
for (int k = 0; k < nColumns; k++)
|
|
|
|
@ -181,15 +201,14 @@ public class HabitScoreView extends ScrollableDataView
|
|
|
|
|
String day = dfDay.format(currentDate);
|
|
|
|
|
|
|
|
|
|
int score = 0;
|
|
|
|
|
int offset = nColumns - k - 1 + dataOffset;
|
|
|
|
|
int offset = nColumns - k - 1 + getDataOffset();
|
|
|
|
|
if(offset < scores.length) score = scores[offset];
|
|
|
|
|
|
|
|
|
|
double sRelative = ((double) score) / Habit.MAX_SCORE;
|
|
|
|
|
int height = (int) (columnHeight * sRelative);
|
|
|
|
|
|
|
|
|
|
rect.set(0, 0, columnWidth, columnWidth);
|
|
|
|
|
rect.offset(k * columnWidth,
|
|
|
|
|
headerHeight + columnHeight - height - columnWidth / 2);
|
|
|
|
|
rect.set(0, 0, baseSize, baseSize);
|
|
|
|
|
rect.offset(k * columnWidth, columnHeight - height - columnWidth / 2);
|
|
|
|
|
|
|
|
|
|
if (!prevRect.isEmpty())
|
|
|
|
|
{
|
|
|
|
@ -202,7 +221,7 @@ public class HabitScoreView extends ScrollableDataView
|
|
|
|
|
prevRect.set(rect);
|
|
|
|
|
|
|
|
|
|
rect.set(0, 0, columnWidth, columnHeight);
|
|
|
|
|
rect.offset(k * columnWidth, headerHeight);
|
|
|
|
|
rect.offset(k * columnWidth, 0);
|
|
|
|
|
if (!month.equals(previousMonth))
|
|
|
|
|
canvas.drawText(month, rect.centerX(), rect.bottom + lineHeight * 1.2f, pText);
|
|
|
|
|
else
|
|
|
|
@ -240,18 +259,31 @@ public class HabitScoreView extends ScrollableDataView
|
|
|
|
|
private void drawMarker(Canvas canvas, RectF rect)
|
|
|
|
|
{
|
|
|
|
|
rect.inset(columnWidth * 0.15f, columnWidth * 0.15f);
|
|
|
|
|
pGraph.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
|
|
|
|
|
setModeOrColor(pGraph, XFERMODE_CLEAR, Color.WHITE);
|
|
|
|
|
canvas.drawOval(rect, pGraph);
|
|
|
|
|
|
|
|
|
|
rect.inset(columnWidth * 0.1f, columnWidth * 0.1f);
|
|
|
|
|
pGraph.setColor(primaryColor);
|
|
|
|
|
pGraph.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
|
|
|
|
|
setModeOrColor(pGraph, XFERMODE_SRC, primaryColor);
|
|
|
|
|
canvas.drawOval(rect, pGraph);
|
|
|
|
|
|
|
|
|
|
rect.inset(columnWidth * 0.1f, columnWidth * 0.1f);
|
|
|
|
|
pGraph.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
|
|
|
|
|
setModeOrColor(pGraph, XFERMODE_CLEAR, Color.WHITE);
|
|
|
|
|
canvas.drawOval(rect, pGraph);
|
|
|
|
|
|
|
|
|
|
pGraph.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
|
|
|
|
|
if(isBackgroundTransparent)
|
|
|
|
|
pGraph.setXfermode(XFERMODE_SRC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
|
|
|
|
{
|
|
|
|
|
this.isBackgroundTransparent = isBackgroundTransparent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setModeOrColor(Paint p, PorterDuffXfermode mode, int color)
|
|
|
|
|
{
|
|
|
|
|
if(isBackgroundTransparent)
|
|
|
|
|
p.setXfermode(mode);
|
|
|
|
|
else
|
|
|
|
|
p.setColor(color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|