Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
android
/
dayu
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
905c2635
authored
May 15, 2018
by
罗翻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加人脸识别
parent
5b0d1c4f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
507 additions
and
424 deletions
IDCardLib/src/main/java/com/megvii/idcardlib/util/ConUtil.java
app/src/main/java/com/dayu/bigfish/InitializeActivity.java
messageCenter/src/main/java/com/dayu/message/ui/activity/MessageDetailActivity.java
userCenter/src/main/java/com/dayu/usercenter/ui/activity/FaceCertificationActivity.java
userCenter/src/main/java/com/dayu/usercenter/ui/activity/IdentityCertificationActivity.java
userCenter/src/main/res/layout/activity_certification_layout.xml
IDCardLib/src/main/java/com/megvii/idcardlib/util/ConUtil.java
View file @
905c2635
...
...
@@ -36,409 +36,453 @@ import java.util.UUID;
public
class
ConUtil
{
/**
* 根据byte数组,生成文件
*/
public
static
String
saveJPGFile
(
Context
mContext
,
byte
[]
data
,
String
key
)
{
if
(
data
==
null
)
return
null
;
File
mediaStorageDir
=
mContext
.
getExternalFilesDir
(
Constant
.
cacheImage
);
if
(!
mediaStorageDir
.
exists
())
{
if
(!
mediaStorageDir
.
mkdirs
())
{
return
null
;
}
}
BufferedOutputStream
bos
=
null
;
FileOutputStream
fos
=
null
;
try
{
String
jpgFileName
=
System
.
currentTimeMillis
()
+
""
+
new
Random
().
nextInt
(
1000000
)
+
"_"
+
key
+
".jpg"
;
fos
=
new
FileOutputStream
(
mediaStorageDir
+
"/"
+
jpgFileName
);
bos
=
new
BufferedOutputStream
(
fos
);
bos
.
write
(
data
);
return
mediaStorageDir
.
getAbsolutePath
()
+
"/"
+
jpgFileName
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
bos
!=
null
)
{
try
{
bos
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
if
(
fos
!=
null
)
{
try
{
fos
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
}
return
null
;
}
public
static
void
copyModels
(
Context
context
)
{
File
dstModelFile
=
new
File
(
context
.
getExternalFilesDir
(
null
),
"model"
);
if
(
dstModelFile
.
exists
())
{
return
;
}
try
{
String
tmpFile
=
"model"
;
BufferedInputStream
inputStream
=
new
BufferedInputStream
(
context
.
getAssets
().
open
(
tmpFile
));
BufferedOutputStream
foutputStream
=
new
BufferedOutputStream
(
new
FileOutputStream
(
dstModelFile
));
byte
[]
buffer
=
new
byte
[
1024
];
int
readcount
=
-
1
;
while
((
readcount
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
foutputStream
.
write
(
buffer
,
0
,
readcount
);
}
foutputStream
.
close
();
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
static
byte
[]
readModel
(
Context
context
)
{
InputStream
inputStream
=
null
;
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
];
int
count
=
-
1
;
try
{
inputStream
=
context
.
getResources
().
openRawResource
(
R
.
raw
.
livenessmodel
);
while
((
count
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
count
);
}
byteArrayOutputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
inputStream
!=
null
)
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
byteArrayOutputStream
.
toByteArray
();
}
public
static
String
getUUIDString
(
Context
mContext
)
{
String
KEY_UUID
=
"key_uuid"
;
SharedUtil
sharedUtil
=
new
SharedUtil
(
mContext
);
String
uuid
=
sharedUtil
.
getStringValueByKey
(
KEY_UUID
);
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
);
return
uuid
;
}
public
static
String
getPhoneNumber
(
Context
mContext
)
{
TelephonyManager
phoneMgr
=
(
TelephonyManager
)
mContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
return
phoneMgr
.
getLine1Number
();
}
public
static
String
getDeviceID
(
Context
mContext
)
{
TelephonyManager
tm
=
(
TelephonyManager
)
mContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
return
tm
.
getDeviceId
();
}
public
static
String
getMacAddress
(
Context
mContext
)
{
WifiManager
wifi
=
(
WifiManager
)
mContext
.
getSystemService
(
Context
.
WIFI_SERVICE
);
WifiInfo
info
=
wifi
.
getConnectionInfo
();
String
address
=
info
.
getMacAddress
();
if
(
address
!=
null
&&
address
.
length
()
>
0
)
{
address
=
address
.
replace
(
":"
,
""
);
}
return
address
;
}
/**
* 获取bitmap的灰度图像
*/
public
static
byte
[]
getGrayscale
(
Bitmap
bitmap
)
{
if
(
bitmap
==
null
)
return
null
;
byte
[]
ret
=
new
byte
[
bitmap
.
getWidth
()
*
bitmap
.
getHeight
()];
for
(
int
j
=
0
;
j
<
bitmap
.
getHeight
();
++
j
)
for
(
int
i
=
0
;
i
<
bitmap
.
getWidth
();
++
i
)
{
int
pixel
=
bitmap
.
getPixel
(
i
,
j
);
int
red
=
((
pixel
&
0x00FF0000
)
>>
16
);
int
green
=
((
pixel
&
0x0000FF00
)
>>
8
);
int
blue
=
pixel
&
0x000000FF
;
ret
[
j
*
bitmap
.
getWidth
()
+
i
]
=
(
byte
)
((
299
*
red
+
587
*
green
+
114
*
blue
)
/
1000
);
}
return
ret
;
}
/**
* 读取图片属性:旋转的角度
*
* @param path
* 图片绝对路径
* @return degree旋转的角度
*/
public
static
int
readPictureDegree
(
String
path
)
{
int
degree
=
0
;
try
{
ExifInterface
exifInterface
=
new
ExifInterface
(
path
);
int
orientation
=
exifInterface
.
getAttributeInt
(
ExifInterface
.
TAG_ORIENTATION
,
ExifInterface
.
ORIENTATION_NORMAL
);
switch
(
orientation
)
{
case
ExifInterface
.
ORIENTATION_ROTATE_90
:
degree
=
90
;
break
;
case
ExifInterface
.
ORIENTATION_ROTATE_180
:
degree
=
180
;
break
;
case
ExifInterface
.
ORIENTATION_ROTATE_270
:
degree
=
270
;
break
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
degree
;
}
/**
* 旋转图片
*
* @param angle
* @param bitmap
* @return Bitmap
*/
public
static
Bitmap
rotateImage
(
int
angle
,
Bitmap
bitmap
)
{
// 图片旋转矩阵
Matrix
matrix
=
new
Matrix
();
matrix
.
postRotate
(
angle
);
// 得到旋转后的图片
Bitmap
resizedBitmap
=
Bitmap
.
createBitmap
(
bitmap
,
0
,
0
,
bitmap
.
getWidth
(),
bitmap
.
getHeight
(),
matrix
,
true
);
return
resizedBitmap
;
}
private
static
Bitmap
getBitMap
(
String
fileSrc
,
int
dstWidth
)
{
if
(
dstWidth
==
-
1
)
{
return
BitmapFactory
.
decodeFile
(
fileSrc
);
}
// 获取图片的宽和高
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
true
;
BitmapFactory
.
decodeFile
(
fileSrc
,
options
);
// 压缩图片
options
.
inSampleSize
=
Math
.
max
(
1
,
(
int
)
(
Math
.
max
((
double
)
options
.
outWidth
/
dstWidth
,
(
double
)
options
.
outHeight
/
dstWidth
)));
options
.
inJustDecodeBounds
=
false
;
return
BitmapFactory
.
decodeFile
(
fileSrc
,
options
);
}
/**
* 压缩图
*/
public
static
Bitmap
getBitmapConsiderExif
(
String
imagePath
)
{
// 获取照相后的bitmap
// Bitmap tmpBitmap = BitmapFactory.decodeFile(imagePath);
Bitmap
tmpBitmap
=
getBitMap
(
imagePath
,
800
);
if
(
tmpBitmap
==
null
)
return
null
;
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
();
float
scale
=
hight
/
800.0f
;
if
(
scale
>
1
)
{
tmpBitmap
=
Bitmap
.
createScaledBitmap
(
tmpBitmap
,
(
int
)
(
tmpBitmap
.
getWidth
()
/
scale
),
(
int
)
(
tmpBitmap
.
getHeight
()
/
scale
),
false
);
}
return
tmpBitmap
;
}
/**
* 切图
*/
public
static
Bitmap
cropImage
(
RectF
rect
,
Bitmap
bitmap
)
{
float
width
=
rect
.
width
()
*
2
;
if
(
width
>
bitmap
.
getWidth
())
{
width
=
bitmap
.
getWidth
();
}
float
hight
=
rect
.
height
()
*
2
;
if
(
hight
>
bitmap
.
getHeight
())
{
hight
=
bitmap
.
getHeight
();
}
float
l
=
rect
.
centerX
()
-
(
width
/
2
);
if
(
l
<
0
)
{
l
=
0
;
}
float
t
=
rect
.
centerY
()
-
(
hight
/
2
);
if
(
t
<
0
)
{
t
=
0
;
}
if
(
l
+
width
>
bitmap
.
getWidth
())
{
width
=
bitmap
.
getWidth
()
-
l
;
}
if
(
t
+
hight
>
bitmap
.
getHeight
())
{
hight
=
bitmap
.
getHeight
()
-
t
;
}
return
Bitmap
.
createBitmap
(
bitmap
,
(
int
)
l
,
(
int
)
t
,
(
int
)
width
,
(
int
)
hight
);
}
/**
* 切图
*/
public
static
Bitmap
cutImage
(
RectF
rect
,
String
imagePath
)
{
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
imagePath
);
return
cropImage
(
rect
,
bitmap
);
}
/**
* 照相机拍照后照片存储路径
*/
public
static
File
getOutputMediaFile
(
Context
mContext
)
{
File
mediaStorageDir
=
mContext
.
getExternalFilesDir
(
Constant
.
cacheCampareImage
);
if
(!
mediaStorageDir
.
exists
())
{
if
(!
mediaStorageDir
.
mkdirs
())
{
return
null
;
}
}
String
timeStamp
=
new
SimpleDateFormat
(
"yyyyMMdd_HHmmss"
).
format
(
new
Date
());
File
mediaFile
;
mediaFile
=
new
File
(
mediaStorageDir
.
getPath
()
+
File
.
separator
+
"IMG_"
+
timeStamp
+
".jpg"
);
return
mediaFile
;
}
/**
* 隐藏软键盘
*/
public
static
void
isGoneKeyBoard
(
Activity
activity
)
{
if
(
activity
.
getCurrentFocus
()
!=
null
)
{
// 隐藏软键盘
((
InputMethodManager
)
activity
.
getSystemService
(
activity
.
INPUT_METHOD_SERVICE
)).
hideSoftInputFromWindow
(
activity
.
getCurrentFocus
().
getWindowToken
(),
InputMethodManager
.
HIDE_NOT_ALWAYS
);
}
}
/**
* 输出toast
*/
public
static
void
showToast
(
Context
context
,
String
str
)
{
if
(
context
!=
null
)
{
Toast
toast
=
Toast
.
makeText
(
context
,
str
,
Toast
.
LENGTH_SHORT
);
// 可以控制toast显示的位置
toast
.
setGravity
(
Gravity
.
TOP
,
0
,
30
);
toast
.
show
();
}
}
/**
* 输出长时间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
);
toast
.
show
();
}
}
/**
* 获取APP版本名
*/
public
static
String
getVersionName
(
Context
context
)
{
try
{
String
versionName
=
context
.
getPackageManager
().
getPackageInfo
(
context
.
getPackageName
(),
0
).
versionName
;
return
versionName
;
}
catch
(
NameNotFoundException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 镜像旋转
*/
public
static
Bitmap
convert
(
Bitmap
bitmap
,
boolean
mIsFrontalCamera
)
{
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
();
// 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
);
cv
.
drawBitmap
(
bitmap2
,
new
Rect
(
0
,
0
,
bitmap2
.
getWidth
(),
bitmap2
.
getHeight
()),
new
Rect
(
0
,
0
,
w
,
h
),
null
);
return
newbBitmap
;
}
/**
* 保存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
;
}
/**
* 根据byte数组,生成文件
*/
public
static
String
saveJPGFile
(
Context
mContext
,
byte
[]
data
,
String
key
)
{
if
(
data
==
null
)
return
null
;
File
mediaStorageDir
=
mContext
.
getExternalFilesDir
(
Constant
.
cacheImage
);
if
(!
mediaStorageDir
.
exists
())
{
if
(!
mediaStorageDir
.
mkdirs
())
{
return
null
;
}
}
BufferedOutputStream
bos
=
null
;
FileOutputStream
fos
=
null
;
try
{
String
jpgFileName
=
System
.
currentTimeMillis
()
+
""
+
new
Random
().
nextInt
(
1000000
)
+
"_"
+
key
+
".jpg"
;
fos
=
new
FileOutputStream
(
mediaStorageDir
+
"/"
+
jpgFileName
);
bos
=
new
BufferedOutputStream
(
fos
);
bos
.
write
(
data
);
return
mediaStorageDir
.
getAbsolutePath
()
+
"/"
+
jpgFileName
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
bos
!=
null
)
{
try
{
bos
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
if
(
fos
!=
null
)
{
try
{
fos
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
}
return
null
;
}
/**
* 根据byte数组,生成文件
*/
public
static
File
saveJPG
(
Context
mContext
,
byte
[]
data
,
String
key
)
{
if
(
data
==
null
)
return
null
;
File
mediaStorageDir
=
mContext
.
getExternalFilesDir
(
Constant
.
cacheImage
);
if
(!
mediaStorageDir
.
exists
())
{
if
(!
mediaStorageDir
.
mkdirs
())
{
return
null
;
}
}
BufferedOutputStream
bos
=
null
;
FileOutputStream
fos
=
null
;
try
{
String
jpgFileName
=
System
.
currentTimeMillis
()
+
""
+
new
Random
().
nextInt
(
1000000
)
+
"_"
+
key
+
".jpg"
;
fos
=
new
FileOutputStream
(
mediaStorageDir
+
"/"
+
jpgFileName
);
bos
=
new
BufferedOutputStream
(
fos
);
bos
.
write
(
data
);
return
mediaStorageDir
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
bos
!=
null
)
{
try
{
bos
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
if
(
fos
!=
null
)
{
try
{
fos
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
}
return
null
;
}
public
static
void
copyModels
(
Context
context
)
{
File
dstModelFile
=
new
File
(
context
.
getExternalFilesDir
(
null
),
"model"
);
if
(
dstModelFile
.
exists
())
{
return
;
}
try
{
String
tmpFile
=
"model"
;
BufferedInputStream
inputStream
=
new
BufferedInputStream
(
context
.
getAssets
().
open
(
tmpFile
));
BufferedOutputStream
foutputStream
=
new
BufferedOutputStream
(
new
FileOutputStream
(
dstModelFile
));
byte
[]
buffer
=
new
byte
[
1024
];
int
readcount
=
-
1
;
while
((
readcount
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
foutputStream
.
write
(
buffer
,
0
,
readcount
);
}
foutputStream
.
close
();
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
static
byte
[]
readModel
(
Context
context
)
{
InputStream
inputStream
=
null
;
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
];
int
count
=
-
1
;
try
{
inputStream
=
context
.
getResources
().
openRawResource
(
R
.
raw
.
livenessmodel
);
while
((
count
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
buffer
,
0
,
count
);
}
byteArrayOutputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
inputStream
!=
null
)
{
try
{
inputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
byteArrayOutputStream
.
toByteArray
();
}
public
static
String
getUUIDString
(
Context
mContext
)
{
String
KEY_UUID
=
"key_uuid"
;
SharedUtil
sharedUtil
=
new
SharedUtil
(
mContext
);
String
uuid
=
sharedUtil
.
getStringValueByKey
(
KEY_UUID
);
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
);
return
uuid
;
}
public
static
String
getPhoneNumber
(
Context
mContext
)
{
TelephonyManager
phoneMgr
=
(
TelephonyManager
)
mContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
return
phoneMgr
.
getLine1Number
();
}
public
static
String
getDeviceID
(
Context
mContext
)
{
TelephonyManager
tm
=
(
TelephonyManager
)
mContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
return
tm
.
getDeviceId
();
}
public
static
String
getMacAddress
(
Context
mContext
)
{
WifiManager
wifi
=
(
WifiManager
)
mContext
.
getSystemService
(
Context
.
WIFI_SERVICE
);
WifiInfo
info
=
wifi
.
getConnectionInfo
();
String
address
=
info
.
getMacAddress
();
if
(
address
!=
null
&&
address
.
length
()
>
0
)
{
address
=
address
.
replace
(
":"
,
""
);
}
return
address
;
}
/**
* 获取bitmap的灰度图像
*/
public
static
byte
[]
getGrayscale
(
Bitmap
bitmap
)
{
if
(
bitmap
==
null
)
return
null
;
byte
[]
ret
=
new
byte
[
bitmap
.
getWidth
()
*
bitmap
.
getHeight
()];
for
(
int
j
=
0
;
j
<
bitmap
.
getHeight
();
++
j
)
for
(
int
i
=
0
;
i
<
bitmap
.
getWidth
();
++
i
)
{
int
pixel
=
bitmap
.
getPixel
(
i
,
j
);
int
red
=
((
pixel
&
0x00FF0000
)
>>
16
);
int
green
=
((
pixel
&
0x0000FF00
)
>>
8
);
int
blue
=
pixel
&
0x000000FF
;
ret
[
j
*
bitmap
.
getWidth
()
+
i
]
=
(
byte
)
((
299
*
red
+
587
*
green
+
114
*
blue
)
/
1000
);
}
return
ret
;
}
/**
* 读取图片属性:旋转的角度
*
* @param path 图片绝对路径
* @return degree旋转的角度
*/
public
static
int
readPictureDegree
(
String
path
)
{
int
degree
=
0
;
try
{
ExifInterface
exifInterface
=
new
ExifInterface
(
path
);
int
orientation
=
exifInterface
.
getAttributeInt
(
ExifInterface
.
TAG_ORIENTATION
,
ExifInterface
.
ORIENTATION_NORMAL
);
switch
(
orientation
)
{
case
ExifInterface
.
ORIENTATION_ROTATE_90
:
degree
=
90
;
break
;
case
ExifInterface
.
ORIENTATION_ROTATE_180
:
degree
=
180
;
break
;
case
ExifInterface
.
ORIENTATION_ROTATE_270
:
degree
=
270
;
break
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
degree
;
}
/**
* 旋转图片
*
* @param angle
* @param bitmap
* @return Bitmap
*/
public
static
Bitmap
rotateImage
(
int
angle
,
Bitmap
bitmap
)
{
// 图片旋转矩阵
Matrix
matrix
=
new
Matrix
();
matrix
.
postRotate
(
angle
);
// 得到旋转后的图片
Bitmap
resizedBitmap
=
Bitmap
.
createBitmap
(
bitmap
,
0
,
0
,
bitmap
.
getWidth
(),
bitmap
.
getHeight
(),
matrix
,
true
);
return
resizedBitmap
;
}
private
static
Bitmap
getBitMap
(
String
fileSrc
,
int
dstWidth
)
{
if
(
dstWidth
==
-
1
)
{
return
BitmapFactory
.
decodeFile
(
fileSrc
);
}
// 获取图片的宽和高
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
true
;
BitmapFactory
.
decodeFile
(
fileSrc
,
options
);
// 压缩图片
options
.
inSampleSize
=
Math
.
max
(
1
,
(
int
)
(
Math
.
max
((
double
)
options
.
outWidth
/
dstWidth
,
(
double
)
options
.
outHeight
/
dstWidth
)));
options
.
inJustDecodeBounds
=
false
;
return
BitmapFactory
.
decodeFile
(
fileSrc
,
options
);
}
/**
* 压缩图
*/
public
static
Bitmap
getBitmapConsiderExif
(
String
imagePath
)
{
// 获取照相后的bitmap
// Bitmap tmpBitmap = BitmapFactory.decodeFile(imagePath);
Bitmap
tmpBitmap
=
getBitMap
(
imagePath
,
800
);
if
(
tmpBitmap
==
null
)
return
null
;
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
();
float
scale
=
hight
/
800.0f
;
if
(
scale
>
1
)
{
tmpBitmap
=
Bitmap
.
createScaledBitmap
(
tmpBitmap
,
(
int
)
(
tmpBitmap
.
getWidth
()
/
scale
),
(
int
)
(
tmpBitmap
.
getHeight
()
/
scale
),
false
);
}
return
tmpBitmap
;
}
/**
* 切图
*/
public
static
Bitmap
cropImage
(
RectF
rect
,
Bitmap
bitmap
)
{
float
width
=
rect
.
width
()
*
2
;
if
(
width
>
bitmap
.
getWidth
())
{
width
=
bitmap
.
getWidth
();
}
float
hight
=
rect
.
height
()
*
2
;
if
(
hight
>
bitmap
.
getHeight
())
{
hight
=
bitmap
.
getHeight
();
}
float
l
=
rect
.
centerX
()
-
(
width
/
2
);
if
(
l
<
0
)
{
l
=
0
;
}
float
t
=
rect
.
centerY
()
-
(
hight
/
2
);
if
(
t
<
0
)
{
t
=
0
;
}
if
(
l
+
width
>
bitmap
.
getWidth
())
{
width
=
bitmap
.
getWidth
()
-
l
;
}
if
(
t
+
hight
>
bitmap
.
getHeight
())
{
hight
=
bitmap
.
getHeight
()
-
t
;
}
return
Bitmap
.
createBitmap
(
bitmap
,
(
int
)
l
,
(
int
)
t
,
(
int
)
width
,
(
int
)
hight
);
}
/**
* 切图
*/
public
static
Bitmap
cutImage
(
RectF
rect
,
String
imagePath
)
{
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
imagePath
);
return
cropImage
(
rect
,
bitmap
);
}
/**
* 照相机拍照后照片存储路径
*/
public
static
File
getOutputMediaFile
(
Context
mContext
)
{
File
mediaStorageDir
=
mContext
.
getExternalFilesDir
(
Constant
.
cacheCampareImage
);
if
(!
mediaStorageDir
.
exists
())
{
if
(!
mediaStorageDir
.
mkdirs
())
{
return
null
;
}
}
String
timeStamp
=
new
SimpleDateFormat
(
"yyyyMMdd_HHmmss"
).
format
(
new
Date
());
File
mediaFile
;
mediaFile
=
new
File
(
mediaStorageDir
.
getPath
()
+
File
.
separator
+
"IMG_"
+
timeStamp
+
".jpg"
);
return
mediaFile
;
}
/**
* 隐藏软键盘
*/
public
static
void
isGoneKeyBoard
(
Activity
activity
)
{
if
(
activity
.
getCurrentFocus
()
!=
null
)
{
// 隐藏软键盘
((
InputMethodManager
)
activity
.
getSystemService
(
activity
.
INPUT_METHOD_SERVICE
)).
hideSoftInputFromWindow
(
activity
.
getCurrentFocus
().
getWindowToken
(),
InputMethodManager
.
HIDE_NOT_ALWAYS
);
}
}
/**
* 输出toast
*/
public
static
void
showToast
(
Context
context
,
String
str
)
{
if
(
context
!=
null
)
{
Toast
toast
=
Toast
.
makeText
(
context
,
str
,
Toast
.
LENGTH_SHORT
);
// 可以控制toast显示的位置
toast
.
setGravity
(
Gravity
.
TOP
,
0
,
30
);
toast
.
show
();
}
}
/**
* 输出长时间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
);
toast
.
show
();
}
}
/**
* 获取APP版本名
*/
public
static
String
getVersionName
(
Context
context
)
{
try
{
String
versionName
=
context
.
getPackageManager
().
getPackageInfo
(
context
.
getPackageName
(),
0
).
versionName
;
return
versionName
;
}
catch
(
NameNotFoundException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 镜像旋转
*/
public
static
Bitmap
convert
(
Bitmap
bitmap
,
boolean
mIsFrontalCamera
)
{
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
();
// 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
);
cv
.
drawBitmap
(
bitmap2
,
new
Rect
(
0
,
0
,
bitmap2
.
getWidth
(),
bitmap2
.
getHeight
()),
new
Rect
(
0
,
0
,
w
,
h
),
null
);
return
newbBitmap
;
}
/**
* 保存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
;
}
}
app/src/main/java/com/dayu/bigfish/InitializeActivity.java
View file @
905c2635
...
...
@@ -112,9 +112,9 @@ public class InitializeActivity extends DataBindingActivity<ActivityInitializeMa
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
if
(
mDisposable
!=
null
)
{
mDisposable
.
dispose
();
}
//
if (mDisposable != null) {
//
mDisposable.dispose();
//
}
}
@TargetApi
(
23
)
...
...
messageCenter/src/main/java/com/dayu/message/ui/activity/MessageDetailActivity.java
View file @
905c2635
...
...
@@ -13,6 +13,8 @@ import com.dayu.message.databinding.ActivityMessageDetailBinding;
import
com.dayu.provider.common.ProviderConstant
;
import
com.dayu.provider.router.RouterPath
;
import
com.dayu.utils.GsonUtils
;
import
com.dayu.utils.ToastUtils
;
import
com.dayu.utils.UIUtils
;
import
com.dayu.utils.UtilsDate
;
import
com.umeng.analytics.MobclickAgent
;
...
...
@@ -39,6 +41,10 @@ public class MessageDetailActivity extends DataBindingActivity<ActivityMessageDe
public
void
initView
()
{
mBind
.
tvTitle
.
setText
(
getString
(
R
.
string
.
message_dayu_detail
));
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
);
mCategory
=
bundle
.
getInt
(
"category"
,
1
);
String
time
=
null
;
...
...
userCenter/src/main/java/com/dayu/usercenter/ui/activity/FaceCertificationActivity.java
View file @
905c2635
...
...
@@ -12,13 +12,15 @@ import com.dayu.usercenter.R;
import
com.dayu.usercenter.databinding.ActivityFaceCertificationBinding
;
import
com.dayu.usercenter.presenter.facecertification.FaceCertificaitonContract
;
import
com.dayu.usercenter.presenter.facecertification.FaceCertificaitonPresenter
;
import
com.dayu.utils.GlideImageLoader
;
import
com.dayu.utils.ToastUtils
;
import
com.megvii.idcardlib.LivenessActivity
;
import
com.megvii.idcardlib.util.ConUtil
;
import
com.megvii.licensemanager.Manager
;
import
com.megvii.livenessdetection.LivenessLicenseManager
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Map
;
...
...
@@ -94,21 +96,50 @@ public class FaceCertificationActivity extends BaseActivity<FaceCertificaitonPre
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
requestCode
==
PAGE_INTO_LIVENESS
&&
resultCode
==
RESULT_OK
)
{
boolean
isSuccess
=
false
;
String
delta
=
data
.
getStringExtra
(
"delta"
);
int
code
=
data
.
getIntExtra
(
"resultcode"
,
0
);
Map
<
String
,
byte
[]>
images
=
(
Map
<
String
,
byte
[]>)
data
.
getSerializableExtra
(
"images"
);
ArrayList
<
File
>
list
=
new
ArrayList
<>();
byte
[]
image_best
=
images
.
get
(
"image_best"
);
byte
[]
image_env
=
images
.
get
(
"image_env"
);
byte
[]
image_action1
=
images
.
get
(
"imageAction1"
);
byte
[]
image_action2
=
images
.
get
(
"imageAction2"
);
byte
[]
image_action3
=
images
.
get
(
"imageAction3"
);
list
.
add
(
GlideImageLoader
.
compressImage
(
BitmapFactory
.
decodeByteArray
(
image_best
,
0
,
image_best
.
length
),
"best"
));
list
.
add
(
GlideImageLoader
.
compressImage
(
BitmapFactory
.
decodeByteArray
(
image_env
,
0
,
image_best
.
length
),
"env"
));
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"
));
list
.
add
(
GlideImageLoader
.
compressImage
(
BitmapFactory
.
decodeByteArray
(
image_action3
,
0
,
image_best
.
length
),
"action3"
));
mPresenter
.
commitePhoto
(
list
,
delta
);
String
str
=
data
.
getStringExtra
(
"result"
);
try
{
JSONObject
result
=
new
JSONObject
(
str
);
int
resID
=
result
.
getInt
(
"resultcode"
);
checkID
(
resID
);
isSuccess
=
result
.
getString
(
"result"
).
equals
(
getResources
().
getString
(
R
.
string
.
verify_success
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
if
(
isSuccess
)
{
Map
<
String
,
byte
[]>
images
=
(
Map
<
String
,
byte
[]>)
data
.
getSerializableExtra
(
"images"
);
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
{
}
}
...
...
userCenter/src/main/java/com/dayu/usercenter/ui/activity/IdentityCertificationActivity.java
View file @
905c2635
...
...
@@ -89,6 +89,7 @@ public class IdentityCertificationActivity extends BaseActivity<CertificaitonPre
mBind
.
rlNext
.
setClickable
(
false
);
mBind
.
ivSideDelete
.
setVisibility
(
View
.
GONE
);
});
mBind
.
rlNext
.
setOnClickListener
(
v
->
mPresenter
.
commitePhoto
());
mBind
.
ivNext
.
setAlpha
(
0.5f
);
mBind
.
rlNext
.
setClickable
(
false
);
...
...
@@ -161,8 +162,10 @@ public class IdentityCertificationActivity extends BaseActivity<CertificaitonPre
if
(
requestCode
==
INTO_IDCARDSCAN_PAGE
&&
resultCode
==
RESULT_OK
)
{
runOnUiThread
(()
->
{
byte
[]
idcardImgData
=
data
.
getByteArrayExtra
(
"idcardImg"
);
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inSampleSize
=
2
;
Bitmap
idcardBmp
=
BitmapFactory
.
decodeByteArray
(
idcardImgData
,
0
,
idcardImgData
.
length
);
idcardImgData
.
length
,
options
);
if
(
mSide
==
0
)
{
mFrontBitmap
=
idcardBmp
;
mBind
.
ivFront
.
setImageBitmap
(
idcardBmp
);
...
...
userCenter/src/main/res/layout/activity_certification_layout.xml
View file @
905c2635
...
...
@@ -101,8 +101,7 @@
android:id=
"@+id/rl_next"
android:layout_width=
"match_parent"
android:layout_height=
"47dp"
android:layout_marginBottom=
"54dp"
android:onClick=
"@{()->presenter.commitePhoto()}"
>
android:layout_marginBottom=
"54dp"
>
<ImageView
android:id=
"@+id/iv_next"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment