mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Create target widget
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.isoron.uhabits">
|
package="org.isoron.uhabits">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
@@ -8,37 +8,37 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".HabitsApplication"
|
android:name=".HabitsApplication"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:backupAgent=".HabitsBackupAgent"
|
android:backupAgent=".HabitsBackupAgent"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/main_activity_title"
|
android:label="@string/main_activity_title"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppBaseTheme">
|
android:theme="@style/AppBaseTheme">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:exported="true"
|
android:name=".activities.habits.edit.EditHabitActivity"
|
||||||
android:name=".activities.habits.edit.EditHabitActivity">
|
android:exported="true">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".activities.habits.list.ListHabitsActivity" />
|
android:value=".activities.habits.list.ListHabitsActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.google.android.backup.api_key"
|
android:name="com.google.android.backup.api_key"
|
||||||
android:value="AEdPqrEAAAAI6aeWncbnMNo8E5GWeZ44dlc5cQ7tCROwFhOtiw" />
|
android:value="AEdPqrEAAAAI6aeWncbnMNo8E5GWeZ44dlc5cQ7tCROwFhOtiw" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.habits.list.ListHabitsActivity"
|
android:name=".activities.habits.list.ListHabitsActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/main_activity_title"
|
android:label="@string/main_activity_title"
|
||||||
android:launchMode="singleTop" />
|
android:launchMode="singleTop" />
|
||||||
|
|
||||||
<activity-alias
|
<activity-alias
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/main_activity_title"
|
android:label="@string/main_activity_title"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:targetActivity=".activities.habits.list.ListHabitsActivity">
|
android:targetActivity=".activities.habits.list.ListHabitsActivity">
|
||||||
<intent-filter android:label="@string/main_activity_title">
|
<intent-filter android:label="@string/main_activity_title">
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
@@ -47,109 +47,131 @@
|
|||||||
</activity-alias>
|
</activity-alias>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.habits.show.ShowHabitActivity"
|
android:name=".activities.habits.show.ShowHabitActivity"
|
||||||
android:label="@string/title_activity_show_habit">
|
android:label="@string/title_activity_show_habit">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".activities.habits.list.ListHabitsActivity" />
|
android:value=".activities.habits.list.ListHabitsActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.settings.SettingsActivity"
|
android:name=".activities.settings.SettingsActivity"
|
||||||
android:label="@string/settings">
|
android:label="@string/settings">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".activities.habits.list.ListHabitsActivity" />
|
android:value=".activities.habits.list.ListHabitsActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.intro.IntroActivity"
|
android:name=".activities.intro.IntroActivity"
|
||||||
android:label=""
|
android:label=""
|
||||||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
|
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".widgets.HabitPickerDialog"
|
android:name=".widgets.HabitPickerDialog"
|
||||||
android:theme="@style/Theme.AppCompat.Light.Dialog">
|
android:theme="@style/Theme.AppCompat.Light.Dialog">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.about.AboutActivity"
|
android:name=".activities.about.AboutActivity"
|
||||||
android:label="@string/about">
|
android:label="@string/about">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".activities.habits.list.ListHabitsActivity" />
|
android:value=".activities.habits.list.ListHabitsActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".notifications.SnoozeDelayPickerActivity"
|
android:name=".notifications.SnoozeDelayPickerActivity"
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
android:launchMode="singleInstance"
|
android:launchMode="singleInstance"
|
||||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"></activity>
|
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".widgets.CheckmarkWidgetProvider"
|
android:name=".widgets.CheckmarkWidgetProvider"
|
||||||
android:label="@string/checkmark">
|
android:label="@string/checkmark">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/widget_checkmark_info" />
|
android:resource="@xml/widget_checkmark_info" />
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".widgets.StackWidgetService"
|
android:name=".widgets.StackWidgetService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".widgets.HistoryWidgetProvider"
|
android:name=".widgets.HistoryWidgetProvider"
|
||||||
android:label="@string/history">
|
android:label="@string/history">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/widget_history_info" />
|
android:resource="@xml/widget_history_info" />
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".widgets.ScoreWidgetProvider"
|
android:name=".widgets.ScoreWidgetProvider"
|
||||||
android:label="@string/habit_strength">
|
android:label="@string/habit_strength">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/widget_score_info" />
|
android:resource="@xml/widget_score_info" />
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".widgets.StreakWidgetProvider"
|
android:name=".widgets.StreakWidgetProvider"
|
||||||
android:label="@string/streaks">
|
android:label="@string/streaks">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/widget_streak_info" />
|
android:resource="@xml/widget_streak_info" />
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".widgets.FrequencyWidgetProvider"
|
android:name=".widgets.FrequencyWidgetProvider"
|
||||||
android:label="@string/frequency">
|
android:label="@string/frequency">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.appwidget.provider"
|
android:name="android.appwidget.provider"
|
||||||
android:resource="@xml/widget_frequency_info" />
|
android:resource="@xml/widget_frequency_info" />
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".widgets.TargetWidgetProvider"
|
||||||
|
android:label="@string/target">
|
||||||
|
<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>
|
||||||
|
|
||||||
<receiver android:name=".receivers.ReminderReceiver">
|
<receiver android:name=".receivers.ReminderReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver android:name=".receivers.WidgetReceiver">
|
<receiver android:name=".receivers.WidgetReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
@@ -157,8 +179,8 @@
|
|||||||
<action android:name="org.isoron.uhabits.ACTION_TOGGLE_REPETITION" />
|
<action android:name="org.isoron.uhabits.ACTION_TOGGLE_REPETITION" />
|
||||||
|
|
||||||
<data
|
<data
|
||||||
android:host="org.isoron.uhabits"
|
android:host="org.isoron.uhabits"
|
||||||
android:scheme="content" />
|
android:scheme="content" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
@@ -166,8 +188,8 @@
|
|||||||
<action android:name="org.isoron.uhabits.ACTION_ADD_REPETITION" />
|
<action android:name="org.isoron.uhabits.ACTION_ADD_REPETITION" />
|
||||||
|
|
||||||
<data
|
<data
|
||||||
android:host="org.isoron.uhabits"
|
android:host="org.isoron.uhabits"
|
||||||
android:scheme="content" />
|
android:scheme="content" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
@@ -175,41 +197,46 @@
|
|||||||
<action android:name="org.isoron.uhabits.ACTION_REMOVE_REPETITION" />
|
<action android:name="org.isoron.uhabits.ACTION_REMOVE_REPETITION" />
|
||||||
|
|
||||||
<data
|
<data
|
||||||
android:host="org.isoron.uhabits"
|
android:host="org.isoron.uhabits"
|
||||||
android:scheme="content" />
|
android:scheme="content" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver> <!-- Locale/Tasker -->
|
</receiver>
|
||||||
|
|
||||||
|
<!-- Locale/Tasker -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".automation.EditSettingActivity"
|
android:name=".automation.EditSettingActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
|
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity> <!-- Locale/Tasker -->
|
</activity>
|
||||||
|
|
||||||
|
<!-- Locale/Tasker -->
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".automation.FireSettingReceiver"
|
android:name=".automation.FireSettingReceiver"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING" />
|
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
android:authorities="org.isoron.uhabits"
|
android:authorities="org.isoron.uhabits"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:grantUriPermissions="true">
|
android:grantUriPermissions="true">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/file_paths" />
|
android:resource="@xml/file_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".sync.SyncService"
|
android:name=".sync.SyncService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false"></service>
|
android:exported="false" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -93,7 +93,8 @@ public class TargetChart extends View
|
|||||||
maxLabelSize = Math.max(maxLabelSize, len);
|
maxLabelSize = Math.max(maxLabelSize, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.set(0, 0, getWidth(), baseSize);
|
float marginTop = (getHeight() - baseSize * labels.size()) / 2.0f;
|
||||||
|
rect.set(0, marginTop, getWidth(), marginTop + baseSize);
|
||||||
for (int i = 0; i < labels.size(); i++) {
|
for (int i = 0; i < labels.size(); i++) {
|
||||||
drawRow(canvas, i, rect);
|
drawRow(canvas, i, rect);
|
||||||
rect.offset(0, baseSize);
|
rect.offset(0, baseSize);
|
||||||
@@ -103,8 +104,17 @@ public class TargetChart extends View
|
|||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthSpec, int heightSpec)
|
protected void onMeasure(int widthSpec, int heightSpec)
|
||||||
{
|
{
|
||||||
|
baseSize = getResources().getDimensionPixelSize(R.dimen.baseSize);
|
||||||
|
|
||||||
int width = getSize(widthSpec);
|
int width = getSize(widthSpec);
|
||||||
int height = labels.size() * baseSize;
|
int height = labels.size() * baseSize;
|
||||||
|
|
||||||
|
ViewGroup.LayoutParams params = getLayoutParams();
|
||||||
|
if (params != null && params.height == ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||||
|
height = getSize(heightSpec);
|
||||||
|
if (labels.size() > 0) baseSize = height / labels.size();
|
||||||
|
}
|
||||||
|
|
||||||
heightSpec = makeMeasureSpec(height, EXACTLY);
|
heightSpec = makeMeasureSpec(height, EXACTLY);
|
||||||
widthSpec = makeMeasureSpec(width, EXACTLY);
|
widthSpec = makeMeasureSpec(width, EXACTLY);
|
||||||
setMeasuredDimension(widthSpec, heightSpec);
|
setMeasuredDimension(widthSpec, heightSpec);
|
||||||
@@ -194,7 +204,6 @@ public class TargetChart extends View
|
|||||||
mediumContrastTextColor = res.getColor(R.attr.mediumContrastTextColor);
|
mediumContrastTextColor = res.getColor(R.attr.mediumContrastTextColor);
|
||||||
highContrastReverseTextColor = res.getColor(R.attr.highContrastReverseTextColor);
|
highContrastReverseTextColor = res.getColor(R.attr.highContrastReverseTextColor);
|
||||||
tinyTextSize = getDimension(getContext(), R.dimen.tinyTextSize);
|
tinyTextSize = getDimension(getContext(), R.dimen.tinyTextSize);
|
||||||
baseSize = getResources().getDimensionPixelSize(R.dimen.baseSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValues(List<Double> values)
|
public void setValues(List<Double> values)
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import android.content.res.*;
|
|||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
|
import androidx.annotation.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.activities.common.views.*;
|
import org.isoron.uhabits.activities.common.views.*;
|
||||||
@@ -86,10 +88,10 @@ public class TargetCard extends HabitCard
|
|||||||
@Override
|
@Override
|
||||||
protected Task createRefreshTask()
|
protected Task createRefreshTask()
|
||||||
{
|
{
|
||||||
return new RefreshTask();
|
return new RefreshTask(getContext(), getHabit(), firstWeekday, targetChart, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RefreshTask extends CancelableTask
|
public static class RefreshTask extends CancelableTask
|
||||||
{
|
{
|
||||||
double todayValue;
|
double todayValue;
|
||||||
double thisWeekValue;
|
double thisWeekValue;
|
||||||
@@ -97,11 +99,30 @@ public class TargetCard extends HabitCard
|
|||||||
double thisQuarterValue;
|
double thisQuarterValue;
|
||||||
double thisYearValue;
|
double thisYearValue;
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
private Habit habit;
|
||||||
|
private int firstWeekday;
|
||||||
|
private TargetChart chart;
|
||||||
|
private TextView title;
|
||||||
|
|
||||||
|
public RefreshTask(@NonNull Context context,
|
||||||
|
@NonNull Habit habit,
|
||||||
|
int firstWeekday,
|
||||||
|
@NonNull TargetChart chart,
|
||||||
|
@Nullable TextView title)
|
||||||
|
{
|
||||||
|
this.context = context;
|
||||||
|
this.habit = habit;
|
||||||
|
this.firstWeekday = firstWeekday;
|
||||||
|
this.chart = chart;
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doInBackground()
|
public void doInBackground()
|
||||||
{
|
{
|
||||||
if (isCanceled()) return;
|
if (isCanceled()) return;
|
||||||
CheckmarkList checkmarks = getHabit().getCheckmarks();
|
CheckmarkList checkmarks = habit.getCheckmarks();
|
||||||
todayValue = checkmarks.getTodayValue() / 1e3;
|
todayValue = checkmarks.getTodayValue() / 1e3;
|
||||||
thisWeekValue = checkmarks.getThisWeekValue(firstWeekday) / 1e3;
|
thisWeekValue = checkmarks.getThisWeekValue(firstWeekday) / 1e3;
|
||||||
thisMonthValue = checkmarks.getThisMonthValue() / 1e3;
|
thisMonthValue = checkmarks.getThisMonthValue() / 1e3;
|
||||||
@@ -113,15 +134,14 @@ public class TargetCard extends HabitCard
|
|||||||
public void onPostExecute()
|
public void onPostExecute()
|
||||||
{
|
{
|
||||||
if (isCanceled()) return;
|
if (isCanceled()) return;
|
||||||
|
|
||||||
Calendar cal = DateUtils.getStartOfTodayCalendar();
|
Calendar cal = DateUtils.getStartOfTodayCalendar();
|
||||||
int daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
int daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||||
int daysInQuarter = 91;
|
int daysInQuarter = 91;
|
||||||
int daysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
|
int daysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
|
||||||
|
|
||||||
int den = getHabit().getFrequency().getDenominator();
|
int den = habit.getFrequency().getDenominator();
|
||||||
double dailyTarget = getHabit().getTargetValue() / den;
|
double dailyTarget = habit.getTargetValue() / den;
|
||||||
Resources res = getResources();
|
Resources res = context.getResources();
|
||||||
|
|
||||||
ArrayList<Double> values = new ArrayList<>();
|
ArrayList<Double> values = new ArrayList<>();
|
||||||
if (den <= 1) values.add(todayValue);
|
if (den <= 1) values.add(todayValue);
|
||||||
@@ -129,7 +149,7 @@ public class TargetCard extends HabitCard
|
|||||||
values.add(thisMonthValue);
|
values.add(thisMonthValue);
|
||||||
values.add(thisQuarterValue);
|
values.add(thisQuarterValue);
|
||||||
values.add(thisYearValue);
|
values.add(thisYearValue);
|
||||||
targetChart.setValues(values);
|
chart.setValues(values);
|
||||||
|
|
||||||
ArrayList<Double> targets = new ArrayList<>();
|
ArrayList<Double> targets = new ArrayList<>();
|
||||||
if (den <= 1) targets.add(dailyTarget);
|
if (den <= 1) targets.add(dailyTarget);
|
||||||
@@ -137,7 +157,7 @@ public class TargetCard extends HabitCard
|
|||||||
targets.add(dailyTarget * daysInMonth);
|
targets.add(dailyTarget * daysInMonth);
|
||||||
targets.add(dailyTarget * daysInQuarter);
|
targets.add(dailyTarget * daysInQuarter);
|
||||||
targets.add(dailyTarget * daysInYear);
|
targets.add(dailyTarget * daysInYear);
|
||||||
targetChart.setTargets(targets);
|
chart.setTargets(targets);
|
||||||
|
|
||||||
ArrayList<String> labels = new ArrayList<>();
|
ArrayList<String> labels = new ArrayList<>();
|
||||||
if (den <= 1) labels.add(res.getString(R.string.today));
|
if (den <= 1) labels.add(res.getString(R.string.today));
|
||||||
@@ -145,15 +165,15 @@ public class TargetCard extends HabitCard
|
|||||||
labels.add(res.getString(R.string.month));
|
labels.add(res.getString(R.string.month));
|
||||||
labels.add(res.getString(R.string.quarter));
|
labels.add(res.getString(R.string.quarter));
|
||||||
labels.add(res.getString(R.string.year));
|
labels.add(res.getString(R.string.year));
|
||||||
targetChart.setLabels(labels);
|
chart.setLabels(labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPreExecute()
|
public void onPreExecute()
|
||||||
{
|
{
|
||||||
int color = PaletteUtils.getColor(getContext(), getHabit().getColor());
|
int color = PaletteUtils.getColor(context, habit.getColor());
|
||||||
title.setTextColor(color);
|
if(title != null) title.setTextColor(color);
|
||||||
targetChart.setColor(color);
|
chart.setColor(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ public enum StackWidgetType {
|
|||||||
FREQUENCY(1),
|
FREQUENCY(1),
|
||||||
SCORE(2), // habit strength widget
|
SCORE(2), // habit strength widget
|
||||||
HISTORY(3),
|
HISTORY(3),
|
||||||
STREAKS(4);
|
STREAKS(4),
|
||||||
|
TARGET(5);
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
StackWidgetType(int value) {
|
StackWidgetType(int value) {
|
||||||
@@ -34,6 +35,8 @@ public enum StackWidgetType {
|
|||||||
return HISTORY;
|
return HISTORY;
|
||||||
} else if (STREAKS.getValue() == value) {
|
} else if (STREAKS.getValue() == value) {
|
||||||
return STREAKS;
|
return STREAKS;
|
||||||
|
} else if (TARGET.getValue() == value) {
|
||||||
|
return TARGET;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -50,6 +53,8 @@ public enum StackWidgetType {
|
|||||||
return R.layout.history_stackview_widget;
|
return R.layout.history_stackview_widget;
|
||||||
case STREAKS:
|
case STREAKS:
|
||||||
return R.layout.streak_stackview_widget;
|
return R.layout.streak_stackview_widget;
|
||||||
|
case TARGET:
|
||||||
|
return R.layout.target_stackview_widget;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -66,6 +71,8 @@ public enum StackWidgetType {
|
|||||||
return R.id.historyStackWidgetView;
|
return R.id.historyStackWidgetView;
|
||||||
case STREAKS:
|
case STREAKS:
|
||||||
return R.id.streakStackWidgetView;
|
return R.id.streakStackWidgetView;
|
||||||
|
case TARGET:
|
||||||
|
return R.id.targetStackWidgetView;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -82,6 +89,8 @@ public enum StackWidgetType {
|
|||||||
return R.id.historyStackWidgetEmptyView;
|
return R.id.historyStackWidgetEmptyView;
|
||||||
case STREAKS:
|
case STREAKS:
|
||||||
return R.id.streakStackWidgetEmptyView;
|
return R.id.streakStackWidgetEmptyView;
|
||||||
|
case TARGET:
|
||||||
|
return R.id.targetStackWidgetEmptyView;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.widgets
|
||||||
|
|
||||||
|
import android.content.*
|
||||||
|
import android.view.*
|
||||||
|
import android.view.ViewGroup.*
|
||||||
|
import android.view.ViewGroup.LayoutParams.*
|
||||||
|
import org.isoron.uhabits.activities.common.views.*
|
||||||
|
import org.isoron.uhabits.activities.habits.show.views.*
|
||||||
|
import org.isoron.uhabits.core.models.*
|
||||||
|
import org.isoron.uhabits.widgets.views.*
|
||||||
|
|
||||||
|
class TargetWidget(
|
||||||
|
context: Context,
|
||||||
|
id: Int,
|
||||||
|
private val habit: Habit
|
||||||
|
) : BaseWidget(context, id) {
|
||||||
|
|
||||||
|
override fun getOnClickPendingIntent(context: Context) =
|
||||||
|
pendingIntentFactory.showHabit(habit)
|
||||||
|
|
||||||
|
override fun refreshData(view: View) {
|
||||||
|
val widgetView = view as GraphWidgetView
|
||||||
|
widgetView.setBackgroundAlpha(preferedBackgroundAlpha)
|
||||||
|
val chart = (widgetView.dataView as TargetChart)
|
||||||
|
with(TargetCard.RefreshTask(context, habit, prefs.firstWeekday, chart, null)) {
|
||||||
|
onPreExecute()
|
||||||
|
doInBackground()
|
||||||
|
onPostExecute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildView(): View {
|
||||||
|
return GraphWidgetView(context, TargetChart(context)).apply {
|
||||||
|
setTitle(habit.name)
|
||||||
|
layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDefaultHeight() = 200
|
||||||
|
override fun getDefaultWidth() = 200
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* 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.widgets
|
||||||
|
|
||||||
|
import android.content.*
|
||||||
|
|
||||||
|
class TargetWidgetProvider : BaseWidgetProvider() {
|
||||||
|
override fun getWidgetFromId(context: Context, id: Int): BaseWidget {
|
||||||
|
val habits = getHabitsFromWidgetId(id)
|
||||||
|
if (habits.size == 1) return TargetWidget(context, id, habits[0])
|
||||||
|
else return StackWidget(context, id, StackWidgetType.TARGET, habits)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,6 +67,7 @@ class WidgetUpdater
|
|||||||
updateWidgets(modifiedHabitId, ScoreWidgetProvider::class.java)
|
updateWidgets(modifiedHabitId, ScoreWidgetProvider::class.java)
|
||||||
updateWidgets(modifiedHabitId, StreakWidgetProvider::class.java)
|
updateWidgets(modifiedHabitId, StreakWidgetProvider::class.java)
|
||||||
updateWidgets(modifiedHabitId, FrequencyWidgetProvider::class.java)
|
updateWidgets(modifiedHabitId, FrequencyWidgetProvider::class.java)
|
||||||
|
updateWidgets(modifiedHabitId, TargetWidgetProvider::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<StackView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/targetStackWidgetView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:loopViews="true" />
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/targetStackWidgetEmptyView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="@string/streaks_stack_widget"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="#ffffff"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
</FrameLayout>
|
||||||
Reference in New Issue
Block a user