honghengqiang пре 3 година
родитељ
комит
cb9879341c

+ 5 - 0
.idea/jarRepositories.xml

@@ -51,5 +51,10 @@
       <option name="name" value="maven3" />
       <option name="url" value="https://oss.sonatype.org/content/repositories/snapshots/" />
     </remote-repository>
+    <remote-repository>
+      <option name="id" value="maven3" />
+      <option name="name" value="maven3" />
+      <option name="url" value="http://maven.faceunity.com/repository/maven-public/" />
+    </remote-repository>
   </component>
 </project>

BIN
app/debug/com.swago.app-debug-1.0.6.apk


+ 18 - 0
app/debug/output-metadata.json

@@ -0,0 +1,18 @@
+{
+  "version": 2,
+  "artifactType": {
+    "type": "APK",
+    "kind": "Directory"
+  },
+  "applicationId": "com.swago.app",
+  "variantName": "debug",
+  "elements": [
+    {
+      "type": "SINGLE",
+      "filters": [],
+      "versionCode": 106,
+      "versionName": "1.0.6",
+      "outputFile": "com.swago.app-debug-1.0.6.apk"
+    }
+  ]
+}

+ 2 - 0
build.gradle

@@ -6,6 +6,7 @@ buildscript {
         maven { url 'https://jitpack.io' }
         mavenCentral()
         maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
+        maven { url 'http://maven.faceunity.com/repository/maven-public/' }
     }
     dependencies {
         classpath "com.android.tools.build:gradle:4.2.1"
@@ -24,6 +25,7 @@ allprojects {
         maven { url 'https://jitpack.io' }
         mavenCentral()
         maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
+        maven { url 'http://maven.faceunity.com/repository/maven-public/' }
     }
 }
 

+ 1 - 1
lib_beauty/build.gradle

@@ -30,7 +30,7 @@ android {
 }
 
 dependencies {
-
+    api 'com.faceunity:core:7.4.1.0'
     implementation 'androidx.core:core-ktx:1.7.0'
     implementation 'androidx.appcompat:appcompat:1.3.0'
     implementation 'com.google.android.material:material:1.4.0'

BIN
lib_beauty/src/main/assets/model/ai_face_processor_lite.bundle


BIN
lib_beauty/src/main/assets/model/face_beautification.bundle


+ 20 - 0
lib_beauty/src/main/java/com/swago/lib_beauty/BeautyConfig.kt

@@ -0,0 +1,20 @@
+package com.swago.lib_beauty
+
+import java.io.File
+
+/**
+ *@date 2021/8/11 22:12
+ *description:
+ */
+object BeautyConfig {
+
+    //人脸识别
+    var BUNDLE_AI_FACE = "model" + File.separator + "ai_face_processor_lite.bundle"
+    //美颜
+    var BUNDLE_FACE_BEAUTIFICATION = "model" + File.separator + "face_beautification.bundle"
+
+
+    val defaultParams = arrayListOf<Double>(0.7,0.7,0.7,0.0,0.0,0.5,0.0,0.0,
+        0.3,0.5,0.0,0.0,0.0,0.0,0.5,0.0,0.5,0.3,0.5,0.5,0.0,0.5,0.5,0.7,0.5,0.0)
+
+}

+ 76 - 0
lib_beauty/src/main/java/com/swago/lib_beauty/CacheInterface.java

@@ -0,0 +1,76 @@
+package com.swago.lib_beauty;
+
+import android.content.SharedPreferences;
+import android.os.Parcelable;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public interface CacheInterface {
+    public void saveData(String key, String value);
+
+    public void saveData(String key, String value, boolean commit);
+
+    public void saveData(String key, int value);
+
+    public void saveData(String key, int value, boolean commit);
+
+    public void saveData(String key, boolean value);
+
+    public void saveData(String key, boolean value, boolean commit);
+
+    public void saveData(String key, long value);
+
+    public void saveData(String key, long value, boolean commit);
+
+    public void saveData(String key, float value);
+
+    public void saveData(String key, float value, boolean commit);
+
+    public void saveData(String key, Set<String> value);
+
+    public void saveData(String key, Set<String> value, boolean commit);
+
+    public void saveData(String key, Parcelable parcelable);
+
+    public String readString(String key);
+
+    public String readString(String key, String defaultValue);
+
+    public int readInt(String key);
+
+    public int readInt(String key, int defaultValue);
+
+    public boolean readBoolean(String key);
+
+    public boolean readBoolean(String key, boolean defaultValue);
+
+    public long readLong(String key);
+
+    public long readLong(String key, long defaultValue);
+
+    public float readFloat(String key);
+
+    public float readFloat(String key, float defaultValue);
+
+    public HashSet<String> readSetString(String key);
+
+    public HashSet<String> readSetString(String key, Set<String> defaultValue);
+
+    public <T extends Parcelable> T readParcelable(String key, Class<T> tClass);
+
+    public boolean contains(String key);
+
+    public void remove(String key);
+
+    public void remove(String key, boolean commit);
+
+    public void clear();
+
+    public boolean isCacheFileExists();
+
+    public long lastModified();
+
+    public void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener, boolean regist) throws IllegalAccessException;
+
+}

+ 93 - 0
lib_beauty/src/main/java/com/swago/lib_beauty/FURenderer.java

@@ -0,0 +1,93 @@
+package com.swago.lib_beauty;
+
+import com.faceunity.core.entity.FURenderInputData;
+import com.faceunity.core.entity.FURenderOutputData;
+import com.faceunity.core.enumeration.CameraFacingEnum;
+import com.faceunity.core.enumeration.FUTransformMatrixEnum;import com.lin.libfubeauty.FuBeautyManager;import com.lin.libfubeauty.IFURenderer;
+
+import java.util.HashMap;
+
+
+/**
+ * DESC:
+ * Created on 2021/4/26
+ */
+public class FURenderer extends IFURenderer {
+
+    /* 相机角度-朝向映射 */
+    private HashMap<Integer, CameraFacingEnum> cameraOrientationMap = new HashMap<>();
+
+    public volatile static FURenderer INSTANCE;
+
+    public static FURenderer getInstance() {
+        if (INSTANCE == null) {
+            synchronized (FURenderer.class) {
+                if (INSTANCE == null) {
+                    INSTANCE = new FURenderer();
+                }
+            }
+        }
+        return INSTANCE;
+    }
+
+    @Override
+    public void release() {
+        //FuBeautyManager.INSTANCE.getMFURenderKit().release();
+    }
+
+    /**
+     * 双输入接口,输入 buffer 和 texture,必须在具有 GL 环境的线程调用
+     * 由于省去数据拷贝,性能相对最优,优先推荐使用。
+     * 缺点是无法保证 buffer 和纹理对齐,可能出现点位和效果对不上的情况。
+     *
+     * @param img    NV21 buffer
+     * @param texId  纹理 ID
+     * @param width  宽
+     * @param height 高
+     * @return
+     */
+    @Override
+    public int onDrawFrameDualInput(byte[] img, int texId, int width, int height) {
+        FURenderInputData inputData = new FURenderInputData(width, height);
+        /*注释掉Buffer配置,启用单纹理模式,防止Buffer跟纹理存在不对齐造成,美妆偏移*/
+        //inputData.setImageBuffer(new FURenderInputData.FUImageBuffer(inputBufferType, img));//设置为单Buffer输入
+        inputData.setTexture(new FURenderInputData.FUTexture(inputTextureType, texId));
+        FURenderInputData.FURenderConfig config = inputData.getRenderConfig();
+        config.setExternalInputType(externalInputType);
+        config.setInputOrientation(inputOrientation);
+        config.setDeviceOrientation(deviceOrientation);
+        config.setInputBufferMatrix(inputBufferMatrix);
+        config.setInputTextureMatrix(inputTextureMatrix);
+        config.setOutputMatrix(outputMatrix);
+        config.setCameraFacing(cameraFacing);
+        FURenderOutputData outputData = FuBeautyManager.INSTANCE.getMFURenderKit().renderWithInput(inputData);
+        if (outputData.getTexture() != null && outputData.getTexture().getTexId() > 0) {
+            return outputData.getTexture().getTexId();
+        }
+        return texId;
+    }
+
+    /**
+     * 设置输入数据朝向
+     *
+     * @param inputOrientation
+     */
+    @Override
+    public void setInputOrientation(int inputOrientation) {
+        if (cameraOrientationMap.containsKey(inputOrientation)) {
+            CameraFacingEnum cameraFacingEnum = cameraOrientationMap.get(inputOrientation);
+            setCameraFacing(cameraFacingEnum);
+            if (cameraFacingEnum == CameraFacingEnum.CAMERA_FRONT) {
+                setInputBufferMatrix(FUTransformMatrixEnum.CCROT90_FLIPHORIZONTAL);
+                setInputTextureMatrix(FUTransformMatrixEnum.CCROT90_FLIPHORIZONTAL);
+                setOutputMatrix(FUTransformMatrixEnum.CCROT270);
+            } else {
+                setInputBufferMatrix(FUTransformMatrixEnum.CCROT270);
+                setInputTextureMatrix(FUTransformMatrixEnum.CCROT270);
+                setOutputMatrix(FUTransformMatrixEnum.CCROT90_FLIPVERTICAL);
+            }
+        }
+        super.setInputOrientation(inputOrientation);
+    }
+
+}

+ 329 - 0
lib_beauty/src/main/java/com/swago/lib_beauty/FuBeautyManager.kt

@@ -0,0 +1,329 @@
+package com.swago.lib_beauty
+
+
+import android.content.Context
+import android.text.TextUtils
+import com.faceunity.core.callback.OperateCallback
+import com.faceunity.core.entity.FUBundleData
+import com.faceunity.core.enumeration.FUAITypeEnum
+import com.faceunity.core.faceunity.FURenderKit
+import com.faceunity.core.faceunity.FURenderManager.registerFURender
+import com.faceunity.core.faceunity.FURenderManager.setCoreDebug
+import com.faceunity.core.faceunity.FURenderManager.setKitDebug
+import com.faceunity.core.model.facebeauty.FaceBeauty
+import com.faceunity.core.utils.FULogger
+
+/**
+ *@date 2021/8/11 21:38
+ *description:
+ */
+object FuBeautyManager {
+
+    var mFaceBeauty: FaceBeauty? = null
+    var mFURenderKit: FURenderKit? = null
+
+    /**
+     * 美颜初始化
+     */
+    fun initBeauty(context: Context, auth: ByteArray, iOperateCallback: IOperateCallback) {
+        /**
+         * 日志设置
+         */
+//        if (BuildConfig.DEBUG) {
+//            setKitDebug(FULogger.LogLevel.INFO)
+//            setCoreDebug(FULogger.LogLevel.INFO)
+//        }
+
+        registerFURender(context, auth, object : OperateCallback {
+            override fun onFail(errCode: Int, errMsg: String) {
+                iOperateCallback.onFail(errCode, errMsg)
+            }
+
+            override fun onSuccess(code: Int, msg: String) {
+                iOperateCallback.onSuccess(code, msg)
+            }
+        })
+
+
+        mFURenderKit = FURenderKit.getInstance()
+        //人脸识别
+        mFURenderKit?.FUAIController?.loadAIProcessor(
+            BeautyConfig.BUNDLE_AI_FACE,
+            FUAITypeEnum.FUAITYPE_FACEPROCESSOR
+        )
+        //美颜
+        mFaceBeauty = FaceBeauty(FUBundleData(BeautyConfig.BUNDLE_FACE_BEAUTIFICATION))
+        mFURenderKit?.faceBeauty = mFaceBeauty
+        //最大人脸识别数
+        mFURenderKit?.FUAIController?.maxFaces = 2
+    }
+
+    /************************美颜设置****************************/
+
+
+    fun setBeauty(index: Int, value: Double) {
+        when (index) {
+            0 -> {
+                /**
+                 * 磨皮[0.0-6.0]
+                 */
+                mFaceBeauty?.blurIntensity = value * 6
+            }
+
+            1 -> {
+                /**
+                 * 美白[0.0-1.0]
+                 */
+                mFaceBeauty?.colorIntensity = value
+            }
+
+            2 -> {
+                /**
+                 * 红润[0.0-1.0]
+                 */
+                mFaceBeauty?.redIntensity = value
+            }
+
+            3 -> {
+                /**
+                 * 锐化[0.0-1.0]
+                 */
+                mFaceBeauty?.sharpenIntensity = value
+            }
+
+            4 -> {
+                /**
+                 * 亮眼[0.0-1.0]
+                 */
+                mFaceBeauty?.eyeBrightIntensity = value
+            }
+
+            5 -> {
+                /**
+                 * 美牙[0.0-1.0]
+                 */
+                mFaceBeauty?.toothIntensity = value
+            }
+
+            6 -> {
+                /**
+                 * 去黑眼圈强度[0.0-1.0]
+                 */
+                mFaceBeauty?.removePouchIntensity = value
+            }
+
+            7 -> {
+                /**
+                 * 去法令纹[0.0-1.0]
+                 */
+                mFaceBeauty?.removeLawPatternIntensity = value
+            }
+
+            8 -> {
+                /**
+                 * 瘦脸[0.0-1.0]
+                 */
+                mFaceBeauty?.cheekThinningIntensity = value
+            }
+
+            9 -> {
+                /**
+                 * V脸[0.0-1.0]
+                 */
+                mFaceBeauty?.cheekVIntensity = value
+            }
+
+            10 -> {
+                /**
+                 * 窄脸[0.0-0.5]
+                 */
+                mFaceBeauty?.cheekNarrowIntensity = value * 0.5
+            }
+
+            11 -> {
+                /**
+                 * 小脸[0.0-0.5]
+                 */
+                mFaceBeauty?.cheekSmallIntensity = value * 0.5
+            }
+
+            12 -> {
+                /**
+                 * 瘦颧骨[0.0-1.0]
+                 */
+                mFaceBeauty?.cheekBonesIntensity = value
+            }
+
+            13 -> {
+                /**
+                 * 瘦下颌骨[0.0-1.0]
+                 */
+                mFaceBeauty?.lowerJawIntensity = value
+            }
+            14 -> {
+                /**
+                 * 大眼[0.0-1.0]
+                 */
+                mFaceBeauty?.eyeEnlargingIntensity = value
+            }
+
+            15 -> {
+                /**
+                 * 圆眼程度[0.0-1.0]
+                 */
+                mFaceBeauty?.eyeCircleIntensity = value
+            }
+
+            16 -> {
+                /**
+                 * 下巴
+                 * 范围[0.0-1.0],0-0.5是变小,0.5-1是变大
+                 */
+                mFaceBeauty?.chinIntensity = value
+            }
+            17 -> {
+                /**
+                 * 额头
+                 * 范围[0.0-1.0],0-0.5是变小,0.5-1是变大
+                 */
+                mFaceBeauty?.forHeadIntensity = value
+            }
+
+            18 -> {
+                /**
+                 * 瘦鼻[0.0-1.0]
+                 */
+                mFaceBeauty?.noseIntensity = value
+            }
+
+            19 -> {
+                /**
+                 * 嘴巴
+                 * 范围[0.0-1.0],0-0.5是变小,0.5-1是变大
+                 */
+                mFaceBeauty?.mouthIntensity = value
+            }
+            20 -> {
+                /**
+                 * 开眼角[0.0-1.0]
+                 */
+                mFaceBeauty?.canthusIntensity = value
+            }
+
+            21 -> {
+                /**
+                 * 眼睛间距
+                 * 范围[0.0-1.0] ,0.5-0.0 变长,0.5-1.0 变短
+                 */
+                mFaceBeauty?.eyeSpaceIntensity = value
+            }
+
+            22 -> {
+                /**
+                 * 眼睛角度
+                 * 范围[0.0-1.0],0.5-0.0 逆时针旋转,0.5-1.0 顺时针旋转
+                 */
+                mFaceBeauty?.eyeRotateIntensity = value
+            }
+            23 -> {
+                /**
+                 * 鼻子长度
+                 * 范围[0.0-1.0],0.5-0.0 变短,0.5-1.0 变长
+                 */
+                mFaceBeauty?.longNoseIntensity = value
+            }
+
+            24 -> {
+                /**
+                 * 调节人中
+                 * 范围[0.0-1.0],0.5-1.0 变长,0.5-0.0 变短
+                 */
+                mFaceBeauty?.philtrumIntensity = value
+            }
+
+            25 -> {
+                /**
+                 * 微笑嘴角强度[0.0-1.0]
+                 */
+                mFaceBeauty?.smileIntensity = value
+            }
+        }
+    }
+
+
+    /************************美颜设置****************************/
+
+
+    /**
+     * 滤镜
+     */
+    fun setFilterName(name: String) {
+        mFaceBeauty?.filterName = name
+    }
+
+    /**
+     * 滤镜程度[0.0-1.0]
+     */
+    fun setFilterIntensity(value: Double) {
+        mFaceBeauty?.filterIntensity = value
+    }
+
+
+    /*************************美颜参数获取和保存******************************/
+
+    val params = ArrayList<Double>()
+
+    fun saveBeautyParams(context: Context) {
+        var str = ""
+        params.forEach {
+            str = if (TextUtils.isEmpty(str)) {
+                "$it"
+            } else {
+                "$str,$it"
+            }
+        }
+        SpUtil.get("FuBeauty", context).saveData("params", str)
+    }
+
+
+    fun getBeautyParams(context: Context): ArrayList<Double> {
+        if (params.isNotEmpty()) {
+            return params
+        }
+        params.clear()
+        val str = SpUtil.get("FuBeauty", context).readString("params")
+
+        if (TextUtils.isEmpty(str)) {
+            BeautyConfig.defaultParams.forEach {
+                params.add(it)
+            }
+            return params
+        } else {
+            val strA = str.split(",")
+            if (strA.size != BeautyConfig.defaultParams.size) {
+                BeautyConfig.defaultParams.forEach {
+                    params.add(it)
+                }
+                return params
+            }
+            strA.forEach {
+                if (!TextUtils.isEmpty(it)) {
+                    params.add(it.toDouble())
+                }
+            }
+            return params
+        }
+    }
+
+    /**
+     * 设置美颜参数
+     */
+    fun setDefaultBeautyParams(context: Context) {
+        val params = getBeautyParams(context)
+        params.forEachIndexed { index, d ->
+            setBeauty(index, d)
+        }
+    }
+
+
+}

+ 210 - 0
lib_beauty/src/main/java/com/swago/lib_beauty/IFURenderer.java

@@ -0,0 +1,210 @@
+package com.swago.lib_beauty;
+
+
+import com.faceunity.core.enumeration.CameraFacingEnum;
+import com.faceunity.core.enumeration.FUExternalInputEnum;
+import com.faceunity.core.enumeration.FUInputBufferEnum;
+import com.faceunity.core.enumeration.FUInputTextureEnum;
+import com.faceunity.core.enumeration.FUTransformMatrixEnum;
+
+/**
+ * DESC:
+ * Created on 2021/4/26
+ */
+abstract class IFURenderer {
+
+    /**
+     * 渲染属性
+     */
+    protected FUExternalInputEnum externalInputType = FUExternalInputEnum.EXTERNAL_INPUT_TYPE_CAMERA;//数据源类型
+    protected FUInputTextureEnum inputTextureType = FUInputTextureEnum.FU_ADM_FLAG_EXTERNAL_OES_TEXTURE;//纹理类型
+    protected FUInputBufferEnum inputBufferType = FUInputBufferEnum.FU_FORMAT_NV21_BUFFER;//数据类型
+    protected int inputOrientation = 0;//数据源朝向
+    protected int deviceOrientation = 90;//手机设备朝向
+    protected CameraFacingEnum cameraFacing = CameraFacingEnum.CAMERA_FRONT;  //数据源为相机时候->前后置相机
+    protected FUTransformMatrixEnum inputTextureMatrix = FUTransformMatrixEnum.CCROT0_FLIPVERTICAL;//纹理旋转类型
+    protected FUTransformMatrixEnum inputBufferMatrix = FUTransformMatrixEnum.CCROT0_FLIPVERTICAL;//图象旋转类型
+    protected FUTransformMatrixEnum outputMatrix = FUTransformMatrixEnum.CCROT0;//图象旋转类型
+
+
+    /**
+     * 资源释放
+     */
+    public abstract void release();
+
+
+    /**
+     * 双输入接口,输入 buffer 和 texture,必须在具有 GL 环境的线程调用
+     * 由于省去数据拷贝,性能相对最优,优先推荐使用。
+     * 缺点是无法保证 buffer 和纹理对齐,可能出现点位和效果对不上的情况。
+     *
+     * @param img    NV21 buffer
+     * @param texId  纹理 ID
+     * @param width  宽
+     * @param height 高
+     * @return
+     */
+    public abstract int onDrawFrameDualInput(byte[] img, int texId, int width, int height);
+
+    /**
+     * 获取输入源类型
+     *
+     * @return
+     */
+    public FUExternalInputEnum getExternalInputType() {
+        return externalInputType;
+    }
+
+    /**
+     * 设置输入源类型
+     *
+     * @param externalInputType
+     */
+    public void setExternalInputType(FUExternalInputEnum externalInputType) {
+        this.externalInputType = externalInputType;
+    }
+
+    /**
+     * 获取输入纹理类型
+     *
+     * @return
+     */
+    public FUInputTextureEnum getInputTextureType() {
+        return inputTextureType;
+    }
+
+    /**
+     * 设置输入纹理类型
+     *
+     * @param inputTextureType
+     */
+    public void setInputTextureType(FUInputTextureEnum inputTextureType) {
+        this.inputTextureType = inputTextureType;
+    }
+
+    /**
+     * 获取输入Buffer类型
+     *
+     * @return
+     */
+    public FUInputBufferEnum getInputBufferType() {
+        return inputBufferType;
+    }
+
+    /**
+     * 设置输入Buffer类型
+     *
+     * @param inputBufferType
+     */
+    public void setInputBufferType(FUInputBufferEnum inputBufferType) {
+        this.inputBufferType = inputBufferType;
+    }
+
+    /**
+     * 获取输入数据朝向
+     *
+     * @return
+     */
+    public int getInputOrientation() {
+        return inputOrientation;
+    }
+
+    /**
+     * 设置输入数据朝向
+     *
+     * @param inputOrientation
+     */
+    public void setInputOrientation(int inputOrientation) {
+        this.inputOrientation = inputOrientation;
+    }
+
+    /**
+     * 获取设备类型
+     *
+     * @return
+     */
+    public int getDeviceOrientation() {
+        return deviceOrientation;
+    }
+
+    /**
+     * 设置设备类型
+     *
+     * @param deviceOrientation
+     */
+    public void setDeviceOrientation(int deviceOrientation) {
+        this.deviceOrientation = deviceOrientation;
+    }
+
+    /**
+     * 获取设备朝向
+     *
+     * @return
+     */
+    public CameraFacingEnum getCameraFacing() {
+        return cameraFacing;
+    }
+
+    /**
+     * 设置设备朝向
+     *
+     * @param cameraFacing
+     */
+    public void setCameraFacing(CameraFacingEnum cameraFacing) {
+        this.cameraFacing = cameraFacing;
+    }
+
+    /**
+     * 获取输入纹理旋转类型
+     *
+     * @return
+     */
+    public FUTransformMatrixEnum getInputTextureMatrix() {
+        return inputTextureMatrix;
+    }
+
+    /**
+     * 设置输入纹理旋转类型
+     *
+     * @param inputTextureMatrix
+     */
+    public void setInputTextureMatrix(FUTransformMatrixEnum inputTextureMatrix) {
+        this.inputTextureMatrix = inputTextureMatrix;
+    }
+
+    /**
+     * 获取输入数据旋转类型
+     *
+     * @return
+     */
+    public FUTransformMatrixEnum getInputBufferMatrix() {
+        return inputBufferMatrix;
+    }
+
+    /**
+     * 设置输入数据旋转类型
+     *
+     * @param inputBufferMatrix
+     */
+    public void setInputBufferMatrix(FUTransformMatrixEnum inputBufferMatrix) {
+        this.inputBufferMatrix = inputBufferMatrix;
+    }
+
+    /**
+     * 获取输出数据旋转类型
+     *
+     * @return
+     */
+    public FUTransformMatrixEnum getOutputMatrix() {
+        return outputMatrix;
+    }
+
+    /**
+     * 设置输出数据旋转类型
+     *
+     * @param outputMatrix
+     */
+    public void setOutputMatrix(FUTransformMatrixEnum outputMatrix) {
+        this.outputMatrix = outputMatrix;
+    }
+}

+ 10 - 0
lib_beauty/src/main/java/com/swago/lib_beauty/IOperateCallback.kt

@@ -0,0 +1,10 @@
+package com.swago.lib_beauty;
+
+/**
+ *@date 2021/8/11 21:54
+ *description:
+ */
+interface IOperateCallback {
+    fun onFail(errCode: Int, errMsg: String)
+    fun onSuccess(code: Int, msg: String)
+}

+ 477 - 0
lib_beauty/src/main/java/com/swago/lib_beauty/SpUtil.java

@@ -0,0 +1,477 @@
+package com.swago.lib_beauty;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.os.Parcelable;
+
+import androidx.collection.SimpleArrayMap;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * SharedPreferences工具类,支持更具不同name获取不同的sp
+ */
+public class SpUtil implements CacheInterface {
+    private SharedPreferences shref = null;
+    private String shrefName = null;
+    private String shrefDir = null;
+
+    private static SimpleArrayMap<String, SpUtil> SP_MAP = new SimpleArrayMap<>();
+
+    public static CacheInterface get(String spName,Context context) {
+        SpUtil sharefUtil = SP_MAP.get(spName);
+        if (sharefUtil == null) {
+            synchronized (SpUtil.class) {
+                sharefUtil = new SpUtil(spName,context);
+                SP_MAP.put(spName, sharefUtil);
+            }
+        }
+        return sharefUtil;
+    }
+
+    public static CacheInterface get(String spName, int mode,Context context) {
+        SpUtil sharefUtil = SP_MAP.get(spName);
+        if (sharefUtil == null) {
+            synchronized (SpUtil.class) {
+                sharefUtil = new SpUtil(spName, mode,context);
+                SP_MAP.put(spName, sharefUtil);
+            }
+        }
+        return sharefUtil;
+    }
+
+    private SpUtil(Context context) {
+        this("default_sharedpreferences",context);
+    }
+
+    private SpUtil(String shrefName, Context context) {
+        this(shrefName, Context.MODE_PRIVATE,context);
+    }
+
+    private SpUtil(String shrefName, int mode, Context context) {
+        this.shrefName = shrefName;
+        this.shref = context.getSharedPreferences(shrefName, mode);
+        shrefDir = getCacheDir(context);
+    }
+
+    /**
+     * 获取SharedPreferences文件的目录路径
+     *
+     * @param context
+     * @return
+     */
+    private String getCacheDir(Context context) {
+        return File.separator + "data" + File.separator + "data" + File.separator + context.getPackageName()
+                + File.separator + "shared_prefs";
+    }
+
+    /**
+     * 判断sp文件是否存在¬
+     *
+     * @return
+     */
+    @Override
+    public boolean isCacheFileExists() {
+        File file = new File(shrefDir, shrefName + ".xml");
+        if (file != null) {
+            return file.exists();
+        }
+        return false;
+    }
+
+    /**
+     * 获取配置文件上次修改时间
+     *
+     * @return
+     */
+    @Override
+    public final long lastModified() {
+        File file = new File(shrefDir, shrefName + ".xml");
+        if (file != null && file.exists()) {
+            return file.lastModified();
+        }
+        return 0;
+    }
+
+    /**
+     * SP中写入string
+     *
+     * @param key
+     * @param value
+     */
+    @Override
+    public final void saveData(String key, String value) {
+        saveData(key, value, false);
+    }
+
+    /**
+     * SP中写入string
+     *
+     * @param key
+     * @param value
+     * @param commit
+     */
+    @Override
+    public final void saveData(String key, String value, boolean commit) {
+        Editor editor = shref.edit();
+        editor.putString(key, value);
+        if (commit) {
+            editor.commit();
+        } else {
+            editor.apply();
+        }
+    }
+
+    /**
+     * SP中写入int
+     *
+     * @param key
+     * @param value
+     */
+    @Override
+    public final void saveData(String key, int value) {
+        saveData(key, value, false);
+    }
+
+    /**
+     * SP中写入int
+     *
+     * @param key
+     * @param value
+     * @param commit
+     */
+    @Override
+    public final void saveData(String key, int value, boolean commit) {
+        Editor editor = shref.edit();
+        editor.putInt(key, value);
+        if (commit) {
+            editor.commit();
+        } else {
+            editor.apply();
+        }
+    }
+
+    /**
+     * SP中写入boolean
+     *
+     * @param key
+     * @param value
+     */
+    @Override
+    public final void saveData(String key, boolean value) {
+        saveData(key, value, false);
+    }
+
+    /**
+     * SP中写入boolean
+     *
+     * @param key
+     * @param value
+     * @param commit
+     */
+    @Override
+    public final void saveData(String key, boolean value, boolean commit) {
+        Editor editor = shref.edit();
+        editor.putBoolean(key, value);
+        if (commit) {
+            editor.commit();
+        } else {
+            editor.apply();
+        }
+    }
+
+    /**
+     * SP中写入long
+     *
+     * @param key
+     * @param value
+     */
+    @Override
+    public final void saveData(String key, long value) {
+        saveData(key, value, false);
+    }
+
+    /**
+     * SP中写入long
+     *
+     * @param key
+     * @param value
+     * @param commit
+     */
+    @Override
+    public final void saveData(String key, long value, boolean commit) {
+        Editor editor = shref.edit();
+        editor.putLong(key, value);
+        if (commit) {
+            editor.commit();
+        } else {
+            editor.apply();
+        }
+    }
+
+    /**
+     * SP中写入float
+     *
+     * @param key
+     * @param value
+     */
+    @Override
+    public final void saveData(String key, float value) {
+        saveData(key, value, false);
+    }
+
+    /**
+     * SP中写入float
+     *
+     * @param key
+     * @param value
+     * @param commit
+     */
+    @Override
+    public final void saveData(String key, float value, boolean commit) {
+        Editor editor = shref.edit();
+        editor.putFloat(key, value);
+        if (commit) {
+            editor.commit();
+        } else {
+            editor.apply();
+        }
+    }
+
+    /**
+     * SP中写入set<string>
+     *
+     * @param key
+     * @param value
+     */
+    @Override
+    public final void saveData(String key, Set<String> value) {
+        saveData(key, value, false);
+    }
+
+    /**
+     * SP中写入set<string>
+     *
+     * @param key
+     * @param value
+     */
+    @Override
+    public final void saveData(String key, Set<String> value, boolean commit) {
+        Editor editor = shref.edit();
+        editor.putStringSet(key, value);
+        if (commit) {
+            editor.commit();
+        } else {
+            editor.apply();
+        }
+    }
+
+    @Override
+    public void saveData(String key, Parcelable parcelable) {
+        throw new UnsupportedOperationException("sp not support this method");
+    }
+
+    /**
+     * SP中读取string
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    public final String readString(String key) {
+        return readString(key, null);
+    }
+
+    /**
+     * SP中读取string
+     *
+     * @param key
+     * @param defaultValue
+     * @return
+     */
+    @Override
+    public final String readString(String key, String defaultValue) {
+        return shref.getString(key, defaultValue);
+    }
+
+    /**
+     * SP中读取int
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    public final int readInt(String key) {
+        return readInt(key, 0);
+    }
+
+    /**
+     * SP中读取int
+     *
+     * @param key
+     * @param defalValue
+     * @return
+     */
+    @Override
+    public final int readInt(String key, int defalValue) {
+        return shref.getInt(key, defalValue);
+    }
+
+    /**
+     * SP中读取boolean
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    public final boolean readBoolean(String key) {
+        return readBoolean(key, false);
+    }
+
+    /**
+     * SP中读取boolean
+     *
+     * @param key
+     * @param defaultValue
+     * @return
+     */
+    @Override
+    public final boolean readBoolean(String key, boolean defaultValue) {
+        return shref.getBoolean(key, defaultValue);
+    }
+
+    /**
+     * SP中读取long
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    public final long readLong(String key) {
+        return readLong(key, 0);
+    }
+
+    /**
+     * SP中读取long
+     *
+     * @param key
+     * @param defaultValue
+     * @return
+     */
+    @Override
+    public final long readLong(String key, long defaultValue) {
+        return shref.getLong(key, defaultValue);
+    }
+
+    /**
+     * SP中读取float
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    public final float readFloat(String key) {
+        return readFloat(key, 0);
+    }
+
+    /**
+     * SP中读取float
+     *
+     * @param key
+     * @param defaultValue
+     * @return
+     */
+    @Override
+    public final float readFloat(String key, float defaultValue) {
+        return shref.getFloat(key, defaultValue);
+    }
+
+    /**
+     * SP中读取set<string>
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    public final HashSet<String> readSetString(String key) {
+        return new HashSet<String>(shref.getStringSet(key, new HashSet<String>()));
+    }
+
+    /**
+     * SP中读取set<string>
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    public final HashSet<String> readSetString(String key, Set<String> defaultValue) {
+        return new HashSet<String>(shref.getStringSet(key, defaultValue));
+    }
+
+    @Override
+    public <T extends Parcelable> T readParcelable(String key, Class<T> tClass) {
+        throw new UnsupportedOperationException("sp not support this method");
+    }
+
+
+
+    /**
+     * SP中是否包含指定的key
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    public final boolean contains(String key) {
+        return shref.contains(key);
+    }
+
+    /**
+     * SP中移除指定的key
+     *
+     * @param key
+     */
+    @Override
+    public final void remove(String key) {
+        remove(key, false);
+    }
+
+    /**
+     * SP中移除指定的key
+     *
+     * @param key
+     * @param commit
+     */
+    @Override
+    public final void remove(String key, boolean commit) {
+        Editor editor = shref.edit();
+        editor.remove(key);
+        if (commit) {
+            editor.commit();
+        } else {
+            editor.apply();
+        }
+    }
+
+    /**
+     * 清除sp中的数据
+     */
+    @Override
+    public final void clear() {
+        Editor editor = shref.edit();
+        editor.clear();
+        editor.apply();
+    }
+
+    @Override
+    public void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener, boolean regist) {
+        if (regist) {
+            shref.registerOnSharedPreferenceChangeListener(listener);
+        } else {
+            shref.unregisterOnSharedPreferenceChangeListener(listener);
+        }
+    }
+}