update
This commit is contained in:
parent
fc706323ae
commit
828d4ef455
@ -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() {
|
||||
|
@ -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<TextInputEditText>(R.id.port_input)
|
||||
val buttonConnect = findViewById<Button>(R.id.button_connect)
|
||||
|
||||
val ipLayout = findViewById<TextInputLayout>(R.id.ip_input_layout)
|
||||
val portLayout = findViewById<TextInputLayout>(R.id.port_input_layout)
|
||||
|
||||
val sourceLink = findViewById<TextView>(R.id.textView_github)
|
||||
sourceLink.movementMethod = LinkMovementMethod.getInstance();
|
||||
|
||||
buttonConnect.setOnClickListener {
|
||||
// your code to perform when the user clicks on the button
|
||||
|
||||
// Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show()
|
||||
val intent = Intent(this, ControlActivity::class.java).apply {
|
||||
putExtra("ip", ipInput.text.toString())
|
||||
putExtra("port", portInput.text.toString())
|
||||
if (isNumericAddress(ipInput.text.toString()) && portInput.text.toString()
|
||||
.toInt() >= 0 && portInput.text.toString().toInt() <= 65535
|
||||
) {
|
||||
val intent = Intent(this, ControlActivity::class.java).apply {
|
||||
putExtra("ip", ipInput.text.toString())
|
||||
putExtra("port", portInput.text.toString())
|
||||
}
|
||||
startActivity(intent)
|
||||
} else if (!isNumericAddress(ipInput.text.toString())) {
|
||||
ipLayout.error = getString(R.string.invalid_ip)
|
||||
} else {
|
||||
portLayout.error = getString(R.string.invalid_port)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
|
||||
ipInput.addTextChangedListener(object : TextWatcher {
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
// if (isNumericAddress(s.toString())) {
|
||||
// Toast.makeText(this@MainActivity, "Correct", Toast.LENGTH_SHORT).show()
|
||||
// } else {
|
||||
// Toast.makeText(this@MainActivity, "Wrong", Toast.LENGTH_SHORT).show()
|
||||
// }
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
ipLayout.error = null
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
})
|
||||
|
||||
portInput.addTextChangedListener(object : TextWatcher {
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
portLayout.error = null
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
})
|
||||
}
|
||||
}
|
@ -16,9 +16,9 @@
|
||||
android:id="@+id/hexapod_logo"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:src="@drawable/hexapod_logo"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginBottom="32dp"
|
||||
android:src="@drawable/hexapod_logo"
|
||||
app:layout_constraintBottom_toTopOf="@id/ip_input_layout"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@ -28,7 +28,8 @@
|
||||
android:id="@+id/ip_input_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
app:errorEnabled="true"
|
||||
app:layout_constraintBottom_toTopOf="@id/port_input_layout"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@ -48,7 +49,8 @@
|
||||
android:id="@+id/port_input_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
app:errorEnabled="true"
|
||||
app:layout_constraintBottom_toTopOf="@id/button_connect"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@ -68,7 +70,7 @@
|
||||
android:id="@+id/button_connect"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:text="Connect"
|
||||
@ -76,5 +78,16 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/port_input_layout" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_github"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="32dp"
|
||||
android:paddingBottom="32dp"
|
||||
android:text="@string/hexapod_github"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button_connect" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
@ -1,3 +1,7 @@
|
||||
<resources>
|
||||
<string name="app_name">Hexapod</string>
|
||||
<string name="invalid_ip">Invalid IP address</string>
|
||||
<string name="invalid_port">Port should be within 0 ~ 65535</string>
|
||||
|
||||
<string name="hexapod_github"><a href="https://github.com/rookiepeng/hexapod">Source files on GitHub</a></string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user