Commit 905c2635 by 罗翻

增加人脸识别

parent 5b0d1c4f
...@@ -36,409 +36,453 @@ import java.util.UUID; ...@@ -36,409 +36,453 @@ import java.util.UUID;
public class ConUtil { public class ConUtil {
/** /**
* 根据byte数组,生成文件 * 根据byte数组,生成文件
*/ */
public static String saveJPGFile(Context mContext, byte[] data, String key) { public static String saveJPGFile(Context mContext, byte[] data, String key) {
if (data == null) if (data == null)
return null; return null;
File mediaStorageDir = mContext.getExternalFilesDir(Constant.cacheImage); File mediaStorageDir = mContext.getExternalFilesDir(Constant.cacheImage);
if (!mediaStorageDir.exists()) { if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) { if (!mediaStorageDir.mkdirs()) {
return null; return null;
} }
} }
BufferedOutputStream bos = null; BufferedOutputStream bos = null;
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
String jpgFileName = System.currentTimeMillis() + "" + new Random().nextInt(1000000) + "_" + key + ".jpg"; String jpgFileName = System.currentTimeMillis() + "" + new Random().nextInt(1000000) + "_" + key + ".jpg";
fos = new FileOutputStream(mediaStorageDir + "/" + jpgFileName); fos = new FileOutputStream(mediaStorageDir + "/" + jpgFileName);
bos = new BufferedOutputStream(fos); bos = new BufferedOutputStream(fos);
bos.write(data); bos.write(data);
return mediaStorageDir.getAbsolutePath() + "/" + jpgFileName; return mediaStorageDir.getAbsolutePath() + "/" + jpgFileName;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (bos != null) { if (bos != null) {
try { try {
bos.close(); bos.close();
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
} }
if (fos != null) { if (fos != null) {
try { try {
fos.close(); fos.close();
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
} }
} }
return null; return null;
} }
public static void copyModels(Context context) {
File dstModelFile = new File(context.getExternalFilesDir(null), "model"); /**
if (dstModelFile.exists()) { * 根据byte数组,生成文件
return; */
} public static File saveJPG(Context mContext, byte[] data, String key) {
if (data == null)
try { return null;
String tmpFile = "model";
BufferedInputStream inputStream = new BufferedInputStream(context.getAssets().open(tmpFile)); File mediaStorageDir = mContext.getExternalFilesDir(Constant.cacheImage);
BufferedOutputStream foutputStream = new BufferedOutputStream(new FileOutputStream(dstModelFile));
if (!mediaStorageDir.exists()) {
byte[] buffer = new byte[1024]; if (!mediaStorageDir.mkdirs()) {
int readcount = -1; return null;
while ((readcount = inputStream.read(buffer)) != -1) { }
foutputStream.write(buffer, 0, readcount); }
}
foutputStream.close(); BufferedOutputStream bos = null;
inputStream.close(); FileOutputStream fos = null;
} catch (IOException e) { try {
e.printStackTrace(); String jpgFileName = System.currentTimeMillis() + "" + new Random().nextInt(1000000) + "_" + key + ".jpg";
} fos = new FileOutputStream(mediaStorageDir + "/" + jpgFileName);
} bos = new BufferedOutputStream(fos);
bos.write(data);
public static byte[] readModel(Context context) { return mediaStorageDir;
InputStream inputStream = null; } catch (Exception e) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); e.printStackTrace();
byte[] buffer = new byte[1024]; } finally {
int count = -1; if (bos != null) {
try { try {
inputStream = context.getResources().openRawResource(R.raw.livenessmodel); bos.close();
while ((count = inputStream.read(buffer)) != -1) { } catch (IOException e1) {
byteArrayOutputStream.write(buffer, 0, count); e1.printStackTrace();
} }
byteArrayOutputStream.close(); }
} catch (IOException e) { if (fos != null) {
e.printStackTrace(); try {
} finally { fos.close();
if (inputStream != null) { } catch (IOException e1) {
try { e1.printStackTrace();
inputStream.close(); }
} catch (IOException e) { }
e.printStackTrace(); }
} return null;
} }
}
return byteArrayOutputStream.toByteArray(); public static void copyModels(Context context) {
} File dstModelFile = new File(context.getExternalFilesDir(null), "model");
if (dstModelFile.exists()) {
public static String getUUIDString(Context mContext) { return;
String KEY_UUID = "key_uuid"; }
SharedUtil sharedUtil = new SharedUtil(mContext);
String uuid = sharedUtil.getStringValueByKey(KEY_UUID); try {
if (uuid != null && uuid.trim().length() != 0) String tmpFile = "model";
return uuid; BufferedInputStream inputStream = new BufferedInputStream(context.getAssets().open(tmpFile));
BufferedOutputStream foutputStream = new BufferedOutputStream(new FileOutputStream(dstModelFile));
uuid = UUID.randomUUID().toString();
uuid = Base64.encodeToString(uuid.getBytes(), Base64.DEFAULT); byte[] buffer = new byte[1024];
sharedUtil.saveStringValue(KEY_UUID, uuid); int readcount = -1;
return uuid; while ((readcount = inputStream.read(buffer)) != -1) {
} foutputStream.write(buffer, 0, readcount);
}
public static String getPhoneNumber(Context mContext) { foutputStream.close();
TelephonyManager phoneMgr = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); inputStream.close();
return phoneMgr.getLine1Number(); } catch (IOException e) {
} e.printStackTrace();
}
public static String getDeviceID(Context mContext) { }
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
return tm.getDeviceId(); public static byte[] readModel(Context context) {
} InputStream inputStream = null;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
public static String getMacAddress(Context mContext) { byte[] buffer = new byte[1024];
WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); int count = -1;
WifiInfo info = wifi.getConnectionInfo(); try {
String address = info.getMacAddress(); inputStream = context.getResources().openRawResource(R.raw.livenessmodel);
if (address != null && address.length() > 0) { while ((count = inputStream.read(buffer)) != -1) {
address = address.replace(":", ""); byteArrayOutputStream.write(buffer, 0, count);
} }
return address; byteArrayOutputStream.close();
} } catch (IOException e) {
e.printStackTrace();
/** } finally {
* 获取bitmap的灰度图像 if (inputStream != null) {
*/ try {
public static byte[] getGrayscale(Bitmap bitmap) { inputStream.close();
if (bitmap == null) } catch (IOException e) {
return null; e.printStackTrace();
}
byte[] ret = new byte[bitmap.getWidth() * bitmap.getHeight()]; }
for (int j = 0; j < bitmap.getHeight(); ++j) }
for (int i = 0; i < bitmap.getWidth(); ++i) { return byteArrayOutputStream.toByteArray();
int pixel = bitmap.getPixel(i, j); }
int red = ((pixel & 0x00FF0000) >> 16);
int green = ((pixel & 0x0000FF00) >> 8); public static String getUUIDString(Context mContext) {
int blue = pixel & 0x000000FF; String KEY_UUID = "key_uuid";
ret[j * bitmap.getWidth() + i] = (byte) ((299 * red + 587 * green + 114 * blue) / 1000); SharedUtil sharedUtil = new SharedUtil(mContext);
} String uuid = sharedUtil.getStringValueByKey(KEY_UUID);
return ret; if (uuid != null && uuid.trim().length() != 0)
} return uuid;
/** uuid = UUID.randomUUID().toString();
* 读取图片属性:旋转的角度 uuid = Base64.encodeToString(uuid.getBytes(), Base64.DEFAULT);
* sharedUtil.saveStringValue(KEY_UUID, uuid);
* @param path return uuid;
* 图片绝对路径 }
* @return degree旋转的角度
*/ public static String getPhoneNumber(Context mContext) {
public static int readPictureDegree(String path) { TelephonyManager phoneMgr = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
int degree = 0; return phoneMgr.getLine1Number();
try { }
ExifInterface exifInterface = new ExifInterface(path);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, public static String getDeviceID(Context mContext) {
ExifInterface.ORIENTATION_NORMAL); TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
switch (orientation) { return tm.getDeviceId();
case ExifInterface.ORIENTATION_ROTATE_90: }
degree = 90;
break; public static String getMacAddress(Context mContext) {
case ExifInterface.ORIENTATION_ROTATE_180: WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
degree = 180; WifiInfo info = wifi.getConnectionInfo();
break; String address = info.getMacAddress();
case ExifInterface.ORIENTATION_ROTATE_270: if (address != null && address.length() > 0) {
degree = 270; address = address.replace(":", "");
break; }
} return address;
} catch (IOException e) { }
e.printStackTrace();
} /**
return degree; * 获取bitmap的灰度图像
} */
public static byte[] getGrayscale(Bitmap bitmap) {
/** if (bitmap == null)
* 旋转图片 return null;
*
* @param angle byte[] ret = new byte[bitmap.getWidth() * bitmap.getHeight()];
* @param bitmap for (int j = 0; j < bitmap.getHeight(); ++j)
* @return Bitmap for (int i = 0; i < bitmap.getWidth(); ++i) {
*/ int pixel = bitmap.getPixel(i, j);
public static Bitmap rotateImage(int angle, Bitmap bitmap) { int red = ((pixel & 0x00FF0000) >> 16);
// 图片旋转矩阵 int green = ((pixel & 0x0000FF00) >> 8);
Matrix matrix = new Matrix(); int blue = pixel & 0x000000FF;
matrix.postRotate(angle); ret[j * bitmap.getWidth() + i] = (byte) ((299 * red + 587 * green + 114 * blue) / 1000);
// 得到旋转后的图片 }
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); return ret;
return resizedBitmap; }
}
/**
private static Bitmap getBitMap(String fileSrc, int dstWidth) { * 读取图片属性:旋转的角度
if (dstWidth == -1) { *
return BitmapFactory.decodeFile(fileSrc); * @param path 图片绝对路径
} * @return degree旋转的角度
// 获取图片的宽和高 */
BitmapFactory.Options options = new BitmapFactory.Options(); public static int readPictureDegree(String path) {
options.inJustDecodeBounds = true; int degree = 0;
BitmapFactory.decodeFile(fileSrc, options); try {
ExifInterface exifInterface = new ExifInterface(path);
// 压缩图片 int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
options.inSampleSize = Math.max(1, ExifInterface.ORIENTATION_NORMAL);
(int) (Math.max((double) options.outWidth / dstWidth, (double) options.outHeight / dstWidth))); switch (orientation) {
options.inJustDecodeBounds = false; case ExifInterface.ORIENTATION_ROTATE_90:
return BitmapFactory.decodeFile(fileSrc, options); degree = 90;
} break;
case ExifInterface.ORIENTATION_ROTATE_180:
/** degree = 180;
* 压缩图 break;
*/ case ExifInterface.ORIENTATION_ROTATE_270:
public static Bitmap getBitmapConsiderExif(String imagePath) { degree = 270;
break;
// 获取照相后的bitmap }
// Bitmap tmpBitmap = BitmapFactory.decodeFile(imagePath); } catch (IOException e) {
Bitmap tmpBitmap = getBitMap(imagePath, 800); e.printStackTrace();
if (tmpBitmap == null) }
return null; return degree;
Matrix matrix = new Matrix(); }
matrix.postRotate(readPictureDegree(imagePath));
tmpBitmap = Bitmap.createBitmap(tmpBitmap, 0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight(), matrix, true); /**
tmpBitmap = tmpBitmap.copy(Config.ARGB_8888, true); * 旋转图片
*
int hight = tmpBitmap.getHeight() > tmpBitmap.getWidth() ? tmpBitmap.getHeight() : tmpBitmap.getWidth(); * @param angle
* @param bitmap
float scale = hight / 800.0f; * @return Bitmap
*/
if (scale > 1) { public static Bitmap rotateImage(int angle, Bitmap bitmap) {
tmpBitmap = Bitmap.createScaledBitmap(tmpBitmap, (int) (tmpBitmap.getWidth() / scale), // 图片旋转矩阵
(int) (tmpBitmap.getHeight() / scale), false); Matrix matrix = new Matrix();
} matrix.postRotate(angle);
return tmpBitmap; // 得到旋转后的图片
} Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
return resizedBitmap;
/** }
* 切图
*/ private static Bitmap getBitMap(String fileSrc, int dstWidth) {
public static Bitmap cropImage(RectF rect, Bitmap bitmap) { if (dstWidth == -1) {
float width = rect.width() * 2; return BitmapFactory.decodeFile(fileSrc);
if (width > bitmap.getWidth()) { }
width = bitmap.getWidth(); // 获取图片的宽和高
} BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
float hight = rect.height() * 2; BitmapFactory.decodeFile(fileSrc, options);
if (hight > bitmap.getHeight()) {
hight = bitmap.getHeight(); // 压缩图片
} options.inSampleSize = Math.max(1,
(int) (Math.max((double) options.outWidth / dstWidth, (double) options.outHeight / dstWidth)));
float l = rect.centerX() - (width / 2); options.inJustDecodeBounds = false;
if (l < 0) { return BitmapFactory.decodeFile(fileSrc, options);
l = 0; }
}
float t = rect.centerY() - (hight / 2); /**
if (t < 0) { * 压缩图
t = 0; */
} public static Bitmap getBitmapConsiderExif(String imagePath) {
if (l + width > bitmap.getWidth()) {
width = bitmap.getWidth() - l; // 获取照相后的bitmap
} // Bitmap tmpBitmap = BitmapFactory.decodeFile(imagePath);
if (t + hight > bitmap.getHeight()) { Bitmap tmpBitmap = getBitMap(imagePath, 800);
hight = bitmap.getHeight() - t; if (tmpBitmap == null)
} return null;
Matrix matrix = new Matrix();
return Bitmap.createBitmap(bitmap, (int) l, (int) t, (int) width, (int) hight); matrix.postRotate(readPictureDegree(imagePath));
tmpBitmap = Bitmap.createBitmap(tmpBitmap, 0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight(), matrix, true);
} tmpBitmap = tmpBitmap.copy(Config.ARGB_8888, true);
/** int hight = tmpBitmap.getHeight() > tmpBitmap.getWidth() ? tmpBitmap.getHeight() : tmpBitmap.getWidth();
* 切图
*/ float scale = hight / 800.0f;
public static Bitmap cutImage(RectF rect, String imagePath) {
Bitmap bitmap = BitmapFactory.decodeFile(imagePath); if (scale > 1) {
return cropImage(rect, bitmap); tmpBitmap = Bitmap.createScaledBitmap(tmpBitmap, (int) (tmpBitmap.getWidth() / scale),
(int) (tmpBitmap.getHeight() / scale), false);
} }
return tmpBitmap;
/** }
* 照相机拍照后照片存储路径
*/ /**
public static File getOutputMediaFile(Context mContext) { * 切图
File mediaStorageDir = mContext.getExternalFilesDir(Constant.cacheCampareImage); */
if (!mediaStorageDir.exists()) { public static Bitmap cropImage(RectF rect, Bitmap bitmap) {
if (!mediaStorageDir.mkdirs()) { float width = rect.width() * 2;
return null; if (width > bitmap.getWidth()) {
} width = bitmap.getWidth();
} }
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile; float hight = rect.height() * 2;
if (hight > bitmap.getHeight()) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); hight = bitmap.getHeight();
return mediaFile; }
}
float l = rect.centerX() - (width / 2);
/** if (l < 0) {
* 隐藏软键盘 l = 0;
*/ }
public static void isGoneKeyBoard(Activity activity) { float t = rect.centerY() - (hight / 2);
if (activity.getCurrentFocus() != null) { if (t < 0) {
// 隐藏软键盘 t = 0;
((InputMethodManager) activity.getSystemService(activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow( }
activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); if (l + width > bitmap.getWidth()) {
} width = bitmap.getWidth() - l;
} }
if (t + hight > bitmap.getHeight()) {
/** hight = bitmap.getHeight() - t;
* 输出toast }
*/
public static void showToast(Context context, String str) { return Bitmap.createBitmap(bitmap, (int) l, (int) t, (int) width, (int) hight);
if (context != null) {
Toast toast = Toast.makeText(context, str, Toast.LENGTH_SHORT); }
// 可以控制toast显示的位置
toast.setGravity(Gravity.TOP, 0, 30); /**
toast.show(); * 切图
} */
} public static Bitmap cutImage(RectF rect, String imagePath) {
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
/** return cropImage(rect, bitmap);
* 输出长时间toast
*/ }
public static void showLongToast(Context context, String str) {
if (context != null) { /**
Toast toast = Toast.makeText(context, str, Toast.LENGTH_LONG); * 照相机拍照后照片存储路径
// 可以控制toast显示的位置 */
toast.setGravity(Gravity.TOP, 0, 30); public static File getOutputMediaFile(Context mContext) {
toast.show(); File mediaStorageDir = mContext.getExternalFilesDir(Constant.cacheCampareImage);
} if (!mediaStorageDir.exists()) {
} if (!mediaStorageDir.mkdirs()) {
return null;
/** }
* 获取APP版本名 }
*/ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
public static String getVersionName(Context context) { File mediaFile;
try {
String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
return versionName; return mediaFile;
} catch (NameNotFoundException e) { }
e.printStackTrace();
return null; /**
} * 隐藏软键盘
} */
public static void isGoneKeyBoard(Activity activity) {
/** if (activity.getCurrentFocus() != null) {
* 镜像旋转 // 隐藏软键盘
*/ ((InputMethodManager) activity.getSystemService(activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
public static Bitmap convert(Bitmap bitmap, boolean mIsFrontalCamera) { activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
int w = bitmap.getWidth(); }
int h = bitmap.getHeight(); }
Bitmap newbBitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
Canvas cv = new Canvas(newbBitmap); /**
Matrix m = new Matrix(); * 输出toast
// m.postScale(1, -1); //镜像垂直翻转 */
if (mIsFrontalCamera) { public static void showToast(Context context, String str) {
m.postScale(-1, 1); // 镜像水平翻转 if (context != null) {
} Toast toast = Toast.makeText(context, str, Toast.LENGTH_SHORT);
// m.postRotate(-90); //旋转-90度 // 可以控制toast显示的位置
Bitmap bitmap2 = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true); toast.setGravity(Gravity.TOP, 0, 30);
cv.drawBitmap(bitmap2, new Rect(0, 0, bitmap2.getWidth(), bitmap2.getHeight()), new Rect(0, 0, w, h), null); toast.show();
return newbBitmap; }
} }
/** /**
* 保存bitmap至指定Picture文件夹 * 输出长时间toast
*/ */
public static String saveBitmap(Context mContext, Bitmap bitmaptosave) { public static void showLongToast(Context context, String str) {
if (bitmaptosave == null) if (context != null) {
return null; Toast toast = Toast.makeText(context, str, Toast.LENGTH_LONG);
// 可以控制toast显示的位置
File mediaStorageDir = mContext.getExternalFilesDir(Constant.cacheImage); toast.setGravity(Gravity.TOP, 0, 30);
toast.show();
if (!mediaStorageDir.exists()) { }
if (!mediaStorageDir.mkdirs()) { }
return null;
} /**
} * 获取APP版本名
// String bitmapFileName = System.currentTimeMillis() + ".jpg"; */
String bitmapFileName = System.currentTimeMillis() + ""; public static String getVersionName(Context context) {
FileOutputStream fos = null; try {
try { String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
fos = new FileOutputStream(mediaStorageDir + "/" + bitmapFileName); return versionName;
boolean successful = bitmaptosave.compress(Bitmap.CompressFormat.JPEG, 75, fos); } catch (NameNotFoundException e) {
e.printStackTrace();
if (successful) return null;
return mediaStorageDir.getAbsolutePath() + "/" + bitmapFileName; }
else }
return null;
} catch (FileNotFoundException e) { /**
e.printStackTrace(); * 镜像旋转
return null; */
} finally { public static Bitmap convert(Bitmap bitmap, boolean mIsFrontalCamera) {
try { int w = bitmap.getWidth();
fos.close(); int h = bitmap.getHeight();
} catch (IOException e) { Bitmap newbBitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
e.printStackTrace(); Canvas cv = new Canvas(newbBitmap);
} Matrix m = new Matrix();
} // m.postScale(1, -1); //镜像垂直翻转
} if (mIsFrontalCamera) {
m.postScale(-1, 1); // 镜像水平翻转
/** }
* 时间格式化(格式到秒) // m.postRotate(-90); //旋转-90度
*/ Bitmap bitmap2 = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true);
public static String getFormatterTime(long time) { cv.drawBitmap(bitmap2, new Rect(0, 0, bitmap2.getWidth(), bitmap2.getHeight()), new Rect(0, 0, w, h), null);
Date d = new Date(time); return newbBitmap;
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); }
String data = formatter.format(d);
return data; /**
} * 保存bitmap至指定Picture文件夹
*/
public static String saveBitmap(Context mContext, Bitmap bitmaptosave) {
if (bitmaptosave == null)
return null;
File mediaStorageDir = mContext.getExternalFilesDir(Constant.cacheImage);
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
return null;
}
}
// String bitmapFileName = System.currentTimeMillis() + ".jpg";
String bitmapFileName = System.currentTimeMillis() + "";
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mediaStorageDir + "/" + bitmapFileName);
boolean successful = bitmaptosave.compress(Bitmap.CompressFormat.JPEG, 75, fos);
if (successful)
return mediaStorageDir.getAbsolutePath() + "/" + bitmapFileName;
else
return null;
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 时间格式化(格式到秒)
*/
public static String getFormatterTime(long time) {
Date d = new Date(time);
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String data = formatter.format(d);
return data;
}
} }
...@@ -112,9 +112,9 @@ public class InitializeActivity extends DataBindingActivity<ActivityInitializeMa ...@@ -112,9 +112,9 @@ public class InitializeActivity extends DataBindingActivity<ActivityInitializeMa
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
if (mDisposable != null) { // if (mDisposable != null) {
mDisposable.dispose(); // mDisposable.dispose();
} // }
} }
@TargetApi(23) @TargetApi(23)
......
...@@ -13,6 +13,8 @@ import com.dayu.message.databinding.ActivityMessageDetailBinding; ...@@ -13,6 +13,8 @@ import com.dayu.message.databinding.ActivityMessageDetailBinding;
import com.dayu.provider.common.ProviderConstant; import com.dayu.provider.common.ProviderConstant;
import com.dayu.provider.router.RouterPath; import com.dayu.provider.router.RouterPath;
import com.dayu.utils.GsonUtils; import com.dayu.utils.GsonUtils;
import com.dayu.utils.ToastUtils;
import com.dayu.utils.UIUtils;
import com.dayu.utils.UtilsDate; import com.dayu.utils.UtilsDate;
import com.umeng.analytics.MobclickAgent; import com.umeng.analytics.MobclickAgent;
...@@ -39,6 +41,10 @@ public class MessageDetailActivity extends DataBindingActivity<ActivityMessageDe ...@@ -39,6 +41,10 @@ public class MessageDetailActivity extends DataBindingActivity<ActivityMessageDe
public void initView() { public void initView() {
mBind.tvTitle.setText(getString(R.string.message_dayu_detail)); mBind.tvTitle.setText(getString(R.string.message_dayu_detail));
Bundle bundle = mActivity.getIntent().getBundleExtra(Constants.BUNDLE); Bundle bundle = mActivity.getIntent().getBundleExtra(Constants.BUNDLE);
if(bundle==null){
ToastUtils.showShortToast(UIUtils.getString(R.string.get_info_failed));
return;
}
message = (NewMessage) bundle.getSerializable(Constants.HX_MESSAGE); message = (NewMessage) bundle.getSerializable(Constants.HX_MESSAGE);
mCategory = bundle.getInt("category", 1); mCategory = bundle.getInt("category", 1);
String time = null; String time = null;
......
...@@ -12,13 +12,15 @@ import com.dayu.usercenter.R; ...@@ -12,13 +12,15 @@ import com.dayu.usercenter.R;
import com.dayu.usercenter.databinding.ActivityFaceCertificationBinding; import com.dayu.usercenter.databinding.ActivityFaceCertificationBinding;
import com.dayu.usercenter.presenter.facecertification.FaceCertificaitonContract; import com.dayu.usercenter.presenter.facecertification.FaceCertificaitonContract;
import com.dayu.usercenter.presenter.facecertification.FaceCertificaitonPresenter; import com.dayu.usercenter.presenter.facecertification.FaceCertificaitonPresenter;
import com.dayu.utils.GlideImageLoader;
import com.dayu.utils.ToastUtils; import com.dayu.utils.ToastUtils;
import com.megvii.idcardlib.LivenessActivity; import com.megvii.idcardlib.LivenessActivity;
import com.megvii.idcardlib.util.ConUtil; import com.megvii.idcardlib.util.ConUtil;
import com.megvii.licensemanager.Manager; import com.megvii.licensemanager.Manager;
import com.megvii.livenessdetection.LivenessLicenseManager; import com.megvii.livenessdetection.LivenessLicenseManager;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
...@@ -94,21 +96,50 @@ public class FaceCertificationActivity extends BaseActivity<FaceCertificaitonPre ...@@ -94,21 +96,50 @@ public class FaceCertificationActivity extends BaseActivity<FaceCertificaitonPre
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PAGE_INTO_LIVENESS && resultCode == RESULT_OK) { if (requestCode == PAGE_INTO_LIVENESS && resultCode == RESULT_OK) {
boolean isSuccess = false;
String delta = data.getStringExtra("delta"); String delta = data.getStringExtra("delta");
int code = data.getIntExtra("resultcode", 0); int code = data.getIntExtra("resultcode", 0);
Map<String, byte[]> images = (Map<String, byte[]>) data.getSerializableExtra("images"); String str = data.getStringExtra("result");
ArrayList<File> list = new ArrayList<>(); try {
byte[] image_best = images.get("image_best"); JSONObject result = new JSONObject(str);
byte[] image_env = images.get("image_env"); int resID = result.getInt("resultcode");
byte[] image_action1 = images.get("imageAction1"); checkID(resID);
byte[] image_action2 = images.get("imageAction2"); isSuccess = result.getString("result").equals(
byte[] image_action3 = images.get("imageAction3"); getResources().getString(R.string.verify_success));
list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_best, 0, image_best.length), "best")); } catch (JSONException e) {
list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_env, 0, image_best.length), "env")); e.printStackTrace();
list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_action1, 0, image_best.length), "action1")); }
list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_action2, 0, image_best.length), "action2")); if (isSuccess) {
list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_action3, 0, image_best.length), "action3")); Map<String, byte[]> images = (Map<String, byte[]>) data.getSerializableExtra("images");
mPresenter.commitePhoto(list, delta); ArrayList<File> list = new ArrayList<>();
byte[] image_best = images.get("image_best");
byte[] image_env = images.get("image_env");
byte[] image_action1 = images.get("image_action1");
byte[] image_action2 = images.get("image_action2");
byte[] image_action3 = images.get("image_action3");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
list.add(ConUtil.saveJPG(mActivity, image_best, "image_best"));
list.add(ConUtil.saveJPG(mActivity, image_env, "image_env"));
list.add(ConUtil.saveJPG(mActivity, image_action1, "image_action1"));
list.add(ConUtil.saveJPG(mActivity, image_action2, "image_action2"));
list.add(ConUtil.saveJPG(mActivity, image_action3, "image_action3"));
// list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_best, 0, image_best.length, options), "best"));
// list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_env, 0, image_best.length, options), "env"));
// list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_action1, 0, image_best.length, options), "action1"));
// list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_action2, 0, image_best.length, options), "action2"));
// list.add(GlideImageLoader.compressImage(BitmapFactory.decodeByteArray(image_action3, 0, image_best.length, options), "action3"));
mPresenter.commitePhoto(list, delta);
}
}
}
private void checkID(int resID) {
if (resID == R.string.verify_success) {
} else if (resID == R.string.liveness_detection_failed_not_video) {
} else if (resID == R.string.liveness_detection_failed_timeout) {
} else if (resID == R.string.liveness_detection_failed) {
} else {
} }
} }
......
...@@ -89,6 +89,7 @@ public class IdentityCertificationActivity extends BaseActivity<CertificaitonPre ...@@ -89,6 +89,7 @@ public class IdentityCertificationActivity extends BaseActivity<CertificaitonPre
mBind.rlNext.setClickable(false); mBind.rlNext.setClickable(false);
mBind.ivSideDelete.setVisibility(View.GONE); mBind.ivSideDelete.setVisibility(View.GONE);
}); });
mBind.rlNext.setOnClickListener(v->mPresenter.commitePhoto());
mBind.ivNext.setAlpha(0.5f); mBind.ivNext.setAlpha(0.5f);
mBind.rlNext.setClickable(false); mBind.rlNext.setClickable(false);
...@@ -161,8 +162,10 @@ public class IdentityCertificationActivity extends BaseActivity<CertificaitonPre ...@@ -161,8 +162,10 @@ public class IdentityCertificationActivity extends BaseActivity<CertificaitonPre
if (requestCode == INTO_IDCARDSCAN_PAGE && resultCode == RESULT_OK) { if (requestCode == INTO_IDCARDSCAN_PAGE && resultCode == RESULT_OK) {
runOnUiThread(() -> { runOnUiThread(() -> {
byte[] idcardImgData = data.getByteArrayExtra("idcardImg"); byte[] idcardImgData = data.getByteArrayExtra("idcardImg");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap idcardBmp = BitmapFactory.decodeByteArray(idcardImgData, 0, Bitmap idcardBmp = BitmapFactory.decodeByteArray(idcardImgData, 0,
idcardImgData.length); idcardImgData.length,options);
if (mSide == 0) { if (mSide == 0) {
mFrontBitmap = idcardBmp; mFrontBitmap = idcardBmp;
mBind.ivFront.setImageBitmap(idcardBmp); mBind.ivFront.setImageBitmap(idcardBmp);
......
...@@ -101,8 +101,7 @@ ...@@ -101,8 +101,7 @@
android:id="@+id/rl_next" android:id="@+id/rl_next"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="47dp" android:layout_height="47dp"
android:layout_marginBottom="54dp" android:layout_marginBottom="54dp">
android:onClick="@{()->presenter.commitePhoto()}">
<ImageView <ImageView
android:id="@+id/iv_next" android:id="@+id/iv_next"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment