适配中英文切换
This commit is contained in:
@@ -19,8 +19,8 @@ class CustomDialogFragmentText : DialogFragment() {
|
||||
private var message: String = ""
|
||||
private var inputHint: String = ""
|
||||
private var inputText: String = ""
|
||||
private var negativeText: String = "取消"
|
||||
private var positiveText: String = "确定"
|
||||
private var negativeText: String = ""
|
||||
private var positiveText: String = ""
|
||||
private var showInput: Boolean = true
|
||||
private var onConfirmListener: ((String) -> Unit)? = null
|
||||
|
||||
@@ -87,6 +87,9 @@ class CustomDialogFragmentText : DialogFragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
// Set defaults if not explicitly configured
|
||||
if (negativeText.isEmpty()) negativeText = getString(R.string.cancel)
|
||||
if (positiveText.isEmpty()) positiveText = getString(R.string.confirm)
|
||||
binding.tvTitle.text = title
|
||||
binding.tvMessage.text = message
|
||||
binding.etInput.hint = inputHint
|
||||
|
||||
@@ -183,41 +183,41 @@ object DefenseDialogs {
|
||||
.also { it.show(fragment.parentFragmentManager, tag) }
|
||||
}
|
||||
|
||||
fun intrusionAlertConfig(deviceName: String, timeText: String): CustomDialogFragment.Config {
|
||||
fun intrusionAlertConfig(ctx: android.content.Context, deviceName: String, timeText: String): CustomDialogFragment.Config {
|
||||
return CustomDialogFragment.Config(
|
||||
title = "入侵告警",
|
||||
message = "${timeText}有人入侵\n【${deviceName}】",
|
||||
positiveText = "去看一下",
|
||||
negativeText = "取消"
|
||||
title = ctx.getString(R.string.intrusion_alarm),
|
||||
message = "${timeText}${ctx.getString(R.string.someone_invaded)}\n【${deviceName}】",
|
||||
positiveText = ctx.getString(R.string.go_check),
|
||||
negativeText = ctx.getString(R.string.cancel)
|
||||
)
|
||||
}
|
||||
|
||||
fun warmPromptConfig(deviceName: String, runDays: Int): CustomDialogFragment.Config {
|
||||
fun warmPromptConfig(ctx: android.content.Context, deviceName: String, runDays: Int): CustomDialogFragment.Config {
|
||||
return CustomDialogFragment.Config(
|
||||
title = "温馨提示",
|
||||
message = "【${deviceName}】设备已经运行\n${runDays}天请及时维护",
|
||||
positiveText = "知道了",
|
||||
title = ctx.getString(R.string.notice),
|
||||
message = "【${deviceName}】${ctx.getString(R.string.device_running_days, runDays)}",
|
||||
positiveText = ctx.getString(R.string.got_it),
|
||||
negativeText = null
|
||||
)
|
||||
}
|
||||
|
||||
fun deviceOfflineConfig(): CustomDialogFragment.Config {
|
||||
fun deviceOfflineConfig(ctx: android.content.Context): CustomDialogFragment.Config {
|
||||
return CustomDialogFragment.Config(
|
||||
title = "设备离线",
|
||||
message = "设备已离线,请检查设备的WIF及电\n源情况",
|
||||
positiveText = "知道了",
|
||||
title = ctx.getString(R.string.device_offline),
|
||||
message = ctx.getString(R.string.device_offline_message),
|
||||
positiveText = ctx.getString(R.string.got_it),
|
||||
negativeText = null
|
||||
)
|
||||
}
|
||||
|
||||
fun strikeDistanceConfig(defaultDistance: String): CustomDialogFragment.Config {
|
||||
fun strikeDistanceConfig(ctx: android.content.Context, defaultDistance: String): CustomDialogFragment.Config {
|
||||
return CustomDialogFragment.Config(
|
||||
title = "打击距离",
|
||||
title = ctx.getString(R.string.strike_distance),
|
||||
message = "",
|
||||
positiveText = "确定",
|
||||
negativeText = "取消",
|
||||
positiveText = ctx.getString(R.string.confirm),
|
||||
negativeText = ctx.getString(R.string.cancel),
|
||||
showInput = true,
|
||||
inputHint = "请输入打击距离",
|
||||
inputHint = ctx.getString(R.string.enter_strike_distance),
|
||||
inputText = defaultDistance,
|
||||
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.example.defenseapplication.view
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Window
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.utils.LanguageUtil
|
||||
|
||||
/**
|
||||
* 语言选择对话框
|
||||
*/
|
||||
class LanguageDialog(
|
||||
context: Context,
|
||||
private val onLanguageSelected: (String) -> Unit
|
||||
) : Dialog(context) {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
setContentView(R.layout.dialog_language)
|
||||
|
||||
// 设置对话框宽度为屏幕宽度的80%
|
||||
window?.setLayout(
|
||||
(context.resources.displayMetrics.widthPixels * 0.8).toInt(),
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
|
||||
initViews()
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
val tvChinese = findViewById<TextView>(R.id.tvChinese)
|
||||
val tvEnglish = findViewById<TextView>(R.id.tvEnglish)
|
||||
val tvCancel = findViewById<TextView>(R.id.tvCancel)
|
||||
|
||||
val currentLang = LanguageUtil.getCurrentLanguage(context)
|
||||
|
||||
// 根据当前语言高亮显示
|
||||
if (currentLang == LanguageUtil.LANGUAGE_CHINESE) {
|
||||
tvChinese.setTextColor(context.getColor(R.color.green))
|
||||
} else {
|
||||
tvEnglish.setTextColor(context.getColor(R.color.green))
|
||||
}
|
||||
|
||||
tvChinese.setOnClickListener {
|
||||
onLanguageSelected(LanguageUtil.LANGUAGE_CHINESE)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
tvEnglish.setOnClickListener {
|
||||
onLanguageSelected(LanguageUtil.LANGUAGE_ENGLISH)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
tvCancel.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,12 +39,12 @@ class RecognitionModeDialog(context: Context) : Dialog(context) {
|
||||
}
|
||||
|
||||
binding.itemBluetooth.setOnClickListener {
|
||||
selectedMode = "蓝牙识别"
|
||||
selectedMode = context.getString(R.string.bluetooth_recognition)
|
||||
updateSelectedBackground(binding.itemBluetooth)
|
||||
}
|
||||
|
||||
binding.itemBluetoothFace.setOnClickListener {
|
||||
selectedMode = "蓝牙+人脸识别"
|
||||
selectedMode = context.getString(R.string.bluetooth_face_recognition)
|
||||
updateSelectedBackground(binding.itemBluetoothFace)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user