dice roller completed
This commit is contained in:
parent
d9f2f7c550
commit
c1817fc1ce
|
|
@ -10,7 +10,7 @@
|
|||
<component name="VisualizationToolProject">
|
||||
<option name="state">
|
||||
<ProjectState>
|
||||
<option name="scale" value="0.22" />
|
||||
<option name="scale" value="0.045764362220058426" />
|
||||
</ProjectState>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@
|
|||
android:exported="false"
|
||||
android:label="@string/title_activity_notes"/>
|
||||
<activity android:name=".main.MainActivity"/>
|
||||
|
||||
<activity android:name=".quiz.QuizActivity"/>
|
||||
<activity android:name=".dice.DiceActivity"/>
|
||||
<activity
|
||||
android:name=".login.LoginActivity"
|
||||
android:exported="true">
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ public enum BtnID {
|
|||
EDIT_BUTTON,
|
||||
DELETE_BUTTON,
|
||||
NOTES_BUTTON,
|
||||
QUIZ_BUTTON
|
||||
QUIZ_BUTTON,
|
||||
DICE_BUTTON
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package xyz.r0r5chach.cpsAssist.dice;
|
||||
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import xyz.r0r5chach.cpsAssist.R;
|
||||
|
||||
public class BtnOnClickListener implements View.OnClickListener{
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LinearLayout l = (LinearLayout) v.getParent();
|
||||
Random rand = new Random();
|
||||
TextView output = l.findViewById(R.id.dice_output);
|
||||
EditText input = l.findViewById(R.id.dice_input);
|
||||
output.setText(String.valueOf(rand.nextInt(Integer.parseInt(input.getText().toString()))));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package xyz.r0r5chach.cpsAssist.dice;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import xyz.r0r5chach.cpsAssist.R;
|
||||
import xyz.r0r5chach.cpsAssist.dice.BtnOnClickListener;
|
||||
|
||||
public class DiceActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_dice);
|
||||
findViewById(R.id.dice_roll_button).setOnClickListener(new BtnOnClickListener());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import android.view.View;
|
|||
import java.util.Locale;
|
||||
|
||||
import xyz.r0r5chach.cpsAssist.BtnID;
|
||||
import xyz.r0r5chach.cpsAssist.dice.DiceActivity;
|
||||
import xyz.r0r5chach.cpsAssist.quiz.QuizActivity;
|
||||
import xyz.r0r5chach.cpsAssist.notes.NotesActivity;
|
||||
|
||||
|
|
@ -22,6 +23,9 @@ public class BtnOnClickListener implements View.OnClickListener{
|
|||
case QUIZ_BUTTON:
|
||||
intent = new Intent(v.getContext(), QuizActivity.class);
|
||||
break;
|
||||
case DICE_BUTTON:
|
||||
intent = new Intent(v.getContext(), DiceActivity.class);
|
||||
break;
|
||||
}
|
||||
Activity main = (Activity) v.getContext();
|
||||
if (intent != null) {
|
||||
|
|
|
|||
|
|
@ -24,5 +24,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dice_output"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/dice_input"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:autofillHints=""
|
||||
android:ems="10"
|
||||
android:hint="@string/dice_hint"
|
||||
android:inputType="number"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/dice_roll_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dice_button_text" />
|
||||
</LinearLayout>
|
||||
|
|
@ -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,15 @@
|
|||
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="hello" />
|
||||
<Button
|
||||
android:id="@+id/dice_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dice_roller_button_text"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -17,4 +17,7 @@
|
|||
<string name="saveButtonText">Save</string>
|
||||
<string name="quiz_button_text">Quiz</string>
|
||||
<string name="submit_button_text">Submit</string>
|
||||
<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>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue