163 lines
5.5 KiB
Kotlin
163 lines
5.5 KiB
Kotlin
//package com.sw.face.collect
|
||
//
|
||
//import android.Manifest
|
||
//import android.net.Uri
|
||
//import android.util.Log
|
||
//import android.view.View
|
||
//import androidx.camera.view.PreviewView
|
||
//import androidx.core.view.updateLayoutParams
|
||
//import com.sw.face.collect.base.BaseActivity
|
||
//import com.sw.face.collect.databinding.ActivityMainBakBinding
|
||
//import com.sw.face.collect.databinding.LayoutCameraPreviewBinding
|
||
//import com.sw.face.collect.ext.dp
|
||
//import com.sw.face.collect.ext.gone
|
||
//import com.sw.face.collect.ext.toast
|
||
//import com.sw.face.collect.ext.visible
|
||
//import com.sw.face.collect.socket.LanCommunicationManager
|
||
//import com.sw.face.collect.socket.LanServer
|
||
//import com.sw.face.collect.utils.Base64
|
||
//import com.sw.face.collect.utils.CameraUtils
|
||
//import com.sw.face.collect.utils.ToastUtils
|
||
//import org.json.JSONException
|
||
//import org.json.JSONObject
|
||
//
|
||
//class MainActivityBak : BaseActivity<ActivityMainBakBinding>() {
|
||
// // private val debouncer = Debouncer(2000)
|
||
//
|
||
// companion object {
|
||
// private const val TAG = "MainActivity"
|
||
// }
|
||
//
|
||
// private lateinit var previewView: PreviewView
|
||
// private val cameraUtils: CameraUtils by lazy {
|
||
// CameraUtils(this)
|
||
// }
|
||
//
|
||
// override fun inflateViewBinding() = ActivityMainBakBinding.inflate(layoutInflater)
|
||
//
|
||
// override fun initialize() {
|
||
// super.initialize()
|
||
// cameraUtils.initCamera()
|
||
// val previewBinding =
|
||
// LayoutCameraPreviewBinding.inflate(layoutInflater, binding.flCameraPreview)
|
||
// previewView = previewBinding.previewView.also {
|
||
// it.updateLayoutParams {
|
||
// width = 680.dp
|
||
// height = 500.dp
|
||
// }
|
||
// }
|
||
// cameraUtils.setPreviewController(previewView)
|
||
//
|
||
// binding.btnClear.setOnClickListener {
|
||
// binding.ivFaceImage.gone()
|
||
// binding.flCameraPreview.visible()
|
||
// }
|
||
// binding.btnTakePhoto.setOnClickListener {
|
||
// requestSinglePermissionResult(Manifest.permission.CAMERA) { granted ->
|
||
// if (granted.not()) {
|
||
// toast("没有相机权限")
|
||
// return@requestSinglePermissionResult
|
||
// }
|
||
// takePhoto()
|
||
// }
|
||
// }
|
||
// binding.btnUpload.setOnClickListener {
|
||
// getFaceData { faceData ->
|
||
// Log.d(TAG, "faceData: $faceData")
|
||
// sendFaceData(faceData)
|
||
// }
|
||
// }
|
||
// binding.tvTitle.setOnClickListener { finish() }
|
||
// addSocketListener()
|
||
// }
|
||
//
|
||
// private fun sendFaceData(faceData: String) {
|
||
// // 给某个客户端发送
|
||
// val jsonObject = JSONObject().also {
|
||
// it.put("type", "cmd")
|
||
// it.put("content", faceData)
|
||
// }
|
||
// val clientId = "device12231530"
|
||
// lanManager?.sendToClient(clientId, jsonObject)
|
||
// lanManager?.broadcast(jsonObject)
|
||
// }
|
||
//
|
||
// private var lanManager: LanCommunicationManager?=null
|
||
// private fun addSocketListener() {
|
||
// lanManager = LanServer.getInstance()
|
||
// lanManager?.setListener(object : LanCommunicationManager.Listener{
|
||
// override fun onClientConnected(clientId: String?) {
|
||
// Log.d(TAG, "addSocketListener,onClientConnected: clientId=$clientId")
|
||
// }
|
||
//
|
||
// override fun onClientDisconnected(clientId: String?) {
|
||
// Log.d(TAG, "addSocketListener,onClientDisconnected: clientId=$clientId")
|
||
// }
|
||
//
|
||
// override fun onMessageReceived(
|
||
// clientId: String?,
|
||
// message: JSONObject?
|
||
// ) {
|
||
// Log.d(TAG, "addSocketListener,onMessageReceived: clientId=$clientId,message=$message")
|
||
// }
|
||
// })
|
||
// try {
|
||
// lanManager?.start()
|
||
// } catch (e: Exception) {
|
||
// e.printStackTrace()
|
||
// }
|
||
// }
|
||
//
|
||
// private fun takePhoto() {
|
||
// showWaitingDialog("拍照中……")
|
||
// cameraUtils.takePhoto(cameraCallback) { errMsg ->
|
||
// hideWaitingDialog()
|
||
// ToastUtils.showToast("拍照异常,请重新操作")
|
||
// }
|
||
// }
|
||
//
|
||
// private var imageUri: Uri? = null
|
||
// private fun getFaceData(block: (String) -> Unit) {
|
||
// if (imageUri == null) {
|
||
// toast("未采集到照片,请拍照")
|
||
// return
|
||
// }
|
||
// context.contentResolver.openInputStream(imageUri!!)?.use { stream ->
|
||
// val faceData = Base64.encode(stream.readBytes())
|
||
// block(faceData)
|
||
// }
|
||
// }
|
||
//
|
||
// private val cameraCallback: (Uri) -> Unit = { uri ->
|
||
// try {
|
||
// this.imageUri = uri
|
||
// binding.flCameraPreview.gone()
|
||
// binding.ivFaceImage.run {
|
||
// visible()
|
||
// setImageURI(uri)
|
||
// }
|
||
// hideWaitingDialog()
|
||
// } catch (e: Exception) {
|
||
// e.printStackTrace()
|
||
// hideWaitingDialog()
|
||
// ToastUtils.showToast("程序异常${e.message}")
|
||
// }
|
||
// }
|
||
//
|
||
// override fun onResume() {
|
||
// super.onResume()
|
||
// cameraUtils.bind()
|
||
// binding.llCameraFlag.run {
|
||
// visibility = View.VISIBLE
|
||
// postDelayed({
|
||
// visibility = View.GONE
|
||
// }, 3000)
|
||
// }
|
||
// }
|
||
//
|
||
// override fun onPause() {
|
||
// super.onPause()
|
||
// cameraUtils.unbind()
|
||
// binding.llCameraFlag.visibility = View.VISIBLE
|
||
// }
|
||
//} |