mirror of https://github.com/iSoron/uhabits.git
parent
52701666bc
commit
4ae813e6f9
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 35 KiB |
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.widgets;
|
||||||
|
|
||||||
|
import android.support.test.runner.*;
|
||||||
|
import android.test.suitebuilder.annotation.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.widgets.*;
|
||||||
|
import org.junit.*;
|
||||||
|
import org.junit.runner.*;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@MediumTest
|
||||||
|
public class FrequencyWidgetTest extends BaseViewTest
|
||||||
|
{
|
||||||
|
private static final String PATH = "widgets/FrequencyWidget/";
|
||||||
|
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
private FrameLayout view;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
setTheme(R.style.TransparentWidgetTheme);
|
||||||
|
|
||||||
|
habit = fixtures.createLongHabit();
|
||||||
|
FrequencyWidget widget = new FrequencyWidget(targetContext, 0, habit);
|
||||||
|
view = convertToView(widget, 400, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsInstalled()
|
||||||
|
{
|
||||||
|
assertWidgetProviderIsInstalled(FrequencyWidgetProvider.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRender() throws Exception
|
||||||
|
{
|
||||||
|
assertRenders(view, PATH + "render.png");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.widgets;
|
||||||
|
|
||||||
|
import android.support.test.runner.*;
|
||||||
|
import android.test.suitebuilder.annotation.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.widgets.*;
|
||||||
|
import org.junit.*;
|
||||||
|
import org.junit.runner.*;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@MediumTest
|
||||||
|
public class HistoryWidgetTest extends BaseViewTest
|
||||||
|
{
|
||||||
|
private static final String PATH = "widgets/HistoryWidget/";
|
||||||
|
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
private FrameLayout view;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
setTheme(R.style.TransparentWidgetTheme);
|
||||||
|
|
||||||
|
habit = fixtures.createLongHabit();
|
||||||
|
HistoryWidget widget = new HistoryWidget(targetContext, 0, habit);
|
||||||
|
view = convertToView(widget, 400, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsInstalled()
|
||||||
|
{
|
||||||
|
assertWidgetProviderIsInstalled(HistoryWidgetProvider.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRender() throws Exception
|
||||||
|
{
|
||||||
|
assertRenders(view, PATH + "render.png");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.widgets;
|
||||||
|
|
||||||
|
import android.support.test.runner.*;
|
||||||
|
import android.test.suitebuilder.annotation.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.widgets.*;
|
||||||
|
import org.junit.*;
|
||||||
|
import org.junit.runner.*;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@MediumTest
|
||||||
|
public class ScoreWidgetTest extends BaseViewTest
|
||||||
|
{
|
||||||
|
private static final String PATH = "widgets/ScoreWidget/";
|
||||||
|
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
private FrameLayout view;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
setTheme(R.style.TransparentWidgetTheme);
|
||||||
|
|
||||||
|
habit = fixtures.createLongHabit();
|
||||||
|
ScoreWidget widget = new ScoreWidget(targetContext, 0, habit);
|
||||||
|
view = convertToView(widget, 400, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsInstalled()
|
||||||
|
{
|
||||||
|
assertWidgetProviderIsInstalled(ScoreWidgetProvider.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRender() throws Exception
|
||||||
|
{
|
||||||
|
assertRenders(view, PATH + "render.png");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.widgets;
|
||||||
|
|
||||||
|
import android.support.test.runner.*;
|
||||||
|
import android.test.suitebuilder.annotation.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.widgets.*;
|
||||||
|
import org.junit.*;
|
||||||
|
import org.junit.runner.*;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@MediumTest
|
||||||
|
public class StreakWidgetTest extends BaseViewTest
|
||||||
|
{
|
||||||
|
private static final String PATH = "widgets/StreakWidget/";
|
||||||
|
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
private FrameLayout view;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
setTheme(R.style.TransparentWidgetTheme);
|
||||||
|
|
||||||
|
habit = fixtures.createLongHabit();
|
||||||
|
StreakWidget widget = new StreakWidget(targetContext, 0, habit);
|
||||||
|
view = convertToView(widget, 400, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsInstalled()
|
||||||
|
{
|
||||||
|
assertWidgetProviderIsInstalled(StreakWidgetProvider.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRender() throws Exception
|
||||||
|
{
|
||||||
|
assertRenders(view, PATH + "render.png");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits;
|
||||||
|
|
||||||
|
import android.app.*;
|
||||||
|
import android.content.*;
|
||||||
|
import android.net.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.ui.habits.show.*;
|
||||||
|
|
||||||
|
public abstract class HabitPendingIntents
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String BASE_URL =
|
||||||
|
"content://org.isoron.uhabits/habit/";
|
||||||
|
|
||||||
|
public static PendingIntent dismissNotification(Context context)
|
||||||
|
{
|
||||||
|
Intent deleteIntent = new Intent(context, HabitBroadcastReceiver.class);
|
||||||
|
deleteIntent.setAction(HabitBroadcastReceiver.ACTION_DISMISS);
|
||||||
|
return PendingIntent.getBroadcast(context, 0, deleteIntent,
|
||||||
|
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PendingIntent snoozeNotification(Context context, Habit habit)
|
||||||
|
{
|
||||||
|
Uri data = habit.getUri();
|
||||||
|
Intent snoozeIntent = new Intent(context, HabitBroadcastReceiver.class);
|
||||||
|
snoozeIntent.setData(data);
|
||||||
|
snoozeIntent.setAction(HabitBroadcastReceiver.ACTION_SNOOZE);
|
||||||
|
return PendingIntent.getBroadcast(context, 0, snoozeIntent,
|
||||||
|
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PendingIntent toggleCheckmark(Context context,
|
||||||
|
Habit habit,
|
||||||
|
Long timestamp)
|
||||||
|
{
|
||||||
|
Uri data = habit.getUri();
|
||||||
|
Intent checkIntent = new Intent(context, HabitBroadcastReceiver.class);
|
||||||
|
checkIntent.setData(data);
|
||||||
|
checkIntent.setAction(HabitBroadcastReceiver.ACTION_CHECK);
|
||||||
|
if (timestamp != null) checkIntent.putExtra("timestamp", timestamp);
|
||||||
|
return PendingIntent.getBroadcast(context, 0, checkIntent,
|
||||||
|
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PendingIntent viewHabit(Context context, Habit habit)
|
||||||
|
{
|
||||||
|
Intent intent = new Intent(context, ShowHabitActivity.class);
|
||||||
|
intent.setData(Uri.parse(BASE_URL + habit.getId()));
|
||||||
|
return android.support.v4.app.TaskStackBuilder
|
||||||
|
.create(context.getApplicationContext())
|
||||||
|
.addNextIntentWithParentStack(intent)
|
||||||
|
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.widgets;
|
||||||
|
|
||||||
|
import android.app.*;
|
||||||
|
import android.content.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
import android.view.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.ui.common.views.*;
|
||||||
|
import org.isoron.uhabits.ui.widgets.views.*;
|
||||||
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
|
public class FrequencyWidget extends BaseWidget
|
||||||
|
{
|
||||||
|
@NonNull
|
||||||
|
private final Habit habit;
|
||||||
|
|
||||||
|
public FrequencyWidget(@NonNull Context context,
|
||||||
|
int widgetId,
|
||||||
|
@NonNull Habit habit)
|
||||||
|
{
|
||||||
|
super(context, widgetId);
|
||||||
|
this.habit = habit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PendingIntent getOnClickPendingIntent(Context context)
|
||||||
|
{
|
||||||
|
return HabitPendingIntents.viewHabit(context, habit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshData(View v)
|
||||||
|
{
|
||||||
|
GraphWidgetView widgetView = (GraphWidgetView) v;
|
||||||
|
FrequencyChart chart = (FrequencyChart) widgetView.getDataView();
|
||||||
|
|
||||||
|
widgetView.setTitle(habit.getName());
|
||||||
|
|
||||||
|
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||||
|
|
||||||
|
chart.setColor(color);
|
||||||
|
chart.setFrequency(habit.getRepetitions().getWeekdayFrequency());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected View buildView()
|
||||||
|
{
|
||||||
|
FrequencyChart chart = new FrequencyChart(getContext());
|
||||||
|
return new GraphWidgetView(getContext(), chart);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDefaultHeight()
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDefaultWidth()
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.widgets;
|
||||||
|
|
||||||
|
import android.app.*;
|
||||||
|
import android.content.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
import android.view.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.ui.common.views.*;
|
||||||
|
import org.isoron.uhabits.ui.widgets.views.*;
|
||||||
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
|
public class HistoryWidget extends BaseWidget
|
||||||
|
{
|
||||||
|
@NonNull
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
public HistoryWidget(@NonNull Context context, int id, @NonNull Habit habit)
|
||||||
|
{
|
||||||
|
super(context, id);
|
||||||
|
this.habit = habit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PendingIntent getOnClickPendingIntent(Context context)
|
||||||
|
{
|
||||||
|
return HabitPendingIntents.viewHabit(context, habit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshData(View view)
|
||||||
|
{
|
||||||
|
GraphWidgetView widgetView = (GraphWidgetView) view;
|
||||||
|
HistoryChart chart = (HistoryChart) widgetView.getDataView();
|
||||||
|
|
||||||
|
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||||
|
int[] values = habit.getCheckmarks().getAllValues();
|
||||||
|
|
||||||
|
chart.setColor(color);
|
||||||
|
chart.setCheckmarks(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected View buildView()
|
||||||
|
{
|
||||||
|
HistoryChart dataView = new HistoryChart(getContext());
|
||||||
|
GraphWidgetView widgetView =
|
||||||
|
new GraphWidgetView(getContext(), dataView);
|
||||||
|
widgetView.setTitle(habit.getName());
|
||||||
|
return widgetView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDefaultHeight()
|
||||||
|
{
|
||||||
|
return 250;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDefaultWidth()
|
||||||
|
{
|
||||||
|
return 250;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.widgets;
|
||||||
|
|
||||||
|
import android.app.*;
|
||||||
|
import android.content.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
import android.view.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.ui.common.views.*;
|
||||||
|
import org.isoron.uhabits.ui.habits.show.views.*;
|
||||||
|
import org.isoron.uhabits.ui.widgets.views.*;
|
||||||
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ScoreWidget extends BaseWidget
|
||||||
|
{
|
||||||
|
@NonNull
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
public ScoreWidget(@NonNull Context context, int id, @NonNull Habit habit)
|
||||||
|
{
|
||||||
|
super(context, id);
|
||||||
|
this.habit = habit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PendingIntent getOnClickPendingIntent(Context context)
|
||||||
|
{
|
||||||
|
return HabitPendingIntents.viewHabit(context, habit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshData(View view)
|
||||||
|
{
|
||||||
|
int defaultScoreInterval =
|
||||||
|
InterfaceUtils.getDefaultScoreSpinnerPosition(getContext());
|
||||||
|
int size = ScoreCard.BUCKET_SIZES[defaultScoreInterval];
|
||||||
|
|
||||||
|
GraphWidgetView widgetView = (GraphWidgetView) view;
|
||||||
|
ScoreChart chart = (ScoreChart) widgetView.getDataView();
|
||||||
|
|
||||||
|
List<Score> scores;
|
||||||
|
ScoreList scoreList = habit.getScores();
|
||||||
|
|
||||||
|
if (size == 1) scores = scoreList.getAll();
|
||||||
|
else scores = scoreList.groupBy(ScoreCard.getTruncateField(size));
|
||||||
|
|
||||||
|
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||||
|
|
||||||
|
chart.setIsTransparencyEnabled(true);
|
||||||
|
chart.setBucketSize(size);
|
||||||
|
chart.setColor(color);
|
||||||
|
chart.setScores(scores);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected View buildView()
|
||||||
|
{
|
||||||
|
ScoreChart dataView = new ScoreChart(getContext());
|
||||||
|
GraphWidgetView view = new GraphWidgetView(getContext(), dataView);
|
||||||
|
view.setTitle(habit.getName());
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDefaultHeight()
|
||||||
|
{
|
||||||
|
return 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDefaultWidth()
|
||||||
|
{
|
||||||
|
return 300;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.ui.widgets;
|
||||||
|
|
||||||
|
import android.app.*;
|
||||||
|
import android.content.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
|
import android.view.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.ui.common.views.*;
|
||||||
|
import org.isoron.uhabits.ui.widgets.views.*;
|
||||||
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class StreakWidget extends BaseWidget
|
||||||
|
{
|
||||||
|
@NonNull
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
|
public StreakWidget(@NonNull Context context, int id, @NonNull Habit habit)
|
||||||
|
{
|
||||||
|
super(context, id);
|
||||||
|
this.habit = habit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PendingIntent getOnClickPendingIntent(Context context)
|
||||||
|
{
|
||||||
|
return HabitPendingIntents.viewHabit(context, habit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshData(View view)
|
||||||
|
{
|
||||||
|
GraphWidgetView widgetView = (GraphWidgetView) view;
|
||||||
|
StreakChart chart = (StreakChart) widgetView.getDataView();
|
||||||
|
|
||||||
|
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||||
|
|
||||||
|
// TODO: make this dynamic
|
||||||
|
List<Streak> streaks = habit.getStreaks().getBest(10);
|
||||||
|
|
||||||
|
chart.setColor(color);
|
||||||
|
chart.setStreaks(streaks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected View buildView()
|
||||||
|
{
|
||||||
|
StreakChart dataView = new StreakChart(getContext());
|
||||||
|
GraphWidgetView view = new GraphWidgetView(getContext(), dataView);
|
||||||
|
view.setTitle(habit.getName());
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDefaultHeight()
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDefaultWidth()
|
||||||
|
{
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue