Initial commit with project files + first version

This commit is contained in:
2017-07-27 01:40:27 +02:00
commit fed0dbff87
39 changed files with 798 additions and 0 deletions

1
app/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

29
app/build.gradle Normal file
View File

@@ -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'
}

25
app/proguard-rules.pro vendored Normal file
View File

@@ -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

View File

@@ -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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@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());
}
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="be.mathsaey.stoofnogaan">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -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));
}
}
}

View File

@@ -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);
}
}
});
}
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="be.mathsaey.stoofnogaan.MainActivity">
<LinearLayout
android:id="@+id/tasks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<Button
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/task_new"
android:onClick="onNewTaskButtonClick"/>
</LinearLayout>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@null"/>
<EditText
android:id="@+id/textView"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/task_hint"/>
</LinearLayout>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"/>
<item
android:title="@string/settings_text"
android:icon="@android:drawable/ic_menu_preferences"
android:showAsAction="always"/>
</menu>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@@ -0,0 +1,9 @@
<resources>
<string name="app_name">Stoof nog aan?</string>
<string name="task_new">Nieuwe Stoof</string>
<string name="task_hint">Lege Stoof</string>
<string name="settings_text">Stoof Instellen</string>
<string name="taken_text">Nieuwe Stoof</string>
</resources>

View File

@@ -0,0 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>

View File

@@ -0,0 +1,17 @@
package be.mathsaey.stoofnogaan;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}