Commit 5d29ef61 by pye52

Merge branch 'develop'

parents 940f60d9 30b4d247
......@@ -7,8 +7,8 @@ android {
applicationId "com.bgycc.smartcanteen"
minSdkVersion 22
targetSdkVersion 29
versionCode 17
versionName "1.3.7"
versionCode 140
versionName "1.4.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
......
......@@ -15,6 +15,7 @@ import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.os.Process;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
......@@ -34,6 +35,7 @@ import com.bgycc.smartcanteen.Injection;
import com.bgycc.smartcanteen.R;
import com.bgycc.smartcanteen.command.CommandHelper;
import com.bgycc.smartcanteen.entity.Command;
import com.bgycc.smartcanteen.entity.CommandNotice;
import com.bgycc.smartcanteen.entity.PayData;
import com.bgycc.smartcanteen.executor.SCTaskExecutor;
import com.bgycc.smartcanteen.socket.SCWebSocketClient;
......@@ -51,13 +53,14 @@ import com.bgycc.smartcanteen.viewModel.PayOnlineViewModel;
import com.bgycc.smartcanteen.viewModel.QRCodeViewModel;
import com.bgycc.smartcanteen.viewModel.ViewModelFactory;
import com.blankj.utilcode.util.LogUtils;
import com.google.gson.Gson;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import static android.os.Process.myPid;
import static com.bgycc.smartcanteen.utils.SmartCanteenUtils.TAG;
@SuppressWarnings("all")
......@@ -86,6 +89,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private TextView message;
private AudioManager audioManager;
private Gson gson;
private String idle_notice;
private WorkManager workManager;
private Handler handler = new Handler();
private SimpleDateFormat payDateFormat = new SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault());
......@@ -103,9 +108,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
String host = SmartCanteenUtils.getMainWebSocketServerUrl(deviceSN, BuildConfig.VERSION_NAME);
LogUtils.d(TAG, "服务器地址: " + host);
gson = Injection.provideGson();
try {
URI uri = new URI(host);
SCWebSocketClient.init(uri, deviceSN, Injection.provideGson());
SCWebSocketClient.init(uri, deviceSN, gson);
} catch (URISyntaxException e) {
LogUtils.e(TAG, "服务器地址异常: " + e.getMessage(), e);
}
......@@ -138,12 +144,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
switch (event.getState()) {
case PayOnlineState.IDLE:
message.setTextColor(getResources().getColor(R.color.qrcode_normal));
message.setText(R.string.pay_idle);
message.setText(idle_notice);
break;
case PayOnlineState.SEND:
message.setTextColor(getResources().getColor(R.color.pay_idle));
message.setText(R.string.pay_wait);
String time = payDateFormat.format(new Date());
String time = payDateFormat.format(System.currentTimeMillis());
String log = "支付进度: " + time + " - " + event.getMessage();
LogUtils.file(TAG, log);
......@@ -182,7 +188,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
switch (event.getState()) {
case QRCodeState.IDLE:
message.setTextColor(getResources().getColor(R.color.qrcode_normal));
message.setText(R.string.pay_idle);
message.setText(idle_notice);
break;
case QRCodeState.SCANNING:
message.setTextColor(getResources().getColor(R.color.qrcode_normal));
......@@ -243,6 +249,17 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
commandViewModel.commandFinish(command);
return;
}
// 修改主界面的提示语
if (CommandHelper.changedPaymentNotice(command)) {
try {
CommandNotice commandNotice = gson.fromJson(command.getData(), CommandNotice.class);
idle_notice = commandNotice.getData().getNotice();
message.setText(idle_notice);
} finally {
commandViewModel.commandFinish(command);
}
return;
}
// 检查当前是否有在执行的任务
if (runningCommand != null) {
// 若已经有在执行的任务,则跳过该次响应
......@@ -329,10 +346,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCWebSocketClient.getInstance().tryConnect();
}
// 检查debug layout是否已初始化
private boolean debugLayoutIsNotInflate() {
return debugVs != null;
}
// 主界面显示模式切换: Debug <==> Release
private void toggleDebugLayout() {
if (debugLayoutIsNotInflate()) {
inflateDebugLayout();
......@@ -366,7 +385,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
TTSHelper.speak(successMessage);
qrCodeViewModel.scan();
String successTime = payDateFormat.format(new Date());
String successTime = payDateFormat.format(System.currentTimeMillis());
String successLog = "支付成功: " + successTime + " - " + successMessage;
LogUtils.file(TAG, successLog);
......@@ -384,7 +403,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
TTSHelper.speak(failedMessage);
qrCodeViewModel.scan();
String failedTime = payDateFormat.format(new Date());
String failedTime = payDateFormat.format(System.currentTimeMillis());
String failedLog = "支付失败: " + failedTime + " - " + failedMessage;
LogUtils.file(TAG, failedLog);
......@@ -400,6 +419,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCWebSocketClient.getInstance().realClose();
SCTaskExecutor.getInstance().quit();
MonitorUtils.stopMonitors(this);
LogUtils.d(TAG, "MainActivity onDestroy,退出应用");
Process.killProcess(myPid());
}
private void initViews() {
......@@ -411,6 +432,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
settingText = findViewById(R.id._setting_msg);
message = findViewById(R.id._message);
// 设置默认指示语
idle_notice = getString(R.string.default_message);
message.setText(idle_notice);
settingLayout.setAlpha(0);
settingImg.post(() -> {
Animation anim = new RotateAnimation(0f, 360f, 0.5f * settingImg.getWidth(), 0.5f * settingImg.getHeight());
......@@ -511,7 +536,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private Runnable updateTimeRunnable = new Runnable() {
@Override
public void run() {
socketConnectedTime.setText(socketConnectedTimeDateFormat.format(new Date()));
socketConnectedTime.setText(socketConnectedTimeDateFormat.format(System.currentTimeMillis()));
handler.postDelayed(this, 1000);
}
};
......
......@@ -18,6 +18,7 @@ public class CommandHelper {
private static final String CONFIG_WIFI = "CONFIG_WIFI";
private static final String CONFIG_LOG = "CONFIG_LOG";
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>() {
......@@ -27,6 +28,7 @@ public class CommandHelper {
add(CONFIG_WIFI);
add(CONFIG_LOG);
add(EXEC_SHELL);
add(PAYMENT_CHANGED);
}
};
......@@ -38,6 +40,10 @@ public class CommandHelper {
return command.getAction().equals(CONFIG_LOG);
}
public static boolean changedPaymentNotice(Command command) {
return command.getAction().equals(PAYMENT_CHANGED);
}
/**
* 根据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 + '\'' +
'}';
}
}
}
......@@ -26,17 +26,19 @@ public class MonitorUtils {
private static final int LOG_REPEAT_INTERVAL = 4;
private static final int DATABASE_REPEAT_INTERVAL = 12;
// 每天早上指定时间重启设备
private static final int REBOOT_HOUR_OF_DAY = 3;
private static final int REBOOT_MIN = 0;
private static final int REBOOT_HOUR_OF_DAY = 0;
private static final int REBOOT_MIN_OF_HOUR = 1;
public static void startMonitors(Context context) {
startLogFilesMonitor(context);
startDatabaseMonitor(context);
startRebootMonitor(context);
}
public static void stopMonitors(Context context) {
stopLogFilesMonitor(context);
stopDatabaseMonitor(context);
stopRebootMonitor(context);
}
// 指定时间重启设备
......@@ -46,7 +48,7 @@ public class MonitorUtils {
Calendar future = Calendar.getInstance(Locale.getDefault());
future.add(Calendar.DAY_OF_YEAR, 1);
future.set(Calendar.HOUR_OF_DAY, REBOOT_HOUR_OF_DAY);
future.set(Calendar.MINUTE, REBOOT_MIN);
future.set(Calendar.MINUTE, REBOOT_MIN_OF_HOUR);
future.set(Calendar.SECOND, 0);
long delay = future.getTimeInMillis() - now.getTimeInMillis();
LogUtils.d(TAG, delay + "毫秒后将重启设备");
......
......@@ -36,7 +36,6 @@
<TextView
android:id="@+id/_message"
android:text="@string/default_message"
android:textSize="70sp"
android:textColor="#333"
android:textAlignment="center"
......
......@@ -12,16 +12,14 @@
<string name="network_type_ethernet">以太网</string>
<string name="network_type_wifi">Wifi</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="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>
<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