Add tests for HabitCardView

This commit is contained in:
2016-08-05 07:53:53 -04:00
parent 9a470cc61d
commit 3ad3cf54ec
6 changed files with 120 additions and 32 deletions

View File

@@ -154,6 +154,7 @@ public class CheckmarkPanelView extends LinearLayout
CheckmarkButtonView buttonView)
{
if (controller == null) return;
if(!(getContext() instanceof ListHabitsActivity)) return;
ListHabitsActivity activity = (ListHabitsActivity) getContext();
CheckmarkButtonControllerFactory buttonControllerFactory = activity

View File

@@ -43,6 +43,16 @@ public class HabitCardView extends FrameLayout
implements ModelObservable.Listener
{
private static final String EDIT_MODE_HABITS[] = {
"Wake up early",
"Wash dishes",
"Exercise",
"Meditate",
"Play guitar",
"Wash clothes",
"Get a haircut"
};
@BindView(R.id.checkmarkPanel)
CheckmarkPanelView checkmarkPanel;
@@ -105,15 +115,6 @@ public class HabitCardView extends FrameLayout
postInvalidate();
}
private void refresh()
{
int color = getActiveColor(habit);
label.setText(habit.getName());
label.setTextColor(color);
scoreRing.setColor(color);
checkmarkPanel.setColor(color);
}
public void setScore(int score)
{
float percentage = (float) score / Score.MAX_VALUE;
@@ -141,11 +142,6 @@ public class HabitCardView extends FrameLayout
triggerRipple(x, y);
}
protected void detachFromHabit()
{
if (habit != null) habit.getObservable().removeListener(this);
}
@Override
protected void onDetachedFromWindow()
{
@@ -158,6 +154,11 @@ public class HabitCardView extends FrameLayout
if (habit != null) habit.getObservable().addListener(this);
}
private void detachFromHabit()
{
if (habit != null) habit.getObservable().removeListener(this);
}
private int getActiveColor(Habit habit)
{
int mediumContrastColor = res.getColor(R.attr.mediumContrastTextColor);
@@ -189,27 +190,12 @@ public class HabitCardView extends FrameLayout
@SuppressLint("SetTextI18n")
private void initEditMode()
{
String habits[] = {
"Wake up early",
"Wash dishes",
"Exercise",
"Meditate",
"Play guitar",
"Wash clothes",
"Get a haircut"
};
Random rand = new Random();
int color = ColorUtils.getAndroidTestColor(rand.nextInt(10));
int[] values = {
rand.nextInt(3),
rand.nextInt(3),
rand.nextInt(3),
rand.nextInt(3),
rand.nextInt(3)
};
int[] values = new int[5];
for (int i = 0; i < 5; i++) values[i] = rand.nextInt(3);
label.setText(habits[rand.nextInt(habits.length)]);
label.setText(EDIT_MODE_HABITS[rand.nextInt(EDIT_MODE_HABITS.length)]);
label.setTextColor(color);
scoreRing.setColor(color);
scoreRing.setPercentage(rand.nextFloat());
@@ -217,6 +203,16 @@ public class HabitCardView extends FrameLayout
checkmarkPanel.setCheckmarkValues(values);
}
private void refresh()
{
int color = getActiveColor(habit);
label.setText(habit.getName());
label.setTextColor(color);
scoreRing.setColor(color);
checkmarkPanel.setColor(color);
postInvalidate();
}
private void triggerRipple(final float x, final float y)
{
final Drawable background = innerFrame.getBackground();