added logic to all controllers
This commit is contained in:
parent
cc588bbd27
commit
e33b775a3f
@ -2,15 +2,71 @@ package com.wyattjmiller.dicerollerapp
|
||||
|
||||
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
|
||||
|
||||
class CoinActivity : AppCompatActivity() {
|
||||
|
||||
// Private member variables per the layout
|
||||
private lateinit var mCoinTextView: TextView
|
||||
private lateinit var mFlipButton: Button
|
||||
|
||||
// Private member variable - other
|
||||
private lateinit var mCoinStatus: Coin
|
||||
|
||||
// The following methods are for keeping track of the Android lifecycle using Logcat
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_coin)
|
||||
|
||||
mCoinTextView = findViewById(R.id.coinTextView)
|
||||
mFlipButton = findViewById(R.id.flipButton)
|
||||
|
||||
mCoinTextView.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
Log.d("LIFECYCLE", "onStart invoked!")
|
||||
super.onStart()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
Log.d("LIFECYCLE", "onResume invoked!")
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
Log.d("LIFECYCLE", "onPause invoked!")
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
Log.d("LIFECYCLE", "onStop invoked!")
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
Log.d("LIFECYCLE", "onDestroy invoked!")
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
// code behind for the 'flip' button
|
||||
fun onClickCoinFlip(view: View?) {
|
||||
when (Randomizer().randomCoinFlip()) {
|
||||
0 -> {
|
||||
mCoinStatus = Coin.Heads
|
||||
mCoinTextView.text = mCoinStatus.toString()
|
||||
}
|
||||
1 -> {
|
||||
mCoinStatus = Coin.Tails
|
||||
mCoinTextView.text = mCoinStatus.toString()
|
||||
}
|
||||
}
|
||||
|
||||
if (mCoinTextView.visibility == View.INVISIBLE) {
|
||||
mCoinTextView.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
@ -2,15 +2,88 @@ package com.wyattjmiller.dicerollerapp
|
||||
|
||||
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
|
||||
|
||||
class DiceActivity : AppCompatActivity() {
|
||||
|
||||
// Private member variables per the layout
|
||||
private lateinit var mDiceTextView: TextView
|
||||
private lateinit var mRollButton: Button
|
||||
|
||||
// Private member variable - other
|
||||
private lateinit var mDieStatus: Die
|
||||
|
||||
// The following methods are for keeping track of the Android lifecycle using Logcat
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_dice)
|
||||
|
||||
mDiceTextView = findViewById(R.id.diceTextView)
|
||||
mRollButton = findViewById(R.id.rollButton)
|
||||
|
||||
// I realize that you toggle visability in xml
|
||||
mDiceTextView.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
Log.d("LIFECYCLE", "onStart invoked!")
|
||||
super.onStart()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
Log.d("LIFECYCLE", "onResume invoked!")
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
Log.d("LIFECYCLE", "onPause invoked!")
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
Log.d("LIFECYCLE", "onStop invoked!")
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
Log.d("LIFECYCLE", "onDestroy invoked!")
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
// code behind for the 'roll' button
|
||||
fun onClickDieRoll(view: View?) {
|
||||
when (Randomizer().randomDieRoll()) {
|
||||
0 -> {
|
||||
mDieStatus = Die.One
|
||||
mDiceTextView.text = mDieStatus.toString()
|
||||
}
|
||||
1 -> {
|
||||
mDieStatus = Die.Two
|
||||
mDiceTextView.text = mDieStatus.toString()
|
||||
}
|
||||
2 -> {
|
||||
mDieStatus = Die.Three
|
||||
mDiceTextView.text = mDieStatus.toString()
|
||||
}
|
||||
3 -> {
|
||||
mDieStatus = Die.Four
|
||||
mDiceTextView.text = mDieStatus.toString()
|
||||
}
|
||||
4 -> {
|
||||
mDieStatus = Die.Five
|
||||
mDiceTextView.text = mDieStatus.toString()
|
||||
}
|
||||
5 -> {
|
||||
mDieStatus = Die.Six
|
||||
mDiceTextView.text = mDieStatus.toString()
|
||||
}
|
||||
}
|
||||
|
||||
if (mDiceTextView.visibility == View.INVISIBLE) {
|
||||
mDiceTextView.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,70 @@
|
||||
package com.wyattjmiller.dicerollerapp
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
// Private member variables per the layout
|
||||
private lateinit var mCoinButton: Button
|
||||
private lateinit var mDieButton: Button
|
||||
|
||||
// Private member variable - other
|
||||
private lateinit var mIntent: Intent
|
||||
|
||||
// The following methods are for keeping track of the Android lifecycle using Logcat
|
||||
// Very useful, much wow
|
||||
// Android's lifecycle is so much fun lol :P
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
// dark mode, for those who need it, like me :P
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
|
||||
mCoinButton = findViewById(R.id.coinButton)
|
||||
mDieButton = findViewById(R.id.diceButton)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
Log.d("LIFECYCLE", "onStart invoked!")
|
||||
super.onStart()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
Log.d("LIFECYCLE", "onResume invoked!")
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
Log.d("LIFECYCLE", "onPause invoked!")
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
Log.d("LIFECYCLE", "onStop invoked!")
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
Log.d("LIFECYCLE", "onDestroy invoked!")
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
// code behind the 'flip the coin' button
|
||||
fun onClickCoin(view: View?) {
|
||||
mIntent = Intent(this, CoinActivity::class.java)
|
||||
startActivity(mIntent)
|
||||
}
|
||||
|
||||
// code behind the 'roll dice' button
|
||||
fun onClickDie(view: View?) {
|
||||
mIntent = Intent(this, DiceActivity::class.java)
|
||||
startActivity(mIntent)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user