change background completed
This commit is contained in:
parent
d9f2f7c550
commit
9943ea0790
|
|
@ -5,5 +5,6 @@ public enum BtnID {
|
|||
EDIT_BUTTON,
|
||||
DELETE_BUTTON,
|
||||
NOTES_BUTTON,
|
||||
QUIZ_BUTTON
|
||||
QUIZ_BUTTON,
|
||||
BACKGROUND_BUTTON
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,28 @@ 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.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))) {
|
||||
|
|
@ -22,10 +33,18 @@ public class BtnOnClickListener implements View.OnClickListener{
|
|||
case QUIZ_BUTTON:
|
||||
intent = new Intent(v.getContext(), QuizActivity.class);
|
||||
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();
|
||||
if (intent != null) {
|
||||
intent.putExtra("username", main.getIntent().getStringExtra("username"));
|
||||
if (backgroundColor != null) {
|
||||
intent.putExtra("background", backgroundColor);
|
||||
}
|
||||
main.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package xyz.r0r5chach.cpsAssist.main;
|
||||
|
||||
import android.media.MediaDrm;
|
||||
import android.os.Bundle;
|
||||
|
||||
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
|
||||
|
||||
private void initButtons() {
|
||||
findViewById(R.id.notes_button).setOnClickListener(new BtnOnClickListener());
|
||||
findViewById(R.id.quiz_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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/main_layout"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
|
|
@ -15,4 +16,10 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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>
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -17,4 +17,5 @@
|
|||
<string name="saveButtonText">Save</string>
|
||||
<string name="quiz_button_text">Quiz</string>
|
||||
<string name="submit_button_text">Submit</string>
|
||||
<string name="change_background_button_text">Change Background</string>
|
||||
</resources>
|
||||
|
|
@ -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>
|
||||
Loading…
Reference in New Issue