|
@@ -25,6 +25,8 @@ class MainActivity : ComponentActivity() {
|
|
private var mainLayout: ConstraintLayout? = null
|
|
private var mainLayout: ConstraintLayout? = null
|
|
private var computerTextView: TextView? = null
|
|
private var computerTextView: TextView? = null
|
|
private var compterCloseBtn: Button? = null
|
|
private var compterCloseBtn: Button? = null
|
|
|
|
+ private var lightTextView: TextView? = null
|
|
|
|
+ private var lightCloseBtn: Button? = null
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
@@ -34,11 +36,18 @@ class MainActivity : ComponentActivity() {
|
|
mainLayout = findViewById(R.id.mainLayout)
|
|
mainLayout = findViewById(R.id.mainLayout)
|
|
computerTextView = findViewById(R.id.computerText)
|
|
computerTextView = findViewById(R.id.computerText)
|
|
compterCloseBtn = findViewById(R.id.computerCloseButton)
|
|
compterCloseBtn = findViewById(R.id.computerCloseButton)
|
|
|
|
+ lightTextView = findViewById(R.id.lightText)
|
|
|
|
+ lightCloseBtn = findViewById(R.id.lightCloseButton)
|
|
|
|
|
|
compterCloseBtn!!.setOnClickListener {
|
|
compterCloseBtn!!.setOnClickListener {
|
|
//退出APP
|
|
//退出APP
|
|
finish()
|
|
finish()
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ lightCloseBtn!!.setOnClickListener {
|
|
|
|
+ //退出APP
|
|
|
|
+ finish()
|
|
|
|
+ }
|
|
enableEdgeToEdge()
|
|
enableEdgeToEdge()
|
|
Log.i("MainActivity", "打开APP")
|
|
Log.i("MainActivity", "打开APP")
|
|
Log.i("MainActivity", intent.data.toString())
|
|
Log.i("MainActivity", intent.data.toString())
|
|
@@ -60,14 +69,52 @@ class MainActivity : ComponentActivity() {
|
|
val ret = conn.responseCode
|
|
val ret = conn.responseCode
|
|
Log.i("MainActivity", "发送 $webhookID 请求成功,返回码:$ret")
|
|
Log.i("MainActivity", "发送 $webhookID 请求成功,返回码:$ret")
|
|
conn.disconnect()
|
|
conn.disconnect()
|
|
|
|
+ var device = 0;
|
|
|
|
+ when (webhookID) {
|
|
|
|
+ "computer" -> {
|
|
|
|
+ showMessage(0, ret, "电脑已打开")
|
|
|
|
+ }
|
|
|
|
+ "light" -> {
|
|
|
|
+ showMessage(1, ret, "灯已打开")
|
|
|
|
+ }
|
|
|
|
+ else -> {
|
|
|
|
+ device = 2
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
catch (e: Exception) {
|
|
catch (e: Exception) {
|
|
Log.i("MainActivity", "发送 $webhookID 请求失败")
|
|
Log.i("MainActivity", "发送 $webhookID 请求失败")
|
|
Log.i("MainActivity", e.toString())
|
|
Log.i("MainActivity", e.toString())
|
|
|
|
+ when(webhookID) {
|
|
|
|
+ "computer" -> {
|
|
|
|
+ showMessage(0, 0, "电脑操作失败")
|
|
|
|
+ }
|
|
|
|
+ "light" -> {
|
|
|
|
+ showMessage(1, 0, "灯操作失败")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}.start()
|
|
}.start()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun showMessage(device:Int, code:Int, msg:String) {
|
|
|
|
+ // 在UI线程中更新UI
|
|
|
|
+ runOnUiThread {
|
|
|
|
+ // 显示提示信息
|
|
|
|
+ when(device) {
|
|
|
|
+ 0 -> {
|
|
|
|
+ computerTextView!!.text = msg
|
|
|
|
+ }
|
|
|
|
+ 1 -> {
|
|
|
|
+ lightTextView!!.text = msg
|
|
|
|
+ }
|
|
|
|
+ else -> {
|
|
|
|
+ mainLayout!!.visibility = ConstraintLayout.VISIBLE
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
private fun dealAction() {
|
|
private fun dealAction() {
|
|
Log.i("MainActivity", "感应到标签")
|
|
Log.i("MainActivity", "感应到标签")
|
|
var uri = intent.data
|
|
var uri = intent.data
|
|
@@ -88,6 +135,7 @@ class MainActivity : ComponentActivity() {
|
|
computerLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
computerLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
lightLayout!!.visibility = ConstraintLayout.VISIBLE
|
|
lightLayout!!.visibility = ConstraintLayout.VISIBLE
|
|
mainLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
mainLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
|
|
+ lightTextView!!.text = "操作灯开关"
|
|
hassioRequest("light")
|
|
hassioRequest("light")
|
|
}
|
|
}
|
|
else -> {
|
|
else -> {
|