Commit 1105f82d by pye52

增加根据后台返回的指示语改变界面显示的指令

parent 913ccb4c
...@@ -15,6 +15,7 @@ import android.content.Context; ...@@ -15,6 +15,7 @@ import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Process;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.TextUtils; import android.text.TextUtils;
...@@ -34,6 +35,7 @@ import com.bgycc.smartcanteen.Injection; ...@@ -34,6 +35,7 @@ import com.bgycc.smartcanteen.Injection;
import com.bgycc.smartcanteen.R; import com.bgycc.smartcanteen.R;
import com.bgycc.smartcanteen.command.CommandHelper; import com.bgycc.smartcanteen.command.CommandHelper;
import com.bgycc.smartcanteen.entity.Command; import com.bgycc.smartcanteen.entity.Command;
import com.bgycc.smartcanteen.entity.CommandNotice;
import com.bgycc.smartcanteen.entity.PayData; import com.bgycc.smartcanteen.entity.PayData;
import com.bgycc.smartcanteen.executor.SCTaskExecutor; import com.bgycc.smartcanteen.executor.SCTaskExecutor;
import com.bgycc.smartcanteen.socket.SCWebSocketClient; import com.bgycc.smartcanteen.socket.SCWebSocketClient;
...@@ -51,6 +53,7 @@ import com.bgycc.smartcanteen.viewModel.PayOnlineViewModel; ...@@ -51,6 +53,7 @@ import com.bgycc.smartcanteen.viewModel.PayOnlineViewModel;
import com.bgycc.smartcanteen.viewModel.QRCodeViewModel; import com.bgycc.smartcanteen.viewModel.QRCodeViewModel;
import com.bgycc.smartcanteen.viewModel.ViewModelFactory; import com.bgycc.smartcanteen.viewModel.ViewModelFactory;
import com.blankj.utilcode.util.LogUtils; import com.blankj.utilcode.util.LogUtils;
import com.google.gson.Gson;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
...@@ -58,6 +61,7 @@ import java.text.SimpleDateFormat; ...@@ -58,6 +61,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import static android.os.Process.myPid;
import static com.bgycc.smartcanteen.utils.SmartCanteenUtils.TAG; import static com.bgycc.smartcanteen.utils.SmartCanteenUtils.TAG;
@SuppressWarnings("all") @SuppressWarnings("all")
...@@ -86,6 +90,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -86,6 +90,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private TextView message; private TextView message;
private AudioManager audioManager; private AudioManager audioManager;
private String idle_notice;
private WorkManager workManager; private WorkManager workManager;
private Handler handler = new Handler(); private Handler handler = new Handler();
private SimpleDateFormat payDateFormat = new SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault()); private SimpleDateFormat payDateFormat = new SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault());
...@@ -138,7 +143,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -138,7 +143,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
switch (event.getState()) { switch (event.getState()) {
case PayOnlineState.IDLE: case PayOnlineState.IDLE:
message.setTextColor(getResources().getColor(R.color.qrcode_normal)); message.setTextColor(getResources().getColor(R.color.qrcode_normal));
message.setText(R.string.pay_idle); message.setText(idle_notice);
break; break;
case PayOnlineState.SEND: case PayOnlineState.SEND:
message.setTextColor(getResources().getColor(R.color.pay_idle)); message.setTextColor(getResources().getColor(R.color.pay_idle));
...@@ -182,7 +187,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -182,7 +187,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
switch (event.getState()) { switch (event.getState()) {
case QRCodeState.IDLE: case QRCodeState.IDLE:
message.setTextColor(getResources().getColor(R.color.qrcode_normal)); message.setTextColor(getResources().getColor(R.color.qrcode_normal));
message.setText(R.string.pay_idle); message.setText(idle_notice);
break; break;
case QRCodeState.SCANNING: case QRCodeState.SCANNING:
message.setTextColor(getResources().getColor(R.color.qrcode_normal)); message.setTextColor(getResources().getColor(R.color.qrcode_normal));
...@@ -243,6 +248,16 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -243,6 +248,16 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
commandViewModel.commandFinish(command); commandViewModel.commandFinish(command);
return; return;
} }
if (CommandHelper.changedPaymentNotice(command)) {
Gson gson = Injection.provideGson();
try {
CommandNotice commandNotice = gson.fromJson(command.getData(), CommandNotice.class);
idle_notice = commandNotice.getData().getNotice();
} finally {
commandViewModel.commandFinish(command);
}
return;
}
// 检查当前是否有在执行的任务 // 检查当前是否有在执行的任务
if (runningCommand != null) { if (runningCommand != null) {
// 若已经有在执行的任务,则跳过该次响应 // 若已经有在执行的任务,则跳过该次响应
...@@ -401,7 +416,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -401,7 +416,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCTaskExecutor.getInstance().quit(); SCTaskExecutor.getInstance().quit();
MonitorUtils.stopMonitors(this); MonitorUtils.stopMonitors(this);
LogUtils.d(TAG, "MainActivity onDestroy,退出应用"); LogUtils.d(TAG, "MainActivity onDestroy,退出应用");
android.os.Process.killProcess(android.os.Process.myPid()); Process.killProcess(myPid());
} }
private void initViews() { private void initViews() {
...@@ -413,6 +428,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -413,6 +428,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
settingText = findViewById(R.id._setting_msg); settingText = findViewById(R.id._setting_msg);
message = findViewById(R.id._message); message = findViewById(R.id._message);
// 设置默认指示语
idle_notice = getString(R.string.default_message);
message.setText(idle_notice);
settingLayout.setAlpha(0); settingLayout.setAlpha(0);
settingImg.post(() -> { settingImg.post(() -> {
Animation anim = new RotateAnimation(0f, 360f, 0.5f * settingImg.getWidth(), 0.5f * settingImg.getHeight()); Animation anim = new RotateAnimation(0f, 360f, 0.5f * settingImg.getWidth(), 0.5f * settingImg.getHeight());
......
...@@ -18,6 +18,7 @@ public class CommandHelper { ...@@ -18,6 +18,7 @@ public class CommandHelper {
private static final String CONFIG_WIFI = "CONFIG_WIFI"; private static final String CONFIG_WIFI = "CONFIG_WIFI";
private static final String CONFIG_LOG = "CONFIG_LOG"; private static final String CONFIG_LOG = "CONFIG_LOG";
private static final String EXEC_SHELL = "EXEC_SHELL"; private static final String EXEC_SHELL = "EXEC_SHELL";
private static final String PAYMENT_CHANGED = "PAYMENT_CHANGED";
// 设备指令白名单 // 设备指令白名单
private static final Set<String> COMMAND_WHITELIST = new HashSet<String>() { private static final Set<String> COMMAND_WHITELIST = new HashSet<String>() {
...@@ -27,6 +28,7 @@ public class CommandHelper { ...@@ -27,6 +28,7 @@ public class CommandHelper {
add(CONFIG_WIFI); add(CONFIG_WIFI);
add(CONFIG_LOG); add(CONFIG_LOG);
add(EXEC_SHELL); add(EXEC_SHELL);
add(PAYMENT_CHANGED);
} }
}; };
...@@ -38,6 +40,10 @@ public class CommandHelper { ...@@ -38,6 +40,10 @@ public class CommandHelper {
return command.getAction().equals(CONFIG_LOG); return command.getAction().equals(CONFIG_LOG);
} }
public static boolean changedPaymentNotice(Command command) {
return command.getAction().equals(PAYMENT_CHANGED);
}
/** /**
* 根据action检查是否为指令类型 * 根据action检查是否为指令类型
*/ */
......
package com.bgycc.smartcanteen.entity;
import java.util.Objects;
public class CommandNotice {
private String action;
private CommandNoticeData data;
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public CommandNoticeData getData() {
return data;
}
public void setData(CommandNoticeData data) {
this.data = data;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CommandNotice that = (CommandNotice) o;
return Objects.equals(action, that.action) &&
Objects.equals(data, that.data);
}
@Override
public int hashCode() {
return Objects.hash(action, data);
}
@Override
public String toString() {
return "CommandNotice{" +
"action='" + action + '\'' +
", data=" + data +
'}';
}
public static class CommandNoticeData {
private int payment;
private String notice;
public int getPayment() {
return payment;
}
public void setPayment(int payment) {
this.payment = payment;
}
public String getNotice() {
return notice;
}
public void setNotice(String notice) {
this.notice = notice;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CommandNoticeData that = (CommandNoticeData) o;
return payment == that.payment &&
Objects.equals(notice, that.notice);
}
@Override
public int hashCode() {
return Objects.hash(payment, notice);
}
@Override
public String toString() {
return "CommandNoticeData{" +
"payment=" + payment +
", notice='" + notice + '\'' +
'}';
}
}
}
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
<TextView <TextView
android:id="@+id/_message" android:id="@+id/_message"
android:text="@string/default_message"
android:textSize="70sp" android:textSize="70sp"
android:textColor="#333" android:textColor="#333"
android:textAlignment="center" android:textAlignment="center"
......
...@@ -12,16 +12,14 @@ ...@@ -12,16 +12,14 @@
<string name="network_type_ethernet">以太网</string> <string name="network_type_ethernet">以太网</string>
<string name="network_type_wifi">Wifi</string> <string name="network_type_wifi">Wifi</string>
<string name="network_type_unknown">未知</string> <string name="network_type_unknown">未知</string>
<string name="default_message">请出示付款码</string> <string name="default_message">获取后台配置</string>
<string name="qrcode_failed">请出示付款码</string>
<string name="qrcode_scanning">正在扫描…</string> <string name="qrcode_scanning">正在扫描…</string>
<string name="beep">beep</string> <string name="beep">beep</string>
<string name="scan_repeat">请勿重复扫码</string> <string name="scan_repeat">请勿重复扫码</string>
<string name="invalidate_qrcode">无效二维码</string> <string name="invalidate_qrcode">无效二维码</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>
<string name="pay_failed">支付失败</string> <string name="pay_failed">支付失败</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