@ -0,0 +1,93 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="uHabits" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="android-gradle" name="Android-Gradle">
|
||||||
|
<configuration>
|
||||||
|
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
<facet type="android" name="Android">
|
||||||
|
<configuration>
|
||||||
|
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||||
|
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
||||||
|
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||||
|
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||||
|
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
|
||||||
|
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
|
||||||
|
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
|
||||||
|
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||||
|
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||||
|
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||||
|
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||||
|
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||||
|
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="ActiveAndroid" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
@ -0,0 +1,24 @@
|
|||||||
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 22
|
||||||
|
buildToolsVersion "21.1.2"
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "org.isoron.uhabits"
|
||||||
|
minSdkVersion 21
|
||||||
|
targetSdkVersion 22
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile 'com.android.support:support-v4:22.0.0'
|
||||||
|
compile files('libs/ActiveAndroid.jar')
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<lint>
|
||||||
|
</lint>
|
@ -1,7 +1,17 @@
|
|||||||
package org.isoron.helpers;
|
package org.isoron.helpers;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
|
||||||
public class ColorHelper
|
public class ColorHelper
|
||||||
{
|
{
|
||||||
|
public static final int[] palette = { Color.parseColor("#900000"),
|
||||||
|
Color.parseColor("#c54100"), Color.parseColor("#c0ab00"),
|
||||||
|
Color.parseColor("#8db600"), Color.parseColor("#117209"),
|
||||||
|
Color.parseColor("#06965b"), Color.parseColor("#069a95"),
|
||||||
|
Color.parseColor("#114896"), Color.parseColor("#501394"),
|
||||||
|
Color.parseColor("#872086"), Color.parseColor("#c31764"),
|
||||||
|
Color.parseColor("#000000"), Color.parseColor("#aaaaaa") };
|
||||||
|
|
||||||
public static int mixColors(int color1, int color2, float amount)
|
public static int mixColors(int color1, int color2, float amount)
|
||||||
{
|
{
|
||||||
final byte ALPHA_CHANNEL = 24;
|
final byte ALPHA_CHANNEL = 24;
|
@ -0,0 +1,185 @@
|
|||||||
|
package org.isoron.uhabits;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.isoron.helpers.Command;
|
||||||
|
import org.isoron.uhabits.dialogs.ListHabitsFragment;
|
||||||
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
public class MainActivity extends Activity
|
||||||
|
{
|
||||||
|
private static int MAX_UNDO_LEVEL = 15;
|
||||||
|
private ListHabitsFragment listHabitsFragment;
|
||||||
|
private LinkedList<Command> undoList;
|
||||||
|
private LinkedList<Command> redoList;
|
||||||
|
|
||||||
|
private Toast toast;
|
||||||
|
|
||||||
|
public static void createReminderAlarms(Context context)
|
||||||
|
{
|
||||||
|
for (Habit habit : Habit.getHabitsWithReminder())
|
||||||
|
createReminderAlarm(context, habit, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createReminderAlarm(Context context, Habit habit, Long reminderTime)
|
||||||
|
{
|
||||||
|
Uri uri = Uri.parse("content://org.isoron.uhabits/habit/" + habit.getId());
|
||||||
|
|
||||||
|
if (reminderTime == null)
|
||||||
|
{
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, habit.reminder_hour);
|
||||||
|
calendar.set(Calendar.MINUTE, habit.reminder_min);
|
||||||
|
calendar.set(Calendar.SECOND, 0);
|
||||||
|
|
||||||
|
reminderTime = calendar.getTimeInMillis();
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() > reminderTime)
|
||||||
|
{
|
||||||
|
reminderTime += AlarmManager.INTERVAL_DAY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent alarmIntent = new Intent(context, ReminderAlarmReceiver.class);
|
||||||
|
alarmIntent.setAction(ReminderAlarmReceiver.ACTION_REMIND);
|
||||||
|
alarmIntent.setData(uri);
|
||||||
|
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
|
||||||
|
((int) (habit.getId() % Integer.MAX_VALUE)) + 1,
|
||||||
|
alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
if (Build.VERSION.SDK_INT >= 19)
|
||||||
|
{
|
||||||
|
manager.setExact(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
manager.set(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d("Alarm", String.format("Setting alarm (%s): %s", DateFormat.getDateTimeInstance()
|
||||||
|
.format(new Date(reminderTime)), habit.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getActionBar().setElevation(5);
|
||||||
|
|
||||||
|
setContentView(R.layout.list_habits_activity);
|
||||||
|
|
||||||
|
listHabitsFragment = (ListHabitsFragment) getFragmentManager().findFragmentById(
|
||||||
|
R.id.fragment1);
|
||||||
|
|
||||||
|
Log.d("MainActivity", "Creating activity");
|
||||||
|
|
||||||
|
undoList = new LinkedList<>();
|
||||||
|
redoList = new LinkedList<>();
|
||||||
|
|
||||||
|
createReminderAlarms(MainActivity.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
super.onStart();
|
||||||
|
listHabitsFragment.notifyDataSetChanged();
|
||||||
|
Log.d("MainActivity", "Starting activity");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
|
{
|
||||||
|
getMenuInflater().inflate(R.menu.main_activity, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
|
{
|
||||||
|
int id = item.getItemId();
|
||||||
|
if (id == R.id.action_settings)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void executeCommand(Command command, boolean datasetChanged)
|
||||||
|
{
|
||||||
|
executeCommand(command, datasetChanged, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void executeCommand(Command command, boolean datasetChanged, boolean clearRedoStack)
|
||||||
|
{
|
||||||
|
undoList.push(command);
|
||||||
|
if (undoList.size() > MAX_UNDO_LEVEL)
|
||||||
|
undoList.removeLast();
|
||||||
|
if (clearRedoStack)
|
||||||
|
redoList.clear();
|
||||||
|
command.execute();
|
||||||
|
|
||||||
|
showToast(command.getExecuteStringId());
|
||||||
|
if (datasetChanged)
|
||||||
|
{
|
||||||
|
listHabitsFragment.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void undo()
|
||||||
|
{
|
||||||
|
if (undoList.isEmpty())
|
||||||
|
{
|
||||||
|
showToast(R.string.toast_nothing_to_undo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Command last = undoList.pop();
|
||||||
|
redoList.push(last);
|
||||||
|
last.undo();
|
||||||
|
showToast(last.getUndoStringId());
|
||||||
|
|
||||||
|
listHabitsFragment.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void redo()
|
||||||
|
{
|
||||||
|
if (redoList.isEmpty())
|
||||||
|
{
|
||||||
|
showToast(R.string.toast_nothing_to_redo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Command last = redoList.pop();
|
||||||
|
executeCommand(last, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showToast(Integer stringId)
|
||||||
|
{
|
||||||
|
if (stringId == null)
|
||||||
|
return;
|
||||||
|
if (toast == null)
|
||||||
|
toast = Toast.makeText(this, stringId, Toast.LENGTH_SHORT);
|
||||||
|
else
|
||||||
|
toast.setText(stringId);
|
||||||
|
toast.show();
|
||||||
|
}
|
||||||
|
}
|
Before Width: | Height: | Size: 196 B After Width: | Height: | Size: 196 B |
Before Width: | Height: | Size: 187 B After Width: | Height: | Size: 187 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 290 B After Width: | Height: | Size: 290 B |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 181 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 432 B After Width: | Height: | Size: 432 B |
Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B |
Before Width: | Height: | Size: 552 B After Width: | Height: | Size: 552 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 618 B After Width: | Height: | Size: 618 B |
Before Width: | Height: | Size: 164 B After Width: | Height: | Size: 164 B |
Before Width: | Height: | Size: 151 B After Width: | Height: | Size: 151 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 256 B After Width: | Height: | Size: 256 B |
Before Width: | Height: | Size: 134 B After Width: | Height: | Size: 134 B |
Before Width: | Height: | Size: 129 B After Width: | Height: | Size: 129 B |
Before Width: | Height: | Size: 337 B After Width: | Height: | Size: 337 B |
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 192 B |
Before Width: | Height: | Size: 394 B After Width: | Height: | Size: 394 B |
Before Width: | Height: | Size: 694 B After Width: | Height: | Size: 694 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 435 B After Width: | Height: | Size: 435 B |
Before Width: | Height: | Size: 231 B After Width: | Height: | Size: 231 B |
Before Width: | Height: | Size: 220 B After Width: | Height: | Size: 220 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 426 B After Width: | Height: | Size: 426 B |
Before Width: | Height: | Size: 201 B After Width: | Height: | Size: 201 B |
Before Width: | Height: | Size: 189 B After Width: | Height: | Size: 189 B |
Before Width: | Height: | Size: 488 B After Width: | Height: | Size: 488 B |
Before Width: | Height: | Size: 289 B After Width: | Height: | Size: 289 B |
Before Width: | Height: | Size: 716 B After Width: | Height: | Size: 716 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |