forked from iSoron/uhabits
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
190 changed files
with
1,124 additions
and
1,036 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<lint> | ||
</lint> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 11 additions & 1 deletion
12
src/org/isoron/helpers/ColorHelper.java → .../java/org/isoron/helpers/ColorHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.