Merge branch 'master' into dice

This commit is contained in:
Joshua Perry 2023-03-26 20:59:33 +01:00 committed by GitHub
commit f8a5b6f871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 39 additions and 14 deletions

View File

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

View File

@ -2,18 +2,29 @@ package xyz.r0r5chach.cpsAssist.main;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import java.util.Locale;
import java.util.Random;
import xyz.r0r5chach.cpsAssist.BtnID;
import xyz.r0r5chach.cpsAssist.dice.DiceActivity;
import xyz.r0r5chach.cpsAssist.R;
import xyz.r0r5chach.cpsAssist.quiz.QuizActivity;
import xyz.r0r5chach.cpsAssist.notes.NotesActivity;
public class BtnOnClickListener implements View.OnClickListener{
private String backgroundColor;
public BtnOnClickListener() {
backgroundColor = null;
}
@Override
public void onClick(View v) {
LinearLayout l = (LinearLayout) v.getParent();
String id = v.getResources().getResourceName(v.getId()).split("/")[1];
Intent intent = null;
switch(BtnID.valueOf(id.toUpperCase(Locale.ROOT))) {
@ -25,11 +36,18 @@ public class BtnOnClickListener implements View.OnClickListener{
break;
case DICE_BUTTON:
intent = new Intent(v.getContext(), DiceActivity.class);
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();
if (intent != null) {
intent.putExtra("username", main.getIntent().getStringExtra("username"));
if (backgroundColor != null) {
intent.putExtra("background", backgroundColor);
}
main.startActivity(intent);
}
}

View File

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

View File

@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;
@ -18,6 +19,9 @@ public class NotesActivity extends AppCompatActivity {
setContentView(R.layout.activity_notes);
initRecycler();
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));
}

View File

@ -1,5 +1,6 @@
package xyz.r0r5chach.cpsAssist.quiz;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
@ -21,6 +22,9 @@ public class QuizActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
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);
quiz = new Quiz(getString(R.string.questions), getString(R.string.correct_answers), getString(R.string.incorrect_answers));
initQuestions(layout);

View File

@ -21,7 +21,7 @@
android:id="@+id/background_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />
android:text="@string/change_background_button_text" />
<Button
android:id="@+id/dice_button"
android:layout_width="match_parent"

View File

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

View File

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

View File

@ -20,4 +20,5 @@
<string name="dice_hint">How many sides do you want the dice to have?</string>
<string name="dice_button_text">Roll</string>
<string name="dice_roller_button_text">Dice Roller</string>
<string name="change_background_button_text">Change Background</string>
</resources>

View File

@ -19,8 +19,4 @@
</style>
<style name="Theme.CpsAssist.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<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>