Merge pull request #3 from r0r-5chach/background

change background completed
This commit is contained in:
Joshua Perry 2023-03-26 20:42:34 +01:00 committed by GitHub
commit 6f32f1e570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 44 additions and 12 deletions

View File

@ -5,5 +5,6 @@ public enum BtnID {
EDIT_BUTTON, EDIT_BUTTON,
DELETE_BUTTON, DELETE_BUTTON,
NOTES_BUTTON, NOTES_BUTTON,
QUIZ_BUTTON QUIZ_BUTTON,
BACKGROUND_BUTTON
} }

View File

@ -2,17 +2,28 @@ package xyz.r0r5chach.cpsAssist.main;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.view.View; import android.view.View;
import android.widget.LinearLayout;
import java.util.Locale; import java.util.Locale;
import java.util.Random;
import xyz.r0r5chach.cpsAssist.BtnID; import xyz.r0r5chach.cpsAssist.BtnID;
import xyz.r0r5chach.cpsAssist.R;
import xyz.r0r5chach.cpsAssist.quiz.QuizActivity; import xyz.r0r5chach.cpsAssist.quiz.QuizActivity;
import xyz.r0r5chach.cpsAssist.notes.NotesActivity; import xyz.r0r5chach.cpsAssist.notes.NotesActivity;
public class BtnOnClickListener implements View.OnClickListener{ public class BtnOnClickListener implements View.OnClickListener{
private String backgroundColor;
public BtnOnClickListener() {
backgroundColor = null;
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
LinearLayout l = (LinearLayout) v.getParent();
String id = v.getResources().getResourceName(v.getId()).split("/")[1]; String id = v.getResources().getResourceName(v.getId()).split("/")[1];
Intent intent = null; Intent intent = null;
switch(BtnID.valueOf(id.toUpperCase(Locale.ROOT))) { switch(BtnID.valueOf(id.toUpperCase(Locale.ROOT))) {
@ -22,10 +33,18 @@ public class BtnOnClickListener implements View.OnClickListener{
case QUIZ_BUTTON: case QUIZ_BUTTON:
intent = new Intent(v.getContext(), QuizActivity.class); intent = new Intent(v.getContext(), QuizActivity.class);
break; break;
case BACKGROUND_BUTTON:
Random rand = new Random();
backgroundColor = String.format("#%06x", rand.nextInt(0xffffff + 1));
l.setBackgroundColor(Color.parseColor(backgroundColor));
break;
} }
Activity main = (Activity) v.getContext(); Activity main = (Activity) v.getContext();
if (intent != null) { if (intent != null) {
intent.putExtra("username", main.getIntent().getStringExtra("username")); intent.putExtra("username", main.getIntent().getStringExtra("username"));
if (backgroundColor != null) {
intent.putExtra("background", backgroundColor);
}
main.startActivity(intent); main.startActivity(intent);
} }
} }

View File

@ -1,5 +1,6 @@
package xyz.r0r5chach.cpsAssist.main; package xyz.r0r5chach.cpsAssist.main;
import android.media.MediaDrm;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -22,7 +23,9 @@ public class MainActivity extends AppCompatActivity {
} //TODO: Add change background button to layout and add logic to listner } //TODO: Add change background button to layout and add logic to listner
private void initButtons() { private void initButtons() {
findViewById(R.id.notes_button).setOnClickListener(new BtnOnClickListener()); BtnOnClickListener lstn = new BtnOnClickListener();
findViewById(R.id.quiz_button).setOnClickListener(new BtnOnClickListener()); findViewById(R.id.notes_button).setOnClickListener(lstn);
findViewById(R.id.quiz_button).setOnClickListener(lstn);
findViewById(R.id.background_button).setOnClickListener(lstn);
} }
} }

View File

@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.widget.TextView; import android.widget.TextView;
@ -18,6 +19,9 @@ public class NotesActivity extends AppCompatActivity {
setContentView(R.layout.activity_notes); setContentView(R.layout.activity_notes);
initRecycler(); initRecycler();
setTitle("Notes- " + getIntent().getStringExtra("username")); setTitle("Notes- " + getIntent().getStringExtra("username"));
if (getIntent().hasExtra("background")) {
findViewById(R.id.notes_layout).setBackgroundColor(Color.parseColor(getIntent().getStringExtra("background")));
}
findViewById(R.id.add_Button).setOnClickListener(new BtnOnClickListener(adapter)); findViewById(R.id.add_Button).setOnClickListener(new BtnOnClickListener(adapter));
} }

View File

@ -1,5 +1,6 @@
package xyz.r0r5chach.cpsAssist.quiz; package xyz.r0r5chach.cpsAssist.quiz;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -21,6 +22,9 @@ public class QuizActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz); setContentView(R.layout.activity_quiz);
setTitle("Quiz- " + getIntent().getStringExtra("username")); setTitle("Quiz- " + getIntent().getStringExtra("username"));
if (getIntent().hasExtra("background")) {
findViewById(R.id.quiz_layout).setBackgroundColor(Color.parseColor(getIntent().getStringExtra("background")));
}
LinearLayout layout = findViewById(R.id.quiz_layout); LinearLayout layout = findViewById(R.id.quiz_layout);
quiz = new Quiz(getString(R.string.questions), getString(R.string.correct_answers), getString(R.string.incorrect_answers)); quiz = new Quiz(getString(R.string.questions), getString(R.string.correct_answers), getString(R.string.incorrect_answers));
initQuestions(layout); initQuestions(layout);

View File

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/main_layout"
android:orientation="vertical"> android:orientation="vertical">
<Button <Button
@ -15,4 +16,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/quiz_button_text" /> android:text="@string/quiz_button_text" />
<Button
android:id="@+id/background_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/change_background_button_text" />
</LinearLayout> </LinearLayout>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/notes_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"

View File

@ -1,4 +1,4 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources>
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="Theme.CpsAssist" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <style name="Theme.CpsAssist" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. --> <!-- Primary brand color. -->
@ -13,8 +13,4 @@
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
</style> </style>
<style name="edit_dialog">
<item name="android:background">@color/white</item>
<item name="android:textColor">@color/black</item>
</style>
</resources> </resources>

View File

@ -17,4 +17,5 @@
<string name="saveButtonText">Save</string> <string name="saveButtonText">Save</string>
<string name="quiz_button_text">Quiz</string> <string name="quiz_button_text">Quiz</string>
<string name="submit_button_text">Submit</string> <string name="submit_button_text">Submit</string>
<string name="change_background_button_text">Change Background</string>
</resources> </resources>

View File

@ -19,8 +19,4 @@
</style> </style>
<style name="Theme.CpsAssist.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> <style name="Theme.CpsAssist.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.CpsAssist.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> <style name="Theme.CpsAssist.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="edit_dialog">
<item name="android:background">@color/black</item>
<item name="android:textColor">@color/white</item>
</style>
</resources> </resources>