Commit 6898f317 by pye52

优化重复扫码、支付成功、支付失败提示语及TTS播报

parent cebb9970
......@@ -30,4 +30,12 @@
3. 优卡特P60S
其中 **小兵Q6** 是早期评估机型,没有正式上线使用过,因此不再需要维护。
当前已实现天波580C和优卡特P60S的串口读取,并且会根据机型匹配对应的方案。
\ No newline at end of file
当前已实现天波580C和优卡特P60S的串口读取,并且会根据机型匹配对应的方案。
### 语音生成
由于机器TTS功能被阉割,因此当前语音都需要通过文字来匹配对应的语音包进行播放。
语音包设置(通过"知意配音"生成):
- 标准女声
- 主播音量最大
- 配音音调6
package com.bgycc.smartcanteen.activity;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
......@@ -168,6 +169,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
LogUtils.file(TAG, log);
if (debugLayoutIsNotInflate()) return;
sendText.setTextColor(getResources().getColor(R.color.pay_in_process));
sendText.setText(log);
break;
case PayOnlineState.SUCCESS:
......@@ -185,12 +187,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
message.setTextColor(getResources().getColor(R.color.pay_success));
String successText = event.getMessage();
if (TextUtils.isEmpty(successText)) {
message.setText(R.string.pay_success);
TTSHelper.speak(getString(R.string.pay_success));
} else {
message.setText(successText);
TTSHelper.speak(successText);
successText = getString(R.string.pay_success);
}
message.setText(successText);
TTSHelper.speak(successText);
qrCodeViewModel.scan();
break;
case PayOfflineState.MARK_FAILED:
......@@ -202,15 +202,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
qrCodeViewModel.getQRCodeStateEvent().observe(this, event -> {
switch (event.getState()) {
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);
break;
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);
break;
case QRCodeState.SUCCESS:
TTSHelper.speak("beep");
TTSHelper.speak(getString(R.string.beep));
PayData data = event.getData();
if (data != null) {
if (SCWebSocketClient.getInstance().isOpen()) {
......@@ -233,15 +233,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
qrCodeText.setText(msg);
break;
case QRCodeState.FAILED:
String failedText = event.getMessage();
if (TextUtils.isEmpty(failedText)) {
TTSHelper.speak("无效二维码");
} else {
TTSHelper.speak(failedText);
}
qrCodeViewModel.scan();
scanFailed(event.getMessage(), R.string.invalidate_qrcode);
break;
case QRCodeState.SCAN_REPEAT:
scanFailed(event.getMessage(), R.string.scan_repeat);
break;
case QRCodeState.ILLEGAL:
case QRCodeState.INIT_FAILED:
if (debugLayoutIsNotInflate()) return;
message.setVisibility(View.GONE);
sendText.setTextColor(getResources().getColor(R.color.serial_port_error));
......@@ -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) {
message.setTextColor(getResources().getColor(R.color.pay_success));
if (TextUtils.isEmpty(successMessage)) {
message.setText(R.string.pay_success);
TTSHelper.speak(getString(R.string.pay_success));
} else {
message.setText(successMessage);
TTSHelper.speak(successMessage);
successMessage = getString(R.string.pay_success);
}
message.setTextColor(getResources().getColor(R.color.pay_success));
message.setText(successMessage);
TTSHelper.speak(successMessage);
qrCodeViewModel.scan();
String successTime = payDateFormat.format(new Date());
String successLog = "支付成功: " + successTime + " - " + successMessage;
LogUtils.file(TAG, successLog);
if (debugLayoutIsNotInflate()) return;
recText.setTextColor(getResources().getColor(R.color.pay_success));
recText.setText(successLog);
}
private void paidFailed(String failedMessage) {
message.setTextColor(getResources().getColor(R.color.pay_failed));
if (TextUtils.isEmpty(failedMessage)) {
message.setText(R.string.pay_failed);
TTSHelper.speak(getString(R.string.pay_failed));
} else {
message.setText(failedMessage);
TTSHelper.speak(failedMessage);
failedMessage = getString(R.string.pay_failed);
}
message.setTextColor(getResources().getColor(R.color.pay_failed));
message.setText(failedMessage);
TTSHelper.speak(failedMessage);
qrCodeViewModel.scan();
String failedTime = payDateFormat.format(new Date());
String failedLog = "支付失败: " + failedTime + " - " + failedMessage;
LogUtils.file(TAG, failedLog);
if (debugLayoutIsNotInflate()) return;
recText.setTextColor(getResources().getColor(R.color.pay_failed));
recText.setText(failedLog);
}
......
......@@ -11,9 +11,10 @@ public class QRCodeState {
public static final int SCANNING = 1;
public static final int SUCCESS = 2;
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 {
}
......
......@@ -80,7 +80,7 @@ public class TTSHelper {
case "无效二维码":
soundName = "qrcode-invalid.mp3";
break;
case "请不要重复扫码":
case "请重复扫码":
soundName = "qrcode-repeat.mp3";
break;
case "支付成功":
......@@ -125,7 +125,7 @@ public class TTSHelper {
case "非营业时间":
soundName = "pay-canteen-rest-time.mp3";
break;
case "余额不足":
case "可用余额不足":
soundName = "pay-balance-not-enough.mp3";
break;
case "第三方支付异常":
......
......@@ -63,7 +63,7 @@ public class QRCodeViewModel extends ViewModel {
} catch (Exception e) {
LogUtils.e(TAG, "串口初始化失败: " + e.getMessage(), e);
scan = null;
qrCodeState.postValue(new QRCodeState(QRCodeState.ILLEGAL));
qrCodeState.postValue(new QRCodeState(QRCodeState.INIT_FAILED));
}
}
......@@ -123,7 +123,7 @@ public class QRCodeViewModel extends ViewModel {
PayData existsPay = payDataRepository.queryPayDataByPayCode(scanData);
if (existsPay != null) {
LogUtils.w(TAG, "该订单已存在: " + scanData);
qrCodeState.postValue(new QRCodeState(QRCodeState.FAILED, "请不要重复扫码"));
qrCodeState.postValue(new QRCodeState(QRCodeState.SCAN_REPEAT));
return;
}
// 扫描到的二维码保存到数据库
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="qrcode_normal">#FF333333</color>
<color name="qrcode_error">#FFFF0000</color>
<color name="pay_idle">#FF333333</color>
<color name="pay_in_process">#FF009900</color>
<color name="pay_success">#FF009900</color>
<color name="pay_failed">#FFFF0000</color>
<color name="serial_port_error">#FFFF0000</color>
......
......@@ -17,6 +17,10 @@
<string name="qrcode_failed">请出示付款码</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_wait">交易处理中</string>
<string name="pay_success">支付成功</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment