MP1_CalebFontenot
0
Assignments/.idea/.gitignore → Assignments/MP1_CalebFontenot/.idea/.gitignore
generated
vendored
6
Assignments/MP1_CalebFontenot/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
BIN
Assignments/MP1_CalebFontenot/AndroidProgramming3e.zip
Normal file
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 982 B After Width: | Height: | Size: 982 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
@ -0,0 +1,142 @@
|
||||
package com.calebfontenot.quizchapter2;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private Button trueButton;
|
||||
private Button falseButton;
|
||||
private Button nextButton;
|
||||
private Button previousButton;
|
||||
private Button resetButton;
|
||||
private TextView mQuestionTextView;
|
||||
private TextView mScoreTextView;
|
||||
private final String TAG = "QuizController";
|
||||
private long answersCorrect = 0, answersIncorrect = 0;
|
||||
private Question[] mQuestionBank = new Question[]
|
||||
{
|
||||
new Question(R.string.question_australia, true),
|
||||
new Question(R.string.question_oceans, true),
|
||||
new Question(R.string.question_mideast, false),
|
||||
new Question(R.string.question_africa, false),
|
||||
new Question(R.string.question_asia, true),
|
||||
};
|
||||
private int mCurrentIndex = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG,"Calling onCreate...");
|
||||
mQuestionTextView = (TextView)
|
||||
findViewById(R.id.question_text_view);
|
||||
int question =
|
||||
mQuestionBank[mCurrentIndex].getmTextResId();
|
||||
//mQuestionTextView.setText(question);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
mQuestionTextView = findViewById(R.id.question_text_view);
|
||||
trueButton = findViewById(R.id.true_button);
|
||||
falseButton = findViewById(R.id.false_button);
|
||||
nextButton = findViewById(R.id.next_button);
|
||||
previousButton = findViewById(R.id.previous_button);
|
||||
mScoreTextView = findViewById(R.id.score_counter);
|
||||
resetButton = findViewById(R.id.reset_score_button);
|
||||
updateScores();
|
||||
|
||||
trueButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.i(TAG,"Calling trueButton event listener");
|
||||
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
||||
if (q.ismAnswerTrue()) {
|
||||
Toast.makeText(MainActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show();
|
||||
answersCorrect++;
|
||||
updateScores();
|
||||
} else {
|
||||
Toast.makeText(MainActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
|
||||
answersIncorrect++;
|
||||
updateScores();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
falseButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.i(TAG,"Calling falseButton event listener");
|
||||
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
||||
if (!q.ismAnswerTrue()) {
|
||||
Toast.makeText(MainActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show();
|
||||
answersCorrect++;
|
||||
updateScores();
|
||||
} else {
|
||||
Toast.makeText(MainActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
|
||||
answersIncorrect++;
|
||||
updateScores();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
View.OnClickListener nextQuestionHandler = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.i(TAG,"Calling nextButton event listener");
|
||||
updateScores();
|
||||
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
||||
int idOfQuestion = q.getmTextResId();
|
||||
if(MainActivity.this.mCurrentIndex == mQuestionBank.length - 1) {
|
||||
MainActivity.this.mCurrentIndex = 0;
|
||||
} else {
|
||||
MainActivity.this.mCurrentIndex++;
|
||||
}
|
||||
Log.i(TAG, "mCurrentIndex is: " + mCurrentIndex);
|
||||
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
||||
}
|
||||
};
|
||||
|
||||
nextButton.setOnClickListener(nextQuestionHandler);
|
||||
mQuestionTextView.setOnClickListener(nextQuestionHandler);
|
||||
|
||||
|
||||
previousButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.i(TAG, "Calling previousButton event listener");
|
||||
updateScores();
|
||||
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
||||
int idOfQuestion = q.getmTextResId();
|
||||
if (MainActivity.this.mCurrentIndex <= 0) {
|
||||
MainActivity.this.mCurrentIndex = mQuestionBank.length - 1;
|
||||
} else {
|
||||
MainActivity.this.mCurrentIndex--;
|
||||
}
|
||||
Log.i(TAG, "mCurrentIndex is: " + mCurrentIndex);
|
||||
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
||||
}
|
||||
});
|
||||
|
||||
resetButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.i(TAG, "Resetting scores!");
|
||||
answersCorrect = answersIncorrect = 0;
|
||||
updateScores();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateScores() {
|
||||
String score = "Answers correct: " + answersCorrect + "\n"
|
||||
+ "Answers incorrect: " + answersIncorrect + "\n"
|
||||
+ "Question number: " + (MainActivity.this.mCurrentIndex + 1) + " out of " + mQuestionBank.length;
|
||||
Log.i(TAG, score);
|
||||
MainActivity.this.mScoreTextView.setText(score);
|
||||
}
|
||||
|
||||
}
|
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.5 KiB |
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/question_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="24dp"
|
||||
android:text="Tap next or previous to begin."/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="130px"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/true_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/true_button" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/false_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/false_button" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="130px"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/previous_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/previous_button"
|
||||
android:drawableLeft="@drawable/arrow_left"
|
||||
android:drawablePadding="4dp"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/next_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/next_button"
|
||||
android:drawableRight="@drawable/arrow_right"
|
||||
android:drawablePadding="4dp"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/score_counter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="24dp"
|
||||
android:text=""
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/reset_score_button"
|
||||
android:layout_height="wrap_content" android:layout_width="fill_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="Reset Score"/>
|
||||
|
||||
</RelativeLayout>
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 982 B After Width: | Height: | Size: 982 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
@ -0,0 +1,24 @@
|
||||
<resources>
|
||||
<string name="app_name">MP1_CalebFontenot</string>
|
||||
<string name="true_button">True</string>
|
||||
<string name="false_button">False</string>
|
||||
<string name="next_button">Next</string>
|
||||
<string name="previous_button">Previous</string>
|
||||
<string name="correct_toast">Correct!</string>
|
||||
<string name="incorrect_toast">Sorry, try again.</string>
|
||||
|
||||
<string name="question_australia">Canberra is the
|
||||
capital of Australia.</string>
|
||||
<string name="question_oceans">The Pacific Ocean is
|
||||
larger than
|
||||
the Atlantic Ocean.</string>
|
||||
<string name="question_mideast">The Suez Canal
|
||||
connects the Red Sea
|
||||
and the Indian Ocean.</string>
|
||||
<string name="question_africa">The source of the Nile
|
||||
River is in Egypt.</string>
|
||||
<string name="question_americas">The Amazon River is
|
||||
the longest river
|
||||
in the Americas.</string>
|
||||
<string name="question_asia">Lake Baikal is the world\'s oldest and deepest freshwater lake.</string>
|
||||
</resources>
|
5
Assignments/MP1_CalebFontenot/build.gradle
Normal file
@ -0,0 +1,5 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '8.2.2' apply false
|
||||
id 'com.android.library' version '8.2.2' apply false
|
||||
}
|
17
Assignments/MP1_CalebFontenot/settings.gradle
Normal file
@ -0,0 +1,17 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "MP1_CalebFontenot"
|
||||
include ':app'
|
||||
include ':app'
|
15
Assignments/QuizChapter2/.gitignore
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
3
Assignments/QuizChapter2/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
Assignments/QuizChapter2/.idea/compiler.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="17" />
|
||||
</component>
|
||||
</project>
|
10
Assignments/QuizChapter2/.idea/deploymentTargetDropDown.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<value>
|
||||
<entry key="app">
|
||||
<State />
|
||||
</entry>
|
||||
</value>
|
||||
</component>
|
||||
</project>
|
7
Assignments/QuizChapter2/.idea/discord.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
20
Assignments/QuizChapter2/.idea/gradle.xml
generated
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="/usr/share/java/gradle" />
|
||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveExternalAnnotations" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|