Commit 0ac0f500 authored by 赵鹏翔's avatar 赵鹏翔

退款界面数字键盘重写,并处理成kotlin

parent 13aef8bd
...@@ -46,48 +46,50 @@ class NumberManualDialog(context: Context) : Dialog(context) { ...@@ -46,48 +46,50 @@ class NumberManualDialog(context: Context) : Dialog(context) {
numKeyboard = findViewById(R.id.numKeyboard) numKeyboard = findViewById(R.id.numKeyboard)
numInputFinish = numKeyboard.okButton numInputFinish = numKeyboard.okButton
numKeyboard.setKeyboardClickListener { numKeyboard.setKeyNumKeyboardClickListener(object : NumKeyboard.KeyboardClickListener {
when (it) { override fun onNumClick(it: Int) {
NumKeyboard.DELETE -> { when (it) {
if (TextUtils.isEmpty(etNumber.text.toString())) { NumKeyboard.DELETE -> {
return@setKeyboardClickListener if (TextUtils.isEmpty(etNumber.text.toString())) {
return
}
var currentCode: String = etNumber.text.toString()
currentCode = if (currentCode.length <= 1) {
""
} else {
currentCode.substring(0, currentCode.length - 1)
}
etNumber.setText(currentCode)
numInputFinish.isEnabled = !TextUtils.isEmpty(currentCode)
} }
var currentCode: String = etNumber.text.toString() NumKeyboard.SURE -> {
currentCode = if (currentCode.length <= 1) { val currentCode: String = etNumber.text.toString()
"" if (!TextUtils.isEmpty(currentCode)) {
} else { dismiss()
currentCode.substring(0, currentCode.length - 1) tvErrInfo.visibility = View.GONE
etNumber.setText(currentCode)
numberInputListener.numberInput(currentCode)
} else {
tvErrInfo.visibility = View.VISIBLE
tvErrInfo.text = "内容为空"
}
} }
etNumber.setText(currentCode) else -> {
numInputFinish.isEnabled = !TextUtils.isEmpty(currentCode)
}
NumKeyboard.SURE -> {
val currentCode: String = etNumber.text.toString()
if (!TextUtils.isEmpty(currentCode)) {
dismiss()
tvErrInfo.visibility = View.GONE tvErrInfo.visibility = View.GONE
etNumber.setText(currentCode) var currentCode: String = etNumber.text.toString()
numberInputListener.numberInput(currentCode) if (TextUtils.isEmpty(currentCode)) {
} else { etNumber.setText(it.toString())
tvErrInfo.visibility = View.VISIBLE } else {
tvErrInfo.text = "内容为空" currentCode += it
etNumber.setText(currentCode)
}
numInputFinish.isEnabled = !TextUtils.isEmpty(currentCode)
} }
} }
else -> {
tvErrInfo.visibility = View.GONE
var currentCode: String = etNumber.text.toString()
if (TextUtils.isEmpty(currentCode)) {
etNumber.setText(it.toString())
} else {
currentCode += it
etNumber.setText(currentCode)
}
numInputFinish.isEnabled = !TextUtils.isEmpty(currentCode)
}
} }
}
}
})
}
fun setNumberInputListener(numberInputListener: NumberInputListener) { fun setNumberInputListener(numberInputListener: NumberInputListener) {
this.numberInputListener = numberInputListener this.numberInputListener = numberInputListener
......
package com.fastcashier.lib_common.ui.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.fastcashier.lib_common.R;
import java.util.ArrayList;
import java.util.List;
public class NumKeyboard extends LinearLayout {
public static final int DELETE = -2;
public static final int SURE = -3;
private View btn_7, btn_8, btn_9, btn_6, btn_5, btn_4, btn_3, btn_2, btn_1, btn_0;
private View delete;
private Button btn_sure;
private List<View> buttons;
private KeyboardClickListener keyboardClickListener;
public NumKeyboard(Context context) {
this(context, null);
}
public NumKeyboard(Context context, AttributeSet attrs) {
super(context, attrs);
View view = LayoutInflater.from(context).inflate(R.layout.app_layout_keyboard_number, this, true);
buttons = new ArrayList<>(12);
ClickListener clickListener = new ClickListener();
btn_7 = view.findViewById(R.id.btn_7);
btn_8 = view.findViewById(R.id.btn_8);
btn_9 = view.findViewById(R.id.btn_9);
btn_6 = view.findViewById(R.id.btn_6);
btn_5 = view.findViewById(R.id.btn_5);
btn_4 = view.findViewById(R.id.btn_4);
btn_3 = view.findViewById(R.id.btn_3);
btn_2 = view.findViewById(R.id.btn_2);
btn_1 = view.findViewById(R.id.btn_1);
btn_0 = view.findViewById(R.id.btn_0);
delete = view.findViewById(R.id.btn_delete);
btn_sure = view.findViewById(R.id.btn_sure);
buttons.add(btn_7);
buttons.add(btn_8);
buttons.add(btn_9);
buttons.add(btn_6);
buttons.add(btn_5);
buttons.add(btn_4);
buttons.add(btn_3);
buttons.add(btn_2);
buttons.add(btn_1);
buttons.add(btn_0);
buttons.add(delete);
buttons.add(btn_sure);
for (View btn : buttons) {
btn.setOnClickListener(clickListener);
}
}
class ClickListener implements OnClickListener {
@Override
public void onClick(View v) {
if (keyboardClickListener == null) {
return;
}
int i = v.getId();
if (i == R.id.btn_7) {
keyboardClickListener.onNumClick(7);
}
if (i == R.id.btn_8) {
keyboardClickListener.onNumClick(8);
}
if (i == R.id.btn_9) {
keyboardClickListener.onNumClick(9);
}
if (i == R.id.btn_6) {
keyboardClickListener.onNumClick(6);
}
if (i == R.id.btn_5) {
keyboardClickListener.onNumClick(5);
}
if (i == R.id.btn_4) {
keyboardClickListener.onNumClick(4);
}
if (i == R.id.btn_3) {
keyboardClickListener.onNumClick(3);
}
if (i == R.id.btn_2) {
keyboardClickListener.onNumClick(2);
}
if (i == R.id.btn_1) {
keyboardClickListener.onNumClick(1);
}
if (i == R.id.btn_0) {
keyboardClickListener.onNumClick(0);
}
if (i == R.id.btn_delete) {
keyboardClickListener.onNumClick(DELETE);
}
if (i == R.id.btn_sure) {
keyboardClickListener.onNumClick(SURE);
}
}
}
public Button getOkButton(){
return btn_sure;
}
public KeyboardClickListener getKeyboardClickListener() {
return keyboardClickListener;
}
public void setKeyboardClickListener(KeyboardClickListener keyboardClickListener) {
this.keyboardClickListener = keyboardClickListener;
}
public interface KeyboardClickListener {
void onNumClick(int num);
}
}
package com.fastcashier.lib_common.ui.widget
import android.content.Context
import android.util.AttributeSet
import kotlin.jvm.JvmOverloads
import android.widget.LinearLayout
import com.fastcashier.lib_common.R
import com.fastcashier.lib_common.ui.widget.NumKeyboard
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import java.util.ArrayList
class NumKeyboard @JvmOverloads constructor(context: Context?, attrs: AttributeSet? = null) :
LinearLayout(context, attrs) {
private val btn_7: View
private val btn_8: View
private val btn_9: View
private val btn_6: View
private val btn_5: View
private val btn_4: View
private val btn_3: View
private val btn_2: View
private val btn_1: View
private val btn_0: View
private val delete: View
val okButton: Button
private val buttons: MutableList<View>
var keyboardClickListener: KeyboardClickListener? = null
internal inner class ClickListener : OnClickListener {
override fun onClick(v: View) {
if (keyboardClickListener == null) {
return
}
val i = v.id
if (i == R.id.btn_7) {
keyboardClickListener!!.onNumClick(7)
}
if (i == R.id.btn_8) {
keyboardClickListener!!.onNumClick(8)
}
if (i == R.id.btn_9) {
keyboardClickListener!!.onNumClick(9)
}
if (i == R.id.btn_6) {
keyboardClickListener!!.onNumClick(6)
}
if (i == R.id.btn_5) {
keyboardClickListener!!.onNumClick(5)
}
if (i == R.id.btn_4) {
keyboardClickListener!!.onNumClick(4)
}
if (i == R.id.btn_3) {
keyboardClickListener!!.onNumClick(3)
}
if (i == R.id.btn_2) {
keyboardClickListener!!.onNumClick(2)
}
if (i == R.id.btn_1) {
keyboardClickListener!!.onNumClick(1)
}
if (i == R.id.btn_0) {
keyboardClickListener!!.onNumClick(0)
}
if (i == R.id.btn_delete) {
keyboardClickListener!!.onNumClick(DELETE)
}
if (i == R.id.btn_sure) {
keyboardClickListener!!.onNumClick(SURE)
}
}
}
interface KeyboardClickListener {
fun onNumClick(num: Int)
}
companion object {
const val DELETE = -2
const val SURE = -3
}
init {
val view =
LayoutInflater.from(context).inflate(R.layout.app_layout_keyboard_number, this, true)
buttons = ArrayList(12)
val clickListener: ClickListener = ClickListener()
btn_7 = view.findViewById(R.id.btn_7)
btn_8 = view.findViewById(R.id.btn_8)
btn_9 = view.findViewById(R.id.btn_9)
btn_6 = view.findViewById(R.id.btn_6)
btn_5 = view.findViewById(R.id.btn_5)
btn_4 = view.findViewById(R.id.btn_4)
btn_3 = view.findViewById(R.id.btn_3)
btn_2 = view.findViewById(R.id.btn_2)
btn_1 = view.findViewById(R.id.btn_1)
btn_0 = view.findViewById(R.id.btn_0)
delete = view.findViewById(R.id.btn_delete)
okButton = view.findViewById(R.id.btn_sure)
buttons.add(btn_7)
buttons.add(btn_8)
buttons.add(btn_9)
buttons.add(btn_6)
buttons.add(btn_5)
buttons.add(btn_4)
buttons.add(btn_3)
buttons.add(btn_2)
buttons.add(btn_1)
buttons.add(btn_0)
buttons.add(delete)
buttons.add(okButton)
for (btn in buttons) {
btn.setOnClickListener(clickListener)
}
}
fun setKeyNumKeyboardClickListener(keyboardClickListener: KeyboardClickListener){
this.keyboardClickListener = keyboardClickListener
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment