|
@@ -0,0 +1,736 @@
|
|
|
|
+package com.wdkl.ncs.android.component.nursehome.activity
|
|
|
|
+
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
|
+import android.content.*
|
|
|
|
+import android.content.pm.PackageManager
|
|
|
|
+import android.graphics.Color
|
|
|
|
+import android.media.AudioManager
|
|
|
|
+import android.net.ConnectivityManager
|
|
|
|
+import android.net.Uri
|
|
|
|
+import android.os.*
|
|
|
|
+import android.provider.Settings
|
|
|
|
+import android.support.v4.app.Fragment
|
|
|
|
+import android.support.v4.app.FragmentManager
|
|
|
|
+import android.support.v4.app.FragmentTransaction
|
|
|
|
+import android.util.Log
|
|
|
|
+import android.view.KeyEvent
|
|
|
|
+import android.view.View
|
|
|
|
+import android.widget.ImageView
|
|
|
|
+import com.enation.javashop.android.jrouter.external.annotation.Router
|
|
|
|
+import com.enation.javashop.net.engine.model.NetState
|
|
|
|
+import com.wdkl.ncs.android.component.nursehome.R
|
|
|
|
+import com.wdkl.ncs.android.middleware.common.Constants
|
|
|
|
+import com.wdkl.ncs.android.component.nursehome.databinding.ActivityNurseHomeBinding
|
|
|
|
+import com.wdkl.ncs.android.component.nursehome.fragment.*
|
|
|
|
+import com.wdkl.ncs.android.component.nursehome.launch.NurseHomeLaunch
|
|
|
|
+import com.wdkl.ncs.android.component.nursehome.settingconfig.SettingConfig
|
|
|
|
+import com.wdkl.ncs.android.component.nursehome.util.*
|
|
|
|
+import com.wdkl.ncs.android.lib.base.BaseActivity
|
|
|
|
+import com.wdkl.ncs.android.lib.base.BaseApplication
|
|
|
|
+import com.wdkl.ncs.android.lib.db.DeviceBean
|
|
|
|
+import com.wdkl.ncs.android.lib.utils.*
|
|
|
|
+import com.wdkl.ncs.android.middleware.helper.PassCheckDialogHelper
|
|
|
|
+import com.wdkl.ncs.android.middleware.logic.contract.nursehome.NurseHomeActivityContract
|
|
|
|
+import com.wdkl.ncs.android.middleware.logic.presenter.nursehome.NurseHomeActivityPresenter
|
|
|
|
+import com.wdkl.ncs.android.middleware.model.ServerInfo
|
|
|
|
+import com.wdkl.ncs.android.middleware.model.dos.AppVersionDO
|
|
|
|
+import com.wdkl.ncs.android.middleware.model.dos.DeviceDO
|
|
|
|
+import com.wdkl.ncs.android.middleware.model.dto.TcpSeverDTO
|
|
|
|
+import com.wdkl.ncs.android.middleware.model.vo.HostDevicePartSettingVO
|
|
|
|
+import com.wdkl.ncs.android.middleware.model.vo.NurseDeviceInfoVO
|
|
|
|
+import com.wdkl.ncs.android.middleware.tcp.channel.*
|
|
|
|
+import com.wdkl.ncs.android.middleware.utils.CommonUtils
|
|
|
|
+import com.wdkl.ncs.android.middleware.utils.MessageEvent
|
|
|
|
+import com.wdkl.ncs.android.middleware.utils.StringUtil
|
|
|
|
+import com.wdkl.ncs.host.service.WdklSipService
|
|
|
|
+import kotlinx.android.synthetic.main.activity_sip_home.*
|
|
|
|
+import org.greenrobot.eventbus.EventBus
|
|
|
|
+import org.greenrobot.eventbus.Subscribe
|
|
|
|
+import org.greenrobot.eventbus.ThreadMode
|
|
|
|
+import org.linphone.core.AccountCreator
|
|
|
|
+import org.linphone.core.Factory
|
|
|
|
+import org.linphone.core.TransportType
|
|
|
|
+import java.io.File
|
|
|
|
+import java.io.FileOutputStream
|
|
|
|
+import java.io.InputStream
|
|
|
|
+import java.util.*
|
|
|
|
+import java.util.concurrent.Executors
|
|
|
|
+import java.util.concurrent.ScheduledExecutorService
|
|
|
|
+import java.util.concurrent.TimeUnit
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 首页Activity
|
|
|
|
+ */
|
|
|
|
+@Router(path = "/siphome/main")
|
|
|
|
+class SipHomeActivity : BaseActivity<NurseHomeActivityPresenter, ActivityNurseHomeBinding>(), NurseHomeActivityContract.View,
|
|
|
|
+ View.OnClickListener {
|
|
|
|
+ var TAG = SipHomeActivity::class.java.getSimpleName()
|
|
|
|
+
|
|
|
|
+ private var initialized = false
|
|
|
|
+ private val handler by lazy { Handler(Looper.getMainLooper()) }
|
|
|
|
+ private var executor: ScheduledExecutorService? = null
|
|
|
|
+
|
|
|
|
+ var currentFragment:Fragment? = null
|
|
|
|
+ var currentFragmentTwo:Fragment? = null
|
|
|
|
+
|
|
|
|
+ //通话界面fragment
|
|
|
|
+ private var skyCallFragment: Fragment? = null
|
|
|
|
+
|
|
|
|
+ var receiver :TimeReceiver? = null
|
|
|
|
+ var batteryBroadcastReceiver: BatteryBroadcastReceiver? = null
|
|
|
|
+
|
|
|
|
+ //当前选中的button id
|
|
|
|
+ var select_id: Int = 0
|
|
|
|
+ var pressTime: Long = 0
|
|
|
|
+
|
|
|
|
+ private var hookoffTime: Long = 0
|
|
|
|
+ private var hookonTime: Long = 0
|
|
|
|
+
|
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
+ val languageId: Int = SettingConfig.getLanguageId(this)
|
|
|
|
+ LocaleMangerUtils.setApplicationLanguageByIndex(this, languageId)
|
|
|
|
+
|
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 提供layoutID
|
|
|
|
+ */
|
|
|
|
+ override fun getLayId(): Int {
|
|
|
|
+ return R.layout.activity_sip_home
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ *初始化依赖注入
|
|
|
|
+ */
|
|
|
|
+ override fun bindDagger() {
|
|
|
|
+ NurseHomeLaunch.component.inject(this)
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ *初始化操作
|
|
|
|
+ */
|
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
|
+ override fun init() {
|
|
|
|
+ AppTool.SystemUI.showNavigationBar(this,false)
|
|
|
|
+ AppTool.SystemUI.ImmersiveWithBottomBarColor(this, Color.BLACK)
|
|
|
|
+
|
|
|
|
+ if (Build.BOARD.equals("k37mv1_64_bsp") || Build.MODEL.equals("KT10-3F") || "m3520b_bnkj_zx".equals(Build.MODEL)) {
|
|
|
|
+ StatusBarHelper.toggleStatusBar(activity, true)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Constants.sip_id = CommonUtils.getSipAccount(activity)
|
|
|
|
+ sip_name.text = "sip: " + Constants.sip_id
|
|
|
|
+
|
|
|
|
+ permissionGranted()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun permissionGranted() {
|
|
|
|
+ if (SettingConfig.getSipEnabled(activity)) {
|
|
|
|
+ //启动sip服务
|
|
|
|
+ val serviceIntent = Intent(BaseApplication.appContext, WdklSipService::class.java)
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
+ //android8.0以上通过startForegroundService启动service
|
|
|
|
+ startForegroundService(serviceIntent)
|
|
|
|
+ } else {
|
|
|
|
+ startService(serviceIntent)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ("YUNPAI_H6".equals(Build.MODEL) || "YUNPAI_H6B".equals(Build.MODEL) || "m3520b_bnkj_zx".equals(Build.MODEL)) {
|
|
|
|
+ Constants.device_serial_id = Constants.imei
|
|
|
|
+ if ("YUNPAI_H6".equals(Build.MODEL)) {
|
|
|
|
+ startYunpaiPlugin()
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ Constants.device_serial_id = Constants.mac
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SpeechUtil.getInstance().init(BaseApplication.appContext) {
|
|
|
|
+ //如果tts启用失败或者不支持中文则将语音播报切换到音乐模式
|
|
|
|
+ if (!it) {
|
|
|
|
+ if (SettingConfig.getTtsMode(BaseApplication.appContext) == SettingConfig.TTS_ON) {
|
|
|
|
+ SettingConfig.setTtsMode(BaseApplication.appContext, SettingConfig.TTS_OFF)
|
|
|
|
+ showMessage(R.string.tts_disabled)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
+ if (!Settings.canDrawOverlays(this)) {
|
|
|
|
+ val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
|
|
|
+ Uri.parse("package:$packageName"))
|
|
|
|
+ startActivityForResult(intent, 10)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
+ if (!Settings.System.canWrite(this)) {
|
|
|
|
+ val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
|
|
|
|
+ intent.data = Uri.parse("package:" + this.packageName)
|
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
|
+ startActivityForResult(intent, 11)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //检查服务器地址接口是否可用,可用则进入下一步获取设备信息,不可用则稍后再次尝试
|
|
|
|
+ gotoMainHome()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 = "yunpai_launch_app.apk"
|
|
|
|
+ val dstPath = Environment.getExternalStorageDirectory().path + "/Download"
|
|
|
|
+ val file = File(dstPath)
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ file.mkdirs()
|
|
|
|
+ }
|
|
|
|
+ val outFile = File(dstPath + "/" + fileName)
|
|
|
|
+ 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拷贝完成,即将安装
|
|
|
|
+ val action = "com.miki.slient.INSTALL_CUSTOMER_PACKAGES"
|
|
|
|
+ val intent = Intent(action)
|
|
|
|
+ intent.putExtra("apkPath", dstPath + "/" + fileName)
|
|
|
|
+ intent.putExtra("packageName", "com.miki.sensortest")
|
|
|
|
+ sendBroadcast(intent)
|
|
|
|
+
|
|
|
|
+ runOnUiThread {
|
|
|
|
+ showMessage(R.string.plugin_update_tips)
|
|
|
|
+ }
|
|
|
|
+ } catch (e: java.lang.Exception) {
|
|
|
|
+ e.printStackTrace()
|
|
|
|
+ }
|
|
|
|
+ }.start()
|
|
|
|
+ }
|
|
|
|
+ } catch (t: Throwable) {
|
|
|
|
+ t.printStackTrace()
|
|
|
|
+ showMessage(StringUtil.getResString(R.string.plugin_start_failed) + t.message)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun gotoMainHome() {
|
|
|
|
+ //初始化完成
|
|
|
|
+ if (initialized) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ initialized = true
|
|
|
|
+
|
|
|
|
+ currentFragment = HomeFragment()
|
|
|
|
+ supportFragmentManager.beginTransaction().replace(R.id.middle_fralyout, currentFragment, "").commitAllowingStateLoss()
|
|
|
|
+
|
|
|
|
+ home_radio_bt.isChecked = true
|
|
|
|
+
|
|
|
|
+ regReceiver()//注册广播
|
|
|
|
+ updateNetState()
|
|
|
|
+
|
|
|
|
+ startScheduledExecutor()
|
|
|
|
+
|
|
|
|
+ //记录app启动时间
|
|
|
|
+ val lastTime = SettingConfig.getAppStartTime(activity)
|
|
|
|
+ val currentTime = TimeTransition.getDateTime(System.currentTimeMillis(), "MM-dd HH:mm:ss")
|
|
|
|
+ debugLog(TAG, "app last start time: $lastTime, current time: $currentTime")
|
|
|
|
+ SettingConfig.setAppStartTime(activity, currentTime)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (Settings.canDrawOverlays(this) && Settings.System.canWrite(this)) {
|
|
|
|
+ if (Build.BOARD.equals("k37mv1_64_bsp") || Build.MODEL.equals("KT10-3F") || "m3520b_bnkj_zx".equals(Build.MODEL)) {
|
|
|
|
+ StatusBarHelper.toggleStatusBar(activity, false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ updatePower()
|
|
|
|
+
|
|
|
|
+ Thread {
|
|
|
|
+ try {
|
|
|
|
+ if (SettingConfig.getSipEnabled(activity)) {
|
|
|
|
+ //5s后配置sip账号
|
|
|
|
+ Thread.sleep(5000)
|
|
|
|
+
|
|
|
|
+ //无服务器时端口必须,固定5060,否则拨打IP时,也需加上端口号。如:sip:192.168.1.100:6666
|
|
|
|
+ val transports = Factory.instance().createTransports()
|
|
|
|
+ transports.setUdpPort(5060)
|
|
|
|
+ transports.setTcpPort(5060)
|
|
|
|
+ WdklSipService.getCore().setTransports(transports)
|
|
|
|
+
|
|
|
|
+ //设置显示名称
|
|
|
|
+ val accountCreator = WdklSipService.getCore().createAccountCreator(null)
|
|
|
|
+ accountCreator.setUsername(Constants.sip_id) //此处就当设置为房间床位号
|
|
|
|
+ accountCreator.setDomain(NetHelper.getInstance().getLocalIP())
|
|
|
|
+ accountCreator.setTransport(TransportType.Udp)
|
|
|
|
+ val cfg = accountCreator.createProxyConfig()
|
|
|
|
+ WdklSipService.getCore().setDefaultProxyConfig(cfg)
|
|
|
|
+
|
|
|
|
+ Log.e(TAG, "sip service started...")
|
|
|
|
+ }
|
|
|
|
+ } catch (ex: Exception) {
|
|
|
|
+ ex.printStackTrace()
|
|
|
|
+ }
|
|
|
|
+ }.start()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun getPower(): Int {
|
|
|
|
+ val mBatteryManager = getSystemService(BATTERY_SERVICE) as BatteryManager
|
|
|
|
+ val power = mBatteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
|
|
|
+ Log.d(TAG, "power energy: power percent: $power")
|
|
|
|
+
|
|
|
|
+ return power
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun updatePower() {
|
|
|
|
+ battery_state_img.setImageResource(R.drawable.wdkl_stat_sys_battery)
|
|
|
|
+ battery_state_img.drawable.level = getPower()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onResume() {
|
|
|
|
+ super.onResume()
|
|
|
|
+
|
|
|
|
+ if (initialized && Settings.canDrawOverlays(this) && Settings.System.canWrite(this)) {
|
|
|
|
+ if (Build.BOARD.equals("k37mv1_64_bsp") || Build.MODEL.equals("KT10-3F") || "m3520b_bnkj_zx".equals(Build.MODEL)) {
|
|
|
|
+ StatusBarHelper.toggleStatusBar(activity, false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onStop() {
|
|
|
|
+ super.onStop()
|
|
|
|
+
|
|
|
|
+ if (Build.BOARD.equals("k37mv1_64_bsp") || Build.MODEL.equals("KT10-3F") || "m3520b_bnkj_zx".equals(Build.MODEL)) {
|
|
|
|
+ StatusBarHelper.toggleStatusBar(activity, true)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 时间变化监听
|
|
|
|
+ */
|
|
|
|
+ private fun regReceiver() {
|
|
|
|
+ receiver = TimeReceiver()
|
|
|
|
+ val intentFilter = IntentFilter()
|
|
|
|
+ intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION)
|
|
|
|
+ //手柄状态监听
|
|
|
|
+ intentFilter.addAction(Constants.HOOK_OFF)
|
|
|
|
+ intentFilter.addAction(Constants.HOOK_ON)
|
|
|
|
+ registerReceiver(receiver, intentFilter)
|
|
|
|
+
|
|
|
|
+ //注册电池变化广播监听
|
|
|
|
+ val batteryInterFilter = IntentFilter()
|
|
|
|
+ batteryInterFilter.addAction(Intent.ACTION_BATTERY_CHANGED)
|
|
|
|
+ //batteryInterFilter.addAction(Intent.ACTION_POWER_CONNECTED)
|
|
|
|
+ //batteryInterFilter.addAction(Intent.ACTION_POWER_DISCONNECTED)
|
|
|
|
+ batteryBroadcastReceiver = BatteryBroadcastReceiver(battery_state_img)
|
|
|
|
+ registerReceiver(batteryBroadcastReceiver, batteryInterFilter)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun showDeviceData(data: NurseDeviceInfoVO) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun setLedDeviceInfo(data: ArrayList<DeviceDO>) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *绑定事件
|
|
|
|
+ */
|
|
|
|
+ override fun bindEvent() {
|
|
|
|
+ home_radio_bt.setOnClickListener(this)
|
|
|
|
+ system_settings_radio_bt.setOnClickListener(this)
|
|
|
|
+ sip_device_radio_bt.setOnClickListener(this)
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ *页面销毁回调
|
|
|
|
+ */
|
|
|
|
+ override fun destory() {
|
|
|
|
+ handler.removeCallbacksAndMessages(null)
|
|
|
|
+ Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
|
+ if (receiver != null) {
|
|
|
|
+ unregisterReceiver(receiver)
|
|
|
|
+ }
|
|
|
|
+ if (batteryBroadcastReceiver != null) {
|
|
|
|
+ unregisterReceiver(batteryBroadcastReceiver)
|
|
|
|
+ }
|
|
|
|
+ if (Build.BOARD.equals("k37mv1_64_bsp") || Build.MODEL.equals("KT10-3F") || "m3520b_bnkj_zx".equals(Build.MODEL)) {
|
|
|
|
+ StatusBarHelper.toggleStatusBar(activity, true)
|
|
|
|
+ }
|
|
|
|
+ SpeechUtil.getInstance().release()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *处理错误信息
|
|
|
|
+ */
|
|
|
|
+ override fun onError(message: String, type: Int) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onNoneNet() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *耗时加载完成
|
|
|
|
+ */
|
|
|
|
+ override fun complete(message: String, type: Int) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *耗时加载开始
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ override fun start() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *处理网络状态
|
|
|
|
+ */
|
|
|
|
+ override fun networkMonitor(state: NetState) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun showAppVersion(appInfo: AppVersionDO) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 显示设备tcp相关的配置信息
|
|
|
|
+ */
|
|
|
|
+ override fun showTcpData(data: TcpSeverDTO) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun setServerInfo(data: ServerInfo) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 得到设置配置的信息
|
|
|
|
+ */
|
|
|
|
+ override fun showSettingData(data: HostDevicePartSettingVO) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ override fun onClick(p0: View) {
|
|
|
|
+ when(p0.id){
|
|
|
|
+ R.id.home_radio_bt ->{
|
|
|
|
+ if (select_id != 0) {
|
|
|
|
+ showMiddleFragment(HomeFragment())
|
|
|
|
+ removeRightFragment()
|
|
|
|
+ select_id = 0
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ R.id.system_settings_radio_bt ->{
|
|
|
|
+ if (select_id != 1) {
|
|
|
|
+ select_id = 1
|
|
|
|
+ showRightFragment(SystemSettingsFragment())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ R.id.sip_device_radio_bt -> {
|
|
|
|
+ if (select_id != 2) {
|
|
|
|
+ PassCheckDialogHelper.showDialog(activity) {
|
|
|
|
+ select_id = 2
|
|
|
|
+ showMiddleFragment(DeviceManageFragment())
|
|
|
|
+ removeRightFragment()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //显示中间主界面
|
|
|
|
+ fun showMiddleFragment(fragment: Fragment) {
|
|
|
|
+ supportFragmentManager.inTransaction {
|
|
|
|
+ remove(currentFragment)
|
|
|
|
+ currentFragment = fragment
|
|
|
|
+ if(currentFragmentTwo != null){
|
|
|
|
+ remove(currentFragmentTwo)
|
|
|
|
+ currentFragmentTwo = null
|
|
|
|
+ }
|
|
|
|
+ add(R.id.middle_fralyout, fragment)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //显示右侧设置界面
|
|
|
|
+ fun showRightFragment(fragment: Fragment){
|
|
|
|
+ supportFragmentManager.inTransaction {
|
|
|
|
+ if(currentFragmentTwo != null){
|
|
|
|
+ remove(currentFragmentTwo)
|
|
|
|
+ }
|
|
|
|
+ currentFragmentTwo = fragment
|
|
|
|
+ add(R.id.right_fralyout, fragment)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun removeRightFragment() {
|
|
|
|
+ if (currentFragmentTwo != null) {
|
|
|
|
+ supportFragmentManager.inTransaction {
|
|
|
|
+ remove(currentFragmentTwo)
|
|
|
|
+ }
|
|
|
|
+ currentFragmentTwo = null
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun addCallFragment(fragment: Fragment) {
|
|
|
|
+ if (skyCallFragment != null) {
|
|
|
|
+ supportFragmentManager.beginTransaction()
|
|
|
|
+ .remove(skyCallFragment)
|
|
|
|
+ .commitAllowingStateLoss()
|
|
|
|
+ skyCallFragment = null
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ skyCallFragment = fragment
|
|
|
|
+ supportFragmentManager.beginTransaction()
|
|
|
|
+ .setCustomAnimations(R.anim.slide_down_in, R.anim.slide_up_out)
|
|
|
|
+ .add(R.id.call_frame, fragment)
|
|
|
|
+ .commitAllowingStateLoss()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun removeCallFragment() {
|
|
|
|
+ if (skyCallFragment != null) {
|
|
|
|
+ supportFragmentManager.beginTransaction()
|
|
|
|
+ //.setCustomAnimations(R.anim.slide_down_in, R.anim.slide_down_out)
|
|
|
|
+ .remove(skyCallFragment)
|
|
|
|
+ .commitAllowingStateLoss()
|
|
|
|
+ skyCallFragment = null
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun removeFragment(fragment: Fragment) {
|
|
|
|
+ supportFragmentManager.beginTransaction().remove(fragment).commitAllowingStateLoss()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ inline fun FragmentManager.inTransaction(func: FragmentTransaction.() -> FragmentTransaction) {
|
|
|
|
+ beginTransaction().func().commitAllowingStateLoss()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * 启动一个定时任务执行检测
|
|
|
|
+ */
|
|
|
|
+ private fun startScheduledExecutor() {
|
|
|
|
+ val timerTask: TimerTask = object : TimerTask() {
|
|
|
|
+ override fun run() {
|
|
|
|
+ runOnUiThread {
|
|
|
|
+ updateNetState()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ executor = Executors.newSingleThreadScheduledExecutor()
|
|
|
|
+ executor?.scheduleAtFixedRate(timerTask, 100, 90, TimeUnit.SECONDS)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ inner class TimeReceiver: BroadcastReceiver() {
|
|
|
|
+ override fun onReceive(context: Context, intent: Intent) {
|
|
|
|
+ if (intent.action == Constants.HOOK_ON) {
|
|
|
|
+ Log.e(TAG,"手柄放下 ")
|
|
|
|
+ if (System.currentTimeMillis() - hookonTime > 2000) {
|
|
|
|
+ Constants.hookOn = true
|
|
|
|
+ VoiceManagerUtil.switchAudioMode(activity, true)
|
|
|
|
+ VoiceManagerUtil.setCallVoice(activity, SettingConfig.getHostCallVolume(activity))
|
|
|
|
+
|
|
|
|
+ EventBus.getDefault().post(MessageEvent("handoff", Constants.EVENT_END_CALL))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ hookonTime = System.currentTimeMillis()
|
|
|
|
+ } else if (intent.action == Constants.HOOK_OFF) {
|
|
|
|
+ Log.e(TAG,"手柄拿起 ")
|
|
|
|
+ EventBus.getDefault().post(MessageEvent(false, Constants.EVENT_TOGGLE_SPEAKER))
|
|
|
|
+ if (System.currentTimeMillis() - hookoffTime > 2000) {
|
|
|
|
+ Constants.hookOn = false
|
|
|
|
+ VoiceManagerUtil.switchAudioMode(activity, false)
|
|
|
|
+ VoiceManagerUtil.setCallVoice(activity, SettingConfig.getHostCallVolume(activity))
|
|
|
|
+
|
|
|
|
+ EventBus.getDefault().post(MessageEvent("hookoff", Constants.EVENT_HOOK_OFF))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ hookoffTime = System.currentTimeMillis()
|
|
|
|
+ } else if (intent.action == ConnectivityManager.CONNECTIVITY_ACTION) {
|
|
|
|
+ updateNetState()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
|
|
|
+ Log.d(TAG, "keyDown ====> keyCode: $keyCode, action: ${event?.action}")
|
|
|
|
+ if (keyCode == 135) {
|
|
|
|
+ //手柄拿起
|
|
|
|
+ EventBus.getDefault().post(MessageEvent(false, Constants.EVENT_TOGGLE_SPEAKER))
|
|
|
|
+ if (System.currentTimeMillis() - hookoffTime > 2000) {
|
|
|
|
+ Constants.hookOn = false
|
|
|
|
+ VoiceManagerUtil.switchAudioMode(activity, false)
|
|
|
|
+ VoiceManagerUtil.setCallVoice(activity, SettingConfig.getHostCallVolume(activity))
|
|
|
|
+
|
|
|
|
+ EventBus.getDefault().post(MessageEvent("hookoff", Constants.EVENT_HOOK_OFF))
|
|
|
|
+ }
|
|
|
|
+ hookoffTime = System.currentTimeMillis()
|
|
|
|
+ } else if (keyCode == 134) {
|
|
|
|
+ //手柄放下
|
|
|
|
+ if (System.currentTimeMillis() - hookonTime > 2000) {
|
|
|
|
+ Constants.hookOn = true
|
|
|
|
+ VoiceManagerUtil.switchAudioMode(activity, true)
|
|
|
|
+ VoiceManagerUtil.setCallVoice(activity, SettingConfig.getHostCallVolume(activity))
|
|
|
|
+
|
|
|
|
+ EventBus.getDefault().post(MessageEvent("handoff", Constants.EVENT_END_CALL))
|
|
|
|
+ }
|
|
|
|
+ hookonTime = System.currentTimeMillis()
|
|
|
|
+ }
|
|
|
|
+ return super.onKeyDown(keyCode, event)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private fun updateNetState() {
|
|
|
|
+ if (NetHelper.getInstance().networkType == ConnectivityManager.TYPE_WIFI) {
|
|
|
|
+ wifi_state_imagev.visibility = View.VISIBLE
|
|
|
|
+ wifi_state_imagev.setImageResource(R.drawable.ic_wifi_success)
|
|
|
|
+ ethernet_state_imagev.visibility = View.GONE
|
|
|
|
+ } else if (NetHelper.getInstance().networkType == ConnectivityManager.TYPE_ETHERNET) {
|
|
|
|
+ ethernet_state_imagev.visibility = View.VISIBLE
|
|
|
|
+ ethernet_state_imagev.setImageResource(R.drawable.ic_ethernet_success)
|
|
|
|
+ wifi_state_imagev.visibility = View.GONE
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onBackPressed() {
|
|
|
|
+ //禁用返回
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
+ fun onMoonEvent(messageEvent: MessageEvent) {
|
|
|
|
+ when (messageEvent.getType()) {
|
|
|
|
+
|
|
|
|
+ //退出通话界面
|
|
|
|
+ Constants.EVENT_REMOVE_CALL_FRAGMENT -> {
|
|
|
|
+ if (skyCallFragment != null) {
|
|
|
|
+ removeCallFragment()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DeviceChannel.calling = false
|
|
|
|
+ Constants.CALL_STATE = Constants.CALL_STANDBY
|
|
|
|
+ VoiceManagerUtil.setAudioMode(BaseApplication.appContext, AudioManager.MODE_NORMAL)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Constants.SIP_INCOMING_VOICE_CALL -> {
|
|
|
|
+ val callName = messageEvent.getMessage() as String
|
|
|
|
+ val fragment = SipComingCallFragment()
|
|
|
|
+ val bundle = Bundle()
|
|
|
|
+ bundle.putInt("call_state", 1)
|
|
|
|
+ bundle.putBoolean("visiting", false)
|
|
|
|
+ bundle.putBoolean("audio_only", true)
|
|
|
|
+ bundle.putString("call_name", callName)
|
|
|
|
+ fragment.arguments = bundle
|
|
|
|
+ addCallFragment(fragment)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Constants.SIP_INCOMING_VIDEO_CALL -> {
|
|
|
|
+ val callName = messageEvent.getMessage() as String
|
|
|
|
+ val fragment = SipComingCallFragment()
|
|
|
|
+ val bundle = Bundle()
|
|
|
|
+ bundle.putInt("call_state", 1)
|
|
|
|
+ bundle.putBoolean("visiting", false)
|
|
|
|
+ bundle.putBoolean("audio_only", false)
|
|
|
|
+ bundle.putString("call_name", callName)
|
|
|
|
+ fragment.arguments = bundle
|
|
|
|
+ addCallFragment(fragment)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Constants.SIP_OUTGOING_VOICE_CALL -> {
|
|
|
|
+ val device = messageEvent.getMessage() as DeviceBean
|
|
|
|
+ val fragment = SipComingCallFragment()
|
|
|
|
+ val bundle = Bundle()
|
|
|
|
+ bundle.putInt("call_state", 0)
|
|
|
|
+ bundle.putBoolean("visiting", false)
|
|
|
|
+ bundle.putBoolean("audio_only", true)
|
|
|
|
+ bundle.putString("call_name", device.sipId)
|
|
|
|
+ bundle.putString("targetId", device.sipIp)
|
|
|
|
+ fragment.arguments = bundle
|
|
|
|
+ addCallFragment(fragment)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Constants.SIP_OUTGOING_VIDEO_CALL -> {
|
|
|
|
+ val device = messageEvent.getMessage() as DeviceBean
|
|
|
|
+ val fragment = SipComingCallFragment()
|
|
|
|
+ val bundle = Bundle()
|
|
|
|
+ bundle.putInt("call_state", 0)
|
|
|
|
+ bundle.putBoolean("visiting", false)
|
|
|
|
+ bundle.putBoolean("audio_only", false)
|
|
|
|
+ bundle.putString("call_name", device.sipId)
|
|
|
|
+ bundle.putString("targetId", device.sipIp)
|
|
|
|
+ fragment.arguments = bundle
|
|
|
|
+ addCallFragment(fragment)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ inner class BatteryBroadcastReceiver(private val battery_view: ImageView) : BroadcastReceiver() {
|
|
|
|
+ @SuppressLint("LongLogTag")
|
|
|
|
+ override fun onReceive(context: Context, intent: Intent) {
|
|
|
|
+
|
|
|
|
+ val status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1)
|
|
|
|
+ val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
|
|
|
|
+ val scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
|
|
|
|
+ //Log.e("battery", "status: $status, level: $level, scale: $scale")
|
|
|
|
+
|
|
|
|
+ when (status) {
|
|
|
|
+ BatteryManager.BATTERY_STATUS_UNKNOWN -> {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BatteryManager.BATTERY_STATUS_CHARGING -> { //充电中
|
|
|
|
+ battery_view.setImageResource(R.drawable.wdkl_stat_sys_battery_charge)
|
|
|
|
+ battery_view.drawable.level = level
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ else -> { //未充电
|
|
|
|
+ battery_view.setImageResource(R.drawable.wdkl_stat_sys_battery)
|
|
|
|
+ battery_view.drawable.level = level
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|