package com.dayu.general.tool
|
|
import android.app.Activity
|
import android.content.Intent
|
import com.dayu.baselibrary.tools.nfc.NFCCallBack
|
import com.dayu.baselibrary.tools.nfc.NfcWriteAdapter
|
import com.dayu.general.bean.card.UserCard
|
|
class NfcWreatHelper private constructor(intent: Intent, activity: Activity) : GeBaseHelper(activity) {
|
|
private val adapter: NfcWriteAdapter = NfcWriteAdapter(intent, activity)
|
|
companion object {
|
private var helper: NfcWreatHelper? = null
|
|
/**
|
* 单例初始化
|
*/
|
@JvmStatic
|
fun getInstance(intent: Intent, activity: Activity): NfcWreatHelper {
|
if (helper == null) {
|
helper = NfcWreatHelper(intent, activity)
|
}
|
helper!!.adapter.setIntent(intent)
|
return helper!!
|
}
|
}
|
|
|
/**
|
* 写卡
|
*
|
* @param str 书写内容,16个字节
|
* @param a 书写的扇区 (从0开始数)
|
* @param b 书写的块(从0开始数)
|
* @param
|
*/
|
fun writeData(str: ByteArray?, a: Int, b: Int,callBack: NFCCallBack): Boolean {
|
try {
|
return adapter.writeData(str, a, b,false,callBack)
|
} catch (e: Exception) {
|
e.printStackTrace()
|
}
|
return false
|
}
|
|
/**
|
* 写卡
|
*
|
* @param userCard 用户卡内容
|
* @param
|
*/
|
fun writeUserData(userCard: UserCard): Boolean {
|
try {
|
return adapter.writeUserData(userCard,7)
|
} catch (e: java.lang.Exception) {
|
e.printStackTrace()
|
}
|
return false
|
}
|
|
|
}
|