diff --git a/android/app/src/main/java/com/metallic/chiaki/stream/StreamActivity.kt b/android/app/src/main/java/com/metallic/chiaki/stream/StreamActivity.kt
index 1ccf44e..b6cce7e 100644
--- a/android/app/src/main/java/com/metallic/chiaki/stream/StreamActivity.kt
+++ b/android/app/src/main/java/com/metallic/chiaki/stream/StreamActivity.kt
@@ -25,6 +25,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.*
import com.metallic.chiaki.R
+import com.metallic.chiaki.StreamStateIdle
import com.metallic.chiaki.lib.ConnectInfo
import com.metallic.chiaki.touchcontrols.TouchControlsFragment
import kotlinx.android.synthetic.main.activity_stream.*
@@ -60,7 +61,7 @@ class StreamActivity : AppCompatActivity()
viewModel.session.attachToTextureView(textureView)
viewModel.session.state.observe(this, Observer {
- stateTextView.text = "$it"
+ stateTextView.text = if(it != StreamStateIdle) "$it" else ""
})
textureView.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
diff --git a/android/app/src/main/java/com/metallic/chiaki/touchcontrols/ButtonView.kt b/android/app/src/main/java/com/metallic/chiaki/touchcontrols/ButtonView.kt
new file mode 100644
index 0000000..45116fd
--- /dev/null
+++ b/android/app/src/main/java/com/metallic/chiaki/touchcontrols/ButtonView.kt
@@ -0,0 +1,77 @@
+/*
+ * This file is part of Chiaki.
+ *
+ * Chiaki is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chiaki is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Chiaki. If not, see .
+ */
+
+package com.metallic.chiaki.touchcontrols
+
+import android.content.Context
+import android.graphics.Canvas
+import android.graphics.drawable.Drawable
+import android.util.AttributeSet
+import android.view.MotionEvent
+import android.view.View
+import com.metallic.chiaki.R
+
+class ButtonView @JvmOverloads constructor(
+ context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+) : View(context, attrs, defStyleAttr)
+{
+ var buttonPressed = false
+ private set(value)
+ {
+ val diff = field != value
+ field = value
+ if(diff)
+ {
+ invalidate()
+ buttonPressedCallback?.let { it(field) }
+ }
+ }
+
+ var buttonPressedCallback: ((Boolean) -> Unit)? = null
+
+ private val drawableIdle: Drawable?
+ private val drawablePressed: Drawable?
+
+ init
+ {
+ context.theme.obtainStyledAttributes(attrs, R.styleable.ButtonView, 0, 0).apply {
+ drawableIdle = getDrawable(R.styleable.ButtonView_drawableIdle)
+ drawablePressed = getDrawable(R.styleable.ButtonView_drawablePressed)
+ recycle()
+ }
+
+ isClickable = true
+ }
+
+ override fun onDraw(canvas: Canvas)
+ {
+ super.onDraw(canvas)
+ val drawable = if(buttonPressed) drawablePressed else drawableIdle
+ drawable?.setBounds(0, 0, width, height)
+ drawable?.draw(canvas)
+ }
+
+ override fun onTouchEvent(event: MotionEvent): Boolean
+ {
+ when(event.action)
+ {
+ MotionEvent.ACTION_DOWN -> buttonPressed = true
+ MotionEvent.ACTION_UP -> buttonPressed = false
+ }
+ return true
+ }
+}
\ No newline at end of file
diff --git a/android/app/src/main/java/com/metallic/chiaki/touchcontrols/TouchControlsFragment.kt b/android/app/src/main/java/com/metallic/chiaki/touchcontrols/TouchControlsFragment.kt
index d1c4948..6d311f9 100644
--- a/android/app/src/main/java/com/metallic/chiaki/touchcontrols/TouchControlsFragment.kt
+++ b/android/app/src/main/java/com/metallic/chiaki/touchcontrols/TouchControlsFragment.kt
@@ -47,6 +47,11 @@ class TouchControlsFragment : Fragment()
{
super.onViewCreated(view, savedInstanceState)
dpadView.stateChangeCallback = this::dpadStateChanged
+ crossButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_CROSS)
+ moonButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_MOON)
+ pyramidButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_PYRAMID)
+ boxButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_BOX)
+ psButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_PS)
}
private fun dpadStateChanged(direction: DPadView.Direction?)
@@ -67,4 +72,15 @@ class TouchControlsFragment : Fragment()
})
}
}
+
+ private fun buttonStateChanged(buttonMask: UInt) = { pressed: Boolean ->
+ controllerState = controllerState.copy().apply {
+ buttons =
+ if(pressed)
+ buttons or buttonMask
+ else
+ buttons and buttonMask.inv()
+
+ }
+ }
}
\ No newline at end of file
diff --git a/android/app/src/main/res/drawable/control_button_box.xml b/android/app/src/main/res/drawable/control_button_box.xml
new file mode 100644
index 0000000..b642683
--- /dev/null
+++ b/android/app/src/main/res/drawable/control_button_box.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/android/app/src/main/res/drawable/control_button_box_pressed.xml b/android/app/src/main/res/drawable/control_button_box_pressed.xml
new file mode 100644
index 0000000..bd8c5ab
--- /dev/null
+++ b/android/app/src/main/res/drawable/control_button_box_pressed.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/android/app/src/main/res/drawable/control_button_cross.xml b/android/app/src/main/res/drawable/control_button_cross.xml
new file mode 100644
index 0000000..58b4c53
--- /dev/null
+++ b/android/app/src/main/res/drawable/control_button_cross.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/android/app/src/main/res/drawable/control_button_cross_pressed.xml b/android/app/src/main/res/drawable/control_button_cross_pressed.xml
new file mode 100644
index 0000000..e55249c
--- /dev/null
+++ b/android/app/src/main/res/drawable/control_button_cross_pressed.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/android/app/src/main/res/drawable/control_button_moon.xml b/android/app/src/main/res/drawable/control_button_moon.xml
new file mode 100644
index 0000000..efc7434
--- /dev/null
+++ b/android/app/src/main/res/drawable/control_button_moon.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/android/app/src/main/res/drawable/control_button_moon_pressed.xml b/android/app/src/main/res/drawable/control_button_moon_pressed.xml
new file mode 100644
index 0000000..4f8c4b3
--- /dev/null
+++ b/android/app/src/main/res/drawable/control_button_moon_pressed.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/android/app/src/main/res/drawable/control_button_pyramid.xml b/android/app/src/main/res/drawable/control_button_pyramid.xml
new file mode 100644
index 0000000..4a856a0
--- /dev/null
+++ b/android/app/src/main/res/drawable/control_button_pyramid.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/android/app/src/main/res/drawable/control_button_pyramid_pressed.xml b/android/app/src/main/res/drawable/control_button_pyramid_pressed.xml
new file mode 100644
index 0000000..2ebfe4a
--- /dev/null
+++ b/android/app/src/main/res/drawable/control_button_pyramid_pressed.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/android/app/src/main/res/layout/fragment_controls.xml b/android/app/src/main/res/layout/fragment_controls.xml
index 1d04353..35317db 100644
--- a/android/app/src/main/res/layout/fragment_controls.xml
+++ b/android/app/src/main/res/layout/fragment_controls.xml
@@ -10,11 +10,77 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/values/attrs.xml b/android/app/src/main/res/values/attrs.xml
new file mode 100644
index 0000000..8ef2b4d
--- /dev/null
+++ b/android/app/src/main/res/values/attrs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/app/src/main/res/values/dimens.xml b/android/app/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..27bd845
--- /dev/null
+++ b/android/app/src/main/res/values/dimens.xml
@@ -0,0 +1,4 @@
+
+
+ 48dp
+
\ No newline at end of file
diff --git a/assets/controls/buttons.svg b/assets/controls/buttons.svg
new file mode 100644
index 0000000..d2793d8
--- /dev/null
+++ b/assets/controls/buttons.svg
@@ -0,0 +1,163 @@
+
+
+
+