Hide keyboard when clicked outside of name input field.
This commit is contained in:
@@ -7,6 +7,7 @@ import android.text.InputType
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.WindowManager
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.ScrollView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
@@ -43,6 +44,18 @@ class MainActivity : AppCompatActivity() {
|
||||
updateView()
|
||||
|
||||
|
||||
inputTeamA.setOnFocusChangeListener { view, b ->
|
||||
if (b) {
|
||||
hideKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
inputTeamB.setOnFocusChangeListener { view, b ->
|
||||
if (b) {
|
||||
hideKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
inputTeamA.doOnTextChanged { text, start, count, after ->
|
||||
if (inputTeamA.isFocused) {
|
||||
if (inputTeamA.text.isNotEmpty()) {
|
||||
@@ -102,6 +115,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
buttonAdd100.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (inputTeamA.isFocused) {
|
||||
|
||||
currentRound.scoreA = try {
|
||||
@@ -132,6 +147,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
buttonSub100.setOnClickListener {
|
||||
giveFocusToAIfNone()
|
||||
|
||||
if (inputTeamA.isFocused) {
|
||||
currentRound.scoreA = try {
|
||||
inputTeamA.text.toString().toInt() - 100
|
||||
@@ -329,6 +346,12 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideKeyboard() {
|
||||
val imm: InputMethodManager =
|
||||
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(currentFocus!!.windowToken, 0)
|
||||
}
|
||||
|
||||
private fun giveFocusToAIfNone() {
|
||||
if (!inputTeamA.isFocused && !inputTeamB.isFocused) {
|
||||
inputTeamA.requestFocus()
|
||||
@@ -336,10 +359,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun undoLastRound() {
|
||||
|
||||
history.revertLastRound()
|
||||
updateView()
|
||||
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
|
||||
Reference in New Issue
Block a user