左晓为主开发手持机充值管理机
zuoxiao
2023-11-30 8e3719a37a6be0c9e244a0160b5f2f3331ca3122
app/src/main/java/com/dayu/recharge/activity/RechargeActivity.java
@@ -1,6 +1,7 @@
package com.dayu.recharge.activity;
import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
@@ -37,7 +38,7 @@
 */
public class RechargeActivity extends BaseNfcActivity {
    Intent intent;
//    Intent intent;
    boolean userFlag;
    ActivityRechargeBinding binding;
@@ -46,6 +47,7 @@
    AdminDataBean adminData;
    String userName;
    Tag mTag;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -61,10 +63,30 @@
        }
    }
    @Override
    public void physicalCardDoing(Tag tag) {
        super.physicalCardDoing(tag);
        try {
            mTag=tag;
            userCard = NfcReadHelper.getInstence(tag).getUserCardData();
            if (userCard != null) {
                ProgressDialog.show(this);
                selectBalance(userCard.getInitPeasantCode());
            } else {
                TipUtil.show(RechargeActivity.this, "卡片读取失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            CrashReport.postCatchedException(e);
        }
    }
    public void onNewIntent(Intent intent) {
        try {
            this.intent = intent;
//            this.intent = intent;
            userCard = NfcReadHelper.getInstence(intent).getUserCardData();
            if (userCard != null) {
                ProgressDialog.show(this);
@@ -73,7 +95,7 @@
                TipUtil.show(RechargeActivity.this, "卡片读取失败");
            }
            readAllData(intent);
//            readAllData(intent);
        } catch (Exception e) {
            e.printStackTrace();
            CrashReport.postCatchedException(e);
@@ -96,6 +118,7 @@
                    String initCode = DeviceNumberUtils.getDeviceNumber();
                    if (TextUtils.isEmpty(initCode)) {
                        TipUtil.show(RechargeActivity.this, "设备注册号为空,请先设置IP和管理员地址");
                        return;
                    }
                    Intent intent = new Intent(RechargeActivity.this, NFCWreatActivity.class);
                    intent.putExtra("morny", morny);
@@ -179,14 +202,19 @@
                        try {
                            stateText = new StringBuffer();
                            String state = BcdUtil.bcdToStr(readData.getBodyBytes()[2]);  //BCD码00启用 01禁用 02隶属信息不符 03无此卡信息 04其它s
                            int balance = 0;
                            //只有启动状态才能充值
                            //金额
                            byte[] blanceByte = Arrays.copyOfRange(readData.getBodyBytes(), 3, 7);
                            int balance = SocketUtil.get16to10LowHigh(blanceByte);
                            //姓名
                            byte[] nameByte = Arrays.copyOfRange(readData.getBodyBytes(), 7, 19);
                            userName = SocketUtil.fromHexString(SocketUtil.bytesToHexClean0(nameByte));
                            try {
                                //只有启动状态才能充值
                                //金额
                                byte[] blanceByte = Arrays.copyOfRange(readData.getBodyBytes(), 3, 7);
                                balance = SocketUtil.get16to10LowHigh(blanceByte);
                                //姓名
                                byte[] nameByte = Arrays.copyOfRange(readData.getBodyBytes(), 7, 19);
                                userName = SocketUtil.fromHexString(SocketUtil.bytesToHexClean0(nameByte));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            binding.rechargeLL.setVisibility(View.VISIBLE);
                            binding.rechargeRegistBtn.setVisibility(View.VISIBLE);
                            binding.rechargeReadLL.setVisibility(View.GONE);
@@ -195,7 +223,9 @@
                            binding.redRemainderBlance.setText(MornyUtil.changeF2Y(balance));
                            binding.redStatu.setText(stateText.toString());
                            binding.redInitCode.setText(initPeasantCode);
                            if ("00".equals(state)) {
                                binding.rechargeRegistBtn.setVisibility(View.VISIBLE);
                                stateText.append("启用");
                                userCard.setState("00");
                                userCard.setBalance(balance);
@@ -205,7 +235,7 @@
                                stateText.append("该卡已被禁用");
                                userCard.setState("01");
                                userCard.setBalance(balance);
                                userFlag = WriteCardUtils.setUser(intent, userCard);
                                userFlag = WriteCardUtils.setUser(mTag, userCard);
                            } else if ("02".equals(state)) {
                                stateText.append("隶属信息不符");
                            } else if ("03".equals(state)) {
@@ -215,6 +245,7 @@
                            }
                            binding.redStatu.setText(stateText.toString());
                            binding.rechargeLL.setVisibility(View.GONE);
                            binding.rechargeRegistBtn.setVisibility(View.GONE);
                            binding.rechargeRegistBtn.setVisibility(View.GONE);
                            TipUtil.show(RechargeActivity.this, stateText.toString());
                        } catch (Exception e) {
@@ -238,8 +269,9 @@
        }
    }
    protected void onDestroy() {
        super.onDestroy();
        rechargeActivity=null;
        rechargeActivity = null;
    }
}