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
6898f317
authored
May 22, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化重复扫码、支付成功、支付失败提示语及TTS播报
parent
cebb9970
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
54 additions
and
31 deletions
+54
-31
README.md
+8
-0
app/src/main/assets/pay-balance-not-enough.mp3
+0
-0
app/src/main/assets/qrcode-repeat.mp3
+0
-0
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
+32
-25
app/src/main/java/com/bgycc/smartcanteen/state/QRCodeState.java
+3
-2
app/src/main/java/com/bgycc/smartcanteen/utils/TTSHelper.java
+2
-2
app/src/main/java/com/bgycc/smartcanteen/viewModel/QRCodeViewModel.java
+2
-2
app/src/main/res/values/colors.xml
+3
-0
app/src/main/res/values/strings.xml
+4
-0
智慧食堂开发文档.docx
+0
-0
No files found.
README.md
View file @
6898f317
...
@@ -31,3 +31,11 @@
...
@@ -31,3 +31,11 @@
其中
**小兵Q6**
是早期评估机型,没有正式上线使用过,因此不再需要维护。
其中
**小兵Q6**
是早期评估机型,没有正式上线使用过,因此不再需要维护。
当前已实现天波580C和优卡特P60S的串口读取,并且会根据机型匹配对应的方案。
当前已实现天波580C和优卡特P60S的串口读取,并且会根据机型匹配对应的方案。
### 语音生成
由于机器TTS功能被阉割,因此当前语音都需要通过文字来匹配对应的语音包进行播放。
语音包设置(通过"知意配音"生成):
-
标准女声
-
主播音量最大
-
配音音调6
app/src/main/assets/pay-balance-not-enough.mp3
View file @
6898f317
No preview for this file type
app/src/main/assets/qrcode-repeat.mp3
View file @
6898f317
No preview for this file type
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
View file @
6898f317
package
com
.
bgycc
.
smartcanteen
.
activity
;
package
com
.
bgycc
.
smartcanteen
.
activity
;
import
androidx.annotation.StringRes
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.lifecycle.LiveData
;
import
androidx.lifecycle.LiveData
;
import
androidx.lifecycle.Observer
;
import
androidx.lifecycle.Observer
;
...
@@ -168,6 +169,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -168,6 +169,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
LogUtils
.
file
(
TAG
,
log
);
LogUtils
.
file
(
TAG
,
log
);
if
(
debugLayoutIsNotInflate
())
return
;
if
(
debugLayoutIsNotInflate
())
return
;
sendText
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_in_process
));
sendText
.
setText
(
log
);
sendText
.
setText
(
log
);
break
;
break
;
case
PayOnlineState
.
SUCCESS
:
case
PayOnlineState
.
SUCCESS
:
...
@@ -185,12 +187,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -185,12 +187,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_success
));
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_success
));
String
successText
=
event
.
getMessage
();
String
successText
=
event
.
getMessage
();
if
(
TextUtils
.
isEmpty
(
successText
))
{
if
(
TextUtils
.
isEmpty
(
successText
))
{
message
.
setText
(
R
.
string
.
pay_success
);
successText
=
getString
(
R
.
string
.
pay_success
);
TTSHelper
.
speak
(
getString
(
R
.
string
.
pay_success
));
}
}
else
{
message
.
setText
(
successText
);
message
.
setText
(
successText
);
TTSHelper
.
speak
(
successText
);
TTSHelper
.
speak
(
successText
);
}
qrCodeViewModel
.
scan
();
qrCodeViewModel
.
scan
();
break
;
break
;
case
PayOfflineState
.
MARK_FAILED
:
case
PayOfflineState
.
MARK_FAILED
:
...
@@ -202,15 +202,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -202,15 +202,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
qrCodeViewModel
.
getQRCodeStateEvent
().
observe
(
this
,
event
->
{
qrCodeViewModel
.
getQRCodeStateEvent
().
observe
(
this
,
event
->
{
switch
(
event
.
getState
())
{
switch
(
event
.
getState
())
{
case
QRCodeState
.
IDLE
:
case
QRCodeState
.
IDLE
:
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_idle
));
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_normal
));
message
.
setText
(
R
.
string
.
pay_idle
);
message
.
setText
(
R
.
string
.
pay_idle
);
break
;
break
;
case
QRCodeState
.
SCANNING
:
case
QRCodeState
.
SCANNING
:
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_idle
));
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_normal
));
message
.
setText
(
R
.
string
.
qrcode_scanning
);
message
.
setText
(
R
.
string
.
qrcode_scanning
);
break
;
break
;
case
QRCodeState
.
SUCCESS
:
case
QRCodeState
.
SUCCESS
:
TTSHelper
.
speak
(
"beep"
);
TTSHelper
.
speak
(
getString
(
R
.
string
.
beep
)
);
PayData
data
=
event
.
getData
();
PayData
data
=
event
.
getData
();
if
(
data
!=
null
)
{
if
(
data
!=
null
)
{
if
(
SCWebSocketClient
.
getInstance
().
isOpen
())
{
if
(
SCWebSocketClient
.
getInstance
().
isOpen
())
{
...
@@ -233,15 +233,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -233,15 +233,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
qrCodeText
.
setText
(
msg
);
qrCodeText
.
setText
(
msg
);
break
;
break
;
case
QRCodeState
.
FAILED
:
case
QRCodeState
.
FAILED
:
String
failedText
=
event
.
getMessage
();
scanFailed
(
event
.
getMessage
(),
R
.
string
.
invalidate_qrcode
);
if
(
TextUtils
.
isEmpty
(
failedText
))
{
break
;
TTSHelper
.
speak
(
"无效二维码"
);
case
QRCodeState
.
SCAN_REPEAT
:
}
else
{
scanFailed
(
event
.
getMessage
(),
R
.
string
.
scan_repeat
);
TTSHelper
.
speak
(
failedText
);
}
qrCodeViewModel
.
scan
();
break
;
break
;
case
QRCodeState
.
I
LLEGAL
:
case
QRCodeState
.
I
NIT_FAILED
:
if
(
debugLayoutIsNotInflate
())
return
;
if
(
debugLayoutIsNotInflate
())
return
;
message
.
setVisibility
(
View
.
GONE
);
message
.
setVisibility
(
View
.
GONE
);
sendText
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
serial_port_error
));
sendText
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
serial_port_error
));
...
@@ -372,39 +369,49 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
...
@@ -372,39 +369,49 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
}
}
}
private
void
scanFailed
(
String
failedMessage
,
@StringRes
int
defaultMessage
)
{
if
(
TextUtils
.
isEmpty
(
failedMessage
))
{
failedMessage
=
getString
(
defaultMessage
);
}
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_error
));
message
.
setText
(
failedMessage
);
TTSHelper
.
speak
(
failedMessage
);
qrCodeViewModel
.
scan
();
}
private
void
paidSuccess
(
String
successMessage
)
{
private
void
paidSuccess
(
String
successMessage
)
{
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_success
));
if
(
TextUtils
.
isEmpty
(
successMessage
))
{
if
(
TextUtils
.
isEmpty
(
successMessage
))
{
message
.
setText
(
R
.
string
.
pay_success
);
successMessage
=
getString
(
R
.
string
.
pay_success
);
TTSHelper
.
speak
(
getString
(
R
.
string
.
pay_success
));
}
}
else
{
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_success
));
message
.
setText
(
successMessage
);
message
.
setText
(
successMessage
);
TTSHelper
.
speak
(
successMessage
);
TTSHelper
.
speak
(
successMessage
);
}
qrCodeViewModel
.
scan
();
qrCodeViewModel
.
scan
();
String
successTime
=
payDateFormat
.
format
(
new
Date
());
String
successTime
=
payDateFormat
.
format
(
new
Date
());
String
successLog
=
"支付成功: "
+
successTime
+
" - "
+
successMessage
;
String
successLog
=
"支付成功: "
+
successTime
+
" - "
+
successMessage
;
LogUtils
.
file
(
TAG
,
successLog
);
LogUtils
.
file
(
TAG
,
successLog
);
if
(
debugLayoutIsNotInflate
())
return
;
if
(
debugLayoutIsNotInflate
())
return
;
recText
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_success
));
recText
.
setText
(
successLog
);
recText
.
setText
(
successLog
);
}
}
private
void
paidFailed
(
String
failedMessage
)
{
private
void
paidFailed
(
String
failedMessage
)
{
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_failed
));
if
(
TextUtils
.
isEmpty
(
failedMessage
))
{
if
(
TextUtils
.
isEmpty
(
failedMessage
))
{
message
.
setText
(
R
.
string
.
pay_failed
);
failedMessage
=
getString
(
R
.
string
.
pay_failed
);
TTSHelper
.
speak
(
getString
(
R
.
string
.
pay_failed
));
}
}
else
{
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_failed
));
message
.
setText
(
failedMessage
);
message
.
setText
(
failedMessage
);
TTSHelper
.
speak
(
failedMessage
);
TTSHelper
.
speak
(
failedMessage
);
}
qrCodeViewModel
.
scan
();
qrCodeViewModel
.
scan
();
String
failedTime
=
payDateFormat
.
format
(
new
Date
());
String
failedTime
=
payDateFormat
.
format
(
new
Date
());
String
failedLog
=
"支付失败: "
+
failedTime
+
" - "
+
failedMessage
;
String
failedLog
=
"支付失败: "
+
failedTime
+
" - "
+
failedMessage
;
LogUtils
.
file
(
TAG
,
failedLog
);
LogUtils
.
file
(
TAG
,
failedLog
);
if
(
debugLayoutIsNotInflate
())
return
;
if
(
debugLayoutIsNotInflate
())
return
;
recText
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_failed
));
recText
.
setText
(
failedLog
);
recText
.
setText
(
failedLog
);
}
}
...
...
app/src/main/java/com/bgycc/smartcanteen/state/QRCodeState.java
View file @
6898f317
...
@@ -11,9 +11,10 @@ public class QRCodeState {
...
@@ -11,9 +11,10 @@ public class QRCodeState {
public
static
final
int
SCANNING
=
1
;
public
static
final
int
SCANNING
=
1
;
public
static
final
int
SUCCESS
=
2
;
public
static
final
int
SUCCESS
=
2
;
public
static
final
int
FAILED
=
3
;
public
static
final
int
FAILED
=
3
;
public
static
final
int
ILLEGAL
=
4
;
public
static
final
int
SCAN_REPEAT
=
4
;
public
static
final
int
INIT_FAILED
=
5
;
@IntDef
(
value
=
{
IDLE
,
SCANNING
,
SUCCESS
,
FAILED
,
ILLEGAL
})
@IntDef
(
value
=
{
IDLE
,
SCANNING
,
SUCCESS
,
FAILED
,
SCAN_REPEAT
,
INIT_FAILED
})
public
@interface
QRCODE_STATE
{
public
@interface
QRCODE_STATE
{
}
}
...
...
app/src/main/java/com/bgycc/smartcanteen/utils/TTSHelper.java
View file @
6898f317
...
@@ -80,7 +80,7 @@ public class TTSHelper {
...
@@ -80,7 +80,7 @@ public class TTSHelper {
case
"无效二维码"
:
case
"无效二维码"
:
soundName
=
"qrcode-invalid.mp3"
;
soundName
=
"qrcode-invalid.mp3"
;
break
;
break
;
case
"请
不要
重复扫码"
:
case
"请
勿
重复扫码"
:
soundName
=
"qrcode-repeat.mp3"
;
soundName
=
"qrcode-repeat.mp3"
;
break
;
break
;
case
"支付成功"
:
case
"支付成功"
:
...
@@ -125,7 +125,7 @@ public class TTSHelper {
...
@@ -125,7 +125,7 @@ public class TTSHelper {
case
"非营业时间"
:
case
"非营业时间"
:
soundName
=
"pay-canteen-rest-time.mp3"
;
soundName
=
"pay-canteen-rest-time.mp3"
;
break
;
break
;
case
"余额不足"
:
case
"
可用
余额不足"
:
soundName
=
"pay-balance-not-enough.mp3"
;
soundName
=
"pay-balance-not-enough.mp3"
;
break
;
break
;
case
"第三方支付异常"
:
case
"第三方支付异常"
:
...
...
app/src/main/java/com/bgycc/smartcanteen/viewModel/QRCodeViewModel.java
View file @
6898f317
...
@@ -63,7 +63,7 @@ public class QRCodeViewModel extends ViewModel {
...
@@ -63,7 +63,7 @@ public class QRCodeViewModel extends ViewModel {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LogUtils
.
e
(
TAG
,
"串口初始化失败: "
+
e
.
getMessage
(),
e
);
LogUtils
.
e
(
TAG
,
"串口初始化失败: "
+
e
.
getMessage
(),
e
);
scan
=
null
;
scan
=
null
;
qrCodeState
.
postValue
(
new
QRCodeState
(
QRCodeState
.
I
LLEGAL
));
qrCodeState
.
postValue
(
new
QRCodeState
(
QRCodeState
.
I
NIT_FAILED
));
}
}
}
}
...
@@ -123,7 +123,7 @@ public class QRCodeViewModel extends ViewModel {
...
@@ -123,7 +123,7 @@ public class QRCodeViewModel extends ViewModel {
PayData
existsPay
=
payDataRepository
.
queryPayDataByPayCode
(
scanData
);
PayData
existsPay
=
payDataRepository
.
queryPayDataByPayCode
(
scanData
);
if
(
existsPay
!=
null
)
{
if
(
existsPay
!=
null
)
{
LogUtils
.
w
(
TAG
,
"该订单已存在: "
+
scanData
);
LogUtils
.
w
(
TAG
,
"该订单已存在: "
+
scanData
);
qrCodeState
.
postValue
(
new
QRCodeState
(
QRCodeState
.
FAILED
,
"请不要重复扫码"
));
qrCodeState
.
postValue
(
new
QRCodeState
(
QRCodeState
.
SCAN_REPEAT
));
return
;
return
;
}
}
// 扫描到的二维码保存到数据库
// 扫描到的二维码保存到数据库
...
...
app/src/main/res/values/colors.xml
View file @
6898f317
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources>
<color
name=
"qrcode_normal"
>
#FF333333
</color>
<color
name=
"qrcode_error"
>
#FFFF0000
</color>
<color
name=
"pay_idle"
>
#FF333333
</color>
<color
name=
"pay_idle"
>
#FF333333
</color>
<color
name=
"pay_in_process"
>
#FF009900
</color>
<color
name=
"pay_success"
>
#FF009900
</color>
<color
name=
"pay_success"
>
#FF009900
</color>
<color
name=
"pay_failed"
>
#FFFF0000
</color>
<color
name=
"pay_failed"
>
#FFFF0000
</color>
<color
name=
"serial_port_error"
>
#FFFF0000
</color>
<color
name=
"serial_port_error"
>
#FFFF0000
</color>
...
...
app/src/main/res/values/strings.xml
View file @
6898f317
...
@@ -17,6 +17,10 @@
...
@@ -17,6 +17,10 @@
<string
name=
"qrcode_failed"
>
请出示付款码
</string>
<string
name=
"qrcode_failed"
>
请出示付款码
</string>
<string
name=
"qrcode_scanning"
>
正在扫描…
</string>
<string
name=
"qrcode_scanning"
>
正在扫描…
</string>
<string
name=
"beep"
>
beep
</string>
<string
name=
"scan_repeat"
>
请勿重复扫码
</string>
<string
name=
"invalidate_qrcode"
>
无效二维码
</string>
<string
name=
"pay_idle"
>
请出示付款码
</string>
<string
name=
"pay_idle"
>
请出示付款码
</string>
<string
name=
"pay_wait"
>
交易处理中
</string>
<string
name=
"pay_wait"
>
交易处理中
</string>
<string
name=
"pay_success"
>
支付成功
</string>
<string
name=
"pay_success"
>
支付成功
</string>
...
...
智慧食堂开发文档.docx
View file @
6898f317
No preview for this file type
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