3 Commits
4 changed files with 111 additions and 15 deletions
@@ -1,5 +1,7 @@
package com.sw.dualscreen.activity.fragment.pay package com.sw.dualscreen.activity.fragment.pay
import android.text.InputType
import com.sw.dualscreen.R
import com.sw.dualscreen.activity.PayActivity import com.sw.dualscreen.activity.PayActivity
import com.sw.dualscreen.activity.fragment.BaseFragment import com.sw.dualscreen.activity.fragment.BaseFragment
import com.sw.dualscreen.databinding.FragmentNumberPayBinding import com.sw.dualscreen.databinding.FragmentNumberPayBinding
@@ -13,6 +15,8 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
private lateinit var payActivity: PayActivity private lateinit var payActivity: PayActivity
private var foodName: String? = null private var foodName: String? = null
private var payAmount: Double? = null private var payAmount: Double? = null
// 密码是否显示的标志
private var isPasswordVisible = false
override fun inflateViewBinding(): FragmentNumberPayBinding { override fun inflateViewBinding(): FragmentNumberPayBinding {
return FragmentNumberPayBinding.inflate(layoutInflater) return FragmentNumberPayBinding.inflate(layoutInflater)
} }
@@ -27,6 +31,12 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
foodName = it.foodName foodName = it.foodName
payAmount = (it.specPrice ?: 0.0) * payActivity.eatNum payAmount = (it.specPrice ?: 0.0) * payActivity.eatNum
} }
// 密码显示/隐藏切换
binding.ivTogglePassword.setOnClickListener {
togglePasswordVisibility()
}
binding.btnConfirm.setOnClickListener { v -> binding.btnConfirm.setOnClickListener { v ->
val phone = binding.etInputPhone.text.toString().trim() val phone = binding.etInputPhone.text.toString().trim()
val key = binding.etInputNumber.text.toString().trim() val key = binding.etInputNumber.text.toString().trim()
@@ -127,6 +137,30 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
} }
} }
// 切换密码显示/隐藏
private fun togglePasswordVisibility() {
val editText = binding.etInputNumber
val imageView = binding.ivTogglePassword
// 保存当前光标位置
val cursorPosition = editText.selectionStart
if (isPasswordVisible) {
// 当前显示,改为隐藏
editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
imageView.setImageResource(R.drawable.ic_eye_close)
isPasswordVisible = false
} else {
// 当前隐藏,改为显示
editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
imageView.setImageResource(R.drawable.ic_eye_open)
isPasswordVisible = true
}
// 恢复光标位置
editText.setSelection(cursorPosition)
}
// private fun bindOrder(userId: String, block: () -> Unit) { // private fun bindOrder(userId: String, block: () -> Unit) {
// payActivity.bindOrder(userId) { bindResult -> // payActivity.bindOrder(userId) { bindResult ->
// if (bindResult.not()) { // if (bindResult.not()) {
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<!-- 眼睛轮廓 -->
<path
android:fillColor="@android:color/transparent"
android:strokeColor="@android:color/black"
android:strokeWidth="1.5"
android:strokeLineCap="round"
android:strokeLineJoin="round"
android:pathData="M 2 12 C 2 12 5 6 12 6 C 19 6 22 12 22 12 C 22 12 19 18 12 18 C 5 18 2 12 2 12 Z" />
<!-- 瞳孔(path绘制圆形) -->
<path
android:fillColor="@android:color/black"
android:pathData="M 12 9 C 13.66 9 15 10.34 15 12 C 15 13.66 13.66 15 12 15 C 10.34 15 9 13.66 9 12 C 9 10.34 10.34 9 12 9 Z" />
<!-- 斜线表示隐藏 -->
<path
android:fillColor="@android:color/transparent"
android:strokeColor="@android:color/black"
android:strokeWidth="1.5"
android:strokeLineCap="round"
android:pathData="M 4 4 L 20 20" />
</vector>
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<!-- 眼睛轮廓 -->
<path
android:fillColor="@android:color/transparent"
android:strokeColor="@android:color/black"
android:strokeWidth="1.5"
android:strokeLineCap="round"
android:strokeLineJoin="round"
android:pathData="M 2 12 C 2 12 5 6 12 6 C 19 6 22 12 22 12 C 22 12 19 18 12 18 C 5 18 2 12 2 12 Z" />
<!-- 瞳孔(path绘制圆形) -->
<path
android:fillColor="@android:color/black"
android:pathData="M 12 9 C 13.66 9 15 10.34 15 12 C 15 13.66 13.66 15 12 15 C 10.34 15 9 13.66 9 12 C 9 10.34 10.34 9 12 9 Z" />
</vector>
+32 -15
View File
@@ -34,24 +34,41 @@
android:textStyle="bold" android:textStyle="bold"
tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" /> tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" />
<EditText <FrameLayout
android:id="@+id/etInputNumber"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
android:layout_marginHorizontal="64dp" android:layout_marginHorizontal="64dp"
android:inputType="textVisiblePassword" android:layout_marginTop="32dp">
android:background="@drawable/setting_border_gray3"
android:hint="输入消费码" <EditText
android:textColorHint="#ffc4cfda" android:id="@+id/etInputNumber"
android:textColor="#ff0a1428" android:layout_width="match_parent"
android:layout_marginTop="32dp" android:layout_height="match_parent"
android:textSize="36sp" android:inputType="textPassword"
android:gravity="center" android:background="@drawable/setting_border_gray3"
android:maxLines="1" android:hint="输入消费码"
android:text="" android:textColorHint="#ffc4cfda"
android:paddingHorizontal="50dp" android:textColor="#ff0a1428"
android:textStyle="bold" android:textSize="36sp"
tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" /> android:gravity="center"
android:maxLines="1"
android:text=""
android:paddingHorizontal="50dp"
android:textStyle="bold"
tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" />
<ImageView
android:id="@+id/ivTogglePassword"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical|end"
android:paddingEnd="16dp"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_eye_close"
android:scaleType="centerInside"
tools:ignore="HardcodedText" />
</FrameLayout>
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/btnConfirm" android:id="@+id/btnConfirm"