Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f5418204
authored
Dec 10, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加TTS,增加“请不要重复扫码”语音
parent
409444ee
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
0 deletions
+56
-0
app/src/main/assets/qrcode-repeat.mp3
+0
-0
app/src/main/java/com/bgycc/smartcanteen/App.kt
+2
-0
app/src/main/java/com/bgycc/smartcanteen/action/PayOfflineAction.java
+2
-0
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
+12
-0
app/src/main/java/com/bgycc/smartcanteen/event/QRCodeRepeatEvent.kt
+5
-0
app/src/main/java/com/bgycc/smartcanteen/helper/TTSHelper.kt
+35
-0
No files found.
app/src/main/assets/qrcode-repeat.mp3
0 → 100644
View file @
f5418204
File added
app/src/main/java/com/bgycc/smartcanteen/App.kt
View file @
f5418204
...
...
@@ -6,6 +6,7 @@ import android.app.Application
import
android.content.Context
import
com.bgycc.smartcanteen.Storage.PayStorage
import
com.bgycc.smartcanteen.action.UpdateAction
import
com.bgycc.smartcanteen.helper.TTSHelper
import
com.bgycc.smartcanteen.helper.TimerHelper
import
com.bgycc.smartcanteen.helper.WifiHelpler
import
com.bgycc.smartcanteen.manager.NetworkManager
...
...
@@ -59,6 +60,7 @@ class App : Application() {
NetworkManager
.
initialize
(
this
)
WifiHelpler
.
initialize
(
this
)
PayStorage
.
initialize
(
this
)
TTSHelper
.
initialize
(
this
)
Device
.
initialize
(
this
)
PermissionUtils
.
permission
(
PermissionConstants
.
STORAGE
).
request
()
UpdateAction
.
getDefault
().
initialize
()
...
...
app/src/main/java/com/bgycc/smartcanteen/action/PayOfflineAction.java
View file @
f5418204
...
...
@@ -3,6 +3,7 @@ package com.bgycc.smartcanteen.action;
import
com.bgycc.smartcanteen.App
;
import
com.bgycc.smartcanteen.Storage.PayStorage
;
import
com.bgycc.smartcanteen.event.PayStateEvent
;
import
com.bgycc.smartcanteen.event.QRCodeRepeatEvent
;
import
com.bgycc.smartcanteen.helper.TimerHelper
;
import
com.bgycc.smartcanteen.server.websocket.MainWebSocket
;
import
com.bgycc.smartcanteen.task.QRCodeTask
;
...
...
@@ -83,6 +84,7 @@ public class PayOfflineAction extends Action {
}
if
(
checkRepeat
&&
mPayCodeHistory
.
contains
(
payCode
))
{
setState
(
State
.
FAIL
,
"请不要重复扫码"
);
EventBus
.
getDefault
().
post
(
new
QRCodeRepeatEvent
());
return
;
}
addPayCodeHistory
(
payCode
);
...
...
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
View file @
f5418204
...
...
@@ -17,6 +17,7 @@ import com.bgycc.smartcanteen.R
import
com.bgycc.smartcanteen.action.*
import
com.bgycc.smartcanteen.event.*
import
com.bgycc.smartcanteen.helper.EthernetHelper
import
com.bgycc.smartcanteen.helper.TTSHelper
import
com.bgycc.smartcanteen.helper.TimerHelper
import
com.bgycc.smartcanteen.helper.WifiHelpler
import
com.bgycc.smartcanteen.manager.NetworkManager
...
...
@@ -45,6 +46,7 @@ class MainActivity : BaseActivity() {
private
val
mSoundPool
:
SoundPool
=
SoundPool
(
1
,
AudioManager
.
STREAM_SYSTEM
,
0
)
private
var
mBeepSoundId
=
0
private
var
mQRCodeInvalidSoundId
=
0
private
var
mQRCodeRepeatSoundId
=
0
private
var
mPaySuccessSoundId
=
0
private
var
mPayFailSoundId
=
0
private
var
mAudioManager
:
AudioManager
?
=
null
...
...
@@ -80,6 +82,7 @@ class MainActivity : BaseActivity() {
mAudioManager
=
getSystemService
(
Context
.
AUDIO_SERVICE
)
as
AudioManager
mBeepSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"beep.mp3"
),
1
)
mQRCodeInvalidSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"qrcode-invalid.mp3"
),
1
)
mQRCodeRepeatSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"qrcode-repeat.mp3"
),
1
)
mPaySuccessSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"pay-success.mp3"
),
1
)
mPayFailSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"pay-fail.mp3"
),
1
)
MainWebSocket
.
initialize
()
...
...
@@ -166,6 +169,13 @@ class MainActivity : BaseActivity() {
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
fun
onMessageEvent
(
event
:
QRCodeInvalidEvent
)
{
mSoundPool
.
play
(
mQRCodeInvalidSoundId
,
1f
,
1f
,
0
,
0
,
1f
)
TTSHelper
.
speak
(
"无效二维码"
)
}
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
fun
onMessageEvent
(
event
:
QRCodeRepeatEvent
)
{
mSoundPool
.
play
(
mQRCodeRepeatSoundId
,
1f
,
1f
,
0
,
0
,
1f
)
TTSHelper
.
speak
(
"请不要重复扫码"
)
}
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
)
...
...
@@ -181,11 +191,13 @@ class MainActivity : BaseActivity() {
if
(
StringUtil
.
isEmpty
(
event
.
message
))
event
.
message
=
"支付成功"
_message
.
text
=
event
.
message
mSoundPool
.
play
(
mPaySuccessSoundId
,
1f
,
1f
,
0
,
0
,
1f
)
TTSHelper
.
speak
(
event
.
message
)
}
else
if
(
event
.
state
==
PayStateEvent
.
StateEnum
.
FAIL
)
{
_message
.
setTextColor
(
0
xFFFF0000
.
toInt
())
if
(
StringUtil
.
isEmpty
(
event
.
message
))
event
.
message
=
"支付失败"
_message
.
text
=
event
.
message
mSoundPool
.
play
(
mPayFailSoundId
,
1f
,
1f
,
0
,
0
,
1f
)
TTSHelper
.
speak
(
event
.
message
)
}
}
...
...
app/src/main/java/com/bgycc/smartcanteen/event/QRCodeRepeatEvent.kt
0 → 100644
View file @
f5418204
package
com.bgycc.smartcanteen.event
class
QRCodeRepeatEvent
{
}
\ No newline at end of file
app/src/main/java/com/bgycc/smartcanteen/helper/TTSHelper.kt
0 → 100644
View file @
f5418204
package
com.bgycc.smartcanteen.helper
import
android.content.Context
import
android.speech.tts.TextToSpeech
import
com.bgycc.smartcanteen.util.LogUtil
import
com.blankj.utilcode.util.LogUtils
import
java.util.*
object
TTSHelper
{
private
val
TAG
=
TTSHelper
::
class
.
java
.
simpleName
private
var
mTTS
:
TextToSpeech
?
=
null
private
var
mInited
=
false
fun
initialize
(
context
:
Context
)
{
mTTS
=
TextToSpeech
(
context
)
{
if
(
it
==
TextToSpeech
.
SUCCESS
)
{
LogUtil
.
i
(
TAG
,
"TTS初始化成功"
)
LogUtils
.
file
(
TAG
,
"TTS初始化成功"
)
val
result
=
mTTS
?.
setLanguage
(
Locale
.
CHINESE
)
mInited
=
true
}
else
{
LogUtil
.
i
(
TAG
,
"TTS初始化失败"
)
LogUtils
.
file
(
TAG
,
"TTS初始化成功"
)
}
}
}
fun
speak
(
msg
:
String
)
{
if
(!
mInited
)
return
mTTS
?.
speak
(
msg
,
TextToSpeech
.
QUEUE_FLUSH
,
null
)
}
}
\ 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