Preview input value

This commit is contained in:
Johannes Frohnmeyer 2023-01-26 15:03:11 +01:00
parent b742a050c2
commit a09d307f7e
Signed by: Johannes
GPG Key ID: E76429612C2929F4
4 changed files with 27 additions and 6 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@
.externalNativeBuild .externalNativeBuild
.cxx .cxx
local.properties local.properties
release

View File

@ -2,6 +2,7 @@ package io.gitlab.jfronny.hc05ac
import android.os.Bundle import android.os.Bundle
import android.view.MotionEvent import android.view.MotionEvent
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat import androidx.appcompat.widget.LinearLayoutCompat
import io.gitlab.jfronny.hc05ac.util.Action import io.gitlab.jfronny.hc05ac.util.Action
import io.gitlab.jfronny.hc05ac.util.BaseActivity import io.gitlab.jfronny.hc05ac.util.BaseActivity
@ -14,10 +15,14 @@ import io.gitlab.jfronny.hc05ac.util.jAction
*/ */
abstract class InputActivity : BaseActivity() { abstract class InputActivity : BaseActivity() {
private var root: LinearLayoutCompat? = null private var root: LinearLayoutCompat? = null
private var leftView: TextView? = null
private var rightView: TextView? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
root = findViewById(R.id.root) root = findViewById(R.id.root)
leftView = findViewById(R.id.left)
rightView = findViewById(R.id.right)
} }
override fun onTouchEvent(event: MotionEvent?): Boolean { override fun onTouchEvent(event: MotionEvent?): Boolean {
@ -37,7 +42,7 @@ abstract class InputActivity : BaseActivity() {
Action.UP -> 0 Action.UP -> 0
Action.OTHER -> return false Action.OTHER -> return false
} }
send(left, right) update()
return false return false
} }
@ -47,9 +52,15 @@ abstract class InputActivity : BaseActivity() {
Action.UP -> 0 Action.UP -> 0
Action.OTHER -> return false Action.OTHER -> return false
} }
send(left, right) update()
return false return false
} }
private fun update() {
leftView!!.text = left.toString()
rightView!!.text = right.toString()
send(left, right)
}
protected abstract fun send(left: Byte, right: Byte) protected abstract fun send(left: Byte, right: Byte)
} }

View File

@ -10,14 +10,22 @@
app:divider="@drawable/divider" app:divider="@drawable/divider"
app:showDividers="middle"> app:showDividers="middle">
<View <TextView
android:layout_width="wrap_content" android:text="@string/zero"
android:id="@+id/left"
android:gravity="center"
android:textAlignment="gravity"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="0.5" android:layout_weight="0.5"
android:background="?attr/colorPrimary" /> android:background="?attr/colorPrimary" />
<View <TextView
android:layout_width="wrap_content" android:text="@string/zero"
android:id="@+id/right"
android:gravity="center"
android:textAlignment="gravity"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="0.5" android:layout_weight="0.5"
android:background="?attr/colorSecondary" /> android:background="?attr/colorSecondary" />

View File

@ -1,3 +1,4 @@
<resources> <resources>
<string name="app_name">HC05AC</string> <string name="app_name">HC05AC</string>
<string name="zero">0</string>
</resources> </resources>