|
@@ -18,6 +18,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|
|
import tech.xiongweixp.touchaction.ui.theme.TouchActionTheme
|
|
|
import java.net.HttpURLConnection
|
|
|
import java.net.URL
|
|
|
+import java.util.*
|
|
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
|
private var computerLayout: ConstraintLayout? = null
|
|
@@ -27,6 +28,8 @@ class MainActivity : ComponentActivity() {
|
|
|
private var compterCloseBtn: Button? = null
|
|
|
private var lightTextView: TextView? = null
|
|
|
private var lightCloseBtn: Button? = null
|
|
|
+ private var countDownText1: TextView? = null
|
|
|
+ private var countDownText2: TextView? = null
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
@@ -39,6 +42,9 @@ class MainActivity : ComponentActivity() {
|
|
|
lightTextView = findViewById(R.id.lightText)
|
|
|
lightCloseBtn = findViewById(R.id.lightCloseButton)
|
|
|
|
|
|
+ countDownText1 = findViewById(R.id.coundownText1)
|
|
|
+ countDownText2 = findViewById(R.id.coundownText2)
|
|
|
+
|
|
|
compterCloseBtn!!.setOnClickListener {
|
|
|
//退出APP
|
|
|
finish()
|
|
@@ -105,9 +111,11 @@ class MainActivity : ComponentActivity() {
|
|
|
when(device) {
|
|
|
0 -> {
|
|
|
computerTextView!!.text = msg
|
|
|
+ countdownAndQuit(device)
|
|
|
}
|
|
|
1 -> {
|
|
|
lightTextView!!.text = msg
|
|
|
+ countdownAndQuit(device)
|
|
|
}
|
|
|
else -> {
|
|
|
mainLayout!!.visibility = ConstraintLayout.VISIBLE
|
|
@@ -115,6 +123,35 @@ class MainActivity : ComponentActivity() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private fun countdownAndQuit(device: Int){
|
|
|
+ var count = 3
|
|
|
+ var timer = Timer()
|
|
|
+ var timerTask = object : TimerTask() {
|
|
|
+ override fun run() {
|
|
|
+ runOnUiThread {
|
|
|
+ if (count > 0) {
|
|
|
+ when(device) {
|
|
|
+ 0 -> {
|
|
|
+ countDownText1!!.text = "${count}秒后退出"
|
|
|
+ }
|
|
|
+ 1 -> {
|
|
|
+ countDownText2!!.text = "${count}秒后退出"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // computerTextView!!.text = "操作成功,${count}秒后退出"
|
|
|
+ count--
|
|
|
+ } else {
|
|
|
+ // computerTextView!!.text = "操作成功,退出"
|
|
|
+ timer.cancel()
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ timer.schedule(timerTask, 0, 1000)
|
|
|
+ }
|
|
|
+
|
|
|
private fun dealAction() {
|
|
|
Log.i("MainActivity", "感应到标签")
|
|
|
var uri = intent.data
|