左晓为主开发手持机充值管理机
zuoxiao
2024-05-06 e79ced190337222c7475409363c8071c976c7de9
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.qihealonelibrary.activity;
 
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.widget.EditText;
 
import com.dayu.baselibrary.utils.TipUtil;
import com.dayu.qihealonelibrary.databinding.ActivityRechargeQhaBinding;
import com.dayu.qihealonelibrary.dbBean.AdminDataBean;
import com.dayu.qihealonelibrary.tools.NfcReadHelper;
import com.dayu.qihealonelibrary.utils.DeviceNumberUtils;
import com.dayu.qihealonelibrary.view.ProgressDialog;
import com.tencent.bugly.crashreport.CrashReport;
 
 
/**
 * Copyright (C), 2023,
 * Author: zuo
 * Date: 2023-11-5 09:52
 * Description: 充值界面
 */
public class RechargeActivityQHAlone extends BaseNfcActivityQHAlone {
 
    Intent intent;
 
    boolean userFlag;
    ActivityRechargeQhaBinding binding;
    public static RechargeActivityQHAlone rechargeActivity;
 
    AdminDataBean adminData;
    String userName;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            binding = ActivityRechargeQhaBinding.inflate(LayoutInflater.from(this));
            setContentView(binding.getRoot());
            setPricePoint(binding.rechargeWater);
            rechargeActivity = this;
            initView();
        } catch (Exception e) {
            e.printStackTrace();
            CrashReport.postCatchedException(e);
        }
    }
 
    public void onNewIntent(Intent intent) {
 
        try {
            this.intent = intent;
            userCard = NfcReadHelper.getInstence(intent, this).getUserCardData();
            if (userCard != null) {
                ProgressDialog.show(this);
//                selectBalance(userCard.getInitPeasantCode());
            } else {
                TipUtil.show(RechargeActivityQHAlone.this, "卡片读取失败");
            }
 
//            readAllData(intent);
        } catch (Exception e) {
            e.printStackTrace();
            CrashReport.postCatchedException(e);
        }
        super.onNewIntent(intent);
    }
 
    private void initView() {
        try {
            adminData = baseDao.adminDao().findFirst();
        } catch (Exception e) {
            e.printStackTrace();
            CrashReport.postCatchedException(e);
        }
        binding.rechargeRegistBtn.setOnClickListener(v -> {
            String morny = binding.rechargeWater.getText().toString();
            if (!TextUtils.isEmpty(morny)) {
                String initCode = DeviceNumberUtils.getDeviceNumber();
                if (TextUtils.isEmpty(initCode)) {
                    TipUtil.show(RechargeActivityQHAlone.this, "设备注册号为空,请先设置IP和管理员地址");
                    return;
                }
                Intent intent = new Intent(RechargeActivityQHAlone.this, NFCWreatActivityQHAlone.class);
                intent.putExtra("morny", morny);
                intent.putExtra("userName", userName);
                intent.putExtra("userCard", userCard);
                startActivity(intent);
            } else {
                TipUtil.show(RechargeActivityQHAlone.this, "请输入充值金额(元)");
            }
        });
    }
 
 
    //校验金额
    public static 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);
                    }
                }
            }
 
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
 
            }
 
            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
 
            }
 
        });
 
    }
 
 
    protected void onDestroy() {
        super.onDestroy();
        rechargeActivity = null;
    }
}