From 828d4ef455f1538fde04e773da668df57420659a Mon Sep 17 00:00:00 2001 From: Zhengyu Peng Date: Tue, 15 Feb 2022 16:47:50 -0500 Subject: [PATCH] update --- .../com/rookiedev/hexapod/ControlActivity.kt | 154 ++++++++++++------ .../com/rookiedev/hexapod/MainActivity.kt | 46 ++++-- .../app/src/main/res/layout/activity_main.xml | 21 ++- .../app/src/main/res/values/strings.xml | 4 + 4 files changed, 160 insertions(+), 65 deletions(-) diff --git a/software/android/app/src/main/java/com/rookiedev/hexapod/ControlActivity.kt b/software/android/app/src/main/java/com/rookiedev/hexapod/ControlActivity.kt index cf4c758..caf2d8b 100644 --- a/software/android/app/src/main/java/com/rookiedev/hexapod/ControlActivity.kt +++ b/software/android/app/src/main/java/com/rookiedev/hexapod/ControlActivity.kt @@ -147,11 +147,16 @@ class ControlActivity : AppCompatActivity() { currentState = "standby" controlImage!!.setImageResource(R.drawable.ic_control_circle_standby) - buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonTwist!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) + buttonRotateX!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateY!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateZ!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonClimb!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonTwist!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) } } else if (length >= radius / 3 && length < 2 * radius / 3) { val angle = atan2(coorY, coorX) @@ -184,11 +189,16 @@ class ControlActivity : AppCompatActivity() { controlImage!!.setImageResource(R.drawable.ic_control_circle_left) } } - buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonTwist!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) + buttonRotateX!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateY!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateZ!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonClimb!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonTwist!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) } else if (length >= 2 * radius / 3 && length < radius) { val angle = atan2(coorY, coorX) if (angle > -PI / 4 && angle <= PI / 4) { @@ -220,79 +230,109 @@ class ControlActivity : AppCompatActivity() { controlImage!!.setImageResource(R.drawable.ic_control_circle_turnleft) } } - buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonTwist!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) + buttonRotateX!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateY!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateZ!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonClimb!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonTwist!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) } return true } } ) - buttonRotateX!!.setOnClickListener{ - if (currentState != "rotatex"){ + buttonRotateX!!.setOnClickListener { + if (currentState != "rotatex") { sendMessageAsync("rotatex") currentState = "rotatex" controlImage!!.setImageResource(R.drawable.ic_control_circle) - buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.purple_500) - buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonTwist!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) + buttonRotateX!!.backgroundTintList = + applicationContext.getColorStateList(R.color.purple_500) + buttonRotateY!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateZ!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonClimb!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonTwist!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) } } - buttonRotateY!!.setOnClickListener{ - if (currentState != "rotatey"){ + buttonRotateY!!.setOnClickListener { + if (currentState != "rotatey") { sendMessageAsync("rotatey") currentState = "rotatey" controlImage!!.setImageResource(R.drawable.ic_control_circle) - buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.purple_500) - buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonTwist!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) + buttonRotateX!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateY!!.backgroundTintList = + applicationContext.getColorStateList(R.color.purple_500) + buttonRotateZ!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonClimb!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonTwist!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) } } - buttonRotateZ!!.setOnClickListener{ - if (currentState != "rotatez"){ + buttonRotateZ!!.setOnClickListener { + if (currentState != "rotatez") { sendMessageAsync("rotatez") currentState = "rotatez" controlImage!!.setImageResource(R.drawable.ic_control_circle) - buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.purple_500) - buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonTwist!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) + buttonRotateX!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateY!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateZ!!.backgroundTintList = + applicationContext.getColorStateList(R.color.purple_500) + buttonClimb!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonTwist!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) } } - buttonClimb!!.setOnClickListener{ - if (currentState != "climb"){ + buttonClimb!!.setOnClickListener { + if (currentState != "climb") { sendMessageAsync("climb") currentState = "climb" controlImage!!.setImageResource(R.drawable.ic_control_circle) - buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.purple_500) - buttonTwist!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) + buttonRotateX!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateY!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateZ!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonClimb!!.backgroundTintList = + applicationContext.getColorStateList(R.color.purple_500) + buttonTwist!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) } } - buttonTwist!!.setOnClickListener{ - if (currentState != "twist"){ + buttonTwist!!.setOnClickListener { + if (currentState != "twist") { sendMessageAsync("twist") currentState = "twist" controlImage!!.setImageResource(R.drawable.ic_control_circle) - buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) - buttonTwist!!.backgroundTintList = applicationContext.getColorStateList(R.color.purple_500) + buttonRotateX!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateY!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateZ!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonClimb!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonTwist!!.backgroundTintList = + applicationContext.getColorStateList(R.color.purple_500) } } } @@ -327,6 +367,20 @@ class ControlActivity : AppCompatActivity() { ) this.tcpClient!!.start() + currentState = "standby" + controlImage!!.setImageResource(R.drawable.ic_control_circle_standby) + + buttonRotateX!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateY!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonRotateZ!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonClimb!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + buttonTwist!!.backgroundTintList = + applicationContext.getColorStateList(R.color.grey_500) + } override fun onPause() { diff --git a/software/android/app/src/main/java/com/rookiedev/hexapod/MainActivity.kt b/software/android/app/src/main/java/com/rookiedev/hexapod/MainActivity.kt index 2e07ef8..3163833 100644 --- a/software/android/app/src/main/java/com/rookiedev/hexapod/MainActivity.kt +++ b/software/android/app/src/main/java/com/rookiedev/hexapod/MainActivity.kt @@ -10,9 +10,13 @@ import com.google.android.material.textfield.TextInputEditText import android.text.Editable import android.text.TextWatcher +import android.text.method.LinkMovementMethod +import android.widget.TextView +import com.google.android.material.textfield.TextInputLayout class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -21,28 +25,48 @@ class MainActivity : AppCompatActivity() { val portInput = findViewById(R.id.port_input) val buttonConnect = findViewById