左晓为主开发手持机充值管理机
zuoxiao
2024-08-13 3673328730251736f9614793d9a75630c17b28f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.dayu.qiheonlinelibrary.view;
 
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
 
import com.dayu.baselibrary.utils.TipUtil;
import com.dayu.baselibrary.view.EdtDialog;
import com.dayu.qiheonlinelibrary.R;
 
/**
 * author: zuo
 * Date: 2024-08-09
 * Time: 14:52
 * 备注:补卡工本费
 */
public class ReplacementPriceDialog extends Dialog {
 
    Intent intent;
    Context mContext;
    DialogBack mDialogBack;
 
    String mTitle;
 
 
    public ReplacementPriceDialog(Context context, DialogBack dialogBack) {
        super(context, com.dayu.baselibrary.R.style.ws_pay_showSelfDialog);
        mContext = context;
        mDialogBack = dialogBack;
        initView();
    }
 
 
    private void initView() {
        getWindow().setGravity(Gravity.CENTER);
        setContentView(R.layout.dialog_replace_price);
        setCanceledOnTouchOutside(false);
        TextView textView = (TextView) this.findViewById(com.dayu.baselibrary.R.id.pw_ok);
        EditText editText = (EditText) this.findViewById(com.dayu.baselibrary.R.id.pw_et);
        setPricePoint(editText);
        TextView title = this.findViewById(com.dayu.baselibrary.R.id.title);
        if (!TextUtils.isEmpty(mTitle)) {
            title.setVisibility(View.VISIBLE);
            title.setText(mTitle);
        }
        textView.setOnClickListener(v -> {
            String data = editText.getText().toString();
            if (TextUtils.isEmpty(data)) {
                TipUtil.show("请输入工本费");
            } else {
                if (mDialogBack != null) {
                    mDialogBack.onOk(data);
                }
            }
 
        });
        // 设置 OnKeyListener 拦截返回键事件
        setOnKeyListener((dialog, keyCode, event) -> {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                // 拦截返回键事件,返回 true
                return true;
            }
            return false;
        });
    }
 
    @Override
    public void show() {
 
        super.show();
        /**
         * 设置宽度全屏,要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }
 
    public interface DialogBack {
        void onOk(String data);
    }
 
 
    //校验金额
    public void setPricePoint(final EditText editText) {
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {
                if (s.toString().contains(".")) {
                    if (s.length() - 1 - s.toString().indexOf(".") > 2) {
                        s = s.toString().subSequence(0,
                                s.toString().indexOf(".") + 3);
                        editText.setText(s);
                        editText.setSelection(s.length());
                    }
                }
                if (s.toString().trim().substring(0).equals(".")) {
                    s = "0" + s;
                    editText.setText(s);
                    editText.setSelection(2);
                }
 
                if (s.toString().startsWith("0")
                        && s.toString().trim().length() > 1) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        editText.setText(s.subSequence(0, 1));
                        editText.setSelection(1);
                    }
                }
                String morny = editText.getText().toString();
                if (!TextUtils.isEmpty(morny)) {
//                    rechageWater = MornyUtil.intDiv(MornyUtil.changeY2F(editText.getText().toString()), waterPrice);
//                    binding.redRechargeWater.setText("充值水量:" + rechageWater + " 立方米(吨)");
                }
 
 
            }
 
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
 
            }
 
            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
 
            }
 
        });
 
    }
}