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
22ffcc53
Commit
22ffcc53
authored
Feb 11, 2018
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine QR code decoding
parent
b69c20d0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
18 deletions
+19
-18
mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt
...e/src/main/java/com/github/shadowsocks/ScannerActivity.kt
+19
-18
No files found.
mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt
View file @
22ffcc53
...
@@ -35,6 +35,7 @@ import android.support.v4.app.TaskStackBuilder
...
@@ -35,6 +35,7 @@ import android.support.v4.app.TaskStackBuilder
import
android.support.v4.content.ContextCompat
import
android.support.v4.content.ContextCompat
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.widget.Toolbar
import
android.support.v7.widget.Toolbar
import
android.util.Log
import
android.view.MenuItem
import
android.view.MenuItem
import
android.widget.Toast
import
android.widget.Toast
import
com.github.shadowsocks.App.Companion.app
import
com.github.shadowsocks.App.Companion.app
...
@@ -140,26 +141,26 @@ class ScannerActivity : AppCompatActivity(), ZXingScannerView.ResultHandler, Too
...
@@ -140,26 +141,26 @@ class ScannerActivity : AppCompatActivity(), ZXingScannerView.ResultHandler, Too
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
when
(
requestCode
)
{
when
(
requestCode
)
{
REQUEST_IMPORT
,
REQUEST_IMPORT_OR_FINISH
->
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
REQUEST_IMPORT
,
REQUEST_IMPORT_OR_FINISH
->
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
var
success
=
false
val
detector
=
BarcodeDetector
.
Builder
(
this
)
.
setBarcodeFormats
(
Barcode
.
QR_CODE
)
.
build
()
if
(
detector
.
isOperational
)
{
var
list
=
listOfNotNull
(
data
?.
data
)
var
list
=
listOfNotNull
(
data
?.
data
)
val
clipData
=
data
?.
clipData
val
clipData
=
data
?.
clipData
if
(
clipData
!=
null
)
list
+=
(
0
until
clipData
.
itemCount
).
map
{
clipData
.
getItemAt
(
it
).
uri
}
if
(
clipData
!=
null
)
list
+=
(
0
until
clipData
.
itemCount
).
map
{
clipData
.
getItemAt
(
it
).
uri
}
val
resolver
=
contentResolver
val
resolver
=
contentResolver
var
success
=
false
val
detector
=
BarcodeDetector
.
Builder
(
getApplicationContext
())
.
setBarcodeFormats
(
Barcode
.
DATA_MATRIX
or
Barcode
.
QR_CODE
)
.
build
()
for
(
uri
in
list
)
try
{
for
(
uri
in
list
)
try
{
val
bitmap
=
BitmapFactory
.
decodeStream
(
resolver
.
openInputStream
(
uri
))
val
barcodes
=
detector
.
detect
(
Frame
.
Builder
()
val
frame
=
Frame
.
Builder
().
setBitmap
(
bitmap
).
build
()
.
setBitmap
(
BitmapFactory
.
decodeStream
(
resolver
.
openInputStream
(
uri
))).
build
())
val
barcodes
=
detector
.
detect
(
frame
)
for
(
i
in
0
until
barcodes
.
size
())
Profile
.
findAll
(
barcodes
.
valueAt
(
i
).
rawValue
).
forEach
{
val
value
=
barcodes
.
valueAt
(
0
).
rawValue
Profile
.
findAll
(
value
).
forEach
{
ProfileManager
.
createProfile
(
it
)
ProfileManager
.
createProfile
(
it
)
success
=
true
success
=
true
}
}
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
app
.
track
(
e
)
app
.
track
(
e
)
}
}
}
else
Log
.
w
(
"ScannerActivity"
,
"Google vision isn't operational."
)
Toast
.
makeText
(
this
,
if
(
success
)
R
.
string
.
action_import_msg
else
R
.
string
.
action_import_err
,
Toast
.
makeText
(
this
,
if
(
success
)
R
.
string
.
action_import_msg
else
R
.
string
.
action_import_err
,
Toast
.
LENGTH_SHORT
).
show
()
Toast
.
LENGTH_SHORT
).
show
()
finish
()
finish
()
...
...
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