diff --git a/app/src/androidTest/assets/Views/CheckmarkView/checked.png b/app/src/androidTest/assets/Views/CheckmarkView/checked.png new file mode 100644 index 000000000..6f744b1fe Binary files /dev/null and b/app/src/androidTest/assets/Views/CheckmarkView/checked.png differ diff --git a/app/src/androidTest/assets/Views/CheckmarkView/implicitly_checked.png b/app/src/androidTest/assets/Views/CheckmarkView/implicitly_checked.png new file mode 100644 index 000000000..c3190d58c Binary files /dev/null and b/app/src/androidTest/assets/Views/CheckmarkView/implicitly_checked.png differ diff --git a/app/src/androidTest/assets/Views/CheckmarkView/large_size.png b/app/src/androidTest/assets/Views/CheckmarkView/large_size.png new file mode 100644 index 000000000..3aad412d5 Binary files /dev/null and b/app/src/androidTest/assets/Views/CheckmarkView/large_size.png differ diff --git a/app/src/androidTest/assets/Views/CheckmarkView/unchecked.png b/app/src/androidTest/assets/Views/CheckmarkView/unchecked.png new file mode 100644 index 000000000..92dfa2efe Binary files /dev/null and b/app/src/androidTest/assets/Views/CheckmarkView/unchecked.png differ diff --git a/app/src/androidTest/java/org/isoron/uhabits/unit/views/CheckmarkViewTest.java b/app/src/androidTest/java/org/isoron/uhabits/unit/views/CheckmarkViewTest.java new file mode 100644 index 000000000..e86049d13 --- /dev/null +++ b/app/src/androidTest/java/org/isoron/uhabits/unit/views/CheckmarkViewTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * This file is part of Loop Habit Tracker. + * + * Loop Habit Tracker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Loop Habit Tracker is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +package org.isoron.uhabits.unit.views; + +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.SmallTest; + +import org.isoron.uhabits.helpers.DateHelper; +import org.isoron.uhabits.models.Habit; +import org.isoron.uhabits.unit.models.HabitFixtures; +import org.isoron.uhabits.views.CheckmarkView; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class CheckmarkViewTest extends ViewTest +{ + private CheckmarkView view; + private Habit habit; + + @Before + public void setup() + { + super.setup(); + + habit = HabitFixtures.createNonDailyHabit(); + view = new CheckmarkView(targetContext); + view.setHabit(habit); + measureView(dpToPixels(100), dpToPixels(200), view); + } + + @Test + public void render_checked() throws IOException + { + assertRenders(view, "Views/CheckmarkView/checked.png"); + } + + @Test + public void render_unchecked() throws IOException + { + habit.repetitions.toggle(DateHelper.getStartOfToday()); + view.refreshData(); + + assertRenders(view, "Views/CheckmarkView/unchecked.png"); + } + + @Test + public void render_implicitlyChecked() throws IOException + { + long today = DateHelper.getStartOfToday(); + long day = DateHelper.millisecondsInOneDay; + habit.repetitions.toggle(today); + habit.repetitions.toggle(today - day); + habit.repetitions.toggle(today - 2 * day); + view.refreshData(); + + assertRenders(view, "Views/CheckmarkView/implicitly_checked.png"); + } + + @Test + public void render_largeSize() throws IOException + { + measureView(dpToPixels(300), dpToPixels(300), view); + assertRenders(view, "Views/CheckmarkView/large_size.png"); + } +} diff --git a/app/src/main/java/org/isoron/uhabits/views/CheckmarkView.java b/app/src/main/java/org/isoron/uhabits/views/CheckmarkView.java index 3f0950fe6..ebdb2df27 100644 --- a/app/src/main/java/org/isoron/uhabits/views/CheckmarkView.java +++ b/app/src/main/java/org/isoron/uhabits/views/CheckmarkView.java @@ -32,8 +32,8 @@ import android.text.TextPaint; import android.util.AttributeSet; 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 @@ -65,6 +65,7 @@ public class CheckmarkView extends View private Rect rect; private TextPaint textPaint; private StaticLayout labelLayout; + private Habit habit; public CheckmarkView(Context context) { @@ -114,11 +115,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 @@ -193,11 +191,17 @@ public class CheckmarkView extends View 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, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);