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() {
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/Names"
|
||||
android:id="@+id/viewNames"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/NameTeamA"
|
||||
android:id="@+id/nameTeamA"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
@@ -37,7 +37,7 @@
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/NameTeamB"
|
||||
android:id="@+id/nameTeamB"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
@@ -53,7 +53,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/Score"
|
||||
android:id="@+id/viewScore"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
@@ -86,7 +86,8 @@
|
||||
android:id="@+id/scrollViewHistory"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="16dp">
|
||||
android:layout_marginTop="16dp"
|
||||
android:clickable="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -123,7 +124,7 @@
|
||||
app:layout_constraintStart_toEndOf="@+id/left">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/Input"
|
||||
android:id="@+id/viewInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/Names"
|
||||
android:id="@+id/viewNames"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/NameTeamA"
|
||||
android:id="@+id/nameTeamA"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
@@ -28,7 +28,7 @@
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/NameTeamB"
|
||||
android:id="@+id/nameTeamB"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
@@ -44,11 +44,11 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/Score"
|
||||
android:id="@+id/viewScore"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toBottomOf="@+id/Names">
|
||||
app:layout_constraintTop_toBottomOf="@+id/viewNames">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/scoreA"
|
||||
@@ -86,8 +86,9 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/Input"
|
||||
app:layout_constraintTop_toBottomOf="@+id/Score">
|
||||
android:clickable="true"
|
||||
app:layout_constraintBottom_toTopOf="@+id/viewInput"
|
||||
app:layout_constraintTop_toBottomOf="@+id/viewScore">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -118,10 +119,10 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/Score" />
|
||||
app:layout_constraintBottom_toBottomOf="@+id/viewScore" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/Input"
|
||||
android:id="@+id/viewInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="horizontal"
|
||||
|
||||
Reference in New Issue
Block a user