mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Restore all widgets
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 7.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
BIN
app/src/androidTest/assets/views/widgets/ScoreWidget/render.png
Normal file
BIN
app/src/androidTest/assets/views/widgets/ScoreWidget/render.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
BIN
app/src/androidTest/assets/views/widgets/StreakWidget/render.png
Normal file
BIN
app/src/androidTest/assets/views/widgets/StreakWidget/render.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
@@ -22,6 +22,7 @@ package org.isoron.uhabits;
|
||||
import android.appwidget.*;
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.test.*;
|
||||
|
||||
import org.isoron.uhabits.commands.*;
|
||||
@@ -63,6 +64,8 @@ public class BaseAndroidTest
|
||||
|
||||
protected HabitFixtures fixtures;
|
||||
|
||||
protected CountDownLatch latch;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
@@ -83,6 +86,27 @@ public class BaseAndroidTest
|
||||
androidTestComponent.inject(this);
|
||||
|
||||
fixtures = new HabitFixtures(habitList);
|
||||
|
||||
latch = new CountDownLatch(1);
|
||||
}
|
||||
|
||||
protected void assertWidgetProviderIsInstalled(Class componentClass)
|
||||
{
|
||||
ComponentName provider =
|
||||
new ComponentName(targetContext, componentClass);
|
||||
AppWidgetManager manager = AppWidgetManager.getInstance(targetContext);
|
||||
|
||||
List<ComponentName> installedProviders = new LinkedList<>();
|
||||
for (AppWidgetProviderInfo info : manager.getInstalledProviders())
|
||||
installedProviders.add(info.provider);
|
||||
|
||||
assertThat(installedProviders, hasItems(provider));
|
||||
}
|
||||
|
||||
protected void setTheme(@StyleRes int themeId)
|
||||
{
|
||||
InterfaceUtils.setFixedTheme(themeId);
|
||||
targetContext.setTheme(themeId);
|
||||
}
|
||||
|
||||
protected void sleep(int time)
|
||||
@@ -108,19 +132,4 @@ public class BaseAndroidTest
|
||||
|
||||
BaseTask.waitForTasks(10000);
|
||||
}
|
||||
|
||||
protected void assertWidgetProviderIsInstalled(ComponentName desiredProvider)
|
||||
{
|
||||
AppWidgetManager manager = AppWidgetManager.getInstance(targetContext);
|
||||
List<AppWidgetProviderInfo> providerInfoList;
|
||||
List<ComponentName> installedProviders;
|
||||
|
||||
providerInfoList = manager.getInstalledProviders();
|
||||
installedProviders = new LinkedList<>();
|
||||
|
||||
for (AppWidgetProviderInfo info : providerInfoList)
|
||||
installedProviders.add(info.provider);
|
||||
|
||||
assertThat(installedProviders, hasItems(desiredProvider));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package org.isoron.uhabits.ui.widgets;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
import android.widget.*;
|
||||
@@ -70,16 +69,13 @@ public class CheckmarkWidgetTest extends BaseViewTest
|
||||
button.performClick();
|
||||
sleep(1000);
|
||||
|
||||
assertThat(checkmarks.getTodayValue(), equalTo(CHECKED_IMPLICITLY));
|
||||
assertThat(checkmarks.getTodayValue(), equalTo(UNCHECKED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsInstalled()
|
||||
{
|
||||
ComponentName provider =
|
||||
new ComponentName(targetContext, CheckmarkWidgetProvider.class);
|
||||
|
||||
assertWidgetProviderIsInstalled(provider);
|
||||
assertWidgetProviderIsInstalled(CheckmarkWidgetProvider.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -108,53 +108,53 @@
|
||||
android:resource="@xml/widget_checkmark_info"/>
|
||||
</receiver>
|
||||
|
||||
<!--<receiver-->
|
||||
<!--android:name=".widgets.HistoryWidgetProvider"-->
|
||||
<!--android:label="@string/history">-->
|
||||
<!--<intent-filter>-->
|
||||
<!--<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>-->
|
||||
<!--</intent-filter>-->
|
||||
<receiver
|
||||
android:name=".widgets.HistoryWidgetProvider"
|
||||
android:label="@string/history">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
</intent-filter>
|
||||
|
||||
<!--<meta-data-->
|
||||
<!--android:name="android.appwidget.provider"-->
|
||||
<!--android:resource="@xml/widget_history_info"/>-->
|
||||
<!--</receiver>-->
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_history_info"/>
|
||||
</receiver>
|
||||
|
||||
<!--<receiver-->
|
||||
<!--android:name=".widgets.ScoreWidgetProvider"-->
|
||||
<!--android:label="@string/habit_strength">-->
|
||||
<!--<intent-filter>-->
|
||||
<!--<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>-->
|
||||
<!--</intent-filter>-->
|
||||
<receiver
|
||||
android:name=".widgets.ScoreWidgetProvider"
|
||||
android:label="@string/habit_strength">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
</intent-filter>
|
||||
|
||||
<!--<meta-data-->
|
||||
<!--android:name="android.appwidget.provider"-->
|
||||
<!--android:resource="@xml/widget_score_info"/>-->
|
||||
<!--</receiver>-->
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_score_info"/>
|
||||
</receiver>
|
||||
|
||||
<!--<receiver-->
|
||||
<!--android:name=".widgets.StreakWidgetProvider"-->
|
||||
<!--android:label="@string/streaks">-->
|
||||
<!--<intent-filter>-->
|
||||
<!--<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>-->
|
||||
<!--</intent-filter>-->
|
||||
<receiver
|
||||
android:name=".widgets.StreakWidgetProvider"
|
||||
android:label="@string/streaks">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
</intent-filter>
|
||||
|
||||
<!--<meta-data-->
|
||||
<!--android:name="android.appwidget.provider"-->
|
||||
<!--android:resource="@xml/widget_streak_info"/>-->
|
||||
<!--</receiver>-->
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_streak_info"/>
|
||||
</receiver>
|
||||
|
||||
<!--<receiver-->
|
||||
<!--android:name=".widgets.FrequencyWidgetProvider"-->
|
||||
<!--android:label="@string/frequency">-->
|
||||
<!--<intent-filter>-->
|
||||
<!--<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>-->
|
||||
<!--</intent-filter>-->
|
||||
<receiver
|
||||
android:name=".widgets.FrequencyWidgetProvider"
|
||||
android:label="@string/frequency">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
</intent-filter>
|
||||
|
||||
<!--<meta-data-->
|
||||
<!--android:name="android.appwidget.provider"-->
|
||||
<!--android:resource="@xml/widget_frequency_info"/>-->
|
||||
<!--</receiver>-->
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_frequency_info"/>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".HabitBroadcastReceiver">
|
||||
<intent-filter>
|
||||
|
||||
@@ -26,12 +26,10 @@ import android.net.*;
|
||||
import android.os.*;
|
||||
import android.preference.*;
|
||||
import android.support.v4.app.*;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.habits.show.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -39,9 +37,9 @@ import java.util.*;
|
||||
import javax.inject.*;
|
||||
|
||||
/**
|
||||
* The Android BroadacastReceiver for Loop Habit Tracker.
|
||||
* The Android BroadcastReceiver for Loop Habit Tracker.
|
||||
* <p/>
|
||||
* Currently, all broadcast messages are received and processed by this class.
|
||||
* All broadcast messages are received and processed by this class.
|
||||
*/
|
||||
public class HabitBroadcastReceiver extends BroadcastReceiver
|
||||
{
|
||||
@@ -68,50 +66,6 @@ public class HabitBroadcastReceiver extends BroadcastReceiver
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
}
|
||||
|
||||
public static PendingIntent buildCheckIntent(Context context,
|
||||
Habit habit,
|
||||
Long timestamp)
|
||||
{
|
||||
Uri data = habit.getUri();
|
||||
Intent checkIntent = new Intent(context, HabitBroadcastReceiver.class);
|
||||
checkIntent.setData(data);
|
||||
checkIntent.setAction(ACTION_CHECK);
|
||||
if (timestamp != null) checkIntent.putExtra("timestamp", timestamp);
|
||||
return PendingIntent.getBroadcast(context, 0, checkIntent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
}
|
||||
|
||||
public static PendingIntent buildDismissIntent(Context context)
|
||||
{
|
||||
Intent deleteIntent = new Intent(context, HabitBroadcastReceiver.class);
|
||||
deleteIntent.setAction(ACTION_DISMISS);
|
||||
return PendingIntent.getBroadcast(context, 0, deleteIntent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
}
|
||||
|
||||
public static PendingIntent buildSnoozeIntent(Context context, Habit habit)
|
||||
{
|
||||
Uri data = habit.getUri();
|
||||
Intent snoozeIntent = new Intent(context, HabitBroadcastReceiver.class);
|
||||
snoozeIntent.setData(data);
|
||||
snoozeIntent.setAction(ACTION_SNOOZE);
|
||||
return PendingIntent.getBroadcast(context, 0, snoozeIntent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
}
|
||||
|
||||
public static PendingIntent buildViewHabitIntent(Context context,
|
||||
Habit habit)
|
||||
{
|
||||
Intent intent = new Intent(context, ShowHabitActivity.class);
|
||||
intent.setData(
|
||||
Uri.parse("content://org.isoron.uhabits/habit/" + habit.getId()));
|
||||
|
||||
return TaskStackBuilder
|
||||
.create(context.getApplicationContext())
|
||||
.addNextIntentWithParentStack(intent)
|
||||
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
public static void dismissNotification(Context context, Habit habit)
|
||||
{
|
||||
NotificationManager notificationManager =
|
||||
@@ -153,8 +107,8 @@ public class HabitBroadcastReceiver extends BroadcastReceiver
|
||||
private void checkHabit(Context context, Intent intent)
|
||||
{
|
||||
Uri data = intent.getData();
|
||||
Long timestamp =
|
||||
intent.getLongExtra("timestamp", DateUtils.getStartOfToday());
|
||||
long today = DateUtils.getStartOfToday();
|
||||
Long timestamp = intent.getLongExtra("timestamp", today);
|
||||
|
||||
long habitId = ContentUris.parseId(data);
|
||||
Habit habit = habitList.getById(habitId);
|
||||
@@ -217,12 +171,13 @@ public class HabitBroadcastReceiver extends BroadcastReceiver
|
||||
PendingIntent.getActivity(context, 0, contentIntent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
PendingIntent dismissPendingIntent =
|
||||
buildDismissIntent(context);
|
||||
PendingIntent dismissPendingIntent;
|
||||
dismissPendingIntent =
|
||||
HabitPendingIntents.dismissNotification(context);
|
||||
PendingIntent checkIntentPending =
|
||||
buildCheckIntent(context, habit, timestamp);
|
||||
HabitPendingIntents.toggleCheckmark(context, habit, timestamp);
|
||||
PendingIntent snoozeIntentPending =
|
||||
buildSnoozeIntent(context, habit);
|
||||
HabitPendingIntents.snoozeNotification(context, habit);
|
||||
|
||||
Uri ringtoneUri = ReminderUtils.getRingtoneUri(context);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -106,31 +106,6 @@ abstract public class BaseActivity extends AppCompatActivity
|
||||
screen.onResult(request, result, data);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onCommandExecuted(Command command, Long refreshKey)
|
||||
// {
|
||||
// window.showMessage(command.getExecuteStringId());
|
||||
// new BaseTask()
|
||||
// {
|
||||
// @Override
|
||||
// protected void doInBackground()
|
||||
// {
|
||||
// dismissNotifications(BaseActivity.this);
|
||||
// BackupManager.dataChanged("org.isoron.uhabits");
|
||||
// WidgetManager.updateWidgets(BaseActivity.this);
|
||||
// }
|
||||
// }.execute();
|
||||
// }
|
||||
|
||||
// private void dismissNotifications(Context context)
|
||||
// {
|
||||
// for (Habit h : Habit.getHabitsWithReminder())
|
||||
// {
|
||||
// if (h.checkmarks.getTodayValue() != Checkmark.UNCHECKED)
|
||||
// HabitBroadcastReceiver.dismissNotification(context, h);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
|
||||
@@ -164,6 +164,7 @@ public class ListHabitsController
|
||||
|
||||
new Handler().postDelayed(() -> {
|
||||
system.scheduleReminders();
|
||||
HabitsApplication.getWidgetManager().updateWidgets();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,10 +61,25 @@ public class ScoreCard extends HabitCard
|
||||
init();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static DateUtils.TruncateField getTruncateField(int bucketSize)
|
||||
{
|
||||
if (bucketSize == 7) return DateUtils.TruncateField.WEEK_NUMBER;
|
||||
if (bucketSize == 31) return DateUtils.TruncateField.MONTH;
|
||||
if (bucketSize == 92) return DateUtils.TruncateField.QUARTER;
|
||||
if (bucketSize == 365) return DateUtils.TruncateField.YEAR;
|
||||
|
||||
Log.e("ScoreCard",
|
||||
String.format("Unknown bucket size: %d", bucketSize));
|
||||
|
||||
return DateUtils.TruncateField.MONTH;
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.spinner)
|
||||
public void onItemSelected(int position)
|
||||
{
|
||||
setBucketSizeFromPosition(position);
|
||||
HabitsApplication.getWidgetManager().updateWidgets();
|
||||
refreshData();
|
||||
}
|
||||
|
||||
@@ -80,20 +95,6 @@ public class ScoreCard extends HabitCard
|
||||
return InterfaceUtils.getDefaultScoreSpinnerPosition(getContext());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private DateUtils.TruncateField getTruncateField()
|
||||
{
|
||||
if (bucketSize == 7) return DateUtils.TruncateField.WEEK_NUMBER;
|
||||
if (bucketSize == 31) return DateUtils.TruncateField.MONTH;
|
||||
if (bucketSize == 92) return DateUtils.TruncateField.QUARTER;
|
||||
if (bucketSize == 365) return DateUtils.TruncateField.YEAR;
|
||||
|
||||
Log.e("ScoreCard",
|
||||
String.format("Unknown bucket size: %d", bucketSize));
|
||||
|
||||
return DateUtils.TruncateField.MONTH;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
inflate(getContext(), R.layout.show_habit_score, this);
|
||||
@@ -126,9 +127,10 @@ public class ScoreCard extends HabitCard
|
||||
protected void doInBackground()
|
||||
{
|
||||
List<Score> scores;
|
||||
ScoreList scoreList = getHabit().getScores();
|
||||
|
||||
if (bucketSize == 1) scores = getHabit().getScores().getAll();
|
||||
else scores = getHabit().getScores().groupBy(getTruncateField());
|
||||
if (bucketSize == 1) scores = scoreList.getAll();
|
||||
else scores = scoreList.groupBy(getTruncateField(bucketSize));
|
||||
|
||||
chart.setScores(scores);
|
||||
chart.setBucketSize(bucketSize);
|
||||
|
||||
@@ -79,8 +79,6 @@ public abstract class BaseWidget
|
||||
dimensions.getLandscapeHeight());
|
||||
}
|
||||
|
||||
public abstract int getLayoutId();
|
||||
|
||||
public abstract PendingIntent getOnClickPendingIntent(Context context);
|
||||
|
||||
@NonNull
|
||||
@@ -103,8 +101,6 @@ public abstract class BaseWidget
|
||||
|
||||
protected abstract int getDefaultWidth();
|
||||
|
||||
protected abstract String getTitle();
|
||||
|
||||
private void adjustRemoteViewsPadding(RemoteViews remoteViews,
|
||||
View view,
|
||||
int width,
|
||||
@@ -122,7 +118,6 @@ public abstract class BaseWidget
|
||||
int height)
|
||||
{
|
||||
Bitmap bitmap = getBitmapFromView(view);
|
||||
remoteViews.setTextViewText(R.id.label, getTitle());
|
||||
remoteViews.setImageViewBitmap(R.id.imageView, bitmap);
|
||||
|
||||
if (SDK_INT >= JELLY_BEAN)
|
||||
@@ -160,11 +155,10 @@ public abstract class BaseWidget
|
||||
|
||||
refreshData(view);
|
||||
|
||||
if(view.isLayoutRequested())
|
||||
measureView(view, width, height);
|
||||
if (view.isLayoutRequested()) measureView(view, width, height);
|
||||
|
||||
RemoteViews remoteViews =
|
||||
new RemoteViews(context.getPackageName(), getLayoutId());
|
||||
new RemoteViews(context.getPackageName(), R.layout.widget_wrapper);
|
||||
|
||||
buildRemoteViews(view, remoteViews, width, height);
|
||||
|
||||
@@ -174,7 +168,7 @@ public abstract class BaseWidget
|
||||
private void measureView(View view, int width, int height)
|
||||
{
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View entireView = inflater.inflate(getLayoutId(), null);
|
||||
View entireView = inflater.inflate(R.layout.widget_wrapper, null);
|
||||
|
||||
int specWidth = makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
|
||||
int specHeight = makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
|
||||
|
||||
@@ -42,16 +42,10 @@ public class CheckmarkWidget extends BaseWidget
|
||||
this.habit = habit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId()
|
||||
{
|
||||
return R.layout.widget_wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PendingIntent getOnClickPendingIntent(Context context)
|
||||
{
|
||||
return HabitBroadcastReceiver.buildCheckIntent(context, habit, null);
|
||||
return HabitPendingIntents.toggleCheckmark(context, habit, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,10 +81,4 @@ public class CheckmarkWidget extends BaseWidget
|
||||
{
|
||||
return 125;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle()
|
||||
{
|
||||
return habit.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class HabitPickerDialog extends Activity
|
||||
{
|
||||
Long habitId = habitIds.get(position);
|
||||
preferences.addWidget(widgetId, habitId);
|
||||
HabitsApplication.getWidgetManager().updateWidgets(this);
|
||||
HabitsApplication.getWidgetManager().updateWidgets();
|
||||
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(EXTRA_APPWIDGET_ID, widgetId);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class WidgetUpdater implements CommandRunner.Listener
|
||||
public void onCommandExecuted(@NonNull Command command,
|
||||
@Nullable Long refreshKey)
|
||||
{
|
||||
updateWidgets(context);
|
||||
updateWidgets();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,16 +76,16 @@ public class WidgetUpdater implements CommandRunner.Listener
|
||||
commandRunner.removeListener(this);
|
||||
}
|
||||
|
||||
void updateWidgets(Context context)
|
||||
public void updateWidgets()
|
||||
{
|
||||
updateWidgets(context, CheckmarkWidgetProvider.class);
|
||||
updateWidgets(context, HistoryWidgetProvider.class);
|
||||
updateWidgets(context, ScoreWidgetProvider.class);
|
||||
updateWidgets(context, StreakWidgetProvider.class);
|
||||
updateWidgets(context, FrequencyWidgetProvider.class);
|
||||
updateWidgets(CheckmarkWidgetProvider.class);
|
||||
updateWidgets(HistoryWidgetProvider.class);
|
||||
updateWidgets(ScoreWidgetProvider.class);
|
||||
updateWidgets(StreakWidgetProvider.class);
|
||||
updateWidgets(FrequencyWidgetProvider.class);
|
||||
}
|
||||
|
||||
private void updateWidgets(Context context, Class providerClass)
|
||||
public void updateWidgets(Class providerClass)
|
||||
{
|
||||
ComponentName provider = new ComponentName(context, providerClass);
|
||||
Intent intent = new Intent(context, providerClass);
|
||||
|
||||
@@ -22,7 +22,7 @@ package org.isoron.uhabits.widgets;
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.widgets.*;
|
||||
|
||||
public class FrequencyWidgetProvider extends BaseWidgetProvider
|
||||
@@ -31,61 +31,7 @@ public class FrequencyWidgetProvider extends BaseWidgetProvider
|
||||
@Override
|
||||
protected BaseWidget getWidgetFromId(@NonNull Context context, int id)
|
||||
{
|
||||
throw new NotImplementedException("");
|
||||
Habit habit = getHabitFromWidgetId(id);
|
||||
return new FrequencyWidget(context, id, habit);
|
||||
}
|
||||
|
||||
// @NonNull
|
||||
// @Override
|
||||
// protected BaseWidget getWidgetFromId(int id)
|
||||
// {
|
||||
// throw new NotImplementedException("");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected View buildCustomView(Context context, Habit habit)
|
||||
// {
|
||||
// FrequencyChart chart = new FrequencyChart(context);
|
||||
// GraphWidgetView view = new GraphWidgetView(context, chart);
|
||||
// view.setTitle(habit.getName());
|
||||
// return view;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getDefaultHeight()
|
||||
// {
|
||||
// return 200;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getDefaultWidth()
|
||||
// {
|
||||
// return 200;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getLayoutId()
|
||||
// {
|
||||
// return R.layout.widget_wrapper;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected PendingIntent getOnClickPendingIntent(Context context,
|
||||
// Habit habit)
|
||||
// {
|
||||
// return HabitBroadcastReceiver.buildViewHabitIntent(context, habit);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void refreshCustomViewData(Context context,
|
||||
// View view,
|
||||
// Habit habit)
|
||||
// {
|
||||
// GraphWidgetView widgetView = (GraphWidgetView) view;
|
||||
// FrequencyChart chart = (FrequencyChart) widgetView.getDataView();
|
||||
//
|
||||
// int color = ColorUtils.getColor(context, habit.getColor());
|
||||
//
|
||||
// chart.setColor(color);
|
||||
// chart.setFrequency(habit.getRepetitions().getWeekdayFrequency());
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.isoron.uhabits.widgets;
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.widgets.*;
|
||||
|
||||
public class HistoryWidgetProvider extends BaseWidgetProvider
|
||||
@@ -30,62 +30,7 @@ public class HistoryWidgetProvider extends BaseWidgetProvider
|
||||
@Override
|
||||
protected BaseWidget getWidgetFromId(@NonNull Context context, int id)
|
||||
{
|
||||
throw new NotImplementedException("");
|
||||
Habit habit = getHabitFromWidgetId(id);
|
||||
return new HistoryWidget(context, id, habit);
|
||||
}
|
||||
|
||||
// @NonNull
|
||||
// @Override
|
||||
// protected BaseWidget getWidgetFromId(int id)
|
||||
// {
|
||||
// throw new NotImplementedException("");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected View buildCustomView(Context context, Habit habit)
|
||||
// {
|
||||
// HistoryChart dataView = new HistoryChart(context);
|
||||
// GraphWidgetView widgetView = new GraphWidgetView(context, dataView);
|
||||
// widgetView.setTitle(habit.getName());
|
||||
// return widgetView;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getDefaultHeight()
|
||||
// {
|
||||
// return 250;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getDefaultWidth()
|
||||
// {
|
||||
// return 250;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getLayoutId()
|
||||
// {
|
||||
// return R.layout.widget_wrapper;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected PendingIntent getOnClickPendingIntent(Context context,
|
||||
// Habit habit)
|
||||
// {
|
||||
// return HabitBroadcastReceiver.buildViewHabitIntent(context, habit);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void refreshCustomViewData(Context context,
|
||||
// View view,
|
||||
// Habit habit)
|
||||
// {
|
||||
// GraphWidgetView widgetView = (GraphWidgetView) view;
|
||||
// HistoryChart chart = (HistoryChart) widgetView.getDataView();
|
||||
//
|
||||
// int color = ColorUtils.getColor(context, habit.getColor());
|
||||
// int[] values = habit.getCheckmarks().getAllValues();
|
||||
//
|
||||
// chart.setColor(color);
|
||||
// chart.setCheckmarks(values);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.isoron.uhabits.widgets;
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.widgets.*;
|
||||
|
||||
public class ScoreWidgetProvider extends BaseWidgetProvider
|
||||
@@ -30,61 +30,7 @@ public class ScoreWidgetProvider extends BaseWidgetProvider
|
||||
@Override
|
||||
protected BaseWidget getWidgetFromId(@NonNull Context context, int id)
|
||||
{
|
||||
throw new NotImplementedException("");
|
||||
Habit habit = getHabitFromWidgetId(id);
|
||||
return new ScoreWidget(context, id, habit);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected View buildCustomView(Context context, Habit habit)
|
||||
// {
|
||||
// ScoreChart dataView = new ScoreChart(context);
|
||||
// GraphWidgetView view = new GraphWidgetView(context, dataView);
|
||||
// view.setTitle(habit.getName());
|
||||
// return view;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getDefaultHeight()
|
||||
// {
|
||||
// return 300;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getDefaultWidth()
|
||||
// {
|
||||
// return 300;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getLayoutId()
|
||||
// {
|
||||
// return R.layout.widget_wrapper;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected PendingIntent getOnClickPendingIntent(Context context,
|
||||
// Habit habit)
|
||||
// {
|
||||
// return HabitBroadcastReceiver.buildViewHabitIntent(context, habit);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void refreshCustomViewData(Context context,
|
||||
// View view,
|
||||
// Habit habit)
|
||||
// {
|
||||
// int defaultScoreInterval =
|
||||
// InterfaceUtils.getDefaultScoreSpinnerPosition(context);
|
||||
// int size = ScoreCard.BUCKET_SIZES[defaultScoreInterval];
|
||||
//
|
||||
// GraphWidgetView widgetView = (GraphWidgetView) view;
|
||||
// ScoreChart chart = (ScoreChart) widgetView.getDataView();
|
||||
//
|
||||
// int color = ColorUtils.getColor(context, habit.getColor());
|
||||
// List<Score> scores = habit.getScores().getAll();
|
||||
//
|
||||
// chart.setIsTransparencyEnabled(true);
|
||||
// chart.setBucketSize(size);
|
||||
// chart.setColor(color);
|
||||
// chart.setScores(scores);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.isoron.uhabits.widgets;
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.widgets.*;
|
||||
|
||||
public class StreakWidgetProvider extends BaseWidgetProvider
|
||||
@@ -30,48 +30,10 @@ public class StreakWidgetProvider extends BaseWidgetProvider
|
||||
@Override
|
||||
protected BaseWidget getWidgetFromId(@NonNull Context context, int id)
|
||||
{
|
||||
throw new NotImplementedException("");
|
||||
Habit habit = getHabitFromWidgetId(id);
|
||||
return new StreakWidget(context, id, habit);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected View buildCustomView(Context context, Habit habit)
|
||||
// {
|
||||
// StreakChart dataView = new StreakChart(context);
|
||||
// GraphWidgetView view = new GraphWidgetView(context, dataView);
|
||||
// view.setTitle(habit.getName());
|
||||
// return view;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getDefaultHeight()
|
||||
// {
|
||||
// return 200;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getDefaultWidth()
|
||||
// {
|
||||
// return 200;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getLayoutId()
|
||||
// {
|
||||
// return R.layout.widget_wrapper;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected PendingIntent getOnClickPendingIntent(Context context,
|
||||
// Habit habit)
|
||||
// {
|
||||
// return HabitBroadcastReceiver.buildViewHabitIntent(context, habit);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void refreshCustomViewData(Context context,
|
||||
// View view,
|
||||
// Habit habit)
|
||||
// {
|
||||
// GraphWidgetView widgetView = (GraphWidgetView) view;
|
||||
// StreakChart chart = (StreakChart) widgetView.getDataView();
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user