|
@@ -0,0 +1,631 @@
|
|
|
+package com.wdkl.ncs.android.component.home.activity
|
|
|
+
|
|
|
+import android.Manifest
|
|
|
+import android.content.BroadcastReceiver
|
|
|
+import android.content.Context
|
|
|
+import android.content.Intent
|
|
|
+import android.content.IntentFilter
|
|
|
+import android.content.pm.PackageManager
|
|
|
+import android.graphics.Color
|
|
|
+import android.media.AudioManager
|
|
|
+import android.net.ConnectivityManager
|
|
|
+import android.os.Build
|
|
|
+import android.os.Bundle
|
|
|
+import android.os.CountDownTimer
|
|
|
+import android.os.Environment
|
|
|
+import android.provider.Settings
|
|
|
+import android.support.v4.app.ActivityCompat
|
|
|
+import android.support.v4.app.Fragment
|
|
|
+import android.support.v4.content.ContextCompat
|
|
|
+import android.telephony.PhoneStateListener
|
|
|
+import android.telephony.SignalStrength
|
|
|
+import android.telephony.TelephonyManager
|
|
|
+import android.text.TextUtils
|
|
|
+import android.util.Log
|
|
|
+import android.view.KeyEvent
|
|
|
+import android.view.View
|
|
|
+import com.alibaba.fastjson.JSON
|
|
|
+import com.enation.javashop.net.engine.model.NetState
|
|
|
+import com.enation.javashop.net.engine.plugin.permission.RxPermissions
|
|
|
+import com.enation.javashop.utils.base.tool.CommonTool
|
|
|
+import com.enation.javashop.utils.base.widget.LoadingDialog
|
|
|
+import com.google.gson.Gson
|
|
|
+import com.wdkl.ncs.android.component.home.BuildConfig
|
|
|
+import com.wdkl.ncs.android.component.home.R
|
|
|
+import com.wdkl.ncs.android.component.home.broadcast.BatteryBroadcastReceiver
|
|
|
+import com.wdkl.ncs.android.component.home.databinding.ActivityHomeBinding
|
|
|
+import com.wdkl.ncs.android.component.home.fragment.SkyCallFragment
|
|
|
+import com.wdkl.ncs.android.component.home.helper.AppUpdateHelper
|
|
|
+import com.wdkl.ncs.android.component.home.launch.HomeLaunch
|
|
|
+import com.wdkl.ncs.android.component.home.service.TcpHandleService
|
|
|
+import com.wdkl.ncs.android.component.home.service.TcpHandleService.instance.updateLastTime
|
|
|
+import com.wdkl.ncs.android.component.home.settingconfig.SettingConfig
|
|
|
+import com.wdkl.ncs.android.component.home.util.*
|
|
|
+//import com.wdkl.ncs.android.component.home.service.WdKeepAliveService
|
|
|
+import com.wdkl.ncs.android.component.nursehome.common.Constants
|
|
|
+import com.wdkl.ncs.android.lib.base.BaseActivity
|
|
|
+import com.wdkl.ncs.android.lib.base.BaseApplication
|
|
|
+import com.wdkl.ncs.android.lib.utils.AppTool
|
|
|
+import com.wdkl.ncs.android.lib.utils.TimeHandle
|
|
|
+import com.wdkl.ncs.android.lib.utils.joinManager
|
|
|
+import com.wdkl.ncs.android.lib.utils.showMessage
|
|
|
+import com.wdkl.ncs.android.middleware.logic.contract.home.HomeActivityContract
|
|
|
+import com.wdkl.ncs.android.middleware.logic.presenter.home.HomeActivityPresenter
|
|
|
+import com.wdkl.ncs.android.middleware.model.ServerIpInfo
|
|
|
+import com.wdkl.ncs.android.middleware.model.dos.PartSettingDO
|
|
|
+import com.wdkl.ncs.android.middleware.model.dto.TcpSeverDTO
|
|
|
+import com.wdkl.ncs.android.middleware.model.vo.DeviceVO
|
|
|
+import com.wdkl.ncs.android.middleware.model.vo.DeviceWatchInfoVO
|
|
|
+import com.wdkl.ncs.android.middleware.model.vo.InteractionVO
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.TcpClient
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.TcpClientHandler
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.channel.DeviceChannel
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.channel.VideoUtil
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.channel.VoiceUtil
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
|
|
|
+import com.wdkl.ncs.android.middleware.utils.CommonUtils
|
|
|
+import com.wdkl.ncs.android.middleware.utils.MessageEvent
|
|
|
+import com.wdkl.ncs.janus.util.JanusConstant
|
|
|
+import io.reactivex.Observable
|
|
|
+import kotlinx.android.synthetic.main.activity_home.*
|
|
|
+import kotlinx.android.synthetic.main.activity_register.*
|
|
|
+import org.greenrobot.eventbus.EventBus
|
|
|
+import org.greenrobot.eventbus.Subscribe
|
|
|
+import org.greenrobot.eventbus.ThreadMode
|
|
|
+import java.io.File
|
|
|
+import java.io.FileOutputStream
|
|
|
+import java.io.InputStream
|
|
|
+
|
|
|
+class HomeActivity : BaseActivity<HomeActivityPresenter, ActivityHomeBinding>(), HomeActivityContract.View {
|
|
|
+
|
|
|
+ var TAG = HomeActivity::class.java.getSimpleName()
|
|
|
+
|
|
|
+ //监听网络变化
|
|
|
+ lateinit var teleManager: TelephonyManager
|
|
|
+ private var netType: Int = -1
|
|
|
+
|
|
|
+ lateinit var batteryBroadcastReceiver: BatteryBroadcastReceiver
|
|
|
+ private var isRegister = true
|
|
|
+ private var inited = false
|
|
|
+
|
|
|
+ var currentFragment: Fragment? = null
|
|
|
+
|
|
|
+ private var clickTimes: Int = 1
|
|
|
+ private var clickTime: Long = 0
|
|
|
+
|
|
|
+ var netAvailable: Boolean = false
|
|
|
+
|
|
|
+ private lateinit var receiver: TimeReceiver
|
|
|
+
|
|
|
+ override fun getLayId(): Int {
|
|
|
+ return R.layout.activity_home
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun bindDagger() {
|
|
|
+ HomeLaunch.component.inject(this)
|
|
|
+ }
|
|
|
+
|
|
|
+ //初始化
|
|
|
+ override fun init() {
|
|
|
+ AppUtils.hideStatusBar(activity, false)
|
|
|
+
|
|
|
+ requestPermissions()
|
|
|
+
|
|
|
+ //保活守护进程
|
|
|
+ //DaemonEnv.init(this)
|
|
|
+ //請求用戶忽略电池优化
|
|
|
+// val reason = "轨迹跟踪服务的持续运行"
|
|
|
+// DaemonEnv.whiteListMatters(this, reason)
|
|
|
+ //启动work服务
|
|
|
+ //DaemonEnv.startServiceSafelyWithData(this, WdKeepAliveService::class.java)
|
|
|
+
|
|
|
+ //系统设置按钮
|
|
|
+ btn_system_setting0.setOnClickListener {
|
|
|
+ val intent = Intent(Settings.ACTION_SETTINGS)
|
|
|
+ startActivity(intent)
|
|
|
+ }
|
|
|
+
|
|
|
+ btn_restart_app.setOnClickListener {
|
|
|
+ AppUtils.restartApp()
|
|
|
+ }
|
|
|
+
|
|
|
+ btn_server_config.setOnClickListener {
|
|
|
+ ServerConfigDialogHelper.showPasswordDialog(activity)
|
|
|
+ }
|
|
|
+
|
|
|
+ //APP版本
|
|
|
+ tv_version_name.setText("version: " + BuildConfig.VERSION_NAME)
|
|
|
+
|
|
|
+ //网络强度监听
|
|
|
+ teleManager = (applicationContext.getSystemService(Context.TELEPHONY_SERVICE)) as TelephonyManager
|
|
|
+ netType = NetHelper.getInstance().getNetworkState(applicationContext)
|
|
|
+ Log.i(TAG, "网络类型:" + netType)
|
|
|
+ /*if (netType == NetHelper.NETWORK_2G || netType == NetHelper.NETWORK_3G || netType == NetHelper.NETWORK_4G) {
|
|
|
+ if (teleManager != null) {
|
|
|
+ teleManager.listen(object : PhoneStateListener() {
|
|
|
+ override fun onSignalStrengthsChanged(signalStrength: SignalStrength) {
|
|
|
+ super.onSignalStrengthsChanged(signalStrength)
|
|
|
+ val asu = signalStrength.gsmSignalStrength
|
|
|
+ val lastSignal = -113 + 2 * asu;
|
|
|
+ if (lastSignal > 0) {
|
|
|
+ var mobileNetworkSignal = lastSignal
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ //if ("YUNPAI_H6".equals(Build.MODEL)) {
|
|
|
+ startYunpaiPlugin()
|
|
|
+ //}
|
|
|
+
|
|
|
+ //默认使用面板mic
|
|
|
+ setMainMic(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun startYunpaiPlugin() {
|
|
|
+ try {
|
|
|
+ val packageInfos = packageManager.getInstalledPackages(
|
|
|
+ PackageManager.GET_ACTIVITIES or
|
|
|
+ PackageManager.GET_SERVICES
|
|
|
+ )
|
|
|
+ var needInstall = false
|
|
|
+ for (info in packageInfos) {
|
|
|
+ val pkg = info.packageName
|
|
|
+ if (pkg.equals("com.wd.app")) {
|
|
|
+ //启动云派app升级监听服务
|
|
|
+ val intent = Intent()
|
|
|
+ intent.setClassName("com.wd.app", "com.wd.app.MyService")
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ //android8.0以上通过startForegroundService启动service
|
|
|
+ startForegroundService(intent)
|
|
|
+ } else {
|
|
|
+ startService(intent)
|
|
|
+ }
|
|
|
+ Constants.yunpai_plugin = true
|
|
|
+ needInstall = false
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+ needInstall = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (needInstall) {
|
|
|
+ //拷贝并安装云派app升级服务apk
|
|
|
+ Log.d(TAG,"准备安装升级服务apk")
|
|
|
+ Thread{
|
|
|
+ try {
|
|
|
+ val fileName = "wd_update_plugin.apk"
|
|
|
+ val dstPath = Environment.getExternalStorageDirectory().path + "/Download"
|
|
|
+ val file = File(dstPath)
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs()
|
|
|
+ }
|
|
|
+ val filePath = dstPath + "/" + fileName
|
|
|
+ val outFile = File(filePath)
|
|
|
+ if (outFile.exists()) {
|
|
|
+ outFile.delete()
|
|
|
+ }
|
|
|
+ val inputStream: InputStream = getAssets().open(fileName)
|
|
|
+ val fos = FileOutputStream(outFile)
|
|
|
+ val buffer = ByteArray(1024)
|
|
|
+ var byteCount = 0
|
|
|
+ while (inputStream.read(buffer).also { byteCount = it } != -1) {
|
|
|
+ fos.write(buffer, 0, byteCount)
|
|
|
+ }
|
|
|
+ fos.flush()
|
|
|
+ inputStream.close()
|
|
|
+ fos.close()
|
|
|
+
|
|
|
+ //apk拷贝完成,即将安装
|
|
|
+ AppUpdateHelper.rootSilenceInstall(filePath)
|
|
|
+
|
|
|
+ runOnUiThread {
|
|
|
+ showMessage("app升级服务正在安装,请稍后重启设备以完成升级服务启动")
|
|
|
+ }
|
|
|
+ } catch (e: java.lang.Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ }.start()
|
|
|
+ }
|
|
|
+ } catch (t: Throwable) {
|
|
|
+ t.printStackTrace()
|
|
|
+ showMessage("启动升级插件服务失败: " + t.message)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (Constants.yunpai_plugin) {
|
|
|
+ tv_version_name.setText("升级服务已启动 version: " + BuildConfig.VERSION_NAME)
|
|
|
+ } else {
|
|
|
+ tv_version_name.setText("升级服务未启动 version: " + BuildConfig.VERSION_NAME)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun permissionGranted() {
|
|
|
+ Constants.imei = NetHelper.getInstance().imei
|
|
|
+ //Constants.imei = "860475031573358"
|
|
|
+ Log.i(TAG, "IMEI " + Constants.imei)
|
|
|
+ Log.i(TAG, "mac " + Constants.mac)
|
|
|
+ tv_device_imei.text = Constants.imei
|
|
|
+ tv_server_ip.text = NetHelper.getInstance().localIP + "/" + CommonUtils.getUrl(BaseApplication.appContext)
|
|
|
+
|
|
|
+ //获取TCP服务器IP和端口
|
|
|
+ Thread{
|
|
|
+ while (isRegister) {
|
|
|
+ Log.i(TAG, "获取TCP服务器IP和端口")
|
|
|
+ presenter.getServerInfo()
|
|
|
+ try {
|
|
|
+ Thread.sleep(25000)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.start()
|
|
|
+
|
|
|
+ regReceiver()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun regReceiver() {
|
|
|
+ receiver = TimeReceiver()
|
|
|
+ var intentFilter = IntentFilter()
|
|
|
+ intentFilter.addAction(Intent.ACTION_TIME_TICK)
|
|
|
+ registerReceiver(receiver, intentFilter)
|
|
|
+
|
|
|
+ //手柄状态监听
|
|
|
+ intentFilter.addAction(Constants.HOOK_OFF)
|
|
|
+ intentFilter.addAction(Constants.HOOK_ON)
|
|
|
+ intentFilter.addAction(Constants.KEY_CALL_UP)
|
|
|
+ intentFilter.addAction(Constants.KEY_HOME_UP)
|
|
|
+ registerReceiver(receiver, intentFilter)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun releaseReceiver(){
|
|
|
+ unregisterReceiver(receiver)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回的tcp信息
|
|
|
+ */
|
|
|
+ override fun setTcpServerHost(tcpSeverDTO: TcpSeverDTO) {
|
|
|
+ /*isRegister = false
|
|
|
+ if(tcpSeverDTO.publicIp!= null && tcpSeverDTO.tcpPort != null && tcpSeverDTO.readerIdleTime != null){
|
|
|
+ Constants.tcpServer = tcpSeverDTO.publicIp
|
|
|
+ Constants.tcpPort = tcpSeverDTO.tcpPort
|
|
|
+ Constants.heartBeat = tcpSeverDTO.readerIdleTime
|
|
|
+ //tv_server_ip.text = tcpSeverDTO.publicIp
|
|
|
+
|
|
|
+ Thread {
|
|
|
+ //启动tcp连接
|
|
|
+ TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat)
|
|
|
+
|
|
|
+ //获取设备数据
|
|
|
+ while (!inited) {
|
|
|
+ Log.i(TAG, "获取设备数据")
|
|
|
+ if (!TextUtils.isEmpty(Constants.imei)) {
|
|
|
+ presenter.getDeviceVO(Constants.imei)
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Thread.sleep(15000)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.start()
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun setServerInfo(serverIpInfo: ServerIpInfo) {
|
|
|
+ isRegister = false
|
|
|
+ if(serverIpInfo.tcpLocalIp!= null && serverIpInfo.tcpPort != null && serverIpInfo.tcpIdleSeconds != null){
|
|
|
+ Constants.tcpServer = serverIpInfo.tcpLocalIp
|
|
|
+ Constants.tcpPort = serverIpInfo.tcpPort
|
|
|
+ Constants.heartBeat = serverIpInfo.tcpIdleSeconds
|
|
|
+ tv_server_ip.text = NetHelper.getInstance().localIP + "/" + serverIpInfo.tcpLocalIp
|
|
|
+
|
|
|
+ JanusConstant.JANUS_URL = "ws://" + serverIpInfo.rtcLocalIp + ":" + serverIpInfo.rtcPort
|
|
|
+ JanusConstant.STUN_SERVER = arrayOf<String>(serverIpInfo.stunServer)
|
|
|
+ //JanusConstant.TURN_SERVER = data.turnServer
|
|
|
+
|
|
|
+ Thread {
|
|
|
+ //启动tcp连接
|
|
|
+ TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat)
|
|
|
+
|
|
|
+ //获取设备数据
|
|
|
+ while (!inited) {
|
|
|
+ Log.i(TAG, "获取设备数据")
|
|
|
+ if (!TextUtils.isEmpty(Constants.imei)) {
|
|
|
+ presenter.getDeviceVO(Constants.imei)
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Thread.sleep(15000)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.start()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun requestPermissions() {
|
|
|
+ Observable.just("").compose(RxPermissions(this).ensure(Manifest.permission.CAMERA,
|
|
|
+ Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
|
+ Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
+ Manifest.permission.ACCESS_WIFI_STATE,
|
|
|
+ Manifest.permission.BLUETOOTH,
|
|
|
+ Manifest.permission.RECORD_AUDIO,
|
|
|
+ Manifest.permission.READ_PHONE_STATE)).subscribe {
|
|
|
+ if (it) {
|
|
|
+ permissionGranted()
|
|
|
+ } else {
|
|
|
+ showMessage("请重新授权,进入App")
|
|
|
+ requestPermissions()
|
|
|
+ }
|
|
|
+ }.joinManager(disposableManager)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回的设备信息
|
|
|
+ */
|
|
|
+ override fun setDeviceDo(data: DeviceWatchInfoVO) {
|
|
|
+ Log.i(TAG, "收到返回的设备信息 ")
|
|
|
+ try {
|
|
|
+ Constants.partId = data.partId
|
|
|
+ Constants.deviceId = data.id
|
|
|
+ Constants.sipId = data.sipId
|
|
|
+ Constants.ethIp = data.ethIp
|
|
|
+ Constants.sipIp = data.sipIp
|
|
|
+ Constants.sipPassword = data.sipPassword
|
|
|
+ Constants.userName = data.memberName
|
|
|
+ Constants.userRoleName = data.roleName
|
|
|
+
|
|
|
+ if (Constants.deviceId == -1 || TextUtils.isEmpty(Constants.sipId)) {
|
|
|
+ showMessage("初始化数据不全,请联系管理员")
|
|
|
+ tv_status.text = "初始化数据不全,请联系管理员"
|
|
|
+ return
|
|
|
+ } else if (TextUtils.isEmpty(Constants.tcpServer)) {
|
|
|
+ showMessage("初始化tcp连接数据为null")
|
|
|
+ tv_status.text = "初始化tcp连接数据为null"
|
|
|
+ return
|
|
|
+ } else if (data.status != null && data.status == 0) {
|
|
|
+ showMessage("设备未启用")
|
|
|
+ tv_status.text = "设备未启用"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ inited = true
|
|
|
+ activity_register_layout.visibility = View.GONE
|
|
|
+ watch_activity_home_linyout.visibility = View.VISIBLE
|
|
|
+
|
|
|
+ watch_activity_home_linyout.setBackgroundResource(R.drawable.main_bg_1280x800)
|
|
|
+ btn_callout.setBackgroundResource(R.drawable.round_button_100dp)
|
|
|
+ btn_callout.textSize = 36f
|
|
|
+
|
|
|
+ initSDK()
|
|
|
+ presenter.getDeviceSettingData(Constants.partId)
|
|
|
+
|
|
|
+ //tv_part_name.setText(data.hospitalName + data.partName)
|
|
|
+ tv_part_name.text = data.partDisplay
|
|
|
+
|
|
|
+ showMessage("初始化完成")
|
|
|
+
|
|
|
+ AppTool.Time.delay(1500) {
|
|
|
+ AppUtils.hideStatusBar(activity, true)
|
|
|
+ }
|
|
|
+
|
|
|
+ startCheckUpdate()
|
|
|
+ } catch (e: java.lang.Exception) {
|
|
|
+ showMessage("设备数据异常:" + e.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun initSDK() {
|
|
|
+ val intent = Intent(this, TcpHandleService::class.java)
|
|
|
+ startService(intent)
|
|
|
+ }
|
|
|
+
|
|
|
+ //开始呼叫
|
|
|
+ private fun startVideoCall() {
|
|
|
+ currentFragment = SkyCallFragment()
|
|
|
+ var bundle = Bundle()
|
|
|
+ bundle.putInt("call_state", 0)
|
|
|
+ bundle.putBoolean("audio_only", false)
|
|
|
+ currentFragment?.arguments = bundle
|
|
|
+ supportFragmentManager.beginTransaction()
|
|
|
+ .add(R.id.frame_visit, currentFragment)
|
|
|
+ .commit()
|
|
|
+ watch_activity_home_linyout.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置设备数据
|
|
|
+ */
|
|
|
+ override fun setDeviceSettingData(partSettingDO: PartSettingDO) {
|
|
|
+ try {
|
|
|
+ //分机通话音量 没做白昼区分
|
|
|
+ SettingConfig.setExtensionCallVolume(this, partSettingDO.dayBedVol)
|
|
|
+
|
|
|
+ VoiceManagerUtil.setCallVoice(activity, partSettingDO.dayBedVol)
|
|
|
+
|
|
|
+ VoiceManagerUtil.setSystemVoice(activity, partSettingDO.dayBedVol)
|
|
|
+ VoiceManagerUtil.setMusicVoice(activity, partSettingDO.dayBedVol)
|
|
|
+ } catch (ex: Exception) {
|
|
|
+ ex.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onError(message: String, type: Int) {
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun complete(message: String, type: Int) {
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun start() {
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun networkMonitor(state: NetState) {
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun destory() {
|
|
|
+ releaseReceiver()
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
|
|
|
+ Log.i(TAG, "keyup keyCode " + keyCode)
|
|
|
+ return if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
|
|
|
+ //不执行父类点击事件
|
|
|
+ true
|
|
|
+ } else super.onKeyUp(keyCode, event)
|
|
|
+ //继续执行父类其他点击事件
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun bindEvent() {
|
|
|
+ //长按检测升级
|
|
|
+ tv_version_name.setOnLongClickListener {
|
|
|
+ if (System.currentTimeMillis() / 1000 - updateLastTime > 10) {
|
|
|
+ showMessage("检查新版本")
|
|
|
+ updateLastTime = System.currentTimeMillis() / 1000
|
|
|
+ startCheckUpdate()
|
|
|
+ } else {
|
|
|
+ showMessage("请10秒后再尝试")
|
|
|
+ }
|
|
|
+ return@setOnLongClickListener true
|
|
|
+ }
|
|
|
+
|
|
|
+ tv_version_name.setOnClickListener {
|
|
|
+ val time = System.currentTimeMillis()
|
|
|
+ if (time - clickTime < 1500) {
|
|
|
+ clickTimes++
|
|
|
+ } else {
|
|
|
+ clickTimes = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ if (clickTimes > 9) {
|
|
|
+ val intent = Intent(Settings.ACTION_SETTINGS)
|
|
|
+ startActivity(intent)
|
|
|
+ clickTimes = 1
|
|
|
+ }
|
|
|
+ clickTime = time
|
|
|
+ }
|
|
|
+
|
|
|
+ btn_callout.setOnClickListener {
|
|
|
+ if (System.currentTimeMillis() - clickTime > 3000) {
|
|
|
+ if (TcpClientHandler.getConnected() && netAvailable) {
|
|
|
+ startVideoCall()
|
|
|
+ } else {
|
|
|
+ showMessage("通话服务或网络未连接,请检查网络稍后再试")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ showMessage("点击太频繁")
|
|
|
+ }
|
|
|
+ clickTime = System.currentTimeMillis()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun startCheckUpdate() {
|
|
|
+ val intent = Intent()
|
|
|
+ intent.setClass(this, AppUpdateActivity::class.java)
|
|
|
+ startActivity(intent)
|
|
|
+ }
|
|
|
+
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
+ fun onMoonEvent(messageEvent: MessageEvent) {
|
|
|
+ if (messageEvent.tag == Constants.BACK_TO_MAIN_MSG) {
|
|
|
+ if (currentFragment != null) {
|
|
|
+ supportFragmentManager.beginTransaction()
|
|
|
+ .remove(currentFragment)
|
|
|
+ .commit()
|
|
|
+ currentFragment = null
|
|
|
+ }
|
|
|
+ watch_activity_home_linyout.visibility = View.VISIBLE
|
|
|
+ AppUtils.setAudioMode(BaseApplication.appContext, AudioManager.MODE_NORMAL)
|
|
|
+ } else if (messageEvent.tag == Constants.EVENT_TCP_BREAK) {
|
|
|
+ if (TcpClientHandler.getConnected()) {
|
|
|
+ netAvailable = true
|
|
|
+ tv_rtc_status.setBackgroundColor(Color.GREEN)
|
|
|
+ } else {
|
|
|
+ netAvailable = false
|
|
|
+ tv_rtc_status.setBackgroundColor(Color.RED)
|
|
|
+ }
|
|
|
+ } else if (messageEvent.tag == Constants.TCP_MSG) {
|
|
|
+ val tcp = messageEvent.getMessage() as TcpModel
|
|
|
+ if (tcp.action == TcpAction.DataAction.REFRESH) {
|
|
|
+ if (!TextUtils.isEmpty(Constants.imei)) {
|
|
|
+ presenter.getDeviceVO(Constants.imei)
|
|
|
+ }
|
|
|
+ } else if (tcp.action == TcpAction.TimeAction.SYNC) {
|
|
|
+ var time = 0L
|
|
|
+ var timeZone="Asia/Shanghai"
|
|
|
+ if (canParseJson(tcp.data.toString())) {
|
|
|
+ val json = JSON.parseObject(tcp.data.toString())
|
|
|
+ time = json.getLong("time")*1000
|
|
|
+ timeZone = json.getString("time_zone")
|
|
|
+ } else {
|
|
|
+ time = tcp.data.toString().toLong() * 1000
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ AppUtils.setSystemTime(BaseApplication.appContext, time, timeZone)
|
|
|
+ Log.d("setTime", "set sys time1: $time, $timeZone")
|
|
|
+ } catch (e: Exception) {
|
|
|
+ //"20211213:092314"
|
|
|
+ val timeStr = TimeHandle.getDateTime(time, "yyyyMMdd.HHmmss")
|
|
|
+ AppUtils.setSysTime(timeStr, timeZone)
|
|
|
+ Log.d("setTime", "set sys time2: $timeStr, $timeZone")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun canParseJson(str:String) : Boolean {
|
|
|
+ var result = false
|
|
|
+ try {
|
|
|
+ JSON.parseObject(str)
|
|
|
+ result=true
|
|
|
+ }catch (e:java.lang.Exception){
|
|
|
+ result=false
|
|
|
+ }
|
|
|
+ return result
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun setMainMic(mainMic: Boolean) {
|
|
|
+ if (mainMic) {
|
|
|
+ val intent = Intent("com.mic.mic1")
|
|
|
+ sendBroadcast(intent)
|
|
|
+ } else {
|
|
|
+ val intent = Intent("com.mic.mic2")
|
|
|
+ sendBroadcast(intent)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ inner class TimeReceiver: BroadcastReceiver() {
|
|
|
+ override fun onReceive(context: Context, intent: Intent) {
|
|
|
+ if (intent.action == Intent.ACTION_TIME_TICK) {
|
|
|
+ if (inited) {
|
|
|
+ if (TcpClientHandler.getConnected()) {
|
|
|
+ tv_rtc_status.setBackgroundColor(Color.GREEN)
|
|
|
+ } else {
|
|
|
+ tv_rtc_status.setBackgroundColor(Color.RED)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (intent.action == Constants.HOOK_ON) {
|
|
|
+ Log.e(TAG,"手柄放下 ")
|
|
|
+ Constants.hookOn = true
|
|
|
+ AppUtils.switchAudioMode(activity, true)
|
|
|
+ } else if (intent.action == Constants.HOOK_OFF) {
|
|
|
+ Log.e(TAG,"手柄拿起 ")
|
|
|
+ Constants.hookOn = false
|
|
|
+ AppUtils.switchAudioMode(activity, false)
|
|
|
+ } else if (intent.action == Constants.KEY_CALL_UP) {
|
|
|
+ //手柄按键抬起
|
|
|
+ setMainMic(false)
|
|
|
+ } else if (intent.action == Constants.KEY_HOME_UP) {
|
|
|
+ //主板按键抬起
|
|
|
+ setMainMic(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|