TwoPersonActivity.kt 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. package com.example.chemical.ui.verify
  2. import android.os.*
  3. import android.view.LayoutInflater
  4. import android.view.MotionEvent
  5. import android.view.View
  6. import android.widget.TextView
  7. import com.bumptech.glide.Glide
  8. import com.bumptech.glide.load.engine.DiskCacheStrategy
  9. import com.bumptech.glide.request.RequestOptions
  10. import com.example.chemical.ChemicalApp
  11. import com.example.chemical.R
  12. import com.example.chemical.comm.Constants
  13. import com.example.chemical.databinding.ActivityTwoPersonBinding
  14. import com.example.chemical.ui.DoubleDialogBean
  15. import com.example.chemical.ui.common.BaseCountDownActivity
  16. import com.example.chemical.utils.MediaPlayerHelper
  17. import com.example.chemical.utils.SharedPreferencesHelper
  18. import com.example.chemical.utils.UiManager
  19. import com.example.chemical.weidith.CustomDialog
  20. import com.example.chemical.weidith.DoublePeopleDialog
  21. import com.rc.core.log.RcLog
  22. import com.rc.httpcore.HttpClient
  23. import com.rc.httpcore.HttpConfig
  24. import com.rc.httpcore.bean.UserValidationBean
  25. import com.rc.httpcore.client.ApiRepository
  26. import com.rc.httpcore.exception.NetException
  27. import com.rc.httpcore.vo.request.FaceCompareReq
  28. import io.fotoapparat.Fotoapparat
  29. import io.fotoapparat.facedetector.processor.FaceDetectorProcessor
  30. import io.fotoapparat.log.fileLogger
  31. import io.fotoapparat.log.logcat
  32. import io.fotoapparat.log.loggers
  33. import io.fotoapparat.selector.back
  34. import io.fotoapparat.selector.front
  35. import retrofit2.HttpException
  36. import java.io.File
  37. import java.net.ConnectException
  38. import java.net.SocketTimeoutException
  39. import java.text.SimpleDateFormat
  40. import java.util.*
  41. //双人-人脸验证
  42. class TwoPersonActivity : BaseCountDownActivity<ActivityTwoPersonBinding>() {
  43. //第一个人
  44. private lateinit var mFotoapparat: Fotoapparat
  45. //第二个人
  46. private lateinit var mFotoapparatTwo: Fotoapparat
  47. //人脸验证时间
  48. private val totalTimeInMillis: Long = 60 * 1000 // 总时常
  49. private var count = 1 //认证次数
  50. private var mChemicalLevel: Int = 0 //管控类型
  51. private var mTag = 0 //0 新增入库 1 归还废弃空瓶等 2 待入库 3 领用认证需要换api 需要判断不同权限 进行验证通过
  52. private var mUserId: String? = null //第二个人
  53. private var mDoorId: String? = null
  54. private var isLogin = false //是否是登陆人
  55. private val mDoubleDialogBean = mutableListOf<DoubleDialogBean>() //双人认证 需要显示的
  56. private val handlerBack = Handler(Looper.getMainLooper())
  57. private val handlerBackTwo = Handler(Looper.getMainLooper())
  58. private val countHandler = Handler(Looper.getMainLooper()) //整个页面 60秒后 直接关闭
  59. override fun createViewBinding() = ActivityTwoPersonBinding.inflate(LayoutInflater.from(this))
  60. override fun initViews(savedInstanceState: Bundle?) {
  61. super.initViews(savedInstanceState)
  62. Constants.AUTHENTICATION = false
  63. try {
  64. SharedPreferencesHelper.clearList(this)
  65. } catch (e: Exception) {
  66. }
  67. viewBinding.deptName.text = "${ChemicalApp.confs!!.deptName}-${ChemicalApp.confs!!.roomNum}"
  68. viewBinding.tvReturn.text = "返回${ChemicalApp.confs!!.backTime}s"
  69. Glide.with(this)
  70. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.confs!!.circularLogo}")
  71. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  72. .into(viewBinding.image)
  73. mTag = intent.getIntExtra("mTag", 0)
  74. mDoorId = intent.getStringExtra("doorId") //柜子id
  75. mChemicalLevel = intent.getIntExtra("chemicalLevel", 0)
  76. val intExtra = intent.getIntExtra("hides", 0)
  77. when (intExtra) {
  78. 4 -> {
  79. viewBinding.lint.visibility = View.GONE
  80. viewBinding.lintTwo.visibility = View.GONE
  81. }
  82. 0 -> {
  83. viewBinding.scan.visibility = View.GONE
  84. viewBinding.scanTwo.visibility = View.GONE
  85. }
  86. 1 -> {
  87. viewBinding.campus.visibility = View.GONE
  88. viewBinding.campusTwo.visibility = View.GONE
  89. }
  90. }
  91. val map = mutableMapOf<String, Any>()
  92. //跳转扫码
  93. map["chemicalLevel"] = mChemicalLevel //管控类型
  94. map["doorId"] = "$mDoorId" //柜子id
  95. map["mTag"] = mTag
  96. map["hides"] = intExtra //隐藏扫码
  97. viewBinding.scan.setOnClickListener {
  98. UiManager.switcher(this, map, ScanCodeTwoActivity::class.java)
  99. finish()
  100. }
  101. viewBinding.campus.setOnClickListener {
  102. UiManager.switcher(this, map, SwipeCodeTwoActivity::class.java)
  103. finish()
  104. }
  105. viewBinding.scanTwo.setOnClickListener {
  106. UiManager.switcher(this, map, ScanCodeTwoActivity::class.java)
  107. finish()
  108. }
  109. viewBinding.campusTwo.setOnClickListener {
  110. UiManager.switcher(this, map, SwipeCodeTwoActivity::class.java)
  111. finish()
  112. }
  113. viewBinding.tvReturn.setOnClickListener {
  114. finish()
  115. }
  116. mFotoapparat = Fotoapparat.with(this)
  117. .into(viewBinding.cameraView)
  118. .lensPosition(
  119. if (Constants.FACE_TAG == 0) {
  120. front()
  121. } else {
  122. back()
  123. }
  124. )//front()前置 back 后置
  125. .frameProcessor(
  126. FaceDetectorProcessor.with(this)
  127. .listener { faces ->
  128. RcLog.info("=========认证中")
  129. viewBinding.rectanglesView.setRectangles(faces)
  130. }.build()
  131. )
  132. .logger(loggers(logcat(), fileLogger(this)))
  133. .build()
  134. MediaPlayerHelper.playRawMp3(
  135. this@TwoPersonActivity,
  136. R.raw.diyiren_renlianshibie
  137. )
  138. handlerBackTwo.post(countdownRunnableTwo)
  139. countHandler.postDelayed({
  140. finish()
  141. }, totalTimeInMillis) // 15秒后关闭对话框
  142. }
  143. override fun onStart() {
  144. super.onStart()
  145. mFotoapparat.start()
  146. }
  147. override fun onStop() {
  148. super.onStop()
  149. try {
  150. mFotoapparat.stop()
  151. } catch (e: Exception) {
  152. }
  153. try {
  154. mFotoapparatTwo.stop()
  155. } catch (e: Exception) {
  156. }
  157. }
  158. private fun toggleCameraTwo() {
  159. mFotoapparat.stop() //停止第一个 打开第二个
  160. mFotoapparatTwo.stop()
  161. mFotoapparatTwo.start()
  162. }
  163. //第二个人脸
  164. private fun faceTwo() {
  165. count++
  166. // toggleCameraTwo()
  167. mFotoapparatTwo = Fotoapparat.with(this)
  168. .into(viewBinding.cameraViewTwo)
  169. .lensPosition(
  170. if (Constants.FACE_TAG == 0) {
  171. front()
  172. } else {
  173. back()
  174. }
  175. )//front()前置 back 后置
  176. .frameProcessor(
  177. FaceDetectorProcessor.with(this)
  178. .listener { faces ->
  179. viewBinding.rectanglesViewTwo.setRectangles(faces)
  180. }.build()
  181. )
  182. .logger(loggers(logcat(), fileLogger(this)))
  183. .build()
  184. mFotoapparatTwo.stop()
  185. mFotoapparatTwo.start()
  186. }
  187. private val countdownRunnableTwo = object : Runnable {
  188. override fun run() {
  189. // if (timeLeftInSeconds > 0) {
  190. // mTvView!!.text = "${timeLeftInSeconds}秒后自动返回首页"
  191. // timeLeftInSeconds--
  192. // handlerBack.postDelayed(this, 1000)
  193. // } else {
  194. // mDialogsAut!!.dismiss()
  195. // finish()
  196. // }
  197. RcLog.info("=======双人刷卡人脸认证中")
  198. takePicture()
  199. handlerBackTwo.postDelayed(this, 4500)
  200. }
  201. }
  202. override fun onBackPressed() {
  203. super.onBackPressed()
  204. finish()
  205. }
  206. override fun cdTime(cd: Int) {
  207. viewBinding.tvReturn.text = "返回${cd}s"
  208. }
  209. private fun callFaceMatchingApi(
  210. featureData: File,
  211. ) {
  212. showLoading("认证中....")
  213. val param = FaceCompareReq().apply {
  214. data = null
  215. subId = ChemicalApp.subjectId
  216. doorId = mDoorId
  217. }
  218. val disposable = ApiRepository.checkUserFaceByPic(featureData, param)
  219. .subscribe({ data ->
  220. dismissLoading()
  221. // if (count == 1) {
  222. // RcLog.info("第a一个人 $mUserId ${data.userId}")
  223. // }
  224. if (mUserId!=null){
  225. if (mUserId.equals(data.userId)) {
  226. customDialogView(0, "不能是同一个人")
  227. // startHandler()
  228. return@subscribe
  229. }
  230. }
  231. //0 新增入库 1 领用归还废弃空瓶等 2 待入库 需要判断不同权限 进行验证通过
  232. when (mTag) {
  233. 0 -> {
  234. //新增入库
  235. if (count == 1) {
  236. if (data.userId == ChemicalApp.userData!!.userId) {
  237. isLogin = true
  238. faceTwo()
  239. customDialog(data.userName, data.faceImg,data.userId)
  240. var bean =
  241. DoubleDialogBean(data.userName, data.faceImg, data.userId)
  242. mDoubleDialogBean.add(bean)
  243. } else {
  244. if (mChemicalLevel == 1) {
  245. //管控 校级管理员或院级管理
  246. if (data.adminUser == true || data.safeUser == true || data.cabinetAdmin == true) {
  247. var bean = DoubleDialogBean(
  248. data.userName,
  249. data.faceImg,
  250. data.userId
  251. )
  252. mDoubleDialogBean.add(bean)
  253. customDialog(data.userName, data.faceImg, data.userId)
  254. faceTwo()
  255. // if (count == 2) {
  256. // var bean = DoubleDialogBean(
  257. // data.userName,
  258. // data.faceImg,
  259. // data.userId
  260. // )
  261. // mDoubleDialogBean.add(bean)
  262. // customDialog(data.userName, data.faceImg, data.userId)
  263. // faceTwo()
  264. // } else {
  265. // var bean = DoubleDialogBean(
  266. // data.userName,
  267. // data.faceImg,
  268. // data.userId
  269. // )
  270. // mDoubleDialogBean.add(bean)
  271. // passThrough()
  272. // }
  273. } else {
  274. customDialogView(0, "无权限信息")
  275. }
  276. } else {
  277. if (data.adminUser == true || data.safeUser == true || data.cabinetAdmin == true) {
  278. faceTwo()
  279. customDialog(data.userName, data.faceImg, data.userId)
  280. var bean = DoubleDialogBean(
  281. data.userName,
  282. data.faceImg,
  283. data.userId
  284. )
  285. mDoubleDialogBean.add(bean)
  286. // if (count == 2) {
  287. // faceTwo()
  288. // customDialog(data.userName, data.faceImg, data.userId)
  289. // var bean = DoubleDialogBean(
  290. // data.userName,
  291. // data.faceImg,
  292. // data.userId
  293. // )
  294. // mDoubleDialogBean.add(bean)
  295. // } else {
  296. // var bean = DoubleDialogBean(
  297. // data.userName,
  298. // data.faceImg,
  299. // data.userId
  300. // )
  301. // mDoubleDialogBean.add(bean)
  302. // passThrough()
  303. // }
  304. } else {
  305. customDialogView(0, "无权限信息")
  306. }
  307. }
  308. }
  309. } else {
  310. if (isLogin) {
  311. //已经有登陆人
  312. if (mChemicalLevel == 1) {
  313. //管控 校级管理员或院级管理
  314. if (data.adminUser == true || data.safeUser == true || data.cabinetAdmin == true) {
  315. var bean = DoubleDialogBean(
  316. data.userName,
  317. data.faceImg,
  318. data.userId
  319. )
  320. mDoubleDialogBean.add(bean)
  321. passThrough()
  322. } else {
  323. customDialogView(0, "无权限信息")
  324. }
  325. } else {
  326. if (data.adminUser == true || data.safeUser == true || data.cabinetAdmin == true) {
  327. var bean = DoubleDialogBean(
  328. data.userName,
  329. data.faceImg,
  330. data.userId
  331. )
  332. mDoubleDialogBean.add(bean)
  333. passThrough()
  334. } else {
  335. customDialogView(0, "无权限信息")
  336. }
  337. }
  338. } else {
  339. if (data.userId == ChemicalApp.userData!!.userId) {
  340. var bean =
  341. DoubleDialogBean(
  342. data.userName,
  343. data.faceImg,
  344. data.userId
  345. )
  346. mDoubleDialogBean.add(bean)
  347. passThrough()
  348. } else {
  349. customDialogView(0, "无权限信息")
  350. }
  351. }
  352. }
  353. }
  354. 1 -> { //归还业务 标签管理
  355. if (count == 1) {
  356. if (data.userId == ChemicalApp.userData!!.userId) {
  357. isLogin = true
  358. faceTwo()
  359. customDialog(data.userName, data.faceImg, data.userId)
  360. var bean =
  361. DoubleDialogBean(data.userName, data.faceImg, data.userId)
  362. mDoubleDialogBean.add(bean)
  363. } else {
  364. obtainCertification(data)
  365. }
  366. } else {
  367. if (isLogin) {
  368. if (data.adminUser == true || data.safeUser == true || data.cabinetAdmin == true) {
  369. var bean =
  370. DoubleDialogBean(
  371. data.userName,
  372. data.faceImg,
  373. data.userId
  374. )
  375. mDoubleDialogBean.add(bean)
  376. passThrough()
  377. } else {
  378. customDialogView(0, "认证失败")
  379. }
  380. } else {
  381. if (data.userId == ChemicalApp.userData!!.userId) {
  382. var bean =
  383. DoubleDialogBean(
  384. data.userName,
  385. data.faceImg,
  386. data.userId
  387. )
  388. mDoubleDialogBean.add(bean)
  389. passThrough()
  390. } else {
  391. customDialogView(0, "认证失败")
  392. }
  393. }
  394. }
  395. }
  396. 2 -> {//待入库
  397. if (count == 1) {
  398. if (data.userId == ChemicalApp.userData!!.userId) {
  399. isLogin = true
  400. count++
  401. faceTwo()
  402. customDialog(data.userName, data.faceImg, data.userId)
  403. var bean =
  404. DoubleDialogBean(data.userName, data.faceImg, data.userId)
  405. mDoubleDialogBean.add(bean)
  406. } else {
  407. toBeStored(data)
  408. }
  409. } else {
  410. if (isLogin) {
  411. if (mChemicalLevel == 1) {
  412. //管控
  413. if (data.adminUser == true || data.safeUser == true || data.cabinetAdmin == true) {
  414. var bean = DoubleDialogBean(
  415. data.userName,
  416. data.faceImg,
  417. data.userId
  418. )
  419. mDoubleDialogBean.add(bean)
  420. passThrough()
  421. } else {
  422. customDialogView(0, "认证失败")
  423. }
  424. } else {
  425. //非管控 实验室负责人or安全负责人or柜锁管理员
  426. if (data.safeUser == true || data.adminUser == true || data.cabinetAdmin == true) {
  427. var bean = DoubleDialogBean(
  428. data.userName,
  429. data.faceImg,
  430. data.userId
  431. )
  432. mDoubleDialogBean.add(bean)
  433. passThrough()
  434. } else {
  435. customDialogView(0, "认证失败")
  436. }
  437. }
  438. } else {
  439. if (data.userId == ChemicalApp.userData!!.userId) {
  440. var bean =
  441. DoubleDialogBean(
  442. data.userName,
  443. data.faceImg,
  444. data.userId
  445. )
  446. mDoubleDialogBean.add(bean)
  447. passThrough()
  448. } else {
  449. customDialogView(0, "认证失败")
  450. }
  451. }
  452. }
  453. }
  454. }
  455. },
  456. { throwable ->
  457. dismissLoading()
  458. // mFotoapparat.stop()
  459. // handlerBack.removeCallbacks(countdownRunnable)
  460. // handlerBack.removeCallbacksAndMessages(null)
  461. throwableView(throwable)
  462. })
  463. addDisposable(disposable)
  464. }
  465. private fun obtainCertification(data: UserValidationBean) {
  466. //校级管理员 schoolLevelAdmin
  467. //院级管理员 collegeAdmin
  468. //实验室负责人 adminUser
  469. //安全负责人 safeUser
  470. //柜锁管理员 cabinetAdmin
  471. //是否化学品归属人 belongUser
  472. //是否化学品归属课题组下成员 toipcUser
  473. if (data.adminUser == true || data.safeUser == true || data.cabinetAdmin == true) {
  474. count++
  475. faceTwo()
  476. customDialog(data.userName, data.faceImg, data.userId)
  477. var bean = DoubleDialogBean(data.userName, data.faceImg, data.userId)
  478. mDoubleDialogBean.add(bean)
  479. } else {
  480. customDialogView(0, "认证失败")
  481. }
  482. }
  483. private fun toBeStored(data: UserValidationBean) {
  484. //校级管理员 schoolLevelAdmin
  485. //院级管理员 collegeAdmin
  486. //实验室负责人 adminUser
  487. //安全负责人 safeUser
  488. //柜锁管理员 cabinetAdmin
  489. //是否化学品归属人 belongUser
  490. //是否化学品归属课题组下成员 toipcUser
  491. if (mChemicalLevel == 1) {
  492. //管控
  493. if (data.belongUser == true || data.toipcUser == true || data.adminUser == true || data.safeUser == true || data.cabinetAdmin == true) {
  494. count++
  495. faceTwo()
  496. customDialog(data.userName, data.faceImg, data.userId)
  497. var bean = DoubleDialogBean(data.userName, data.faceImg, data.userId)
  498. mDoubleDialogBean.add(bean)
  499. } else {
  500. customDialogView(0, "认证失败")
  501. }
  502. } else {
  503. //非管控 实验室负责人or安全负责人or柜锁管理员
  504. if (data.safeUser == true || data.adminUser == true || data.cabinetAdmin == true) {
  505. count++
  506. faceTwo()
  507. customDialog(data.userName, data.faceImg, data.userId)
  508. var bean = DoubleDialogBean(data.userName, data.faceImg, data.userId)
  509. mDoubleDialogBean.add(bean)
  510. } else {
  511. customDialogView(0, "认证失败")
  512. }
  513. }
  514. }
  515. private fun customDialog(userName: String, imgUrl: String?, userId: String) {
  516. mUserId = userId
  517. viewBinding.through.visibility = View.VISIBLE
  518. viewBinding.userName.text = "$userName"
  519. Glide.with(this)
  520. .load("${HttpConfig.API_BASE_IMG_URL}$imgUrl")
  521. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  522. .error(R.mipmap.icon_zhan_wei)
  523. .into(viewBinding.imgView)
  524. MediaPlayerHelper.playRawMp3(this@TwoPersonActivity, R.raw.dierwei_renlianshibie)
  525. }
  526. private fun takePicture() {
  527. val format = SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.getDefault())
  528. val fileName = "${format.format(Calendar.getInstance().time)}.jpg"
  529. val photoFile = File(this.getExternalFilesDir("photos"), fileName)
  530. RcLog.info("==========当前认证数 $count")
  531. if (count == 1) {
  532. mFotoapparat.takePicture()
  533. .saveToFile(photoFile)
  534. .whenAvailable {
  535. RcLog.info("=====人脸识别D=${HttpClient.token} $it $photoFile")
  536. callFaceMatchingApi(photoFile)
  537. }
  538. } else {
  539. mFotoapparatTwo.takePicture()
  540. .saveToFile(photoFile)
  541. .whenAvailable {
  542. RcLog.info("=====人脸识别B=${HttpClient.token}")
  543. callFaceMatchingApi(photoFile)
  544. }
  545. }
  546. }
  547. override fun onDestroy() {
  548. super.onDestroy()
  549. try {
  550. RcLog.info("=====清空双人认证1 人脸信息")
  551. mFotoapparat.stop()
  552. RcLog.info("=====清空双人认证2 人脸信息")
  553. RcLog.info("=====清空双人认证3 人脸信息")
  554. handlerBackTwo.removeCallbacks(countdownRunnableTwo)
  555. RcLog.info("=====清空双人认证4 人脸信息")
  556. handlerBackTwo.removeCallbacksAndMessages(null)
  557. RcLog.info("=====清空双人认证5 人脸信息")
  558. } catch (e: Exception) {
  559. }
  560. try {
  561. mFotoapparatTwo.stop()
  562. RcLog.info("=====清空双人认证6 人脸信息")
  563. } catch (e: Exception) {
  564. }
  565. try {
  566. handlerBack.removeCallbacks(countdownRunnable)
  567. RcLog.info("=====清空双人认证7 人脸信息")
  568. } catch (e: Exception) {
  569. }
  570. try {
  571. handlerBack.removeCallbacksAndMessages(null)
  572. RcLog.info("=====清空双人认证8 人脸信息")
  573. } catch (e: Exception) {
  574. }
  575. try {
  576. countHandler.removeCallbacksAndMessages(null)
  577. } catch (e: Exception) {
  578. }
  579. }
  580. /**
  581. * 0 没有图标 1 绿色(成功) 2红色(失败)
  582. * 失败或者成功的弹框
  583. */
  584. private fun customDialogView(types: Int, msg: String) {
  585. val customDialog = CustomDialog(this, types, msg)
  586. if (!this.isFinishing && !this.isDestroyed) {
  587. customDialog.show()
  588. }
  589. }
  590. /**
  591. * 异常处理
  592. */
  593. private fun throwableView(throwable: Throwable) {
  594. when (throwable) {
  595. is NetException -> {
  596. if (throwable.message.isNullOrEmpty()) {
  597. "接口请求失败(${throwable.code})"
  598. } else {
  599. throwable.message!!
  600. }
  601. }
  602. is SocketTimeoutException -> "请求超时,请稍后重试"
  603. is ConnectException -> "无法连接服务器,请检查网络"
  604. is HttpException -> "服务器繁忙,请稍后重试"
  605. else -> null
  606. }?.let { customDialogView(2, "$it") }
  607. }
  608. private lateinit var dialogsAut: DoublePeopleDialog
  609. private var timeLeftInSeconds = 2
  610. private var mTvView: TextView? = null
  611. //验证通过
  612. private fun passThrough() {
  613. // 在需要时关闭定时器
  614. try {
  615. RcLog.info("=====清空双人认证3 人脸信息")
  616. mFotoapparatTwo.stop()
  617. handlerBackTwo.removeCallbacks(countdownRunnableTwo)
  618. RcLog.info("=====清空双人认证4 人脸信息")
  619. handlerBackTwo.removeCallbacksAndMessages(null)
  620. } catch (e: Exception) {
  621. }
  622. Constants.AUTHENTICATION = true
  623. // 存储集合到 SharedPreferences
  624. SharedPreferencesHelper.saveList(this, mDoubleDialogBean)
  625. dialogsAut =
  626. DoublePeopleDialog(this, mDoubleDialogBean, object : DoublePeopleDialog.IClickLit {
  627. override fun onUpView(tvView: TextView) {
  628. mTvView = tvView
  629. }
  630. })
  631. dialogsAut.show()
  632. // 开始倒计时
  633. handlerBack.post(countdownRunnable)
  634. // 获取对话框的 Window 对象
  635. dialogsAut?.window?.decorView?.setOnTouchListener { _, event ->
  636. // 判断是否点击了对话框外部空白区域
  637. if (event.action == MotionEvent.ACTION_DOWN) {
  638. val x = event.x
  639. val y = event.y
  640. val dialogView = dialogsAut?.window?.decorView
  641. if (dialogView != null && (x < 0 || x > dialogView.width || y < 0 || y > dialogView.height)) {
  642. // 在此处执行点击对话框外部空白区域时的操作
  643. // 例如关闭对话框
  644. dialogsAut.dismiss()
  645. finish()
  646. return@setOnTouchListener true
  647. }
  648. }
  649. return@setOnTouchListener false
  650. }
  651. MediaPlayerHelper.playRawMp3(this, R.raw.shuangren_tongguo)
  652. }
  653. private val countdownRunnable = object : Runnable {
  654. override fun run() {
  655. if (timeLeftInSeconds > 0) {
  656. mTvView!!.text = "${timeLeftInSeconds}秒后自动返回首页"
  657. timeLeftInSeconds--
  658. handlerBack.postDelayed(this, 1000)
  659. } else {
  660. dialogsAut!!.dismiss()
  661. finish()
  662. }
  663. }
  664. }
  665. }