| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.doumee.keyCabinet.utils.face; |
| | | |
| | | import android.content.Context; |
| | | import android.text.TextUtils; |
| | | |
| | | import com.baidu.idl.main.facesdk.FaceAuth; |
| | | import com.baidu.idl.main.facesdk.callback.Callback; |
| | | import com.baidu.idl.main.facesdk.license.BDFaceLicenseAuthInfo; |
| | | import com.baidu.idl.main.facesdk.model.BDFaceSDKCommon; |
| | | import com.baidu.idl.main.facesdk.utils.PreferencesUtil; |
| | | import com.doumee.lib_coremodel.view.ToastView; |
| | | import com.example.datalibrary.listener.SdkInitListener; |
| | | import com.example.datalibrary.utils.ToastUtils; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | |
| | | public class FaceSDKManager { |
| | | |
| | | public static final int SDK_MODEL_LOAD_SUCCESS = 0; |
| | | public static final int SDK_UNACTIVATION = 1; |
| | | public static final int SDK_UNINIT = 2; |
| | | public static final int SDK_INITING = 3; |
| | | public static final int SDK_INITED = 4; |
| | | public static final int SDK_INIT_FAIL = 5; |
| | | public static final int SDK_INIT_SUCCESS = 6; |
| | | |
| | | public static volatile int initStatus = SDK_UNACTIVATION; |
| | | private FaceAuth faceAuth; |
| | | |
| | | |
| | | private FaceSDKManager() { |
| | | faceAuth = new FaceAuth(); |
| | | faceAuth.setActiveLog(BDFaceSDKCommon.BDFaceLogInfo.BDFACE_LOG_TYPE_ALL, 1); |
| | | faceAuth.setCoreConfigure(BDFaceSDKCommon.BDFaceCoreRunMode.BDFACE_LITE_POWER_NO_BIND, 2); |
| | | |
| | | } |
| | | |
| | | private static class HolderClass { |
| | | private static final FaceSDKManager instance = new FaceSDKManager(); |
| | | } |
| | | |
| | | public static FaceSDKManager getInstance() { |
| | | return HolderClass.instance; |
| | | } |
| | | /** |
| | | * åå§åé´æï¼å¦æé´æéè¿ï¼ç´æ¥åå§å模å |
| | | * |
| | | * @param context |
| | | * @param listener |
| | | */ |
| | | public void init(final Context context, final SdkInitListener listener) { |
| | | |
| | | PreferencesUtil.initPrefs(context.getApplicationContext()); |
| | | final String licenseOfflineKey = PreferencesUtil.getString("activate_offline_key", ""); |
| | | final String licenseOnlineKey = PreferencesUtil.getString("activate_online_key", ""); |
| | | final String licenseBatchlineKey = PreferencesUtil.getString("activate_batchline_key", ""); |
| | | |
| | | // 妿licenseKey ä¸åå¨æç¤ºææç 为空ï¼å¹¶è·³è½¬ææé¡µé¢ææ |
| | | if (TextUtils.isEmpty(licenseOfflineKey) && TextUtils.isEmpty(licenseOnlineKey) |
| | | && TextUtils.isEmpty(licenseBatchlineKey)) { |
| | | ToastView.show(context, "æªææè®¾å¤ï¼è¯·å®ææææ¿æ´»"); |
| | | if (listener != null) { |
| | | listener.initLicenseFail(-1, "ææç ä¸åå¨ï¼è¯·éæ°è¾å
¥ï¼"); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | if (listener != null) { |
| | | listener.initStart(); |
| | | } |
| | | |
| | | if (!TextUtils.isEmpty(licenseOnlineKey)) { |
| | | // å¨çº¿æ¿æ´» |
| | | faceAuth.initLicenseOnLine(context, licenseOnlineKey, new Callback() { |
| | | @Override |
| | | public void onResponse(int code, String response) { |
| | | if (code == 0) { |
| | | initStatus = SDK_INIT_SUCCESS; |
| | | if (listener != null) { |
| | | listener.initLicenseSuccess(); |
| | | } |
| | | // initModel(context, listener); |
| | | return; |
| | | } else { |
| | | listener.initLicenseFail(code, response); |
| | | } |
| | | } |
| | | }); |
| | | } else if (!TextUtils.isEmpty(licenseOfflineKey)) { |
| | | // ç¦»çº¿æ¿æ´» |
| | | faceAuth.initLicenseOffLine(context, new Callback() { |
| | | @Override |
| | | public void onResponse(int code, String response) { |
| | | if (code == 0) { |
| | | initStatus = SDK_INIT_SUCCESS; |
| | | if (listener != null) { |
| | | listener.initLicenseSuccess(); |
| | | } |
| | | // initModel(context, listener); |
| | | return; |
| | | } else { |
| | | listener.initLicenseFail(code, response); |
| | | } |
| | | } |
| | | }); |
| | | } else if (!TextUtils.isEmpty(licenseBatchlineKey)) { |
| | | // åºç¨æ¿æ´» |
| | | faceAuth.initLicenseBatchLine(context, licenseBatchlineKey, new Callback() { |
| | | @Override |
| | | public void onResponse(int code, String response) { |
| | | if (code == 0) { |
| | | PreferencesUtil.putString("activate_batchline_key", licenseBatchlineKey); |
| | | initStatus = SDK_INIT_SUCCESS; |
| | | if (listener != null) { |
| | | listener.initLicenseSuccess(); |
| | | } |
| | | // initModel(context, listener); |
| | | return; |
| | | } else { |
| | | listener.initLicenseFail(code, response); |
| | | } |
| | | } |
| | | }); |
| | | } else { |
| | | if (listener != null) { |
| | | listener.initLicenseFail(-1, "ææç ä¸åå¨ï¼è¯·éæ°è¾å
¥ï¼"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public String getLicenseData(Context context) { |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyå¹´MMæddæ¥"); |
| | | BDFaceLicenseAuthInfo bdFaceLicenseAuthInfo = faceAuth.getAuthInfo(context); |
| | | Date dateLong = new Date(bdFaceLicenseAuthInfo.expireTime * 1000L); |
| | | String dateTime = simpleDateFormat.format(dateLong); |
| | | return dateTime; |
| | | } |
| | | } |