bug修改

This commit is contained in:
jjLv 2025-11-13 13:13:58 +08:00
parent 5af720c2d6
commit d9c13a34bd
19 changed files with 341 additions and 64 deletions

View File

@ -150,7 +150,7 @@
</provider> </provider>
<service android:name="org.eclipse.paho.android.service.MqttService" /> <service android:name="org.eclipse.paho.android.service.MqttService" />
<service android:name="com.bonus.canteen.service.DeviceMonitorService" />
<!-- 开机自启广播--> <!-- 开机自启广播-->
<receiver android:name="com.bonus.canteen.receiver.BootReceiver" <receiver android:name="com.bonus.canteen.receiver.BootReceiver"
android:enabled="true" android:enabled="true"

View File

@ -2,13 +2,13 @@ package com.bonus.canteen.activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
@ -19,6 +19,7 @@ import com.bonus.canteen.db.AppDatabase;
import com.bonus.canteen.db.entity.base.DeviceInfo; import com.bonus.canteen.db.entity.base.DeviceInfo;
import com.bonus.canteen.db.entity.base.LoginInfo; import com.bonus.canteen.db.entity.base.LoginInfo;
import com.bonus.canteen.db.entity.base.ParamSettingInfo; import com.bonus.canteen.db.entity.base.ParamSettingInfo;
import com.bonus.canteen.service.DeviceMonitorService;
import com.bonus.canteen.utils.AppUtil; import com.bonus.canteen.utils.AppUtil;
import com.bonus.canteen.utils.OkHttpService; import com.bonus.canteen.utils.OkHttpService;
import com.bonus.canteen.utils.SM4EncryptUtils; import com.bonus.canteen.utils.SM4EncryptUtils;
@ -59,19 +60,39 @@ public class LoginActivity extends BaseActivity<ActivityLoginBinding> {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setupImmersiveMode(); setupImmersiveMode();
initView(); initView();
startService(new Intent(this, DeviceMonitorService.class));
} }
private void setupImmersiveMode() { private void setupImmersiveMode() {
View decorView = getWindow().getDecorView(); View decorView = getWindow().getDecorView();
int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 设置初始全屏标志
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// 隐藏导航栏
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
// 沉浸式模式
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
// 添加监听器当系统UI可见性变化时重新应用全屏设置
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
// 当系统UI可见性变化时重新设置全屏
decorView.setSystemUiVisibility(uiOptions);
});
// 确保Activity的主题也支持全屏
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
} }
decorView.setSystemUiVisibility(flags); @Override
protected void onResume() {
super.onResume();
setupImmersiveMode();
} }
public void initView() { public void initView() {

View File

@ -51,6 +51,7 @@ import android.view.Surface;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -164,17 +165,36 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
activity = this; activity = this;
//设置全屏 //设置全屏
setFullScreen(); setupImmersiveMode();
init(); init();
//初始化秤--延迟两秒 否则程序会崩溃 //初始化秤--延迟两秒 否则程序会崩溃
mHandler.postDelayed(this::initScale, 2000); mHandler.postDelayed(this::initScale, 2000);
} }
private void setFullScreen() { private void setupImmersiveMode() {
getWindow().getDecorView().setSystemUiVisibility( View decorView = getWindow().getDecorView();
View.SYSTEM_UI_FLAG_FULLSCREEN
// 设置初始全屏标志
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// 隐藏导航栏
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
// 沉浸式模式
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
// 添加监听器当系统UI可见性变化时重新应用全屏设置
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
// 当系统UI可见性变化时重新设置全屏
decorView.setSystemUiVisibility(uiOptions);
});
// 确保Activity的主题也支持全屏
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
); );
} }
@ -273,6 +293,7 @@ public class MainActivity extends AppCompatActivity {
}); });
findViewById(R.id.refresh).setOnClickListener(view -> { findViewById(R.id.refresh).setOnClickListener(view -> {
isInitData = false; isInitData = false;
XToastUtils.info("正在刷新,请稍候...");
initStallTab(canteenList.get(0).getCanteenId()); initStallTab(canteenList.get(0).getCanteenId());
}); });
} }
@ -321,7 +342,7 @@ public class MainActivity extends AppCompatActivity {
for (int i = 0; i < tempSize; i++) { for (int i = 0; i < tempSize; i++) {
hexString.append(String.format("%02X ", tempBuffer[i])); hexString.append(String.format("%02X ", tempBuffer[i]));
} }
if (!isStopRead && !ThreadPoolManager.getExecutor().isShutdown()) { if (!ThreadPoolManager.getExecutor().isShutdown()) {
ThreadPoolManager.getExecutor().execute(() -> parseTheData(hexString.toString())); ThreadPoolManager.getExecutor().execute(() -> parseTheData(hexString.toString()));
} }
} }
@ -642,7 +663,6 @@ public class MainActivity extends AppCompatActivity {
if (jsonObject.getInteger("code") == 200) { if (jsonObject.getInteger("code") == 200) {
String userName = AppDatabase.getDatabase(this).loginInfoDao().getLoginInfoOne().getUserName(); String userName = AppDatabase.getDatabase(this).loginInfoDao().getLoginInfoOne().getUserName();
runOnUiThread(() -> { runOnUiThread(() -> {
isStopRead = false; // 重新开始读取秤数据
isUpload = false; isUpload = false;
XToastUtils.success("留样成功"); XToastUtils.success("留样成功");
KeepSampleRecordBean keepSampleRecordBean = new KeepSampleRecordBean(); KeepSampleRecordBean keepSampleRecordBean = new KeepSampleRecordBean();
@ -662,15 +682,16 @@ public class MainActivity extends AppCompatActivity {
toPrint(keepSampleRecordBean); toPrint(keepSampleRecordBean);
dialog.dismiss(); dialog.dismiss();
currentDishBean = new DishBean(); // 清空当前菜品信息 currentDishBean = new DishBean(); // 清空当前菜品信息
ThreadPoolManager.getExecutor().execute(this::readScale);
}); });
} else { } else {
isUpload = false; isUpload = false;
isStopRead = false; // 重新开始读取秤数据 ThreadPoolManager.getExecutor().execute(this::readScale);
runOnUiThread(() -> XToastUtils.error("留样失败,请重试!")); runOnUiThread(() -> XToastUtils.error("留样失败,请重试!"));
} }
} else { } else {
isUpload = false; isUpload = false;
isStopRead = false; // 重新开始读取秤数据 ThreadPoolManager.getExecutor().execute(this::readScale);
runOnUiThread(() -> XToastUtils.error("留样失败,请重试!")); runOnUiThread(() -> XToastUtils.error("留样失败,请重试!"));
} }
}); });
@ -685,10 +706,14 @@ public class MainActivity extends AppCompatActivity {
try { try {
h = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb("VID:0x4B43,PID:0x3538", 1); h = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb("VID:0x4B43,PID:0x3538", 1);
if (h == Pointer.NULL) { if (h == Pointer.NULL) {
// runOnUiThread(() -> XToastUtils.warning("打印机连接失败,尝试重新连接"));
h = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb("VID:0x4B43,PID:0x3538", 1);
if (h == Pointer.NULL) {
Log.e(TAG, "打印机连接失败"); Log.e(TAG, "打印机连接失败");
runOnUiThread(() -> XToastUtils.error("打印机连接失败,请检查设备连接")); runOnUiThread(() -> XToastUtils.error("打印机连接失败,请检查设备连接"));
return; return;
} }
}
TestFunction fun = new TestFunction(); TestFunction fun = new TestFunction();
fun.ctx = activity; fun.ctx = activity;
Method m = TestFunction.class.getDeclaredMethod("ToPrint", Pointer.class, KeepSampleRecordBean.class); Method m = TestFunction.class.getDeclaredMethod("ToPrint", Pointer.class, KeepSampleRecordBean.class);
@ -1181,7 +1206,7 @@ public class MainActivity extends AppCompatActivity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
startBackgroundThread(); startBackgroundThread();
setupImmersiveMode();
// 如果Surface已经可用直接打开相机 // 如果Surface已经可用直接打开相机
if (mSurfaceView.getHolder().getSurface().isValid()) { if (mSurfaceView.getHolder().getSurface().isValid()) {
openCamera(); openCamera();

View File

@ -24,6 +24,7 @@ import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -55,18 +56,42 @@ public class ParamSettingsActivity extends BaseActivity<ActivityParamSettingBind
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
//设置全屏 setupImmersiveMode();
getWindow().getDecorView().setSystemUiVisibility(
android.view.View.SYSTEM_UI_FLAG_FULLSCREEN
| android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE
);
initData(); initData();
initView(); initView();
initListeners(); initListeners();
} }
private void setupImmersiveMode() {
View decorView = getWindow().getDecorView();
// 设置初始全屏标志
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// 隐藏导航栏
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
// 沉浸式模式
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
// 添加监听器当系统UI可见性变化时重新应用全屏设置
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
// 当系统UI可见性变化时重新设置全屏
decorView.setSystemUiVisibility(uiOptions);
});
// 确保Activity的主题也支持全屏
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
}
@Override
protected void onResume() {
super.onResume();
setupImmersiveMode();
}
private void initView() { private void initView() {
TextView pageTitle = findViewById(R.id.page_title); TextView pageTitle = findViewById(R.id.page_title);
pageTitle.setText("参数设置"); pageTitle.setText("参数设置");

View File

@ -8,6 +8,7 @@ import android.os.Looper;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -76,20 +77,44 @@ public class SampleRetentionRecordActivity extends BaseActivity<ActivityKeepSamp
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setFullScreen(); setupImmersiveMode();
initSaveStatusList(); initSaveStatusList();
initTitleView(); initTitleView();
initSelect(); initSelect();
initListener(); initListener();
} }
private void setFullScreen() { private void setupImmersiveMode() {
getWindow().getDecorView().setSystemUiVisibility( View decorView = getWindow().getDecorView();
View.SYSTEM_UI_FLAG_FULLSCREEN
// 设置初始全屏标志
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// 隐藏导航栏
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
// 沉浸式模式
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
// 添加监听器当系统UI可见性变化时重新应用全屏设置
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
// 当系统UI可见性变化时重新设置全屏
decorView.setSystemUiVisibility(uiOptions);
});
// 确保Activity的主题也支持全屏
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
); );
} }
@Override
protected void onResume() {
super.onResume();
setupImmersiveMode();
}
private void initSaveStatusList() { private void initSaveStatusList() {
saveStatusBeanList.clear(); saveStatusBeanList.clear();

View File

@ -23,6 +23,7 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -56,12 +57,7 @@ public class SampleRetentionRecordDetailsActivity extends BaseActivity<ActivityK
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
//设置全屏 setupImmersiveMode();
getWindow().getDecorView().setSystemUiVisibility(
android.view.View.SYSTEM_UI_FLAG_FULLSCREEN
| android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE
);
mealTimeMap.put("1", "早餐"); mealTimeMap.put("1", "早餐");
mealTimeMap.put("2", "午餐"); mealTimeMap.put("2", "午餐");
mealTimeMap.put("3", "下午茶"); mealTimeMap.put("3", "下午茶");
@ -76,7 +72,37 @@ public class SampleRetentionRecordDetailsActivity extends BaseActivity<ActivityK
initTitleView(); initTitleView();
initData(); initData();
} }
private void setupImmersiveMode() {
View decorView = getWindow().getDecorView();
// 设置初始全屏标志
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// 隐藏导航栏
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
// 沉浸式模式
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
// 添加监听器当系统UI可见性变化时重新应用全屏设置
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
// 当系统UI可见性变化时重新设置全屏
decorView.setSystemUiVisibility(uiOptions);
});
// 确保Activity的主题也支持全屏
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
}
@Override
protected void onResume() {
super.onResume();
setupImmersiveMode();
}
protected void initTitleView() { protected void initTitleView() {
TextView titleView = findViewById(R.id.page_title); TextView titleView = findViewById(R.id.page_title);
@ -103,7 +129,7 @@ public class SampleRetentionRecordDetailsActivity extends BaseActivity<ActivityK
binding.entryCabinetTime.setText(keepSampleRecordBean.getEnterCabinetTime()); binding.entryCabinetTime.setText(keepSampleRecordBean.getEnterCabinetTime());
binding.leaveCabinetTime.setText(keepSampleRecordBean.getLeaveCabinetTime()); binding.leaveCabinetTime.setText(keepSampleRecordBean.getLeaveCabinetTime());
binding.durationInTheCabinet.setText(keepSampleRecordBean.getValidDuration()); binding.durationInTheCabinet.setText(keepSampleRecordBean.getValidDuration());
binding.isViolation.setText(keepSampleRecordBean.getIllegalStatusName()); binding.isViolation.setText(keepSampleRecordBean.getIllegalStatusName().replaceAll(" ",""));
binding.printingTime.setText(keepSampleRecordBean.getPrintRecordTime()); binding.printingTime.setText(keepSampleRecordBean.getPrintRecordTime());
ImageView photo = binding.samplePhoto; ImageView photo = binding.samplePhoto;
if (keepSampleRecordBean.getImageUrl() != null) { if (keepSampleRecordBean.getImageUrl() != null) {

View File

@ -9,6 +9,8 @@ import androidx.annotation.NonNull;
import com.bonus.canteen.activity.SampleRetentionRecordActivity; import com.bonus.canteen.activity.SampleRetentionRecordActivity;
import com.bonus.canteen.entity.KitchenSampleDishesRecord; import com.bonus.canteen.entity.KitchenSampleDishesRecord;
import com.bonus.canteen.utils.DateTimeHelper;
import com.bonus.canteen.utils.StringHelper;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder; import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
import org.easydarwin.easypusher.R; import org.easydarwin.easypusher.R;
@ -59,6 +61,13 @@ public class KeepSampleRecordAdapter extends BaseRecyclerAdapter<KitchenSampleDi
@Override @Override
protected void bindData(@NonNull RecyclerViewHolder holder, int position, KitchenSampleDishesRecord item) { protected void bindData(@NonNull RecyclerViewHolder holder, int position, KitchenSampleDishesRecord item) {
if (StringHelper.isEmptyAndNull(item.getLeaveCabinetTime())){
item.setValidDuration("0");
}else{
item.setValidDuration(String.valueOf(DateTimeHelper.calculateHoursDifference(StringHelper.isEmptyAndNull(item.getLeaveCabinetTime()) ? DateTimeHelper.getTime() : item.getLeaveCabinetTime(), item.getEnterCabinetTime())));
}
holder.text(R.id.canteen_name, item.getCanteenName()); holder.text(R.id.canteen_name, item.getCanteenName());
holder.text(R.id.stall_name, item.getStallName()); holder.text(R.id.stall_name, item.getStallName());
holder.text(R.id.meal_time_name, mealTimeMap.get(item.getMealtimeType())); holder.text(R.id.meal_time_name, mealTimeMap.get(item.getMealtimeType()));

View File

@ -67,7 +67,7 @@ public abstract class BaseActivity<Binding extends ViewBinding> extends XPageAct
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
initStatusBarStyle(); initStatusBarStyle();
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
registerSlideBack(); unregisterSlideBack();
} }
/** /**

View File

@ -35,9 +35,9 @@ public class TestFunction {
void Test_Pos_QueryPrintResult(Pointer h) { void Test_Pos_QueryPrintResult(Pointer h) {
boolean result = AutoReplyPrint.INSTANCE.CP_Pos_QueryPrintResult(h, 30000); boolean result = AutoReplyPrint.INSTANCE.CP_Pos_QueryPrintResult(h, 30000);
if (!result) if (!result)
TestUtils.showMessageOnUiThread(ctx, "Print failed"); TestUtils.showMessageOnUiThread(ctx, "打印失败");
else else
TestUtils.showMessageOnUiThread(ctx, "Print Success"); TestUtils.showMessageOnUiThread(ctx, "打印成功");
} }
} }

View File

@ -0,0 +1,124 @@
/*
* Copyright (C) 2025 xuexiangjys(xuexiangjys@163.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.bonus.canteen.service;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.Nullable;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
// Android Service中创建TCP服务
public class DeviceMonitorService extends Service {
private ServerSocket serverSocket;
private boolean isRunning = false;
private int port = 8080; // 设置的端口号
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
startTCPServer();
return START_STICKY;
}
private void startTCPServer() {
new Thread(() -> {
try {
serverSocket = new ServerSocket(port);
isRunning = true;
Log.d("DeviceMonitor", "TCP服务已启动端口: " + port);
while (isRunning) {
Socket clientSocket = serverSocket.accept();
// 处理客户端连接
handleClientConnection(clientSocket);
}
} catch (IOException e) {
Log.e("DeviceMonitor", "启动TCP服务失败: " + e.getMessage());
// 端口被占用尝试其他端口
tryAlternativePorts();
}
}).start();
}
private void tryAlternativePorts() {
int[] alternativePorts = {8081, 8082, 8000, 8888, 9000};
for (int altPort : alternativePorts) {
try {
this.port = altPort;
serverSocket = new ServerSocket(altPort);
isRunning = true;
Log.d("DeviceMonitor", "TCP服务在备用端口启动: " + altPort);
break;
} catch (IOException ex) {
Log.e("DeviceMonitor", "端口 " + altPort + " 也被占用");
}
}
}
private void handleClientConnection(Socket clientSocket) {
new Thread(() -> {
try {
// 读取客户端数据
BufferedReader reader = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
String request = reader.readLine();
// Log.d("DeviceMonitor", "收到请求: " + request);
// 返回响应
PrintWriter writer = new PrintWriter(clientSocket.getOutputStream());
writer.println("DEVICE_STATUS:ONLINE");
writer.flush();
clientSocket.close();
} catch (IOException e) {
Log.e("DeviceMonitor", "处理连接错误: " + e.getMessage());
}
}).start();
}
@Override
public void onDestroy() {
isRunning = false;
try {
if (serverSocket != null) {
serverSocket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
super.onDestroy();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}

View File

@ -18,11 +18,13 @@
package com.bonus.canteen.utils; package com.bonus.canteen.utils;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.util.Log;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit;
public class DateTimeHelper { public class DateTimeHelper {
public static String format(Date d, String f) { public static String format(Date d, String f) {
@ -87,4 +89,20 @@ public class DateTimeHelper {
} }
return false; return false;
} }
public static int calculateHoursDifference(String startTimeStr, String endTimeStr) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
try {
Date startDate = formatter.parse(startTimeStr);
Date endDate = formatter.parse(endTimeStr);
long diffInMillis = Math.abs(endDate.getTime() - startDate.getTime());
Log.e("duration", diffInMillis + "");
return (int) TimeUnit.MILLISECONDS.toHours(diffInMillis);
} catch (ParseException e) {
e.printStackTrace();
return 0;
}
}
} }

View File

@ -25,15 +25,15 @@ public class WorkConfig {
throw new UnsupportedOperationException("Cannot instantiate utility class"); throw new UnsupportedOperationException("Cannot instantiate utility class");
} }
//本地 //本地
protected static String baseUrl = "http://192.168.0.244:48380/smart-canteen"; protected static String baseUrl = "http://192.168.20.234:48390/smart-canteen";
protected static String prefixesUrl = "http://192.168.0.244:48380"; protected static String prefixesUrl = "http://192.168.20.234:48390";
// protected static String baseUrl = "http://192.168.0.244:48380/smart-canteen"; // protected static String baseUrl = "http://192.168.0.244:48380/smart-canteen";
// protected static String prefixesUrl = "http://192.168.0.244:48380"; // protected static String prefixesUrl = "http://192.168.0.244:48380";
protected static String fileUrl = "http://192.168.0.14:9090/lnyst/"; protected static String fileUrl = "http://192.168.20.234:9090/lnyst/";
protected static String updateUrl = "https://www.baidu.com"; protected static String updateUrl = "https://www.baidu.com";
protected static String serverUri = "tcp://192.168.0.244:1883"; protected static String serverUri = "tcp://192.168.20.234:1883";
protected static String MqttUserName = "admin"; protected static String MqttUserName = "guest";
protected static String MqttPassWord = "Bonus@admin123!"; protected static String MqttPassWord = "Bonus@Rabbitmq123!";
protected static String APP_ID = "52XE2dQBtdmMsfDMvyKmPCCPyFsc4jvo8TKvAdaYfr28"; protected static String APP_ID = "52XE2dQBtdmMsfDMvyKmPCCPyFsc4jvo8TKvAdaYfr28";
protected static String APP_KEY = "9YFPa6eiuNQAFnzJUadn4LaR8w1bcw3a5ZWYZB6FB57Y"; protected static String APP_KEY = "9YFPa6eiuNQAFnzJUadn4LaR8w1bcw3a5ZWYZB6FB57Y";
protected static String FACE_PASS_RATE = "0.8"; protected static String FACE_PASS_RATE = "0.8";

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -0,0 +1,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#7D97FF"
android:endColor="#4367F5"
android:angle="180"/>
</shape>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -26,7 +26,7 @@
android:layout_width="500dp" android:layout_width="500dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginStart="240dp" android:layout_marginStart="160dp"
android:padding="50dp" android:padding="50dp"
android:background="@drawable/btn_border_bg_10_white_1" android:background="@drawable/btn_border_bg_10_white_1"
android:orientation="vertical"> android:orientation="vertical">
@ -82,7 +82,7 @@
android:maxLength="20" android:maxLength="20"
android:hint="@string/please_enter_username" android:hint="@string/please_enter_username"
android:textColorHint="#999999" android:textColorHint="#999999"
android:text="13866134935" android:text="18158863319"
android:inputType="textPersonName" android:inputType="textPersonName"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:paddingStart="10dp" android:paddingStart="10dp"
@ -116,7 +116,7 @@
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:inputType="textPassword" android:inputType="textPassword"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:text="Bonus$2028" /> android:text="Bonus$2025" />
<ImageView <ImageView
android:id="@+id/check_password" android:id="@+id/check_password"

View File

@ -8,30 +8,28 @@
<include layout="@layout/activity_title" <include layout="@layout/activity_title"
android:id="@+id/title"/> android:id="@+id/title"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:padding="10dp">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/hello" android:text="@string/hello"
android:fontFamily="@font/source_han_sans_cn_medium" android:fontFamily="@font/source_han_sans_cn_medium"
android:layout_marginStart="20dp" android:layout_marginStart="20dp"
android:textSize="15pt"/> android:textSize="11pt"/>
<TextView <TextView
android:id="@+id/username" android:id="@+id/username"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="@font/source_han_sans_cn_medium" android:fontFamily="@font/source_han_sans_cn_medium"
android:text="智小样" android:text="智小样"
android:textSize="15pt"/> android:textSize="11pt"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="@font/source_han_sans_cn_medium" android:fontFamily="@font/source_han_sans_cn_medium"
android:text="!" android:text="!"
android:textSize="15pt"/> android:textSize="11pt"/>
<LinearLayout <LinearLayout
style="?android:attr/buttonBarStyle" style="?android:attr/buttonBarStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -247,7 +245,6 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginStart="30dp" android:layout_marginStart="30dp"
android:enabled="false" android:enabled="false"
android:layout_marginEnd="10dp"
android:background="@drawable/btn_border_bg_10_dark_gray" android:background="@drawable/btn_border_bg_10_dark_gray"
android:text="@string/theWeightDoesNotMeetTheStandard" /> android:text="@string/theWeightDoesNotMeetTheStandard" />
</LinearLayout> </LinearLayout>

View File

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="80dp" android:layout_height="80dp"
android:background="@drawable/title_bg" android:background="@drawable/activity_title_bg"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView

View File

@ -1,5 +1,5 @@
<resources> <resources>
<string name="app_name">慧食堂</string> <string name="app_name">能留样仪</string>
<string name="app_browser_name">通用浏览器</string> <string name="app_browser_name">通用浏览器</string>
<string name="more">更多</string> <string name="more">更多</string>