Merge branch 'feature/unit-test-views' into dev

This commit is contained in:
2016-03-28 21:14:42 -04:00
20 changed files with 459 additions and 29 deletions

View File

@@ -30,10 +30,11 @@ import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import org.isoron.uhabits.helpers.ColorHelper;
import org.isoron.uhabits.R;
import org.isoron.uhabits.helpers.ColorHelper;
import org.isoron.uhabits.models.Habit;
public class CheckmarkView extends View
@@ -48,9 +49,9 @@ public class CheckmarkView extends View
private int width;
private int height;
private int leftMargin;
private int topMargin;
private int padding;
private float leftMargin;
private float topMargin;
private float padding;
private String label;
private String fa_check;
@@ -65,6 +66,7 @@ public class CheckmarkView extends View
private Rect rect;
private TextPaint textPaint;
private StaticLayout labelLayout;
private Habit habit;
public CheckmarkView(Context context)
{
@@ -114,11 +116,8 @@ public class CheckmarkView extends View
public void setHabit(Habit habit)
{
this.check_status = habit.checkmarks.getTodayValue();
this.star_status = habit.scores.getTodayStarStatus();
this.primaryColor = Color.argb(230, Color.red(habit.color), Color.green(habit.color), Color.blue(habit.color));
this.label = habit.name;
updateLabel();
this.habit = habit;
refreshData();
}
@Override
@@ -152,8 +151,6 @@ public class CheckmarkView extends View
pIcon.setTextSize(width * 0.5f);
pIcon.getTextBounds(text, 0, 1, rect);
// canvas.drawLine(0, 0.67f * height, width, 0.67f * height, pIcon);
int y = (int) ((0.67f * height - rect.bottom - rect.top) / 2);
canvas.drawText(text, width / 2, y, pIcon);
}
@@ -188,18 +185,25 @@ public class CheckmarkView extends View
this.width = getMeasuredWidth();
this.height = getMeasuredHeight();
leftMargin = (int) (width * 0.015);
topMargin = (int) (height * 0.015);
leftMargin = (width * 0.015f);
topMargin = (height * 0.015f);
padding = 8 * leftMargin;
textPaint.setTextSize(0.15f * width);
updateLabel();
refreshData();
}
private void updateLabel()
public void refreshData()
{
this.check_status = habit.checkmarks.getTodayValue();
this.star_status = habit.scores.getTodayStarStatus();
this.primaryColor = Color.argb(230, Color.red(habit.color), Color.green(habit.color),
Color.blue(habit.color));
this.label = habit.name;
textPaint.setColor(Color.WHITE);
labelLayout = new StaticLayout(label, textPaint, width - 2 * leftMargin - 2 * padding,
labelLayout = new StaticLayout(label, textPaint,
(int) (width - 2 * leftMargin - 2 * padding),
Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
}

View File

@@ -29,11 +29,11 @@ import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import org.isoron.uhabits.helpers.ColorHelper;
import org.isoron.uhabits.helpers.DialogHelper;
import org.isoron.uhabits.R;
import org.isoron.uhabits.helpers.DialogHelper;
public class RingView extends View
{
@@ -48,10 +48,16 @@ public class RingView extends View
private int width;
private int height;
private float diameter;
private float maxDiameter;
private float textSize;
private int fadedTextColor;
public RingView(Context context)
{
super(context);
init();
}
public RingView(Context context, AttributeSet attrs)
{
@@ -59,25 +65,28 @@ public class RingView extends View
this.label = DialogHelper.getAttribute(context, attrs, "label");
this.maxDiameter = DialogHelper.getFloatAttribute(context, attrs, "maxDiameter");
this.maxDiameter = DialogHelper.dpToPixels(context, maxDiameter);
this.textSize = getResources().getDimension(R.dimen.smallTextSize);
this.color = ColorHelper.palette[7];
this.percentage = 0.75f;
init();
}
public void setColor(int color)
{
this.color = color;
pRing.setColor(color);
postInvalidate();
}
public void setMaxDiameter(float maxDiameter)
{
this.maxDiameter = maxDiameter;
}
public void setLabel(String label)
{
this.label = label;
}
public void setPercentage(float percentage)
{
this.percentage = percentage;
postInvalidate();
}
private void init()
@@ -88,6 +97,8 @@ public class RingView extends View
pRing.setTextAlign(Paint.Align.CENTER);
fadedTextColor = getResources().getColor(R.color.fadedTextColor);
textSize = getResources().getDimension(R.dimen.smallTextSize);
Log.d("RingView", String.format("textSize=%f", textSize));
rect = new RectF();
}