左晓为主开发手持机充值管理机
zuoxiao
2024-03-26 1b4835badb3ca32402b6544c668a700c5334d90f
app/src/main/java/com/dayu/recharge/activity/RechargeActivity.java
@@ -65,7 +65,7 @@
        try {
            this.intent = intent;
            userCard = NfcReadHelper.getInstence(intent).getUserCardData();
            userCard = NfcReadHelper.getInstence(intent, this).getUserCardData();
            if (userCard != null) {
                ProgressDialog.show(this);
                selectBalance(userCard.getInitPeasantCode());
@@ -73,7 +73,7 @@
                TipUtil.show(RechargeActivity.this, "卡片读取失败");
            }
            readAllData(intent);
//            readAllData(intent);
        } catch (Exception e) {
            e.printStackTrace();
            CrashReport.postCatchedException(e);
@@ -88,23 +88,21 @@
            e.printStackTrace();
            CrashReport.postCatchedException(e);
        }
        binding.rechargeRegistBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String morny = binding.rechargeWater.getText().toString();
                if (!TextUtils.isEmpty(morny)) {
                    String initCode = DeviceNumberUtils.getDeviceNumber();
                    if (TextUtils.isEmpty(initCode)) {
                        TipUtil.show(RechargeActivity.this, "设备注册号为空,请先设置IP和管理员地址");
                    }
                    Intent intent = new Intent(RechargeActivity.this, NFCWreatActivity.class);
                    intent.putExtra("morny", morny);
                    intent.putExtra("userName", userName);
                    intent.putExtra("userCard", userCard);
                    startActivity(intent);
                } else {
                    TipUtil.show(RechargeActivity.this, "请输入充值金额(元)");
        binding.rechargeRegistBtn.setOnClickListener(v -> {
            String morny = binding.rechargeWater.getText().toString();
            if (!TextUtils.isEmpty(morny)) {
                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);
                intent.putExtra("userName", userName);
                intent.putExtra("userCard", userCard);
                startActivity(intent);
            } else {
                TipUtil.show(RechargeActivity.this, "请输入充值金额(元)");
            }
        });
    }
@@ -135,7 +133,6 @@
                    if (!s.toString().substring(1, 2).equals(".")) {
                        editText.setText(s.subSequence(0, 1));
                        editText.setSelection(1);
                        return;
                    }
                }
            }
@@ -170,41 +167,49 @@
            requestBean.setInitCode(initCode);
            requestBean.setInitPeasantCode(initPeasantCode);
            requestBean.setXuLie(SocketUtil.getXuLie(this));
            SocketNet.getInstance().sendTestMessage(requestBean.pack(), new SocketCallBack() {
            SocketNet.getInstance().sendTestMessage(requestBean.pack(),"94", new SocketCallBack() {
                @Override
                public void onSocketResponse(SocketData readData) {
                    ProgressDialog.dismiss();
                    if (CRC8.isCRC8(readData.getOriginDataBytes())) {
                        StringBuffer stateText = null;
                        StringBuffer stateText ;
                        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);
                            binding.rechargeTextLL.setVisibility(View.VISIBLE);
                            binding.userName.setText(userName);
                            binding.redRemainderBlance.setText(MornyUtil.changeF2Y(balance));
                            binding.redStatu.setText(stateText.toString());
                            binding.redInitCode.setText(initPeasantCode);
                            if ("00".equals(state)) {
                                stateText.append("启用");
                                binding.rechargeLL.setVisibility(View.VISIBLE);
                                binding.rechargeRegistBtn.setVisibility(View.VISIBLE);
                                binding.rechargeReadLL.setVisibility(View.GONE);
                                binding.rechargeTextLL.setVisibility(View.VISIBLE);
                                binding.userName.setText(userName);
                                binding.redRemainderBlance.setText(MornyUtil.changeF2Y(balance));
                                binding.redStatu.setText(stateText.toString());
                                binding.redInitCode.setText(initPeasantCode);
                                stateText.append("启用");
                                userCard.setState("00");
                                userCard.setBalance(balance);
                                binding.redStatu.setText(stateText.toString());
                                return;
                            } else if ("01".equals(state)) {
                                stateText.append("该卡已被禁用");
                                userCard.setState("01");
                                userCard.setBalance(balance);
                                userFlag = WriteCardUtils.setUser(intent, userCard);
                                userFlag = WriteCardUtils.setUser(intent, userCard, RechargeActivity.this);
                            } else if ("02".equals(state)) {
                                stateText.append("隶属信息不符");
                            } else if ("03".equals(state)) {
@@ -212,7 +217,9 @@
                            } else if ("04".equals(state)) {
                                stateText.append("其它");
                            }
                            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) {
@@ -237,4 +244,8 @@
    }
    protected void onDestroy() {
        super.onDestroy();
        rechargeActivity = null;
    }
}