package com.dayu.qihealonelibrary.tools;
|
|
import android.app.Activity;
|
import android.content.Intent;
|
import android.nfc.tech.MifareClassic;
|
|
import com.dayu.baselibrary.tools.nfc.NfcWriteAdapter;
|
import com.dayu.qihealonelibrary.card.UserCard;
|
|
/**
|
* @author zx
|
* @date 2018/4/25 8:08
|
* email 1058083107@qq.com
|
* description
|
*/
|
public class NFCWriteHelper extends QHBaseNFCHelper {
|
|
|
private static NFCWriteHelper helper;
|
private NfcWriteAdapter adapter;
|
|
|
public NFCWriteHelper(Intent intent, Activity activity) {
|
super(activity);
|
adapter = new NfcWriteAdapter(intent, activity);
|
}
|
|
/**
|
* 单例初始化
|
*
|
* @param intent
|
* @return
|
*/
|
public static NFCWriteHelper getInstence(Intent intent, Activity activity) {
|
if (helper == null) {
|
helper = new NFCWriteHelper(intent, activity);
|
}
|
helper.adapter.setIntent(intent);
|
return helper;
|
}
|
|
|
/**
|
* 写卡
|
*
|
* @param userCard 用户卡内容
|
* @param
|
*/
|
public boolean writeUserData(UserCard userCard) {
|
try {
|
return adapter.writeUserData(userCard,1);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return false;
|
}
|
|
|
/**
|
* 写卡
|
*
|
* @param str 书写内容,16个字节
|
* @param a 书写的扇区 (从0开始数)
|
* @param b 书写的块(从0开始数)
|
* @param
|
*/
|
public boolean writeData(byte[] str, int a, int b) {
|
try {
|
return adapter.writeData(str, a, b);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return false;
|
}
|
|
|
/**
|
* 修改密码
|
*
|
* @param a 书写的扇区
|
* // * @param callback 返回监听
|
*/
|
public boolean changePasword(int a, MifareClassic mfc) {
|
try {
|
return adapter.changePasword(a, mfc);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return false;
|
}
|
|
/**
|
* 返回监听类
|
*/
|
public interface NFCCallback {
|
/**
|
* 返回是否成功
|
*
|
* @param flag
|
*/
|
void isSusses(boolean flag);
|
}
|
}
|