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; } }