Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
Scan QR Code Barcode Reader
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
Scan QR Code Barcode Reader
Commits
3e08a526
Commit
3e08a526
authored
Dec 25, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
093cb506
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
16 deletions
+87
-16
EmailCodeActivity.kt
...c/main/java/com/base/scanqr/ui/email/EmailCodeActivity.kt
+3
-1
HistoryAdapter.kt
app/src/main/java/com/base/scanqr/ui/main/HistoryAdapter.kt
+10
-2
ScanFragment.kt
app/src/main/java/com/base/scanqr/ui/main/ScanFragment.kt
+25
-0
QRCodeUtils.kt
app/src/main/java/com/base/scanqr/utils/QRCodeUtils.kt
+49
-13
No files found.
app/src/main/java/com/base/scanqr/ui/email/EmailCodeActivity.kt
View file @
3e08a526
...
...
@@ -36,8 +36,10 @@ class EmailCodeActivity : BaseActivity<ActivityEmailCodeBinding>(ActivityEmailCo
binding
.
tvSubject
.
text
=
email
.
subject
binding
.
tvMessage
.
text
=
email
.
message
//MATMSG:TO:xxxx;SUB:xxx;BODY:xxx;
val
qrContent
=
StringBuilder
()
qrContent
.
append
(
"MATMSG:TO:"
).
append
(
email
.
address
).
append
(
";"
)
qrContent
.
append
(
"MATMSG:"
)
qrContent
.
append
(
"TO:"
).
append
(
email
.
address
).
append
(
";"
)
qrContent
.
append
(
"SUB:"
).
append
(
email
.
subject
).
append
(
";"
)
qrContent
.
append
(
"BODY:"
).
append
(
email
.
message
).
append
(
";"
)
content
=
qrContent
.
toString
()
...
...
app/src/main/java/com/base/scanqr/ui/main/HistoryAdapter.kt
View file @
3e08a526
...
...
@@ -5,6 +5,7 @@ import android.text.format.DateUtils
import
android.view.View
import
android.view.ViewGroup
import
com.base.scanqr.R
import
com.base.scanqr.bean.EmailUIBean
import
com.base.scanqr.bean.FunctionUIBean.Companion.KEY_CONTACT
import
com.base.scanqr.bean.FunctionUIBean.Companion.KEY_EMAIL
import
com.base.scanqr.bean.FunctionUIBean.Companion.KEY_EVENT
...
...
@@ -15,6 +16,7 @@ import com.base.scanqr.bean.FunctionUIBean.Companion.KEY_TEXT
import
com.base.scanqr.bean.FunctionUIBean.Companion.KEY_WEBSITE
import
com.base.scanqr.bean.FunctionUIBean.Companion.KEY_WIFI
import
com.base.scanqr.bean.ScanBean
import
com.base.scanqr.bean.TextUIBean
import
com.base.scanqr.bean.WifiUIBean
import
com.base.scanqr.databinding.ItemHistoryBinding
import
com.base.scanqr.ui.adapter.CommonViewHolder
...
...
@@ -39,11 +41,17 @@ class HistoryAdapter : BaseQuickAdapter<ScanBean, CommonViewHolder>() {
}
KEY_TEXT
->
{
if
(
item
is
TextUIBean
)
{
binding
.
ivIcon
.
setImageResource
(
R
.
mipmap
.
h_text
)
binding
.
tvDesc
.
text
=
item
.
content
}
}
KEY_EMAIL
->
{
if
(
item
is
EmailUIBean
)
{
binding
.
ivIcon
.
setImageResource
(
R
.
mipmap
.
h_email
)
binding
.
tvDesc
.
text
=
item
.
address
}
}
KEY_EVENT
->
{
...
...
app/src/main/java/com/base/scanqr/ui/main/ScanFragment.kt
View file @
3e08a526
...
...
@@ -9,8 +9,11 @@ import android.widget.SeekBar
import
androidx.camera.core.ImageCapture.FLASH_MODE_ON
import
com.base.scanqr.R
import
com.base.scanqr.base.BaseFragment
import
com.base.scanqr.bean.TextUIBean
import
com.base.scanqr.databinding.FragmentScanBinding
import
com.base.scanqr.qr.QRImageAnalyzer
import
com.base.scanqr.ui.email.EmailCodeActivity
import
com.base.scanqr.ui.text.TextCodeActivity
import
com.base.scanqr.ui.wifi.WifiCodeActivity
import
com.base.scanqr.utils.IntentUtils.intentSafPickImage
import
com.base.scanqr.utils.LogEx
...
...
@@ -105,6 +108,28 @@ class ScanFragment : BaseFragment<FragmentScanBinding>(FragmentScanBinding::infl
})
return
}
if
(
QRCodeUtils
.
isEmailQR
(
qrCodeValue
))
{
if
(
scanJump
.
get
())
return
scanJump
.
set
(
true
)
activity
.
startActivity
(
Intent
(
activity
,
EmailCodeActivity
::
class
.
java
).
apply
{
val
bean
=
QRCodeUtils
.
createEmailBean
(
qrCodeValue
)
putExtra
(
"data"
,
Gson
().
toJson
(
bean
))
})
return
}
if
(
qrCodeValue
.
isEmpty
())
{
if
(
scanJump
.
get
())
return
scanJump
.
set
(
true
)
activity
.
startActivity
(
Intent
(
activity
,
TextCodeActivity
::
class
.
java
).
apply
{
val
bean
=
TextUIBean
()
bean
.
content
=
qrCodeValue
bean
.
isCreateOrScan
=
false
putExtra
(
"data"
,
Gson
().
toJson
(
bean
))
})
return
}
}
override
fun
onPause
()
{
...
...
app/src/main/java/com/base/scanqr/utils/QRCodeUtils.kt
View file @
3e08a526
...
...
@@ -2,6 +2,7 @@ package com.base.scanqr.utils
import
android.graphics.Bitmap
import
android.graphics.Color
import
com.base.scanqr.bean.EmailUIBean
import
com.base.scanqr.bean.WifiUIBean
import
com.google.zxing.BarcodeFormat
import
com.google.zxing.EncodeHintType
...
...
@@ -11,6 +12,8 @@ import com.google.zxing.qrcode.QRCodeWriter
object
QRCodeUtils
{
private
val
TAG
=
"QRCodeUtils"
// fun generateQRCode(content: String, width: Int, height: Int): Bitmap? {
// val writer = QRCodeWriter()
// val hints = EnumMap<EncodeHintType, Any>(EncodeHintType::class.java)
...
...
@@ -39,7 +42,7 @@ object QRCodeUtils {
val
hints
=
HashMap
<
EncodeHintType
,
Any
>()
hints
[
EncodeHintType
.
MARGIN
]
=
margin
// 设置二维码边距,默认为1
hints
[
EncodeHintType
.
ERROR_CORRECTION
]
=
com
.
google
.
zxing
.
qrcode
.
decoder
.
ErrorCorrectionLevel
.
L
// 设置二维码的容错级别
hints
[
EncodeHintType
.
CHARACTER_SET
]
=
"UTF-8"
// 设置字符集为UTF-8,确保中文可以正确编码
try
{
val
bitMatrix
:
BitMatrix
=
writer
.
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
width
,
height
,
hints
)
val
bitmapWidth
=
bitMatrix
.
width
+
margin
*
2
...
...
@@ -61,6 +64,18 @@ object QRCodeUtils {
return
null
}
private
fun
getPairKeyValue
(
keyValue
:
String
):
Pair
<
String
,
String
>
{
val
split
=
keyValue
.
split
(
":"
)
var
key
=
""
kotlin
.
runCatching
{
key
=
split
[
0
]
}
var
value
:
String
=
""
kotlin
.
runCatching
{
value
=
split
[
1
]
}
return
Pair
(
key
,
value
)
}
fun
isWifiQR
(
qrCodeValue
:
String
):
Boolean
{
val
flag
=
qrCodeValue
.
startsWith
(
"WIFI:"
)
...
...
@@ -71,11 +86,13 @@ object QRCodeUtils {
}
fun
createWifiBean
(
qrCodeValue
:
String
):
WifiUIBean
{
val
splitList
=
qrCodeValue
.
split
(
";"
)
val
startTag
=
"WIFI:"
val
subString
=
qrCodeValue
.
subSequence
(
startTag
.
length
,
qrCodeValue
.
length
)
LogEx
.
logDebug
(
TAG
,
"subString=$subString"
)
val
splitList
=
subString
.
split
(
";"
)
val
wifiUIBean
=
WifiUIBean
()
wifiUIBean
.
isCreateOrScan
=
false
wifiUIBean
.
createTime
=
System
.
currentTimeMillis
()
val
ssidKV
=
splitList
.
find
{
it
.
startsWith
(
"S:"
)
}
?:
""
wifiUIBean
.
ssid
=
getPairKeyValue
(
ssidKV
).
second
...
...
@@ -99,16 +116,35 @@ object QRCodeUtils {
return
wifiUIBean
}
fun
getPairKeyValue
(
keyValue
:
String
):
Pair
<
String
,
String
>
{
val
split
=
keyValue
.
split
(
":"
)
var
key
=
""
kotlin
.
runCatching
{
key
=
split
[
0
]
}
var
value
:
String
=
""
kotlin
.
runCatching
{
value
=
split
[
1
]
fun
isEmailQR
(
qrCodeValue
:
String
):
Boolean
{
val
flag
=
qrCodeValue
.
startsWith
(
"MATMSG:"
)
if
(
flag
)
{
return
true
}
return
Pair
(
key
,
value
)
return
false
}
//MATMSG:TO:179621228@qq.com;SUB:王雷;BODY:记得记得就觉得;
fun
createEmailBean
(
qrCodeValue
:
String
):
EmailUIBean
{
val
startTag
=
"MATMSG:"
val
subString
=
qrCodeValue
.
subSequence
(
startTag
.
length
,
qrCodeValue
.
length
)
LogEx
.
logDebug
(
TAG
,
"subString=$subString"
)
val
splitList
=
subString
.
split
(
";"
)
val
emailUIBean
=
EmailUIBean
()
emailUIBean
.
isCreateOrScan
=
false
val
addressKV
=
splitList
.
find
{
it
.
startsWith
(
"TO:"
)
}
?:
""
emailUIBean
.
address
=
getPairKeyValue
(
addressKV
).
second
val
subKV
=
splitList
.
find
{
it
.
startsWith
(
"SUB:"
)
}
?:
""
emailUIBean
.
subject
=
getPairKeyValue
(
subKV
).
second
val
bodyKV
=
splitList
.
find
{
it
.
startsWith
(
"BODY:"
)
}
?:
""
emailUIBean
.
message
=
getPairKeyValue
(
bodyKV
).
second
return
emailUIBean
}
}
\ No newline at end of file
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