Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
208d5369
Commit
208d5369
authored
Jun 29, 2020
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine Scanner
parent
717d3a16
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt
...e/src/main/java/com/github/shadowsocks/ScannerActivity.kt
+10
-10
No files found.
mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt
View file @
208d5369
...
...
@@ -23,8 +23,6 @@ package com.github.shadowsocks
import
android.Manifest
import
android.content.Intent
import
android.content.pm.ShortcutManager
import
android.hardware.camera2.CameraAccessException
import
android.hardware.camera2.CameraManager
import
android.net.Uri
import
android.os.Build
import
android.os.Bundle
...
...
@@ -84,25 +82,27 @@ class ScannerActivity : AppCompatActivity(), ImageAnalysis.Analyzer {
super
.
onCreate
(
savedInstanceState
)
if
(
Build
.
VERSION
.
SDK_INT
<
23
)
return
startImport
()
// we show no love to lollipop
if
(
Build
.
VERSION
.
SDK_INT
>=
25
)
getSystemService
<
ShortcutManager
>()
!!
.
reportShortcutUsed
(
"scan"
)
if
(
try
{
getSystemService
<
CameraManager
>()
?.
cameraIdList
?.
isEmpty
()
}
catch
(
_
:
CameraAccessException
)
{
true
}
!=
false
)
return
startImport
()
setContentView
(
R
.
layout
.
layout_scanner
)
ListHolderListener
.
setup
(
this
)
setSupportActionBar
(
findViewById
(
R
.
id
.
toolbar
))
supportActionBar
!!
.
setDisplayHomeAsUpEnabled
(
true
)
lifecycle
.
addObserver
(
scanner
)
requestCamera
.
launch
(
Manifest
.
permission
.
CAMERA
)
}
private
val
requestCamera
=
registerForActivityResult
(
ActivityResultContracts
.
RequestPermission
())
{
granted
->
if
(
granted
)
lifecycleScope
.
launchWhenCreated
{
val
cameraProvider
=
ProcessCameraProvider
.
getInstance
(
this
@ScannerActivity
).
await
()
val
selector
=
if
(
cameraProvider
.
hasCamera
(
CameraSelector
.
DEFAULT_BACK_CAMERA
))
{
CameraSelector
.
DEFAULT_BACK_CAMERA
}
else
CameraSelector
.
DEFAULT_FRONT_CAMERA
val
preview
=
Preview
.
Builder
().
build
()
preview
.
setSurfaceProvider
(
findViewById
<
PreviewView
>(
R
.
id
.
barcode
).
createSurfaceProvider
())
cameraProvider
.
bindToLifecycle
(
this
@ScannerActivity
,
CameraSelector
.
Builder
().
apply
{
requireLensFacing
(
CameraSelector
.
LENS_FACING_BACK
)
}.
build
(),
preview
,
imageAnalysis
)
try
{
cameraProvider
.
bindToLifecycle
(
this
@ScannerActivity
,
selector
,
preview
,
imageAnalysis
)
}
catch
(
e
:
IllegalArgumentException
)
{
Timber
.
d
(
e
)
startImport
()
}
}
else
permissionMissing
()
}
...
...
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