设置
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.example.defenseapplication.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.defenseapplication.databinding.ItemAlarmLogBinding
|
||||
|
||||
class AlarmLogAdapter(private val items: List<String>) : RecyclerView.Adapter<AlarmLogAdapter.ViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val binding = ItemAlarmLogBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
class ViewHolder(private val binding: ItemAlarmLogBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(item: String) {
|
||||
val parts = item.split(" - ")
|
||||
binding.tvTitle.text = parts.firstOrNull()
|
||||
binding.tvTime.text = parts.getOrNull(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,21 @@
|
||||
package com.example.defenseapplication.liveVideo
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.os.LocaleList
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.adapter.AlarmLogAdapter
|
||||
import com.example.defenseapplication.databinding.AlarmLogActivityBinding
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
import com.google.android.material.datepicker.MaterialDatePicker
|
||||
import java.util.*
|
||||
|
||||
class AlarmLogActivity : AppCompatActivity() {
|
||||
private lateinit var binding: AlarmLogActivityBinding
|
||||
private lateinit var calendar: Calendar
|
||||
private var adapter: AlarmLogAdapter? = null
|
||||
private val alarmList = mutableListOf<String>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -18,12 +25,57 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
.statusBarDarkFont(true)
|
||||
.titleBar(binding.topBar)
|
||||
.init()
|
||||
|
||||
calendar = Calendar.getInstance()
|
||||
updateDateDisplay()
|
||||
initRecyclerView()
|
||||
loadAlarmList()
|
||||
initListener()
|
||||
}
|
||||
|
||||
private fun initRecyclerView() {
|
||||
adapter = AlarmLogAdapter(alarmList)
|
||||
binding.alarmListRecyclerView.layoutManager = LinearLayoutManager(this)
|
||||
binding.alarmListRecyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
private fun loadAlarmList() {
|
||||
alarmList.clear()
|
||||
alarmList.add("入侵告警 - 10:30")
|
||||
alarmList.add("入侵告警 - 09:15")
|
||||
alarmList.add("入侵告警 - 08:45")
|
||||
alarmList.add("入侵告警 - 07:20")
|
||||
alarmList.add("入侵告警 - 06:50")
|
||||
adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun updateDateDisplay() {
|
||||
val month = calendar.get(Calendar.MONTH) + 1
|
||||
val day = calendar.get(Calendar.DAY_OF_MONTH)
|
||||
binding.tvDate.text = "${month}月${day}日"
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
binding.btnBack.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
binding.expandImg.setOnClickListener {
|
||||
showDatePicker()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showDatePicker() {
|
||||
val datePicker = android.app.DatePickerDialog(
|
||||
this,
|
||||
{ _, year, month, dayOfMonth ->
|
||||
calendar.set(year, month, dayOfMonth)
|
||||
updateDateDisplay()
|
||||
loadAlarmList()
|
||||
},
|
||||
calendar.get(Calendar.YEAR),
|
||||
calendar.get(Calendar.MONTH),
|
||||
calendar.get(Calendar.DAY_OF_MONTH)
|
||||
)
|
||||
datePicker.show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ class LiveVideoActivity : AppCompatActivity(), SurfaceHolder.Callback {
|
||||
|
||||
if (isVoiceEnabled) {
|
||||
mediaPlayer?.setVolume(1.0f, 1.0f)
|
||||
binding.ivVoice.setImageResource(com.example.defenseapplication.R.drawable.voice_open)
|
||||
binding.ivVoice.setImageResource(com.example.defenseapplication.R.drawable.voice_on_open)
|
||||
Toast.makeText(this, "声音已开启", Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
mediaPlayer?.setVolume(0.0f, 0.0f)
|
||||
@@ -335,14 +335,14 @@ class LiveVideoActivity : AppCompatActivity(), SurfaceHolder.Callback {
|
||||
binding.consoleBar.visibility = View.VISIBLE
|
||||
|
||||
// 麦克风切换成开启状态
|
||||
binding.ivVoice.setImageResource(com.example.defenseapplication.R.drawable.voice_open)
|
||||
binding.ivVoice.setImageResource(com.example.defenseapplication.R.drawable.voice_on_open)
|
||||
isVoiceEnabled = true
|
||||
|
||||
// 启动语音录制
|
||||
startVoiceRecording()
|
||||
|
||||
// 启动麦克风脉冲动画
|
||||
startMicPulseAnimation()
|
||||
//startMicPulseAnimation()
|
||||
|
||||
Toast.makeText(this, "开始控制模式", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
@@ -367,22 +367,22 @@ class LiveVideoActivity : AppCompatActivity(), SurfaceHolder.Callback {
|
||||
|
||||
Toast.makeText(this, "停止控制模式", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun startMicPulseAnimation() {
|
||||
micPulseAnimation = ScaleAnimation(
|
||||
1.0f, 1.3f,
|
||||
1.0f, 1.3f,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f
|
||||
).apply {
|
||||
duration = 500
|
||||
repeatCount = Animation.INFINITE
|
||||
repeatMode = Animation.REVERSE
|
||||
interpolator = LinearInterpolator()
|
||||
}
|
||||
binding.ivVoice.startAnimation(micPulseAnimation)
|
||||
}
|
||||
|
||||
|
||||
// private fun startMicPulseAnimation() {
|
||||
// micPulseAnimation = ScaleAnimation(
|
||||
// 1.0f, 1.3f,
|
||||
// 1.0f, 1.3f,
|
||||
// Animation.RELATIVE_TO_SELF, 0.5f,
|
||||
// Animation.RELATIVE_TO_SELF, 0.5f
|
||||
// ).apply {
|
||||
// duration = 500
|
||||
// repeatCount = Animation.INFINITE
|
||||
// repeatMode = Animation.REVERSE
|
||||
// interpolator = LinearInterpolator()
|
||||
// }
|
||||
// binding.ivVoice.startAnimation(micPulseAnimation)
|
||||
// }
|
||||
|
||||
private fun stopMicPulseAnimation() {
|
||||
micPulseAnimation?.let {
|
||||
binding.ivVoice.clearAnimation()
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.example.defenseapplication.liveVideo
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.defenseapplication.databinding.SettingsActivityBinding
|
||||
import com.example.defenseapplication.view.CustomDialogFragmentText
|
||||
import com.example.defenseapplication.view.RecognitionModeDialog
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
@@ -21,5 +23,37 @@ class SettingsActivity : AppCompatActivity() {
|
||||
binding.ivBack.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
|
||||
binding.itemRecognitionMode.setOnClickListener {
|
||||
val dialog = RecognitionModeDialog(this)
|
||||
dialog.setOnConfirmListener { mode ->
|
||||
binding.tvRecognitionMode.text = mode
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
binding.itemDeviceName.setOnClickListener {
|
||||
val dialog = CustomDialogFragmentText()
|
||||
.setTitle("设备名称")
|
||||
.setInputHint("请输入设备名称")
|
||||
.setInputText(binding.tvDeviceName.text.toString())
|
||||
dialog.setOnConfirmListener { name ->
|
||||
binding.tvDeviceName.text = name
|
||||
}
|
||||
dialog.show(supportFragmentManager, "CustomDialogFragment")
|
||||
}
|
||||
|
||||
binding.itemUnbindDevice.setOnClickListener {
|
||||
val dialog = CustomDialogFragmentText()
|
||||
.setTitle("提示")
|
||||
.setMessage("确定解除该设备的绑定?")
|
||||
.setNegativeText("取消")
|
||||
.setPositiveText("确定")
|
||||
.setShowInput(false)
|
||||
dialog.setOnConfirmListener {
|
||||
finish()
|
||||
}
|
||||
dialog.show(supportFragmentManager, "CustomDialogFragment")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.example.defenseapplication.view
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.databinding.DialogCustomBinding
|
||||
|
||||
class CustomDialogFragmentText : DialogFragment() {
|
||||
|
||||
private lateinit var binding: DialogCustomBinding
|
||||
private var title: String = ""
|
||||
private var message: String = ""
|
||||
private var inputHint: String = ""
|
||||
private var inputText: String = ""
|
||||
private var negativeText: String = "取消"
|
||||
private var positiveText: String = "确定"
|
||||
private var showInput: Boolean = true
|
||||
private var onConfirmListener: ((String) -> Unit)? = null
|
||||
|
||||
fun setTitle(title: String): CustomDialogFragmentText {
|
||||
this.title = title
|
||||
return this
|
||||
}
|
||||
|
||||
fun setMessage(message: String): CustomDialogFragmentText {
|
||||
this.message = message
|
||||
return this
|
||||
}
|
||||
|
||||
fun setInputHint(hint: String): CustomDialogFragmentText {
|
||||
this.inputHint = hint
|
||||
return this
|
||||
}
|
||||
|
||||
fun setInputText(text: String): CustomDialogFragmentText {
|
||||
this.inputText = text
|
||||
return this
|
||||
}
|
||||
|
||||
fun setNegativeText(text: String): CustomDialogFragmentText {
|
||||
this.negativeText = text
|
||||
return this
|
||||
}
|
||||
|
||||
fun setPositiveText(text: String): CustomDialogFragmentText {
|
||||
this.positiveText = text
|
||||
return this
|
||||
}
|
||||
|
||||
fun setShowInput(show: Boolean): CustomDialogFragmentText {
|
||||
this.showInput = show
|
||||
return this
|
||||
}
|
||||
|
||||
fun setOnConfirmListener(listener: (String) -> Unit) {
|
||||
this.onConfirmListener = listener
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val dialog = super.onCreateDialog(savedInstanceState)
|
||||
dialog.window?.let {
|
||||
val params = it.attributes
|
||||
params.gravity = Gravity.CENTER
|
||||
params.width = WindowManager.LayoutParams.MATCH_PARENT
|
||||
params.height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||
it.attributes = params
|
||||
it.setBackgroundDrawableResource(R.drawable.round_bg)
|
||||
}
|
||||
return dialog
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = DialogCustomBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding.tvTitle.text = title
|
||||
binding.tvMessage.text = message
|
||||
binding.etInput.hint = inputHint
|
||||
binding.etInput.setText(inputText)
|
||||
binding.btnNegative.text = negativeText
|
||||
binding.btnPositive.text = positiveText
|
||||
|
||||
binding.etInput.visibility = if (showInput) View.VISIBLE else View.GONE
|
||||
|
||||
binding.btnNegative.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.btnPositive.setOnClickListener {
|
||||
val inputText = binding.etInput.text.toString()
|
||||
onConfirmListener?.invoke(inputText)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
super.onDismiss(dialog)
|
||||
onConfirmListener = null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.example.defenseapplication.view
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.view.WindowManager
|
||||
import android.widget.LinearLayout
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.databinding.DialogRecognitionModeBinding
|
||||
|
||||
class RecognitionModeDialog(context: Context) : Dialog(context) {
|
||||
|
||||
private lateinit var binding: DialogRecognitionModeBinding
|
||||
private var selectedMode: String = ""
|
||||
private var onConfirmListener: ((String) -> Unit)? = null
|
||||
|
||||
fun setOnConfirmListener(listener: (String) -> Unit) {
|
||||
this.onConfirmListener = listener
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = DialogRecognitionModeBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val window = window
|
||||
window?.let {
|
||||
val params = it.attributes
|
||||
params.gravity = Gravity.BOTTOM
|
||||
params.width = WindowManager.LayoutParams.MATCH_PARENT
|
||||
params.height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||
it.attributes = params
|
||||
it.setBackgroundDrawableResource(R.drawable.round_bg)
|
||||
}
|
||||
|
||||
binding.tvCancel.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.itemBluetooth.setOnClickListener {
|
||||
selectedMode = "蓝牙识别"
|
||||
updateSelectedBackground(binding.itemBluetooth)
|
||||
}
|
||||
|
||||
binding.itemBluetoothFace.setOnClickListener {
|
||||
selectedMode = "蓝牙+人脸识别"
|
||||
updateSelectedBackground(binding.itemBluetoothFace)
|
||||
}
|
||||
|
||||
binding.tvConfirm.setOnClickListener {
|
||||
if (selectedMode.isNotEmpty()) {
|
||||
onConfirmListener?.invoke(selectedMode)
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSelectedBackground(selectedItem: LinearLayout) {
|
||||
binding.itemBluetooth.setBackgroundColor(
|
||||
if (selectedItem == binding.itemBluetooth) {
|
||||
context.resources.getColor(R.color.bg_gray)
|
||||
} else {
|
||||
context.resources.getColor(R.color.white)
|
||||
}
|
||||
)
|
||||
binding.itemBluetoothFace.setBackgroundColor(
|
||||
if (selectedItem == binding.itemBluetoothFace) {
|
||||
context.resources.getColor(R.color.bg_gray)
|
||||
} else {
|
||||
context.resources.getColor(R.color.white)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user