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
78413444
Commit
78413444
authored
Jun 11, 2018
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine scanner
parent
4ad046a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
21 deletions
+38
-21
mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt
...e/src/main/java/com/github/shadowsocks/ScannerActivity.kt
+37
-19
mobile/src/main/res/layout/layout_scanner.xml
mobile/src/main/res/layout/layout_scanner.xml
+1
-2
No files found.
mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt
View file @
78413444
...
...
@@ -40,6 +40,7 @@ import com.github.shadowsocks.App.Companion.app
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.utils.resolveResourceId
import
com.google.android.gms.common.GoogleApiAvailability
import
com.google.android.gms.samples.vision.barcodereader.BarcodeCapture
import
com.google.android.gms.samples.vision.barcodereader.BarcodeGraphic
import
com.google.android.gms.vision.Frame
...
...
@@ -52,8 +53,11 @@ class ScannerActivity : AppCompatActivity(), Toolbar.OnMenuItemClickListener, Ba
private
const
val
TAG
=
"ScannerActivity"
private
const
val
REQUEST_IMPORT
=
2
private
const
val
REQUEST_IMPORT_OR_FINISH
=
3
private
const
val
REQUEST_GOOGLE_API
=
4
}
private
lateinit
var
detector
:
BarcodeDetector
private
fun
navigateUp
()
{
val
intent
=
parentActivityIntent
if
(
shouldUpRecreateTask
(
intent
)
||
isTaskRoot
)
...
...
@@ -63,6 +67,23 @@ class ScannerActivity : AppCompatActivity(), Toolbar.OnMenuItemClickListener, Ba
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
detector
=
BarcodeDetector
.
Builder
(
this
)
.
setBarcodeFormats
(
Barcode
.
QR_CODE
)
.
build
()
if
(!
detector
.
isOperational
)
{
val
availability
=
GoogleApiAvailability
.
getInstance
()
val
dialog
=
availability
.
getErrorDialog
(
this
,
availability
.
isGooglePlayServicesAvailable
(
this
),
REQUEST_GOOGLE_API
)
if
(
dialog
==
null
)
{
Toast
.
makeText
(
this
,
R
.
string
.
common_google_play_services_notification_ticker
,
Toast
.
LENGTH_SHORT
)
.
show
()
finish
()
}
else
{
dialog
.
setOnDismissListener
{
finish
()
}
dialog
.
show
()
}
return
}
if
(
Build
.
VERSION
.
SDK_INT
>=
25
)
getSystemService
(
ShortcutManager
::
class
.
java
).
reportShortcutUsed
(
"scan"
)
if
(
try
{
(
getSystemService
(
Context
.
CAMERA_SERVICE
)
as
CameraManager
).
cameraIdList
.
isEmpty
()
...
...
@@ -79,7 +100,9 @@ class ScannerActivity : AppCompatActivity(), Toolbar.OnMenuItemClickListener, Ba
toolbar
.
setNavigationOnClickListener
{
navigateUp
()
}
toolbar
.
inflateMenu
(
R
.
menu
.
scanner_menu
)
toolbar
.
setOnMenuItemClickListener
(
this
)
(
supportFragmentManager
.
findFragmentById
(
R
.
id
.
barcode
)
as
BarcodeCapture
).
setRetrieval
(
this
)
val
capture
=
supportFragmentManager
.
findFragmentById
(
R
.
id
.
barcode
)
as
BarcodeCapture
capture
.
setCustomDetector
(
detector
)
capture
.
setRetrieval
(
this
)
}
override
fun
onRetrieved
(
barcode
:
Barcode
)
=
runOnUiThread
{
...
...
@@ -112,25 +135,20 @@ class ScannerActivity : AppCompatActivity(), Toolbar.OnMenuItemClickListener, Ba
when
(
requestCode
)
{
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
)
val
clipData
=
data
?.
clipData
if
(
clipData
!=
null
)
list
+=
(
0
until
clipData
.
itemCount
).
map
{
clipData
.
getItemAt
(
it
).
uri
}
val
resolver
=
contentResolver
for
(
uri
in
list
)
try
{
val
barcodes
=
detector
.
detect
(
Frame
.
Builder
()
.
setBitmap
(
BitmapFactory
.
decodeStream
(
resolver
.
openInputStream
(
uri
))).
build
())
for
(
i
in
0
until
barcodes
.
size
())
Profile
.
findAll
(
barcodes
.
valueAt
(
i
).
rawValue
).
forEach
{
ProfileManager
.
createProfile
(
it
)
success
=
true
}
}
catch
(
e
:
Exception
)
{
app
.
track
(
e
)
var
list
=
listOfNotNull
(
data
?.
data
)
val
clipData
=
data
?.
clipData
if
(
clipData
!=
null
)
list
+=
(
0
until
clipData
.
itemCount
).
map
{
clipData
.
getItemAt
(
it
).
uri
}
val
resolver
=
contentResolver
for
(
uri
in
list
)
try
{
val
barcodes
=
detector
.
detect
(
Frame
.
Builder
()
.
setBitmap
(
BitmapFactory
.
decodeStream
(
resolver
.
openInputStream
(
uri
))).
build
())
for
(
i
in
0
until
barcodes
.
size
())
Profile
.
findAll
(
barcodes
.
valueAt
(
i
).
rawValue
).
forEach
{
ProfileManager
.
createProfile
(
it
)
success
=
true
}
}
else
Log
.
w
(
TAG
,
"Google vision isn't operational."
)
}
catch
(
e
:
Exception
)
{
app
.
track
(
e
)
}
Toast
.
makeText
(
this
,
if
(
success
)
R
.
string
.
action_import_msg
else
R
.
string
.
action_import_err
,
Toast
.
LENGTH_SHORT
).
show
()
navigateUp
()
...
...
mobile/src/main/res/layout/layout_scanner.xml
View file @
78413444
...
...
@@ -11,6 +11,5 @@
android:name=
"com.google.android.gms.samples.vision.barcodereader.BarcodeCapture"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
app:gvb_auto_focus=
"true"
app:gvb_code_format=
"qr_code"
/>
app:gvb_auto_focus=
"true"
/>
</LinearLayout>
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