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
c314a02e
Commit
c314a02e
authored
Jan 07, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
b3d0d4a3
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
249 additions
and
258 deletions
+249
-258
WifiUIBean.kt
app/src/main/java/com/base/scanqr/bean/WifiUIBean.kt
+24
-0
AdConfigBean.kt
...src/main/java/com/base/scanqr/bean/config/AdConfigBean.kt
+1
-1
ContractCodeActivity.kt
...n/java/com/base/scanqr/ui/contact/ContractCodeActivity.kt
+16
-25
EmailCodeActivity.kt
...c/main/java/com/base/scanqr/ui/email/EmailCodeActivity.kt
+15
-24
EventCodeActivity.kt
...c/main/java/com/base/scanqr/ui/event/EventCodeActivity.kt
+15
-24
LocationCodeActivity.kt
.../java/com/base/scanqr/ui/location/LocationCodeActivity.kt
+10
-16
MainActivity.kt
app/src/main/java/com/base/scanqr/ui/main/MainActivity.kt
+30
-10
MessageCodeActivity.kt
...in/java/com/base/scanqr/ui/message/MessageCodeActivity.kt
+16
-23
ProductCodeActivity.kt
...in/java/com/base/scanqr/ui/product/ProductCodeActivity.kt
+14
-20
TelephoneCodeActivity.kt
...ava/com/base/scanqr/ui/telephone/TelephoneCodeActivity.kt
+15
-23
TextCodeActivity.kt
...src/main/java/com/base/scanqr/ui/text/TextCodeActivity.kt
+12
-20
QrViewModel.kt
app/src/main/java/com/base/scanqr/ui/vm/QrViewModel.kt
+35
-0
WebsiteCodeActivity.kt
...in/java/com/base/scanqr/ui/website/WebsiteCodeActivity.kt
+15
-20
WifiCodeActivity.kt
...src/main/java/com/base/scanqr/ui/wifi/WifiCodeActivity.kt
+31
-52
No files found.
app/src/main/java/com/base/scanqr/bean/WifiUIBean.kt
View file @
c314a02e
package
com.base.scanqr.bean
import
com.base.scanqr.bean.FunctionUIBean.Companion.KEY_WIFI
import
com.base.scanqr.utils.LogEx
import
com.base.scanqr.utils.QRCodeUtils.getPairKeyValue
...
...
@@ -22,6 +23,29 @@ data class WifiUIBean(
return
false
}
fun
createWifiQRString
(
bean
:
WifiUIBean
):
String
{
val
content
=
StringBuilder
()
content
.
append
(
"WIFI:"
)
content
.
append
(
"T:"
)
if
(
bean
.
securityId
==
0
)
{
content
.
append
(
"WPA/WPA2"
).
append
(
";"
)
}
if
(
bean
.
securityId
==
1
)
{
content
.
append
(
"WEP"
).
append
(
";"
)
}
if
(
bean
.
securityId
==
2
)
{
content
.
append
(
";"
)
}
content
.
append
(
"S:"
)
content
.
append
(
bean
.
ssid
).
append
(
";"
)
content
.
append
(
"P:"
)
content
.
append
(
bean
.
password
).
append
(
";"
)
content
.
append
(
"H:"
)
content
.
append
(
bean
.
hidden
).
append
(
";"
)
return
content
.
toString
()
}
fun
createWifiBean
(
qrCodeValue
:
String
):
WifiUIBean
{
val
startTag
=
"WIFI:"
val
subString
=
qrCodeValue
.
subSequence
(
startTag
.
length
,
qrCodeValue
.
length
)
...
...
app/src/main/java/com/base/scanqr/bean/config/AdConfigBean.kt
View file @
c314a02e
...
...
@@ -9,7 +9,7 @@ class AdConfigBean(
var
openAdLoading
:
Int
=
15
,
var
functionBackShowAd
:
Boolean
=
true
,
var
functionInShowAd
:
Boolean
=
true
,
var
createFgInterval
:
Int
=
1
,
var
tabFgInterval
:
Int
=
15
,
)
{
companion
object
{
/**
...
...
app/src/main/java/com/base/scanqr/ui/contact/ContractCodeActivity.kt
View file @
c314a02e
package
com.base.scanqr.ui.contact
import
android.Manifest
import
android.os.Environment
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
androidx.lifecycle.ViewModelProvider
import
com.base.scanqr.R
import
com.base.scanqr.ads.AdsMgr
import
com.base.scanqr.ads.AdsShowCallBack
...
...
@@ -11,6 +10,7 @@ import com.base.scanqr.base.BaseActivity
import
com.base.scanqr.bean.ContractUIBean
import
com.base.scanqr.bean.FunctionUIBean
import
com.base.scanqr.databinding.ActivityContractCodeBinding
import
com.base.scanqr.ui.vm.QrViewModel
import
com.base.scanqr.ui.widget.InputNameDialog.showInputNameDialog
import
com.base.scanqr.utils.BarUtils
import
com.base.scanqr.utils.BitmapUtils.saveBitmapToFile
...
...
@@ -28,8 +28,12 @@ class ContractCodeActivity : BaseActivity<ActivityContractCodeBinding>(ActivityC
private
var
contractUIBean
=
ContractUIBean
()
private
var
tempImage
:
String
=
""
private
var
contractQrString
=
""
private
var
tempImagePath
:
String
=
""
private
var
qrString
=
""
private
val
viewModel
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
ViewModelProvider
(
this
)[
QrViewModel
::
class
.
java
]
}
override
fun
onResumeOneShoot
()
{
super
.
onResumeOneShoot
()
...
...
@@ -54,9 +58,9 @@ class ContractCodeActivity : BaseActivity<ActivityContractCodeBinding>(ActivityC
binding
.
tvAddress
.
text
=
contractUIBean
.
adr
}
Thread
{
contractQ
rString
=
ContractUIBean
.
createContractQrString
(
contractUIBean
)
LogEx
.
logDebug
(
TAG
,
"contractQrString=$
contractQ
rString"
)
val
bitmap
=
generateQRCode
(
contractQ
rString
,
735
,
735
,
5
)
q
rString
=
ContractUIBean
.
createContractQrString
(
contractUIBean
)
LogEx
.
logDebug
(
TAG
,
"contractQrString=$
q
rString"
)
val
bitmap
=
generateQRCode
(
q
rString
,
735
,
735
,
5
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
val
file
=
File
(
cacheDir
,
System
.
currentTimeMillis
().
toString
()
+
".jpg"
)
...
...
@@ -64,7 +68,7 @@ class ContractCodeActivity : BaseActivity<ActivityContractCodeBinding>(ActivityC
val
flag
=
saveBitmapToFile
(
it
,
file
.
absolutePath
)
LogEx
.
logDebug
(
TAG
,
"flag=$flag tempImage=${file.absolutePath}"
)
if
(
flag
)
{
tempImage
=
file
.
absolutePath
tempImage
Path
=
file
.
absolutePath
}
}
if
(
contractUIBean
.
needCreate
)
{
...
...
@@ -96,7 +100,7 @@ class ContractCodeActivity : BaseActivity<ActivityContractCodeBinding>(ActivityC
onBackPressedDispatcher
.
onBackPressed
()
}
binding
.
llShare
.
setOnClickListener
{
val
intent
=
intentShareImage
(
this
,
tempImage
)
val
intent
=
intentShareImage
(
this
,
tempImage
Path
)
runCatching
{
startActivity
(
intent
)
}
...
...
@@ -106,27 +110,14 @@ class ContractCodeActivity : BaseActivity<ActivityContractCodeBinding>(ActivityC
}
binding
.
llDownload
.
setOnClickListener
{
kotlin
.
runCatching
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
this
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
File
(
tempImage
).
name
val
newName
=
File
(
tempImagePath
).
name
showInputNameDialog
(
newName
)
{
name
->
if
(
name
.
endsWith
(
".jpg"
))
{
name
.
also
{
newName
=
it
}
}
else
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
downFile
.
createNewFile
()
File
(
tempImage
).
copyTo
(
downFile
,
true
)
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
viewModel
.
copyFileToDownloads
(
this
,
name
,
tempImagePath
)
}
}
}
binding
.
llCopy
.
setOnClickListener
{
copyText
(
TAG
,
contractQ
rString
)
copyText
(
TAG
,
q
rString
)
toast
(
"Copied to clipboard"
,
true
)
}
binding
.
flSearch
.
setOnClickListener
{
...
...
app/src/main/java/com/base/scanqr/ui/email/EmailCodeActivity.kt
View file @
c314a02e
package
com.base.scanqr.ui.email
import
android.os.Environment
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
androidx.lifecycle.ViewModelProvider
import
com.base.scanqr.R
import
com.base.scanqr.ads.AdsMgr
import
com.base.scanqr.ads.AdsShowCallBack
...
...
@@ -11,6 +11,7 @@ import com.base.scanqr.bean.EmailUIBean
import
com.base.scanqr.bean.EmailUIBean.Companion.createEmailQrString
import
com.base.scanqr.bean.FunctionUIBean.Companion.KEY_EMAIL
import
com.base.scanqr.databinding.ActivityEmailCodeBinding
import
com.base.scanqr.ui.vm.QrViewModel
import
com.base.scanqr.ui.widget.InputNameDialog.showInputNameDialog
import
com.base.scanqr.utils.BarUtils
import
com.base.scanqr.utils.BitmapUtils.saveBitmapToFile
...
...
@@ -27,8 +28,12 @@ import java.io.File
class
EmailCodeActivity
:
BaseActivity
<
ActivityEmailCodeBinding
>(
ActivityEmailCodeBinding
::
inflate
)
{
private
var
email
=
EmailUIBean
()
private
var
tempImage
:
String
=
""
private
var
emailQrString
:
String
=
""
private
var
tempImagePath
:
String
=
""
private
var
qrString
:
String
=
""
private
val
viewModel
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
ViewModelProvider
(
this
)[
QrViewModel
::
class
.
java
]
}
override
fun
onResumeOneShoot
()
{
super
.
onResumeOneShoot
()
...
...
@@ -51,8 +56,8 @@ class EmailCodeActivity : BaseActivity<ActivityEmailCodeBinding>(ActivityEmailCo
binding
.
tvMessage
.
text
=
email
.
message
Thread
{
emailQ
rString
=
createEmailQrString
(
email
)
val
bitmap
=
generateQRCode
(
emailQ
rString
,
735
,
735
,
5
)
q
rString
=
createEmailQrString
(
email
)
val
bitmap
=
generateQRCode
(
q
rString
,
735
,
735
,
5
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
val
file
=
File
(
cacheDir
,
System
.
currentTimeMillis
().
toString
()
+
".jpg"
)
...
...
@@ -60,7 +65,7 @@ class EmailCodeActivity : BaseActivity<ActivityEmailCodeBinding>(ActivityEmailCo
val
flag
=
saveBitmapToFile
(
it
,
file
.
absolutePath
)
LogEx
.
logDebug
(
TAG
,
"flag=$flag tempImage=${file.absolutePath}"
)
if
(
flag
)
{
tempImage
=
file
.
absolutePath
tempImage
Path
=
file
.
absolutePath
}
}
if
(
email
.
needCreate
)
{
...
...
@@ -95,7 +100,7 @@ class EmailCodeActivity : BaseActivity<ActivityEmailCodeBinding>(ActivityEmailCo
}
binding
.
llShare
.
setOnClickListener
{
val
intent
=
intentShareImage
(
this
,
tempImage
)
val
intent
=
intentShareImage
(
this
,
tempImage
Path
)
runCatching
{
startActivity
(
intent
)
}
...
...
@@ -105,27 +110,14 @@ class EmailCodeActivity : BaseActivity<ActivityEmailCodeBinding>(ActivityEmailCo
}
binding
.
llDownload
.
setOnClickListener
{
kotlin
.
runCatching
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
this
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
File
(
tempImage
).
name
val
newName
=
File
(
tempImagePath
).
name
showInputNameDialog
(
newName
)
{
name
->
if
(
name
.
endsWith
(
".jpg"
))
{
name
.
also
{
newName
=
it
}
}
else
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
downFile
.
createNewFile
()
File
(
tempImage
).
copyTo
(
downFile
,
true
)
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
viewModel
.
copyFileToDownloads
(
this
,
name
,
tempImagePath
)
}
}
}
binding
.
llCopy
.
setOnClickListener
{
copyText
(
TAG
,
emailQ
rString
)
copyText
(
TAG
,
q
rString
)
toast
(
"Copied to clipboard"
,
true
)
}
binding
.
flSearch
.
setOnClickListener
{
...
...
@@ -136,6 +128,5 @@ class EmailCodeActivity : BaseActivity<ActivityEmailCodeBinding>(ActivityEmailCo
toast
(
"No application was found to handle the email request"
,
true
)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/scanqr/ui/event/EventCodeActivity.kt
View file @
c314a02e
package
com.base.scanqr.ui.event
import
android.Manifest
import
android.annotation.SuppressLint
import
android.os.Environment
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
androidx.lifecycle.ViewModelProvider
import
com.base.scanqr.R
import
com.base.scanqr.ads.AdsMgr
import
com.base.scanqr.ads.AdsShowCallBack
...
...
@@ -12,6 +12,7 @@ import com.base.scanqr.base.BaseActivity
import
com.base.scanqr.bean.EventUIBean
import
com.base.scanqr.bean.FunctionUIBean
import
com.base.scanqr.databinding.ActivityEventCodeBinding
import
com.base.scanqr.ui.vm.QrViewModel
import
com.base.scanqr.ui.widget.InputNameDialog.showInputNameDialog
import
com.base.scanqr.utils.BarUtils
import
com.base.scanqr.utils.BitmapUtils.saveBitmapToFile
...
...
@@ -29,8 +30,11 @@ import java.io.File
class
EventCodeActivity
:
BaseActivity
<
ActivityEventCodeBinding
>(
ActivityEventCodeBinding
::
inflate
)
{
private
var
eventUIBean
=
EventUIBean
()
private
var
tempImage
:
String
=
""
private
var
eventQrString
=
""
private
var
tempImagePath
:
String
=
""
private
var
qrString
=
""
private
val
viewModel
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
ViewModelProvider
(
this
)[
QrViewModel
::
class
.
java
]
}
override
fun
onResumeOneShoot
()
{
super
.
onResumeOneShoot
()
...
...
@@ -55,9 +59,9 @@ class EventCodeActivity : BaseActivity<ActivityEventCodeBinding>(ActivityEventCo
binding
.
tvDesc
.
text
=
eventUIBean
.
description
}
Thread
{
eventQ
rString
=
EventUIBean
.
createEventQRString
(
eventUIBean
)
LogEx
.
logDebug
(
TAG
,
"eventQrString=$
eventQ
rString"
)
val
bitmap
=
generateQRCode
(
eventQ
rString
,
735
,
735
,
5
)
q
rString
=
EventUIBean
.
createEventQRString
(
eventUIBean
)
LogEx
.
logDebug
(
TAG
,
"eventQrString=$
q
rString"
)
val
bitmap
=
generateQRCode
(
q
rString
,
735
,
735
,
5
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
val
file
=
File
(
cacheDir
,
System
.
currentTimeMillis
().
toString
()
+
".jpg"
)
...
...
@@ -65,7 +69,7 @@ class EventCodeActivity : BaseActivity<ActivityEventCodeBinding>(ActivityEventCo
val
flag
=
saveBitmapToFile
(
it
,
file
.
absolutePath
)
LogEx
.
logDebug
(
TAG
,
"flag=$flag tempImage=${file.absolutePath}"
)
if
(
flag
)
{
tempImage
=
file
.
absolutePath
tempImage
Path
=
file
.
absolutePath
}
}
if
(
eventUIBean
.
needCreate
)
{
...
...
@@ -98,7 +102,7 @@ class EventCodeActivity : BaseActivity<ActivityEventCodeBinding>(ActivityEventCo
onBackPressedDispatcher
.
onBackPressed
()
}
binding
.
llShare
.
setOnClickListener
{
val
intent
=
intentShareImage
(
this
,
tempImage
)
val
intent
=
intentShareImage
(
this
,
tempImage
Path
)
runCatching
{
startActivity
(
intent
)
}
...
...
@@ -108,27 +112,14 @@ class EventCodeActivity : BaseActivity<ActivityEventCodeBinding>(ActivityEventCo
}
binding
.
llDownload
.
setOnClickListener
{
kotlin
.
runCatching
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
this
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
File
(
tempImage
).
name
val
newName
=
File
(
tempImagePath
).
name
showInputNameDialog
(
newName
)
{
name
->
if
(
name
.
endsWith
(
".jpg"
))
{
name
.
also
{
newName
=
it
}
}
else
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
downFile
.
createNewFile
()
File
(
tempImage
).
copyTo
(
downFile
,
true
)
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
viewModel
.
copyFileToDownloads
(
this
,
name
,
tempImagePath
)
}
}
}
binding
.
llCopy
.
setOnClickListener
{
copyText
(
TAG
,
eventQ
rString
)
copyText
(
TAG
,
q
rString
)
toast
(
"Copied to clipboard"
,
true
)
}
binding
.
flSearch
.
setOnClickListener
{
...
...
app/src/main/java/com/base/scanqr/ui/location/LocationCodeActivity.kt
View file @
c314a02e
package
com.base.scanqr.ui.location
import
android.os.Bundle
import
androidx.activity.enableEdgeToEdge
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.view.ViewCompat
import
androidx.core.view.WindowInsetsCompat
import
com.base.scanqr.R
import
com.base.scanqr.base.BaseActivity
import
com.base.scanqr.databinding.ActivityLocationCodeBinding
class
LocationCodeActivity
:
AppCompatActivity
()
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
enableEdgeToEdge
()
setContentView
(
R
.
layout
.
activity_location_code
)
ViewCompat
.
setOnApplyWindowInsetsListener
(
findViewById
(
R
.
id
.
main
))
{
v
,
insets
->
val
systemBars
=
insets
.
getInsets
(
WindowInsetsCompat
.
Type
.
systemBars
())
v
.
setPadding
(
systemBars
.
left
,
systemBars
.
top
,
systemBars
.
right
,
systemBars
.
bottom
)
insets
}
class
LocationCodeActivity
:
BaseActivity
<
ActivityLocationCodeBinding
>(
ActivityLocationCodeBinding
::
inflate
)
{
override
fun
initView
()
{
super
.
initView
()
}
override
fun
initListener
()
{
super
.
initListener
()
}
}
\ No newline at end of file
app/src/main/java/com/base/scanqr/ui/main/MainActivity.kt
View file @
c314a02e
...
...
@@ -147,17 +147,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::infl
0
->
{
tabAt
=
0
navController
?.
navigate
(
R
.
id
.
createFragment
)
val
createPgPassTime
=
(
System
.
currentTimeMillis
()
-
createFgLastShow
)
LogEx
.
logDebug
(
TAG
,
"createPgPassTime=$createPgPassTime "
+
"createFgInterval=${AdConfigBean.adsConfigBean.createFgInterval}"
)
val
flag
=
createPgPassTime
/
1000L
>
AdConfigBean
.
adsConfigBean
.
createFgInterval
if
(
createFgLastShow
==
0L
||
flag
)
if
(
tabCanShowAd
())
AdsMgr
.
showInsert
(
this
,
false
,
object
:
AdsShowCallBack
()
{
override
fun
show
()
{
createFg
LastShow
=
System
.
currentTimeMillis
()
mainFgTab
LastShow
=
System
.
currentTimeMillis
()
}
override
fun
close
(
where
:
Int
)
{
...
...
@@ -179,6 +173,21 @@ class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::infl
2
->
{
tabAt
=
2
navController
?.
navigate
(
R
.
id
.
historyFragment
)
if
(
tabCanShowAd
())
AdsMgr
.
showInsert
(
this
,
false
,
object
:
AdsShowCallBack
()
{
override
fun
show
()
{
mainFgTabLastShow
=
System
.
currentTimeMillis
()
}
override
fun
close
(
where
:
Int
)
{
}
override
fun
failed
(
where
:
Int
)
{
}
override
fun
googleFailed
(
where
:
Int
)
{
}
})
}
3
->
{
...
...
@@ -188,6 +197,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::infl
}
}
private
fun
tabCanShowAd
():
Boolean
{
val
tabChangePassTime
=
(
System
.
currentTimeMillis
()
-
mainFgTabLastShow
)
LogEx
.
logDebug
(
TAG
,
"tabChangePassTime=$tabChangePassTime "
+
"tabFgInterval=${AdConfigBean.adsConfigBean.tabFgInterval}"
)
val
flag
=
tabChangePassTime
/
1000L
>
AdConfigBean
.
adsConfigBean
.
tabFgInterval
return
mainFgTabLastShow
==
0L
||
flag
}
fun
TabLayout
.
Tab
.
setUnselected
()
{
val
textView
=
customView
?.
findViewById
<
TextView
>(
R
.
id
.
tv_tab
)
LogEx
.
logDebug
(
TAG
,
"setUnselected ${textView?.text}"
)
...
...
@@ -215,6 +235,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::infl
companion
object
{
var
tabAt
=
1
var
createFg
LastShow
=
0L
var
mainFgTab
LastShow
=
0L
}
}
\ No newline at end of file
app/src/main/java/com/base/scanqr/ui/message/MessageCodeActivity.kt
View file @
c314a02e
...
...
@@ -3,6 +3,7 @@ package com.base.scanqr.ui.message
import
android.os.Environment
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
androidx.lifecycle.ViewModelProvider
import
com.base.scanqr.R
import
com.base.scanqr.ads.AdsMgr
import
com.base.scanqr.ads.AdsShowCallBack
...
...
@@ -10,6 +11,7 @@ import com.base.scanqr.base.BaseActivity
import
com.base.scanqr.bean.FunctionUIBean
import
com.base.scanqr.bean.MessageUIBean
import
com.base.scanqr.databinding.ActivityMessageCodeBinding
import
com.base.scanqr.ui.vm.QrViewModel
import
com.base.scanqr.ui.widget.InputNameDialog.showInputNameDialog
import
com.base.scanqr.utils.BarUtils
import
com.base.scanqr.utils.BitmapUtils.saveBitmapToFile
...
...
@@ -26,8 +28,12 @@ import java.io.File
class
MessageCodeActivity
:
BaseActivity
<
ActivityMessageCodeBinding
>(
ActivityMessageCodeBinding
::
inflate
)
{
private
var
messageUIBean
=
MessageUIBean
()
private
var
messageQrString
=
""
private
var
tempImage
:
String
=
""
private
var
qrString
=
""
private
var
tempImagePath
:
String
=
""
private
val
viewModel
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
ViewModelProvider
(
this
)[
QrViewModel
::
class
.
java
]
}
override
fun
onResumeOneShoot
()
{
super
.
onResumeOneShoot
()
...
...
@@ -49,9 +55,9 @@ class MessageCodeActivity : BaseActivity<ActivityMessageCodeBinding>(ActivityMes
binding
.
tvMsg
.
text
=
messageUIBean
.
msg
}
Thread
{
messageQ
rString
=
MessageUIBean
.
createMessageQrString
(
messageUIBean
)
LogEx
.
logDebug
(
TAG
,
"messageQrString=$
messageQ
rString"
)
val
bitmap
=
generateQRCode
(
messageQ
rString
,
735
,
735
,
5
)
q
rString
=
MessageUIBean
.
createMessageQrString
(
messageUIBean
)
LogEx
.
logDebug
(
TAG
,
"messageQrString=$
q
rString"
)
val
bitmap
=
generateQRCode
(
q
rString
,
735
,
735
,
5
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
val
file
=
File
(
cacheDir
,
System
.
currentTimeMillis
().
toString
()
+
".jpg"
)
...
...
@@ -59,7 +65,7 @@ class MessageCodeActivity : BaseActivity<ActivityMessageCodeBinding>(ActivityMes
val
flag
=
saveBitmapToFile
(
it
,
file
.
absolutePath
)
LogEx
.
logDebug
(
TAG
,
"flag=$flag tempImage=${file.absolutePath}"
)
if
(
flag
)
{
tempImage
=
file
.
absolutePath
tempImage
Path
=
file
.
absolutePath
}
}
if
(
messageUIBean
.
needCreate
)
{
...
...
@@ -91,7 +97,7 @@ class MessageCodeActivity : BaseActivity<ActivityMessageCodeBinding>(ActivityMes
onBackPressedDispatcher
.
onBackPressed
()
}
binding
.
llShare
.
setOnClickListener
{
val
intent
=
intentShareImage
(
this
,
tempImage
)
val
intent
=
intentShareImage
(
this
,
tempImage
Path
)
runCatching
{
startActivity
(
intent
)
}
...
...
@@ -101,27 +107,14 @@ class MessageCodeActivity : BaseActivity<ActivityMessageCodeBinding>(ActivityMes
}
binding
.
llDownload
.
setOnClickListener
{
kotlin
.
runCatching
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
this
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
File
(
tempImage
).
name
val
newName
=
File
(
tempImagePath
).
name
showInputNameDialog
(
newName
)
{
name
->
if
(
name
.
endsWith
(
".jpg"
))
{
name
.
also
{
newName
=
it
}
}
else
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
downFile
.
createNewFile
()
File
(
tempImage
).
copyTo
(
downFile
,
true
)
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
viewModel
.
copyFileToDownloads
(
this
,
name
,
tempImagePath
)
}
}
}
binding
.
llCopy
.
setOnClickListener
{
copyText
(
TAG
,
messageQ
rString
)
copyText
(
TAG
,
q
rString
)
toast
(
"Copied to clipboard"
,
true
)
}
binding
.
flSearch
.
setOnClickListener
{
...
...
app/src/main/java/com/base/scanqr/ui/product/ProductCodeActivity.kt
View file @
c314a02e
...
...
@@ -3,10 +3,10 @@ package com.base.scanqr.ui.product
import
android.content.ActivityNotFoundException
import
android.content.Intent
import
android.net.Uri
import
android.os.Environment
import
android.widget.Toast
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
androidx.lifecycle.ViewModelProvider
import
com.base.scanqr.R
import
com.base.scanqr.ads.AdsMgr
import
com.base.scanqr.ads.AdsShowCallBack
...
...
@@ -14,6 +14,7 @@ import com.base.scanqr.base.BaseActivity
import
com.base.scanqr.bean.FunctionUIBean
import
com.base.scanqr.bean.ProductUIBean
import
com.base.scanqr.databinding.ActivityProductCodeBinding
import
com.base.scanqr.ui.vm.QrViewModel
import
com.base.scanqr.ui.widget.InputNameDialog.showInputNameDialog
import
com.base.scanqr.utils.BarUtils
import
com.base.scanqr.utils.BitmapUtils.saveBitmapToFile
...
...
@@ -33,7 +34,12 @@ import java.io.File
class
ProductCodeActivity
:
BaseActivity
<
ActivityProductCodeBinding
>(
ActivityProductCodeBinding
::
inflate
)
{
private
var
productUIBean
=
ProductUIBean
()
private
var
tempImage
:
String
=
""
private
var
qrString
:
String
=
""
private
var
tempImagePath
:
String
=
""
private
val
viewModel
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
ViewModelProvider
(
this
)[
QrViewModel
::
class
.
java
]
}
override
fun
onResumeOneShoot
()
{
super
.
onResumeOneShoot
()
...
...
@@ -51,11 +57,12 @@ class ProductCodeActivity : BaseActivity<ActivityProductCodeBinding>(ActivityPro
val
data
=
intent
.
extras
?.
getString
(
"data"
)
data
?.
let
{
productUIBean
=
Gson
().
fromJson
(
data
,
ProductUIBean
::
class
.
java
)
qrString
=
productUIBean
.
content
binding
.
tvContent
.
text
=
productUIBean
.
content
}
Thread
{
val
bitmap
=
generateEAN13Barcode
(
productUIBean
.
content
,
648
,
255
)
val
bitmap
=
generateEAN13Barcode
(
qrString
,
648
,
255
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
val
file
=
File
(
cacheDir
,
System
.
currentTimeMillis
().
toString
()
+
".jpg"
)
...
...
@@ -63,7 +70,7 @@ class ProductCodeActivity : BaseActivity<ActivityProductCodeBinding>(ActivityPro
val
flag
=
saveBitmapToFile
(
it
,
file
.
absolutePath
)
LogEx
.
logDebug
(
TAG
,
"flag=$flag tempImage=${file.absolutePath}"
)
if
(
flag
)
{
tempImage
=
file
.
absolutePath
tempImage
Path
=
file
.
absolutePath
}
}
if
(
productUIBean
.
needCreate
)
{
...
...
@@ -96,29 +103,16 @@ class ProductCodeActivity : BaseActivity<ActivityProductCodeBinding>(ActivityPro
onBackPressedDispatcher
.
onBackPressed
()
}
binding
.
llShare
.
setOnClickListener
{
val
intent
=
intentShareImage
(
this
,
tempImage
)
val
intent
=
intentShareImage
(
this
,
qrString
)
runCatching
{
startActivity
(
intent
)
}
}
binding
.
llDownload
.
setOnClickListener
{
kotlin
.
runCatching
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
this
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
File
(
tempImage
).
name
val
newName
=
File
(
qrString
).
name
showInputNameDialog
(
newName
)
{
name
->
if
(
name
.
endsWith
(
".jpg"
))
{
name
.
also
{
newName
=
it
}
}
else
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
downFile
.
createNewFile
()
File
(
tempImage
).
copyTo
(
downFile
,
true
)
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
viewModel
.
copyFileToDownloads
(
this
,
name
,
tempImagePath
)
}
}
}
...
...
app/src/main/java/com/base/scanqr/ui/telephone/TelephoneCodeActivity.kt
View file @
c314a02e
package
com.base.scanqr.ui.telephone
import
android.Manifest
import
android.os.Environment
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
androidx.lifecycle.ViewModelProvider
import
com.base.scanqr.R
import
com.base.scanqr.ads.AdsMgr
import
com.base.scanqr.ads.AdsShowCallBack
...
...
@@ -11,6 +11,7 @@ import com.base.scanqr.base.BaseActivity
import
com.base.scanqr.bean.FunctionUIBean
import
com.base.scanqr.bean.TelephoneUIBean
import
com.base.scanqr.databinding.ActivityTelephoneCodeBinding
import
com.base.scanqr.ui.vm.QrViewModel
import
com.base.scanqr.ui.widget.InputNameDialog.showInputNameDialog
import
com.base.scanqr.utils.BarUtils
import
com.base.scanqr.utils.BitmapUtils.saveBitmapToFile
...
...
@@ -28,9 +29,13 @@ import java.io.File
class
TelephoneCodeActivity
:
BaseActivity
<
ActivityTelephoneCodeBinding
>(
ActivityTelephoneCodeBinding
::
inflate
)
{
private
var
telephoneUIBean
=
TelephoneUIBean
()
private
var
telQrString
=
""
private
var
qrString
=
""
private
var
tempImagePath
:
String
=
""
private
val
viewModel
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
ViewModelProvider
(
this
)[
QrViewModel
::
class
.
java
]
}
private
var
tempImage
:
String
=
""
override
fun
onResumeOneShoot
()
{
super
.
onResumeOneShoot
()
val
flag
=
changeLanguage
()
...
...
@@ -51,11 +56,11 @@ class TelephoneCodeActivity : BaseActivity<ActivityTelephoneCodeBinding>(Activit
data
?.
let
{
telephoneUIBean
=
Gson
().
fromJson
(
data
,
TelephoneUIBean
::
class
.
java
)
binding
.
tvTel
.
text
=
telephoneUIBean
.
tel
qrString
=
"tel:"
+
telephoneUIBean
.
tel
}
Thread
{
telQrString
=
"tel:"
+
telephoneUIBean
.
tel
val
bitmap
=
generateQRCode
(
telQrString
,
735
,
735
,
5
)
val
bitmap
=
generateQRCode
(
qrString
,
735
,
735
,
5
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
val
file
=
File
(
cacheDir
,
System
.
currentTimeMillis
().
toString
()
+
".jpg"
)
...
...
@@ -63,7 +68,7 @@ class TelephoneCodeActivity : BaseActivity<ActivityTelephoneCodeBinding>(Activit
val
flag
=
saveBitmapToFile
(
it
,
file
.
absolutePath
)
LogEx
.
logDebug
(
TAG
,
"flag=$flag tempImage=${file.absolutePath}"
)
if
(
flag
)
{
tempImage
=
file
.
absolutePath
tempImage
Path
=
file
.
absolutePath
}
}
if
(
telephoneUIBean
.
needCreate
)
{
...
...
@@ -95,34 +100,21 @@ class TelephoneCodeActivity : BaseActivity<ActivityTelephoneCodeBinding>(Activit
onBackPressedDispatcher
.
onBackPressed
()
}
binding
.
llShare
.
setOnClickListener
{
val
intent
=
intentShareImage
(
this
,
tempImage
)
val
intent
=
intentShareImage
(
this
,
tempImage
Path
)
runCatching
{
startActivity
(
intent
)
}
}
binding
.
llDownload
.
setOnClickListener
{
kotlin
.
runCatching
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
this
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
File
(
tempImage
).
name
val
newName
=
File
(
tempImagePath
).
name
showInputNameDialog
(
newName
)
{
name
->
if
(
name
.
endsWith
(
".jpg"
))
{
name
.
also
{
newName
=
it
}
}
else
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
downFile
.
createNewFile
()
File
(
tempImage
).
copyTo
(
downFile
,
true
)
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
viewModel
.
copyFileToDownloads
(
this
,
name
,
tempImagePath
)
}
}
}
binding
.
llCopy
.
setOnClickListener
{
copyText
(
TAG
,
telQ
rString
)
copyText
(
TAG
,
q
rString
)
toast
(
"Copied to clipboard"
,
true
)
}
binding
.
flSearch
.
setOnClickListener
{
...
...
app/src/main/java/com/base/scanqr/ui/text/TextCodeActivity.kt
View file @
c314a02e
...
...
@@ -3,18 +3,18 @@ package com.base.scanqr.ui.text
import
android.content.ActivityNotFoundException
import
android.content.Intent
import
android.net.Uri
import
android.os.Environment
import
android.widget.Toast
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
androidx.lifecycle.ViewModelProvider
import
com.base.scanqr.R
import
com.base.scanqr.ads.AdsMgr
import
com.base.scanqr.ads.AdsShowCallBack
import
com.base.scanqr.base.BaseActivity
import
com.base.scanqr.bean.FunctionUIBean
import
com.base.scanqr.bean.ScanBean
import
com.base.scanqr.bean.TextUIBean
import
com.base.scanqr.databinding.ActivityTextCodeBinding
import
com.base.scanqr.ui.vm.QrViewModel
import
com.base.scanqr.ui.widget.InputNameDialog.showInputNameDialog
import
com.base.scanqr.utils.BarUtils
import
com.base.scanqr.utils.BitmapUtils.saveBitmapToFile
...
...
@@ -31,7 +31,11 @@ import java.io.File
class
TextCodeActivity
:
BaseActivity
<
ActivityTextCodeBinding
>(
ActivityTextCodeBinding
::
inflate
)
{
private
var
textUIBean
=
TextUIBean
()
private
var
tempImage
:
String
=
""
private
var
tempImagePath
:
String
=
""
private
var
qrString
=
""
private
val
viewModel
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
ViewModelProvider
(
this
)[
QrViewModel
::
class
.
java
]
}
override
fun
onResumeOneShoot
()
{
super
.
onResumeOneShoot
()
...
...
@@ -50,9 +54,10 @@ class TextCodeActivity : BaseActivity<ActivityTextCodeBinding>(ActivityTextCodeB
data
?.
let
{
textUIBean
=
Gson
().
fromJson
(
data
,
TextUIBean
::
class
.
java
)
binding
.
tvContent
.
text
=
textUIBean
.
content
qrString
=
textUIBean
.
content
}
Thread
{
val
bitmap
=
generateQRCode
(
textUIBean
.
content
,
735
,
735
,
5
)
val
bitmap
=
generateQRCode
(
qrString
,
735
,
735
,
5
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
val
file
=
File
(
cacheDir
,
System
.
currentTimeMillis
().
toString
()
+
".jpg"
)
...
...
@@ -60,7 +65,7 @@ class TextCodeActivity : BaseActivity<ActivityTextCodeBinding>(ActivityTextCodeB
val
flag
=
saveBitmapToFile
(
it
,
file
.
absolutePath
)
LogEx
.
logDebug
(
TAG
,
"flag=$flag tempImage=${file.absolutePath}"
)
if
(
flag
)
{
tempImage
=
file
.
absolutePath
tempImage
Path
=
file
.
absolutePath
}
}
if
(
textUIBean
.
needCreate
)
{
...
...
@@ -102,22 +107,9 @@ class TextCodeActivity : BaseActivity<ActivityTextCodeBinding>(ActivityTextCodeB
}
binding
.
llDownload
.
setOnClickListener
{
kotlin
.
runCatching
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
this
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
File
(
tempImage
).
name
val
newName
=
File
(
tempImagePath
).
name
showInputNameDialog
(
newName
)
{
name
->
if
(
name
.
endsWith
(
".jpg"
))
{
name
.
also
{
newName
=
it
}
}
else
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
downFile
.
createNewFile
()
File
(
tempImage
).
copyTo
(
downFile
,
true
)
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
viewModel
.
copyFileToDownloads
(
this
,
name
,
tempImagePath
)
}
}
}
...
...
app/src/main/java/com/base/scanqr/ui/vm/QrViewModel.kt
0 → 100644
View file @
c314a02e
package
com.base.scanqr.ui.vm
import
android.content.Context
import
android.os.Environment
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.viewModelScope
import
com.base.scanqr.R
import
com.base.scanqr.utils.ToastUtils.toast
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
java.io.File
class
QrViewModel
:
ViewModel
()
{
fun
copyFileToDownloads
(
context
:
Context
,
name
:
String
,
copyTempPath
:
String
)
=
viewModelScope
.
launch
(
Dispatchers
.
IO
)
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
context
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
name
if
(!
name
.
endsWith
(
".jpg"
))
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
val
flag
=
downFile
.
createNewFile
()
if
(
flag
)
{
File
(
copyTempPath
).
copyTo
(
downFile
,
true
)
launch
(
Dispatchers
.
Main
)
{
context
.
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/scanqr/ui/website/WebsiteCodeActivity.kt
View file @
c314a02e
...
...
@@ -3,7 +3,7 @@ package com.base.scanqr.ui.website
import
android.os.Environment
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
com.base.scanqr.BuildConfig
import
androidx.lifecycle.ViewModelProvider
import
com.base.scanqr.R
import
com.base.scanqr.ads.AdsMgr
import
com.base.scanqr.ads.AdsShowCallBack
...
...
@@ -11,6 +11,7 @@ import com.base.scanqr.base.BaseActivity
import
com.base.scanqr.bean.FunctionUIBean
import
com.base.scanqr.bean.WebsiteUIBean
import
com.base.scanqr.databinding.ActivityWebsiteCodeBinding
import
com.base.scanqr.ui.vm.QrViewModel
import
com.base.scanqr.ui.widget.InputNameDialog.showInputNameDialog
import
com.base.scanqr.utils.BarUtils
import
com.base.scanqr.utils.BitmapUtils.saveBitmapToFile
...
...
@@ -27,7 +28,13 @@ import java.io.File
class
WebsiteCodeActivity
:
BaseActivity
<
ActivityWebsiteCodeBinding
>(
ActivityWebsiteCodeBinding
::
inflate
)
{
private
var
websiteUIBean
=
WebsiteUIBean
()
private
var
tempImage
:
String
=
""
private
var
tempImagePath
:
String
=
""
private
var
qrString
=
""
private
val
viewModel
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
ViewModelProvider
(
this
)[
QrViewModel
::
class
.
java
]
}
override
fun
onResumeOneShoot
()
{
super
.
onResumeOneShoot
()
val
flag
=
changeLanguage
()
...
...
@@ -46,10 +53,11 @@ class WebsiteCodeActivity : BaseActivity<ActivityWebsiteCodeBinding>(ActivityWeb
data
?.
let
{
websiteUIBean
=
Gson
().
fromJson
(
data
,
WebsiteUIBean
::
class
.
java
)
binding
.
tvHttp
.
text
=
websiteUIBean
.
http
qrString
=
websiteUIBean
.
http
}
Thread
{
val
bitmap
=
generateQRCode
(
websiteUIBean
.
http
,
735
,
735
,
5
)
val
bitmap
=
generateQRCode
(
qrString
,
735
,
735
,
5
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
val
file
=
File
(
cacheDir
,
System
.
currentTimeMillis
().
toString
()
+
".jpg"
)
...
...
@@ -57,7 +65,7 @@ class WebsiteCodeActivity : BaseActivity<ActivityWebsiteCodeBinding>(ActivityWeb
val
flag
=
saveBitmapToFile
(
it
,
file
.
absolutePath
)
LogEx
.
logDebug
(
TAG
,
"flag=$flag tempImage=${file.absolutePath}"
)
if
(
flag
)
{
tempImage
=
file
.
absolutePath
tempImage
Path
=
file
.
absolutePath
}
}
if
(
websiteUIBean
.
needCreate
)
{
...
...
@@ -89,29 +97,16 @@ class WebsiteCodeActivity : BaseActivity<ActivityWebsiteCodeBinding>(ActivityWeb
onBackPressedDispatcher
.
onBackPressed
()
}
binding
.
llShare
.
setOnClickListener
{
val
intent
=
intentShareImage
(
this
,
tempImage
)
val
intent
=
intentShareImage
(
this
,
tempImage
Path
)
runCatching
{
startActivity
(
intent
)
}
}
binding
.
llDownload
.
setOnClickListener
{
kotlin
.
runCatching
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
this
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
File
(
tempImage
).
name
val
newName
=
File
(
tempImagePath
).
name
showInputNameDialog
(
newName
)
{
name
->
if
(
name
.
endsWith
(
".jpg"
))
{
name
.
also
{
newName
=
it
}
}
else
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
downFile
.
createNewFile
()
File
(
tempImage
).
copyTo
(
downFile
,
true
)
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
viewModel
.
copyFileToDownloads
(
this
,
name
,
tempImagePath
)
}
}
}
...
...
app/src/main/java/com/base/scanqr/ui/wifi/WifiCodeActivity.kt
View file @
c314a02e
...
...
@@ -3,13 +3,16 @@ package com.base.scanqr.ui.wifi
import
android.os.Environment
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
androidx.lifecycle.ViewModelProvider
import
com.base.scanqr.R
import
com.base.scanqr.ads.AdsMgr
import
com.base.scanqr.ads.AdsShowCallBack
import
com.base.scanqr.base.BaseActivity
import
com.base.scanqr.bean.FunctionUIBean
import
com.base.scanqr.bean.WifiUIBean
import
com.base.scanqr.bean.WifiUIBean.Companion.createWifiQRString
import
com.base.scanqr.databinding.ActivityWifiCodeBinding
import
com.base.scanqr.ui.vm.QrViewModel
import
com.base.scanqr.ui.widget.InputNameDialog.showInputNameDialog
import
com.base.scanqr.utils.BarUtils
import
com.base.scanqr.utils.BitmapUtils.saveBitmapToFile
...
...
@@ -27,8 +30,12 @@ import java.io.File
class
WifiCodeActivity
:
BaseActivity
<
ActivityWifiCodeBinding
>(
ActivityWifiCodeBinding
::
inflate
)
{
private
var
wifiBean
:
WifiUIBean
=
WifiUIBean
()
private
var
wifiQrString
:
String
=
""
private
var
tempImage
:
String
=
""
private
var
qrString
:
String
=
""
private
var
tempImagePath
:
String
=
""
private
val
viewModel
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
ViewModelProvider
(
this
)[
QrViewModel
::
class
.
java
]
}
override
fun
onResumeOneShoot
()
{
super
.
onResumeOneShoot
()
...
...
@@ -47,41 +54,26 @@ class WifiCodeActivity : BaseActivity<ActivityWifiCodeBinding>(ActivityWifiCodeB
LogEx
.
logDebug
(
TAG
,
"data=$data"
)
data
?.
let
{
wifiBean
=
Gson
().
fromJson
(
data
,
WifiUIBean
::
class
.
java
)
}
if
(
wifiBean
.
securityId
==
0
)
{
binding
.
tvSecurity
.
text
=
"WPA/WPA2"
}
if
(
wifiBean
.
securityId
==
1
)
{
binding
.
tvSecurity
.
text
=
"WEP"
}
binding
.
tvSsid
.
text
=
wifiBean
.
ssid
binding
.
tvPassword
.
text
=
wifiBean
.
password
if
(
wifiBean
.
hidden
)
{
binding
.
tvHidden
.
text
=
"YES"
}
else
{
binding
.
tvHidden
.
text
=
"NO"
}
val
content
=
StringBuilder
()
content
.
append
(
"WIFI:"
)
content
.
append
(
"T:"
)
if
(
wifiBean
.
securityId
==
0
)
{
content
.
append
(
"WPA/WPA2"
).
append
(
";"
)
binding
.
tvSecurity
.
text
=
"WPA/WPA2"
}
if
(
wifiBean
.
securityId
==
1
)
{
content
.
append
(
"WEP"
).
append
(
";"
)
binding
.
tvSecurity
.
text
=
"WEP"
}
if
(
wifiBean
.
securityId
==
2
)
{
content
.
append
(
";"
)
}
content
.
append
(
"S:"
)
content
.
append
(
wifiBean
.
ssid
).
append
(
";"
)
content
.
append
(
"P:"
)
content
.
append
(
wifiBean
.
password
).
append
(
";"
)
content
.
append
(
"H:"
)
content
.
append
(
wifiBean
.
hidden
).
append
(
";"
)
wifiQrString
=
content
.
toString
()
LogEx
.
logDebug
(
TAG
,
"wifiContent=$wifiQrString"
)
binding
.
tvSsid
.
text
=
wifiBean
.
ssid
binding
.
tvPassword
.
text
=
wifiBean
.
password
if
(
wifiBean
.
hidden
)
{
binding
.
tvHidden
.
text
=
"YES"
}
else
{
binding
.
tvHidden
.
text
=
"NO"
qrString
=
createWifiQRString
(
wifiBean
)
LogEx
.
logDebug
(
TAG
,
"wifiContent=$qrString"
)
}
Thread
{
val
bitmap
=
generateQRCode
(
wifiQ
rString
,
735
,
735
,
5
)
val
bitmap
=
generateQRCode
(
q
rString
,
735
,
735
,
5
)
runOnUiThread
{
binding
.
ivQr
.
setImageBitmap
(
bitmap
)
val
file
=
File
(
cacheDir
,
System
.
currentTimeMillis
().
toString
()
+
".jpg"
)
...
...
@@ -90,7 +82,7 @@ class WifiCodeActivity : BaseActivity<ActivityWifiCodeBinding>(ActivityWifiCodeB
val
flag
=
saveBitmapToFile
(
it
,
file
.
absolutePath
)
LogEx
.
logDebug
(
TAG
,
"flag=$flag tempImage=${file.absolutePath}"
)
if
(
flag
)
{
tempImage
=
file
.
absolutePath
tempImage
Path
=
file
.
absolutePath
}
}
if
(
wifiBean
.
needCreate
)
{
...
...
@@ -124,7 +116,7 @@ class WifiCodeActivity : BaseActivity<ActivityWifiCodeBinding>(ActivityWifiCodeB
onBackPressedDispatcher
.
onBackPressed
()
}
binding
.
llShare
.
setOnClickListener
{
val
intent
=
intentShareImage
(
this
,
tempImage
)
val
intent
=
intentShareImage
(
this
,
tempImage
Path
)
runCatching
{
startActivity
(
intent
)
}
...
...
@@ -134,27 +126,14 @@ class WifiCodeActivity : BaseActivity<ActivityWifiCodeBinding>(ActivityWifiCodeB
}
binding
.
llDownload
.
setOnClickListener
{
kotlin
.
runCatching
{
val
appFile
=
File
(
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_DOWNLOADS
),
this
.
resources
.
getString
(
R
.
string
.
app_name
)
)
if
(!
appFile
.
exists
())
appFile
.
mkdirs
()
var
newName
=
File
(
tempImage
).
name
val
newName
=
File
(
tempImagePath
).
name
showInputNameDialog
(
newName
)
{
name
->
if
(
name
.
endsWith
(
".jpg"
))
{
name
.
also
{
newName
=
it
}
}
else
{
newName
=
"$name.jpg"
}
val
downFile
=
File
(
appFile
,
newName
)
downFile
.
createNewFile
()
File
(
tempImage
).
copyTo
(
downFile
,
true
)
toast
(
"Save to:${appFile.absolutePath}"
,
true
)
viewModel
.
copyFileToDownloads
(
this
,
name
,
tempImagePath
)
}
}
}
binding
.
llCopy
.
setOnClickListener
{
copyText
(
TAG
,
wifiQ
rString
)
copyText
(
TAG
,
q
rString
)
toast
(
"Copied to clipboard"
,
true
)
}
binding
.
flSearch
.
setOnClickListener
{
...
...
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