Compare commits
3
Commits
8673cec545
...
a6d2441704
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6d2441704 | ||
|
|
e7d11530a6 | ||
|
|
c56769769b |
@@ -1,5 +1,7 @@
|
||||
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.fragment.BaseFragment
|
||||
import com.sw.dualscreen.databinding.FragmentNumberPayBinding
|
||||
@@ -13,6 +15,8 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
|
||||
private lateinit var payActivity: PayActivity
|
||||
private var foodName: String? = null
|
||||
private var payAmount: Double? = null
|
||||
// 密码是否显示的标志
|
||||
private var isPasswordVisible = false
|
||||
override fun inflateViewBinding(): FragmentNumberPayBinding {
|
||||
return FragmentNumberPayBinding.inflate(layoutInflater)
|
||||
}
|
||||
@@ -27,6 +31,12 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
|
||||
foodName = it.foodName
|
||||
payAmount = (it.specPrice ?: 0.0) * payActivity.eatNum
|
||||
}
|
||||
|
||||
// 密码显示/隐藏切换
|
||||
binding.ivTogglePassword.setOnClickListener {
|
||||
togglePasswordVisibility()
|
||||
}
|
||||
|
||||
binding.btnConfirm.setOnClickListener { v ->
|
||||
val phone = binding.etInputPhone.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) {
|
||||
// payActivity.bindOrder(userId) { bindResult ->
|
||||
// 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>
|
||||
@@ -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>
|
||||
@@ -34,24 +34,41 @@
|
||||
android:textStyle="bold"
|
||||
tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etInputNumber"
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_marginHorizontal="64dp"
|
||||
android:inputType="textVisiblePassword"
|
||||
android:background="@drawable/setting_border_gray3"
|
||||
android:hint="输入消费码"
|
||||
android:textColorHint="#ffc4cfda"
|
||||
android:textColor="#ff0a1428"
|
||||
android:layout_marginTop="32dp"
|
||||
android:textSize="36sp"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:text=""
|
||||
android:paddingHorizontal="50dp"
|
||||
android:textStyle="bold"
|
||||
tools:ignore="Autofill,HardcodedText,LabelFor,TextFields" />
|
||||
android:layout_marginTop="32dp">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etInputNumber"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="textPassword"
|
||||
android:background="@drawable/setting_border_gray3"
|
||||
android:hint="输入消费码"
|
||||
android:textColorHint="#ffc4cfda"
|
||||
android:textColor="#ff0a1428"
|
||||
android:textSize="36sp"
|
||||
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
|
||||
android:id="@+id/btnConfirm"
|
||||
|
||||
Reference in New Issue
Block a user