master
Zhengyu Peng 3 years ago
parent fc706323ae
commit 828d4ef455

@ -147,11 +147,16 @@ class ControlActivity : AppCompatActivity() {
currentState = "standby" currentState = "standby"
controlImage!!.setImageResource(R.drawable.ic_control_circle_standby) controlImage!!.setImageResource(R.drawable.ic_control_circle_standby)
buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateX!!.backgroundTintList =
buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateY!!.backgroundTintList =
buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonTwist!!.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) { } else if (length >= radius / 3 && length < 2 * radius / 3) {
val angle = atan2(coorY, coorX) val angle = atan2(coorY, coorX)
@ -184,11 +189,16 @@ class ControlActivity : AppCompatActivity() {
controlImage!!.setImageResource(R.drawable.ic_control_circle_left) controlImage!!.setImageResource(R.drawable.ic_control_circle_left)
} }
} }
buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateX!!.backgroundTintList =
buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateY!!.backgroundTintList =
buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonTwist!!.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) { } else if (length >= 2 * radius / 3 && length < radius) {
val angle = atan2(coorY, coorX) val angle = atan2(coorY, coorX)
if (angle > -PI / 4 && angle <= PI / 4) { if (angle > -PI / 4 && angle <= PI / 4) {
@ -220,79 +230,109 @@ class ControlActivity : AppCompatActivity() {
controlImage!!.setImageResource(R.drawable.ic_control_circle_turnleft) controlImage!!.setImageResource(R.drawable.ic_control_circle_turnleft)
} }
} }
buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateX!!.backgroundTintList =
buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateY!!.backgroundTintList =
buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonTwist!!.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 return true
} }
} }
) )
buttonRotateX!!.setOnClickListener{ buttonRotateX!!.setOnClickListener {
if (currentState != "rotatex"){ if (currentState != "rotatex") {
sendMessageAsync("rotatex") sendMessageAsync("rotatex")
currentState = "rotatex" currentState = "rotatex"
controlImage!!.setImageResource(R.drawable.ic_control_circle) controlImage!!.setImageResource(R.drawable.ic_control_circle)
buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.purple_500) buttonRotateX!!.backgroundTintList =
buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.purple_500)
buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateY!!.backgroundTintList =
buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonTwist!!.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{ buttonRotateY!!.setOnClickListener {
if (currentState != "rotatey"){ if (currentState != "rotatey") {
sendMessageAsync("rotatey") sendMessageAsync("rotatey")
currentState = "rotatey" currentState = "rotatey"
controlImage!!.setImageResource(R.drawable.ic_control_circle) controlImage!!.setImageResource(R.drawable.ic_control_circle)
buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateX!!.backgroundTintList =
buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.purple_500) applicationContext.getColorStateList(R.color.grey_500)
buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateY!!.backgroundTintList =
buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.purple_500)
buttonTwist!!.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)
} }
} }
buttonRotateZ!!.setOnClickListener{ buttonRotateZ!!.setOnClickListener {
if (currentState != "rotatez"){ if (currentState != "rotatez") {
sendMessageAsync("rotatez") sendMessageAsync("rotatez")
currentState = "rotatez" currentState = "rotatez"
controlImage!!.setImageResource(R.drawable.ic_control_circle) controlImage!!.setImageResource(R.drawable.ic_control_circle)
buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateX!!.backgroundTintList =
buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.purple_500) buttonRotateY!!.backgroundTintList =
buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonTwist!!.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{ buttonClimb!!.setOnClickListener {
if (currentState != "climb"){ if (currentState != "climb") {
sendMessageAsync("climb") sendMessageAsync("climb")
currentState = "climb" currentState = "climb"
controlImage!!.setImageResource(R.drawable.ic_control_circle) controlImage!!.setImageResource(R.drawable.ic_control_circle)
buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateX!!.backgroundTintList =
buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateY!!.backgroundTintList =
buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.purple_500) applicationContext.getColorStateList(R.color.grey_500)
buttonTwist!!.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{ buttonTwist!!.setOnClickListener {
if (currentState != "twist"){ if (currentState != "twist") {
sendMessageAsync("twist") sendMessageAsync("twist")
currentState = "twist" currentState = "twist"
controlImage!!.setImageResource(R.drawable.ic_control_circle) controlImage!!.setImageResource(R.drawable.ic_control_circle)
buttonRotateX!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateX!!.backgroundTintList =
buttonRotateY!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonRotateZ!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) buttonRotateY!!.backgroundTintList =
buttonClimb!!.backgroundTintList = applicationContext.getColorStateList(R.color.grey_500) applicationContext.getColorStateList(R.color.grey_500)
buttonTwist!!.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.purple_500)
} }
} }
} }
@ -327,6 +367,20 @@ class ControlActivity : AppCompatActivity() {
) )
this.tcpClient!!.start() 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() { override fun onPause() {

@ -10,9 +10,13 @@ import com.google.android.material.textfield.TextInputEditText
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.text.method.LinkMovementMethod
import android.widget.TextView
import com.google.android.material.textfield.TextInputLayout
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
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)
@ -21,28 +25,48 @@ class MainActivity : AppCompatActivity() {
val portInput = findViewById<TextInputEditText>(R.id.port_input) val portInput = findViewById<TextInputEditText>(R.id.port_input)
val buttonConnect = findViewById<Button>(R.id.button_connect) 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 { buttonConnect.setOnClickListener {
// your code to perform when the user clicks on the button // your code to perform when the user clicks on the button
// Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show() // Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show()
val intent = Intent(this, ControlActivity::class.java).apply { if (isNumericAddress(ipInput.text.toString()) && portInput.text.toString()
putExtra("ip", ipInput.text.toString()) .toInt() >= 0 && portInput.text.toString().toInt() <= 65535
putExtra("port", portInput.text.toString()) ) {
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 { ipInput.addTextChangedListener(object : TextWatcher {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {} 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 beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun afterTextChanged(s: Editable) { override fun afterTextChanged(s: Editable) {}
// if (isNumericAddress(s.toString())) { })
// Toast.makeText(this@MainActivity, "Correct", Toast.LENGTH_SHORT).show()
// } else { portInput.addTextChangedListener(object : TextWatcher {
// Toast.makeText(this@MainActivity, "Wrong", Toast.LENGTH_SHORT).show() 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:id="@+id/hexapod_logo"
android:layout_width="120dp" android:layout_width="120dp"
android:layout_height="120dp" android:layout_height="120dp"
android:src="@drawable/hexapod_logo"
android:layout_marginTop="32dp" android:layout_marginTop="32dp"
android:layout_marginBottom="32dp" android:layout_marginBottom="32dp"
android:src="@drawable/hexapod_logo"
app:layout_constraintBottom_toTopOf="@id/ip_input_layout" app:layout_constraintBottom_toTopOf="@id/ip_input_layout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -28,7 +28,8 @@
android:id="@+id/ip_input_layout" android:id="@+id/ip_input_layout"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" 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_constraintBottom_toTopOf="@id/port_input_layout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -48,7 +49,8 @@
android:id="@+id/port_input_layout" android:id="@+id/port_input_layout"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" 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_constraintBottom_toTopOf="@id/button_connect"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -68,7 +70,7 @@
android:id="@+id/button_connect" android:id="@+id/button_connect"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="32dp" android:layout_marginTop="16dp"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp" android:paddingBottom="16dp"
android:text="Connect" android:text="Connect"
@ -76,5 +78,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/port_input_layout" /> 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> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

@ -1,3 +1,7 @@
<resources> <resources>
<string name="app_name">Hexapod</string> <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> </resources>
Loading…
Cancel
Save