- Add functionality for on screen buttons.
- Improve layout.
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
package me.zobrist.tichucounter
|
package me.zobrist.tichucounter
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.widget.doOnTextChanged
|
import androidx.core.widget.doOnTextChanged
|
||||||
import kotlinx.android.synthetic.main.content_main.*
|
import kotlinx.android.synthetic.main.content_main.*
|
||||||
|
import android.text.InputType
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlin.Exception
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@@ -26,22 +26,34 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
setSupportActionBar(findViewById(R.id.toolbar))
|
setSupportActionBar(findViewById(R.id.toolbar))
|
||||||
|
inputTeamA.setRawInputType(InputType.TYPE_NULL)
|
||||||
|
inputTeamB.setRawInputType(InputType.TYPE_NULL)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inputTeamA.doOnTextChanged { text, start, count, after ->
|
inputTeamA.doOnTextChanged { text, start, count, after ->
|
||||||
if (inputTeamA.isFocused) {
|
if (inputTeamA.isFocused) {
|
||||||
|
if (inputTeamA.text.isNotEmpty()){
|
||||||
inputTeamB.setText(updateNumber(text, tempCounterTeamA + tempCounterTeamB))
|
inputTeamB.setText(updateNumber(text, tempCounterTeamA + tempCounterTeamB))
|
||||||
|
}else{
|
||||||
|
inputTeamA.text.clear()
|
||||||
|
inputTeamB.text.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inputTeamB.doOnTextChanged { text, start, count, after ->
|
inputTeamB.doOnTextChanged { text, start, count, after ->
|
||||||
if (inputTeamB.isFocused) {
|
if (inputTeamB.isFocused) {
|
||||||
|
if (inputTeamB.text.isNotEmpty()){
|
||||||
inputTeamA.setText(updateNumber(text, tempCounterTeamB + tempCounterTeamA))
|
inputTeamA.setText(updateNumber(text, tempCounterTeamB + tempCounterTeamA))
|
||||||
|
}else{
|
||||||
|
inputTeamA.text.clear()
|
||||||
|
inputTeamB.text.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add100.setOnClickListener {
|
buttonAdd100.setOnClickListener {
|
||||||
if (inputTeamA.isFocused) {
|
if (inputTeamA.isFocused) {
|
||||||
tempCounterTeamA += 100
|
tempCounterTeamA += 100
|
||||||
val temp = try {
|
val temp = try {
|
||||||
@@ -63,7 +75,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub100.setOnClickListener {
|
buttonSub100.setOnClickListener {
|
||||||
if (inputTeamA.isFocused) {
|
if (inputTeamA.isFocused) {
|
||||||
tempCounterTeamA -= 100
|
tempCounterTeamA -= 100
|
||||||
val temp = try {
|
val temp = try {
|
||||||
@@ -86,6 +98,61 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button0.setOnClickListener {
|
||||||
|
appedtoFocusedInput('0')
|
||||||
|
}
|
||||||
|
|
||||||
|
button1.setOnClickListener {
|
||||||
|
appedtoFocusedInput('1')
|
||||||
|
}
|
||||||
|
|
||||||
|
button2.setOnClickListener {
|
||||||
|
appedtoFocusedInput('2')
|
||||||
|
}
|
||||||
|
|
||||||
|
button3.setOnClickListener {
|
||||||
|
appedtoFocusedInput('3')
|
||||||
|
}
|
||||||
|
|
||||||
|
button4.setOnClickListener {
|
||||||
|
appedtoFocusedInput('4')
|
||||||
|
}
|
||||||
|
|
||||||
|
button5.setOnClickListener {
|
||||||
|
appedtoFocusedInput('5')
|
||||||
|
}
|
||||||
|
|
||||||
|
button6.setOnClickListener {
|
||||||
|
appedtoFocusedInput('6')
|
||||||
|
}
|
||||||
|
|
||||||
|
button7.setOnClickListener {
|
||||||
|
appedtoFocusedInput('7')
|
||||||
|
}
|
||||||
|
|
||||||
|
button8.setOnClickListener {
|
||||||
|
appedtoFocusedInput('8')
|
||||||
|
}
|
||||||
|
|
||||||
|
button9.setOnClickListener {
|
||||||
|
appedtoFocusedInput('9')
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonBack.setOnClickListener{
|
||||||
|
if(inputTeamA.isFocused ){
|
||||||
|
if(inputTeamA.text.isNotEmpty()){
|
||||||
|
var string = inputTeamA.text.toString()
|
||||||
|
inputTeamA.setText(string.substring(0, string.length -1))
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(inputTeamB.isFocused) {
|
||||||
|
if(inputTeamB.text.isNotEmpty()) {
|
||||||
|
var string = inputTeamB.text.toString()
|
||||||
|
inputTeamB.setText(string.substring(0, string.length - 1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
add.setOnClickListener {
|
add.setOnClickListener {
|
||||||
|
|
||||||
if (inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
|
if (inputTeamA.text.isNotEmpty() && inputTeamB.text.isNotEmpty()) {
|
||||||
@@ -101,8 +168,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
scoreA.text = counterTeamA.toString()
|
scoreA.text = counterTeamA.toString()
|
||||||
scoreB.text = counterTeamB.toString()
|
scoreB.text = counterTeamB.toString()
|
||||||
|
|
||||||
inputTeamA.setText("")
|
inputTeamA.text.clear()
|
||||||
inputTeamB.setText("")
|
inputTeamB.text.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,12 +193,21 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private fun clearAll() {
|
private fun clearAll() {
|
||||||
historyA.text = ""
|
historyA.text = ""
|
||||||
historyB.text = ""
|
historyB.text = ""
|
||||||
inputTeamA.setText("")
|
inputTeamA.text.clear()
|
||||||
inputTeamB.setText("")
|
inputTeamB.text.clear()
|
||||||
scoreA.text = ""
|
scoreA.text = ""
|
||||||
scoreB.text = ""
|
scoreB.text = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun appedtoFocusedInput(toAppend: Char){
|
||||||
|
if(inputTeamA.isFocused){
|
||||||
|
inputTeamA.text.append(toAppend)
|
||||||
|
}else if(inputTeamB.isFocused)
|
||||||
|
{
|
||||||
|
inputTeamB.text.append(toAppend)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun updateNumber(inputText: CharSequence?, offset: Int): String {
|
private fun updateNumber(inputText: CharSequence?, offset: Int): String {
|
||||||
var toSet: Int = 0
|
var toSet: Int = 0
|
||||||
|
|||||||
BIN
app/src/main/res/drawable/back.png
Normal file
BIN
app/src/main/res/drawable/back.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
@@ -14,23 +14,32 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/nameTeamA"
|
android:id="@+id/NameTeamA"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
android:text="@string/team_a"
|
android:text="@string/team_a"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/nameTeamB"
|
android:id="@+id/NameTeamB"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
android:text="@string/team_b"
|
android:text="@string/team_b"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/divider5"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="?android:attr/listDivider"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/scrollView2" />
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:id="@+id/scrollView2"
|
android:id="@+id/scrollView2"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -40,22 +49,22 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/historyA"
|
android:id="@+id/historyA"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="123" />
|
android:gravity="center" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/historyB"
|
android:id="@+id/historyB"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="123" />
|
android:gravity="center" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
@@ -72,6 +81,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
@@ -80,11 +90,19 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/divider6"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="?android:attr/listDivider"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/Score" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/Input"
|
android:id="@+id/Input"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -96,21 +114,23 @@
|
|||||||
android:id="@+id/inputTeamA"
|
android:id="@+id/inputTeamA"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.5"
|
android:layout_weight="1"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:hint="0"
|
android:hint="0"
|
||||||
android:importantForAutofill="no"
|
android:importantForAutofill="no"
|
||||||
android:inputType="numberSigned" />
|
android:inputType="numberSigned"
|
||||||
|
android:gravity="center"/>
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/inputTeamB"
|
android:id="@+id/inputTeamB"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.5"
|
android:layout_weight="1"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:hint="0"
|
android:hint="0"
|
||||||
android:importantForAutofill="no"
|
android:importantForAutofill="no"
|
||||||
android:inputType="numberSigned" />
|
android:inputType="numberSigned"
|
||||||
|
android:gravity="center"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -122,28 +142,28 @@
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button1"
|
android:id="@+id/button1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="1" />
|
android:text="1" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button2"
|
android:id="@+id/button2"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="2" />
|
android:text="2" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button3"
|
android:id="@+id/button3"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="3" />
|
android:text="3" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/add100"
|
android:id="@+id/buttonAdd100"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="+100" />
|
android:text="+100" />
|
||||||
@@ -158,28 +178,28 @@
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button4"
|
android:id="@+id/button4"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="4" />
|
android:text="4" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button5"
|
android:id="@+id/button5"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="5" />
|
android:text="5" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button6"
|
android:id="@+id/button6"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="6" />
|
android:text="6" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/sub100"
|
android:id="@+id/buttonSub100"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="-100" />
|
android:text="-100" />
|
||||||
@@ -194,31 +214,36 @@
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button7"
|
android:id="@+id/button7"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="7" />
|
android:text="7" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button8"
|
android:id="@+id/button8"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="8" />
|
android:text="8" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button9"
|
android:id="@+id/button9"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="9" />
|
android:text="9" />
|
||||||
|
|
||||||
<Button
|
<ImageButton
|
||||||
android:id="@+id/back"
|
android:id="@+id/buttonBack"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="d-" />
|
android:cropToPadding="false"
|
||||||
|
android:paddingTop="15dp"
|
||||||
|
android:paddingBottom="15dp"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
app:srcCompat="@drawable/back" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -230,30 +255,26 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
tools:layout_editor_absoluteX="1dp">
|
tools:layout_editor_absoluteX="1dp">
|
||||||
|
|
||||||
<Button
|
<Space
|
||||||
android:id="@+id/dummy1"
|
android:layout_width="0dp"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1.0"
|
android:layout_weight="1.0" />
|
||||||
android:visibility="invisible" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button0"
|
android:id="@+id/button0"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1.0"
|
android:layout_weight="1.0"
|
||||||
android:text="Button" />
|
android:text="0" />
|
||||||
|
|
||||||
<Button
|
<Space
|
||||||
android:id="@+id/dummy2"
|
android:layout_width="0dp"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1.0"
|
android:layout_weight="1.0" />
|
||||||
android:visibility="invisible" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/add"
|
android:id="@+id/add"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1.0"
|
android:layout_weight="1.0"
|
||||||
android:text="@string/add" />
|
android:text="@string/add" />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="colorPrimary">#6200EE</color>
|
<color name="colorPrimary">#1E9703</color>
|
||||||
<color name="colorPrimaryDark">#3700B3</color>
|
<color name="colorPrimaryDark">#164C02</color>
|
||||||
<color name="colorAccent">#03DAC5</color>
|
<color name="colorAccent">#CFDA38</color>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user