From fed0dbff87433748e4b13bb22d65a8a55104831a Mon Sep 17 00:00:00 2001 From: Mathijs Saey Date: Thu, 27 Jul 2017 01:40:27 +0200 Subject: [PATCH] Initial commit with project files + first version --- .gitignore | 9 + .idea/compiler.xml | 22 +++ .idea/copyright/profiles_settings.xml | 3 + .idea/gradle.xml | 18 ++ .idea/misc.xml | 46 +++++ .idea/modules.xml | 9 + .idea/runConfigurations.xml | 12 ++ .idea/vcs.xml | 6 + app/.gitignore | 1 + app/build.gradle | 29 ++++ app/proguard-rules.pro | 25 +++ .../stoofnogaan/ExampleInstrumentedTest.java | 26 +++ app/src/main/AndroidManifest.xml | 21 +++ .../be/mathsaey/stoofnogaan/MainActivity.java | 109 ++++++++++++ .../be/mathsaey/stoofnogaan/TaskView.java | 73 ++++++++ app/src/main/res/layout/activity_main.xml | 24 +++ app/src/main/res/layout/task.xml | 20 +++ app/src/main/res/menu/menu_main.xml | 8 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4208 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2555 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6114 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10056 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 14696 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/strings.xml | 9 + app/src/main/res/values/styles.xml | 8 + .../mathsaey/stoofnogaan/ExampleUnitTest.java | 17 ++ build.gradle | 23 +++ gradle.properties | 17 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 ++++++++++++++++++ gradlew.bat | 90 ++++++++++ settings.gradle | 1 + 39 files changed, 798 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/be/mathsaey/stoofnogaan/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/be/mathsaey/stoofnogaan/MainActivity.java create mode 100644 app/src/main/java/be/mathsaey/stoofnogaan/TaskView.java create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/task.xml create mode 100644 app/src/main/res/menu/menu_main.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/be/mathsaey/stoofnogaan/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d19981 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..48bfe44 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..aa8f431 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + buildToolsVersion "26.0.1" + defaultConfig { + applicationId "be.mathsaey.stoofnogaan" + minSdkVersion 21 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..7fee49b --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/mathsaey/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/be/mathsaey/stoofnogaan/ExampleInstrumentedTest.java b/app/src/androidTest/java/be/mathsaey/stoofnogaan/ExampleInstrumentedTest.java new file mode 100644 index 0000000..1e40355 --- /dev/null +++ b/app/src/androidTest/java/be/mathsaey/stoofnogaan/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package be.mathsaey.stoofnogaan; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("be.mathsaey.stoofnogaan", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..fe4e954 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/be/mathsaey/stoofnogaan/MainActivity.java b/app/src/main/java/be/mathsaey/stoofnogaan/MainActivity.java new file mode 100644 index 0000000..d97f453 --- /dev/null +++ b/app/src/main/java/be/mathsaey/stoofnogaan/MainActivity.java @@ -0,0 +1,109 @@ +package be.mathsaey.stoofnogaan; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.view.Menu; +import android.view.View; +import android.widget.LinearLayout; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +public class MainActivity extends Activity { + + // View which contains all the tasks + private LinearLayout taskView; + private TaskView lastChild; + + private final String TASKS_FILE = "tasks.txt"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + taskView = findViewById(R.id.tasks); + loadFromFile(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + writeToFile(); + taskView.removeAllViews(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + public void onNewTaskButtonClick(View v) { + if (lastChild == null || !lastChild.isEmpty()) { + TaskView task = new TaskView(this); + taskView.addView(task); + lastChild = task; + } + } + + public void deleteTask(TaskView v) { + taskView.removeView(v); + + if (taskView.getChildCount() == 0){ + lastChild = null; + } + } + + private void writeToFile() { + try { + FileOutputStream output = openFileOutput(TASKS_FILE, Context.MODE_PRIVATE); + + for (int i = 0; i < taskView.getChildCount(); i++) { + TaskView v = (TaskView) taskView.getChildAt(i); + if (!v.isEmpty()) { + String s = v.toString() + "\n"; + output.write(s.getBytes()); + } + } + + output.close(); + } + catch (FileNotFoundException e) { + Log.e(BuildConfig.APPLICATION_ID, "Could not find file for writing, that's weird..."); + } + catch (IOException e) { + Log.e(BuildConfig.APPLICATION_ID, "Error when trying to write, deleting"); + + } + } + + private void loadFromFile() { + try { + FileInputStream input = openFileInput(TASKS_FILE); + + InputStreamReader streamReader = new InputStreamReader(input); + BufferedReader bufferedReader = new BufferedReader(streamReader); + String line; + + while ((line = bufferedReader.readLine()) != null) { + TaskView task = new TaskView(this, line); + taskView.addView(task); + lastChild = task; + } + input.close(); + } + catch (IOException e) {} + catch (Exception e) { + Log.w(BuildConfig.APPLICATION_ID, Log.getStackTraceString(e)); + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/be/mathsaey/stoofnogaan/TaskView.java b/app/src/main/java/be/mathsaey/stoofnogaan/TaskView.java new file mode 100644 index 0000000..b0fb84e --- /dev/null +++ b/app/src/main/java/be/mathsaey/stoofnogaan/TaskView.java @@ -0,0 +1,73 @@ +package be.mathsaey.stoofnogaan; + +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.LinearLayout; + +class TaskView extends LinearLayout { + private MainActivity parent; + + protected CheckBox checkBox; + protected EditText textView; + + public TaskView(MainActivity p) { + super(p); + + LayoutInflater.from(p).inflate(R.layout.task, this); + + parent = p; + checkBox = findViewById(R.id.checkBox); + textView = findViewById(R.id.textView); + + addTextListeners(); + } + + public TaskView(MainActivity p, String s) { + this(p); + + if (!s.isEmpty()) { + Log.d(BuildConfig.APPLICATION_ID, s); + String[] split = s.split("\\t"); + checkBox.setChecked(split[0].equalsIgnoreCase("true")); + textView.setText(split[1]); + } + } + + public boolean isEmpty() { + return textView.getText().length() == 0; + } + + public String toString() { + return String.format("%s\t%s", checkBox.isChecked(), textView.getText()); + } + + // Android is horrible, this code tries to figure out when the user finished editing. + // When this is the case, check if the text field is empty, delete the taskview if this is + // the case. + private void addTextListeners() { + // When done is clicked... + // Or not because that is when things start to go boom +// textView.setOnEditorActionListener(new TextView.OnEditorActionListener() { +// @Override +// public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { +// if (i == EditorInfo.IME_ACTION_DONE && TaskView.this.isEmpty()) { +// parent.deleteTask(TaskView.this); +// return true; +// } +// return false; +// } +// }); + // Or when we lose focus + textView.setOnFocusChangeListener(new OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean b) { + if (!b && TaskView.this.isEmpty()) { + parent.deleteTask(TaskView.this); + } + } + }); + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b3eeaba --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,24 @@ + + + + + + +