diff --git a/Assignments/GeoQuizChapter5_TwoActivities/.idea/gradle.xml b/Assignments/GeoQuizChapter5_TwoActivities/.idea/gradle.xml index 89935b5..b2302f7 100644 --- a/Assignments/GeoQuizChapter5_TwoActivities/.idea/gradle.xml +++ b/Assignments/GeoQuizChapter5_TwoActivities/.idea/gradle.xml @@ -1,10 +1,18 @@ + diff --git a/Assignments/GeoQuizChapter5_TwoActivities/.idea/misc.xml b/Assignments/GeoQuizChapter5_TwoActivities/.idea/misc.xml index 3040d03..8978d23 100644 --- a/Assignments/GeoQuizChapter5_TwoActivities/.idea/misc.xml +++ b/Assignments/GeoQuizChapter5_TwoActivities/.idea/misc.xml @@ -1,7 +1,6 @@ - - + diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/build.gradle b/Assignments/GeoQuizChapter5_TwoActivities/app/build.gradle index afd7931..5a2da95 100644 --- a/Assignments/GeoQuizChapter5_TwoActivities/app/build.gradle +++ b/Assignments/GeoQuizChapter5_TwoActivities/app/build.gradle @@ -3,13 +3,13 @@ plugins { } android { - namespace 'com.example.geoquizchapter1' - compileSdk 32 + namespace 'com.calebfontenot.quizchapter2' + compileSdk 34 defaultConfig { - applicationId "com.example.geoquizchapter1" - minSdk 21 - targetSdk 32 + applicationId "com.calebfontenot.quizchapter2" + minSdk 30 + targetSdk 34 versionCode 1 versionName "1.0" @@ -30,8 +30,8 @@ android { dependencies { - implementation 'androidx.appcompat:appcompat:1.5.1' - implementation 'com.google.android.material:material:1.7.0' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.11.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/src/androidTest/java/com/example/geoquizchapter1/ExampleInstrumentedTest.java b/Assignments/GeoQuizChapter5_TwoActivities/app/src/androidTest/java/com/example/geoquizchapter1/ExampleInstrumentedTest.java deleted file mode 100644 index ac27c2c..0000000 --- a/Assignments/GeoQuizChapter5_TwoActivities/app/src/androidTest/java/com/example/geoquizchapter1/ExampleInstrumentedTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.example.geoquizchapter1; - -import android.content.Context; - -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest -{ - @Test - public void useAppContext() - { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.example.geoquizchapter1", appContext.getPackageName()); - } -} \ No newline at end of file diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/AndroidManifest.xml b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/AndroidManifest.xml index 05fb444..fb394c7 100644 --- a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/AndroidManifest.xml +++ b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/AndroidManifest.xml @@ -10,15 +10,11 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/Theme.GeoQuizChapter1" + android:theme="@style/Theme.QuizChapter2" tools:targetApi="31"> - - + android:exported="false" /> @@ -27,10 +23,6 @@ - - diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/calebfontenot/quizchapter2/CheatActivity.java b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/calebfontenot/quizchapter2/CheatActivity.java new file mode 100644 index 0000000..39bf367 --- /dev/null +++ b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/calebfontenot/quizchapter2/CheatActivity.java @@ -0,0 +1,94 @@ +package com.calebfontenot.quizchapter2; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Context; +import android.content.Intent; +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 CheatActivity extends AppCompatActivity { + + private Button cheatButton; + private Question currentQuestion; + //private boolean hasCheatingBeenActivated; + private boolean mAnswerIsTrue; + private TextView mAnswerTextView; + private static final String CURRENT_QUESTION = "com.calebfontenot.quizchapter2.currentQuestion"; + private static final String EXTRA_ANSWER_SHOWN = "com.calebfontenot.quizchapter2.answer_shown"; + private final String TAG = "CheatActivity"; + //private static final String CHEATING_STATE = "this variable determines whether or not the user is currently in a cheating state."; + public static Intent newIntent(Context packageContext, Question currentQuestion) { + Intent intent = new Intent(packageContext, CheatActivity.class); + intent.putExtra(CURRENT_QUESTION, currentQuestion); + return intent; + } + public static boolean wasAnswerShown(Intent result) { + return result.getBooleanExtra(EXTRA_ANSWER_SHOWN, + false); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_cheat); + mAnswerTextView = (TextView) + findViewById(R.id.answer_text_view); + cheatButton = findViewById(R.id.cheat_button); + Question currentQuestion = getIntent().getParcelableExtra(CURRENT_QUESTION); + Log.i(TAG, currentQuestion.toString() + " " + currentQuestion.hashCode()); + setAnswerShownResult(false); + mAnswerIsTrue = currentQuestion.ismAnswerTrue(); + if (currentQuestion.isHasCheated()) { + if (mAnswerIsTrue) { + mAnswerTextView.setText(R.string.cheat_reveal_true); + } else { + mAnswerTextView.setText(R.string.cheat_reveal_false); + } + } +/* + //if (savedInstanceState != null) { + //hasCheatingBeenActivated = savedInstanceState.getBoolean(CHEATING_STATE); + if (mAnswerIsTrue) { + mAnswerTextView.setText(R.string.cheat_reveal_true); + } else { + mAnswerTextView.setText(R.string.cheat_reveal_false); + } + //} else { + hasCheatingBeenActivated = false; + //} +*/ + cheatButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //hasCheatingBeenActivated = true; + + //Toast.makeText(CheatActivity.this, R.string.cheat_toast, Toast.LENGTH_LONG).show(); + if (mAnswerIsTrue) { + mAnswerTextView.setText(R.string.cheat_reveal_true); + } else { + mAnswerTextView.setText(R.string.cheat_reveal_false); + } + currentQuestion.setHasCheated(true); + setAnswerShownResult(true); + } + }); + } +/* + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(CHEATING_STATE, hasCheatingBeenActivated) ; + } +*/ + private void setAnswerShownResult(boolean isAnswerShown) { + Intent data = new Intent(); + data.putExtra(EXTRA_ANSWER_SHOWN, + isAnswerShown); + setResult(RESULT_OK, data); + } +} \ No newline at end of file diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/example/geoquizchapter1/CheatActivity.java b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/example/geoquizchapter1/CheatActivity.java deleted file mode 100644 index e1da01a..0000000 --- a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/example/geoquizchapter1/CheatActivity.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.example.geoquizchapter1; - -import androidx.appcompat.app.AppCompatActivity; - -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; -import android.widget.Toast; - -public class CheatActivity extends AppCompatActivity -{ - boolean bAnswer ; - Button btShownAnswer; - boolean bHasCheated; - TextView tvAnswer; - @Override - protected void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_cheat); - Intent i = this.getIntent(); - boolean isTrue = i.getBooleanExtra("key_from_main", false); - this.bAnswer = isTrue; - this.tvAnswer = findViewById( R.id.answer_text_view ); - this.btShownAnswer = findViewById( R.id.show_answer_button ); - this.btShownAnswer.setOnClickListener(new View.OnClickListener() - { - @Override public void onClick(View view) { - if ( bAnswer == true) { - CheatActivity.this.tvAnswer.setText("The answer is true."); - Toast.makeText(CheatActivity.this, "The answer is true.", - Toast.LENGTH_LONG).show(); - } - else { - CheatActivity.this.tvAnswer.setText("The answer is false."); - Toast.makeText(CheatActivity.this, "The answer is false.", Toast.LENGTH_LONG).show(); - } - bHasCheated = true; - Intent i = new Intent(); - i.putExtra("888", bHasCheated); - setResult( 33, i ); - } - }); - - } -} \ No newline at end of file diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/example/geoquizchapter1/MainActivity.java b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/example/geoquizchapter1/MainActivity.java deleted file mode 100644 index 91706eb..0000000 --- a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/example/geoquizchapter1/MainActivity.java +++ /dev/null @@ -1,191 +0,0 @@ -package com.example.geoquizchapter1; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - -import android.app.Activity; -import android.content.Intent; -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 static final String TAG = "MainActivity"; - private int currentIndex = 0; - private Button trueButton; - private Button falseButton; - private Button nextButton; - private TextView questionTextView; - - private Question[] questionBank = new Question[] - { - new Question( R.string.question_australia, true), - new Question(R.string.question_africa, false), - new Question(R.string.question_asia , true), - new Question(R.string.question_americas , true), - new Question(R.string.question_mideast , false) - }; - private Button cheatButton; - @Override - protected void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - Log.d(TAG, "onCreate(Bundle) called"); - setContentView( R.layout.activity_main ); - if ( savedInstanceState != null ) - { - Log.d(TAG, "onCreate(Bundle) savedInstanceState not null:" + savedInstanceState.toString()); - this.currentIndex = savedInstanceState.getInt("KEY_CURRENT_INDEX", 0); - } - questionTextView = this.findViewById(R.id.question_text_view); - nextButton = this.findViewById(R.id.next_button); - //trueButton = this.findViewById(R.id.button_true); - trueButton = this.findViewById(R.id.button_true); - falseButton = this.findViewById(R.id.button_false); - - int questionID = questionBank[ currentIndex ].getTextResId(); - questionTextView.setText( questionID ); - - nextButton.setOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View view) - { - - - currentIndex = (currentIndex + 1) % questionBank.length; - int question = questionBank[currentIndex].getTextResId(); - - questionTextView.setText(question); - } - }); - - - - trueButton.setOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View view) - { - - if ( MainActivity.this.questionBank[MainActivity.this.currentIndex].isAnswerTrue() ) - - Toast.makeText(MainActivity.this, "correct!", Toast.LENGTH_SHORT).show(); - else - Toast.makeText(MainActivity.this, "incorrect!", Toast.LENGTH_SHORT).show(); - } - }); - - falseButton.setOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View view) - { - - if ( MainActivity.this.questionBank[MainActivity.this.currentIndex].isAnswerTrue() == false ) - - Toast.makeText(MainActivity.this, "correct!", Toast.LENGTH_SHORT).show(); - else - Toast.makeText(MainActivity.this, "incorrect!", Toast.LENGTH_SHORT).show(); - } - }); - - - - cheatButton = findViewById(R.id.cheat_button); - cheatButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent( - MainActivity.this, - CheatActivity.class); - - intent.putExtra("key_from_main", - questionBank[MainActivity.this.currentIndex].isAnswerTrue()); - //MainActivity.this.startActivity(intent); - MainActivity.this.startActivityForResult(intent, 888); - } - }); - } - - @Override - protected void onStart() - { - super.onStart(); - Log.d(TAG, "onStart() called"); - } - - /** - * {@inheritDoc} - *

- * Dispatch onResume() to fragments. Note that for better inter-operation - * with older versions of the platform, at the point of this call the - * fragments attached to the activity are not resumed. - */ - @Override - protected void onResume() - { - super.onResume(); - Log.d(TAG, "onResume() called"); - } - - /** - * {@inheritDoc} - *

- * Dispatch onPause() to fragments. - */ - @Override - protected void onPause() - { - super.onPause(); - Log.d(TAG, "onPause() called"); - - } - - @Override - protected void onStop() - { - super.onStop(); - Log.d(TAG, "onStop() called"); - - } - - - @Override - protected void onDestroy() - { - super.onDestroy(); - Log.d(TAG, "onDestroy() called"); - - } - - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) - { - super.onSaveInstanceState(outState); - Log.d(TAG, "onSaveInstanceState() called"); - outState.putInt("KEY_CURRENT_INDEX", this.currentIndex); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent i) - { - super.onActivityResult(requestCode, resultCode, i); - - if (resultCode != 33) - return; - Log.d("request code" , Integer.toString(requestCode)); - boolean bCheated = - i.getBooleanExtra( Integer.toString(requestCode), false); - if (bCheated ) - Toast.makeText(MainActivity.this, "Cheating is bad!", Toast.LENGTH_LONG).show(); - else - Toast.makeText(MainActivity.this, "Good! You did not cheat!", - Toast.LENGTH_LONG).show(); - } -} \ No newline at end of file diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/example/geoquizchapter1/Question.java b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/example/geoquizchapter1/Question.java deleted file mode 100644 index 6cafc4e..0000000 --- a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/java/com/example/geoquizchapter1/Question.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.example.geoquizchapter1; - -public class Question -{ - private int textResId; - private boolean answerTrue; - - public Question(int textResId, boolean answerTrue) - { - this.textResId = textResId; - this.answerTrue = answerTrue; - } - - public int getTextResId() - { - return textResId; - } - - public void setTextResId(int textResId) - { - this.textResId = textResId; - } - - public boolean isAnswerTrue() - { - return answerTrue; - } - - public void setAnswerTrue(boolean answerTrue) - { - this.answerTrue = answerTrue; - } -} diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/drawable-mdpi/arrow_left.png b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/drawable-mdpi/arrow_left.png deleted file mode 100644 index 71c1a42..0000000 Binary files a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/drawable-mdpi/arrow_left.png and /dev/null differ diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/drawable-mdpi/arrow_right.png b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/drawable-mdpi/arrow_right.png deleted file mode 100644 index c505b45..0000000 Binary files a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/drawable-mdpi/arrow_right.png and /dev/null differ diff --git a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/layout-land/activity_main.xml b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/layout-land/activity_main.xml index 29105f1..acf8c90 100644 --- a/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/layout-land/activity_main.xml +++ b/Assignments/GeoQuizChapter5_TwoActivities/app/src/main/res/layout-land/activity_main.xml @@ -1,60 +1,83 @@ - - - - - - + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="horizontal"> + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center" + android:orientation="vertical"> -