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