| package com.dayu.qiheonlinelibrary.tools; | 
|   | 
| import android.app.Activity; | 
| import android.content.Intent; | 
| import android.nfc.tech.MifareClassic; | 
|   | 
| import com.dayu.baselibrary.tools.nfc.NfcWriteAdapter; | 
| import com.dayu.qiheonlinelibrary.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; | 
|     } | 
|   | 
|     /** | 
|      * 初始化卡 | 
|      * | 
|      * @return | 
|      */ | 
|     public boolean initCard() { | 
|         try { | 
|             return adapter.initCard(); | 
|         } catch (Exception e) { | 
|             e.printStackTrace(); | 
|         } | 
|         return false; | 
|     } | 
|   | 
|   | 
| } |