diff --git a/prog_android/ToDoList/.gitignore b/prog_android/ToDoList/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/prog_android/ToDoList/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/prog_android/ToDoList/.idea/.gitignore b/prog_android/ToDoList/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/prog_android/ToDoList/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/prog_android/ToDoList/.idea/.name b/prog_android/ToDoList/.idea/.name new file mode 100644 index 0000000..386985f --- /dev/null +++ b/prog_android/ToDoList/.idea/.name @@ -0,0 +1 @@ +ToDo-List \ No newline at end of file diff --git a/prog_android/ToDoList/.idea/compiler.xml b/prog_android/ToDoList/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/prog_android/ToDoList/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/.idea/deploymentTargetDropDown.xml b/prog_android/ToDoList/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..0c0c338 --- /dev/null +++ b/prog_android/ToDoList/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/.idea/gradle.xml b/prog_android/ToDoList/.idea/gradle.xml new file mode 100644 index 0000000..0897082 --- /dev/null +++ b/prog_android/ToDoList/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/.idea/inspectionProfiles/Project_Default.xml b/prog_android/ToDoList/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..44ca2d9 --- /dev/null +++ b/prog_android/ToDoList/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,41 @@ + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/.idea/kotlinc.xml b/prog_android/ToDoList/.idea/kotlinc.xml new file mode 100644 index 0000000..fdf8d99 --- /dev/null +++ b/prog_android/ToDoList/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/.idea/migrations.xml b/prog_android/ToDoList/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/prog_android/ToDoList/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/.idea/misc.xml b/prog_android/ToDoList/.idea/misc.xml new file mode 100644 index 0000000..8978d23 --- /dev/null +++ b/prog_android/ToDoList/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/.idea/vcs.xml b/prog_android/ToDoList/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/prog_android/ToDoList/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/app/.gitignore b/prog_android/ToDoList/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/prog_android/ToDoList/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/prog_android/ToDoList/app/build.gradle.kts b/prog_android/ToDoList/app/build.gradle.kts new file mode 100644 index 0000000..630c18b --- /dev/null +++ b/prog_android/ToDoList/app/build.gradle.kts @@ -0,0 +1,39 @@ +plugins { + id("com.android.application") +} + +android { + namespace = "fr.univpau.todo_list" + compileSdk = 34 + + defaultConfig { + applicationId = "fr.univpau.todo_list" + minSdk = 29 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation("androidx.appcompat:appcompat:1.7.0") + implementation("com.google.android.material:material:1.12.0") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.2.1") + androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1") +} \ No newline at end of file diff --git a/prog_android/ToDoList/app/proguard-rules.pro b/prog_android/ToDoList/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/prog_android/ToDoList/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# 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 \ No newline at end of file diff --git a/prog_android/ToDoList/app/src/androidTest/java/fr/univpau/todo_list/ExampleInstrumentedTest.java b/prog_android/ToDoList/app/src/androidTest/java/fr/univpau/todo_list/ExampleInstrumentedTest.java new file mode 100644 index 0000000..24c0825 --- /dev/null +++ b/prog_android/ToDoList/app/src/androidTest/java/fr/univpau/todo_list/ExampleInstrumentedTest.java @@ -0,0 +1,24 @@ +package fr.univpau.todo_list; + +import android.content.Context; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("fr.univpau.todo_list", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/prog_android/ToDoList/app/src/main/AndroidManifest.xml b/prog_android/ToDoList/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..369ae34 --- /dev/null +++ b/prog_android/ToDoList/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/TodoList.java b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/TodoList.java new file mode 100644 index 0000000..4e9bf54 --- /dev/null +++ b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/TodoList.java @@ -0,0 +1,74 @@ +package fr.univpau.todo_list; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.Menu; +import android.widget.Button; +import android.widget.ListView; + +import java.util.ArrayList; + +import fr.univpau.todo_list.adapters.TaskAdapter; +import fr.univpau.todo_list.entities.Task; +import fr.univpau.todo_list.listeners.AddTaskButtonListener; + +public class TodoList extends AppCompatActivity { + ArrayList tasks = new ArrayList<>(); + TaskAdapter taskAdapter; + + /** + * Called when the activity is starting. + * @param savedInstanceState If the activity is being re-initialized after + * previously being shut down then this Bundle contains the data it most + * recently supplied in {@link #onSaveInstanceState}. Note: Otherwise it is null. + * + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_todo_list); + Button addTaskButton = findViewById(R.id.addTaskButton); + ListView taskList = findViewById(R.id.taskList); + this.taskAdapter = new TaskAdapter(this, tasks); + taskList.setAdapter(this.taskAdapter); + + addTaskButton.setOnClickListener(new AddTaskButtonListener(findViewById(R.id.addTaskText), this.taskAdapter)); + } + + /** + * Initialize the contents of the Activity's standard options menu. + * @param menu The options menu in which you place your items. + * + * @return true + */ + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.menu, menu); + return true; + } + + /** + * This method is called when an item in the options menu is selected. + * @param item The menu item that was selected. + * + * @return true + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.menuRemoveAll) { + this.taskAdapter.removeAll(); + return true; + } + if (item.getItemId() == R.id.menuRemoveChecked) { + this.taskAdapter.removeChecked(); + return true; + } + return super.onOptionsItemSelected(item); + + } + +} \ No newline at end of file diff --git a/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/adapters/TaskAdapter.java b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/adapters/TaskAdapter.java new file mode 100644 index 0000000..4ad3cf6 --- /dev/null +++ b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/adapters/TaskAdapter.java @@ -0,0 +1,100 @@ +package fr.univpau.todo_list.adapters; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.view.LayoutInflater; +import android.widget.CheckBox; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; + +import java.util.ArrayList; + +import fr.univpau.todo_list.R; +import fr.univpau.todo_list.entities.Task; +import fr.univpau.todo_list.listeners.OnCheckTaskListener; + + +public class TaskAdapter extends ArrayAdapter { + + ArrayList tasks; + + public TaskAdapter(Context context, ArrayList tasks) { + super(context, 0); + this.tasks = tasks; + } + + @NonNull + @Override + public View getView(int position, View convertView, ViewGroup parent) { + // Check if the view is already created + if (convertView == null) { + LayoutInflater layoutInflater = LayoutInflater.from(getContext()); + convertView = layoutInflater.inflate(R.layout.task_list, null); + } + // Get the task + Task task = getItem(position); + if (task == null) { + return convertView; + } + // Get the views + TextView taskName = convertView.findViewById(R.id.taskName); + TextView taskDate = convertView.findViewById(R.id.taskDate); + CheckBox taskDone = convertView.findViewById(R.id.taskCheck); + + // Set the task data + taskDone.setOnCheckedChangeListener(null); + taskName.setText(task.getName()); + taskDate.setText(task.getDate().toString()); + taskDone.setChecked(task.isDone()); + taskDone.setOnCheckedChangeListener(new OnCheckTaskListener(task)); + + return convertView; + + } + + /** + * Add a task to the list + * @param task + */ + public void addTask(Task task) { + add(task); + } + + /** + * Remove all the tasks from the list + */ + public void removeAll() { + if (getCount() == 0) { + Toast.makeText(this.getContext(), "Aucune tâche à supprimer", Toast.LENGTH_SHORT).show(); + return; + } + clear(); + Toast.makeText(this.getContext(), "Toutes les tâches ont été supprimées", Toast.LENGTH_SHORT).show(); + + } + + /** + * Remove all the checked tasks from the list + */ + public void removeChecked() { + int counter = 0; + for (int i = 0; i < getCount(); i++) { + Task task = getItem(i); + if (task.isDone()) { + remove(task); + i--; + counter++; + } + } + if (counter == 0) { + Toast.makeText(this.getContext(), "Aucune tâche à supprimée", Toast.LENGTH_SHORT).show(); + return; + } + Toast.makeText(this.getContext(), counter + " tâches ont été supprimée", Toast.LENGTH_SHORT).show(); + + } +} diff --git a/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/entities/Task.java b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/entities/Task.java new file mode 100644 index 0000000..8316781 --- /dev/null +++ b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/entities/Task.java @@ -0,0 +1,31 @@ +package fr.univpau.todo_list.entities; + +import java.util.Date; + +public class Task { + private final String name; + private boolean done; + private final Date date; + + public Task(String name) { + this.name = name; + this.done = false; + this.date = new Date(); + } + + public String getName() { + return name; + } + + public boolean isDone() { + return done; + } + + public void setDone(boolean done) { + this.done = done; + } + + public Date getDate() { + return date; + } +} diff --git a/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/listeners/AddTaskButtonListener.java b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/listeners/AddTaskButtonListener.java new file mode 100644 index 0000000..9401116 --- /dev/null +++ b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/listeners/AddTaskButtonListener.java @@ -0,0 +1,35 @@ +package fr.univpau.todo_list.listeners; + +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +import fr.univpau.todo_list.entities.Task; +import fr.univpau.todo_list.adapters.TaskAdapter; + +public class AddTaskButtonListener implements View.OnClickListener { + + EditText taskName; + + TaskAdapter taskAdapter; + + public AddTaskButtonListener(EditText taskName, TaskAdapter taskAdapter) { + this.taskName = taskName; + this.taskAdapter = taskAdapter; + } + + @Override + public void onClick(View v) { + // Check if the task name is empty + if (taskName.getText().toString().isEmpty()) { + Toast.makeText(v.getContext(), "Le nom de la tâche ne peut pas être vide", Toast.LENGTH_SHORT).show(); + return; + } + // Add the task to the list + Task task = new Task(taskName.getText().toString()); + taskAdapter.addTask(task); + taskName.setText(""); + // Notify the user that the task has been created + Toast.makeText(v.getContext(), "Une nouvelle tâche à été crée", Toast.LENGTH_SHORT).show(); + } +} diff --git a/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/listeners/OnCheckTaskListener.java b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/listeners/OnCheckTaskListener.java new file mode 100644 index 0000000..7d4ab6a --- /dev/null +++ b/prog_android/ToDoList/app/src/main/java/fr/univpau/todo_list/listeners/OnCheckTaskListener.java @@ -0,0 +1,24 @@ +package fr.univpau.todo_list.listeners; + +import android.widget.CompoundButton; + +import fr.univpau.todo_list.entities.Task; + +public class OnCheckTaskListener implements CompoundButton.OnCheckedChangeListener { + + private Task task; + + public OnCheckTaskListener(Task task) { + this.task = task; + } + + /** + * Called when the checked state of a compound button has changed. + * @param checkbox The compound button view whose state has changed. + * @param isChecked The new checked state of buttonView. + */ + @Override + public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) { + task.setDone(isChecked); + } +} diff --git a/prog_android/ToDoList/app/src/main/res/drawable/ic_launcher_background.xml b/prog_android/ToDoList/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/prog_android/ToDoList/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prog_android/ToDoList/app/src/main/res/drawable/ic_launcher_foreground.xml b/prog_android/ToDoList/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/prog_android/ToDoList/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/prog_android/ToDoList/app/src/main/res/layout/activity_todo_list.xml b/prog_android/ToDoList/app/src/main/res/layout/activity_todo_list.xml new file mode 100644 index 0000000..68f33ad --- /dev/null +++ b/prog_android/ToDoList/app/src/main/res/layout/activity_todo_list.xml @@ -0,0 +1,38 @@ + + + + + + +