|
|
|
@ -96,6 +96,9 @@ class ControlActivity : AppCompatActivity() {
|
|
|
|
|
private const val CMD_ROTATEZ = "rotatez:"
|
|
|
|
|
|
|
|
|
|
private const val CMD_TWIST = "twist:"
|
|
|
|
|
|
|
|
|
|
private const val CTRL_LEFT = 1
|
|
|
|
|
private const val CTRL_RIGHT = 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private var rightWidth = 0
|
|
|
|
@ -124,6 +127,8 @@ class ControlActivity : AppCompatActivity() {
|
|
|
|
|
private var rightControlImage: ImageView? = null
|
|
|
|
|
private var leftControlImage: ImageView? = null
|
|
|
|
|
|
|
|
|
|
private var controlImg = CTRL_RIGHT
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
@ -171,6 +176,12 @@ class ControlActivity : AppCompatActivity() {
|
|
|
|
|
rightControlImage!!.setOnTouchListener(
|
|
|
|
|
object : View.OnTouchListener {
|
|
|
|
|
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
|
|
|
|
|
when (motionEvent.action) {
|
|
|
|
|
MotionEvent.ACTION_MOVE, MotionEvent.ACTION_DOWN -> {
|
|
|
|
|
if (motionEvent.action == MotionEvent.ACTION_DOWN) {
|
|
|
|
|
controlImg = CTRL_RIGHT
|
|
|
|
|
}
|
|
|
|
|
if (controlImg == CTRL_RIGHT) {
|
|
|
|
|
val touchX = motionEvent.x
|
|
|
|
|
val touchY = motionEvent.y
|
|
|
|
|
if (touchX < 0) {
|
|
|
|
@ -273,6 +284,20 @@ class ControlActivity : AppCompatActivity() {
|
|
|
|
|
}
|
|
|
|
|
leftControlImage!!.setImageResource(R.drawable.ic_control_left)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MotionEvent.ACTION_UP -> {
|
|
|
|
|
if (controlImg == CTRL_RIGHT) {
|
|
|
|
|
sendMessageAsync(CMD_STANDBY)
|
|
|
|
|
currentState = CMD_STANDBY
|
|
|
|
|
rightControlImage!!.setImageResource(R.drawable.ic_control_circle_standby)
|
|
|
|
|
|
|
|
|
|
leftControlImage!!.setImageResource(R.drawable.ic_control_left)
|
|
|
|
|
|
|
|
|
|
controlImg = CTRL_LEFT
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -281,6 +306,12 @@ class ControlActivity : AppCompatActivity() {
|
|
|
|
|
leftControlImage!!.setOnTouchListener(
|
|
|
|
|
object : View.OnTouchListener {
|
|
|
|
|
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
|
|
|
|
|
when (motionEvent.action) {
|
|
|
|
|
MotionEvent.ACTION_MOVE, MotionEvent.ACTION_DOWN -> {
|
|
|
|
|
if (motionEvent.action == MotionEvent.ACTION_DOWN) {
|
|
|
|
|
controlImg = CTRL_LEFT
|
|
|
|
|
}
|
|
|
|
|
if (controlImg == CTRL_LEFT) {
|
|
|
|
|
val touchX = motionEvent.x
|
|
|
|
|
val touchY = motionEvent.y
|
|
|
|
|
if (touchX < 0 || touchX > leftWidth) {
|
|
|
|
@ -332,6 +363,20 @@ class ControlActivity : AppCompatActivity() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rightControlImage!!.setImageResource(R.drawable.ic_control_circle)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MotionEvent.ACTION_UP -> {
|
|
|
|
|
if (controlImg == CTRL_LEFT) {
|
|
|
|
|
sendMessageAsync(CMD_STANDBY)
|
|
|
|
|
currentState = CMD_STANDBY
|
|
|
|
|
rightControlImage!!.setImageResource(R.drawable.ic_control_circle_standby)
|
|
|
|
|
|
|
|
|
|
leftControlImage!!.setImageResource(R.drawable.ic_control_left)
|
|
|
|
|
|
|
|
|
|
controlImg = CTRL_RIGHT
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -458,7 +503,8 @@ class ControlActivity : AppCompatActivity() {
|
|
|
|
|
"Unable to connect to the Hexapod."
|
|
|
|
|
)
|
|
|
|
|
alert.setOnCancelListener { finish() }
|
|
|
|
|
alert.setButton(AlertDialog.BUTTON_POSITIVE,
|
|
|
|
|
alert.setButton(
|
|
|
|
|
AlertDialog.BUTTON_POSITIVE,
|
|
|
|
|
"OK"
|
|
|
|
|
) { _, _ -> finish() }
|
|
|
|
|
}
|
|
|
|
|