baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcReadHelper.java
@@ -31,8 +31,6 @@ private static NativeNfcReadHelper helper; public NativeNfcReadHelper(Intent intent, Activity activity) { } @Override @@ -49,7 +47,7 @@ */ public static NativeNfcReadHelper getInstence(Intent intent, Activity activity) { if (helper == null) { helper = new NativeNfcReadHelper(intent, activity); helper = new NativeNfcReadHelper(); } helper.setIntent(intent); return helper; @@ -387,6 +385,9 @@ @Override public String getCardNumber() { if (tag == null) { return ""; } MifareClassic mfc = MifareClassic.get(tag); if (null != mfc) { try { @@ -434,7 +435,13 @@ } public String getCardNumberNoClose() { if (tag == null) { return ""; } MifareClassic mfc = MifareClassic.get(tag); if (null != mfc) { try { @@ -667,4 +674,6 @@ } return null; } } baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NativeNfcWriteHelper.java
@@ -9,6 +9,7 @@ import com.dayu.baselibrary.bean.BaseUserCardCard; import com.dayu.baselibrary.tools.HexUtil; import com.tencent.bugly.crashreport.CrashReport; import java.io.IOException; @@ -23,8 +24,6 @@ private static NativeNfcWriteHelper helper; public NativeNfcWriteHelper(Intent intent, Activity activity) { } public void setIntent(Intent intent) { this.tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); @@ -38,7 +37,7 @@ */ public static NativeNfcWriteHelper getInstence(Intent intent, Activity activity) { if (helper == null) { helper = new NativeNfcWriteHelper(intent, activity); helper = new NativeNfcWriteHelper(); } helper.setIntent(intent); return helper; @@ -125,7 +124,7 @@ @Override public boolean writeData(byte[] str, int a, int b, NFCCallBack callBack) { return writeData(str, a, b, true,null); return writeData(str, a, b, true, null); } @Override @@ -137,7 +136,7 @@ if (null != mfc) { try { //连接NFC if (isConnect){ if (isConnect) { mfc.connect(); } //获取扇区数量 @@ -172,11 +171,10 @@ } } } else if (listA_PS.size() != 0 && listA_PS.size() > a) { if (mfc.authenticateSectorWithKeyA(a, defauleKey)){ changePasword(a, mfc); if (mfc.authenticateSectorWithKeyA(a, defauleKey)) { isOpen = true; }else if (mfc.authenticateSectorWithKeyA(a, listA_PS.get(a))) { } else if (mfc.authenticateSectorWithKeyA(a, listA_PS.get(a))) { isOpen = true; } } @@ -288,6 +286,18 @@ return false; } public boolean changePasword(int a,byte[] passWord, MifareClassic mfc) { try { } catch (Exception e) { e.printStackTrace(); CrashReport.postCatchedException(e); } return false; } /** * 初始化卡 * baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NfcReadAdapter.java
@@ -27,7 +27,7 @@ public NfcReadAdapter(Intent intent, Activity activity) { switch (BaseNfcActivity.adapterType) { case ModelUtils.defaultType: nativeNfcReadHelper = new NativeNfcReadHelper(intent, activity); nativeNfcReadHelper = NativeNfcReadHelper.getInstence(intent, activity); break; } @@ -62,9 +62,14 @@ } } @Override public String getCardNumber() { return getCardNumber(false); } public String getCardNumber(boolean isChangePS) { switch (BaseNfcActivity.adapterType) { case ModelUtils.defaultType: return nativeNfcReadHelper.getCardNumber(); baselibrary/src/main/java/com/dayu/baselibrary/tools/nfc/NfcWriteAdapter.java
@@ -20,7 +20,7 @@ public NfcWriteAdapter(Intent intent, Activity activity) { switch (BaseNfcActivity.adapterType) { case ModelUtils.defaultType: nativeNfcWriteHelper = new NativeNfcWriteHelper(intent, activity); nativeNfcWriteHelper = NativeNfcWriteHelper.getInstence(intent, activity); break; } } generallibrary/src/main/java/com/dayu/general/activity/BSCardFragment.kt
@@ -15,7 +15,7 @@ */ class BSCardFragment :Fragment() { private var binding: FragmentCardBinding? = null private lateinit var binding: FragmentCardBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } @@ -31,22 +31,28 @@ } private fun initView() { binding?.homeNewCard?.setOnClickListener { binding.homeNewCard.setOnClickListener { val intent = Intent(context, SearchUserListActivity::class.java).apply { putExtra("type", "newUser") } startActivity(intent) } binding?.homeManage?.setOnClickListener { binding.homeManage.setOnClickListener { val intent = Intent(context, ManageListActivity::class.java) startActivity(intent) } binding?.homeLossLL?.setOnClickListener { binding.homeLossLL.setOnClickListener { val intent = Intent(context, SearchCardListActivity::class.java).apply{ putExtra("type", "loss") } startActivity(intent) } binding.homeReplaceLL.setOnClickListener{ val intent = Intent(context, SearchCardListActivity::class.java).apply{ putExtra("type", "replace") } startActivity(intent) } } } generallibrary/src/main/java/com/dayu/general/activity/MainActivity.kt
@@ -33,8 +33,8 @@ getUserInfo() } override fun onNfcBack(intent: Intent?) { intent?.let { nfcIntent -> override fun onNfcBack(intent: Intent) { intent.let { nfcIntent -> // 获取当前显示的Fragment val currentFragment = fragments[binding?.viewPager?.currentItem ?: 0] generallibrary/src/main/java/com/dayu/general/activity/NewCard2Activity.kt
@@ -20,7 +20,7 @@ import kotlinx.coroutines.launch /** * Description: 用户开卡界面 * Description: 用户开卡界面(同步修改白卡密码) * Author: zuo * Date: 2025/4/7 */ generallibrary/src/main/java/com/dayu/general/activity/RechargeFragment.kt
@@ -13,6 +13,7 @@ import com.dayu.general.databinding.FragmentRechargeBinding import com.dayu.general.net.ApiManager import com.dayu.general.net.BaseResponse import com.dayu.general.tool.NfcReadHelper class RechargeFragment : Fragment() { var binding: FragmentRechargeBinding? = null @@ -56,9 +57,15 @@ fun handleNfcIntent(intent: Intent) { activity?.let { activity -> try { // 检查intent中是否包含NFC Tag if (intent.getParcelableExtra<android.nfc.Tag>(android.nfc.NfcAdapter.EXTRA_TAG) == null) { ToastUtil.show("未检测到NFC卡片,请确保卡片已正确放置") return } // 使用NfcReadAdapter读取卡号 val nfcAdapter = NfcReadAdapter(intent, activity) cardNumber = nfcAdapter.cardNumber val nfcAdapter = NfcReadHelper.getInstance(intent, activity) cardNumber = nfcAdapter.getCardNumber() if (cardNumber.isNullOrEmpty()) { ToastUtil.show("读卡失败,请重新刷卡") generallibrary/src/main/res/layout/activity_manage_list_ge.xml
@@ -3,9 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/white" > android:orientation="vertical"> <com.dayu.baselibrary.view.TitleBar android:id="@+id/titleBar" @@ -17,140 +16,146 @@ <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" > android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:orientation="vertical"> android:orientation="vertical" android:padding="16dp"> <TextView android:id="@+id/tv_area_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="设置区域表号卡" android:textSize="16sp" android:textColor="#333333" android:padding="16dp" android:layout_marginBottom="12dp" android:background="@drawable/card_ripple_effect" android:elevation="2dp" android:drawableEnd="@drawable/ic_arrow_right" android:gravity="center_vertical" android:clickable="true" android:focusable="true" /> android:drawableEnd="@drawable/ic_arrow_right" android:elevation="2dp" android:focusable="true" android:gravity="center_vertical" android:padding="16dp" android:text="设置区域表号卡" android:textColor="#333333" android:textSize="16sp" /> <TextView android:id="@+id/tv_check_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="检查卡" android:textSize="16sp" android:textColor="#333333" android:padding="16dp" android:layout_marginBottom="12dp" android:background="@drawable/card_ripple_effect" android:elevation="2dp" android:drawableEnd="@drawable/ic_arrow_right" android:gravity="center_vertical" android:clickable="true" android:focusable="true" /> android:drawableEnd="@drawable/ic_arrow_right" android:elevation="2dp" android:focusable="true" android:gravity="center_vertical" android:padding="16dp" android:text="检查卡" android:textColor="#333333" android:textSize="16sp" /> <TextView android:id="@+id/tv_debug_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="调试卡" android:textSize="16sp" android:textColor="#333333" android:padding="16dp" android:layout_marginBottom="12dp" android:background="@drawable/card_ripple_effect" android:elevation="2dp" android:drawableEnd="@drawable/ic_arrow_right" android:gravity="center_vertical" android:clickable="true" android:focusable="true" /> android:drawableEnd="@drawable/ic_arrow_right" android:elevation="2dp" android:focusable="true" android:gravity="center_vertical" android:padding="16dp" android:text="调试卡" android:textColor="#333333" android:textSize="16sp" /> <TextView android:id="@+id/tv_clean_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="清零卡" android:textSize="16sp" android:textColor="#333333" android:padding="16dp" android:layout_marginBottom="12dp" android:background="@drawable/card_ripple_effect" android:elevation="2dp" android:drawableEnd="@drawable/ic_arrow_right" android:gravity="center_vertical" android:clickable="true" android:focusable="true" /> android:drawableEnd="@drawable/ic_arrow_right" android:elevation="2dp" android:focusable="true" android:gravity="center_vertical" android:padding="16dp" android:text="清零卡" android:textColor="#333333" android:textSize="16sp" android:visibility="gone" /> <TextView android:id="@+id/tv_ip_setting_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="IP地址设置卡" android:textSize="16sp" android:textColor="#333333" android:padding="16dp" android:layout_marginBottom="12dp" android:background="@drawable/card_ripple_effect" android:elevation="2dp" android:drawableEnd="@drawable/ic_arrow_right" android:gravity="center_vertical" android:clickable="true" android:focusable="true" /> android:drawableEnd="@drawable/ic_arrow_right" android:elevation="2dp" android:focusable="true" android:gravity="center_vertical" android:padding="16dp" android:text="IP地址设置卡" android:textColor="#333333" android:textSize="16sp" android:visibility="gone" /> <TextView android:id="@+id/tv_domain_setting_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="域名设置卡" android:textSize="16sp" android:textColor="#333333" android:padding="16dp" android:layout_marginBottom="12dp" android:background="@drawable/card_ripple_effect" android:elevation="2dp" android:drawableEnd="@drawable/ic_arrow_right" android:gravity="center_vertical" android:clickable="true" android:focusable="true" /> android:drawableEnd="@drawable/ic_arrow_right" android:elevation="2dp" android:focusable="true" android:gravity="center_vertical" android:padding="16dp" android:text="域名设置卡" android:textColor="#333333" android:textSize="16sp" android:visibility="gone" /> <TextView android:id="@+id/tv_gps_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="GPS定位卡" android:textSize="16sp" android:textColor="#333333" android:padding="16dp" android:layout_marginBottom="12dp" android:background="@drawable/card_ripple_effect" android:elevation="2dp" android:drawableEnd="@drawable/ic_arrow_right" android:gravity="center_vertical" android:clickable="true" android:focusable="true" /> android:drawableEnd="@drawable/ic_arrow_right" android:elevation="2dp" android:focusable="true" android:gravity="center_vertical" android:padding="16dp" android:text="GPS定位卡" android:textColor="#333333" android:textSize="16sp" android:visibility="gone" /> <TextView android:id="@+id/tv_valve_time_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="配置开关阀时间卡" android:textSize="16sp" android:textColor="#333333" android:padding="16dp" android:layout_marginBottom="12dp" android:background="@drawable/card_ripple_effect" android:elevation="2dp" android:drawableEnd="@drawable/ic_arrow_right" android:gravity="center_vertical" android:clickable="true" android:focusable="true" /> android:drawableEnd="@drawable/ic_arrow_right" android:elevation="2dp" android:focusable="true" android:gravity="center_vertical" android:padding="16dp" android:text="配置开关阀时间卡" android:textColor="#333333" android:textSize="16sp" android:visibility="gone" /> </LinearLayout> </ScrollView> </LinearLayout> generallibrary/src/main/res/layout/fragment_card.xml
@@ -215,6 +215,7 @@ app:layout_constraintTop_toBottomOf="@+id/home_redCard"> <LinearLayout android:id="@+id/home_replaceLL" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" @@ -231,7 +232,7 @@ android:layout_height="wrap_content" android:layout_marginTop="6dp" android:gravity="center" android:text="补卡" android:text="解挂、补卡" android:textColor="@color/text_selecter_color" android:textSize="14sp" /> </LinearLayout> generallibrary/src/main/res/layout/item_card_replace.xml
New file @@ -0,0 +1,180 @@ <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <data> <variable name="cardInfo" type="com.dayu.general.bean.net.CardReplaceInfo" /> </data> <androidx.cardview.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginHorizontal="10dp" android:layout_marginVertical="6dp" app:cardCornerRadius="10dp" app:cardElevation="3dp" app:cardBackgroundColor="@color/white"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="12dp"> <!-- 顶部信息:卡号和状态 --> <TextView android:id="@+id/tv_card_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="卡号" android:textColor="@color/title_bar_text" android:textSize="14sp" android:textStyle="bold" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/tv_card_number" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginEnd="16dp" android:text="@{cardInfo.cardNum}" android:textColor="@color/colorPrimary" android:textSize="16sp" android:textStyle="bold" app:layout_constraintStart_toEndOf="@+id/tv_card_label" app:layout_constraintTop_toTopOf="@+id/tv_card_label" app:layout_constraintEnd_toStartOf="@+id/tv_status" tools:text="123456789" /> <TextView android:id="@+id/tv_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/shape_status_bg" android:paddingHorizontal="10dp" android:paddingVertical="3dp" android:text="@{cardInfo.stateName}" android:textColor="@color/white" android:textSize="12sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" tools:text="已挂失" /> <!-- 分隔线 --> <View android:id="@+id/divider" android:layout_width="match_parent" android:layout_height="0.5dp" android:layout_marginTop="12dp" android:background="@color/light_grey" app:layout_constraintTop_toBottomOf="@+id/tv_card_number" /> <!-- 客户信息 --> <TextView android:id="@+id/tv_client_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:text="客户" android:textColor="@color/title_bar_text" android:textSize="14sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/divider" /> <TextView android:id="@+id/tv_client_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:text="@{cardInfo.clientName}" android:textColor="@color/title_bar_text" android:textSize="14sp" android:textStyle="bold" app:layout_constraintStart_toEndOf="@+id/tv_client_label" app:layout_constraintTop_toTopOf="@+id/tv_client_label" tools:text="张三" /> <!-- 卡类型信息(交换到客户编号的位置) --> <TextView android:id="@+id/tv_card_type_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="30dp" android:text="卡类型" android:textColor="@color/title_bar_text" android:textSize="14sp" app:layout_constraintStart_toEndOf="@+id/tv_client_name" app:layout_constraintTop_toTopOf="@+id/tv_client_name" /> <TextView android:id="@+id/tv_card_type" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:text="@{cardInfo.cardType}" android:textColor="@color/title_bar_text" android:textSize="14sp" app:layout_constraintStart_toEndOf="@+id/tv_card_type_label" app:layout_constraintTop_toTopOf="@+id/tv_card_type_label" tools:text="普通卡" /> <!-- 客户编号信息(交换到卡类型的位置) --> <TextView android:id="@+id/tv_client_number_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="编号" android:textColor="@color/title_bar_text" android:textSize="14sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/tv_client_label" /> <TextView android:id="@+id/tv_client_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:text="@{cardInfo.clientNum}" android:textColor="@color/title_bar_text" android:textSize="14sp" app:layout_constraintStart_toEndOf="@+id/tv_client_number_label" app:layout_constraintTop_toTopOf="@+id/tv_client_number_label" tools:text="C12345" /> <!-- 余额信息(放大字体) --> <TextView android:id="@+id/tv_money_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:text="余额" android:textColor="@color/colorAccent" android:textSize="16sp" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/tv_client_number_label" app:layout_constraintVertical_bias="1.0" /> <TextView android:id="@+id/tv_money" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:text="@{cardInfo.money.concat(" 元")}" android:textColor="@color/colorAccent" android:textSize="20sp" android:textStyle="bold" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="@+id/tv_money_label" tools:text="100.00 元" /> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.cardview.widget.CardView> </layout>