From 1a62f959f1a9955dba52110d2400b6e7f353478e Mon Sep 17 00:00:00 2001 From: Rito <116003382+vinhnamhai321@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:31:45 +0700 Subject: [PATCH 1/5] Add toDoButton and musicButton --- .../CustomUIComponent/MyButton.java | 11 ++- .../MainScreenActivity.java | 88 ++++++++++++++++--- app/src/main/res/drawable/music.xml | 20 +++++ app/src/main/res/drawable/note.xml | 9 ++ .../main/res/layout/activity_main_screen.xml | 56 ++++++++++++ app/src/main/res/values/styles.xml | 2 +- 6 files changed, 170 insertions(+), 16 deletions(-) create mode 100644 app/src/main/res/drawable/music.xml create mode 100644 app/src/main/res/drawable/note.xml diff --git a/app/src/main/java/com/hfad/cs426_final_project/CustomUIComponent/MyButton.java b/app/src/main/java/com/hfad/cs426_final_project/CustomUIComponent/MyButton.java index 873b569..d48c5e1 100644 --- a/app/src/main/java/com/hfad/cs426_final_project/CustomUIComponent/MyButton.java +++ b/app/src/main/java/com/hfad/cs426_final_project/CustomUIComponent/MyButton.java @@ -47,18 +47,25 @@ private void init() { @Override public boolean onTouchEvent(MotionEvent event) { + int color; switch (event.getAction()) { + //case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN: // Change tint color when the button is pressed //DrawableCompat.setTint(originalDrawable, ContextCompat.getColor(getContext(), R.color.ripple_effect)); this.getBackground().setAlpha(128); + color = getCurrentTextColor(); + this.setTextColor(Color.argb(128, Color.red(color),Color.green(color),Color.blue(color))); break; - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: + //case MotionEvent.ACTION_UP: + //case MotionEvent.ACTION_CANCEL: + default: // Reset to the original tint color when the button is released //DrawableCompat.setTintList(originalDrawable, null); // Reset to the original tint this.getBackground().setAlpha(255); + color = getCurrentTextColor(); + this.setTextColor(Color.argb(255, Color.red(color),Color.green(color),Color.blue(color))); break; } return super.onTouchEvent(event); diff --git a/app/src/main/java/com/hfad/cs426_final_project/MainScreenActivity.java b/app/src/main/java/com/hfad/cs426_final_project/MainScreenActivity.java index 2a4d5e4..eb3b031 100644 --- a/app/src/main/java/com/hfad/cs426_final_project/MainScreenActivity.java +++ b/app/src/main/java/com/hfad/cs426_final_project/MainScreenActivity.java @@ -1,9 +1,14 @@ package com.hfad.cs426_final_project; +import android.annotation.SuppressLint; +import android.graphics.Color; import android.os.Bundle; import android.os.Handler; +import android.util.Log; +import android.view.MotionEvent; import android.view.View; import android.widget.Button; +import android.widget.LinearLayout; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; @@ -12,6 +17,7 @@ import com.hfad.cs426_final_project.CustomUIComponent.MyButton; import java.util.Locale; +import java.util.Objects; public class MainScreenActivity extends AppCompatActivity { //Number of seconds displayed on the stopwatch. @@ -20,15 +26,23 @@ public class MainScreenActivity extends AppCompatActivity { private boolean running; TextView timeView; - MyButton startButton; - ClickableImageView dropdownMenu, timer, stopwatch; + MyButton startButton, todoButton, musicButton; + ClickableImageView dropdownMenu, timer, stopwatch, todo, music ; + LinearLayout todoContainer, musicContainer; + @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_screen); + getUIReferences(); + startButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + } + }); - dropdownMenu = findViewById(R.id.dropdown_menu); dropdownMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -36,7 +50,15 @@ public void onClick(View v) { } }); - timer = findViewById(R.id.timer); + todoContainer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Log.d("debug","todoContainer"); + todo.setPressed(true); + + } + }); + timer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -44,27 +66,67 @@ public void onClick(View v) { } }); - stopwatch = findViewById(R.id.stopwatch); + stopwatch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); - getUIReferences(); - runTimer(); - } - private void getUIReferences() { - timeView = findViewById(R.id.time_view); - startButton = findViewById(R.id.plant_button); - startButton.setOnClickListener(new View.OnClickListener() { + musicContainer.setOnTouchListener(new View.OnTouchListener() { @Override - public void onClick(View v) { + public boolean onTouch(View v, MotionEvent event) { + v.performClick(); + // Pass the MotionEvent to the MyButton + + return true; // Return true to indicate the touch was handled + } + }); + + musicButton.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + musicButton.onTouchEvent(event); + boolean isPressed = false; + if (event.getAction() == MotionEvent.ACTION_DOWN) { + isPressed = true; + } + music.setPressed(isPressed); + return true; + } + }); + todoButton.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + todoButton.onTouchEvent(event); + boolean isPressed = false; + if (event.getAction() == MotionEvent.ACTION_DOWN) { + isPressed = true; + } + todo.setPressed(isPressed); + return true; } }); + + + runTimer(); + } + + private void getUIReferences() { + timeView = findViewById(R.id.time_view); + startButton = findViewById(R.id.plant_button); + dropdownMenu = findViewById(R.id.dropdown_menu); + todo = findViewById(R.id.todo_image); + todoButton = findViewById(R.id.todo_button); + stopwatch = findViewById(R.id.stopwatch); + timer = findViewById(R.id.timer); + musicContainer = findViewById(R.id.music_container); + todoContainer = findViewById(R.id.to_do_container); + music=findViewById(R.id.music_image); + musicButton=findViewById(R.id.music_button); } private void runTimer() { diff --git a/app/src/main/res/drawable/music.xml b/app/src/main/res/drawable/music.xml new file mode 100644 index 0000000..866f9d8 --- /dev/null +++ b/app/src/main/res/drawable/music.xml @@ -0,0 +1,20 @@ + + + + diff --git a/app/src/main/res/drawable/note.xml b/app/src/main/res/drawable/note.xml new file mode 100644 index 0000000..3ae1559 --- /dev/null +++ b/app/src/main/res/drawable/note.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_main_screen.xml b/app/src/main/res/layout/activity_main_screen.xml index 8deefca..874b5e3 100644 --- a/app/src/main/res/layout/activity_main_screen.xml +++ b/app/src/main/res/layout/activity_main_screen.xml @@ -37,6 +37,7 @@ android:background="@drawable/button_border" android:backgroundTint="@color/primary_20" android:text="@string/start" + style="@style/SubTitle" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.498" app:layout_constraintStart_toStartOf="parent" @@ -235,6 +236,61 @@ app:layout_constraintTop_toTopOf="parent" /> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 13243fd..b39ab86 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -26,7 +26,7 @@ \ No newline at end of file From f52d3441035d30984a4ad26575fdfcda349c8d7a Mon Sep 17 00:00:00 2001 From: Rito <116003382+vinhnamhai321@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:33:58 +0700 Subject: [PATCH 2/5] Update toDoButton and musicButton --- .../MainScreenActivity.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/src/main/java/com/hfad/cs426_final_project/MainScreenActivity.java b/app/src/main/java/com/hfad/cs426_final_project/MainScreenActivity.java index eb3b031..62ebed5 100644 --- a/app/src/main/java/com/hfad/cs426_final_project/MainScreenActivity.java +++ b/app/src/main/java/com/hfad/cs426_final_project/MainScreenActivity.java @@ -97,6 +97,19 @@ public boolean onTouch(View v, MotionEvent event) { } }); + music.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + musicButton.onTouchEvent(event); + boolean isPressed = false; + if (event.getAction() == MotionEvent.ACTION_DOWN) { + isPressed = true; + } + music.setPressed(isPressed); + return true; + } + }); + todoButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { @@ -110,6 +123,19 @@ public boolean onTouch(View v, MotionEvent event) { } }); + todo.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + todoButton.onTouchEvent(event); + boolean isPressed = false; + if (event.getAction() == MotionEvent.ACTION_DOWN) { + isPressed = true; + } + todo.setPressed(isPressed); + return true; + } + }); + runTimer(); From 0589533f2035f51f28a8a3b42421c9bf6d307227 Mon Sep 17 00:00:00 2001 From: Rito <116003382+vinhnamhai321@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:33:58 +0700 Subject: [PATCH 3/5] Update toDoButton and musicButton --- .idea/other.xml | 44 +++++++++++++++++++ .../MainScreenActivity.java | 26 +++++++++++ 2 files changed, 70 insertions(+) diff --git a/.idea/other.xml b/.idea/other.xml index 4604c44..1b1a2c5 100644 --- a/.idea/other.xml +++ b/.idea/other.xml @@ -69,6 +69,28 @@