|
@@ -1,25 +1,150 @@
|
|
|
package com.sunwin.visitorapp.fragment;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.EditText;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
-import androidx.fragment.app.Fragment;
|
|
|
|
|
|
+import com.sunwin.visitorapp.BaseFragment;
|
|
|
import com.sunwin.visitorapp.R;
|
|
|
+import com.sunwin.visitorapp.face.FRImpl;
|
|
|
+import com.sunwin.visitorapp.net.RetrofitUtil;
|
|
|
+import com.sunwin.visitorapp.utils.Constant;
|
|
|
+import com.sunwin.visitorapp.utils.SharePrefenceUtils;
|
|
|
+import com.sunwin.visitorapp.utils.ToastUtils;
|
|
|
|
|
|
-public class SystemOptionFr extends Fragment {
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+
|
|
|
+import mcv.facepass.FacePassException;
|
|
|
+import mcv.facepass.FacePassHandler;
|
|
|
+import mcv.facepass.types.FacePassConfig;
|
|
|
+import okhttp3.HttpUrl;
|
|
|
+
|
|
|
+public class SystemOptionFr extends BaseFragment implements View.OnClickListener {
|
|
|
+
|
|
|
+ private EditText mEditTimeZone;
|
|
|
+ private EditText mEditIPAddress;
|
|
|
+ private EditText mEtCompareValue;
|
|
|
+ private EditText mEtIpServer;
|
|
|
+ private EditText mEtLivenessValue;
|
|
|
+ private EditText mEtIpPort;
|
|
|
+ private EditText mEtCompareNum;
|
|
|
+ private Button mTextButtonSure;
|
|
|
|
|
|
- private View root;
|
|
|
@Nullable
|
|
|
@Override
|
|
|
- public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
+ public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
|
|
|
+ View view = inflater.inflate(R.layout.fr_system_option, container, false);
|
|
|
+
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
|
|
|
+ super.onViewCreated(view, savedInstanceState);
|
|
|
+ initView(view);
|
|
|
+ initData();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initData() {
|
|
|
+ String serverUrl = SharePrefenceUtils.getString(Constant.ISharePrefence.BASEURL, Constant.BASE_HOST);
|
|
|
+
|
|
|
+ int lastIndex = serverUrl.lastIndexOf(":");
|
|
|
+ mEtIpServer.setText(serverUrl.substring(0, lastIndex));
|
|
|
+ mEtIpPort.setText(serverUrl.substring(lastIndex + 1, serverUrl.length() - 1));
|
|
|
+
|
|
|
+ mEtCompareValue.setText(Constant.COMPARSION_VALUE + "");
|
|
|
+ mEtLivenessValue.setText(Constant.LIVENESS_VALUE + "");
|
|
|
+ mEtCompareNum.setText(Constant.COMPARSION_FREQUENCY + "");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView(View view) {
|
|
|
+ mEditTimeZone = view.findViewById(R.id.EditTimeZone);
|
|
|
+ mEditIPAddress = view.findViewById(R.id.EditIPAddress);
|
|
|
+ mEtCompareValue = view.findViewById(R.id.et_compareValue);
|
|
|
+ mEtIpServer = view.findViewById(R.id.et_ipServer);
|
|
|
+ mEtLivenessValue = view.findViewById(R.id.et_livenessValue);
|
|
|
+ mEtIpPort = view.findViewById(R.id.et_ipPort);
|
|
|
+ mEtCompareNum = view.findViewById(R.id.et_compareNum);
|
|
|
+ mTextButtonSure = view.findViewById(R.id.TextButtonSure);
|
|
|
+ mTextButtonSure.setOnClickListener(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ submit();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void submit() {
|
|
|
+ String ipServer = mEtIpServer.getText().toString().trim();
|
|
|
+ String ipPort = mEtIpPort.getText().toString().trim();
|
|
|
+ String campareValue = mEtCompareValue.getText().toString().trim();
|
|
|
+ String livenessValue = mEtLivenessValue.getText().toString().trim();
|
|
|
+ String compareNum = mEtCompareNum.getText().toString().trim();
|
|
|
+ if (TextUtils.isEmpty(ipServer)) {
|
|
|
+ ToastUtils.showToast("服务器地址不能为空!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(ipPort)) {
|
|
|
+ ToastUtils.showToast("服务器端口不能为空!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(campareValue)) {
|
|
|
+ ToastUtils.showToast("比对阈值不能为空!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(livenessValue)) {
|
|
|
+ ToastUtils.showToast("活体阈值不能为空!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(compareNum)) {
|
|
|
+ ToastUtils.showToast("比对次数不能为空!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String address = ipServer + ":" + ipPort + "/";
|
|
|
+ boolean illegalUrl = isIllegalUrl(address);
|
|
|
+ if (!illegalUrl) {
|
|
|
+ ToastUtils.showToast("非法服务器路径,请重新输入!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SharePrefenceUtils.putString(Constant.ISharePrefence.BASEURL, address);
|
|
|
+ RetrofitUtil.initRetrofit();
|
|
|
+
|
|
|
+ //人脸比对参数
|
|
|
+ try {
|
|
|
+ FacePassHandler mFacePassHandler = FRImpl.getInstance().mFacePassHandler;
|
|
|
+
|
|
|
+ FacePassConfig config = mFacePassHandler.getConfig();
|
|
|
+ config.searchThreshold = Integer.parseInt(campareValue);
|
|
|
+ config.livenessThreshold = Integer.parseInt(livenessValue);
|
|
|
+ mFacePassHandler.setConfig(config);
|
|
|
+ } catch (FacePassException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ SharePrefenceUtils.putInt("comparsion_value", Integer.parseInt(campareValue));
|
|
|
+ SharePrefenceUtils.putInt("liveness_value", Integer.parseInt(campareValue));
|
|
|
+ SharePrefenceUtils.putInt("comparsion_frequency_value", Integer.parseInt(compareNum));
|
|
|
+
|
|
|
+ ToastUtils.showToast("保存成功!");
|
|
|
+ }
|
|
|
|
|
|
- if(root==null)root = inflater.inflate(R.layout.fr_system_option,container,false);
|
|
|
|
|
|
- return root;
|
|
|
+ /**
|
|
|
+ * 判断服务器地址是否合法
|
|
|
+ */
|
|
|
+ boolean isIllegalUrl(String url) {
|
|
|
+ HttpUrl httpUrl = HttpUrl.parse(url);
|
|
|
+ if (httpUrl == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|