diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 000000000..31acf8f74
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,25 @@
+# Changelog
+
+### 1.2.0 (March 4, 2016)
+
+* Ability to export habit data as CSV
+* Widgets (checkmark, history, score and streaks)
+* More natural scrolling on data views (fling)
+* Minor UI improvements on pre-Lollipop devices
+* Fix crash on Samsung Galaxy TabS 8.4
+* Other minor bug fixes
+
+### 1.1.1 (February 24, 2016)
+
+* Show reminder only on chosen days of the week
+* Rearrange habits by long-pressing then dragging
+* Select and modify multiple habits simultaneously
+* 12/24 hour format according to phone preferences
+* Permanently delete habits
+* Usage hints during startup
+* Translation to Brazilian Portuguese and Chinese
+* Other minor fixes
+
+### 1.0.0 (February 19, 2016)
+
+* Initial release
\ No newline at end of file
diff --git a/README.md b/README.md
index 59737a051..065430702 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,31 @@
# Loop Habit Tracker
-Loop is a simple Android app that helps you create and maintain good habits. Detailed graphs and statistics show you how your habits improved over time. It is completely ad-free and open source, with no intrusive permissions. Join the open beta at [Google Play Store](https://play.google.com/apps/testing/org.isoron.uhabits).
+Loop is a simple Android app that helps you create and maintain good habits, allowing you to achieve your long-term goals. Detailed graphs and statistics show you how your habits improved over time. It is completely ad-free and open source.
+
+
## Features
-* Simple and beautiful interface, following the Material Design guidelines.
-* Advanced algorithms for calculating the strength of your habits. Every repetition makes your habit stronger, and every missed day makes it weaker. A few missed days after a long streak, however, will not completely destroy your entire progress.
-* Detailed graphs and statistics, showing how did you habits improve over time. Scroll back to see the complete history of your habit.
-* Support for both daily habits and habits with more complex schedules, such as 3 times every week; one time every other week; or every other day.
-* Habit reminders at a chosen hour of the day.
-* Support for Android Wear. Reminders can be checked or dismissed from the watch.
-* Completely ad-free and open source. There are absolutely no advertisements, annoying notifications or intrusive permissions in this app, and there will never be. The complete source code is available under the GPLv3.
+Simple, beautiful and modern interface
+Loop has a minimalistic interface that is easy to use and follows the material design guidelines.
+
+Habit score
+In addition to showing your current streak, Loop has an advanced algorithm for calculating the strength of your habits. Every repetition makes your habit stronger, and every missed day makes it weaker. A few missed days after a long streak, however, will not completely destroy your entire progress.
+
+Detailed graphs and statistics
+Clearly see how your habits improved over time with beautiful and detailed graphs. Scroll back to see the complete history of your habits.
+
+Flexible schedules
+Supports both daily habits and habits with more complex schedules, such as 3 times every week; one time every other week; or every other day.
+
+Reminders
+Create an individual reminder for each habit, at a chosen hour of the day. Easily check, dismiss or snooze your habit directly from the notification, without opening the app.
+
+Optimized for smartwatches
+Reminders can be checked, snoozed or dismissed directly from your Android Wear watch.
+
+Completely ad-free and open source
+There are absolutely no advertisements, annoying notifications or intrusive permissions in this app, and there will never be. The complete source code is available under the GPLv3.
## Screenshots
@@ -18,12 +33,15 @@ Loop is a simple Android app that helps you create and maintain good habits. Det
[![Edit habit][screen2th]][screen2]
[![Habit strength][screen3th]][screen3]
[![Habit history and streaks][screen4th]][screen4]
+[![Widgets][screen5th]][screen5]
[screen1]: screenshots/original/uhabits1.png
[screen2]: screenshots/original/uhabits2.png
[screen3]: screenshots/original/uhabits3.png
[screen4]: screenshots/original/uhabits4.png
+[screen5]: screenshots/original/uhabits5.png
[screen1th]: screenshots/thumbs/uhabits1.png
[screen2th]: screenshots/thumbs/uhabits2.png
[screen3th]: screenshots/thumbs/uhabits3.png
[screen4th]: screenshots/thumbs/uhabits4.png
+[screen5th]: screenshots/thumbs/uhabits5.png
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d68cee904..80f2bbd0d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,18 +2,23 @@
+ android:versionCode="9"
+ android:versionName="1.2.0">
+
+
+ android:theme="@style/AppBaseTheme">
+ android:value="12"/>
+ android:value="AEdPqrEAAAAI6aeWncbnMNo8E5GWeZ44dlc5cQ7tCROwFhOtiw"/>
+ android:name=".HabitBroadcastReceiver"/>
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/assets/migrations/12.sql b/app/src/main/assets/migrations/12.sql
new file mode 100644
index 000000000..e13df67f7
--- /dev/null
+++ b/app/src/main/assets/migrations/12.sql
@@ -0,0 +1,3 @@
+delete from Score;
+delete from Streak;
+delete from Checkmarks;
\ No newline at end of file
diff --git a/app/src/main/ic_small_widget_preview-web.png b/app/src/main/ic_small_widget_preview-web.png
new file mode 100644
index 000000000..5d6fa2451
Binary files /dev/null and b/app/src/main/ic_small_widget_preview-web.png differ
diff --git a/app/src/main/java/com/android/datetimepicker/time/TimePickerDialog.java b/app/src/main/java/com/android/datetimepicker/time/TimePickerDialog.java
index db3ed7890..e365005f4 100644
--- a/app/src/main/java/com/android/datetimepicker/time/TimePickerDialog.java
+++ b/app/src/main/java/com/android/datetimepicker/time/TimePickerDialog.java
@@ -23,6 +23,7 @@ import java.util.Locale;
import org.isoron.uhabits.R;
import android.animation.ObjectAnimator;
+import android.annotation.SuppressLint;
import android.app.ActionBar.LayoutParams;
import android.app.DialogFragment;
import android.content.Context;
@@ -132,6 +133,7 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
// Empty constructor required for dialog fragment.
}
+ @SuppressLint("Java")
public TimePickerDialog(Context context, int theme, OnTimeSetListener callback,
int hourOfDay, int minute, boolean is24HourMode) {
// Empty constructor required for dialog fragment.
diff --git a/app/src/main/java/org/isoron/helpers/ColorHelper.java b/app/src/main/java/org/isoron/helpers/ColorHelper.java
index adb4849c5..2a4a0a258 100644
--- a/app/src/main/java/org/isoron/helpers/ColorHelper.java
+++ b/app/src/main/java/org/isoron/helpers/ColorHelper.java
@@ -57,4 +57,35 @@ public class ColorHelper
return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL;
}
+
+ public static int setHue(int color, float newHue)
+ {
+ return setHSVParameter(color, newHue, 0);
+ }
+
+ public static int setSaturation(int color, float newSaturation)
+ {
+ return setHSVParameter(color, newSaturation, 1);
+ }
+
+ public static int setValue(int color, float newValue)
+ {
+ return setHSVParameter(color, newValue, 2);
+ }
+
+ public static int setMinValue(int color, float newValue)
+ {
+ float hsv[] = new float[3];
+ Color.colorToHSV(color, hsv);
+ hsv[2] = Math.max(hsv[2], newValue);
+ return Color.HSVToColor(hsv);
+ }
+
+ private static int setHSVParameter(int color, float newValue, int index)
+ {
+ float hsv[] = new float[3];
+ Color.colorToHSV(color, hsv);
+ hsv[index] = newValue;
+ return Color.HSVToColor(hsv);
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/org/isoron/helpers/DialogHelper.java b/app/src/main/java/org/isoron/helpers/DialogHelper.java
index 04e99d65d..48d2cad02 100644
--- a/app/src/main/java/org/isoron/helpers/DialogHelper.java
+++ b/app/src/main/java/org/isoron/helpers/DialogHelper.java
@@ -17,21 +17,22 @@
package org.isoron.helpers;
import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences;
+import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Vibrator;
import android.preference.PreferenceManager;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
-import android.widget.TextView;
-import org.isoron.uhabits.R;
+import org.isoron.uhabits.BuildConfig;
public abstract class DialogHelper
{
+ public static final String ISORON_NAMESPACE = "http://isoron.org/android";
private static Typeface fontawesome;
public interface OnSavedListener
@@ -60,9 +61,32 @@ public abstract class DialogHelper
prefs.edit().putInt("launch_count", count + 1).apply();
}
+ public static void updateLastAppVersion(Context context)
+ {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ prefs.edit().putInt("last_version", BuildConfig.VERSION_CODE).apply();
+ }
+
public static int getLaunchCount(Context context)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getInt("launch_count", 0);
}
+
+ public static String getAttribute(Context context, AttributeSet attrs, String name)
+ {
+ int resId = attrs.getAttributeResourceValue(ISORON_NAMESPACE, name, 0);
+
+ if(resId != 0)
+ return context.getResources().getString(resId);
+ else
+ return attrs.getAttributeValue(ISORON_NAMESPACE, name);
+ }
+
+ public static float dpToPixels(Context context, float dp)
+ {
+ Resources resources = context.getResources();
+ DisplayMetrics metrics = resources.getDisplayMetrics();
+ return dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
+ }
}
diff --git a/app/src/main/java/org/isoron/uhabits/ReminderAlarmReceiver.java b/app/src/main/java/org/isoron/uhabits/HabitBroadcastReceiver.java
similarity index 76%
rename from app/src/main/java/org/isoron/uhabits/ReminderAlarmReceiver.java
rename to app/src/main/java/org/isoron/uhabits/HabitBroadcastReceiver.java
index e2769614f..3942f8e52 100644
--- a/app/src/main/java/org/isoron/uhabits/ReminderAlarmReceiver.java
+++ b/app/src/main/java/org/isoron/uhabits/HabitBroadcastReceiver.java
@@ -31,6 +31,7 @@ import android.net.Uri;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
+import android.support.v4.content.LocalBroadcastManager;
import org.isoron.helpers.DateHelper;
import org.isoron.uhabits.helpers.ReminderHelper;
@@ -38,12 +39,11 @@ import org.isoron.uhabits.models.Habit;
import java.util.Date;
-public class ReminderAlarmReceiver extends BroadcastReceiver
+public class HabitBroadcastReceiver extends BroadcastReceiver
{
public static final String ACTION_CHECK = "org.isoron.uhabits.ACTION_CHECK";
public static final String ACTION_DISMISS = "org.isoron.uhabits.ACTION_DISMISS";
- public static final String ACTION_REMIND = "org.isoron.uhabits.ACTION_REMIND";
- public static final String ACTION_REMOVE_REMINDER = "org.isoron.uhabits.ACTION_REMOVE_REMINDER";
+ public static final String ACTION_SHOW_REMINDER = "org.isoron.uhabits.ACTION_SHOW_REMINDER";
public static final String ACTION_SNOOZE = "org.isoron.uhabits.ACTION_SNOOZE";
@Override
@@ -51,7 +51,7 @@ public class ReminderAlarmReceiver extends BroadcastReceiver
{
switch (intent.getAction())
{
- case ACTION_REMIND:
+ case ACTION_SHOW_REMINDER:
createNotification(context, intent);
createReminderAlarms(context);
break;
@@ -97,15 +97,18 @@ public class ReminderAlarmReceiver extends BroadcastReceiver
private void checkHabit(Context context, Intent intent)
{
Uri data = intent.getData();
- Long timestamp = DateHelper.getStartOfToday();
- String paramTimestamp = data.getQueryParameter("timestamp");
-
- if(paramTimestamp != null) timestamp = Long.parseLong(paramTimestamp);
+ Long timestamp = intent.getLongExtra("timestamp", DateHelper.getStartOfToday());
Habit habit = Habit.get(ContentUris.parseId(data));
- habit.toggleRepetition(timestamp);
+ habit.repetitions.toggle(timestamp);
habit.save();
dismissNotification(context, habit);
+
+ LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
+ Intent refreshIntent = new Intent(MainActivity.ACTION_REFRESH);
+ manager.sendBroadcast(refreshIntent);
+
+ MainActivity.updateWidgets(context);
}
private void dismissAllHabits()
@@ -131,8 +134,10 @@ public class ReminderAlarmReceiver extends BroadcastReceiver
{
Uri data = intent.getData();
Habit habit = Habit.get(ContentUris.parseId(data));
+ Long timestamp = intent.getLongExtra("timestamp", DateHelper.getStartOfToday());
+ Long reminderTime = intent.getLongExtra("reminderTime", DateHelper.getStartOfToday());
- if (habit.hasImplicitRepToday()) return;
+ if (habit.repetitions.hasImplicitRepToday()) return;
habit.highlight = 1;
habit.save();
@@ -147,24 +152,12 @@ public class ReminderAlarmReceiver extends BroadcastReceiver
PendingIntent contentPendingIntent =
PendingIntent.getActivity(context, 0, contentIntent, 0);
- Intent deleteIntent = new Intent(context, ReminderAlarmReceiver.class);
- deleteIntent.setAction(ACTION_DISMISS);
- PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, 0);
-
- Intent checkIntent = new Intent(context, ReminderAlarmReceiver.class);
- checkIntent.setData(data);
- checkIntent.setAction(ACTION_CHECK);
- PendingIntent checkIntentPending = PendingIntent.getBroadcast(context, 0, checkIntent, 0);
-
- Intent snoozeIntent = new Intent(context, ReminderAlarmReceiver.class);
- snoozeIntent.setData(data);
- snoozeIntent.setAction(ACTION_SNOOZE);
- PendingIntent snoozeIntentPending = PendingIntent.getBroadcast(context, 0, snoozeIntent, 0);
+ PendingIntent dismissPendingIntent = buildDismissIntent(context);
+ PendingIntent checkIntentPending = buildCheckIntent(context, habit, timestamp);
+ PendingIntent snoozeIntentPending = buildSnoozeIntent(context, habit);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- Long reminderTime = intent.getLongExtra("reminderTime", DateHelper.getStartOfToday());
-
NotificationCompat.WearableExtender wearableExtender =
new NotificationCompat.WearableExtender().setBackground(
BitmapFactory.decodeResource(context.getResources(), R.drawable.stripe));
@@ -174,7 +167,7 @@ public class ReminderAlarmReceiver extends BroadcastReceiver
.setContentTitle(habit.name)
.setContentText(habit.description)
.setContentIntent(contentPendingIntent)
- .setDeleteIntent(deletePendingIntent)
+ .setDeleteIntent(dismissPendingIntent)
.addAction(R.drawable.ic_action_check,
context.getString(R.string.check), checkIntentPending)
.addAction(R.drawable.ic_action_snooze,
@@ -194,6 +187,32 @@ public class ReminderAlarmReceiver extends BroadcastReceiver
notificationManager.notify(notificationId, notification);
}
+ 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, 0);
+ }
+
+ 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_ONE_SHOT);
+ }
+
+ public static PendingIntent buildDismissIntent(Context context)
+ {
+ Intent deleteIntent = new Intent(context, HabitBroadcastReceiver.class);
+ deleteIntent.setAction(ACTION_DISMISS);
+ return PendingIntent.getBroadcast(context, 0, deleteIntent, 0);
+ }
+
private boolean checkWeekday(Intent intent, Habit habit)
{
Long timestamp = intent.getLongExtra("timestamp", DateHelper.getStartOfToday());
diff --git a/app/src/main/java/org/isoron/uhabits/MainActivity.java b/app/src/main/java/org/isoron/uhabits/MainActivity.java
index 4b7656154..e9f07bd01 100644
--- a/app/src/main/java/org/isoron/uhabits/MainActivity.java
+++ b/app/src/main/java/org/isoron/uhabits/MainActivity.java
@@ -16,11 +16,18 @@
package org.isoron.uhabits;
+import android.appwidget.AppWidgetManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.support.v4.content.LocalBroadcastManager;
import android.view.Menu;
import android.view.MenuItem;
@@ -30,12 +37,20 @@ import org.isoron.helpers.ReplayableActivity;
import org.isoron.uhabits.fragments.ListHabitsFragment;
import org.isoron.uhabits.helpers.ReminderHelper;
import org.isoron.uhabits.models.Habit;
+import org.isoron.uhabits.widgets.CheckmarkWidgetProvider;
+import org.isoron.uhabits.widgets.HistoryWidgetProvider;
+import org.isoron.uhabits.widgets.ScoreWidgetProvider;
+import org.isoron.uhabits.widgets.StreakWidgetProvider;
public class MainActivity extends ReplayableActivity
implements ListHabitsFragment.OnHabitClickListener
{
private ListHabitsFragment listHabitsFragment;
- SharedPreferences prefs;
+ private SharedPreferences prefs;
+ private BroadcastReceiver receiver;
+ private LocalBroadcastManager localBroadcastManager;
+
+ public static final String ACTION_REFRESH = "org.isoron.uhabits.ACTION_REFRESH";
@Override
protected void onCreate(Bundle savedInstanceState)
@@ -47,15 +62,30 @@ public class MainActivity extends ReplayableActivity
listHabitsFragment =
(ListHabitsFragment) getFragmentManager().findFragmentById(R.id.fragment1);
+ receiver = new Receiver();
+ localBroadcastManager = LocalBroadcastManager.getInstance(this);
+ localBroadcastManager.registerReceiver(receiver, new IntentFilter(ACTION_REFRESH));
+
onStartup();
}
private void onStartup()
{
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
- ReminderHelper.createReminderAlarms(MainActivity.this);
DialogHelper.incrementLaunchCount(this);
+ DialogHelper.updateLastAppVersion(this);
showTutorial();
+
+ new AsyncTask() {
+ @Override
+ protected Void doInBackground(Void... params)
+ {
+ ReminderHelper.createReminderAlarms(MainActivity.this);
+ updateWidgets(MainActivity.this);
+ return null;
+ }
+ }.execute();
+
}
private void showTutorial()
@@ -108,5 +138,40 @@ public class MainActivity extends ReplayableActivity
public void onPostExecuteCommand(Long refreshKey)
{
listHabitsFragment.onPostExecuteCommand(refreshKey);
+ updateWidgets(this);
+ }
+
+ public static void updateWidgets(Context context)
+ {
+ updateWidgets(context, CheckmarkWidgetProvider.class);
+ updateWidgets(context, HistoryWidgetProvider.class);
+ updateWidgets(context, ScoreWidgetProvider.class);
+ updateWidgets(context, StreakWidgetProvider.class);
+ }
+
+ private static void updateWidgets(Context context, Class providerClass)
+ {
+ ComponentName provider = new ComponentName(context, providerClass);
+ Intent intent = new Intent(context, providerClass);
+ intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
+ int ids[] = AppWidgetManager.getInstance(context).getAppWidgetIds(provider);
+ intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
+ context.sendBroadcast(intent);
+ }
+
+ @Override
+ protected void onDestroy()
+ {
+ localBroadcastManager.unregisterReceiver(receiver);
+ super.onDestroy();
+ }
+
+ class Receiver extends BroadcastReceiver
+ {
+ @Override
+ public void onReceive(Context context, Intent intent)
+ {
+ listHabitsFragment.onPostExecuteCommand(null);
+ }
}
}
diff --git a/app/src/main/java/org/isoron/uhabits/commands/ChangeHabitColorCommand.java b/app/src/main/java/org/isoron/uhabits/commands/ChangeHabitColorCommand.java
index f522f0bf5..547024b42 100644
--- a/app/src/main/java/org/isoron/uhabits/commands/ChangeHabitColorCommand.java
+++ b/app/src/main/java/org/isoron/uhabits/commands/ChangeHabitColorCommand.java
@@ -23,7 +23,6 @@ import org.isoron.uhabits.R;
import org.isoron.uhabits.models.Habit;
import java.util.ArrayList;
-import java.util.LinkedList;
import java.util.List;
public class ChangeHabitColorCommand extends Command
diff --git a/app/src/main/java/org/isoron/uhabits/commands/CreateHabitCommand.java b/app/src/main/java/org/isoron/uhabits/commands/CreateHabitCommand.java
new file mode 100644
index 000000000..aa758cbb7
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/commands/CreateHabitCommand.java
@@ -0,0 +1,66 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.commands;
+
+import org.isoron.helpers.Command;
+import org.isoron.uhabits.R;
+import org.isoron.uhabits.models.Habit;
+
+public class CreateHabitCommand extends Command
+{
+ private Habit model;
+ private Long savedId;
+
+ public CreateHabitCommand(Habit model)
+ {
+ this.model = model;
+ }
+
+ @Override
+ public void execute()
+ {
+ Habit savedHabit = new Habit(model);
+ if (savedId == null)
+ {
+ savedHabit.save();
+ savedId = savedHabit.getId();
+ }
+ else
+ {
+ savedHabit.save(savedId);
+ }
+ }
+
+ @Override
+ public void undo()
+ {
+ Habit.get(savedId).delete();
+ }
+
+ @Override
+ public Integer getExecuteStringId()
+ {
+ return R.string.toast_habit_created;
+ }
+
+ @Override
+ public Integer getUndoStringId()
+ {
+ return R.string.toast_habit_deleted;
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/isoron/uhabits/commands/EditHabitCommand.java b/app/src/main/java/org/isoron/uhabits/commands/EditHabitCommand.java
new file mode 100644
index 000000000..53b4bbf1b
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/commands/EditHabitCommand.java
@@ -0,0 +1,75 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.commands;
+
+import org.isoron.helpers.Command;
+import org.isoron.uhabits.R;
+import org.isoron.uhabits.models.Habit;
+
+public class EditHabitCommand extends Command
+{
+ private Habit original;
+ private Habit modified;
+ private long savedId;
+ private boolean hasIntervalChanged;
+
+ public EditHabitCommand(Habit original, Habit modified)
+ {
+ this.savedId = original.getId();
+ this.modified = new Habit(modified);
+ this.original = new Habit(original);
+
+ hasIntervalChanged = (this.original.freqDen != this.modified.freqDen ||
+ this.original.freqNum != this.modified.freqNum);
+ }
+
+ public void execute()
+ {
+ Habit habit = Habit.get(savedId);
+ habit.copyAttributes(modified);
+ habit.save();
+ if (hasIntervalChanged)
+ {
+ habit.checkmarks.deleteNewerThan(0);
+ habit.streaks.deleteNewerThan(0);
+ habit.scores.deleteNewerThan(0);
+ }
+ }
+
+ public void undo()
+ {
+ Habit habit = Habit.get(savedId);
+ habit.copyAttributes(original);
+ habit.save();
+ if (hasIntervalChanged)
+ {
+ habit.checkmarks.deleteNewerThan(0);
+ habit.streaks.deleteNewerThan(0);
+ habit.scores.deleteNewerThan(0);
+ }
+ }
+
+ public Integer getExecuteStringId()
+ {
+ return R.string.toast_habit_changed;
+ }
+
+ public Integer getUndoStringId()
+ {
+ return R.string.toast_habit_changed_back;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/isoron/uhabits/commands/ToggleRepetitionCommand.java b/app/src/main/java/org/isoron/uhabits/commands/ToggleRepetitionCommand.java
new file mode 100644
index 000000000..c19ff5a5d
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/commands/ToggleRepetitionCommand.java
@@ -0,0 +1,44 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.commands;
+
+import org.isoron.helpers.Command;
+import org.isoron.uhabits.models.Habit;
+
+public class ToggleRepetitionCommand extends Command
+{
+ private Long offset;
+ private Habit habit;
+
+ public ToggleRepetitionCommand(Habit habit, long offset)
+ {
+ this.offset = offset;
+ this.habit = habit;
+ }
+
+ @Override
+ public void execute()
+ {
+ habit.repetitions.toggle(offset);
+ }
+
+ @Override
+ public void undo()
+ {
+ execute();
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/isoron/uhabits/fragments/EditHabitFragment.java b/app/src/main/java/org/isoron/uhabits/fragments/EditHabitFragment.java
index 7a6745ba4..82a32d37d 100644
--- a/app/src/main/java/org/isoron/uhabits/fragments/EditHabitFragment.java
+++ b/app/src/main/java/org/isoron/uhabits/fragments/EditHabitFragment.java
@@ -40,6 +40,8 @@ import org.isoron.helpers.Command;
import org.isoron.helpers.DateHelper;
import org.isoron.helpers.DialogHelper.OnSavedListener;
import org.isoron.uhabits.R;
+import org.isoron.uhabits.commands.CreateHabitCommand;
+import org.isoron.uhabits.commands.EditHabitCommand;
import org.isoron.uhabits.dialogs.WeekdayPickerDialog;
import org.isoron.uhabits.models.Habit;
@@ -241,11 +243,11 @@ public class EditHabitFragment extends DialogFragment
if (mode == EDIT_MODE)
{
- command = originalHabit.new EditCommand(modifiedHabit);
+ command = new EditHabitCommand(originalHabit, modifiedHabit);
savedHabit = originalHabit;
}
- if (mode == CREATE_MODE) command = new Habit.CreateCommand(modifiedHabit);
+ if (mode == CREATE_MODE) command = new CreateHabitCommand(modifiedHabit);
if (onSavedListener != null) onSavedListener.onSaved(command, savedHabit);
diff --git a/app/src/main/java/org/isoron/uhabits/fragments/ListHabitsFragment.java b/app/src/main/java/org/isoron/uhabits/fragments/ListHabitsFragment.java
index 9a9fcfc73..278e54345 100644
--- a/app/src/main/java/org/isoron/uhabits/fragments/ListHabitsFragment.java
+++ b/app/src/main/java/org/isoron/uhabits/fragments/ListHabitsFragment.java
@@ -23,9 +23,12 @@ import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
+import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
@@ -66,11 +69,15 @@ import org.isoron.uhabits.R;
import org.isoron.uhabits.commands.ArchiveHabitsCommand;
import org.isoron.uhabits.commands.ChangeHabitColorCommand;
import org.isoron.uhabits.commands.DeleteHabitsCommand;
+import org.isoron.uhabits.commands.ToggleRepetitionCommand;
import org.isoron.uhabits.commands.UnarchiveHabitsCommand;
import org.isoron.uhabits.helpers.ReminderHelper;
+import org.isoron.uhabits.io.CSVExporter;
import org.isoron.uhabits.loaders.HabitListLoader;
import org.isoron.uhabits.models.Habit;
+import org.isoron.uhabits.models.Score;
+import java.io.File;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedList;
@@ -199,6 +206,12 @@ public class ListHabitsFragment extends Fragment
return true;
}
+
+ case R.id.action_export_csv:
+ {
+ onExportHabitsClick(selectedHabits);
+ return true;
+ }
}
return false;
@@ -248,6 +261,7 @@ public class ListHabitsFragment extends Fragment
private ActionMode actionMode;
private List selectedPositions;
private DragSortController dragSortController;
+ private ProgressBar progressBar;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@@ -255,7 +269,7 @@ public class ListHabitsFragment extends Fragment
{
DisplayMetrics dm = getResources().getDisplayMetrics();
int width = (int) (dm.widthPixels / dm.density);
- buttonCount = (int) ((width - 160) / 42.0);
+ buttonCount = Math.max(0, (int) ((width - 160) / 42.0));
tvNameWidth = (int) ((width - 30 - buttonCount * 42) * dm.density);
loader = new HabitListLoader();
@@ -265,7 +279,7 @@ public class ListHabitsFragment extends Fragment
View view = inflater.inflate(R.layout.list_habits_fragment, container, false);
tvNameHeader = (TextView) view.findViewById(R.id.tvNameHeader);
- ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
+ progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
loader.setProgressBar(progressBar);
adapter = new ListHabitsAdapter(getActivity());
@@ -533,7 +547,7 @@ public class ListHabitsFragment extends Fragment
if (v.getTag(R.string.toggle_key).equals(2)) updateCheckmark(habit.color, (TextView) v, 0);
else updateCheckmark(habit.color, (TextView) v, 2);
- executeCommand(habit.new ToggleRepetitionCommand(timestamp), habit.getId());
+ executeCommand(new ToggleRepetitionCommand(habit, timestamp), habit.getId());
}
private void executeCommand(Command c, Long refreshKey)
@@ -648,7 +662,7 @@ public class ListHabitsFragment extends Fragment
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(tvNameWidth, LayoutParams.WRAP_CONTENT, 1);
- view.findViewById(R.id.tvName).setLayoutParams(params);
+ view.findViewById(R.id.label).setLayoutParams(params);
inflateCheckmarkButtons(view);
@@ -656,7 +670,7 @@ public class ListHabitsFragment extends Fragment
}
TextView tvStar = ((TextView) view.findViewById(R.id.tvStar));
- TextView tvName = (TextView) view.findViewById(R.id.tvName);
+ TextView tvName = (TextView) view.findViewById(R.id.label);
LinearLayout llInner = (LinearLayout) view.findViewById(R.id.llInner);
LinearLayout llButtons = (LinearLayout) view.findViewById(R.id.llButtons);
@@ -673,7 +687,7 @@ public class ListHabitsFragment extends Fragment
if (android.os.Build.VERSION.SDK_INT >= 21)
llInner.setBackgroundResource(R.drawable.ripple_white);
else
- llInner.setBackgroundColor(Color.WHITE);
+ llInner.setBackgroundResource(R.drawable.card_background);
}
return view;
@@ -707,7 +721,8 @@ public class ListHabitsFragment extends Fragment
TextView tvCheck = (TextView) llButtons.getChildAt(i);
tvCheck.setTag(R.string.habit_key, habitId);
tvCheck.setTag(R.string.offset_key, i);
- updateCheckmark(activeColor, tvCheck, isChecked[i]);
+ if(isChecked.length > i)
+ updateCheckmark(activeColor, tvCheck, isChecked[i]);
}
}
@@ -727,12 +742,12 @@ public class ListHabitsFragment extends Fragment
{
int score = loader.scores.get(habit.getId());
- if (score < Habit.HALF_STAR_CUTOFF)
+ if (score < Score.HALF_STAR_CUTOFF)
{
tvStar.setText(getString(R.string.fa_star_o));
tvStar.setTextColor(INACTIVE_COLOR);
}
- else if (score < Habit.FULL_STAR_CUTOFF)
+ else if (score < Score.FULL_STAR_CUTOFF)
{
tvStar.setText(getString(R.string.fa_star_half_o));
tvStar.setTextColor(INACTIVE_COLOR);
@@ -782,4 +797,43 @@ public class ListHabitsFragment extends Fragment
if (refreshKey == null) loader.updateAllHabits(true);
else loader.updateHabit(refreshKey);
}
+
+ private void onExportHabitsClick(final LinkedList selectedHabits)
+ {
+ new AsyncTask()
+ {
+ String filename;
+
+ @Override
+ protected void onPreExecute()
+ {
+ progressBar.setIndeterminate(true);
+ progressBar.setVisibility(View.VISIBLE);
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid)
+ {
+ if(filename != null)
+ {
+ Intent intent = new Intent();
+ intent.setAction(Intent.ACTION_SEND);
+ intent.setType("application/zip");
+ intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filename)));
+
+ startActivity(intent);
+ }
+
+ progressBar.setVisibility(View.GONE);
+ }
+
+ @Override
+ protected Void doInBackground(Void... params)
+ {
+ CSVExporter exporter = new CSVExporter(activity, selectedHabits);
+ filename = exporter.writeArchive();
+ return null;
+ }
+ }.execute();
+ }
}
diff --git a/app/src/main/java/org/isoron/uhabits/fragments/ShowHabitFragment.java b/app/src/main/java/org/isoron/uhabits/fragments/ShowHabitFragment.java
index 90b586163..812f832ef 100644
--- a/app/src/main/java/org/isoron/uhabits/fragments/ShowHabitFragment.java
+++ b/app/src/main/java/org/isoron/uhabits/fragments/ShowHabitFragment.java
@@ -25,16 +25,16 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.LinearLayout;
import android.widget.TextView;
import org.isoron.helpers.ColorHelper;
import org.isoron.helpers.Command;
import org.isoron.helpers.DialogHelper;
import org.isoron.uhabits.R;
-import org.isoron.uhabits.helpers.ReminderHelper;
import org.isoron.uhabits.ShowHabitActivity;
+import org.isoron.uhabits.helpers.ReminderHelper;
import org.isoron.uhabits.models.Habit;
+import org.isoron.uhabits.models.Score;
import org.isoron.uhabits.views.HabitHistoryView;
import org.isoron.uhabits.views.HabitScoreView;
import org.isoron.uhabits.views.HabitStreakView;
@@ -59,7 +59,7 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
activity = (ShowHabitActivity) getActivity();
habit = activity.habit;
- habit.updateCheckmarks();
+ habit.checkmarks.rebuild();
if (android.os.Build.VERSION.SDK_INT >= 21)
{
@@ -71,29 +71,21 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
TextView tvOverview = (TextView) view.findViewById(R.id.tvOverview);
TextView tvStrength = (TextView) view.findViewById(R.id.tvStrength);
TextView tvStreaks = (TextView) view.findViewById(R.id.tvStreaks);
+ RingView scoreRing = (RingView) view.findViewById(R.id.scoreRing);
+ HabitStreakView streakView = (HabitStreakView) view.findViewById(R.id.streakView);
+ HabitScoreView scoreView = (HabitScoreView) view.findViewById(R.id.scoreView);
+ HabitHistoryView historyView = (HabitHistoryView) view.findViewById(R.id.historyView);
+
tvHistory.setTextColor(habit.color);
tvOverview.setTextColor(habit.color);
tvStrength.setTextColor(habit.color);
tvStreaks.setTextColor(habit.color);
- LinearLayout llOverview = (LinearLayout) view.findViewById(R.id.llOverview);
- llOverview.addView(new RingView(activity,
- (int) activity.getResources().getDimension(R.dimen.small_square_size) * 4,
- habit.color, ((float) habit.getScore() / Habit.MAX_SCORE), activity.getString(R.string.habit_strength)));
-
- LinearLayout llStrength = (LinearLayout) view.findViewById(R.id.llStrength);
- llStrength.addView(new HabitScoreView(activity, habit,
- (int) activity.getResources().getDimension(R.dimen.small_square_size)));
-
- LinearLayout llHistory = (LinearLayout) view.findViewById(R.id.llHistory);
- HabitHistoryView hhv = new HabitHistoryView(activity, habit,
- (int) activity.getResources().getDimension(R.dimen.small_square_size));
- llHistory.addView(hhv);
-
- LinearLayout llStreaks = (LinearLayout) view.findViewById(R.id.llStreaks);
- HabitStreakView hsv = new HabitStreakView(activity, habit,
- (int) activity.getResources().getDimension(R.dimen.small_square_size));
- llStreaks.addView(hsv);
+ scoreRing.setColor(habit.color);
+ scoreRing.setPercentage((float) habit.scores.getNewestValue() / Score.MAX_SCORE);
+ streakView.setHabit(habit);
+ scoreView.setHabit(habit);
+ historyView.setHabit(habit);
setHasOptionsMenu(true);
return view;
diff --git a/app/src/main/java/org/isoron/uhabits/helpers/ReminderHelper.java b/app/src/main/java/org/isoron/uhabits/helpers/ReminderHelper.java
index 94d10e5f2..cbc1bd9c1 100644
--- a/app/src/main/java/org/isoron/uhabits/helpers/ReminderHelper.java
+++ b/app/src/main/java/org/isoron/uhabits/helpers/ReminderHelper.java
@@ -25,7 +25,7 @@ import android.os.Build;
import android.util.Log;
import org.isoron.helpers.DateHelper;
-import org.isoron.uhabits.ReminderAlarmReceiver;
+import org.isoron.uhabits.HabitBroadcastReceiver;
import org.isoron.uhabits.models.Habit;
import java.text.DateFormat;
@@ -58,10 +58,10 @@ public class ReminderHelper
long timestamp = DateHelper.getStartOfDay(DateHelper.toLocalTime(reminderTime));
- Uri uri = Uri.parse(String.format("content://org.isoron.uhabits/habit/%d", habit.getId()));
+ Uri uri = habit.getUri();
- Intent alarmIntent = new Intent(context, ReminderAlarmReceiver.class);
- alarmIntent.setAction(ReminderAlarmReceiver.ACTION_REMIND);
+ Intent alarmIntent = new Intent(context, HabitBroadcastReceiver.class);
+ alarmIntent.setAction(HabitBroadcastReceiver.ACTION_SHOW_REMINDER);
alarmIntent.setData(uri);
alarmIntent.putExtra("timestamp", timestamp);
alarmIntent.putExtra("reminderTime", reminderTime);
diff --git a/app/src/main/java/org/isoron/uhabits/io/CSVExporter.java b/app/src/main/java/org/isoron/uhabits/io/CSVExporter.java
new file mode 100644
index 000000000..4af223161
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/io/CSVExporter.java
@@ -0,0 +1,194 @@
+package org.isoron.uhabits.io;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.util.Log;
+
+import com.activeandroid.Cache;
+
+import org.isoron.helpers.DateHelper;
+import org.isoron.uhabits.models.Habit;
+import org.isoron.uhabits.models.Score;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+public class CSVExporter
+{
+ private List habits;
+ private Context context;
+ private java.text.DateFormat dateFormat;
+
+ private List generateDirs;
+ private List generateFilenames;
+
+ private String basePath;
+
+ public CSVExporter(Context context, List habits)
+ {
+ this.habits = habits;
+ this.context = context;
+ generateDirs = new LinkedList<>();
+ generateFilenames = new LinkedList<>();
+
+ basePath = String.format("%s/export/", context.getFilesDir());
+
+ dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ }
+
+ public String formatDate(long timestamp)
+ {
+ return dateFormat.format(new Date(timestamp));
+ }
+
+ public String formatScore(int score)
+ {
+ return String.format("%.2f", ((float) score) / Score.MAX_SCORE);
+ }
+
+ private void writeScores(String dirPath, Habit habit) throws IOException
+ {
+ String path = dirPath + "scores.csv";
+ FileWriter out = new FileWriter(basePath + path);
+ generateFilenames.add(path);
+
+ String query = "select timestamp, score from score where habit = ? order by timestamp";
+ String params[] = { habit.getId().toString() };
+
+ SQLiteDatabase db = Cache.openDatabase();
+ Cursor cursor = db.rawQuery(query, params);
+
+ if(!cursor.moveToFirst()) return;
+
+ do
+ {
+ String timestamp = formatDate(cursor.getLong(0));
+ String score = formatScore(cursor.getInt(1));
+ out.write(String.format("%s,%s\n", timestamp, score));
+
+ } while(cursor.moveToNext());
+
+ out.close();
+ cursor.close();
+ }
+
+ private void writeCheckmarks(String dirPath, Habit habit) throws IOException
+ {
+ String path = dirPath + "checkmarks.csv";
+ FileWriter out = new FileWriter(basePath + path);
+ generateFilenames.add(path);
+
+ String query = "select timestamp, value from checkmarks where habit = ? order by timestamp";
+ String params[] = { habit.getId().toString() };
+
+ SQLiteDatabase db = Cache.openDatabase();
+ Cursor cursor = db.rawQuery(query, params);
+
+ if(!cursor.moveToFirst()) return;
+
+ do
+ {
+ String timestamp = formatDate(cursor.getLong(0));
+ Integer value = cursor.getInt(1);
+ out.write(String.format("%s,%d\n", timestamp, value));
+
+ } while(cursor.moveToNext());
+
+ out.close();
+ cursor.close();
+ }
+
+ private void writeFiles(Habit habit) throws IOException
+ {
+ String path = String.format("%s/", habit.name);
+ new File(basePath + path).mkdirs();
+ generateDirs.add(path);
+
+ writeScores(path, habit);
+ writeCheckmarks(path, habit);
+ }
+
+ private void writeZipFile(String zipFilename) throws IOException
+ {
+ FileOutputStream fos = new FileOutputStream(zipFilename);
+ ZipOutputStream zos = new ZipOutputStream(fos);
+
+ for(String filename : generateFilenames)
+ addFileToZip(zos, filename);
+
+ zos.close();
+ fos.close();
+ }
+
+ private void addFileToZip(ZipOutputStream zos, String filename) throws IOException
+ {
+ FileInputStream fis = new FileInputStream(new File(basePath + filename));
+ ZipEntry ze = new ZipEntry(filename);
+ zos.putNextEntry(ze);
+
+ int length;
+ byte bytes[] = new byte[1024];
+ while((length = fis.read(bytes)) >= 0)
+ zos.write(bytes, 0, length);
+
+ zos.closeEntry();
+ fis.close();
+ }
+
+ private void cleanup()
+ {
+ for(String filename : generateFilenames)
+ new File(basePath + filename).delete();
+
+ for(String filename : generateDirs)
+ new File(basePath + filename).delete();
+
+ new File(basePath).delete();
+ }
+
+ public String writeArchive()
+ {
+ String date = formatDate(DateHelper.getStartOfToday());
+
+ File dir = context.getExternalCacheDir();
+
+ if(dir == null)
+ {
+ Log.e("CSVExporter", "No suitable directory found.");
+ return null;
+ }
+
+ String zipFilename = String.format("%s/habits-%s.zip", dir, date);
+
+ try
+ {
+ for (Habit h : habits)
+ writeFiles(h);
+
+ writeZipFile(zipFilename);
+ cleanup();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+
+ return zipFilename;
+ }
+
+
+}
diff --git a/app/src/main/java/org/isoron/uhabits/loaders/HabitListLoader.java b/app/src/main/java/org/isoron/uhabits/loaders/HabitListLoader.java
index bd7443626..204b5e243 100644
--- a/app/src/main/java/org/isoron/uhabits/loaders/HabitListLoader.java
+++ b/app/src/main/java/org/isoron/uhabits/loaders/HabitListLoader.java
@@ -144,8 +144,8 @@ public class HabitListLoader
if (isCancelled()) return null;
Long id = h.getId();
- newScores.put(id, h.getScore());
- newCheckmarks.put(id, h.getCheckmarks(dateFrom, dateTo));
+ newScores.put(id, h.scores.getNewestValue());
+ newCheckmarks.put(id, h.checkmarks.getValues(dateFrom, dateTo));
publishProgress(current++, newHabits.size());
}
@@ -213,8 +213,8 @@ public class HabitListLoader
Habit h = Habit.get(id);
habits.put(id, h);
- scores.put(id, h.getScore());
- checkmarks.put(id, h.getCheckmarks(dateFrom, dateTo));
+ scores.put(id, h.scores.getNewestValue());
+ checkmarks.put(id, h.checkmarks.getValues(dateFrom, dateTo));
return null;
}
diff --git a/app/src/main/java/org/isoron/uhabits/models/CheckmarkList.java b/app/src/main/java/org/isoron/uhabits/models/CheckmarkList.java
new file mode 100644
index 000000000..61187ea30
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/models/CheckmarkList.java
@@ -0,0 +1,175 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.models;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
+import com.activeandroid.ActiveAndroid;
+import com.activeandroid.Cache;
+import com.activeandroid.query.Delete;
+import com.activeandroid.query.Select;
+
+import org.isoron.helpers.DateHelper;
+
+import java.util.List;
+
+public class CheckmarkList
+{
+ private Habit habit;
+
+ public CheckmarkList(Habit habit)
+ {
+ this.habit = habit;
+ }
+
+ public void deleteNewerThan(long timestamp)
+ {
+ new Delete().from(Checkmark.class)
+ .where("habit = ?", habit.getId())
+ .and("timestamp >= ?", timestamp)
+ .execute();
+ }
+
+ public int[] getValues(Long fromTimestamp, Long toTimestamp)
+ {
+ rebuild();
+
+ if(fromTimestamp > toTimestamp) return new int[0];
+
+ String query = "select value, timestamp from Checkmarks where " +
+ "habit = ? and timestamp >= ? and timestamp <= ?";
+
+ SQLiteDatabase db = Cache.openDatabase();
+ String args[] = { habit.getId().toString(), fromTimestamp.toString(),
+ toTimestamp.toString() };
+ Cursor cursor = db.rawQuery(query, args);
+
+ long day = DateHelper.millisecondsInOneDay;
+ int nDays = (int) ((toTimestamp - fromTimestamp) / day) + 1;
+ int[] checks = new int[nDays];
+
+ if (cursor.moveToFirst())
+ {
+ do
+ {
+ long timestamp = cursor.getLong(1);
+ int offset = (int) ((timestamp - fromTimestamp) / day);
+ checks[nDays - offset - 1] = cursor.getInt(0);
+
+ } while (cursor.moveToNext());
+ }
+
+ cursor.close();
+ return checks;
+ }
+
+ public int[] getAllValues()
+ {
+ Repetition oldestRep = habit.repetitions.getOldest();
+ if(oldestRep == null) return new int[0];
+
+ Long toTimestamp = DateHelper.getStartOfToday();
+ Long fromTimestamp = oldestRep.timestamp;
+ return getValues(fromTimestamp, toTimestamp);
+ }
+
+ public void rebuild()
+ {
+ long beginning;
+ long today = DateHelper.getStartOfToday();
+ long day = DateHelper.millisecondsInOneDay;
+
+ Checkmark newestCheckmark = getNewest();
+ if (newestCheckmark == null)
+ {
+ Repetition oldestRep = habit.repetitions.getOldest();
+ if (oldestRep == null) return;
+
+ beginning = oldestRep.timestamp;
+ }
+ else
+ {
+ beginning = newestCheckmark.timestamp + day;
+ }
+
+ if (beginning > today) return;
+
+ long beginningExtended = beginning - (long) (habit.freqDen) * day;
+ List reps = habit.repetitions.selectFromTo(beginningExtended, today).execute();
+
+ int nDays = (int) ((today - beginning) / day) + 1;
+ int nDaysExtended = (int) ((today - beginningExtended) / day) + 1;
+
+ int checks[] = new int[nDaysExtended];
+
+ // explicit checks
+ for (Repetition rep : reps)
+ {
+ int offset = (int) ((rep.timestamp - beginningExtended) / day);
+ checks[nDaysExtended - offset - 1] = 2;
+ }
+
+ // implicit checks
+ for (int i = 0; i < nDays; i++)
+ {
+ int counter = 0;
+
+ for (int j = 0; j < habit.freqDen; j++)
+ if (checks[i + j] == 2) counter++;
+
+ if (counter >= habit.freqNum) checks[i] = Math.max(checks[i], 1);
+ }
+
+ ActiveAndroid.beginTransaction();
+
+ try
+ {
+ for (int i = 0; i < nDays; i++)
+ {
+ Checkmark c = new Checkmark();
+ c.habit = habit;
+ c.timestamp = today - i * day;
+ c.value = checks[i];
+ c.save();
+ }
+
+ ActiveAndroid.setTransactionSuccessful();
+ } finally
+ {
+ ActiveAndroid.endTransaction();
+ }
+ }
+
+ public Checkmark getNewest()
+ {
+ return new Select().from(Checkmark.class)
+ .where("habit = ?", habit.getId())
+ .orderBy("timestamp desc")
+ .limit(1)
+ .executeSingle();
+ }
+
+ public int getCurrentValue()
+ {
+ rebuild();
+ Checkmark c = getNewest();
+
+ if(c != null) return c.value;
+ else return 0;
+ }
+}
diff --git a/app/src/main/java/org/isoron/uhabits/models/Habit.java b/app/src/main/java/org/isoron/uhabits/models/Habit.java
index ccd483458..fc3163b21 100644
--- a/app/src/main/java/org/isoron/uhabits/models/Habit.java
+++ b/app/src/main/java/org/isoron/uhabits/models/Habit.java
@@ -17,11 +17,9 @@
package org.isoron.uhabits.models;
import android.annotation.SuppressLint;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
+import android.net.Uri;
import com.activeandroid.ActiveAndroid;
-import com.activeandroid.Cache;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
@@ -32,21 +30,12 @@ import com.activeandroid.query.Update;
import com.activeandroid.util.SQLiteUtils;
import org.isoron.helpers.ColorHelper;
-import org.isoron.helpers.Command;
-import org.isoron.helpers.DateHelper;
-import org.isoron.uhabits.R;
-import java.util.ArrayList;
import java.util.List;
@Table(name = "Habits")
public class Habit extends Model
{
-
- public static final int HALF_STAR_CUTOFF = 9629750;
- public static final int FULL_STAR_CUTOFF = 15407600;
- public static final int MAX_SCORE = 19259500;
-
@Column(name = "name")
public String name;
@@ -80,20 +69,35 @@ public class Habit extends Model
@Column(name = "archived")
public Integer archived;
+ public StreakList streaks;
+ public ScoreList scores;
+ public RepetitionList repetitions;
+ public CheckmarkList checkmarks;
+
public Habit(Habit model)
{
copyAttributes(model);
+ initializeLists();
}
public Habit()
{
this.color = ColorHelper.palette[5];
- this.position = Habit.getCount();
+ this.position = Habit.countWithArchived();
this.highlight = 0;
this.archived = 0;
this.freqDen = 7;
this.freqNum = 3;
this.reminderDays = 127;
+ initializeLists();
+ }
+
+ private void initializeLists()
+ {
+ streaks = new StreakList(this);
+ scores = new ScoreList(this);
+ repetitions = new RepetitionList(this);
+ checkmarks = new CheckmarkList(this);
}
public static Habit get(Long id)
@@ -123,11 +127,16 @@ public class Habit extends Model
return new Select().from(Habit.class).orderBy("position");
}
- public static int getCount()
+ public static int count()
{
return select().count();
}
+ public static int countWithArchived()
+ {
+ return selectWithArchived().count();
+ }
+
public static java.util.List getHighlightedHabits()
{
return select().where("highlight = 1")
@@ -176,7 +185,8 @@ public class Habit extends Model
}
ActiveAndroid.setTransactionSuccessful();
- } finally
+ }
+ finally
{
ActiveAndroid.endTransaction();
}
@@ -204,22 +214,6 @@ public class Habit extends Model
Habit.updateId(getId(), id);
}
- protected From selectReps()
- {
- return new Select().from(Repetition.class).where("habit = ?", getId()).orderBy("timestamp");
- }
-
- protected From selectRepsFromTo(long timeFrom, long timeTo)
- {
- return selectReps().and("timestamp >= ?", timeFrom).and("timestamp <= ?", timeTo);
- }
-
- public boolean hasRep(long timestamp)
- {
- int count = selectReps().where("timestamp = ?", timestamp).count();
- return (count > 0);
- }
-
public void cascadeDelete()
{
Long id = getId();
@@ -241,176 +235,9 @@ public class Habit extends Model
}
}
- public void deleteReps(long timestamp)
- {
- new Delete().from(Repetition.class)
- .where("habit = ?", getId())
- .and("timestamp = ?", timestamp)
- .execute();
- }
-
- public void deleteCheckmarksNewerThan(long timestamp)
- {
- new Delete().from(Checkmark.class)
- .where("habit = ?", getId())
- .and("timestamp >= ?", timestamp)
- .execute();
- }
-
- public void deleteStreaksNewerThan(long timestamp)
- {
- new Delete().from(Streak.class)
- .where("habit = ?", getId())
- .and("end >= ?", timestamp - DateHelper.millisecondsInOneDay)
- .execute();
- }
-
- public int[] getCheckmarks(Long fromTimestamp, Long toTimestamp)
- {
- updateCheckmarks();
-
- String query = "select value, timestamp from Checkmarks where " +
- "habit = ? and timestamp >= ? and timestamp <= ?";
-
- SQLiteDatabase db = Cache.openDatabase();
- String args[] = {getId().toString(), fromTimestamp.toString(), toTimestamp.toString()};
- Cursor cursor = db.rawQuery(query, args);
-
- long day = DateHelper.millisecondsInOneDay;
- int nDays = (int) ((toTimestamp - fromTimestamp) / day) + 1;
- int[] checks = new int[nDays];
-
- if (cursor.moveToFirst())
- {
- do
- {
- long timestamp = cursor.getLong(1);
- int offset = (int) ((timestamp - fromTimestamp) / day);
- checks[nDays - offset - 1] = cursor.getInt(0);
-
- } while (cursor.moveToNext());
- }
-
- return checks;
- }
-
- public void updateCheckmarks()
- {
- long beginning;
- long today = DateHelper.getStartOfToday();
- long day = DateHelper.millisecondsInOneDay;
-
- Checkmark newestCheckmark = getNewestCheckmark();
- if (newestCheckmark == null)
- {
- Repetition oldestRep = getOldestRep();
- if (oldestRep == null) return;
-
- beginning = oldestRep.timestamp;
- }
- else
- {
- beginning = newestCheckmark.timestamp + day;
- }
-
- if (beginning > today) return;
-
- long beginningExtended = beginning - (long) (freqDen) * day;
- List reps = selectRepsFromTo(beginningExtended, today).execute();
-
- int nDays = (int) ((today - beginning) / day) + 1;
- int nDaysExtended = (int) ((today - beginningExtended) / day) + 1;
-
- int checks[] = new int[nDaysExtended];
-
- // explicit checks
- for (Repetition rep : reps)
- {
- int offset = (int) ((rep.timestamp - beginningExtended) / day);
- checks[nDaysExtended - offset - 1] = 2;
- }
-
- // implicit checks
- for (int i = 0; i < nDays; i++)
- {
- int counter = 0;
-
- for (int j = 0; j < freqDen; j++)
- if (checks[i + j] == 2) counter++;
-
- if (counter >= freqNum) checks[i] = Math.max(checks[i], 1);
- }
-
- ActiveAndroid.beginTransaction();
-
- try
- {
- for (int i = 0; i < nDays; i++)
- {
- Checkmark c = new Checkmark();
- c.habit = this;
- c.timestamp = today - i * day;
- c.value = checks[i];
- c.save();
- }
-
- ActiveAndroid.setTransactionSuccessful();
- } finally
- {
- ActiveAndroid.endTransaction();
- }
- }
-
- public Checkmark getNewestCheckmark()
+ public Uri getUri()
{
- return new Select().from(Checkmark.class)
- .where("habit = ?", getId())
- .orderBy("timestamp desc")
- .limit(1)
- .executeSingle();
- }
-
- public int getRepsCount(int days)
- {
- long timeTo = DateHelper.getStartOfToday();
- long timeFrom = timeTo - DateHelper.millisecondsInOneDay * days;
- return selectRepsFromTo(timeFrom, timeTo).count();
- }
-
- public boolean hasImplicitRepToday()
- {
- long today = DateHelper.getStartOfToday();
- int reps[] = getCheckmarks(today - DateHelper.millisecondsInOneDay, today);
- return (reps[0] > 0);
- }
-
- public Repetition getOldestRep()
- {
- return (Repetition) selectReps().limit(1).executeSingle();
- }
-
- public Repetition getOldestRepNewerThan(long timestamp)
- {
- return selectReps().where("timestamp > ?", timestamp).limit(1).executeSingle();
- }
-
- public void toggleRepetition(long timestamp)
- {
- if (hasRep(timestamp))
- {
- deleteReps(timestamp);
- }
- else
- {
- Repetition rep = new Repetition();
- rep.habit = this;
- rep.timestamp = timestamp;
- rep.save();
- }
-
- deleteScoresNewerThan(timestamp);
- deleteCheckmarksNewerThan(timestamp);
- deleteStreaksNewerThan(timestamp);
+ return Uri.parse(String.format("content://org.isoron.uhabits/habit/%d", getId()));
}
public void archive()
@@ -429,297 +256,4 @@ public class Habit extends Model
{
return archived != 0;
}
-
- public void toggleRepetitionToday()
- {
- toggleRepetition(DateHelper.getStartOfToday());
- }
-
- public Score getNewestScore()
- {
- return new Select().from(Score.class)
- .where("habit = ?", getId())
- .orderBy("timestamp desc")
- .limit(1)
- .executeSingle();
- }
-
- public void deleteScoresNewerThan(long timestamp)
- {
- new Delete().from(Score.class)
- .where("habit = ?", getId())
- .and("timestamp >= ?", timestamp)
- .execute();
- }
-
- public Integer getScore()
- {
- int beginningScore;
- long beginningTime;
-
- long today = DateHelper.getStartOfDay(DateHelper.getLocalTime());
- long day = DateHelper.millisecondsInOneDay;
-
- double freq = ((double) freqNum) / freqDen;
- double multiplier = Math.pow(0.5, 1.0 / (14.0 / freq - 1));
-
- Score newestScore = getNewestScore();
- if (newestScore == null)
- {
- Repetition oldestRep = getOldestRep();
- if (oldestRep == null) return 0;
- beginningTime = oldestRep.timestamp;
- beginningScore = 0;
- }
- else
- {
- beginningTime = newestScore.timestamp + day;
- beginningScore = newestScore.score;
- }
-
- long nDays = (today - beginningTime) / day;
- if (nDays < 0) return newestScore.score;
-
- int reps[] = getCheckmarks(beginningTime, today);
-
- ActiveAndroid.beginTransaction();
- int lastScore = beginningScore;
-
- try
- {
- for (int i = 0; i < reps.length; i++)
- {
- Score s = new Score();
- s.habit = this;
- s.timestamp = beginningTime + day * i;
- s.score = (int) (lastScore * multiplier);
- if (reps[reps.length - i - 1] == 2)
- {
- s.score += 1000000;
- s.score = Math.min(s.score, MAX_SCORE);
- }
- s.save();
-
- lastScore = s.score;
- }
-
- ActiveAndroid.setTransactionSuccessful();
- } finally
- {
- ActiveAndroid.endTransaction();
- }
-
- return lastScore;
- }
-
- public List getScores(long fromTimestamp, long toTimestamp, int divisor, long offset)
- {
- return new Select().from(Score.class)
- .where("habit = ? and timestamp > ? and " +
- "timestamp <= ? and (timestamp - ?) % ? = 0", getId(), fromTimestamp,
- toTimestamp, offset, divisor)
- .execute();
- }
-
- public List getStreaks()
- {
- updateStreaks();
-
- return new Select().from(Streak.class)
- .where("habit = ?", getId())
- .orderBy("end asc")
- .execute();
- }
-
- public Streak getNewestStreak()
- {
- return new Select().from(Streak.class)
- .where("habit = ?", getId())
- .orderBy("end desc")
- .limit(1)
- .executeSingle();
- }
-
- public void updateStreaks()
- {
- long beginning;
- long today = DateHelper.getStartOfToday();
- long day = DateHelper.millisecondsInOneDay;
-
- Streak newestStreak = getNewestStreak();
- if (newestStreak == null)
- {
- Repetition oldestRep = getOldestRep();
- if (oldestRep == null) return;
-
- beginning = oldestRep.timestamp;
- }
- else
- {
- Repetition oldestRep = getOldestRepNewerThan(newestStreak.end);
- if (oldestRep == null) return;
-
- beginning = oldestRep.timestamp;
- }
-
- if (beginning > today) return;
-
- int checks[] = getCheckmarks(beginning, today);
- ArrayList list = new ArrayList<>();
-
- long current = beginning;
- list.add(current);
-
- for (int i = 1; i < checks.length; i++)
- {
- current += day;
- int j = checks.length - i - 1;
-
- if ((checks[j + 1] == 0 && checks[j] > 0)) list.add(current);
- if ((checks[j + 1] > 0 && checks[j] == 0)) list.add(current - day);
- }
-
- if (list.size() % 2 == 1) list.add(current);
-
- ActiveAndroid.beginTransaction();
-
- try
- {
- for (int i = 0; i < list.size(); i += 2)
- {
- Streak streak = new Streak();
- streak.habit = this;
- streak.start = list.get(i);
- streak.end = list.get(i + 1);
- streak.length = (streak.end - streak.start) / day + 1;
- streak.save();
- }
-
- ActiveAndroid.setTransactionSuccessful();
- } finally
- {
- ActiveAndroid.endTransaction();
- }
- }
-
- public static class CreateCommand extends Command
- {
- private Habit model;
- private Long savedId;
-
- public CreateCommand(Habit model)
- {
- this.model = model;
- }
-
- @Override
- public void execute()
- {
- Habit savedHabit = new Habit(model);
- if (savedId == null)
- {
- savedHabit.save();
- savedId = savedHabit.getId();
- }
- else
- {
- savedHabit.save(savedId);
- }
- }
-
- @Override
- public void undo()
- {
- Habit.get(savedId).delete();
- }
-
- @Override
- public Integer getExecuteStringId()
- {
- return R.string.toast_habit_created;
- }
-
- @Override
- public Integer getUndoStringId()
- {
- return R.string.toast_habit_deleted;
- }
-
- }
-
- public class EditCommand extends Command
- {
- private Habit original;
- private Habit modified;
- private long savedId;
- private boolean hasIntervalChanged;
-
- public EditCommand(Habit modified)
- {
- this.savedId = getId();
- this.modified = new Habit(modified);
- this.original = new Habit(Habit.this);
-
- hasIntervalChanged = (this.original.freqDen != this.modified.freqDen ||
- this.original.freqNum != this.modified.freqNum);
- }
-
- public void execute()
- {
- Habit habit = Habit.get(savedId);
- habit.copyAttributes(modified);
- habit.save();
- if (hasIntervalChanged)
- {
- habit.deleteCheckmarksNewerThan(0);
- habit.deleteStreaksNewerThan(0);
- habit.deleteScoresNewerThan(0);
- }
- }
-
- public void undo()
- {
- Habit habit = Habit.get(savedId);
- habit.copyAttributes(original);
- habit.save();
- if (hasIntervalChanged)
- {
- habit.deleteCheckmarksNewerThan(0);
- habit.deleteStreaksNewerThan(0);
- habit.deleteScoresNewerThan(0);
- }
- }
-
- public Integer getExecuteStringId()
- {
- return R.string.toast_habit_changed;
- }
-
- public Integer getUndoStringId()
- {
- return R.string.toast_habit_changed_back;
- }
- }
-
- public class ToggleRepetitionCommand extends Command
- {
- private Long offset;
-
- public ToggleRepetitionCommand(long offset)
- {
- this.offset = offset;
- }
-
- @Override
- public void execute()
- {
- toggleRepetition(offset);
- }
-
- @Override
- public void undo()
- {
- execute();
- }
- }
}
diff --git a/app/src/main/java/org/isoron/uhabits/models/RepetitionList.java b/app/src/main/java/org/isoron/uhabits/models/RepetitionList.java
new file mode 100644
index 000000000..6828101ab
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/models/RepetitionList.java
@@ -0,0 +1,96 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.models;
+
+import com.activeandroid.query.Delete;
+import com.activeandroid.query.From;
+import com.activeandroid.query.Select;
+
+import org.isoron.helpers.DateHelper;
+
+public class RepetitionList
+{
+
+ private Habit habit;
+
+ public RepetitionList(Habit habit)
+ {
+ this.habit = habit;
+ }
+
+ protected From select()
+ {
+ return new Select().from(Repetition.class)
+ .where("habit = ?", habit.getId())
+ .orderBy("timestamp");
+ }
+
+ protected From selectFromTo(long timeFrom, long timeTo)
+ {
+ return select().and("timestamp >= ?", timeFrom).and("timestamp <= ?", timeTo);
+ }
+
+ public boolean contains(long timestamp)
+ {
+ int count = select().where("timestamp = ?", timestamp).count();
+ return (count > 0);
+ }
+
+ public void delete(long timestamp)
+ {
+ new Delete().from(Repetition.class)
+ .where("habit = ?", habit.getId())
+ .and("timestamp = ?", timestamp)
+ .execute();
+ }
+
+ public Repetition getOldestNewerThan(long timestamp)
+ {
+ return select().where("timestamp > ?", timestamp).limit(1).executeSingle();
+ }
+
+ public void toggle(long timestamp)
+ {
+ if (contains(timestamp))
+ {
+ delete(timestamp);
+ }
+ else
+ {
+ Repetition rep = new Repetition();
+ rep.habit = habit;
+ rep.timestamp = timestamp;
+ rep.save();
+ }
+
+ habit.scores.deleteNewerThan(timestamp);
+ habit.checkmarks.deleteNewerThan(timestamp);
+ habit.streaks.deleteNewerThan(timestamp);
+ }
+
+ public Repetition getOldest()
+ {
+ return (Repetition) select().limit(1).executeSingle();
+ }
+
+ public boolean hasImplicitRepToday()
+ {
+ long today = DateHelper.getStartOfToday();
+ int reps[] = habit.checkmarks.getValues(today - DateHelper.millisecondsInOneDay, today);
+ return (reps[0] > 0);
+ }
+}
diff --git a/app/src/main/java/org/isoron/uhabits/models/Score.java b/app/src/main/java/org/isoron/uhabits/models/Score.java
index 33f1723cc..44af97588 100644
--- a/app/src/main/java/org/isoron/uhabits/models/Score.java
+++ b/app/src/main/java/org/isoron/uhabits/models/Score.java
@@ -23,6 +23,10 @@ import com.activeandroid.annotation.Table;
@Table(name = "Score")
public class Score extends Model
{
+ public static final int HALF_STAR_CUTOFF = 9629750;
+ public static final int FULL_STAR_CUTOFF = 15407600;
+ public static final int MAX_SCORE = 19259500;
+
@Column(name = "habit")
public Habit habit;
diff --git a/app/src/main/java/org/isoron/uhabits/models/ScoreList.java b/app/src/main/java/org/isoron/uhabits/models/ScoreList.java
new file mode 100644
index 000000000..8312a15e2
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/models/ScoreList.java
@@ -0,0 +1,163 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.models;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
+import com.activeandroid.ActiveAndroid;
+import com.activeandroid.Cache;
+import com.activeandroid.query.Delete;
+import com.activeandroid.query.Select;
+
+import org.isoron.helpers.DateHelper;
+
+public class ScoreList
+{
+ private Habit habit;
+
+ public ScoreList(Habit habit)
+ {
+ this.habit = habit;
+ }
+
+ public int getCurrentStarStatus()
+ {
+ int score = getNewestValue();
+
+ if(score >= Score.FULL_STAR_CUTOFF) return 2;
+ else if(score >= Score.HALF_STAR_CUTOFF) return 1;
+ else return 0;
+ }
+
+ public Score getNewest()
+ {
+ return new Select().from(Score.class)
+ .where("habit = ?", habit.getId())
+ .orderBy("timestamp desc")
+ .limit(1)
+ .executeSingle();
+ }
+
+ public void deleteNewerThan(long timestamp)
+ {
+ new Delete().from(Score.class)
+ .where("habit = ?", habit.getId())
+ .and("timestamp >= ?", timestamp)
+ .execute();
+ }
+
+ public Integer getNewestValue()
+ {
+ int beginningScore;
+ long beginningTime;
+
+ long today = DateHelper.getStartOfDay(DateHelper.getLocalTime());
+ long day = DateHelper.millisecondsInOneDay;
+
+ double freq = ((double) habit.freqNum) / habit.freqDen;
+ double multiplier = Math.pow(0.5, 1.0 / (14.0 / freq - 1));
+
+ Score newestScore = getNewest();
+ if (newestScore == null)
+ {
+ Repetition oldestRep = habit.repetitions.getOldest();
+ if (oldestRep == null) return 0;
+ beginningTime = oldestRep.timestamp;
+ beginningScore = 0;
+ }
+ else
+ {
+ beginningTime = newestScore.timestamp + day;
+ beginningScore = newestScore.score;
+ }
+
+ long nDays = (today - beginningTime) / day;
+ if (nDays < 0) return newestScore.score;
+
+ int reps[] = habit.checkmarks.getValues(beginningTime, today);
+
+ ActiveAndroid.beginTransaction();
+ int lastScore = beginningScore;
+
+ try
+ {
+ for (int i = 0; i < reps.length; i++)
+ {
+ Score s = new Score();
+ s.habit = habit;
+ s.timestamp = beginningTime + day * i;
+ s.score = (int) (lastScore * multiplier);
+ if (reps[reps.length - i - 1] == 2)
+ {
+ s.score += 1000000;
+ s.score = Math.min(s.score, Score.MAX_SCORE);
+ }
+ s.save();
+
+ lastScore = s.score;
+ }
+
+ ActiveAndroid.setTransactionSuccessful();
+ } finally
+ {
+ ActiveAndroid.endTransaction();
+ }
+
+ return lastScore;
+ }
+
+ public int[] getAllValues(Long fromTimestamp, Long toTimestamp, Integer divisor)
+ {
+ Long offset = toTimestamp - (divisor - 1) * DateHelper.millisecondsInOneDay;
+
+ String query = "select ((timestamp - ?) / ?) as time, avg(score) from Score " +
+ "where habit = ? and timestamp > ? and timestamp <= ? " +
+ "group by time order by time desc";
+
+ String params[] = { offset.toString(), divisor.toString(), habit.getId().toString(),
+ fromTimestamp.toString(), toTimestamp.toString()};
+
+ SQLiteDatabase db = Cache.openDatabase();
+ Cursor cursor = db.rawQuery(query, params);
+
+ if(!cursor.moveToFirst()) return new int[0];
+
+ int k = 0;
+ int[] scores = new int[cursor.getCount()];
+
+ do
+ {
+ scores[k++] = (int) cursor.getLong(1);
+ }
+ while (cursor.moveToNext());
+
+ cursor.close();
+ return scores;
+
+ }
+
+ public int[] getAllValues(int divisor)
+ {
+ Repetition oldestRep = habit.repetitions.getOldest();
+ if(oldestRep == null) return new int[0];
+
+ long fromTimestamp = oldestRep.timestamp;
+ long toTimestamp = DateHelper.getStartOfToday();
+ return getAllValues(fromTimestamp, toTimestamp, divisor);
+ }
+}
diff --git a/app/src/main/java/org/isoron/uhabits/models/StreakList.java b/app/src/main/java/org/isoron/uhabits/models/StreakList.java
new file mode 100644
index 000000000..d83a29d85
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/models/StreakList.java
@@ -0,0 +1,126 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.models;
+
+import com.activeandroid.ActiveAndroid;
+import com.activeandroid.query.Delete;
+import com.activeandroid.query.Select;
+
+import org.isoron.helpers.DateHelper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class StreakList
+{
+ private Habit habit;
+
+ public StreakList(Habit habit)
+ {
+ this.habit = habit;
+ }
+
+ public List getAll()
+ {
+ rebuild();
+
+ return new Select().from(Streak.class)
+ .where("habit = ?", habit.getId())
+ .orderBy("end asc")
+ .execute();
+ }
+
+ public Streak getNewest()
+ {
+ return new Select().from(Streak.class)
+ .where("habit = ?", habit.getId())
+ .orderBy("end desc")
+ .limit(1)
+ .executeSingle();
+ }
+
+ public void rebuild()
+ {
+ long beginning;
+ long today = DateHelper.getStartOfToday();
+ long day = DateHelper.millisecondsInOneDay;
+
+ Streak newestStreak = getNewest();
+ if (newestStreak != null)
+ {
+ beginning = newestStreak.start;
+ }
+ else
+ {
+ Repetition oldestRep = habit.repetitions.getOldest();
+ if (oldestRep == null) return;
+
+ beginning = oldestRep.timestamp;
+ }
+
+ if (beginning > today) return;
+
+ int checks[] = habit.checkmarks.getValues(beginning, today);
+ ArrayList list = new ArrayList<>();
+
+ long current = beginning;
+ list.add(current);
+
+ for (int i = 1; i < checks.length; i++)
+ {
+ current += day;
+ int j = checks.length - i - 1;
+
+ if ((checks[j + 1] == 0 && checks[j] > 0)) list.add(current);
+ if ((checks[j + 1] > 0 && checks[j] == 0)) list.add(current - day);
+ }
+
+ if (list.size() % 2 == 1) list.add(current);
+
+ ActiveAndroid.beginTransaction();
+
+ if(newestStreak != null) newestStreak.delete();
+
+ try
+ {
+ for (int i = 0; i < list.size(); i += 2)
+ {
+ Streak streak = new Streak();
+ streak.habit = habit;
+ streak.start = list.get(i);
+ streak.end = list.get(i + 1);
+ streak.length = (streak.end - streak.start) / day + 1;
+ streak.save();
+ }
+
+ ActiveAndroid.setTransactionSuccessful();
+ }
+ finally
+ {
+ ActiveAndroid.endTransaction();
+ }
+ }
+
+
+ public void deleteNewerThan(long timestamp)
+ {
+ new Delete().from(Streak.class)
+ .where("habit = ?", habit.getId())
+ .and("end >= ?", timestamp - DateHelper.millisecondsInOneDay)
+ .execute();
+ }
+}
diff --git a/app/src/main/java/org/isoron/uhabits/views/CheckmarkView.java b/app/src/main/java/org/isoron/uhabits/views/CheckmarkView.java
new file mode 100644
index 000000000..223217aad
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/views/CheckmarkView.java
@@ -0,0 +1,203 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.views;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.Typeface;
+import android.os.Build;
+import android.text.Layout;
+import android.text.StaticLayout;
+import android.text.TextPaint;
+import android.util.AttributeSet;
+import android.view.View;
+
+import org.isoron.helpers.ColorHelper;
+import org.isoron.uhabits.R;
+import org.isoron.uhabits.models.Habit;
+
+public class CheckmarkView extends View
+{
+ private Paint pCard;
+ private Paint pIcon;
+
+ private int primaryColor;
+ private int backgroundColor;
+ private int timesColor;
+ private int darkGrey;
+
+ private int width;
+ private int height;
+ private int leftMargin;
+ private int topMargin;
+ private int padding;
+ private String label;
+
+ private String fa_check;
+ private String fa_times;
+ private String fa_full_star;
+ private String fa_half_star;
+ private String fa_empty_star;
+
+ private int check_status;
+ private int star_status;
+
+ private Rect rect;
+ private TextPaint textPaint;
+ private StaticLayout labelLayout;
+
+ public CheckmarkView(Context context)
+ {
+ super(context);
+ init(context);
+ }
+
+ public CheckmarkView(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ init(context);
+ }
+
+ private void init(Context context)
+ {
+ Typeface fontawesome =
+ Typeface.createFromAsset(context.getAssets(), "fontawesome-webfont.ttf");
+
+ pCard = new Paint();
+ pCard.setAntiAlias(true);
+
+ pIcon = new Paint();
+ pIcon.setAntiAlias(true);
+ pIcon.setTypeface(fontawesome);
+ pIcon.setTextAlign(Paint.Align.CENTER);
+
+ textPaint = new TextPaint();
+ textPaint.setColor(Color.WHITE);
+ textPaint.setAntiAlias(true);
+
+ fa_check = context.getString(R.string.fa_check);
+ fa_times = context.getString(R.string.fa_times);
+ fa_empty_star = context.getString(R.string.fa_star_o);
+ fa_half_star = context.getString(R.string.fa_star_half_o);
+ fa_full_star = context.getString(R.string.fa_star);
+
+ primaryColor = ColorHelper.palette[10];
+ backgroundColor = Color.argb(255, 255, 255, 255);
+ timesColor = Color.argb(128, 255, 255, 255);
+ darkGrey = Color.argb(64, 0, 0, 0);
+
+ rect = new Rect();
+ check_status = 2;
+ star_status = 0;
+ label = "Wake up early";
+ }
+
+ public void setHabit(Habit habit)
+ {
+ this.check_status = habit.checkmarks.getCurrentValue();
+ this.star_status = habit.scores.getCurrentStarStatus();
+ this.primaryColor = Color.argb(230, Color.red(habit.color), Color.green(habit.color), Color.blue(habit.color));
+ this.label = habit.name;
+ updateLabel();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas)
+ {
+ super.onDraw(canvas);
+
+ drawBackground(canvas);
+ drawCheckmark(canvas);
+ drawLabel(canvas);
+ }
+
+ private void drawBackground(Canvas canvas)
+ {
+ int color = (check_status == 2 ? primaryColor : darkGrey);
+
+ pCard.setColor(color);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
+ canvas.drawRoundRect(leftMargin, topMargin, width - leftMargin, height - topMargin, padding,
+ padding, pCard);
+ else
+ canvas.drawRect(leftMargin, topMargin, width - leftMargin, height - topMargin, pCard);
+ }
+
+ private void drawCheckmark(Canvas canvas)
+ {
+ String text = (check_status == 0 ? fa_times : fa_check);
+ int color = (check_status == 2 ? Color.WHITE : timesColor);
+
+ pIcon.setColor(color);
+ pIcon.setTextSize(width * 0.5f);
+ pIcon.getTextBounds(text, 0, 1, rect);
+
+// canvas.drawLine(0, 0.67f * height, width, 0.67f * height, pIcon);
+
+ int y = (int) ((0.67f * height - rect.bottom - rect.top) / 2);
+ canvas.drawText(text, width / 2, y, pIcon);
+ }
+
+ private void drawLabel(Canvas canvas)
+ {
+ canvas.save();
+ float y;
+ int nLines = labelLayout.getLineCount();
+
+ if(nLines == 1)
+ y = height * 0.8f - padding;
+ else
+ y = height * 0.7f - padding;
+
+ canvas.translate(leftMargin + padding, y);
+
+ labelLayout.draw(canvas);
+ canvas.restore();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
+ {
+ int width = MeasureSpec.getSize(widthMeasureSpec);
+ setMeasuredDimension(width, (int) (width * 1.25));
+ }
+
+ @Override
+ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
+ {
+ this.width = getMeasuredWidth();
+ this.height = getMeasuredHeight();
+
+ leftMargin = (int) (width * 0.015);
+ topMargin = (int) (height * 0.015);
+ padding = 8 * leftMargin;
+ textPaint.setTextSize(0.15f * width);
+
+ updateLabel();
+ }
+
+ private void updateLabel()
+ {
+ textPaint.setColor(Color.WHITE);
+ labelLayout = new StaticLayout(label, textPaint, width - 2 * leftMargin - 2 * padding,
+ Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
+ }
+
+}
diff --git a/app/src/main/java/org/isoron/uhabits/views/HabitHistoryView.java b/app/src/main/java/org/isoron/uhabits/views/HabitHistoryView.java
index 3d0a25396..d99ba765b 100644
--- a/app/src/main/java/org/isoron/uhabits/views/HabitHistoryView.java
+++ b/app/src/main/java/org/isoron/uhabits/views/HabitHistoryView.java
@@ -22,6 +22,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
+import android.util.AttributeSet;
import org.isoron.helpers.ColorHelper;
import org.isoron.helpers.DateHelper;
@@ -30,10 +31,11 @@ import org.isoron.uhabits.models.Habit;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.Random;
public class HabitHistoryView extends ScrollableDataView
{
-
private Habit habit;
private int[] checkmarks;
private Paint pSquareBg, pSquareFg, pTextHeader;
@@ -42,6 +44,11 @@ public class HabitHistoryView extends ScrollableDataView
private float squareTextOffset;
private float headerTextOffset;
+ private int columnWidth;
+ private int columnHeight;
+ private int nColumns;
+ private int baseSize;
+
private String wdays[];
private SimpleDateFormat dfMonth;
private SimpleDateFormat dfYear;
@@ -50,25 +57,43 @@ public class HabitHistoryView extends ScrollableDataView
private int nDays;
private int todayWeekday;
private int colors[];
+ private Rect baseLocation;
+ private int primaryColor;
+
+ private boolean isBackgroundTransparent;
+ private int textColor;
+
+ public HabitHistoryView(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ this.primaryColor = ColorHelper.palette[7];
+ init();
+ }
- public HabitHistoryView(Context context, Habit habit, int baseSize)
+ public void setHabit(Habit habit)
{
- super(context);
this.habit = habit;
+ createColors();
+ fetchData();
+ postInvalidate();
+ }
- setDimensions(baseSize);
+ private void init()
+ {
createPaints();
createColors();
wdays = DateHelper.getShortDayNames();
- dfMonth = new SimpleDateFormat("MMM");
- dfYear = new SimpleDateFormat("yyyy");
+ dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
+ dfYear = new SimpleDateFormat("yyyy", Locale.getDefault());
+
+ baseLocation = new Rect();
}
private void updateDate()
{
baseDate = new GregorianCalendar();
- baseDate.add(Calendar.DAY_OF_YEAR, -(dataOffset - 1) * 7);
+ baseDate.add(Calendar.DAY_OF_YEAR, -(getDataOffset() - 1) * 7);
nDays = (nColumns - 1) * 7;
todayWeekday = new GregorianCalendar().get(Calendar.DAY_OF_WEEK) % 7;
@@ -78,71 +103,114 @@ public class HabitHistoryView extends ScrollableDataView
}
@Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh)
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
- super.onSizeChanged(w, h, oldw, oldh);
- updateDate();
+ int width = MeasureSpec.getSize(widthMeasureSpec);
+ int height = MeasureSpec.getSize(heightMeasureSpec);
+ setMeasuredDimension(width, height);
}
- private void createColors()
+ @Override
+ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
{
- int primaryColor = habit.color;
- int primaryColorBright = ColorHelper.mixColors(primaryColor, Color.WHITE, 0.5f);
- int grey = Color.rgb(230, 230, 230);
+ if(height < 8) height = 200;
- colors = new int[3];
- colors[0] = grey;
- colors[1] = primaryColorBright;
- colors[2] = primaryColor;
- }
+ baseSize = height / 8;
+ setScrollerBucketSize(baseSize);
- private void setDimensions(int baseSize)
- {
columnWidth = baseSize;
columnHeight = 8 * baseSize;
- squareSpacing = 2;
+ nColumns = width / baseSize;
+
+ squareSpacing = (int) Math.floor(baseSize / 15.0);
+ pSquareFg.setTextSize(baseSize * 0.5f);
+ pTextHeader.setTextSize(baseSize * 0.5f);
+ squareTextOffset = pSquareFg.getFontSpacing() * 0.4f;
+ headerTextOffset = pTextHeader.getFontSpacing() * 0.3f;
+
+ updateDate();
}
- private void createPaints()
+ private void createColors()
+ {
+ if(habit != null)
+ this.primaryColor = habit.color;
+
+ if(isBackgroundTransparent)
+ primaryColor = ColorHelper.setMinValue(primaryColor, 0.75f);
+
+ int red = Color.red(primaryColor);
+ int green = Color.green(primaryColor);
+ int blue = Color.blue(primaryColor);
+
+ if(isBackgroundTransparent)
+ {
+ colors = new int[3];
+ colors[0] = Color.argb(16, 255, 255, 255);
+ colors[1] = Color.argb(128, red, green, blue);
+ colors[2] = primaryColor;
+ textColor = Color.rgb(255, 255, 255);
+ }
+ else
+ {
+ colors = new int[3];
+ colors[0] = Color.argb(25, 0, 0, 0);
+ colors[1] = Color.argb(127, red, green, blue);
+ colors[2] = primaryColor;
+ textColor = Color.argb(64, 0, 0, 0);
+ }
+ }
+
+ protected void createPaints()
{
pTextHeader = new Paint();
- pTextHeader.setColor(Color.LTGRAY);
pTextHeader.setTextAlign(Align.LEFT);
- pTextHeader.setTextSize(columnWidth * 0.5f);
pTextHeader.setAntiAlias(true);
pSquareBg = new Paint();
- pSquareBg.setColor(habit.color);
+ pSquareBg.setColor(primaryColor);
pSquareFg = new Paint();
pSquareFg.setColor(Color.WHITE);
pSquareFg.setAntiAlias(true);
- pSquareFg.setTextSize(columnWidth * 0.5f);
pSquareFg.setTextAlign(Align.CENTER);
-
- squareTextOffset = pSquareFg.getFontSpacing() * 0.4f;
- headerTextOffset = pTextHeader.getFontSpacing() * 0.3f;
}
protected void fetchData()
{
- Calendar currentDate = new GregorianCalendar();
- currentDate.add(Calendar.DAY_OF_YEAR, -dataOffset * 7);
- int dayOfWeek = currentDate.get(Calendar.DAY_OF_WEEK) % 7;
+ if(isInEditMode())
+ generateRandomData();
+ else
+ {
+ if(habit == null)
+ {
+ checkmarks = new int[0];
+ return;
+ }
- long dateTo = DateHelper.getStartOfToday();
- for (int i = 0; i < 7 - dayOfWeek; i++)
- dateTo += DateHelper.millisecondsInOneDay;
+ checkmarks = habit.checkmarks.getAllValues();
+ }
- for (int i = 0; i < dataOffset * 7; i++)
- dateTo -= DateHelper.millisecondsInOneDay;
+ updateDate();
+ }
- long dateFrom = dateTo;
- for (int i = 0; i < (nColumns - 1) * 7; i++)
- dateFrom -= DateHelper.millisecondsInOneDay;
+ private void generateRandomData()
+ {
+ Random random = new Random();
+ checkmarks = new int[100];
- checkmarks = habit.getCheckmarks(dateFrom, dateTo);
- updateDate();
+ for(int i = 0; i < 100; i++)
+ if(random.nextFloat() < 0.3) checkmarks[i] = 2;
+
+ for(int i = 0; i < 100 - 7; i++)
+ {
+ int count = 0;
+ for (int j = 0; j < 7; j++)
+ if(checkmarks[i + j] != 0)
+ count++;
+
+ if(count >= 3) checkmarks[i] = Math.max(checkmarks[i], 1);
+ }
}
private String previousMonth;
@@ -154,21 +222,24 @@ public class HabitHistoryView extends ScrollableDataView
{
super.onDraw(canvas);
- Rect location = new Rect(0, 0, columnWidth - squareSpacing, columnWidth - squareSpacing);
+ baseLocation.set(0, 0, columnWidth - squareSpacing, columnWidth - squareSpacing);
previousMonth = "";
previousYear = "";
justPrintedYear = false;
+ pTextHeader.setColor(textColor);
+
+ updateDate();
GregorianCalendar currentDate = (GregorianCalendar) baseDate.clone();
for (int column = 0; column < nColumns - 1; column++)
{
- drawColumn(canvas, location, currentDate, column);
- location.offset(columnWidth, -columnHeight);
+ drawColumn(canvas, baseLocation, currentDate, column);
+ baseLocation.offset(columnWidth, - columnHeight);
}
- drawAxis(canvas, location);
+ drawAxis(canvas, baseLocation);
}
private void drawColumn(Canvas canvas, Rect location, GregorianCalendar date, int column)
@@ -178,9 +249,9 @@ public class HabitHistoryView extends ScrollableDataView
for (int j = 0; j < 7; j++)
{
- if (!(column == nColumns - 2 && dataOffset == 0 && j > todayWeekday))
+ if (!(column == nColumns - 2 && getDataOffset() == 0 && j > todayWeekday))
{
- int checkmarkOffset = nDays - 7 * column - j;
+ int checkmarkOffset = getDataOffset() * 7 + nDays - 7 * (column + 1) + todayWeekday - j;
drawSquare(canvas, location, date, checkmarkOffset);
}
@@ -210,6 +281,8 @@ public class HabitHistoryView extends ScrollableDataView
}
}
+ private boolean justSkippedColumn = false;
+
private void drawColumnHeader(Canvas canvas, Rect location, GregorianCalendar date)
{
String month = dfMonth.format(date.getTime());
@@ -218,22 +291,39 @@ public class HabitHistoryView extends ScrollableDataView
if (!month.equals(previousMonth))
{
int offset = 0;
- if (justPrintedYear) offset += columnWidth;
+ if (justPrintedYear)
+ {
+ offset += columnWidth;
+ justSkippedColumn = true;
+ }
canvas.drawText(month, location.left + offset, location.bottom - headerTextOffset,
pTextHeader);
+
previousMonth = month;
justPrintedYear = false;
}
else if (!year.equals(previousYear))
{
- canvas.drawText(year, location.left, location.bottom - headerTextOffset, pTextHeader);
- previousYear = year;
- justPrintedYear = true;
+ if(!justSkippedColumn)
+ {
+ canvas.drawText(year, location.left, location.bottom - headerTextOffset, pTextHeader);
+ previousYear = year;
+ justPrintedYear = true;
+ }
+
+ justSkippedColumn = false;
}
else
{
+ justSkippedColumn = false;
justPrintedYear = false;
}
}
+
+ public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
+ {
+ this.isBackgroundTransparent = isBackgroundTransparent;
+ createColors();
+ }
}
diff --git a/app/src/main/java/org/isoron/uhabits/views/HabitScoreView.java b/app/src/main/java/org/isoron/uhabits/views/HabitScoreView.java
index 6b4294f80..68855e50a 100644
--- a/app/src/main/java/org/isoron/uhabits/views/HabitScoreView.java
+++ b/app/src/main/java/org/isoron/uhabits/views/HabitScoreView.java
@@ -20,7 +20,10 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
+import android.util.AttributeSet;
import org.isoron.helpers.ColorHelper;
import org.isoron.helpers.DateHelper;
@@ -28,71 +31,163 @@ import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.Score;
import java.text.SimpleDateFormat;
-import java.util.List;
+import java.util.Locale;
+import java.util.Random;
public class HabitScoreView extends ScrollableDataView
{
public static final int BUCKET_SIZE = 7;
+ public static final PorterDuffXfermode XFERMODE_CLEAR =
+ new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
+ public static final PorterDuffXfermode XFERMODE_SRC =
+ new PorterDuffXfermode(PorterDuff.Mode.SRC);
- private final Paint pGrid;
- private final float em;
+ private Paint pGrid;
+ private float em;
private Habit habit;
+ private SimpleDateFormat dfMonth;
+ private SimpleDateFormat dfDay;
private Paint pText, pGraph;
+ private RectF rect, prevRect;
+ private int baseSize;
+ private int paddingTop;
+ private int columnWidth;
+ private int columnHeight;
+ private int nColumns;
+
+ private int textColor;
+ private int dimmedTextColor;
private int[] colors;
- private List scores;
+ private int[] scores;
+ private int primaryColor;
+ private boolean isBackgroundTransparent;
+
+ public HabitScoreView(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ this.primaryColor = ColorHelper.palette[7];
+ init();
+ }
- public HabitScoreView(Context context, Habit habit, int columnWidth)
+ public void setHabit(Habit habit)
{
- super(context);
this.habit = habit;
+ createColors();
+ fetchData();
+ postInvalidate();
+ }
+
+ private void init()
+ {
+ createPaints();
+ createColors();
+
+ dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
+ dfDay = new SimpleDateFormat("d", Locale.getDefault());
+ rect = new RectF();
+ prevRect = new RectF();
+ }
+
+ private void createColors()
+ {
+ if(habit != null)
+ this.primaryColor = habit.color;
+
+ if (isBackgroundTransparent)
+ {
+ primaryColor = ColorHelper.setSaturation(primaryColor, 0.75f);
+ primaryColor = ColorHelper.setValue(primaryColor, 1.0f);
+
+ textColor = Color.argb(192, 255, 255, 255);
+ dimmedTextColor = Color.argb(128, 255, 255, 255);
+ }
+ else
+ {
+ textColor = Color.argb(64, 0, 0, 0);
+ dimmedTextColor = Color.argb(16, 0, 0, 0);
+ }
+
+ colors = new int[4];
+
+ colors[0] = Color.rgb(230, 230, 230);
+ colors[3] = primaryColor;
+ colors[1] = ColorHelper.mixColors(colors[0], colors[3], 0.66f);
+ colors[2] = ColorHelper.mixColors(colors[0], colors[3], 0.33f);
+ }
+
+ protected void createPaints()
+ {
pText = new Paint();
- pText.setColor(Color.LTGRAY);
- pText.setTextAlign(Paint.Align.LEFT);
- pText.setTextSize(columnWidth * 0.5f);
pText.setAntiAlias(true);
pGraph = new Paint();
pGraph.setTextAlign(Paint.Align.CENTER);
- pGraph.setTextSize(columnWidth * 0.5f);
pGraph.setAntiAlias(true);
- pGraph.setStrokeWidth(columnWidth * 0.1f);
pGrid = new Paint();
- pGrid.setColor(Color.LTGRAY);
pGrid.setAntiAlias(true);
- pGrid.setStrokeWidth(columnWidth * 0.05f);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
+ {
+ int width = MeasureSpec.getSize(widthMeasureSpec);
+ int height = MeasureSpec.getSize(heightMeasureSpec);
+ setMeasuredDimension(width, height);
+ }
- this.columnWidth = columnWidth;
- columnHeight = 8 * columnWidth;
- headerHeight = columnWidth;
- footerHeight = columnWidth;
+ @Override
+ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
+ {
+ if(height < 9) height = 200;
- em = pText.getFontSpacing();
+ baseSize = height / 9;
+ setScrollerBucketSize(baseSize);
- colors = new int[4];
+ columnWidth = baseSize;
+ columnHeight = 8 * baseSize;
+ nColumns = width / baseSize;
+ paddingTop = (int) (baseSize * 0.15f);
- colors[0] = Color.rgb(230, 230, 230);
- colors[3] = habit.color;
- colors[1] = ColorHelper.mixColors(colors[0], colors[3], 0.66f);
- colors[2] = ColorHelper.mixColors(colors[0], colors[3], 0.33f);
+ pText.setTextSize(baseSize * 0.5f);
+ pGraph.setTextSize(baseSize * 0.5f);
+ pGraph.setStrokeWidth(baseSize * 0.1f);
+ pGrid.setStrokeWidth(baseSize * 0.05f);
+ em = pText.getFontSpacing();
}
protected void fetchData()
{
+ if(isInEditMode())
+ generateRandomData();
+ else
+ {
+ if (habit == null)
+ {
+ scores = new int[0];
+ return;
+ }
- long toTimestamp = DateHelper.getStartOfToday();
- for (int i = 0; i < dataOffset * BUCKET_SIZE; i++)
- toTimestamp -= DateHelper.millisecondsInOneDay;
+ scores = habit.scores.getAllValues(BUCKET_SIZE * DateHelper.millisecondsInOneDay);
+ }
+
+ }
- long fromTimestamp = toTimestamp;
- for (int i = 0; i < nColumns * BUCKET_SIZE; i++)
- fromTimestamp -= DateHelper.millisecondsInOneDay;
+ private void generateRandomData()
+ {
+ Random random = new Random();
+ scores = new int[100];
+ scores[0] = Score.MAX_SCORE / 2;
- scores = habit.getScores(fromTimestamp, toTimestamp,
- BUCKET_SIZE * DateHelper.millisecondsInOneDay, toTimestamp);
+ for(int i = 1; i < 100; i++)
+ {
+ int step = Score.MAX_SCORE / 10;
+ scores[i] = scores[i - 1] + random.nextInt(step * 2) - step;
+ scores[i] = Math.max(0, Math.min(Score.MAX_SCORE, scores[i]));
+ }
}
@Override
@@ -102,52 +197,58 @@ public class HabitScoreView extends ScrollableDataView
float lineHeight = pText.getFontSpacing();
- RectF rGrid = new RectF(0, 0, nColumns * columnWidth, columnHeight);
- rGrid.offset(0, headerHeight);
- drawGrid(canvas, rGrid);
+ rect.set(0, 0, nColumns * columnWidth, columnHeight);
+ rect.offset(0, paddingTop);
- SimpleDateFormat dfMonth = new SimpleDateFormat("MMM");
- SimpleDateFormat dfDay = new SimpleDateFormat("d");
+ drawGrid(canvas, rect);
String previousMonth = "";
- pGraph.setColor(habit.color);
- RectF prevR = null;
+ pText.setTextAlign(Paint.Align.CENTER);
+ pText.setColor(textColor);
+ pGraph.setColor(primaryColor);
+ prevRect.setEmpty();
+
+ long currentDate = DateHelper.getStartOfToday();
+
+ for(int k = 0; k < nColumns + getDataOffset() - 1; k++)
+ currentDate -= 7 * DateHelper.millisecondsInOneDay;
- for (int offset = nColumns - scores.size(); offset < nColumns; offset++)
+ for (int k = 0; k < nColumns; k++)
{
- Score score = scores.get(offset - nColumns + scores.size());
- String month = dfMonth.format(score.timestamp);
- String day = dfDay.format(score.timestamp);
+ String month = dfMonth.format(currentDate);
+ String day = dfDay.format(currentDate);
- long s = score.score;
- double sRelative = ((double) s) / Habit.MAX_SCORE;
+ int score = 0;
+ int offset = nColumns - k - 1 + getDataOffset();
+ if(offset < scores.length) score = scores[offset];
+ double sRelative = ((double) score) / Score.MAX_SCORE;
int height = (int) (columnHeight * sRelative);
- RectF r = new RectF(0, 0, columnWidth, columnWidth);
- r.offset(offset * columnWidth,
- headerHeight + columnHeight - height - columnWidth / 2);
+ rect.set(0, 0, baseSize, baseSize);
+ rect.offset(k * columnWidth, paddingTop + columnHeight - height - columnWidth / 2);
- if (prevR != null)
+ if (!prevRect.isEmpty())
{
- drawLine(canvas, prevR, r);
- drawMarker(canvas, prevR);
+ drawLine(canvas, prevRect, rect);
+ drawMarker(canvas, prevRect);
}
- if (offset == nColumns - 1) drawMarker(canvas, r);
+ if (k == nColumns - 1) drawMarker(canvas, rect);
- prevR = r;
+ prevRect.set(rect);
+
+ rect.set(0, 0, columnWidth, columnHeight);
+ rect.offset(k * columnWidth, paddingTop);
- r = new RectF(0, 0, columnWidth, columnHeight);
- r.offset(offset * columnWidth, headerHeight);
if (!month.equals(previousMonth))
- canvas.drawText(month, r.centerX(), r.bottom + lineHeight * 1.2f, pText);
+ canvas.drawText(month, rect.centerX(), rect.bottom + lineHeight * 1.2f, pText);
else
- canvas.drawText(day, r.centerX(), r.bottom + lineHeight * 1.2f, pText);
+ canvas.drawText(day, rect.centerX(), rect.bottom + lineHeight * 1.2f, pText);
previousMonth = month;
-
+ currentDate += 7 * DateHelper.millisecondsInOneDay;
}
}
@@ -156,7 +257,10 @@ public class HabitScoreView extends ScrollableDataView
int nRows = 5;
float rowHeight = rGrid.height() / nRows;
- pGrid.setColor(Color.rgb(240, 240, 240));
+ pText.setTextAlign(Paint.Align.LEFT);
+ pText.setColor(textColor);
+ pGrid.setColor(dimmedTextColor);
+
for (int i = 0; i < nRows; i++)
{
canvas.drawText(String.format("%d%%", (100 - i * 100 / nRows)), rGrid.left + 0.5f * em,
@@ -170,7 +274,7 @@ public class HabitScoreView extends ScrollableDataView
private void drawLine(Canvas canvas, RectF rectFrom, RectF rectTo)
{
- pGraph.setColor(habit.color);
+ pGraph.setColor(primaryColor);
canvas.drawLine(rectFrom.centerX(), rectFrom.centerY(), rectTo.centerX(), rectTo.centerY(),
pGraph);
}
@@ -178,15 +282,32 @@ public class HabitScoreView extends ScrollableDataView
private void drawMarker(Canvas canvas, RectF rect)
{
rect.inset(columnWidth * 0.15f, columnWidth * 0.15f);
- pGraph.setColor(Color.WHITE);
+ setModeOrColor(pGraph, XFERMODE_CLEAR, Color.WHITE);
canvas.drawOval(rect, pGraph);
rect.inset(columnWidth * 0.1f, columnWidth * 0.1f);
- pGraph.setColor(habit.color);
+ setModeOrColor(pGraph, XFERMODE_SRC, primaryColor);
canvas.drawOval(rect, pGraph);
rect.inset(columnWidth * 0.1f, columnWidth * 0.1f);
- pGraph.setColor(Color.WHITE);
+ setModeOrColor(pGraph, XFERMODE_CLEAR, Color.WHITE);
canvas.drawOval(rect, pGraph);
+
+ if(isBackgroundTransparent)
+ pGraph.setXfermode(XFERMODE_SRC);
+ }
+
+ public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
+ {
+ this.isBackgroundTransparent = isBackgroundTransparent;
+ createColors();
+ }
+
+ private void setModeOrColor(Paint p, PorterDuffXfermode mode, int color)
+ {
+ if(isBackgroundTransparent)
+ p.setXfermode(mode);
+ else
+ p.setColor(color);
}
}
diff --git a/app/src/main/java/org/isoron/uhabits/views/HabitStreakView.java b/app/src/main/java/org/isoron/uhabits/views/HabitStreakView.java
index cf3fb7569..5872d96c9 100644
--- a/app/src/main/java/org/isoron/uhabits/views/HabitStreakView.java
+++ b/app/src/main/java/org/isoron/uhabits/views/HabitStreakView.java
@@ -21,71 +21,194 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
+import android.util.AttributeSet;
import org.isoron.helpers.ColorHelper;
+import org.isoron.helpers.DateHelper;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.Streak;
import java.text.SimpleDateFormat;
import java.util.List;
+import java.util.Locale;
+import java.util.Random;
public class HabitStreakView extends ScrollableDataView
{
private Habit habit;
private Paint pText, pBar;
- private List streaks;
+
+ private long[] startTimes;
+ private long[] endTimes;
+ private long[] lengths;
+
+ private int columnWidth;
+ private int columnHeight;
+ private int headerHeight;
+ private int nColumns;
+
private long maxStreakLength;
private int[] colors;
+ private SimpleDateFormat dfMonth;
+ private Rect rect;
+ private int baseSize;
+ private int primaryColor;
+
+ private boolean isBackgroundTransparent;
+ private int textColor;
+ private Paint pBarText;
+
+ public HabitStreakView(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ this.primaryColor = ColorHelper.palette[7];
+ init();
+ }
- public HabitStreakView(Context context, Habit habit, int columnWidth)
+ public void setHabit(Habit habit)
{
- super(context);
this.habit = habit;
- setDimensions(columnWidth);
+ createColors();
+ fetchData();
+ postInvalidate();
+ }
+
+ private void init()
+ {
createPaints();
createColors();
+
+ dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
+ rect = new Rect();
}
- private void setDimensions(int baseSize)
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
+ {
+ int width = MeasureSpec.getSize(widthMeasureSpec);
+ int height = MeasureSpec.getSize(heightMeasureSpec);
+ setMeasuredDimension(width, height);
+ }
+
+ @Override
+ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
{
- this.columnWidth = baseSize;
+ baseSize = height / 10;
+ setScrollerBucketSize(baseSize);
+
+ columnWidth = baseSize;
columnHeight = 8 * baseSize;
headerHeight = baseSize;
- footerHeight = baseSize;
+ nColumns = width / baseSize - 1;
+
+ pText.setTextSize(baseSize * 0.5f);
+ pBar.setTextSize(baseSize * 0.5f);
}
private void createColors()
{
- colors = new int[4];
- colors[0] = Color.rgb(230, 230, 230);
- colors[3] = habit.color;
- colors[1] = ColorHelper.mixColors(colors[0], colors[3], 0.66f);
- colors[2] = ColorHelper.mixColors(colors[0], colors[3], 0.33f);
+ if(habit != null)
+ this.primaryColor = habit.color;
+
+ if(isBackgroundTransparent)
+ {
+ primaryColor = ColorHelper.setSaturation(primaryColor, 0.75f);
+ primaryColor = ColorHelper.setValue(primaryColor, 1.0f);
+ }
+
+ int red = Color.red(primaryColor);
+ int green = Color.green(primaryColor);
+ int blue = Color.blue(primaryColor);
+
+ if(isBackgroundTransparent)
+ {
+ colors = new int[4];
+ colors[3] = primaryColor;
+ colors[2] = Color.argb(213, red, green, blue);
+ colors[1] = Color.argb(170, red, green, blue);
+ colors[0] = Color.argb(128, red, green, blue);
+ textColor = Color.rgb(255, 255, 255);
+ pBarText = pText;
+ }
+ else
+ {
+ colors = new int[4];
+ colors[3] = primaryColor;
+ colors[2] = Color.argb(192, red, green, blue);
+ colors[1] = Color.argb(96, red, green, blue);
+ colors[0] = Color.argb(32, 0, 0, 0);
+ textColor = Color.argb(64, 0, 0, 0);
+ pBarText = pBar;
+ }
}
- private void createPaints()
+ protected void createPaints()
{
pText = new Paint();
- pText.setColor(Color.LTGRAY);
pText.setTextAlign(Paint.Align.CENTER);
- pText.setTextSize(columnWidth * 0.5f);
pText.setAntiAlias(true);
pBar = new Paint();
pBar.setTextAlign(Paint.Align.CENTER);
- pBar.setTextSize(columnWidth * 0.5f);
pBar.setAntiAlias(true);
}
protected void fetchData()
{
- streaks = habit.getStreaks();
+ if(isInEditMode())
+ generateRandomData();
+ else
+ {
+ if(habit == null)
+ {
+ startTimes = endTimes = lengths = new long[0];
+ return;
+ }
+
+ List streaks = habit.streaks.getAll();
+ int size = streaks.size();
- for (Streak s : streaks)
- maxStreakLength = Math.max(maxStreakLength, s.length);
+ startTimes = new long[size];
+ endTimes = new long[size];
+ lengths = new long[size];
+
+ int k = 0;
+ for (Streak s : streaks)
+ {
+ startTimes[k] = s.start;
+ endTimes[k] = s.end;
+ lengths[k] = s.length;
+ k++;
+
+ maxStreakLength = Math.max(maxStreakLength, s.length);
+ }
+ }
}
+ private void generateRandomData()
+ {
+ int size = 30;
+
+ startTimes = new long[size];
+ endTimes = new long[size];
+ lengths = new long[size];
+
+ Random random = new Random();
+ Long date = DateHelper.getStartOfToday();
+
+ for(int i = 0; i < size; i++)
+ {
+ int l = (int) Math.pow(2, random.nextFloat() * 5 + 1);
+
+ endTimes[i] = date;
+ date -= l * DateHelper.millisecondsInOneDay;
+ lengths[i] = (long) l;
+ startTimes[i] = date;
+
+ maxStreakLength = Math.max(maxStreakLength, l);
+ }
+ }
@Override
protected void onDraw(Canvas canvas)
@@ -95,32 +218,40 @@ public class HabitStreakView extends ScrollableDataView
float lineHeight = pText.getFontSpacing();
float barHeaderOffset = lineHeight * 0.4f;
- int nStreaks = streaks.size();
- int start = Math.max(0, nStreaks - nColumns - dataOffset);
- SimpleDateFormat dfMonth = new SimpleDateFormat("MMM");
+ int nStreaks = startTimes.length;
+ int start = nStreaks - nColumns - getDataOffset();
+
+ pText.setColor(textColor);
String previousMonth = "";
for (int offset = 0; offset < nColumns && start + offset < nStreaks; offset++)
{
- String month = dfMonth.format(streaks.get(start + offset).start);
+ if(start + offset < 0) continue;
+ String month = dfMonth.format(startTimes[start + offset]);
- long l = streaks.get(offset + start).length;
+ long l = lengths[offset + start];
double lRelative = ((double) l) / maxStreakLength;
pBar.setColor(colors[(int) Math.floor(lRelative * 3)]);
int height = (int) (columnHeight * lRelative);
- Rect r = new Rect(0, 0, columnWidth - 2, height);
- r.offset(offset * columnWidth, headerHeight + columnHeight - height);
+ rect.set(0, 0, columnWidth - 2, height);
+ rect.offset(offset * columnWidth, headerHeight + columnHeight - height);
- canvas.drawRect(r, pBar);
- canvas.drawText(Long.toString(l), r.centerX(), r.top - barHeaderOffset, pBar);
+ canvas.drawRect(rect, pBar);
+ canvas.drawText(Long.toString(l), rect.centerX(), rect.top - barHeaderOffset, pBarText);
if (!month.equals(previousMonth))
- canvas.drawText(month, r.centerX(), r.bottom + lineHeight * 1.2f, pText);
+ canvas.drawText(month, rect.centerX(), rect.bottom + lineHeight * 1.2f, pText);
previousMonth = month;
}
}
+
+ public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
+ {
+ this.isBackgroundTransparent = isBackgroundTransparent;
+ createColors();
+ }
}
diff --git a/app/src/main/java/org/isoron/uhabits/views/RingView.java b/app/src/main/java/org/isoron/uhabits/views/RingView.java
index 41722ef18..e897fb5fb 100644
--- a/app/src/main/java/org/isoron/uhabits/views/RingView.java
+++ b/app/src/main/java/org/isoron/uhabits/views/RingView.java
@@ -21,31 +21,57 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
+import android.util.AttributeSet;
import android.view.View;
+import org.isoron.helpers.ColorHelper;
+import org.isoron.helpers.DialogHelper;
+import org.isoron.uhabits.R;
+
public class RingView extends View
{
private int size;
private int color;
- private float perc;
+ private float percentage;
private Paint pRing;
private float lineHeight;
private String label;
+ private RectF rect;
+
+ public RingView(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+
+ this.size = (int) context.getResources().getDimension(R.dimen.small_square_size) * 4;
+ this.label = DialogHelper.getAttribute(context, attrs, "label");
+ this.color = ColorHelper.palette[7];
+ this.percentage = 0.75f;
+ init();
+ }
- public RingView(Context context, int size, int color, float perc, String label)
+ public void setColor(int color)
{
- super(context);
- this.size = size;
this.color = color;
- this.perc = perc;
+ pRing.setColor(color);
+ postInvalidate();
+ }
+ public void setPercentage(float percentage)
+ {
+ this.percentage = percentage;
+ postInvalidate();
+ }
+
+ private void init()
+ {
pRing = new Paint();
- pRing.setColor(color);
pRing.setAntiAlias(true);
+ pRing.setColor(color);
pRing.setTextAlign(Paint.Align.CENTER);
-
- this.label = label;
+ pRing.setTextSize(size * 0.2f);
+ lineHeight = pRing.getFontSpacing();
+ rect = new RectF();
}
@Override
@@ -62,21 +88,20 @@ public class RingView extends View
float thickness = size * 0.15f;
pRing.setColor(color);
- RectF r = new RectF(0, 0, size, size);
- canvas.drawArc(r, -90, 360 * perc, true, pRing);
+ rect.set(0, 0, size, size);
+ canvas.drawArc(rect, -90, 360 * percentage, true, pRing);
pRing.setColor(Color.rgb(230, 230, 230));
- canvas.drawArc(r, 360 * perc - 90 + 2, 360 * (1 - perc) - 4, true, pRing);
+ canvas.drawArc(rect, 360 * percentage - 90 + 2, 360 * (1 - percentage) - 4, true, pRing);
pRing.setColor(Color.WHITE);
- r.inset(thickness, thickness);
- canvas.drawArc(r, -90, 360, true, pRing);
+ rect.inset(thickness, thickness);
+ canvas.drawArc(rect, -90, 360, true, pRing);
pRing.setColor(Color.GRAY);
pRing.setTextSize(size * 0.2f);
- lineHeight = pRing.getFontSpacing();
- canvas.drawText(String.format("%.0f%%", perc * 100), r.centerX(),
- r.centerY() + lineHeight / 3, pRing);
+ canvas.drawText(String.format("%.0f%%", percentage * 100), rect.centerX(),
+ rect.centerY() + lineHeight / 3, pRing);
pRing.setTextSize(size * 0.15f);
canvas.drawText(label, size / 2, size + lineHeight * 1.2f, pRing);
diff --git a/app/src/main/java/org/isoron/uhabits/views/ScrollableDataView.java b/app/src/main/java/org/isoron/uhabits/views/ScrollableDataView.java
index 5368595a4..7360456da 100644
--- a/app/src/main/java/org/isoron/uhabits/views/ScrollableDataView.java
+++ b/app/src/main/java/org/isoron/uhabits/views/ScrollableDataView.java
@@ -19,87 +19,129 @@
package org.isoron.uhabits.views;
+import android.animation.ValueAnimator;
import android.content.Context;
-import android.support.v4.view.MotionEventCompat;
+import android.util.AttributeSet;
+import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
+import android.widget.Scroller;
-public abstract class ScrollableDataView extends View
+public abstract class ScrollableDataView extends View implements GestureDetector.OnGestureListener,
+ ValueAnimator.AnimatorUpdateListener
{
- protected int dataOffset;
- protected int nColumns;
- protected int columnWidth, columnHeight;
- protected int headerHeight, footerHeight;
+ private int dataOffset;
+ private int scrollerBucketSize;
- private float prevX, prevY;
+ private GestureDetector detector;
+ private Scroller scroller;
+ private ValueAnimator scrollAnimator;
public ScrollableDataView(Context context)
{
super(context);
+ init(context);
+ }
+
+ public ScrollableDataView(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ init(context);
+ }
+
+ private void init(Context context)
+ {
+ detector = new GestureDetector(context, this);
+ scroller = new Scroller(context, null, true);
+ scrollAnimator = ValueAnimator.ofFloat(0, 1);
+ scrollAnimator.addUpdateListener(this);
}
protected abstract void fetchData();
- protected boolean move(float dx)
+ @Override
+ public boolean onTouchEvent(MotionEvent event)
{
- int newDataOffset = dataOffset + (int) (dx / columnWidth);
- newDataOffset = Math.max(0, newDataOffset);
+ return detector.onTouchEvent(event);
+ }
- if (newDataOffset != dataOffset)
- {
- dataOffset = newDataOffset;
- fetchData();
- invalidate();
- return true;
- }
- else return false;
+ @Override
+ public boolean onDown(MotionEvent e)
+ {
+ return true;
}
@Override
- public boolean onTouchEvent(MotionEvent event)
+ public void onShowPress(MotionEvent e)
{
- int action = event.getAction();
- int pointerIndex = MotionEventCompat.getActionIndex(event);
- final float x = MotionEventCompat.getX(event, pointerIndex);
- final float y = MotionEventCompat.getY(event, pointerIndex);
+ }
- if (action == MotionEvent.ACTION_DOWN)
- {
- prevX = x;
- prevY = y;
- }
+ @Override
+ public boolean onSingleTapUp(MotionEvent e)
+ {
+ return false;
+ }
- if (action == MotionEvent.ACTION_MOVE)
- {
- float dx = x - prevX;
- float dy = y - prevY;
+ @Override
+ public boolean onScroll(MotionEvent e1, MotionEvent e2, float dx, float dy)
+ {
+ if(scrollerBucketSize == 0)
+ return false;
- if (Math.abs(dy) > Math.abs(dx)) return false;
+ if(Math.abs(dx) > Math.abs(dy))
getParent().requestDisallowInterceptTouchEvent(true);
- if (move(dx))
- {
- prevX = x;
- prevY = y;
- }
- }
+
+ scroller.startScroll(scroller.getCurrX(), scroller.getCurrY(), (int) -dx, (int) dy, 0);
+ scroller.computeScrollOffset();
+ dataOffset = Math.max(0, scroller.getCurrX() / scrollerBucketSize);
+ postInvalidate();
return true;
}
@Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
+ public void onLongPress(MotionEvent e)
{
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- setMeasuredDimension(getMeasuredWidth(), columnHeight + headerHeight + footerHeight);
+
+ }
+
+ @Override
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
+ {
+ scroller.fling(scroller.getCurrX(), scroller.getCurrY(), (int) velocityX / 2, 0, 0, 100000,
+ 0, 0);
+ invalidate();
+
+ scrollAnimator.setDuration(scroller.getDuration());
+ scrollAnimator.start();
+
+ return false;
}
@Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh)
+ public void onAnimationUpdate(ValueAnimator animation)
+ {
+ if (!scroller.isFinished())
+ {
+ scroller.computeScrollOffset();
+ dataOffset = Math.max(0, scroller.getCurrX() / scrollerBucketSize);
+ postInvalidate();
+ }
+ else
+ {
+ scrollAnimator.cancel();
+ }
+ }
+
+ public int getDataOffset()
+ {
+ return dataOffset;
+ }
+
+ public void setScrollerBucketSize(int scrollerBucketSize)
{
- super.onSizeChanged(w, h, oldw, oldh);
- nColumns = w / columnWidth;
- fetchData();
+ this.scrollerBucketSize = scrollerBucketSize;
}
}
diff --git a/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java b/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java
new file mode 100644
index 000000000..d890ea1b3
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java
@@ -0,0 +1,198 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.widgets;
+
+import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProvider;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.graphics.Bitmap;
+import android.media.Image;
+import android.os.Build;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RemoteViews;
+
+import org.isoron.helpers.DialogHelper;
+import org.isoron.uhabits.R;
+import org.isoron.uhabits.models.Habit;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public abstract class BaseWidgetProvider extends AppWidgetProvider
+{
+
+ private int width, height;
+
+ protected abstract int getDefaultHeight();
+
+ protected abstract int getDefaultWidth();
+
+ protected abstract PendingIntent getOnClickPendingIntent(Context context, Habit habit);
+
+ protected abstract int getLayoutId();
+
+ protected abstract View buildCustomView(Context context, Habit habit);
+
+ public static String getHabitIdKey(long widgetId)
+ {
+ return String.format("widget-%06d-habit", widgetId);
+ }
+
+ @Override
+ public void onDeleted(Context context, int[] appWidgetIds)
+ {
+ Context appContext = context.getApplicationContext();
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
+
+ for(Integer id : appWidgetIds)
+ prefs.edit().remove(getHabitIdKey(id));
+ }
+
+ @Override
+ public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager,
+ int appWidgetId, Bundle newOptions)
+ {
+ updateWidget(context, appWidgetManager, appWidgetId, newOptions);
+ }
+
+ @Override
+ public void onUpdate(Context context, AppWidgetManager manager, int[] appWidgetIds)
+ {
+ for(int id : appWidgetIds)
+ {
+ Bundle options = null;
+
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN)
+ options = manager.getAppWidgetOptions(id);
+
+ updateWidget(context, manager, id, options);
+ }
+ }
+
+ private void updateWidget(Context context, AppWidgetManager manager, int widgetId, Bundle options)
+ {
+ updateWidgetSize(context, options);
+
+ Context appContext = context.getApplicationContext();
+ RemoteViews remoteViews = new RemoteViews(context.getPackageName(), getLayoutId());
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
+
+ Long habitId = prefs.getLong(getHabitIdKey(widgetId), -1L);
+ if(habitId < 0) return;
+
+ Habit habit = Habit.get(habitId);
+ View widgetView = buildCustomView(context, habit);
+ measureCustomView(context, width, height, widgetView);
+
+ widgetView.setDrawingCacheEnabled(true);
+ widgetView.buildDrawingCache(true);
+ Bitmap drawingCache = widgetView.getDrawingCache();
+
+ remoteViews.setTextViewText(R.id.label, habit.name);
+ remoteViews.setImageViewBitmap(R.id.imageView, drawingCache);
+
+ //savePreview(context, widgetId, drawingCache);
+
+ PendingIntent onClickIntent = getOnClickPendingIntent(context, habit);
+ if(onClickIntent != null) remoteViews.setOnClickPendingIntent(R.id.imageView, onClickIntent);
+
+ manager.updateAppWidget(widgetId, remoteViews);
+ }
+
+ private void savePreview(Context context, int widgetId, Bitmap widgetCache)
+ {
+ try
+ {
+ LayoutInflater inflater = LayoutInflater.from(context);
+ View view = inflater.inflate(getLayoutId(), null);
+
+ ImageView iv = (ImageView) view.findViewById(R.id.imageView);
+ iv.setImageBitmap(widgetCache);
+
+ view.measure(width, height);
+ view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
+ view.setDrawingCacheEnabled(true);
+ view.buildDrawingCache();
+ Bitmap previewCache = view.getDrawingCache();
+
+ String filename = String.format("%s/%d.png", context.getExternalCacheDir(), widgetId);
+ Log.d("BaseWidgetProvider", String.format("Writing %s", filename));
+ FileOutputStream out = new FileOutputStream(filename);
+
+ if(previewCache != null)
+ previewCache.compress(Bitmap.CompressFormat.PNG, 100, out);
+
+ out.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void updateWidgetSize(Context context, Bundle options)
+ {
+ int maxWidth = getDefaultWidth();
+ int minWidth = getDefaultWidth();
+ int maxHeight = getDefaultHeight();
+ int minHeight = getDefaultHeight();
+
+ if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
+ {
+ maxWidth = (int) DialogHelper.dpToPixels(context,
+ options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH));
+ maxHeight = (int) DialogHelper.dpToPixels(context,
+ options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT));
+ minWidth = (int) DialogHelper.dpToPixels(context,
+ options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH));
+ minHeight = (int) DialogHelper.dpToPixels(context,
+ options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT));
+ }
+
+ width = maxWidth;
+ height = maxHeight;
+ }
+
+ private void measureCustomView(Context context, int w, int h, View customView)
+ {
+ LayoutInflater inflater = LayoutInflater.from(context);
+ View entireView = inflater.inflate(getLayoutId(), null);
+
+ int specWidth = View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY);
+ int specHeight = View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY);
+
+ entireView.measure(specWidth, specHeight);
+ entireView.layout(0, 0, entireView.getMeasuredWidth(), entireView.getMeasuredHeight());
+
+ View imageView = entireView.findViewById(R.id.imageView);
+ w = imageView.getMeasuredWidth();
+ h = imageView.getMeasuredHeight();
+
+ specWidth = View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY);
+ specHeight = View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY);
+ customView.measure(specWidth, specHeight);
+ customView.layout(0, 0, customView.getMeasuredWidth(), customView.getMeasuredHeight());
+ }
+}
diff --git a/app/src/main/java/org/isoron/uhabits/widgets/CheckmarkWidgetProvider.java b/app/src/main/java/org/isoron/uhabits/widgets/CheckmarkWidgetProvider.java
new file mode 100644
index 000000000..2710435f9
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/widgets/CheckmarkWidgetProvider.java
@@ -0,0 +1,60 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.isoron.uhabits.widgets;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.view.View;
+
+import org.isoron.uhabits.HabitBroadcastReceiver;
+import org.isoron.uhabits.R;
+import org.isoron.uhabits.models.Habit;
+import org.isoron.uhabits.views.CheckmarkView;
+
+public class CheckmarkWidgetProvider extends BaseWidgetProvider
+{
+ @Override
+ protected View buildCustomView(Context context, Habit habit)
+ {
+ CheckmarkView view = new CheckmarkView(context);
+ view.setHabit(habit);
+ return view;
+ }
+
+ @Override
+ protected PendingIntent getOnClickPendingIntent(Context context, Habit habit)
+ {
+ return HabitBroadcastReceiver.buildCheckIntent(context, habit, null);
+ }
+
+ @Override
+ protected int getDefaultHeight()
+ {
+ return 200;
+ }
+
+ @Override
+ protected int getDefaultWidth()
+ {
+ return 200;
+ }
+
+ @Override
+ protected int getLayoutId()
+ {
+ return R.layout.widget_checkmark;
+ }
+}
diff --git a/app/src/main/java/org/isoron/uhabits/widgets/HabitPickerDialog.java b/app/src/main/java/org/isoron/uhabits/widgets/HabitPickerDialog.java
new file mode 100644
index 000000000..f44127cac
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/widgets/HabitPickerDialog.java
@@ -0,0 +1,90 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.isoron.uhabits.widgets;
+
+import android.app.Activity;
+import android.appwidget.AppWidgetManager;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+import org.isoron.uhabits.MainActivity;
+import org.isoron.uhabits.R;
+import org.isoron.uhabits.models.Habit;
+import org.isoron.uhabits.widgets.BaseWidgetProvider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class HabitPickerDialog extends Activity implements AdapterView.OnItemClickListener
+{
+
+ private Integer widgetId;
+ private ArrayList habitIds;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.widget_configure_activity);
+
+ Intent intent = getIntent();
+ Bundle extras = intent.getExtras();
+
+ if (extras != null) widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
+ AppWidgetManager.INVALID_APPWIDGET_ID);
+
+ ListView listView = (ListView) findViewById(R.id.listView);
+
+ habitIds = new ArrayList<>();
+ ArrayList habitNames = new ArrayList<>();
+
+ List habits = Habit.getAll(false);
+ for(Habit h : habits)
+ {
+ habitIds.add(h.getId());
+ habitNames.add(h.name);
+ }
+
+ ArrayAdapter adapter =
+ new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, habitNames);
+ listView.setAdapter(adapter);
+ listView.setOnItemClickListener(this);
+ }
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id)
+ {
+ Long habitId = habitIds.get(position);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
+ getApplicationContext());
+ prefs.edit().putLong(BaseWidgetProvider.getHabitIdKey(widgetId), habitId).commit();
+
+ MainActivity.updateWidgets(this);
+
+ Intent resultValue = new Intent();
+ resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
+ setResult(RESULT_OK, resultValue);
+ finish();
+ }
+
+}
diff --git a/app/src/main/java/org/isoron/uhabits/widgets/HistoryWidgetProvider.java b/app/src/main/java/org/isoron/uhabits/widgets/HistoryWidgetProvider.java
new file mode 100644
index 000000000..7f6b50aea
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/widgets/HistoryWidgetProvider.java
@@ -0,0 +1,60 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.isoron.uhabits.widgets;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.view.View;
+
+import org.isoron.uhabits.R;
+import org.isoron.uhabits.models.Habit;
+import org.isoron.uhabits.views.HabitHistoryView;
+
+public class HistoryWidgetProvider extends BaseWidgetProvider
+{
+ @Override
+ protected View buildCustomView(Context context, Habit habit)
+ {
+ HabitHistoryView view = new HabitHistoryView(context, null);
+ view.setHabit(habit);
+ view.setIsBackgroundTransparent(true);
+ return view;
+ }
+
+ @Override
+ protected PendingIntent getOnClickPendingIntent(Context context, Habit habit)
+ {
+ return null;
+ }
+
+ @Override
+ protected int getDefaultHeight()
+ {
+ return 200;
+ }
+
+ @Override
+ protected int getDefaultWidth()
+ {
+ return 200;
+ }
+
+ @Override
+ protected int getLayoutId()
+ {
+ return R.layout.widget_graph;
+ }
+}
diff --git a/app/src/main/java/org/isoron/uhabits/widgets/ScoreWidgetProvider.java b/app/src/main/java/org/isoron/uhabits/widgets/ScoreWidgetProvider.java
new file mode 100644
index 000000000..3cede1dee
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/widgets/ScoreWidgetProvider.java
@@ -0,0 +1,60 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.isoron.uhabits.widgets;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.view.View;
+
+import org.isoron.uhabits.R;
+import org.isoron.uhabits.models.Habit;
+import org.isoron.uhabits.views.HabitScoreView;
+
+public class ScoreWidgetProvider extends BaseWidgetProvider
+{
+ @Override
+ protected View buildCustomView(Context context, Habit habit)
+ {
+ HabitScoreView view = new HabitScoreView(context, null);
+ view.setIsBackgroundTransparent(true);
+ view.setHabit(habit);
+ return view;
+ }
+
+ @Override
+ protected PendingIntent getOnClickPendingIntent(Context context, Habit habit)
+ {
+ return null;
+ }
+
+ @Override
+ protected int getDefaultHeight()
+ {
+ return 200;
+ }
+
+ @Override
+ protected int getDefaultWidth()
+ {
+ return 200;
+ }
+
+ @Override
+ protected int getLayoutId()
+ {
+ return R.layout.widget_graph;
+ }
+}
diff --git a/app/src/main/java/org/isoron/uhabits/widgets/StreakWidgetProvider.java b/app/src/main/java/org/isoron/uhabits/widgets/StreakWidgetProvider.java
new file mode 100644
index 000000000..c125654d2
--- /dev/null
+++ b/app/src/main/java/org/isoron/uhabits/widgets/StreakWidgetProvider.java
@@ -0,0 +1,60 @@
+/* Copyright (C) 2016 Alinson Santos Xavier
+ *
+ * This program 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.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.isoron.uhabits.widgets;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.view.View;
+
+import org.isoron.uhabits.R;
+import org.isoron.uhabits.models.Habit;
+import org.isoron.uhabits.views.HabitStreakView;
+
+public class StreakWidgetProvider extends BaseWidgetProvider
+{
+ @Override
+ protected View buildCustomView(Context context, Habit habit)
+ {
+ HabitStreakView view = new HabitStreakView(context, null);
+ view.setIsBackgroundTransparent(true);
+ view.setHabit(habit);
+ return view;
+ }
+
+ @Override
+ protected PendingIntent getOnClickPendingIntent(Context context, Habit habit)
+ {
+ return null;
+ }
+
+ @Override
+ protected int getDefaultHeight()
+ {
+ return 200;
+ }
+
+ @Override
+ protected int getDefaultWidth()
+ {
+ return 200;
+ }
+
+ @Override
+ protected int getLayoutId()
+ {
+ return R.layout.widget_graph;
+ }
+}
diff --git a/app/src/main/res/drawable-hdpi/ic_action_dismiss.png b/app/src/main/res/drawable-hdpi/ic_action_dismiss.png
deleted file mode 100644
index ea21b1bf2..000000000
Binary files a/app/src/main/res/drawable-hdpi/ic_action_dismiss.png and /dev/null differ
diff --git a/app/src/main/res/drawable-hdpi/ic_action_edit.png b/app/src/main/res/drawable-hdpi/ic_action_edit.png
deleted file mode 100644
index 5c8bcf881..000000000
Binary files a/app/src/main/res/drawable-hdpi/ic_action_edit.png and /dev/null differ
diff --git a/app/src/main/res/drawable-hdpi/ic_action_pick_color.png b/app/src/main/res/drawable-hdpi/ic_action_pick_color.png
deleted file mode 100644
index 69c1085a3..000000000
Binary files a/app/src/main/res/drawable-hdpi/ic_action_pick_color.png and /dev/null differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_dismiss.png b/app/src/main/res/drawable-mdpi/ic_action_dismiss.png
deleted file mode 100644
index cfb167994..000000000
Binary files a/app/src/main/res/drawable-mdpi/ic_action_dismiss.png and /dev/null differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_edit.png b/app/src/main/res/drawable-mdpi/ic_action_edit.png
deleted file mode 100644
index c6367decf..000000000
Binary files a/app/src/main/res/drawable-mdpi/ic_action_edit.png and /dev/null differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_pick_color.png b/app/src/main/res/drawable-mdpi/ic_action_pick_color.png
deleted file mode 100644
index 70891e87d..000000000
Binary files a/app/src/main/res/drawable-mdpi/ic_action_pick_color.png and /dev/null differ
diff --git a/app/src/main/res/drawable/ripple_transparent.xml b/app/src/main/res/drawable-v21/ripple_transparent.xml
similarity index 100%
rename from app/src/main/res/drawable/ripple_transparent.xml
rename to app/src/main/res/drawable-v21/ripple_transparent.xml
diff --git a/app/src/main/res/drawable/ripple_white.xml b/app/src/main/res/drawable-v21/ripple_white.xml
similarity index 100%
rename from app/src/main/res/drawable/ripple_white.xml
rename to app/src/main/res/drawable-v21/ripple_white.xml
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_dismiss.png b/app/src/main/res/drawable-xhdpi/ic_action_dismiss.png
deleted file mode 100644
index 0aaf7e2df..000000000
Binary files a/app/src/main/res/drawable-xhdpi/ic_action_dismiss.png and /dev/null differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_edit.png b/app/src/main/res/drawable-xhdpi/ic_action_edit.png
deleted file mode 100644
index 955a22d51..000000000
Binary files a/app/src/main/res/drawable-xhdpi/ic_action_edit.png and /dev/null differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_pick_color.png b/app/src/main/res/drawable-xhdpi/ic_action_pick_color.png
deleted file mode 100644
index cda4f1376..000000000
Binary files a/app/src/main/res/drawable-xhdpi/ic_action_pick_color.png and /dev/null differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_dismiss.png b/app/src/main/res/drawable-xxhdpi/ic_action_dismiss.png
deleted file mode 100644
index 61817c96b..000000000
Binary files a/app/src/main/res/drawable-xxhdpi/ic_action_dismiss.png and /dev/null differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_edit.png b/app/src/main/res/drawable-xxhdpi/ic_action_edit.png
deleted file mode 100644
index e2a84d81f..000000000
Binary files a/app/src/main/res/drawable-xxhdpi/ic_action_edit.png and /dev/null differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_pick_color.png b/app/src/main/res/drawable-xxhdpi/ic_action_pick_color.png
deleted file mode 100644
index ec00751d8..000000000
Binary files a/app/src/main/res/drawable-xxhdpi/ic_action_pick_color.png and /dev/null differ
diff --git a/app/src/main/res/drawable/habits_header.xml b/app/src/main/res/drawable/habits_header.xml
deleted file mode 100644
index e1c4cfc84..000000000
--- a/app/src/main/res/drawable/habits_header.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/drawable/habits_header_check.xml b/app/src/main/res/drawable/habits_header_check.xml
deleted file mode 100644
index 101e22dcb..000000000
--- a/app/src/main/res/drawable/habits_header_check.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/drawable/habits_item.xml b/app/src/main/res/drawable/habits_item.xml
deleted file mode 100644
index 4ba72d44f..000000000
--- a/app/src/main/res/drawable/habits_item.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
- -
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/drawable/habits_item_check.xml b/app/src/main/res/drawable/habits_item_check.xml
deleted file mode 100644
index e217a4e9c..000000000
--- a/app/src/main/res/drawable/habits_item_check.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/drawable/widget_background.xml b/app/src/main/res/drawable/widget_background.xml
new file mode 100644
index 000000000..1c66dd34c
--- /dev/null
+++ b/app/src/main/res/drawable/widget_background.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/widget_preview_checkmark.png b/app/src/main/res/drawable/widget_preview_checkmark.png
new file mode 100644
index 000000000..ceb7d6541
Binary files /dev/null and b/app/src/main/res/drawable/widget_preview_checkmark.png differ
diff --git a/app/src/main/res/drawable/widget_preview_history.png b/app/src/main/res/drawable/widget_preview_history.png
new file mode 100644
index 000000000..bcc829bbc
Binary files /dev/null and b/app/src/main/res/drawable/widget_preview_history.png differ
diff --git a/app/src/main/res/drawable/widget_preview_score.png b/app/src/main/res/drawable/widget_preview_score.png
new file mode 100644
index 000000000..101569dbc
Binary files /dev/null and b/app/src/main/res/drawable/widget_preview_score.png differ
diff --git a/app/src/main/res/drawable/widget_preview_streaks.png b/app/src/main/res/drawable/widget_preview_streaks.png
new file mode 100644
index 000000000..9977ca6f0
Binary files /dev/null and b/app/src/main/res/drawable/widget_preview_streaks.png differ
diff --git a/app/src/main/res/layout/edit_habit.xml b/app/src/main/res/layout/edit_habit.xml
index 64e55c64a..17881a36a 100644
--- a/app/src/main/res/layout/edit_habit.xml
+++ b/app/src/main/res/layout/edit_habit.xml
@@ -24,6 +24,7 @@
@@ -77,7 +78,6 @@
diff --git a/app/src/main/res/layout/list_habits_item.xml b/app/src/main/res/layout/list_habits_item.xml
index b1f07dc7a..2e4704952 100644
--- a/app/src/main/res/layout/list_habits_item.xml
+++ b/app/src/main/res/layout/list_habits_item.xml
@@ -12,7 +12,7 @@
style="@style/habitsListStarStyle" />
@@ -19,18 +19,26 @@
style="@style/cardHeaderStyle"
android:text="@string/overview"/>
+
+
-
+
+
+
@@ -45,6 +53,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
+
+
+
@@ -59,6 +73,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/show_habit_activity.xml b/app/src/main/res/layout/show_habit_activity.xml
index 281221efc..1c2bb74d2 100644
--- a/app/src/main/res/layout/show_habit_activity.xml
+++ b/app/src/main/res/layout/show_habit_activity.xml
@@ -4,12 +4,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.isoron.uhabits.ShowHabitActivity"
- tools:ignore="MergeRootFrame" >
+ tools:ignore="MergeRootFrame"
+ tools:menu="show_habit_activity_menu,show_habit_fragment_menu">
+ android:layout_height="match_parent"
+ tools:layout="@layout/show_habit"
+ android:layout_gravity="center"/>
diff --git a/app/src/main/res/layout/small_widget_preview.xml b/app/src/main/res/layout/small_widget_preview.xml
new file mode 100644
index 000000000..d9a8c5ac1
--- /dev/null
+++ b/app/src/main/res/layout/small_widget_preview.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/widget_checkmark.xml b/app/src/main/res/layout/widget_checkmark.xml
new file mode 100644
index 000000000..40205476c
--- /dev/null
+++ b/app/src/main/res/layout/widget_checkmark.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/widget_configure_activity.xml b/app/src/main/res/layout/widget_configure_activity.xml
new file mode 100644
index 000000000..8c653b697
--- /dev/null
+++ b/app/src/main/res/layout/widget_configure_activity.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/widget_graph.xml b/app/src/main/res/layout/widget_graph.xml
new file mode 100644
index 000000000..94a5fd001
--- /dev/null
+++ b/app/src/main/res/layout/widget_graph.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu-v21/list_habits_context.xml b/app/src/main/res/menu-v21/list_habits_context.xml
index 1427d4ab5..1f1872977 100644
--- a/app/src/main/res/menu-v21/list_habits_context.xml
+++ b/app/src/main/res/menu-v21/list_habits_context.xml
@@ -21,6 +21,11 @@
android:title="@string/unarchive"
android:icon="@drawable/ic_action_unarchive_dark"/>
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/list_habits_menu.xml b/app/src/main/res/menu/list_habits_menu.xml
index 408bae45e..c87717e70 100644
--- a/app/src/main/res/menu/list_habits_menu.xml
+++ b/app/src/main/res/menu/list_habits_menu.xml
@@ -1,16 +1,18 @@
diff --git a/app/src/main/res/menu/list_habits_options.xml b/app/src/main/res/menu/list_habits_options.xml
index c00cdabe0..a8397d437 100644
--- a/app/src/main/res/menu/list_habits_options.xml
+++ b/app/src/main/res/menu/list_habits_options.xml
@@ -1,9 +1,11 @@
diff --git a/app/src/main/res/menu/show_habit_activity_menu.xml b/app/src/main/res/menu/show_habit_activity_menu.xml
index 923f4f112..7d2a0cf17 100644
--- a/app/src/main/res/menu/show_habit_activity_menu.xml
+++ b/app/src/main/res/menu/show_habit_activity_menu.xml
@@ -1,12 +1,12 @@
diff --git a/app/src/main/res/menu/show_habit_fragment_menu.xml b/app/src/main/res/menu/show_habit_fragment_menu.xml
index d77372b2c..90a54e0c7 100644
--- a/app/src/main/res/menu/show_habit_fragment_menu.xml
+++ b/app/src/main/res/menu/show_habit_fragment_menu.xml
@@ -3,8 +3,8 @@
+ android:icon="@drawable/ic_action_edit_light"
+ android:title="@string/edit"
+ android:showAsAction="ifRoom"/>
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-hdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-hdpi/ic_small_widget_preview.png
new file mode 100644
index 000000000..7ee617aa6
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_small_widget_preview.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-mdpi/ic_small_widget_preview.png
new file mode 100644
index 000000000..ff862e252
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_small_widget_preview.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-xhdpi/ic_small_widget_preview.png
new file mode 100644
index 000000000..8d90b8901
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_small_widget_preview.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-xxhdpi/ic_small_widget_preview.png
new file mode 100644
index 000000000..734f9630f
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_small_widget_preview.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_small_widget_preview.png b/app/src/main/res/mipmap-xxxhdpi/ic_small_widget_preview.png
new file mode 100644
index 000000000..f049e8332
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_small_widget_preview.png differ
diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml
index 5f84a5be7..1c98c7aac 100644
--- a/app/src/main/res/values-pt/strings.xml
+++ b/app/src/main/res/values-pt/strings.xml
@@ -30,7 +30,6 @@
Criar hábito
dias
Deletar
- Descrição
Pergunta (por ex., \"você meditou hoje?\")
Cancelar
Editar
@@ -58,7 +57,6 @@
Mais tarde
Correntes
Você não tem nenhum hábito ativo
-
Hábitos arquivados.
Hábito modificado.
Hábito restaurado.
@@ -67,7 +65,6 @@
Hábitos restaurados.
Nada para refazer.
Nada para desfazer.
- Marcado.
Desarquivar
Você pode ter no máximo uma repetição por dia.
Nome não pode ficar em branco.
@@ -104,4 +101,5 @@
Segunda a sexta
Qualquer dia
Selecionar dias
+ Exportar dados
\ No newline at end of file
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 7f3d15ab7..e1a260566 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -17,7 +17,6 @@
Nothing to redo.
习惯修改了.
取消了修改.
- Repetition toggled.
习惯存档成功.
习惯取消存档成功.
@@ -26,16 +25,11 @@
取消
选择小时
选择分钟
- Year list
- Select month and day
- Select year
-
总览
习惯强度
历史
取消
- 描叙
提醒问题(你xxx了吗)
重复
次每
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index bd3296cf7..6748fdb6c 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -18,11 +18,9 @@
#37474f
#263238
- #9a4000
#e6e6e6
#ffffff
- #cccccc
#f2f2f2
@@ -50,281 +48,278 @@
#404040
#363636
#808080
- #ffffff
- #888888
- #bfbfbf
- #FFEBEE
- #FFCDD2
- #EF9A9A
- #E57373
- #EF5350
- #F44336
- #E53935
- #D32F2F
- #C62828
- #B71C1C
- #FF8A80
- #FF5252
- #FF1744
- #D50000
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #EDE7F6
- #D1C4E9
- #B39DDB
- #9575CD
- #7E57C2
- #673AB7
- #5E35B1
- #512DA8
- #4527A0
- #311B92
- #B388FF
- #7C4DFF
- #651FFF
- #6200EA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #E1F5FE
- #B3E5FC
- #81D4FA
- #4FC3F7
- #29B6F6
- #03A9F4
- #039BE5
- #0288D1
- #0277BD
- #01579B
- #80D8FF
- #40C4FF
- #00B0FF
- #0091EA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #E8F5E9
- #C8E6C9
- #A5D6A7
- #81C784
- #66BB6A
- #4CAF50
- #43A047
- #388E3C
- #2E7D32
- #1B5E20
- #B9F6CA
- #69F0AE
- #00E676
- #00C853
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #FFFDE7
- #FFF9C4
- #FFF59D
- #FFF176
- #FFEE58
- #FFEB3B
- #FDD835
- #FBC02D
- #F9A825
- #F57F17
- #FFFF8D
- #FFFF00
- #FFEA00
- #FFD600
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #FBE9E7
- #FFCCBC
- #FFAB91
- #FF8A65
- #FF7043
- #FF5722
- #F4511E
- #E64A19
- #D84315
- #BF360C
- #FF9E80
- #FF6E40
- #FF3D00
- #DD2C00
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #ECEFF1
- #CFD8DC
- #B0BEC5
- #90A4AE
- #78909C
- #607D8B
- #546E7A
- #455A64
- #37474F
- #263238
+
+
+
+
+
+
+
+
+
+
- #FCE4EC
- #F8BBD0
- #F48FB1
- #F06292
- #EC407A
- #E91E63
- #D81B60
- #C2185B
- #AD1457
- #880E4F
- #FF80AB
- #FF4081
- #F50057
- #C51162
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #E8EAF6
- #C5CAE9
- #9FA8DA
- #7986CB
- #5C6BC0
+
+
+
+
+
#3F51B5
- #3949AB
- #303F9F
- #283593
- #1A237E
- #8C9EFF
- #536DFE
- #3D5AFE
- #304FFE
+
+
+
+
+
+
+
+
- #E0F7FA
- #B2EBF2
- #80DEEA
- #4DD0E1
- #26C6DA
- #00BCD4
- #00ACC1
- #0097A7
- #00838F
- #006064
- #84FFFF
- #18FFFF
- #00E5FF
- #00B8D4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #F1F8E9
- #DCEDC8
- #C5E1A5
- #AED581
- #9CCC65
- #8BC34A
- #7CB342
- #689F38
- #558B2F
- #33691E
- #CCFF90
- #B2FF59
- #76FF03
- #64DD17
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #FFF8E1
- #FFECB3
- #FFE082
- #FFD54F
- #FFCA28
- #FFC107
- #FFB300
- #FFA000
- #FF8F00
- #FF6F00
- #FFE57F
- #FFD740
- #FFC400
- #FFAB00
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #EFEBE9
- #D7CCC8
- #BCAAA4
- #A1887F
- #8D6E63
- #795548
- #6D4C41
- #5D4037
- #4E342E
- #3E2723
+
+
+
+
+
+
+
+
+
+
- #F3E5F5
- #E1BEE7
- #CE93D8
- #BA68C8
- #AB47BC
- #9C27B0
- #8E24AA
- #7B1FA2
- #6A1B9A
- #4A148C
- #EA80FC
- #E040FB
- #D500F9
- #AA00FF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #E3F2FD
- #BBDEFB
- #90CAF9
- #64B5F6
- #42A5F5
- #2196F3
- #1E88E5
- #1976D2
- #1565C0
- #0D47A1
- #82B1FF
- #448AFF
- #2979FF
- #2962FF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #E0F2F1
- #B2DFDB
- #80CBC4
- #4DB6AC
- #26A69A
- #009688
- #00897B
- #00796B
- #00695C
- #004D40
- #A7FFEB
- #64FFDA
- #1DE9B6
- #00BFA5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #F9FBE7
- #F0F4C3
- #E6EE9C
- #DCE775
- #D4E157
- #CDDC39
- #C0CA33
- #AFB42B
- #9E9D24
- #827717
- #F4FF81
- #EEFF41
- #C6FF00
- #AEEA00
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #FFF3E0
- #FFE0B2
- #FFCC80
- #FFB74D
- #FFA726
- #FF9800
- #FB8C00
- #F57C00
- #EF6C00
- #E65100
- #FFD180
- #FFAB40
- #FF9100
- #FF6D00
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- #FAFAFA
+
#F5F5F5
- #EEEEEE
- #E0E0E0
- #BDBDBD
+
+
+
#9E9E9E
- #757575
- #616161
- #424242
- #212121
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index 74258a4ab..045683958 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -1,6 +1,4 @@
- 16dp
- 16dp
20dp
42dp
@@ -13,7 +11,7 @@
- @string/interval_8_hour
-
+
- 15
- 30
- 60
diff --git a/app/src/main/res/values/fontawesome.xml b/app/src/main/res/values/fontawesome.xml
index 8b20b647d..d760dbfe0 100644
--- a/app/src/main/res/values/fontawesome.xml
+++ b/app/src/main/res/values/fontawesome.xml
@@ -1,372 +1,373 @@
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8795e7a86..cd1e5b642 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -18,7 +18,6 @@
Nothing to redo.
Habit changed.
Habit changed back.
- Repetition toggled.
Habits archived.
Habits unarchived.
@@ -49,7 +48,6 @@
Habit strength
History
Clear
- Description
Question (Did you … today?)
Repeat
times in
@@ -111,6 +109,7 @@
Weekdays
Any day
Select days
+ Export data
- @string/hint_drag
diff --git a/app/src/main/res/xml/widget_checkmark_info.xml b/app/src/main/res/xml/widget_checkmark_info.xml
new file mode 100644
index 000000000..bd169b0d6
--- /dev/null
+++ b/app/src/main/res/xml/widget_checkmark_info.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/widget_history_info.xml b/app/src/main/res/xml/widget_history_info.xml
new file mode 100644
index 000000000..b02ef8079
--- /dev/null
+++ b/app/src/main/res/xml/widget_history_info.xml
@@ -0,0 +1,14 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/widget_score_info.xml b/app/src/main/res/xml/widget_score_info.xml
new file mode 100644
index 000000000..22d3de7ff
--- /dev/null
+++ b/app/src/main/res/xml/widget_score_info.xml
@@ -0,0 +1,14 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/widget_streak_info.xml b/app/src/main/res/xml/widget_streak_info.xml
new file mode 100644
index 000000000..60d32c780
--- /dev/null
+++ b/app/src/main/res/xml/widget_streak_info.xml
@@ -0,0 +1,14 @@
+
+
+
+
\ No newline at end of file
diff --git a/libs/drag-sort-listview b/libs/drag-sort-listview
index e8905e2c7..318d69cf6 160000
--- a/libs/drag-sort-listview
+++ b/libs/drag-sort-listview
@@ -1 +1 @@
-Subproject commit e8905e2c78d27bc064d03496abea3a0956e49b18
+Subproject commit 318d69cf6b2adc287cf8944bb847dd7139c60376
diff --git a/screenshots/original/uhabits5.png b/screenshots/original/uhabits5.png
new file mode 100644
index 000000000..022a4bf86
Binary files /dev/null and b/screenshots/original/uhabits5.png differ
diff --git a/screenshots/thumbs/uhabits5.png b/screenshots/thumbs/uhabits5.png
new file mode 100644
index 000000000..b9454844e
Binary files /dev/null and b/screenshots/thumbs/uhabits5.png differ