|
|
@@ -5,8 +5,6 @@ package com.baidu.idl.face.platform.ui;
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
-import android.graphics.Bitmap;
|
|
|
-import android.graphics.BitmapFactory;
|
|
|
import android.graphics.PixelFormat;
|
|
|
import android.graphics.Point;
|
|
|
import android.graphics.Rect;
|
|
|
@@ -20,12 +18,8 @@ import android.view.Gravity;
|
|
|
import android.view.Surface;
|
|
|
import android.view.SurfaceHolder;
|
|
|
import android.view.SurfaceView;
|
|
|
-import android.view.View;
|
|
|
import android.view.WindowManager;
|
|
|
import android.widget.FrameLayout;
|
|
|
-import android.widget.ImageView;
|
|
|
-import android.widget.LinearLayout;
|
|
|
-import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.baidu.aip.face.stat.Ast;
|
|
|
@@ -38,9 +32,7 @@ import com.baidu.idl.face.platform.ui.utils.CameraUtils;
|
|
|
import com.baidu.idl.face.platform.ui.utils.VolumeUtils;
|
|
|
import com.baidu.idl.face.platform.ui.widget.FaceDetectRoundView;
|
|
|
import com.baidu.idl.face.platform.utils.APIUtils;
|
|
|
-import com.baidu.idl.face.platform.utils.Base64Utils;
|
|
|
import com.baidu.idl.face.platform.utils.CameraPreviewUtils;
|
|
|
-import com.common.LogUtil;
|
|
|
import com.modular.apputils.activity.BaseNetActivity;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
@@ -59,17 +51,13 @@ public abstract class FaceDetectActivity extends BaseNetActivity implements
|
|
|
|
|
|
|
|
|
// View
|
|
|
- protected View mRootView;
|
|
|
protected FrameLayout mFrameLayout;
|
|
|
protected SurfaceView mSurfaceView;
|
|
|
protected SurfaceHolder mSurfaceHolder;
|
|
|
- protected ImageView mCloseView;
|
|
|
- protected ImageView mSoundView;
|
|
|
- protected ImageView mSuccessView;
|
|
|
protected TextView mTipsTopView;
|
|
|
- protected TextView mTipsBottomView;
|
|
|
protected FaceDetectRoundView mFaceDetectRoundView;
|
|
|
- protected LinearLayout mImageLayout;
|
|
|
+
|
|
|
+
|
|
|
// 人脸信息
|
|
|
protected FaceConfig mFaceConfig;
|
|
|
protected IDetectStrategy mIDetectStrategy;
|
|
|
@@ -97,13 +85,16 @@ public abstract class FaceDetectActivity extends BaseNetActivity implements
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
- return R.layout.activity_face_detect_v3100;
|
|
|
+ return R.layout.activity_face_verifty;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected void init() throws Exception {
|
|
|
+ public void preOnCreacte() {
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
Ast.getInstance().init(getApplicationContext(), "3.1.0.0", "facenormal");
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected void init() throws Exception {
|
|
|
DisplayMetrics dm = new DisplayMetrics();
|
|
|
Display display = this.getWindowManager().getDefaultDisplay();
|
|
|
display.getMetrics(dm);
|
|
|
@@ -116,8 +107,10 @@ public abstract class FaceDetectActivity extends BaseNetActivity implements
|
|
|
int vol = am.getStreamVolume(AudioManager.STREAM_MUSIC);
|
|
|
mIsEnableSound = vol > 0 ? mFaceConfig.isSound : false;
|
|
|
|
|
|
- mRootView = this.findViewById(R.id.detect_root_layout);
|
|
|
- mFrameLayout = (FrameLayout) mRootView.findViewById(R.id.detect_surface_layout);
|
|
|
+ mFrameLayout =findViewById(R.id.liveness_surface_layout);
|
|
|
+ mFaceDetectRoundView = findViewById(R.id.liveness_face_round);
|
|
|
+ mTipsTopView = findViewById(R.id.liveness_top_tips);
|
|
|
+
|
|
|
|
|
|
mSurfaceView = new SurfaceView(this);
|
|
|
mSurfaceHolder = mSurfaceView.getHolder();
|
|
|
@@ -135,33 +128,6 @@ public abstract class FaceDetectActivity extends BaseNetActivity implements
|
|
|
mSurfaceView.setLayoutParams(cameraFL);
|
|
|
mFrameLayout.addView(mSurfaceView);
|
|
|
|
|
|
- mRootView.findViewById(R.id.detect_close).setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- onBackPressed();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- mFaceDetectRoundView = (FaceDetectRoundView) mRootView.findViewById(R.id.detect_face_round);
|
|
|
- mCloseView = (ImageView) mRootView.findViewById(R.id.detect_close);
|
|
|
- mSoundView = (ImageView) mRootView.findViewById(R.id.detect_sound);
|
|
|
- mSoundView.setImageResource(mIsEnableSound ?
|
|
|
- R.mipmap.ic_enable_sound_ext : R.mipmap.ic_disable_sound_ext);
|
|
|
- mSoundView.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- mIsEnableSound = !mIsEnableSound;
|
|
|
- mSoundView.setImageResource(mIsEnableSound ?
|
|
|
- R.mipmap.ic_enable_sound_ext : R.mipmap.ic_disable_sound_ext);
|
|
|
- if (mIDetectStrategy != null) {
|
|
|
- mIDetectStrategy.setDetectStrategySoundEnable(mIsEnableSound);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- mTipsTopView = (TextView) mRootView.findViewById(R.id.detect_top_tips);
|
|
|
- mTipsBottomView = (TextView) mRootView.findViewById(R.id.detect_bottom_tips);
|
|
|
- mSuccessView = (ImageView) mRootView.findViewById(R.id.detect_success_image);
|
|
|
- mImageLayout = (LinearLayout) mRootView.findViewById(R.id.detect_result_image_layout);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -198,16 +164,15 @@ public abstract class FaceDetectActivity extends BaseNetActivity implements
|
|
|
@Override
|
|
|
public void volumeChanged() {
|
|
|
try {
|
|
|
- AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
|
|
|
- if (am != null) {
|
|
|
- int cv = am.getStreamVolume(AudioManager.STREAM_MUSIC);
|
|
|
- mIsEnableSound = cv > 0;
|
|
|
- mSoundView.setImageResource(mIsEnableSound
|
|
|
- ? R.mipmap.ic_enable_sound_ext : R.mipmap.ic_disable_sound_ext);
|
|
|
- if (mIDetectStrategy != null) {
|
|
|
- mIDetectStrategy.setDetectStrategySoundEnable(mIsEnableSound);
|
|
|
- }
|
|
|
- }
|
|
|
+// AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
|
|
|
+// if (am != null) {
|
|
|
+// int cv = am.getStreamVolume(AudioManager.STREAM_MUSIC);
|
|
|
+// mIsEnableSound = cv > 0;
|
|
|
+//
|
|
|
+// if (mIDetectStrategy != null) {
|
|
|
+// mIDetectStrategy.setDetectStrategySoundEnable(mIsEnableSound);
|
|
|
+// }
|
|
|
+// }
|
|
|
} catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
@@ -388,26 +353,21 @@ public abstract class FaceDetectActivity extends BaseNetActivity implements
|
|
|
if (mIsCompletion) {
|
|
|
return;
|
|
|
}
|
|
|
- initIDetectStrategy();
|
|
|
- if (mIDetectStrategy != null) {
|
|
|
- mIDetectStrategy.detectStrategy(data);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void initIDetectStrategy() {
|
|
|
- if (mIDetectStrategy == null) {
|
|
|
+ if (mIDetectStrategy == null && mFaceDetectRoundView != null && mFaceDetectRoundView.getRound() > 0) {
|
|
|
mIDetectStrategy = FaceSDKManager.getInstance().getDetectStrategyModule();
|
|
|
- } else {
|
|
|
- mIDetectStrategy.reset();
|
|
|
- }
|
|
|
- if (mFaceDetectRoundView != null && mFaceDetectRoundView.getRound() > 0) {
|
|
|
mIDetectStrategy.setPreviewDegree(mPreviewDegree);
|
|
|
mIDetectStrategy.setDetectStrategySoundEnable(mIsEnableSound);
|
|
|
+
|
|
|
Rect detectRect = FaceDetectRoundView.getPreviewDetectRect(mDisplayWidth, mPreviewHight, mPreviewWidth);
|
|
|
mIDetectStrategy.setDetectStrategyConfig(mPreviewRect, detectRect, this);
|
|
|
}
|
|
|
+ if (mIDetectStrategy != null) {
|
|
|
+ mIDetectStrategy.detectStrategy(data);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void onError(int error, Camera camera) {
|
|
|
}
|
|
|
@@ -415,7 +375,6 @@ public abstract class FaceDetectActivity extends BaseNetActivity implements
|
|
|
@Override
|
|
|
public void onDetectCompletion(FaceStatusEnum status, String message,
|
|
|
HashMap<String, String> base64ImageMap) {
|
|
|
- LogUtil.i("gong", "onDetectCompletion=" + message);
|
|
|
if (mIsCompletion) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -430,66 +389,54 @@ public abstract class FaceDetectActivity extends BaseNetActivity implements
|
|
|
private void onRefreshView(FaceStatusEnum status, String message) {
|
|
|
switch (status) {
|
|
|
case OK:
|
|
|
+ case Liveness_Completion:
|
|
|
onRefreshTipsView(false, message);
|
|
|
- mTipsBottomView.setText("");
|
|
|
- mFaceDetectRoundView.processDrawState(false);
|
|
|
- onRefreshSuccessView(true);
|
|
|
+ mFaceDetectRoundView.onRefreshSuccessView(true);
|
|
|
break;
|
|
|
case Detect_PitchOutOfUpMaxRange:
|
|
|
case Detect_PitchOutOfDownMaxRange:
|
|
|
case Detect_PitchOutOfLeftMaxRange:
|
|
|
case Detect_PitchOutOfRightMaxRange:
|
|
|
- onRefreshTipsView(true, message);
|
|
|
- mTipsBottomView.setText(message);
|
|
|
- mFaceDetectRoundView.processDrawState(true);
|
|
|
- onRefreshSuccessView(false);
|
|
|
+ onRefreshTipsView(false, message);
|
|
|
+ mFaceDetectRoundView.onRefreshSuccessView(false);
|
|
|
+ break;
|
|
|
+ case Error_LivenessTimeout:
|
|
|
+ case Error_Timeout:
|
|
|
+ case Error_DetectTimeout:
|
|
|
+ errorTimeOut();
|
|
|
+ onRefreshTipsView(false, message);
|
|
|
break;
|
|
|
default:
|
|
|
onRefreshTipsView(false, message);
|
|
|
- mTipsBottomView.setText("");
|
|
|
- mFaceDetectRoundView.processDrawState(true);
|
|
|
- onRefreshSuccessView(false);
|
|
|
+ mFaceDetectRoundView.onRefreshSuccessView(false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void onRefreshTipsView(boolean isAlert, String message) {
|
|
|
- if (isAlert) {
|
|
|
- if (mTipsIcon == null) {
|
|
|
- mTipsIcon = getResources().getDrawable(R.mipmap.ic_warning);
|
|
|
- mTipsIcon.setBounds(0, 0, (int) (mTipsIcon.getMinimumWidth() * 0.7f),
|
|
|
- (int) (mTipsIcon.getMinimumHeight() * 0.7f));
|
|
|
- mTipsTopView.setCompoundDrawablePadding(15);
|
|
|
- }
|
|
|
- mTipsTopView.setBackgroundResource(R.drawable.bg_tips);
|
|
|
- mTipsTopView.setText(R.string.detect_standard);
|
|
|
- mTipsTopView.setCompoundDrawables(mTipsIcon, null, null, null);
|
|
|
- } else {
|
|
|
- mTipsTopView.setBackgroundResource(R.drawable.bg_tips_no);
|
|
|
- mTipsTopView.setCompoundDrawables(null, null, null, null);
|
|
|
- if (!TextUtils.isEmpty(message)) {
|
|
|
- mTipsTopView.setText(message);
|
|
|
- }
|
|
|
- }
|
|
|
+ mFaceDetectRoundView.onRefreshTipsView(message);
|
|
|
+// if (isAlert) {
|
|
|
+// if (mTipsIcon == null) {
|
|
|
+// mTipsIcon = getResources().getDrawable(R.mipmap.ic_warning);
|
|
|
+// mTipsIcon.setBounds(0, 0, (int) (mTipsIcon.getMinimumWidth() * 0.7f),
|
|
|
+// (int) (mTipsIcon.getMinimumHeight() * 0.7f));
|
|
|
+// mTipsTopView.setCompoundDrawablePadding(15);
|
|
|
+// }
|
|
|
+// mTipsTopView.setBackgroundResource(R.drawable.bg_tips);
|
|
|
+// mTipsTopView.setText(R.string.detect_standard);
|
|
|
+// mTipsTopView.setCompoundDrawables(mTipsIcon, null, null, null);
|
|
|
+// } else {
|
|
|
+// mTipsTopView.setBackgroundResource(R.drawable.bg_tips_no);
|
|
|
+// mTipsTopView.setCompoundDrawables(null, null, null, null);
|
|
|
+// if (!TextUtils.isEmpty(message)) {
|
|
|
+// mTipsTopView.setText(message);
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
- private void onRefreshSuccessView(boolean isShow) {
|
|
|
- if (mSuccessView.getTag() == null) {
|
|
|
- Rect rect = mFaceDetectRoundView.getFaceRoundRect();
|
|
|
- RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) mSuccessView.getLayoutParams();
|
|
|
- rlp.setMargins(
|
|
|
- rect.centerX() - (mSuccessView.getWidth() / 2),
|
|
|
- rect.top - (mSuccessView.getHeight() / 2),
|
|
|
- 0,
|
|
|
- 0);
|
|
|
- mSuccessView.setLayoutParams(rlp);
|
|
|
- mSuccessView.setTag("setlayout");
|
|
|
- }
|
|
|
- mSuccessView.setVisibility(isShow ? View.VISIBLE : View.INVISIBLE);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
private void saveImage(HashMap<String, String> imageMap) {
|
|
|
Set<Map.Entry<String, String>> sets = imageMap.entrySet();
|
|
|
- mImageLayout.removeAllViews();
|
|
|
for (Map.Entry<String, String> entry : sets) {
|
|
|
String bmpBase64 = entry.getValue();
|
|
|
if (!TextUtils.isEmpty(bmpBase64)) {
|
|
|
@@ -499,22 +446,19 @@ public abstract class FaceDetectActivity extends BaseNetActivity implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static Bitmap base64ToBitmap(String base64Data) {
|
|
|
- byte[] bytes = Base64Utils.decode(base64Data, Base64Utils.NO_WRAP);
|
|
|
- return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 重新开启
|
|
|
*/
|
|
|
public void reSetDetect() {
|
|
|
- //TODO 重新验证
|
|
|
mIsCompletion = false;
|
|
|
- initIDetectStrategy();
|
|
|
+ mIDetectStrategy = null;
|
|
|
+ startPreview();
|
|
|
}
|
|
|
|
|
|
public abstract void saveBmpBase64Ok(String bmpBase64);
|
|
|
|
|
|
+ public abstract void errorTimeOut();
|
|
|
|
|
|
}
|
|
|
|