|
@@ -5,10 +5,12 @@ import android.content.Intent
|
|
|
import android.content.pm.PackageManager
|
|
|
import android.graphics.Color
|
|
|
import android.os.Handler
|
|
|
+import android.os.Looper
|
|
|
import android.support.v4.app.ActivityCompat
|
|
|
import android.support.v4.content.ContextCompat
|
|
|
import android.text.TextUtils
|
|
|
import android.util.Log
|
|
|
+import android.view.KeyEvent
|
|
|
import com.enation.javashop.android.jrouter.external.annotation.Router
|
|
|
import com.enation.javashop.net.engine.model.NetState
|
|
|
import com.enation.javashop.net.engine.plugin.permission.RxPermissions
|
|
@@ -49,6 +51,8 @@ class WatchRegisterActivity : BaseActivity<WatchDevicePresenter, WatchActivityRe
|
|
|
|
|
|
private val WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 127//这个值是自定义的一个int值,在申请多个权限时要
|
|
|
|
|
|
+ private var isRegister = true
|
|
|
+
|
|
|
override fun getLayId(): Int {
|
|
|
return R.layout.watch_activity_register
|
|
|
}
|
|
@@ -61,7 +65,7 @@ class WatchRegisterActivity : BaseActivity<WatchDevicePresenter, WatchActivityRe
|
|
|
// AppTool.SystemUI.showNavigationBar(this,false)
|
|
|
// AppTool.SystemUI.ImmersiveWithBottomBarColor(this, Color.BLACK)
|
|
|
|
|
|
- presenter.loadTcpServerHost()
|
|
|
+
|
|
|
|
|
|
// val permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
|
|
|
//
|
|
@@ -70,7 +74,26 @@ class WatchRegisterActivity : BaseActivity<WatchDevicePresenter, WatchActivityRe
|
|
|
// } else {
|
|
|
// //TODO
|
|
|
// }
|
|
|
- requestPermissions()
|
|
|
+
|
|
|
+ Thread(Runnable {
|
|
|
+ while (isRegister) {
|
|
|
+ Log.e(TAG,"注册心跳")
|
|
|
+ runOnUiThread(Runnable {
|
|
|
+ presenter.loadTcpServerHost()
|
|
|
+ requestPermissions()
|
|
|
+ })
|
|
|
+ Looper.prepare()
|
|
|
+// Handler().post { Runnable {
|
|
|
+// presenter.loadTcpServerHost()
|
|
|
+// requestPermissions()
|
|
|
+// } }
|
|
|
+ try {
|
|
|
+ Thread.sleep(2000)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }).start()
|
|
|
}
|
|
|
|
|
|
override fun bindEvent() {
|
|
@@ -80,6 +103,7 @@ class WatchRegisterActivity : BaseActivity<WatchDevicePresenter, WatchActivityRe
|
|
|
}
|
|
|
|
|
|
override fun setTcpServerHost(tcpSeverDTO: TcpSeverDTO) {
|
|
|
+ isRegister = false
|
|
|
Constants.tcp_server = tcpSeverDTO.publicIp
|
|
|
Constants.tcp_port = tcpSeverDTO.tcpPort
|
|
|
Constants.heart_beat = tcpSeverDTO.readerIdleTime
|
|
@@ -100,6 +124,7 @@ class WatchRegisterActivity : BaseActivity<WatchDevicePresenter, WatchActivityRe
|
|
|
}
|
|
|
|
|
|
override fun showData(data: DeviceDO) {
|
|
|
+
|
|
|
Log.e(TAG, "收到返回的设备信息 ")
|
|
|
Constants.part_id = data.partId
|
|
|
Constants.ids = "" + data.id
|
|
@@ -165,7 +190,9 @@ class WatchRegisterActivity : BaseActivity<WatchDevicePresenter, WatchActivityRe
|
|
|
Constants.mac = NetHelper.getInstance().macAddress
|
|
|
//Constants.mac = "4C:C0:0A:8E:D6:BB"
|
|
|
Log.e(TAG, "mac " + Constants.mac)
|
|
|
- tv_mac_addr.text = "MAC地址: " + Constants.mac + "\n" + "IMEI号:" + Constants.imei
|
|
|
+ runOnUiThread(Runnable {
|
|
|
+ tv_mac_addr.text = "MAC地址: " + Constants.mac + "\n" + "IMEI号:" + Constants.imei
|
|
|
+ })
|
|
|
|
|
|
// presenter.loadData(Constants.mac)//传Mac
|
|
|
presenter.loadData(Constants.imei)// 传imei
|
|
@@ -201,6 +228,14 @@ class WatchRegisterActivity : BaseActivity<WatchDevicePresenter, WatchActivityRe
|
|
|
override fun networkMonitor(state: NetState) {
|
|
|
|
|
|
}
|
|
|
+ override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
|
|
|
+ return if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
|
|
|
+
|
|
|
+ //不执行父类点击事件
|
|
|
+ true
|
|
|
+ } else super.onKeyUp(keyCode, event)
|
|
|
+ //继续执行父类其他点击事件
|
|
|
+ }
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
fun onMoonEvent(messageEvent: MessageEvent) {
|