bug修改
This commit is contained in:
parent
5af720c2d6
commit
d9c13a34bd
|
|
@ -150,7 +150,7 @@
|
|||
</provider>
|
||||
|
||||
<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"
|
||||
android:enabled="true"
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ package com.bonus.canteen.activity;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
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.LoginInfo;
|
||||
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.OkHttpService;
|
||||
import com.bonus.canteen.utils.SM4EncryptUtils;
|
||||
|
|
@ -59,19 +60,39 @@ public class LoginActivity extends BaseActivity<ActivityLoginBinding> {
|
|||
super.onCreate(savedInstanceState);
|
||||
setupImmersiveMode();
|
||||
initView();
|
||||
startService(new Intent(this, DeviceMonitorService.class));
|
||||
}
|
||||
|
||||
private void setupImmersiveMode() {
|
||||
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;
|
||||
}
|
||||
decorView.setSystemUiVisibility(flags);
|
||||
// 设置初始全屏标志
|
||||
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();
|
||||
}
|
||||
|
||||
public void initView() {
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import android.view.Surface;
|
|||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
|
@ -164,17 +165,36 @@ public class MainActivity extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_main);
|
||||
activity = this;
|
||||
//设置全屏
|
||||
setFullScreen();
|
||||
setupImmersiveMode();
|
||||
init();
|
||||
//初始化秤--延迟两秒 (否则程序会崩溃)
|
||||
mHandler.postDelayed(this::initScale, 2000);
|
||||
}
|
||||
|
||||
private void setFullScreen() {
|
||||
getWindow().getDecorView().setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -273,6 +293,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
});
|
||||
findViewById(R.id.refresh).setOnClickListener(view -> {
|
||||
isInitData = false;
|
||||
XToastUtils.info("正在刷新,请稍候...");
|
||||
initStallTab(canteenList.get(0).getCanteenId());
|
||||
});
|
||||
}
|
||||
|
|
@ -321,7 +342,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
for (int i = 0; i < tempSize; i++) {
|
||||
hexString.append(String.format("%02X ", tempBuffer[i]));
|
||||
}
|
||||
if (!isStopRead && !ThreadPoolManager.getExecutor().isShutdown()) {
|
||||
if (!ThreadPoolManager.getExecutor().isShutdown()) {
|
||||
ThreadPoolManager.getExecutor().execute(() -> parseTheData(hexString.toString()));
|
||||
}
|
||||
}
|
||||
|
|
@ -642,7 +663,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
if (jsonObject.getInteger("code") == 200) {
|
||||
String userName = AppDatabase.getDatabase(this).loginInfoDao().getLoginInfoOne().getUserName();
|
||||
runOnUiThread(() -> {
|
||||
isStopRead = false; // 重新开始读取秤数据
|
||||
isUpload = false;
|
||||
XToastUtils.success("留样成功");
|
||||
KeepSampleRecordBean keepSampleRecordBean = new KeepSampleRecordBean();
|
||||
|
|
@ -662,15 +682,16 @@ public class MainActivity extends AppCompatActivity {
|
|||
toPrint(keepSampleRecordBean);
|
||||
dialog.dismiss();
|
||||
currentDishBean = new DishBean(); // 清空当前菜品信息
|
||||
ThreadPoolManager.getExecutor().execute(this::readScale);
|
||||
});
|
||||
} else {
|
||||
isUpload = false;
|
||||
isStopRead = false; // 重新开始读取秤数据
|
||||
ThreadPoolManager.getExecutor().execute(this::readScale);
|
||||
runOnUiThread(() -> XToastUtils.error("留样失败,请重试!"));
|
||||
}
|
||||
} else {
|
||||
isUpload = false;
|
||||
isStopRead = false; // 重新开始读取秤数据
|
||||
ThreadPoolManager.getExecutor().execute(this::readScale);
|
||||
runOnUiThread(() -> XToastUtils.error("留样失败,请重试!"));
|
||||
}
|
||||
});
|
||||
|
|
@ -685,9 +706,13 @@ public class MainActivity extends AppCompatActivity {
|
|||
try {
|
||||
h = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb("VID:0x4B43,PID:0x3538", 1);
|
||||
if (h == Pointer.NULL) {
|
||||
Log.e(TAG, "打印机连接失败");
|
||||
runOnUiThread(() -> XToastUtils.error("打印机连接失败,请检查设备连接"));
|
||||
return;
|
||||
// runOnUiThread(() -> XToastUtils.warning("打印机连接失败,尝试重新连接"));
|
||||
h = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb("VID:0x4B43,PID:0x3538", 1);
|
||||
if (h == Pointer.NULL) {
|
||||
Log.e(TAG, "打印机连接失败");
|
||||
runOnUiThread(() -> XToastUtils.error("打印机连接失败,请检查设备连接"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
TestFunction fun = new TestFunction();
|
||||
fun.ctx = activity;
|
||||
|
|
@ -1181,7 +1206,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
startBackgroundThread();
|
||||
|
||||
setupImmersiveMode();
|
||||
// 如果Surface已经可用,直接打开相机
|
||||
if (mSurfaceView.getHolder().getSurface().isValid()) {
|
||||
openCamera();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import android.os.Bundle;
|
|||
import android.text.InputType;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
|
@ -55,18 +56,42 @@ public class ParamSettingsActivity extends BaseActivity<ActivityParamSettingBind
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
//设置全屏
|
||||
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
|
||||
);
|
||||
setupImmersiveMode();
|
||||
initData();
|
||||
initView();
|
||||
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() {
|
||||
TextView pageTitle = findViewById(R.id.page_title);
|
||||
pageTitle.setText("参数设置");
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.os.Looper;
|
|||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
|
@ -76,20 +77,44 @@ public class SampleRetentionRecordActivity extends BaseActivity<ActivityKeepSamp
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setFullScreen();
|
||||
setupImmersiveMode();
|
||||
initSaveStatusList();
|
||||
initTitleView();
|
||||
initSelect();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void setFullScreen() {
|
||||
getWindow().getDecorView().setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
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 initSaveStatusList() {
|
||||
saveStatusBeanList.clear();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import android.os.Bundle;
|
|||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
|
@ -56,12 +57,7 @@ public class SampleRetentionRecordDetailsActivity extends BaseActivity<ActivityK
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
//设置全屏
|
||||
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
|
||||
);
|
||||
setupImmersiveMode();
|
||||
mealTimeMap.put("1", "早餐");
|
||||
mealTimeMap.put("2", "午餐");
|
||||
mealTimeMap.put("3", "下午茶");
|
||||
|
|
@ -76,7 +72,37 @@ public class SampleRetentionRecordDetailsActivity extends BaseActivity<ActivityK
|
|||
initTitleView();
|
||||
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() {
|
||||
TextView titleView = findViewById(R.id.page_title);
|
||||
|
|
@ -103,7 +129,7 @@ public class SampleRetentionRecordDetailsActivity extends BaseActivity<ActivityK
|
|||
binding.entryCabinetTime.setText(keepSampleRecordBean.getEnterCabinetTime());
|
||||
binding.leaveCabinetTime.setText(keepSampleRecordBean.getLeaveCabinetTime());
|
||||
binding.durationInTheCabinet.setText(keepSampleRecordBean.getValidDuration());
|
||||
binding.isViolation.setText(keepSampleRecordBean.getIllegalStatusName());
|
||||
binding.isViolation.setText(keepSampleRecordBean.getIllegalStatusName().replaceAll(" ",""));
|
||||
binding.printingTime.setText(keepSampleRecordBean.getPrintRecordTime());
|
||||
ImageView photo = binding.samplePhoto;
|
||||
if (keepSampleRecordBean.getImageUrl() != null) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import com.bonus.canteen.activity.SampleRetentionRecordActivity;
|
||||
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 org.easydarwin.easypusher.R;
|
||||
|
|
@ -59,6 +61,13 @@ public class KeepSampleRecordAdapter extends BaseRecyclerAdapter<KitchenSampleDi
|
|||
|
||||
@Override
|
||||
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.stall_name, item.getStallName());
|
||||
holder.text(R.id.meal_time_name, mealTimeMap.get(item.getMealtimeType()));
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public abstract class BaseActivity<Binding extends ViewBinding> extends XPageAct
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
initStatusBarStyle();
|
||||
super.onCreate(savedInstanceState);
|
||||
registerSlideBack();
|
||||
unregisterSlideBack();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ public class TestFunction {
|
|||
void Test_Pos_QueryPrintResult(Pointer h) {
|
||||
boolean result = AutoReplyPrint.INSTANCE.CP_Pos_QueryPrintResult(h, 30000);
|
||||
if (!result)
|
||||
TestUtils.showMessageOnUiThread(ctx, "Print failed");
|
||||
TestUtils.showMessageOnUiThread(ctx, "打印失败");
|
||||
else
|
||||
TestUtils.showMessageOnUiThread(ctx, "Print Success");
|
||||
TestUtils.showMessageOnUiThread(ctx, "打印成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,11 +18,13 @@
|
|||
package com.bonus.canteen.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.util.Log;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DateTimeHelper {
|
||||
public static String format(Date d, String f) {
|
||||
|
|
@ -87,4 +89,20 @@ public class DateTimeHelper {
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,15 +25,15 @@ public class WorkConfig {
|
|||
throw new UnsupportedOperationException("Cannot instantiate utility class");
|
||||
}
|
||||
//本地
|
||||
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 baseUrl = "http://192.168.20.234:48390/smart-canteen";
|
||||
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 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 serverUri = "tcp://192.168.0.244:1883";
|
||||
protected static String MqttUserName = "admin";
|
||||
protected static String MqttPassWord = "Bonus@admin123!";
|
||||
protected static String serverUri = "tcp://192.168.20.234:1883";
|
||||
protected static String MqttUserName = "guest";
|
||||
protected static String MqttPassWord = "Bonus@Rabbitmq123!";
|
||||
protected static String APP_ID = "52XE2dQBtdmMsfDMvyKmPCCPyFsc4jvo8TKvAdaYfr28";
|
||||
protected static String APP_KEY = "9YFPa6eiuNQAFnzJUadn4LaR8w1bcw3a5ZWYZB6FB57Y";
|
||||
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 |
|
|
@ -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 |
|
|
@ -26,7 +26,7 @@
|
|||
android:layout_width="500dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="240dp"
|
||||
android:layout_marginStart="160dp"
|
||||
android:padding="50dp"
|
||||
android:background="@drawable/btn_border_bg_10_white_1"
|
||||
android:orientation="vertical">
|
||||
|
|
@ -82,7 +82,7 @@
|
|||
android:maxLength="20"
|
||||
android:hint="@string/please_enter_username"
|
||||
android:textColorHint="#999999"
|
||||
android:text="13866134935"
|
||||
android:text="18158863319"
|
||||
android:inputType="textPersonName"
|
||||
android:background="@android:color/transparent"
|
||||
android:paddingStart="10dp"
|
||||
|
|
@ -116,7 +116,7 @@
|
|||
android:layout_marginEnd="5dp"
|
||||
android:inputType="textPassword"
|
||||
android:paddingLeft="10dp"
|
||||
android:text="Bonus$2028" />
|
||||
android:text="Bonus$2025" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/check_password"
|
||||
|
|
|
|||
|
|
@ -8,30 +8,28 @@
|
|||
<include layout="@layout/activity_title"
|
||||
android:id="@+id/title"/>
|
||||
<LinearLayout
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp">
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hello"
|
||||
android:fontFamily="@font/source_han_sans_cn_medium"
|
||||
android:layout_marginStart="20dp"
|
||||
android:textSize="15pt"/>
|
||||
android:textSize="11pt"/>
|
||||
<TextView
|
||||
android:id="@+id/username"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/source_han_sans_cn_medium"
|
||||
android:text="智小样"
|
||||
android:textSize="15pt"/>
|
||||
android:textSize="11pt"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/source_han_sans_cn_medium"
|
||||
android:text="!"
|
||||
android:textSize="15pt"/>
|
||||
android:textSize="11pt"/>
|
||||
<LinearLayout
|
||||
style="?android:attr/buttonBarStyle"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -247,7 +245,6 @@
|
|||
android:layout_gravity="center"
|
||||
android:layout_marginStart="30dp"
|
||||
android:enabled="false"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:background="@drawable/btn_border_bg_10_dark_gray"
|
||||
android:text="@string/theWeightDoesNotMeetTheStandard" />
|
||||
</LinearLayout>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:background="@drawable/title_bg"
|
||||
android:background="@drawable/activity_title_bg"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<resources>
|
||||
<string name="app_name">智慧食堂</string>
|
||||
<string name="app_name">智能留样仪</string>
|
||||
<string name="app_browser_name">通用浏览器</string>
|
||||
|
||||
<string name="more">更多</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue