Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
ShenghuoquanBusiness
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
ShenghuoquanBusiness
Commits
e8dd1930
Commit
e8dd1930
authored
May 25, 2021
by
yinjiacheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add 营业执照OCR
parent
f37b326e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
288 additions
and
2 deletions
+288
-2
XRouterPathConstants.kt
...n/src/main/java/com/yidian/common/XRouterPathConstants.kt
+1
-0
file_paths.xml
CommonLib/Common/src/main/res/xml/file_paths.xml
+1
-0
AndroidManifest.xml
Components/newscontent/src/main/AndroidManifest.xml
+3
-0
NewsContentApplication.kt
...an/shenghuoquan/newscontent/app/NewsContentApplication.kt
+13
-0
LifeAccountEnterpriseCertificationActivity.kt
...scontent/ui/LifeAccountEnterpriseCertificationActivity.kt
+230
-0
TempListActivity.kt
...om/yidian/shenghuoquan/newscontent/ui/TempListActivity.kt
+1
-1
activity_life_account_enterprise_certification.xml
...layout/activity_life_account_enterprise_certification.xml
+38
-0
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-1
No files found.
CommonLib/Common/src/main/java/com/yidian/common/XRouterPathConstants.kt
View file @
e8dd1930
...
...
@@ -32,5 +32,6 @@ class XRouterPathConstants {
const
val
LIFE_ACCOUNT_IDENTITY
=
"/lifeAccountIdentity"
const
val
LIFE_ACCOUNT_AUTH
=
"/lifeAccountAuth"
const
val
ID_CARD_TEST
=
"/idCardTest"
const
val
LIFE_ACCOUNT_ENTERPRISE_CERTIFICATION
=
"/lifeAccountEnterpriseCertification"
}
}
\ No newline at end of file
CommonLib/Common/src/main/res/xml/file_paths.xml
View file @
e8dd1930
...
...
@@ -4,4 +4,5 @@
<external-files-path
name=
"opensdk_external"
path=
"Images/tmp"
/>
<root-path
name=
"opensdk_root"
path=
""
/>
<external-cache-path
name=
"video_cache"
path=
"video_cache/"
/>
<external-cache-path
name=
"ocr"
path=
"ocr"
/>
</paths>
\ No newline at end of file
Components/newscontent/src/main/AndroidManifest.xml
View file @
e8dd1930
...
...
@@ -111,6 +111,9 @@
android:name=
".ui.LifeAccountAuthActivity"
android:theme=
"@style/Transparent"
/>
<activity
android:name=
".ui.LifeAccountEnterpriseCertificationActivity"
android:theme=
"@style/Transparent"
/>
</application>
</manifest>
\ No newline at end of file
Components/newscontent/src/main/java/com/yidian/shenghuoquan/newscontent/app/NewsContentApplication.kt
View file @
e8dd1930
...
...
@@ -20,6 +20,7 @@ import com.yidian.common.XRouterPathConstants.Companion.GALLERY
import
com.yidian.common.XRouterPathConstants.Companion.HOME
import
com.yidian.common.XRouterPathConstants.Companion.ID_CARD_TEST
import
com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_AUTH
import
com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_ENTERPRISE_CERTIFICATION
import
com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_IDENTITY
import
com.yidian.common.XRouterPathConstants.Companion.LOGIN_LIFE_CIRCLE
import
com.yidian.common.XRouterPathConstants.Companion.NEWS_CONTENT
...
...
@@ -157,6 +158,18 @@ class NewsContentApplication : YdBaseApplication() {
}
}),
XPageNode
(
LIFE_ACCOUNT_ENTERPRISE_CERTIFICATION
,
XPageNodePageType
.
NATIVE
,
object
:
XPageHandler
{
override
fun
handler
(
params
:
Map
<
String
,
Any
?
>?)
{
val
intent
=
Intent
()
if
(
params
!=
null
)
{
intent
.
putExtra
(
XRouterPathConstants
.
ParamsKey
,
params
as
HashMap
)
}
intent
.
setClass
(
context
,
LifeAccountEnterpriseCertificationActivity
::
class
.
java
)
intent
.
flags
=
Intent
.
FLAG_ACTIVITY_NEW_TASK
context
.
startActivity
(
intent
)
}
}),
XPageNode
(
NEWS_CONTENT
,
XPageNodePageType
.
NATIVE
,
object
:
XPageHandler
{
override
fun
handler
(
params
:
Map
<
String
,
Any
?
>?)
{
val
intent
=
Intent
()
...
...
Components/newscontent/src/main/java/com/yidian/shenghuoquan/newscontent/ui/LifeAccountEnterpriseCertificationActivity.kt
0 → 100644
View file @
e8dd1930
package
com.yidian.shenghuoquan.newscontent.ui
import
android.app.Activity
import
android.content.ContentResolver
import
android.content.Intent
import
android.graphics.Bitmap
import
android.graphics.BitmapFactory
import
android.net.Uri
import
android.os.Build
import
android.os.Bundle
import
android.os.FileUtils
import
android.provider.MediaStore
import
android.util.Log
import
androidx.core.content.FileProvider
import
com.yidian.common.XRouterPathConstants
import
com.yidian.common.base.BaseActivity
import
com.yidian.shenghuoquan.newscontent.databinding.ActivityLifeAccountEnterpriseCertificationBinding
import
com.yidian.shenghuoquan.newscontent.http.ApiService
import
com.yidian.shenghuoquan.newscontent.http.httpbean.BusinessLicenseOCRBean
import
com.yidian.shenghuoquan.newscontent.http.httpbean.IBusinessLicenseOCRCallback
import
com.yidian.shenghuoquan.newscontent.utils.KS3Core
import
java.io.File
import
java.io.FileOutputStream
/**
* author: yinjiacheng
* date: 5/24/21 3:15 PM
* description: 企业生活号认证
*/
class
LifeAccountEnterpriseCertificationActivity
:
BaseActivity
<
ActivityLifeAccountEnterpriseCertificationBinding
>()
{
companion
object
{
private
const
val
TAG
=
"BusinessLicenseOCR"
private
const
val
REQUEST_CODE_PERMISSIONS
=
1000
//权限
private
const
val
REQUEST_CODE_ALBUM
=
1001
//相册
private
const
val
REQUEST_CODE_CAMERA
=
1002
//相机
private
const
val
FILE_PATH_BUSINESS_LICENSE_CAMERA
=
"/ocr/business_license_camera.jpg"
private
const
val
FILE_PATH_BUSINESS_LICENSE
=
"/ocr/business_license.jpg"
}
/**
* 调用系统相机拍照,照片Uri
*/
private
lateinit
var
photoUri
:
Uri
/**
* 营业执照文件路径
*/
private
var
filePath
:
String
?
=
null
override
fun
createViewBinding
():
ActivityLifeAccountEnterpriseCertificationBinding
{
return
ActivityLifeAccountEnterpriseCertificationBinding
.
inflate
(
layoutInflater
)
}
override
fun
getXPageName
():
String
{
return
XRouterPathConstants
.
LIFE_ACCOUNT_ENTERPRISE_CERTIFICATION
}
override
fun
init
(
savedInstanceState
:
Bundle
?)
{
super
.
init
(
savedInstanceState
)
initListener
()
}
private
fun
initListener
()
{
viewBind
.
btnOpenAlbum
.
setOnClickListener
{
// 打开系统相册
val
intent
=
Intent
()
intent
.
action
=
Intent
.
ACTION_PICK
intent
.
setDataAndType
(
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
,
"image/*"
)
startActivityForResult
(
intent
,
REQUEST_CODE_ALBUM
)
}
viewBind
.
btnTakePhoto
.
setOnClickListener
{
val
file
=
File
(
externalCacheDir
?.
absolutePath
+
FILE_PATH_BUSINESS_LICENSE_CAMERA
)
if
(
file
.
exists
())
{
file
.
delete
()
}
else
{
file
.
parentFile
?.
mkdirs
()
file
.
createNewFile
()
}
photoUri
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
//适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri
FileProvider
.
getUriForFile
(
this
,
"$packageName.provider"
,
file
)
}
else
{
Uri
.
fromFile
(
file
)
}
val
intent
=
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
)
//android11以后强制分区存储,外部资源无法访问,所以添加一个输出保存位置,然后取值操作
intent
.
putExtra
(
MediaStore
.
EXTRA_OUTPUT
,
photoUri
)
startActivityForResult
(
intent
,
REQUEST_CODE_CAMERA
)
}
viewBind
.
btnOcr
.
setOnClickListener
{
KS3Core
.
INSTANCE
.
uploadObject
(
generateUploadFile
(
filePath
),
KS3Core
.
ObjectType
.
IMAGE
,
object
:
KS3Core
.
OnKS3TaskListener
{
override
fun
onTaskStart
()
{
}
override
fun
onTaskProgress
(
progress
:
Double
)
{
}
override
fun
onTaskFinish
()
{
}
override
fun
onTaskCancel
()
{
}
override
fun
onTaskSuccess
(
bucket
:
String
?,
objectKey
:
String
?)
{
val
request
=
BusinessLicenseOCRBean
.
Request
(
objectKey
)
ApiService
.
businessLicenseOCR
(
object
:
IBusinessLicenseOCRCallback
{
override
fun
businessLicenseOCRSuccess
(
result
:
BusinessLicenseOCRBean
.
Response
?)
{
Log
.
d
(
TAG
,
"name: ${result?.name}, code: ${result?.code}"
)
}
override
fun
businessLicenseOCRFailure
(
message
:
String
?)
{
}
},
request
)
}
override
fun
onTaskFailure
(
statesCode
:
Int
,
message
:
String
?)
{
}
})
}
}
/**
* 通过Uri获取文件圈路径
*/
private
fun
getFilePathFromUri
(
uri
:
Uri
?):
String
?
{
val
filePath
=
externalCacheDir
?.
absolutePath
+
FILE_PATH_BUSINESS_LICENSE
val
file
=
File
(
filePath
)
if
(
file
.
exists
())
{
file
.
delete
()
}
else
{
// 相册
file
.
parentFile
?.
mkdirs
()
file
.
createNewFile
()
}
return
when
(
uri
?.
scheme
)
{
ContentResolver
.
SCHEME_CONTENT
->
{
val
inputStream
=
contentResolver
.
openInputStream
(
uri
)
val
fileOutputStream
=
FileOutputStream
(
file
)
inputStream
?.
let
{
FileUtils
.
copy
(
it
,
fileOutputStream
)
}
inputStream
?.
close
()
fileOutputStream
.
close
()
filePath
}
else
->
{
uri
?.
path
}
}
}
/**
* 生成金山云上传文件
*/
private
fun
generateUploadFile
(
filePath
:
String
?):
File
{
BitmapFactory
.
decodeFile
(
filePath
)
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
10
,
FileOutputStream
(
filePath
))
return
File
(
filePath
)
}
/**
* 根据容器大小生成Bitmap
*
* @param filePath 本地文件路径
*/
private
fun
generateBitmap
(
filePath
:
String
?):
Bitmap
?
{
val
options
=
BitmapFactory
.
Options
()
options
.
inJustDecodeBounds
=
true
BitmapFactory
.
decodeFile
(
filePath
,
options
)
options
.
inSampleSize
=
calculateInSampleSize
(
options
,
viewBind
.
ivImage
.
width
,
viewBind
.
ivImage
.
height
)
options
.
inJustDecodeBounds
=
false
return
BitmapFactory
.
decodeFile
(
filePath
,
options
)
}
/**
* 计算Bitmap inSampleSize
*
* @param targetWidth 容器宽
* @param targetHeight 容器高
*/
private
fun
calculateInSampleSize
(
options
:
BitmapFactory
.
Options
,
targetWidth
:
Int
,
targetHeight
:
Int
):
Int
{
val
sourceWidth
=
options
.
outWidth
val
sourceHeight
=
options
.
outHeight
var
inSampleSize
=
1
if
(
sourceWidth
>
targetWidth
||
sourceHeight
>
targetHeight
)
{
val
halfWidth
=
sourceWidth
/
2
val
halfHeight
=
sourceHeight
/
2
// 压缩后的尺寸与所需的尺寸进行比较
while
(
halfWidth
/
inSampleSize
>=
targetWidth
&&
halfHeight
/
inSampleSize
>=
targetHeight
)
{
inSampleSize
*=
2
}
}
return
inSampleSize
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
when
(
requestCode
)
{
REQUEST_CODE_ALBUM
->
{
filePath
=
getFilePathFromUri
(
data
?.
data
)
viewBind
.
ivImage
.
setImageBitmap
(
generateBitmap
(
filePath
))
}
REQUEST_CODE_CAMERA
->
{
filePath
=
getFilePathFromUri
(
photoUri
)
viewBind
.
ivImage
.
setImageBitmap
(
generateBitmap
(
filePath
))
}
}
}
}
}
\ No newline at end of file
Components/newscontent/src/main/java/com/yidian/shenghuoquan/newscontent/ui/TempListActivity.kt
View file @
e8dd1930
...
...
@@ -32,7 +32,7 @@ class TempListActivity : BaseActivity<ActivityTempListBinding>() {
}
viewBind
.
btBusinessLicense
.
setOnClickListener
{
startActivity
(
Intent
(
this
@TempListActivity
,
AliveTest
Activity
::
class
.
java
))
startActivity
(
Intent
(
this
@TempListActivity
,
LifeAccountEnterpriseCertification
Activity
::
class
.
java
))
}
}
}
\ No newline at end of file
Components/newscontent/src/main/res/layout/activity_life_account_enterprise_certification.xml
0 → 100644
View file @
e8dd1930
<?xml version="1.0" encoding="utf-8"?>
<com.yidian.nightmode.widget.YdConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<com.yidian.nightmode.widget.YdButton
android:id=
"@+id/btn_open_album"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"100dp"
android:text=
"打开系统相册"
app:layout_constraintTop_toTopOf=
"parent"
/>
<com.yidian.nightmode.widget.YdButton
android:id=
"@+id/btn_take_photo"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"20dp"
android:text=
"拍照"
app:layout_constraintTop_toBottomOf=
"@id/btn_open_album"
/>
<com.yidian.nightmode.widget.YdImageView
android:id=
"@+id/iv_image"
android:layout_width=
"match_parent"
android:layout_height=
"300dp"
android:layout_marginTop=
"20dp"
app:layout_constraintTop_toBottomOf=
"@id/btn_take_photo"
/>
<com.yidian.nightmode.widget.YdButton
android:id=
"@+id/btn_ocr"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"20dp"
android:text=
"营业执照OCR"
app:layout_constraintTop_toBottomOf=
"@id/iv_image"
/>
</com.yidian.nightmode.widget.YdConstraintLayout>
\ No newline at end of file
app/src/main/AndroidManifest.xml
View file @
e8dd1930
...
...
@@ -34,7 +34,7 @@
<!-- 以下为友盟分享基本配置信息 start-->
<provider
android:name=
"androidx.core.content.FileProvider"
android:authorities=
"com.
yidian.subway
.provider"
android:authorities=
"com.
shenghuoquan.business
.provider"
android:exported=
"false"
android:grantUriPermissions=
"true"
>
<meta-data
...
...
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